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 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 void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
783 static void ensure_echo_area_buffers (void);
784 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
785 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
786 static int with_echo_area_buffer (struct window
*, int,
787 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
788 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
789 static void clear_garbaged_frames (void);
790 static int current_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
791 static void pop_message (void);
792 static int truncate_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
793 static void set_message (const char *, Lisp_Object
, EMACS_INT
, int);
794 static int set_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
795 static int display_echo_area (struct window
*);
796 static int display_echo_area_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
797 static int resize_mini_window_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
798 static Lisp_Object
unwind_redisplay (Lisp_Object
);
799 static int string_char_and_length (const unsigned char *, int *);
800 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
802 static int compute_window_start_on_continuation_line (struct window
*);
803 static Lisp_Object
safe_eval_handler (Lisp_Object
);
804 static void insert_left_trunc_glyphs (struct it
*);
805 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
807 static void extend_face_to_end_of_line (struct it
*);
808 static int append_space_for_newline (struct it
*, int);
809 static int cursor_row_fully_visible_p (struct window
*, int, int);
810 static int try_scrolling (Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int);
811 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
812 static int trailing_whitespace_p (EMACS_INT
);
813 static intmax_t message_log_check_duplicate (EMACS_INT
, EMACS_INT
);
814 static void push_it (struct it
*, struct text_pos
*);
815 static void pop_it (struct it
*);
816 static void sync_frame_with_window_matrix_rows (struct window
*);
817 static void select_frame_for_redisplay (Lisp_Object
);
818 static void redisplay_internal (void);
819 static int echo_area_display (int);
820 static void redisplay_windows (Lisp_Object
);
821 static void redisplay_window (Lisp_Object
, int);
822 static Lisp_Object
redisplay_window_error (Lisp_Object
);
823 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
824 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
825 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
826 struct glyph_matrix
*, EMACS_INT
, EMACS_INT
,
828 static int update_menu_bar (struct frame
*, int, int);
829 static int try_window_reusing_current_matrix (struct window
*);
830 static int try_window_id (struct window
*);
831 static int display_line (struct it
*);
832 static int display_mode_lines (struct window
*);
833 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
834 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
835 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
836 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
837 static void display_menu_bar (struct window
*);
838 static EMACS_INT
display_count_lines (EMACS_INT
, EMACS_INT
, EMACS_INT
,
840 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
841 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int);
842 static void compute_line_metrics (struct it
*);
843 static void run_redisplay_end_trigger_hook (struct it
*);
844 static int get_overlay_strings (struct it
*, EMACS_INT
);
845 static int get_overlay_strings_1 (struct it
*, EMACS_INT
, int);
846 static void next_overlay_string (struct it
*);
847 static void reseat (struct it
*, struct text_pos
, int);
848 static void reseat_1 (struct it
*, struct text_pos
, int);
849 static void back_to_previous_visible_line_start (struct it
*);
850 void reseat_at_previous_visible_line_start (struct it
*);
851 static void reseat_at_next_visible_line_start (struct it
*, int);
852 static int next_element_from_ellipsis (struct it
*);
853 static int next_element_from_display_vector (struct it
*);
854 static int next_element_from_string (struct it
*);
855 static int next_element_from_c_string (struct it
*);
856 static int next_element_from_buffer (struct it
*);
857 static int next_element_from_composition (struct it
*);
858 static int next_element_from_image (struct it
*);
859 static int next_element_from_stretch (struct it
*);
860 static void load_overlay_strings (struct it
*, EMACS_INT
);
861 static int init_from_display_pos (struct it
*, struct window
*,
862 struct display_pos
*);
863 static void reseat_to_string (struct it
*, const char *,
864 Lisp_Object
, EMACS_INT
, EMACS_INT
, int, int);
865 static int get_next_display_element (struct it
*);
866 static enum move_it_result
867 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
868 enum move_operation_enum
);
869 void move_it_vertically_backward (struct it
*, int);
870 static void init_to_row_start (struct it
*, struct window
*,
872 static int init_to_row_end (struct it
*, struct window
*,
874 static void back_to_previous_line_start (struct it
*);
875 static int forward_to_next_line_start (struct it
*, int *);
876 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
877 Lisp_Object
, EMACS_INT
);
878 static struct text_pos
string_pos (EMACS_INT
, Lisp_Object
);
879 static struct text_pos
c_string_pos (EMACS_INT
, const char *, int);
880 static EMACS_INT
number_of_chars (const char *, int);
881 static void compute_stop_pos (struct it
*);
882 static void compute_string_pos (struct text_pos
*, struct text_pos
,
884 static int face_before_or_after_it_pos (struct it
*, int);
885 static EMACS_INT
next_overlay_change (EMACS_INT
);
886 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
887 Lisp_Object
, struct text_pos
*, EMACS_INT
, int);
888 static int handle_single_display_spec (struct it
*, Lisp_Object
,
889 Lisp_Object
, Lisp_Object
,
890 struct text_pos
*, EMACS_INT
, int, int);
891 static int underlying_face_id (struct it
*);
892 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
895 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
896 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
898 #ifdef HAVE_WINDOW_SYSTEM
900 static void x_consider_frame_title (Lisp_Object
);
901 static int tool_bar_lines_needed (struct frame
*, int *);
902 static void update_tool_bar (struct frame
*, int);
903 static void build_desired_tool_bar_string (struct frame
*f
);
904 static int redisplay_tool_bar (struct frame
*);
905 static void display_tool_bar_line (struct it
*, int);
906 static void notice_overwritten_cursor (struct window
*,
909 static void append_stretch_glyph (struct it
*, Lisp_Object
,
913 #endif /* HAVE_WINDOW_SYSTEM */
915 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
916 static int coords_in_mouse_face_p (struct window
*, int, int);
920 /***********************************************************************
921 Window display dimensions
922 ***********************************************************************/
924 /* Return the bottom boundary y-position for text lines in window W.
925 This is the first y position at which a line cannot start.
926 It is relative to the top of the window.
928 This is the height of W minus the height of a mode line, if any. */
931 window_text_bottom_y (struct window
*w
)
933 int height
= WINDOW_TOTAL_HEIGHT (w
);
935 if (WINDOW_WANTS_MODELINE_P (w
))
936 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
940 /* Return the pixel width of display area AREA of window W. AREA < 0
941 means return the total width of W, not including fringes to
942 the left and right of the window. */
945 window_box_width (struct window
*w
, int area
)
947 int cols
= XFASTINT (w
->total_cols
);
950 if (!w
->pseudo_window_p
)
952 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
954 if (area
== TEXT_AREA
)
956 if (INTEGERP (w
->left_margin_cols
))
957 cols
-= XFASTINT (w
->left_margin_cols
);
958 if (INTEGERP (w
->right_margin_cols
))
959 cols
-= XFASTINT (w
->right_margin_cols
);
960 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
962 else if (area
== LEFT_MARGIN_AREA
)
964 cols
= (INTEGERP (w
->left_margin_cols
)
965 ? XFASTINT (w
->left_margin_cols
) : 0);
968 else if (area
== RIGHT_MARGIN_AREA
)
970 cols
= (INTEGERP (w
->right_margin_cols
)
971 ? XFASTINT (w
->right_margin_cols
) : 0);
976 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
980 /* Return the pixel height of the display area of window W, not
981 including mode lines of W, if any. */
984 window_box_height (struct window
*w
)
986 struct frame
*f
= XFRAME (w
->frame
);
987 int height
= WINDOW_TOTAL_HEIGHT (w
);
989 xassert (height
>= 0);
991 /* Note: the code below that determines the mode-line/header-line
992 height is essentially the same as that contained in the macro
993 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
994 the appropriate glyph row has its `mode_line_p' flag set,
995 and if it doesn't, uses estimate_mode_line_height instead. */
997 if (WINDOW_WANTS_MODELINE_P (w
))
999 struct glyph_row
*ml_row
1000 = (w
->current_matrix
&& w
->current_matrix
->rows
1001 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1003 if (ml_row
&& ml_row
->mode_line_p
)
1004 height
-= ml_row
->height
;
1006 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1009 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1011 struct glyph_row
*hl_row
1012 = (w
->current_matrix
&& w
->current_matrix
->rows
1013 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1015 if (hl_row
&& hl_row
->mode_line_p
)
1016 height
-= hl_row
->height
;
1018 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1021 /* With a very small font and a mode-line that's taller than
1022 default, we might end up with a negative height. */
1023 return max (0, height
);
1026 /* Return the window-relative coordinate of the left edge of display
1027 area AREA of window W. AREA < 0 means return the left edge of the
1028 whole window, to the right of the left fringe of W. */
1031 window_box_left_offset (struct window
*w
, int area
)
1035 if (w
->pseudo_window_p
)
1038 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1040 if (area
== TEXT_AREA
)
1041 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1042 + window_box_width (w
, LEFT_MARGIN_AREA
));
1043 else if (area
== RIGHT_MARGIN_AREA
)
1044 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1045 + window_box_width (w
, LEFT_MARGIN_AREA
)
1046 + window_box_width (w
, TEXT_AREA
)
1047 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1049 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1050 else if (area
== LEFT_MARGIN_AREA
1051 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1052 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1058 /* Return the window-relative coordinate of the right edge of display
1059 area AREA of window W. AREA < 0 means return the right edge of the
1060 whole window, to the left of the right fringe of W. */
1063 window_box_right_offset (struct window
*w
, int area
)
1065 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1068 /* Return the frame-relative coordinate of the left edge of display
1069 area AREA of window W. AREA < 0 means return the left edge of the
1070 whole window, to the right of the left fringe of W. */
1073 window_box_left (struct window
*w
, int area
)
1075 struct frame
*f
= XFRAME (w
->frame
);
1078 if (w
->pseudo_window_p
)
1079 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1081 x
= (WINDOW_LEFT_EDGE_X (w
)
1082 + window_box_left_offset (w
, area
));
1088 /* Return the frame-relative coordinate of the right edge of display
1089 area AREA of window W. AREA < 0 means return the right edge of the
1090 whole window, to the left of the right fringe of W. */
1093 window_box_right (struct window
*w
, int area
)
1095 return window_box_left (w
, area
) + window_box_width (w
, area
);
1098 /* Get the bounding box of the display area AREA of window W, without
1099 mode lines, in frame-relative coordinates. AREA < 0 means the
1100 whole window, not including the left and right fringes of
1101 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1102 coordinates of the upper-left corner of the box. Return in
1103 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1106 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1107 int *box_width
, int *box_height
)
1110 *box_width
= window_box_width (w
, area
);
1112 *box_height
= window_box_height (w
);
1114 *box_x
= window_box_left (w
, area
);
1117 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1118 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1119 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1124 /* Get the bounding box of the display area AREA of window W, without
1125 mode lines. AREA < 0 means the whole window, not including the
1126 left and right fringe of the window. Return in *TOP_LEFT_X
1127 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1128 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1129 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1133 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1134 int *bottom_right_x
, int *bottom_right_y
)
1136 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1138 *bottom_right_x
+= *top_left_x
;
1139 *bottom_right_y
+= *top_left_y
;
1144 /***********************************************************************
1146 ***********************************************************************/
1148 /* Return the bottom y-position of the line the iterator IT is in.
1149 This can modify IT's settings. */
1152 line_bottom_y (struct it
*it
)
1154 int line_height
= it
->max_ascent
+ it
->max_descent
;
1155 int line_top_y
= it
->current_y
;
1157 if (line_height
== 0)
1160 line_height
= last_height
;
1161 else if (IT_CHARPOS (*it
) < ZV
)
1163 move_it_by_lines (it
, 1);
1164 line_height
= (it
->max_ascent
|| it
->max_descent
1165 ? it
->max_ascent
+ it
->max_descent
1170 struct glyph_row
*row
= it
->glyph_row
;
1172 /* Use the default character height. */
1173 it
->glyph_row
= NULL
;
1174 it
->what
= IT_CHARACTER
;
1177 PRODUCE_GLYPHS (it
);
1178 line_height
= it
->ascent
+ it
->descent
;
1179 it
->glyph_row
= row
;
1183 return line_top_y
+ line_height
;
1187 /* Return 1 if position CHARPOS is visible in window W.
1188 CHARPOS < 0 means return info about WINDOW_END position.
1189 If visible, set *X and *Y to pixel coordinates of top left corner.
1190 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1191 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1194 pos_visible_p (struct window
*w
, EMACS_INT charpos
, int *x
, int *y
,
1195 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1198 struct text_pos top
;
1200 struct buffer
*old_buffer
= NULL
;
1202 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1205 if (XBUFFER (w
->buffer
) != current_buffer
)
1207 old_buffer
= current_buffer
;
1208 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1211 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1213 /* Compute exact mode line heights. */
1214 if (WINDOW_WANTS_MODELINE_P (w
))
1215 current_mode_line_height
1216 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1217 BVAR (current_buffer
, mode_line_format
));
1219 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1220 current_header_line_height
1221 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1222 BVAR (current_buffer
, header_line_format
));
1224 start_display (&it
, w
, top
);
1225 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1226 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1228 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1230 /* We have reached CHARPOS, or passed it. How the call to
1231 move_it_to can overshoot: (i) If CHARPOS is on invisible
1232 text, move_it_to stops at the end of the invisible text,
1233 after CHARPOS. (ii) If CHARPOS is in a display vector,
1234 move_it_to stops on its last glyph. */
1235 int top_x
= it
.current_x
;
1236 int top_y
= it
.current_y
;
1237 enum it_method it_method
= it
.method
;
1238 /* Calling line_bottom_y may change it.method, it.position, etc. */
1239 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1240 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1242 if (top_y
< window_top_y
)
1243 visible_p
= bottom_y
> window_top_y
;
1244 else if (top_y
< it
.last_visible_y
)
1248 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1250 /* We stopped on the last glyph of a display vector.
1251 Try and recompute. Hack alert! */
1252 if (charpos
< 2 || top
.charpos
>= charpos
)
1253 top_x
= it
.glyph_row
->x
;
1257 start_display (&it2
, w
, top
);
1258 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1259 get_next_display_element (&it2
);
1260 PRODUCE_GLYPHS (&it2
);
1261 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1262 || it2
.current_x
> it2
.last_visible_x
)
1263 top_x
= it
.glyph_row
->x
;
1266 top_x
= it2
.current_x
;
1267 top_y
= it2
.current_y
;
1273 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1274 *rtop
= max (0, window_top_y
- top_y
);
1275 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1276 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1277 - max (top_y
, window_top_y
)));
1286 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1287 move_it_by_lines (&it
, 1);
1288 if (charpos
< IT_CHARPOS (it
)
1289 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1292 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1294 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1295 *rtop
= max (0, -it2
.current_y
);
1296 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1297 - it
.last_visible_y
));
1298 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1300 - max (it2
.current_y
,
1301 WINDOW_HEADER_LINE_HEIGHT (w
))));
1307 set_buffer_internal_1 (old_buffer
);
1309 current_header_line_height
= current_mode_line_height
= -1;
1311 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1312 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1315 /* Debugging code. */
1317 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1318 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1320 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1327 /* Return the next character from STR. Return in *LEN the length of
1328 the character. This is like STRING_CHAR_AND_LENGTH but never
1329 returns an invalid character. If we find one, we return a `?', but
1330 with the length of the invalid character. */
1333 string_char_and_length (const unsigned char *str
, int *len
)
1337 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1338 if (!CHAR_VALID_P (c
))
1339 /* We may not change the length here because other places in Emacs
1340 don't use this function, i.e. they silently accept invalid
1349 /* Given a position POS containing a valid character and byte position
1350 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1352 static struct text_pos
1353 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, EMACS_INT nchars
)
1355 xassert (STRINGP (string
) && nchars
>= 0);
1357 if (STRING_MULTIBYTE (string
))
1359 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1364 string_char_and_length (p
, &len
);
1367 BYTEPOS (pos
) += len
;
1371 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1377 /* Value is the text position, i.e. character and byte position,
1378 for character position CHARPOS in STRING. */
1380 static inline struct text_pos
1381 string_pos (EMACS_INT charpos
, Lisp_Object string
)
1383 struct text_pos pos
;
1384 xassert (STRINGP (string
));
1385 xassert (charpos
>= 0);
1386 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1391 /* Value is a text position, i.e. character and byte position, for
1392 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1393 means recognize multibyte characters. */
1395 static struct text_pos
1396 c_string_pos (EMACS_INT charpos
, const char *s
, int multibyte_p
)
1398 struct text_pos pos
;
1400 xassert (s
!= NULL
);
1401 xassert (charpos
>= 0);
1407 SET_TEXT_POS (pos
, 0, 0);
1410 string_char_and_length ((const unsigned char *) s
, &len
);
1413 BYTEPOS (pos
) += len
;
1417 SET_TEXT_POS (pos
, charpos
, charpos
);
1423 /* Value is the number of characters in C string S. MULTIBYTE_P
1424 non-zero means recognize multibyte characters. */
1427 number_of_chars (const char *s
, int multibyte_p
)
1433 EMACS_INT rest
= strlen (s
);
1435 const unsigned char *p
= (const unsigned char *) s
;
1437 for (nchars
= 0; rest
> 0; ++nchars
)
1439 string_char_and_length (p
, &len
);
1440 rest
-= len
, p
+= len
;
1444 nchars
= strlen (s
);
1450 /* Compute byte position NEWPOS->bytepos corresponding to
1451 NEWPOS->charpos. POS is a known position in string STRING.
1452 NEWPOS->charpos must be >= POS.charpos. */
1455 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1457 xassert (STRINGP (string
));
1458 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1460 if (STRING_MULTIBYTE (string
))
1461 *newpos
= string_pos_nchars_ahead (pos
, string
,
1462 CHARPOS (*newpos
) - CHARPOS (pos
));
1464 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1468 Return an estimation of the pixel height of mode or header lines on
1469 frame F. FACE_ID specifies what line's height to estimate. */
1472 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1474 #ifdef HAVE_WINDOW_SYSTEM
1475 if (FRAME_WINDOW_P (f
))
1477 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1479 /* This function is called so early when Emacs starts that the face
1480 cache and mode line face are not yet initialized. */
1481 if (FRAME_FACE_CACHE (f
))
1483 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1487 height
= FONT_HEIGHT (face
->font
);
1488 if (face
->box_line_width
> 0)
1489 height
+= 2 * face
->box_line_width
;
1500 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1501 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1502 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1503 not force the value into range. */
1506 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1507 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1510 #ifdef HAVE_WINDOW_SYSTEM
1511 if (FRAME_WINDOW_P (f
))
1513 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1514 even for negative values. */
1516 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1518 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1520 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1521 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1524 STORE_NATIVE_RECT (*bounds
,
1525 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1526 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1527 FRAME_COLUMN_WIDTH (f
) - 1,
1528 FRAME_LINE_HEIGHT (f
) - 1);
1534 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1535 pix_x
= FRAME_TOTAL_COLS (f
);
1539 else if (pix_y
> FRAME_LINES (f
))
1540 pix_y
= FRAME_LINES (f
);
1550 /* Find the glyph under window-relative coordinates X/Y in window W.
1551 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1552 strings. Return in *HPOS and *VPOS the row and column number of
1553 the glyph found. Return in *AREA the glyph area containing X.
1554 Value is a pointer to the glyph found or null if X/Y is not on
1555 text, or we can't tell because W's current matrix is not up to
1560 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1561 int *dx
, int *dy
, int *area
)
1563 struct glyph
*glyph
, *end
;
1564 struct glyph_row
*row
= NULL
;
1567 /* Find row containing Y. Give up if some row is not enabled. */
1568 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1570 row
= MATRIX_ROW (w
->current_matrix
, i
);
1571 if (!row
->enabled_p
)
1573 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1580 /* Give up if Y is not in the window. */
1581 if (i
== w
->current_matrix
->nrows
)
1584 /* Get the glyph area containing X. */
1585 if (w
->pseudo_window_p
)
1592 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1594 *area
= LEFT_MARGIN_AREA
;
1595 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1597 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1600 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1604 *area
= RIGHT_MARGIN_AREA
;
1605 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1609 /* Find glyph containing X. */
1610 glyph
= row
->glyphs
[*area
];
1611 end
= glyph
+ row
->used
[*area
];
1613 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1615 x
-= glyph
->pixel_width
;
1625 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1628 *hpos
= glyph
- row
->glyphs
[*area
];
1632 /* Convert frame-relative x/y to coordinates relative to window W.
1633 Takes pseudo-windows into account. */
1636 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1638 if (w
->pseudo_window_p
)
1640 /* A pseudo-window is always full-width, and starts at the
1641 left edge of the frame, plus a frame border. */
1642 struct frame
*f
= XFRAME (w
->frame
);
1643 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1644 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1648 *x
-= WINDOW_LEFT_EDGE_X (w
);
1649 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1653 #ifdef HAVE_WINDOW_SYSTEM
1656 Return in RECTS[] at most N clipping rectangles for glyph string S.
1657 Return the number of stored rectangles. */
1660 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1667 if (s
->row
->full_width_p
)
1669 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1670 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1671 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1673 /* Unless displaying a mode or menu bar line, which are always
1674 fully visible, clip to the visible part of the row. */
1675 if (s
->w
->pseudo_window_p
)
1676 r
.height
= s
->row
->visible_height
;
1678 r
.height
= s
->height
;
1682 /* This is a text line that may be partially visible. */
1683 r
.x
= window_box_left (s
->w
, s
->area
);
1684 r
.width
= window_box_width (s
->w
, s
->area
);
1685 r
.height
= s
->row
->visible_height
;
1689 if (r
.x
< s
->clip_head
->x
)
1691 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1692 r
.width
-= s
->clip_head
->x
- r
.x
;
1695 r
.x
= s
->clip_head
->x
;
1698 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1700 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1701 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1706 /* If S draws overlapping rows, it's sufficient to use the top and
1707 bottom of the window for clipping because this glyph string
1708 intentionally draws over other lines. */
1709 if (s
->for_overlaps
)
1711 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1712 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1714 /* Alas, the above simple strategy does not work for the
1715 environments with anti-aliased text: if the same text is
1716 drawn onto the same place multiple times, it gets thicker.
1717 If the overlap we are processing is for the erased cursor, we
1718 take the intersection with the rectagle of the cursor. */
1719 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1721 XRectangle rc
, r_save
= r
;
1723 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1724 rc
.y
= s
->w
->phys_cursor
.y
;
1725 rc
.width
= s
->w
->phys_cursor_width
;
1726 rc
.height
= s
->w
->phys_cursor_height
;
1728 x_intersect_rectangles (&r_save
, &rc
, &r
);
1733 /* Don't use S->y for clipping because it doesn't take partially
1734 visible lines into account. For example, it can be negative for
1735 partially visible lines at the top of a window. */
1736 if (!s
->row
->full_width_p
1737 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1738 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1740 r
.y
= max (0, s
->row
->y
);
1743 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1745 /* If drawing the cursor, don't let glyph draw outside its
1746 advertised boundaries. Cleartype does this under some circumstances. */
1747 if (s
->hl
== DRAW_CURSOR
)
1749 struct glyph
*glyph
= s
->first_glyph
;
1754 r
.width
-= s
->x
- r
.x
;
1757 r
.width
= min (r
.width
, glyph
->pixel_width
);
1759 /* If r.y is below window bottom, ensure that we still see a cursor. */
1760 height
= min (glyph
->ascent
+ glyph
->descent
,
1761 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1762 max_y
= window_text_bottom_y (s
->w
) - height
;
1763 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1764 if (s
->ybase
- glyph
->ascent
> max_y
)
1771 /* Don't draw cursor glyph taller than our actual glyph. */
1772 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1773 if (height
< r
.height
)
1775 max_y
= r
.y
+ r
.height
;
1776 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1777 r
.height
= min (max_y
- r
.y
, height
);
1784 XRectangle r_save
= r
;
1786 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
1790 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1791 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1793 #ifdef CONVERT_FROM_XRECT
1794 CONVERT_FROM_XRECT (r
, *rects
);
1802 /* If we are processing overlapping and allowed to return
1803 multiple clipping rectangles, we exclude the row of the glyph
1804 string from the clipping rectangle. This is to avoid drawing
1805 the same text on the environment with anti-aliasing. */
1806 #ifdef CONVERT_FROM_XRECT
1809 XRectangle
*rs
= rects
;
1811 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1813 if (s
->for_overlaps
& OVERLAPS_PRED
)
1816 if (r
.y
+ r
.height
> row_y
)
1819 rs
[i
].height
= row_y
- r
.y
;
1825 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1828 if (r
.y
< row_y
+ s
->row
->visible_height
)
1830 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1832 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1833 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1842 #ifdef CONVERT_FROM_XRECT
1843 for (i
= 0; i
< n
; i
++)
1844 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1851 Return in *NR the clipping rectangle for glyph string S. */
1854 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
1856 get_glyph_string_clip_rects (s
, nr
, 1);
1861 Return the position and height of the phys cursor in window W.
1862 Set w->phys_cursor_width to width of phys cursor.
1866 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
1867 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
1869 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1870 int x
, y
, wd
, h
, h0
, y0
;
1872 /* Compute the width of the rectangle to draw. If on a stretch
1873 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1874 rectangle as wide as the glyph, but use a canonical character
1876 wd
= glyph
->pixel_width
- 1;
1877 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
1881 x
= w
->phys_cursor
.x
;
1888 if (glyph
->type
== STRETCH_GLYPH
1889 && !x_stretch_cursor_p
)
1890 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
1891 w
->phys_cursor_width
= wd
;
1893 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
1895 /* If y is below window bottom, ensure that we still see a cursor. */
1896 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
1898 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
1899 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
1901 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
1904 h
= max (h
- (y0
- y
) + 1, h0
);
1909 y0
= window_text_bottom_y (w
) - h0
;
1917 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
1918 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
1923 * Remember which glyph the mouse is over.
1927 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
1931 struct glyph_row
*r
, *gr
, *end_row
;
1932 enum window_part part
;
1933 enum glyph_row_area area
;
1934 int x
, y
, width
, height
;
1936 /* Try to determine frame pixel position and size of the glyph under
1937 frame pixel coordinates X/Y on frame F. */
1939 if (!f
->glyphs_initialized_p
1940 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
1943 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
1944 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
1948 w
= XWINDOW (window
);
1949 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
1950 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
1952 x
= window_relative_x_coord (w
, part
, gx
);
1953 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
1955 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1956 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1958 if (w
->pseudo_window_p
)
1961 part
= ON_MODE_LINE
; /* Don't adjust margin. */
1967 case ON_LEFT_MARGIN
:
1968 area
= LEFT_MARGIN_AREA
;
1971 case ON_RIGHT_MARGIN
:
1972 area
= RIGHT_MARGIN_AREA
;
1975 case ON_HEADER_LINE
:
1977 gr
= (part
== ON_HEADER_LINE
1978 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1979 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
1982 goto text_glyph_row_found
;
1989 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
1990 if (r
->y
+ r
->height
> y
)
1996 text_glyph_row_found
:
1999 struct glyph
*g
= gr
->glyphs
[area
];
2000 struct glyph
*end
= g
+ gr
->used
[area
];
2002 height
= gr
->height
;
2003 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2004 if (gx
+ g
->pixel_width
> x
)
2009 if (g
->type
== IMAGE_GLYPH
)
2011 /* Don't remember when mouse is over image, as
2012 image may have hot-spots. */
2013 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2016 width
= g
->pixel_width
;
2020 /* Use nominal char spacing at end of line. */
2022 gx
+= (x
/ width
) * width
;
2025 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2026 gx
+= window_box_left_offset (w
, area
);
2030 /* Use nominal line height at end of window. */
2031 gx
= (x
/ width
) * width
;
2033 gy
+= (y
/ height
) * height
;
2037 case ON_LEFT_FRINGE
:
2038 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2039 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2040 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2041 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2044 case ON_RIGHT_FRINGE
:
2045 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2046 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2047 : window_box_right_offset (w
, TEXT_AREA
));
2048 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2052 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2054 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2055 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2056 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2058 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2062 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2063 if (r
->y
+ r
->height
> y
)
2070 height
= gr
->height
;
2073 /* Use nominal line height at end of window. */
2075 gy
+= (y
/ height
) * height
;
2082 /* If there is no glyph under the mouse, then we divide the screen
2083 into a grid of the smallest glyph in the frame, and use that
2086 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2087 round down even for negative values. */
2093 gx
= (gx
/ width
) * width
;
2094 gy
= (gy
/ height
) * height
;
2099 gx
+= WINDOW_LEFT_EDGE_X (w
);
2100 gy
+= WINDOW_TOP_EDGE_Y (w
);
2103 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2105 /* Visible feedback for debugging. */
2108 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2109 f
->output_data
.x
->normal_gc
,
2110 gx
, gy
, width
, height
);
2116 #endif /* HAVE_WINDOW_SYSTEM */
2119 /***********************************************************************
2120 Lisp form evaluation
2121 ***********************************************************************/
2123 /* Error handler for safe_eval and safe_call. */
2126 safe_eval_handler (Lisp_Object arg
)
2128 add_to_log ("Error during redisplay: %S", arg
, Qnil
);
2133 /* Evaluate SEXPR and return the result, or nil if something went
2134 wrong. Prevent redisplay during the evaluation. */
2136 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2137 Return the result, or nil if something went wrong. Prevent
2138 redisplay during the evaluation. */
2141 safe_call (ptrdiff_t nargs
, Lisp_Object
*args
)
2145 if (inhibit_eval_during_redisplay
)
2149 int count
= SPECPDL_INDEX ();
2150 struct gcpro gcpro1
;
2153 gcpro1
.nvars
= nargs
;
2154 specbind (Qinhibit_redisplay
, Qt
);
2155 /* Use Qt to ensure debugger does not run,
2156 so there is no possibility of wanting to redisplay. */
2157 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2160 val
= unbind_to (count
, val
);
2167 /* Call function FN with one argument ARG.
2168 Return the result, or nil if something went wrong. */
2171 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2173 Lisp_Object args
[2];
2176 return safe_call (2, args
);
2179 static Lisp_Object Qeval
;
2182 safe_eval (Lisp_Object sexpr
)
2184 return safe_call1 (Qeval
, sexpr
);
2187 /* Call function FN with one argument ARG.
2188 Return the result, or nil if something went wrong. */
2191 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2193 Lisp_Object args
[3];
2197 return safe_call (3, args
);
2202 /***********************************************************************
2204 ***********************************************************************/
2208 /* Define CHECK_IT to perform sanity checks on iterators.
2209 This is for debugging. It is too slow to do unconditionally. */
2212 check_it (struct it
*it
)
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
2244 #if GLYPH_DEBUG && XASSERTS
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 (struct window
*w
)
2252 if (!MINI_WINDOW_P (w
)
2253 && !NILP (w
->window_end_valid
))
2255 struct glyph_row
*row
;
2256 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2257 XFASTINT (w
->window_end_vpos
)),
2259 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2260 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2264 #define CHECK_WINDOW_END(W) check_window_end ((W))
2268 #define CHECK_WINDOW_END(W) (void) 0
2274 /***********************************************************************
2275 Iterator initialization
2276 ***********************************************************************/
2278 /* Initialize IT for displaying current_buffer in window W, starting
2279 at character position CHARPOS. CHARPOS < 0 means that no buffer
2280 position is specified which is useful when the iterator is assigned
2281 a position later. BYTEPOS is the byte position corresponding to
2282 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2284 If ROW is not null, calls to produce_glyphs with IT as parameter
2285 will produce glyphs in that row.
2287 BASE_FACE_ID is the id of a base face to use. It must be one of
2288 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2289 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2290 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2292 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2293 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2294 will be initialized to use the corresponding mode line glyph row of
2295 the desired matrix of W. */
2298 init_iterator (struct it
*it
, struct window
*w
,
2299 EMACS_INT charpos
, EMACS_INT bytepos
,
2300 struct glyph_row
*row
, enum face_id base_face_id
)
2302 int highlight_region_p
;
2303 enum face_id remapped_base_face_id
= base_face_id
;
2305 /* Some precondition checks. */
2306 xassert (w
!= NULL
&& it
!= NULL
);
2307 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2310 /* If face attributes have been changed since the last redisplay,
2311 free realized faces now because they depend on face definitions
2312 that might have changed. Don't free faces while there might be
2313 desired matrices pending which reference these faces. */
2314 if (face_change_count
&& !inhibit_free_realized_faces
)
2316 face_change_count
= 0;
2317 free_all_realized_faces (Qnil
);
2320 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2321 if (! NILP (Vface_remapping_alist
))
2322 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2324 /* Use one of the mode line rows of W's desired matrix if
2328 if (base_face_id
== MODE_LINE_FACE_ID
2329 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2330 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2331 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2332 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2336 memset (it
, 0, sizeof *it
);
2337 it
->current
.overlay_string_index
= -1;
2338 it
->current
.dpvec_index
= -1;
2339 it
->base_face_id
= remapped_base_face_id
;
2341 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2343 /* The window in which we iterate over current_buffer: */
2344 XSETWINDOW (it
->window
, w
);
2346 it
->f
= XFRAME (w
->frame
);
2350 /* Extra space between lines (on window systems only). */
2351 if (base_face_id
== DEFAULT_FACE_ID
2352 && FRAME_WINDOW_P (it
->f
))
2354 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2355 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2356 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2357 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2358 * FRAME_LINE_HEIGHT (it
->f
));
2359 else if (it
->f
->extra_line_spacing
> 0)
2360 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2361 it
->max_extra_line_spacing
= 0;
2364 /* If realized faces have been removed, e.g. because of face
2365 attribute changes of named faces, recompute them. When running
2366 in batch mode, the face cache of the initial frame is null. If
2367 we happen to get called, make a dummy face cache. */
2368 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2369 init_frame_faces (it
->f
);
2370 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2371 recompute_basic_faces (it
->f
);
2373 /* Current value of the `slice', `space-width', and 'height' properties. */
2374 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2375 it
->space_width
= Qnil
;
2376 it
->font_height
= Qnil
;
2377 it
->override_ascent
= -1;
2379 /* Are control characters displayed as `^C'? */
2380 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2382 /* -1 means everything between a CR and the following line end
2383 is invisible. >0 means lines indented more than this value are
2385 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2386 ? XINT (BVAR (current_buffer
, selective_display
))
2387 : (!NILP (BVAR (current_buffer
, selective_display
))
2389 it
->selective_display_ellipsis_p
2390 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2392 /* Display table to use. */
2393 it
->dp
= window_display_table (w
);
2395 /* Are multibyte characters enabled in current_buffer? */
2396 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2398 /* Do we need to reorder bidirectional text? Not if this is a
2399 unibyte buffer: by definition, none of the single-byte characters
2400 are strong R2L, so no reordering is needed. And bidi.c doesn't
2401 support unibyte buffers anyway. */
2403 = !NILP (BVAR (current_buffer
, bidi_display_reordering
)) && it
->multibyte_p
;
2405 /* Non-zero if we should highlight the region. */
2407 = (!NILP (Vtransient_mark_mode
)
2408 && !NILP (BVAR (current_buffer
, mark_active
))
2409 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= 0);
2411 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2412 start and end of a visible region in window IT->w. Set both to
2413 -1 to indicate no region. */
2414 if (highlight_region_p
2415 /* Maybe highlight only in selected window. */
2416 && (/* Either show region everywhere. */
2417 highlight_nonselected_windows
2418 /* Or show region in the selected window. */
2419 || w
== XWINDOW (selected_window
)
2420 /* Or show the region if we are in the mini-buffer and W is
2421 the window the mini-buffer refers to. */
2422 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2423 && WINDOWP (minibuf_selected_window
)
2424 && w
== XWINDOW (minibuf_selected_window
))))
2426 EMACS_INT markpos
= marker_position (BVAR (current_buffer
, mark
));
2427 it
->region_beg_charpos
= min (PT
, markpos
);
2428 it
->region_end_charpos
= max (PT
, markpos
);
2431 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2433 /* Get the position at which the redisplay_end_trigger hook should
2434 be run, if it is to be run at all. */
2435 if (MARKERP (w
->redisplay_end_trigger
)
2436 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2437 it
->redisplay_end_trigger_charpos
2438 = marker_position (w
->redisplay_end_trigger
);
2439 else if (INTEGERP (w
->redisplay_end_trigger
))
2440 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2442 /* Correct bogus values of tab_width. */
2443 it
->tab_width
= XINT (BVAR (current_buffer
, tab_width
));
2444 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2447 /* Are lines in the display truncated? */
2448 if (base_face_id
!= DEFAULT_FACE_ID
2449 || XINT (it
->w
->hscroll
)
2450 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2451 && ((!NILP (Vtruncate_partial_width_windows
)
2452 && !INTEGERP (Vtruncate_partial_width_windows
))
2453 || (INTEGERP (Vtruncate_partial_width_windows
)
2454 && (WINDOW_TOTAL_COLS (it
->w
)
2455 < XINT (Vtruncate_partial_width_windows
))))))
2456 it
->line_wrap
= TRUNCATE
;
2457 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2458 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2459 ? WINDOW_WRAP
: WORD_WRAP
;
2461 it
->line_wrap
= TRUNCATE
;
2463 /* Get dimensions of truncation and continuation glyphs. These are
2464 displayed as fringe bitmaps under X, so we don't need them for such
2466 if (!FRAME_WINDOW_P (it
->f
))
2468 if (it
->line_wrap
== TRUNCATE
)
2470 /* We will need the truncation glyph. */
2471 xassert (it
->glyph_row
== NULL
);
2472 produce_special_glyphs (it
, IT_TRUNCATION
);
2473 it
->truncation_pixel_width
= it
->pixel_width
;
2477 /* We will need the continuation glyph. */
2478 xassert (it
->glyph_row
== NULL
);
2479 produce_special_glyphs (it
, IT_CONTINUATION
);
2480 it
->continuation_pixel_width
= it
->pixel_width
;
2483 /* Reset these values to zero because the produce_special_glyphs
2484 above has changed them. */
2485 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2486 it
->phys_ascent
= it
->phys_descent
= 0;
2489 /* Set this after getting the dimensions of truncation and
2490 continuation glyphs, so that we don't produce glyphs when calling
2491 produce_special_glyphs, above. */
2492 it
->glyph_row
= row
;
2493 it
->area
= TEXT_AREA
;
2495 /* Forget any previous info about this row being reversed. */
2497 it
->glyph_row
->reversed_p
= 0;
2499 /* Get the dimensions of the display area. The display area
2500 consists of the visible window area plus a horizontally scrolled
2501 part to the left of the window. All x-values are relative to the
2502 start of this total display area. */
2503 if (base_face_id
!= DEFAULT_FACE_ID
)
2505 /* Mode lines, menu bar in terminal frames. */
2506 it
->first_visible_x
= 0;
2507 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2512 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2513 it
->last_visible_x
= (it
->first_visible_x
2514 + window_box_width (w
, TEXT_AREA
));
2516 /* If we truncate lines, leave room for the truncator glyph(s) at
2517 the right margin. Otherwise, leave room for the continuation
2518 glyph(s). Truncation and continuation glyphs are not inserted
2519 for window-based redisplay. */
2520 if (!FRAME_WINDOW_P (it
->f
))
2522 if (it
->line_wrap
== TRUNCATE
)
2523 it
->last_visible_x
-= it
->truncation_pixel_width
;
2525 it
->last_visible_x
-= it
->continuation_pixel_width
;
2528 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2529 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2532 /* Leave room for a border glyph. */
2533 if (!FRAME_WINDOW_P (it
->f
)
2534 && !WINDOW_RIGHTMOST_P (it
->w
))
2535 it
->last_visible_x
-= 1;
2537 it
->last_visible_y
= window_text_bottom_y (w
);
2539 /* For mode lines and alike, arrange for the first glyph having a
2540 left box line if the face specifies a box. */
2541 if (base_face_id
!= DEFAULT_FACE_ID
)
2545 it
->face_id
= remapped_base_face_id
;
2547 /* If we have a boxed mode line, make the first character appear
2548 with a left box line. */
2549 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2550 if (face
->box
!= FACE_NO_BOX
)
2551 it
->start_of_box_run_p
= 1;
2554 /* If we are to reorder bidirectional text, init the bidi
2558 /* Note the paragraph direction that this buffer wants to
2560 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
), Qleft_to_right
))
2561 it
->paragraph_embedding
= L2R
;
2562 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
), Qright_to_left
))
2563 it
->paragraph_embedding
= R2L
;
2565 it
->paragraph_embedding
= NEUTRAL_DIR
;
2566 bidi_init_it (charpos
, bytepos
, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
2569 /* If a buffer position was specified, set the iterator there,
2570 getting overlays and face properties from that position. */
2571 if (charpos
>= BUF_BEG (current_buffer
))
2573 it
->end_charpos
= ZV
;
2575 IT_CHARPOS (*it
) = charpos
;
2577 /* Compute byte position if not specified. */
2578 if (bytepos
< charpos
)
2579 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2581 IT_BYTEPOS (*it
) = bytepos
;
2583 it
->start
= it
->current
;
2585 /* Compute faces etc. */
2586 reseat (it
, it
->current
.pos
, 1);
2593 /* Initialize IT for the display of window W with window start POS. */
2596 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2598 struct glyph_row
*row
;
2599 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2601 row
= w
->desired_matrix
->rows
+ first_vpos
;
2602 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2603 it
->first_vpos
= first_vpos
;
2605 /* Don't reseat to previous visible line start if current start
2606 position is in a string or image. */
2607 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2609 int start_at_line_beg_p
;
2610 int first_y
= it
->current_y
;
2612 /* If window start is not at a line start, skip forward to POS to
2613 get the correct continuation lines width. */
2614 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2615 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2616 if (!start_at_line_beg_p
)
2620 reseat_at_previous_visible_line_start (it
);
2621 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2623 new_x
= it
->current_x
+ it
->pixel_width
;
2625 /* If lines are continued, this line may end in the middle
2626 of a multi-glyph character (e.g. a control character
2627 displayed as \003, or in the middle of an overlay
2628 string). In this case move_it_to above will not have
2629 taken us to the start of the continuation line but to the
2630 end of the continued line. */
2631 if (it
->current_x
> 0
2632 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2633 && (/* And glyph doesn't fit on the line. */
2634 new_x
> it
->last_visible_x
2635 /* Or it fits exactly and we're on a window
2637 || (new_x
== it
->last_visible_x
2638 && FRAME_WINDOW_P (it
->f
))))
2640 if (it
->current
.dpvec_index
>= 0
2641 || it
->current
.overlay_string_index
>= 0)
2643 set_iterator_to_next (it
, 1);
2644 move_it_in_display_line_to (it
, -1, -1, 0);
2647 it
->continuation_lines_width
+= it
->current_x
;
2650 /* We're starting a new display line, not affected by the
2651 height of the continued line, so clear the appropriate
2652 fields in the iterator structure. */
2653 it
->max_ascent
= it
->max_descent
= 0;
2654 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2656 it
->current_y
= first_y
;
2658 it
->current_x
= it
->hpos
= 0;
2664 /* Return 1 if POS is a position in ellipses displayed for invisible
2665 text. W is the window we display, for text property lookup. */
2668 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2670 Lisp_Object prop
, window
;
2672 EMACS_INT charpos
= CHARPOS (pos
->pos
);
2674 /* If POS specifies a position in a display vector, this might
2675 be for an ellipsis displayed for invisible text. We won't
2676 get the iterator set up for delivering that ellipsis unless
2677 we make sure that it gets aware of the invisible text. */
2678 if (pos
->dpvec_index
>= 0
2679 && pos
->overlay_string_index
< 0
2680 && CHARPOS (pos
->string_pos
) < 0
2682 && (XSETWINDOW (window
, w
),
2683 prop
= Fget_char_property (make_number (charpos
),
2684 Qinvisible
, window
),
2685 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2687 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2689 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2696 /* Initialize IT for stepping through current_buffer in window W,
2697 starting at position POS that includes overlay string and display
2698 vector/ control character translation position information. Value
2699 is zero if there are overlay strings with newlines at POS. */
2702 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
2704 EMACS_INT charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2705 int i
, overlay_strings_with_newlines
= 0;
2707 /* If POS specifies a position in a display vector, this might
2708 be for an ellipsis displayed for invisible text. We won't
2709 get the iterator set up for delivering that ellipsis unless
2710 we make sure that it gets aware of the invisible text. */
2711 if (in_ellipses_for_invisible_text_p (pos
, w
))
2717 /* Keep in mind: the call to reseat in init_iterator skips invisible
2718 text, so we might end up at a position different from POS. This
2719 is only a problem when POS is a row start after a newline and an
2720 overlay starts there with an after-string, and the overlay has an
2721 invisible property. Since we don't skip invisible text in
2722 display_line and elsewhere immediately after consuming the
2723 newline before the row start, such a POS will not be in a string,
2724 but the call to init_iterator below will move us to the
2726 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2728 /* This only scans the current chunk -- it should scan all chunks.
2729 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2730 to 16 in 22.1 to make this a lesser problem. */
2731 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2733 const char *s
= SSDATA (it
->overlay_strings
[i
]);
2734 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2736 while (s
< e
&& *s
!= '\n')
2741 overlay_strings_with_newlines
= 1;
2746 /* If position is within an overlay string, set up IT to the right
2748 if (pos
->overlay_string_index
>= 0)
2752 /* If the first overlay string happens to have a `display'
2753 property for an image, the iterator will be set up for that
2754 image, and we have to undo that setup first before we can
2755 correct the overlay string index. */
2756 if (it
->method
== GET_FROM_IMAGE
)
2759 /* We already have the first chunk of overlay strings in
2760 IT->overlay_strings. Load more until the one for
2761 pos->overlay_string_index is in IT->overlay_strings. */
2762 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2764 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2765 it
->current
.overlay_string_index
= 0;
2768 load_overlay_strings (it
, 0);
2769 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2773 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2774 relative_index
= (it
->current
.overlay_string_index
2775 % OVERLAY_STRING_CHUNK_SIZE
);
2776 it
->string
= it
->overlay_strings
[relative_index
];
2777 xassert (STRINGP (it
->string
));
2778 it
->current
.string_pos
= pos
->string_pos
;
2779 it
->method
= GET_FROM_STRING
;
2782 if (CHARPOS (pos
->string_pos
) >= 0)
2784 /* Recorded position is not in an overlay string, but in another
2785 string. This can only be a string from a `display' property.
2786 IT should already be filled with that string. */
2787 it
->current
.string_pos
= pos
->string_pos
;
2788 xassert (STRINGP (it
->string
));
2791 /* Restore position in display vector translations, control
2792 character translations or ellipses. */
2793 if (pos
->dpvec_index
>= 0)
2795 if (it
->dpvec
== NULL
)
2796 get_next_display_element (it
);
2797 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2798 it
->current
.dpvec_index
= pos
->dpvec_index
;
2802 return !overlay_strings_with_newlines
;
2806 /* Initialize IT for stepping through current_buffer in window W
2807 starting at ROW->start. */
2810 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
2812 init_from_display_pos (it
, w
, &row
->start
);
2813 it
->start
= row
->start
;
2814 it
->continuation_lines_width
= row
->continuation_lines_width
;
2819 /* Initialize IT for stepping through current_buffer in window W
2820 starting in the line following ROW, i.e. starting at ROW->end.
2821 Value is zero if there are overlay strings with newlines at ROW's
2825 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
2829 if (init_from_display_pos (it
, w
, &row
->end
))
2831 if (row
->continued_p
)
2832 it
->continuation_lines_width
2833 = row
->continuation_lines_width
+ row
->pixel_width
;
2844 /***********************************************************************
2846 ***********************************************************************/
2848 /* Called when IT reaches IT->stop_charpos. Handle text property and
2849 overlay changes. Set IT->stop_charpos to the next position where
2853 handle_stop (struct it
*it
)
2855 enum prop_handled handled
;
2856 int handle_overlay_change_p
;
2860 it
->current
.dpvec_index
= -1;
2861 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
2862 it
->ignore_overlay_strings_at_pos_p
= 0;
2865 /* Use face of preceding text for ellipsis (if invisible) */
2866 if (it
->selective_display_ellipsis_p
)
2867 it
->saved_face_id
= it
->face_id
;
2871 handled
= HANDLED_NORMALLY
;
2873 /* Call text property handlers. */
2874 for (p
= it_props
; p
->handler
; ++p
)
2876 handled
= p
->handler (it
);
2878 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2880 else if (handled
== HANDLED_RETURN
)
2882 /* We still want to show before and after strings from
2883 overlays even if the actual buffer text is replaced. */
2884 if (!handle_overlay_change_p
2886 || !get_overlay_strings_1 (it
, 0, 0))
2889 setup_for_ellipsis (it
, 0);
2890 /* When handling a display spec, we might load an
2891 empty string. In that case, discard it here. We
2892 used to discard it in handle_single_display_spec,
2893 but that causes get_overlay_strings_1, above, to
2894 ignore overlay strings that we must check. */
2895 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
2899 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
2903 it
->ignore_overlay_strings_at_pos_p
= 1;
2904 it
->string_from_display_prop_p
= 0;
2905 handle_overlay_change_p
= 0;
2907 handled
= HANDLED_RECOMPUTE_PROPS
;
2910 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2911 handle_overlay_change_p
= 0;
2914 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2916 /* Don't check for overlay strings below when set to deliver
2917 characters from a display vector. */
2918 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
2919 handle_overlay_change_p
= 0;
2921 /* Handle overlay changes.
2922 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
2923 if it finds overlays. */
2924 if (handle_overlay_change_p
)
2925 handled
= handle_overlay_change (it
);
2930 setup_for_ellipsis (it
, 0);
2934 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2936 /* Determine where to stop next. */
2937 if (handled
== HANDLED_NORMALLY
)
2938 compute_stop_pos (it
);
2942 /* Compute IT->stop_charpos from text property and overlay change
2943 information for IT's current position. */
2946 compute_stop_pos (struct it
*it
)
2948 register INTERVAL iv
, next_iv
;
2949 Lisp_Object object
, limit
, position
;
2950 EMACS_INT charpos
, bytepos
;
2952 /* If nowhere else, stop at the end. */
2953 it
->stop_charpos
= it
->end_charpos
;
2955 if (STRINGP (it
->string
))
2957 /* Strings are usually short, so don't limit the search for
2959 object
= it
->string
;
2961 charpos
= IT_STRING_CHARPOS (*it
);
2962 bytepos
= IT_STRING_BYTEPOS (*it
);
2968 /* If next overlay change is in front of the current stop pos
2969 (which is IT->end_charpos), stop there. Note: value of
2970 next_overlay_change is point-max if no overlay change
2972 charpos
= IT_CHARPOS (*it
);
2973 bytepos
= IT_BYTEPOS (*it
);
2974 pos
= next_overlay_change (charpos
);
2975 if (pos
< it
->stop_charpos
)
2976 it
->stop_charpos
= pos
;
2978 /* If showing the region, we have to stop at the region
2979 start or end because the face might change there. */
2980 if (it
->region_beg_charpos
> 0)
2982 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2983 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2984 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2985 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2988 /* Set up variables for computing the stop position from text
2989 property changes. */
2990 XSETBUFFER (object
, current_buffer
);
2991 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2994 /* Get the interval containing IT's position. Value is a null
2995 interval if there isn't such an interval. */
2996 position
= make_number (charpos
);
2997 iv
= validate_interval_range (object
, &position
, &position
, 0);
2998 if (!NULL_INTERVAL_P (iv
))
3000 Lisp_Object values_here
[LAST_PROP_IDX
];
3003 /* Get properties here. */
3004 for (p
= it_props
; p
->handler
; ++p
)
3005 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3007 /* Look for an interval following iv that has different
3009 for (next_iv
= next_interval (iv
);
3010 (!NULL_INTERVAL_P (next_iv
)
3012 || XFASTINT (limit
) > next_iv
->position
));
3013 next_iv
= next_interval (next_iv
))
3015 for (p
= it_props
; p
->handler
; ++p
)
3017 Lisp_Object new_value
;
3019 new_value
= textget (next_iv
->plist
, *p
->name
);
3020 if (!EQ (values_here
[p
->idx
], new_value
))
3028 if (!NULL_INTERVAL_P (next_iv
))
3030 if (INTEGERP (limit
)
3031 && next_iv
->position
>= XFASTINT (limit
))
3032 /* No text property change up to limit. */
3033 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3035 /* Text properties change in next_iv. */
3036 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3040 if (it
->cmp_it
.id
< 0)
3042 EMACS_INT stoppos
= it
->end_charpos
;
3044 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3046 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3047 stoppos
, it
->string
);
3050 xassert (STRINGP (it
->string
)
3051 || (it
->stop_charpos
>= BEGV
3052 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3056 /* Return the position of the next overlay change after POS in
3057 current_buffer. Value is point-max if no overlay change
3058 follows. This is like `next-overlay-change' but doesn't use
3062 next_overlay_change (EMACS_INT pos
)
3064 ptrdiff_t i
, noverlays
;
3066 Lisp_Object
*overlays
;
3068 /* Get all overlays at the given position. */
3069 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3071 /* If any of these overlays ends before endpos,
3072 use its ending point instead. */
3073 for (i
= 0; i
< noverlays
; ++i
)
3078 oend
= OVERLAY_END (overlays
[i
]);
3079 oendpos
= OVERLAY_POSITION (oend
);
3080 endpos
= min (endpos
, oendpos
);
3086 /* Return the character position of a display string at or after CHARPOS.
3087 If no display string exists at or after CHARPOS, return ZV. A
3088 display string is either an overlay with `display' property whose
3089 value is a string, or a `display' text property whose value is a
3090 string. FRAME_WINDOW_P is non-zero when we are displaying a window
3093 compute_display_string_pos (EMACS_INT charpos
, int frame_window_p
)
3095 /* FIXME: Support display properties on strings (object = Qnil means
3097 Lisp_Object object
= Qnil
;
3098 Lisp_Object pos
, spec
;
3099 struct text_pos position
;
3105 /* If the character at CHARPOS is where the display string begins,
3107 pos
= make_number (charpos
);
3108 CHARPOS (position
) = charpos
;
3109 BYTEPOS (position
) = CHAR_TO_BYTE (charpos
);
3110 bufpos
= charpos
; /* FIXME! support strings as well */
3111 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3113 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3116 && handle_display_spec (NULL
, spec
, object
, Qnil
, &position
, bufpos
,
3120 /* Look forward for the first character with a `display' property
3121 that will replace the underlying text when displayed. */
3123 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3124 CHARPOS (position
) = XFASTINT (pos
);
3125 BYTEPOS (position
) = CHAR_TO_BYTE (CHARPOS (position
));
3126 if (CHARPOS (position
) >= ZV
)
3128 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3129 bufpos
= CHARPOS (position
); /* FIXME! support strings as well */
3130 } while (NILP (spec
)
3131 || !handle_display_spec (NULL
, spec
, object
, Qnil
, &position
, bufpos
,
3134 return CHARPOS (position
);
3137 /* Return the character position of the end of the display string that
3138 started at CHARPOS. A display string is either an overlay with
3139 `display' property whose value is a string or a `display' text
3140 property whose value is a string. */
3142 compute_display_string_end (EMACS_INT charpos
)
3144 /* FIXME: Support display properties on strings (object = Qnil means
3146 Lisp_Object object
= Qnil
;
3147 Lisp_Object pos
= make_number (charpos
);
3152 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3155 /* Look forward for the first character where the `display' property
3157 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3159 return XFASTINT (pos
);
3164 /***********************************************************************
3166 ***********************************************************************/
3168 /* Handle changes in the `fontified' property of the current buffer by
3169 calling hook functions from Qfontification_functions to fontify
3172 static enum prop_handled
3173 handle_fontified_prop (struct it
*it
)
3175 Lisp_Object prop
, pos
;
3176 enum prop_handled handled
= HANDLED_NORMALLY
;
3178 if (!NILP (Vmemory_full
))
3181 /* Get the value of the `fontified' property at IT's current buffer
3182 position. (The `fontified' property doesn't have a special
3183 meaning in strings.) If the value is nil, call functions from
3184 Qfontification_functions. */
3185 if (!STRINGP (it
->string
)
3187 && !NILP (Vfontification_functions
)
3188 && !NILP (Vrun_hooks
)
3189 && (pos
= make_number (IT_CHARPOS (*it
)),
3190 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3191 /* Ignore the special cased nil value always present at EOB since
3192 no amount of fontifying will be able to change it. */
3193 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3195 int count
= SPECPDL_INDEX ();
3197 struct buffer
*obuf
= current_buffer
;
3198 int begv
= BEGV
, zv
= ZV
;
3199 int old_clip_changed
= current_buffer
->clip_changed
;
3201 val
= Vfontification_functions
;
3202 specbind (Qfontification_functions
, Qnil
);
3204 xassert (it
->end_charpos
== ZV
);
3206 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3207 safe_call1 (val
, pos
);
3210 Lisp_Object fns
, fn
;
3211 struct gcpro gcpro1
, gcpro2
;
3216 for (; CONSP (val
); val
= XCDR (val
))
3222 /* A value of t indicates this hook has a local
3223 binding; it means to run the global binding too.
3224 In a global value, t should not occur. If it
3225 does, we must ignore it to avoid an endless
3227 for (fns
= Fdefault_value (Qfontification_functions
);
3233 safe_call1 (fn
, pos
);
3237 safe_call1 (fn
, pos
);
3243 unbind_to (count
, Qnil
);
3245 /* Fontification functions routinely call `save-restriction'.
3246 Normally, this tags clip_changed, which can confuse redisplay
3247 (see discussion in Bug#6671). Since we don't perform any
3248 special handling of fontification changes in the case where
3249 `save-restriction' isn't called, there's no point doing so in
3250 this case either. So, if the buffer's restrictions are
3251 actually left unchanged, reset clip_changed. */
3252 if (obuf
== current_buffer
)
3254 if (begv
== BEGV
&& zv
== ZV
)
3255 current_buffer
->clip_changed
= old_clip_changed
;
3257 /* There isn't much we can reasonably do to protect against
3258 misbehaving fontification, but here's a fig leaf. */
3259 else if (!NILP (BVAR (obuf
, name
)))
3260 set_buffer_internal_1 (obuf
);
3262 /* The fontification code may have added/removed text.
3263 It could do even a lot worse, but let's at least protect against
3264 the most obvious case where only the text past `pos' gets changed',
3265 as is/was done in grep.el where some escapes sequences are turned
3266 into face properties (bug#7876). */
3267 it
->end_charpos
= ZV
;
3269 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3270 something. This avoids an endless loop if they failed to
3271 fontify the text for which reason ever. */
3272 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3273 handled
= HANDLED_RECOMPUTE_PROPS
;
3281 /***********************************************************************
3283 ***********************************************************************/
3285 /* Set up iterator IT from face properties at its current position.
3286 Called from handle_stop. */
3288 static enum prop_handled
3289 handle_face_prop (struct it
*it
)
3292 EMACS_INT next_stop
;
3294 if (!STRINGP (it
->string
))
3297 = face_at_buffer_position (it
->w
,
3299 it
->region_beg_charpos
,
3300 it
->region_end_charpos
,
3303 + TEXT_PROP_DISTANCE_LIMIT
),
3304 0, it
->base_face_id
);
3306 /* Is this a start of a run of characters with box face?
3307 Caveat: this can be called for a freshly initialized
3308 iterator; face_id is -1 in this case. We know that the new
3309 face will not change until limit, i.e. if the new face has a
3310 box, all characters up to limit will have one. But, as
3311 usual, we don't know whether limit is really the end. */
3312 if (new_face_id
!= it
->face_id
)
3314 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3316 /* If new face has a box but old face has not, this is
3317 the start of a run of characters with box, i.e. it has
3318 a shadow on the left side. The value of face_id of the
3319 iterator will be -1 if this is the initial call that gets
3320 the face. In this case, we have to look in front of IT's
3321 position and see whether there is a face != new_face_id. */
3322 it
->start_of_box_run_p
3323 = (new_face
->box
!= FACE_NO_BOX
3324 && (it
->face_id
>= 0
3325 || IT_CHARPOS (*it
) == BEG
3326 || new_face_id
!= face_before_it_pos (it
)));
3327 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3335 Lisp_Object from_overlay
3336 = (it
->current
.overlay_string_index
>= 0
3337 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3340 /* See if we got to this string directly or indirectly from
3341 an overlay property. That includes the before-string or
3342 after-string of an overlay, strings in display properties
3343 provided by an overlay, their text properties, etc.
3345 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3346 if (! NILP (from_overlay
))
3347 for (i
= it
->sp
- 1; i
>= 0; i
--)
3349 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3351 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3352 else if (! NILP (it
->stack
[i
].from_overlay
))
3353 from_overlay
= it
->stack
[i
].from_overlay
;
3355 if (!NILP (from_overlay
))
3359 if (! NILP (from_overlay
))
3361 bufpos
= IT_CHARPOS (*it
);
3362 /* For a string from an overlay, the base face depends
3363 only on text properties and ignores overlays. */
3365 = face_for_overlay_string (it
->w
,
3367 it
->region_beg_charpos
,
3368 it
->region_end_charpos
,
3371 + TEXT_PROP_DISTANCE_LIMIT
),
3379 /* For strings from a `display' property, use the face at
3380 IT's current buffer position as the base face to merge
3381 with, so that overlay strings appear in the same face as
3382 surrounding text, unless they specify their own
3384 base_face_id
= underlying_face_id (it
);
3387 new_face_id
= face_at_string_position (it
->w
,
3389 IT_STRING_CHARPOS (*it
),
3391 it
->region_beg_charpos
,
3392 it
->region_end_charpos
,
3396 /* Is this a start of a run of characters with box? Caveat:
3397 this can be called for a freshly allocated iterator; face_id
3398 is -1 is this case. We know that the new face will not
3399 change until the next check pos, i.e. if the new face has a
3400 box, all characters up to that position will have a
3401 box. But, as usual, we don't know whether that position
3402 is really the end. */
3403 if (new_face_id
!= it
->face_id
)
3405 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3406 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3408 /* If new face has a box but old face hasn't, this is the
3409 start of a run of characters with box, i.e. it has a
3410 shadow on the left side. */
3411 it
->start_of_box_run_p
3412 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3413 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3417 it
->face_id
= new_face_id
;
3418 return HANDLED_NORMALLY
;
3422 /* Return the ID of the face ``underlying'' IT's current position,
3423 which is in a string. If the iterator is associated with a
3424 buffer, return the face at IT's current buffer position.
3425 Otherwise, use the iterator's base_face_id. */
3428 underlying_face_id (struct it
*it
)
3430 int face_id
= it
->base_face_id
, i
;
3432 xassert (STRINGP (it
->string
));
3434 for (i
= it
->sp
- 1; i
>= 0; --i
)
3435 if (NILP (it
->stack
[i
].string
))
3436 face_id
= it
->stack
[i
].face_id
;
3442 /* Compute the face one character before or after the current position
3443 of IT. BEFORE_P non-zero means get the face in front of IT's
3444 position. Value is the id of the face. */
3447 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3450 EMACS_INT next_check_charpos
;
3451 struct text_pos pos
;
3453 xassert (it
->s
== NULL
);
3455 if (STRINGP (it
->string
))
3460 /* No face change past the end of the string (for the case
3461 we are padding with spaces). No face change before the
3463 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3464 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3467 /* Set pos to the position before or after IT's current position. */
3469 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3471 /* For composition, we must check the character after the
3473 pos
= (it
->what
== IT_COMPOSITION
3474 ? string_pos (IT_STRING_CHARPOS (*it
)
3475 + it
->cmp_it
.nchars
, it
->string
)
3476 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3478 if (it
->current
.overlay_string_index
>= 0)
3479 bufpos
= IT_CHARPOS (*it
);
3483 base_face_id
= underlying_face_id (it
);
3485 /* Get the face for ASCII, or unibyte. */
3486 face_id
= face_at_string_position (it
->w
,
3490 it
->region_beg_charpos
,
3491 it
->region_end_charpos
,
3492 &next_check_charpos
,
3495 /* Correct the face for charsets different from ASCII. Do it
3496 for the multibyte case only. The face returned above is
3497 suitable for unibyte text if IT->string is unibyte. */
3498 if (STRING_MULTIBYTE (it
->string
))
3500 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3502 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3504 c
= string_char_and_length (p
, &len
);
3505 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3510 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3511 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3514 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3515 pos
= it
->current
.pos
;
3518 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3521 if (it
->what
== IT_COMPOSITION
)
3522 /* For composition, we must check the position after the
3524 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3526 INC_TEXT_POS (pos
, it
->multibyte_p
);
3529 /* Determine face for CHARSET_ASCII, or unibyte. */
3530 face_id
= face_at_buffer_position (it
->w
,
3532 it
->region_beg_charpos
,
3533 it
->region_end_charpos
,
3534 &next_check_charpos
,
3537 /* Correct the face for charsets different from ASCII. Do it
3538 for the multibyte case only. The face returned above is
3539 suitable for unibyte text if current_buffer is unibyte. */
3540 if (it
->multibyte_p
)
3542 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3543 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3544 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3553 /***********************************************************************
3555 ***********************************************************************/
3557 /* Set up iterator IT from invisible properties at its current
3558 position. Called from handle_stop. */
3560 static enum prop_handled
3561 handle_invisible_prop (struct it
*it
)
3563 enum prop_handled handled
= HANDLED_NORMALLY
;
3565 if (STRINGP (it
->string
))
3567 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3569 /* Get the value of the invisible text property at the
3570 current position. Value will be nil if there is no such
3572 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3573 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3576 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3578 handled
= HANDLED_RECOMPUTE_PROPS
;
3580 /* Get the position at which the next change of the
3581 invisible text property can be found in IT->string.
3582 Value will be nil if the property value is the same for
3583 all the rest of IT->string. */
3584 XSETINT (limit
, SCHARS (it
->string
));
3585 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3588 /* Text at current position is invisible. The next
3589 change in the property is at position end_charpos.
3590 Move IT's current position to that position. */
3591 if (INTEGERP (end_charpos
)
3592 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3594 struct text_pos old
;
3595 old
= it
->current
.string_pos
;
3596 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3597 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3601 /* The rest of the string is invisible. If this is an
3602 overlay string, proceed with the next overlay string
3603 or whatever comes and return a character from there. */
3604 if (it
->current
.overlay_string_index
>= 0)
3606 next_overlay_string (it
);
3607 /* Don't check for overlay strings when we just
3608 finished processing them. */
3609 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3613 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3614 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3622 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
3623 Lisp_Object pos
, prop
, overlay
;
3625 /* First of all, is there invisible text at this position? */
3626 tem
= start_charpos
= IT_CHARPOS (*it
);
3627 pos
= make_number (tem
);
3628 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3630 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3632 /* If we are on invisible text, skip over it. */
3633 if (invis_p
&& start_charpos
< it
->end_charpos
)
3635 /* Record whether we have to display an ellipsis for the
3637 int display_ellipsis_p
= invis_p
== 2;
3639 handled
= HANDLED_RECOMPUTE_PROPS
;
3641 /* Loop skipping over invisible text. The loop is left at
3642 ZV or with IT on the first char being visible again. */
3645 /* Try to skip some invisible text. Return value is the
3646 position reached which can be equal to where we start
3647 if there is nothing invisible there. This skips both
3648 over invisible text properties and overlays with
3649 invisible property. */
3650 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
3652 /* If we skipped nothing at all we weren't at invisible
3653 text in the first place. If everything to the end of
3654 the buffer was skipped, end the loop. */
3655 if (newpos
== tem
|| newpos
>= ZV
)
3659 /* We skipped some characters but not necessarily
3660 all there are. Check if we ended up on visible
3661 text. Fget_char_property returns the property of
3662 the char before the given position, i.e. if we
3663 get invis_p = 0, this means that the char at
3664 newpos is visible. */
3665 pos
= make_number (newpos
);
3666 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3667 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3670 /* If we ended up on invisible text, proceed to
3671 skip starting with next_stop. */
3675 /* If there are adjacent invisible texts, don't lose the
3676 second one's ellipsis. */
3678 display_ellipsis_p
= 1;
3682 /* The position newpos is now either ZV or on visible text. */
3683 if (it
->bidi_p
&& newpos
< ZV
)
3685 /* With bidi iteration, the region of invisible text
3686 could start and/or end in the middle of a non-base
3687 embedding level. Therefore, we need to skip
3688 invisible text using the bidi iterator, starting at
3689 IT's current position, until we find ourselves
3690 outside the invisible text. Skipping invisible text
3691 _after_ bidi iteration avoids affecting the visual
3692 order of the displayed text when invisible properties
3693 are added or removed. */
3694 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
3696 /* If we were `reseat'ed to a new paragraph,
3697 determine the paragraph base direction. We need
3698 to do it now because next_element_from_buffer may
3699 not have a chance to do it, if we are going to
3700 skip any text at the beginning, which resets the
3702 bidi_paragraph_init (it
->paragraph_embedding
,
3707 bidi_move_to_visually_next (&it
->bidi_it
);
3709 while (it
->stop_charpos
<= it
->bidi_it
.charpos
3710 && it
->bidi_it
.charpos
< newpos
);
3711 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3712 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3713 /* If we overstepped NEWPOS, record its position in the
3714 iterator, so that we skip invisible text if later the
3715 bidi iteration lands us in the invisible region
3717 if (IT_CHARPOS (*it
) >= newpos
)
3718 it
->prev_stop
= newpos
;
3722 IT_CHARPOS (*it
) = newpos
;
3723 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3726 /* If there are before-strings at the start of invisible
3727 text, and the text is invisible because of a text
3728 property, arrange to show before-strings because 20.x did
3729 it that way. (If the text is invisible because of an
3730 overlay property instead of a text property, this is
3731 already handled in the overlay code.) */
3733 && get_overlay_strings (it
, it
->stop_charpos
))
3735 handled
= HANDLED_RECOMPUTE_PROPS
;
3736 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3738 else if (display_ellipsis_p
)
3740 /* Make sure that the glyphs of the ellipsis will get
3741 correct `charpos' values. If we would not update
3742 it->position here, the glyphs would belong to the
3743 last visible character _before_ the invisible
3744 text, which confuses `set_cursor_from_row'.
3746 We use the last invisible position instead of the
3747 first because this way the cursor is always drawn on
3748 the first "." of the ellipsis, whenever PT is inside
3749 the invisible text. Otherwise the cursor would be
3750 placed _after_ the ellipsis when the point is after the
3751 first invisible character. */
3752 if (!STRINGP (it
->object
))
3754 it
->position
.charpos
= newpos
- 1;
3755 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3758 /* Let the ellipsis display before
3759 considering any properties of the following char.
3760 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3761 handled
= HANDLED_RETURN
;
3770 /* Make iterator IT return `...' next.
3771 Replaces LEN characters from buffer. */
3774 setup_for_ellipsis (struct it
*it
, int len
)
3776 /* Use the display table definition for `...'. Invalid glyphs
3777 will be handled by the method returning elements from dpvec. */
3778 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3780 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3781 it
->dpvec
= v
->contents
;
3782 it
->dpend
= v
->contents
+ v
->header
.size
;
3786 /* Default `...'. */
3787 it
->dpvec
= default_invis_vector
;
3788 it
->dpend
= default_invis_vector
+ 3;
3791 it
->dpvec_char_len
= len
;
3792 it
->current
.dpvec_index
= 0;
3793 it
->dpvec_face_id
= -1;
3795 /* Remember the current face id in case glyphs specify faces.
3796 IT's face is restored in set_iterator_to_next.
3797 saved_face_id was set to preceding char's face in handle_stop. */
3798 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3799 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3801 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3807 /***********************************************************************
3809 ***********************************************************************/
3811 /* Set up iterator IT from `display' property at its current position.
3812 Called from handle_stop.
3813 We return HANDLED_RETURN if some part of the display property
3814 overrides the display of the buffer text itself.
3815 Otherwise we return HANDLED_NORMALLY. */
3817 static enum prop_handled
3818 handle_display_prop (struct it
*it
)
3820 Lisp_Object propval
, object
, overlay
;
3821 struct text_pos
*position
;
3823 /* Nonzero if some property replaces the display of the text itself. */
3824 int display_replaced_p
= 0;
3826 if (STRINGP (it
->string
))
3828 object
= it
->string
;
3829 position
= &it
->current
.string_pos
;
3830 bufpos
= CHARPOS (it
->current
.pos
);
3834 XSETWINDOW (object
, it
->w
);
3835 position
= &it
->current
.pos
;
3836 bufpos
= CHARPOS (*position
);
3839 /* Reset those iterator values set from display property values. */
3840 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3841 it
->space_width
= Qnil
;
3842 it
->font_height
= Qnil
;
3845 /* We don't support recursive `display' properties, i.e. string
3846 values that have a string `display' property, that have a string
3847 `display' property etc. */
3848 if (!it
->string_from_display_prop_p
)
3849 it
->area
= TEXT_AREA
;
3851 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
3852 Qdisplay
, object
, &overlay
);
3854 return HANDLED_NORMALLY
;
3855 /* Now OVERLAY is the overlay that gave us this property, or nil
3856 if it was a text property. */
3858 if (!STRINGP (it
->string
))
3859 object
= it
->w
->buffer
;
3861 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
3863 FRAME_WINDOW_P (it
->f
));
3865 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3868 /* Subroutine of handle_display_prop. Returns non-zero if the display
3869 specification in SPEC is a replacing specification, i.e. it would
3870 replace the text covered by `display' property with something else,
3871 such as an image or a display string.
3873 See handle_single_display_spec for documentation of arguments.
3874 frame_window_p is non-zero if the window being redisplayed is on a
3875 GUI frame; this argument is used only if IT is NULL, see below.
3877 IT can be NULL, if this is called by the bidi reordering code
3878 through compute_display_string_pos, which see. In that case, this
3879 function only examines SPEC, but does not otherwise "handle" it, in
3880 the sense that it doesn't set up members of IT from the display
3883 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
3884 Lisp_Object overlay
, struct text_pos
*position
,
3885 EMACS_INT bufpos
, int frame_window_p
)
3887 int replacing_p
= 0;
3890 /* Simple specerties. */
3891 && !EQ (XCAR (spec
), Qimage
)
3892 && !EQ (XCAR (spec
), Qspace
)
3893 && !EQ (XCAR (spec
), Qwhen
)
3894 && !EQ (XCAR (spec
), Qslice
)
3895 && !EQ (XCAR (spec
), Qspace_width
)
3896 && !EQ (XCAR (spec
), Qheight
)
3897 && !EQ (XCAR (spec
), Qraise
)
3898 /* Marginal area specifications. */
3899 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
3900 && !EQ (XCAR (spec
), Qleft_fringe
)
3901 && !EQ (XCAR (spec
), Qright_fringe
)
3902 && !NILP (XCAR (spec
)))
3904 for (; CONSP (spec
); spec
= XCDR (spec
))
3906 if (handle_single_display_spec (it
, XCAR (spec
), object
, overlay
,
3907 position
, bufpos
, replacing_p
,
3911 /* If some text in a string is replaced, `position' no
3912 longer points to the position of `object'. */
3913 if (!it
|| STRINGP (object
))
3918 else if (VECTORP (spec
))
3921 for (i
= 0; i
< ASIZE (spec
); ++i
)
3922 if (handle_single_display_spec (it
, AREF (spec
, i
), object
, overlay
,
3923 position
, bufpos
, replacing_p
,
3927 /* If some text in a string is replaced, `position' no
3928 longer points to the position of `object'. */
3929 if (!it
|| STRINGP (object
))
3935 if (handle_single_display_spec (it
, spec
, object
, overlay
,
3936 position
, bufpos
, 0, frame_window_p
))
3943 /* Value is the position of the end of the `display' property starting
3944 at START_POS in OBJECT. */
3946 static struct text_pos
3947 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
3950 struct text_pos end_pos
;
3952 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3953 Qdisplay
, object
, Qnil
);
3954 CHARPOS (end_pos
) = XFASTINT (end
);
3955 if (STRINGP (object
))
3956 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3958 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3964 /* Set up IT from a single `display' property specification SPEC. OBJECT
3965 is the object in which the `display' property was found. *POSITION
3966 is the position in OBJECT at which the `display' property was found.
3967 BUFPOS is the buffer position of OBJECT (different from POSITION if
3968 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
3969 previously saw a display specification which already replaced text
3970 display with something else, for example an image; we ignore such
3971 properties after the first one has been processed.
3973 OVERLAY is the overlay this `display' property came from,
3974 or nil if it was a text property.
3976 If SPEC is a `space' or `image' specification, and in some other
3977 cases too, set *POSITION to the position where the `display'
3980 If IT is NULL, only examine the property specification in SPEC, but
3981 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
3982 is intended to be displayed in a window on a GUI frame.
3984 Value is non-zero if something was found which replaces the display
3985 of buffer or string text. */
3988 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
3989 Lisp_Object overlay
, struct text_pos
*position
,
3990 EMACS_INT bufpos
, int display_replaced_p
,
3994 Lisp_Object location
, value
;
3995 struct text_pos start_pos
= *position
;
3998 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3999 If the result is non-nil, use VALUE instead of SPEC. */
4001 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4010 if (!NILP (form
) && !EQ (form
, Qt
))
4012 int count
= SPECPDL_INDEX ();
4013 struct gcpro gcpro1
;
4015 /* Bind `object' to the object having the `display' property, a
4016 buffer or string. Bind `position' to the position in the
4017 object where the property was found, and `buffer-position'
4018 to the current position in the buffer. */
4021 XSETBUFFER (object
, current_buffer
);
4022 specbind (Qobject
, object
);
4023 specbind (Qposition
, make_number (CHARPOS (*position
)));
4024 specbind (Qbuffer_position
, make_number (bufpos
));
4026 form
= safe_eval (form
);
4028 unbind_to (count
, Qnil
);
4034 /* Handle `(height HEIGHT)' specifications. */
4036 && EQ (XCAR (spec
), Qheight
)
4037 && CONSP (XCDR (spec
)))
4041 if (!FRAME_WINDOW_P (it
->f
))
4044 it
->font_height
= XCAR (XCDR (spec
));
4045 if (!NILP (it
->font_height
))
4047 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4048 int new_height
= -1;
4050 if (CONSP (it
->font_height
)
4051 && (EQ (XCAR (it
->font_height
), Qplus
)
4052 || EQ (XCAR (it
->font_height
), Qminus
))
4053 && CONSP (XCDR (it
->font_height
))
4054 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4056 /* `(+ N)' or `(- N)' where N is an integer. */
4057 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4058 if (EQ (XCAR (it
->font_height
), Qplus
))
4060 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4062 else if (FUNCTIONP (it
->font_height
))
4064 /* Call function with current height as argument.
4065 Value is the new height. */
4067 height
= safe_call1 (it
->font_height
,
4068 face
->lface
[LFACE_HEIGHT_INDEX
]);
4069 if (NUMBERP (height
))
4070 new_height
= XFLOATINT (height
);
4072 else if (NUMBERP (it
->font_height
))
4074 /* Value is a multiple of the canonical char height. */
4077 f
= FACE_FROM_ID (it
->f
,
4078 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4079 new_height
= (XFLOATINT (it
->font_height
)
4080 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4084 /* Evaluate IT->font_height with `height' bound to the
4085 current specified height to get the new height. */
4086 int count
= SPECPDL_INDEX ();
4088 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4089 value
= safe_eval (it
->font_height
);
4090 unbind_to (count
, Qnil
);
4092 if (NUMBERP (value
))
4093 new_height
= XFLOATINT (value
);
4097 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4104 /* Handle `(space-width WIDTH)'. */
4106 && EQ (XCAR (spec
), Qspace_width
)
4107 && CONSP (XCDR (spec
)))
4111 if (!FRAME_WINDOW_P (it
->f
))
4114 value
= XCAR (XCDR (spec
));
4115 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4116 it
->space_width
= value
;
4122 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4124 && EQ (XCAR (spec
), Qslice
))
4130 if (!FRAME_WINDOW_P (it
->f
))
4133 if (tem
= XCDR (spec
), CONSP (tem
))
4135 it
->slice
.x
= XCAR (tem
);
4136 if (tem
= XCDR (tem
), CONSP (tem
))
4138 it
->slice
.y
= XCAR (tem
);
4139 if (tem
= XCDR (tem
), CONSP (tem
))
4141 it
->slice
.width
= XCAR (tem
);
4142 if (tem
= XCDR (tem
), CONSP (tem
))
4143 it
->slice
.height
= XCAR (tem
);
4152 /* Handle `(raise FACTOR)'. */
4154 && EQ (XCAR (spec
), Qraise
)
4155 && CONSP (XCDR (spec
)))
4159 if (!FRAME_WINDOW_P (it
->f
))
4162 #ifdef HAVE_WINDOW_SYSTEM
4163 value
= XCAR (XCDR (spec
));
4164 if (NUMBERP (value
))
4166 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4167 it
->voffset
= - (XFLOATINT (value
)
4168 * (FONT_HEIGHT (face
->font
)));
4170 #endif /* HAVE_WINDOW_SYSTEM */
4176 /* Don't handle the other kinds of display specifications
4177 inside a string that we got from a `display' property. */
4178 if (it
&& it
->string_from_display_prop_p
)
4181 /* Characters having this form of property are not displayed, so
4182 we have to find the end of the property. */
4185 start_pos
= *position
;
4186 *position
= display_prop_end (it
, object
, start_pos
);
4190 /* Stop the scan at that end position--we assume that all
4191 text properties change there. */
4193 it
->stop_charpos
= position
->charpos
;
4195 /* Handle `(left-fringe BITMAP [FACE])'
4196 and `(right-fringe BITMAP [FACE])'. */
4198 && (EQ (XCAR (spec
), Qleft_fringe
)
4199 || EQ (XCAR (spec
), Qright_fringe
))
4200 && CONSP (XCDR (spec
)))
4206 if (!FRAME_WINDOW_P (it
->f
))
4207 /* If we return here, POSITION has been advanced
4208 across the text with this property. */
4211 else if (!frame_window_p
)
4214 #ifdef HAVE_WINDOW_SYSTEM
4215 value
= XCAR (XCDR (spec
));
4216 if (!SYMBOLP (value
)
4217 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4218 /* If we return here, POSITION has been advanced
4219 across the text with this property. */
4224 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4226 if (CONSP (XCDR (XCDR (spec
))))
4228 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4229 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4235 /* Save current settings of IT so that we can restore them
4236 when we are finished with the glyph property value. */
4237 push_it (it
, position
);
4239 it
->area
= TEXT_AREA
;
4240 it
->what
= IT_IMAGE
;
4241 it
->image_id
= -1; /* no image */
4242 it
->position
= start_pos
;
4243 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4244 it
->method
= GET_FROM_IMAGE
;
4245 it
->from_overlay
= Qnil
;
4246 it
->face_id
= face_id
;
4248 /* Say that we haven't consumed the characters with
4249 `display' property yet. The call to pop_it in
4250 set_iterator_to_next will clean this up. */
4251 *position
= start_pos
;
4253 if (EQ (XCAR (spec
), Qleft_fringe
))
4255 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4256 it
->left_user_fringe_face_id
= face_id
;
4260 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4261 it
->right_user_fringe_face_id
= face_id
;
4264 #endif /* HAVE_WINDOW_SYSTEM */
4268 /* Prepare to handle `((margin left-margin) ...)',
4269 `((margin right-margin) ...)' and `((margin nil) ...)'
4270 prefixes for display specifications. */
4271 location
= Qunbound
;
4272 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4276 value
= XCDR (spec
);
4278 value
= XCAR (value
);
4281 if (EQ (XCAR (tem
), Qmargin
)
4282 && (tem
= XCDR (tem
),
4283 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4285 || EQ (tem
, Qleft_margin
)
4286 || EQ (tem
, Qright_margin
))))
4290 if (EQ (location
, Qunbound
))
4296 /* After this point, VALUE is the property after any
4297 margin prefix has been stripped. It must be a string,
4298 an image specification, or `(space ...)'.
4300 LOCATION specifies where to display: `left-margin',
4301 `right-margin' or nil. */
4303 valid_p
= (STRINGP (value
)
4304 #ifdef HAVE_WINDOW_SYSTEM
4305 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4306 && valid_image_p (value
))
4307 #endif /* not HAVE_WINDOW_SYSTEM */
4308 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4310 if (valid_p
&& !display_replaced_p
)
4315 /* Save current settings of IT so that we can restore them
4316 when we are finished with the glyph property value. */
4317 push_it (it
, position
);
4318 it
->from_overlay
= overlay
;
4320 if (NILP (location
))
4321 it
->area
= TEXT_AREA
;
4322 else if (EQ (location
, Qleft_margin
))
4323 it
->area
= LEFT_MARGIN_AREA
;
4325 it
->area
= RIGHT_MARGIN_AREA
;
4327 if (STRINGP (value
))
4330 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4331 it
->current
.overlay_string_index
= -1;
4332 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4333 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4334 it
->method
= GET_FROM_STRING
;
4335 it
->stop_charpos
= 0;
4336 it
->string_from_display_prop_p
= 1;
4337 /* Say that we haven't consumed the characters with
4338 `display' property yet. The call to pop_it in
4339 set_iterator_to_next will clean this up. */
4340 if (BUFFERP (object
))
4341 *position
= start_pos
;
4343 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4345 it
->method
= GET_FROM_STRETCH
;
4347 *position
= it
->position
= start_pos
;
4349 #ifdef HAVE_WINDOW_SYSTEM
4352 it
->what
= IT_IMAGE
;
4353 it
->image_id
= lookup_image (it
->f
, value
);
4354 it
->position
= start_pos
;
4355 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4356 it
->method
= GET_FROM_IMAGE
;
4358 /* Say that we haven't consumed the characters with
4359 `display' property yet. The call to pop_it in
4360 set_iterator_to_next will clean this up. */
4361 *position
= start_pos
;
4363 #endif /* HAVE_WINDOW_SYSTEM */
4368 /* Invalid property or property not supported. Restore
4369 POSITION to what it was before. */
4370 *position
= start_pos
;
4374 /* Check if PROP is a display property value whose text should be
4375 treated as intangible. OVERLAY is the overlay from which PROP
4376 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4377 specify the buffer position covered by PROP. */
4380 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4381 EMACS_INT charpos
, EMACS_INT bytepos
)
4383 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4384 struct text_pos position
;
4386 SET_TEXT_POS (position
, charpos
, bytepos
);
4387 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4388 &position
, charpos
, frame_window_p
);
4392 /* Return 1 if PROP is a display sub-property value containing STRING.
4394 Implementation note: this and the following function are really
4395 special cases of handle_display_spec and
4396 handle_single_display_spec, and should ideally use the same code.
4397 Until they do, these two pairs must be consistent and must be
4398 modified in sync. */
4401 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4403 if (EQ (string
, prop
))
4406 /* Skip over `when FORM'. */
4407 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4412 /* Actually, the condition following `when' should be eval'ed,
4413 like handle_single_display_spec does, and we should return
4414 zero if it evaluates to nil. However, this function is
4415 called only when the buffer was already displayed and some
4416 glyph in the glyph matrix was found to come from a display
4417 string. Therefore, the condition was already evaluated, and
4418 the result was non-nil, otherwise the display string wouldn't
4419 have been displayed and we would have never been called for
4420 this property. Thus, we can skip the evaluation and assume
4421 its result is non-nil. */
4426 /* Skip over `margin LOCATION'. */
4427 if (EQ (XCAR (prop
), Qmargin
))
4438 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
4442 /* Return 1 if STRING appears in the `display' property PROP. */
4445 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4448 && !EQ (XCAR (prop
), Qwhen
)
4449 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
4451 /* A list of sub-properties. */
4452 while (CONSP (prop
))
4454 if (single_display_spec_string_p (XCAR (prop
), string
))
4459 else if (VECTORP (prop
))
4461 /* A vector of sub-properties. */
4463 for (i
= 0; i
< ASIZE (prop
); ++i
)
4464 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4468 return single_display_spec_string_p (prop
, string
);
4473 /* Look for STRING in overlays and text properties in the current
4474 buffer, between character positions FROM and TO (excluding TO).
4475 BACK_P non-zero means look back (in this case, TO is supposed to be
4477 Value is the first character position where STRING was found, or
4478 zero if it wasn't found before hitting TO.
4480 This function may only use code that doesn't eval because it is
4481 called asynchronously from note_mouse_highlight. */
4484 string_buffer_position_lim (Lisp_Object string
,
4485 EMACS_INT from
, EMACS_INT to
, int back_p
)
4487 Lisp_Object limit
, prop
, pos
;
4490 pos
= make_number (from
);
4492 if (!back_p
) /* looking forward */
4494 limit
= make_number (min (to
, ZV
));
4495 while (!found
&& !EQ (pos
, limit
))
4497 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4498 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4501 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4505 else /* looking back */
4507 limit
= make_number (max (to
, BEGV
));
4508 while (!found
&& !EQ (pos
, limit
))
4510 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4511 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4514 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4519 return found
? XINT (pos
) : 0;
4522 /* Determine which buffer position in current buffer STRING comes from.
4523 AROUND_CHARPOS is an approximate position where it could come from.
4524 Value is the buffer position or 0 if it couldn't be determined.
4526 This function is necessary because we don't record buffer positions
4527 in glyphs generated from strings (to keep struct glyph small).
4528 This function may only use code that doesn't eval because it is
4529 called asynchronously from note_mouse_highlight. */
4532 string_buffer_position (Lisp_Object string
, EMACS_INT around_charpos
)
4534 const int MAX_DISTANCE
= 1000;
4535 EMACS_INT found
= string_buffer_position_lim (string
, around_charpos
,
4536 around_charpos
+ MAX_DISTANCE
,
4540 found
= string_buffer_position_lim (string
, around_charpos
,
4541 around_charpos
- MAX_DISTANCE
, 1);
4547 /***********************************************************************
4548 `composition' property
4549 ***********************************************************************/
4551 /* Set up iterator IT from `composition' property at its current
4552 position. Called from handle_stop. */
4554 static enum prop_handled
4555 handle_composition_prop (struct it
*it
)
4557 Lisp_Object prop
, string
;
4558 EMACS_INT pos
, pos_byte
, start
, end
;
4560 if (STRINGP (it
->string
))
4564 pos
= IT_STRING_CHARPOS (*it
);
4565 pos_byte
= IT_STRING_BYTEPOS (*it
);
4566 string
= it
->string
;
4567 s
= SDATA (string
) + pos_byte
;
4568 it
->c
= STRING_CHAR (s
);
4572 pos
= IT_CHARPOS (*it
);
4573 pos_byte
= IT_BYTEPOS (*it
);
4575 it
->c
= FETCH_CHAR (pos_byte
);
4578 /* If there's a valid composition and point is not inside of the
4579 composition (in the case that the composition is from the current
4580 buffer), draw a glyph composed from the composition components. */
4581 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4582 && COMPOSITION_VALID_P (start
, end
, prop
)
4583 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4586 /* As we can't handle this situation (perhaps font-lock added
4587 a new composition), we just return here hoping that next
4588 redisplay will detect this composition much earlier. */
4589 return HANDLED_NORMALLY
;
4592 if (STRINGP (it
->string
))
4593 pos_byte
= string_char_to_byte (it
->string
, start
);
4595 pos_byte
= CHAR_TO_BYTE (start
);
4597 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4600 if (it
->cmp_it
.id
>= 0)
4603 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4604 it
->cmp_it
.nglyphs
= -1;
4608 return HANDLED_NORMALLY
;
4613 /***********************************************************************
4615 ***********************************************************************/
4617 /* The following structure is used to record overlay strings for
4618 later sorting in load_overlay_strings. */
4620 struct overlay_entry
4622 Lisp_Object overlay
;
4629 /* Set up iterator IT from overlay strings at its current position.
4630 Called from handle_stop. */
4632 static enum prop_handled
4633 handle_overlay_change (struct it
*it
)
4635 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4636 return HANDLED_RECOMPUTE_PROPS
;
4638 return HANDLED_NORMALLY
;
4642 /* Set up the next overlay string for delivery by IT, if there is an
4643 overlay string to deliver. Called by set_iterator_to_next when the
4644 end of the current overlay string is reached. If there are more
4645 overlay strings to display, IT->string and
4646 IT->current.overlay_string_index are set appropriately here.
4647 Otherwise IT->string is set to nil. */
4650 next_overlay_string (struct it
*it
)
4652 ++it
->current
.overlay_string_index
;
4653 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4655 /* No more overlay strings. Restore IT's settings to what
4656 they were before overlay strings were processed, and
4657 continue to deliver from current_buffer. */
4659 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4662 || (NILP (it
->string
)
4663 && it
->method
== GET_FROM_BUFFER
4664 && it
->stop_charpos
>= BEGV
4665 && it
->stop_charpos
<= it
->end_charpos
));
4666 it
->current
.overlay_string_index
= -1;
4667 it
->n_overlay_strings
= 0;
4668 it
->overlay_strings_charpos
= -1;
4670 /* If we're at the end of the buffer, record that we have
4671 processed the overlay strings there already, so that
4672 next_element_from_buffer doesn't try it again. */
4673 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4674 it
->overlay_strings_at_end_processed_p
= 1;
4678 /* There are more overlay strings to process. If
4679 IT->current.overlay_string_index has advanced to a position
4680 where we must load IT->overlay_strings with more strings, do
4681 it. We must load at the IT->overlay_strings_charpos where
4682 IT->n_overlay_strings was originally computed; when invisible
4683 text is present, this might not be IT_CHARPOS (Bug#7016). */
4684 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4686 if (it
->current
.overlay_string_index
&& i
== 0)
4687 load_overlay_strings (it
, it
->overlay_strings_charpos
);
4689 /* Initialize IT to deliver display elements from the overlay
4691 it
->string
= it
->overlay_strings
[i
];
4692 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4693 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4694 it
->method
= GET_FROM_STRING
;
4695 it
->stop_charpos
= 0;
4696 if (it
->cmp_it
.stop_pos
>= 0)
4697 it
->cmp_it
.stop_pos
= 0;
4704 /* Compare two overlay_entry structures E1 and E2. Used as a
4705 comparison function for qsort in load_overlay_strings. Overlay
4706 strings for the same position are sorted so that
4708 1. All after-strings come in front of before-strings, except
4709 when they come from the same overlay.
4711 2. Within after-strings, strings are sorted so that overlay strings
4712 from overlays with higher priorities come first.
4714 2. Within before-strings, strings are sorted so that overlay
4715 strings from overlays with higher priorities come last.
4717 Value is analogous to strcmp. */
4721 compare_overlay_entries (const void *e1
, const void *e2
)
4723 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4724 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4727 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4729 /* Let after-strings appear in front of before-strings if
4730 they come from different overlays. */
4731 if (EQ (entry1
->overlay
, entry2
->overlay
))
4732 result
= entry1
->after_string_p
? 1 : -1;
4734 result
= entry1
->after_string_p
? -1 : 1;
4736 else if (entry1
->after_string_p
)
4737 /* After-strings sorted in order of decreasing priority. */
4738 result
= entry2
->priority
- entry1
->priority
;
4740 /* Before-strings sorted in order of increasing priority. */
4741 result
= entry1
->priority
- entry2
->priority
;
4747 /* Load the vector IT->overlay_strings with overlay strings from IT's
4748 current buffer position, or from CHARPOS if that is > 0. Set
4749 IT->n_overlays to the total number of overlay strings found.
4751 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4752 a time. On entry into load_overlay_strings,
4753 IT->current.overlay_string_index gives the number of overlay
4754 strings that have already been loaded by previous calls to this
4757 IT->add_overlay_start contains an additional overlay start
4758 position to consider for taking overlay strings from, if non-zero.
4759 This position comes into play when the overlay has an `invisible'
4760 property, and both before and after-strings. When we've skipped to
4761 the end of the overlay, because of its `invisible' property, we
4762 nevertheless want its before-string to appear.
4763 IT->add_overlay_start will contain the overlay start position
4766 Overlay strings are sorted so that after-string strings come in
4767 front of before-string strings. Within before and after-strings,
4768 strings are sorted by overlay priority. See also function
4769 compare_overlay_entries. */
4772 load_overlay_strings (struct it
*it
, EMACS_INT charpos
)
4774 Lisp_Object overlay
, window
, str
, invisible
;
4775 struct Lisp_Overlay
*ov
;
4776 EMACS_INT start
, end
;
4778 int n
= 0, i
, j
, invis_p
;
4779 struct overlay_entry
*entries
4780 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4783 charpos
= IT_CHARPOS (*it
);
4785 /* Append the overlay string STRING of overlay OVERLAY to vector
4786 `entries' which has size `size' and currently contains `n'
4787 elements. AFTER_P non-zero means STRING is an after-string of
4789 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4792 Lisp_Object priority; \
4796 int new_size = 2 * size; \
4797 struct overlay_entry *old = entries; \
4799 (struct overlay_entry *) alloca (new_size \
4800 * sizeof *entries); \
4801 memcpy (entries, old, size * sizeof *entries); \
4805 entries[n].string = (STRING); \
4806 entries[n].overlay = (OVERLAY); \
4807 priority = Foverlay_get ((OVERLAY), Qpriority); \
4808 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4809 entries[n].after_string_p = (AFTER_P); \
4814 /* Process overlay before the overlay center. */
4815 for (ov
= current_buffer
->overlays_before
; 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
));
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, both before-
4836 and after-strings from this overlay are visible; start and
4837 end position are indistinguishable. */
4838 invisible
= Foverlay_get (overlay
, Qinvisible
);
4839 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4841 /* If overlay has a non-empty before-string, record it. */
4842 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4843 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4845 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4847 /* If overlay has a non-empty after-string, record it. */
4848 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4849 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4851 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4854 /* Process overlays after the overlay center. */
4855 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4857 XSETMISC (overlay
, ov
);
4858 xassert (OVERLAYP (overlay
));
4859 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4860 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4862 if (start
> charpos
)
4865 /* Skip this overlay if it doesn't start or end at IT's current
4867 if (end
!= charpos
&& start
!= charpos
)
4870 /* Skip this overlay if it doesn't apply to IT->w. */
4871 window
= Foverlay_get (overlay
, Qwindow
);
4872 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4875 /* If the text ``under'' the overlay is invisible, it has a zero
4876 dimension, and both before- and after-strings apply. */
4877 invisible
= Foverlay_get (overlay
, Qinvisible
);
4878 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4880 /* If overlay has a non-empty before-string, record it. */
4881 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4882 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4884 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4886 /* If overlay has a non-empty after-string, record it. */
4887 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4888 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4890 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4893 #undef RECORD_OVERLAY_STRING
4897 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4899 /* Record number of overlay strings, and where we computed it. */
4900 it
->n_overlay_strings
= n
;
4901 it
->overlay_strings_charpos
= charpos
;
4903 /* IT->current.overlay_string_index is the number of overlay strings
4904 that have already been consumed by IT. Copy some of the
4905 remaining overlay strings to IT->overlay_strings. */
4907 j
= it
->current
.overlay_string_index
;
4908 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4910 it
->overlay_strings
[i
] = entries
[j
].string
;
4911 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
4918 /* Get the first chunk of overlay strings at IT's current buffer
4919 position, or at CHARPOS if that is > 0. Value is non-zero if at
4920 least one overlay string was found. */
4923 get_overlay_strings_1 (struct it
*it
, EMACS_INT charpos
, int compute_stop_p
)
4925 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4926 process. This fills IT->overlay_strings with strings, and sets
4927 IT->n_overlay_strings to the total number of strings to process.
4928 IT->pos.overlay_string_index has to be set temporarily to zero
4929 because load_overlay_strings needs this; it must be set to -1
4930 when no overlay strings are found because a zero value would
4931 indicate a position in the first overlay string. */
4932 it
->current
.overlay_string_index
= 0;
4933 load_overlay_strings (it
, charpos
);
4935 /* If we found overlay strings, set up IT to deliver display
4936 elements from the first one. Otherwise set up IT to deliver
4937 from current_buffer. */
4938 if (it
->n_overlay_strings
)
4940 /* Make sure we know settings in current_buffer, so that we can
4941 restore meaningful values when we're done with the overlay
4944 compute_stop_pos (it
);
4945 xassert (it
->face_id
>= 0);
4947 /* Save IT's settings. They are restored after all overlay
4948 strings have been processed. */
4949 xassert (!compute_stop_p
|| it
->sp
== 0);
4951 /* When called from handle_stop, there might be an empty display
4952 string loaded. In that case, don't bother saving it. */
4953 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
4956 /* Set up IT to deliver display elements from the first overlay
4958 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4959 it
->string
= it
->overlay_strings
[0];
4960 it
->from_overlay
= Qnil
;
4961 it
->stop_charpos
= 0;
4962 xassert (STRINGP (it
->string
));
4963 it
->end_charpos
= SCHARS (it
->string
);
4964 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4965 it
->method
= GET_FROM_STRING
;
4969 it
->current
.overlay_string_index
= -1;
4974 get_overlay_strings (struct it
*it
, EMACS_INT charpos
)
4977 it
->method
= GET_FROM_BUFFER
;
4979 (void) get_overlay_strings_1 (it
, charpos
, 1);
4983 /* Value is non-zero if we found at least one overlay string. */
4984 return STRINGP (it
->string
);
4989 /***********************************************************************
4990 Saving and restoring state
4991 ***********************************************************************/
4993 /* Save current settings of IT on IT->stack. Called, for example,
4994 before setting up IT for an overlay string, to be able to restore
4995 IT's settings to what they were after the overlay string has been
4996 processed. If POSITION is non-NULL, it is the position to save on
4997 the stack instead of IT->position. */
5000 push_it (struct it
*it
, struct text_pos
*position
)
5002 struct iterator_stack_entry
*p
;
5004 xassert (it
->sp
< IT_STACK_SIZE
);
5005 p
= it
->stack
+ it
->sp
;
5007 p
->stop_charpos
= it
->stop_charpos
;
5008 p
->prev_stop
= it
->prev_stop
;
5009 p
->base_level_stop
= it
->base_level_stop
;
5010 p
->cmp_it
= it
->cmp_it
;
5011 xassert (it
->face_id
>= 0);
5012 p
->face_id
= it
->face_id
;
5013 p
->string
= it
->string
;
5014 p
->method
= it
->method
;
5015 p
->from_overlay
= it
->from_overlay
;
5018 case GET_FROM_IMAGE
:
5019 p
->u
.image
.object
= it
->object
;
5020 p
->u
.image
.image_id
= it
->image_id
;
5021 p
->u
.image
.slice
= it
->slice
;
5023 case GET_FROM_STRETCH
:
5024 p
->u
.stretch
.object
= it
->object
;
5027 p
->position
= position
? *position
: it
->position
;
5028 p
->current
= it
->current
;
5029 p
->end_charpos
= it
->end_charpos
;
5030 p
->string_nchars
= it
->string_nchars
;
5032 p
->multibyte_p
= it
->multibyte_p
;
5033 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5034 p
->space_width
= it
->space_width
;
5035 p
->font_height
= it
->font_height
;
5036 p
->voffset
= it
->voffset
;
5037 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5038 p
->display_ellipsis_p
= 0;
5039 p
->line_wrap
= it
->line_wrap
;
5044 iterate_out_of_display_property (struct it
*it
)
5046 /* Maybe initialize paragraph direction. If we are at the beginning
5047 of a new paragraph, next_element_from_buffer may not have a
5048 chance to do that. */
5049 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
5050 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5051 /* prev_stop can be zero, so check against BEGV as well. */
5052 while (it
->bidi_it
.charpos
>= BEGV
5053 && it
->prev_stop
<= it
->bidi_it
.charpos
5054 && it
->bidi_it
.charpos
< CHARPOS (it
->position
))
5055 bidi_move_to_visually_next (&it
->bidi_it
);
5056 /* Record the stop_pos we just crossed, for when we cross it
5058 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5059 it
->prev_stop
= CHARPOS (it
->position
);
5060 /* If we ended up not where pop_it put us, resync IT's
5061 positional members with the bidi iterator. */
5062 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5064 SET_TEXT_POS (it
->position
,
5065 it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5066 it
->current
.pos
= it
->position
;
5070 /* Restore IT's settings from IT->stack. Called, for example, when no
5071 more overlay strings must be processed, and we return to delivering
5072 display elements from a buffer, or when the end of a string from a
5073 `display' property is reached and we return to delivering display
5074 elements from an overlay string, or from a buffer. */
5077 pop_it (struct it
*it
)
5079 struct iterator_stack_entry
*p
;
5081 xassert (it
->sp
> 0);
5083 p
= it
->stack
+ it
->sp
;
5084 it
->stop_charpos
= p
->stop_charpos
;
5085 it
->prev_stop
= p
->prev_stop
;
5086 it
->base_level_stop
= p
->base_level_stop
;
5087 it
->cmp_it
= p
->cmp_it
;
5088 it
->face_id
= p
->face_id
;
5089 it
->current
= p
->current
;
5090 it
->position
= p
->position
;
5091 it
->string
= p
->string
;
5092 it
->from_overlay
= p
->from_overlay
;
5093 if (NILP (it
->string
))
5094 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5095 it
->method
= p
->method
;
5098 case GET_FROM_IMAGE
:
5099 it
->image_id
= p
->u
.image
.image_id
;
5100 it
->object
= p
->u
.image
.object
;
5101 it
->slice
= p
->u
.image
.slice
;
5103 case GET_FROM_STRETCH
:
5104 it
->object
= p
->u
.comp
.object
;
5106 case GET_FROM_BUFFER
:
5107 it
->object
= it
->w
->buffer
;
5110 /* Bidi-iterate until we get out of the portion of text, if
5111 any, covered by a `display' text property or an overlay
5112 with `display' property. (We cannot just jump there,
5113 because the internal coherency of the bidi iterator state
5114 can not be preserved across such jumps.) We also must
5115 determine the paragraph base direction if the overlay we
5116 just processed is at the beginning of a new
5118 iterate_out_of_display_property (it
);
5121 case GET_FROM_STRING
:
5122 it
->object
= it
->string
;
5124 case GET_FROM_DISPLAY_VECTOR
:
5126 it
->method
= GET_FROM_C_STRING
;
5127 else if (STRINGP (it
->string
))
5128 it
->method
= GET_FROM_STRING
;
5131 it
->method
= GET_FROM_BUFFER
;
5132 it
->object
= it
->w
->buffer
;
5135 it
->end_charpos
= p
->end_charpos
;
5136 it
->string_nchars
= p
->string_nchars
;
5138 it
->multibyte_p
= p
->multibyte_p
;
5139 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5140 it
->space_width
= p
->space_width
;
5141 it
->font_height
= p
->font_height
;
5142 it
->voffset
= p
->voffset
;
5143 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5144 it
->line_wrap
= p
->line_wrap
;
5149 /***********************************************************************
5151 ***********************************************************************/
5153 /* Set IT's current position to the previous line start. */
5156 back_to_previous_line_start (struct it
*it
)
5158 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5159 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5163 /* Move IT to the next line start.
5165 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5166 we skipped over part of the text (as opposed to moving the iterator
5167 continuously over the text). Otherwise, don't change the value
5170 Newlines may come from buffer text, overlay strings, or strings
5171 displayed via the `display' property. That's the reason we can't
5172 simply use find_next_newline_no_quit.
5174 Note that this function may not skip over invisible text that is so
5175 because of text properties and immediately follows a newline. If
5176 it would, function reseat_at_next_visible_line_start, when called
5177 from set_iterator_to_next, would effectively make invisible
5178 characters following a newline part of the wrong glyph row, which
5179 leads to wrong cursor motion. */
5182 forward_to_next_line_start (struct it
*it
, int *skipped_p
)
5184 EMACS_INT old_selective
;
5185 int newline_found_p
, n
;
5186 const int MAX_NEWLINE_DISTANCE
= 500;
5188 /* If already on a newline, just consume it to avoid unintended
5189 skipping over invisible text below. */
5190 if (it
->what
== IT_CHARACTER
5192 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5194 set_iterator_to_next (it
, 0);
5199 /* Don't handle selective display in the following. It's (a)
5200 unnecessary because it's done by the caller, and (b) leads to an
5201 infinite recursion because next_element_from_ellipsis indirectly
5202 calls this function. */
5203 old_selective
= it
->selective
;
5206 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5207 from buffer text. */
5208 for (n
= newline_found_p
= 0;
5209 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5210 n
+= STRINGP (it
->string
) ? 0 : 1)
5212 if (!get_next_display_element (it
))
5214 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5215 set_iterator_to_next (it
, 0);
5218 /* If we didn't find a newline near enough, see if we can use a
5220 if (!newline_found_p
)
5222 EMACS_INT start
= IT_CHARPOS (*it
);
5223 EMACS_INT limit
= find_next_newline_no_quit (start
, 1);
5226 xassert (!STRINGP (it
->string
));
5228 /* If there isn't any `display' property in sight, and no
5229 overlays, we can just use the position of the newline in
5231 if (it
->stop_charpos
>= limit
5232 || ((pos
= Fnext_single_property_change (make_number (start
),
5234 Qnil
, make_number (limit
)),
5236 && next_overlay_change (start
) == ZV
))
5238 IT_CHARPOS (*it
) = limit
;
5239 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5240 *skipped_p
= newline_found_p
= 1;
5244 while (get_next_display_element (it
)
5245 && !newline_found_p
)
5247 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5248 set_iterator_to_next (it
, 0);
5253 it
->selective
= old_selective
;
5254 return newline_found_p
;
5258 /* Set IT's current position to the previous visible line start. Skip
5259 invisible text that is so either due to text properties or due to
5260 selective display. Caution: this does not change IT->current_x and
5264 back_to_previous_visible_line_start (struct it
*it
)
5266 while (IT_CHARPOS (*it
) > BEGV
)
5268 back_to_previous_line_start (it
);
5270 if (IT_CHARPOS (*it
) <= BEGV
)
5273 /* If selective > 0, then lines indented more than its value are
5275 if (it
->selective
> 0
5276 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5280 /* Check the newline before point for invisibility. */
5283 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5284 Qinvisible
, it
->window
);
5285 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5289 if (IT_CHARPOS (*it
) <= BEGV
)
5296 Lisp_Object val
, overlay
;
5298 /* If newline is part of a composition, continue from start of composition */
5299 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5300 && beg
< IT_CHARPOS (*it
))
5303 /* If newline is replaced by a display property, find start of overlay
5304 or interval and continue search from that point. */
5306 pos
= --IT_CHARPOS (it2
);
5309 it2
.string_from_display_prop_p
= 0;
5310 if (handle_display_prop (&it2
) == HANDLED_RETURN
5311 && !NILP (val
= get_char_property_and_overlay
5312 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5313 && (OVERLAYP (overlay
)
5314 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5315 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5318 /* Newline is not replaced by anything -- so we are done. */
5324 IT_CHARPOS (*it
) = beg
;
5325 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5329 it
->continuation_lines_width
= 0;
5331 xassert (IT_CHARPOS (*it
) >= BEGV
);
5332 xassert (IT_CHARPOS (*it
) == BEGV
5333 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5338 /* Reseat iterator IT at the previous visible line start. Skip
5339 invisible text that is so either due to text properties or due to
5340 selective display. At the end, update IT's overlay information,
5341 face information etc. */
5344 reseat_at_previous_visible_line_start (struct it
*it
)
5346 back_to_previous_visible_line_start (it
);
5347 reseat (it
, it
->current
.pos
, 1);
5352 /* Reseat iterator IT on the next visible line start in the current
5353 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5354 preceding the line start. Skip over invisible text that is so
5355 because of selective display. Compute faces, overlays etc at the
5356 new position. Note that this function does not skip over text that
5357 is invisible because of text properties. */
5360 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5362 int newline_found_p
, skipped_p
= 0;
5364 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5366 /* Skip over lines that are invisible because they are indented
5367 more than the value of IT->selective. */
5368 if (it
->selective
> 0)
5369 while (IT_CHARPOS (*it
) < ZV
5370 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5373 xassert (IT_BYTEPOS (*it
) == BEGV
5374 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5375 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5378 /* Position on the newline if that's what's requested. */
5379 if (on_newline_p
&& newline_found_p
)
5381 if (STRINGP (it
->string
))
5383 if (IT_STRING_CHARPOS (*it
) > 0)
5385 --IT_STRING_CHARPOS (*it
);
5386 --IT_STRING_BYTEPOS (*it
);
5389 else if (IT_CHARPOS (*it
) > BEGV
)
5393 reseat (it
, it
->current
.pos
, 0);
5397 reseat (it
, it
->current
.pos
, 0);
5404 /***********************************************************************
5405 Changing an iterator's position
5406 ***********************************************************************/
5408 /* Change IT's current position to POS in current_buffer. If FORCE_P
5409 is non-zero, always check for text properties at the new position.
5410 Otherwise, text properties are only looked up if POS >=
5411 IT->check_charpos of a property. */
5414 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
5416 EMACS_INT original_pos
= IT_CHARPOS (*it
);
5418 reseat_1 (it
, pos
, 0);
5420 /* Determine where to check text properties. Avoid doing it
5421 where possible because text property lookup is very expensive. */
5423 || CHARPOS (pos
) > it
->stop_charpos
5424 || CHARPOS (pos
) < original_pos
)
5428 /* For bidi iteration, we need to prime prev_stop and
5429 base_level_stop with our best estimations. */
5430 if (CHARPOS (pos
) < it
->prev_stop
)
5432 handle_stop_backwards (it
, BEGV
);
5433 if (CHARPOS (pos
) < it
->base_level_stop
)
5434 it
->base_level_stop
= 0;
5436 else if (CHARPOS (pos
) > it
->stop_charpos
5437 && it
->stop_charpos
>= BEGV
)
5438 handle_stop_backwards (it
, it
->stop_charpos
);
5445 it
->prev_stop
= it
->base_level_stop
= 0;
5454 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5455 IT->stop_pos to POS, also. */
5458 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
5460 /* Don't call this function when scanning a C string. */
5461 xassert (it
->s
== NULL
);
5463 /* POS must be a reasonable value. */
5464 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5466 it
->current
.pos
= it
->position
= pos
;
5467 it
->end_charpos
= ZV
;
5469 it
->current
.dpvec_index
= -1;
5470 it
->current
.overlay_string_index
= -1;
5471 IT_STRING_CHARPOS (*it
) = -1;
5472 IT_STRING_BYTEPOS (*it
) = -1;
5474 it
->string_from_display_prop_p
= 0;
5475 it
->method
= GET_FROM_BUFFER
;
5476 it
->object
= it
->w
->buffer
;
5477 it
->area
= TEXT_AREA
;
5478 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
5480 it
->string_from_display_prop_p
= 0;
5481 it
->face_before_selective_p
= 0;
5484 it
->bidi_it
.first_elt
= 1;
5485 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5486 it
->bidi_it
.disp_pos
= -1;
5491 it
->stop_charpos
= CHARPOS (pos
);
5492 it
->base_level_stop
= CHARPOS (pos
);
5497 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5498 If S is non-null, it is a C string to iterate over. Otherwise,
5499 STRING gives a Lisp string to iterate over.
5501 If PRECISION > 0, don't return more then PRECISION number of
5502 characters from the string.
5504 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5505 characters have been returned. FIELD_WIDTH < 0 means an infinite
5508 MULTIBYTE = 0 means disable processing of multibyte characters,
5509 MULTIBYTE > 0 means enable it,
5510 MULTIBYTE < 0 means use IT->multibyte_p.
5512 IT must be initialized via a prior call to init_iterator before
5513 calling this function. */
5516 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
5517 EMACS_INT charpos
, EMACS_INT precision
, int field_width
,
5520 /* No region in strings. */
5521 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5523 /* No text property checks performed by default, but see below. */
5524 it
->stop_charpos
= -1;
5526 /* Set iterator position and end position. */
5527 memset (&it
->current
, 0, sizeof it
->current
);
5528 it
->current
.overlay_string_index
= -1;
5529 it
->current
.dpvec_index
= -1;
5530 xassert (charpos
>= 0);
5532 /* If STRING is specified, use its multibyteness, otherwise use the
5533 setting of MULTIBYTE, if specified. */
5535 it
->multibyte_p
= multibyte
> 0;
5539 xassert (STRINGP (string
));
5540 it
->string
= string
;
5542 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5543 it
->method
= GET_FROM_STRING
;
5544 it
->current
.string_pos
= string_pos (charpos
, string
);
5548 it
->s
= (const unsigned char *) s
;
5551 /* Note that we use IT->current.pos, not it->current.string_pos,
5552 for displaying C strings. */
5553 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5554 if (it
->multibyte_p
)
5556 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5557 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5561 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5562 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5565 it
->method
= GET_FROM_C_STRING
;
5568 /* PRECISION > 0 means don't return more than PRECISION characters
5570 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5571 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5573 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5574 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5575 FIELD_WIDTH < 0 means infinite field width. This is useful for
5576 padding with `-' at the end of a mode line. */
5577 if (field_width
< 0)
5578 field_width
= INFINITY
;
5579 if (field_width
> it
->end_charpos
- charpos
)
5580 it
->end_charpos
= charpos
+ field_width
;
5582 /* Use the standard display table for displaying strings. */
5583 if (DISP_TABLE_P (Vstandard_display_table
))
5584 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5586 it
->stop_charpos
= charpos
;
5587 if (s
== NULL
&& it
->multibyte_p
)
5589 EMACS_INT endpos
= SCHARS (it
->string
);
5590 if (endpos
> it
->end_charpos
)
5591 endpos
= it
->end_charpos
;
5592 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5600 /***********************************************************************
5602 ***********************************************************************/
5604 /* Map enum it_method value to corresponding next_element_from_* function. */
5606 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
5608 next_element_from_buffer
,
5609 next_element_from_display_vector
,
5610 next_element_from_string
,
5611 next_element_from_c_string
,
5612 next_element_from_image
,
5613 next_element_from_stretch
5616 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5619 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5620 (possibly with the following characters). */
5622 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5623 ((IT)->cmp_it.id >= 0 \
5624 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5625 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5626 END_CHARPOS, (IT)->w, \
5627 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5631 /* Lookup the char-table Vglyphless_char_display for character C (-1
5632 if we want information for no-font case), and return the display
5633 method symbol. By side-effect, update it->what and
5634 it->glyphless_method. This function is called from
5635 get_next_display_element for each character element, and from
5636 x_produce_glyphs when no suitable font was found. */
5639 lookup_glyphless_char_display (int c
, struct it
*it
)
5641 Lisp_Object glyphless_method
= Qnil
;
5643 if (CHAR_TABLE_P (Vglyphless_char_display
)
5644 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
5648 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
5649 if (CONSP (glyphless_method
))
5650 glyphless_method
= FRAME_WINDOW_P (it
->f
)
5651 ? XCAR (glyphless_method
)
5652 : XCDR (glyphless_method
);
5655 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
5659 if (NILP (glyphless_method
))
5662 /* The default is to display the character by a proper font. */
5664 /* The default for the no-font case is to display an empty box. */
5665 glyphless_method
= Qempty_box
;
5667 if (EQ (glyphless_method
, Qzero_width
))
5670 return glyphless_method
;
5671 /* This method can't be used for the no-font case. */
5672 glyphless_method
= Qempty_box
;
5674 if (EQ (glyphless_method
, Qthin_space
))
5675 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
5676 else if (EQ (glyphless_method
, Qempty_box
))
5677 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
5678 else if (EQ (glyphless_method
, Qhex_code
))
5679 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
5680 else if (STRINGP (glyphless_method
))
5681 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
5684 /* Invalid value. We use the default method. */
5685 glyphless_method
= Qnil
;
5688 it
->what
= IT_GLYPHLESS
;
5689 return glyphless_method
;
5692 /* Load IT's display element fields with information about the next
5693 display element from the current position of IT. Value is zero if
5694 end of buffer (or C string) is reached. */
5696 static struct frame
*last_escape_glyph_frame
= NULL
;
5697 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5698 static int last_escape_glyph_merged_face_id
= 0;
5700 struct frame
*last_glyphless_glyph_frame
= NULL
;
5701 unsigned last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
5702 int last_glyphless_glyph_merged_face_id
= 0;
5705 get_next_display_element (struct it
*it
)
5707 /* Non-zero means that we found a display element. Zero means that
5708 we hit the end of what we iterate over. Performance note: the
5709 function pointer `method' used here turns out to be faster than
5710 using a sequence of if-statements. */
5714 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5716 if (it
->what
== IT_CHARACTER
)
5718 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
5719 and only if (a) the resolved directionality of that character
5721 /* FIXME: Do we need an exception for characters from display
5723 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
5724 it
->c
= bidi_mirror_char (it
->c
);
5725 /* Map via display table or translate control characters.
5726 IT->c, IT->len etc. have been set to the next character by
5727 the function call above. If we have a display table, and it
5728 contains an entry for IT->c, translate it. Don't do this if
5729 IT->c itself comes from a display table, otherwise we could
5730 end up in an infinite recursion. (An alternative could be to
5731 count the recursion depth of this function and signal an
5732 error when a certain maximum depth is reached.) Is it worth
5734 if (success_p
&& it
->dpvec
== NULL
)
5737 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5738 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5739 nbsp_or_shy
= char_is_other
;
5740 int c
= it
->c
; /* This is the character to display. */
5742 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
5744 xassert (SINGLE_BYTE_CHAR_P (c
));
5745 if (unibyte_display_via_language_environment
)
5747 c
= DECODE_CHAR (unibyte
, c
);
5749 c
= BYTE8_TO_CHAR (it
->c
);
5752 c
= BYTE8_TO_CHAR (it
->c
);
5756 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
5759 struct Lisp_Vector
*v
= XVECTOR (dv
);
5761 /* Return the first character from the display table
5762 entry, if not empty. If empty, don't display the
5763 current character. */
5766 it
->dpvec_char_len
= it
->len
;
5767 it
->dpvec
= v
->contents
;
5768 it
->dpend
= v
->contents
+ v
->header
.size
;
5769 it
->current
.dpvec_index
= 0;
5770 it
->dpvec_face_id
= -1;
5771 it
->saved_face_id
= it
->face_id
;
5772 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5777 set_iterator_to_next (it
, 0);
5782 if (! NILP (lookup_glyphless_char_display (c
, it
)))
5784 if (it
->what
== IT_GLYPHLESS
)
5786 /* Don't display this character. */
5787 set_iterator_to_next (it
, 0);
5791 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
5792 nbsp_or_shy
= (c
== 0xA0 ? char_is_nbsp
5793 : c
== 0xAD ? char_is_soft_hyphen
5796 /* Translate control characters into `\003' or `^C' form.
5797 Control characters coming from a display table entry are
5798 currently not translated because we use IT->dpvec to hold
5799 the translation. This could easily be changed but I
5800 don't believe that it is worth doing.
5802 NBSP and SOFT-HYPEN are property translated too.
5804 Non-printable characters and raw-byte characters are also
5805 translated to octal form. */
5806 if (((c
< ' ' || c
== 127) /* ASCII control chars */
5807 ? (it
->area
!= TEXT_AREA
5808 /* In mode line, treat \n, \t like other crl chars. */
5811 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5812 || (c
!= '\n' && c
!= '\t'))
5815 || ! CHAR_PRINTABLE_P (c
))))
5817 /* C is a control character, NBSP, SOFT-HYPEN, raw-byte,
5818 or a non-printable character which must be displayed
5819 either as '\003' or as `^C' where the '\\' and '^'
5820 can be defined in the display table. Fill
5821 IT->ctl_chars with glyphs for what we have to
5822 display. Then, set IT->dpvec to these glyphs. */
5826 EMACS_INT lface_id
= 0;
5829 /* Handle control characters with ^. */
5831 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
5835 g
= '^'; /* default glyph for Control */
5836 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5838 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5839 && GLYPH_CODE_CHAR_VALID_P (gc
))
5841 g
= GLYPH_CODE_CHAR (gc
);
5842 lface_id
= GLYPH_CODE_FACE (gc
);
5846 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5848 else if (it
->f
== last_escape_glyph_frame
5849 && it
->face_id
== last_escape_glyph_face_id
)
5851 face_id
= last_escape_glyph_merged_face_id
;
5855 /* Merge the escape-glyph face into the current face. */
5856 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5858 last_escape_glyph_frame
= it
->f
;
5859 last_escape_glyph_face_id
= it
->face_id
;
5860 last_escape_glyph_merged_face_id
= face_id
;
5863 XSETINT (it
->ctl_chars
[0], g
);
5864 XSETINT (it
->ctl_chars
[1], c
^ 0100);
5866 goto display_control
;
5869 /* Handle non-break space in the mode where it only gets
5872 if (EQ (Vnobreak_char_display
, Qt
)
5873 && nbsp_or_shy
== char_is_nbsp
)
5875 /* Merge the no-break-space face into the current face. */
5876 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5880 XSETINT (it
->ctl_chars
[0], ' ');
5882 goto display_control
;
5885 /* Handle sequences that start with the "escape glyph". */
5887 /* the default escape glyph is \. */
5888 escape_glyph
= '\\';
5891 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5892 && GLYPH_CODE_CHAR_VALID_P (gc
))
5894 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5895 lface_id
= GLYPH_CODE_FACE (gc
);
5899 /* The display table specified a face.
5900 Merge it into face_id and also into escape_glyph. */
5901 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5904 else if (it
->f
== last_escape_glyph_frame
5905 && it
->face_id
== last_escape_glyph_face_id
)
5907 face_id
= last_escape_glyph_merged_face_id
;
5911 /* Merge the escape-glyph face into the current face. */
5912 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5914 last_escape_glyph_frame
= it
->f
;
5915 last_escape_glyph_face_id
= it
->face_id
;
5916 last_escape_glyph_merged_face_id
= face_id
;
5919 /* Handle soft hyphens in the mode where they only get
5922 if (EQ (Vnobreak_char_display
, Qt
)
5923 && nbsp_or_shy
== char_is_soft_hyphen
)
5925 XSETINT (it
->ctl_chars
[0], '-');
5927 goto display_control
;
5930 /* Handle non-break space and soft hyphen
5931 with the escape glyph. */
5935 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5936 c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
5937 XSETINT (it
->ctl_chars
[1], c
);
5939 goto display_control
;
5946 if (CHAR_BYTE8_P (c
))
5947 /* Display \200 instead of \17777600. */
5948 c
= CHAR_TO_BYTE8 (c
);
5949 len
= sprintf (str
, "%03o", c
);
5951 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5952 for (i
= 0; i
< len
; i
++)
5953 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
5958 /* Set up IT->dpvec and return first character from it. */
5959 it
->dpvec_char_len
= it
->len
;
5960 it
->dpvec
= it
->ctl_chars
;
5961 it
->dpend
= it
->dpvec
+ ctl_len
;
5962 it
->current
.dpvec_index
= 0;
5963 it
->dpvec_face_id
= face_id
;
5964 it
->saved_face_id
= it
->face_id
;
5965 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5969 it
->char_to_display
= c
;
5973 it
->char_to_display
= it
->c
;
5977 /* Adjust face id for a multibyte character. There are no multibyte
5978 character in unibyte text. */
5979 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
5982 && FRAME_WINDOW_P (it
->f
))
5984 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5986 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
5988 /* Automatic composition with glyph-string. */
5989 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
5991 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
5995 EMACS_INT pos
= (it
->s
? -1
5996 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
5997 : IT_CHARPOS (*it
));
6000 if (it
->what
== IT_CHARACTER
)
6001 c
= it
->char_to_display
;
6004 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6008 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6009 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6012 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6017 /* Is this character the last one of a run of characters with
6018 box? If yes, set IT->end_of_box_run_p to 1. */
6022 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6024 int face_id
= underlying_face_id (it
);
6025 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6029 if (face
->box
== FACE_NO_BOX
)
6031 /* If the box comes from face properties in a
6032 display string, check faces in that string. */
6033 int string_face_id
= face_after_it_pos (it
);
6034 it
->end_of_box_run_p
6035 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6038 /* Otherwise, the box comes from the underlying face.
6039 If this is the last string character displayed, check
6040 the next buffer location. */
6041 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6042 && (it
->current
.overlay_string_index
6043 == it
->n_overlay_strings
- 1))
6047 struct text_pos pos
= it
->current
.pos
;
6048 INC_TEXT_POS (pos
, it
->multibyte_p
);
6050 next_face_id
= face_at_buffer_position
6051 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6052 it
->region_end_charpos
, &ignore
,
6053 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6055 it
->end_of_box_run_p
6056 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6063 int face_id
= face_after_it_pos (it
);
6064 it
->end_of_box_run_p
6065 = (face_id
!= it
->face_id
6066 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6070 /* Value is 0 if end of buffer or string reached. */
6075 /* Move IT to the next display element.
6077 RESEAT_P non-zero means if called on a newline in buffer text,
6078 skip to the next visible line start.
6080 Functions get_next_display_element and set_iterator_to_next are
6081 separate because I find this arrangement easier to handle than a
6082 get_next_display_element function that also increments IT's
6083 position. The way it is we can first look at an iterator's current
6084 display element, decide whether it fits on a line, and if it does,
6085 increment the iterator position. The other way around we probably
6086 would either need a flag indicating whether the iterator has to be
6087 incremented the next time, or we would have to implement a
6088 decrement position function which would not be easy to write. */
6091 set_iterator_to_next (struct it
*it
, int reseat_p
)
6093 /* Reset flags indicating start and end of a sequence of characters
6094 with box. Reset them at the start of this function because
6095 moving the iterator to a new position might set them. */
6096 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6100 case GET_FROM_BUFFER
:
6101 /* The current display element of IT is a character from
6102 current_buffer. Advance in the buffer, and maybe skip over
6103 invisible lines that are so because of selective display. */
6104 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6105 reseat_at_next_visible_line_start (it
, 0);
6106 else if (it
->cmp_it
.id
>= 0)
6108 /* We are currently getting glyphs from a composition. */
6113 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6114 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6115 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6117 it
->cmp_it
.from
= it
->cmp_it
.to
;
6122 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6124 it
->end_charpos
, Qnil
);
6127 else if (! it
->cmp_it
.reversed_p
)
6129 /* Composition created while scanning forward. */
6130 /* Update IT's char/byte positions to point to the first
6131 character of the next grapheme cluster, or to the
6132 character visually after the current composition. */
6133 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6134 bidi_move_to_visually_next (&it
->bidi_it
);
6135 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6136 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6138 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6140 /* Proceed to the next grapheme cluster. */
6141 it
->cmp_it
.from
= it
->cmp_it
.to
;
6145 /* No more grapheme clusters in this composition.
6146 Find the next stop position. */
6147 EMACS_INT stop
= it
->end_charpos
;
6148 if (it
->bidi_it
.scan_dir
< 0)
6149 /* Now we are scanning backward and don't know
6152 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6153 IT_BYTEPOS (*it
), stop
, Qnil
);
6158 /* Composition created while scanning backward. */
6159 /* Update IT's char/byte positions to point to the last
6160 character of the previous grapheme cluster, or the
6161 character visually after the current composition. */
6162 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6163 bidi_move_to_visually_next (&it
->bidi_it
);
6164 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6165 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6166 if (it
->cmp_it
.from
> 0)
6168 /* Proceed to the previous grapheme cluster. */
6169 it
->cmp_it
.to
= it
->cmp_it
.from
;
6173 /* No more grapheme clusters in this composition.
6174 Find the next stop position. */
6175 EMACS_INT stop
= it
->end_charpos
;
6176 if (it
->bidi_it
.scan_dir
< 0)
6177 /* Now we are scanning backward and don't know
6180 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6181 IT_BYTEPOS (*it
), stop
, Qnil
);
6187 xassert (it
->len
!= 0);
6191 IT_BYTEPOS (*it
) += it
->len
;
6192 IT_CHARPOS (*it
) += 1;
6196 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6197 /* If this is a new paragraph, determine its base
6198 direction (a.k.a. its base embedding level). */
6199 if (it
->bidi_it
.new_paragraph
)
6200 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6201 bidi_move_to_visually_next (&it
->bidi_it
);
6202 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6203 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6204 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6206 /* As the scan direction was changed, we must
6207 re-compute the stop position for composition. */
6208 EMACS_INT stop
= it
->end_charpos
;
6209 if (it
->bidi_it
.scan_dir
< 0)
6211 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6212 IT_BYTEPOS (*it
), stop
, Qnil
);
6215 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6219 case GET_FROM_C_STRING
:
6220 /* Current display element of IT is from a C string. */
6221 IT_BYTEPOS (*it
) += it
->len
;
6222 IT_CHARPOS (*it
) += 1;
6225 case GET_FROM_DISPLAY_VECTOR
:
6226 /* Current display element of IT is from a display table entry.
6227 Advance in the display table definition. Reset it to null if
6228 end reached, and continue with characters from buffers/
6230 ++it
->current
.dpvec_index
;
6232 /* Restore face of the iterator to what they were before the
6233 display vector entry (these entries may contain faces). */
6234 it
->face_id
= it
->saved_face_id
;
6236 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6238 int recheck_faces
= it
->ellipsis_p
;
6241 it
->method
= GET_FROM_C_STRING
;
6242 else if (STRINGP (it
->string
))
6243 it
->method
= GET_FROM_STRING
;
6246 it
->method
= GET_FROM_BUFFER
;
6247 it
->object
= it
->w
->buffer
;
6251 it
->current
.dpvec_index
= -1;
6253 /* Skip over characters which were displayed via IT->dpvec. */
6254 if (it
->dpvec_char_len
< 0)
6255 reseat_at_next_visible_line_start (it
, 1);
6256 else if (it
->dpvec_char_len
> 0)
6258 if (it
->method
== GET_FROM_STRING
6259 && it
->n_overlay_strings
> 0)
6260 it
->ignore_overlay_strings_at_pos_p
= 1;
6261 it
->len
= it
->dpvec_char_len
;
6262 set_iterator_to_next (it
, reseat_p
);
6265 /* Maybe recheck faces after display vector */
6267 it
->stop_charpos
= IT_CHARPOS (*it
);
6271 case GET_FROM_STRING
:
6272 /* Current display element is a character from a Lisp string. */
6273 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6274 if (it
->cmp_it
.id
>= 0)
6276 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6277 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6278 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6279 it
->cmp_it
.from
= it
->cmp_it
.to
;
6283 composition_compute_stop_pos (&it
->cmp_it
,
6284 IT_STRING_CHARPOS (*it
),
6285 IT_STRING_BYTEPOS (*it
),
6286 it
->end_charpos
, it
->string
);
6291 IT_STRING_BYTEPOS (*it
) += it
->len
;
6292 IT_STRING_CHARPOS (*it
) += 1;
6295 consider_string_end
:
6297 if (it
->current
.overlay_string_index
>= 0)
6299 /* IT->string is an overlay string. Advance to the
6300 next, if there is one. */
6301 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6304 next_overlay_string (it
);
6306 setup_for_ellipsis (it
, 0);
6311 /* IT->string is not an overlay string. If we reached
6312 its end, and there is something on IT->stack, proceed
6313 with what is on the stack. This can be either another
6314 string, this time an overlay string, or a buffer. */
6315 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6319 if (it
->method
== GET_FROM_STRING
)
6320 goto consider_string_end
;
6325 case GET_FROM_IMAGE
:
6326 case GET_FROM_STRETCH
:
6327 /* The position etc with which we have to proceed are on
6328 the stack. The position may be at the end of a string,
6329 if the `display' property takes up the whole string. */
6330 xassert (it
->sp
> 0);
6332 if (it
->method
== GET_FROM_STRING
)
6333 goto consider_string_end
;
6337 /* There are no other methods defined, so this should be a bug. */
6341 xassert (it
->method
!= GET_FROM_STRING
6342 || (STRINGP (it
->string
)
6343 && IT_STRING_CHARPOS (*it
) >= 0));
6346 /* Load IT's display element fields with information about the next
6347 display element which comes from a display table entry or from the
6348 result of translating a control character to one of the forms `^C'
6351 IT->dpvec holds the glyphs to return as characters.
6352 IT->saved_face_id holds the face id before the display vector--it
6353 is restored into IT->face_id in set_iterator_to_next. */
6356 next_element_from_display_vector (struct it
*it
)
6361 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6363 it
->face_id
= it
->saved_face_id
;
6365 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6366 That seemed totally bogus - so I changed it... */
6367 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6369 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6371 it
->c
= GLYPH_CODE_CHAR (gc
);
6372 it
->len
= CHAR_BYTES (it
->c
);
6374 /* The entry may contain a face id to use. Such a face id is
6375 the id of a Lisp face, not a realized face. A face id of
6376 zero means no face is specified. */
6377 if (it
->dpvec_face_id
>= 0)
6378 it
->face_id
= it
->dpvec_face_id
;
6381 EMACS_INT lface_id
= GLYPH_CODE_FACE (gc
);
6383 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6388 /* Display table entry is invalid. Return a space. */
6389 it
->c
= ' ', it
->len
= 1;
6391 /* Don't change position and object of the iterator here. They are
6392 still the values of the character that had this display table
6393 entry or was translated, and that's what we want. */
6394 it
->what
= IT_CHARACTER
;
6399 /* Load IT with the next display element from Lisp string IT->string.
6400 IT->current.string_pos is the current position within the string.
6401 If IT->current.overlay_string_index >= 0, the Lisp string is an
6405 next_element_from_string (struct it
*it
)
6407 struct text_pos position
;
6409 xassert (STRINGP (it
->string
));
6410 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6411 position
= it
->current
.string_pos
;
6413 /* Time to check for invisible text? */
6414 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6415 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6419 /* Since a handler may have changed IT->method, we must
6421 return GET_NEXT_DISPLAY_ELEMENT (it
);
6424 if (it
->current
.overlay_string_index
>= 0)
6426 /* Get the next character from an overlay string. In overlay
6427 strings, There is no field width or padding with spaces to
6429 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6434 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6435 IT_STRING_BYTEPOS (*it
), SCHARS (it
->string
))
6436 && next_element_from_composition (it
))
6440 else if (STRING_MULTIBYTE (it
->string
))
6442 const unsigned char *s
= (SDATA (it
->string
)
6443 + IT_STRING_BYTEPOS (*it
));
6444 it
->c
= string_char_and_length (s
, &it
->len
);
6448 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6454 /* Get the next character from a Lisp string that is not an
6455 overlay string. Such strings come from the mode line, for
6456 example. We may have to pad with spaces, or truncate the
6457 string. See also next_element_from_c_string. */
6458 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6463 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6465 /* Pad with spaces. */
6466 it
->c
= ' ', it
->len
= 1;
6467 CHARPOS (position
) = BYTEPOS (position
) = -1;
6469 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6470 IT_STRING_BYTEPOS (*it
), it
->string_nchars
)
6471 && next_element_from_composition (it
))
6475 else if (STRING_MULTIBYTE (it
->string
))
6477 const unsigned char *s
= (SDATA (it
->string
)
6478 + IT_STRING_BYTEPOS (*it
));
6479 it
->c
= string_char_and_length (s
, &it
->len
);
6483 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6488 /* Record what we have and where it came from. */
6489 it
->what
= IT_CHARACTER
;
6490 it
->object
= it
->string
;
6491 it
->position
= position
;
6496 /* Load IT with next display element from C string IT->s.
6497 IT->string_nchars is the maximum number of characters to return
6498 from the string. IT->end_charpos may be greater than
6499 IT->string_nchars when this function is called, in which case we
6500 may have to return padding spaces. Value is zero if end of string
6501 reached, including padding spaces. */
6504 next_element_from_c_string (struct it
*it
)
6509 it
->what
= IT_CHARACTER
;
6510 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6513 /* IT's position can be greater IT->string_nchars in case a field
6514 width or precision has been specified when the iterator was
6516 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6518 /* End of the game. */
6522 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6524 /* Pad with spaces. */
6525 it
->c
= ' ', it
->len
= 1;
6526 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6528 else if (it
->multibyte_p
)
6529 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6531 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6537 /* Set up IT to return characters from an ellipsis, if appropriate.
6538 The definition of the ellipsis glyphs may come from a display table
6539 entry. This function fills IT with the first glyph from the
6540 ellipsis if an ellipsis is to be displayed. */
6543 next_element_from_ellipsis (struct it
*it
)
6545 if (it
->selective_display_ellipsis_p
)
6546 setup_for_ellipsis (it
, it
->len
);
6549 /* The face at the current position may be different from the
6550 face we find after the invisible text. Remember what it
6551 was in IT->saved_face_id, and signal that it's there by
6552 setting face_before_selective_p. */
6553 it
->saved_face_id
= it
->face_id
;
6554 it
->method
= GET_FROM_BUFFER
;
6555 it
->object
= it
->w
->buffer
;
6556 reseat_at_next_visible_line_start (it
, 1);
6557 it
->face_before_selective_p
= 1;
6560 return GET_NEXT_DISPLAY_ELEMENT (it
);
6564 /* Deliver an image display element. The iterator IT is already
6565 filled with image information (done in handle_display_prop). Value
6570 next_element_from_image (struct it
*it
)
6572 it
->what
= IT_IMAGE
;
6573 it
->ignore_overlay_strings_at_pos_p
= 0;
6578 /* Fill iterator IT with next display element from a stretch glyph
6579 property. IT->object is the value of the text property. Value is
6583 next_element_from_stretch (struct it
*it
)
6585 it
->what
= IT_STRETCH
;
6589 /* Scan forward from CHARPOS in the current buffer, until we find a
6590 stop position > current IT's position. Then handle the stop
6591 position before that. This is called when we bump into a stop
6592 position while reordering bidirectional text. CHARPOS should be
6593 the last previously processed stop_pos (or BEGV, if none were
6594 processed yet) whose position is less that IT's current
6598 handle_stop_backwards (struct it
*it
, EMACS_INT charpos
)
6600 EMACS_INT where_we_are
= IT_CHARPOS (*it
);
6601 struct display_pos save_current
= it
->current
;
6602 struct text_pos save_position
= it
->position
;
6603 struct text_pos pos1
;
6604 EMACS_INT next_stop
;
6606 /* Scan in strict logical order. */
6610 it
->prev_stop
= charpos
;
6611 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
6612 reseat_1 (it
, pos1
, 0);
6613 compute_stop_pos (it
);
6614 /* We must advance forward, right? */
6615 if (it
->stop_charpos
<= it
->prev_stop
)
6617 charpos
= it
->stop_charpos
;
6619 while (charpos
<= where_we_are
);
6621 next_stop
= it
->stop_charpos
;
6622 it
->stop_charpos
= it
->prev_stop
;
6624 it
->current
= save_current
;
6625 it
->position
= save_position
;
6627 it
->stop_charpos
= next_stop
;
6630 /* Load IT with the next display element from current_buffer. Value
6631 is zero if end of buffer reached. IT->stop_charpos is the next
6632 position at which to stop and check for text properties or buffer
6636 next_element_from_buffer (struct it
*it
)
6640 xassert (IT_CHARPOS (*it
) >= BEGV
);
6642 /* With bidi reordering, the character to display might not be the
6643 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
6644 we were reseat()ed to a new buffer position, which is potentially
6645 a different paragraph. */
6646 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6648 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6649 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6650 if (it
->bidi_it
.bytepos
== ZV_BYTE
)
6652 /* Nothing to do, but reset the FIRST_ELT flag, like
6653 bidi_paragraph_init does, because we are not going to
6655 it
->bidi_it
.first_elt
= 0;
6657 else if (it
->bidi_it
.bytepos
== BEGV_BYTE
6658 /* FIXME: Should support all Unicode line separators. */
6659 || FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6660 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')
6662 /* If we are at the beginning of a line, we can produce the
6663 next element right away. */
6664 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6665 bidi_move_to_visually_next (&it
->bidi_it
);
6669 EMACS_INT orig_bytepos
= IT_BYTEPOS (*it
);
6671 /* We need to prime the bidi iterator starting at the line's
6672 beginning, before we will be able to produce the next
6674 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), -1);
6675 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
6676 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6677 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6678 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6681 /* Now return to buffer position where we were asked to
6682 get the next display element, and produce that. */
6683 bidi_move_to_visually_next (&it
->bidi_it
);
6685 while (it
->bidi_it
.bytepos
!= orig_bytepos
6686 && it
->bidi_it
.bytepos
< ZV_BYTE
);
6689 it
->bidi_it
.first_elt
= 0; /* paranoia: bidi.c does this */
6690 /* Adjust IT's position information to where we ended up. */
6691 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6692 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6693 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
6695 EMACS_INT stop
= it
->end_charpos
;
6696 if (it
->bidi_it
.scan_dir
< 0)
6698 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6699 IT_BYTEPOS (*it
), stop
, Qnil
);
6703 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6705 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6707 int overlay_strings_follow_p
;
6709 /* End of the game, except when overlay strings follow that
6710 haven't been returned yet. */
6711 if (it
->overlay_strings_at_end_processed_p
)
6712 overlay_strings_follow_p
= 0;
6715 it
->overlay_strings_at_end_processed_p
= 1;
6716 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6719 if (overlay_strings_follow_p
)
6720 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6724 it
->position
= it
->current
.pos
;
6728 else if (!(!it
->bidi_p
6729 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6730 || IT_CHARPOS (*it
) == it
->stop_charpos
))
6732 /* With bidi non-linear iteration, we could find ourselves
6733 far beyond the last computed stop_charpos, with several
6734 other stop positions in between that we missed. Scan
6735 them all now, in buffer's logical order, until we find
6736 and handle the last stop_charpos that precedes our
6737 current position. */
6738 handle_stop_backwards (it
, it
->stop_charpos
);
6739 return GET_NEXT_DISPLAY_ELEMENT (it
);
6745 /* Take note of the stop position we just moved across,
6746 for when we will move back across it. */
6747 it
->prev_stop
= it
->stop_charpos
;
6748 /* If we are at base paragraph embedding level, take
6749 note of the last stop position seen at this
6751 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6752 it
->base_level_stop
= it
->stop_charpos
;
6755 return GET_NEXT_DISPLAY_ELEMENT (it
);
6759 /* We can sometimes back up for reasons that have nothing
6760 to do with bidi reordering. E.g., compositions. The
6761 code below is only needed when we are above the base
6762 embedding level, so test for that explicitly. */
6763 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6764 && IT_CHARPOS (*it
) < it
->prev_stop
)
6766 if (it
->base_level_stop
<= 0)
6767 it
->base_level_stop
= BEGV
;
6768 if (IT_CHARPOS (*it
) < it
->base_level_stop
)
6770 handle_stop_backwards (it
, it
->base_level_stop
);
6771 return GET_NEXT_DISPLAY_ELEMENT (it
);
6775 /* No face changes, overlays etc. in sight, so just return a
6776 character from current_buffer. */
6780 /* Maybe run the redisplay end trigger hook. Performance note:
6781 This doesn't seem to cost measurable time. */
6782 if (it
->redisplay_end_trigger_charpos
6784 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6785 run_redisplay_end_trigger_hook (it
);
6787 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
6788 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6790 && next_element_from_composition (it
))
6795 /* Get the next character, maybe multibyte. */
6796 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6797 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6798 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
6800 it
->c
= *p
, it
->len
= 1;
6802 /* Record what we have and where it came from. */
6803 it
->what
= IT_CHARACTER
;
6804 it
->object
= it
->w
->buffer
;
6805 it
->position
= it
->current
.pos
;
6807 /* Normally we return the character found above, except when we
6808 really want to return an ellipsis for selective display. */
6813 /* A value of selective > 0 means hide lines indented more
6814 than that number of columns. */
6815 if (it
->selective
> 0
6816 && IT_CHARPOS (*it
) + 1 < ZV
6817 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6818 IT_BYTEPOS (*it
) + 1,
6821 success_p
= next_element_from_ellipsis (it
);
6822 it
->dpvec_char_len
= -1;
6825 else if (it
->c
== '\r' && it
->selective
== -1)
6827 /* A value of selective == -1 means that everything from the
6828 CR to the end of the line is invisible, with maybe an
6829 ellipsis displayed for it. */
6830 success_p
= next_element_from_ellipsis (it
);
6831 it
->dpvec_char_len
= -1;
6836 /* Value is zero if end of buffer reached. */
6837 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6842 /* Run the redisplay end trigger hook for IT. */
6845 run_redisplay_end_trigger_hook (struct it
*it
)
6847 Lisp_Object args
[3];
6849 /* IT->glyph_row should be non-null, i.e. we should be actually
6850 displaying something, or otherwise we should not run the hook. */
6851 xassert (it
->glyph_row
);
6853 /* Set up hook arguments. */
6854 args
[0] = Qredisplay_end_trigger_functions
;
6855 args
[1] = it
->window
;
6856 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6857 it
->redisplay_end_trigger_charpos
= 0;
6859 /* Since we are *trying* to run these functions, don't try to run
6860 them again, even if they get an error. */
6861 it
->w
->redisplay_end_trigger
= Qnil
;
6862 Frun_hook_with_args (3, args
);
6864 /* Notice if it changed the face of the character we are on. */
6865 handle_face_prop (it
);
6869 /* Deliver a composition display element. Unlike the other
6870 next_element_from_XXX, this function is not registered in the array
6871 get_next_element[]. It is called from next_element_from_buffer and
6872 next_element_from_string when necessary. */
6875 next_element_from_composition (struct it
*it
)
6877 it
->what
= IT_COMPOSITION
;
6878 it
->len
= it
->cmp_it
.nbytes
;
6879 if (STRINGP (it
->string
))
6883 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6884 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6887 it
->position
= it
->current
.string_pos
;
6888 it
->object
= it
->string
;
6889 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6890 IT_STRING_BYTEPOS (*it
), it
->string
);
6896 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6897 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6900 if (it
->bidi_it
.new_paragraph
)
6901 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6902 /* Resync the bidi iterator with IT's new position.
6903 FIXME: this doesn't support bidirectional text. */
6904 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
6905 bidi_move_to_visually_next (&it
->bidi_it
);
6909 it
->position
= it
->current
.pos
;
6910 it
->object
= it
->w
->buffer
;
6911 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6912 IT_BYTEPOS (*it
), Qnil
);
6919 /***********************************************************************
6920 Moving an iterator without producing glyphs
6921 ***********************************************************************/
6923 /* Check if iterator is at a position corresponding to a valid buffer
6924 position after some move_it_ call. */
6926 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6927 ((it)->method == GET_FROM_STRING \
6928 ? IT_STRING_CHARPOS (*it) == 0 \
6932 /* Move iterator IT to a specified buffer or X position within one
6933 line on the display without producing glyphs.
6935 OP should be a bit mask including some or all of these bits:
6936 MOVE_TO_X: Stop upon reaching x-position TO_X.
6937 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
6938 Regardless of OP's value, stop upon reaching the end of the display line.
6940 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6941 This means, in particular, that TO_X includes window's horizontal
6944 The return value has several possible values that
6945 say what condition caused the scan to stop:
6947 MOVE_POS_MATCH_OR_ZV
6948 - when TO_POS or ZV was reached.
6951 -when TO_X was reached before TO_POS or ZV were reached.
6954 - when we reached the end of the display area and the line must
6958 - when we reached the end of the display area and the line is
6962 - when we stopped at a line end, i.e. a newline or a CR and selective
6965 static enum move_it_result
6966 move_it_in_display_line_to (struct it
*it
,
6967 EMACS_INT to_charpos
, int to_x
,
6968 enum move_operation_enum op
)
6970 enum move_it_result result
= MOVE_UNDEFINED
;
6971 struct glyph_row
*saved_glyph_row
;
6972 struct it wrap_it
, atpos_it
, atx_it
;
6974 enum it_method prev_method
= it
->method
;
6975 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
6977 /* Don't produce glyphs in produce_glyphs. */
6978 saved_glyph_row
= it
->glyph_row
;
6979 it
->glyph_row
= NULL
;
6981 /* Use wrap_it to save a copy of IT wherever a word wrap could
6982 occur. Use atpos_it to save a copy of IT at the desired buffer
6983 position, if found, so that we can scan ahead and check if the
6984 word later overshoots the window edge. Use atx_it similarly, for
6990 #define BUFFER_POS_REACHED_P() \
6991 ((op & MOVE_TO_POS) != 0 \
6992 && BUFFERP (it->object) \
6993 && (IT_CHARPOS (*it) == to_charpos \
6994 || (!it->bidi_p && IT_CHARPOS (*it) > to_charpos)) \
6995 && (it->method == GET_FROM_BUFFER \
6996 || (it->method == GET_FROM_DISPLAY_VECTOR \
6997 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6999 /* If there's a line-/wrap-prefix, handle it. */
7000 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
7001 && it
->current_y
< it
->last_visible_y
)
7002 handle_line_prefix (it
);
7004 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7005 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7009 int x
, i
, ascent
= 0, descent
= 0;
7011 /* Utility macro to reset an iterator with x, ascent, and descent. */
7012 #define IT_RESET_X_ASCENT_DESCENT(IT) \
7013 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
7014 (IT)->max_descent = descent)
7016 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
7018 if ((op
& MOVE_TO_POS
) != 0
7019 && BUFFERP (it
->object
)
7020 && it
->method
== GET_FROM_BUFFER
7021 && ((!it
->bidi_p
&& IT_CHARPOS (*it
) > to_charpos
)
7023 && (prev_method
== GET_FROM_IMAGE
7024 || prev_method
== GET_FROM_STRETCH
)
7025 /* Passed TO_CHARPOS from left to right. */
7026 && ((prev_pos
< to_charpos
7027 && IT_CHARPOS (*it
) > to_charpos
)
7028 /* Passed TO_CHARPOS from right to left. */
7029 || (prev_pos
> to_charpos
7030 && IT_CHARPOS (*it
) < to_charpos
)))))
7032 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7034 result
= MOVE_POS_MATCH_OR_ZV
;
7037 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7038 /* If wrap_it is valid, the current position might be in a
7039 word that is wrapped. So, save the iterator in
7040 atpos_it and continue to see if wrapping happens. */
7044 prev_method
= it
->method
;
7045 if (it
->method
== GET_FROM_BUFFER
)
7046 prev_pos
= IT_CHARPOS (*it
);
7047 /* Stop when ZV reached.
7048 We used to stop here when TO_CHARPOS reached as well, but that is
7049 too soon if this glyph does not fit on this line. So we handle it
7050 explicitly below. */
7051 if (!get_next_display_element (it
))
7053 result
= MOVE_POS_MATCH_OR_ZV
;
7057 if (it
->line_wrap
== TRUNCATE
)
7059 if (BUFFER_POS_REACHED_P ())
7061 result
= MOVE_POS_MATCH_OR_ZV
;
7067 if (it
->line_wrap
== WORD_WRAP
)
7069 if (IT_DISPLAYING_WHITESPACE (it
))
7073 /* We have reached a glyph that follows one or more
7074 whitespace characters. If the position is
7075 already found, we are done. */
7076 if (atpos_it
.sp
>= 0)
7079 result
= MOVE_POS_MATCH_OR_ZV
;
7085 result
= MOVE_X_REACHED
;
7088 /* Otherwise, we can wrap here. */
7095 /* Remember the line height for the current line, in case
7096 the next element doesn't fit on the line. */
7097 ascent
= it
->max_ascent
;
7098 descent
= it
->max_descent
;
7100 /* The call to produce_glyphs will get the metrics of the
7101 display element IT is loaded with. Record the x-position
7102 before this display element, in case it doesn't fit on the
7106 PRODUCE_GLYPHS (it
);
7108 if (it
->area
!= TEXT_AREA
)
7110 set_iterator_to_next (it
, 1);
7111 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7112 SET_TEXT_POS (this_line_min_pos
,
7113 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7117 /* The number of glyphs we get back in IT->nglyphs will normally
7118 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7119 character on a terminal frame, or (iii) a line end. For the
7120 second case, IT->nglyphs - 1 padding glyphs will be present.
7121 (On X frames, there is only one glyph produced for a
7122 composite character.)
7124 The behavior implemented below means, for continuation lines,
7125 that as many spaces of a TAB as fit on the current line are
7126 displayed there. For terminal frames, as many glyphs of a
7127 multi-glyph character are displayed in the current line, too.
7128 This is what the old redisplay code did, and we keep it that
7129 way. Under X, the whole shape of a complex character must
7130 fit on the line or it will be completely displayed in the
7133 Note that both for tabs and padding glyphs, all glyphs have
7137 /* More than one glyph or glyph doesn't fit on line. All
7138 glyphs have the same width. */
7139 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7141 int x_before_this_char
= x
;
7142 int hpos_before_this_char
= it
->hpos
;
7144 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7146 new_x
= x
+ single_glyph_width
;
7148 /* We want to leave anything reaching TO_X to the caller. */
7149 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7151 if (BUFFER_POS_REACHED_P ())
7153 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7154 goto buffer_pos_reached
;
7155 if (atpos_it
.sp
< 0)
7158 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7163 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7166 result
= MOVE_X_REACHED
;
7172 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7177 if (/* Lines are continued. */
7178 it
->line_wrap
!= TRUNCATE
7179 && (/* And glyph doesn't fit on the line. */
7180 new_x
> it
->last_visible_x
7181 /* Or it fits exactly and we're on a window
7183 || (new_x
== it
->last_visible_x
7184 && FRAME_WINDOW_P (it
->f
))))
7186 if (/* IT->hpos == 0 means the very first glyph
7187 doesn't fit on the line, e.g. a wide image. */
7189 || (new_x
== it
->last_visible_x
7190 && FRAME_WINDOW_P (it
->f
)))
7193 it
->current_x
= new_x
;
7195 /* The character's last glyph just barely fits
7197 if (i
== it
->nglyphs
- 1)
7199 /* If this is the destination position,
7200 return a position *before* it in this row,
7201 now that we know it fits in this row. */
7202 if (BUFFER_POS_REACHED_P ())
7204 if (it
->line_wrap
!= WORD_WRAP
7207 it
->hpos
= hpos_before_this_char
;
7208 it
->current_x
= x_before_this_char
;
7209 result
= MOVE_POS_MATCH_OR_ZV
;
7212 if (it
->line_wrap
== WORD_WRAP
7216 atpos_it
.current_x
= x_before_this_char
;
7217 atpos_it
.hpos
= hpos_before_this_char
;
7221 set_iterator_to_next (it
, 1);
7222 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7223 SET_TEXT_POS (this_line_min_pos
,
7224 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7225 /* On graphical terminals, newlines may
7226 "overflow" into the fringe if
7227 overflow-newline-into-fringe is non-nil.
7228 On text-only terminals, newlines may
7229 overflow into the last glyph on the
7231 if (!FRAME_WINDOW_P (it
->f
)
7232 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7234 if (!get_next_display_element (it
))
7236 result
= MOVE_POS_MATCH_OR_ZV
;
7239 if (BUFFER_POS_REACHED_P ())
7241 if (ITERATOR_AT_END_OF_LINE_P (it
))
7242 result
= MOVE_POS_MATCH_OR_ZV
;
7244 result
= MOVE_LINE_CONTINUED
;
7247 if (ITERATOR_AT_END_OF_LINE_P (it
))
7249 result
= MOVE_NEWLINE_OR_CR
;
7256 IT_RESET_X_ASCENT_DESCENT (it
);
7258 if (wrap_it
.sp
>= 0)
7265 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7267 result
= MOVE_LINE_CONTINUED
;
7271 if (BUFFER_POS_REACHED_P ())
7273 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7274 goto buffer_pos_reached
;
7275 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7278 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7282 if (new_x
> it
->first_visible_x
)
7284 /* Glyph is visible. Increment number of glyphs that
7285 would be displayed. */
7290 if (result
!= MOVE_UNDEFINED
)
7293 else if (BUFFER_POS_REACHED_P ())
7296 IT_RESET_X_ASCENT_DESCENT (it
);
7297 result
= MOVE_POS_MATCH_OR_ZV
;
7300 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7302 /* Stop when TO_X specified and reached. This check is
7303 necessary here because of lines consisting of a line end,
7304 only. The line end will not produce any glyphs and we
7305 would never get MOVE_X_REACHED. */
7306 xassert (it
->nglyphs
== 0);
7307 result
= MOVE_X_REACHED
;
7311 /* Is this a line end? If yes, we're done. */
7312 if (ITERATOR_AT_END_OF_LINE_P (it
))
7314 result
= MOVE_NEWLINE_OR_CR
;
7318 if (it
->method
== GET_FROM_BUFFER
)
7319 prev_pos
= IT_CHARPOS (*it
);
7320 /* The current display element has been consumed. Advance
7322 set_iterator_to_next (it
, 1);
7323 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7324 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7326 /* Stop if lines are truncated and IT's current x-position is
7327 past the right edge of the window now. */
7328 if (it
->line_wrap
== TRUNCATE
7329 && it
->current_x
>= it
->last_visible_x
)
7331 if (!FRAME_WINDOW_P (it
->f
)
7332 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7334 if (!get_next_display_element (it
)
7335 || BUFFER_POS_REACHED_P ())
7337 result
= MOVE_POS_MATCH_OR_ZV
;
7340 if (ITERATOR_AT_END_OF_LINE_P (it
))
7342 result
= MOVE_NEWLINE_OR_CR
;
7346 result
= MOVE_LINE_TRUNCATED
;
7349 #undef IT_RESET_X_ASCENT_DESCENT
7352 #undef BUFFER_POS_REACHED_P
7354 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7355 restore the saved iterator. */
7356 if (atpos_it
.sp
>= 0)
7358 else if (atx_it
.sp
>= 0)
7363 /* Restore the iterator settings altered at the beginning of this
7365 it
->glyph_row
= saved_glyph_row
;
7369 /* For external use. */
7371 move_it_in_display_line (struct it
*it
,
7372 EMACS_INT to_charpos
, int to_x
,
7373 enum move_operation_enum op
)
7375 if (it
->line_wrap
== WORD_WRAP
7376 && (op
& MOVE_TO_X
))
7378 struct it save_it
= *it
;
7379 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7380 /* When word-wrap is on, TO_X may lie past the end
7381 of a wrapped line. Then it->current is the
7382 character on the next line, so backtrack to the
7383 space before the wrap point. */
7384 if (skip
== MOVE_LINE_CONTINUED
)
7386 int prev_x
= max (it
->current_x
- 1, 0);
7388 move_it_in_display_line_to
7389 (it
, -1, prev_x
, MOVE_TO_X
);
7393 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7397 /* Move IT forward until it satisfies one or more of the criteria in
7398 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7400 OP is a bit-mask that specifies where to stop, and in particular,
7401 which of those four position arguments makes a difference. See the
7402 description of enum move_operation_enum.
7404 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7405 screen line, this function will set IT to the next position >
7409 move_it_to (struct it
*it
, EMACS_INT to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
7411 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7412 int line_height
, line_start_x
= 0, reached
= 0;
7416 if (op
& MOVE_TO_VPOS
)
7418 /* If no TO_CHARPOS and no TO_X specified, stop at the
7419 start of the line TO_VPOS. */
7420 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7422 if (it
->vpos
== to_vpos
)
7428 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7432 /* TO_VPOS >= 0 means stop at TO_X in the line at
7433 TO_VPOS, or at TO_POS, whichever comes first. */
7434 if (it
->vpos
== to_vpos
)
7440 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7442 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7447 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7449 /* We have reached TO_X but not in the line we want. */
7450 skip
= move_it_in_display_line_to (it
, to_charpos
,
7452 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7460 else if (op
& MOVE_TO_Y
)
7462 struct it it_backup
;
7464 if (it
->line_wrap
== WORD_WRAP
)
7467 /* TO_Y specified means stop at TO_X in the line containing
7468 TO_Y---or at TO_CHARPOS if this is reached first. The
7469 problem is that we can't really tell whether the line
7470 contains TO_Y before we have completely scanned it, and
7471 this may skip past TO_X. What we do is to first scan to
7474 If TO_X is not specified, use a TO_X of zero. The reason
7475 is to make the outcome of this function more predictable.
7476 If we didn't use TO_X == 0, we would stop at the end of
7477 the line which is probably not what a caller would expect
7479 skip
= move_it_in_display_line_to
7480 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7481 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7483 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7484 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7486 else if (skip
== MOVE_X_REACHED
)
7488 /* If TO_X was reached, we want to know whether TO_Y is
7489 in the line. We know this is the case if the already
7490 scanned glyphs make the line tall enough. Otherwise,
7491 we must check by scanning the rest of the line. */
7492 line_height
= it
->max_ascent
+ it
->max_descent
;
7493 if (to_y
>= it
->current_y
7494 && to_y
< it
->current_y
+ line_height
)
7500 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7501 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7503 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7504 line_height
= it
->max_ascent
+ it
->max_descent
;
7505 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7507 if (to_y
>= it
->current_y
7508 && to_y
< it
->current_y
+ line_height
)
7510 /* If TO_Y is in this line and TO_X was reached
7511 above, we scanned too far. We have to restore
7512 IT's settings to the ones before skipping. */
7519 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7525 /* Check whether TO_Y is in this line. */
7526 line_height
= it
->max_ascent
+ it
->max_descent
;
7527 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7529 if (to_y
>= it
->current_y
7530 && to_y
< it
->current_y
+ line_height
)
7532 /* When word-wrap is on, TO_X may lie past the end
7533 of a wrapped line. Then it->current is the
7534 character on the next line, so backtrack to the
7535 space before the wrap point. */
7536 if (skip
== MOVE_LINE_CONTINUED
7537 && it
->line_wrap
== WORD_WRAP
)
7539 int prev_x
= max (it
->current_x
- 1, 0);
7541 skip
= move_it_in_display_line_to
7542 (it
, -1, prev_x
, MOVE_TO_X
);
7551 else if (BUFFERP (it
->object
)
7552 && (it
->method
== GET_FROM_BUFFER
7553 || it
->method
== GET_FROM_STRETCH
)
7554 && IT_CHARPOS (*it
) >= to_charpos
)
7555 skip
= MOVE_POS_MATCH_OR_ZV
;
7557 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7561 case MOVE_POS_MATCH_OR_ZV
:
7565 case MOVE_NEWLINE_OR_CR
:
7566 set_iterator_to_next (it
, 1);
7567 it
->continuation_lines_width
= 0;
7570 case MOVE_LINE_TRUNCATED
:
7571 it
->continuation_lines_width
= 0;
7572 reseat_at_next_visible_line_start (it
, 0);
7573 if ((op
& MOVE_TO_POS
) != 0
7574 && IT_CHARPOS (*it
) > to_charpos
)
7581 case MOVE_LINE_CONTINUED
:
7582 /* For continued lines ending in a tab, some of the glyphs
7583 associated with the tab are displayed on the current
7584 line. Since it->current_x does not include these glyphs,
7585 we use it->last_visible_x instead. */
7588 it
->continuation_lines_width
+= it
->last_visible_x
;
7589 /* When moving by vpos, ensure that the iterator really
7590 advances to the next line (bug#847, bug#969). Fixme:
7591 do we need to do this in other circumstances? */
7592 if (it
->current_x
!= it
->last_visible_x
7593 && (op
& MOVE_TO_VPOS
)
7594 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7596 line_start_x
= it
->current_x
+ it
->pixel_width
7597 - it
->last_visible_x
;
7598 set_iterator_to_next (it
, 0);
7602 it
->continuation_lines_width
+= it
->current_x
;
7609 /* Reset/increment for the next run. */
7610 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7611 it
->current_x
= line_start_x
;
7614 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7616 last_height
= it
->max_ascent
+ it
->max_descent
;
7617 last_max_ascent
= it
->max_ascent
;
7618 it
->max_ascent
= it
->max_descent
= 0;
7623 /* On text terminals, we may stop at the end of a line in the middle
7624 of a multi-character glyph. If the glyph itself is continued,
7625 i.e. it is actually displayed on the next line, don't treat this
7626 stopping point as valid; move to the next line instead (unless
7627 that brings us offscreen). */
7628 if (!FRAME_WINDOW_P (it
->f
)
7630 && IT_CHARPOS (*it
) == to_charpos
7631 && it
->what
== IT_CHARACTER
7633 && it
->line_wrap
== WINDOW_WRAP
7634 && it
->current_x
== it
->last_visible_x
- 1
7637 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7639 it
->continuation_lines_width
+= it
->current_x
;
7640 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7641 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7643 last_height
= it
->max_ascent
+ it
->max_descent
;
7644 last_max_ascent
= it
->max_ascent
;
7647 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7651 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7653 If DY > 0, move IT backward at least that many pixels. DY = 0
7654 means move IT backward to the preceding line start or BEGV. This
7655 function may move over more than DY pixels if IT->current_y - DY
7656 ends up in the middle of a line; in this case IT->current_y will be
7657 set to the top of the line moved to. */
7660 move_it_vertically_backward (struct it
*it
, int dy
)
7664 EMACS_INT start_pos
;
7669 start_pos
= IT_CHARPOS (*it
);
7671 /* Estimate how many newlines we must move back. */
7672 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7674 /* Set the iterator's position that many lines back. */
7675 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7676 back_to_previous_visible_line_start (it
);
7678 /* Reseat the iterator here. When moving backward, we don't want
7679 reseat to skip forward over invisible text, set up the iterator
7680 to deliver from overlay strings at the new position etc. So,
7681 use reseat_1 here. */
7682 reseat_1 (it
, it
->current
.pos
, 1);
7684 /* We are now surely at a line start. */
7685 it
->current_x
= it
->hpos
= 0;
7686 it
->continuation_lines_width
= 0;
7688 /* Move forward and see what y-distance we moved. First move to the
7689 start of the next line so that we get its height. We need this
7690 height to be able to tell whether we reached the specified
7693 it2
.max_ascent
= it2
.max_descent
= 0;
7696 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7697 MOVE_TO_POS
| MOVE_TO_VPOS
);
7699 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7700 xassert (IT_CHARPOS (*it
) >= BEGV
);
7703 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7704 xassert (IT_CHARPOS (*it
) >= BEGV
);
7705 /* H is the actual vertical distance from the position in *IT
7706 and the starting position. */
7707 h
= it2
.current_y
- it
->current_y
;
7708 /* NLINES is the distance in number of lines. */
7709 nlines
= it2
.vpos
- it
->vpos
;
7711 /* Correct IT's y and vpos position
7712 so that they are relative to the starting point. */
7718 /* DY == 0 means move to the start of the screen line. The
7719 value of nlines is > 0 if continuation lines were involved. */
7721 move_it_by_lines (it
, nlines
);
7725 /* The y-position we try to reach, relative to *IT.
7726 Note that H has been subtracted in front of the if-statement. */
7727 int target_y
= it
->current_y
+ h
- dy
;
7728 int y0
= it3
.current_y
;
7729 int y1
= line_bottom_y (&it3
);
7730 int line_height
= y1
- y0
;
7732 /* If we did not reach target_y, try to move further backward if
7733 we can. If we moved too far backward, try to move forward. */
7734 if (target_y
< it
->current_y
7735 /* This is heuristic. In a window that's 3 lines high, with
7736 a line height of 13 pixels each, recentering with point
7737 on the bottom line will try to move -39/2 = 19 pixels
7738 backward. Try to avoid moving into the first line. */
7739 && (it
->current_y
- target_y
7740 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7741 && IT_CHARPOS (*it
) > BEGV
)
7743 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7744 target_y
- it
->current_y
));
7745 dy
= it
->current_y
- target_y
;
7746 goto move_further_back
;
7748 else if (target_y
>= it
->current_y
+ line_height
7749 && IT_CHARPOS (*it
) < ZV
)
7751 /* Should move forward by at least one line, maybe more.
7753 Note: Calling move_it_by_lines can be expensive on
7754 terminal frames, where compute_motion is used (via
7755 vmotion) to do the job, when there are very long lines
7756 and truncate-lines is nil. That's the reason for
7757 treating terminal frames specially here. */
7759 if (!FRAME_WINDOW_P (it
->f
))
7760 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7765 move_it_by_lines (it
, 1);
7767 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7774 /* Move IT by a specified amount of pixel lines DY. DY negative means
7775 move backwards. DY = 0 means move to start of screen line. At the
7776 end, IT will be on the start of a screen line. */
7779 move_it_vertically (struct it
*it
, int dy
)
7782 move_it_vertically_backward (it
, -dy
);
7785 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7786 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7787 MOVE_TO_POS
| MOVE_TO_Y
);
7788 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7790 /* If buffer ends in ZV without a newline, move to the start of
7791 the line to satisfy the post-condition. */
7792 if (IT_CHARPOS (*it
) == ZV
7794 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7795 move_it_by_lines (it
, 0);
7800 /* Move iterator IT past the end of the text line it is in. */
7803 move_it_past_eol (struct it
*it
)
7805 enum move_it_result rc
;
7807 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7808 if (rc
== MOVE_NEWLINE_OR_CR
)
7809 set_iterator_to_next (it
, 0);
7813 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7814 negative means move up. DVPOS == 0 means move to the start of the
7817 Optimization idea: If we would know that IT->f doesn't use
7818 a face with proportional font, we could be faster for
7819 truncate-lines nil. */
7822 move_it_by_lines (struct it
*it
, int dvpos
)
7825 /* The commented-out optimization uses vmotion on terminals. This
7826 gives bad results, because elements like it->what, on which
7827 callers such as pos_visible_p rely, aren't updated. */
7828 /* struct position pos;
7829 if (!FRAME_WINDOW_P (it->f))
7831 struct text_pos textpos;
7833 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7834 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7835 reseat (it, textpos, 1);
7836 it->vpos += pos.vpos;
7837 it->current_y += pos.vpos;
7843 /* DVPOS == 0 means move to the start of the screen line. */
7844 move_it_vertically_backward (it
, 0);
7845 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7846 /* Let next call to line_bottom_y calculate real line height */
7851 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7852 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7853 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7858 EMACS_INT start_charpos
, i
;
7860 /* Start at the beginning of the screen line containing IT's
7861 position. This may actually move vertically backwards,
7862 in case of overlays, so adjust dvpos accordingly. */
7864 move_it_vertically_backward (it
, 0);
7867 /* Go back -DVPOS visible lines and reseat the iterator there. */
7868 start_charpos
= IT_CHARPOS (*it
);
7869 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7870 back_to_previous_visible_line_start (it
);
7871 reseat (it
, it
->current
.pos
, 1);
7873 /* Move further back if we end up in a string or an image. */
7874 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7876 /* First try to move to start of display line. */
7878 move_it_vertically_backward (it
, 0);
7880 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7882 /* If start of line is still in string or image,
7883 move further back. */
7884 back_to_previous_visible_line_start (it
);
7885 reseat (it
, it
->current
.pos
, 1);
7889 it
->current_x
= it
->hpos
= 0;
7891 /* Above call may have moved too far if continuation lines
7892 are involved. Scan forward and see if it did. */
7894 it2
.vpos
= it2
.current_y
= 0;
7895 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7896 it
->vpos
-= it2
.vpos
;
7897 it
->current_y
-= it2
.current_y
;
7898 it
->current_x
= it
->hpos
= 0;
7900 /* If we moved too far back, move IT some lines forward. */
7901 if (it2
.vpos
> -dvpos
)
7903 int delta
= it2
.vpos
+ dvpos
;
7905 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7906 /* Move back again if we got too far ahead. */
7907 if (IT_CHARPOS (*it
) >= start_charpos
)
7913 /* Return 1 if IT points into the middle of a display vector. */
7916 in_display_vector_p (struct it
*it
)
7918 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7919 && it
->current
.dpvec_index
> 0
7920 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7924 /***********************************************************************
7926 ***********************************************************************/
7929 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7933 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
7935 Lisp_Object args
[3];
7936 Lisp_Object msg
, fmt
;
7939 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7942 /* Do nothing if called asynchronously. Inserting text into
7943 a buffer may call after-change-functions and alike and
7944 that would means running Lisp asynchronously. */
7945 if (handling_signal
)
7949 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7951 args
[0] = fmt
= build_string (format
);
7954 msg
= Fformat (3, args
);
7956 len
= SBYTES (msg
) + 1;
7957 SAFE_ALLOCA (buffer
, char *, len
);
7958 memcpy (buffer
, SDATA (msg
), len
);
7960 message_dolog (buffer
, len
- 1, 1, 0);
7967 /* Output a newline in the *Messages* buffer if "needs" one. */
7970 message_log_maybe_newline (void)
7972 if (message_log_need_newline
)
7973 message_dolog ("", 0, 1, 0);
7977 /* Add a string M of length NBYTES to the message log, optionally
7978 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7979 nonzero, means interpret the contents of M as multibyte. This
7980 function calls low-level routines in order to bypass text property
7981 hooks, etc. which might not be safe to run.
7983 This may GC (insert may run before/after change hooks),
7984 so the buffer M must NOT point to a Lisp string. */
7987 message_dolog (const char *m
, EMACS_INT nbytes
, int nlflag
, int multibyte
)
7989 const unsigned char *msg
= (const unsigned char *) m
;
7991 if (!NILP (Vmemory_full
))
7994 if (!NILP (Vmessage_log_max
))
7996 struct buffer
*oldbuf
;
7997 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7998 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7999 EMACS_INT point_at_end
= 0;
8000 EMACS_INT zv_at_end
= 0;
8001 Lisp_Object old_deactivate_mark
, tem
;
8002 struct gcpro gcpro1
;
8004 old_deactivate_mark
= Vdeactivate_mark
;
8005 oldbuf
= current_buffer
;
8006 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
8007 BVAR (current_buffer
, undo_list
) = Qt
;
8009 oldpoint
= message_dolog_marker1
;
8010 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
8011 oldbegv
= message_dolog_marker2
;
8012 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
8013 oldzv
= message_dolog_marker3
;
8014 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
8015 GCPRO1 (old_deactivate_mark
);
8023 BEGV_BYTE
= BEG_BYTE
;
8026 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8028 /* Insert the string--maybe converting multibyte to single byte
8029 or vice versa, so that all the text fits the buffer. */
8031 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8037 /* Convert a multibyte string to single-byte
8038 for the *Message* buffer. */
8039 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
8041 c
= string_char_and_length (msg
+ i
, &char_bytes
);
8042 work
[0] = (ASCII_CHAR_P (c
)
8044 : multibyte_char_to_unibyte (c
));
8045 insert_1_both (work
, 1, 1, 1, 0, 0);
8048 else if (! multibyte
8049 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8053 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8054 /* Convert a single-byte string to multibyte
8055 for the *Message* buffer. */
8056 for (i
= 0; i
< nbytes
; i
++)
8059 MAKE_CHAR_MULTIBYTE (c
);
8060 char_bytes
= CHAR_STRING (c
, str
);
8061 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
8065 insert_1 (m
, nbytes
, 1, 0, 0);
8069 EMACS_INT this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
8071 insert_1 ("\n", 1, 1, 0, 0);
8073 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8075 this_bol_byte
= PT_BYTE
;
8077 /* See if this line duplicates the previous one.
8078 If so, combine duplicates. */
8081 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8083 prev_bol_byte
= PT_BYTE
;
8085 dups
= message_log_check_duplicate (prev_bol_byte
,
8089 del_range_both (prev_bol
, prev_bol_byte
,
8090 this_bol
, this_bol_byte
, 0);
8093 char dupstr
[sizeof " [ times]"
8094 + INT_STRLEN_BOUND (printmax_t
)];
8097 /* If you change this format, don't forget to also
8098 change message_log_check_duplicate. */
8099 sprintf (dupstr
, " [%"pMd
" times]", dups
);
8100 duplen
= strlen (dupstr
);
8101 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8102 insert_1 (dupstr
, duplen
, 1, 0, 1);
8107 /* If we have more than the desired maximum number of lines
8108 in the *Messages* buffer now, delete the oldest ones.
8109 This is safe because we don't have undo in this buffer. */
8111 if (NATNUMP (Vmessage_log_max
))
8113 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8114 -XFASTINT (Vmessage_log_max
) - 1, 0);
8115 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8118 BEGV
= XMARKER (oldbegv
)->charpos
;
8119 BEGV_BYTE
= marker_byte_position (oldbegv
);
8128 ZV
= XMARKER (oldzv
)->charpos
;
8129 ZV_BYTE
= marker_byte_position (oldzv
);
8133 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8135 /* We can't do Fgoto_char (oldpoint) because it will run some
8137 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8138 XMARKER (oldpoint
)->bytepos
);
8141 unchain_marker (XMARKER (oldpoint
));
8142 unchain_marker (XMARKER (oldbegv
));
8143 unchain_marker (XMARKER (oldzv
));
8145 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8146 set_buffer_internal (oldbuf
);
8148 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8149 message_log_need_newline
= !nlflag
;
8150 Vdeactivate_mark
= old_deactivate_mark
;
8155 /* We are at the end of the buffer after just having inserted a newline.
8156 (Note: We depend on the fact we won't be crossing the gap.)
8157 Check to see if the most recent message looks a lot like the previous one.
8158 Return 0 if different, 1 if the new one should just replace it, or a
8159 value N > 1 if we should also append " [N times]". */
8162 message_log_check_duplicate (EMACS_INT prev_bol_byte
, EMACS_INT this_bol_byte
)
8165 EMACS_INT len
= Z_BYTE
- 1 - this_bol_byte
;
8167 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8168 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8170 for (i
= 0; i
< len
; i
++)
8172 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8180 if (*p1
++ == ' ' && *p1
++ == '[')
8183 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
8184 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
8191 /* Display an echo area message M with a specified length of NBYTES
8192 bytes. The string may include null characters. If M is 0, clear
8193 out any existing message, and let the mini-buffer text show
8196 This may GC, so the buffer M must NOT point to a Lisp string. */
8199 message2 (const char *m
, EMACS_INT nbytes
, int multibyte
)
8201 /* First flush out any partial line written with print. */
8202 message_log_maybe_newline ();
8204 message_dolog (m
, nbytes
, 1, multibyte
);
8205 message2_nolog (m
, nbytes
, multibyte
);
8209 /* The non-logging counterpart of message2. */
8212 message2_nolog (const char *m
, EMACS_INT nbytes
, int multibyte
)
8214 struct frame
*sf
= SELECTED_FRAME ();
8215 message_enable_multibyte
= multibyte
;
8217 if (FRAME_INITIAL_P (sf
))
8219 if (noninteractive_need_newline
)
8220 putc ('\n', stderr
);
8221 noninteractive_need_newline
= 0;
8223 fwrite (m
, nbytes
, 1, stderr
);
8224 if (cursor_in_echo_area
== 0)
8225 fprintf (stderr
, "\n");
8228 /* A null message buffer means that the frame hasn't really been
8229 initialized yet. Error messages get reported properly by
8230 cmd_error, so this must be just an informative message; toss it. */
8231 else if (INTERACTIVE
8232 && sf
->glyphs_initialized_p
8233 && FRAME_MESSAGE_BUF (sf
))
8235 Lisp_Object mini_window
;
8238 /* Get the frame containing the mini-buffer
8239 that the selected frame is using. */
8240 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8241 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8243 FRAME_SAMPLE_VISIBILITY (f
);
8244 if (FRAME_VISIBLE_P (sf
)
8245 && ! FRAME_VISIBLE_P (f
))
8246 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8250 set_message (m
, Qnil
, nbytes
, multibyte
);
8251 if (minibuffer_auto_raise
)
8252 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8255 clear_message (1, 1);
8257 do_pending_window_change (0);
8258 echo_area_display (1);
8259 do_pending_window_change (0);
8260 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8261 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8266 /* Display an echo area message M with a specified length of NBYTES
8267 bytes. The string may include null characters. If M is not a
8268 string, clear out any existing message, and let the mini-buffer
8271 This function cancels echoing. */
8274 message3 (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8276 struct gcpro gcpro1
;
8279 clear_message (1,1);
8282 /* First flush out any partial line written with print. */
8283 message_log_maybe_newline ();
8289 SAFE_ALLOCA (buffer
, char *, nbytes
);
8290 memcpy (buffer
, SDATA (m
), nbytes
);
8291 message_dolog (buffer
, nbytes
, 1, multibyte
);
8294 message3_nolog (m
, nbytes
, multibyte
);
8300 /* The non-logging version of message3.
8301 This does not cancel echoing, because it is used for echoing.
8302 Perhaps we need to make a separate function for echoing
8303 and make this cancel echoing. */
8306 message3_nolog (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8308 struct frame
*sf
= SELECTED_FRAME ();
8309 message_enable_multibyte
= multibyte
;
8311 if (FRAME_INITIAL_P (sf
))
8313 if (noninteractive_need_newline
)
8314 putc ('\n', stderr
);
8315 noninteractive_need_newline
= 0;
8317 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8318 if (cursor_in_echo_area
== 0)
8319 fprintf (stderr
, "\n");
8322 /* A null message buffer means that the frame hasn't really been
8323 initialized yet. Error messages get reported properly by
8324 cmd_error, so this must be just an informative message; toss it. */
8325 else if (INTERACTIVE
8326 && sf
->glyphs_initialized_p
8327 && FRAME_MESSAGE_BUF (sf
))
8329 Lisp_Object mini_window
;
8333 /* Get the frame containing the mini-buffer
8334 that the selected frame is using. */
8335 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8336 frame
= XWINDOW (mini_window
)->frame
;
8339 FRAME_SAMPLE_VISIBILITY (f
);
8340 if (FRAME_VISIBLE_P (sf
)
8341 && !FRAME_VISIBLE_P (f
))
8342 Fmake_frame_visible (frame
);
8344 if (STRINGP (m
) && SCHARS (m
) > 0)
8346 set_message (NULL
, m
, nbytes
, multibyte
);
8347 if (minibuffer_auto_raise
)
8348 Fraise_frame (frame
);
8349 /* Assume we are not echoing.
8350 (If we are, echo_now will override this.) */
8351 echo_message_buffer
= Qnil
;
8354 clear_message (1, 1);
8356 do_pending_window_change (0);
8357 echo_area_display (1);
8358 do_pending_window_change (0);
8359 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8360 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8365 /* Display a null-terminated echo area message M. If M is 0, clear
8366 out any existing message, and let the mini-buffer text show through.
8368 The buffer M must continue to exist until after the echo area gets
8369 cleared or some other message gets displayed there. Do not pass
8370 text that is stored in a Lisp string. Do not pass text in a buffer
8371 that was alloca'd. */
8374 message1 (const char *m
)
8376 message2 (m
, (m
? strlen (m
) : 0), 0);
8380 /* The non-logging counterpart of message1. */
8383 message1_nolog (const char *m
)
8385 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8388 /* Display a message M which contains a single %s
8389 which gets replaced with STRING. */
8392 message_with_string (const char *m
, Lisp_Object string
, int log
)
8394 CHECK_STRING (string
);
8400 if (noninteractive_need_newline
)
8401 putc ('\n', stderr
);
8402 noninteractive_need_newline
= 0;
8403 fprintf (stderr
, m
, SDATA (string
));
8404 if (!cursor_in_echo_area
)
8405 fprintf (stderr
, "\n");
8409 else if (INTERACTIVE
)
8411 /* The frame whose minibuffer we're going to display the message on.
8412 It may be larger than the selected frame, so we need
8413 to use its buffer, not the selected frame's buffer. */
8414 Lisp_Object mini_window
;
8415 struct frame
*f
, *sf
= SELECTED_FRAME ();
8417 /* Get the frame containing the minibuffer
8418 that the selected frame is using. */
8419 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8420 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8422 /* A null message buffer means that the frame hasn't really been
8423 initialized yet. Error messages get reported properly by
8424 cmd_error, so this must be just an informative message; toss it. */
8425 if (FRAME_MESSAGE_BUF (f
))
8427 Lisp_Object args
[2], msg
;
8428 struct gcpro gcpro1
, gcpro2
;
8430 args
[0] = build_string (m
);
8431 args
[1] = msg
= string
;
8432 GCPRO2 (args
[0], msg
);
8435 msg
= Fformat (2, args
);
8438 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8440 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8444 /* Print should start at the beginning of the message
8445 buffer next time. */
8446 message_buf_print
= 0;
8452 /* Dump an informative message to the minibuf. If M is 0, clear out
8453 any existing message, and let the mini-buffer text show through. */
8456 vmessage (const char *m
, va_list ap
)
8462 if (noninteractive_need_newline
)
8463 putc ('\n', stderr
);
8464 noninteractive_need_newline
= 0;
8465 vfprintf (stderr
, m
, ap
);
8466 if (cursor_in_echo_area
== 0)
8467 fprintf (stderr
, "\n");
8471 else if (INTERACTIVE
)
8473 /* The frame whose mini-buffer we're going to display the message
8474 on. It may be larger than the selected frame, so we need to
8475 use its buffer, not the selected frame's buffer. */
8476 Lisp_Object mini_window
;
8477 struct frame
*f
, *sf
= SELECTED_FRAME ();
8479 /* Get the frame containing the mini-buffer
8480 that the selected frame is using. */
8481 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8482 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8484 /* A null message buffer means that the frame hasn't really been
8485 initialized yet. Error messages get reported properly by
8486 cmd_error, so this must be just an informative message; toss
8488 if (FRAME_MESSAGE_BUF (f
))
8494 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8495 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
8497 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8502 /* Print should start at the beginning of the message
8503 buffer next time. */
8504 message_buf_print
= 0;
8510 message (const char *m
, ...)
8520 /* The non-logging version of message. */
8523 message_nolog (const char *m
, ...)
8525 Lisp_Object old_log_max
;
8528 old_log_max
= Vmessage_log_max
;
8529 Vmessage_log_max
= Qnil
;
8531 Vmessage_log_max
= old_log_max
;
8537 /* Display the current message in the current mini-buffer. This is
8538 only called from error handlers in process.c, and is not time
8542 update_echo_area (void)
8544 if (!NILP (echo_area_buffer
[0]))
8547 string
= Fcurrent_message ();
8548 message3 (string
, SBYTES (string
),
8549 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
8554 /* Make sure echo area buffers in `echo_buffers' are live.
8555 If they aren't, make new ones. */
8558 ensure_echo_area_buffers (void)
8562 for (i
= 0; i
< 2; ++i
)
8563 if (!BUFFERP (echo_buffer
[i
])
8564 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
8567 Lisp_Object old_buffer
;
8570 old_buffer
= echo_buffer
[i
];
8571 sprintf (name
, " *Echo Area %d*", i
);
8572 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8573 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
8574 /* to force word wrap in echo area -
8575 it was decided to postpone this*/
8576 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8578 for (j
= 0; j
< 2; ++j
)
8579 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8580 echo_area_buffer
[j
] = echo_buffer
[i
];
8585 /* Call FN with args A1..A4 with either the current or last displayed
8586 echo_area_buffer as current buffer.
8588 WHICH zero means use the current message buffer
8589 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8590 from echo_buffer[] and clear it.
8592 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8593 suitable buffer from echo_buffer[] and clear it.
8595 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8596 that the current message becomes the last displayed one, make
8597 choose a suitable buffer for echo_area_buffer[0], and clear it.
8599 Value is what FN returns. */
8602 with_echo_area_buffer (struct window
*w
, int which
,
8603 int (*fn
) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
8604 EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
8607 int this_one
, the_other
, clear_buffer_p
, rc
;
8608 int count
= SPECPDL_INDEX ();
8610 /* If buffers aren't live, make new ones. */
8611 ensure_echo_area_buffers ();
8616 this_one
= 0, the_other
= 1;
8618 this_one
= 1, the_other
= 0;
8621 this_one
= 0, the_other
= 1;
8624 /* We need a fresh one in case the current echo buffer equals
8625 the one containing the last displayed echo area message. */
8626 if (!NILP (echo_area_buffer
[this_one
])
8627 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8628 echo_area_buffer
[this_one
] = Qnil
;
8631 /* Choose a suitable buffer from echo_buffer[] is we don't
8633 if (NILP (echo_area_buffer
[this_one
]))
8635 echo_area_buffer
[this_one
]
8636 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8637 ? echo_buffer
[the_other
]
8638 : echo_buffer
[this_one
]);
8642 buffer
= echo_area_buffer
[this_one
];
8644 /* Don't get confused by reusing the buffer used for echoing
8645 for a different purpose. */
8646 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8649 record_unwind_protect (unwind_with_echo_area_buffer
,
8650 with_echo_area_buffer_unwind_data (w
));
8652 /* Make the echo area buffer current. Note that for display
8653 purposes, it is not necessary that the displayed window's buffer
8654 == current_buffer, except for text property lookup. So, let's
8655 only set that buffer temporarily here without doing a full
8656 Fset_window_buffer. We must also change w->pointm, though,
8657 because otherwise an assertions in unshow_buffer fails, and Emacs
8659 set_buffer_internal_1 (XBUFFER (buffer
));
8663 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8666 BVAR (current_buffer
, undo_list
) = Qt
;
8667 BVAR (current_buffer
, read_only
) = Qnil
;
8668 specbind (Qinhibit_read_only
, Qt
);
8669 specbind (Qinhibit_modification_hooks
, Qt
);
8671 if (clear_buffer_p
&& Z
> BEG
)
8674 xassert (BEGV
>= BEG
);
8675 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8677 rc
= fn (a1
, a2
, a3
, a4
);
8679 xassert (BEGV
>= BEG
);
8680 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8682 unbind_to (count
, Qnil
);
8687 /* Save state that should be preserved around the call to the function
8688 FN called in with_echo_area_buffer. */
8691 with_echo_area_buffer_unwind_data (struct window
*w
)
8694 Lisp_Object vector
, tmp
;
8696 /* Reduce consing by keeping one vector in
8697 Vwith_echo_area_save_vector. */
8698 vector
= Vwith_echo_area_save_vector
;
8699 Vwith_echo_area_save_vector
= Qnil
;
8702 vector
= Fmake_vector (make_number (7), Qnil
);
8704 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8705 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8706 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8710 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8711 ASET (vector
, i
, w
->buffer
); ++i
;
8712 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8713 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8718 for (; i
< end
; ++i
)
8719 ASET (vector
, i
, Qnil
);
8722 xassert (i
== ASIZE (vector
));
8727 /* Restore global state from VECTOR which was created by
8728 with_echo_area_buffer_unwind_data. */
8731 unwind_with_echo_area_buffer (Lisp_Object vector
)
8733 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8734 Vdeactivate_mark
= AREF (vector
, 1);
8735 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8737 if (WINDOWP (AREF (vector
, 3)))
8740 Lisp_Object buffer
, charpos
, bytepos
;
8742 w
= XWINDOW (AREF (vector
, 3));
8743 buffer
= AREF (vector
, 4);
8744 charpos
= AREF (vector
, 5);
8745 bytepos
= AREF (vector
, 6);
8748 set_marker_both (w
->pointm
, buffer
,
8749 XFASTINT (charpos
), XFASTINT (bytepos
));
8752 Vwith_echo_area_save_vector
= vector
;
8757 /* Set up the echo area for use by print functions. MULTIBYTE_P
8758 non-zero means we will print multibyte. */
8761 setup_echo_area_for_printing (int multibyte_p
)
8763 /* If we can't find an echo area any more, exit. */
8764 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8767 ensure_echo_area_buffers ();
8769 if (!message_buf_print
)
8771 /* A message has been output since the last time we printed.
8772 Choose a fresh echo area buffer. */
8773 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8774 echo_area_buffer
[0] = echo_buffer
[1];
8776 echo_area_buffer
[0] = echo_buffer
[0];
8778 /* Switch to that buffer and clear it. */
8779 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8780 BVAR (current_buffer
, truncate_lines
) = Qnil
;
8784 int count
= SPECPDL_INDEX ();
8785 specbind (Qinhibit_read_only
, Qt
);
8786 /* Note that undo recording is always disabled. */
8788 unbind_to (count
, Qnil
);
8790 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8792 /* Set up the buffer for the multibyteness we need. */
8794 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8795 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8797 /* Raise the frame containing the echo area. */
8798 if (minibuffer_auto_raise
)
8800 struct frame
*sf
= SELECTED_FRAME ();
8801 Lisp_Object mini_window
;
8802 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8803 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8806 message_log_maybe_newline ();
8807 message_buf_print
= 1;
8811 if (NILP (echo_area_buffer
[0]))
8813 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8814 echo_area_buffer
[0] = echo_buffer
[1];
8816 echo_area_buffer
[0] = echo_buffer
[0];
8819 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8821 /* Someone switched buffers between print requests. */
8822 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8823 BVAR (current_buffer
, truncate_lines
) = Qnil
;
8829 /* Display an echo area message in window W. Value is non-zero if W's
8830 height is changed. If display_last_displayed_message_p is
8831 non-zero, display the message that was last displayed, otherwise
8832 display the current message. */
8835 display_echo_area (struct window
*w
)
8837 int i
, no_message_p
, window_height_changed_p
, count
;
8839 /* Temporarily disable garbage collections while displaying the echo
8840 area. This is done because a GC can print a message itself.
8841 That message would modify the echo area buffer's contents while a
8842 redisplay of the buffer is going on, and seriously confuse
8844 count
= inhibit_garbage_collection ();
8846 /* If there is no message, we must call display_echo_area_1
8847 nevertheless because it resizes the window. But we will have to
8848 reset the echo_area_buffer in question to nil at the end because
8849 with_echo_area_buffer will sets it to an empty buffer. */
8850 i
= display_last_displayed_message_p
? 1 : 0;
8851 no_message_p
= NILP (echo_area_buffer
[i
]);
8853 window_height_changed_p
8854 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8855 display_echo_area_1
,
8856 (intptr_t) w
, Qnil
, 0, 0);
8859 echo_area_buffer
[i
] = Qnil
;
8861 unbind_to (count
, Qnil
);
8862 return window_height_changed_p
;
8866 /* Helper for display_echo_area. Display the current buffer which
8867 contains the current echo area message in window W, a mini-window,
8868 a pointer to which is passed in A1. A2..A4 are currently not used.
8869 Change the height of W so that all of the message is displayed.
8870 Value is non-zero if height of W was changed. */
8873 display_echo_area_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
8876 struct window
*w
= (struct window
*) i1
;
8878 struct text_pos start
;
8879 int window_height_changed_p
= 0;
8881 /* Do this before displaying, so that we have a large enough glyph
8882 matrix for the display. If we can't get enough space for the
8883 whole text, display the last N lines. That works by setting w->start. */
8884 window_height_changed_p
= resize_mini_window (w
, 0);
8886 /* Use the starting position chosen by resize_mini_window. */
8887 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8890 clear_glyph_matrix (w
->desired_matrix
);
8891 XSETWINDOW (window
, w
);
8892 try_window (window
, start
, 0);
8894 return window_height_changed_p
;
8898 /* Resize the echo area window to exactly the size needed for the
8899 currently displayed message, if there is one. If a mini-buffer
8900 is active, don't shrink it. */
8903 resize_echo_area_exactly (void)
8905 if (BUFFERP (echo_area_buffer
[0])
8906 && WINDOWP (echo_area_window
))
8908 struct window
*w
= XWINDOW (echo_area_window
);
8910 Lisp_Object resize_exactly
;
8912 if (minibuf_level
== 0)
8913 resize_exactly
= Qt
;
8915 resize_exactly
= Qnil
;
8917 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8918 (intptr_t) w
, resize_exactly
,
8922 ++windows_or_buffers_changed
;
8923 ++update_mode_lines
;
8924 redisplay_internal ();
8930 /* Callback function for with_echo_area_buffer, when used from
8931 resize_echo_area_exactly. A1 contains a pointer to the window to
8932 resize, EXACTLY non-nil means resize the mini-window exactly to the
8933 size of the text displayed. A3 and A4 are not used. Value is what
8934 resize_mini_window returns. */
8937 resize_mini_window_1 (EMACS_INT a1
, Lisp_Object exactly
, EMACS_INT a3
, EMACS_INT a4
)
8940 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
8944 /* Resize mini-window W to fit the size of its contents. EXACT_P
8945 means size the window exactly to the size needed. Otherwise, it's
8946 only enlarged until W's buffer is empty.
8948 Set W->start to the right place to begin display. If the whole
8949 contents fit, start at the beginning. Otherwise, start so as
8950 to make the end of the contents appear. This is particularly
8951 important for y-or-n-p, but seems desirable generally.
8953 Value is non-zero if the window height has been changed. */
8956 resize_mini_window (struct window
*w
, int exact_p
)
8958 struct frame
*f
= XFRAME (w
->frame
);
8959 int window_height_changed_p
= 0;
8961 xassert (MINI_WINDOW_P (w
));
8963 /* By default, start display at the beginning. */
8964 set_marker_both (w
->start
, w
->buffer
,
8965 BUF_BEGV (XBUFFER (w
->buffer
)),
8966 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8968 /* Don't resize windows while redisplaying a window; it would
8969 confuse redisplay functions when the size of the window they are
8970 displaying changes from under them. Such a resizing can happen,
8971 for instance, when which-func prints a long message while
8972 we are running fontification-functions. We're running these
8973 functions with safe_call which binds inhibit-redisplay to t. */
8974 if (!NILP (Vinhibit_redisplay
))
8977 /* Nil means don't try to resize. */
8978 if (NILP (Vresize_mini_windows
)
8979 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8982 if (!FRAME_MINIBUF_ONLY_P (f
))
8985 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8986 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8987 int height
, max_height
;
8988 int unit
= FRAME_LINE_HEIGHT (f
);
8989 struct text_pos start
;
8990 struct buffer
*old_current_buffer
= NULL
;
8992 if (current_buffer
!= XBUFFER (w
->buffer
))
8994 old_current_buffer
= current_buffer
;
8995 set_buffer_internal (XBUFFER (w
->buffer
));
8998 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9000 /* Compute the max. number of lines specified by the user. */
9001 if (FLOATP (Vmax_mini_window_height
))
9002 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
9003 else if (INTEGERP (Vmax_mini_window_height
))
9004 max_height
= XINT (Vmax_mini_window_height
);
9006 max_height
= total_height
/ 4;
9008 /* Correct that max. height if it's bogus. */
9009 max_height
= max (1, max_height
);
9010 max_height
= min (total_height
, max_height
);
9012 /* Find out the height of the text in the window. */
9013 if (it
.line_wrap
== TRUNCATE
)
9018 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
9019 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
9020 height
= it
.current_y
+ last_height
;
9022 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9023 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9024 height
= (height
+ unit
- 1) / unit
;
9027 /* Compute a suitable window start. */
9028 if (height
> max_height
)
9030 height
= max_height
;
9031 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9032 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9033 start
= it
.current
.pos
;
9036 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9037 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9039 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9041 /* Let it grow only, until we display an empty message, in which
9042 case the window shrinks again. */
9043 if (height
> WINDOW_TOTAL_LINES (w
))
9045 int old_height
= WINDOW_TOTAL_LINES (w
);
9046 freeze_window_starts (f
, 1);
9047 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9048 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9050 else if (height
< WINDOW_TOTAL_LINES (w
)
9051 && (exact_p
|| BEGV
== ZV
))
9053 int old_height
= WINDOW_TOTAL_LINES (w
);
9054 freeze_window_starts (f
, 0);
9055 shrink_mini_window (w
);
9056 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9061 /* Always resize to exact size needed. */
9062 if (height
> WINDOW_TOTAL_LINES (w
))
9064 int old_height
= WINDOW_TOTAL_LINES (w
);
9065 freeze_window_starts (f
, 1);
9066 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9067 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9069 else if (height
< WINDOW_TOTAL_LINES (w
))
9071 int old_height
= WINDOW_TOTAL_LINES (w
);
9072 freeze_window_starts (f
, 0);
9073 shrink_mini_window (w
);
9077 freeze_window_starts (f
, 1);
9078 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9081 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9085 if (old_current_buffer
)
9086 set_buffer_internal (old_current_buffer
);
9089 return window_height_changed_p
;
9093 /* Value is the current message, a string, or nil if there is no
9097 current_message (void)
9101 if (!BUFFERP (echo_area_buffer
[0]))
9105 with_echo_area_buffer (0, 0, current_message_1
,
9106 (intptr_t) &msg
, Qnil
, 0, 0);
9108 echo_area_buffer
[0] = Qnil
;
9116 current_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9119 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
9122 *msg
= make_buffer_string (BEG
, Z
, 1);
9129 /* Push the current message on Vmessage_stack for later restauration
9130 by restore_message. Value is non-zero if the current message isn't
9131 empty. This is a relatively infrequent operation, so it's not
9132 worth optimizing. */
9138 msg
= current_message ();
9139 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9140 return STRINGP (msg
);
9144 /* Restore message display from the top of Vmessage_stack. */
9147 restore_message (void)
9151 xassert (CONSP (Vmessage_stack
));
9152 msg
= XCAR (Vmessage_stack
);
9154 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9156 message3_nolog (msg
, 0, 0);
9160 /* Handler for record_unwind_protect calling pop_message. */
9163 pop_message_unwind (Lisp_Object dummy
)
9169 /* Pop the top-most entry off Vmessage_stack. */
9174 xassert (CONSP (Vmessage_stack
));
9175 Vmessage_stack
= XCDR (Vmessage_stack
);
9179 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9180 exits. If the stack is not empty, we have a missing pop_message
9184 check_message_stack (void)
9186 if (!NILP (Vmessage_stack
))
9191 /* Truncate to NCHARS what will be displayed in the echo area the next
9192 time we display it---but don't redisplay it now. */
9195 truncate_echo_area (EMACS_INT nchars
)
9198 echo_area_buffer
[0] = Qnil
;
9199 /* A null message buffer means that the frame hasn't really been
9200 initialized yet. Error messages get reported properly by
9201 cmd_error, so this must be just an informative message; toss it. */
9202 else if (!noninteractive
9204 && !NILP (echo_area_buffer
[0]))
9206 struct frame
*sf
= SELECTED_FRAME ();
9207 if (FRAME_MESSAGE_BUF (sf
))
9208 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9213 /* Helper function for truncate_echo_area. Truncate the current
9214 message to at most NCHARS characters. */
9217 truncate_message_1 (EMACS_INT nchars
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9219 if (BEG
+ nchars
< Z
)
9220 del_range (BEG
+ nchars
, Z
);
9222 echo_area_buffer
[0] = Qnil
;
9227 /* Set the current message to a substring of S or STRING.
9229 If STRING is a Lisp string, set the message to the first NBYTES
9230 bytes from STRING. NBYTES zero means use the whole string. If
9231 STRING is multibyte, the message will be displayed multibyte.
9233 If S is not null, set the message to the first LEN bytes of S. LEN
9234 zero means use the whole string. MULTIBYTE_P non-zero means S is
9235 multibyte. Display the message multibyte in that case.
9237 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9238 to t before calling set_message_1 (which calls insert).
9242 set_message (const char *s
, Lisp_Object string
,
9243 EMACS_INT nbytes
, int multibyte_p
)
9245 message_enable_multibyte
9246 = ((s
&& multibyte_p
)
9247 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9249 with_echo_area_buffer (0, -1, set_message_1
,
9250 (intptr_t) s
, string
, nbytes
, multibyte_p
);
9251 message_buf_print
= 0;
9252 help_echo_showing_p
= 0;
9256 /* Helper function for set_message. Arguments have the same meaning
9257 as there, with A1 corresponding to S and A2 corresponding to STRING
9258 This function is called with the echo area buffer being
9262 set_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT nbytes
, EMACS_INT multibyte_p
)
9265 const char *s
= (const char *) i1
;
9266 const unsigned char *msg
= (const unsigned char *) s
;
9267 Lisp_Object string
= a2
;
9269 /* Change multibyteness of the echo buffer appropriately. */
9270 if (message_enable_multibyte
9271 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9272 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9274 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
9275 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
9276 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
9278 /* Insert new message at BEG. */
9279 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9281 if (STRINGP (string
))
9286 nbytes
= SBYTES (string
);
9287 nchars
= string_byte_to_char (string
, nbytes
);
9289 /* This function takes care of single/multibyte conversion. We
9290 just have to ensure that the echo area buffer has the right
9291 setting of enable_multibyte_characters. */
9292 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9297 nbytes
= strlen (s
);
9299 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9301 /* Convert from multi-byte to single-byte. */
9306 /* Convert a multibyte string to single-byte. */
9307 for (i
= 0; i
< nbytes
; i
+= n
)
9309 c
= string_char_and_length (msg
+ i
, &n
);
9310 work
[0] = (ASCII_CHAR_P (c
)
9312 : multibyte_char_to_unibyte (c
));
9313 insert_1_both (work
, 1, 1, 1, 0, 0);
9316 else if (!multibyte_p
9317 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9319 /* Convert from single-byte to multi-byte. */
9322 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9324 /* Convert a single-byte string to multibyte. */
9325 for (i
= 0; i
< nbytes
; i
++)
9328 MAKE_CHAR_MULTIBYTE (c
);
9329 n
= CHAR_STRING (c
, str
);
9330 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
9334 insert_1 (s
, nbytes
, 1, 0, 0);
9341 /* Clear messages. CURRENT_P non-zero means clear the current
9342 message. LAST_DISPLAYED_P non-zero means clear the message
9346 clear_message (int current_p
, int last_displayed_p
)
9350 echo_area_buffer
[0] = Qnil
;
9351 message_cleared_p
= 1;
9354 if (last_displayed_p
)
9355 echo_area_buffer
[1] = Qnil
;
9357 message_buf_print
= 0;
9360 /* Clear garbaged frames.
9362 This function is used where the old redisplay called
9363 redraw_garbaged_frames which in turn called redraw_frame which in
9364 turn called clear_frame. The call to clear_frame was a source of
9365 flickering. I believe a clear_frame is not necessary. It should
9366 suffice in the new redisplay to invalidate all current matrices,
9367 and ensure a complete redisplay of all windows. */
9370 clear_garbaged_frames (void)
9374 Lisp_Object tail
, frame
;
9375 int changed_count
= 0;
9377 FOR_EACH_FRAME (tail
, frame
)
9379 struct frame
*f
= XFRAME (frame
);
9381 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9385 Fredraw_frame (frame
);
9386 f
->force_flush_display_p
= 1;
9388 clear_current_matrices (f
);
9397 ++windows_or_buffers_changed
;
9402 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9403 is non-zero update selected_frame. Value is non-zero if the
9404 mini-windows height has been changed. */
9407 echo_area_display (int update_frame_p
)
9409 Lisp_Object mini_window
;
9412 int window_height_changed_p
= 0;
9413 struct frame
*sf
= SELECTED_FRAME ();
9415 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9416 w
= XWINDOW (mini_window
);
9417 f
= XFRAME (WINDOW_FRAME (w
));
9419 /* Don't display if frame is invisible or not yet initialized. */
9420 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9423 #ifdef HAVE_WINDOW_SYSTEM
9424 /* When Emacs starts, selected_frame may be the initial terminal
9425 frame. If we let this through, a message would be displayed on
9427 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9429 #endif /* HAVE_WINDOW_SYSTEM */
9431 /* Redraw garbaged frames. */
9433 clear_garbaged_frames ();
9435 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9437 echo_area_window
= mini_window
;
9438 window_height_changed_p
= display_echo_area (w
);
9439 w
->must_be_updated_p
= 1;
9441 /* Update the display, unless called from redisplay_internal.
9442 Also don't update the screen during redisplay itself. The
9443 update will happen at the end of redisplay, and an update
9444 here could cause confusion. */
9445 if (update_frame_p
&& !redisplaying_p
)
9449 /* If the display update has been interrupted by pending
9450 input, update mode lines in the frame. Due to the
9451 pending input, it might have been that redisplay hasn't
9452 been called, so that mode lines above the echo area are
9453 garbaged. This looks odd, so we prevent it here. */
9454 if (!display_completed
)
9455 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9457 if (window_height_changed_p
9458 /* Don't do this if Emacs is shutting down. Redisplay
9459 needs to run hooks. */
9460 && !NILP (Vrun_hooks
))
9462 /* Must update other windows. Likewise as in other
9463 cases, don't let this update be interrupted by
9465 int count
= SPECPDL_INDEX ();
9466 specbind (Qredisplay_dont_pause
, Qt
);
9467 windows_or_buffers_changed
= 1;
9468 redisplay_internal ();
9469 unbind_to (count
, Qnil
);
9471 else if (FRAME_WINDOW_P (f
) && n
== 0)
9473 /* Window configuration is the same as before.
9474 Can do with a display update of the echo area,
9475 unless we displayed some mode lines. */
9476 update_single_window (w
, 1);
9477 FRAME_RIF (f
)->flush_display (f
);
9480 update_frame (f
, 1, 1);
9482 /* If cursor is in the echo area, make sure that the next
9483 redisplay displays the minibuffer, so that the cursor will
9484 be replaced with what the minibuffer wants. */
9485 if (cursor_in_echo_area
)
9486 ++windows_or_buffers_changed
;
9489 else if (!EQ (mini_window
, selected_window
))
9490 windows_or_buffers_changed
++;
9492 /* Last displayed message is now the current message. */
9493 echo_area_buffer
[1] = echo_area_buffer
[0];
9494 /* Inform read_char that we're not echoing. */
9495 echo_message_buffer
= Qnil
;
9497 /* Prevent redisplay optimization in redisplay_internal by resetting
9498 this_line_start_pos. This is done because the mini-buffer now
9499 displays the message instead of its buffer text. */
9500 if (EQ (mini_window
, selected_window
))
9501 CHARPOS (this_line_start_pos
) = 0;
9503 return window_height_changed_p
;
9508 /***********************************************************************
9509 Mode Lines and Frame Titles
9510 ***********************************************************************/
9512 /* A buffer for constructing non-propertized mode-line strings and
9513 frame titles in it; allocated from the heap in init_xdisp and
9514 resized as needed in store_mode_line_noprop_char. */
9516 static char *mode_line_noprop_buf
;
9518 /* The buffer's end, and a current output position in it. */
9520 static char *mode_line_noprop_buf_end
;
9521 static char *mode_line_noprop_ptr
;
9523 #define MODE_LINE_NOPROP_LEN(start) \
9524 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9527 MODE_LINE_DISPLAY
= 0,
9533 /* Alist that caches the results of :propertize.
9534 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9535 static Lisp_Object mode_line_proptrans_alist
;
9537 /* List of strings making up the mode-line. */
9538 static Lisp_Object mode_line_string_list
;
9540 /* Base face property when building propertized mode line string. */
9541 static Lisp_Object mode_line_string_face
;
9542 static Lisp_Object mode_line_string_face_prop
;
9545 /* Unwind data for mode line strings */
9547 static Lisp_Object Vmode_line_unwind_vector
;
9550 format_mode_line_unwind_data (struct buffer
*obuf
,
9554 Lisp_Object vector
, tmp
;
9556 /* Reduce consing by keeping one vector in
9557 Vwith_echo_area_save_vector. */
9558 vector
= Vmode_line_unwind_vector
;
9559 Vmode_line_unwind_vector
= Qnil
;
9562 vector
= Fmake_vector (make_number (8), Qnil
);
9564 ASET (vector
, 0, make_number (mode_line_target
));
9565 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9566 ASET (vector
, 2, mode_line_string_list
);
9567 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9568 ASET (vector
, 4, mode_line_string_face
);
9569 ASET (vector
, 5, mode_line_string_face_prop
);
9572 XSETBUFFER (tmp
, obuf
);
9575 ASET (vector
, 6, tmp
);
9576 ASET (vector
, 7, owin
);
9582 unwind_format_mode_line (Lisp_Object vector
)
9584 mode_line_target
= XINT (AREF (vector
, 0));
9585 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9586 mode_line_string_list
= AREF (vector
, 2);
9587 if (! EQ (AREF (vector
, 3), Qt
))
9588 mode_line_proptrans_alist
= AREF (vector
, 3);
9589 mode_line_string_face
= AREF (vector
, 4);
9590 mode_line_string_face_prop
= AREF (vector
, 5);
9592 if (!NILP (AREF (vector
, 7)))
9593 /* Select window before buffer, since it may change the buffer. */
9594 Fselect_window (AREF (vector
, 7), Qt
);
9596 if (!NILP (AREF (vector
, 6)))
9598 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9599 ASET (vector
, 6, Qnil
);
9602 Vmode_line_unwind_vector
= vector
;
9607 /* Store a single character C for the frame title in mode_line_noprop_buf.
9608 Re-allocate mode_line_noprop_buf if necessary. */
9611 store_mode_line_noprop_char (char c
)
9613 /* If output position has reached the end of the allocated buffer,
9614 double the buffer's size. */
9615 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9617 int len
= MODE_LINE_NOPROP_LEN (0);
9618 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9619 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9620 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9621 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9624 *mode_line_noprop_ptr
++ = c
;
9628 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9629 mode_line_noprop_ptr. STRING is the string to store. Do not copy
9630 characters that yield more columns than PRECISION; PRECISION <= 0
9631 means copy the whole string. Pad with spaces until FIELD_WIDTH
9632 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9633 pad. Called from display_mode_element when it is used to build a
9637 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
9639 const unsigned char *str
= (const unsigned char *) string
;
9641 EMACS_INT dummy
, nbytes
;
9643 /* Copy at most PRECISION chars from STR. */
9644 nbytes
= strlen (string
);
9645 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9647 store_mode_line_noprop_char (*str
++);
9649 /* Fill up with spaces until FIELD_WIDTH reached. */
9650 while (field_width
> 0
9653 store_mode_line_noprop_char (' ');
9660 /***********************************************************************
9662 ***********************************************************************/
9664 #ifdef HAVE_WINDOW_SYSTEM
9666 /* Set the title of FRAME, if it has changed. The title format is
9667 Vicon_title_format if FRAME is iconified, otherwise it is
9668 frame_title_format. */
9671 x_consider_frame_title (Lisp_Object frame
)
9673 struct frame
*f
= XFRAME (frame
);
9675 if (FRAME_WINDOW_P (f
)
9676 || FRAME_MINIBUF_ONLY_P (f
)
9677 || f
->explicit_name
)
9679 /* Do we have more than one visible frame on this X display? */
9686 int count
= SPECPDL_INDEX ();
9688 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9690 Lisp_Object other_frame
= XCAR (tail
);
9691 struct frame
*tf
= XFRAME (other_frame
);
9694 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9695 && !FRAME_MINIBUF_ONLY_P (tf
)
9696 && !EQ (other_frame
, tip_frame
)
9697 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9701 /* Set global variable indicating that multiple frames exist. */
9702 multiple_frames
= CONSP (tail
);
9704 /* Switch to the buffer of selected window of the frame. Set up
9705 mode_line_target so that display_mode_element will output into
9706 mode_line_noprop_buf; then display the title. */
9707 record_unwind_protect (unwind_format_mode_line
,
9708 format_mode_line_unwind_data
9709 (current_buffer
, selected_window
, 0));
9711 Fselect_window (f
->selected_window
, Qt
);
9712 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9713 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9715 mode_line_target
= MODE_LINE_TITLE
;
9716 title_start
= MODE_LINE_NOPROP_LEN (0);
9717 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9718 NULL
, DEFAULT_FACE_ID
);
9719 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9720 len
= MODE_LINE_NOPROP_LEN (title_start
);
9721 title
= mode_line_noprop_buf
+ title_start
;
9722 unbind_to (count
, Qnil
);
9724 /* Set the title only if it's changed. This avoids consing in
9725 the common case where it hasn't. (If it turns out that we've
9726 already wasted too much time by walking through the list with
9727 display_mode_element, then we might need to optimize at a
9728 higher level than this.) */
9729 if (! STRINGP (f
->name
)
9730 || SBYTES (f
->name
) != len
9731 || memcmp (title
, SDATA (f
->name
), len
) != 0)
9732 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9736 #endif /* not HAVE_WINDOW_SYSTEM */
9741 /***********************************************************************
9743 ***********************************************************************/
9746 /* Prepare for redisplay by updating menu-bar item lists when
9747 appropriate. This can call eval. */
9750 prepare_menu_bars (void)
9753 struct gcpro gcpro1
, gcpro2
;
9755 Lisp_Object tooltip_frame
;
9757 #ifdef HAVE_WINDOW_SYSTEM
9758 tooltip_frame
= tip_frame
;
9760 tooltip_frame
= Qnil
;
9763 /* Update all frame titles based on their buffer names, etc. We do
9764 this before the menu bars so that the buffer-menu will show the
9765 up-to-date frame titles. */
9766 #ifdef HAVE_WINDOW_SYSTEM
9767 if (windows_or_buffers_changed
|| update_mode_lines
)
9769 Lisp_Object tail
, frame
;
9771 FOR_EACH_FRAME (tail
, frame
)
9774 if (!EQ (frame
, tooltip_frame
)
9775 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9776 x_consider_frame_title (frame
);
9779 #endif /* HAVE_WINDOW_SYSTEM */
9781 /* Update the menu bar item lists, if appropriate. This has to be
9782 done before any actual redisplay or generation of display lines. */
9783 all_windows
= (update_mode_lines
9784 || buffer_shared
> 1
9785 || windows_or_buffers_changed
);
9788 Lisp_Object tail
, frame
;
9789 int count
= SPECPDL_INDEX ();
9790 /* 1 means that update_menu_bar has run its hooks
9791 so any further calls to update_menu_bar shouldn't do so again. */
9792 int menu_bar_hooks_run
= 0;
9794 record_unwind_save_match_data ();
9796 FOR_EACH_FRAME (tail
, frame
)
9800 /* Ignore tooltip frame. */
9801 if (EQ (frame
, tooltip_frame
))
9804 /* If a window on this frame changed size, report that to
9805 the user and clear the size-change flag. */
9806 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9808 Lisp_Object functions
;
9810 /* Clear flag first in case we get an error below. */
9811 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9812 functions
= Vwindow_size_change_functions
;
9813 GCPRO2 (tail
, functions
);
9815 while (CONSP (functions
))
9817 if (!EQ (XCAR (functions
), Qt
))
9818 call1 (XCAR (functions
), frame
);
9819 functions
= XCDR (functions
);
9825 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9826 #ifdef HAVE_WINDOW_SYSTEM
9827 update_tool_bar (f
, 0);
9830 if (windows_or_buffers_changed
9832 ns_set_doc_edited (f
, Fbuffer_modified_p
9833 (XWINDOW (f
->selected_window
)->buffer
));
9838 unbind_to (count
, Qnil
);
9842 struct frame
*sf
= SELECTED_FRAME ();
9843 update_menu_bar (sf
, 1, 0);
9844 #ifdef HAVE_WINDOW_SYSTEM
9845 update_tool_bar (sf
, 1);
9851 /* Update the menu bar item list for frame F. This has to be done
9852 before we start to fill in any display lines, because it can call
9855 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9857 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9858 already ran the menu bar hooks for this redisplay, so there
9859 is no need to run them again. The return value is the
9860 updated value of this flag, to pass to the next call. */
9863 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
9866 register struct window
*w
;
9868 /* If called recursively during a menu update, do nothing. This can
9869 happen when, for instance, an activate-menubar-hook causes a
9871 if (inhibit_menubar_update
)
9874 window
= FRAME_SELECTED_WINDOW (f
);
9875 w
= XWINDOW (window
);
9877 if (FRAME_WINDOW_P (f
)
9879 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9880 || defined (HAVE_NS) || defined (USE_GTK)
9881 FRAME_EXTERNAL_MENU_BAR (f
)
9883 FRAME_MENU_BAR_LINES (f
) > 0
9885 : FRAME_MENU_BAR_LINES (f
) > 0)
9887 /* If the user has switched buffers or windows, we need to
9888 recompute to reflect the new bindings. But we'll
9889 recompute when update_mode_lines is set too; that means
9890 that people can use force-mode-line-update to request
9891 that the menu bar be recomputed. The adverse effect on
9892 the rest of the redisplay algorithm is about the same as
9893 windows_or_buffers_changed anyway. */
9894 if (windows_or_buffers_changed
9895 /* This used to test w->update_mode_line, but we believe
9896 there is no need to recompute the menu in that case. */
9897 || update_mode_lines
9898 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9899 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9900 != !NILP (w
->last_had_star
))
9901 || ((!NILP (Vtransient_mark_mode
)
9902 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
9903 != !NILP (w
->region_showing
)))
9905 struct buffer
*prev
= current_buffer
;
9906 int count
= SPECPDL_INDEX ();
9908 specbind (Qinhibit_menubar_update
, Qt
);
9910 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9911 if (save_match_data
)
9912 record_unwind_save_match_data ();
9913 if (NILP (Voverriding_local_map_menu_flag
))
9915 specbind (Qoverriding_terminal_local_map
, Qnil
);
9916 specbind (Qoverriding_local_map
, Qnil
);
9921 /* Run the Lucid hook. */
9922 safe_run_hooks (Qactivate_menubar_hook
);
9924 /* If it has changed current-menubar from previous value,
9925 really recompute the menu-bar from the value. */
9926 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9927 call0 (Qrecompute_lucid_menubar
);
9929 safe_run_hooks (Qmenu_bar_update_hook
);
9934 XSETFRAME (Vmenu_updating_frame
, f
);
9935 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9937 /* Redisplay the menu bar in case we changed it. */
9938 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9939 || defined (HAVE_NS) || defined (USE_GTK)
9940 if (FRAME_WINDOW_P (f
))
9942 #if defined (HAVE_NS)
9943 /* All frames on Mac OS share the same menubar. So only
9944 the selected frame should be allowed to set it. */
9945 if (f
== SELECTED_FRAME ())
9947 set_frame_menubar (f
, 0, 0);
9950 /* On a terminal screen, the menu bar is an ordinary screen
9951 line, and this makes it get updated. */
9952 w
->update_mode_line
= Qt
;
9953 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9954 /* In the non-toolkit version, the menu bar is an ordinary screen
9955 line, and this makes it get updated. */
9956 w
->update_mode_line
= Qt
;
9957 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9959 unbind_to (count
, Qnil
);
9960 set_buffer_internal_1 (prev
);
9969 /***********************************************************************
9971 ***********************************************************************/
9973 #ifdef HAVE_WINDOW_SYSTEM
9976 Nominal cursor position -- where to draw output.
9977 HPOS and VPOS are window relative glyph matrix coordinates.
9978 X and Y are window relative pixel coordinates. */
9980 struct cursor_pos output_cursor
;
9984 Set the global variable output_cursor to CURSOR. All cursor
9985 positions are relative to updated_window. */
9988 set_output_cursor (struct cursor_pos
*cursor
)
9990 output_cursor
.hpos
= cursor
->hpos
;
9991 output_cursor
.vpos
= cursor
->vpos
;
9992 output_cursor
.x
= cursor
->x
;
9993 output_cursor
.y
= cursor
->y
;
9998 Set a nominal cursor position.
10000 HPOS and VPOS are column/row positions in a window glyph matrix. X
10001 and Y are window text area relative pixel positions.
10003 If this is done during an update, updated_window will contain the
10004 window that is being updated and the position is the future output
10005 cursor position for that window. If updated_window is null, use
10006 selected_window and display the cursor at the given position. */
10009 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
10013 /* If updated_window is not set, work on selected_window. */
10014 if (updated_window
)
10015 w
= updated_window
;
10017 w
= XWINDOW (selected_window
);
10019 /* Set the output cursor. */
10020 output_cursor
.hpos
= hpos
;
10021 output_cursor
.vpos
= vpos
;
10022 output_cursor
.x
= x
;
10023 output_cursor
.y
= y
;
10025 /* If not called as part of an update, really display the cursor.
10026 This will also set the cursor position of W. */
10027 if (updated_window
== NULL
)
10030 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10031 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10032 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10037 #endif /* HAVE_WINDOW_SYSTEM */
10040 /***********************************************************************
10042 ***********************************************************************/
10044 #ifdef HAVE_WINDOW_SYSTEM
10046 /* Where the mouse was last time we reported a mouse event. */
10048 FRAME_PTR last_mouse_frame
;
10050 /* Tool-bar item index of the item on which a mouse button was pressed
10053 int last_tool_bar_item
;
10057 update_tool_bar_unwind (Lisp_Object frame
)
10059 selected_frame
= frame
;
10063 /* Update the tool-bar item list for frame F. This has to be done
10064 before we start to fill in any display lines. Called from
10065 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10066 and restore it here. */
10069 update_tool_bar (struct frame
*f
, int save_match_data
)
10071 #if defined (USE_GTK) || defined (HAVE_NS)
10072 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10074 int do_update
= WINDOWP (f
->tool_bar_window
)
10075 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10080 Lisp_Object window
;
10083 window
= FRAME_SELECTED_WINDOW (f
);
10084 w
= XWINDOW (window
);
10086 /* If the user has switched buffers or windows, we need to
10087 recompute to reflect the new bindings. But we'll
10088 recompute when update_mode_lines is set too; that means
10089 that people can use force-mode-line-update to request
10090 that the menu bar be recomputed. The adverse effect on
10091 the rest of the redisplay algorithm is about the same as
10092 windows_or_buffers_changed anyway. */
10093 if (windows_or_buffers_changed
10094 || !NILP (w
->update_mode_line
)
10095 || update_mode_lines
10096 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10097 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10098 != !NILP (w
->last_had_star
))
10099 || ((!NILP (Vtransient_mark_mode
)
10100 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10101 != !NILP (w
->region_showing
)))
10103 struct buffer
*prev
= current_buffer
;
10104 int count
= SPECPDL_INDEX ();
10105 Lisp_Object frame
, new_tool_bar
;
10106 int new_n_tool_bar
;
10107 struct gcpro gcpro1
;
10109 /* Set current_buffer to the buffer of the selected
10110 window of the frame, so that we get the right local
10112 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10114 /* Save match data, if we must. */
10115 if (save_match_data
)
10116 record_unwind_save_match_data ();
10118 /* Make sure that we don't accidentally use bogus keymaps. */
10119 if (NILP (Voverriding_local_map_menu_flag
))
10121 specbind (Qoverriding_terminal_local_map
, Qnil
);
10122 specbind (Qoverriding_local_map
, Qnil
);
10125 GCPRO1 (new_tool_bar
);
10127 /* We must temporarily set the selected frame to this frame
10128 before calling tool_bar_items, because the calculation of
10129 the tool-bar keymap uses the selected frame (see
10130 `tool-bar-make-keymap' in tool-bar.el). */
10131 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10132 XSETFRAME (frame
, f
);
10133 selected_frame
= frame
;
10135 /* Build desired tool-bar items from keymaps. */
10136 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10139 /* Redisplay the tool-bar if we changed it. */
10140 if (new_n_tool_bar
!= f
->n_tool_bar_items
10141 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10143 /* Redisplay that happens asynchronously due to an expose event
10144 may access f->tool_bar_items. Make sure we update both
10145 variables within BLOCK_INPUT so no such event interrupts. */
10147 f
->tool_bar_items
= new_tool_bar
;
10148 f
->n_tool_bar_items
= new_n_tool_bar
;
10149 w
->update_mode_line
= Qt
;
10155 unbind_to (count
, Qnil
);
10156 set_buffer_internal_1 (prev
);
10162 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10163 F's desired tool-bar contents. F->tool_bar_items must have
10164 been set up previously by calling prepare_menu_bars. */
10167 build_desired_tool_bar_string (struct frame
*f
)
10169 int i
, size
, size_needed
;
10170 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10171 Lisp_Object image
, plist
, props
;
10173 image
= plist
= props
= Qnil
;
10174 GCPRO3 (image
, plist
, props
);
10176 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10177 Otherwise, make a new string. */
10179 /* The size of the string we might be able to reuse. */
10180 size
= (STRINGP (f
->desired_tool_bar_string
)
10181 ? SCHARS (f
->desired_tool_bar_string
)
10184 /* We need one space in the string for each image. */
10185 size_needed
= f
->n_tool_bar_items
;
10187 /* Reuse f->desired_tool_bar_string, if possible. */
10188 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10189 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10190 make_number (' '));
10193 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10194 Fremove_text_properties (make_number (0), make_number (size
),
10195 props
, f
->desired_tool_bar_string
);
10198 /* Put a `display' property on the string for the images to display,
10199 put a `menu_item' property on tool-bar items with a value that
10200 is the index of the item in F's tool-bar item vector. */
10201 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10203 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10205 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10206 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10207 int hmargin
, vmargin
, relief
, idx
, end
;
10209 /* If image is a vector, choose the image according to the
10211 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10212 if (VECTORP (image
))
10216 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10217 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10220 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10221 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10223 xassert (ASIZE (image
) >= idx
);
10224 image
= AREF (image
, idx
);
10229 /* Ignore invalid image specifications. */
10230 if (!valid_image_p (image
))
10233 /* Display the tool-bar button pressed, or depressed. */
10234 plist
= Fcopy_sequence (XCDR (image
));
10236 /* Compute margin and relief to draw. */
10237 relief
= (tool_bar_button_relief
>= 0
10238 ? tool_bar_button_relief
10239 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10240 hmargin
= vmargin
= relief
;
10242 if (INTEGERP (Vtool_bar_button_margin
)
10243 && XINT (Vtool_bar_button_margin
) > 0)
10245 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10246 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10248 else if (CONSP (Vtool_bar_button_margin
))
10250 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10251 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10252 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10254 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10255 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10256 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10259 if (auto_raise_tool_bar_buttons_p
)
10261 /* Add a `:relief' property to the image spec if the item is
10265 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10272 /* If image is selected, display it pressed, i.e. with a
10273 negative relief. If it's not selected, display it with a
10275 plist
= Fplist_put (plist
, QCrelief
,
10277 ? make_number (-relief
)
10278 : make_number (relief
)));
10283 /* Put a margin around the image. */
10284 if (hmargin
|| vmargin
)
10286 if (hmargin
== vmargin
)
10287 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10289 plist
= Fplist_put (plist
, QCmargin
,
10290 Fcons (make_number (hmargin
),
10291 make_number (vmargin
)));
10294 /* If button is not enabled, and we don't have special images
10295 for the disabled state, make the image appear disabled by
10296 applying an appropriate algorithm to it. */
10297 if (!enabled_p
&& idx
< 0)
10298 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10300 /* Put a `display' text property on the string for the image to
10301 display. Put a `menu-item' property on the string that gives
10302 the start of this item's properties in the tool-bar items
10304 image
= Fcons (Qimage
, plist
);
10305 props
= list4 (Qdisplay
, image
,
10306 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10308 /* Let the last image hide all remaining spaces in the tool bar
10309 string. The string can be longer than needed when we reuse a
10310 previous string. */
10311 if (i
+ 1 == f
->n_tool_bar_items
)
10312 end
= SCHARS (f
->desired_tool_bar_string
);
10315 Fadd_text_properties (make_number (i
), make_number (end
),
10316 props
, f
->desired_tool_bar_string
);
10324 /* Display one line of the tool-bar of frame IT->f.
10326 HEIGHT specifies the desired height of the tool-bar line.
10327 If the actual height of the glyph row is less than HEIGHT, the
10328 row's height is increased to HEIGHT, and the icons are centered
10329 vertically in the new height.
10331 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10332 count a final empty row in case the tool-bar width exactly matches
10337 display_tool_bar_line (struct it
*it
, int height
)
10339 struct glyph_row
*row
= it
->glyph_row
;
10340 int max_x
= it
->last_visible_x
;
10341 struct glyph
*last
;
10343 prepare_desired_row (row
);
10344 row
->y
= it
->current_y
;
10346 /* Note that this isn't made use of if the face hasn't a box,
10347 so there's no need to check the face here. */
10348 it
->start_of_box_run_p
= 1;
10350 while (it
->current_x
< max_x
)
10352 int x
, n_glyphs_before
, i
, nglyphs
;
10353 struct it it_before
;
10355 /* Get the next display element. */
10356 if (!get_next_display_element (it
))
10358 /* Don't count empty row if we are counting needed tool-bar lines. */
10359 if (height
< 0 && !it
->hpos
)
10364 /* Produce glyphs. */
10365 n_glyphs_before
= row
->used
[TEXT_AREA
];
10368 PRODUCE_GLYPHS (it
);
10370 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10372 x
= it_before
.current_x
;
10373 while (i
< nglyphs
)
10375 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10377 if (x
+ glyph
->pixel_width
> max_x
)
10379 /* Glyph doesn't fit on line. Backtrack. */
10380 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10382 /* If this is the only glyph on this line, it will never fit on the
10383 tool-bar, so skip it. But ensure there is at least one glyph,
10384 so we don't accidentally disable the tool-bar. */
10385 if (n_glyphs_before
== 0
10386 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10392 x
+= glyph
->pixel_width
;
10396 /* Stop at line ends. */
10397 if (ITERATOR_AT_END_OF_LINE_P (it
))
10400 set_iterator_to_next (it
, 1);
10405 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10407 /* Use default face for the border below the tool bar.
10409 FIXME: When auto-resize-tool-bars is grow-only, there is
10410 no additional border below the possibly empty tool-bar lines.
10411 So to make the extra empty lines look "normal", we have to
10412 use the tool-bar face for the border too. */
10413 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10414 it
->face_id
= DEFAULT_FACE_ID
;
10416 extend_face_to_end_of_line (it
);
10417 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10418 last
->right_box_line_p
= 1;
10419 if (last
== row
->glyphs
[TEXT_AREA
])
10420 last
->left_box_line_p
= 1;
10422 /* Make line the desired height and center it vertically. */
10423 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10425 /* Don't add more than one line height. */
10426 height
%= FRAME_LINE_HEIGHT (it
->f
);
10427 it
->max_ascent
+= height
/ 2;
10428 it
->max_descent
+= (height
+ 1) / 2;
10431 compute_line_metrics (it
);
10433 /* If line is empty, make it occupy the rest of the tool-bar. */
10434 if (!row
->displays_text_p
)
10436 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10437 row
->visible_height
= row
->height
;
10438 row
->ascent
= row
->phys_ascent
= 0;
10439 row
->extra_line_spacing
= 0;
10442 row
->full_width_p
= 1;
10443 row
->continued_p
= 0;
10444 row
->truncated_on_left_p
= 0;
10445 row
->truncated_on_right_p
= 0;
10447 it
->current_x
= it
->hpos
= 0;
10448 it
->current_y
+= row
->height
;
10454 /* Max tool-bar height. */
10456 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10457 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10459 /* Value is the number of screen lines needed to make all tool-bar
10460 items of frame F visible. The number of actual rows needed is
10461 returned in *N_ROWS if non-NULL. */
10464 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
10466 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10468 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10469 the desired matrix, so use (unused) mode-line row as temporary row to
10470 avoid destroying the first tool-bar row. */
10471 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10473 /* Initialize an iterator for iteration over
10474 F->desired_tool_bar_string in the tool-bar window of frame F. */
10475 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10476 it
.first_visible_x
= 0;
10477 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10478 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10480 while (!ITERATOR_AT_END_P (&it
))
10482 clear_glyph_row (temp_row
);
10483 it
.glyph_row
= temp_row
;
10484 display_tool_bar_line (&it
, -1);
10486 clear_glyph_row (temp_row
);
10488 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10490 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10492 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10496 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10498 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10499 (Lisp_Object frame
)
10506 frame
= selected_frame
;
10508 CHECK_FRAME (frame
);
10509 f
= XFRAME (frame
);
10511 if (WINDOWP (f
->tool_bar_window
)
10512 && (w
= XWINDOW (f
->tool_bar_window
),
10513 WINDOW_TOTAL_LINES (w
) > 0))
10515 update_tool_bar (f
, 1);
10516 if (f
->n_tool_bar_items
)
10518 build_desired_tool_bar_string (f
);
10519 nlines
= tool_bar_lines_needed (f
, NULL
);
10523 return make_number (nlines
);
10527 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10528 height should be changed. */
10531 redisplay_tool_bar (struct frame
*f
)
10535 struct glyph_row
*row
;
10537 #if defined (USE_GTK) || defined (HAVE_NS)
10538 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10539 update_frame_tool_bar (f
);
10543 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10544 do anything. This means you must start with tool-bar-lines
10545 non-zero to get the auto-sizing effect. Or in other words, you
10546 can turn off tool-bars by specifying tool-bar-lines zero. */
10547 if (!WINDOWP (f
->tool_bar_window
)
10548 || (w
= XWINDOW (f
->tool_bar_window
),
10549 WINDOW_TOTAL_LINES (w
) == 0))
10552 /* Set up an iterator for the tool-bar window. */
10553 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10554 it
.first_visible_x
= 0;
10555 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10556 row
= it
.glyph_row
;
10558 /* Build a string that represents the contents of the tool-bar. */
10559 build_desired_tool_bar_string (f
);
10560 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10562 if (f
->n_tool_bar_rows
== 0)
10566 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10567 nlines
!= WINDOW_TOTAL_LINES (w
)))
10570 int old_height
= WINDOW_TOTAL_LINES (w
);
10572 XSETFRAME (frame
, f
);
10573 Fmodify_frame_parameters (frame
,
10574 Fcons (Fcons (Qtool_bar_lines
,
10575 make_number (nlines
)),
10577 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10579 clear_glyph_matrix (w
->desired_matrix
);
10580 fonts_changed_p
= 1;
10586 /* Display as many lines as needed to display all tool-bar items. */
10588 if (f
->n_tool_bar_rows
> 0)
10590 int border
, rows
, height
, extra
;
10592 if (INTEGERP (Vtool_bar_border
))
10593 border
= XINT (Vtool_bar_border
);
10594 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10595 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10596 else if (EQ (Vtool_bar_border
, Qborder_width
))
10597 border
= f
->border_width
;
10603 rows
= f
->n_tool_bar_rows
;
10604 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10605 extra
= it
.last_visible_y
- border
- height
* rows
;
10607 while (it
.current_y
< it
.last_visible_y
)
10610 if (extra
> 0 && rows
-- > 0)
10612 h
= (extra
+ rows
- 1) / rows
;
10615 display_tool_bar_line (&it
, height
+ h
);
10620 while (it
.current_y
< it
.last_visible_y
)
10621 display_tool_bar_line (&it
, 0);
10624 /* It doesn't make much sense to try scrolling in the tool-bar
10625 window, so don't do it. */
10626 w
->desired_matrix
->no_scrolling_p
= 1;
10627 w
->must_be_updated_p
= 1;
10629 if (!NILP (Vauto_resize_tool_bars
))
10631 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10632 int change_height_p
= 0;
10634 /* If we couldn't display everything, change the tool-bar's
10635 height if there is room for more. */
10636 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10637 && it
.current_y
< max_tool_bar_height
)
10638 change_height_p
= 1;
10640 row
= it
.glyph_row
- 1;
10642 /* If there are blank lines at the end, except for a partially
10643 visible blank line at the end that is smaller than
10644 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10645 if (!row
->displays_text_p
10646 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10647 change_height_p
= 1;
10649 /* If row displays tool-bar items, but is partially visible,
10650 change the tool-bar's height. */
10651 if (row
->displays_text_p
10652 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10653 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10654 change_height_p
= 1;
10656 /* Resize windows as needed by changing the `tool-bar-lines'
10657 frame parameter. */
10658 if (change_height_p
)
10661 int old_height
= WINDOW_TOTAL_LINES (w
);
10663 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10665 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10666 && !f
->minimize_tool_bar_window_p
)
10667 ? (nlines
> old_height
)
10668 : (nlines
!= old_height
));
10669 f
->minimize_tool_bar_window_p
= 0;
10671 if (change_height_p
)
10673 XSETFRAME (frame
, f
);
10674 Fmodify_frame_parameters (frame
,
10675 Fcons (Fcons (Qtool_bar_lines
,
10676 make_number (nlines
)),
10678 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10680 clear_glyph_matrix (w
->desired_matrix
);
10681 f
->n_tool_bar_rows
= nrows
;
10682 fonts_changed_p
= 1;
10689 f
->minimize_tool_bar_window_p
= 0;
10694 /* Get information about the tool-bar item which is displayed in GLYPH
10695 on frame F. Return in *PROP_IDX the index where tool-bar item
10696 properties start in F->tool_bar_items. Value is zero if
10697 GLYPH doesn't display a tool-bar item. */
10700 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
10706 /* This function can be called asynchronously, which means we must
10707 exclude any possibility that Fget_text_property signals an
10709 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10710 charpos
= max (0, charpos
);
10712 /* Get the text property `menu-item' at pos. The value of that
10713 property is the start index of this item's properties in
10714 F->tool_bar_items. */
10715 prop
= Fget_text_property (make_number (charpos
),
10716 Qmenu_item
, f
->current_tool_bar_string
);
10717 if (INTEGERP (prop
))
10719 *prop_idx
= XINT (prop
);
10729 /* Get information about the tool-bar item at position X/Y on frame F.
10730 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10731 the current matrix of the tool-bar window of F, or NULL if not
10732 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10733 item in F->tool_bar_items. Value is
10735 -1 if X/Y is not on a tool-bar item
10736 0 if X/Y is on the same item that was highlighted before.
10740 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
10741 int *hpos
, int *vpos
, int *prop_idx
)
10743 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10744 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10747 /* Find the glyph under X/Y. */
10748 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10749 if (*glyph
== NULL
)
10752 /* Get the start of this tool-bar item's properties in
10753 f->tool_bar_items. */
10754 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10757 /* Is mouse on the highlighted item? */
10758 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
10759 && *vpos
>= hlinfo
->mouse_face_beg_row
10760 && *vpos
<= hlinfo
->mouse_face_end_row
10761 && (*vpos
> hlinfo
->mouse_face_beg_row
10762 || *hpos
>= hlinfo
->mouse_face_beg_col
)
10763 && (*vpos
< hlinfo
->mouse_face_end_row
10764 || *hpos
< hlinfo
->mouse_face_end_col
10765 || hlinfo
->mouse_face_past_end
))
10773 Handle mouse button event on the tool-bar of frame F, at
10774 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10775 0 for button release. MODIFIERS is event modifiers for button
10779 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
10780 unsigned int modifiers
)
10782 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10783 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10784 int hpos
, vpos
, prop_idx
;
10785 struct glyph
*glyph
;
10786 Lisp_Object enabled_p
;
10788 /* If not on the highlighted tool-bar item, return. */
10789 frame_to_window_pixel_xy (w
, &x
, &y
);
10790 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10793 /* If item is disabled, do nothing. */
10794 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10795 if (NILP (enabled_p
))
10800 /* Show item in pressed state. */
10801 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
10802 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10803 last_tool_bar_item
= prop_idx
;
10807 Lisp_Object key
, frame
;
10808 struct input_event event
;
10809 EVENT_INIT (event
);
10811 /* Show item in released state. */
10812 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
10813 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10815 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10817 XSETFRAME (frame
, f
);
10818 event
.kind
= TOOL_BAR_EVENT
;
10819 event
.frame_or_window
= frame
;
10821 kbd_buffer_store_event (&event
);
10823 event
.kind
= TOOL_BAR_EVENT
;
10824 event
.frame_or_window
= frame
;
10826 event
.modifiers
= modifiers
;
10827 kbd_buffer_store_event (&event
);
10828 last_tool_bar_item
= -1;
10833 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10834 tool-bar window-relative coordinates X/Y. Called from
10835 note_mouse_highlight. */
10838 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
10840 Lisp_Object window
= f
->tool_bar_window
;
10841 struct window
*w
= XWINDOW (window
);
10842 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10843 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10845 struct glyph
*glyph
;
10846 struct glyph_row
*row
;
10848 Lisp_Object enabled_p
;
10850 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10851 int mouse_down_p
, rc
;
10853 /* Function note_mouse_highlight is called with negative X/Y
10854 values when mouse moves outside of the frame. */
10855 if (x
<= 0 || y
<= 0)
10857 clear_mouse_face (hlinfo
);
10861 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10864 /* Not on tool-bar item. */
10865 clear_mouse_face (hlinfo
);
10869 /* On same tool-bar item as before. */
10870 goto set_help_echo
;
10872 clear_mouse_face (hlinfo
);
10874 /* Mouse is down, but on different tool-bar item? */
10875 mouse_down_p
= (dpyinfo
->grabbed
10876 && f
== last_mouse_frame
10877 && FRAME_LIVE_P (f
));
10879 && last_tool_bar_item
!= prop_idx
)
10882 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10883 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10885 /* If tool-bar item is not enabled, don't highlight it. */
10886 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10887 if (!NILP (enabled_p
))
10889 /* Compute the x-position of the glyph. In front and past the
10890 image is a space. We include this in the highlighted area. */
10891 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10892 for (i
= x
= 0; i
< hpos
; ++i
)
10893 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10895 /* Record this as the current active region. */
10896 hlinfo
->mouse_face_beg_col
= hpos
;
10897 hlinfo
->mouse_face_beg_row
= vpos
;
10898 hlinfo
->mouse_face_beg_x
= x
;
10899 hlinfo
->mouse_face_beg_y
= row
->y
;
10900 hlinfo
->mouse_face_past_end
= 0;
10902 hlinfo
->mouse_face_end_col
= hpos
+ 1;
10903 hlinfo
->mouse_face_end_row
= vpos
;
10904 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10905 hlinfo
->mouse_face_end_y
= row
->y
;
10906 hlinfo
->mouse_face_window
= window
;
10907 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10909 /* Display it as active. */
10910 show_mouse_face (hlinfo
, draw
);
10911 hlinfo
->mouse_face_image_state
= draw
;
10916 /* Set help_echo_string to a help string to display for this tool-bar item.
10917 XTread_socket does the rest. */
10918 help_echo_object
= help_echo_window
= Qnil
;
10919 help_echo_pos
= -1;
10920 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10921 if (NILP (help_echo_string
))
10922 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10925 #endif /* HAVE_WINDOW_SYSTEM */
10929 /************************************************************************
10930 Horizontal scrolling
10931 ************************************************************************/
10933 static int hscroll_window_tree (Lisp_Object
);
10934 static int hscroll_windows (Lisp_Object
);
10936 /* For all leaf windows in the window tree rooted at WINDOW, set their
10937 hscroll value so that PT is (i) visible in the window, and (ii) so
10938 that it is not within a certain margin at the window's left and
10939 right border. Value is non-zero if any window's hscroll has been
10943 hscroll_window_tree (Lisp_Object window
)
10945 int hscrolled_p
= 0;
10946 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10947 int hscroll_step_abs
= 0;
10948 double hscroll_step_rel
= 0;
10950 if (hscroll_relative_p
)
10952 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10953 if (hscroll_step_rel
< 0)
10955 hscroll_relative_p
= 0;
10956 hscroll_step_abs
= 0;
10959 else if (INTEGERP (Vhscroll_step
))
10961 hscroll_step_abs
= XINT (Vhscroll_step
);
10962 if (hscroll_step_abs
< 0)
10963 hscroll_step_abs
= 0;
10966 hscroll_step_abs
= 0;
10968 while (WINDOWP (window
))
10970 struct window
*w
= XWINDOW (window
);
10972 if (WINDOWP (w
->hchild
))
10973 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10974 else if (WINDOWP (w
->vchild
))
10975 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10976 else if (w
->cursor
.vpos
>= 0)
10979 int text_area_width
;
10980 struct glyph_row
*current_cursor_row
10981 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10982 struct glyph_row
*desired_cursor_row
10983 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10984 struct glyph_row
*cursor_row
10985 = (desired_cursor_row
->enabled_p
10986 ? desired_cursor_row
10987 : current_cursor_row
);
10989 text_area_width
= window_box_width (w
, TEXT_AREA
);
10991 /* Scroll when cursor is inside this scroll margin. */
10992 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10994 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10995 && ((XFASTINT (w
->hscroll
)
10996 && w
->cursor
.x
<= h_margin
)
10997 || (cursor_row
->enabled_p
10998 && cursor_row
->truncated_on_right_p
10999 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11003 struct buffer
*saved_current_buffer
;
11007 /* Find point in a display of infinite width. */
11008 saved_current_buffer
= current_buffer
;
11009 current_buffer
= XBUFFER (w
->buffer
);
11011 if (w
== XWINDOW (selected_window
))
11015 pt
= marker_position (w
->pointm
);
11016 pt
= max (BEGV
, pt
);
11020 /* Move iterator to pt starting at cursor_row->start in
11021 a line with infinite width. */
11022 init_to_row_start (&it
, w
, cursor_row
);
11023 it
.last_visible_x
= INFINITY
;
11024 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11025 current_buffer
= saved_current_buffer
;
11027 /* Position cursor in window. */
11028 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11029 hscroll
= max (0, (it
.current_x
11030 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11031 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11032 : (text_area_width
/ 2))))
11033 / FRAME_COLUMN_WIDTH (it
.f
);
11034 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11036 if (hscroll_relative_p
)
11037 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11040 wanted_x
= text_area_width
11041 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11044 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11048 if (hscroll_relative_p
)
11049 wanted_x
= text_area_width
* hscroll_step_rel
11052 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11055 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11057 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11059 /* Don't call Fset_window_hscroll if value hasn't
11060 changed because it will prevent redisplay
11062 if (XFASTINT (w
->hscroll
) != hscroll
)
11064 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11065 w
->hscroll
= make_number (hscroll
);
11074 /* Value is non-zero if hscroll of any leaf window has been changed. */
11075 return hscrolled_p
;
11079 /* Set hscroll so that cursor is visible and not inside horizontal
11080 scroll margins for all windows in the tree rooted at WINDOW. See
11081 also hscroll_window_tree above. Value is non-zero if any window's
11082 hscroll has been changed. If it has, desired matrices on the frame
11083 of WINDOW are cleared. */
11086 hscroll_windows (Lisp_Object window
)
11088 int hscrolled_p
= hscroll_window_tree (window
);
11090 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11091 return hscrolled_p
;
11096 /************************************************************************
11098 ************************************************************************/
11100 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11101 to a non-zero value. This is sometimes handy to have in a debugger
11106 /* First and last unchanged row for try_window_id. */
11108 static int debug_first_unchanged_at_end_vpos
;
11109 static int debug_last_unchanged_at_beg_vpos
;
11111 /* Delta vpos and y. */
11113 static int debug_dvpos
, debug_dy
;
11115 /* Delta in characters and bytes for try_window_id. */
11117 static EMACS_INT debug_delta
, debug_delta_bytes
;
11119 /* Values of window_end_pos and window_end_vpos at the end of
11122 static EMACS_INT debug_end_vpos
;
11124 /* Append a string to W->desired_matrix->method. FMT is a printf
11125 format string. If trace_redisplay_p is non-zero also printf the
11126 resulting string to stderr. */
11128 static void debug_method_add (struct window
*, char const *, ...)
11129 ATTRIBUTE_FORMAT_PRINTF (2, 3);
11132 debug_method_add (struct window
*w
, char const *fmt
, ...)
11135 char *method
= w
->desired_matrix
->method
;
11136 int len
= strlen (method
);
11137 int size
= sizeof w
->desired_matrix
->method
;
11138 int remaining
= size
- len
- 1;
11141 va_start (ap
, fmt
);
11142 vsprintf (buffer
, fmt
, ap
);
11144 if (len
&& remaining
)
11147 --remaining
, ++len
;
11150 strncpy (method
+ len
, buffer
, remaining
);
11152 if (trace_redisplay_p
)
11153 fprintf (stderr
, "%p (%s): %s\n",
11155 ((BUFFERP (w
->buffer
)
11156 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
11157 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
11162 #endif /* GLYPH_DEBUG */
11165 /* Value is non-zero if all changes in window W, which displays
11166 current_buffer, are in the text between START and END. START is a
11167 buffer position, END is given as a distance from Z. Used in
11168 redisplay_internal for display optimization. */
11171 text_outside_line_unchanged_p (struct window
*w
,
11172 EMACS_INT start
, EMACS_INT end
)
11174 int unchanged_p
= 1;
11176 /* If text or overlays have changed, see where. */
11177 if (XFASTINT (w
->last_modified
) < MODIFF
11178 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11180 /* Gap in the line? */
11181 if (GPT
< start
|| Z
- GPT
< end
)
11184 /* Changes start in front of the line, or end after it? */
11186 && (BEG_UNCHANGED
< start
- 1
11187 || END_UNCHANGED
< end
))
11190 /* If selective display, can't optimize if changes start at the
11191 beginning of the line. */
11193 && INTEGERP (BVAR (current_buffer
, selective_display
))
11194 && XINT (BVAR (current_buffer
, selective_display
)) > 0
11195 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11198 /* If there are overlays at the start or end of the line, these
11199 may have overlay strings with newlines in them. A change at
11200 START, for instance, may actually concern the display of such
11201 overlay strings as well, and they are displayed on different
11202 lines. So, quickly rule out this case. (For the future, it
11203 might be desirable to implement something more telling than
11204 just BEG/END_UNCHANGED.) */
11207 if (BEG
+ BEG_UNCHANGED
== start
11208 && overlay_touches_p (start
))
11210 if (END_UNCHANGED
== end
11211 && overlay_touches_p (Z
- end
))
11215 /* Under bidi reordering, adding or deleting a character in the
11216 beginning of a paragraph, before the first strong directional
11217 character, can change the base direction of the paragraph (unless
11218 the buffer specifies a fixed paragraph direction), which will
11219 require to redisplay the whole paragraph. It might be worthwhile
11220 to find the paragraph limits and widen the range of redisplayed
11221 lines to that, but for now just give up this optimization. */
11222 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
11223 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
11227 return unchanged_p
;
11231 /* Do a frame update, taking possible shortcuts into account. This is
11232 the main external entry point for redisplay.
11234 If the last redisplay displayed an echo area message and that message
11235 is no longer requested, we clear the echo area or bring back the
11236 mini-buffer if that is in use. */
11241 redisplay_internal ();
11246 overlay_arrow_string_or_property (Lisp_Object var
)
11250 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11253 return Voverlay_arrow_string
;
11256 /* Return 1 if there are any overlay-arrows in current_buffer. */
11258 overlay_arrow_in_current_buffer_p (void)
11262 for (vlist
= Voverlay_arrow_variable_list
;
11264 vlist
= XCDR (vlist
))
11266 Lisp_Object var
= XCAR (vlist
);
11269 if (!SYMBOLP (var
))
11271 val
= find_symbol_value (var
);
11273 && current_buffer
== XMARKER (val
)->buffer
)
11280 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11284 overlay_arrows_changed_p (void)
11288 for (vlist
= Voverlay_arrow_variable_list
;
11290 vlist
= XCDR (vlist
))
11292 Lisp_Object var
= XCAR (vlist
);
11293 Lisp_Object val
, pstr
;
11295 if (!SYMBOLP (var
))
11297 val
= find_symbol_value (var
);
11298 if (!MARKERP (val
))
11300 if (! EQ (COERCE_MARKER (val
),
11301 Fget (var
, Qlast_arrow_position
))
11302 || ! (pstr
= overlay_arrow_string_or_property (var
),
11303 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11309 /* Mark overlay arrows to be updated on next redisplay. */
11312 update_overlay_arrows (int up_to_date
)
11316 for (vlist
= Voverlay_arrow_variable_list
;
11318 vlist
= XCDR (vlist
))
11320 Lisp_Object var
= XCAR (vlist
);
11322 if (!SYMBOLP (var
))
11325 if (up_to_date
> 0)
11327 Lisp_Object val
= find_symbol_value (var
);
11328 Fput (var
, Qlast_arrow_position
,
11329 COERCE_MARKER (val
));
11330 Fput (var
, Qlast_arrow_string
,
11331 overlay_arrow_string_or_property (var
));
11333 else if (up_to_date
< 0
11334 || !NILP (Fget (var
, Qlast_arrow_position
)))
11336 Fput (var
, Qlast_arrow_position
, Qt
);
11337 Fput (var
, Qlast_arrow_string
, Qt
);
11343 /* Return overlay arrow string to display at row.
11344 Return integer (bitmap number) for arrow bitmap in left fringe.
11345 Return nil if no overlay arrow. */
11348 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
11352 for (vlist
= Voverlay_arrow_variable_list
;
11354 vlist
= XCDR (vlist
))
11356 Lisp_Object var
= XCAR (vlist
);
11359 if (!SYMBOLP (var
))
11362 val
= find_symbol_value (var
);
11365 && current_buffer
== XMARKER (val
)->buffer
11366 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11368 if (FRAME_WINDOW_P (it
->f
)
11369 /* FIXME: if ROW->reversed_p is set, this should test
11370 the right fringe, not the left one. */
11371 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11373 #ifdef HAVE_WINDOW_SYSTEM
11374 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11377 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11378 return make_number (fringe_bitmap
);
11381 return make_number (-1); /* Use default arrow bitmap */
11383 return overlay_arrow_string_or_property (var
);
11390 /* Return 1 if point moved out of or into a composition. Otherwise
11391 return 0. PREV_BUF and PREV_PT are the last point buffer and
11392 position. BUF and PT are the current point buffer and position. */
11395 check_point_in_composition (struct buffer
*prev_buf
, EMACS_INT prev_pt
,
11396 struct buffer
*buf
, EMACS_INT pt
)
11398 EMACS_INT start
, end
;
11400 Lisp_Object buffer
;
11402 XSETBUFFER (buffer
, buf
);
11403 /* Check a composition at the last point if point moved within the
11405 if (prev_buf
== buf
)
11408 /* Point didn't move. */
11411 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11412 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11413 && COMPOSITION_VALID_P (start
, end
, prop
)
11414 && start
< prev_pt
&& end
> prev_pt
)
11415 /* The last point was within the composition. Return 1 iff
11416 point moved out of the composition. */
11417 return (pt
<= start
|| pt
>= end
);
11420 /* Check a composition at the current point. */
11421 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11422 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11423 && COMPOSITION_VALID_P (start
, end
, prop
)
11424 && start
< pt
&& end
> pt
);
11428 /* Reconsider the setting of B->clip_changed which is displayed
11432 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
11434 if (b
->clip_changed
11435 && !NILP (w
->window_end_valid
)
11436 && w
->current_matrix
->buffer
== b
11437 && w
->current_matrix
->zv
== BUF_ZV (b
)
11438 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11439 b
->clip_changed
= 0;
11441 /* If display wasn't paused, and W is not a tool bar window, see if
11442 point has been moved into or out of a composition. In that case,
11443 we set b->clip_changed to 1 to force updating the screen. If
11444 b->clip_changed has already been set to 1, we can skip this
11446 if (!b
->clip_changed
11447 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11451 if (w
== XWINDOW (selected_window
))
11454 pt
= marker_position (w
->pointm
);
11456 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11457 || pt
!= XINT (w
->last_point
))
11458 && check_point_in_composition (w
->current_matrix
->buffer
,
11459 XINT (w
->last_point
),
11460 XBUFFER (w
->buffer
), pt
))
11461 b
->clip_changed
= 1;
11466 /* Select FRAME to forward the values of frame-local variables into C
11467 variables so that the redisplay routines can access those values
11471 select_frame_for_redisplay (Lisp_Object frame
)
11473 Lisp_Object tail
, tem
;
11474 Lisp_Object old
= selected_frame
;
11475 struct Lisp_Symbol
*sym
;
11477 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11479 selected_frame
= frame
;
11482 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11483 if (CONSP (XCAR (tail
))
11484 && (tem
= XCAR (XCAR (tail
)),
11486 && (sym
= indirect_variable (XSYMBOL (tem
)),
11487 sym
->redirect
== SYMBOL_LOCALIZED
)
11488 && sym
->val
.blv
->frame_local
)
11489 /* Use find_symbol_value rather than Fsymbol_value
11490 to avoid an error if it is void. */
11491 find_symbol_value (tem
);
11492 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11496 #define STOP_POLLING \
11497 do { if (! polling_stopped_here) stop_polling (); \
11498 polling_stopped_here = 1; } while (0)
11500 #define RESUME_POLLING \
11501 do { if (polling_stopped_here) start_polling (); \
11502 polling_stopped_here = 0; } while (0)
11505 /* Perhaps in the future avoid recentering windows if it
11506 is not necessary; currently that causes some problems. */
11509 redisplay_internal (void)
11511 struct window
*w
= XWINDOW (selected_window
);
11515 int must_finish
= 0;
11516 struct text_pos tlbufpos
, tlendpos
;
11517 int number_of_visible_frames
;
11520 int polling_stopped_here
= 0;
11521 Lisp_Object old_frame
= selected_frame
;
11523 /* Non-zero means redisplay has to consider all windows on all
11524 frames. Zero means, only selected_window is considered. */
11525 int consider_all_windows_p
;
11527 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11529 /* No redisplay if running in batch mode or frame is not yet fully
11530 initialized, or redisplay is explicitly turned off by setting
11531 Vinhibit_redisplay. */
11532 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11533 || !NILP (Vinhibit_redisplay
))
11536 /* Don't examine these until after testing Vinhibit_redisplay.
11537 When Emacs is shutting down, perhaps because its connection to
11538 X has dropped, we should not look at them at all. */
11539 fr
= XFRAME (w
->frame
);
11540 sf
= SELECTED_FRAME ();
11542 if (!fr
->glyphs_initialized_p
)
11545 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11546 if (popup_activated ())
11550 /* I don't think this happens but let's be paranoid. */
11551 if (redisplaying_p
)
11554 /* Record a function that resets redisplaying_p to its old value
11555 when we leave this function. */
11556 count
= SPECPDL_INDEX ();
11557 record_unwind_protect (unwind_redisplay
,
11558 Fcons (make_number (redisplaying_p
), selected_frame
));
11560 specbind (Qinhibit_free_realized_faces
, Qnil
);
11563 Lisp_Object tail
, frame
;
11565 FOR_EACH_FRAME (tail
, frame
)
11567 struct frame
*f
= XFRAME (frame
);
11568 f
->already_hscrolled_p
= 0;
11573 /* Remember the currently selected window. */
11576 if (!EQ (old_frame
, selected_frame
)
11577 && FRAME_LIVE_P (XFRAME (old_frame
)))
11578 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11579 selected_frame and selected_window to be temporarily out-of-sync so
11580 when we come back here via `goto retry', we need to resync because we
11581 may need to run Elisp code (via prepare_menu_bars). */
11582 select_frame_for_redisplay (old_frame
);
11585 reconsider_clip_changes (w
, current_buffer
);
11586 last_escape_glyph_frame
= NULL
;
11587 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11588 last_glyphless_glyph_frame
= NULL
;
11589 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
11591 /* If new fonts have been loaded that make a glyph matrix adjustment
11592 necessary, do it. */
11593 if (fonts_changed_p
)
11595 adjust_glyphs (NULL
);
11596 ++windows_or_buffers_changed
;
11597 fonts_changed_p
= 0;
11600 /* If face_change_count is non-zero, init_iterator will free all
11601 realized faces, which includes the faces referenced from current
11602 matrices. So, we can't reuse current matrices in this case. */
11603 if (face_change_count
)
11604 ++windows_or_buffers_changed
;
11606 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11607 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11609 /* Since frames on a single ASCII terminal share the same
11610 display area, displaying a different frame means redisplay
11611 the whole thing. */
11612 windows_or_buffers_changed
++;
11613 SET_FRAME_GARBAGED (sf
);
11615 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11617 FRAME_TTY (sf
)->previous_frame
= sf
;
11620 /* Set the visible flags for all frames. Do this before checking
11621 for resized or garbaged frames; they want to know if their frames
11622 are visible. See the comment in frame.h for
11623 FRAME_SAMPLE_VISIBILITY. */
11625 Lisp_Object tail
, frame
;
11627 number_of_visible_frames
= 0;
11629 FOR_EACH_FRAME (tail
, frame
)
11631 struct frame
*f
= XFRAME (frame
);
11633 FRAME_SAMPLE_VISIBILITY (f
);
11634 if (FRAME_VISIBLE_P (f
))
11635 ++number_of_visible_frames
;
11636 clear_desired_matrices (f
);
11640 /* Notice any pending interrupt request to change frame size. */
11641 do_pending_window_change (1);
11643 /* do_pending_window_change could change the selected_window due to
11644 frame resizing which makes the selected window too small. */
11645 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
11648 reconsider_clip_changes (w
, current_buffer
);
11651 /* Clear frames marked as garbaged. */
11652 if (frame_garbaged
)
11653 clear_garbaged_frames ();
11655 /* Build menubar and tool-bar items. */
11656 if (NILP (Vmemory_full
))
11657 prepare_menu_bars ();
11659 if (windows_or_buffers_changed
)
11660 update_mode_lines
++;
11662 /* Detect case that we need to write or remove a star in the mode line. */
11663 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11665 w
->update_mode_line
= Qt
;
11666 if (buffer_shared
> 1)
11667 update_mode_lines
++;
11670 /* Avoid invocation of point motion hooks by `current_column' below. */
11671 count1
= SPECPDL_INDEX ();
11672 specbind (Qinhibit_point_motion_hooks
, Qt
);
11674 /* If %c is in the mode line, update it if needed. */
11675 if (!NILP (w
->column_number_displayed
)
11676 /* This alternative quickly identifies a common case
11677 where no change is needed. */
11678 && !(PT
== XFASTINT (w
->last_point
)
11679 && XFASTINT (w
->last_modified
) >= MODIFF
11680 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11681 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
11682 w
->update_mode_line
= Qt
;
11684 unbind_to (count1
, Qnil
);
11686 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11688 /* The variable buffer_shared is set in redisplay_window and
11689 indicates that we redisplay a buffer in different windows. See
11691 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11692 || cursor_type_changed
);
11694 /* If specs for an arrow have changed, do thorough redisplay
11695 to ensure we remove any arrow that should no longer exist. */
11696 if (overlay_arrows_changed_p ())
11697 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11699 /* Normally the message* functions will have already displayed and
11700 updated the echo area, but the frame may have been trashed, or
11701 the update may have been preempted, so display the echo area
11702 again here. Checking message_cleared_p captures the case that
11703 the echo area should be cleared. */
11704 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11705 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11706 || (message_cleared_p
11707 && minibuf_level
== 0
11708 /* If the mini-window is currently selected, this means the
11709 echo-area doesn't show through. */
11710 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11712 int window_height_changed_p
= echo_area_display (0);
11715 /* If we don't display the current message, don't clear the
11716 message_cleared_p flag, because, if we did, we wouldn't clear
11717 the echo area in the next redisplay which doesn't preserve
11719 if (!display_last_displayed_message_p
)
11720 message_cleared_p
= 0;
11722 if (fonts_changed_p
)
11724 else if (window_height_changed_p
)
11726 consider_all_windows_p
= 1;
11727 ++update_mode_lines
;
11728 ++windows_or_buffers_changed
;
11730 /* If window configuration was changed, frames may have been
11731 marked garbaged. Clear them or we will experience
11732 surprises wrt scrolling. */
11733 if (frame_garbaged
)
11734 clear_garbaged_frames ();
11737 else if (EQ (selected_window
, minibuf_window
)
11738 && (current_buffer
->clip_changed
11739 || XFASTINT (w
->last_modified
) < MODIFF
11740 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11741 && resize_mini_window (w
, 0))
11743 /* Resized active mini-window to fit the size of what it is
11744 showing if its contents might have changed. */
11746 /* FIXME: this causes all frames to be updated, which seems unnecessary
11747 since only the current frame needs to be considered. This function needs
11748 to be rewritten with two variables, consider_all_windows and
11749 consider_all_frames. */
11750 consider_all_windows_p
= 1;
11751 ++windows_or_buffers_changed
;
11752 ++update_mode_lines
;
11754 /* If window configuration was changed, frames may have been
11755 marked garbaged. Clear them or we will experience
11756 surprises wrt scrolling. */
11757 if (frame_garbaged
)
11758 clear_garbaged_frames ();
11762 /* If showing the region, and mark has changed, we must redisplay
11763 the whole window. The assignment to this_line_start_pos prevents
11764 the optimization directly below this if-statement. */
11765 if (((!NILP (Vtransient_mark_mode
)
11766 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11767 != !NILP (w
->region_showing
))
11768 || (!NILP (w
->region_showing
)
11769 && !EQ (w
->region_showing
,
11770 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
11771 CHARPOS (this_line_start_pos
) = 0;
11773 /* Optimize the case that only the line containing the cursor in the
11774 selected window has changed. Variables starting with this_ are
11775 set in display_line and record information about the line
11776 containing the cursor. */
11777 tlbufpos
= this_line_start_pos
;
11778 tlendpos
= this_line_end_pos
;
11779 if (!consider_all_windows_p
11780 && CHARPOS (tlbufpos
) > 0
11781 && NILP (w
->update_mode_line
)
11782 && !current_buffer
->clip_changed
11783 && !current_buffer
->prevent_redisplay_optimizations_p
11784 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11785 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11786 /* Make sure recorded data applies to current buffer, etc. */
11787 && this_line_buffer
== current_buffer
11788 && current_buffer
== XBUFFER (w
->buffer
)
11789 && NILP (w
->force_start
)
11790 && NILP (w
->optional_new_start
)
11791 /* Point must be on the line that we have info recorded about. */
11792 && PT
>= CHARPOS (tlbufpos
)
11793 && PT
<= Z
- CHARPOS (tlendpos
)
11794 /* All text outside that line, including its final newline,
11795 must be unchanged. */
11796 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11797 CHARPOS (tlendpos
)))
11799 if (CHARPOS (tlbufpos
) > BEGV
11800 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11801 && (CHARPOS (tlbufpos
) == ZV
11802 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11803 /* Former continuation line has disappeared by becoming empty. */
11805 else if (XFASTINT (w
->last_modified
) < MODIFF
11806 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11807 || MINI_WINDOW_P (w
))
11809 /* We have to handle the case of continuation around a
11810 wide-column character (see the comment in indent.c around
11813 For instance, in the following case:
11815 -------- Insert --------
11816 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11817 J_I_ ==> J_I_ `^^' are cursors.
11821 As we have to redraw the line above, we cannot use this
11825 int line_height_before
= this_line_pixel_height
;
11827 /* Note that start_display will handle the case that the
11828 line starting at tlbufpos is a continuation line. */
11829 start_display (&it
, w
, tlbufpos
);
11831 /* Implementation note: It this still necessary? */
11832 if (it
.current_x
!= this_line_start_x
)
11835 TRACE ((stderr
, "trying display optimization 1\n"));
11836 w
->cursor
.vpos
= -1;
11837 overlay_arrow_seen
= 0;
11838 it
.vpos
= this_line_vpos
;
11839 it
.current_y
= this_line_y
;
11840 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11841 display_line (&it
);
11843 /* If line contains point, is not continued,
11844 and ends at same distance from eob as before, we win. */
11845 if (w
->cursor
.vpos
>= 0
11846 /* Line is not continued, otherwise this_line_start_pos
11847 would have been set to 0 in display_line. */
11848 && CHARPOS (this_line_start_pos
)
11849 /* Line ends as before. */
11850 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11851 /* Line has same height as before. Otherwise other lines
11852 would have to be shifted up or down. */
11853 && this_line_pixel_height
== line_height_before
)
11855 /* If this is not the window's last line, we must adjust
11856 the charstarts of the lines below. */
11857 if (it
.current_y
< it
.last_visible_y
)
11859 struct glyph_row
*row
11860 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11861 EMACS_INT delta
, delta_bytes
;
11863 /* We used to distinguish between two cases here,
11864 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11865 when the line ends in a newline or the end of the
11866 buffer's accessible portion. But both cases did
11867 the same, so they were collapsed. */
11869 - CHARPOS (tlendpos
)
11870 - MATRIX_ROW_START_CHARPOS (row
));
11871 delta_bytes
= (Z_BYTE
11872 - BYTEPOS (tlendpos
)
11873 - MATRIX_ROW_START_BYTEPOS (row
));
11875 increment_matrix_positions (w
->current_matrix
,
11876 this_line_vpos
+ 1,
11877 w
->current_matrix
->nrows
,
11878 delta
, delta_bytes
);
11881 /* If this row displays text now but previously didn't,
11882 or vice versa, w->window_end_vpos may have to be
11884 if ((it
.glyph_row
- 1)->displays_text_p
)
11886 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11887 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11889 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11890 && this_line_vpos
> 0)
11891 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11892 w
->window_end_valid
= Qnil
;
11894 /* Update hint: No need to try to scroll in update_window. */
11895 w
->desired_matrix
->no_scrolling_p
= 1;
11898 *w
->desired_matrix
->method
= 0;
11899 debug_method_add (w
, "optimization 1");
11901 #ifdef HAVE_WINDOW_SYSTEM
11902 update_window_fringes (w
, 0);
11909 else if (/* Cursor position hasn't changed. */
11910 PT
== XFASTINT (w
->last_point
)
11911 /* Make sure the cursor was last displayed
11912 in this window. Otherwise we have to reposition it. */
11913 && 0 <= w
->cursor
.vpos
11914 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11918 do_pending_window_change (1);
11919 /* If selected_window changed, redisplay again. */
11920 if (WINDOWP (selected_window
)
11921 && (w
= XWINDOW (selected_window
)) != sw
)
11924 /* We used to always goto end_of_redisplay here, but this
11925 isn't enough if we have a blinking cursor. */
11926 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11927 goto end_of_redisplay
;
11931 /* If highlighting the region, or if the cursor is in the echo area,
11932 then we can't just move the cursor. */
11933 else if (! (!NILP (Vtransient_mark_mode
)
11934 && !NILP (BVAR (current_buffer
, mark_active
)))
11935 && (EQ (selected_window
, BVAR (current_buffer
, last_selected_window
))
11936 || highlight_nonselected_windows
)
11937 && NILP (w
->region_showing
)
11938 && NILP (Vshow_trailing_whitespace
)
11939 && !cursor_in_echo_area
)
11942 struct glyph_row
*row
;
11944 /* Skip from tlbufpos to PT and see where it is. Note that
11945 PT may be in invisible text. If so, we will end at the
11946 next visible position. */
11947 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11948 NULL
, DEFAULT_FACE_ID
);
11949 it
.current_x
= this_line_start_x
;
11950 it
.current_y
= this_line_y
;
11951 it
.vpos
= this_line_vpos
;
11953 /* The call to move_it_to stops in front of PT, but
11954 moves over before-strings. */
11955 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11957 if (it
.vpos
== this_line_vpos
11958 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11961 xassert (this_line_vpos
== it
.vpos
);
11962 xassert (this_line_y
== it
.current_y
);
11963 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11965 *w
->desired_matrix
->method
= 0;
11966 debug_method_add (w
, "optimization 3");
11975 /* Text changed drastically or point moved off of line. */
11976 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11979 CHARPOS (this_line_start_pos
) = 0;
11980 consider_all_windows_p
|= buffer_shared
> 1;
11981 ++clear_face_cache_count
;
11982 #ifdef HAVE_WINDOW_SYSTEM
11983 ++clear_image_cache_count
;
11986 /* Build desired matrices, and update the display. If
11987 consider_all_windows_p is non-zero, do it for all windows on all
11988 frames. Otherwise do it for selected_window, only. */
11990 if (consider_all_windows_p
)
11992 Lisp_Object tail
, frame
;
11994 FOR_EACH_FRAME (tail
, frame
)
11995 XFRAME (frame
)->updated_p
= 0;
11997 /* Recompute # windows showing selected buffer. This will be
11998 incremented each time such a window is displayed. */
12001 FOR_EACH_FRAME (tail
, frame
)
12003 struct frame
*f
= XFRAME (frame
);
12005 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12007 if (! EQ (frame
, selected_frame
))
12008 /* Select the frame, for the sake of frame-local
12010 select_frame_for_redisplay (frame
);
12012 /* Mark all the scroll bars to be removed; we'll redeem
12013 the ones we want when we redisplay their windows. */
12014 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12015 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12017 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12018 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12020 /* The X error handler may have deleted that frame. */
12021 if (!FRAME_LIVE_P (f
))
12024 /* Any scroll bars which redisplay_windows should have
12025 nuked should now go away. */
12026 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12027 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12029 /* If fonts changed, display again. */
12030 /* ??? rms: I suspect it is a mistake to jump all the way
12031 back to retry here. It should just retry this frame. */
12032 if (fonts_changed_p
)
12035 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12037 /* See if we have to hscroll. */
12038 if (!f
->already_hscrolled_p
)
12040 f
->already_hscrolled_p
= 1;
12041 if (hscroll_windows (f
->root_window
))
12045 /* Prevent various kinds of signals during display
12046 update. stdio is not robust about handling
12047 signals, which can cause an apparent I/O
12049 if (interrupt_input
)
12050 unrequest_sigio ();
12053 /* Update the display. */
12054 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12055 pending
|= update_frame (f
, 0, 0);
12061 if (!EQ (old_frame
, selected_frame
)
12062 && FRAME_LIVE_P (XFRAME (old_frame
)))
12063 /* We played a bit fast-and-loose above and allowed selected_frame
12064 and selected_window to be temporarily out-of-sync but let's make
12065 sure this stays contained. */
12066 select_frame_for_redisplay (old_frame
);
12067 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12071 /* Do the mark_window_display_accurate after all windows have
12072 been redisplayed because this call resets flags in buffers
12073 which are needed for proper redisplay. */
12074 FOR_EACH_FRAME (tail
, frame
)
12076 struct frame
*f
= XFRAME (frame
);
12079 mark_window_display_accurate (f
->root_window
, 1);
12080 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12081 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12086 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12088 Lisp_Object mini_window
;
12089 struct frame
*mini_frame
;
12091 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12092 /* Use list_of_error, not Qerror, so that
12093 we catch only errors and don't run the debugger. */
12094 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12096 redisplay_window_error
);
12098 /* Compare desired and current matrices, perform output. */
12101 /* If fonts changed, display again. */
12102 if (fonts_changed_p
)
12105 /* Prevent various kinds of signals during display update.
12106 stdio is not robust about handling signals,
12107 which can cause an apparent I/O error. */
12108 if (interrupt_input
)
12109 unrequest_sigio ();
12112 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12114 if (hscroll_windows (selected_window
))
12117 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12118 pending
= update_frame (sf
, 0, 0);
12121 /* We may have called echo_area_display at the top of this
12122 function. If the echo area is on another frame, that may
12123 have put text on a frame other than the selected one, so the
12124 above call to update_frame would not have caught it. Catch
12126 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12127 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12129 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12131 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12132 pending
|= update_frame (mini_frame
, 0, 0);
12133 if (!pending
&& hscroll_windows (mini_window
))
12138 /* If display was paused because of pending input, make sure we do a
12139 thorough update the next time. */
12142 /* Prevent the optimization at the beginning of
12143 redisplay_internal that tries a single-line update of the
12144 line containing the cursor in the selected window. */
12145 CHARPOS (this_line_start_pos
) = 0;
12147 /* Let the overlay arrow be updated the next time. */
12148 update_overlay_arrows (0);
12150 /* If we pause after scrolling, some rows in the current
12151 matrices of some windows are not valid. */
12152 if (!WINDOW_FULL_WIDTH_P (w
)
12153 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12154 update_mode_lines
= 1;
12158 if (!consider_all_windows_p
)
12160 /* This has already been done above if
12161 consider_all_windows_p is set. */
12162 mark_window_display_accurate_1 (w
, 1);
12164 /* Say overlay arrows are up to date. */
12165 update_overlay_arrows (1);
12167 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12168 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12171 update_mode_lines
= 0;
12172 windows_or_buffers_changed
= 0;
12173 cursor_type_changed
= 0;
12176 /* Start SIGIO interrupts coming again. Having them off during the
12177 code above makes it less likely one will discard output, but not
12178 impossible, since there might be stuff in the system buffer here.
12179 But it is much hairier to try to do anything about that. */
12180 if (interrupt_input
)
12184 /* If a frame has become visible which was not before, redisplay
12185 again, so that we display it. Expose events for such a frame
12186 (which it gets when becoming visible) don't call the parts of
12187 redisplay constructing glyphs, so simply exposing a frame won't
12188 display anything in this case. So, we have to display these
12189 frames here explicitly. */
12192 Lisp_Object tail
, frame
;
12195 FOR_EACH_FRAME (tail
, frame
)
12197 int this_is_visible
= 0;
12199 if (XFRAME (frame
)->visible
)
12200 this_is_visible
= 1;
12201 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12202 if (XFRAME (frame
)->visible
)
12203 this_is_visible
= 1;
12205 if (this_is_visible
)
12209 if (new_count
!= number_of_visible_frames
)
12210 windows_or_buffers_changed
++;
12213 /* Change frame size now if a change is pending. */
12214 do_pending_window_change (1);
12216 /* If we just did a pending size change, or have additional
12217 visible frames, or selected_window changed, redisplay again. */
12218 if ((windows_or_buffers_changed
&& !pending
)
12219 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
12222 /* Clear the face and image caches.
12224 We used to do this only if consider_all_windows_p. But the cache
12225 needs to be cleared if a timer creates images in the current
12226 buffer (e.g. the test case in Bug#6230). */
12228 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12230 clear_face_cache (0);
12231 clear_face_cache_count
= 0;
12234 #ifdef HAVE_WINDOW_SYSTEM
12235 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12237 clear_image_caches (Qnil
);
12238 clear_image_cache_count
= 0;
12240 #endif /* HAVE_WINDOW_SYSTEM */
12243 unbind_to (count
, Qnil
);
12248 /* Redisplay, but leave alone any recent echo area message unless
12249 another message has been requested in its place.
12251 This is useful in situations where you need to redisplay but no
12252 user action has occurred, making it inappropriate for the message
12253 area to be cleared. See tracking_off and
12254 wait_reading_process_output for examples of these situations.
12256 FROM_WHERE is an integer saying from where this function was
12257 called. This is useful for debugging. */
12260 redisplay_preserve_echo_area (int from_where
)
12262 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12264 if (!NILP (echo_area_buffer
[1]))
12266 /* We have a previously displayed message, but no current
12267 message. Redisplay the previous message. */
12268 display_last_displayed_message_p
= 1;
12269 redisplay_internal ();
12270 display_last_displayed_message_p
= 0;
12273 redisplay_internal ();
12275 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12276 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12277 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12281 /* Function registered with record_unwind_protect in
12282 redisplay_internal. Reset redisplaying_p to the value it had
12283 before redisplay_internal was called, and clear
12284 prevent_freeing_realized_faces_p. It also selects the previously
12285 selected frame, unless it has been deleted (by an X connection
12286 failure during redisplay, for example). */
12289 unwind_redisplay (Lisp_Object val
)
12291 Lisp_Object old_redisplaying_p
, old_frame
;
12293 old_redisplaying_p
= XCAR (val
);
12294 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12295 old_frame
= XCDR (val
);
12296 if (! EQ (old_frame
, selected_frame
)
12297 && FRAME_LIVE_P (XFRAME (old_frame
)))
12298 select_frame_for_redisplay (old_frame
);
12303 /* Mark the display of window W as accurate or inaccurate. If
12304 ACCURATE_P is non-zero mark display of W as accurate. If
12305 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12306 redisplay_internal is called. */
12309 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
12311 if (BUFFERP (w
->buffer
))
12313 struct buffer
*b
= XBUFFER (w
->buffer
);
12316 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12317 w
->last_overlay_modified
12318 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12320 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12324 b
->clip_changed
= 0;
12325 b
->prevent_redisplay_optimizations_p
= 0;
12327 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12328 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12329 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12330 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12332 w
->current_matrix
->buffer
= b
;
12333 w
->current_matrix
->begv
= BUF_BEGV (b
);
12334 w
->current_matrix
->zv
= BUF_ZV (b
);
12336 w
->last_cursor
= w
->cursor
;
12337 w
->last_cursor_off_p
= w
->cursor_off_p
;
12339 if (w
== XWINDOW (selected_window
))
12340 w
->last_point
= make_number (BUF_PT (b
));
12342 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12348 w
->window_end_valid
= w
->buffer
;
12349 w
->update_mode_line
= Qnil
;
12354 /* Mark the display of windows in the window tree rooted at WINDOW as
12355 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12356 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12357 be redisplayed the next time redisplay_internal is called. */
12360 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
12364 for (; !NILP (window
); window
= w
->next
)
12366 w
= XWINDOW (window
);
12367 mark_window_display_accurate_1 (w
, accurate_p
);
12369 if (!NILP (w
->vchild
))
12370 mark_window_display_accurate (w
->vchild
, accurate_p
);
12371 if (!NILP (w
->hchild
))
12372 mark_window_display_accurate (w
->hchild
, accurate_p
);
12377 update_overlay_arrows (1);
12381 /* Force a thorough redisplay the next time by setting
12382 last_arrow_position and last_arrow_string to t, which is
12383 unequal to any useful value of Voverlay_arrow_... */
12384 update_overlay_arrows (-1);
12389 /* Return value in display table DP (Lisp_Char_Table *) for character
12390 C. Since a display table doesn't have any parent, we don't have to
12391 follow parent. Do not call this function directly but use the
12392 macro DISP_CHAR_VECTOR. */
12395 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
12399 if (ASCII_CHAR_P (c
))
12402 if (SUB_CHAR_TABLE_P (val
))
12403 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12409 XSETCHAR_TABLE (table
, dp
);
12410 val
= char_table_ref (table
, c
);
12419 /***********************************************************************
12421 ***********************************************************************/
12423 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12426 redisplay_windows (Lisp_Object window
)
12428 while (!NILP (window
))
12430 struct window
*w
= XWINDOW (window
);
12432 if (!NILP (w
->hchild
))
12433 redisplay_windows (w
->hchild
);
12434 else if (!NILP (w
->vchild
))
12435 redisplay_windows (w
->vchild
);
12436 else if (!NILP (w
->buffer
))
12438 displayed_buffer
= XBUFFER (w
->buffer
);
12439 /* Use list_of_error, not Qerror, so that
12440 we catch only errors and don't run the debugger. */
12441 internal_condition_case_1 (redisplay_window_0
, window
,
12443 redisplay_window_error
);
12451 redisplay_window_error (Lisp_Object ignore
)
12453 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12458 redisplay_window_0 (Lisp_Object window
)
12460 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12461 redisplay_window (window
, 0);
12466 redisplay_window_1 (Lisp_Object window
)
12468 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12469 redisplay_window (window
, 1);
12474 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12475 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12476 which positions recorded in ROW differ from current buffer
12479 Return 0 if cursor is not on this row, 1 otherwise. */
12482 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
12483 struct glyph_matrix
*matrix
,
12484 EMACS_INT delta
, EMACS_INT delta_bytes
,
12487 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12488 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12489 struct glyph
*cursor
= NULL
;
12490 /* The last known character position in row. */
12491 EMACS_INT last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12493 EMACS_INT pt_old
= PT
- delta
;
12494 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12495 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12496 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
12497 /* A glyph beyond the edge of TEXT_AREA which we should never
12499 struct glyph
*glyphs_end
= end
;
12500 /* Non-zero means we've found a match for cursor position, but that
12501 glyph has the avoid_cursor_p flag set. */
12502 int match_with_avoid_cursor
= 0;
12503 /* Non-zero means we've seen at least one glyph that came from a
12505 int string_seen
= 0;
12506 /* Largest and smalles buffer positions seen so far during scan of
12508 EMACS_INT bpos_max
= pos_before
;
12509 EMACS_INT bpos_min
= pos_after
;
12510 /* Last buffer position covered by an overlay string with an integer
12511 `cursor' property. */
12512 EMACS_INT bpos_covered
= 0;
12514 /* Skip over glyphs not having an object at the start and the end of
12515 the row. These are special glyphs like truncation marks on
12516 terminal frames. */
12517 if (row
->displays_text_p
)
12519 if (!row
->reversed_p
)
12522 && INTEGERP (glyph
->object
)
12523 && glyph
->charpos
< 0)
12525 x
+= glyph
->pixel_width
;
12529 && INTEGERP ((end
- 1)->object
)
12530 /* CHARPOS is zero for blanks and stretch glyphs
12531 inserted by extend_face_to_end_of_line. */
12532 && (end
- 1)->charpos
<= 0)
12534 glyph_before
= glyph
- 1;
12541 /* If the glyph row is reversed, we need to process it from back
12542 to front, so swap the edge pointers. */
12543 glyphs_end
= end
= glyph
- 1;
12544 glyph
+= row
->used
[TEXT_AREA
] - 1;
12546 while (glyph
> end
+ 1
12547 && INTEGERP (glyph
->object
)
12548 && glyph
->charpos
< 0)
12551 x
-= glyph
->pixel_width
;
12553 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
12555 /* By default, in reversed rows we put the cursor on the
12556 rightmost (first in the reading order) glyph. */
12557 for (g
= end
+ 1; g
< glyph
; g
++)
12558 x
+= g
->pixel_width
;
12560 && INTEGERP ((end
+ 1)->object
)
12561 && (end
+ 1)->charpos
<= 0)
12563 glyph_before
= glyph
+ 1;
12567 else if (row
->reversed_p
)
12569 /* In R2L rows that don't display text, put the cursor on the
12570 rightmost glyph. Case in point: an empty last line that is
12571 part of an R2L paragraph. */
12573 /* Avoid placing the cursor on the last glyph of the row, where
12574 on terminal frames we hold the vertical border between
12575 adjacent windows. */
12576 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
12577 && !WINDOW_RIGHTMOST_P (w
)
12578 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
12580 x
= -1; /* will be computed below, at label compute_x */
12583 /* Step 1: Try to find the glyph whose character position
12584 corresponds to point. If that's not possible, find 2 glyphs
12585 whose character positions are the closest to point, one before
12586 point, the other after it. */
12587 if (!row
->reversed_p
)
12588 while (/* not marched to end of glyph row */
12590 /* glyph was not inserted by redisplay for internal purposes */
12591 && !INTEGERP (glyph
->object
))
12593 if (BUFFERP (glyph
->object
))
12595 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12597 if (glyph
->charpos
> bpos_max
)
12598 bpos_max
= glyph
->charpos
;
12599 if (glyph
->charpos
< bpos_min
)
12600 bpos_min
= glyph
->charpos
;
12601 if (!glyph
->avoid_cursor_p
)
12603 /* If we hit point, we've found the glyph on which to
12604 display the cursor. */
12607 match_with_avoid_cursor
= 0;
12610 /* See if we've found a better approximation to
12611 POS_BEFORE or to POS_AFTER. Note that we want the
12612 first (leftmost) glyph of all those that are the
12613 closest from below, and the last (rightmost) of all
12614 those from above. */
12615 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12617 pos_before
= glyph
->charpos
;
12618 glyph_before
= glyph
;
12620 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12622 pos_after
= glyph
->charpos
;
12623 glyph_after
= glyph
;
12626 else if (dpos
== 0)
12627 match_with_avoid_cursor
= 1;
12629 else if (STRINGP (glyph
->object
))
12631 Lisp_Object chprop
;
12632 EMACS_INT glyph_pos
= glyph
->charpos
;
12634 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12636 if (INTEGERP (chprop
))
12638 bpos_covered
= bpos_max
+ XINT (chprop
);
12639 /* If the `cursor' property covers buffer positions up
12640 to and including point, we should display cursor on
12641 this glyph. Note that overlays and text properties
12642 with string values stop bidi reordering, so every
12643 buffer position to the left of the string is always
12644 smaller than any position to the right of the
12645 string. Therefore, if a `cursor' property on one
12646 of the string's characters has an integer value, we
12647 will break out of the loop below _before_ we get to
12648 the position match above. IOW, integer values of
12649 the `cursor' property override the "exact match for
12650 point" strategy of positioning the cursor. */
12651 /* Implementation note: bpos_max == pt_old when, e.g.,
12652 we are in an empty line, where bpos_max is set to
12653 MATRIX_ROW_START_CHARPOS, see above. */
12654 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12663 x
+= glyph
->pixel_width
;
12666 else if (glyph
> end
) /* row is reversed */
12667 while (!INTEGERP (glyph
->object
))
12669 if (BUFFERP (glyph
->object
))
12671 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12673 if (glyph
->charpos
> bpos_max
)
12674 bpos_max
= glyph
->charpos
;
12675 if (glyph
->charpos
< bpos_min
)
12676 bpos_min
= glyph
->charpos
;
12677 if (!glyph
->avoid_cursor_p
)
12681 match_with_avoid_cursor
= 0;
12684 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12686 pos_before
= glyph
->charpos
;
12687 glyph_before
= glyph
;
12689 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12691 pos_after
= glyph
->charpos
;
12692 glyph_after
= glyph
;
12695 else if (dpos
== 0)
12696 match_with_avoid_cursor
= 1;
12698 else if (STRINGP (glyph
->object
))
12700 Lisp_Object chprop
;
12701 EMACS_INT glyph_pos
= glyph
->charpos
;
12703 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12705 if (INTEGERP (chprop
))
12707 bpos_covered
= bpos_max
+ XINT (chprop
);
12708 /* If the `cursor' property covers buffer positions up
12709 to and including point, we should display cursor on
12711 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12720 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
12722 x
--; /* can't use any pixel_width */
12725 x
-= glyph
->pixel_width
;
12728 /* Step 2: If we didn't find an exact match for point, we need to
12729 look for a proper place to put the cursor among glyphs between
12730 GLYPH_BEFORE and GLYPH_AFTER. */
12731 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
12732 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12733 && bpos_covered
< pt_old
)
12735 /* An empty line has a single glyph whose OBJECT is zero and
12736 whose CHARPOS is the position of a newline on that line.
12737 Note that on a TTY, there are more glyphs after that, which
12738 were produced by extend_face_to_end_of_line, but their
12739 CHARPOS is zero or negative. */
12741 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
12742 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
12744 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
12746 EMACS_INT ellipsis_pos
;
12748 /* Scan back over the ellipsis glyphs. */
12749 if (!row
->reversed_p
)
12751 ellipsis_pos
= (glyph
- 1)->charpos
;
12752 while (glyph
> row
->glyphs
[TEXT_AREA
]
12753 && (glyph
- 1)->charpos
== ellipsis_pos
)
12754 glyph
--, x
-= glyph
->pixel_width
;
12755 /* That loop always goes one position too far, including
12756 the glyph before the ellipsis. So scan forward over
12758 x
+= glyph
->pixel_width
;
12761 else /* row is reversed */
12763 ellipsis_pos
= (glyph
+ 1)->charpos
;
12764 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
12765 && (glyph
+ 1)->charpos
== ellipsis_pos
)
12766 glyph
++, x
+= glyph
->pixel_width
;
12767 x
-= glyph
->pixel_width
;
12771 else if (match_with_avoid_cursor
12772 /* A truncated row may not include PT among its
12773 character positions. Setting the cursor inside the
12774 scroll margin will trigger recalculation of hscroll
12775 in hscroll_window_tree. */
12776 || (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
12777 || (row
->truncated_on_right_p
&& pt_old
> bpos_max
)
12778 /* Zero-width characters produce no glyphs. */
12781 && (row
->reversed_p
12782 ? glyph_after
> glyphs_end
12783 : glyph_after
< glyphs_end
)))
12785 cursor
= glyph_after
;
12788 else if (string_seen
)
12790 int incr
= row
->reversed_p
? -1 : +1;
12792 /* Need to find the glyph that came out of a string which is
12793 present at point. That glyph is somewhere between
12794 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
12795 positioned between POS_BEFORE and POS_AFTER in the
12797 struct glyph
*start
, *stop
;
12798 EMACS_INT pos
= pos_before
;
12802 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
12803 correspond to POS_BEFORE and POS_AFTER, respectively. We
12804 need START and STOP in the order that corresponds to the
12805 row's direction as given by its reversed_p flag. If the
12806 directionality of characters between POS_BEFORE and
12807 POS_AFTER is the opposite of the row's base direction,
12808 these characters will have been reordered for display,
12809 and we need to reverse START and STOP. */
12810 if (!row
->reversed_p
)
12812 start
= min (glyph_before
, glyph_after
);
12813 stop
= max (glyph_before
, glyph_after
);
12817 start
= max (glyph_before
, glyph_after
);
12818 stop
= min (glyph_before
, glyph_after
);
12820 for (glyph
= start
+ incr
;
12821 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
12824 /* Any glyphs that come from the buffer are here because
12825 of bidi reordering. Skip them, and only pay
12826 attention to glyphs that came from some string. */
12827 if (STRINGP (glyph
->object
))
12832 str
= glyph
->object
;
12833 tem
= string_buffer_position_lim (str
, pos
, pos_after
, 0);
12834 if (tem
== 0 /* from overlay */
12837 /* If the string from which this glyph came is
12838 found in the buffer at point, then we've
12839 found the glyph we've been looking for. If
12840 it comes from an overlay (tem == 0), and it
12841 has the `cursor' property on one of its
12842 glyphs, record that glyph as a candidate for
12843 displaying the cursor. (As in the
12844 unidirectional version, we will display the
12845 cursor on the last candidate we find.) */
12846 if (tem
== 0 || tem
== pt_old
)
12848 /* The glyphs from this string could have
12849 been reordered. Find the one with the
12850 smallest string position. Or there could
12851 be a character in the string with the
12852 `cursor' property, which means display
12853 cursor on that character's glyph. */
12854 EMACS_INT strpos
= glyph
->charpos
;
12859 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12860 && EQ (glyph
->object
, str
);
12864 EMACS_INT gpos
= glyph
->charpos
;
12866 cprop
= Fget_char_property (make_number (gpos
),
12874 if (tem
&& glyph
->charpos
< strpos
)
12876 strpos
= glyph
->charpos
;
12885 pos
= tem
+ 1; /* don't find previous instances */
12887 /* This string is not what we want; skip all of the
12888 glyphs that came from it. */
12889 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12890 && EQ (glyph
->object
, str
))
12897 /* If we reached the end of the line, and END was from a string,
12898 the cursor is not on this line. */
12900 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
12901 && STRINGP (end
->object
)
12902 && row
->continued_p
)
12908 if (cursor
!= NULL
)
12914 /* Need to compute x that corresponds to GLYPH. */
12915 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
12917 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
12919 x
+= g
->pixel_width
;
12923 /* ROW could be part of a continued line, which, under bidi
12924 reordering, might have other rows whose start and end charpos
12925 occlude point. Only set w->cursor if we found a better
12926 approximation to the cursor position than we have from previously
12927 examined candidate rows belonging to the same continued line. */
12928 if (/* we already have a candidate row */
12929 w
->cursor
.vpos
>= 0
12930 /* that candidate is not the row we are processing */
12931 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
12932 /* the row we are processing is part of a continued line */
12933 && (row
->continued_p
|| MATRIX_ROW_CONTINUATION_LINE_P (row
))
12934 /* Make sure cursor.vpos specifies a row whose start and end
12935 charpos occlude point. This is because some callers of this
12936 function leave cursor.vpos at the row where the cursor was
12937 displayed during the last redisplay cycle. */
12938 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
12939 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
12942 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
12944 /* Don't consider glyphs that are outside TEXT_AREA. */
12945 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
12947 /* Keep the candidate whose buffer position is the closest to
12949 if (/* previous candidate is a glyph in TEXT_AREA of that row */
12950 w
->cursor
.hpos
>= 0
12951 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
12952 && BUFFERP (g1
->object
)
12953 && (g1
->charpos
== pt_old
/* an exact match always wins */
12954 || (BUFFERP (glyph
->object
)
12955 && eabs (g1
->charpos
- pt_old
)
12956 < eabs (glyph
->charpos
- pt_old
))))
12958 /* If this candidate gives an exact match, use that. */
12959 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12960 /* Otherwise, keep the candidate that comes from a row
12961 spanning less buffer positions. This may win when one or
12962 both candidate positions are on glyphs that came from
12963 display strings, for which we cannot compare buffer
12965 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
12966 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
12967 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
12970 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12972 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12973 w
->cursor
.y
= row
->y
+ dy
;
12975 if (w
== XWINDOW (selected_window
))
12977 if (!row
->continued_p
12978 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12981 this_line_buffer
= XBUFFER (w
->buffer
);
12983 CHARPOS (this_line_start_pos
)
12984 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12985 BYTEPOS (this_line_start_pos
)
12986 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12988 CHARPOS (this_line_end_pos
)
12989 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12990 BYTEPOS (this_line_end_pos
)
12991 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12993 this_line_y
= w
->cursor
.y
;
12994 this_line_pixel_height
= row
->height
;
12995 this_line_vpos
= w
->cursor
.vpos
;
12996 this_line_start_x
= row
->x
;
12999 CHARPOS (this_line_start_pos
) = 0;
13006 /* Run window scroll functions, if any, for WINDOW with new window
13007 start STARTP. Sets the window start of WINDOW to that position.
13009 We assume that the window's buffer is really current. */
13011 static inline struct text_pos
13012 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
13014 struct window
*w
= XWINDOW (window
);
13015 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13017 if (current_buffer
!= XBUFFER (w
->buffer
))
13020 if (!NILP (Vwindow_scroll_functions
))
13022 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13023 make_number (CHARPOS (startp
)));
13024 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13025 /* In case the hook functions switch buffers. */
13026 if (current_buffer
!= XBUFFER (w
->buffer
))
13027 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13034 /* Make sure the line containing the cursor is fully visible.
13035 A value of 1 means there is nothing to be done.
13036 (Either the line is fully visible, or it cannot be made so,
13037 or we cannot tell.)
13039 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13040 is higher than window.
13042 A value of 0 means the caller should do scrolling
13043 as if point had gone off the screen. */
13046 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
13048 struct glyph_matrix
*matrix
;
13049 struct glyph_row
*row
;
13052 if (!make_cursor_line_fully_visible_p
)
13055 /* It's not always possible to find the cursor, e.g, when a window
13056 is full of overlay strings. Don't do anything in that case. */
13057 if (w
->cursor
.vpos
< 0)
13060 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13061 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13063 /* If the cursor row is not partially visible, there's nothing to do. */
13064 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13067 /* If the row the cursor is in is taller than the window's height,
13068 it's not clear what to do, so do nothing. */
13069 window_height
= window_box_height (w
);
13070 if (row
->height
>= window_height
)
13072 if (!force_p
|| MINI_WINDOW_P (w
)
13073 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13080 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13081 non-zero means only WINDOW is redisplayed in redisplay_internal.
13082 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
13083 in redisplay_window to bring a partially visible line into view in
13084 the case that only the cursor has moved.
13086 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13087 last screen line's vertical height extends past the end of the screen.
13091 1 if scrolling succeeded
13093 0 if scrolling didn't find point.
13095 -1 if new fonts have been loaded so that we must interrupt
13096 redisplay, adjust glyph matrices, and try again. */
13102 SCROLLING_NEED_LARGER_MATRICES
13105 /* If scroll-conservatively is more than this, never recenter.
13107 If you change this, don't forget to update the doc string of
13108 `scroll-conservatively' and the Emacs manual. */
13109 #define SCROLL_LIMIT 100
13112 try_scrolling (Lisp_Object window
, int just_this_one_p
,
13113 EMACS_INT arg_scroll_conservatively
, EMACS_INT scroll_step
,
13114 int temp_scroll_step
, int last_line_misfit
)
13116 struct window
*w
= XWINDOW (window
);
13117 struct frame
*f
= XFRAME (w
->frame
);
13118 struct text_pos pos
, startp
;
13120 int this_scroll_margin
, scroll_max
, rc
, height
;
13121 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13122 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13123 Lisp_Object aggressive
;
13124 /* We will never try scrolling more than this number of lines. */
13125 int scroll_limit
= SCROLL_LIMIT
;
13128 debug_method_add (w
, "try_scrolling");
13131 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13133 /* Compute scroll margin height in pixels. We scroll when point is
13134 within this distance from the top or bottom of the window. */
13135 if (scroll_margin
> 0)
13136 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13137 * FRAME_LINE_HEIGHT (f
);
13139 this_scroll_margin
= 0;
13141 /* Force arg_scroll_conservatively to have a reasonable value, to
13142 avoid scrolling too far away with slow move_it_* functions. Note
13143 that the user can supply scroll-conservatively equal to
13144 `most-positive-fixnum', which can be larger than INT_MAX. */
13145 if (arg_scroll_conservatively
> scroll_limit
)
13147 arg_scroll_conservatively
= scroll_limit
+ 1;
13148 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
13150 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
13151 /* Compute how much we should try to scroll maximally to bring
13152 point into view. */
13153 scroll_max
= (max (scroll_step
,
13154 max (arg_scroll_conservatively
, temp_scroll_step
))
13155 * FRAME_LINE_HEIGHT (f
));
13156 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
13157 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
13158 /* We're trying to scroll because of aggressive scrolling but no
13159 scroll_step is set. Choose an arbitrary one. */
13160 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13166 /* Decide whether to scroll down. */
13167 if (PT
> CHARPOS (startp
))
13169 int scroll_margin_y
;
13171 /* Compute the pixel ypos of the scroll margin, then move it to
13172 either that ypos or PT, whichever comes first. */
13173 start_display (&it
, w
, startp
);
13174 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13175 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13176 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13177 (MOVE_TO_POS
| MOVE_TO_Y
));
13179 if (PT
> CHARPOS (it
.current
.pos
))
13181 int y0
= line_bottom_y (&it
);
13182 /* Compute how many pixels below window bottom to stop searching
13183 for PT. This avoids costly search for PT that is far away if
13184 the user limited scrolling by a small number of lines, but
13185 always finds PT if scroll_conservatively is set to a large
13186 number, such as most-positive-fixnum. */
13187 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
13188 int y_to_move
= it
.last_visible_y
+ slack
;
13190 /* Compute the distance from the scroll margin to PT or to
13191 the scroll limit, whichever comes first. This should
13192 include the height of the cursor line, to make that line
13194 move_it_to (&it
, PT
, -1, y_to_move
,
13195 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13196 dy
= line_bottom_y (&it
) - y0
;
13198 if (dy
> scroll_max
)
13199 return SCROLLING_FAILED
;
13207 /* Point is in or below the bottom scroll margin, so move the
13208 window start down. If scrolling conservatively, move it just
13209 enough down to make point visible. If scroll_step is set,
13210 move it down by scroll_step. */
13211 if (arg_scroll_conservatively
)
13213 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13214 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
13215 else if (scroll_step
|| temp_scroll_step
)
13216 amount_to_scroll
= scroll_max
;
13219 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
13220 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13221 if (NUMBERP (aggressive
))
13223 double float_amount
= XFLOATINT (aggressive
) * height
;
13224 amount_to_scroll
= float_amount
;
13225 if (amount_to_scroll
== 0 && float_amount
> 0)
13226 amount_to_scroll
= 1;
13227 /* Don't let point enter the scroll margin near top of
13229 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13230 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13234 if (amount_to_scroll
<= 0)
13235 return SCROLLING_FAILED
;
13237 start_display (&it
, w
, startp
);
13238 if (arg_scroll_conservatively
<= scroll_limit
)
13239 move_it_vertically (&it
, amount_to_scroll
);
13242 /* Extra precision for users who set scroll-conservatively
13243 to a large number: make sure the amount we scroll
13244 the window start is never less than amount_to_scroll,
13245 which was computed as distance from window bottom to
13246 point. This matters when lines at window top and lines
13247 below window bottom have different height. */
13248 struct it it1
= it
;
13249 /* We use a temporary it1 because line_bottom_y can modify
13250 its argument, if it moves one line down; see there. */
13251 int start_y
= line_bottom_y (&it1
);
13254 move_it_by_lines (&it
, 1);
13256 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
13259 /* If STARTP is unchanged, move it down another screen line. */
13260 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13261 move_it_by_lines (&it
, 1);
13262 startp
= it
.current
.pos
;
13266 struct text_pos scroll_margin_pos
= startp
;
13268 /* See if point is inside the scroll margin at the top of the
13270 if (this_scroll_margin
)
13272 start_display (&it
, w
, startp
);
13273 move_it_vertically (&it
, this_scroll_margin
);
13274 scroll_margin_pos
= it
.current
.pos
;
13277 if (PT
< CHARPOS (scroll_margin_pos
))
13279 /* Point is in the scroll margin at the top of the window or
13280 above what is displayed in the window. */
13283 /* Compute the vertical distance from PT to the scroll
13284 margin position. Move as far as scroll_max allows, or
13285 one screenful, or 10 screen lines, whichever is largest.
13286 Give up if distance is greater than scroll_max. */
13287 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13288 start_display (&it
, w
, pos
);
13290 y_to_move
= max (it
.last_visible_y
,
13291 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
13292 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13294 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13295 dy
= it
.current_y
- y0
;
13296 if (dy
> scroll_max
)
13297 return SCROLLING_FAILED
;
13299 /* Compute new window start. */
13300 start_display (&it
, w
, startp
);
13302 if (arg_scroll_conservatively
)
13303 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
13304 max (scroll_step
, temp_scroll_step
));
13305 else if (scroll_step
|| temp_scroll_step
)
13306 amount_to_scroll
= scroll_max
;
13309 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
13310 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13311 if (NUMBERP (aggressive
))
13313 double float_amount
= XFLOATINT (aggressive
) * height
;
13314 amount_to_scroll
= float_amount
;
13315 if (amount_to_scroll
== 0 && float_amount
> 0)
13316 amount_to_scroll
= 1;
13317 amount_to_scroll
-=
13318 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
13319 /* Don't let point enter the scroll margin near
13320 bottom of the window. */
13321 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13322 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13326 if (amount_to_scroll
<= 0)
13327 return SCROLLING_FAILED
;
13329 move_it_vertically_backward (&it
, amount_to_scroll
);
13330 startp
= it
.current
.pos
;
13334 /* Run window scroll functions. */
13335 startp
= run_window_scroll_functions (window
, startp
);
13337 /* Display the window. Give up if new fonts are loaded, or if point
13339 if (!try_window (window
, startp
, 0))
13340 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13341 else if (w
->cursor
.vpos
< 0)
13343 clear_glyph_matrix (w
->desired_matrix
);
13344 rc
= SCROLLING_FAILED
;
13348 /* Maybe forget recorded base line for line number display. */
13349 if (!just_this_one_p
13350 || current_buffer
->clip_changed
13351 || BEG_UNCHANGED
< CHARPOS (startp
))
13352 w
->base_line_number
= Qnil
;
13354 /* If cursor ends up on a partially visible line,
13355 treat that as being off the bottom of the screen. */
13356 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
13357 /* It's possible that the cursor is on the first line of the
13358 buffer, which is partially obscured due to a vscroll
13359 (Bug#7537). In that case, avoid looping forever . */
13360 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
13362 clear_glyph_matrix (w
->desired_matrix
);
13363 ++extra_scroll_margin_lines
;
13366 rc
= SCROLLING_SUCCESS
;
13373 /* Compute a suitable window start for window W if display of W starts
13374 on a continuation line. Value is non-zero if a new window start
13377 The new window start will be computed, based on W's width, starting
13378 from the start of the continued line. It is the start of the
13379 screen line with the minimum distance from the old start W->start. */
13382 compute_window_start_on_continuation_line (struct window
*w
)
13384 struct text_pos pos
, start_pos
;
13385 int window_start_changed_p
= 0;
13387 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13389 /* If window start is on a continuation line... Window start may be
13390 < BEGV in case there's invisible text at the start of the
13391 buffer (M-x rmail, for example). */
13392 if (CHARPOS (start_pos
) > BEGV
13393 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13396 struct glyph_row
*row
;
13398 /* Handle the case that the window start is out of range. */
13399 if (CHARPOS (start_pos
) < BEGV
)
13400 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13401 else if (CHARPOS (start_pos
) > ZV
)
13402 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13404 /* Find the start of the continued line. This should be fast
13405 because scan_buffer is fast (newline cache). */
13406 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13407 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13408 row
, DEFAULT_FACE_ID
);
13409 reseat_at_previous_visible_line_start (&it
);
13411 /* If the line start is "too far" away from the window start,
13412 say it takes too much time to compute a new window start. */
13413 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13414 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13416 int min_distance
, distance
;
13418 /* Move forward by display lines to find the new window
13419 start. If window width was enlarged, the new start can
13420 be expected to be > the old start. If window width was
13421 decreased, the new window start will be < the old start.
13422 So, we're looking for the display line start with the
13423 minimum distance from the old window start. */
13424 pos
= it
.current
.pos
;
13425 min_distance
= INFINITY
;
13426 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13427 distance
< min_distance
)
13429 min_distance
= distance
;
13430 pos
= it
.current
.pos
;
13431 move_it_by_lines (&it
, 1);
13434 /* Set the window start there. */
13435 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13436 window_start_changed_p
= 1;
13440 return window_start_changed_p
;
13444 /* Try cursor movement in case text has not changed in window WINDOW,
13445 with window start STARTP. Value is
13447 CURSOR_MOVEMENT_SUCCESS if successful
13449 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13451 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13452 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13453 we want to scroll as if scroll-step were set to 1. See the code.
13455 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13456 which case we have to abort this redisplay, and adjust matrices
13461 CURSOR_MOVEMENT_SUCCESS
,
13462 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13463 CURSOR_MOVEMENT_MUST_SCROLL
,
13464 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13468 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
13470 struct window
*w
= XWINDOW (window
);
13471 struct frame
*f
= XFRAME (w
->frame
);
13472 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13475 if (inhibit_try_cursor_movement
)
13479 /* Handle case where text has not changed, only point, and it has
13480 not moved off the frame. */
13481 if (/* Point may be in this window. */
13482 PT
>= CHARPOS (startp
)
13483 /* Selective display hasn't changed. */
13484 && !current_buffer
->clip_changed
13485 /* Function force-mode-line-update is used to force a thorough
13486 redisplay. It sets either windows_or_buffers_changed or
13487 update_mode_lines. So don't take a shortcut here for these
13489 && !update_mode_lines
13490 && !windows_or_buffers_changed
13491 && !cursor_type_changed
13492 /* Can't use this case if highlighting a region. When a
13493 region exists, cursor movement has to do more than just
13495 && !(!NILP (Vtransient_mark_mode
)
13496 && !NILP (BVAR (current_buffer
, mark_active
)))
13497 && NILP (w
->region_showing
)
13498 && NILP (Vshow_trailing_whitespace
)
13499 /* Right after splitting windows, last_point may be nil. */
13500 && INTEGERP (w
->last_point
)
13501 /* This code is not used for mini-buffer for the sake of the case
13502 of redisplaying to replace an echo area message; since in
13503 that case the mini-buffer contents per se are usually
13504 unchanged. This code is of no real use in the mini-buffer
13505 since the handling of this_line_start_pos, etc., in redisplay
13506 handles the same cases. */
13507 && !EQ (window
, minibuf_window
)
13508 /* When splitting windows or for new windows, it happens that
13509 redisplay is called with a nil window_end_vpos or one being
13510 larger than the window. This should really be fixed in
13511 window.c. I don't have this on my list, now, so we do
13512 approximately the same as the old redisplay code. --gerd. */
13513 && INTEGERP (w
->window_end_vpos
)
13514 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13515 && (FRAME_WINDOW_P (f
)
13516 || !overlay_arrow_in_current_buffer_p ()))
13518 int this_scroll_margin
, top_scroll_margin
;
13519 struct glyph_row
*row
= NULL
;
13522 debug_method_add (w
, "cursor movement");
13525 /* Scroll if point within this distance from the top or bottom
13526 of the window. This is a pixel value. */
13527 if (scroll_margin
> 0)
13529 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13530 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13533 this_scroll_margin
= 0;
13535 top_scroll_margin
= this_scroll_margin
;
13536 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13537 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13539 /* Start with the row the cursor was displayed during the last
13540 not paused redisplay. Give up if that row is not valid. */
13541 if (w
->last_cursor
.vpos
< 0
13542 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13543 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13546 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13547 if (row
->mode_line_p
)
13549 if (!row
->enabled_p
)
13550 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13553 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13555 int scroll_p
= 0, must_scroll
= 0;
13556 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13558 if (PT
> XFASTINT (w
->last_point
))
13560 /* Point has moved forward. */
13561 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13562 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13564 xassert (row
->enabled_p
);
13568 /* If the end position of a row equals the start
13569 position of the next row, and PT is at that position,
13570 we would rather display cursor in the next line. */
13571 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13572 && MATRIX_ROW_END_CHARPOS (row
) == PT
13573 && row
< w
->current_matrix
->rows
13574 + w
->current_matrix
->nrows
- 1
13575 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
13576 && !cursor_row_p (row
))
13579 /* If within the scroll margin, scroll. Note that
13580 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13581 the next line would be drawn, and that
13582 this_scroll_margin can be zero. */
13583 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13584 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13585 /* Line is completely visible last line in window
13586 and PT is to be set in the next line. */
13587 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13588 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13589 && !row
->ends_at_zv_p
13590 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13593 else if (PT
< XFASTINT (w
->last_point
))
13595 /* Cursor has to be moved backward. Note that PT >=
13596 CHARPOS (startp) because of the outer if-statement. */
13597 while (!row
->mode_line_p
13598 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13599 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13600 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13601 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13602 row
> w
->current_matrix
->rows
13603 && (row
-1)->ends_in_newline_from_string_p
))))
13604 && (row
->y
> top_scroll_margin
13605 || CHARPOS (startp
) == BEGV
))
13607 xassert (row
->enabled_p
);
13611 /* Consider the following case: Window starts at BEGV,
13612 there is invisible, intangible text at BEGV, so that
13613 display starts at some point START > BEGV. It can
13614 happen that we are called with PT somewhere between
13615 BEGV and START. Try to handle that case. */
13616 if (row
< w
->current_matrix
->rows
13617 || row
->mode_line_p
)
13619 row
= w
->current_matrix
->rows
;
13620 if (row
->mode_line_p
)
13624 /* Due to newlines in overlay strings, we may have to
13625 skip forward over overlay strings. */
13626 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13627 && MATRIX_ROW_END_CHARPOS (row
) == PT
13628 && !cursor_row_p (row
))
13631 /* If within the scroll margin, scroll. */
13632 if (row
->y
< top_scroll_margin
13633 && CHARPOS (startp
) != BEGV
)
13638 /* Cursor did not move. So don't scroll even if cursor line
13639 is partially visible, as it was so before. */
13640 rc
= CURSOR_MOVEMENT_SUCCESS
;
13643 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13644 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13646 /* if PT is not in the glyph row, give up. */
13647 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13650 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13651 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
13653 /* If rows are bidi-reordered and point moved, back up
13654 until we find a row that does not belong to a
13655 continuation line. This is because we must consider
13656 all rows of a continued line as candidates for the
13657 new cursor positioning, since row start and end
13658 positions change non-linearly with vertical position
13660 /* FIXME: Revisit this when glyph ``spilling'' in
13661 continuation lines' rows is implemented for
13662 bidi-reordered rows. */
13663 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
13665 xassert (row
->enabled_p
);
13667 /* If we hit the beginning of the displayed portion
13668 without finding the first row of a continued
13670 if (row
<= w
->current_matrix
->rows
)
13672 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13680 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13681 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13682 && make_cursor_line_fully_visible_p
)
13684 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13685 && !row
->ends_at_zv_p
13686 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13687 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13688 else if (row
->height
> window_box_height (w
))
13690 /* If we end up in a partially visible line, let's
13691 make it fully visible, except when it's taller
13692 than the window, in which case we can't do much
13695 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13699 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13700 if (!cursor_row_fully_visible_p (w
, 0, 1))
13701 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13703 rc
= CURSOR_MOVEMENT_SUCCESS
;
13707 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13708 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13709 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
13711 /* With bidi-reordered rows, there could be more than
13712 one candidate row whose start and end positions
13713 occlude point. We need to let set_cursor_from_row
13714 find the best candidate. */
13715 /* FIXME: Revisit this when glyph ``spilling'' in
13716 continuation lines' rows is implemented for
13717 bidi-reordered rows. */
13722 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
13723 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13724 && cursor_row_p (row
))
13725 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
13727 /* As soon as we've found the first suitable row
13728 whose ends_at_zv_p flag is set, we are done. */
13730 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
13732 rc
= CURSOR_MOVEMENT_SUCCESS
;
13737 while ((MATRIX_ROW_CONTINUATION_LINE_P (row
)
13738 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
13739 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13740 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
13741 /* If we didn't find any candidate rows, or exited the
13742 loop before all the candidates were examined, signal
13743 to the caller that this method failed. */
13744 if (rc
!= CURSOR_MOVEMENT_SUCCESS
13745 && (!rv
|| MATRIX_ROW_CONTINUATION_LINE_P (row
)))
13746 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13748 rc
= CURSOR_MOVEMENT_SUCCESS
;
13754 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13756 rc
= CURSOR_MOVEMENT_SUCCESS
;
13761 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13762 && MATRIX_ROW_START_CHARPOS (row
) == PT
13763 && cursor_row_p (row
));
13771 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
13775 set_vertical_scroll_bar (struct window
*w
)
13777 EMACS_INT start
, end
, whole
;
13779 /* Calculate the start and end positions for the current window.
13780 At some point, it would be nice to choose between scrollbars
13781 which reflect the whole buffer size, with special markers
13782 indicating narrowing, and scrollbars which reflect only the
13785 Note that mini-buffers sometimes aren't displaying any text. */
13786 if (!MINI_WINDOW_P (w
)
13787 || (w
== XWINDOW (minibuf_window
)
13788 && NILP (echo_area_buffer
[0])))
13790 struct buffer
*buf
= XBUFFER (w
->buffer
);
13791 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13792 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13793 /* I don't think this is guaranteed to be right. For the
13794 moment, we'll pretend it is. */
13795 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13799 if (whole
< (end
- start
))
13800 whole
= end
- start
;
13803 start
= end
= whole
= 0;
13805 /* Indicate what this scroll bar ought to be displaying now. */
13806 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13807 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13808 (w
, end
- start
, whole
, start
);
13812 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13813 selected_window is redisplayed.
13815 We can return without actually redisplaying the window if
13816 fonts_changed_p is nonzero. In that case, redisplay_internal will
13820 redisplay_window (Lisp_Object window
, int just_this_one_p
)
13822 struct window
*w
= XWINDOW (window
);
13823 struct frame
*f
= XFRAME (w
->frame
);
13824 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13825 struct buffer
*old
= current_buffer
;
13826 struct text_pos lpoint
, opoint
, startp
;
13827 int update_mode_line
;
13830 /* Record it now because it's overwritten. */
13831 int current_matrix_up_to_date_p
= 0;
13832 int used_current_matrix_p
= 0;
13833 /* This is less strict than current_matrix_up_to_date_p.
13834 It indictes that the buffer contents and narrowing are unchanged. */
13835 int buffer_unchanged_p
= 0;
13836 int temp_scroll_step
= 0;
13837 int count
= SPECPDL_INDEX ();
13839 int centering_position
= -1;
13840 int last_line_misfit
= 0;
13841 EMACS_INT beg_unchanged
, end_unchanged
;
13843 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13846 /* W must be a leaf window here. */
13847 xassert (!NILP (w
->buffer
));
13849 *w
->desired_matrix
->method
= 0;
13853 reconsider_clip_changes (w
, buffer
);
13855 /* Has the mode line to be updated? */
13856 update_mode_line
= (!NILP (w
->update_mode_line
)
13857 || update_mode_lines
13858 || buffer
->clip_changed
13859 || buffer
->prevent_redisplay_optimizations_p
);
13861 if (MINI_WINDOW_P (w
))
13863 if (w
== XWINDOW (echo_area_window
)
13864 && !NILP (echo_area_buffer
[0]))
13866 if (update_mode_line
)
13867 /* We may have to update a tty frame's menu bar or a
13868 tool-bar. Example `M-x C-h C-h C-g'. */
13869 goto finish_menu_bars
;
13871 /* We've already displayed the echo area glyphs in this window. */
13872 goto finish_scroll_bars
;
13874 else if ((w
!= XWINDOW (minibuf_window
)
13875 || minibuf_level
== 0)
13876 /* When buffer is nonempty, redisplay window normally. */
13877 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13878 /* Quail displays non-mini buffers in minibuffer window.
13879 In that case, redisplay the window normally. */
13880 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13882 /* W is a mini-buffer window, but it's not active, so clear
13884 int yb
= window_text_bottom_y (w
);
13885 struct glyph_row
*row
;
13888 for (y
= 0, row
= w
->desired_matrix
->rows
;
13890 y
+= row
->height
, ++row
)
13891 blank_row (w
, row
, y
);
13892 goto finish_scroll_bars
;
13895 clear_glyph_matrix (w
->desired_matrix
);
13898 /* Otherwise set up data on this window; select its buffer and point
13900 /* Really select the buffer, for the sake of buffer-local
13902 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13904 current_matrix_up_to_date_p
13905 = (!NILP (w
->window_end_valid
)
13906 && !current_buffer
->clip_changed
13907 && !current_buffer
->prevent_redisplay_optimizations_p
13908 && XFASTINT (w
->last_modified
) >= MODIFF
13909 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13911 /* Run the window-bottom-change-functions
13912 if it is possible that the text on the screen has changed
13913 (either due to modification of the text, or any other reason). */
13914 if (!current_matrix_up_to_date_p
13915 && !NILP (Vwindow_text_change_functions
))
13917 safe_run_hooks (Qwindow_text_change_functions
);
13921 beg_unchanged
= BEG_UNCHANGED
;
13922 end_unchanged
= END_UNCHANGED
;
13924 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13926 specbind (Qinhibit_point_motion_hooks
, Qt
);
13929 = (!NILP (w
->window_end_valid
)
13930 && !current_buffer
->clip_changed
13931 && XFASTINT (w
->last_modified
) >= MODIFF
13932 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13934 /* When windows_or_buffers_changed is non-zero, we can't rely on
13935 the window end being valid, so set it to nil there. */
13936 if (windows_or_buffers_changed
)
13938 /* If window starts on a continuation line, maybe adjust the
13939 window start in case the window's width changed. */
13940 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13941 compute_window_start_on_continuation_line (w
);
13943 w
->window_end_valid
= Qnil
;
13946 /* Some sanity checks. */
13947 CHECK_WINDOW_END (w
);
13948 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13950 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13953 /* If %c is in mode line, update it if needed. */
13954 if (!NILP (w
->column_number_displayed
)
13955 /* This alternative quickly identifies a common case
13956 where no change is needed. */
13957 && !(PT
== XFASTINT (w
->last_point
)
13958 && XFASTINT (w
->last_modified
) >= MODIFF
13959 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13960 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
13961 update_mode_line
= 1;
13963 /* Count number of windows showing the selected buffer. An indirect
13964 buffer counts as its base buffer. */
13965 if (!just_this_one_p
)
13967 struct buffer
*current_base
, *window_base
;
13968 current_base
= current_buffer
;
13969 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13970 if (current_base
->base_buffer
)
13971 current_base
= current_base
->base_buffer
;
13972 if (window_base
->base_buffer
)
13973 window_base
= window_base
->base_buffer
;
13974 if (current_base
== window_base
)
13978 /* Point refers normally to the selected window. For any other
13979 window, set up appropriate value. */
13980 if (!EQ (window
, selected_window
))
13982 EMACS_INT new_pt
= XMARKER (w
->pointm
)->charpos
;
13983 EMACS_INT new_pt_byte
= marker_byte_position (w
->pointm
);
13987 new_pt_byte
= BEGV_BYTE
;
13988 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13990 else if (new_pt
> (ZV
- 1))
13993 new_pt_byte
= ZV_BYTE
;
13994 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13997 /* We don't use SET_PT so that the point-motion hooks don't run. */
13998 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
14001 /* If any of the character widths specified in the display table
14002 have changed, invalidate the width run cache. It's true that
14003 this may be a bit late to catch such changes, but the rest of
14004 redisplay goes (non-fatally) haywire when the display table is
14005 changed, so why should we worry about doing any better? */
14006 if (current_buffer
->width_run_cache
)
14008 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
14010 if (! disptab_matches_widthtab (disptab
,
14011 XVECTOR (BVAR (current_buffer
, width_table
))))
14013 invalidate_region_cache (current_buffer
,
14014 current_buffer
->width_run_cache
,
14016 recompute_width_table (current_buffer
, disptab
);
14020 /* If window-start is screwed up, choose a new one. */
14021 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
14024 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14026 /* If someone specified a new starting point but did not insist,
14027 check whether it can be used. */
14028 if (!NILP (w
->optional_new_start
)
14029 && CHARPOS (startp
) >= BEGV
14030 && CHARPOS (startp
) <= ZV
)
14032 w
->optional_new_start
= Qnil
;
14033 start_display (&it
, w
, startp
);
14034 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
14035 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14036 if (IT_CHARPOS (it
) == PT
)
14037 w
->force_start
= Qt
;
14038 /* IT may overshoot PT if text at PT is invisible. */
14039 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
14040 w
->force_start
= Qt
;
14045 /* Handle case where place to start displaying has been specified,
14046 unless the specified location is outside the accessible range. */
14047 if (!NILP (w
->force_start
)
14048 || w
->frozen_window_start_p
)
14050 /* We set this later on if we have to adjust point. */
14053 w
->force_start
= Qnil
;
14055 w
->window_end_valid
= Qnil
;
14057 /* Forget any recorded base line for line number display. */
14058 if (!buffer_unchanged_p
)
14059 w
->base_line_number
= Qnil
;
14061 /* Redisplay the mode line. Select the buffer properly for that.
14062 Also, run the hook window-scroll-functions
14063 because we have scrolled. */
14064 /* Note, we do this after clearing force_start because
14065 if there's an error, it is better to forget about force_start
14066 than to get into an infinite loop calling the hook functions
14067 and having them get more errors. */
14068 if (!update_mode_line
14069 || ! NILP (Vwindow_scroll_functions
))
14071 update_mode_line
= 1;
14072 w
->update_mode_line
= Qt
;
14073 startp
= run_window_scroll_functions (window
, startp
);
14076 w
->last_modified
= make_number (0);
14077 w
->last_overlay_modified
= make_number (0);
14078 if (CHARPOS (startp
) < BEGV
)
14079 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14080 else if (CHARPOS (startp
) > ZV
)
14081 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14083 /* Redisplay, then check if cursor has been set during the
14084 redisplay. Give up if new fonts were loaded. */
14085 /* We used to issue a CHECK_MARGINS argument to try_window here,
14086 but this causes scrolling to fail when point begins inside
14087 the scroll margin (bug#148) -- cyd */
14088 if (!try_window (window
, startp
, 0))
14090 w
->force_start
= Qt
;
14091 clear_glyph_matrix (w
->desired_matrix
);
14092 goto need_larger_matrices
;
14095 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14097 /* If point does not appear, try to move point so it does
14098 appear. The desired matrix has been built above, so we
14099 can use it here. */
14100 new_vpos
= window_box_height (w
) / 2;
14103 if (!cursor_row_fully_visible_p (w
, 0, 0))
14105 /* Point does appear, but on a line partly visible at end of window.
14106 Move it back to a fully-visible line. */
14107 new_vpos
= window_box_height (w
);
14110 /* If we need to move point for either of the above reasons,
14111 now actually do it. */
14114 struct glyph_row
*row
;
14116 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14117 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14120 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14121 MATRIX_ROW_START_BYTEPOS (row
));
14123 if (w
!= XWINDOW (selected_window
))
14124 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14125 else if (current_buffer
== old
)
14126 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14128 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14130 /* If we are highlighting the region, then we just changed
14131 the region, so redisplay to show it. */
14132 if (!NILP (Vtransient_mark_mode
)
14133 && !NILP (BVAR (current_buffer
, mark_active
)))
14135 clear_glyph_matrix (w
->desired_matrix
);
14136 if (!try_window (window
, startp
, 0))
14137 goto need_larger_matrices
;
14142 debug_method_add (w
, "forced window start");
14147 /* Handle case where text has not changed, only point, and it has
14148 not moved off the frame, and we are not retrying after hscroll.
14149 (current_matrix_up_to_date_p is nonzero when retrying.) */
14150 if (current_matrix_up_to_date_p
14151 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14152 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14156 case CURSOR_MOVEMENT_SUCCESS
:
14157 used_current_matrix_p
= 1;
14160 case CURSOR_MOVEMENT_MUST_SCROLL
:
14161 goto try_to_scroll
;
14167 /* If current starting point was originally the beginning of a line
14168 but no longer is, find a new starting point. */
14169 else if (!NILP (w
->start_at_line_beg
)
14170 && !(CHARPOS (startp
) <= BEGV
14171 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14174 debug_method_add (w
, "recenter 1");
14179 /* Try scrolling with try_window_id. Value is > 0 if update has
14180 been done, it is -1 if we know that the same window start will
14181 not work. It is 0 if unsuccessful for some other reason. */
14182 else if ((tem
= try_window_id (w
)) != 0)
14185 debug_method_add (w
, "try_window_id %d", tem
);
14188 if (fonts_changed_p
)
14189 goto need_larger_matrices
;
14193 /* Otherwise try_window_id has returned -1 which means that we
14194 don't want the alternative below this comment to execute. */
14196 else if (CHARPOS (startp
) >= BEGV
14197 && CHARPOS (startp
) <= ZV
14198 && PT
>= CHARPOS (startp
)
14199 && (CHARPOS (startp
) < ZV
14200 /* Avoid starting at end of buffer. */
14201 || CHARPOS (startp
) == BEGV
14202 || (XFASTINT (w
->last_modified
) >= MODIFF
14203 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14206 /* If first window line is a continuation line, and window start
14207 is inside the modified region, but the first change is before
14208 current window start, we must select a new window start.
14210 However, if this is the result of a down-mouse event (e.g. by
14211 extending the mouse-drag-overlay), we don't want to select a
14212 new window start, since that would change the position under
14213 the mouse, resulting in an unwanted mouse-movement rather
14214 than a simple mouse-click. */
14215 if (NILP (w
->start_at_line_beg
)
14216 && NILP (do_mouse_tracking
)
14217 && CHARPOS (startp
) > BEGV
14218 && CHARPOS (startp
) > BEG
+ beg_unchanged
14219 && CHARPOS (startp
) <= Z
- end_unchanged
14220 /* Even if w->start_at_line_beg is nil, a new window may
14221 start at a line_beg, since that's how set_buffer_window
14222 sets it. So, we need to check the return value of
14223 compute_window_start_on_continuation_line. (See also
14225 && XMARKER (w
->start
)->buffer
== current_buffer
14226 && compute_window_start_on_continuation_line (w
))
14228 w
->force_start
= Qt
;
14229 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14234 debug_method_add (w
, "same window start");
14237 /* Try to redisplay starting at same place as before.
14238 If point has not moved off frame, accept the results. */
14239 if (!current_matrix_up_to_date_p
14240 /* Don't use try_window_reusing_current_matrix in this case
14241 because a window scroll function can have changed the
14243 || !NILP (Vwindow_scroll_functions
)
14244 || MINI_WINDOW_P (w
)
14245 || !(used_current_matrix_p
14246 = try_window_reusing_current_matrix (w
)))
14248 IF_DEBUG (debug_method_add (w
, "1"));
14249 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
14250 /* -1 means we need to scroll.
14251 0 means we need new matrices, but fonts_changed_p
14252 is set in that case, so we will detect it below. */
14253 goto try_to_scroll
;
14256 if (fonts_changed_p
)
14257 goto need_larger_matrices
;
14259 if (w
->cursor
.vpos
>= 0)
14261 if (!just_this_one_p
14262 || current_buffer
->clip_changed
14263 || BEG_UNCHANGED
< CHARPOS (startp
))
14264 /* Forget any recorded base line for line number display. */
14265 w
->base_line_number
= Qnil
;
14267 if (!cursor_row_fully_visible_p (w
, 1, 0))
14269 clear_glyph_matrix (w
->desired_matrix
);
14270 last_line_misfit
= 1;
14272 /* Drop through and scroll. */
14277 clear_glyph_matrix (w
->desired_matrix
);
14282 w
->last_modified
= make_number (0);
14283 w
->last_overlay_modified
= make_number (0);
14285 /* Redisplay the mode line. Select the buffer properly for that. */
14286 if (!update_mode_line
)
14288 update_mode_line
= 1;
14289 w
->update_mode_line
= Qt
;
14292 /* Try to scroll by specified few lines. */
14293 if ((scroll_conservatively
14294 || emacs_scroll_step
14295 || temp_scroll_step
14296 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
14297 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
14298 && CHARPOS (startp
) >= BEGV
14299 && CHARPOS (startp
) <= ZV
)
14301 /* The function returns -1 if new fonts were loaded, 1 if
14302 successful, 0 if not successful. */
14303 int ss
= try_scrolling (window
, just_this_one_p
,
14304 scroll_conservatively
,
14306 temp_scroll_step
, last_line_misfit
);
14309 case SCROLLING_SUCCESS
:
14312 case SCROLLING_NEED_LARGER_MATRICES
:
14313 goto need_larger_matrices
;
14315 case SCROLLING_FAILED
:
14323 /* Finally, just choose a place to start which positions point
14324 according to user preferences. */
14329 debug_method_add (w
, "recenter");
14332 /* w->vscroll = 0; */
14334 /* Forget any previously recorded base line for line number display. */
14335 if (!buffer_unchanged_p
)
14336 w
->base_line_number
= Qnil
;
14338 /* Determine the window start relative to point. */
14339 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14340 it
.current_y
= it
.last_visible_y
;
14341 if (centering_position
< 0)
14345 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14347 EMACS_INT margin_pos
= CHARPOS (startp
);
14349 Lisp_Object aggressive
;
14351 /* If there is a scroll margin at the top of the window, find
14352 its character position. */
14354 /* Cannot call start_display if startp is not in the
14355 accessible region of the buffer. This can happen when we
14356 have just switched to a different buffer and/or changed
14357 its restriction. In that case, startp is initialized to
14358 the character position 1 (BEG) because we did not yet
14359 have chance to display the buffer even once. */
14360 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
14364 start_display (&it1
, w
, startp
);
14365 move_it_vertically (&it1
, margin
);
14366 margin_pos
= IT_CHARPOS (it1
);
14368 scrolling_up
= PT
> margin_pos
;
14371 ? BVAR (current_buffer
, scroll_up_aggressively
)
14372 : BVAR (current_buffer
, scroll_down_aggressively
);
14374 if (!MINI_WINDOW_P (w
)
14375 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
14379 /* Setting scroll-conservatively overrides
14380 scroll-*-aggressively. */
14381 if (!scroll_conservatively
&& NUMBERP (aggressive
))
14383 double float_amount
= XFLOATINT (aggressive
);
14385 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
14386 if (pt_offset
== 0 && float_amount
> 0)
14391 /* Compute how much to move the window start backward from
14392 point so that point will be displayed where the user
14396 centering_position
= it
.last_visible_y
;
14398 centering_position
-= pt_offset
;
14399 centering_position
-=
14400 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0));
14401 /* Don't let point enter the scroll margin near top of
14403 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
14404 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
14407 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
14410 /* Set the window start half the height of the window backward
14412 centering_position
= window_box_height (w
) / 2;
14414 move_it_vertically_backward (&it
, centering_position
);
14416 xassert (IT_CHARPOS (it
) >= BEGV
);
14418 /* The function move_it_vertically_backward may move over more
14419 than the specified y-distance. If it->w is small, e.g. a
14420 mini-buffer window, we may end up in front of the window's
14421 display area. Start displaying at the start of the line
14422 containing PT in this case. */
14423 if (it
.current_y
<= 0)
14425 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14426 move_it_vertically_backward (&it
, 0);
14430 it
.current_x
= it
.hpos
= 0;
14432 /* Set the window start position here explicitly, to avoid an
14433 infinite loop in case the functions in window-scroll-functions
14435 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14437 /* Run scroll hooks. */
14438 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14440 /* Redisplay the window. */
14441 if (!current_matrix_up_to_date_p
14442 || windows_or_buffers_changed
14443 || cursor_type_changed
14444 /* Don't use try_window_reusing_current_matrix in this case
14445 because it can have changed the buffer. */
14446 || !NILP (Vwindow_scroll_functions
)
14447 || !just_this_one_p
14448 || MINI_WINDOW_P (w
)
14449 || !(used_current_matrix_p
14450 = try_window_reusing_current_matrix (w
)))
14451 try_window (window
, startp
, 0);
14453 /* If new fonts have been loaded (due to fontsets), give up. We
14454 have to start a new redisplay since we need to re-adjust glyph
14456 if (fonts_changed_p
)
14457 goto need_larger_matrices
;
14459 /* If cursor did not appear assume that the middle of the window is
14460 in the first line of the window. Do it again with the next line.
14461 (Imagine a window of height 100, displaying two lines of height
14462 60. Moving back 50 from it->last_visible_y will end in the first
14464 if (w
->cursor
.vpos
< 0)
14466 if (!NILP (w
->window_end_valid
)
14467 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14469 clear_glyph_matrix (w
->desired_matrix
);
14470 move_it_by_lines (&it
, 1);
14471 try_window (window
, it
.current
.pos
, 0);
14473 else if (PT
< IT_CHARPOS (it
))
14475 clear_glyph_matrix (w
->desired_matrix
);
14476 move_it_by_lines (&it
, -1);
14477 try_window (window
, it
.current
.pos
, 0);
14481 /* Not much we can do about it. */
14485 /* Consider the following case: Window starts at BEGV, there is
14486 invisible, intangible text at BEGV, so that display starts at
14487 some point START > BEGV. It can happen that we are called with
14488 PT somewhere between BEGV and START. Try to handle that case. */
14489 if (w
->cursor
.vpos
< 0)
14491 struct glyph_row
*row
= w
->current_matrix
->rows
;
14492 if (row
->mode_line_p
)
14494 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14497 if (!cursor_row_fully_visible_p (w
, 0, 0))
14499 /* If vscroll is enabled, disable it and try again. */
14503 clear_glyph_matrix (w
->desired_matrix
);
14507 /* If centering point failed to make the whole line visible,
14508 put point at the top instead. That has to make the whole line
14509 visible, if it can be done. */
14510 if (centering_position
== 0)
14513 clear_glyph_matrix (w
->desired_matrix
);
14514 centering_position
= 0;
14520 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14521 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14522 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14525 /* Display the mode line, if we must. */
14526 if ((update_mode_line
14527 /* If window not full width, must redo its mode line
14528 if (a) the window to its side is being redone and
14529 (b) we do a frame-based redisplay. This is a consequence
14530 of how inverted lines are drawn in frame-based redisplay. */
14531 || (!just_this_one_p
14532 && !FRAME_WINDOW_P (f
)
14533 && !WINDOW_FULL_WIDTH_P (w
))
14534 /* Line number to display. */
14535 || INTEGERP (w
->base_line_pos
)
14536 /* Column number is displayed and different from the one displayed. */
14537 || (!NILP (w
->column_number_displayed
)
14538 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
14539 /* This means that the window has a mode line. */
14540 && (WINDOW_WANTS_MODELINE_P (w
)
14541 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14543 display_mode_lines (w
);
14545 /* If mode line height has changed, arrange for a thorough
14546 immediate redisplay using the correct mode line height. */
14547 if (WINDOW_WANTS_MODELINE_P (w
)
14548 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14550 fonts_changed_p
= 1;
14551 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14552 = DESIRED_MODE_LINE_HEIGHT (w
);
14555 /* If header line height has changed, arrange for a thorough
14556 immediate redisplay using the correct header line height. */
14557 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14558 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14560 fonts_changed_p
= 1;
14561 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14562 = DESIRED_HEADER_LINE_HEIGHT (w
);
14565 if (fonts_changed_p
)
14566 goto need_larger_matrices
;
14569 if (!line_number_displayed
14570 && !BUFFERP (w
->base_line_pos
))
14572 w
->base_line_pos
= Qnil
;
14573 w
->base_line_number
= Qnil
;
14578 /* When we reach a frame's selected window, redo the frame's menu bar. */
14579 if (update_mode_line
14580 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14582 int redisplay_menu_p
= 0;
14584 if (FRAME_WINDOW_P (f
))
14586 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14587 || defined (HAVE_NS) || defined (USE_GTK)
14588 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
14590 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14594 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14596 if (redisplay_menu_p
)
14597 display_menu_bar (w
);
14599 #ifdef HAVE_WINDOW_SYSTEM
14600 if (FRAME_WINDOW_P (f
))
14602 #if defined (USE_GTK) || defined (HAVE_NS)
14603 if (FRAME_EXTERNAL_TOOL_BAR (f
))
14604 redisplay_tool_bar (f
);
14606 if (WINDOWP (f
->tool_bar_window
)
14607 && (FRAME_TOOL_BAR_LINES (f
) > 0
14608 || !NILP (Vauto_resize_tool_bars
))
14609 && redisplay_tool_bar (f
))
14610 ignore_mouse_drag_p
= 1;
14616 #ifdef HAVE_WINDOW_SYSTEM
14617 if (FRAME_WINDOW_P (f
)
14618 && update_window_fringes (w
, (just_this_one_p
14619 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
14620 || w
->pseudo_window_p
)))
14624 if (draw_window_fringes (w
, 1))
14625 x_draw_vertical_border (w
);
14629 #endif /* HAVE_WINDOW_SYSTEM */
14631 /* We go to this label, with fonts_changed_p nonzero,
14632 if it is necessary to try again using larger glyph matrices.
14633 We have to redeem the scroll bar even in this case,
14634 because the loop in redisplay_internal expects that. */
14635 need_larger_matrices
:
14637 finish_scroll_bars
:
14639 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14641 /* Set the thumb's position and size. */
14642 set_vertical_scroll_bar (w
);
14644 /* Note that we actually used the scroll bar attached to this
14645 window, so it shouldn't be deleted at the end of redisplay. */
14646 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14647 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14650 /* Restore current_buffer and value of point in it. The window
14651 update may have changed the buffer, so first make sure `opoint'
14652 is still valid (Bug#6177). */
14653 if (CHARPOS (opoint
) < BEGV
)
14654 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
14655 else if (CHARPOS (opoint
) > ZV
)
14656 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
14658 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14660 set_buffer_internal_1 (old
);
14661 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14662 shorter. This can be caused by log truncation in *Messages*. */
14663 if (CHARPOS (lpoint
) <= ZV
)
14664 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14666 unbind_to (count
, Qnil
);
14670 /* Build the complete desired matrix of WINDOW with a window start
14671 buffer position POS.
14673 Value is 1 if successful. It is zero if fonts were loaded during
14674 redisplay which makes re-adjusting glyph matrices necessary, and -1
14675 if point would appear in the scroll margins.
14676 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
14677 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
14681 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
14683 struct window
*w
= XWINDOW (window
);
14685 struct glyph_row
*last_text_row
= NULL
;
14686 struct frame
*f
= XFRAME (w
->frame
);
14688 /* Make POS the new window start. */
14689 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14691 /* Mark cursor position as unknown. No overlay arrow seen. */
14692 w
->cursor
.vpos
= -1;
14693 overlay_arrow_seen
= 0;
14695 /* Initialize iterator and info to start at POS. */
14696 start_display (&it
, w
, pos
);
14698 /* Display all lines of W. */
14699 while (it
.current_y
< it
.last_visible_y
)
14701 if (display_line (&it
))
14702 last_text_row
= it
.glyph_row
- 1;
14703 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
14707 /* Don't let the cursor end in the scroll margins. */
14708 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
14709 && !MINI_WINDOW_P (w
))
14711 int this_scroll_margin
;
14713 if (scroll_margin
> 0)
14715 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14716 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14719 this_scroll_margin
= 0;
14721 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14722 && w
->cursor
.y
< this_scroll_margin
14723 && CHARPOS (pos
) > BEGV
14724 && IT_CHARPOS (it
) < ZV
)
14725 /* rms: considering make_cursor_line_fully_visible_p here
14726 seems to give wrong results. We don't want to recenter
14727 when the last line is partly visible, we want to allow
14728 that case to be handled in the usual way. */
14729 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14731 w
->cursor
.vpos
= -1;
14732 clear_glyph_matrix (w
->desired_matrix
);
14737 /* If bottom moved off end of frame, change mode line percentage. */
14738 if (XFASTINT (w
->window_end_pos
) <= 0
14739 && Z
!= IT_CHARPOS (it
))
14740 w
->update_mode_line
= Qt
;
14742 /* Set window_end_pos to the offset of the last character displayed
14743 on the window from the end of current_buffer. Set
14744 window_end_vpos to its row number. */
14747 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14748 w
->window_end_bytepos
14749 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14751 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14753 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14754 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14755 ->displays_text_p
);
14759 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14760 w
->window_end_pos
= make_number (Z
- ZV
);
14761 w
->window_end_vpos
= make_number (0);
14764 /* But that is not valid info until redisplay finishes. */
14765 w
->window_end_valid
= Qnil
;
14771 /************************************************************************
14772 Window redisplay reusing current matrix when buffer has not changed
14773 ************************************************************************/
14775 /* Try redisplay of window W showing an unchanged buffer with a
14776 different window start than the last time it was displayed by
14777 reusing its current matrix. Value is non-zero if successful.
14778 W->start is the new window start. */
14781 try_window_reusing_current_matrix (struct window
*w
)
14783 struct frame
*f
= XFRAME (w
->frame
);
14784 struct glyph_row
*bottom_row
;
14787 struct text_pos start
, new_start
;
14788 int nrows_scrolled
, i
;
14789 struct glyph_row
*last_text_row
;
14790 struct glyph_row
*last_reused_text_row
;
14791 struct glyph_row
*start_row
;
14792 int start_vpos
, min_y
, max_y
;
14795 if (inhibit_try_window_reusing
)
14799 if (/* This function doesn't handle terminal frames. */
14800 !FRAME_WINDOW_P (f
)
14801 /* Don't try to reuse the display if windows have been split
14803 || windows_or_buffers_changed
14804 || cursor_type_changed
)
14807 /* Can't do this if region may have changed. */
14808 if ((!NILP (Vtransient_mark_mode
)
14809 && !NILP (BVAR (current_buffer
, mark_active
)))
14810 || !NILP (w
->region_showing
)
14811 || !NILP (Vshow_trailing_whitespace
))
14814 /* If top-line visibility has changed, give up. */
14815 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14816 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14819 /* Give up if old or new display is scrolled vertically. We could
14820 make this function handle this, but right now it doesn't. */
14821 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14822 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14825 /* The variable new_start now holds the new window start. The old
14826 start `start' can be determined from the current matrix. */
14827 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14828 start
= start_row
->minpos
;
14829 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14831 /* Clear the desired matrix for the display below. */
14832 clear_glyph_matrix (w
->desired_matrix
);
14834 if (CHARPOS (new_start
) <= CHARPOS (start
))
14836 /* Don't use this method if the display starts with an ellipsis
14837 displayed for invisible text. It's not easy to handle that case
14838 below, and it's certainly not worth the effort since this is
14839 not a frequent case. */
14840 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14843 IF_DEBUG (debug_method_add (w
, "twu1"));
14845 /* Display up to a row that can be reused. The variable
14846 last_text_row is set to the last row displayed that displays
14847 text. Note that it.vpos == 0 if or if not there is a
14848 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14849 start_display (&it
, w
, new_start
);
14850 w
->cursor
.vpos
= -1;
14851 last_text_row
= last_reused_text_row
= NULL
;
14853 while (it
.current_y
< it
.last_visible_y
14854 && !fonts_changed_p
)
14856 /* If we have reached into the characters in the START row,
14857 that means the line boundaries have changed. So we
14858 can't start copying with the row START. Maybe it will
14859 work to start copying with the following row. */
14860 while (IT_CHARPOS (it
) > CHARPOS (start
))
14862 /* Advance to the next row as the "start". */
14864 start
= start_row
->minpos
;
14865 /* If there are no more rows to try, or just one, give up. */
14866 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14867 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14868 || CHARPOS (start
) == ZV
)
14870 clear_glyph_matrix (w
->desired_matrix
);
14874 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14876 /* If we have reached alignment,
14877 we can copy the rest of the rows. */
14878 if (IT_CHARPOS (it
) == CHARPOS (start
))
14881 if (display_line (&it
))
14882 last_text_row
= it
.glyph_row
- 1;
14885 /* A value of current_y < last_visible_y means that we stopped
14886 at the previous window start, which in turn means that we
14887 have at least one reusable row. */
14888 if (it
.current_y
< it
.last_visible_y
)
14890 struct glyph_row
*row
;
14892 /* IT.vpos always starts from 0; it counts text lines. */
14893 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14895 /* Find PT if not already found in the lines displayed. */
14896 if (w
->cursor
.vpos
< 0)
14898 int dy
= it
.current_y
- start_row
->y
;
14900 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14901 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14903 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14904 dy
, nrows_scrolled
);
14907 clear_glyph_matrix (w
->desired_matrix
);
14912 /* Scroll the display. Do it before the current matrix is
14913 changed. The problem here is that update has not yet
14914 run, i.e. part of the current matrix is not up to date.
14915 scroll_run_hook will clear the cursor, and use the
14916 current matrix to get the height of the row the cursor is
14918 run
.current_y
= start_row
->y
;
14919 run
.desired_y
= it
.current_y
;
14920 run
.height
= it
.last_visible_y
- it
.current_y
;
14922 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14925 FRAME_RIF (f
)->update_window_begin_hook (w
);
14926 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14927 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14928 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14932 /* Shift current matrix down by nrows_scrolled lines. */
14933 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14934 rotate_matrix (w
->current_matrix
,
14936 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14939 /* Disable lines that must be updated. */
14940 for (i
= 0; i
< nrows_scrolled
; ++i
)
14941 (start_row
+ i
)->enabled_p
= 0;
14943 /* Re-compute Y positions. */
14944 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14945 max_y
= it
.last_visible_y
;
14946 for (row
= start_row
+ nrows_scrolled
;
14950 row
->y
= it
.current_y
;
14951 row
->visible_height
= row
->height
;
14953 if (row
->y
< min_y
)
14954 row
->visible_height
-= min_y
- row
->y
;
14955 if (row
->y
+ row
->height
> max_y
)
14956 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14957 if (row
->fringe_bitmap_periodic_p
)
14958 row
->redraw_fringe_bitmaps_p
= 1;
14960 it
.current_y
+= row
->height
;
14962 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14963 last_reused_text_row
= row
;
14964 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14968 /* Disable lines in the current matrix which are now
14969 below the window. */
14970 for (++row
; row
< bottom_row
; ++row
)
14971 row
->enabled_p
= row
->mode_line_p
= 0;
14974 /* Update window_end_pos etc.; last_reused_text_row is the last
14975 reused row from the current matrix containing text, if any.
14976 The value of last_text_row is the last displayed line
14977 containing text. */
14978 if (last_reused_text_row
)
14980 w
->window_end_bytepos
14981 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14983 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14985 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14986 w
->current_matrix
));
14988 else if (last_text_row
)
14990 w
->window_end_bytepos
14991 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14993 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14995 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14999 /* This window must be completely empty. */
15000 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
15001 w
->window_end_pos
= make_number (Z
- ZV
);
15002 w
->window_end_vpos
= make_number (0);
15004 w
->window_end_valid
= Qnil
;
15006 /* Update hint: don't try scrolling again in update_window. */
15007 w
->desired_matrix
->no_scrolling_p
= 1;
15010 debug_method_add (w
, "try_window_reusing_current_matrix 1");
15014 else if (CHARPOS (new_start
) > CHARPOS (start
))
15016 struct glyph_row
*pt_row
, *row
;
15017 struct glyph_row
*first_reusable_row
;
15018 struct glyph_row
*first_row_to_display
;
15020 int yb
= window_text_bottom_y (w
);
15022 /* Find the row starting at new_start, if there is one. Don't
15023 reuse a partially visible line at the end. */
15024 first_reusable_row
= start_row
;
15025 while (first_reusable_row
->enabled_p
15026 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
15027 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15028 < CHARPOS (new_start
)))
15029 ++first_reusable_row
;
15031 /* Give up if there is no row to reuse. */
15032 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
15033 || !first_reusable_row
->enabled_p
15034 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15035 != CHARPOS (new_start
)))
15038 /* We can reuse fully visible rows beginning with
15039 first_reusable_row to the end of the window. Set
15040 first_row_to_display to the first row that cannot be reused.
15041 Set pt_row to the row containing point, if there is any. */
15043 for (first_row_to_display
= first_reusable_row
;
15044 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
15045 ++first_row_to_display
)
15047 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
15048 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
15049 pt_row
= first_row_to_display
;
15052 /* Start displaying at the start of first_row_to_display. */
15053 xassert (first_row_to_display
->y
< yb
);
15054 init_to_row_start (&it
, w
, first_row_to_display
);
15056 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
15058 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
15060 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
15061 + WINDOW_HEADER_LINE_HEIGHT (w
));
15063 /* Display lines beginning with first_row_to_display in the
15064 desired matrix. Set last_text_row to the last row displayed
15065 that displays text. */
15066 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
15067 if (pt_row
== NULL
)
15068 w
->cursor
.vpos
= -1;
15069 last_text_row
= NULL
;
15070 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
15071 if (display_line (&it
))
15072 last_text_row
= it
.glyph_row
- 1;
15074 /* If point is in a reused row, adjust y and vpos of the cursor
15078 w
->cursor
.vpos
-= nrows_scrolled
;
15079 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
15082 /* Give up if point isn't in a row displayed or reused. (This
15083 also handles the case where w->cursor.vpos < nrows_scrolled
15084 after the calls to display_line, which can happen with scroll
15085 margins. See bug#1295.) */
15086 if (w
->cursor
.vpos
< 0)
15088 clear_glyph_matrix (w
->desired_matrix
);
15092 /* Scroll the display. */
15093 run
.current_y
= first_reusable_row
->y
;
15094 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15095 run
.height
= it
.last_visible_y
- run
.current_y
;
15096 dy
= run
.current_y
- run
.desired_y
;
15101 FRAME_RIF (f
)->update_window_begin_hook (w
);
15102 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15103 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15104 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15108 /* Adjust Y positions of reused rows. */
15109 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15110 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15111 max_y
= it
.last_visible_y
;
15112 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15115 row
->visible_height
= row
->height
;
15116 if (row
->y
< min_y
)
15117 row
->visible_height
-= min_y
- row
->y
;
15118 if (row
->y
+ row
->height
> max_y
)
15119 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15120 if (row
->fringe_bitmap_periodic_p
)
15121 row
->redraw_fringe_bitmaps_p
= 1;
15124 /* Scroll the current matrix. */
15125 xassert (nrows_scrolled
> 0);
15126 rotate_matrix (w
->current_matrix
,
15128 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15131 /* Disable rows not reused. */
15132 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15133 row
->enabled_p
= 0;
15135 /* Point may have moved to a different line, so we cannot assume that
15136 the previous cursor position is valid; locate the correct row. */
15139 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15140 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15144 w
->cursor
.y
= row
->y
;
15146 if (row
< bottom_row
)
15148 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15149 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15151 /* Can't use this optimization with bidi-reordered glyph
15152 rows, unless cursor is already at point. */
15153 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15155 if (!(w
->cursor
.hpos
>= 0
15156 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
15157 && BUFFERP (glyph
->object
)
15158 && glyph
->charpos
== PT
))
15163 && (!BUFFERP (glyph
->object
)
15164 || glyph
->charpos
< PT
);
15168 w
->cursor
.x
+= glyph
->pixel_width
;
15173 /* Adjust window end. A null value of last_text_row means that
15174 the window end is in reused rows which in turn means that
15175 only its vpos can have changed. */
15178 w
->window_end_bytepos
15179 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15181 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15183 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15188 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15191 w
->window_end_valid
= Qnil
;
15192 w
->desired_matrix
->no_scrolling_p
= 1;
15195 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15205 /************************************************************************
15206 Window redisplay reusing current matrix when buffer has changed
15207 ************************************************************************/
15209 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
15210 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
15211 EMACS_INT
*, EMACS_INT
*);
15212 static struct glyph_row
*
15213 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
15214 struct glyph_row
*);
15217 /* Return the last row in MATRIX displaying text. If row START is
15218 non-null, start searching with that row. IT gives the dimensions
15219 of the display. Value is null if matrix is empty; otherwise it is
15220 a pointer to the row found. */
15222 static struct glyph_row
*
15223 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
15224 struct glyph_row
*start
)
15226 struct glyph_row
*row
, *row_found
;
15228 /* Set row_found to the last row in IT->w's current matrix
15229 displaying text. The loop looks funny but think of partially
15232 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15233 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15235 xassert (row
->enabled_p
);
15237 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15246 /* Return the last row in the current matrix of W that is not affected
15247 by changes at the start of current_buffer that occurred since W's
15248 current matrix was built. Value is null if no such row exists.
15250 BEG_UNCHANGED us the number of characters unchanged at the start of
15251 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15252 first changed character in current_buffer. Characters at positions <
15253 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15254 when the current matrix was built. */
15256 static struct glyph_row
*
15257 find_last_unchanged_at_beg_row (struct window
*w
)
15259 EMACS_INT first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15260 struct glyph_row
*row
;
15261 struct glyph_row
*row_found
= NULL
;
15262 int yb
= window_text_bottom_y (w
);
15264 /* Find the last row displaying unchanged text. */
15265 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15266 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15267 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15270 if (/* If row ends before first_changed_pos, it is unchanged,
15271 except in some case. */
15272 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15273 /* When row ends in ZV and we write at ZV it is not
15275 && !row
->ends_at_zv_p
15276 /* When first_changed_pos is the end of a continued line,
15277 row is not unchanged because it may be no longer
15279 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15280 && (row
->continued_p
15281 || row
->exact_window_width_line_p
)))
15284 /* Stop if last visible row. */
15285 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15293 /* Find the first glyph row in the current matrix of W that is not
15294 affected by changes at the end of current_buffer since the
15295 time W's current matrix was built.
15297 Return in *DELTA the number of chars by which buffer positions in
15298 unchanged text at the end of current_buffer must be adjusted.
15300 Return in *DELTA_BYTES the corresponding number of bytes.
15302 Value is null if no such row exists, i.e. all rows are affected by
15305 static struct glyph_row
*
15306 find_first_unchanged_at_end_row (struct window
*w
,
15307 EMACS_INT
*delta
, EMACS_INT
*delta_bytes
)
15309 struct glyph_row
*row
;
15310 struct glyph_row
*row_found
= NULL
;
15312 *delta
= *delta_bytes
= 0;
15314 /* Display must not have been paused, otherwise the current matrix
15315 is not up to date. */
15316 eassert (!NILP (w
->window_end_valid
));
15318 /* A value of window_end_pos >= END_UNCHANGED means that the window
15319 end is in the range of changed text. If so, there is no
15320 unchanged row at the end of W's current matrix. */
15321 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15324 /* Set row to the last row in W's current matrix displaying text. */
15325 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15327 /* If matrix is entirely empty, no unchanged row exists. */
15328 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15330 /* The value of row is the last glyph row in the matrix having a
15331 meaningful buffer position in it. The end position of row
15332 corresponds to window_end_pos. This allows us to translate
15333 buffer positions in the current matrix to current buffer
15334 positions for characters not in changed text. */
15336 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15337 EMACS_INT Z_BYTE_old
=
15338 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15339 EMACS_INT last_unchanged_pos
, last_unchanged_pos_old
;
15340 struct glyph_row
*first_text_row
15341 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15343 *delta
= Z
- Z_old
;
15344 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15346 /* Set last_unchanged_pos to the buffer position of the last
15347 character in the buffer that has not been changed. Z is the
15348 index + 1 of the last character in current_buffer, i.e. by
15349 subtracting END_UNCHANGED we get the index of the last
15350 unchanged character, and we have to add BEG to get its buffer
15352 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15353 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15355 /* Search backward from ROW for a row displaying a line that
15356 starts at a minimum position >= last_unchanged_pos_old. */
15357 for (; row
> first_text_row
; --row
)
15359 /* This used to abort, but it can happen.
15360 It is ok to just stop the search instead here. KFS. */
15361 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15364 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15369 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15375 /* Make sure that glyph rows in the current matrix of window W
15376 reference the same glyph memory as corresponding rows in the
15377 frame's frame matrix. This function is called after scrolling W's
15378 current matrix on a terminal frame in try_window_id and
15379 try_window_reusing_current_matrix. */
15382 sync_frame_with_window_matrix_rows (struct window
*w
)
15384 struct frame
*f
= XFRAME (w
->frame
);
15385 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15387 /* Preconditions: W must be a leaf window and full-width. Its frame
15388 must have a frame matrix. */
15389 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15390 xassert (WINDOW_FULL_WIDTH_P (w
));
15391 xassert (!FRAME_WINDOW_P (f
));
15393 /* If W is a full-width window, glyph pointers in W's current matrix
15394 have, by definition, to be the same as glyph pointers in the
15395 corresponding frame matrix. Note that frame matrices have no
15396 marginal areas (see build_frame_matrix). */
15397 window_row
= w
->current_matrix
->rows
;
15398 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15399 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15400 while (window_row
< window_row_end
)
15402 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15403 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15405 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15406 frame_row
->glyphs
[TEXT_AREA
] = start
;
15407 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15408 frame_row
->glyphs
[LAST_AREA
] = end
;
15410 /* Disable frame rows whose corresponding window rows have
15411 been disabled in try_window_id. */
15412 if (!window_row
->enabled_p
)
15413 frame_row
->enabled_p
= 0;
15415 ++window_row
, ++frame_row
;
15420 /* Find the glyph row in window W containing CHARPOS. Consider all
15421 rows between START and END (not inclusive). END null means search
15422 all rows to the end of the display area of W. Value is the row
15423 containing CHARPOS or null. */
15426 row_containing_pos (struct window
*w
, EMACS_INT charpos
,
15427 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
15429 struct glyph_row
*row
= start
;
15430 struct glyph_row
*best_row
= NULL
;
15431 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15434 /* If we happen to start on a header-line, skip that. */
15435 if (row
->mode_line_p
)
15438 if ((end
&& row
>= end
) || !row
->enabled_p
)
15441 last_y
= window_text_bottom_y (w
) - dy
;
15445 /* Give up if we have gone too far. */
15446 if (end
&& row
>= end
)
15448 /* This formerly returned if they were equal.
15449 I think that both quantities are of a "last plus one" type;
15450 if so, when they are equal, the row is within the screen. -- rms. */
15451 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15454 /* If it is in this row, return this row. */
15455 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15456 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15457 /* The end position of a row equals the start
15458 position of the next row. If CHARPOS is there, we
15459 would rather display it in the next line, except
15460 when this line ends in ZV. */
15461 && !row
->ends_at_zv_p
15462 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15463 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15467 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
15468 || (!best_row
&& !row
->continued_p
))
15470 /* In bidi-reordered rows, there could be several rows
15471 occluding point, all of them belonging to the same
15472 continued line. We need to find the row which fits
15473 CHARPOS the best. */
15474 for (g
= row
->glyphs
[TEXT_AREA
];
15475 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15478 if (!STRINGP (g
->object
))
15480 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
15482 mindif
= eabs (g
->charpos
- charpos
);
15484 /* Exact match always wins. */
15491 else if (best_row
&& !row
->continued_p
)
15498 /* Try to redisplay window W by reusing its existing display. W's
15499 current matrix must be up to date when this function is called,
15500 i.e. window_end_valid must not be nil.
15504 1 if display has been updated
15505 0 if otherwise unsuccessful
15506 -1 if redisplay with same window start is known not to succeed
15508 The following steps are performed:
15510 1. Find the last row in the current matrix of W that is not
15511 affected by changes at the start of current_buffer. If no such row
15514 2. Find the first row in W's current matrix that is not affected by
15515 changes at the end of current_buffer. Maybe there is no such row.
15517 3. Display lines beginning with the row + 1 found in step 1 to the
15518 row found in step 2 or, if step 2 didn't find a row, to the end of
15521 4. If cursor is not known to appear on the window, give up.
15523 5. If display stopped at the row found in step 2, scroll the
15524 display and current matrix as needed.
15526 6. Maybe display some lines at the end of W, if we must. This can
15527 happen under various circumstances, like a partially visible line
15528 becoming fully visible, or because newly displayed lines are displayed
15529 in smaller font sizes.
15531 7. Update W's window end information. */
15534 try_window_id (struct window
*w
)
15536 struct frame
*f
= XFRAME (w
->frame
);
15537 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15538 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15539 struct glyph_row
*last_unchanged_at_beg_row
;
15540 struct glyph_row
*first_unchanged_at_end_row
;
15541 struct glyph_row
*row
;
15542 struct glyph_row
*bottom_row
;
15545 EMACS_INT delta
= 0, delta_bytes
= 0, stop_pos
;
15547 struct text_pos start_pos
;
15549 int first_unchanged_at_end_vpos
= 0;
15550 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15551 struct text_pos start
;
15552 EMACS_INT first_changed_charpos
, last_changed_charpos
;
15555 if (inhibit_try_window_id
)
15559 /* This is handy for debugging. */
15561 #define GIVE_UP(X) \
15563 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15567 #define GIVE_UP(X) return 0
15570 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15572 /* Don't use this for mini-windows because these can show
15573 messages and mini-buffers, and we don't handle that here. */
15574 if (MINI_WINDOW_P (w
))
15577 /* This flag is used to prevent redisplay optimizations. */
15578 if (windows_or_buffers_changed
|| cursor_type_changed
)
15581 /* Verify that narrowing has not changed.
15582 Also verify that we were not told to prevent redisplay optimizations.
15583 It would be nice to further
15584 reduce the number of cases where this prevents try_window_id. */
15585 if (current_buffer
->clip_changed
15586 || current_buffer
->prevent_redisplay_optimizations_p
)
15589 /* Window must either use window-based redisplay or be full width. */
15590 if (!FRAME_WINDOW_P (f
)
15591 && (!FRAME_LINE_INS_DEL_OK (f
)
15592 || !WINDOW_FULL_WIDTH_P (w
)))
15595 /* Give up if point is known NOT to appear in W. */
15596 if (PT
< CHARPOS (start
))
15599 /* Another way to prevent redisplay optimizations. */
15600 if (XFASTINT (w
->last_modified
) == 0)
15603 /* Verify that window is not hscrolled. */
15604 if (XFASTINT (w
->hscroll
) != 0)
15607 /* Verify that display wasn't paused. */
15608 if (NILP (w
->window_end_valid
))
15611 /* Can't use this if highlighting a region because a cursor movement
15612 will do more than just set the cursor. */
15613 if (!NILP (Vtransient_mark_mode
)
15614 && !NILP (BVAR (current_buffer
, mark_active
)))
15617 /* Likewise if highlighting trailing whitespace. */
15618 if (!NILP (Vshow_trailing_whitespace
))
15621 /* Likewise if showing a region. */
15622 if (!NILP (w
->region_showing
))
15625 /* Can't use this if overlay arrow position and/or string have
15627 if (overlay_arrows_changed_p ())
15630 /* When word-wrap is on, adding a space to the first word of a
15631 wrapped line can change the wrap position, altering the line
15632 above it. It might be worthwhile to handle this more
15633 intelligently, but for now just redisplay from scratch. */
15634 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
15637 /* Under bidi reordering, adding or deleting a character in the
15638 beginning of a paragraph, before the first strong directional
15639 character, can change the base direction of the paragraph (unless
15640 the buffer specifies a fixed paragraph direction), which will
15641 require to redisplay the whole paragraph. It might be worthwhile
15642 to find the paragraph limits and widen the range of redisplayed
15643 lines to that, but for now just give up this optimization and
15644 redisplay from scratch. */
15645 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
15646 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
15649 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
15650 only if buffer has really changed. The reason is that the gap is
15651 initially at Z for freshly visited files. The code below would
15652 set end_unchanged to 0 in that case. */
15653 if (MODIFF
> SAVE_MODIFF
15654 /* This seems to happen sometimes after saving a buffer. */
15655 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
15657 if (GPT
- BEG
< BEG_UNCHANGED
)
15658 BEG_UNCHANGED
= GPT
- BEG
;
15659 if (Z
- GPT
< END_UNCHANGED
)
15660 END_UNCHANGED
= Z
- GPT
;
15663 /* The position of the first and last character that has been changed. */
15664 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
15665 last_changed_charpos
= Z
- END_UNCHANGED
;
15667 /* If window starts after a line end, and the last change is in
15668 front of that newline, then changes don't affect the display.
15669 This case happens with stealth-fontification. Note that although
15670 the display is unchanged, glyph positions in the matrix have to
15671 be adjusted, of course. */
15672 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15673 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15674 && ((last_changed_charpos
< CHARPOS (start
)
15675 && CHARPOS (start
) == BEGV
)
15676 || (last_changed_charpos
< CHARPOS (start
) - 1
15677 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
15679 EMACS_INT Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
15680 struct glyph_row
*r0
;
15682 /* Compute how many chars/bytes have been added to or removed
15683 from the buffer. */
15684 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15685 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15686 Z_delta
= Z
- Z_old
;
15687 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15689 /* Give up if PT is not in the window. Note that it already has
15690 been checked at the start of try_window_id that PT is not in
15691 front of the window start. */
15692 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
15695 /* If window start is unchanged, we can reuse the whole matrix
15696 as is, after adjusting glyph positions. No need to compute
15697 the window end again, since its offset from Z hasn't changed. */
15698 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15699 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
15700 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
15701 /* PT must not be in a partially visible line. */
15702 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
15703 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15705 /* Adjust positions in the glyph matrix. */
15706 if (Z_delta
|| Z_delta_bytes
)
15708 struct glyph_row
*r1
15709 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15710 increment_matrix_positions (w
->current_matrix
,
15711 MATRIX_ROW_VPOS (r0
, current_matrix
),
15712 MATRIX_ROW_VPOS (r1
, current_matrix
),
15713 Z_delta
, Z_delta_bytes
);
15716 /* Set the cursor. */
15717 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15719 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15726 /* Handle the case that changes are all below what is displayed in
15727 the window, and that PT is in the window. This shortcut cannot
15728 be taken if ZV is visible in the window, and text has been added
15729 there that is visible in the window. */
15730 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15731 /* ZV is not visible in the window, or there are no
15732 changes at ZV, actually. */
15733 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15734 || first_changed_charpos
== last_changed_charpos
))
15736 struct glyph_row
*r0
;
15738 /* Give up if PT is not in the window. Note that it already has
15739 been checked at the start of try_window_id that PT is not in
15740 front of the window start. */
15741 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15744 /* If window start is unchanged, we can reuse the whole matrix
15745 as is, without changing glyph positions since no text has
15746 been added/removed in front of the window end. */
15747 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15748 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
15749 /* PT must not be in a partially visible line. */
15750 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15751 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15753 /* We have to compute the window end anew since text
15754 could have been added/removed after it. */
15756 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15757 w
->window_end_bytepos
15758 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15760 /* Set the cursor. */
15761 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15763 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15770 /* Give up if window start is in the changed area.
15772 The condition used to read
15774 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15776 but why that was tested escapes me at the moment. */
15777 if (CHARPOS (start
) >= first_changed_charpos
15778 && CHARPOS (start
) <= last_changed_charpos
)
15781 /* Check that window start agrees with the start of the first glyph
15782 row in its current matrix. Check this after we know the window
15783 start is not in changed text, otherwise positions would not be
15785 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15786 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
15789 /* Give up if the window ends in strings. Overlay strings
15790 at the end are difficult to handle, so don't try. */
15791 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15792 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15795 /* Compute the position at which we have to start displaying new
15796 lines. Some of the lines at the top of the window might be
15797 reusable because they are not displaying changed text. Find the
15798 last row in W's current matrix not affected by changes at the
15799 start of current_buffer. Value is null if changes start in the
15800 first line of window. */
15801 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15802 if (last_unchanged_at_beg_row
)
15804 /* Avoid starting to display in the moddle of a character, a TAB
15805 for instance. This is easier than to set up the iterator
15806 exactly, and it's not a frequent case, so the additional
15807 effort wouldn't really pay off. */
15808 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15809 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15810 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15811 --last_unchanged_at_beg_row
;
15813 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15816 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15818 start_pos
= it
.current
.pos
;
15820 /* Start displaying new lines in the desired matrix at the same
15821 vpos we would use in the current matrix, i.e. below
15822 last_unchanged_at_beg_row. */
15823 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15825 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15826 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15828 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15832 /* There are no reusable lines at the start of the window.
15833 Start displaying in the first text line. */
15834 start_display (&it
, w
, start
);
15835 it
.vpos
= it
.first_vpos
;
15836 start_pos
= it
.current
.pos
;
15839 /* Find the first row that is not affected by changes at the end of
15840 the buffer. Value will be null if there is no unchanged row, in
15841 which case we must redisplay to the end of the window. delta
15842 will be set to the value by which buffer positions beginning with
15843 first_unchanged_at_end_row have to be adjusted due to text
15845 first_unchanged_at_end_row
15846 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15847 IF_DEBUG (debug_delta
= delta
);
15848 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15850 /* Set stop_pos to the buffer position up to which we will have to
15851 display new lines. If first_unchanged_at_end_row != NULL, this
15852 is the buffer position of the start of the line displayed in that
15853 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15854 that we don't stop at a buffer position. */
15856 if (first_unchanged_at_end_row
)
15858 xassert (last_unchanged_at_beg_row
== NULL
15859 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15861 /* If this is a continuation line, move forward to the next one
15862 that isn't. Changes in lines above affect this line.
15863 Caution: this may move first_unchanged_at_end_row to a row
15864 not displaying text. */
15865 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15866 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15867 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15868 < it
.last_visible_y
))
15869 ++first_unchanged_at_end_row
;
15871 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15872 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15873 >= it
.last_visible_y
))
15874 first_unchanged_at_end_row
= NULL
;
15877 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15879 first_unchanged_at_end_vpos
15880 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15881 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15884 else if (last_unchanged_at_beg_row
== NULL
)
15890 /* Either there is no unchanged row at the end, or the one we have
15891 now displays text. This is a necessary condition for the window
15892 end pos calculation at the end of this function. */
15893 xassert (first_unchanged_at_end_row
== NULL
15894 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15896 debug_last_unchanged_at_beg_vpos
15897 = (last_unchanged_at_beg_row
15898 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15900 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15902 #endif /* GLYPH_DEBUG != 0 */
15905 /* Display new lines. Set last_text_row to the last new line
15906 displayed which has text on it, i.e. might end up as being the
15907 line where the window_end_vpos is. */
15908 w
->cursor
.vpos
= -1;
15909 last_text_row
= NULL
;
15910 overlay_arrow_seen
= 0;
15911 while (it
.current_y
< it
.last_visible_y
15912 && !fonts_changed_p
15913 && (first_unchanged_at_end_row
== NULL
15914 || IT_CHARPOS (it
) < stop_pos
))
15916 if (display_line (&it
))
15917 last_text_row
= it
.glyph_row
- 1;
15920 if (fonts_changed_p
)
15924 /* Compute differences in buffer positions, y-positions etc. for
15925 lines reused at the bottom of the window. Compute what we can
15927 if (first_unchanged_at_end_row
15928 /* No lines reused because we displayed everything up to the
15929 bottom of the window. */
15930 && it
.current_y
< it
.last_visible_y
)
15933 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15935 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15936 run
.current_y
= first_unchanged_at_end_row
->y
;
15937 run
.desired_y
= run
.current_y
+ dy
;
15938 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15942 delta
= delta_bytes
= dvpos
= dy
15943 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15944 first_unchanged_at_end_row
= NULL
;
15946 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15949 /* Find the cursor if not already found. We have to decide whether
15950 PT will appear on this window (it sometimes doesn't, but this is
15951 not a very frequent case.) This decision has to be made before
15952 the current matrix is altered. A value of cursor.vpos < 0 means
15953 that PT is either in one of the lines beginning at
15954 first_unchanged_at_end_row or below the window. Don't care for
15955 lines that might be displayed later at the window end; as
15956 mentioned, this is not a frequent case. */
15957 if (w
->cursor
.vpos
< 0)
15959 /* Cursor in unchanged rows at the top? */
15960 if (PT
< CHARPOS (start_pos
)
15961 && last_unchanged_at_beg_row
)
15963 row
= row_containing_pos (w
, PT
,
15964 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15965 last_unchanged_at_beg_row
+ 1, 0);
15967 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15970 /* Start from first_unchanged_at_end_row looking for PT. */
15971 else if (first_unchanged_at_end_row
)
15973 row
= row_containing_pos (w
, PT
- delta
,
15974 first_unchanged_at_end_row
, NULL
, 0);
15976 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15977 delta_bytes
, dy
, dvpos
);
15980 /* Give up if cursor was not found. */
15981 if (w
->cursor
.vpos
< 0)
15983 clear_glyph_matrix (w
->desired_matrix
);
15988 /* Don't let the cursor end in the scroll margins. */
15990 int this_scroll_margin
, cursor_height
;
15992 this_scroll_margin
= max (0, scroll_margin
);
15993 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15994 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15995 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15997 if ((w
->cursor
.y
< this_scroll_margin
15998 && CHARPOS (start
) > BEGV
)
15999 /* Old redisplay didn't take scroll margin into account at the bottom,
16000 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
16001 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
16002 ? cursor_height
+ this_scroll_margin
16003 : 1)) > it
.last_visible_y
)
16005 w
->cursor
.vpos
= -1;
16006 clear_glyph_matrix (w
->desired_matrix
);
16011 /* Scroll the display. Do it before changing the current matrix so
16012 that xterm.c doesn't get confused about where the cursor glyph is
16014 if (dy
&& run
.height
)
16018 if (FRAME_WINDOW_P (f
))
16020 FRAME_RIF (f
)->update_window_begin_hook (w
);
16021 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16022 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16023 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16027 /* Terminal frame. In this case, dvpos gives the number of
16028 lines to scroll by; dvpos < 0 means scroll up. */
16030 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
16031 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
16032 int end
= (WINDOW_TOP_EDGE_LINE (w
)
16033 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
16034 + window_internal_height (w
));
16036 #if defined (HAVE_GPM) || defined (MSDOS)
16037 x_clear_window_mouse_face (w
);
16039 /* Perform the operation on the screen. */
16042 /* Scroll last_unchanged_at_beg_row to the end of the
16043 window down dvpos lines. */
16044 set_terminal_window (f
, end
);
16046 /* On dumb terminals delete dvpos lines at the end
16047 before inserting dvpos empty lines. */
16048 if (!FRAME_SCROLL_REGION_OK (f
))
16049 ins_del_lines (f
, end
- dvpos
, -dvpos
);
16051 /* Insert dvpos empty lines in front of
16052 last_unchanged_at_beg_row. */
16053 ins_del_lines (f
, from
, dvpos
);
16055 else if (dvpos
< 0)
16057 /* Scroll up last_unchanged_at_beg_vpos to the end of
16058 the window to last_unchanged_at_beg_vpos - |dvpos|. */
16059 set_terminal_window (f
, end
);
16061 /* Delete dvpos lines in front of
16062 last_unchanged_at_beg_vpos. ins_del_lines will set
16063 the cursor to the given vpos and emit |dvpos| delete
16065 ins_del_lines (f
, from
+ dvpos
, dvpos
);
16067 /* On a dumb terminal insert dvpos empty lines at the
16069 if (!FRAME_SCROLL_REGION_OK (f
))
16070 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
16073 set_terminal_window (f
, 0);
16079 /* Shift reused rows of the current matrix to the right position.
16080 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
16082 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16083 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
16086 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
16087 bottom_vpos
, dvpos
);
16088 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
16091 else if (dvpos
> 0)
16093 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
16094 bottom_vpos
, dvpos
);
16095 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
16096 first_unchanged_at_end_vpos
+ dvpos
, 0);
16099 /* For frame-based redisplay, make sure that current frame and window
16100 matrix are in sync with respect to glyph memory. */
16101 if (!FRAME_WINDOW_P (f
))
16102 sync_frame_with_window_matrix_rows (w
);
16104 /* Adjust buffer positions in reused rows. */
16105 if (delta
|| delta_bytes
)
16106 increment_matrix_positions (current_matrix
,
16107 first_unchanged_at_end_vpos
+ dvpos
,
16108 bottom_vpos
, delta
, delta_bytes
);
16110 /* Adjust Y positions. */
16112 shift_glyph_matrix (w
, current_matrix
,
16113 first_unchanged_at_end_vpos
+ dvpos
,
16116 if (first_unchanged_at_end_row
)
16118 first_unchanged_at_end_row
+= dvpos
;
16119 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16120 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16121 first_unchanged_at_end_row
= NULL
;
16124 /* If scrolling up, there may be some lines to display at the end of
16126 last_text_row_at_end
= NULL
;
16129 /* Scrolling up can leave for example a partially visible line
16130 at the end of the window to be redisplayed. */
16131 /* Set last_row to the glyph row in the current matrix where the
16132 window end line is found. It has been moved up or down in
16133 the matrix by dvpos. */
16134 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16135 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16137 /* If last_row is the window end line, it should display text. */
16138 xassert (last_row
->displays_text_p
);
16140 /* If window end line was partially visible before, begin
16141 displaying at that line. Otherwise begin displaying with the
16142 line following it. */
16143 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16145 init_to_row_start (&it
, w
, last_row
);
16146 it
.vpos
= last_vpos
;
16147 it
.current_y
= last_row
->y
;
16151 init_to_row_end (&it
, w
, last_row
);
16152 it
.vpos
= 1 + last_vpos
;
16153 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16157 /* We may start in a continuation line. If so, we have to
16158 get the right continuation_lines_width and current_x. */
16159 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16160 it
.hpos
= it
.current_x
= 0;
16162 /* Display the rest of the lines at the window end. */
16163 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16164 while (it
.current_y
< it
.last_visible_y
16165 && !fonts_changed_p
)
16167 /* Is it always sure that the display agrees with lines in
16168 the current matrix? I don't think so, so we mark rows
16169 displayed invalid in the current matrix by setting their
16170 enabled_p flag to zero. */
16171 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16172 if (display_line (&it
))
16173 last_text_row_at_end
= it
.glyph_row
- 1;
16177 /* Update window_end_pos and window_end_vpos. */
16178 if (first_unchanged_at_end_row
16179 && !last_text_row_at_end
)
16181 /* Window end line if one of the preserved rows from the current
16182 matrix. Set row to the last row displaying text in current
16183 matrix starting at first_unchanged_at_end_row, after
16185 xassert (first_unchanged_at_end_row
->displays_text_p
);
16186 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16187 first_unchanged_at_end_row
);
16188 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16190 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16191 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16193 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16194 xassert (w
->window_end_bytepos
>= 0);
16195 IF_DEBUG (debug_method_add (w
, "A"));
16197 else if (last_text_row_at_end
)
16200 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16201 w
->window_end_bytepos
16202 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16204 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16205 xassert (w
->window_end_bytepos
>= 0);
16206 IF_DEBUG (debug_method_add (w
, "B"));
16208 else if (last_text_row
)
16210 /* We have displayed either to the end of the window or at the
16211 end of the window, i.e. the last row with text is to be found
16212 in the desired matrix. */
16214 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16215 w
->window_end_bytepos
16216 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16218 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16219 xassert (w
->window_end_bytepos
>= 0);
16221 else if (first_unchanged_at_end_row
== NULL
16222 && last_text_row
== NULL
16223 && last_text_row_at_end
== NULL
)
16225 /* Displayed to end of window, but no line containing text was
16226 displayed. Lines were deleted at the end of the window. */
16227 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16228 int vpos
= XFASTINT (w
->window_end_vpos
);
16229 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16230 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16233 row
== NULL
&& vpos
>= first_vpos
;
16234 --vpos
, --current_row
, --desired_row
)
16236 if (desired_row
->enabled_p
)
16238 if (desired_row
->displays_text_p
)
16241 else if (current_row
->displays_text_p
)
16245 xassert (row
!= NULL
);
16246 w
->window_end_vpos
= make_number (vpos
+ 1);
16247 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16248 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16249 xassert (w
->window_end_bytepos
>= 0);
16250 IF_DEBUG (debug_method_add (w
, "C"));
16255 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16256 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16258 /* Record that display has not been completed. */
16259 w
->window_end_valid
= Qnil
;
16260 w
->desired_matrix
->no_scrolling_p
= 1;
16268 /***********************************************************************
16269 More debugging support
16270 ***********************************************************************/
16274 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
16275 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
16276 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
16279 /* Dump the contents of glyph matrix MATRIX on stderr.
16281 GLYPHS 0 means don't show glyph contents.
16282 GLYPHS 1 means show glyphs in short form
16283 GLYPHS > 1 means show glyphs in long form. */
16286 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
16289 for (i
= 0; i
< matrix
->nrows
; ++i
)
16290 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16294 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16295 the glyph row and area where the glyph comes from. */
16298 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
16300 if (glyph
->type
== CHAR_GLYPH
)
16303 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16304 glyph
- row
->glyphs
[TEXT_AREA
],
16307 (BUFFERP (glyph
->object
)
16309 : (STRINGP (glyph
->object
)
16312 glyph
->pixel_width
,
16314 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16318 glyph
->left_box_line_p
,
16319 glyph
->right_box_line_p
);
16321 else if (glyph
->type
== STRETCH_GLYPH
)
16324 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16325 glyph
- row
->glyphs
[TEXT_AREA
],
16328 (BUFFERP (glyph
->object
)
16330 : (STRINGP (glyph
->object
)
16333 glyph
->pixel_width
,
16337 glyph
->left_box_line_p
,
16338 glyph
->right_box_line_p
);
16340 else if (glyph
->type
== IMAGE_GLYPH
)
16343 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16344 glyph
- row
->glyphs
[TEXT_AREA
],
16347 (BUFFERP (glyph
->object
)
16349 : (STRINGP (glyph
->object
)
16352 glyph
->pixel_width
,
16356 glyph
->left_box_line_p
,
16357 glyph
->right_box_line_p
);
16359 else if (glyph
->type
== COMPOSITE_GLYPH
)
16362 " %5td %4c %6"pI
"d %c %3d 0x%05x",
16363 glyph
- row
->glyphs
[TEXT_AREA
],
16366 (BUFFERP (glyph
->object
)
16368 : (STRINGP (glyph
->object
)
16371 glyph
->pixel_width
,
16373 if (glyph
->u
.cmp
.automatic
)
16376 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
16377 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16379 glyph
->left_box_line_p
,
16380 glyph
->right_box_line_p
);
16385 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16386 GLYPHS 0 means don't show glyph contents.
16387 GLYPHS 1 means show glyphs in short form
16388 GLYPHS > 1 means show glyphs in long form. */
16391 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
16395 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16396 fprintf (stderr
, "======================================================================\n");
16398 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
16399 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16401 MATRIX_ROW_START_CHARPOS (row
),
16402 MATRIX_ROW_END_CHARPOS (row
),
16403 row
->used
[TEXT_AREA
],
16404 row
->contains_overlapping_glyphs_p
,
16406 row
->truncated_on_left_p
,
16407 row
->truncated_on_right_p
,
16409 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16410 row
->displays_text_p
,
16413 row
->ends_in_middle_of_char_p
,
16414 row
->starts_in_middle_of_char_p
,
16420 row
->visible_height
,
16423 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16424 row
->end
.overlay_string_index
,
16425 row
->continuation_lines_width
);
16426 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
16427 CHARPOS (row
->start
.string_pos
),
16428 CHARPOS (row
->end
.string_pos
));
16429 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16430 row
->end
.dpvec_index
);
16437 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16439 struct glyph
*glyph
= row
->glyphs
[area
];
16440 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16442 /* Glyph for a line end in text. */
16443 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16446 if (glyph
< glyph_end
)
16447 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16449 for (; glyph
< glyph_end
; ++glyph
)
16450 dump_glyph (row
, glyph
, area
);
16453 else if (glyphs
== 1)
16457 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16459 char *s
= (char *) alloca (row
->used
[area
] + 1);
16462 for (i
= 0; i
< row
->used
[area
]; ++i
)
16464 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16465 if (glyph
->type
== CHAR_GLYPH
16466 && glyph
->u
.ch
< 0x80
16467 && glyph
->u
.ch
>= ' ')
16468 s
[i
] = glyph
->u
.ch
;
16474 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16480 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16481 Sdump_glyph_matrix
, 0, 1, "p",
16482 doc
: /* Dump the current matrix of the selected window to stderr.
16483 Shows contents of glyph row structures. With non-nil
16484 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16485 glyphs in short form, otherwise show glyphs in long form. */)
16486 (Lisp_Object glyphs
)
16488 struct window
*w
= XWINDOW (selected_window
);
16489 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16491 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
16492 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16493 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16494 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16495 fprintf (stderr
, "=============================================\n");
16496 dump_glyph_matrix (w
->current_matrix
,
16497 NILP (glyphs
) ? 0 : XINT (glyphs
));
16502 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16503 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16506 struct frame
*f
= XFRAME (selected_frame
);
16507 dump_glyph_matrix (f
->current_matrix
, 1);
16512 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16513 doc
: /* Dump glyph row ROW to stderr.
16514 GLYPH 0 means don't dump glyphs.
16515 GLYPH 1 means dump glyphs in short form.
16516 GLYPH > 1 or omitted means dump glyphs in long form. */)
16517 (Lisp_Object row
, Lisp_Object glyphs
)
16519 struct glyph_matrix
*matrix
;
16522 CHECK_NUMBER (row
);
16523 matrix
= XWINDOW (selected_window
)->current_matrix
;
16525 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16526 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16528 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16533 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16534 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16535 GLYPH 0 means don't dump glyphs.
16536 GLYPH 1 means dump glyphs in short form.
16537 GLYPH > 1 or omitted means dump glyphs in long form. */)
16538 (Lisp_Object row
, Lisp_Object glyphs
)
16540 struct frame
*sf
= SELECTED_FRAME ();
16541 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16544 CHECK_NUMBER (row
);
16546 if (vpos
>= 0 && vpos
< m
->nrows
)
16547 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16548 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16553 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16554 doc
: /* Toggle tracing of redisplay.
16555 With ARG, turn tracing on if and only if ARG is positive. */)
16559 trace_redisplay_p
= !trace_redisplay_p
;
16562 arg
= Fprefix_numeric_value (arg
);
16563 trace_redisplay_p
= XINT (arg
) > 0;
16570 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16571 doc
: /* Like `format', but print result to stderr.
16572 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16573 (ptrdiff_t nargs
, Lisp_Object
*args
)
16575 Lisp_Object s
= Fformat (nargs
, args
);
16576 fprintf (stderr
, "%s", SDATA (s
));
16580 #endif /* GLYPH_DEBUG */
16584 /***********************************************************************
16585 Building Desired Matrix Rows
16586 ***********************************************************************/
16588 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
16589 Used for non-window-redisplay windows, and for windows w/o left fringe. */
16591 static struct glyph_row
*
16592 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
16594 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16595 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16596 struct buffer
*old
= current_buffer
;
16597 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
16598 int arrow_len
= SCHARS (overlay_arrow_string
);
16599 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
16600 const unsigned char *p
;
16603 int n_glyphs_before
;
16605 set_buffer_temp (buffer
);
16606 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
16607 it
.glyph_row
->used
[TEXT_AREA
] = 0;
16608 SET_TEXT_POS (it
.position
, 0, 0);
16610 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
16612 while (p
< arrow_end
)
16614 Lisp_Object face
, ilisp
;
16616 /* Get the next character. */
16618 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
16621 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
16622 if (! ASCII_CHAR_P (it
.c
))
16623 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
16627 /* Get its face. */
16628 ilisp
= make_number (p
- arrow_string
);
16629 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
16630 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
16632 /* Compute its width, get its glyphs. */
16633 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
16634 SET_TEXT_POS (it
.position
, -1, -1);
16635 PRODUCE_GLYPHS (&it
);
16637 /* If this character doesn't fit any more in the line, we have
16638 to remove some glyphs. */
16639 if (it
.current_x
> it
.last_visible_x
)
16641 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16646 set_buffer_temp (old
);
16647 return it
.glyph_row
;
16651 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
16652 glyphs are only inserted for terminal frames since we can't really
16653 win with truncation glyphs when partially visible glyphs are
16654 involved. Which glyphs to insert is determined by
16655 produce_special_glyphs. */
16658 insert_left_trunc_glyphs (struct it
*it
)
16660 struct it truncate_it
;
16661 struct glyph
*from
, *end
, *to
, *toend
;
16663 xassert (!FRAME_WINDOW_P (it
->f
));
16665 /* Get the truncation glyphs. */
16667 truncate_it
.current_x
= 0;
16668 truncate_it
.face_id
= DEFAULT_FACE_ID
;
16669 truncate_it
.glyph_row
= &scratch_glyph_row
;
16670 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
16671 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
16672 truncate_it
.object
= make_number (0);
16673 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
16675 /* Overwrite glyphs from IT with truncation glyphs. */
16676 if (!it
->glyph_row
->reversed_p
)
16678 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16679 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
16680 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16681 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16686 /* There may be padding glyphs left over. Overwrite them too. */
16687 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16689 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16695 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16699 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
16700 that back to front. */
16701 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16702 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
16703 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16704 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
16706 while (from
>= end
&& to
>= toend
)
16708 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
16711 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
16712 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
16713 while (from
>= end
&& to
>= toend
)
16718 /* Need to free some room before prepending additional
16720 int move_by
= from
- end
+ 1;
16721 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16722 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
16724 for ( ; g
>= g0
; g
--)
16726 while (from
>= end
)
16728 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
16734 /* Compute the pixel height and width of IT->glyph_row.
16736 Most of the time, ascent and height of a display line will be equal
16737 to the max_ascent and max_height values of the display iterator
16738 structure. This is not the case if
16740 1. We hit ZV without displaying anything. In this case, max_ascent
16741 and max_height will be zero.
16743 2. We have some glyphs that don't contribute to the line height.
16744 (The glyph row flag contributes_to_line_height_p is for future
16745 pixmap extensions).
16747 The first case is easily covered by using default values because in
16748 these cases, the line height does not really matter, except that it
16749 must not be zero. */
16752 compute_line_metrics (struct it
*it
)
16754 struct glyph_row
*row
= it
->glyph_row
;
16756 if (FRAME_WINDOW_P (it
->f
))
16758 int i
, min_y
, max_y
;
16760 /* The line may consist of one space only, that was added to
16761 place the cursor on it. If so, the row's height hasn't been
16763 if (row
->height
== 0)
16765 if (it
->max_ascent
+ it
->max_descent
== 0)
16766 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16767 row
->ascent
= it
->max_ascent
;
16768 row
->height
= it
->max_ascent
+ it
->max_descent
;
16769 row
->phys_ascent
= it
->max_phys_ascent
;
16770 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16771 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16774 /* Compute the width of this line. */
16775 row
->pixel_width
= row
->x
;
16776 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16777 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16779 xassert (row
->pixel_width
>= 0);
16780 xassert (row
->ascent
>= 0 && row
->height
> 0);
16782 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16783 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16785 /* If first line's physical ascent is larger than its logical
16786 ascent, use the physical ascent, and make the row taller.
16787 This makes accented characters fully visible. */
16788 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16789 && row
->phys_ascent
> row
->ascent
)
16791 row
->height
+= row
->phys_ascent
- row
->ascent
;
16792 row
->ascent
= row
->phys_ascent
;
16795 /* Compute how much of the line is visible. */
16796 row
->visible_height
= row
->height
;
16798 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16799 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16801 if (row
->y
< min_y
)
16802 row
->visible_height
-= min_y
- row
->y
;
16803 if (row
->y
+ row
->height
> max_y
)
16804 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16808 row
->pixel_width
= row
->used
[TEXT_AREA
];
16809 if (row
->continued_p
)
16810 row
->pixel_width
-= it
->continuation_pixel_width
;
16811 else if (row
->truncated_on_right_p
)
16812 row
->pixel_width
-= it
->truncation_pixel_width
;
16813 row
->ascent
= row
->phys_ascent
= 0;
16814 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16815 row
->extra_line_spacing
= 0;
16818 /* Compute a hash code for this row. */
16822 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16823 for (i
= 0; i
< row
->used
[area
]; ++i
)
16824 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16825 + row
->glyphs
[area
][i
].u
.val
16826 + row
->glyphs
[area
][i
].face_id
16827 + row
->glyphs
[area
][i
].padding_p
16828 + (row
->glyphs
[area
][i
].type
<< 2));
16831 it
->max_ascent
= it
->max_descent
= 0;
16832 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16836 /* Append one space to the glyph row of iterator IT if doing a
16837 window-based redisplay. The space has the same face as
16838 IT->face_id. Value is non-zero if a space was added.
16840 This function is called to make sure that there is always one glyph
16841 at the end of a glyph row that the cursor can be set on under
16842 window-systems. (If there weren't such a glyph we would not know
16843 how wide and tall a box cursor should be displayed).
16845 At the same time this space let's a nicely handle clearing to the
16846 end of the line if the row ends in italic text. */
16849 append_space_for_newline (struct it
*it
, int default_face_p
)
16851 if (FRAME_WINDOW_P (it
->f
))
16853 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16855 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16856 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16858 /* Save some values that must not be changed.
16859 Must save IT->c and IT->len because otherwise
16860 ITERATOR_AT_END_P wouldn't work anymore after
16861 append_space_for_newline has been called. */
16862 enum display_element_type saved_what
= it
->what
;
16863 int saved_c
= it
->c
, saved_len
= it
->len
;
16864 int saved_char_to_display
= it
->char_to_display
;
16865 int saved_x
= it
->current_x
;
16866 int saved_face_id
= it
->face_id
;
16867 struct text_pos saved_pos
;
16868 Lisp_Object saved_object
;
16871 saved_object
= it
->object
;
16872 saved_pos
= it
->position
;
16874 it
->what
= IT_CHARACTER
;
16875 memset (&it
->position
, 0, sizeof it
->position
);
16876 it
->object
= make_number (0);
16877 it
->c
= it
->char_to_display
= ' ';
16880 if (default_face_p
)
16881 it
->face_id
= DEFAULT_FACE_ID
;
16882 else if (it
->face_before_selective_p
)
16883 it
->face_id
= it
->saved_face_id
;
16884 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16885 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16887 PRODUCE_GLYPHS (it
);
16889 it
->override_ascent
= -1;
16890 it
->constrain_row_ascent_descent_p
= 0;
16891 it
->current_x
= saved_x
;
16892 it
->object
= saved_object
;
16893 it
->position
= saved_pos
;
16894 it
->what
= saved_what
;
16895 it
->face_id
= saved_face_id
;
16896 it
->len
= saved_len
;
16898 it
->char_to_display
= saved_char_to_display
;
16907 /* Extend the face of the last glyph in the text area of IT->glyph_row
16908 to the end of the display line. Called from display_line. If the
16909 glyph row is empty, add a space glyph to it so that we know the
16910 face to draw. Set the glyph row flag fill_line_p. If the glyph
16911 row is R2L, prepend a stretch glyph to cover the empty space to the
16912 left of the leftmost glyph. */
16915 extend_face_to_end_of_line (struct it
*it
)
16918 struct frame
*f
= it
->f
;
16920 /* If line is already filled, do nothing. Non window-system frames
16921 get a grace of one more ``pixel'' because their characters are
16922 1-``pixel'' wide, so they hit the equality too early. This grace
16923 is needed only for R2L rows that are not continued, to produce
16924 one extra blank where we could display the cursor. */
16925 if (it
->current_x
>= it
->last_visible_x
16926 + (!FRAME_WINDOW_P (f
)
16927 && it
->glyph_row
->reversed_p
16928 && !it
->glyph_row
->continued_p
))
16931 /* Face extension extends the background and box of IT->face_id
16932 to the end of the line. If the background equals the background
16933 of the frame, we don't have to do anything. */
16934 if (it
->face_before_selective_p
)
16935 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
16937 face
= FACE_FROM_ID (f
, it
->face_id
);
16939 if (FRAME_WINDOW_P (f
)
16940 && it
->glyph_row
->displays_text_p
16941 && face
->box
== FACE_NO_BOX
16942 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16944 && !it
->glyph_row
->reversed_p
)
16947 /* Set the glyph row flag indicating that the face of the last glyph
16948 in the text area has to be drawn to the end of the text area. */
16949 it
->glyph_row
->fill_line_p
= 1;
16951 /* If current character of IT is not ASCII, make sure we have the
16952 ASCII face. This will be automatically undone the next time
16953 get_next_display_element returns a multibyte character. Note
16954 that the character will always be single byte in unibyte
16956 if (!ASCII_CHAR_P (it
->c
))
16958 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16961 if (FRAME_WINDOW_P (f
))
16963 /* If the row is empty, add a space with the current face of IT,
16964 so that we know which face to draw. */
16965 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16967 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16968 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16969 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16971 #ifdef HAVE_WINDOW_SYSTEM
16972 if (it
->glyph_row
->reversed_p
)
16974 /* Prepend a stretch glyph to the row, such that the
16975 rightmost glyph will be drawn flushed all the way to the
16976 right margin of the window. The stretch glyph that will
16977 occupy the empty space, if any, to the left of the
16979 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
16980 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16981 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
16983 int row_width
, stretch_ascent
, stretch_width
;
16984 struct text_pos saved_pos
;
16985 int saved_face_id
, saved_avoid_cursor
;
16987 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
16988 row_width
+= g
->pixel_width
;
16989 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
16990 if (stretch_width
> 0)
16993 (((it
->ascent
+ it
->descent
)
16994 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
16995 saved_pos
= it
->position
;
16996 memset (&it
->position
, 0, sizeof it
->position
);
16997 saved_avoid_cursor
= it
->avoid_cursor_p
;
16998 it
->avoid_cursor_p
= 1;
16999 saved_face_id
= it
->face_id
;
17000 /* The last row's stretch glyph should get the default
17001 face, to avoid painting the rest of the window with
17002 the region face, if the region ends at ZV. */
17003 if (it
->glyph_row
->ends_at_zv_p
)
17004 it
->face_id
= DEFAULT_FACE_ID
;
17006 it
->face_id
= face
->id
;
17007 append_stretch_glyph (it
, make_number (0), stretch_width
,
17008 it
->ascent
+ it
->descent
, stretch_ascent
);
17009 it
->position
= saved_pos
;
17010 it
->avoid_cursor_p
= saved_avoid_cursor
;
17011 it
->face_id
= saved_face_id
;
17014 #endif /* HAVE_WINDOW_SYSTEM */
17018 /* Save some values that must not be changed. */
17019 int saved_x
= it
->current_x
;
17020 struct text_pos saved_pos
;
17021 Lisp_Object saved_object
;
17022 enum display_element_type saved_what
= it
->what
;
17023 int saved_face_id
= it
->face_id
;
17025 saved_object
= it
->object
;
17026 saved_pos
= it
->position
;
17028 it
->what
= IT_CHARACTER
;
17029 memset (&it
->position
, 0, sizeof it
->position
);
17030 it
->object
= make_number (0);
17031 it
->c
= it
->char_to_display
= ' ';
17033 /* The last row's blank glyphs should get the default face, to
17034 avoid painting the rest of the window with the region face,
17035 if the region ends at ZV. */
17036 if (it
->glyph_row
->ends_at_zv_p
)
17037 it
->face_id
= DEFAULT_FACE_ID
;
17039 it
->face_id
= face
->id
;
17041 PRODUCE_GLYPHS (it
);
17043 while (it
->current_x
<= it
->last_visible_x
)
17044 PRODUCE_GLYPHS (it
);
17046 /* Don't count these blanks really. It would let us insert a left
17047 truncation glyph below and make us set the cursor on them, maybe. */
17048 it
->current_x
= saved_x
;
17049 it
->object
= saved_object
;
17050 it
->position
= saved_pos
;
17051 it
->what
= saved_what
;
17052 it
->face_id
= saved_face_id
;
17057 /* Value is non-zero if text starting at CHARPOS in current_buffer is
17058 trailing whitespace. */
17061 trailing_whitespace_p (EMACS_INT charpos
)
17063 EMACS_INT bytepos
= CHAR_TO_BYTE (charpos
);
17066 while (bytepos
< ZV_BYTE
17067 && (c
= FETCH_CHAR (bytepos
),
17068 c
== ' ' || c
== '\t'))
17071 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
17073 if (bytepos
!= PT_BYTE
)
17080 /* Highlight trailing whitespace, if any, in ROW. */
17083 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
17085 int used
= row
->used
[TEXT_AREA
];
17089 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
17090 struct glyph
*glyph
= start
+ used
- 1;
17092 if (row
->reversed_p
)
17094 /* Right-to-left rows need to be processed in the opposite
17095 direction, so swap the edge pointers. */
17097 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
17100 /* Skip over glyphs inserted to display the cursor at the
17101 end of a line, for extending the face of the last glyph
17102 to the end of the line on terminals, and for truncation
17103 and continuation glyphs. */
17104 if (!row
->reversed_p
)
17106 while (glyph
>= start
17107 && glyph
->type
== CHAR_GLYPH
17108 && INTEGERP (glyph
->object
))
17113 while (glyph
<= start
17114 && glyph
->type
== CHAR_GLYPH
17115 && INTEGERP (glyph
->object
))
17119 /* If last glyph is a space or stretch, and it's trailing
17120 whitespace, set the face of all trailing whitespace glyphs in
17121 IT->glyph_row to `trailing-whitespace'. */
17122 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
17123 && BUFFERP (glyph
->object
)
17124 && (glyph
->type
== STRETCH_GLYPH
17125 || (glyph
->type
== CHAR_GLYPH
17126 && glyph
->u
.ch
== ' '))
17127 && trailing_whitespace_p (glyph
->charpos
))
17129 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
17133 if (!row
->reversed_p
)
17135 while (glyph
>= start
17136 && BUFFERP (glyph
->object
)
17137 && (glyph
->type
== STRETCH_GLYPH
17138 || (glyph
->type
== CHAR_GLYPH
17139 && glyph
->u
.ch
== ' ')))
17140 (glyph
--)->face_id
= face_id
;
17144 while (glyph
<= start
17145 && BUFFERP (glyph
->object
)
17146 && (glyph
->type
== STRETCH_GLYPH
17147 || (glyph
->type
== CHAR_GLYPH
17148 && glyph
->u
.ch
== ' ')))
17149 (glyph
++)->face_id
= face_id
;
17156 /* Value is non-zero if glyph row ROW should be
17157 used to hold the cursor. */
17160 cursor_row_p (struct glyph_row
*row
)
17164 if (PT
== CHARPOS (row
->end
.pos
))
17166 /* Suppose the row ends on a string.
17167 Unless the row is continued, that means it ends on a newline
17168 in the string. If it's anything other than a display string
17169 (e.g. a before-string from an overlay), we don't want the
17170 cursor there. (This heuristic seems to give the optimal
17171 behavior for the various types of multi-line strings.) */
17172 if (CHARPOS (row
->end
.string_pos
) >= 0)
17174 if (row
->continued_p
)
17178 /* Check for `display' property. */
17179 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17180 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17181 struct glyph
*glyph
;
17184 for (glyph
= end
; glyph
>= beg
; --glyph
)
17185 if (STRINGP (glyph
->object
))
17188 = Fget_char_property (make_number (PT
),
17192 && display_prop_string_p (prop
, glyph
->object
));
17197 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17199 /* If the row ends in middle of a real character,
17200 and the line is continued, we want the cursor here.
17201 That's because CHARPOS (ROW->end.pos) would equal
17202 PT if PT is before the character. */
17203 if (!row
->ends_in_ellipsis_p
)
17204 result
= row
->continued_p
;
17206 /* If the row ends in an ellipsis, then
17207 CHARPOS (ROW->end.pos) will equal point after the
17208 invisible text. We want that position to be displayed
17209 after the ellipsis. */
17212 /* If the row ends at ZV, display the cursor at the end of that
17213 row instead of at the start of the row below. */
17214 else if (row
->ends_at_zv_p
)
17225 /* Push the display property PROP so that it will be rendered at the
17226 current position in IT. Return 1 if PROP was successfully pushed,
17230 push_display_prop (struct it
*it
, Lisp_Object prop
)
17232 push_it (it
, NULL
);
17234 if (STRINGP (prop
))
17236 if (SCHARS (prop
) == 0)
17243 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17244 it
->current
.overlay_string_index
= -1;
17245 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17246 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17247 it
->method
= GET_FROM_STRING
;
17248 it
->stop_charpos
= 0;
17250 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17252 it
->method
= GET_FROM_STRETCH
;
17255 #ifdef HAVE_WINDOW_SYSTEM
17256 else if (IMAGEP (prop
))
17258 it
->what
= IT_IMAGE
;
17259 it
->image_id
= lookup_image (it
->f
, prop
);
17260 it
->method
= GET_FROM_IMAGE
;
17262 #endif /* HAVE_WINDOW_SYSTEM */
17265 pop_it (it
); /* bogus display property, give up */
17272 /* Return the character-property PROP at the current position in IT. */
17275 get_it_property (struct it
*it
, Lisp_Object prop
)
17277 Lisp_Object position
;
17279 if (STRINGP (it
->object
))
17280 position
= make_number (IT_STRING_CHARPOS (*it
));
17281 else if (BUFFERP (it
->object
))
17282 position
= make_number (IT_CHARPOS (*it
));
17286 return Fget_char_property (position
, prop
, it
->object
);
17289 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17292 handle_line_prefix (struct it
*it
)
17294 Lisp_Object prefix
;
17295 if (it
->continuation_lines_width
> 0)
17297 prefix
= get_it_property (it
, Qwrap_prefix
);
17299 prefix
= Vwrap_prefix
;
17303 prefix
= get_it_property (it
, Qline_prefix
);
17305 prefix
= Vline_prefix
;
17307 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17309 /* If the prefix is wider than the window, and we try to wrap
17310 it, it would acquire its own wrap prefix, and so on till the
17311 iterator stack overflows. So, don't wrap the prefix. */
17312 it
->line_wrap
= TRUNCATE
;
17313 it
->avoid_cursor_p
= 1;
17319 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
17320 only for R2L lines from display_line, when it decides that too many
17321 glyphs were produced by PRODUCE_GLYPHS, and the line needs to be
17324 unproduce_glyphs (struct it
*it
, int n
)
17326 struct glyph
*glyph
, *end
;
17328 xassert (it
->glyph_row
);
17329 xassert (it
->glyph_row
->reversed_p
);
17330 xassert (it
->area
== TEXT_AREA
);
17331 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
17333 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
17334 n
= it
->glyph_row
->used
[TEXT_AREA
];
17335 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
17336 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
17337 for ( ; glyph
< end
; glyph
++)
17338 glyph
[-n
] = *glyph
;
17341 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
17342 and ROW->maxpos. */
17344 find_row_edges (struct it
*it
, struct glyph_row
*row
,
17345 EMACS_INT min_pos
, EMACS_INT min_bpos
,
17346 EMACS_INT max_pos
, EMACS_INT max_bpos
)
17348 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17349 lines' rows is implemented for bidi-reordered rows. */
17351 /* ROW->minpos is the value of min_pos, the minimal buffer position
17354 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
17356 /* We didn't find _any_ valid buffer positions in any of the
17357 glyphs, so we must trust the iterator's computed positions. */
17358 row
->minpos
= row
->start
.pos
;
17361 max_pos
= CHARPOS (it
->current
.pos
);
17362 max_bpos
= BYTEPOS (it
->current
.pos
);
17365 /* Here are the various use-cases for ending the row, and the
17366 corresponding values for ROW->maxpos:
17368 Line ends in a newline from buffer eol_pos + 1
17369 Line is continued from buffer max_pos + 1
17370 Line is truncated on right it->current.pos
17371 Line ends in a newline from string max_pos
17372 Line is continued from string max_pos
17373 Line is continued from display vector max_pos
17374 Line is entirely from a string min_pos == max_pos
17375 Line is entirely from a display vector min_pos == max_pos
17376 Line that ends at ZV ZV
17378 If you discover other use-cases, please add them here as
17380 if (row
->ends_at_zv_p
)
17381 row
->maxpos
= it
->current
.pos
;
17382 else if (row
->used
[TEXT_AREA
])
17384 if (row
->ends_in_newline_from_string_p
)
17385 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17386 else if (CHARPOS (it
->eol_pos
) > 0)
17387 SET_TEXT_POS (row
->maxpos
,
17388 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
17389 else if (row
->continued_p
)
17391 /* If max_pos is different from IT's current position, it
17392 means IT->method does not belong to the display element
17393 at max_pos. However, it also means that the display
17394 element at max_pos was displayed in its entirety on this
17395 line, which is equivalent to saying that the next line
17396 starts at the next buffer position. */
17397 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
17398 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17401 INC_BOTH (max_pos
, max_bpos
);
17402 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17405 else if (row
->truncated_on_right_p
)
17406 /* display_line already called reseat_at_next_visible_line_start,
17407 which puts the iterator at the beginning of the next line, in
17408 the logical order. */
17409 row
->maxpos
= it
->current
.pos
;
17410 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
17411 /* A line that is entirely from a string/image/stretch... */
17412 row
->maxpos
= row
->minpos
;
17417 row
->maxpos
= it
->current
.pos
;
17420 /* Construct the glyph row IT->glyph_row in the desired matrix of
17421 IT->w from text at the current position of IT. See dispextern.h
17422 for an overview of struct it. Value is non-zero if
17423 IT->glyph_row displays text, as opposed to a line displaying ZV
17427 display_line (struct it
*it
)
17429 struct glyph_row
*row
= it
->glyph_row
;
17430 Lisp_Object overlay_arrow_string
;
17432 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
17433 int wrap_row_used
= -1;
17434 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
17435 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
17436 int wrap_row_extra_line_spacing
IF_LINT (= 0);
17437 EMACS_INT wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
17438 EMACS_INT wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
17440 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
17441 EMACS_INT min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
17443 /* We always start displaying at hpos zero even if hscrolled. */
17444 xassert (it
->hpos
== 0 && it
->current_x
== 0);
17446 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
17447 >= it
->w
->desired_matrix
->nrows
)
17449 it
->w
->nrows_scale_factor
++;
17450 fonts_changed_p
= 1;
17454 /* Is IT->w showing the region? */
17455 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
17457 /* Clear the result glyph row and enable it. */
17458 prepare_desired_row (row
);
17460 row
->y
= it
->current_y
;
17461 row
->start
= it
->start
;
17462 row
->continuation_lines_width
= it
->continuation_lines_width
;
17463 row
->displays_text_p
= 1;
17464 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
17465 it
->starts_in_middle_of_char_p
= 0;
17467 /* Arrange the overlays nicely for our purposes. Usually, we call
17468 display_line on only one line at a time, in which case this
17469 can't really hurt too much, or we call it on lines which appear
17470 one after another in the buffer, in which case all calls to
17471 recenter_overlay_lists but the first will be pretty cheap. */
17472 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
17474 /* Move over display elements that are not visible because we are
17475 hscrolled. This may stop at an x-position < IT->first_visible_x
17476 if the first glyph is partially visible or if we hit a line end. */
17477 if (it
->current_x
< it
->first_visible_x
)
17479 this_line_min_pos
= row
->start
.pos
;
17480 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
17481 MOVE_TO_POS
| MOVE_TO_X
);
17482 /* Record the smallest positions seen while we moved over
17483 display elements that are not visible. This is needed by
17484 redisplay_internal for optimizing the case where the cursor
17485 stays inside the same line. The rest of this function only
17486 considers positions that are actually displayed, so
17487 RECORD_MAX_MIN_POS will not otherwise record positions that
17488 are hscrolled to the left of the left edge of the window. */
17489 min_pos
= CHARPOS (this_line_min_pos
);
17490 min_bpos
= BYTEPOS (this_line_min_pos
);
17494 /* We only do this when not calling `move_it_in_display_line_to'
17495 above, because move_it_in_display_line_to calls
17496 handle_line_prefix itself. */
17497 handle_line_prefix (it
);
17500 /* Get the initial row height. This is either the height of the
17501 text hscrolled, if there is any, or zero. */
17502 row
->ascent
= it
->max_ascent
;
17503 row
->height
= it
->max_ascent
+ it
->max_descent
;
17504 row
->phys_ascent
= it
->max_phys_ascent
;
17505 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17506 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17508 /* Utility macro to record max and min buffer positions seen until now. */
17509 #define RECORD_MAX_MIN_POS(IT) \
17512 if (IT_CHARPOS (*(IT)) < min_pos) \
17514 min_pos = IT_CHARPOS (*(IT)); \
17515 min_bpos = IT_BYTEPOS (*(IT)); \
17517 if (IT_CHARPOS (*(IT)) > max_pos) \
17519 max_pos = IT_CHARPOS (*(IT)); \
17520 max_bpos = IT_BYTEPOS (*(IT)); \
17525 /* Loop generating characters. The loop is left with IT on the next
17526 character to display. */
17529 int n_glyphs_before
, hpos_before
, x_before
;
17531 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17533 /* Retrieve the next thing to display. Value is zero if end of
17535 if (!get_next_display_element (it
))
17537 /* Maybe add a space at the end of this line that is used to
17538 display the cursor there under X. Set the charpos of the
17539 first glyph of blank lines not corresponding to any text
17541 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17542 row
->exact_window_width_line_p
= 1;
17543 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17544 || row
->used
[TEXT_AREA
] == 0)
17546 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17547 row
->displays_text_p
= 0;
17549 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
17550 && (!MINI_WINDOW_P (it
->w
)
17551 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17552 row
->indicate_empty_line_p
= 1;
17555 it
->continuation_lines_width
= 0;
17556 row
->ends_at_zv_p
= 1;
17557 /* A row that displays right-to-left text must always have
17558 its last face extended all the way to the end of line,
17559 even if this row ends in ZV, because we still write to
17560 the screen left to right. */
17561 if (row
->reversed_p
)
17562 extend_face_to_end_of_line (it
);
17566 /* Now, get the metrics of what we want to display. This also
17567 generates glyphs in `row' (which is IT->glyph_row). */
17568 n_glyphs_before
= row
->used
[TEXT_AREA
];
17571 /* Remember the line height so far in case the next element doesn't
17572 fit on the line. */
17573 if (it
->line_wrap
!= TRUNCATE
)
17575 ascent
= it
->max_ascent
;
17576 descent
= it
->max_descent
;
17577 phys_ascent
= it
->max_phys_ascent
;
17578 phys_descent
= it
->max_phys_descent
;
17580 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17582 if (IT_DISPLAYING_WHITESPACE (it
))
17588 wrap_row_used
= row
->used
[TEXT_AREA
];
17589 wrap_row_ascent
= row
->ascent
;
17590 wrap_row_height
= row
->height
;
17591 wrap_row_phys_ascent
= row
->phys_ascent
;
17592 wrap_row_phys_height
= row
->phys_height
;
17593 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
17594 wrap_row_min_pos
= min_pos
;
17595 wrap_row_min_bpos
= min_bpos
;
17596 wrap_row_max_pos
= max_pos
;
17597 wrap_row_max_bpos
= max_bpos
;
17603 PRODUCE_GLYPHS (it
);
17605 /* If this display element was in marginal areas, continue with
17607 if (it
->area
!= TEXT_AREA
)
17609 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17610 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17611 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17612 row
->phys_height
= max (row
->phys_height
,
17613 it
->max_phys_ascent
+ it
->max_phys_descent
);
17614 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17615 it
->max_extra_line_spacing
);
17616 set_iterator_to_next (it
, 1);
17620 /* Does the display element fit on the line? If we truncate
17621 lines, we should draw past the right edge of the window. If
17622 we don't truncate, we want to stop so that we can display the
17623 continuation glyph before the right margin. If lines are
17624 continued, there are two possible strategies for characters
17625 resulting in more than 1 glyph (e.g. tabs): Display as many
17626 glyphs as possible in this line and leave the rest for the
17627 continuation line, or display the whole element in the next
17628 line. Original redisplay did the former, so we do it also. */
17629 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
17630 hpos_before
= it
->hpos
;
17633 if (/* Not a newline. */
17635 /* Glyphs produced fit entirely in the line. */
17636 && it
->current_x
< it
->last_visible_x
)
17638 it
->hpos
+= nglyphs
;
17639 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17640 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17641 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17642 row
->phys_height
= max (row
->phys_height
,
17643 it
->max_phys_ascent
+ it
->max_phys_descent
);
17644 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17645 it
->max_extra_line_spacing
);
17646 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
17647 row
->x
= x
- it
->first_visible_x
;
17648 /* Record the maximum and minimum buffer positions seen so
17649 far in glyphs that will be displayed by this row. */
17651 RECORD_MAX_MIN_POS (it
);
17656 struct glyph
*glyph
;
17658 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
17660 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17661 new_x
= x
+ glyph
->pixel_width
;
17663 if (/* Lines are continued. */
17664 it
->line_wrap
!= TRUNCATE
17665 && (/* Glyph doesn't fit on the line. */
17666 new_x
> it
->last_visible_x
17667 /* Or it fits exactly on a window system frame. */
17668 || (new_x
== it
->last_visible_x
17669 && FRAME_WINDOW_P (it
->f
))))
17671 /* End of a continued line. */
17674 || (new_x
== it
->last_visible_x
17675 && FRAME_WINDOW_P (it
->f
)))
17677 /* Current glyph is the only one on the line or
17678 fits exactly on the line. We must continue
17679 the line because we can't draw the cursor
17680 after the glyph. */
17681 row
->continued_p
= 1;
17682 it
->current_x
= new_x
;
17683 it
->continuation_lines_width
+= new_x
;
17685 /* Record the maximum and minimum buffer
17686 positions seen so far in glyphs that will be
17687 displayed by this row. */
17689 RECORD_MAX_MIN_POS (it
);
17690 if (i
== nglyphs
- 1)
17692 /* If line-wrap is on, check if a previous
17693 wrap point was found. */
17694 if (wrap_row_used
> 0
17695 /* Even if there is a previous wrap
17696 point, continue the line here as
17697 usual, if (i) the previous character
17698 was a space or tab AND (ii) the
17699 current character is not. */
17701 || IT_DISPLAYING_WHITESPACE (it
)))
17704 set_iterator_to_next (it
, 1);
17705 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17707 if (!get_next_display_element (it
))
17709 row
->exact_window_width_line_p
= 1;
17710 it
->continuation_lines_width
= 0;
17711 row
->continued_p
= 0;
17712 row
->ends_at_zv_p
= 1;
17714 else if (ITERATOR_AT_END_OF_LINE_P (it
))
17716 row
->continued_p
= 0;
17717 row
->exact_window_width_line_p
= 1;
17722 else if (CHAR_GLYPH_PADDING_P (*glyph
)
17723 && !FRAME_WINDOW_P (it
->f
))
17725 /* A padding glyph that doesn't fit on this line.
17726 This means the whole character doesn't fit
17728 if (row
->reversed_p
)
17729 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
17730 - n_glyphs_before
);
17731 row
->used
[TEXT_AREA
] = n_glyphs_before
;
17733 /* Fill the rest of the row with continuation
17734 glyphs like in 20.x. */
17735 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
17736 < row
->glyphs
[1 + TEXT_AREA
])
17737 produce_special_glyphs (it
, IT_CONTINUATION
);
17739 row
->continued_p
= 1;
17740 it
->current_x
= x_before
;
17741 it
->continuation_lines_width
+= x_before
;
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
;
17750 else if (wrap_row_used
> 0)
17753 if (row
->reversed_p
)
17754 unproduce_glyphs (it
,
17755 row
->used
[TEXT_AREA
] - wrap_row_used
);
17757 it
->continuation_lines_width
+= wrap_x
;
17758 row
->used
[TEXT_AREA
] = wrap_row_used
;
17759 row
->ascent
= wrap_row_ascent
;
17760 row
->height
= wrap_row_height
;
17761 row
->phys_ascent
= wrap_row_phys_ascent
;
17762 row
->phys_height
= wrap_row_phys_height
;
17763 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
17764 min_pos
= wrap_row_min_pos
;
17765 min_bpos
= wrap_row_min_bpos
;
17766 max_pos
= wrap_row_max_pos
;
17767 max_bpos
= wrap_row_max_bpos
;
17768 row
->continued_p
= 1;
17769 row
->ends_at_zv_p
= 0;
17770 row
->exact_window_width_line_p
= 0;
17771 it
->continuation_lines_width
+= x
;
17773 /* Make sure that a non-default face is extended
17774 up to the right margin of the window. */
17775 extend_face_to_end_of_line (it
);
17777 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
17779 /* A TAB that extends past the right edge of the
17780 window. This produces a single glyph on
17781 window system frames. We leave the glyph in
17782 this row and let it fill the row, but don't
17783 consume the TAB. */
17784 it
->continuation_lines_width
+= it
->last_visible_x
;
17785 row
->ends_in_middle_of_char_p
= 1;
17786 row
->continued_p
= 1;
17787 glyph
->pixel_width
= it
->last_visible_x
- x
;
17788 it
->starts_in_middle_of_char_p
= 1;
17792 /* Something other than a TAB that draws past
17793 the right edge of the window. Restore
17794 positions to values before the element. */
17795 if (row
->reversed_p
)
17796 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
17797 - (n_glyphs_before
+ i
));
17798 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17800 /* Display continuation glyphs. */
17801 if (!FRAME_WINDOW_P (it
->f
))
17802 produce_special_glyphs (it
, IT_CONTINUATION
);
17803 row
->continued_p
= 1;
17805 it
->current_x
= x_before
;
17806 it
->continuation_lines_width
+= x
;
17807 extend_face_to_end_of_line (it
);
17809 if (nglyphs
> 1 && i
> 0)
17811 row
->ends_in_middle_of_char_p
= 1;
17812 it
->starts_in_middle_of_char_p
= 1;
17815 /* Restore the height to what it was before the
17816 element not fitting on the line. */
17817 it
->max_ascent
= ascent
;
17818 it
->max_descent
= descent
;
17819 it
->max_phys_ascent
= phys_ascent
;
17820 it
->max_phys_descent
= phys_descent
;
17825 else if (new_x
> it
->first_visible_x
)
17827 /* Increment number of glyphs actually displayed. */
17830 /* Record the maximum and minimum buffer positions
17831 seen so far in glyphs that will be displayed by
17834 RECORD_MAX_MIN_POS (it
);
17836 if (x
< it
->first_visible_x
)
17837 /* Glyph is partially visible, i.e. row starts at
17838 negative X position. */
17839 row
->x
= x
- it
->first_visible_x
;
17843 /* Glyph is completely off the left margin of the
17844 window. This should not happen because of the
17845 move_it_in_display_line at the start of this
17846 function, unless the text display area of the
17847 window is empty. */
17848 xassert (it
->first_visible_x
<= it
->last_visible_x
);
17852 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17853 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17854 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17855 row
->phys_height
= max (row
->phys_height
,
17856 it
->max_phys_ascent
+ it
->max_phys_descent
);
17857 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17858 it
->max_extra_line_spacing
);
17860 /* End of this display line if row is continued. */
17861 if (row
->continued_p
|| row
->ends_at_zv_p
)
17866 /* Is this a line end? If yes, we're also done, after making
17867 sure that a non-default face is extended up to the right
17868 margin of the window. */
17869 if (ITERATOR_AT_END_OF_LINE_P (it
))
17871 int used_before
= row
->used
[TEXT_AREA
];
17873 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
17875 /* Add a space at the end of the line that is used to
17876 display the cursor there. */
17877 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17878 append_space_for_newline (it
, 0);
17880 /* Extend the face to the end of the line. */
17881 extend_face_to_end_of_line (it
);
17883 /* Make sure we have the position. */
17884 if (used_before
== 0)
17885 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
17887 /* Record the position of the newline, for use in
17889 it
->eol_pos
= it
->current
.pos
;
17891 /* Consume the line end. This skips over invisible lines. */
17892 set_iterator_to_next (it
, 1);
17893 it
->continuation_lines_width
= 0;
17897 /* Proceed with next display element. Note that this skips
17898 over lines invisible because of selective display. */
17899 set_iterator_to_next (it
, 1);
17901 /* If we truncate lines, we are done when the last displayed
17902 glyphs reach past the right margin of the window. */
17903 if (it
->line_wrap
== TRUNCATE
17904 && (FRAME_WINDOW_P (it
->f
)
17905 ? (it
->current_x
>= it
->last_visible_x
)
17906 : (it
->current_x
> it
->last_visible_x
)))
17908 /* Maybe add truncation glyphs. */
17909 if (!FRAME_WINDOW_P (it
->f
))
17913 if (!row
->reversed_p
)
17915 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17916 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17921 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
17922 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17924 /* Remove any padding glyphs at the front of ROW, to
17925 make room for the truncation glyphs we will be
17926 adding below. The loop below always inserts at
17927 least one truncation glyph, so also remove the
17928 last glyph added to ROW. */
17929 unproduce_glyphs (it
, i
+ 1);
17930 /* Adjust i for the loop below. */
17931 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
17934 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17936 row
->used
[TEXT_AREA
] = i
;
17937 produce_special_glyphs (it
, IT_TRUNCATION
);
17940 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17942 /* Don't truncate if we can overflow newline into fringe. */
17943 if (!get_next_display_element (it
))
17945 it
->continuation_lines_width
= 0;
17946 row
->ends_at_zv_p
= 1;
17947 row
->exact_window_width_line_p
= 1;
17950 if (ITERATOR_AT_END_OF_LINE_P (it
))
17952 row
->exact_window_width_line_p
= 1;
17953 goto at_end_of_line
;
17957 row
->truncated_on_right_p
= 1;
17958 it
->continuation_lines_width
= 0;
17959 reseat_at_next_visible_line_start (it
, 0);
17960 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
17961 it
->hpos
= hpos_before
;
17962 it
->current_x
= x_before
;
17967 /* If line is not empty and hscrolled, maybe insert truncation glyphs
17968 at the left window margin. */
17969 if (it
->first_visible_x
17970 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
17972 if (!FRAME_WINDOW_P (it
->f
))
17973 insert_left_trunc_glyphs (it
);
17974 row
->truncated_on_left_p
= 1;
17977 /* Remember the position at which this line ends.
17979 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
17980 cannot be before the call to find_row_edges below, since that is
17981 where these positions are determined. */
17982 row
->end
= it
->current
;
17985 row
->minpos
= row
->start
.pos
;
17986 row
->maxpos
= row
->end
.pos
;
17990 /* ROW->minpos and ROW->maxpos must be the smallest and
17991 `1 + the largest' buffer positions in ROW. But if ROW was
17992 bidi-reordered, these two positions can be anywhere in the
17993 row, so we must determine them now. */
17994 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
17997 /* If the start of this line is the overlay arrow-position, then
17998 mark this glyph row as the one containing the overlay arrow.
17999 This is clearly a mess with variable size fonts. It would be
18000 better to let it be displayed like cursors under X. */
18001 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
18002 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
18003 !NILP (overlay_arrow_string
)))
18005 /* Overlay arrow in window redisplay is a fringe bitmap. */
18006 if (STRINGP (overlay_arrow_string
))
18008 struct glyph_row
*arrow_row
18009 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
18010 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
18011 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
18012 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
18013 struct glyph
*p2
, *end
;
18015 /* Copy the arrow glyphs. */
18016 while (glyph
< arrow_end
)
18019 /* Throw away padding glyphs. */
18021 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
18022 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
18028 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
18033 xassert (INTEGERP (overlay_arrow_string
));
18034 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
18036 overlay_arrow_seen
= 1;
18039 /* Compute pixel dimensions of this line. */
18040 compute_line_metrics (it
);
18042 /* Record whether this row ends inside an ellipsis. */
18043 row
->ends_in_ellipsis_p
18044 = (it
->method
== GET_FROM_DISPLAY_VECTOR
18045 && it
->ellipsis_p
);
18047 /* Save fringe bitmaps in this row. */
18048 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
18049 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
18050 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
18051 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
18053 it
->left_user_fringe_bitmap
= 0;
18054 it
->left_user_fringe_face_id
= 0;
18055 it
->right_user_fringe_bitmap
= 0;
18056 it
->right_user_fringe_face_id
= 0;
18058 /* Maybe set the cursor. */
18059 cvpos
= it
->w
->cursor
.vpos
;
18061 /* In bidi-reordered rows, keep checking for proper cursor
18062 position even if one has been found already, because buffer
18063 positions in such rows change non-linearly with ROW->VPOS,
18064 when a line is continued. One exception: when we are at ZV,
18065 display cursor on the first suitable glyph row, since all
18066 the empty rows after that also have their position set to ZV. */
18067 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18068 lines' rows is implemented for bidi-reordered rows. */
18070 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
18071 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
18072 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
18073 && cursor_row_p (row
))
18074 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
18076 /* Highlight trailing whitespace. */
18077 if (!NILP (Vshow_trailing_whitespace
))
18078 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
18080 /* Prepare for the next line. This line starts horizontally at (X
18081 HPOS) = (0 0). Vertical positions are incremented. As a
18082 convenience for the caller, IT->glyph_row is set to the next
18084 it
->current_x
= it
->hpos
= 0;
18085 it
->current_y
+= row
->height
;
18086 SET_TEXT_POS (it
->eol_pos
, 0, 0);
18089 /* The next row should by default use the same value of the
18090 reversed_p flag as this one. set_iterator_to_next decides when
18091 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
18092 the flag accordingly. */
18093 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
18094 it
->glyph_row
->reversed_p
= row
->reversed_p
;
18095 it
->start
= row
->end
;
18096 return row
->displays_text_p
;
18098 #undef RECORD_MAX_MIN_POS
18101 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
18102 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
18103 doc
: /* Return paragraph direction at point in BUFFER.
18104 Value is either `left-to-right' or `right-to-left'.
18105 If BUFFER is omitted or nil, it defaults to the current buffer.
18107 Paragraph direction determines how the text in the paragraph is displayed.
18108 In left-to-right paragraphs, text begins at the left margin of the window
18109 and the reading direction is generally left to right. In right-to-left
18110 paragraphs, text begins at the right margin and is read from right to left.
18112 See also `bidi-paragraph-direction'. */)
18113 (Lisp_Object buffer
)
18115 struct buffer
*buf
= current_buffer
;
18116 struct buffer
*old
= buf
;
18118 if (! NILP (buffer
))
18120 CHECK_BUFFER (buffer
);
18121 buf
= XBUFFER (buffer
);
18124 if (NILP (BVAR (buf
, bidi_display_reordering
)))
18125 return Qleft_to_right
;
18126 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
18127 return BVAR (buf
, bidi_paragraph_direction
);
18130 /* Determine the direction from buffer text. We could try to
18131 use current_matrix if it is up to date, but this seems fast
18132 enough as it is. */
18133 struct bidi_it itb
;
18134 EMACS_INT pos
= BUF_PT (buf
);
18135 EMACS_INT bytepos
= BUF_PT_BYTE (buf
);
18138 set_buffer_temp (buf
);
18139 /* bidi_paragraph_init finds the base direction of the paragraph
18140 by searching forward from paragraph start. We need the base
18141 direction of the current or _previous_ paragraph, so we need
18142 to make sure we are within that paragraph. To that end, find
18143 the previous non-empty line. */
18144 if (pos
>= ZV
&& pos
> BEGV
)
18147 bytepos
= CHAR_TO_BYTE (pos
);
18149 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
18150 || c
== ' ' || c
== '\t' || c
== '\f')
18152 if (bytepos
<= BEGV_BYTE
)
18157 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
18160 itb
.bytepos
= bytepos
;
18162 itb
.frame_window_p
= FRAME_WINDOW_P (SELECTED_FRAME ()); /* guesswork */
18164 itb
.separator_limit
= -1;
18165 itb
.paragraph_dir
= NEUTRAL_DIR
;
18167 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
18168 set_buffer_temp (old
);
18169 switch (itb
.paragraph_dir
)
18172 return Qleft_to_right
;
18175 return Qright_to_left
;
18185 /***********************************************************************
18187 ***********************************************************************/
18189 /* Redisplay the menu bar in the frame for window W.
18191 The menu bar of X frames that don't have X toolkit support is
18192 displayed in a special window W->frame->menu_bar_window.
18194 The menu bar of terminal frames is treated specially as far as
18195 glyph matrices are concerned. Menu bar lines are not part of
18196 windows, so the update is done directly on the frame matrix rows
18197 for the menu bar. */
18200 display_menu_bar (struct window
*w
)
18202 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18207 /* Don't do all this for graphical frames. */
18209 if (FRAME_W32_P (f
))
18212 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
18218 if (FRAME_NS_P (f
))
18220 #endif /* HAVE_NS */
18222 #ifdef USE_X_TOOLKIT
18223 xassert (!FRAME_WINDOW_P (f
));
18224 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
18225 it
.first_visible_x
= 0;
18226 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18227 #else /* not USE_X_TOOLKIT */
18228 if (FRAME_WINDOW_P (f
))
18230 /* Menu bar lines are displayed in the desired matrix of the
18231 dummy window menu_bar_window. */
18232 struct window
*menu_w
;
18233 xassert (WINDOWP (f
->menu_bar_window
));
18234 menu_w
= XWINDOW (f
->menu_bar_window
);
18235 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
18237 it
.first_visible_x
= 0;
18238 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18242 /* This is a TTY frame, i.e. character hpos/vpos are used as
18244 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
18246 it
.first_visible_x
= 0;
18247 it
.last_visible_x
= FRAME_COLS (f
);
18249 #endif /* not USE_X_TOOLKIT */
18251 if (! mode_line_inverse_video
)
18252 /* Force the menu-bar to be displayed in the default face. */
18253 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18255 /* Clear all rows of the menu bar. */
18256 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
18258 struct glyph_row
*row
= it
.glyph_row
+ i
;
18259 clear_glyph_row (row
);
18260 row
->enabled_p
= 1;
18261 row
->full_width_p
= 1;
18264 /* Display all items of the menu bar. */
18265 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
18266 for (i
= 0; i
< ASIZE (items
); i
+= 4)
18268 Lisp_Object string
;
18270 /* Stop at nil string. */
18271 string
= AREF (items
, i
+ 1);
18275 /* Remember where item was displayed. */
18276 ASET (items
, i
+ 3, make_number (it
.hpos
));
18278 /* Display the item, pad with one space. */
18279 if (it
.current_x
< it
.last_visible_x
)
18280 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
18281 SCHARS (string
) + 1, 0, 0, -1);
18284 /* Fill out the line with spaces. */
18285 if (it
.current_x
< it
.last_visible_x
)
18286 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
18288 /* Compute the total height of the lines. */
18289 compute_line_metrics (&it
);
18294 /***********************************************************************
18296 ***********************************************************************/
18298 /* Redisplay mode lines in the window tree whose root is WINDOW. If
18299 FORCE is non-zero, redisplay mode lines unconditionally.
18300 Otherwise, redisplay only mode lines that are garbaged. Value is
18301 the number of windows whose mode lines were redisplayed. */
18304 redisplay_mode_lines (Lisp_Object window
, int force
)
18308 while (!NILP (window
))
18310 struct window
*w
= XWINDOW (window
);
18312 if (WINDOWP (w
->hchild
))
18313 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
18314 else if (WINDOWP (w
->vchild
))
18315 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18317 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18318 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18320 struct text_pos lpoint
;
18321 struct buffer
*old
= current_buffer
;
18323 /* Set the window's buffer for the mode line display. */
18324 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18325 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18327 /* Point refers normally to the selected window. For any
18328 other window, set up appropriate value. */
18329 if (!EQ (window
, selected_window
))
18331 struct text_pos pt
;
18333 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18334 if (CHARPOS (pt
) < BEGV
)
18335 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18336 else if (CHARPOS (pt
) > (ZV
- 1))
18337 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18339 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18342 /* Display mode lines. */
18343 clear_glyph_matrix (w
->desired_matrix
);
18344 if (display_mode_lines (w
))
18347 w
->must_be_updated_p
= 1;
18350 /* Restore old settings. */
18351 set_buffer_internal_1 (old
);
18352 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18362 /* Display the mode and/or header line of window W. Value is the
18363 sum number of mode lines and header lines displayed. */
18366 display_mode_lines (struct window
*w
)
18368 Lisp_Object old_selected_window
, old_selected_frame
;
18371 old_selected_frame
= selected_frame
;
18372 selected_frame
= w
->frame
;
18373 old_selected_window
= selected_window
;
18374 XSETWINDOW (selected_window
, w
);
18376 /* These will be set while the mode line specs are processed. */
18377 line_number_displayed
= 0;
18378 w
->column_number_displayed
= Qnil
;
18380 if (WINDOW_WANTS_MODELINE_P (w
))
18382 struct window
*sel_w
= XWINDOW (old_selected_window
);
18384 /* Select mode line face based on the real selected window. */
18385 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18386 BVAR (current_buffer
, mode_line_format
));
18390 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18392 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18393 BVAR (current_buffer
, header_line_format
));
18397 selected_frame
= old_selected_frame
;
18398 selected_window
= old_selected_window
;
18403 /* Display mode or header line of window W. FACE_ID specifies which
18404 line to display; it is either MODE_LINE_FACE_ID or
18405 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18406 display. Value is the pixel height of the mode/header line
18410 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
18414 int count
= SPECPDL_INDEX ();
18416 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18417 /* Don't extend on a previously drawn mode-line.
18418 This may happen if called from pos_visible_p. */
18419 it
.glyph_row
->enabled_p
= 0;
18420 prepare_desired_row (it
.glyph_row
);
18422 it
.glyph_row
->mode_line_p
= 1;
18424 if (! mode_line_inverse_video
)
18425 /* Force the mode-line to be displayed in the default face. */
18426 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18428 record_unwind_protect (unwind_format_mode_line
,
18429 format_mode_line_unwind_data (NULL
, Qnil
, 0));
18431 mode_line_target
= MODE_LINE_DISPLAY
;
18433 /* Temporarily make frame's keyboard the current kboard so that
18434 kboard-local variables in the mode_line_format will get the right
18436 push_kboard (FRAME_KBOARD (it
.f
));
18437 record_unwind_save_match_data ();
18438 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18441 unbind_to (count
, Qnil
);
18443 /* Fill up with spaces. */
18444 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
18446 compute_line_metrics (&it
);
18447 it
.glyph_row
->full_width_p
= 1;
18448 it
.glyph_row
->continued_p
= 0;
18449 it
.glyph_row
->truncated_on_left_p
= 0;
18450 it
.glyph_row
->truncated_on_right_p
= 0;
18452 /* Make a 3D mode-line have a shadow at its right end. */
18453 face
= FACE_FROM_ID (it
.f
, face_id
);
18454 extend_face_to_end_of_line (&it
);
18455 if (face
->box
!= FACE_NO_BOX
)
18457 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
18458 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
18459 last
->right_box_line_p
= 1;
18462 return it
.glyph_row
->height
;
18465 /* Move element ELT in LIST to the front of LIST.
18466 Return the updated list. */
18469 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
18471 register Lisp_Object tail
, prev
;
18472 register Lisp_Object tem
;
18476 while (CONSP (tail
))
18482 /* Splice out the link TAIL. */
18484 list
= XCDR (tail
);
18486 Fsetcdr (prev
, XCDR (tail
));
18488 /* Now make it the first. */
18489 Fsetcdr (tail
, list
);
18494 tail
= XCDR (tail
);
18498 /* Not found--return unchanged LIST. */
18502 /* Contribute ELT to the mode line for window IT->w. How it
18503 translates into text depends on its data type.
18505 IT describes the display environment in which we display, as usual.
18507 DEPTH is the depth in recursion. It is used to prevent
18508 infinite recursion here.
18510 FIELD_WIDTH is the number of characters the display of ELT should
18511 occupy in the mode line, and PRECISION is the maximum number of
18512 characters to display from ELT's representation. See
18513 display_string for details.
18515 Returns the hpos of the end of the text generated by ELT.
18517 PROPS is a property list to add to any string we encounter.
18519 If RISKY is nonzero, remove (disregard) any properties in any string
18520 we encounter, and ignore :eval and :propertize.
18522 The global variable `mode_line_target' determines whether the
18523 output is passed to `store_mode_line_noprop',
18524 `store_mode_line_string', or `display_string'. */
18527 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
18528 Lisp_Object elt
, Lisp_Object props
, int risky
)
18530 int n
= 0, field
, prec
;
18535 elt
= build_string ("*too-deep*");
18539 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
18543 /* A string: output it and check for %-constructs within it. */
18545 EMACS_INT offset
= 0;
18547 if (SCHARS (elt
) > 0
18548 && (!NILP (props
) || risky
))
18550 Lisp_Object oprops
, aelt
;
18551 oprops
= Ftext_properties_at (make_number (0), elt
);
18553 /* If the starting string's properties are not what
18554 we want, translate the string. Also, if the string
18555 is risky, do that anyway. */
18557 if (NILP (Fequal (props
, oprops
)) || risky
)
18559 /* If the starting string has properties,
18560 merge the specified ones onto the existing ones. */
18561 if (! NILP (oprops
) && !risky
)
18565 oprops
= Fcopy_sequence (oprops
);
18567 while (CONSP (tem
))
18569 oprops
= Fplist_put (oprops
, XCAR (tem
),
18570 XCAR (XCDR (tem
)));
18571 tem
= XCDR (XCDR (tem
));
18576 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
18577 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
18579 /* AELT is what we want. Move it to the front
18580 without consing. */
18582 mode_line_proptrans_alist
18583 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
18589 /* If AELT has the wrong props, it is useless.
18590 so get rid of it. */
18592 mode_line_proptrans_alist
18593 = Fdelq (aelt
, mode_line_proptrans_alist
);
18595 elt
= Fcopy_sequence (elt
);
18596 Fset_text_properties (make_number (0), Flength (elt
),
18598 /* Add this item to mode_line_proptrans_alist. */
18599 mode_line_proptrans_alist
18600 = Fcons (Fcons (elt
, props
),
18601 mode_line_proptrans_alist
);
18602 /* Truncate mode_line_proptrans_alist
18603 to at most 50 elements. */
18604 tem
= Fnthcdr (make_number (50),
18605 mode_line_proptrans_alist
);
18607 XSETCDR (tem
, Qnil
);
18616 prec
= precision
- n
;
18617 switch (mode_line_target
)
18619 case MODE_LINE_NOPROP
:
18620 case MODE_LINE_TITLE
:
18621 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
18623 case MODE_LINE_STRING
:
18624 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
18626 case MODE_LINE_DISPLAY
:
18627 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
18628 0, prec
, 0, STRING_MULTIBYTE (elt
));
18635 /* Handle the non-literal case. */
18637 while ((precision
<= 0 || n
< precision
)
18638 && SREF (elt
, offset
) != 0
18639 && (mode_line_target
!= MODE_LINE_DISPLAY
18640 || it
->current_x
< it
->last_visible_x
))
18642 EMACS_INT last_offset
= offset
;
18644 /* Advance to end of string or next format specifier. */
18645 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
18648 if (offset
- 1 != last_offset
)
18650 EMACS_INT nchars
, nbytes
;
18652 /* Output to end of string or up to '%'. Field width
18653 is length of string. Don't output more than
18654 PRECISION allows us. */
18657 prec
= c_string_width (SDATA (elt
) + last_offset
,
18658 offset
- last_offset
, precision
- n
,
18661 switch (mode_line_target
)
18663 case MODE_LINE_NOPROP
:
18664 case MODE_LINE_TITLE
:
18665 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
18667 case MODE_LINE_STRING
:
18669 EMACS_INT bytepos
= last_offset
;
18670 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
18671 EMACS_INT endpos
= (precision
<= 0
18672 ? string_byte_to_char (elt
, offset
)
18673 : charpos
+ nchars
);
18675 n
+= store_mode_line_string (NULL
,
18676 Fsubstring (elt
, make_number (charpos
),
18677 make_number (endpos
)),
18681 case MODE_LINE_DISPLAY
:
18683 EMACS_INT bytepos
= last_offset
;
18684 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
18686 if (precision
<= 0)
18687 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
18688 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
18690 STRING_MULTIBYTE (elt
));
18695 else /* c == '%' */
18697 EMACS_INT percent_position
= offset
;
18699 /* Get the specified minimum width. Zero means
18702 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
18703 field
= field
* 10 + c
- '0';
18705 /* Don't pad beyond the total padding allowed. */
18706 if (field_width
- n
> 0 && field
> field_width
- n
)
18707 field
= field_width
- n
;
18709 /* Note that either PRECISION <= 0 or N < PRECISION. */
18710 prec
= precision
- n
;
18713 n
+= display_mode_element (it
, depth
, field
, prec
,
18714 Vglobal_mode_string
, props
,
18719 EMACS_INT bytepos
, charpos
;
18721 Lisp_Object string
;
18723 bytepos
= percent_position
;
18724 charpos
= (STRING_MULTIBYTE (elt
)
18725 ? string_byte_to_char (elt
, bytepos
)
18727 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
18728 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
18730 switch (mode_line_target
)
18732 case MODE_LINE_NOPROP
:
18733 case MODE_LINE_TITLE
:
18734 n
+= store_mode_line_noprop (spec
, field
, prec
);
18736 case MODE_LINE_STRING
:
18738 Lisp_Object tem
= build_string (spec
);
18739 props
= Ftext_properties_at (make_number (charpos
), elt
);
18740 /* Should only keep face property in props */
18741 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
18744 case MODE_LINE_DISPLAY
:
18746 int nglyphs_before
, nwritten
;
18748 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18749 nwritten
= display_string (spec
, string
, elt
,
18754 /* Assign to the glyphs written above the
18755 string where the `%x' came from, position
18759 struct glyph
*glyph
18760 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
18764 for (i
= 0; i
< nwritten
; ++i
)
18766 glyph
[i
].object
= elt
;
18767 glyph
[i
].charpos
= charpos
;
18784 /* A symbol: process the value of the symbol recursively
18785 as if it appeared here directly. Avoid error if symbol void.
18786 Special case: if value of symbol is a string, output the string
18789 register Lisp_Object tem
;
18791 /* If the variable is not marked as risky to set
18792 then its contents are risky to use. */
18793 if (NILP (Fget (elt
, Qrisky_local_variable
)))
18796 tem
= Fboundp (elt
);
18799 tem
= Fsymbol_value (elt
);
18800 /* If value is a string, output that string literally:
18801 don't check for % within it. */
18805 if (!EQ (tem
, elt
))
18807 /* Give up right away for nil or t. */
18817 register Lisp_Object car
, tem
;
18819 /* A cons cell: five distinct cases.
18820 If first element is :eval or :propertize, do something special.
18821 If first element is a string or a cons, process all the elements
18822 and effectively concatenate them.
18823 If first element is a negative number, truncate displaying cdr to
18824 at most that many characters. If positive, pad (with spaces)
18825 to at least that many characters.
18826 If first element is a symbol, process the cadr or caddr recursively
18827 according to whether the symbol's value is non-nil or nil. */
18829 if (EQ (car
, QCeval
))
18831 /* An element of the form (:eval FORM) means evaluate FORM
18832 and use the result as mode line elements. */
18837 if (CONSP (XCDR (elt
)))
18840 spec
= safe_eval (XCAR (XCDR (elt
)));
18841 n
+= display_mode_element (it
, depth
, field_width
- n
,
18842 precision
- n
, spec
, props
,
18846 else if (EQ (car
, QCpropertize
))
18848 /* An element of the form (:propertize ELT PROPS...)
18849 means display ELT but applying properties PROPS. */
18854 if (CONSP (XCDR (elt
)))
18855 n
+= display_mode_element (it
, depth
, field_width
- n
,
18856 precision
- n
, XCAR (XCDR (elt
)),
18857 XCDR (XCDR (elt
)), risky
);
18859 else if (SYMBOLP (car
))
18861 tem
= Fboundp (car
);
18865 /* elt is now the cdr, and we know it is a cons cell.
18866 Use its car if CAR has a non-nil value. */
18869 tem
= Fsymbol_value (car
);
18876 /* Symbol's value is nil (or symbol is unbound)
18877 Get the cddr of the original list
18878 and if possible find the caddr and use that. */
18882 else if (!CONSP (elt
))
18887 else if (INTEGERP (car
))
18889 register int lim
= XINT (car
);
18893 /* Negative int means reduce maximum width. */
18894 if (precision
<= 0)
18897 precision
= min (precision
, -lim
);
18901 /* Padding specified. Don't let it be more than
18902 current maximum. */
18904 lim
= min (precision
, lim
);
18906 /* If that's more padding than already wanted, queue it.
18907 But don't reduce padding already specified even if
18908 that is beyond the current truncation point. */
18909 field_width
= max (lim
, field_width
);
18913 else if (STRINGP (car
) || CONSP (car
))
18915 Lisp_Object halftail
= elt
;
18919 && (precision
<= 0 || n
< precision
))
18921 n
+= display_mode_element (it
, depth
,
18922 /* Do padding only after the last
18923 element in the list. */
18924 (! CONSP (XCDR (elt
))
18927 precision
- n
, XCAR (elt
),
18931 if ((len
& 1) == 0)
18932 halftail
= XCDR (halftail
);
18933 /* Check for cycle. */
18934 if (EQ (halftail
, elt
))
18943 elt
= build_string ("*invalid*");
18947 /* Pad to FIELD_WIDTH. */
18948 if (field_width
> 0 && n
< field_width
)
18950 switch (mode_line_target
)
18952 case MODE_LINE_NOPROP
:
18953 case MODE_LINE_TITLE
:
18954 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
18956 case MODE_LINE_STRING
:
18957 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
18959 case MODE_LINE_DISPLAY
:
18960 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
18969 /* Store a mode-line string element in mode_line_string_list.
18971 If STRING is non-null, display that C string. Otherwise, the Lisp
18972 string LISP_STRING is displayed.
18974 FIELD_WIDTH is the minimum number of output glyphs to produce.
18975 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18976 with spaces. FIELD_WIDTH <= 0 means don't pad.
18978 PRECISION is the maximum number of characters to output from
18979 STRING. PRECISION <= 0 means don't truncate the string.
18981 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
18982 properties to the string.
18984 PROPS are the properties to add to the string.
18985 The mode_line_string_face face property is always added to the string.
18989 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
18990 int field_width
, int precision
, Lisp_Object props
)
18995 if (string
!= NULL
)
18997 len
= strlen (string
);
18998 if (precision
> 0 && len
> precision
)
19000 lisp_string
= make_string (string
, len
);
19002 props
= mode_line_string_face_prop
;
19003 else if (!NILP (mode_line_string_face
))
19005 Lisp_Object face
= Fplist_get (props
, Qface
);
19006 props
= Fcopy_sequence (props
);
19008 face
= mode_line_string_face
;
19010 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19011 props
= Fplist_put (props
, Qface
, face
);
19013 Fadd_text_properties (make_number (0), make_number (len
),
19014 props
, lisp_string
);
19018 len
= XFASTINT (Flength (lisp_string
));
19019 if (precision
> 0 && len
> precision
)
19022 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
19025 if (!NILP (mode_line_string_face
))
19029 props
= Ftext_properties_at (make_number (0), lisp_string
);
19030 face
= Fplist_get (props
, Qface
);
19032 face
= mode_line_string_face
;
19034 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19035 props
= Fcons (Qface
, Fcons (face
, Qnil
));
19037 lisp_string
= Fcopy_sequence (lisp_string
);
19040 Fadd_text_properties (make_number (0), make_number (len
),
19041 props
, lisp_string
);
19046 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19050 if (field_width
> len
)
19052 field_width
-= len
;
19053 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
19055 Fadd_text_properties (make_number (0), make_number (field_width
),
19056 props
, lisp_string
);
19057 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19065 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
19067 doc
: /* Format a string out of a mode line format specification.
19068 First arg FORMAT specifies the mode line format (see `mode-line-format'
19069 for details) to use.
19071 By default, the format is evaluated for the currently selected window.
19073 Optional second arg FACE specifies the face property to put on all
19074 characters for which no face is specified. The value nil means the
19075 default face. The value t means whatever face the window's mode line
19076 currently uses (either `mode-line' or `mode-line-inactive',
19077 depending on whether the window is the selected window or not).
19078 An integer value means the value string has no text
19081 Optional third and fourth args WINDOW and BUFFER specify the window
19082 and buffer to use as the context for the formatting (defaults
19083 are the selected window and the WINDOW's buffer). */)
19084 (Lisp_Object format
, Lisp_Object face
,
19085 Lisp_Object window
, Lisp_Object buffer
)
19090 struct buffer
*old_buffer
= NULL
;
19092 int no_props
= INTEGERP (face
);
19093 int count
= SPECPDL_INDEX ();
19095 int string_start
= 0;
19098 window
= selected_window
;
19099 CHECK_WINDOW (window
);
19100 w
= XWINDOW (window
);
19103 buffer
= w
->buffer
;
19104 CHECK_BUFFER (buffer
);
19106 /* Make formatting the modeline a non-op when noninteractive, otherwise
19107 there will be problems later caused by a partially initialized frame. */
19108 if (NILP (format
) || noninteractive
)
19109 return empty_unibyte_string
;
19114 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
19115 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
19116 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
19117 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
19118 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
19119 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
19120 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
19123 if (XBUFFER (buffer
) != current_buffer
)
19124 old_buffer
= current_buffer
;
19126 /* Save things including mode_line_proptrans_alist,
19127 and set that to nil so that we don't alter the outer value. */
19128 record_unwind_protect (unwind_format_mode_line
,
19129 format_mode_line_unwind_data
19130 (old_buffer
, selected_window
, 1));
19131 mode_line_proptrans_alist
= Qnil
;
19133 Fselect_window (window
, Qt
);
19135 set_buffer_internal_1 (XBUFFER (buffer
));
19137 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19141 mode_line_target
= MODE_LINE_NOPROP
;
19142 mode_line_string_face_prop
= Qnil
;
19143 mode_line_string_list
= Qnil
;
19144 string_start
= MODE_LINE_NOPROP_LEN (0);
19148 mode_line_target
= MODE_LINE_STRING
;
19149 mode_line_string_list
= Qnil
;
19150 mode_line_string_face
= face
;
19151 mode_line_string_face_prop
19152 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
19155 push_kboard (FRAME_KBOARD (it
.f
));
19156 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19161 len
= MODE_LINE_NOPROP_LEN (string_start
);
19162 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
19166 mode_line_string_list
= Fnreverse (mode_line_string_list
);
19167 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
19168 empty_unibyte_string
);
19171 unbind_to (count
, Qnil
);
19175 /* Write a null-terminated, right justified decimal representation of
19176 the positive integer D to BUF using a minimal field width WIDTH. */
19179 pint2str (register char *buf
, register int width
, register EMACS_INT d
)
19181 register char *p
= buf
;
19189 *p
++ = d
% 10 + '0';
19194 for (width
-= (int) (p
- buf
); width
> 0; --width
)
19205 /* Write a null-terminated, right justified decimal and "human
19206 readable" representation of the nonnegative integer D to BUF using
19207 a minimal field width WIDTH. D should be smaller than 999.5e24. */
19209 static const char power_letter
[] =
19223 pint2hrstr (char *buf
, int width
, EMACS_INT d
)
19225 /* We aim to represent the nonnegative integer D as
19226 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
19227 EMACS_INT quotient
= d
;
19229 /* -1 means: do not use TENTHS. */
19233 /* Length of QUOTIENT.TENTHS as a string. */
19239 if (1000 <= quotient
)
19241 /* Scale to the appropriate EXPONENT. */
19244 remainder
= quotient
% 1000;
19248 while (1000 <= quotient
);
19250 /* Round to nearest and decide whether to use TENTHS or not. */
19253 tenths
= remainder
/ 100;
19254 if (50 <= remainder
% 100)
19261 if (quotient
== 10)
19269 if (500 <= remainder
)
19271 if (quotient
< 999)
19282 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
19283 if (tenths
== -1 && quotient
<= 99)
19290 p
= psuffix
= buf
+ max (width
, length
);
19292 /* Print EXPONENT. */
19293 *psuffix
++ = power_letter
[exponent
];
19296 /* Print TENTHS. */
19299 *--p
= '0' + tenths
;
19303 /* Print QUOTIENT. */
19306 int digit
= quotient
% 10;
19307 *--p
= '0' + digit
;
19309 while ((quotient
/= 10) != 0);
19311 /* Print leading spaces. */
19316 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19317 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19318 type of CODING_SYSTEM. Return updated pointer into BUF. */
19320 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19323 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
19326 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
19327 const unsigned char *eol_str
;
19329 /* The EOL conversion we are using. */
19330 Lisp_Object eoltype
;
19332 val
= CODING_SYSTEM_SPEC (coding_system
);
19335 if (!VECTORP (val
)) /* Not yet decided. */
19340 eoltype
= eol_mnemonic_undecided
;
19341 /* Don't mention EOL conversion if it isn't decided. */
19346 Lisp_Object eolvalue
;
19348 attrs
= AREF (val
, 0);
19349 eolvalue
= AREF (val
, 2);
19352 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19356 /* The EOL conversion that is normal on this system. */
19358 if (NILP (eolvalue
)) /* Not yet decided. */
19359 eoltype
= eol_mnemonic_undecided
;
19360 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19361 eoltype
= eol_mnemonic_undecided
;
19362 else /* eolvalue is Qunix, Qdos, or Qmac. */
19363 eoltype
= (EQ (eolvalue
, Qunix
)
19364 ? eol_mnemonic_unix
19365 : (EQ (eolvalue
, Qdos
) == 1
19366 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19372 /* Mention the EOL conversion if it is not the usual one. */
19373 if (STRINGP (eoltype
))
19375 eol_str
= SDATA (eoltype
);
19376 eol_str_len
= SBYTES (eoltype
);
19378 else if (CHARACTERP (eoltype
))
19380 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19381 int c
= XFASTINT (eoltype
);
19382 eol_str_len
= CHAR_STRING (c
, tmp
);
19387 eol_str
= invalid_eol_type
;
19388 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19390 memcpy (buf
, eol_str
, eol_str_len
);
19391 buf
+= eol_str_len
;
19397 /* Return a string for the output of a mode line %-spec for window W,
19398 generated by character C. FIELD_WIDTH > 0 means pad the string
19399 returned with spaces to that value. Return a Lisp string in
19400 *STRING if the resulting string is taken from that Lisp string.
19402 Note we operate on the current buffer for most purposes,
19403 the exception being w->base_line_pos. */
19405 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19407 static const char *
19408 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
19409 Lisp_Object
*string
)
19412 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19413 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19414 struct buffer
*b
= current_buffer
;
19422 if (!NILP (BVAR (b
, read_only
)))
19424 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19429 /* This differs from %* only for a modified read-only buffer. */
19430 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19432 if (!NILP (BVAR (b
, read_only
)))
19437 /* This differs from %* in ignoring read-only-ness. */
19438 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19450 if (command_loop_level
> 5)
19452 p
= decode_mode_spec_buf
;
19453 for (i
= 0; i
< command_loop_level
; i
++)
19456 return decode_mode_spec_buf
;
19464 if (command_loop_level
> 5)
19466 p
= decode_mode_spec_buf
;
19467 for (i
= 0; i
< command_loop_level
; i
++)
19470 return decode_mode_spec_buf
;
19477 /* Let lots_of_dashes be a string of infinite length. */
19478 if (mode_line_target
== MODE_LINE_NOPROP
||
19479 mode_line_target
== MODE_LINE_STRING
)
19481 if (field_width
<= 0
19482 || field_width
> sizeof (lots_of_dashes
))
19484 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
19485 decode_mode_spec_buf
[i
] = '-';
19486 decode_mode_spec_buf
[i
] = '\0';
19487 return decode_mode_spec_buf
;
19490 return lots_of_dashes
;
19494 obj
= BVAR (b
, name
);
19498 /* %c and %l are ignored in `frame-title-format'.
19499 (In redisplay_internal, the frame title is drawn _before_ the
19500 windows are updated, so the stuff which depends on actual
19501 window contents (such as %l) may fail to render properly, or
19502 even crash emacs.) */
19503 if (mode_line_target
== MODE_LINE_TITLE
)
19507 EMACS_INT col
= current_column ();
19508 w
->column_number_displayed
= make_number (col
);
19509 pint2str (decode_mode_spec_buf
, field_width
, col
);
19510 return decode_mode_spec_buf
;
19514 #ifndef SYSTEM_MALLOC
19516 if (NILP (Vmemory_full
))
19519 return "!MEM FULL! ";
19526 /* %F displays the frame name. */
19527 if (!NILP (f
->title
))
19528 return SSDATA (f
->title
);
19529 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
19530 return SSDATA (f
->name
);
19534 obj
= BVAR (b
, filename
);
19539 EMACS_INT size
= ZV
- BEGV
;
19540 pint2str (decode_mode_spec_buf
, field_width
, size
);
19541 return decode_mode_spec_buf
;
19546 EMACS_INT size
= ZV
- BEGV
;
19547 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
19548 return decode_mode_spec_buf
;
19553 EMACS_INT startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
19554 EMACS_INT topline
, nlines
, height
;
19557 /* %c and %l are ignored in `frame-title-format'. */
19558 if (mode_line_target
== MODE_LINE_TITLE
)
19561 startpos
= XMARKER (w
->start
)->charpos
;
19562 startpos_byte
= marker_byte_position (w
->start
);
19563 height
= WINDOW_TOTAL_LINES (w
);
19565 /* If we decided that this buffer isn't suitable for line numbers,
19566 don't forget that too fast. */
19567 if (EQ (w
->base_line_pos
, w
->buffer
))
19569 /* But do forget it, if the window shows a different buffer now. */
19570 else if (BUFFERP (w
->base_line_pos
))
19571 w
->base_line_pos
= Qnil
;
19573 /* If the buffer is very big, don't waste time. */
19574 if (INTEGERP (Vline_number_display_limit
)
19575 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
19577 w
->base_line_pos
= Qnil
;
19578 w
->base_line_number
= Qnil
;
19582 if (INTEGERP (w
->base_line_number
)
19583 && INTEGERP (w
->base_line_pos
)
19584 && XFASTINT (w
->base_line_pos
) <= startpos
)
19586 line
= XFASTINT (w
->base_line_number
);
19587 linepos
= XFASTINT (w
->base_line_pos
);
19588 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
19593 linepos
= BUF_BEGV (b
);
19594 linepos_byte
= BUF_BEGV_BYTE (b
);
19597 /* Count lines from base line to window start position. */
19598 nlines
= display_count_lines (linepos_byte
,
19602 topline
= nlines
+ line
;
19604 /* Determine a new base line, if the old one is too close
19605 or too far away, or if we did not have one.
19606 "Too close" means it's plausible a scroll-down would
19607 go back past it. */
19608 if (startpos
== BUF_BEGV (b
))
19610 w
->base_line_number
= make_number (topline
);
19611 w
->base_line_pos
= make_number (BUF_BEGV (b
));
19613 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
19614 || linepos
== BUF_BEGV (b
))
19616 EMACS_INT limit
= BUF_BEGV (b
);
19617 EMACS_INT limit_byte
= BUF_BEGV_BYTE (b
);
19618 EMACS_INT position
;
19619 EMACS_INT distance
=
19620 (height
* 2 + 30) * line_number_display_limit_width
;
19622 if (startpos
- distance
> limit
)
19624 limit
= startpos
- distance
;
19625 limit_byte
= CHAR_TO_BYTE (limit
);
19628 nlines
= display_count_lines (startpos_byte
,
19630 - (height
* 2 + 30),
19632 /* If we couldn't find the lines we wanted within
19633 line_number_display_limit_width chars per line,
19634 give up on line numbers for this window. */
19635 if (position
== limit_byte
&& limit
== startpos
- distance
)
19637 w
->base_line_pos
= w
->buffer
;
19638 w
->base_line_number
= Qnil
;
19642 w
->base_line_number
= make_number (topline
- nlines
);
19643 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
19646 /* Now count lines from the start pos to point. */
19647 nlines
= display_count_lines (startpos_byte
,
19648 PT_BYTE
, PT
, &junk
);
19650 /* Record that we did display the line number. */
19651 line_number_displayed
= 1;
19653 /* Make the string to show. */
19654 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
19655 return decode_mode_spec_buf
;
19658 char* p
= decode_mode_spec_buf
;
19659 int pad
= field_width
- 2;
19665 return decode_mode_spec_buf
;
19671 obj
= BVAR (b
, mode_name
);
19675 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
19681 EMACS_INT pos
= marker_position (w
->start
);
19682 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
19684 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
19686 if (pos
<= BUF_BEGV (b
))
19691 else if (pos
<= BUF_BEGV (b
))
19695 if (total
> 1000000)
19696 /* Do it differently for a large value, to avoid overflow. */
19697 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19699 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19700 /* We can't normally display a 3-digit number,
19701 so get us a 2-digit number that is close. */
19704 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
19705 return decode_mode_spec_buf
;
19709 /* Display percentage of size above the bottom of the screen. */
19712 EMACS_INT toppos
= marker_position (w
->start
);
19713 EMACS_INT botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
19714 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
19716 if (botpos
>= BUF_ZV (b
))
19718 if (toppos
<= BUF_BEGV (b
))
19725 if (total
> 1000000)
19726 /* Do it differently for a large value, to avoid overflow. */
19727 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19729 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19730 /* We can't normally display a 3-digit number,
19731 so get us a 2-digit number that is close. */
19734 if (toppos
<= BUF_BEGV (b
))
19735 sprintf (decode_mode_spec_buf
, "Top%2"pI
"d%%", total
);
19737 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
19738 return decode_mode_spec_buf
;
19743 /* status of process */
19744 obj
= Fget_buffer_process (Fcurrent_buffer ());
19746 return "no process";
19748 obj
= Fsymbol_name (Fprocess_status (obj
));
19754 int count
= inhibit_garbage_collection ();
19755 Lisp_Object val
= call1 (intern ("file-remote-p"),
19756 BVAR (current_buffer
, directory
));
19757 unbind_to (count
, Qnil
);
19765 case 't': /* indicate TEXT or BINARY */
19769 /* coding-system (not including end-of-line format) */
19771 /* coding-system (including end-of-line type) */
19773 int eol_flag
= (c
== 'Z');
19774 char *p
= decode_mode_spec_buf
;
19776 if (! FRAME_WINDOW_P (f
))
19778 /* No need to mention EOL here--the terminal never needs
19779 to do EOL conversion. */
19780 p
= decode_mode_spec_coding (CODING_ID_NAME
19781 (FRAME_KEYBOARD_CODING (f
)->id
),
19783 p
= decode_mode_spec_coding (CODING_ID_NAME
19784 (FRAME_TERMINAL_CODING (f
)->id
),
19787 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
19790 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
19791 #ifdef subprocesses
19792 obj
= Fget_buffer_process (Fcurrent_buffer ());
19793 if (PROCESSP (obj
))
19795 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
19797 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
19800 #endif /* subprocesses */
19803 return decode_mode_spec_buf
;
19810 return SSDATA (obj
);
19817 /* Count up to COUNT lines starting from START_BYTE.
19818 But don't go beyond LIMIT_BYTE.
19819 Return the number of lines thus found (always nonnegative).
19821 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
19824 display_count_lines (EMACS_INT start_byte
,
19825 EMACS_INT limit_byte
, EMACS_INT count
,
19826 EMACS_INT
*byte_pos_ptr
)
19828 register unsigned char *cursor
;
19829 unsigned char *base
;
19831 register EMACS_INT ceiling
;
19832 register unsigned char *ceiling_addr
;
19833 EMACS_INT orig_count
= count
;
19835 /* If we are not in selective display mode,
19836 check only for newlines. */
19837 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
19838 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
19842 while (start_byte
< limit_byte
)
19844 ceiling
= BUFFER_CEILING_OF (start_byte
);
19845 ceiling
= min (limit_byte
- 1, ceiling
);
19846 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
19847 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
19850 if (selective_display
)
19851 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
19854 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
19857 if (cursor
!= ceiling_addr
)
19861 start_byte
+= cursor
- base
+ 1;
19862 *byte_pos_ptr
= start_byte
;
19866 if (++cursor
== ceiling_addr
)
19872 start_byte
+= cursor
- base
;
19877 while (start_byte
> limit_byte
)
19879 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
19880 ceiling
= max (limit_byte
, ceiling
);
19881 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
19882 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
19885 if (selective_display
)
19886 while (--cursor
!= ceiling_addr
19887 && *cursor
!= '\n' && *cursor
!= 015)
19890 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
19893 if (cursor
!= ceiling_addr
)
19897 start_byte
+= cursor
- base
+ 1;
19898 *byte_pos_ptr
= start_byte
;
19899 /* When scanning backwards, we should
19900 not count the newline posterior to which we stop. */
19901 return - orig_count
- 1;
19907 /* Here we add 1 to compensate for the last decrement
19908 of CURSOR, which took it past the valid range. */
19909 start_byte
+= cursor
- base
+ 1;
19913 *byte_pos_ptr
= limit_byte
;
19916 return - orig_count
+ count
;
19917 return orig_count
- count
;
19923 /***********************************************************************
19925 ***********************************************************************/
19927 /* Display a NUL-terminated string, starting with index START.
19929 If STRING is non-null, display that C string. Otherwise, the Lisp
19930 string LISP_STRING is displayed. There's a case that STRING is
19931 non-null and LISP_STRING is not nil. It means STRING is a string
19932 data of LISP_STRING. In that case, we display LISP_STRING while
19933 ignoring its text properties.
19935 If FACE_STRING is not nil, FACE_STRING_POS is a position in
19936 FACE_STRING. Display STRING or LISP_STRING with the face at
19937 FACE_STRING_POS in FACE_STRING:
19939 Display the string in the environment given by IT, but use the
19940 standard display table, temporarily.
19942 FIELD_WIDTH is the minimum number of output glyphs to produce.
19943 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19944 with spaces. If STRING has more characters, more than FIELD_WIDTH
19945 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
19947 PRECISION is the maximum number of characters to output from
19948 STRING. PRECISION < 0 means don't truncate the string.
19950 This is roughly equivalent to printf format specifiers:
19952 FIELD_WIDTH PRECISION PRINTF
19953 ----------------------------------------
19959 MULTIBYTE zero means do not display multibyte chars, > 0 means do
19960 display them, and < 0 means obey the current buffer's value of
19961 enable_multibyte_characters.
19963 Value is the number of columns displayed. */
19966 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
19967 EMACS_INT face_string_pos
, EMACS_INT start
, struct it
*it
,
19968 int field_width
, int precision
, int max_x
, int multibyte
)
19970 int hpos_at_start
= it
->hpos
;
19971 int saved_face_id
= it
->face_id
;
19972 struct glyph_row
*row
= it
->glyph_row
;
19974 /* Initialize the iterator IT for iteration over STRING beginning
19975 with index START. */
19976 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
19977 precision
, field_width
, multibyte
);
19978 if (string
&& STRINGP (lisp_string
))
19979 /* LISP_STRING is the one returned by decode_mode_spec. We should
19980 ignore its text properties. */
19981 it
->stop_charpos
= -1;
19983 /* If displaying STRING, set up the face of the iterator
19984 from LISP_STRING, if that's given. */
19985 if (STRINGP (face_string
))
19991 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
19992 0, it
->region_beg_charpos
,
19993 it
->region_end_charpos
,
19994 &endptr
, it
->base_face_id
, 0);
19995 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19996 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
19999 /* Set max_x to the maximum allowed X position. Don't let it go
20000 beyond the right edge of the window. */
20002 max_x
= it
->last_visible_x
;
20004 max_x
= min (max_x
, it
->last_visible_x
);
20006 /* Skip over display elements that are not visible. because IT->w is
20008 if (it
->current_x
< it
->first_visible_x
)
20009 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
20010 MOVE_TO_POS
| MOVE_TO_X
);
20012 row
->ascent
= it
->max_ascent
;
20013 row
->height
= it
->max_ascent
+ it
->max_descent
;
20014 row
->phys_ascent
= it
->max_phys_ascent
;
20015 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20016 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20018 /* This condition is for the case that we are called with current_x
20019 past last_visible_x. */
20020 while (it
->current_x
< max_x
)
20022 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
20024 /* Get the next display element. */
20025 if (!get_next_display_element (it
))
20028 /* Produce glyphs. */
20029 x_before
= it
->current_x
;
20030 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20031 PRODUCE_GLYPHS (it
);
20033 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
20036 while (i
< nglyphs
)
20038 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20040 if (it
->line_wrap
!= TRUNCATE
20041 && x
+ glyph
->pixel_width
> max_x
)
20043 /* End of continued line or max_x reached. */
20044 if (CHAR_GLYPH_PADDING_P (*glyph
))
20046 /* A wide character is unbreakable. */
20047 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
20048 it
->current_x
= x_before
;
20052 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20057 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
20059 /* Glyph is at least partially visible. */
20061 if (x
< it
->first_visible_x
)
20062 it
->glyph_row
->x
= x
- it
->first_visible_x
;
20066 /* Glyph is off the left margin of the display area.
20067 Should not happen. */
20071 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20072 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20073 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20074 row
->phys_height
= max (row
->phys_height
,
20075 it
->max_phys_ascent
+ it
->max_phys_descent
);
20076 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20077 it
->max_extra_line_spacing
);
20078 x
+= glyph
->pixel_width
;
20082 /* Stop if max_x reached. */
20086 /* Stop at line ends. */
20087 if (ITERATOR_AT_END_OF_LINE_P (it
))
20089 it
->continuation_lines_width
= 0;
20093 set_iterator_to_next (it
, 1);
20095 /* Stop if truncating at the right edge. */
20096 if (it
->line_wrap
== TRUNCATE
20097 && it
->current_x
>= it
->last_visible_x
)
20099 /* Add truncation mark, but don't do it if the line is
20100 truncated at a padding space. */
20101 if (IT_CHARPOS (*it
) < it
->string_nchars
)
20103 if (!FRAME_WINDOW_P (it
->f
))
20107 if (it
->current_x
> it
->last_visible_x
)
20109 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
20110 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20112 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
20114 row
->used
[TEXT_AREA
] = ii
;
20115 produce_special_glyphs (it
, IT_TRUNCATION
);
20118 produce_special_glyphs (it
, IT_TRUNCATION
);
20120 it
->glyph_row
->truncated_on_right_p
= 1;
20126 /* Maybe insert a truncation at the left. */
20127 if (it
->first_visible_x
20128 && IT_CHARPOS (*it
) > 0)
20130 if (!FRAME_WINDOW_P (it
->f
))
20131 insert_left_trunc_glyphs (it
);
20132 it
->glyph_row
->truncated_on_left_p
= 1;
20135 it
->face_id
= saved_face_id
;
20137 /* Value is number of columns displayed. */
20138 return it
->hpos
- hpos_at_start
;
20143 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
20144 appears as an element of LIST or as the car of an element of LIST.
20145 If PROPVAL is a list, compare each element against LIST in that
20146 way, and return 1/2 if any element of PROPVAL is found in LIST.
20147 Otherwise return 0. This function cannot quit.
20148 The return value is 2 if the text is invisible but with an ellipsis
20149 and 1 if it's invisible and without an ellipsis. */
20152 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
20154 register Lisp_Object tail
, proptail
;
20156 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20158 register Lisp_Object tem
;
20160 if (EQ (propval
, tem
))
20162 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
20163 return NILP (XCDR (tem
)) ? 1 : 2;
20166 if (CONSP (propval
))
20168 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
20170 Lisp_Object propelt
;
20171 propelt
= XCAR (proptail
);
20172 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20174 register Lisp_Object tem
;
20176 if (EQ (propelt
, tem
))
20178 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
20179 return NILP (XCDR (tem
)) ? 1 : 2;
20187 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
20188 doc
: /* Non-nil if the property makes the text invisible.
20189 POS-OR-PROP can be a marker or number, in which case it is taken to be
20190 a position in the current buffer and the value of the `invisible' property
20191 is checked; or it can be some other value, which is then presumed to be the
20192 value of the `invisible' property of the text of interest.
20193 The non-nil value returned can be t for truly invisible text or something
20194 else if the text is replaced by an ellipsis. */)
20195 (Lisp_Object pos_or_prop
)
20198 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
20199 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
20201 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
20202 return (invis
== 0 ? Qnil
20204 : make_number (invis
));
20207 /* Calculate a width or height in pixels from a specification using
20208 the following elements:
20211 NUM - a (fractional) multiple of the default font width/height
20212 (NUM) - specifies exactly NUM pixels
20213 UNIT - a fixed number of pixels, see below.
20214 ELEMENT - size of a display element in pixels, see below.
20215 (NUM . SPEC) - equals NUM * SPEC
20216 (+ SPEC SPEC ...) - add pixel values
20217 (- SPEC SPEC ...) - subtract pixel values
20218 (- SPEC) - negate pixel value
20221 INT or FLOAT - a number constant
20222 SYMBOL - use symbol's (buffer local) variable binding.
20225 in - pixels per inch *)
20226 mm - pixels per 1/1000 meter *)
20227 cm - pixels per 1/100 meter *)
20228 width - width of current font in pixels.
20229 height - height of current font in pixels.
20231 *) using the ratio(s) defined in display-pixels-per-inch.
20235 left-fringe - left fringe width in pixels
20236 right-fringe - right fringe width in pixels
20238 left-margin - left margin width in pixels
20239 right-margin - right margin width in pixels
20241 scroll-bar - scroll-bar area width in pixels
20245 Pixels corresponding to 5 inches:
20248 Total width of non-text areas on left side of window (if scroll-bar is on left):
20249 '(space :width (+ left-fringe left-margin scroll-bar))
20251 Align to first text column (in header line):
20252 '(space :align-to 0)
20254 Align to middle of text area minus half the width of variable `my-image'
20255 containing a loaded image:
20256 '(space :align-to (0.5 . (- text my-image)))
20258 Width of left margin minus width of 1 character in the default font:
20259 '(space :width (- left-margin 1))
20261 Width of left margin minus width of 2 characters in the current font:
20262 '(space :width (- left-margin (2 . width)))
20264 Center 1 character over left-margin (in header line):
20265 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
20267 Different ways to express width of left fringe plus left margin minus one pixel:
20268 '(space :width (- (+ left-fringe left-margin) (1)))
20269 '(space :width (+ left-fringe left-margin (- (1))))
20270 '(space :width (+ left-fringe left-margin (-1)))
20274 #define NUMVAL(X) \
20275 ((INTEGERP (X) || FLOATP (X)) \
20280 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
20281 struct font
*font
, int width_p
, int *align_to
)
20285 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20286 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20289 return OK_PIXELS (0);
20291 xassert (FRAME_LIVE_P (it
->f
));
20293 if (SYMBOLP (prop
))
20295 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20297 char *unit
= SSDATA (SYMBOL_NAME (prop
));
20299 if (unit
[0] == 'i' && unit
[1] == 'n')
20301 else if (unit
[0] == 'm' && unit
[1] == 'm')
20303 else if (unit
[0] == 'c' && unit
[1] == 'm')
20310 #ifdef HAVE_WINDOW_SYSTEM
20311 if (FRAME_WINDOW_P (it
->f
)
20313 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20314 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20316 return OK_PIXELS (ppi
/ pixels
);
20319 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20320 || (CONSP (Vdisplay_pixels_per_inch
)
20322 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20323 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20325 return OK_PIXELS (ppi
/ pixels
);
20331 #ifdef HAVE_WINDOW_SYSTEM
20332 if (EQ (prop
, Qheight
))
20333 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20334 if (EQ (prop
, Qwidth
))
20335 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20337 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20338 return OK_PIXELS (1);
20341 if (EQ (prop
, Qtext
))
20342 return OK_PIXELS (width_p
20343 ? window_box_width (it
->w
, TEXT_AREA
)
20344 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20346 if (align_to
&& *align_to
< 0)
20349 if (EQ (prop
, Qleft
))
20350 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20351 if (EQ (prop
, Qright
))
20352 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20353 if (EQ (prop
, Qcenter
))
20354 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20355 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20356 if (EQ (prop
, Qleft_fringe
))
20357 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20358 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20359 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20360 if (EQ (prop
, Qright_fringe
))
20361 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20362 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20363 : window_box_right_offset (it
->w
, TEXT_AREA
));
20364 if (EQ (prop
, Qleft_margin
))
20365 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20366 if (EQ (prop
, Qright_margin
))
20367 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20368 if (EQ (prop
, Qscroll_bar
))
20369 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20371 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20372 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20373 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20378 if (EQ (prop
, Qleft_fringe
))
20379 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20380 if (EQ (prop
, Qright_fringe
))
20381 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20382 if (EQ (prop
, Qleft_margin
))
20383 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20384 if (EQ (prop
, Qright_margin
))
20385 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20386 if (EQ (prop
, Qscroll_bar
))
20387 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20390 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20393 if (INTEGERP (prop
) || FLOATP (prop
))
20395 int base_unit
= (width_p
20396 ? FRAME_COLUMN_WIDTH (it
->f
)
20397 : FRAME_LINE_HEIGHT (it
->f
));
20398 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
20403 Lisp_Object car
= XCAR (prop
);
20404 Lisp_Object cdr
= XCDR (prop
);
20408 #ifdef HAVE_WINDOW_SYSTEM
20409 if (FRAME_WINDOW_P (it
->f
)
20410 && valid_image_p (prop
))
20412 int id
= lookup_image (it
->f
, prop
);
20413 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
20415 return OK_PIXELS (width_p
? img
->width
: img
->height
);
20418 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
20424 while (CONSP (cdr
))
20426 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
20427 font
, width_p
, align_to
))
20430 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
20435 if (EQ (car
, Qminus
))
20437 return OK_PIXELS (pixels
);
20440 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
20443 if (INTEGERP (car
) || FLOATP (car
))
20446 pixels
= XFLOATINT (car
);
20448 return OK_PIXELS (pixels
);
20449 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
20450 font
, width_p
, align_to
))
20451 return OK_PIXELS (pixels
* fact
);
20462 /***********************************************************************
20464 ***********************************************************************/
20466 #ifdef HAVE_WINDOW_SYSTEM
20471 dump_glyph_string (struct glyph_string
*s
)
20473 fprintf (stderr
, "glyph string\n");
20474 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
20475 s
->x
, s
->y
, s
->width
, s
->height
);
20476 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
20477 fprintf (stderr
, " hl = %d\n", s
->hl
);
20478 fprintf (stderr
, " left overhang = %d, right = %d\n",
20479 s
->left_overhang
, s
->right_overhang
);
20480 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
20481 fprintf (stderr
, " extends to end of line = %d\n",
20482 s
->extends_to_end_of_line_p
);
20483 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
20484 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
20487 #endif /* GLYPH_DEBUG */
20489 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
20490 of XChar2b structures for S; it can't be allocated in
20491 init_glyph_string because it must be allocated via `alloca'. W
20492 is the window on which S is drawn. ROW and AREA are the glyph row
20493 and area within the row from which S is constructed. START is the
20494 index of the first glyph structure covered by S. HL is a
20495 face-override for drawing S. */
20498 #define OPTIONAL_HDC(hdc) HDC hdc,
20499 #define DECLARE_HDC(hdc) HDC hdc;
20500 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
20501 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
20504 #ifndef OPTIONAL_HDC
20505 #define OPTIONAL_HDC(hdc)
20506 #define DECLARE_HDC(hdc)
20507 #define ALLOCATE_HDC(hdc, f)
20508 #define RELEASE_HDC(hdc, f)
20512 init_glyph_string (struct glyph_string
*s
,
20514 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
20515 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
20517 memset (s
, 0, sizeof *s
);
20519 s
->f
= XFRAME (w
->frame
);
20523 s
->display
= FRAME_X_DISPLAY (s
->f
);
20524 s
->window
= FRAME_X_WINDOW (s
->f
);
20525 s
->char2b
= char2b
;
20529 s
->first_glyph
= row
->glyphs
[area
] + start
;
20530 s
->height
= row
->height
;
20531 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
20532 s
->ybase
= s
->y
+ row
->ascent
;
20536 /* Append the list of glyph strings with head H and tail T to the list
20537 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
20540 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20541 struct glyph_string
*h
, struct glyph_string
*t
)
20555 /* Prepend the list of glyph strings with head H and tail T to the
20556 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
20560 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20561 struct glyph_string
*h
, struct glyph_string
*t
)
20575 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
20576 Set *HEAD and *TAIL to the resulting list. */
20579 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
20580 struct glyph_string
*s
)
20582 s
->next
= s
->prev
= NULL
;
20583 append_glyph_string_lists (head
, tail
, s
, s
);
20587 /* Get face and two-byte form of character C in face FACE_ID on frame F.
20588 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
20589 make sure that X resources for the face returned are allocated.
20590 Value is a pointer to a realized face that is ready for display if
20591 DISPLAY_P is non-zero. */
20593 static inline struct face
*
20594 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
20595 XChar2b
*char2b
, int display_p
)
20597 struct face
*face
= FACE_FROM_ID (f
, face_id
);
20601 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
20603 if (code
!= FONT_INVALID_CODE
)
20604 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20606 STORE_XCHAR2B (char2b
, 0, 0);
20609 /* Make sure X resources of the face are allocated. */
20610 #ifdef HAVE_X_WINDOWS
20614 xassert (face
!= NULL
);
20615 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20622 /* Get face and two-byte form of character glyph GLYPH on frame F.
20623 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
20624 a pointer to a realized face that is ready for display. */
20626 static inline struct face
*
20627 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
20628 XChar2b
*char2b
, int *two_byte_p
)
20632 xassert (glyph
->type
== CHAR_GLYPH
);
20633 face
= FACE_FROM_ID (f
, glyph
->face_id
);
20642 if (CHAR_BYTE8_P (glyph
->u
.ch
))
20643 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
20645 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
20647 if (code
!= FONT_INVALID_CODE
)
20648 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20650 STORE_XCHAR2B (char2b
, 0, 0);
20653 /* Make sure X resources of the face are allocated. */
20654 xassert (face
!= NULL
);
20655 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20660 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
20661 Retunr 1 if FONT has a glyph for C, otherwise return 0. */
20664 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
20668 if (CHAR_BYTE8_P (c
))
20669 code
= CHAR_TO_BYTE8 (c
);
20671 code
= font
->driver
->encode_char (font
, c
);
20673 if (code
== FONT_INVALID_CODE
)
20675 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20680 /* Fill glyph string S with composition components specified by S->cmp.
20682 BASE_FACE is the base face of the composition.
20683 S->cmp_from is the index of the first component for S.
20685 OVERLAPS non-zero means S should draw the foreground only, and use
20686 its physical height for clipping. See also draw_glyphs.
20688 Value is the index of a component not in S. */
20691 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
20695 /* For all glyphs of this composition, starting at the offset
20696 S->cmp_from, until we reach the end of the definition or encounter a
20697 glyph that requires the different face, add it to S. */
20702 s
->for_overlaps
= overlaps
;
20705 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
20707 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
20711 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
20714 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
20721 s
->font
= s
->face
->font
;
20723 else if (s
->face
!= face
)
20731 /* All glyph strings for the same composition has the same width,
20732 i.e. the width set for the first component of the composition. */
20733 s
->width
= s
->first_glyph
->pixel_width
;
20735 /* If the specified font could not be loaded, use the frame's
20736 default font, but record the fact that we couldn't load it in
20737 the glyph string so that we can draw rectangles for the
20738 characters of the glyph string. */
20739 if (s
->font
== NULL
)
20741 s
->font_not_found_p
= 1;
20742 s
->font
= FRAME_FONT (s
->f
);
20745 /* Adjust base line for subscript/superscript text. */
20746 s
->ybase
+= s
->first_glyph
->voffset
;
20748 /* This glyph string must always be drawn with 16-bit functions. */
20755 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
20756 int start
, int end
, int overlaps
)
20758 struct glyph
*glyph
, *last
;
20759 Lisp_Object lgstring
;
20762 s
->for_overlaps
= overlaps
;
20763 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20764 last
= s
->row
->glyphs
[s
->area
] + end
;
20765 s
->cmp_id
= glyph
->u
.cmp
.id
;
20766 s
->cmp_from
= glyph
->slice
.cmp
.from
;
20767 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
20768 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20769 lgstring
= composition_gstring_from_id (s
->cmp_id
);
20770 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
20772 while (glyph
< last
20773 && glyph
->u
.cmp
.automatic
20774 && glyph
->u
.cmp
.id
== s
->cmp_id
20775 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
20776 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
20778 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
20780 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
20781 unsigned code
= LGLYPH_CODE (lglyph
);
20783 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
20785 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
20786 return glyph
- s
->row
->glyphs
[s
->area
];
20790 /* Fill glyph string S from a sequence glyphs for glyphless characters.
20791 See the comment of fill_glyph_string for arguments.
20792 Value is the index of the first glyph not in S. */
20796 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
20797 int start
, int end
, int overlaps
)
20799 struct glyph
*glyph
, *last
;
20802 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
20803 s
->for_overlaps
= overlaps
;
20804 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20805 last
= s
->row
->glyphs
[s
->area
] + end
;
20806 voffset
= glyph
->voffset
;
20807 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20808 s
->font
= s
->face
->font
;
20810 s
->width
= glyph
->pixel_width
;
20812 while (glyph
< last
20813 && glyph
->type
== GLYPHLESS_GLYPH
20814 && glyph
->voffset
== voffset
20815 && glyph
->face_id
== face_id
)
20818 s
->width
+= glyph
->pixel_width
;
20821 s
->ybase
+= voffset
;
20822 return glyph
- s
->row
->glyphs
[s
->area
];
20826 /* Fill glyph string S from a sequence of character glyphs.
20828 FACE_ID is the face id of the string. START is the index of the
20829 first glyph to consider, END is the index of the last + 1.
20830 OVERLAPS non-zero means S should draw the foreground only, and use
20831 its physical height for clipping. See also draw_glyphs.
20833 Value is the index of the first glyph not in S. */
20836 fill_glyph_string (struct glyph_string
*s
, int face_id
,
20837 int start
, int end
, int overlaps
)
20839 struct glyph
*glyph
, *last
;
20841 int glyph_not_available_p
;
20843 xassert (s
->f
== XFRAME (s
->w
->frame
));
20844 xassert (s
->nchars
== 0);
20845 xassert (start
>= 0 && end
> start
);
20847 s
->for_overlaps
= overlaps
;
20848 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20849 last
= s
->row
->glyphs
[s
->area
] + end
;
20850 voffset
= glyph
->voffset
;
20851 s
->padding_p
= glyph
->padding_p
;
20852 glyph_not_available_p
= glyph
->glyph_not_available_p
;
20854 while (glyph
< last
20855 && glyph
->type
== CHAR_GLYPH
20856 && glyph
->voffset
== voffset
20857 /* Same face id implies same font, nowadays. */
20858 && glyph
->face_id
== face_id
20859 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
20863 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
20864 s
->char2b
+ s
->nchars
,
20866 s
->two_byte_p
= two_byte_p
;
20868 xassert (s
->nchars
<= end
- start
);
20869 s
->width
+= glyph
->pixel_width
;
20870 if (glyph
++->padding_p
!= s
->padding_p
)
20874 s
->font
= s
->face
->font
;
20876 /* If the specified font could not be loaded, use the frame's font,
20877 but record the fact that we couldn't load it in
20878 S->font_not_found_p so that we can draw rectangles for the
20879 characters of the glyph string. */
20880 if (s
->font
== NULL
|| glyph_not_available_p
)
20882 s
->font_not_found_p
= 1;
20883 s
->font
= FRAME_FONT (s
->f
);
20886 /* Adjust base line for subscript/superscript text. */
20887 s
->ybase
+= voffset
;
20889 xassert (s
->face
&& s
->face
->gc
);
20890 return glyph
- s
->row
->glyphs
[s
->area
];
20894 /* Fill glyph string S from image glyph S->first_glyph. */
20897 fill_image_glyph_string (struct glyph_string
*s
)
20899 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
20900 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
20902 s
->slice
= s
->first_glyph
->slice
.img
;
20903 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
20904 s
->font
= s
->face
->font
;
20905 s
->width
= s
->first_glyph
->pixel_width
;
20907 /* Adjust base line for subscript/superscript text. */
20908 s
->ybase
+= s
->first_glyph
->voffset
;
20912 /* Fill glyph string S from a sequence of stretch glyphs.
20914 START is the index of the first glyph to consider,
20915 END is the index of the last + 1.
20917 Value is the index of the first glyph not in S. */
20920 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
20922 struct glyph
*glyph
, *last
;
20923 int voffset
, face_id
;
20925 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
20927 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20928 last
= s
->row
->glyphs
[s
->area
] + end
;
20929 face_id
= glyph
->face_id
;
20930 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20931 s
->font
= s
->face
->font
;
20932 s
->width
= glyph
->pixel_width
;
20934 voffset
= glyph
->voffset
;
20938 && glyph
->type
== STRETCH_GLYPH
20939 && glyph
->voffset
== voffset
20940 && glyph
->face_id
== face_id
);
20942 s
->width
+= glyph
->pixel_width
;
20944 /* Adjust base line for subscript/superscript text. */
20945 s
->ybase
+= voffset
;
20947 /* The case that face->gc == 0 is handled when drawing the glyph
20948 string by calling PREPARE_FACE_FOR_DISPLAY. */
20950 return glyph
- s
->row
->glyphs
[s
->area
];
20953 static struct font_metrics
*
20954 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
20956 static struct font_metrics metrics
;
20957 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
20959 if (! font
|| code
== FONT_INVALID_CODE
)
20961 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
20966 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
20967 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
20968 assumed to be zero. */
20971 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
20973 *left
= *right
= 0;
20975 if (glyph
->type
== CHAR_GLYPH
)
20979 struct font_metrics
*pcm
;
20981 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
20982 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
20984 if (pcm
->rbearing
> pcm
->width
)
20985 *right
= pcm
->rbearing
- pcm
->width
;
20986 if (pcm
->lbearing
< 0)
20987 *left
= -pcm
->lbearing
;
20990 else if (glyph
->type
== COMPOSITE_GLYPH
)
20992 if (! glyph
->u
.cmp
.automatic
)
20994 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
20996 if (cmp
->rbearing
> cmp
->pixel_width
)
20997 *right
= cmp
->rbearing
- cmp
->pixel_width
;
20998 if (cmp
->lbearing
< 0)
20999 *left
= - cmp
->lbearing
;
21003 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
21004 struct font_metrics metrics
;
21006 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
21007 glyph
->slice
.cmp
.to
+ 1, &metrics
);
21008 if (metrics
.rbearing
> metrics
.width
)
21009 *right
= metrics
.rbearing
- metrics
.width
;
21010 if (metrics
.lbearing
< 0)
21011 *left
= - metrics
.lbearing
;
21017 /* Return the index of the first glyph preceding glyph string S that
21018 is overwritten by S because of S's left overhang. Value is -1
21019 if no glyphs are overwritten. */
21022 left_overwritten (struct glyph_string
*s
)
21026 if (s
->left_overhang
)
21029 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21030 int first
= s
->first_glyph
- glyphs
;
21032 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
21033 x
-= glyphs
[i
].pixel_width
;
21044 /* Return the index of the first glyph preceding glyph string S that
21045 is overwriting S because of its right overhang. Value is -1 if no
21046 glyph in front of S overwrites S. */
21049 left_overwriting (struct glyph_string
*s
)
21052 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21053 int first
= s
->first_glyph
- glyphs
;
21057 for (i
= first
- 1; i
>= 0; --i
)
21060 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21063 x
-= glyphs
[i
].pixel_width
;
21070 /* Return the index of the last glyph following glyph string S that is
21071 overwritten by S because of S's right overhang. Value is -1 if
21072 no such glyph is found. */
21075 right_overwritten (struct glyph_string
*s
)
21079 if (s
->right_overhang
)
21082 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21083 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21084 int end
= s
->row
->used
[s
->area
];
21086 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
21087 x
+= glyphs
[i
].pixel_width
;
21096 /* Return the index of the last glyph following glyph string S that
21097 overwrites S because of its left overhang. Value is negative
21098 if no such glyph is found. */
21101 right_overwriting (struct glyph_string
*s
)
21104 int end
= s
->row
->used
[s
->area
];
21105 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21106 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21110 for (i
= first
; i
< end
; ++i
)
21113 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21116 x
+= glyphs
[i
].pixel_width
;
21123 /* Set background width of glyph string S. START is the index of the
21124 first glyph following S. LAST_X is the right-most x-position + 1
21125 in the drawing area. */
21128 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
21130 /* If the face of this glyph string has to be drawn to the end of
21131 the drawing area, set S->extends_to_end_of_line_p. */
21133 if (start
== s
->row
->used
[s
->area
]
21134 && s
->area
== TEXT_AREA
21135 && ((s
->row
->fill_line_p
21136 && (s
->hl
== DRAW_NORMAL_TEXT
21137 || s
->hl
== DRAW_IMAGE_RAISED
21138 || s
->hl
== DRAW_IMAGE_SUNKEN
))
21139 || s
->hl
== DRAW_MOUSE_FACE
))
21140 s
->extends_to_end_of_line_p
= 1;
21142 /* If S extends its face to the end of the line, set its
21143 background_width to the distance to the right edge of the drawing
21145 if (s
->extends_to_end_of_line_p
)
21146 s
->background_width
= last_x
- s
->x
+ 1;
21148 s
->background_width
= s
->width
;
21152 /* Compute overhangs and x-positions for glyph string S and its
21153 predecessors, or successors. X is the starting x-position for S.
21154 BACKWARD_P non-zero means process predecessors. */
21157 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
21163 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21164 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21174 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21175 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21185 /* The following macros are only called from draw_glyphs below.
21186 They reference the following parameters of that function directly:
21187 `w', `row', `area', and `overlap_p'
21188 as well as the following local variables:
21189 `s', `f', and `hdc' (in W32) */
21192 /* On W32, silently add local `hdc' variable to argument list of
21193 init_glyph_string. */
21194 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21195 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
21197 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21198 init_glyph_string (s, char2b, w, row, area, start, hl)
21201 /* Add a glyph string for a stretch glyph to the list of strings
21202 between HEAD and TAIL. START is the index of the stretch glyph in
21203 row area AREA of glyph row ROW. END is the index of the last glyph
21204 in that glyph row area. X is the current output position assigned
21205 to the new glyph string constructed. HL overrides that face of the
21206 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21207 is the right-most x-position of the drawing area. */
21209 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
21210 and below -- keep them on one line. */
21211 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21214 s = (struct glyph_string *) alloca (sizeof *s); \
21215 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21216 START = fill_stretch_glyph_string (s, START, END); \
21217 append_glyph_string (&HEAD, &TAIL, s); \
21223 /* Add a glyph string for an image glyph to the list of strings
21224 between HEAD and TAIL. START is the index of the image glyph in
21225 row area AREA of glyph row ROW. END is the index of the last glyph
21226 in that glyph row area. X is the current output position assigned
21227 to the new glyph string constructed. HL overrides that face of the
21228 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21229 is the right-most x-position of the drawing area. */
21231 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21234 s = (struct glyph_string *) alloca (sizeof *s); \
21235 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21236 fill_image_glyph_string (s); \
21237 append_glyph_string (&HEAD, &TAIL, s); \
21244 /* Add a glyph string for a sequence of character glyphs to the list
21245 of strings between HEAD and TAIL. START is the index of the first
21246 glyph in row area AREA of glyph row ROW that is part of the new
21247 glyph string. END is the index of the last glyph in that glyph row
21248 area. X is the current output position assigned to the new glyph
21249 string constructed. HL overrides that face of the glyph; e.g. it
21250 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
21251 right-most x-position of the drawing area. */
21253 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21259 face_id = (row)->glyphs[area][START].face_id; \
21261 s = (struct glyph_string *) alloca (sizeof *s); \
21262 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
21263 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21264 append_glyph_string (&HEAD, &TAIL, s); \
21266 START = fill_glyph_string (s, face_id, START, END, overlaps); \
21271 /* Add a glyph string for a composite sequence to the list of strings
21272 between HEAD and TAIL. START is the index of the first glyph in
21273 row area AREA of glyph row ROW that is part of the new glyph
21274 string. END is the index of the last glyph in that glyph row area.
21275 X is the current output position assigned to the new glyph string
21276 constructed. HL overrides that face of the glyph; e.g. it is
21277 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
21278 x-position of the drawing area. */
21280 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21282 int face_id = (row)->glyphs[area][START].face_id; \
21283 struct face *base_face = FACE_FROM_ID (f, face_id); \
21284 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
21285 struct composition *cmp = composition_table[cmp_id]; \
21287 struct glyph_string *first_s IF_LINT (= NULL); \
21290 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21292 /* Make glyph_strings for each glyph sequence that is drawable by \
21293 the same face, and append them to HEAD/TAIL. */ \
21294 for (n = 0; n < cmp->glyph_len;) \
21296 s = (struct glyph_string *) alloca (sizeof *s); \
21297 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21298 append_glyph_string (&(HEAD), &(TAIL), s); \
21304 n = fill_composite_glyph_string (s, base_face, overlaps); \
21312 /* Add a glyph string for a glyph-string sequence to the list of strings
21313 between HEAD and TAIL. */
21315 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21319 Lisp_Object gstring; \
21321 face_id = (row)->glyphs[area][START].face_id; \
21322 gstring = (composition_gstring_from_id \
21323 ((row)->glyphs[area][START].u.cmp.id)); \
21324 s = (struct glyph_string *) alloca (sizeof *s); \
21325 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21326 * LGSTRING_GLYPH_LEN (gstring)); \
21327 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21328 append_glyph_string (&(HEAD), &(TAIL), s); \
21330 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21334 /* Add a glyph string for a sequence of glyphless character's glyphs
21335 to the list of strings between HEAD and TAIL. The meanings of
21336 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
21338 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21343 face_id = (row)->glyphs[area][START].face_id; \
21345 s = (struct glyph_string *) alloca (sizeof *s); \
21346 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21347 append_glyph_string (&HEAD, &TAIL, s); \
21349 START = fill_glyphless_glyph_string (s, face_id, START, END, \
21355 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21356 of AREA of glyph row ROW on window W between indices START and END.
21357 HL overrides the face for drawing glyph strings, e.g. it is
21358 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21359 x-positions of the drawing area.
21361 This is an ugly monster macro construct because we must use alloca
21362 to allocate glyph strings (because draw_glyphs can be called
21363 asynchronously). */
21365 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21368 HEAD = TAIL = NULL; \
21369 while (START < END) \
21371 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21372 switch (first_glyph->type) \
21375 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21379 case COMPOSITE_GLYPH: \
21380 if (first_glyph->u.cmp.automatic) \
21381 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21384 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21388 case STRETCH_GLYPH: \
21389 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21393 case IMAGE_GLYPH: \
21394 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21398 case GLYPHLESS_GLYPH: \
21399 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
21409 set_glyph_string_background_width (s, START, LAST_X); \
21416 /* Draw glyphs between START and END in AREA of ROW on window W,
21417 starting at x-position X. X is relative to AREA in W. HL is a
21418 face-override with the following meaning:
21420 DRAW_NORMAL_TEXT draw normally
21421 DRAW_CURSOR draw in cursor face
21422 DRAW_MOUSE_FACE draw in mouse face.
21423 DRAW_INVERSE_VIDEO draw in mode line face
21424 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
21425 DRAW_IMAGE_RAISED draw an image with a raised relief around it
21427 If OVERLAPS is non-zero, draw only the foreground of characters and
21428 clip to the physical height of ROW. Non-zero value also defines
21429 the overlapping part to be drawn:
21431 OVERLAPS_PRED overlap with preceding rows
21432 OVERLAPS_SUCC overlap with succeeding rows
21433 OVERLAPS_BOTH overlap with both preceding/succeeding rows
21434 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
21436 Value is the x-position reached, relative to AREA of W. */
21439 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
21440 enum glyph_row_area area
, EMACS_INT start
, EMACS_INT end
,
21441 enum draw_glyphs_face hl
, int overlaps
)
21443 struct glyph_string
*head
, *tail
;
21444 struct glyph_string
*s
;
21445 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
21446 int i
, j
, x_reached
, last_x
, area_left
= 0;
21447 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21450 ALLOCATE_HDC (hdc
, f
);
21452 /* Let's rather be paranoid than getting a SEGV. */
21453 end
= min (end
, row
->used
[area
]);
21454 start
= max (0, start
);
21455 start
= min (end
, start
);
21457 /* Translate X to frame coordinates. Set last_x to the right
21458 end of the drawing area. */
21459 if (row
->full_width_p
)
21461 /* X is relative to the left edge of W, without scroll bars
21463 area_left
= WINDOW_LEFT_EDGE_X (w
);
21464 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
21468 area_left
= window_box_left (w
, area
);
21469 last_x
= area_left
+ window_box_width (w
, area
);
21473 /* Build a doubly-linked list of glyph_string structures between
21474 head and tail from what we have to draw. Note that the macro
21475 BUILD_GLYPH_STRINGS will modify its start parameter. That's
21476 the reason we use a separate variable `i'. */
21478 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
21480 x_reached
= tail
->x
+ tail
->background_width
;
21484 /* If there are any glyphs with lbearing < 0 or rbearing > width in
21485 the row, redraw some glyphs in front or following the glyph
21486 strings built above. */
21487 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
21489 struct glyph_string
*h
, *t
;
21490 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
21491 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
21492 int check_mouse_face
= 0;
21495 /* If mouse highlighting is on, we may need to draw adjacent
21496 glyphs using mouse-face highlighting. */
21497 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
21499 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
21501 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
21502 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
21504 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
21506 check_mouse_face
= 1;
21507 mouse_beg_col
= (row
== mouse_beg_row
)
21508 ? hlinfo
->mouse_face_beg_col
: 0;
21509 mouse_end_col
= (row
== mouse_end_row
)
21510 ? hlinfo
->mouse_face_end_col
21511 : row
->used
[TEXT_AREA
];
21515 /* Compute overhangs for all glyph strings. */
21516 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
21517 for (s
= head
; s
; s
= s
->next
)
21518 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
21520 /* Prepend glyph strings for glyphs in front of the first glyph
21521 string that are overwritten because of the first glyph
21522 string's left overhang. The background of all strings
21523 prepended must be drawn because the first glyph string
21525 i
= left_overwritten (head
);
21528 enum draw_glyphs_face overlap_hl
;
21530 /* If this row contains mouse highlighting, attempt to draw
21531 the overlapped glyphs with the correct highlight. This
21532 code fails if the overlap encompasses more than one glyph
21533 and mouse-highlight spans only some of these glyphs.
21534 However, making it work perfectly involves a lot more
21535 code, and I don't know if the pathological case occurs in
21536 practice, so we'll stick to this for now. --- cyd */
21537 if (check_mouse_face
21538 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21539 overlap_hl
= DRAW_MOUSE_FACE
;
21541 overlap_hl
= DRAW_NORMAL_TEXT
;
21544 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
21545 overlap_hl
, dummy_x
, last_x
);
21547 compute_overhangs_and_x (t
, head
->x
, 1);
21548 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21552 /* Prepend glyph strings for glyphs in front of the first glyph
21553 string that overwrite that glyph string because of their
21554 right overhang. For these strings, only the foreground must
21555 be drawn, because it draws over the glyph string at `head'.
21556 The background must not be drawn because this would overwrite
21557 right overhangs of preceding glyphs for which no glyph
21559 i
= left_overwriting (head
);
21562 enum draw_glyphs_face overlap_hl
;
21564 if (check_mouse_face
21565 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21566 overlap_hl
= DRAW_MOUSE_FACE
;
21568 overlap_hl
= DRAW_NORMAL_TEXT
;
21571 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
21572 overlap_hl
, dummy_x
, last_x
);
21573 for (s
= h
; s
; s
= s
->next
)
21574 s
->background_filled_p
= 1;
21575 compute_overhangs_and_x (t
, head
->x
, 1);
21576 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21579 /* Append glyphs strings for glyphs following the last glyph
21580 string tail that are overwritten by tail. The background of
21581 these strings has to be drawn because tail's foreground draws
21583 i
= right_overwritten (tail
);
21586 enum draw_glyphs_face overlap_hl
;
21588 if (check_mouse_face
21589 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21590 overlap_hl
= DRAW_MOUSE_FACE
;
21592 overlap_hl
= DRAW_NORMAL_TEXT
;
21594 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21595 overlap_hl
, x
, last_x
);
21596 /* Because BUILD_GLYPH_STRINGS updates the first argument,
21597 we don't have `end = i;' here. */
21598 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21599 append_glyph_string_lists (&head
, &tail
, h
, t
);
21603 /* Append glyph strings for glyphs following the last glyph
21604 string tail that overwrite tail. The foreground of such
21605 glyphs has to be drawn because it writes into the background
21606 of tail. The background must not be drawn because it could
21607 paint over the foreground of following glyphs. */
21608 i
= right_overwriting (tail
);
21611 enum draw_glyphs_face overlap_hl
;
21612 if (check_mouse_face
21613 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21614 overlap_hl
= DRAW_MOUSE_FACE
;
21616 overlap_hl
= DRAW_NORMAL_TEXT
;
21619 i
++; /* We must include the Ith glyph. */
21620 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21621 overlap_hl
, x
, last_x
);
21622 for (s
= h
; s
; s
= s
->next
)
21623 s
->background_filled_p
= 1;
21624 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21625 append_glyph_string_lists (&head
, &tail
, h
, t
);
21627 if (clip_head
|| clip_tail
)
21628 for (s
= head
; s
; s
= s
->next
)
21630 s
->clip_head
= clip_head
;
21631 s
->clip_tail
= clip_tail
;
21635 /* Draw all strings. */
21636 for (s
= head
; s
; s
= s
->next
)
21637 FRAME_RIF (f
)->draw_glyph_string (s
);
21640 /* When focus a sole frame and move horizontally, this sets on_p to 0
21641 causing a failure to erase prev cursor position. */
21642 if (area
== TEXT_AREA
21643 && !row
->full_width_p
21644 /* When drawing overlapping rows, only the glyph strings'
21645 foreground is drawn, which doesn't erase a cursor
21649 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
21650 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
21651 : (tail
? tail
->x
+ tail
->background_width
: x
));
21655 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
21656 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
21660 /* Value is the x-position up to which drawn, relative to AREA of W.
21661 This doesn't include parts drawn because of overhangs. */
21662 if (row
->full_width_p
)
21663 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
21665 x_reached
-= area_left
;
21667 RELEASE_HDC (hdc
, f
);
21672 /* Expand row matrix if too narrow. Don't expand if area
21675 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
21677 if (!fonts_changed_p \
21678 && (it->glyph_row->glyphs[area] \
21679 < it->glyph_row->glyphs[area + 1])) \
21681 it->w->ncols_scale_factor++; \
21682 fonts_changed_p = 1; \
21686 /* Store one glyph for IT->char_to_display in IT->glyph_row.
21687 Called from x_produce_glyphs when IT->glyph_row is non-null. */
21690 append_glyph (struct it
*it
)
21692 struct glyph
*glyph
;
21693 enum glyph_row_area area
= it
->area
;
21695 xassert (it
->glyph_row
);
21696 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
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
&& area
== TEXT_AREA
)
21707 /* Make room for the additional glyph. */
21708 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
21710 glyph
= it
->glyph_row
->glyphs
[area
];
21712 glyph
->charpos
= CHARPOS (it
->position
);
21713 glyph
->object
= it
->object
;
21714 if (it
->pixel_width
> 0)
21716 glyph
->pixel_width
= it
->pixel_width
;
21717 glyph
->padding_p
= 0;
21721 /* Assure at least 1-pixel width. Otherwise, cursor can't
21722 be displayed correctly. */
21723 glyph
->pixel_width
= 1;
21724 glyph
->padding_p
= 1;
21726 glyph
->ascent
= it
->ascent
;
21727 glyph
->descent
= it
->descent
;
21728 glyph
->voffset
= it
->voffset
;
21729 glyph
->type
= CHAR_GLYPH
;
21730 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21731 glyph
->multibyte_p
= it
->multibyte_p
;
21732 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21733 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21734 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21735 || it
->phys_descent
> it
->descent
);
21736 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
21737 glyph
->face_id
= it
->face_id
;
21738 glyph
->u
.ch
= it
->char_to_display
;
21739 glyph
->slice
.img
= null_glyph_slice
;
21740 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21743 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21744 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21746 glyph
->bidi_type
= it
->bidi_it
.type
;
21750 glyph
->resolved_level
= 0;
21751 glyph
->bidi_type
= UNKNOWN_BT
;
21753 ++it
->glyph_row
->used
[area
];
21756 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21759 /* Store one glyph for the composition IT->cmp_it.id in
21760 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
21764 append_composite_glyph (struct it
*it
)
21766 struct glyph
*glyph
;
21767 enum glyph_row_area area
= it
->area
;
21769 xassert (it
->glyph_row
);
21771 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21772 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21774 /* If the glyph row is reversed, we need to prepend the glyph
21775 rather than append it. */
21776 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
21780 /* Make room for the new glyph. */
21781 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
21783 glyph
= it
->glyph_row
->glyphs
[it
->area
];
21785 glyph
->charpos
= it
->cmp_it
.charpos
;
21786 glyph
->object
= it
->object
;
21787 glyph
->pixel_width
= it
->pixel_width
;
21788 glyph
->ascent
= it
->ascent
;
21789 glyph
->descent
= it
->descent
;
21790 glyph
->voffset
= it
->voffset
;
21791 glyph
->type
= COMPOSITE_GLYPH
;
21792 if (it
->cmp_it
.ch
< 0)
21794 glyph
->u
.cmp
.automatic
= 0;
21795 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21796 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
21800 glyph
->u
.cmp
.automatic
= 1;
21801 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21802 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
21803 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
21805 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21806 glyph
->multibyte_p
= it
->multibyte_p
;
21807 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21808 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21809 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21810 || it
->phys_descent
> it
->descent
);
21811 glyph
->padding_p
= 0;
21812 glyph
->glyph_not_available_p
= 0;
21813 glyph
->face_id
= it
->face_id
;
21814 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21817 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21818 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21820 glyph
->bidi_type
= it
->bidi_it
.type
;
21822 ++it
->glyph_row
->used
[area
];
21825 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21829 /* Change IT->ascent and IT->height according to the setting of
21833 take_vertical_position_into_account (struct it
*it
)
21837 if (it
->voffset
< 0)
21838 /* Increase the ascent so that we can display the text higher
21840 it
->ascent
-= it
->voffset
;
21842 /* Increase the descent so that we can display the text lower
21844 it
->descent
+= it
->voffset
;
21849 /* Produce glyphs/get display metrics for the image IT is loaded with.
21850 See the description of struct display_iterator in dispextern.h for
21851 an overview of struct display_iterator. */
21854 produce_image_glyph (struct it
*it
)
21858 int glyph_ascent
, crop
;
21859 struct glyph_slice slice
;
21861 xassert (it
->what
== IT_IMAGE
);
21863 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21865 /* Make sure X resources of the face is loaded. */
21866 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21868 if (it
->image_id
< 0)
21870 /* Fringe bitmap. */
21871 it
->ascent
= it
->phys_ascent
= 0;
21872 it
->descent
= it
->phys_descent
= 0;
21873 it
->pixel_width
= 0;
21878 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
21880 /* Make sure X resources of the image is loaded. */
21881 prepare_image_for_display (it
->f
, img
);
21883 slice
.x
= slice
.y
= 0;
21884 slice
.width
= img
->width
;
21885 slice
.height
= img
->height
;
21887 if (INTEGERP (it
->slice
.x
))
21888 slice
.x
= XINT (it
->slice
.x
);
21889 else if (FLOATP (it
->slice
.x
))
21890 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
21892 if (INTEGERP (it
->slice
.y
))
21893 slice
.y
= XINT (it
->slice
.y
);
21894 else if (FLOATP (it
->slice
.y
))
21895 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
21897 if (INTEGERP (it
->slice
.width
))
21898 slice
.width
= XINT (it
->slice
.width
);
21899 else if (FLOATP (it
->slice
.width
))
21900 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
21902 if (INTEGERP (it
->slice
.height
))
21903 slice
.height
= XINT (it
->slice
.height
);
21904 else if (FLOATP (it
->slice
.height
))
21905 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
21907 if (slice
.x
>= img
->width
)
21908 slice
.x
= img
->width
;
21909 if (slice
.y
>= img
->height
)
21910 slice
.y
= img
->height
;
21911 if (slice
.x
+ slice
.width
>= img
->width
)
21912 slice
.width
= img
->width
- slice
.x
;
21913 if (slice
.y
+ slice
.height
> img
->height
)
21914 slice
.height
= img
->height
- slice
.y
;
21916 if (slice
.width
== 0 || slice
.height
== 0)
21919 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
21921 it
->descent
= slice
.height
- glyph_ascent
;
21923 it
->descent
+= img
->vmargin
;
21924 if (slice
.y
+ slice
.height
== img
->height
)
21925 it
->descent
+= img
->vmargin
;
21926 it
->phys_descent
= it
->descent
;
21928 it
->pixel_width
= slice
.width
;
21930 it
->pixel_width
+= img
->hmargin
;
21931 if (slice
.x
+ slice
.width
== img
->width
)
21932 it
->pixel_width
+= img
->hmargin
;
21934 /* It's quite possible for images to have an ascent greater than
21935 their height, so don't get confused in that case. */
21936 if (it
->descent
< 0)
21941 if (face
->box
!= FACE_NO_BOX
)
21943 if (face
->box_line_width
> 0)
21946 it
->ascent
+= face
->box_line_width
;
21947 if (slice
.y
+ slice
.height
== img
->height
)
21948 it
->descent
+= face
->box_line_width
;
21951 if (it
->start_of_box_run_p
&& slice
.x
== 0)
21952 it
->pixel_width
+= eabs (face
->box_line_width
);
21953 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
21954 it
->pixel_width
+= eabs (face
->box_line_width
);
21957 take_vertical_position_into_account (it
);
21959 /* Automatically crop wide image glyphs at right edge so we can
21960 draw the cursor on same display row. */
21961 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
21962 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
21964 it
->pixel_width
-= crop
;
21965 slice
.width
-= crop
;
21970 struct glyph
*glyph
;
21971 enum glyph_row_area area
= it
->area
;
21973 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21974 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21976 glyph
->charpos
= CHARPOS (it
->position
);
21977 glyph
->object
= it
->object
;
21978 glyph
->pixel_width
= it
->pixel_width
;
21979 glyph
->ascent
= glyph_ascent
;
21980 glyph
->descent
= it
->descent
;
21981 glyph
->voffset
= it
->voffset
;
21982 glyph
->type
= IMAGE_GLYPH
;
21983 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21984 glyph
->multibyte_p
= it
->multibyte_p
;
21985 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21986 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21987 glyph
->overlaps_vertically_p
= 0;
21988 glyph
->padding_p
= 0;
21989 glyph
->glyph_not_available_p
= 0;
21990 glyph
->face_id
= it
->face_id
;
21991 glyph
->u
.img_id
= img
->id
;
21992 glyph
->slice
.img
= slice
;
21993 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21996 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21997 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21999 glyph
->bidi_type
= it
->bidi_it
.type
;
22001 ++it
->glyph_row
->used
[area
];
22004 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22009 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
22010 of the glyph, WIDTH and HEIGHT are the width and height of the
22011 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
22014 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
22015 int width
, int height
, int ascent
)
22017 struct glyph
*glyph
;
22018 enum glyph_row_area area
= it
->area
;
22020 xassert (ascent
>= 0 && ascent
<= height
);
22022 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22023 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22025 /* If the glyph row is reversed, we need to prepend the glyph
22026 rather than append it. */
22027 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22031 /* Make room for the additional glyph. */
22032 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22034 glyph
= it
->glyph_row
->glyphs
[area
];
22036 glyph
->charpos
= CHARPOS (it
->position
);
22037 glyph
->object
= object
;
22038 glyph
->pixel_width
= width
;
22039 glyph
->ascent
= ascent
;
22040 glyph
->descent
= height
- ascent
;
22041 glyph
->voffset
= it
->voffset
;
22042 glyph
->type
= STRETCH_GLYPH
;
22043 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22044 glyph
->multibyte_p
= it
->multibyte_p
;
22045 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22046 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22047 glyph
->overlaps_vertically_p
= 0;
22048 glyph
->padding_p
= 0;
22049 glyph
->glyph_not_available_p
= 0;
22050 glyph
->face_id
= it
->face_id
;
22051 glyph
->u
.stretch
.ascent
= ascent
;
22052 glyph
->u
.stretch
.height
= height
;
22053 glyph
->slice
.img
= null_glyph_slice
;
22054 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22057 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22058 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22060 glyph
->bidi_type
= it
->bidi_it
.type
;
22064 glyph
->resolved_level
= 0;
22065 glyph
->bidi_type
= UNKNOWN_BT
;
22067 ++it
->glyph_row
->used
[area
];
22070 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22074 /* Produce a stretch glyph for iterator IT. IT->object is the value
22075 of the glyph property displayed. The value must be a list
22076 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
22079 1. `:width WIDTH' specifies that the space should be WIDTH *
22080 canonical char width wide. WIDTH may be an integer or floating
22083 2. `:relative-width FACTOR' specifies that the width of the stretch
22084 should be computed from the width of the first character having the
22085 `glyph' property, and should be FACTOR times that width.
22087 3. `:align-to HPOS' specifies that the space should be wide enough
22088 to reach HPOS, a value in canonical character units.
22090 Exactly one of the above pairs must be present.
22092 4. `:height HEIGHT' specifies that the height of the stretch produced
22093 should be HEIGHT, measured in canonical character units.
22095 5. `:relative-height FACTOR' specifies that the height of the
22096 stretch should be FACTOR times the height of the characters having
22097 the glyph property.
22099 Either none or exactly one of 4 or 5 must be present.
22101 6. `:ascent ASCENT' specifies that ASCENT percent of the height
22102 of the stretch should be used for the ascent of the stretch.
22103 ASCENT must be in the range 0 <= ASCENT <= 100. */
22106 produce_stretch_glyph (struct it
*it
)
22108 /* (space :width WIDTH :height HEIGHT ...) */
22109 Lisp_Object prop
, plist
;
22110 int width
= 0, height
= 0, align_to
= -1;
22111 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
22114 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22115 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22117 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22119 /* List should start with `space'. */
22120 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
22121 plist
= XCDR (it
->object
);
22123 /* Compute the width of the stretch. */
22124 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
22125 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
22127 /* Absolute width `:width WIDTH' specified and valid. */
22128 zero_width_ok_p
= 1;
22131 else if (prop
= Fplist_get (plist
, QCrelative_width
),
22134 /* Relative width `:relative-width FACTOR' specified and valid.
22135 Compute the width of the characters having the `glyph'
22138 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
22141 if (it
->multibyte_p
)
22142 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
22145 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
22146 if (! ASCII_CHAR_P (it2
.c
))
22147 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
22150 it2
.glyph_row
= NULL
;
22151 it2
.what
= IT_CHARACTER
;
22152 x_produce_glyphs (&it2
);
22153 width
= NUMVAL (prop
) * it2
.pixel_width
;
22155 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
22156 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
22158 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
22159 align_to
= (align_to
< 0
22161 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
22162 else if (align_to
< 0)
22163 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
22164 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
22165 zero_width_ok_p
= 1;
22168 /* Nothing specified -> width defaults to canonical char width. */
22169 width
= FRAME_COLUMN_WIDTH (it
->f
);
22171 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
22174 /* Compute height. */
22175 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
22176 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22179 zero_height_ok_p
= 1;
22181 else if (prop
= Fplist_get (plist
, QCrelative_height
),
22183 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
22185 height
= FONT_HEIGHT (font
);
22187 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
22190 /* Compute percentage of height used for ascent. If
22191 `:ascent ASCENT' is present and valid, use that. Otherwise,
22192 derive the ascent from the font in use. */
22193 if (prop
= Fplist_get (plist
, QCascent
),
22194 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
22195 ascent
= height
* NUMVAL (prop
) / 100.0;
22196 else if (!NILP (prop
)
22197 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22198 ascent
= min (max (0, (int)tem
), height
);
22200 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
22202 if (width
> 0 && it
->line_wrap
!= TRUNCATE
22203 && it
->current_x
+ width
> it
->last_visible_x
)
22204 width
= it
->last_visible_x
- it
->current_x
- 1;
22206 if (width
> 0 && height
> 0 && it
->glyph_row
)
22208 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
22209 if (!STRINGP (object
))
22210 object
= it
->w
->buffer
;
22211 append_stretch_glyph (it
, object
, width
, height
, ascent
);
22214 it
->pixel_width
= width
;
22215 it
->ascent
= it
->phys_ascent
= ascent
;
22216 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
22217 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
22219 take_vertical_position_into_account (it
);
22222 /* Calculate line-height and line-spacing properties.
22223 An integer value specifies explicit pixel value.
22224 A float value specifies relative value to current face height.
22225 A cons (float . face-name) specifies relative value to
22226 height of specified face font.
22228 Returns height in pixels, or nil. */
22232 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
22233 int boff
, int override
)
22235 Lisp_Object face_name
= Qnil
;
22236 int ascent
, descent
, height
;
22238 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
22243 face_name
= XCAR (val
);
22245 if (!NUMBERP (val
))
22246 val
= make_number (1);
22247 if (NILP (face_name
))
22249 height
= it
->ascent
+ it
->descent
;
22254 if (NILP (face_name
))
22256 font
= FRAME_FONT (it
->f
);
22257 boff
= FRAME_BASELINE_OFFSET (it
->f
);
22259 else if (EQ (face_name
, Qt
))
22268 face_id
= lookup_named_face (it
->f
, face_name
, 0);
22270 return make_number (-1);
22272 face
= FACE_FROM_ID (it
->f
, face_id
);
22275 return make_number (-1);
22276 boff
= font
->baseline_offset
;
22277 if (font
->vertical_centering
)
22278 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22281 ascent
= FONT_BASE (font
) + boff
;
22282 descent
= FONT_DESCENT (font
) - boff
;
22286 it
->override_ascent
= ascent
;
22287 it
->override_descent
= descent
;
22288 it
->override_boff
= boff
;
22291 height
= ascent
+ descent
;
22295 height
= (int)(XFLOAT_DATA (val
) * height
);
22296 else if (INTEGERP (val
))
22297 height
*= XINT (val
);
22299 return make_number (height
);
22303 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
22304 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
22305 and only if this is for a character for which no font was found.
22307 If the display method (it->glyphless_method) is
22308 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
22309 length of the acronym or the hexadecimal string, UPPER_XOFF and
22310 UPPER_YOFF are pixel offsets for the upper part of the string,
22311 LOWER_XOFF and LOWER_YOFF are for the lower part.
22313 For the other display methods, LEN through LOWER_YOFF are zero. */
22316 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
22317 short upper_xoff
, short upper_yoff
,
22318 short lower_xoff
, short lower_yoff
)
22320 struct glyph
*glyph
;
22321 enum glyph_row_area area
= it
->area
;
22323 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22324 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22326 /* If the glyph row is reversed, we need to prepend the glyph
22327 rather than append it. */
22328 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22332 /* Make room for the additional glyph. */
22333 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22335 glyph
= it
->glyph_row
->glyphs
[area
];
22337 glyph
->charpos
= CHARPOS (it
->position
);
22338 glyph
->object
= it
->object
;
22339 glyph
->pixel_width
= it
->pixel_width
;
22340 glyph
->ascent
= it
->ascent
;
22341 glyph
->descent
= it
->descent
;
22342 glyph
->voffset
= it
->voffset
;
22343 glyph
->type
= GLYPHLESS_GLYPH
;
22344 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
22345 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
22346 glyph
->u
.glyphless
.len
= len
;
22347 glyph
->u
.glyphless
.ch
= it
->c
;
22348 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
22349 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
22350 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
22351 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
22352 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22353 glyph
->multibyte_p
= it
->multibyte_p
;
22354 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22355 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22356 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22357 || it
->phys_descent
> it
->descent
);
22358 glyph
->padding_p
= 0;
22359 glyph
->glyph_not_available_p
= 0;
22360 glyph
->face_id
= face_id
;
22361 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22364 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22365 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22367 glyph
->bidi_type
= it
->bidi_it
.type
;
22369 ++it
->glyph_row
->used
[area
];
22372 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22376 /* Produce a glyph for a glyphless character for iterator IT.
22377 IT->glyphless_method specifies which method to use for displaying
22378 the character. See the description of enum
22379 glyphless_display_method in dispextern.h for the detail.
22381 FOR_NO_FONT is nonzero if and only if this is for a character for
22382 which no font was found. ACRONYM, if non-nil, is an acronym string
22383 for the character. */
22386 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
22391 int base_width
, base_height
, width
, height
;
22392 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
22395 /* Get the metrics of the base font. We always refer to the current
22397 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
22398 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22399 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
22400 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
22401 base_height
= it
->ascent
+ it
->descent
;
22402 base_width
= font
->average_width
;
22404 /* Get a face ID for the glyph by utilizing a cache (the same way as
22405 doen for `escape-glyph' in get_next_display_element). */
22406 if (it
->f
== last_glyphless_glyph_frame
22407 && it
->face_id
== last_glyphless_glyph_face_id
)
22409 face_id
= last_glyphless_glyph_merged_face_id
;
22413 /* Merge the `glyphless-char' face into the current face. */
22414 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
22415 last_glyphless_glyph_frame
= it
->f
;
22416 last_glyphless_glyph_face_id
= it
->face_id
;
22417 last_glyphless_glyph_merged_face_id
= face_id
;
22420 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
22422 it
->pixel_width
= THIN_SPACE_WIDTH
;
22424 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22426 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
22428 width
= CHAR_WIDTH (it
->c
);
22431 else if (width
> 4)
22433 it
->pixel_width
= base_width
* width
;
22435 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22441 unsigned int code
[6];
22443 int ascent
, descent
;
22444 struct font_metrics metrics_upper
, metrics_lower
;
22446 face
= FACE_FROM_ID (it
->f
, face_id
);
22447 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22448 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22450 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
22452 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
22453 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
22454 if (CONSP (acronym
))
22455 acronym
= XCAR (acronym
);
22456 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
22460 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
22461 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
22464 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
22465 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
22466 upper_len
= (len
+ 1) / 2;
22467 font
->driver
->text_extents (font
, code
, upper_len
,
22469 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
22474 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
22475 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
22476 upper_xoff
= upper_yoff
= 2; /* the typical case */
22477 if (base_width
>= width
)
22479 /* Align the upper to the left, the lower to the right. */
22480 it
->pixel_width
= base_width
;
22481 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
22485 /* Center the shorter one. */
22486 it
->pixel_width
= width
;
22487 if (metrics_upper
.width
>= metrics_lower
.width
)
22488 lower_xoff
= (width
- metrics_lower
.width
) / 2;
22491 /* FIXME: This code doesn't look right. It formerly was
22492 missing the "lower_xoff = 0;", which couldn't have
22493 been right since it left lower_xoff uninitialized. */
22495 upper_xoff
= (width
- metrics_upper
.width
) / 2;
22499 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
22500 top, bottom, and between upper and lower strings. */
22501 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
22502 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
22503 /* Center vertically.
22504 H:base_height, D:base_descent
22505 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
22507 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
22508 descent = D - H/2 + h/2;
22509 lower_yoff = descent - 2 - ld;
22510 upper_yoff = lower_yoff - la - 1 - ud; */
22511 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
22512 descent
= it
->descent
- (base_height
- height
) / 2;
22513 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
22514 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
22515 - metrics_upper
.descent
);
22516 /* Don't make the height shorter than the base height. */
22517 if (height
> base_height
)
22519 it
->ascent
= ascent
;
22520 it
->descent
= descent
;
22524 it
->phys_ascent
= it
->ascent
;
22525 it
->phys_descent
= it
->descent
;
22527 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
22528 upper_xoff
, upper_yoff
,
22529 lower_xoff
, lower_yoff
);
22531 take_vertical_position_into_account (it
);
22536 Produce glyphs/get display metrics for the display element IT is
22537 loaded with. See the description of struct it in dispextern.h
22538 for an overview of struct it. */
22541 x_produce_glyphs (struct it
*it
)
22543 int extra_line_spacing
= it
->extra_line_spacing
;
22545 it
->glyph_not_available_p
= 0;
22547 if (it
->what
== IT_CHARACTER
)
22550 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22551 struct font
*font
= face
->font
;
22552 struct font_metrics
*pcm
= NULL
;
22553 int boff
; /* baseline offset */
22557 /* When no suitable font is found, display this character by
22558 the method specified in the first extra slot of
22559 Vglyphless_char_display. */
22560 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
22562 xassert (it
->what
== IT_GLYPHLESS
);
22563 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
22567 boff
= font
->baseline_offset
;
22568 if (font
->vertical_centering
)
22569 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22571 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
22577 if (it
->override_ascent
>= 0)
22579 it
->ascent
= it
->override_ascent
;
22580 it
->descent
= it
->override_descent
;
22581 boff
= it
->override_boff
;
22585 it
->ascent
= FONT_BASE (font
) + boff
;
22586 it
->descent
= FONT_DESCENT (font
) - boff
;
22589 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
22591 pcm
= get_per_char_metric (font
, &char2b
);
22592 if (pcm
->width
== 0
22593 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
22599 it
->phys_ascent
= pcm
->ascent
+ boff
;
22600 it
->phys_descent
= pcm
->descent
- boff
;
22601 it
->pixel_width
= pcm
->width
;
22605 it
->glyph_not_available_p
= 1;
22606 it
->phys_ascent
= it
->ascent
;
22607 it
->phys_descent
= it
->descent
;
22608 it
->pixel_width
= font
->space_width
;
22611 if (it
->constrain_row_ascent_descent_p
)
22613 if (it
->descent
> it
->max_descent
)
22615 it
->ascent
+= it
->descent
- it
->max_descent
;
22616 it
->descent
= it
->max_descent
;
22618 if (it
->ascent
> it
->max_ascent
)
22620 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22621 it
->ascent
= it
->max_ascent
;
22623 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22624 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22625 extra_line_spacing
= 0;
22628 /* If this is a space inside a region of text with
22629 `space-width' property, change its width. */
22630 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
22632 it
->pixel_width
*= XFLOATINT (it
->space_width
);
22634 /* If face has a box, add the box thickness to the character
22635 height. If character has a box line to the left and/or
22636 right, add the box line width to the character's width. */
22637 if (face
->box
!= FACE_NO_BOX
)
22639 int thick
= face
->box_line_width
;
22643 it
->ascent
+= thick
;
22644 it
->descent
+= thick
;
22649 if (it
->start_of_box_run_p
)
22650 it
->pixel_width
+= thick
;
22651 if (it
->end_of_box_run_p
)
22652 it
->pixel_width
+= thick
;
22655 /* If face has an overline, add the height of the overline
22656 (1 pixel) and a 1 pixel margin to the character height. */
22657 if (face
->overline_p
)
22658 it
->ascent
+= overline_margin
;
22660 if (it
->constrain_row_ascent_descent_p
)
22662 if (it
->ascent
> it
->max_ascent
)
22663 it
->ascent
= it
->max_ascent
;
22664 if (it
->descent
> it
->max_descent
)
22665 it
->descent
= it
->max_descent
;
22668 take_vertical_position_into_account (it
);
22670 /* If we have to actually produce glyphs, do it. */
22675 /* Translate a space with a `space-width' property
22676 into a stretch glyph. */
22677 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
22678 / FONT_HEIGHT (font
));
22679 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22680 it
->ascent
+ it
->descent
, ascent
);
22685 /* If characters with lbearing or rbearing are displayed
22686 in this line, record that fact in a flag of the
22687 glyph row. This is used to optimize X output code. */
22688 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
22689 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22691 if (! stretched_p
&& it
->pixel_width
== 0)
22692 /* We assure that all visible glyphs have at least 1-pixel
22694 it
->pixel_width
= 1;
22696 else if (it
->char_to_display
== '\n')
22698 /* A newline has no width, but we need the height of the
22699 line. But if previous part of the line sets a height,
22700 don't increase that height */
22702 Lisp_Object height
;
22703 Lisp_Object total_height
= Qnil
;
22705 it
->override_ascent
= -1;
22706 it
->pixel_width
= 0;
22709 height
= get_it_property (it
, Qline_height
);
22710 /* Split (line-height total-height) list */
22712 && CONSP (XCDR (height
))
22713 && NILP (XCDR (XCDR (height
))))
22715 total_height
= XCAR (XCDR (height
));
22716 height
= XCAR (height
);
22718 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
22720 if (it
->override_ascent
>= 0)
22722 it
->ascent
= it
->override_ascent
;
22723 it
->descent
= it
->override_descent
;
22724 boff
= it
->override_boff
;
22728 it
->ascent
= FONT_BASE (font
) + boff
;
22729 it
->descent
= FONT_DESCENT (font
) - boff
;
22732 if (EQ (height
, Qt
))
22734 if (it
->descent
> it
->max_descent
)
22736 it
->ascent
+= it
->descent
- it
->max_descent
;
22737 it
->descent
= it
->max_descent
;
22739 if (it
->ascent
> it
->max_ascent
)
22741 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22742 it
->ascent
= it
->max_ascent
;
22744 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22745 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22746 it
->constrain_row_ascent_descent_p
= 1;
22747 extra_line_spacing
= 0;
22751 Lisp_Object spacing
;
22753 it
->phys_ascent
= it
->ascent
;
22754 it
->phys_descent
= it
->descent
;
22756 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
22757 && face
->box
!= FACE_NO_BOX
22758 && face
->box_line_width
> 0)
22760 it
->ascent
+= face
->box_line_width
;
22761 it
->descent
+= face
->box_line_width
;
22764 && XINT (height
) > it
->ascent
+ it
->descent
)
22765 it
->ascent
= XINT (height
) - it
->descent
;
22767 if (!NILP (total_height
))
22768 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
22771 spacing
= get_it_property (it
, Qline_spacing
);
22772 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
22774 if (INTEGERP (spacing
))
22776 extra_line_spacing
= XINT (spacing
);
22777 if (!NILP (total_height
))
22778 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
22782 else /* i.e. (it->char_to_display == '\t') */
22784 if (font
->space_width
> 0)
22786 int tab_width
= it
->tab_width
* font
->space_width
;
22787 int x
= it
->current_x
+ it
->continuation_lines_width
;
22788 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
22790 /* If the distance from the current position to the next tab
22791 stop is less than a space character width, use the
22792 tab stop after that. */
22793 if (next_tab_x
- x
< font
->space_width
)
22794 next_tab_x
+= tab_width
;
22796 it
->pixel_width
= next_tab_x
- x
;
22798 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
22799 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22803 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22804 it
->ascent
+ it
->descent
, it
->ascent
);
22809 it
->pixel_width
= 0;
22814 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
22816 /* A static composition.
22818 Note: A composition is represented as one glyph in the
22819 glyph matrix. There are no padding glyphs.
22821 Important note: pixel_width, ascent, and descent are the
22822 values of what is drawn by draw_glyphs (i.e. the values of
22823 the overall glyphs composed). */
22824 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22825 int boff
; /* baseline offset */
22826 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
22827 int glyph_len
= cmp
->glyph_len
;
22828 struct font
*font
= face
->font
;
22832 /* If we have not yet calculated pixel size data of glyphs of
22833 the composition for the current face font, calculate them
22834 now. Theoretically, we have to check all fonts for the
22835 glyphs, but that requires much time and memory space. So,
22836 here we check only the font of the first glyph. This may
22837 lead to incorrect display, but it's very rare, and C-l
22838 (recenter-top-bottom) can correct the display anyway. */
22839 if (! cmp
->font
|| cmp
->font
!= font
)
22841 /* Ascent and descent of the font of the first character
22842 of this composition (adjusted by baseline offset).
22843 Ascent and descent of overall glyphs should not be less
22844 than these, respectively. */
22845 int font_ascent
, font_descent
, font_height
;
22846 /* Bounding box of the overall glyphs. */
22847 int leftmost
, rightmost
, lowest
, highest
;
22848 int lbearing
, rbearing
;
22849 int i
, width
, ascent
, descent
;
22850 int left_padded
= 0, right_padded
= 0;
22851 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
22853 struct font_metrics
*pcm
;
22854 int font_not_found_p
;
22857 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
22858 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
22860 if (glyph_len
< cmp
->glyph_len
)
22862 for (i
= 0; i
< glyph_len
; i
++)
22864 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
22866 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22871 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
22872 : IT_CHARPOS (*it
));
22873 /* If no suitable font is found, use the default font. */
22874 font_not_found_p
= font
== NULL
;
22875 if (font_not_found_p
)
22877 face
= face
->ascii_face
;
22880 boff
= font
->baseline_offset
;
22881 if (font
->vertical_centering
)
22882 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22883 font_ascent
= FONT_BASE (font
) + boff
;
22884 font_descent
= FONT_DESCENT (font
) - boff
;
22885 font_height
= FONT_HEIGHT (font
);
22887 cmp
->font
= (void *) font
;
22890 if (! font_not_found_p
)
22892 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
22894 pcm
= get_per_char_metric (font
, &char2b
);
22897 /* Initialize the bounding box. */
22900 width
= pcm
->width
;
22901 ascent
= pcm
->ascent
;
22902 descent
= pcm
->descent
;
22903 lbearing
= pcm
->lbearing
;
22904 rbearing
= pcm
->rbearing
;
22908 width
= font
->space_width
;
22909 ascent
= FONT_BASE (font
);
22910 descent
= FONT_DESCENT (font
);
22917 lowest
= - descent
+ boff
;
22918 highest
= ascent
+ boff
;
22920 if (! font_not_found_p
22921 && font
->default_ascent
22922 && CHAR_TABLE_P (Vuse_default_ascent
)
22923 && !NILP (Faref (Vuse_default_ascent
,
22924 make_number (it
->char_to_display
))))
22925 highest
= font
->default_ascent
+ boff
;
22927 /* Draw the first glyph at the normal position. It may be
22928 shifted to right later if some other glyphs are drawn
22930 cmp
->offsets
[i
* 2] = 0;
22931 cmp
->offsets
[i
* 2 + 1] = boff
;
22932 cmp
->lbearing
= lbearing
;
22933 cmp
->rbearing
= rbearing
;
22935 /* Set cmp->offsets for the remaining glyphs. */
22936 for (i
++; i
< glyph_len
; i
++)
22938 int left
, right
, btm
, top
;
22939 int ch
= COMPOSITION_GLYPH (cmp
, i
);
22941 struct face
*this_face
;
22945 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
22946 this_face
= FACE_FROM_ID (it
->f
, face_id
);
22947 font
= this_face
->font
;
22953 get_char_face_and_encoding (it
->f
, ch
, face_id
,
22955 pcm
= get_per_char_metric (font
, &char2b
);
22958 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22961 width
= pcm
->width
;
22962 ascent
= pcm
->ascent
;
22963 descent
= pcm
->descent
;
22964 lbearing
= pcm
->lbearing
;
22965 rbearing
= pcm
->rbearing
;
22966 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
22968 /* Relative composition with or without
22969 alternate chars. */
22970 left
= (leftmost
+ rightmost
- width
) / 2;
22971 btm
= - descent
+ boff
;
22972 if (font
->relative_compose
22973 && (! CHAR_TABLE_P (Vignore_relative_composition
)
22974 || NILP (Faref (Vignore_relative_composition
,
22975 make_number (ch
)))))
22978 if (- descent
>= font
->relative_compose
)
22979 /* One extra pixel between two glyphs. */
22981 else if (ascent
<= 0)
22982 /* One extra pixel between two glyphs. */
22983 btm
= lowest
- 1 - ascent
- descent
;
22988 /* A composition rule is specified by an integer
22989 value that encodes global and new reference
22990 points (GREF and NREF). GREF and NREF are
22991 specified by numbers as below:
22993 0---1---2 -- ascent
22997 9--10--11 -- center
22999 ---3---4---5--- baseline
23001 6---7---8 -- descent
23003 int rule
= COMPOSITION_RULE (cmp
, i
);
23004 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
23006 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
23007 grefx
= gref
% 3, nrefx
= nref
% 3;
23008 grefy
= gref
/ 3, nrefy
= nref
/ 3;
23010 xoff
= font_height
* (xoff
- 128) / 256;
23012 yoff
= font_height
* (yoff
- 128) / 256;
23015 + grefx
* (rightmost
- leftmost
) / 2
23016 - nrefx
* width
/ 2
23019 btm
= ((grefy
== 0 ? highest
23021 : grefy
== 2 ? lowest
23022 : (highest
+ lowest
) / 2)
23023 - (nrefy
== 0 ? ascent
+ descent
23024 : nrefy
== 1 ? descent
- boff
23026 : (ascent
+ descent
) / 2)
23030 cmp
->offsets
[i
* 2] = left
;
23031 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
23033 /* Update the bounding box of the overall glyphs. */
23036 right
= left
+ width
;
23037 if (left
< leftmost
)
23039 if (right
> rightmost
)
23042 top
= btm
+ descent
+ ascent
;
23048 if (cmp
->lbearing
> left
+ lbearing
)
23049 cmp
->lbearing
= left
+ lbearing
;
23050 if (cmp
->rbearing
< left
+ rbearing
)
23051 cmp
->rbearing
= left
+ rbearing
;
23055 /* If there are glyphs whose x-offsets are negative,
23056 shift all glyphs to the right and make all x-offsets
23060 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23061 cmp
->offsets
[i
* 2] -= leftmost
;
23062 rightmost
-= leftmost
;
23063 cmp
->lbearing
-= leftmost
;
23064 cmp
->rbearing
-= leftmost
;
23067 if (left_padded
&& cmp
->lbearing
< 0)
23069 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23070 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
23071 rightmost
-= cmp
->lbearing
;
23072 cmp
->rbearing
-= cmp
->lbearing
;
23075 if (right_padded
&& rightmost
< cmp
->rbearing
)
23077 rightmost
= cmp
->rbearing
;
23080 cmp
->pixel_width
= rightmost
;
23081 cmp
->ascent
= highest
;
23082 cmp
->descent
= - lowest
;
23083 if (cmp
->ascent
< font_ascent
)
23084 cmp
->ascent
= font_ascent
;
23085 if (cmp
->descent
< font_descent
)
23086 cmp
->descent
= font_descent
;
23090 && (cmp
->lbearing
< 0
23091 || cmp
->rbearing
> cmp
->pixel_width
))
23092 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23094 it
->pixel_width
= cmp
->pixel_width
;
23095 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
23096 it
->descent
= it
->phys_descent
= cmp
->descent
;
23097 if (face
->box
!= FACE_NO_BOX
)
23099 int thick
= face
->box_line_width
;
23103 it
->ascent
+= thick
;
23104 it
->descent
+= thick
;
23109 if (it
->start_of_box_run_p
)
23110 it
->pixel_width
+= thick
;
23111 if (it
->end_of_box_run_p
)
23112 it
->pixel_width
+= thick
;
23115 /* If face has an overline, add the height of the overline
23116 (1 pixel) and a 1 pixel margin to the character height. */
23117 if (face
->overline_p
)
23118 it
->ascent
+= overline_margin
;
23120 take_vertical_position_into_account (it
);
23121 if (it
->ascent
< 0)
23123 if (it
->descent
< 0)
23127 append_composite_glyph (it
);
23129 else if (it
->what
== IT_COMPOSITION
)
23131 /* A dynamic (automatic) composition. */
23132 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23133 Lisp_Object gstring
;
23134 struct font_metrics metrics
;
23136 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
23138 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
23141 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
23142 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23143 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
23144 it
->descent
= it
->phys_descent
= metrics
.descent
;
23145 if (face
->box
!= FACE_NO_BOX
)
23147 int thick
= face
->box_line_width
;
23151 it
->ascent
+= thick
;
23152 it
->descent
+= thick
;
23157 if (it
->start_of_box_run_p
)
23158 it
->pixel_width
+= thick
;
23159 if (it
->end_of_box_run_p
)
23160 it
->pixel_width
+= thick
;
23162 /* If face has an overline, add the height of the overline
23163 (1 pixel) and a 1 pixel margin to the character height. */
23164 if (face
->overline_p
)
23165 it
->ascent
+= overline_margin
;
23166 take_vertical_position_into_account (it
);
23167 if (it
->ascent
< 0)
23169 if (it
->descent
< 0)
23173 append_composite_glyph (it
);
23175 else if (it
->what
== IT_GLYPHLESS
)
23176 produce_glyphless_glyph (it
, 0, Qnil
);
23177 else if (it
->what
== IT_IMAGE
)
23178 produce_image_glyph (it
);
23179 else if (it
->what
== IT_STRETCH
)
23180 produce_stretch_glyph (it
);
23183 /* Accumulate dimensions. Note: can't assume that it->descent > 0
23184 because this isn't true for images with `:ascent 100'. */
23185 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
23186 if (it
->area
== TEXT_AREA
)
23187 it
->current_x
+= it
->pixel_width
;
23189 if (extra_line_spacing
> 0)
23191 it
->descent
+= extra_line_spacing
;
23192 if (extra_line_spacing
> it
->max_extra_line_spacing
)
23193 it
->max_extra_line_spacing
= extra_line_spacing
;
23196 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
23197 it
->max_descent
= max (it
->max_descent
, it
->descent
);
23198 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
23199 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
23203 Output LEN glyphs starting at START at the nominal cursor position.
23204 Advance the nominal cursor over the text. The global variable
23205 updated_window contains the window being updated, updated_row is
23206 the glyph row being updated, and updated_area is the area of that
23207 row being updated. */
23210 x_write_glyphs (struct glyph
*start
, int len
)
23214 xassert (updated_window
&& updated_row
);
23217 /* Write glyphs. */
23219 hpos
= start
- updated_row
->glyphs
[updated_area
];
23220 x
= draw_glyphs (updated_window
, output_cursor
.x
,
23221 updated_row
, updated_area
,
23223 DRAW_NORMAL_TEXT
, 0);
23225 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
23226 if (updated_area
== TEXT_AREA
23227 && updated_window
->phys_cursor_on_p
23228 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
23229 && updated_window
->phys_cursor
.hpos
>= hpos
23230 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
23231 updated_window
->phys_cursor_on_p
= 0;
23235 /* Advance the output cursor. */
23236 output_cursor
.hpos
+= len
;
23237 output_cursor
.x
= x
;
23242 Insert LEN glyphs from START at the nominal cursor position. */
23245 x_insert_glyphs (struct glyph
*start
, int len
)
23249 int line_height
, shift_by_width
, shifted_region_width
;
23250 struct glyph_row
*row
;
23251 struct glyph
*glyph
;
23252 int frame_x
, frame_y
;
23255 xassert (updated_window
&& updated_row
);
23257 w
= updated_window
;
23258 f
= XFRAME (WINDOW_FRAME (w
));
23260 /* Get the height of the line we are in. */
23262 line_height
= row
->height
;
23264 /* Get the width of the glyphs to insert. */
23265 shift_by_width
= 0;
23266 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
23267 shift_by_width
+= glyph
->pixel_width
;
23269 /* Get the width of the region to shift right. */
23270 shifted_region_width
= (window_box_width (w
, updated_area
)
23275 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
23276 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
23278 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
23279 line_height
, shift_by_width
);
23281 /* Write the glyphs. */
23282 hpos
= start
- row
->glyphs
[updated_area
];
23283 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
23285 DRAW_NORMAL_TEXT
, 0);
23287 /* Advance the output cursor. */
23288 output_cursor
.hpos
+= len
;
23289 output_cursor
.x
+= shift_by_width
;
23295 Erase the current text line from the nominal cursor position
23296 (inclusive) to pixel column TO_X (exclusive). The idea is that
23297 everything from TO_X onward is already erased.
23299 TO_X is a pixel position relative to updated_area of
23300 updated_window. TO_X == -1 means clear to the end of this area. */
23303 x_clear_end_of_line (int to_x
)
23306 struct window
*w
= updated_window
;
23307 int max_x
, min_y
, max_y
;
23308 int from_x
, from_y
, to_y
;
23310 xassert (updated_window
&& updated_row
);
23311 f
= XFRAME (w
->frame
);
23313 if (updated_row
->full_width_p
)
23314 max_x
= WINDOW_TOTAL_WIDTH (w
);
23316 max_x
= window_box_width (w
, updated_area
);
23317 max_y
= window_text_bottom_y (w
);
23319 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
23320 of window. For TO_X > 0, truncate to end of drawing area. */
23326 to_x
= min (to_x
, max_x
);
23328 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
23330 /* Notice if the cursor will be cleared by this operation. */
23331 if (!updated_row
->full_width_p
)
23332 notice_overwritten_cursor (w
, updated_area
,
23333 output_cursor
.x
, -1,
23335 MATRIX_ROW_BOTTOM_Y (updated_row
));
23337 from_x
= output_cursor
.x
;
23339 /* Translate to frame coordinates. */
23340 if (updated_row
->full_width_p
)
23342 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
23343 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
23347 int area_left
= window_box_left (w
, updated_area
);
23348 from_x
+= area_left
;
23352 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
23353 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
23354 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
23356 /* Prevent inadvertently clearing to end of the X window. */
23357 if (to_x
> from_x
&& to_y
> from_y
)
23360 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
23361 to_x
- from_x
, to_y
- from_y
);
23366 #endif /* HAVE_WINDOW_SYSTEM */
23370 /***********************************************************************
23372 ***********************************************************************/
23374 /* Value is the internal representation of the specified cursor type
23375 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
23376 of the bar cursor. */
23378 static enum text_cursor_kinds
23379 get_specified_cursor_type (Lisp_Object arg
, int *width
)
23381 enum text_cursor_kinds type
;
23386 if (EQ (arg
, Qbox
))
23387 return FILLED_BOX_CURSOR
;
23389 if (EQ (arg
, Qhollow
))
23390 return HOLLOW_BOX_CURSOR
;
23392 if (EQ (arg
, Qbar
))
23399 && EQ (XCAR (arg
), Qbar
)
23400 && INTEGERP (XCDR (arg
))
23401 && XINT (XCDR (arg
)) >= 0)
23403 *width
= XINT (XCDR (arg
));
23407 if (EQ (arg
, Qhbar
))
23410 return HBAR_CURSOR
;
23414 && EQ (XCAR (arg
), Qhbar
)
23415 && INTEGERP (XCDR (arg
))
23416 && XINT (XCDR (arg
)) >= 0)
23418 *width
= XINT (XCDR (arg
));
23419 return HBAR_CURSOR
;
23422 /* Treat anything unknown as "hollow box cursor".
23423 It was bad to signal an error; people have trouble fixing
23424 .Xdefaults with Emacs, when it has something bad in it. */
23425 type
= HOLLOW_BOX_CURSOR
;
23430 /* Set the default cursor types for specified frame. */
23432 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
23437 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
23438 FRAME_CURSOR_WIDTH (f
) = width
;
23440 /* By default, set up the blink-off state depending on the on-state. */
23442 tem
= Fassoc (arg
, Vblink_cursor_alist
);
23445 FRAME_BLINK_OFF_CURSOR (f
)
23446 = get_specified_cursor_type (XCDR (tem
), &width
);
23447 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
23450 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
23454 #ifdef HAVE_WINDOW_SYSTEM
23456 /* Return the cursor we want to be displayed in window W. Return
23457 width of bar/hbar cursor through WIDTH arg. Return with
23458 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
23459 (i.e. if the `system caret' should track this cursor).
23461 In a mini-buffer window, we want the cursor only to appear if we
23462 are reading input from this window. For the selected window, we
23463 want the cursor type given by the frame parameter or buffer local
23464 setting of cursor-type. If explicitly marked off, draw no cursor.
23465 In all other cases, we want a hollow box cursor. */
23467 static enum text_cursor_kinds
23468 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
23469 int *active_cursor
)
23471 struct frame
*f
= XFRAME (w
->frame
);
23472 struct buffer
*b
= XBUFFER (w
->buffer
);
23473 int cursor_type
= DEFAULT_CURSOR
;
23474 Lisp_Object alt_cursor
;
23475 int non_selected
= 0;
23477 *active_cursor
= 1;
23480 if (cursor_in_echo_area
23481 && FRAME_HAS_MINIBUF_P (f
)
23482 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
23484 if (w
== XWINDOW (echo_area_window
))
23486 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
23488 *width
= FRAME_CURSOR_WIDTH (f
);
23489 return FRAME_DESIRED_CURSOR (f
);
23492 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
23495 *active_cursor
= 0;
23499 /* Detect a nonselected window or nonselected frame. */
23500 else if (w
!= XWINDOW (f
->selected_window
)
23501 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
23503 *active_cursor
= 0;
23505 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
23511 /* Never display a cursor in a window in which cursor-type is nil. */
23512 if (NILP (BVAR (b
, cursor_type
)))
23515 /* Get the normal cursor type for this window. */
23516 if (EQ (BVAR (b
, cursor_type
), Qt
))
23518 cursor_type
= FRAME_DESIRED_CURSOR (f
);
23519 *width
= FRAME_CURSOR_WIDTH (f
);
23522 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
23524 /* Use cursor-in-non-selected-windows instead
23525 for non-selected window or frame. */
23528 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
23529 if (!EQ (Qt
, alt_cursor
))
23530 return get_specified_cursor_type (alt_cursor
, width
);
23531 /* t means modify the normal cursor type. */
23532 if (cursor_type
== FILLED_BOX_CURSOR
)
23533 cursor_type
= HOLLOW_BOX_CURSOR
;
23534 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
23536 return cursor_type
;
23539 /* Use normal cursor if not blinked off. */
23540 if (!w
->cursor_off_p
)
23542 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23544 if (cursor_type
== FILLED_BOX_CURSOR
)
23546 /* Using a block cursor on large images can be very annoying.
23547 So use a hollow cursor for "large" images.
23548 If image is not transparent (no mask), also use hollow cursor. */
23549 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23550 if (img
!= NULL
&& IMAGEP (img
->spec
))
23552 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
23553 where N = size of default frame font size.
23554 This should cover most of the "tiny" icons people may use. */
23556 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
23557 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
23558 cursor_type
= HOLLOW_BOX_CURSOR
;
23561 else if (cursor_type
!= NO_CURSOR
)
23563 /* Display current only supports BOX and HOLLOW cursors for images.
23564 So for now, unconditionally use a HOLLOW cursor when cursor is
23565 not a solid box cursor. */
23566 cursor_type
= HOLLOW_BOX_CURSOR
;
23569 return cursor_type
;
23572 /* Cursor is blinked off, so determine how to "toggle" it. */
23574 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
23575 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
23576 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
23578 /* Then see if frame has specified a specific blink off cursor type. */
23579 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
23581 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
23582 return FRAME_BLINK_OFF_CURSOR (f
);
23586 /* Some people liked having a permanently visible blinking cursor,
23587 while others had very strong opinions against it. So it was
23588 decided to remove it. KFS 2003-09-03 */
23590 /* Finally perform built-in cursor blinking:
23591 filled box <-> hollow box
23592 wide [h]bar <-> narrow [h]bar
23593 narrow [h]bar <-> no cursor
23594 other type <-> no cursor */
23596 if (cursor_type
== FILLED_BOX_CURSOR
)
23597 return HOLLOW_BOX_CURSOR
;
23599 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
23602 return cursor_type
;
23610 /* Notice when the text cursor of window W has been completely
23611 overwritten by a drawing operation that outputs glyphs in AREA
23612 starting at X0 and ending at X1 in the line starting at Y0 and
23613 ending at Y1. X coordinates are area-relative. X1 < 0 means all
23614 the rest of the line after X0 has been written. Y coordinates
23615 are window-relative. */
23618 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
23619 int x0
, int x1
, int y0
, int y1
)
23621 int cx0
, cx1
, cy0
, cy1
;
23622 struct glyph_row
*row
;
23624 if (!w
->phys_cursor_on_p
)
23626 if (area
!= TEXT_AREA
)
23629 if (w
->phys_cursor
.vpos
< 0
23630 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
23631 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
23632 !(row
->enabled_p
&& row
->displays_text_p
)))
23635 if (row
->cursor_in_fringe_p
)
23637 row
->cursor_in_fringe_p
= 0;
23638 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
23639 w
->phys_cursor_on_p
= 0;
23643 cx0
= w
->phys_cursor
.x
;
23644 cx1
= cx0
+ w
->phys_cursor_width
;
23645 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
23648 /* The cursor image will be completely removed from the
23649 screen if the output area intersects the cursor area in
23650 y-direction. When we draw in [y0 y1[, and some part of
23651 the cursor is at y < y0, that part must have been drawn
23652 before. When scrolling, the cursor is erased before
23653 actually scrolling, so we don't come here. When not
23654 scrolling, the rows above the old cursor row must have
23655 changed, and in this case these rows must have written
23656 over the cursor image.
23658 Likewise if part of the cursor is below y1, with the
23659 exception of the cursor being in the first blank row at
23660 the buffer and window end because update_text_area
23661 doesn't draw that row. (Except when it does, but
23662 that's handled in update_text_area.) */
23664 cy0
= w
->phys_cursor
.y
;
23665 cy1
= cy0
+ w
->phys_cursor_height
;
23666 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
23669 w
->phys_cursor_on_p
= 0;
23672 #endif /* HAVE_WINDOW_SYSTEM */
23675 /************************************************************************
23677 ************************************************************************/
23679 #ifdef HAVE_WINDOW_SYSTEM
23682 Fix the display of area AREA of overlapping row ROW in window W
23683 with respect to the overlapping part OVERLAPS. */
23686 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
23687 enum glyph_row_area area
, int overlaps
)
23694 for (i
= 0; i
< row
->used
[area
];)
23696 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
23698 int start
= i
, start_x
= x
;
23702 x
+= row
->glyphs
[area
][i
].pixel_width
;
23705 while (i
< row
->used
[area
]
23706 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
23708 draw_glyphs (w
, start_x
, row
, area
,
23710 DRAW_NORMAL_TEXT
, overlaps
);
23714 x
+= row
->glyphs
[area
][i
].pixel_width
;
23724 Draw the cursor glyph of window W in glyph row ROW. See the
23725 comment of draw_glyphs for the meaning of HL. */
23728 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
23729 enum draw_glyphs_face hl
)
23731 /* If cursor hpos is out of bounds, don't draw garbage. This can
23732 happen in mini-buffer windows when switching between echo area
23733 glyphs and mini-buffer. */
23734 if ((row
->reversed_p
23735 ? (w
->phys_cursor
.hpos
>= 0)
23736 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
23738 int on_p
= w
->phys_cursor_on_p
;
23740 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
23741 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
23743 w
->phys_cursor_on_p
= on_p
;
23745 if (hl
== DRAW_CURSOR
)
23746 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23747 /* When we erase the cursor, and ROW is overlapped by other
23748 rows, make sure that these overlapping parts of other rows
23750 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
23752 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23754 if (row
> w
->current_matrix
->rows
23755 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
23756 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
23757 OVERLAPS_ERASED_CURSOR
);
23759 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
23760 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
23761 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
23762 OVERLAPS_ERASED_CURSOR
);
23769 Erase the image of a cursor of window W from the screen. */
23772 erase_phys_cursor (struct window
*w
)
23774 struct frame
*f
= XFRAME (w
->frame
);
23775 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23776 int hpos
= w
->phys_cursor
.hpos
;
23777 int vpos
= w
->phys_cursor
.vpos
;
23778 int mouse_face_here_p
= 0;
23779 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
23780 struct glyph_row
*cursor_row
;
23781 struct glyph
*cursor_glyph
;
23782 enum draw_glyphs_face hl
;
23784 /* No cursor displayed or row invalidated => nothing to do on the
23786 if (w
->phys_cursor_type
== NO_CURSOR
)
23787 goto mark_cursor_off
;
23789 /* VPOS >= active_glyphs->nrows means that window has been resized.
23790 Don't bother to erase the cursor. */
23791 if (vpos
>= active_glyphs
->nrows
)
23792 goto mark_cursor_off
;
23794 /* If row containing cursor is marked invalid, there is nothing we
23796 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
23797 if (!cursor_row
->enabled_p
)
23798 goto mark_cursor_off
;
23800 /* If line spacing is > 0, old cursor may only be partially visible in
23801 window after split-window. So adjust visible height. */
23802 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
23803 window_text_bottom_y (w
) - cursor_row
->y
);
23805 /* If row is completely invisible, don't attempt to delete a cursor which
23806 isn't there. This can happen if cursor is at top of a window, and
23807 we switch to a buffer with a header line in that window. */
23808 if (cursor_row
->visible_height
<= 0)
23809 goto mark_cursor_off
;
23811 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
23812 if (cursor_row
->cursor_in_fringe_p
)
23814 cursor_row
->cursor_in_fringe_p
= 0;
23815 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
23816 goto mark_cursor_off
;
23819 /* This can happen when the new row is shorter than the old one.
23820 In this case, either draw_glyphs or clear_end_of_line
23821 should have cleared the cursor. Note that we wouldn't be
23822 able to erase the cursor in this case because we don't have a
23823 cursor glyph at hand. */
23824 if ((cursor_row
->reversed_p
23825 ? (w
->phys_cursor
.hpos
< 0)
23826 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
23827 goto mark_cursor_off
;
23829 /* If the cursor is in the mouse face area, redisplay that when
23830 we clear the cursor. */
23831 if (! NILP (hlinfo
->mouse_face_window
)
23832 && coords_in_mouse_face_p (w
, hpos
, vpos
)
23833 /* Don't redraw the cursor's spot in mouse face if it is at the
23834 end of a line (on a newline). The cursor appears there, but
23835 mouse highlighting does not. */
23836 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
23837 mouse_face_here_p
= 1;
23839 /* Maybe clear the display under the cursor. */
23840 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
23843 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
23846 cursor_glyph
= get_phys_cursor_glyph (w
);
23847 if (cursor_glyph
== NULL
)
23848 goto mark_cursor_off
;
23850 width
= cursor_glyph
->pixel_width
;
23851 left_x
= window_box_left_offset (w
, TEXT_AREA
);
23852 x
= w
->phys_cursor
.x
;
23854 width
-= left_x
- x
;
23855 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
23856 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
23857 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
23860 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
23863 /* Erase the cursor by redrawing the character underneath it. */
23864 if (mouse_face_here_p
)
23865 hl
= DRAW_MOUSE_FACE
;
23867 hl
= DRAW_NORMAL_TEXT
;
23868 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
23871 w
->phys_cursor_on_p
= 0;
23872 w
->phys_cursor_type
= NO_CURSOR
;
23877 Display or clear cursor of window W. If ON is zero, clear the
23878 cursor. If it is non-zero, display the cursor. If ON is nonzero,
23879 where to put the cursor is specified by HPOS, VPOS, X and Y. */
23882 display_and_set_cursor (struct window
*w
, int on
,
23883 int hpos
, int vpos
, int x
, int y
)
23885 struct frame
*f
= XFRAME (w
->frame
);
23886 int new_cursor_type
;
23887 int new_cursor_width
;
23889 struct glyph_row
*glyph_row
;
23890 struct glyph
*glyph
;
23892 /* This is pointless on invisible frames, and dangerous on garbaged
23893 windows and frames; in the latter case, the frame or window may
23894 be in the midst of changing its size, and x and y may be off the
23896 if (! FRAME_VISIBLE_P (f
)
23897 || FRAME_GARBAGED_P (f
)
23898 || vpos
>= w
->current_matrix
->nrows
23899 || hpos
>= w
->current_matrix
->matrix_w
)
23902 /* If cursor is off and we want it off, return quickly. */
23903 if (!on
&& !w
->phys_cursor_on_p
)
23906 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
23907 /* If cursor row is not enabled, we don't really know where to
23908 display the cursor. */
23909 if (!glyph_row
->enabled_p
)
23911 w
->phys_cursor_on_p
= 0;
23916 if (!glyph_row
->exact_window_width_line_p
23917 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
23918 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
23920 xassert (interrupt_input_blocked
);
23922 /* Set new_cursor_type to the cursor we want to be displayed. */
23923 new_cursor_type
= get_window_cursor_type (w
, glyph
,
23924 &new_cursor_width
, &active_cursor
);
23926 /* If cursor is currently being shown and we don't want it to be or
23927 it is in the wrong place, or the cursor type is not what we want,
23929 if (w
->phys_cursor_on_p
23931 || w
->phys_cursor
.x
!= x
23932 || w
->phys_cursor
.y
!= y
23933 || new_cursor_type
!= w
->phys_cursor_type
23934 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
23935 && new_cursor_width
!= w
->phys_cursor_width
)))
23936 erase_phys_cursor (w
);
23938 /* Don't check phys_cursor_on_p here because that flag is only set
23939 to zero in some cases where we know that the cursor has been
23940 completely erased, to avoid the extra work of erasing the cursor
23941 twice. In other words, phys_cursor_on_p can be 1 and the cursor
23942 still not be visible, or it has only been partly erased. */
23945 w
->phys_cursor_ascent
= glyph_row
->ascent
;
23946 w
->phys_cursor_height
= glyph_row
->height
;
23948 /* Set phys_cursor_.* before x_draw_.* is called because some
23949 of them may need the information. */
23950 w
->phys_cursor
.x
= x
;
23951 w
->phys_cursor
.y
= glyph_row
->y
;
23952 w
->phys_cursor
.hpos
= hpos
;
23953 w
->phys_cursor
.vpos
= vpos
;
23956 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
23957 new_cursor_type
, new_cursor_width
,
23958 on
, active_cursor
);
23962 /* Switch the display of W's cursor on or off, according to the value
23966 update_window_cursor (struct window
*w
, int on
)
23968 /* Don't update cursor in windows whose frame is in the process
23969 of being deleted. */
23970 if (w
->current_matrix
)
23973 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23974 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23980 /* Call update_window_cursor with parameter ON_P on all leaf windows
23981 in the window tree rooted at W. */
23984 update_cursor_in_window_tree (struct window
*w
, int on_p
)
23988 if (!NILP (w
->hchild
))
23989 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
23990 else if (!NILP (w
->vchild
))
23991 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
23993 update_window_cursor (w
, on_p
);
23995 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
24001 Display the cursor on window W, or clear it, according to ON_P.
24002 Don't change the cursor's position. */
24005 x_update_cursor (struct frame
*f
, int on_p
)
24007 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
24012 Clear the cursor of window W to background color, and mark the
24013 cursor as not shown. This is used when the text where the cursor
24014 is about to be rewritten. */
24017 x_clear_cursor (struct window
*w
)
24019 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
24020 update_window_cursor (w
, 0);
24023 #endif /* HAVE_WINDOW_SYSTEM */
24025 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
24028 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
24029 int start_hpos
, int end_hpos
,
24030 enum draw_glyphs_face draw
)
24032 #ifdef HAVE_WINDOW_SYSTEM
24033 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
24035 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
24039 #if defined (HAVE_GPM) || defined (MSDOS)
24040 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
24044 /* Display the active region described by mouse_face_* according to DRAW. */
24047 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
24049 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
24050 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24052 if (/* If window is in the process of being destroyed, don't bother
24054 w
->current_matrix
!= NULL
24055 /* Don't update mouse highlight if hidden */
24056 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
24057 /* Recognize when we are called to operate on rows that don't exist
24058 anymore. This can happen when a window is split. */
24059 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
24061 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
24062 struct glyph_row
*row
, *first
, *last
;
24064 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
24065 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
24067 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
24069 int start_hpos
, end_hpos
, start_x
;
24071 /* For all but the first row, the highlight starts at column 0. */
24074 /* R2L rows have BEG and END in reversed order, but the
24075 screen drawing geometry is always left to right. So
24076 we need to mirror the beginning and end of the
24077 highlighted area in R2L rows. */
24078 if (!row
->reversed_p
)
24080 start_hpos
= hlinfo
->mouse_face_beg_col
;
24081 start_x
= hlinfo
->mouse_face_beg_x
;
24083 else if (row
== last
)
24085 start_hpos
= hlinfo
->mouse_face_end_col
;
24086 start_x
= hlinfo
->mouse_face_end_x
;
24094 else if (row
->reversed_p
&& row
== last
)
24096 start_hpos
= hlinfo
->mouse_face_end_col
;
24097 start_x
= hlinfo
->mouse_face_end_x
;
24107 if (!row
->reversed_p
)
24108 end_hpos
= hlinfo
->mouse_face_end_col
;
24109 else if (row
== first
)
24110 end_hpos
= hlinfo
->mouse_face_beg_col
;
24113 end_hpos
= row
->used
[TEXT_AREA
];
24114 if (draw
== DRAW_NORMAL_TEXT
)
24115 row
->fill_line_p
= 1; /* Clear to end of line */
24118 else if (row
->reversed_p
&& row
== first
)
24119 end_hpos
= hlinfo
->mouse_face_beg_col
;
24122 end_hpos
= row
->used
[TEXT_AREA
];
24123 if (draw
== DRAW_NORMAL_TEXT
)
24124 row
->fill_line_p
= 1; /* Clear to end of line */
24127 if (end_hpos
> start_hpos
)
24129 draw_row_with_mouse_face (w
, start_x
, row
,
24130 start_hpos
, end_hpos
, draw
);
24133 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
24137 #ifdef HAVE_WINDOW_SYSTEM
24138 /* When we've written over the cursor, arrange for it to
24139 be displayed again. */
24140 if (FRAME_WINDOW_P (f
)
24141 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
24144 display_and_set_cursor (w
, 1,
24145 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24146 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24149 #endif /* HAVE_WINDOW_SYSTEM */
24152 #ifdef HAVE_WINDOW_SYSTEM
24153 /* Change the mouse cursor. */
24154 if (FRAME_WINDOW_P (f
))
24156 if (draw
== DRAW_NORMAL_TEXT
24157 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
24158 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
24159 else if (draw
== DRAW_MOUSE_FACE
)
24160 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
24162 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
24164 #endif /* HAVE_WINDOW_SYSTEM */
24168 Clear out the mouse-highlighted active region.
24169 Redraw it un-highlighted first. Value is non-zero if mouse
24170 face was actually drawn unhighlighted. */
24173 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
24177 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
24179 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
24183 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
24184 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
24185 hlinfo
->mouse_face_window
= Qnil
;
24186 hlinfo
->mouse_face_overlay
= Qnil
;
24190 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
24191 within the mouse face on that window. */
24193 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
24195 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
24197 /* Quickly resolve the easy cases. */
24198 if (!(WINDOWP (hlinfo
->mouse_face_window
)
24199 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
24201 if (vpos
< hlinfo
->mouse_face_beg_row
24202 || vpos
> hlinfo
->mouse_face_end_row
)
24204 if (vpos
> hlinfo
->mouse_face_beg_row
24205 && vpos
< hlinfo
->mouse_face_end_row
)
24208 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
24210 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24212 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
24215 else if ((vpos
== hlinfo
->mouse_face_beg_row
24216 && hpos
>= hlinfo
->mouse_face_beg_col
)
24217 || (vpos
== hlinfo
->mouse_face_end_row
24218 && hpos
< hlinfo
->mouse_face_end_col
))
24223 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24225 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
24228 else if ((vpos
== hlinfo
->mouse_face_beg_row
24229 && hpos
<= hlinfo
->mouse_face_beg_col
)
24230 || (vpos
== hlinfo
->mouse_face_end_row
24231 && hpos
> hlinfo
->mouse_face_end_col
))
24239 Non-zero if physical cursor of window W is within mouse face. */
24242 cursor_in_mouse_face_p (struct window
*w
)
24244 return coords_in_mouse_face_p (w
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
);
24249 /* Find the glyph rows START_ROW and END_ROW of window W that display
24250 characters between buffer positions START_CHARPOS and END_CHARPOS
24251 (excluding END_CHARPOS). This is similar to row_containing_pos,
24252 but is more accurate when bidi reordering makes buffer positions
24253 change non-linearly with glyph rows. */
24255 rows_from_pos_range (struct window
*w
,
24256 EMACS_INT start_charpos
, EMACS_INT end_charpos
,
24257 struct glyph_row
**start
, struct glyph_row
**end
)
24259 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24260 int last_y
= window_text_bottom_y (w
);
24261 struct glyph_row
*row
;
24266 while (!first
->enabled_p
24267 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
24270 /* Find the START row. */
24272 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
24275 /* A row can potentially be the START row if the range of the
24276 characters it displays intersects the range
24277 [START_CHARPOS..END_CHARPOS). */
24278 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
24279 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
24280 /* See the commentary in row_containing_pos, for the
24281 explanation of the complicated way to check whether
24282 some position is beyond the end of the characters
24283 displayed by a row. */
24284 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24285 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24286 && !row
->ends_at_zv_p
24287 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
24288 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24289 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24290 && !row
->ends_at_zv_p
24291 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
24293 /* Found a candidate row. Now make sure at least one of the
24294 glyphs it displays has a charpos from the range
24295 [START_CHARPOS..END_CHARPOS).
24297 This is not obvious because bidi reordering could make
24298 buffer positions of a row be 1,2,3,102,101,100, and if we
24299 want to highlight characters in [50..60), we don't want
24300 this row, even though [50..60) does intersect [1..103),
24301 the range of character positions given by the row's start
24302 and end positions. */
24303 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
24304 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
24308 if (BUFFERP (g
->object
)
24309 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24318 /* Find the END row. */
24320 /* If the last row is partially visible, start looking for END
24321 from that row, instead of starting from FIRST. */
24322 && !(row
->enabled_p
24323 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
24325 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
24327 struct glyph_row
*next
= row
+ 1;
24329 if (!next
->enabled_p
24330 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
24331 /* The first row >= START whose range of displayed characters
24332 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
24333 is the row END + 1. */
24334 || (start_charpos
< MATRIX_ROW_START_CHARPOS (next
)
24335 && end_charpos
< MATRIX_ROW_START_CHARPOS (next
))
24336 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24337 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24338 && !next
->ends_at_zv_p
24339 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
24340 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24341 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24342 && !next
->ends_at_zv_p
24343 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
24350 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
24351 but none of the characters it displays are in the range, it is
24353 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
24354 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
24358 if (BUFFERP (g
->object
)
24359 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24372 /* This function sets the mouse_face_* elements of HLINFO, assuming
24373 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
24374 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
24375 for the overlay or run of text properties specifying the mouse
24376 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
24377 before-string and after-string that must also be highlighted.
24378 COVER_STRING, if non-nil, is a display string that may cover some
24379 or all of the highlighted text. */
24382 mouse_face_from_buffer_pos (Lisp_Object window
,
24383 Mouse_HLInfo
*hlinfo
,
24384 EMACS_INT mouse_charpos
,
24385 EMACS_INT start_charpos
,
24386 EMACS_INT end_charpos
,
24387 Lisp_Object before_string
,
24388 Lisp_Object after_string
,
24389 Lisp_Object cover_string
)
24391 struct window
*w
= XWINDOW (window
);
24392 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24393 struct glyph_row
*r1
, *r2
;
24394 struct glyph
*glyph
, *end
;
24395 EMACS_INT ignore
, pos
;
24398 xassert (NILP (cover_string
) || STRINGP (cover_string
));
24399 xassert (NILP (before_string
) || STRINGP (before_string
));
24400 xassert (NILP (after_string
) || STRINGP (after_string
));
24402 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
24403 rows_from_pos_range (w
, start_charpos
, end_charpos
, &r1
, &r2
);
24405 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24406 /* If the before-string or display-string contains newlines,
24407 rows_from_pos_range skips to its last row. Move back. */
24408 if (!NILP (before_string
) || !NILP (cover_string
))
24410 struct glyph_row
*prev
;
24411 while ((prev
= r1
- 1, prev
>= first
)
24412 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
24413 && prev
->used
[TEXT_AREA
] > 0)
24415 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
24416 glyph
= beg
+ prev
->used
[TEXT_AREA
];
24417 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
24419 || !(EQ (glyph
->object
, before_string
)
24420 || EQ (glyph
->object
, cover_string
)))
24427 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24428 hlinfo
->mouse_face_past_end
= 1;
24430 else if (!NILP (after_string
))
24432 /* If the after-string has newlines, advance to its last row. */
24433 struct glyph_row
*next
;
24434 struct glyph_row
*last
24435 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24437 for (next
= r2
+ 1;
24439 && next
->used
[TEXT_AREA
] > 0
24440 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
24444 /* The rest of the display engine assumes that mouse_face_beg_row is
24445 either above below mouse_face_end_row or identical to it. But
24446 with bidi-reordered continued lines, the row for START_CHARPOS
24447 could be below the row for END_CHARPOS. If so, swap the rows and
24448 store them in correct order. */
24451 struct glyph_row
*tem
= r2
;
24457 hlinfo
->mouse_face_beg_y
= r1
->y
;
24458 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
24459 hlinfo
->mouse_face_end_y
= r2
->y
;
24460 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
24462 /* For a bidi-reordered row, the positions of BEFORE_STRING,
24463 AFTER_STRING, COVER_STRING, START_CHARPOS, and END_CHARPOS
24464 could be anywhere in the row and in any order. The strategy
24465 below is to find the leftmost and the rightmost glyph that
24466 belongs to either of these 3 strings, or whose position is
24467 between START_CHARPOS and END_CHARPOS, and highlight all the
24468 glyphs between those two. This may cover more than just the text
24469 between START_CHARPOS and END_CHARPOS if the range of characters
24470 strides the bidi level boundary, e.g. if the beginning is in R2L
24471 text while the end is in L2R text or vice versa. */
24472 if (!r1
->reversed_p
)
24474 /* This row is in a left to right paragraph. Scan it left to
24476 glyph
= r1
->glyphs
[TEXT_AREA
];
24477 end
= glyph
+ r1
->used
[TEXT_AREA
];
24480 /* Skip truncation glyphs at the start of the glyph row. */
24481 if (r1
->displays_text_p
)
24483 && INTEGERP (glyph
->object
)
24484 && glyph
->charpos
< 0;
24486 x
+= glyph
->pixel_width
;
24488 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24489 or COVER_STRING, and the first glyph from buffer whose
24490 position is between START_CHARPOS and END_CHARPOS. */
24492 && !INTEGERP (glyph
->object
)
24493 && !EQ (glyph
->object
, cover_string
)
24494 && !(BUFFERP (glyph
->object
)
24495 && (glyph
->charpos
>= start_charpos
24496 && glyph
->charpos
< end_charpos
));
24499 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24500 are present at buffer positions between START_CHARPOS and
24501 END_CHARPOS, or if they come from an overlay. */
24502 if (EQ (glyph
->object
, before_string
))
24504 pos
= string_buffer_position (before_string
,
24506 /* If pos == 0, it means before_string came from an
24507 overlay, not from a buffer position. */
24508 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24511 else if (EQ (glyph
->object
, after_string
))
24513 pos
= string_buffer_position (after_string
, end_charpos
);
24514 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24517 x
+= glyph
->pixel_width
;
24519 hlinfo
->mouse_face_beg_x
= x
;
24520 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24524 /* This row is in a right to left paragraph. Scan it right to
24528 end
= r1
->glyphs
[TEXT_AREA
] - 1;
24529 glyph
= end
+ r1
->used
[TEXT_AREA
];
24531 /* Skip truncation glyphs at the start of the glyph row. */
24532 if (r1
->displays_text_p
)
24534 && INTEGERP (glyph
->object
)
24535 && glyph
->charpos
< 0;
24539 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24540 or COVER_STRING, and the first glyph from buffer whose
24541 position is between START_CHARPOS and END_CHARPOS. */
24543 && !INTEGERP (glyph
->object
)
24544 && !EQ (glyph
->object
, cover_string
)
24545 && !(BUFFERP (glyph
->object
)
24546 && (glyph
->charpos
>= start_charpos
24547 && glyph
->charpos
< end_charpos
));
24550 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24551 are present at buffer positions between START_CHARPOS and
24552 END_CHARPOS, or if they come from an overlay. */
24553 if (EQ (glyph
->object
, before_string
))
24555 pos
= string_buffer_position (before_string
, start_charpos
);
24556 /* If pos == 0, it means before_string came from an
24557 overlay, not from a buffer position. */
24558 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24561 else if (EQ (glyph
->object
, after_string
))
24563 pos
= string_buffer_position (after_string
, end_charpos
);
24564 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24569 glyph
++; /* first glyph to the right of the highlighted area */
24570 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
24571 x
+= g
->pixel_width
;
24572 hlinfo
->mouse_face_beg_x
= x
;
24573 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24576 /* If the highlight ends in a different row, compute GLYPH and END
24577 for the end row. Otherwise, reuse the values computed above for
24578 the row where the highlight begins. */
24581 if (!r2
->reversed_p
)
24583 glyph
= r2
->glyphs
[TEXT_AREA
];
24584 end
= glyph
+ r2
->used
[TEXT_AREA
];
24589 end
= r2
->glyphs
[TEXT_AREA
] - 1;
24590 glyph
= end
+ r2
->used
[TEXT_AREA
];
24594 if (!r2
->reversed_p
)
24596 /* Skip truncation and continuation glyphs near the end of the
24597 row, and also blanks and stretch glyphs inserted by
24598 extend_face_to_end_of_line. */
24600 && INTEGERP ((end
- 1)->object
)
24601 && (end
- 1)->charpos
<= 0)
24603 /* Scan the rest of the glyph row from the end, looking for the
24604 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
24605 COVER_STRING, or whose position is between START_CHARPOS
24609 && !INTEGERP (end
->object
)
24610 && !EQ (end
->object
, cover_string
)
24611 && !(BUFFERP (end
->object
)
24612 && (end
->charpos
>= start_charpos
24613 && end
->charpos
< end_charpos
));
24616 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24617 are present at buffer positions between START_CHARPOS and
24618 END_CHARPOS, or if they come from an overlay. */
24619 if (EQ (end
->object
, before_string
))
24621 pos
= string_buffer_position (before_string
, start_charpos
);
24622 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24625 else if (EQ (end
->object
, after_string
))
24627 pos
= string_buffer_position (after_string
, end_charpos
);
24628 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24632 /* Find the X coordinate of the last glyph to be highlighted. */
24633 for (; glyph
<= end
; ++glyph
)
24634 x
+= glyph
->pixel_width
;
24636 hlinfo
->mouse_face_end_x
= x
;
24637 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
24641 /* Skip truncation and continuation glyphs near the end of the
24642 row, and also blanks and stretch glyphs inserted by
24643 extend_face_to_end_of_line. */
24647 && INTEGERP (end
->object
)
24648 && end
->charpos
<= 0)
24650 x
+= end
->pixel_width
;
24653 /* Scan the rest of the glyph row from the end, looking for the
24654 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
24655 COVER_STRING, or whose position is between START_CHARPOS
24659 && !INTEGERP (end
->object
)
24660 && !EQ (end
->object
, cover_string
)
24661 && !(BUFFERP (end
->object
)
24662 && (end
->charpos
>= start_charpos
24663 && end
->charpos
< end_charpos
));
24666 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24667 are present at buffer positions between START_CHARPOS and
24668 END_CHARPOS, or if they come from an overlay. */
24669 if (EQ (end
->object
, before_string
))
24671 pos
= string_buffer_position (before_string
, start_charpos
);
24672 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24675 else if (EQ (end
->object
, after_string
))
24677 pos
= string_buffer_position (after_string
, end_charpos
);
24678 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24681 x
+= end
->pixel_width
;
24683 hlinfo
->mouse_face_end_x
= x
;
24684 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
24687 hlinfo
->mouse_face_window
= window
;
24688 hlinfo
->mouse_face_face_id
24689 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
24691 !hlinfo
->mouse_face_hidden
, -1);
24692 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
24695 /* The following function is not used anymore (replaced with
24696 mouse_face_from_string_pos), but I leave it here for the time
24697 being, in case someone would. */
24699 #if 0 /* not used */
24701 /* Find the position of the glyph for position POS in OBJECT in
24702 window W's current matrix, and return in *X, *Y the pixel
24703 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
24705 RIGHT_P non-zero means return the position of the right edge of the
24706 glyph, RIGHT_P zero means return the left edge position.
24708 If no glyph for POS exists in the matrix, return the position of
24709 the glyph with the next smaller position that is in the matrix, if
24710 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
24711 exists in the matrix, return the position of the glyph with the
24712 next larger position in OBJECT.
24714 Value is non-zero if a glyph was found. */
24717 fast_find_string_pos (struct window
*w
, EMACS_INT pos
, Lisp_Object object
,
24718 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
24720 int yb
= window_text_bottom_y (w
);
24721 struct glyph_row
*r
;
24722 struct glyph
*best_glyph
= NULL
;
24723 struct glyph_row
*best_row
= NULL
;
24726 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24727 r
->enabled_p
&& r
->y
< yb
;
24730 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
24731 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
24734 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
24735 if (EQ (g
->object
, object
))
24737 if (g
->charpos
== pos
)
24744 else if (best_glyph
== NULL
24745 || ((eabs (g
->charpos
- pos
)
24746 < eabs (best_glyph
->charpos
- pos
))
24749 : g
->charpos
> pos
)))
24763 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
24767 *x
+= best_glyph
->pixel_width
;
24772 *vpos
= best_row
- w
->current_matrix
->rows
;
24775 return best_glyph
!= NULL
;
24777 #endif /* not used */
24779 /* Find the positions of the first and the last glyphs in window W's
24780 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
24781 (assumed to be a string), and return in HLINFO's mouse_face_*
24782 members the pixel and column/row coordinates of those glyphs. */
24785 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
24786 Lisp_Object object
,
24787 EMACS_INT startpos
, EMACS_INT endpos
)
24789 int yb
= window_text_bottom_y (w
);
24790 struct glyph_row
*r
;
24791 struct glyph
*g
, *e
;
24795 /* Find the glyph row with at least one position in the range
24796 [STARTPOS..ENDPOS], and the first glyph in that row whose
24797 position belongs to that range. */
24798 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24799 r
->enabled_p
&& r
->y
< yb
;
24802 if (!r
->reversed_p
)
24804 g
= r
->glyphs
[TEXT_AREA
];
24805 e
= g
+ r
->used
[TEXT_AREA
];
24806 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
24807 if (EQ (g
->object
, object
)
24808 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
24810 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
24811 hlinfo
->mouse_face_beg_y
= r
->y
;
24812 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
24813 hlinfo
->mouse_face_beg_x
= gx
;
24822 e
= r
->glyphs
[TEXT_AREA
];
24823 g
= e
+ r
->used
[TEXT_AREA
];
24824 for ( ; g
> e
; --g
)
24825 if (EQ ((g
-1)->object
, object
)
24826 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
24828 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
24829 hlinfo
->mouse_face_beg_y
= r
->y
;
24830 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
24831 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
24832 gx
+= g1
->pixel_width
;
24833 hlinfo
->mouse_face_beg_x
= gx
;
24845 /* Starting with the next row, look for the first row which does NOT
24846 include any glyphs whose positions are in the range. */
24847 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
24849 g
= r
->glyphs
[TEXT_AREA
];
24850 e
= g
+ r
->used
[TEXT_AREA
];
24852 for ( ; g
< e
; ++g
)
24853 if (EQ (g
->object
, object
)
24854 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
24863 /* The highlighted region ends on the previous row. */
24866 /* Set the end row and its vertical pixel coordinate. */
24867 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
24868 hlinfo
->mouse_face_end_y
= r
->y
;
24870 /* Compute and set the end column and the end column's horizontal
24871 pixel coordinate. */
24872 if (!r
->reversed_p
)
24874 g
= r
->glyphs
[TEXT_AREA
];
24875 e
= g
+ r
->used
[TEXT_AREA
];
24876 for ( ; e
> g
; --e
)
24877 if (EQ ((e
-1)->object
, object
)
24878 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
24880 hlinfo
->mouse_face_end_col
= e
- g
;
24882 for (gx
= r
->x
; g
< e
; ++g
)
24883 gx
+= g
->pixel_width
;
24884 hlinfo
->mouse_face_end_x
= gx
;
24888 e
= r
->glyphs
[TEXT_AREA
];
24889 g
= e
+ r
->used
[TEXT_AREA
];
24890 for (gx
= r
->x
; e
< g
; ++e
)
24892 if (EQ (e
->object
, object
)
24893 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
24895 gx
+= e
->pixel_width
;
24897 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
24898 hlinfo
->mouse_face_end_x
= gx
;
24902 #ifdef HAVE_WINDOW_SYSTEM
24904 /* See if position X, Y is within a hot-spot of an image. */
24907 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
24909 if (!CONSP (hot_spot
))
24912 if (EQ (XCAR (hot_spot
), Qrect
))
24914 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
24915 Lisp_Object rect
= XCDR (hot_spot
);
24919 if (!CONSP (XCAR (rect
)))
24921 if (!CONSP (XCDR (rect
)))
24923 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
24925 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
24927 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
24929 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
24933 else if (EQ (XCAR (hot_spot
), Qcircle
))
24935 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
24936 Lisp_Object circ
= XCDR (hot_spot
);
24937 Lisp_Object lr
, lx0
, ly0
;
24939 && CONSP (XCAR (circ
))
24940 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
24941 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
24942 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
24944 double r
= XFLOATINT (lr
);
24945 double dx
= XINT (lx0
) - x
;
24946 double dy
= XINT (ly0
) - y
;
24947 return (dx
* dx
+ dy
* dy
<= r
* r
);
24950 else if (EQ (XCAR (hot_spot
), Qpoly
))
24952 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
24953 if (VECTORP (XCDR (hot_spot
)))
24955 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
24956 Lisp_Object
*poly
= v
->contents
;
24957 int n
= v
->header
.size
;
24960 Lisp_Object lx
, ly
;
24963 /* Need an even number of coordinates, and at least 3 edges. */
24964 if (n
< 6 || n
& 1)
24967 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
24968 If count is odd, we are inside polygon. Pixels on edges
24969 may or may not be included depending on actual geometry of the
24971 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
24972 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
24974 x0
= XINT (lx
), y0
= XINT (ly
);
24975 for (i
= 0; i
< n
; i
+= 2)
24977 int x1
= x0
, y1
= y0
;
24978 if ((lx
= poly
[i
], !INTEGERP (lx
))
24979 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
24981 x0
= XINT (lx
), y0
= XINT (ly
);
24983 /* Does this segment cross the X line? */
24991 if (y
> y0
&& y
> y1
)
24993 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
25003 find_hot_spot (Lisp_Object map
, int x
, int y
)
25005 while (CONSP (map
))
25007 if (CONSP (XCAR (map
))
25008 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
25016 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
25018 doc
: /* Lookup in image map MAP coordinates X and Y.
25019 An image map is an alist where each element has the format (AREA ID PLIST).
25020 An AREA is specified as either a rectangle, a circle, or a polygon:
25021 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
25022 pixel coordinates of the upper left and bottom right corners.
25023 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
25024 and the radius of the circle; r may be a float or integer.
25025 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
25026 vector describes one corner in the polygon.
25027 Returns the alist element for the first matching AREA in MAP. */)
25028 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
25036 return find_hot_spot (map
, XINT (x
), XINT (y
));
25040 /* Display frame CURSOR, optionally using shape defined by POINTER. */
25042 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
25044 /* Do not change cursor shape while dragging mouse. */
25045 if (!NILP (do_mouse_tracking
))
25048 if (!NILP (pointer
))
25050 if (EQ (pointer
, Qarrow
))
25051 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25052 else if (EQ (pointer
, Qhand
))
25053 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
25054 else if (EQ (pointer
, Qtext
))
25055 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25056 else if (EQ (pointer
, intern ("hdrag")))
25057 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25058 #ifdef HAVE_X_WINDOWS
25059 else if (EQ (pointer
, intern ("vdrag")))
25060 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
25062 else if (EQ (pointer
, intern ("hourglass")))
25063 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
25064 else if (EQ (pointer
, Qmodeline
))
25065 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
25067 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25070 if (cursor
!= No_Cursor
)
25071 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
25074 #endif /* HAVE_WINDOW_SYSTEM */
25076 /* Take proper action when mouse has moved to the mode or header line
25077 or marginal area AREA of window W, x-position X and y-position Y.
25078 X is relative to the start of the text display area of W, so the
25079 width of bitmap areas and scroll bars must be subtracted to get a
25080 position relative to the start of the mode line. */
25083 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
25084 enum window_part area
)
25086 struct window
*w
= XWINDOW (window
);
25087 struct frame
*f
= XFRAME (w
->frame
);
25088 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25089 #ifdef HAVE_WINDOW_SYSTEM
25090 Display_Info
*dpyinfo
;
25092 Cursor cursor
= No_Cursor
;
25093 Lisp_Object pointer
= Qnil
;
25094 int dx
, dy
, width
, height
;
25096 Lisp_Object string
, object
= Qnil
;
25097 Lisp_Object pos
, help
;
25099 Lisp_Object mouse_face
;
25100 int original_x_pixel
= x
;
25101 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
25102 struct glyph_row
*row
;
25104 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
25109 /* Kludge alert: mode_line_string takes X/Y in pixels, but
25110 returns them in row/column units! */
25111 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
25112 &object
, &dx
, &dy
, &width
, &height
);
25114 row
= (area
== ON_MODE_LINE
25115 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
25116 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
25118 /* Find the glyph under the mouse pointer. */
25119 if (row
->mode_line_p
&& row
->enabled_p
)
25121 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
25122 end
= glyph
+ row
->used
[TEXT_AREA
];
25124 for (x0
= original_x_pixel
;
25125 glyph
< end
&& x0
>= glyph
->pixel_width
;
25127 x0
-= glyph
->pixel_width
;
25135 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
25136 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
25137 returns them in row/column units! */
25138 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
25139 &object
, &dx
, &dy
, &width
, &height
);
25144 #ifdef HAVE_WINDOW_SYSTEM
25145 if (IMAGEP (object
))
25147 Lisp_Object image_map
, hotspot
;
25148 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
25150 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
25152 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25156 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
25157 If so, we could look for mouse-enter, mouse-leave
25158 properties in PLIST (and do something...). */
25159 hotspot
= XCDR (hotspot
);
25160 if (CONSP (hotspot
)
25161 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25163 pointer
= Fplist_get (plist
, Qpointer
);
25164 if (NILP (pointer
))
25166 help
= Fplist_get (plist
, Qhelp_echo
);
25169 help_echo_string
= help
;
25170 /* Is this correct? ++kfs */
25171 XSETWINDOW (help_echo_window
, w
);
25172 help_echo_object
= w
->buffer
;
25173 help_echo_pos
= charpos
;
25177 if (NILP (pointer
))
25178 pointer
= Fplist_get (XCDR (object
), QCpointer
);
25180 #endif /* HAVE_WINDOW_SYSTEM */
25182 if (STRINGP (string
))
25184 pos
= make_number (charpos
);
25185 /* If we're on a string with `help-echo' text property, arrange
25186 for the help to be displayed. This is done by setting the
25187 global variable help_echo_string to the help string. */
25190 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
25193 help_echo_string
= help
;
25194 XSETWINDOW (help_echo_window
, w
);
25195 help_echo_object
= string
;
25196 help_echo_pos
= charpos
;
25200 #ifdef HAVE_WINDOW_SYSTEM
25201 if (FRAME_WINDOW_P (f
))
25203 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25204 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25205 if (NILP (pointer
))
25206 pointer
= Fget_text_property (pos
, Qpointer
, string
);
25208 /* Change the mouse pointer according to what is under X/Y. */
25210 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
25213 map
= Fget_text_property (pos
, Qlocal_map
, string
);
25214 if (!KEYMAPP (map
))
25215 map
= Fget_text_property (pos
, Qkeymap
, string
);
25216 if (!KEYMAPP (map
))
25217 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
25222 /* Change the mouse face according to what is under X/Y. */
25223 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
25224 if (!NILP (mouse_face
)
25225 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25230 struct glyph
* tmp_glyph
;
25234 int total_pixel_width
;
25235 EMACS_INT begpos
, endpos
, ignore
;
25239 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
25240 Qmouse_face
, string
, Qnil
);
25246 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
25248 endpos
= SCHARS (string
);
25252 /* Calculate the glyph position GPOS of GLYPH in the
25253 displayed string, relative to the beginning of the
25254 highlighted part of the string.
25256 Note: GPOS is different from CHARPOS. CHARPOS is the
25257 position of GLYPH in the internal string object. A mode
25258 line string format has structures which are converted to
25259 a flattened string by the Emacs Lisp interpreter. The
25260 internal string is an element of those structures. The
25261 displayed string is the flattened string. */
25262 tmp_glyph
= row_start_glyph
;
25263 while (tmp_glyph
< glyph
25264 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25265 && begpos
<= tmp_glyph
->charpos
25266 && tmp_glyph
->charpos
< endpos
)))
25268 gpos
= glyph
- tmp_glyph
;
25270 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
25271 the highlighted part of the displayed string to which
25272 GLYPH belongs. Note: GSEQ_LENGTH is different from
25273 SCHARS (STRING), because the latter returns the length of
25274 the internal string. */
25275 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
25277 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25278 && begpos
<= tmp_glyph
->charpos
25279 && tmp_glyph
->charpos
< endpos
));
25282 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
25284 /* Calculate the total pixel width of all the glyphs between
25285 the beginning of the highlighted area and GLYPH. */
25286 total_pixel_width
= 0;
25287 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
25288 total_pixel_width
+= tmp_glyph
->pixel_width
;
25290 /* Pre calculation of re-rendering position. Note: X is in
25291 column units here, after the call to mode_line_string or
25292 marginal_area_string. */
25294 vpos
= (area
== ON_MODE_LINE
25295 ? (w
->current_matrix
)->nrows
- 1
25298 /* If GLYPH's position is included in the region that is
25299 already drawn in mouse face, we have nothing to do. */
25300 if ( EQ (window
, hlinfo
->mouse_face_window
)
25301 && (!row
->reversed_p
25302 ? (hlinfo
->mouse_face_beg_col
<= hpos
25303 && hpos
< hlinfo
->mouse_face_end_col
)
25304 /* In R2L rows we swap BEG and END, see below. */
25305 : (hlinfo
->mouse_face_end_col
<= hpos
25306 && hpos
< hlinfo
->mouse_face_beg_col
))
25307 && hlinfo
->mouse_face_beg_row
== vpos
)
25310 if (clear_mouse_face (hlinfo
))
25311 cursor
= No_Cursor
;
25313 if (!row
->reversed_p
)
25315 hlinfo
->mouse_face_beg_col
= hpos
;
25316 hlinfo
->mouse_face_beg_x
= original_x_pixel
25317 - (total_pixel_width
+ dx
);
25318 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
25319 hlinfo
->mouse_face_end_x
= 0;
25323 /* In R2L rows, show_mouse_face expects BEG and END
25324 coordinates to be swapped. */
25325 hlinfo
->mouse_face_end_col
= hpos
;
25326 hlinfo
->mouse_face_end_x
= original_x_pixel
25327 - (total_pixel_width
+ dx
);
25328 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
25329 hlinfo
->mouse_face_beg_x
= 0;
25332 hlinfo
->mouse_face_beg_row
= vpos
;
25333 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
25334 hlinfo
->mouse_face_beg_y
= 0;
25335 hlinfo
->mouse_face_end_y
= 0;
25336 hlinfo
->mouse_face_past_end
= 0;
25337 hlinfo
->mouse_face_window
= window
;
25339 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
25345 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25347 if (NILP (pointer
))
25350 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25351 clear_mouse_face (hlinfo
);
25353 #ifdef HAVE_WINDOW_SYSTEM
25354 if (FRAME_WINDOW_P (f
))
25355 define_frame_cursor1 (f
, cursor
, pointer
);
25361 Take proper action when the mouse has moved to position X, Y on
25362 frame F as regards highlighting characters that have mouse-face
25363 properties. Also de-highlighting chars where the mouse was before.
25364 X and Y can be negative or out of range. */
25367 note_mouse_highlight (struct frame
*f
, int x
, int y
)
25369 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25370 enum window_part part
;
25371 Lisp_Object window
;
25373 Cursor cursor
= No_Cursor
;
25374 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
25377 /* When a menu is active, don't highlight because this looks odd. */
25378 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
25379 if (popup_activated ())
25383 if (NILP (Vmouse_highlight
)
25384 || !f
->glyphs_initialized_p
25385 || f
->pointer_invisible
)
25388 hlinfo
->mouse_face_mouse_x
= x
;
25389 hlinfo
->mouse_face_mouse_y
= y
;
25390 hlinfo
->mouse_face_mouse_frame
= f
;
25392 if (hlinfo
->mouse_face_defer
)
25395 if (gc_in_progress
)
25397 hlinfo
->mouse_face_deferred_gc
= 1;
25401 /* Which window is that in? */
25402 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
25404 /* If we were displaying active text in another window, clear that.
25405 Also clear if we move out of text area in same window. */
25406 if (! EQ (window
, hlinfo
->mouse_face_window
)
25407 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
25408 && !NILP (hlinfo
->mouse_face_window
)))
25409 clear_mouse_face (hlinfo
);
25411 /* Not on a window -> return. */
25412 if (!WINDOWP (window
))
25415 /* Reset help_echo_string. It will get recomputed below. */
25416 help_echo_string
= Qnil
;
25418 /* Convert to window-relative pixel coordinates. */
25419 w
= XWINDOW (window
);
25420 frame_to_window_pixel_xy (w
, &x
, &y
);
25422 #ifdef HAVE_WINDOW_SYSTEM
25423 /* Handle tool-bar window differently since it doesn't display a
25425 if (EQ (window
, f
->tool_bar_window
))
25427 note_tool_bar_highlight (f
, x
, y
);
25432 /* Mouse is on the mode, header line or margin? */
25433 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
25434 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
25436 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
25440 #ifdef HAVE_WINDOW_SYSTEM
25441 if (part
== ON_VERTICAL_BORDER
)
25443 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25444 help_echo_string
= build_string ("drag-mouse-1: resize");
25446 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
25447 || part
== ON_SCROLL_BAR
)
25448 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25450 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25453 /* Are we in a window whose display is up to date?
25454 And verify the buffer's text has not changed. */
25455 b
= XBUFFER (w
->buffer
);
25456 if (part
== ON_TEXT
25457 && EQ (w
->window_end_valid
, w
->buffer
)
25458 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
25459 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
25461 int hpos
, vpos
, dx
, dy
, area
;
25463 struct glyph
*glyph
;
25464 Lisp_Object object
;
25465 Lisp_Object mouse_face
= Qnil
, position
;
25466 Lisp_Object
*overlay_vec
= NULL
;
25467 ptrdiff_t i
, noverlays
;
25468 struct buffer
*obuf
;
25469 EMACS_INT obegv
, ozv
;
25472 /* Find the glyph under X/Y. */
25473 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
25475 #ifdef HAVE_WINDOW_SYSTEM
25476 /* Look for :pointer property on image. */
25477 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25479 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25480 if (img
!= NULL
&& IMAGEP (img
->spec
))
25482 Lisp_Object image_map
, hotspot
;
25483 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
25485 && (hotspot
= find_hot_spot (image_map
,
25486 glyph
->slice
.img
.x
+ dx
,
25487 glyph
->slice
.img
.y
+ dy
),
25489 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25493 /* Could check XCAR (hotspot) to see if we enter/leave
25495 If so, we could look for mouse-enter, mouse-leave
25496 properties in PLIST (and do something...). */
25497 hotspot
= XCDR (hotspot
);
25498 if (CONSP (hotspot
)
25499 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25501 pointer
= Fplist_get (plist
, Qpointer
);
25502 if (NILP (pointer
))
25504 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
25505 if (!NILP (help_echo_string
))
25507 help_echo_window
= window
;
25508 help_echo_object
= glyph
->object
;
25509 help_echo_pos
= glyph
->charpos
;
25513 if (NILP (pointer
))
25514 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
25517 #endif /* HAVE_WINDOW_SYSTEM */
25519 /* Clear mouse face if X/Y not over text. */
25521 || area
!= TEXT_AREA
25522 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
25523 /* Glyph's OBJECT is an integer for glyphs inserted by the
25524 display engine for its internal purposes, like truncation
25525 and continuation glyphs and blanks beyond the end of
25526 line's text on text terminals. If we are over such a
25527 glyph, we are not over any text. */
25528 || INTEGERP (glyph
->object
)
25529 /* R2L rows have a stretch glyph at their front, which
25530 stands for no text, whereas L2R rows have no glyphs at
25531 all beyond the end of text. Treat such stretch glyphs
25532 like we do with NULL glyphs in L2R rows. */
25533 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
25534 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
25535 && glyph
->type
== STRETCH_GLYPH
25536 && glyph
->avoid_cursor_p
))
25538 if (clear_mouse_face (hlinfo
))
25539 cursor
= No_Cursor
;
25540 #ifdef HAVE_WINDOW_SYSTEM
25541 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
25543 if (area
!= TEXT_AREA
)
25544 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25546 pointer
= Vvoid_text_area_pointer
;
25552 pos
= glyph
->charpos
;
25553 object
= glyph
->object
;
25554 if (!STRINGP (object
) && !BUFFERP (object
))
25557 /* If we get an out-of-range value, return now; avoid an error. */
25558 if (BUFFERP (object
) && pos
> BUF_Z (b
))
25561 /* Make the window's buffer temporarily current for
25562 overlays_at and compute_char_face. */
25563 obuf
= current_buffer
;
25564 current_buffer
= b
;
25570 /* Is this char mouse-active or does it have help-echo? */
25571 position
= make_number (pos
);
25573 if (BUFFERP (object
))
25575 /* Put all the overlays we want in a vector in overlay_vec. */
25576 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
25577 /* Sort overlays into increasing priority order. */
25578 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
25583 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
25586 cursor
= No_Cursor
;
25588 /* Check mouse-face highlighting. */
25590 /* If there exists an overlay with mouse-face overlapping
25591 the one we are currently highlighting, we have to
25592 check if we enter the overlapping overlay, and then
25593 highlight only that. */
25594 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
25595 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
25597 /* Find the highest priority overlay with a mouse-face. */
25598 Lisp_Object overlay
= Qnil
;
25599 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
25601 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
25602 if (!NILP (mouse_face
))
25603 overlay
= overlay_vec
[i
];
25606 /* If we're highlighting the same overlay as before, there's
25607 no need to do that again. */
25608 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
25609 goto check_help_echo
;
25610 hlinfo
->mouse_face_overlay
= overlay
;
25612 /* Clear the display of the old active region, if any. */
25613 if (clear_mouse_face (hlinfo
))
25614 cursor
= No_Cursor
;
25616 /* If no overlay applies, get a text property. */
25617 if (NILP (overlay
))
25618 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
25620 /* Next, compute the bounds of the mouse highlighting and
25622 if (!NILP (mouse_face
) && STRINGP (object
))
25624 /* The mouse-highlighting comes from a display string
25625 with a mouse-face. */
25629 s
= Fprevious_single_property_change
25630 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
25631 e
= Fnext_single_property_change
25632 (position
, Qmouse_face
, object
, Qnil
);
25634 s
= make_number (0);
25636 e
= make_number (SCHARS (object
) - 1);
25637 mouse_face_from_string_pos (w
, hlinfo
, object
,
25638 XINT (s
), XINT (e
));
25639 hlinfo
->mouse_face_past_end
= 0;
25640 hlinfo
->mouse_face_window
= window
;
25641 hlinfo
->mouse_face_face_id
25642 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
25643 glyph
->face_id
, 1);
25644 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25645 cursor
= No_Cursor
;
25649 /* The mouse-highlighting, if any, comes from an overlay
25650 or text property in the buffer. */
25651 Lisp_Object buffer
IF_LINT (= Qnil
);
25652 Lisp_Object cover_string
IF_LINT (= Qnil
);
25654 if (STRINGP (object
))
25656 /* If we are on a display string with no mouse-face,
25657 check if the text under it has one. */
25658 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
25659 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25660 pos
= string_buffer_position (object
, start
);
25663 mouse_face
= get_char_property_and_overlay
25664 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
25665 buffer
= w
->buffer
;
25666 cover_string
= object
;
25672 cover_string
= Qnil
;
25675 if (!NILP (mouse_face
))
25677 Lisp_Object before
, after
;
25678 Lisp_Object before_string
, after_string
;
25679 /* To correctly find the limits of mouse highlight
25680 in a bidi-reordered buffer, we must not use the
25681 optimization of limiting the search in
25682 previous-single-property-change and
25683 next-single-property-change, because
25684 rows_from_pos_range needs the real start and end
25685 positions to DTRT in this case. That's because
25686 the first row visible in a window does not
25687 necessarily display the character whose position
25688 is the smallest. */
25690 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
25691 ? Fmarker_position (w
->start
)
25694 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
25695 ? make_number (BUF_Z (XBUFFER (buffer
))
25696 - XFASTINT (w
->window_end_pos
))
25699 if (NILP (overlay
))
25701 /* Handle the text property case. */
25702 before
= Fprevious_single_property_change
25703 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
25704 after
= Fnext_single_property_change
25705 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
25706 before_string
= after_string
= Qnil
;
25710 /* Handle the overlay case. */
25711 before
= Foverlay_start (overlay
);
25712 after
= Foverlay_end (overlay
);
25713 before_string
= Foverlay_get (overlay
, Qbefore_string
);
25714 after_string
= Foverlay_get (overlay
, Qafter_string
);
25716 if (!STRINGP (before_string
)) before_string
= Qnil
;
25717 if (!STRINGP (after_string
)) after_string
= Qnil
;
25720 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
25723 before_string
, after_string
,
25725 cursor
= No_Cursor
;
25732 /* Look for a `help-echo' property. */
25733 if (NILP (help_echo_string
)) {
25734 Lisp_Object help
, overlay
;
25736 /* Check overlays first. */
25737 help
= overlay
= Qnil
;
25738 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
25740 overlay
= overlay_vec
[i
];
25741 help
= Foverlay_get (overlay
, Qhelp_echo
);
25746 help_echo_string
= help
;
25747 help_echo_window
= window
;
25748 help_echo_object
= overlay
;
25749 help_echo_pos
= pos
;
25753 Lisp_Object obj
= glyph
->object
;
25754 EMACS_INT charpos
= glyph
->charpos
;
25756 /* Try text properties. */
25759 && charpos
< SCHARS (obj
))
25761 help
= Fget_text_property (make_number (charpos
),
25765 /* If the string itself doesn't specify a help-echo,
25766 see if the buffer text ``under'' it does. */
25767 struct glyph_row
*r
25768 = MATRIX_ROW (w
->current_matrix
, vpos
);
25769 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25770 EMACS_INT p
= string_buffer_position (obj
, start
);
25773 help
= Fget_char_property (make_number (p
),
25774 Qhelp_echo
, w
->buffer
);
25783 else if (BUFFERP (obj
)
25786 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
25791 help_echo_string
= help
;
25792 help_echo_window
= window
;
25793 help_echo_object
= obj
;
25794 help_echo_pos
= charpos
;
25799 #ifdef HAVE_WINDOW_SYSTEM
25800 /* Look for a `pointer' property. */
25801 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
25803 /* Check overlays first. */
25804 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
25805 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
25807 if (NILP (pointer
))
25809 Lisp_Object obj
= glyph
->object
;
25810 EMACS_INT charpos
= glyph
->charpos
;
25812 /* Try text properties. */
25815 && charpos
< SCHARS (obj
))
25817 pointer
= Fget_text_property (make_number (charpos
),
25819 if (NILP (pointer
))
25821 /* If the string itself doesn't specify a pointer,
25822 see if the buffer text ``under'' it does. */
25823 struct glyph_row
*r
25824 = MATRIX_ROW (w
->current_matrix
, vpos
);
25825 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25826 EMACS_INT p
= string_buffer_position (obj
, start
);
25828 pointer
= Fget_char_property (make_number (p
),
25829 Qpointer
, w
->buffer
);
25832 else if (BUFFERP (obj
)
25835 pointer
= Fget_text_property (make_number (charpos
),
25839 #endif /* HAVE_WINDOW_SYSTEM */
25843 current_buffer
= obuf
;
25848 #ifdef HAVE_WINDOW_SYSTEM
25849 if (FRAME_WINDOW_P (f
))
25850 define_frame_cursor1 (f
, cursor
, pointer
);
25852 /* This is here to prevent a compiler error, about "label at end of
25853 compound statement". */
25860 Clear any mouse-face on window W. This function is part of the
25861 redisplay interface, and is called from try_window_id and similar
25862 functions to ensure the mouse-highlight is off. */
25865 x_clear_window_mouse_face (struct window
*w
)
25867 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
25868 Lisp_Object window
;
25871 XSETWINDOW (window
, w
);
25872 if (EQ (window
, hlinfo
->mouse_face_window
))
25873 clear_mouse_face (hlinfo
);
25879 Just discard the mouse face information for frame F, if any.
25880 This is used when the size of F is changed. */
25883 cancel_mouse_face (struct frame
*f
)
25885 Lisp_Object window
;
25886 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25888 window
= hlinfo
->mouse_face_window
;
25889 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
25891 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
25892 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
25893 hlinfo
->mouse_face_window
= Qnil
;
25899 /***********************************************************************
25901 ***********************************************************************/
25903 #ifdef HAVE_WINDOW_SYSTEM
25905 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
25906 which intersects rectangle R. R is in window-relative coordinates. */
25909 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
25910 enum glyph_row_area area
)
25912 struct glyph
*first
= row
->glyphs
[area
];
25913 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
25914 struct glyph
*last
;
25915 int first_x
, start_x
, x
;
25917 if (area
== TEXT_AREA
&& row
->fill_line_p
)
25918 /* If row extends face to end of line write the whole line. */
25919 draw_glyphs (w
, 0, row
, area
,
25920 0, row
->used
[area
],
25921 DRAW_NORMAL_TEXT
, 0);
25924 /* Set START_X to the window-relative start position for drawing glyphs of
25925 AREA. The first glyph of the text area can be partially visible.
25926 The first glyphs of other areas cannot. */
25927 start_x
= window_box_left_offset (w
, area
);
25929 if (area
== TEXT_AREA
)
25932 /* Find the first glyph that must be redrawn. */
25934 && x
+ first
->pixel_width
< r
->x
)
25936 x
+= first
->pixel_width
;
25940 /* Find the last one. */
25944 && x
< r
->x
+ r
->width
)
25946 x
+= last
->pixel_width
;
25952 draw_glyphs (w
, first_x
- start_x
, row
, area
,
25953 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
25954 DRAW_NORMAL_TEXT
, 0);
25959 /* Redraw the parts of the glyph row ROW on window W intersecting
25960 rectangle R. R is in window-relative coordinates. Value is
25961 non-zero if mouse-face was overwritten. */
25964 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
25966 xassert (row
->enabled_p
);
25968 if (row
->mode_line_p
|| w
->pseudo_window_p
)
25969 draw_glyphs (w
, 0, row
, TEXT_AREA
,
25970 0, row
->used
[TEXT_AREA
],
25971 DRAW_NORMAL_TEXT
, 0);
25974 if (row
->used
[LEFT_MARGIN_AREA
])
25975 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
25976 if (row
->used
[TEXT_AREA
])
25977 expose_area (w
, row
, r
, TEXT_AREA
);
25978 if (row
->used
[RIGHT_MARGIN_AREA
])
25979 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
25980 draw_row_fringe_bitmaps (w
, row
);
25983 return row
->mouse_face_p
;
25987 /* Redraw those parts of glyphs rows during expose event handling that
25988 overlap other rows. Redrawing of an exposed line writes over parts
25989 of lines overlapping that exposed line; this function fixes that.
25991 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
25992 row in W's current matrix that is exposed and overlaps other rows.
25993 LAST_OVERLAPPING_ROW is the last such row. */
25996 expose_overlaps (struct window
*w
,
25997 struct glyph_row
*first_overlapping_row
,
25998 struct glyph_row
*last_overlapping_row
,
26001 struct glyph_row
*row
;
26003 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
26004 if (row
->overlapping_p
)
26006 xassert (row
->enabled_p
&& !row
->mode_line_p
);
26009 if (row
->used
[LEFT_MARGIN_AREA
])
26010 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
26012 if (row
->used
[TEXT_AREA
])
26013 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
26015 if (row
->used
[RIGHT_MARGIN_AREA
])
26016 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
26022 /* Return non-zero if W's cursor intersects rectangle R. */
26025 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
26027 XRectangle cr
, result
;
26028 struct glyph
*cursor_glyph
;
26029 struct glyph_row
*row
;
26031 if (w
->phys_cursor
.vpos
>= 0
26032 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
26033 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
26035 && row
->cursor_in_fringe_p
)
26037 /* Cursor is in the fringe. */
26038 cr
.x
= window_box_right_offset (w
,
26039 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
26040 ? RIGHT_MARGIN_AREA
26043 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
26044 cr
.height
= row
->height
;
26045 return x_intersect_rectangles (&cr
, r
, &result
);
26048 cursor_glyph
= get_phys_cursor_glyph (w
);
26051 /* r is relative to W's box, but w->phys_cursor.x is relative
26052 to left edge of W's TEXT area. Adjust it. */
26053 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
26054 cr
.y
= w
->phys_cursor
.y
;
26055 cr
.width
= cursor_glyph
->pixel_width
;
26056 cr
.height
= w
->phys_cursor_height
;
26057 /* ++KFS: W32 version used W32-specific IntersectRect here, but
26058 I assume the effect is the same -- and this is portable. */
26059 return x_intersect_rectangles (&cr
, r
, &result
);
26061 /* If we don't understand the format, pretend we're not in the hot-spot. */
26067 Draw a vertical window border to the right of window W if W doesn't
26068 have vertical scroll bars. */
26071 x_draw_vertical_border (struct window
*w
)
26073 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26075 /* We could do better, if we knew what type of scroll-bar the adjacent
26076 windows (on either side) have... But we don't :-(
26077 However, I think this works ok. ++KFS 2003-04-25 */
26079 /* Redraw borders between horizontally adjacent windows. Don't
26080 do it for frames with vertical scroll bars because either the
26081 right scroll bar of a window, or the left scroll bar of its
26082 neighbor will suffice as a border. */
26083 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
26086 if (!WINDOW_RIGHTMOST_P (w
)
26087 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
26089 int x0
, x1
, y0
, y1
;
26091 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26094 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26097 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
26099 else if (!WINDOW_LEFTMOST_P (w
)
26100 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
26102 int x0
, x1
, y0
, y1
;
26104 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26107 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26110 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
26115 /* Redraw the part of window W intersection rectangle FR. Pixel
26116 coordinates in FR are frame-relative. Call this function with
26117 input blocked. Value is non-zero if the exposure overwrites
26121 expose_window (struct window
*w
, XRectangle
*fr
)
26123 struct frame
*f
= XFRAME (w
->frame
);
26125 int mouse_face_overwritten_p
= 0;
26127 /* If window is not yet fully initialized, do nothing. This can
26128 happen when toolkit scroll bars are used and a window is split.
26129 Reconfiguring the scroll bar will generate an expose for a newly
26131 if (w
->current_matrix
== NULL
)
26134 /* When we're currently updating the window, display and current
26135 matrix usually don't agree. Arrange for a thorough display
26137 if (w
== updated_window
)
26139 SET_FRAME_GARBAGED (f
);
26143 /* Frame-relative pixel rectangle of W. */
26144 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
26145 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
26146 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
26147 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
26149 if (x_intersect_rectangles (fr
, &wr
, &r
))
26151 int yb
= window_text_bottom_y (w
);
26152 struct glyph_row
*row
;
26153 int cursor_cleared_p
;
26154 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
26156 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
26157 r
.x
, r
.y
, r
.width
, r
.height
));
26159 /* Convert to window coordinates. */
26160 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
26161 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
26163 /* Turn off the cursor. */
26164 if (!w
->pseudo_window_p
26165 && phys_cursor_in_rect_p (w
, &r
))
26167 x_clear_cursor (w
);
26168 cursor_cleared_p
= 1;
26171 cursor_cleared_p
= 0;
26173 /* Update lines intersecting rectangle R. */
26174 first_overlapping_row
= last_overlapping_row
= NULL
;
26175 for (row
= w
->current_matrix
->rows
;
26180 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
26182 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
26183 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
26184 || (r
.y
>= y0
&& r
.y
< y1
)
26185 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
26187 /* A header line may be overlapping, but there is no need
26188 to fix overlapping areas for them. KFS 2005-02-12 */
26189 if (row
->overlapping_p
&& !row
->mode_line_p
)
26191 if (first_overlapping_row
== NULL
)
26192 first_overlapping_row
= row
;
26193 last_overlapping_row
= row
;
26197 if (expose_line (w
, row
, &r
))
26198 mouse_face_overwritten_p
= 1;
26201 else if (row
->overlapping_p
)
26203 /* We must redraw a row overlapping the exposed area. */
26205 ? y0
+ row
->phys_height
> r
.y
26206 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
26208 if (first_overlapping_row
== NULL
)
26209 first_overlapping_row
= row
;
26210 last_overlapping_row
= row
;
26218 /* Display the mode line if there is one. */
26219 if (WINDOW_WANTS_MODELINE_P (w
)
26220 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
26222 && row
->y
< r
.y
+ r
.height
)
26224 if (expose_line (w
, row
, &r
))
26225 mouse_face_overwritten_p
= 1;
26228 if (!w
->pseudo_window_p
)
26230 /* Fix the display of overlapping rows. */
26231 if (first_overlapping_row
)
26232 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
26235 /* Draw border between windows. */
26236 x_draw_vertical_border (w
);
26238 /* Turn the cursor on again. */
26239 if (cursor_cleared_p
)
26240 update_window_cursor (w
, 1);
26244 return mouse_face_overwritten_p
;
26249 /* Redraw (parts) of all windows in the window tree rooted at W that
26250 intersect R. R contains frame pixel coordinates. Value is
26251 non-zero if the exposure overwrites mouse-face. */
26254 expose_window_tree (struct window
*w
, XRectangle
*r
)
26256 struct frame
*f
= XFRAME (w
->frame
);
26257 int mouse_face_overwritten_p
= 0;
26259 while (w
&& !FRAME_GARBAGED_P (f
))
26261 if (!NILP (w
->hchild
))
26262 mouse_face_overwritten_p
26263 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
26264 else if (!NILP (w
->vchild
))
26265 mouse_face_overwritten_p
26266 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
26268 mouse_face_overwritten_p
|= expose_window (w
, r
);
26270 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
26273 return mouse_face_overwritten_p
;
26278 Redisplay an exposed area of frame F. X and Y are the upper-left
26279 corner of the exposed rectangle. W and H are width and height of
26280 the exposed area. All are pixel values. W or H zero means redraw
26281 the entire frame. */
26284 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
26287 int mouse_face_overwritten_p
= 0;
26289 TRACE ((stderr
, "expose_frame "));
26291 /* No need to redraw if frame will be redrawn soon. */
26292 if (FRAME_GARBAGED_P (f
))
26294 TRACE ((stderr
, " garbaged\n"));
26298 /* If basic faces haven't been realized yet, there is no point in
26299 trying to redraw anything. This can happen when we get an expose
26300 event while Emacs is starting, e.g. by moving another window. */
26301 if (FRAME_FACE_CACHE (f
) == NULL
26302 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
26304 TRACE ((stderr
, " no faces\n"));
26308 if (w
== 0 || h
== 0)
26311 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
26312 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
26322 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
26323 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
26325 if (WINDOWP (f
->tool_bar_window
))
26326 mouse_face_overwritten_p
26327 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
26329 #ifdef HAVE_X_WINDOWS
26331 #ifndef USE_X_TOOLKIT
26332 if (WINDOWP (f
->menu_bar_window
))
26333 mouse_face_overwritten_p
26334 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
26335 #endif /* not USE_X_TOOLKIT */
26339 /* Some window managers support a focus-follows-mouse style with
26340 delayed raising of frames. Imagine a partially obscured frame,
26341 and moving the mouse into partially obscured mouse-face on that
26342 frame. The visible part of the mouse-face will be highlighted,
26343 then the WM raises the obscured frame. With at least one WM, KDE
26344 2.1, Emacs is not getting any event for the raising of the frame
26345 (even tried with SubstructureRedirectMask), only Expose events.
26346 These expose events will draw text normally, i.e. not
26347 highlighted. Which means we must redo the highlight here.
26348 Subsume it under ``we love X''. --gerd 2001-08-15 */
26349 /* Included in Windows version because Windows most likely does not
26350 do the right thing if any third party tool offers
26351 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
26352 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
26354 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26355 if (f
== hlinfo
->mouse_face_mouse_frame
)
26357 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
26358 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
26359 clear_mouse_face (hlinfo
);
26360 note_mouse_highlight (f
, mouse_x
, mouse_y
);
26367 Determine the intersection of two rectangles R1 and R2. Return
26368 the intersection in *RESULT. Value is non-zero if RESULT is not
26372 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
26374 XRectangle
*left
, *right
;
26375 XRectangle
*upper
, *lower
;
26376 int intersection_p
= 0;
26378 /* Rearrange so that R1 is the left-most rectangle. */
26380 left
= r1
, right
= r2
;
26382 left
= r2
, right
= r1
;
26384 /* X0 of the intersection is right.x0, if this is inside R1,
26385 otherwise there is no intersection. */
26386 if (right
->x
<= left
->x
+ left
->width
)
26388 result
->x
= right
->x
;
26390 /* The right end of the intersection is the minimum of
26391 the right ends of left and right. */
26392 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
26395 /* Same game for Y. */
26397 upper
= r1
, lower
= r2
;
26399 upper
= r2
, lower
= r1
;
26401 /* The upper end of the intersection is lower.y0, if this is inside
26402 of upper. Otherwise, there is no intersection. */
26403 if (lower
->y
<= upper
->y
+ upper
->height
)
26405 result
->y
= lower
->y
;
26407 /* The lower end of the intersection is the minimum of the lower
26408 ends of upper and lower. */
26409 result
->height
= (min (lower
->y
+ lower
->height
,
26410 upper
->y
+ upper
->height
)
26412 intersection_p
= 1;
26416 return intersection_p
;
26419 #endif /* HAVE_WINDOW_SYSTEM */
26422 /***********************************************************************
26424 ***********************************************************************/
26427 syms_of_xdisp (void)
26429 Vwith_echo_area_save_vector
= Qnil
;
26430 staticpro (&Vwith_echo_area_save_vector
);
26432 Vmessage_stack
= Qnil
;
26433 staticpro (&Vmessage_stack
);
26435 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
26437 message_dolog_marker1
= Fmake_marker ();
26438 staticpro (&message_dolog_marker1
);
26439 message_dolog_marker2
= Fmake_marker ();
26440 staticpro (&message_dolog_marker2
);
26441 message_dolog_marker3
= Fmake_marker ();
26442 staticpro (&message_dolog_marker3
);
26445 defsubr (&Sdump_frame_glyph_matrix
);
26446 defsubr (&Sdump_glyph_matrix
);
26447 defsubr (&Sdump_glyph_row
);
26448 defsubr (&Sdump_tool_bar_row
);
26449 defsubr (&Strace_redisplay
);
26450 defsubr (&Strace_to_stderr
);
26452 #ifdef HAVE_WINDOW_SYSTEM
26453 defsubr (&Stool_bar_lines_needed
);
26454 defsubr (&Slookup_image_map
);
26456 defsubr (&Sformat_mode_line
);
26457 defsubr (&Sinvisible_p
);
26458 defsubr (&Scurrent_bidi_paragraph_direction
);
26460 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
26461 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
26462 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
26463 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
26464 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
26465 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
26466 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
26467 DEFSYM (Qeval
, "eval");
26468 DEFSYM (QCdata
, ":data");
26469 DEFSYM (Qdisplay
, "display");
26470 DEFSYM (Qspace_width
, "space-width");
26471 DEFSYM (Qraise
, "raise");
26472 DEFSYM (Qslice
, "slice");
26473 DEFSYM (Qspace
, "space");
26474 DEFSYM (Qmargin
, "margin");
26475 DEFSYM (Qpointer
, "pointer");
26476 DEFSYM (Qleft_margin
, "left-margin");
26477 DEFSYM (Qright_margin
, "right-margin");
26478 DEFSYM (Qcenter
, "center");
26479 DEFSYM (Qline_height
, "line-height");
26480 DEFSYM (QCalign_to
, ":align-to");
26481 DEFSYM (QCrelative_width
, ":relative-width");
26482 DEFSYM (QCrelative_height
, ":relative-height");
26483 DEFSYM (QCeval
, ":eval");
26484 DEFSYM (QCpropertize
, ":propertize");
26485 DEFSYM (QCfile
, ":file");
26486 DEFSYM (Qfontified
, "fontified");
26487 DEFSYM (Qfontification_functions
, "fontification-functions");
26488 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
26489 DEFSYM (Qescape_glyph
, "escape-glyph");
26490 DEFSYM (Qnobreak_space
, "nobreak-space");
26491 DEFSYM (Qimage
, "image");
26492 DEFSYM (Qtext
, "text");
26493 DEFSYM (Qboth
, "both");
26494 DEFSYM (Qboth_horiz
, "both-horiz");
26495 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
26496 DEFSYM (QCmap
, ":map");
26497 DEFSYM (QCpointer
, ":pointer");
26498 DEFSYM (Qrect
, "rect");
26499 DEFSYM (Qcircle
, "circle");
26500 DEFSYM (Qpoly
, "poly");
26501 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
26502 DEFSYM (Qgrow_only
, "grow-only");
26503 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
26504 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
26505 DEFSYM (Qposition
, "position");
26506 DEFSYM (Qbuffer_position
, "buffer-position");
26507 DEFSYM (Qobject
, "object");
26508 DEFSYM (Qbar
, "bar");
26509 DEFSYM (Qhbar
, "hbar");
26510 DEFSYM (Qbox
, "box");
26511 DEFSYM (Qhollow
, "hollow");
26512 DEFSYM (Qhand
, "hand");
26513 DEFSYM (Qarrow
, "arrow");
26514 DEFSYM (Qtext
, "text");
26515 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
26517 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
26518 Fcons (intern_c_string ("void-variable"), Qnil
)),
26520 staticpro (&list_of_error
);
26522 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
26523 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
26524 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
26525 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
26527 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
26528 staticpro (&echo_buffer
[0]);
26529 staticpro (&echo_buffer
[1]);
26531 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
26532 staticpro (&echo_area_buffer
[0]);
26533 staticpro (&echo_area_buffer
[1]);
26535 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
26536 staticpro (&Vmessages_buffer_name
);
26538 mode_line_proptrans_alist
= Qnil
;
26539 staticpro (&mode_line_proptrans_alist
);
26540 mode_line_string_list
= Qnil
;
26541 staticpro (&mode_line_string_list
);
26542 mode_line_string_face
= Qnil
;
26543 staticpro (&mode_line_string_face
);
26544 mode_line_string_face_prop
= Qnil
;
26545 staticpro (&mode_line_string_face_prop
);
26546 Vmode_line_unwind_vector
= Qnil
;
26547 staticpro (&Vmode_line_unwind_vector
);
26549 help_echo_string
= Qnil
;
26550 staticpro (&help_echo_string
);
26551 help_echo_object
= Qnil
;
26552 staticpro (&help_echo_object
);
26553 help_echo_window
= Qnil
;
26554 staticpro (&help_echo_window
);
26555 previous_help_echo_string
= Qnil
;
26556 staticpro (&previous_help_echo_string
);
26557 help_echo_pos
= -1;
26559 DEFSYM (Qright_to_left
, "right-to-left");
26560 DEFSYM (Qleft_to_right
, "left-to-right");
26562 #ifdef HAVE_WINDOW_SYSTEM
26563 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
26564 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
26565 For example, if a block cursor is over a tab, it will be drawn as
26566 wide as that tab on the display. */);
26567 x_stretch_cursor_p
= 0;
26570 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
26571 doc
: /* *Non-nil means highlight trailing whitespace.
26572 The face used for trailing whitespace is `trailing-whitespace'. */);
26573 Vshow_trailing_whitespace
= Qnil
;
26575 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
26576 doc
: /* *Control highlighting of nobreak space and soft hyphen.
26577 A value of t means highlight the character itself (for nobreak space,
26578 use face `nobreak-space').
26579 A value of nil means no highlighting.
26580 Other values mean display the escape glyph followed by an ordinary
26581 space or ordinary hyphen. */);
26582 Vnobreak_char_display
= Qt
;
26584 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
26585 doc
: /* *The pointer shape to show in void text areas.
26586 A value of nil means to show the text pointer. Other options are `arrow',
26587 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
26588 Vvoid_text_area_pointer
= Qarrow
;
26590 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
26591 doc
: /* Non-nil means don't actually do any redisplay.
26592 This is used for internal purposes. */);
26593 Vinhibit_redisplay
= Qnil
;
26595 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
26596 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
26597 Vglobal_mode_string
= Qnil
;
26599 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
26600 doc
: /* Marker for where to display an arrow on top of the buffer text.
26601 This must be the beginning of a line in order to work.
26602 See also `overlay-arrow-string'. */);
26603 Voverlay_arrow_position
= Qnil
;
26605 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
26606 doc
: /* String to display as an arrow in non-window frames.
26607 See also `overlay-arrow-position'. */);
26608 Voverlay_arrow_string
= make_pure_c_string ("=>");
26610 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
26611 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
26612 The symbols on this list are examined during redisplay to determine
26613 where to display overlay arrows. */);
26614 Voverlay_arrow_variable_list
26615 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
26617 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
26618 doc
: /* *The number of lines to try scrolling a window by when point moves out.
26619 If that fails to bring point back on frame, point is centered instead.
26620 If this is zero, point is always centered after it moves off frame.
26621 If you want scrolling to always be a line at a time, you should set
26622 `scroll-conservatively' to a large value rather than set this to 1. */);
26624 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
26625 doc
: /* *Scroll up to this many lines, to bring point back on screen.
26626 If point moves off-screen, redisplay will scroll by up to
26627 `scroll-conservatively' lines in order to bring point just barely
26628 onto the screen again. If that cannot be done, then redisplay
26629 recenters point as usual.
26631 If the value is greater than 100, redisplay will never recenter point,
26632 but will always scroll just enough text to bring point into view, even
26633 if you move far away.
26635 A value of zero means always recenter point if it moves off screen. */);
26636 scroll_conservatively
= 0;
26638 DEFVAR_INT ("scroll-margin", scroll_margin
,
26639 doc
: /* *Number of lines of margin at the top and bottom of a window.
26640 Recenter the window whenever point gets within this many lines
26641 of the top or bottom of the window. */);
26644 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
26645 doc
: /* Pixels per inch value for non-window system displays.
26646 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
26647 Vdisplay_pixels_per_inch
= make_float (72.0);
26650 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
26653 DEFVAR_LISP ("truncate-partial-width-windows",
26654 Vtruncate_partial_width_windows
,
26655 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
26656 For an integer value, truncate lines in each window narrower than the
26657 full frame width, provided the window width is less than that integer;
26658 otherwise, respect the value of `truncate-lines'.
26660 For any other non-nil value, truncate lines in all windows that do
26661 not span the full frame width.
26663 A value of nil means to respect the value of `truncate-lines'.
26665 If `word-wrap' is enabled, you might want to reduce this. */);
26666 Vtruncate_partial_width_windows
= make_number (50);
26668 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
26669 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
26670 Any other value means to use the appropriate face, `mode-line',
26671 `header-line', or `menu' respectively. */);
26672 mode_line_inverse_video
= 1;
26674 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
26675 doc
: /* *Maximum buffer size for which line number should be displayed.
26676 If the buffer is bigger than this, the line number does not appear
26677 in the mode line. A value of nil means no limit. */);
26678 Vline_number_display_limit
= Qnil
;
26680 DEFVAR_INT ("line-number-display-limit-width",
26681 line_number_display_limit_width
,
26682 doc
: /* *Maximum line width (in characters) for line number display.
26683 If the average length of the lines near point is bigger than this, then the
26684 line number may be omitted from the mode line. */);
26685 line_number_display_limit_width
= 200;
26687 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
26688 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
26689 highlight_nonselected_windows
= 0;
26691 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
26692 doc
: /* Non-nil if more than one frame is visible on this display.
26693 Minibuffer-only frames don't count, but iconified frames do.
26694 This variable is not guaranteed to be accurate except while processing
26695 `frame-title-format' and `icon-title-format'. */);
26697 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
26698 doc
: /* Template for displaying the title bar of visible frames.
26699 \(Assuming the window manager supports this feature.)
26701 This variable has the same structure as `mode-line-format', except that
26702 the %c and %l constructs are ignored. It is used only on frames for
26703 which no explicit name has been set \(see `modify-frame-parameters'). */);
26705 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
26706 doc
: /* Template for displaying the title bar of an iconified frame.
26707 \(Assuming the window manager supports this feature.)
26708 This variable has the same structure as `mode-line-format' (which see),
26709 and is used only on frames for which no explicit name has been set
26710 \(see `modify-frame-parameters'). */);
26712 = Vframe_title_format
26713 = pure_cons (intern_c_string ("multiple-frames"),
26714 pure_cons (make_pure_c_string ("%b"),
26715 pure_cons (pure_cons (empty_unibyte_string
,
26716 pure_cons (intern_c_string ("invocation-name"),
26717 pure_cons (make_pure_c_string ("@"),
26718 pure_cons (intern_c_string ("system-name"),
26722 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
26723 doc
: /* Maximum number of lines to keep in the message log buffer.
26724 If nil, disable message logging. If t, log messages but don't truncate
26725 the buffer when it becomes large. */);
26726 Vmessage_log_max
= make_number (100);
26728 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
26729 doc
: /* Functions called before redisplay, if window sizes have changed.
26730 The value should be a list of functions that take one argument.
26731 Just before redisplay, for each frame, if any of its windows have changed
26732 size since the last redisplay, or have been split or deleted,
26733 all the functions in the list are called, with the frame as argument. */);
26734 Vwindow_size_change_functions
= Qnil
;
26736 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
26737 doc
: /* List of functions to call before redisplaying a window with scrolling.
26738 Each function is called with two arguments, the window and its new
26739 display-start position. Note that these functions are also called by
26740 `set-window-buffer'. Also note that the value of `window-end' is not
26741 valid when these functions are called. */);
26742 Vwindow_scroll_functions
= Qnil
;
26744 DEFVAR_LISP ("window-text-change-functions",
26745 Vwindow_text_change_functions
,
26746 doc
: /* Functions to call in redisplay when text in the window might change. */);
26747 Vwindow_text_change_functions
= Qnil
;
26749 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
26750 doc
: /* Functions called when redisplay of a window reaches the end trigger.
26751 Each function is called with two arguments, the window and the end trigger value.
26752 See `set-window-redisplay-end-trigger'. */);
26753 Vredisplay_end_trigger_functions
= Qnil
;
26755 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
26756 doc
: /* *Non-nil means autoselect window with mouse pointer.
26757 If nil, do not autoselect windows.
26758 A positive number means delay autoselection by that many seconds: a
26759 window is autoselected only after the mouse has remained in that
26760 window for the duration of the delay.
26761 A negative number has a similar effect, but causes windows to be
26762 autoselected only after the mouse has stopped moving. \(Because of
26763 the way Emacs compares mouse events, you will occasionally wait twice
26764 that time before the window gets selected.\)
26765 Any other value means to autoselect window instantaneously when the
26766 mouse pointer enters it.
26768 Autoselection selects the minibuffer only if it is active, and never
26769 unselects the minibuffer if it is active.
26771 When customizing this variable make sure that the actual value of
26772 `focus-follows-mouse' matches the behavior of your window manager. */);
26773 Vmouse_autoselect_window
= Qnil
;
26775 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
26776 doc
: /* *Non-nil means automatically resize tool-bars.
26777 This dynamically changes the tool-bar's height to the minimum height
26778 that is needed to make all tool-bar items visible.
26779 If value is `grow-only', the tool-bar's height is only increased
26780 automatically; to decrease the tool-bar height, use \\[recenter]. */);
26781 Vauto_resize_tool_bars
= Qt
;
26783 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
26784 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
26785 auto_raise_tool_bar_buttons_p
= 1;
26787 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
26788 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
26789 make_cursor_line_fully_visible_p
= 1;
26791 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
26792 doc
: /* *Border below tool-bar in pixels.
26793 If an integer, use it as the height of the border.
26794 If it is one of `internal-border-width' or `border-width', use the
26795 value of the corresponding frame parameter.
26796 Otherwise, no border is added below the tool-bar. */);
26797 Vtool_bar_border
= Qinternal_border_width
;
26799 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
26800 doc
: /* *Margin around tool-bar buttons in pixels.
26801 If an integer, use that for both horizontal and vertical margins.
26802 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
26803 HORZ specifying the horizontal margin, and VERT specifying the
26804 vertical margin. */);
26805 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
26807 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
26808 doc
: /* *Relief thickness of tool-bar buttons. */);
26809 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
26811 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
26812 doc
: /* Tool bar style to use.
26814 image - show images only
26815 text - show text only
26816 both - show both, text below image
26817 both-horiz - show text to the right of the image
26818 text-image-horiz - show text to the left of the image
26819 any other - use system default or image if no system default. */);
26820 Vtool_bar_style
= Qnil
;
26822 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
26823 doc
: /* *Maximum number of characters a label can have to be shown.
26824 The tool bar style must also show labels for this to have any effect, see
26825 `tool-bar-style'. */);
26826 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
26828 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
26829 doc
: /* List of functions to call to fontify regions of text.
26830 Each function is called with one argument POS. Functions must
26831 fontify a region starting at POS in the current buffer, and give
26832 fontified regions the property `fontified'. */);
26833 Vfontification_functions
= Qnil
;
26834 Fmake_variable_buffer_local (Qfontification_functions
);
26836 DEFVAR_BOOL ("unibyte-display-via-language-environment",
26837 unibyte_display_via_language_environment
,
26838 doc
: /* *Non-nil means display unibyte text according to language environment.
26839 Specifically, this means that raw bytes in the range 160-255 decimal
26840 are displayed by converting them to the equivalent multibyte characters
26841 according to the current language environment. As a result, they are
26842 displayed according to the current fontset.
26844 Note that this variable affects only how these bytes are displayed,
26845 but does not change the fact they are interpreted as raw bytes. */);
26846 unibyte_display_via_language_environment
= 0;
26848 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
26849 doc
: /* *Maximum height for resizing mini-windows (the minibuffer and the echo area).
26850 If a float, it specifies a fraction of the mini-window frame's height.
26851 If an integer, it specifies a number of lines. */);
26852 Vmax_mini_window_height
= make_float (0.25);
26854 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
26855 doc
: /* *How to resize mini-windows (the minibuffer and the echo area).
26856 A value of nil means don't automatically resize mini-windows.
26857 A value of t means resize them to fit the text displayed in them.
26858 A value of `grow-only', the default, means let mini-windows grow
26859 only, until their display becomes empty, at which point the windows
26860 go back to their normal size. */);
26861 Vresize_mini_windows
= Qgrow_only
;
26863 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
26864 doc
: /* Alist specifying how to blink the cursor off.
26865 Each element has the form (ON-STATE . OFF-STATE). Whenever the
26866 `cursor-type' frame-parameter or variable equals ON-STATE,
26867 comparing using `equal', Emacs uses OFF-STATE to specify
26868 how to blink it off. ON-STATE and OFF-STATE are values for
26869 the `cursor-type' frame parameter.
26871 If a frame's ON-STATE has no entry in this list,
26872 the frame's other specifications determine how to blink the cursor off. */);
26873 Vblink_cursor_alist
= Qnil
;
26875 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
26876 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
26877 If non-nil, windows are automatically scrolled horizontally to make
26878 point visible. */);
26879 automatic_hscrolling_p
= 1;
26880 DEFSYM (Qauto_hscroll_mode
, "auto-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 DEFSYM (Qwrap_prefix
, "wrap-prefix");
26937 Fmake_variable_buffer_local (Qwrap_prefix
);
26939 DEFVAR_LISP ("line-prefix", Vline_prefix
,
26940 doc
: /* Prefix prepended to all non-continuation lines at display time.
26941 The value may be a string, an image, or a stretch-glyph; it is
26942 interpreted in the same way as the value of a `display' text property.
26944 This variable is overridden by any `line-prefix' text or overlay
26947 To add a prefix to continuation lines, use `wrap-prefix'. */);
26948 Vline_prefix
= Qnil
;
26949 DEFSYM (Qline_prefix
, "line-prefix");
26950 Fmake_variable_buffer_local (Qline_prefix
);
26952 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
26953 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
26954 inhibit_eval_during_redisplay
= 0;
26956 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
26957 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
26958 inhibit_free_realized_faces
= 0;
26961 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
26962 doc
: /* Inhibit try_window_id display optimization. */);
26963 inhibit_try_window_id
= 0;
26965 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
26966 doc
: /* Inhibit try_window_reusing display optimization. */);
26967 inhibit_try_window_reusing
= 0;
26969 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
26970 doc
: /* Inhibit try_cursor_movement display optimization. */);
26971 inhibit_try_cursor_movement
= 0;
26972 #endif /* GLYPH_DEBUG */
26974 DEFVAR_INT ("overline-margin", overline_margin
,
26975 doc
: /* *Space between overline and text, in pixels.
26976 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
26977 margin to the caracter height. */);
26978 overline_margin
= 2;
26980 DEFVAR_INT ("underline-minimum-offset",
26981 underline_minimum_offset
,
26982 doc
: /* Minimum distance between baseline and underline.
26983 This can improve legibility of underlined text at small font sizes,
26984 particularly when using variable `x-use-underline-position-properties'
26985 with fonts that specify an UNDERLINE_POSITION relatively close to the
26986 baseline. The default value is 1. */);
26987 underline_minimum_offset
= 1;
26989 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
26990 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
26991 This feature only works when on a window system that can change
26992 cursor shapes. */);
26993 display_hourglass_p
= 1;
26995 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
26996 doc
: /* *Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
26997 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
26999 hourglass_atimer
= NULL
;
27000 hourglass_shown_p
= 0;
27002 DEFSYM (Qglyphless_char
, "glyphless-char");
27003 DEFSYM (Qhex_code
, "hex-code");
27004 DEFSYM (Qempty_box
, "empty-box");
27005 DEFSYM (Qthin_space
, "thin-space");
27006 DEFSYM (Qzero_width
, "zero-width");
27008 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
27009 /* Intern this now in case it isn't already done.
27010 Setting this variable twice is harmless.
27011 But don't staticpro it here--that is done in alloc.c. */
27012 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
27013 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
27015 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
27016 doc
: /* Char-table defining glyphless characters.
27017 Each element, if non-nil, should be one of the following:
27018 an ASCII acronym string: display this string in a box
27019 `hex-code': display the hexadecimal code of a character in a box
27020 `empty-box': display as an empty box
27021 `thin-space': display as 1-pixel width space
27022 `zero-width': don't display
27023 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
27024 display method for graphical terminals and text terminals respectively.
27025 GRAPHICAL and TEXT should each have one of the values listed above.
27027 The char-table has one extra slot to control the display of a character for
27028 which no font is found. This slot only takes effect on graphical terminals.
27029 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
27030 `thin-space'. The default is `empty-box'. */);
27031 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
27032 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
27037 /* Initialize this module when Emacs starts. */
27042 current_header_line_height
= current_mode_line_height
= -1;
27044 CHARPOS (this_line_start_pos
) = 0;
27046 if (!noninteractive
)
27048 struct window
*m
= XWINDOW (minibuf_window
);
27049 Lisp_Object frame
= m
->frame
;
27050 struct frame
*f
= XFRAME (frame
);
27051 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
27052 struct window
*r
= XWINDOW (root
);
27055 echo_area_window
= minibuf_window
;
27057 XSETFASTINT (r
->top_line
, FRAME_TOP_MARGIN (f
));
27058 XSETFASTINT (r
->total_lines
, FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
));
27059 XSETFASTINT (r
->total_cols
, FRAME_COLS (f
));
27060 XSETFASTINT (m
->top_line
, FRAME_LINES (f
) - 1);
27061 XSETFASTINT (m
->total_lines
, 1);
27062 XSETFASTINT (m
->total_cols
, FRAME_COLS (f
));
27064 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
27065 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
27066 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
27068 /* The default ellipsis glyphs `...'. */
27069 for (i
= 0; i
< 3; ++i
)
27070 default_invis_vector
[i
] = make_number ('.');
27074 /* Allocate the buffer for frame titles.
27075 Also used for `format-mode-line'. */
27077 mode_line_noprop_buf
= (char *) xmalloc (size
);
27078 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
27079 mode_line_noprop_ptr
= mode_line_noprop_buf
;
27080 mode_line_target
= MODE_LINE_DISPLAY
;
27083 help_echo_showing_p
= 0;
27086 /* Since w32 does not support atimers, it defines its own implementation of
27087 the following three functions in w32fns.c. */
27090 /* Platform-independent portion of hourglass implementation. */
27092 /* Return non-zero if houglass timer has been started or hourglass is shown. */
27094 hourglass_started (void)
27096 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
27099 /* Cancel a currently active hourglass timer, and start a new one. */
27101 start_hourglass (void)
27103 #if defined (HAVE_WINDOW_SYSTEM)
27105 int secs
, usecs
= 0;
27107 cancel_hourglass ();
27109 if (INTEGERP (Vhourglass_delay
)
27110 && XINT (Vhourglass_delay
) > 0)
27111 secs
= XFASTINT (Vhourglass_delay
);
27112 else if (FLOATP (Vhourglass_delay
)
27113 && XFLOAT_DATA (Vhourglass_delay
) > 0)
27116 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
27117 secs
= XFASTINT (tem
);
27118 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
27121 secs
= DEFAULT_HOURGLASS_DELAY
;
27123 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
27124 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
27125 show_hourglass
, NULL
);
27130 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
27133 cancel_hourglass (void)
27135 #if defined (HAVE_WINDOW_SYSTEM)
27136 if (hourglass_atimer
)
27138 cancel_atimer (hourglass_atimer
);
27139 hourglass_atimer
= NULL
;
27142 if (hourglass_shown_p
)
27146 #endif /* ! WINDOWSNT */