1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2011 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
24 Emacs separates the task of updating the display from code
25 modifying global state, e.g. buffer text. This way functions
26 operating on buffers don't also have to be concerned with updating
29 Updating the display is triggered by the Lisp interpreter when it
30 decides it's time to do it. This is done either automatically for
31 you as part of the interpreter's command loop or as the result of
32 calling Lisp functions like `sit-for'. The C function `redisplay'
33 in xdisp.c is the only entry into the inner redisplay code.
35 The following diagram shows how redisplay code is invoked. As you
36 can see, Lisp calls redisplay and vice versa. Under window systems
37 like X, some portions of the redisplay code are also called
38 asynchronously during mouse movement or expose events. It is very
39 important that these code parts do NOT use the C library (malloc,
40 free) because many C libraries under Unix are not reentrant. They
41 may also NOT call functions of the Lisp interpreter which could
42 change the interpreter's state. If you don't follow these rules,
43 you will encounter bugs which are very hard to explain.
45 +--------------+ redisplay +----------------+
46 | Lisp machine |---------------->| Redisplay code |<--+
47 +--------------+ (xdisp.c) +----------------+ |
49 +----------------------------------+ |
50 Don't use this path when called |
53 expose_window (asynchronous) |
55 X expose events -----+
57 What does redisplay do? Obviously, it has to figure out somehow what
58 has been changed since the last time the display has been updated,
59 and to make these changes visible. Preferably it would do that in
60 a moderately intelligent way, i.e. fast.
62 Changes in buffer text can be deduced from window and buffer
63 structures, and from some global variables like `beg_unchanged' and
64 `end_unchanged'. The contents of the display are additionally
65 recorded in a `glyph matrix', a two-dimensional matrix of glyph
66 structures. Each row in such a matrix corresponds to a line on the
67 display, and each glyph in a row corresponds to a column displaying
68 a character, an image, or what else. This matrix is called the
69 `current glyph matrix' or `current matrix' in redisplay
72 For buffer parts that have been changed since the last update, a
73 second glyph matrix is constructed, the so called `desired glyph
74 matrix' or short `desired matrix'. Current and desired matrix are
75 then compared to find a cheap way to update the display, e.g. by
76 reusing part of the display by scrolling lines.
78 You will find a lot of redisplay optimizations when you start
79 looking at the innards of redisplay. The overall goal of all these
80 optimizations is to make redisplay fast because it is done
81 frequently. Some of these optimizations are implemented by the
86 This function tries to update the display if the text in the
87 window did not change and did not scroll, only point moved, and
88 it did not move off the displayed portion of the text.
90 . try_window_reusing_current_matrix
92 This function reuses the current matrix of a window when text
93 has not changed, but the window start changed (e.g., due to
98 This function attempts to redisplay a window by reusing parts of
99 its existing display. It finds and reuses the part that was not
100 changed, and redraws the rest.
104 This function performs the full redisplay of a single window
105 assuming that its fonts were not changed and that the cursor
106 will not end up in the scroll margins. (Loading fonts requires
107 re-adjustment of dimensions of glyph matrices, which makes this
108 method impossible to use.)
110 These optimizations are tried in sequence (some can be skipped if
111 it is known that they are not applicable). If none of the
112 optimizations were successful, redisplay calls redisplay_windows,
113 which performs a full redisplay of all windows.
117 Desired matrices are always built per Emacs window. The function
118 `display_line' is the central function to look at if you are
119 interested. It constructs one row in a desired matrix given an
120 iterator structure containing both a buffer position and a
121 description of the environment in which the text is to be
122 displayed. But this is too early, read on.
124 Characters and pixmaps displayed for a range of buffer text depend
125 on various settings of buffers and windows, on overlays and text
126 properties, on display tables, on selective display. The good news
127 is that all this hairy stuff is hidden behind a small set of
128 interface functions taking an iterator structure (struct it)
131 Iteration over things to be displayed is then simple. It is
132 started by initializing an iterator with a call to init_iterator,
133 passing it the buffer position where to start iteration. For
134 iteration over strings, pass -1 as the position to init_iterator,
135 and call reseat_to_string when the string is ready, to initialize
136 the iterator for that string. Thereafter, calls to
137 get_next_display_element fill the iterator structure with relevant
138 information about the next thing to display. Calls to
139 set_iterator_to_next move the iterator to the next thing.
141 Besides this, an iterator also contains information about the
142 display environment in which glyphs for display elements are to be
143 produced. It has fields for the width and height of the display,
144 the information whether long lines are truncated or continued, a
145 current X and Y position, and lots of other stuff you can better
148 Glyphs in a desired matrix are normally constructed in a loop
149 calling get_next_display_element and then PRODUCE_GLYPHS. The call
150 to PRODUCE_GLYPHS will fill the iterator structure with pixel
151 information about the element being displayed and at the same time
152 produce glyphs for it. If the display element fits on the line
153 being displayed, set_iterator_to_next is called next, otherwise the
154 glyphs produced are discarded. The function display_line is the
155 workhorse of filling glyph rows in the desired matrix with glyphs.
156 In addition to producing glyphs, it also handles line truncation
157 and continuation, word wrap, and cursor positioning (for the
158 latter, see also set_cursor_from_row).
162 That just couldn't be all, could it? What about terminal types not
163 supporting operations on sub-windows of the screen? To update the
164 display on such a terminal, window-based glyph matrices are not
165 well suited. To be able to reuse part of the display (scrolling
166 lines up and down), we must instead have a view of the whole
167 screen. This is what `frame matrices' are for. They are a trick.
169 Frames on terminals like above have a glyph pool. Windows on such
170 a frame sub-allocate their glyph memory from their frame's glyph
171 pool. The frame itself is given its own glyph matrices. By
172 coincidence---or maybe something else---rows in window glyph
173 matrices are slices of corresponding rows in frame matrices. Thus
174 writing to window matrices implicitly updates a frame matrix which
175 provides us with the view of the whole screen that we originally
176 wanted to have without having to move many bytes around. To be
177 honest, there is a little bit more done, but not much more. If you
178 plan to extend that code, take a look at dispnew.c. The function
179 build_frame_matrix is a good starting point.
181 Bidirectional display.
183 Bidirectional display adds quite some hair to this already complex
184 design. The good news are that a large portion of that hairy stuff
185 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
186 reordering engine which is called by set_iterator_to_next and
187 returns the next character to display in the visual order. See
188 commentary on bidi.c for more details. As far as redisplay is
189 concerned, the effect of calling bidi_move_to_visually_next, the
190 main interface of the reordering engine, is that the iterator gets
191 magically placed on the buffer or string position that is to be
192 displayed next. In other words, a linear iteration through the
193 buffer/string is replaced with a non-linear one. All the rest of
194 the redisplay is oblivious to the bidi reordering.
196 Well, almost oblivious---there are still complications, most of
197 them due to the fact that buffer and string positions no longer
198 change monotonously with glyph indices in a glyph row. Moreover,
199 for continued lines, the buffer positions may not even be
200 monotonously changing with vertical positions. Also, accounting
201 for face changes, overlays, etc. becomes more complex because
202 non-linear iteration could potentially skip many positions with
203 changes, and then cross them again on the way back...
205 One other prominent effect of bidirectional display is that some
206 paragraphs of text need to be displayed starting at the right
207 margin of the window---the so-called right-to-left, or R2L
208 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
209 which have their reversed_p flag set. The bidi reordering engine
210 produces characters in such rows starting from the character which
211 should be the rightmost on display. PRODUCE_GLYPHS then reverses
212 the order, when it fills up the glyph row whose reversed_p flag is
213 set, by prepending each new glyph to what is already there, instead
214 of appending it. When the glyph row is complete, the function
215 extend_face_to_end_of_line fills the empty space to the left of the
216 leftmost character with special glyphs, which will display as,
217 well, empty. On text terminals, these special glyphs are simply
218 blank characters. On graphics terminals, there's a single stretch
219 glyph of a suitably computed width. Both the blanks and the
220 stretch glyph are given the face of the background of the line.
221 This way, the terminal-specific back-end can still draw the glyphs
222 left to right, even for R2L lines.
224 Bidirectional display and character compositions
226 Some scripts cannot be displayed by drawing each character
227 individually, because adjacent characters change each other's shape
228 on display. For example, Arabic and Indic scripts belong to this
231 Emacs display supports this by providing "character compositions",
232 most of which is implemented in composite.c. During the buffer
233 scan that delivers characters to PRODUCE_GLYPHS, if the next
234 character to be delivered is a composed character, the iteration
235 calls composition_reseat_it and next_element_from_composition. If
236 they succeed to compose the character with one or more of the
237 following characters, the whole sequence of characters that where
238 composed is recorded in the `struct composition_it' object that is
239 part of the buffer iterator. The composed sequence could produce
240 one or more font glyphs (called "grapheme clusters") on the screen.
241 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
242 in the direction corresponding to the current bidi scan direction
243 (recorded in the scan_dir member of the `struct bidi_it' object
244 that is part of the buffer iterator). In particular, if the bidi
245 iterator currently scans the buffer backwards, the grapheme
246 clusters are delivered back to front. This reorders the grapheme
247 clusters as appropriate for the current bidi context. Note that
248 this means that the grapheme clusters are always stored in the
249 LGSTRING object (see composite.c) in the logical order.
251 Moving an iterator in bidirectional text
252 without producing glyphs
254 Note one important detail mentioned above: that the bidi reordering
255 engine, driven by the iterator, produces characters in R2L rows
256 starting at the character that will be the rightmost on display.
257 As far as the iterator is concerned, the geometry of such rows is
258 still left to right, i.e. the iterator "thinks" the first character
259 is at the leftmost pixel position. The iterator does not know that
260 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
261 delivers. This is important when functions from the the move_it_*
262 family are used to get to certain screen position or to match
263 screen coordinates with buffer coordinates: these functions use the
264 iterator geometry, which is left to right even in R2L paragraphs.
265 This works well with most callers of move_it_*, because they need
266 to get to a specific column, and columns are still numbered in the
267 reading order, i.e. the rightmost character in a R2L paragraph is
268 still column zero. But some callers do not get well with this; a
269 notable example is mouse clicks that need to find the character
270 that corresponds to certain pixel coordinates. See
271 buffer_posn_from_coords in dispnew.c for how this is handled. */
279 #include "keyboard.h"
282 #include "termchar.h"
283 #include "dispextern.h"
285 #include "character.h"
288 #include "commands.h"
292 #include "termhooks.h"
293 #include "termopts.h"
294 #include "intervals.h"
297 #include "region-cache.h"
300 #include "blockinput.h"
302 #ifdef HAVE_X_WINDOWS
317 #ifndef FRAME_X_OUTPUT
318 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
321 #define INFINITY 10000000
323 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
324 Lisp_Object Qwindow_scroll_functions
;
325 static Lisp_Object Qwindow_text_change_functions
;
326 static Lisp_Object Qredisplay_end_trigger_functions
;
327 Lisp_Object Qinhibit_point_motion_hooks
;
328 static Lisp_Object QCeval
, QCpropertize
;
329 Lisp_Object QCfile
, QCdata
;
330 static Lisp_Object Qfontified
;
331 static Lisp_Object Qgrow_only
;
332 static Lisp_Object Qinhibit_eval_during_redisplay
;
333 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
334 static Lisp_Object Qright_to_left
, Qleft_to_right
;
337 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
340 static Lisp_Object Qarrow
, Qhand
;
343 /* Holds the list (error). */
344 static Lisp_Object list_of_error
;
346 static Lisp_Object Qfontification_functions
;
348 static Lisp_Object Qwrap_prefix
;
349 static Lisp_Object Qline_prefix
;
351 /* Non-nil means don't actually do any redisplay. */
353 Lisp_Object Qinhibit_redisplay
;
355 /* Names of text properties relevant for redisplay. */
357 Lisp_Object Qdisplay
;
359 Lisp_Object Qspace
, QCalign_to
;
360 static Lisp_Object QCrelative_width
, QCrelative_height
;
361 Lisp_Object Qleft_margin
, Qright_margin
;
362 static Lisp_Object Qspace_width
, Qraise
;
363 static Lisp_Object Qslice
;
365 static Lisp_Object Qmargin
, Qpointer
;
366 static Lisp_Object Qline_height
;
368 #ifdef HAVE_WINDOW_SYSTEM
370 /* Test if overflow newline into fringe. Called with iterator IT
371 at or past right window margin, and with IT->current_x set. */
373 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
374 (!NILP (Voverflow_newline_into_fringe) \
375 && FRAME_WINDOW_P ((IT)->f) \
376 && ((IT)->bidi_it.paragraph_dir == R2L \
377 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
378 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
379 && (IT)->current_x == (IT)->last_visible_x \
380 && (IT)->line_wrap != WORD_WRAP)
382 #else /* !HAVE_WINDOW_SYSTEM */
383 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
384 #endif /* HAVE_WINDOW_SYSTEM */
386 /* Test if the display element loaded in IT is a space or tab
387 character. This is used to determine word wrapping. */
389 #define IT_DISPLAYING_WHITESPACE(it) \
390 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
392 /* Name of the face used to highlight trailing whitespace. */
394 static Lisp_Object Qtrailing_whitespace
;
396 /* Name and number of the face used to highlight escape glyphs. */
398 static Lisp_Object Qescape_glyph
;
400 /* Name and number of the face used to highlight non-breaking spaces. */
402 static Lisp_Object Qnobreak_space
;
404 /* The symbol `image' which is the car of the lists used to represent
405 images in Lisp. Also a tool bar style. */
409 /* The image map types. */
411 static Lisp_Object QCpointer
;
412 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
414 /* Tool bar styles */
415 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
417 /* Non-zero means print newline to stdout before next mini-buffer
420 int noninteractive_need_newline
;
422 /* Non-zero means print newline to message log before next message. */
424 static int message_log_need_newline
;
426 /* Three markers that message_dolog uses.
427 It could allocate them itself, but that causes trouble
428 in handling memory-full errors. */
429 static Lisp_Object message_dolog_marker1
;
430 static Lisp_Object message_dolog_marker2
;
431 static Lisp_Object message_dolog_marker3
;
433 /* The buffer position of the first character appearing entirely or
434 partially on the line of the selected window which contains the
435 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
436 redisplay optimization in redisplay_internal. */
438 static struct text_pos this_line_start_pos
;
440 /* Number of characters past the end of the line above, including the
441 terminating newline. */
443 static struct text_pos this_line_end_pos
;
445 /* The vertical positions and the height of this line. */
447 static int this_line_vpos
;
448 static int this_line_y
;
449 static int this_line_pixel_height
;
451 /* X position at which this display line starts. Usually zero;
452 negative if first character is partially visible. */
454 static int this_line_start_x
;
456 /* The smallest character position seen by move_it_* functions as they
457 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
458 hscrolled lines, see display_line. */
460 static struct text_pos this_line_min_pos
;
462 /* Buffer that this_line_.* variables are referring to. */
464 static struct buffer
*this_line_buffer
;
467 /* Values of those variables at last redisplay are stored as
468 properties on `overlay-arrow-position' symbol. However, if
469 Voverlay_arrow_position is a marker, last-arrow-position is its
470 numerical position. */
472 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
474 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
475 properties on a symbol in overlay-arrow-variable-list. */
477 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
479 Lisp_Object Qmenu_bar_update_hook
;
481 /* Nonzero if an overlay arrow has been displayed in this window. */
483 static int overlay_arrow_seen
;
485 /* Number of windows showing the buffer of the selected window (or
486 another buffer with the same base buffer). keyboard.c refers to
491 /* Vector containing glyphs for an ellipsis `...'. */
493 static Lisp_Object default_invis_vector
[3];
495 /* This is the window where the echo area message was displayed. It
496 is always a mini-buffer window, but it may not be the same window
497 currently active as a mini-buffer. */
499 Lisp_Object echo_area_window
;
501 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
502 pushes the current message and the value of
503 message_enable_multibyte on the stack, the function restore_message
504 pops the stack and displays MESSAGE again. */
506 static Lisp_Object Vmessage_stack
;
508 /* Nonzero means multibyte characters were enabled when the echo area
509 message was specified. */
511 static int message_enable_multibyte
;
513 /* Nonzero if we should redraw the mode lines on the next redisplay. */
515 int update_mode_lines
;
517 /* Nonzero if window sizes or contents have changed since last
518 redisplay that finished. */
520 int windows_or_buffers_changed
;
522 /* Nonzero means a frame's cursor type has been changed. */
524 int cursor_type_changed
;
526 /* Nonzero after display_mode_line if %l was used and it displayed a
529 static int line_number_displayed
;
531 /* The name of the *Messages* buffer, a string. */
533 static Lisp_Object Vmessages_buffer_name
;
535 /* Current, index 0, and last displayed echo area message. Either
536 buffers from echo_buffers, or nil to indicate no message. */
538 Lisp_Object echo_area_buffer
[2];
540 /* The buffers referenced from echo_area_buffer. */
542 static Lisp_Object echo_buffer
[2];
544 /* A vector saved used in with_area_buffer to reduce consing. */
546 static Lisp_Object Vwith_echo_area_save_vector
;
548 /* Non-zero means display_echo_area should display the last echo area
549 message again. Set by redisplay_preserve_echo_area. */
551 static int display_last_displayed_message_p
;
553 /* Nonzero if echo area is being used by print; zero if being used by
556 static int message_buf_print
;
558 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
560 static Lisp_Object Qinhibit_menubar_update
;
561 static Lisp_Object Qmessage_truncate_lines
;
563 /* Set to 1 in clear_message to make redisplay_internal aware
564 of an emptied echo area. */
566 static int message_cleared_p
;
568 /* A scratch glyph row with contents used for generating truncation
569 glyphs. Also used in direct_output_for_insert. */
571 #define MAX_SCRATCH_GLYPHS 100
572 static struct glyph_row scratch_glyph_row
;
573 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
575 /* Ascent and height of the last line processed by move_it_to. */
577 static int last_max_ascent
, last_height
;
579 /* Non-zero if there's a help-echo in the echo area. */
581 int help_echo_showing_p
;
583 /* If >= 0, computed, exact values of mode-line and header-line height
584 to use in the macros CURRENT_MODE_LINE_HEIGHT and
585 CURRENT_HEADER_LINE_HEIGHT. */
587 int current_mode_line_height
, current_header_line_height
;
589 /* The maximum distance to look ahead for text properties. Values
590 that are too small let us call compute_char_face and similar
591 functions too often which is expensive. Values that are too large
592 let us call compute_char_face and alike too often because we
593 might not be interested in text properties that far away. */
595 #define TEXT_PROP_DISTANCE_LIMIT 100
599 /* Non-zero means print traces of redisplay if compiled with
602 int trace_redisplay_p
;
604 #endif /* GLYPH_DEBUG */
606 #ifdef DEBUG_TRACE_MOVE
607 /* Non-zero means trace with TRACE_MOVE to stderr. */
610 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
612 #define TRACE_MOVE(x) (void) 0
615 static Lisp_Object Qauto_hscroll_mode
;
617 /* Buffer being redisplayed -- for redisplay_window_error. */
619 static struct buffer
*displayed_buffer
;
621 /* Value returned from text property handlers (see below). */
626 HANDLED_RECOMPUTE_PROPS
,
627 HANDLED_OVERLAY_STRING_CONSUMED
,
631 /* A description of text properties that redisplay is interested
636 /* The name of the property. */
639 /* A unique index for the property. */
642 /* A handler function called to set up iterator IT from the property
643 at IT's current position. Value is used to steer handle_stop. */
644 enum prop_handled (*handler
) (struct it
*it
);
647 static enum prop_handled
handle_face_prop (struct it
*);
648 static enum prop_handled
handle_invisible_prop (struct it
*);
649 static enum prop_handled
handle_display_prop (struct it
*);
650 static enum prop_handled
handle_composition_prop (struct it
*);
651 static enum prop_handled
handle_overlay_change (struct it
*);
652 static enum prop_handled
handle_fontified_prop (struct it
*);
654 /* Properties handled by iterators. */
656 static struct props it_props
[] =
658 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
659 /* Handle `face' before `display' because some sub-properties of
660 `display' need to know the face. */
661 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
662 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
663 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
664 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
668 /* Value is the position described by X. If X is a marker, value is
669 the marker_position of X. Otherwise, value is X. */
671 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
673 /* Enumeration returned by some move_it_.* functions internally. */
677 /* Not used. Undefined value. */
680 /* Move ended at the requested buffer position or ZV. */
681 MOVE_POS_MATCH_OR_ZV
,
683 /* Move ended at the requested X pixel position. */
686 /* Move within a line ended at the end of a line that must be
690 /* Move within a line ended at the end of a line that would
691 be displayed truncated. */
694 /* Move within a line ended at a line end. */
698 /* This counter is used to clear the face cache every once in a while
699 in redisplay_internal. It is incremented for each redisplay.
700 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
703 #define CLEAR_FACE_CACHE_COUNT 500
704 static int clear_face_cache_count
;
706 /* Similarly for the image cache. */
708 #ifdef HAVE_WINDOW_SYSTEM
709 #define CLEAR_IMAGE_CACHE_COUNT 101
710 static int clear_image_cache_count
;
712 /* Null glyph slice */
713 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
716 /* Non-zero while redisplay_internal is in progress. */
720 static Lisp_Object Qinhibit_free_realized_faces
;
722 /* If a string, XTread_socket generates an event to display that string.
723 (The display is done in read_char.) */
725 Lisp_Object help_echo_string
;
726 Lisp_Object help_echo_window
;
727 Lisp_Object help_echo_object
;
728 EMACS_INT help_echo_pos
;
730 /* Temporary variable for XTread_socket. */
732 Lisp_Object previous_help_echo_string
;
734 /* Platform-independent portion of hourglass implementation. */
736 /* Non-zero means an hourglass cursor is currently shown. */
737 int hourglass_shown_p
;
739 /* If non-null, an asynchronous timer that, when it expires, displays
740 an hourglass cursor on all frames. */
741 struct atimer
*hourglass_atimer
;
743 /* Name of the face used to display glyphless characters. */
744 Lisp_Object Qglyphless_char
;
746 /* Symbol for the purpose of Vglyphless_char_display. */
747 static Lisp_Object Qglyphless_char_display
;
749 /* Method symbols for Vglyphless_char_display. */
750 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
752 /* Default pixel width of `thin-space' display method. */
753 #define THIN_SPACE_WIDTH 1
755 /* Default number of seconds to wait before displaying an hourglass
757 #define DEFAULT_HOURGLASS_DELAY 1
760 /* Function prototypes. */
762 static void setup_for_ellipsis (struct it
*, int);
763 static void set_iterator_to_next (struct it
*, int);
764 static void mark_window_display_accurate_1 (struct window
*, int);
765 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
766 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
767 static int cursor_row_p (struct glyph_row
*);
768 static int redisplay_mode_lines (Lisp_Object
, int);
769 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
771 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
773 static void handle_line_prefix (struct it
*);
775 static void pint2str (char *, int, EMACS_INT
);
776 static void pint2hrstr (char *, int, EMACS_INT
);
777 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
779 static void reconsider_clip_changes (struct window
*, struct buffer
*);
780 static int text_outside_line_unchanged_p (struct window
*,
781 EMACS_INT
, EMACS_INT
);
782 static void store_mode_line_noprop_char (char);
783 static int store_mode_line_noprop (const char *, int, int);
784 static void handle_stop (struct it
*);
785 static void handle_stop_backwards (struct it
*, EMACS_INT
);
786 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
787 static void ensure_echo_area_buffers (void);
788 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
789 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
790 static int with_echo_area_buffer (struct window
*, int,
791 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
792 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
793 static void clear_garbaged_frames (void);
794 static int current_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
795 static void pop_message (void);
796 static int truncate_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
797 static void set_message (const char *, Lisp_Object
, EMACS_INT
, int);
798 static int set_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
799 static int display_echo_area (struct window
*);
800 static int display_echo_area_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
801 static int resize_mini_window_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
802 static Lisp_Object
unwind_redisplay (Lisp_Object
);
803 static int string_char_and_length (const unsigned char *, int *);
804 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
806 static int compute_window_start_on_continuation_line (struct window
*);
807 static Lisp_Object
safe_eval_handler (Lisp_Object
);
808 static void insert_left_trunc_glyphs (struct it
*);
809 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
811 static void extend_face_to_end_of_line (struct it
*);
812 static int append_space_for_newline (struct it
*, int);
813 static int cursor_row_fully_visible_p (struct window
*, int, int);
814 static int try_scrolling (Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int);
815 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
816 static int trailing_whitespace_p (EMACS_INT
);
817 static unsigned long int message_log_check_duplicate (EMACS_INT
, EMACS_INT
);
818 static void push_it (struct it
*, struct text_pos
*);
819 static void pop_it (struct it
*);
820 static void sync_frame_with_window_matrix_rows (struct window
*);
821 static void select_frame_for_redisplay (Lisp_Object
);
822 static void redisplay_internal (void);
823 static int echo_area_display (int);
824 static void redisplay_windows (Lisp_Object
);
825 static void redisplay_window (Lisp_Object
, int);
826 static Lisp_Object
redisplay_window_error (Lisp_Object
);
827 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
828 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
829 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
830 struct glyph_matrix
*, EMACS_INT
, EMACS_INT
,
832 static int update_menu_bar (struct frame
*, int, int);
833 static int try_window_reusing_current_matrix (struct window
*);
834 static int try_window_id (struct window
*);
835 static int display_line (struct it
*);
836 static int display_mode_lines (struct window
*);
837 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
838 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
839 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
840 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
841 static void display_menu_bar (struct window
*);
842 static EMACS_INT
display_count_lines (EMACS_INT
, EMACS_INT
, EMACS_INT
,
844 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
845 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int);
846 static void compute_line_metrics (struct it
*);
847 static void run_redisplay_end_trigger_hook (struct it
*);
848 static int get_overlay_strings (struct it
*, EMACS_INT
);
849 static int get_overlay_strings_1 (struct it
*, EMACS_INT
, int);
850 static void next_overlay_string (struct it
*);
851 static void reseat (struct it
*, struct text_pos
, int);
852 static void reseat_1 (struct it
*, struct text_pos
, int);
853 static void back_to_previous_visible_line_start (struct it
*);
854 void reseat_at_previous_visible_line_start (struct it
*);
855 static void reseat_at_next_visible_line_start (struct it
*, int);
856 static int next_element_from_ellipsis (struct it
*);
857 static int next_element_from_display_vector (struct it
*);
858 static int next_element_from_string (struct it
*);
859 static int next_element_from_c_string (struct it
*);
860 static int next_element_from_buffer (struct it
*);
861 static int next_element_from_composition (struct it
*);
862 static int next_element_from_image (struct it
*);
863 static int next_element_from_stretch (struct it
*);
864 static void load_overlay_strings (struct it
*, EMACS_INT
);
865 static int init_from_display_pos (struct it
*, struct window
*,
866 struct display_pos
*);
867 static void reseat_to_string (struct it
*, const char *,
868 Lisp_Object
, EMACS_INT
, EMACS_INT
, int, int);
869 static int get_next_display_element (struct it
*);
870 static enum move_it_result
871 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
872 enum move_operation_enum
);
873 void move_it_vertically_backward (struct it
*, int);
874 static void init_to_row_start (struct it
*, struct window
*,
876 static int init_to_row_end (struct it
*, struct window
*,
878 static void back_to_previous_line_start (struct it
*);
879 static int forward_to_next_line_start (struct it
*, int *);
880 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
881 Lisp_Object
, EMACS_INT
);
882 static struct text_pos
string_pos (EMACS_INT
, Lisp_Object
);
883 static struct text_pos
c_string_pos (EMACS_INT
, const char *, int);
884 static EMACS_INT
number_of_chars (const char *, int);
885 static void compute_stop_pos (struct it
*);
886 static void compute_string_pos (struct text_pos
*, struct text_pos
,
888 static int face_before_or_after_it_pos (struct it
*, int);
889 static EMACS_INT
next_overlay_change (EMACS_INT
);
890 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
891 Lisp_Object
, struct text_pos
*, EMACS_INT
, int);
892 static int handle_single_display_spec (struct it
*, Lisp_Object
,
893 Lisp_Object
, Lisp_Object
,
894 struct text_pos
*, EMACS_INT
, int, int);
895 static int underlying_face_id (struct it
*);
896 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
899 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
900 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
902 #ifdef HAVE_WINDOW_SYSTEM
904 static void x_consider_frame_title (Lisp_Object
);
905 static int tool_bar_lines_needed (struct frame
*, int *);
906 static void update_tool_bar (struct frame
*, int);
907 static void build_desired_tool_bar_string (struct frame
*f
);
908 static int redisplay_tool_bar (struct frame
*);
909 static void display_tool_bar_line (struct it
*, int);
910 static void notice_overwritten_cursor (struct window
*,
913 static void append_stretch_glyph (struct it
*, Lisp_Object
,
917 #endif /* HAVE_WINDOW_SYSTEM */
919 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
920 static int coords_in_mouse_face_p (struct window
*, int, int);
924 /***********************************************************************
925 Window display dimensions
926 ***********************************************************************/
928 /* Return the bottom boundary y-position for text lines in window W.
929 This is the first y position at which a line cannot start.
930 It is relative to the top of the window.
932 This is the height of W minus the height of a mode line, if any. */
935 window_text_bottom_y (struct window
*w
)
937 int height
= WINDOW_TOTAL_HEIGHT (w
);
939 if (WINDOW_WANTS_MODELINE_P (w
))
940 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
944 /* Return the pixel width of display area AREA of window W. AREA < 0
945 means return the total width of W, not including fringes to
946 the left and right of the window. */
949 window_box_width (struct window
*w
, int area
)
951 int cols
= XFASTINT (w
->total_cols
);
954 if (!w
->pseudo_window_p
)
956 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
958 if (area
== TEXT_AREA
)
960 if (INTEGERP (w
->left_margin_cols
))
961 cols
-= XFASTINT (w
->left_margin_cols
);
962 if (INTEGERP (w
->right_margin_cols
))
963 cols
-= XFASTINT (w
->right_margin_cols
);
964 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
966 else if (area
== LEFT_MARGIN_AREA
)
968 cols
= (INTEGERP (w
->left_margin_cols
)
969 ? XFASTINT (w
->left_margin_cols
) : 0);
972 else if (area
== RIGHT_MARGIN_AREA
)
974 cols
= (INTEGERP (w
->right_margin_cols
)
975 ? XFASTINT (w
->right_margin_cols
) : 0);
980 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
984 /* Return the pixel height of the display area of window W, not
985 including mode lines of W, if any. */
988 window_box_height (struct window
*w
)
990 struct frame
*f
= XFRAME (w
->frame
);
991 int height
= WINDOW_TOTAL_HEIGHT (w
);
993 xassert (height
>= 0);
995 /* Note: the code below that determines the mode-line/header-line
996 height is essentially the same as that contained in the macro
997 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
998 the appropriate glyph row has its `mode_line_p' flag set,
999 and if it doesn't, uses estimate_mode_line_height instead. */
1001 if (WINDOW_WANTS_MODELINE_P (w
))
1003 struct glyph_row
*ml_row
1004 = (w
->current_matrix
&& w
->current_matrix
->rows
1005 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1007 if (ml_row
&& ml_row
->mode_line_p
)
1008 height
-= ml_row
->height
;
1010 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1013 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1015 struct glyph_row
*hl_row
1016 = (w
->current_matrix
&& w
->current_matrix
->rows
1017 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1019 if (hl_row
&& hl_row
->mode_line_p
)
1020 height
-= hl_row
->height
;
1022 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1025 /* With a very small font and a mode-line that's taller than
1026 default, we might end up with a negative height. */
1027 return max (0, height
);
1030 /* Return the window-relative coordinate of the left edge of display
1031 area AREA of window W. AREA < 0 means return the left edge of the
1032 whole window, to the right of the left fringe of W. */
1035 window_box_left_offset (struct window
*w
, int area
)
1039 if (w
->pseudo_window_p
)
1042 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1044 if (area
== TEXT_AREA
)
1045 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1046 + window_box_width (w
, LEFT_MARGIN_AREA
));
1047 else if (area
== RIGHT_MARGIN_AREA
)
1048 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1049 + window_box_width (w
, LEFT_MARGIN_AREA
)
1050 + window_box_width (w
, TEXT_AREA
)
1051 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1053 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1054 else if (area
== LEFT_MARGIN_AREA
1055 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1056 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1062 /* Return the window-relative coordinate of the right edge of display
1063 area AREA of window W. AREA < 0 means return the right edge of the
1064 whole window, to the left of the right fringe of W. */
1067 window_box_right_offset (struct window
*w
, int area
)
1069 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1072 /* Return the frame-relative coordinate of the left edge of display
1073 area AREA of window W. AREA < 0 means return the left edge of the
1074 whole window, to the right of the left fringe of W. */
1077 window_box_left (struct window
*w
, int area
)
1079 struct frame
*f
= XFRAME (w
->frame
);
1082 if (w
->pseudo_window_p
)
1083 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1085 x
= (WINDOW_LEFT_EDGE_X (w
)
1086 + window_box_left_offset (w
, area
));
1092 /* Return the frame-relative coordinate of the right edge of display
1093 area AREA of window W. AREA < 0 means return the right edge of the
1094 whole window, to the left of the right fringe of W. */
1097 window_box_right (struct window
*w
, int area
)
1099 return window_box_left (w
, area
) + window_box_width (w
, area
);
1102 /* Get the bounding box of the display area AREA of window W, without
1103 mode lines, in frame-relative coordinates. AREA < 0 means the
1104 whole window, not including the left and right fringes of
1105 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1106 coordinates of the upper-left corner of the box. Return in
1107 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1110 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1111 int *box_width
, int *box_height
)
1114 *box_width
= window_box_width (w
, area
);
1116 *box_height
= window_box_height (w
);
1118 *box_x
= window_box_left (w
, area
);
1121 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1122 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1123 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1128 /* Get the bounding box of the display area AREA of window W, without
1129 mode lines. AREA < 0 means the whole window, not including the
1130 left and right fringe of the window. Return in *TOP_LEFT_X
1131 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1132 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1133 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1137 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1138 int *bottom_right_x
, int *bottom_right_y
)
1140 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1142 *bottom_right_x
+= *top_left_x
;
1143 *bottom_right_y
+= *top_left_y
;
1148 /***********************************************************************
1150 ***********************************************************************/
1152 /* Return the bottom y-position of the line the iterator IT is in.
1153 This can modify IT's settings. */
1156 line_bottom_y (struct it
*it
)
1158 int line_height
= it
->max_ascent
+ it
->max_descent
;
1159 int line_top_y
= it
->current_y
;
1161 if (line_height
== 0)
1164 line_height
= last_height
;
1165 else if (IT_CHARPOS (*it
) < ZV
)
1167 move_it_by_lines (it
, 1);
1168 line_height
= (it
->max_ascent
|| it
->max_descent
1169 ? it
->max_ascent
+ it
->max_descent
1174 struct glyph_row
*row
= it
->glyph_row
;
1176 /* Use the default character height. */
1177 it
->glyph_row
= NULL
;
1178 it
->what
= IT_CHARACTER
;
1181 PRODUCE_GLYPHS (it
);
1182 line_height
= it
->ascent
+ it
->descent
;
1183 it
->glyph_row
= row
;
1187 return line_top_y
+ line_height
;
1191 /* Return 1 if position CHARPOS is visible in window W.
1192 CHARPOS < 0 means return info about WINDOW_END position.
1193 If visible, set *X and *Y to pixel coordinates of top left corner.
1194 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1195 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1198 pos_visible_p (struct window
*w
, EMACS_INT charpos
, int *x
, int *y
,
1199 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1202 struct text_pos top
;
1204 struct buffer
*old_buffer
= NULL
;
1206 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1209 if (XBUFFER (w
->buffer
) != current_buffer
)
1211 old_buffer
= current_buffer
;
1212 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1215 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1217 /* Compute exact mode line heights. */
1218 if (WINDOW_WANTS_MODELINE_P (w
))
1219 current_mode_line_height
1220 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1221 BVAR (current_buffer
, mode_line_format
));
1223 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1224 current_header_line_height
1225 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1226 BVAR (current_buffer
, header_line_format
));
1228 start_display (&it
, w
, top
);
1229 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1230 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1232 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1234 /* We have reached CHARPOS, or passed it. How the call to
1235 move_it_to can overshoot: (i) If CHARPOS is on invisible
1236 text, move_it_to stops at the end of the invisible text,
1237 after CHARPOS. (ii) If CHARPOS is in a display vector,
1238 move_it_to stops on its last glyph. */
1239 int top_x
= it
.current_x
;
1240 int top_y
= it
.current_y
;
1241 enum it_method it_method
= it
.method
;
1242 /* Calling line_bottom_y may change it.method, it.position, etc. */
1243 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1244 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1246 if (top_y
< window_top_y
)
1247 visible_p
= bottom_y
> window_top_y
;
1248 else if (top_y
< it
.last_visible_y
)
1252 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1254 /* We stopped on the last glyph of a display vector.
1255 Try and recompute. Hack alert! */
1256 if (charpos
< 2 || top
.charpos
>= charpos
)
1257 top_x
= it
.glyph_row
->x
;
1261 start_display (&it2
, w
, top
);
1262 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1263 get_next_display_element (&it2
);
1264 PRODUCE_GLYPHS (&it2
);
1265 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1266 || it2
.current_x
> it2
.last_visible_x
)
1267 top_x
= it
.glyph_row
->x
;
1270 top_x
= it2
.current_x
;
1271 top_y
= it2
.current_y
;
1277 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1278 *rtop
= max (0, window_top_y
- top_y
);
1279 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1280 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1281 - max (top_y
, window_top_y
)));
1290 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1291 move_it_by_lines (&it
, 1);
1292 if (charpos
< IT_CHARPOS (it
)
1293 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1296 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1298 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1299 *rtop
= max (0, -it2
.current_y
);
1300 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1301 - it
.last_visible_y
));
1302 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1304 - max (it2
.current_y
,
1305 WINDOW_HEADER_LINE_HEIGHT (w
))));
1311 set_buffer_internal_1 (old_buffer
);
1313 current_header_line_height
= current_mode_line_height
= -1;
1315 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1316 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1319 /* Debugging code. */
1321 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1322 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1324 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1331 /* Return the next character from STR. Return in *LEN the length of
1332 the character. This is like STRING_CHAR_AND_LENGTH but never
1333 returns an invalid character. If we find one, we return a `?', but
1334 with the length of the invalid character. */
1337 string_char_and_length (const unsigned char *str
, int *len
)
1341 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1342 if (!CHAR_VALID_P (c
, 1))
1343 /* We may not change the length here because other places in Emacs
1344 don't use this function, i.e. they silently accept invalid
1353 /* Given a position POS containing a valid character and byte position
1354 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1356 static struct text_pos
1357 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, EMACS_INT nchars
)
1359 xassert (STRINGP (string
) && nchars
>= 0);
1361 if (STRING_MULTIBYTE (string
))
1363 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1368 string_char_and_length (p
, &len
);
1371 BYTEPOS (pos
) += len
;
1375 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1381 /* Value is the text position, i.e. character and byte position,
1382 for character position CHARPOS in STRING. */
1384 static INLINE
struct text_pos
1385 string_pos (EMACS_INT charpos
, Lisp_Object string
)
1387 struct text_pos pos
;
1388 xassert (STRINGP (string
));
1389 xassert (charpos
>= 0);
1390 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1395 /* Value is a text position, i.e. character and byte position, for
1396 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1397 means recognize multibyte characters. */
1399 static struct text_pos
1400 c_string_pos (EMACS_INT charpos
, const char *s
, int multibyte_p
)
1402 struct text_pos pos
;
1404 xassert (s
!= NULL
);
1405 xassert (charpos
>= 0);
1411 SET_TEXT_POS (pos
, 0, 0);
1414 string_char_and_length ((const unsigned char *) s
, &len
);
1417 BYTEPOS (pos
) += len
;
1421 SET_TEXT_POS (pos
, charpos
, charpos
);
1427 /* Value is the number of characters in C string S. MULTIBYTE_P
1428 non-zero means recognize multibyte characters. */
1431 number_of_chars (const char *s
, int multibyte_p
)
1437 EMACS_INT rest
= strlen (s
);
1439 const unsigned char *p
= (const unsigned char *) s
;
1441 for (nchars
= 0; rest
> 0; ++nchars
)
1443 string_char_and_length (p
, &len
);
1444 rest
-= len
, p
+= len
;
1448 nchars
= strlen (s
);
1454 /* Compute byte position NEWPOS->bytepos corresponding to
1455 NEWPOS->charpos. POS is a known position in string STRING.
1456 NEWPOS->charpos must be >= POS.charpos. */
1459 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1461 xassert (STRINGP (string
));
1462 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1464 if (STRING_MULTIBYTE (string
))
1465 *newpos
= string_pos_nchars_ahead (pos
, string
,
1466 CHARPOS (*newpos
) - CHARPOS (pos
));
1468 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1472 Return an estimation of the pixel height of mode or header lines on
1473 frame F. FACE_ID specifies what line's height to estimate. */
1476 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1478 #ifdef HAVE_WINDOW_SYSTEM
1479 if (FRAME_WINDOW_P (f
))
1481 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1483 /* This function is called so early when Emacs starts that the face
1484 cache and mode line face are not yet initialized. */
1485 if (FRAME_FACE_CACHE (f
))
1487 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1491 height
= FONT_HEIGHT (face
->font
);
1492 if (face
->box_line_width
> 0)
1493 height
+= 2 * face
->box_line_width
;
1504 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1505 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1506 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1507 not force the value into range. */
1510 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1511 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1514 #ifdef HAVE_WINDOW_SYSTEM
1515 if (FRAME_WINDOW_P (f
))
1517 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1518 even for negative values. */
1520 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1522 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1524 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1525 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1528 STORE_NATIVE_RECT (*bounds
,
1529 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1530 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1531 FRAME_COLUMN_WIDTH (f
) - 1,
1532 FRAME_LINE_HEIGHT (f
) - 1);
1538 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1539 pix_x
= FRAME_TOTAL_COLS (f
);
1543 else if (pix_y
> FRAME_LINES (f
))
1544 pix_y
= FRAME_LINES (f
);
1554 /* Find the glyph under window-relative coordinates X/Y in window W.
1555 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1556 strings. Return in *HPOS and *VPOS the row and column number of
1557 the glyph found. Return in *AREA the glyph area containing X.
1558 Value is a pointer to the glyph found or null if X/Y is not on
1559 text, or we can't tell because W's current matrix is not up to
1564 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1565 int *dx
, int *dy
, int *area
)
1567 struct glyph
*glyph
, *end
;
1568 struct glyph_row
*row
= NULL
;
1571 /* Find row containing Y. Give up if some row is not enabled. */
1572 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1574 row
= MATRIX_ROW (w
->current_matrix
, i
);
1575 if (!row
->enabled_p
)
1577 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1584 /* Give up if Y is not in the window. */
1585 if (i
== w
->current_matrix
->nrows
)
1588 /* Get the glyph area containing X. */
1589 if (w
->pseudo_window_p
)
1596 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1598 *area
= LEFT_MARGIN_AREA
;
1599 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1601 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1604 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1608 *area
= RIGHT_MARGIN_AREA
;
1609 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1613 /* Find glyph containing X. */
1614 glyph
= row
->glyphs
[*area
];
1615 end
= glyph
+ row
->used
[*area
];
1617 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1619 x
-= glyph
->pixel_width
;
1629 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1632 *hpos
= glyph
- row
->glyphs
[*area
];
1636 /* Convert frame-relative x/y to coordinates relative to window W.
1637 Takes pseudo-windows into account. */
1640 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1642 if (w
->pseudo_window_p
)
1644 /* A pseudo-window is always full-width, and starts at the
1645 left edge of the frame, plus a frame border. */
1646 struct frame
*f
= XFRAME (w
->frame
);
1647 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1648 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1652 *x
-= WINDOW_LEFT_EDGE_X (w
);
1653 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1657 #ifdef HAVE_WINDOW_SYSTEM
1660 Return in RECTS[] at most N clipping rectangles for glyph string S.
1661 Return the number of stored rectangles. */
1664 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1671 if (s
->row
->full_width_p
)
1673 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1674 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1675 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1677 /* Unless displaying a mode or menu bar line, which are always
1678 fully visible, clip to the visible part of the row. */
1679 if (s
->w
->pseudo_window_p
)
1680 r
.height
= s
->row
->visible_height
;
1682 r
.height
= s
->height
;
1686 /* This is a text line that may be partially visible. */
1687 r
.x
= window_box_left (s
->w
, s
->area
);
1688 r
.width
= window_box_width (s
->w
, s
->area
);
1689 r
.height
= s
->row
->visible_height
;
1693 if (r
.x
< s
->clip_head
->x
)
1695 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1696 r
.width
-= s
->clip_head
->x
- r
.x
;
1699 r
.x
= s
->clip_head
->x
;
1702 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1704 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1705 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1710 /* If S draws overlapping rows, it's sufficient to use the top and
1711 bottom of the window for clipping because this glyph string
1712 intentionally draws over other lines. */
1713 if (s
->for_overlaps
)
1715 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1716 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1718 /* Alas, the above simple strategy does not work for the
1719 environments with anti-aliased text: if the same text is
1720 drawn onto the same place multiple times, it gets thicker.
1721 If the overlap we are processing is for the erased cursor, we
1722 take the intersection with the rectagle of the cursor. */
1723 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1725 XRectangle rc
, r_save
= r
;
1727 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1728 rc
.y
= s
->w
->phys_cursor
.y
;
1729 rc
.width
= s
->w
->phys_cursor_width
;
1730 rc
.height
= s
->w
->phys_cursor_height
;
1732 x_intersect_rectangles (&r_save
, &rc
, &r
);
1737 /* Don't use S->y for clipping because it doesn't take partially
1738 visible lines into account. For example, it can be negative for
1739 partially visible lines at the top of a window. */
1740 if (!s
->row
->full_width_p
1741 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1742 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1744 r
.y
= max (0, s
->row
->y
);
1747 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1749 /* If drawing the cursor, don't let glyph draw outside its
1750 advertised boundaries. Cleartype does this under some circumstances. */
1751 if (s
->hl
== DRAW_CURSOR
)
1753 struct glyph
*glyph
= s
->first_glyph
;
1758 r
.width
-= s
->x
- r
.x
;
1761 r
.width
= min (r
.width
, glyph
->pixel_width
);
1763 /* If r.y is below window bottom, ensure that we still see a cursor. */
1764 height
= min (glyph
->ascent
+ glyph
->descent
,
1765 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1766 max_y
= window_text_bottom_y (s
->w
) - height
;
1767 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1768 if (s
->ybase
- glyph
->ascent
> max_y
)
1775 /* Don't draw cursor glyph taller than our actual glyph. */
1776 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1777 if (height
< r
.height
)
1779 max_y
= r
.y
+ r
.height
;
1780 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1781 r
.height
= min (max_y
- r
.y
, height
);
1788 XRectangle r_save
= r
;
1790 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
1794 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1795 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1797 #ifdef CONVERT_FROM_XRECT
1798 CONVERT_FROM_XRECT (r
, *rects
);
1806 /* If we are processing overlapping and allowed to return
1807 multiple clipping rectangles, we exclude the row of the glyph
1808 string from the clipping rectangle. This is to avoid drawing
1809 the same text on the environment with anti-aliasing. */
1810 #ifdef CONVERT_FROM_XRECT
1813 XRectangle
*rs
= rects
;
1815 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1817 if (s
->for_overlaps
& OVERLAPS_PRED
)
1820 if (r
.y
+ r
.height
> row_y
)
1823 rs
[i
].height
= row_y
- r
.y
;
1829 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1832 if (r
.y
< row_y
+ s
->row
->visible_height
)
1834 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1836 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1837 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1846 #ifdef CONVERT_FROM_XRECT
1847 for (i
= 0; i
< n
; i
++)
1848 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1855 Return in *NR the clipping rectangle for glyph string S. */
1858 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
1860 get_glyph_string_clip_rects (s
, nr
, 1);
1865 Return the position and height of the phys cursor in window W.
1866 Set w->phys_cursor_width to width of phys cursor.
1870 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
1871 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
1873 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1874 int x
, y
, wd
, h
, h0
, y0
;
1876 /* Compute the width of the rectangle to draw. If on a stretch
1877 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1878 rectangle as wide as the glyph, but use a canonical character
1880 wd
= glyph
->pixel_width
- 1;
1881 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
1885 x
= w
->phys_cursor
.x
;
1892 if (glyph
->type
== STRETCH_GLYPH
1893 && !x_stretch_cursor_p
)
1894 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
1895 w
->phys_cursor_width
= wd
;
1897 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
1899 /* If y is below window bottom, ensure that we still see a cursor. */
1900 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
1902 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
1903 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
1905 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
1908 h
= max (h
- (y0
- y
) + 1, h0
);
1913 y0
= window_text_bottom_y (w
) - h0
;
1921 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
1922 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
1927 * Remember which glyph the mouse is over.
1931 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
1935 struct glyph_row
*r
, *gr
, *end_row
;
1936 enum window_part part
;
1937 enum glyph_row_area area
;
1938 int x
, y
, width
, height
;
1940 /* Try to determine frame pixel position and size of the glyph under
1941 frame pixel coordinates X/Y on frame F. */
1943 if (!f
->glyphs_initialized_p
1944 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
1947 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
1948 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
1952 w
= XWINDOW (window
);
1953 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
1954 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
1956 x
= window_relative_x_coord (w
, part
, gx
);
1957 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
1959 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1960 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1962 if (w
->pseudo_window_p
)
1965 part
= ON_MODE_LINE
; /* Don't adjust margin. */
1971 case ON_LEFT_MARGIN
:
1972 area
= LEFT_MARGIN_AREA
;
1975 case ON_RIGHT_MARGIN
:
1976 area
= RIGHT_MARGIN_AREA
;
1979 case ON_HEADER_LINE
:
1981 gr
= (part
== ON_HEADER_LINE
1982 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1983 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
1986 goto text_glyph_row_found
;
1993 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
1994 if (r
->y
+ r
->height
> y
)
2000 text_glyph_row_found
:
2003 struct glyph
*g
= gr
->glyphs
[area
];
2004 struct glyph
*end
= g
+ gr
->used
[area
];
2006 height
= gr
->height
;
2007 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2008 if (gx
+ g
->pixel_width
> x
)
2013 if (g
->type
== IMAGE_GLYPH
)
2015 /* Don't remember when mouse is over image, as
2016 image may have hot-spots. */
2017 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2020 width
= g
->pixel_width
;
2024 /* Use nominal char spacing at end of line. */
2026 gx
+= (x
/ width
) * width
;
2029 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2030 gx
+= window_box_left_offset (w
, area
);
2034 /* Use nominal line height at end of window. */
2035 gx
= (x
/ width
) * width
;
2037 gy
+= (y
/ height
) * height
;
2041 case ON_LEFT_FRINGE
:
2042 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2043 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2044 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2045 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2048 case ON_RIGHT_FRINGE
:
2049 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2050 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2051 : window_box_right_offset (w
, TEXT_AREA
));
2052 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2056 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2058 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2059 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2060 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2062 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2066 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2067 if (r
->y
+ r
->height
> y
)
2074 height
= gr
->height
;
2077 /* Use nominal line height at end of window. */
2079 gy
+= (y
/ height
) * height
;
2086 /* If there is no glyph under the mouse, then we divide the screen
2087 into a grid of the smallest glyph in the frame, and use that
2090 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2091 round down even for negative values. */
2097 gx
= (gx
/ width
) * width
;
2098 gy
= (gy
/ height
) * height
;
2103 gx
+= WINDOW_LEFT_EDGE_X (w
);
2104 gy
+= WINDOW_TOP_EDGE_Y (w
);
2107 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2109 /* Visible feedback for debugging. */
2112 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2113 f
->output_data
.x
->normal_gc
,
2114 gx
, gy
, width
, height
);
2120 #endif /* HAVE_WINDOW_SYSTEM */
2123 /***********************************************************************
2124 Lisp form evaluation
2125 ***********************************************************************/
2127 /* Error handler for safe_eval and safe_call. */
2130 safe_eval_handler (Lisp_Object arg
)
2132 add_to_log ("Error during redisplay: %S", arg
, Qnil
);
2137 /* Evaluate SEXPR and return the result, or nil if something went
2138 wrong. Prevent redisplay during the evaluation. */
2140 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2141 Return the result, or nil if something went wrong. Prevent
2142 redisplay during the evaluation. */
2145 safe_call (size_t nargs
, Lisp_Object
*args
)
2149 if (inhibit_eval_during_redisplay
)
2153 int count
= SPECPDL_INDEX ();
2154 struct gcpro gcpro1
;
2157 gcpro1
.nvars
= nargs
;
2158 specbind (Qinhibit_redisplay
, Qt
);
2159 /* Use Qt to ensure debugger does not run,
2160 so there is no possibility of wanting to redisplay. */
2161 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2164 val
= unbind_to (count
, val
);
2171 /* Call function FN with one argument ARG.
2172 Return the result, or nil if something went wrong. */
2175 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2177 Lisp_Object args
[2];
2180 return safe_call (2, args
);
2183 static Lisp_Object Qeval
;
2186 safe_eval (Lisp_Object sexpr
)
2188 return safe_call1 (Qeval
, sexpr
);
2191 /* Call function FN with one argument ARG.
2192 Return the result, or nil if something went wrong. */
2195 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2197 Lisp_Object args
[3];
2201 return safe_call (3, args
);
2206 /***********************************************************************
2208 ***********************************************************************/
2212 /* Define CHECK_IT to perform sanity checks on iterators.
2213 This is for debugging. It is too slow to do unconditionally. */
2219 if (it
->method
== GET_FROM_STRING
)
2221 xassert (STRINGP (it
->string
));
2222 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2226 xassert (IT_STRING_CHARPOS (*it
) < 0);
2227 if (it
->method
== GET_FROM_BUFFER
)
2229 /* Check that character and byte positions agree. */
2230 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2235 xassert (it
->current
.dpvec_index
>= 0);
2237 xassert (it
->current
.dpvec_index
< 0);
2240 #define CHECK_IT(IT) check_it ((IT))
2244 #define CHECK_IT(IT) (void) 0
2251 /* Check that the window end of window W is what we expect it
2252 to be---the last row in the current matrix displaying text. */
2255 check_window_end (w
)
2258 if (!MINI_WINDOW_P (w
)
2259 && !NILP (w
->window_end_valid
))
2261 struct glyph_row
*row
;
2262 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2263 XFASTINT (w
->window_end_vpos
)),
2265 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2266 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2270 #define CHECK_WINDOW_END(W) check_window_end ((W))
2272 #else /* not GLYPH_DEBUG */
2274 #define CHECK_WINDOW_END(W) (void) 0
2276 #endif /* not GLYPH_DEBUG */
2280 /***********************************************************************
2281 Iterator initialization
2282 ***********************************************************************/
2284 /* Initialize IT for displaying current_buffer in window W, starting
2285 at character position CHARPOS. CHARPOS < 0 means that no buffer
2286 position is specified which is useful when the iterator is assigned
2287 a position later. BYTEPOS is the byte position corresponding to
2288 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2290 If ROW is not null, calls to produce_glyphs with IT as parameter
2291 will produce glyphs in that row.
2293 BASE_FACE_ID is the id of a base face to use. It must be one of
2294 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2295 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2296 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2298 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2299 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2300 will be initialized to use the corresponding mode line glyph row of
2301 the desired matrix of W. */
2304 init_iterator (struct it
*it
, struct window
*w
,
2305 EMACS_INT charpos
, EMACS_INT bytepos
,
2306 struct glyph_row
*row
, enum face_id base_face_id
)
2308 int highlight_region_p
;
2309 enum face_id remapped_base_face_id
= base_face_id
;
2311 /* Some precondition checks. */
2312 xassert (w
!= NULL
&& it
!= NULL
);
2313 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2316 /* If face attributes have been changed since the last redisplay,
2317 free realized faces now because they depend on face definitions
2318 that might have changed. Don't free faces while there might be
2319 desired matrices pending which reference these faces. */
2320 if (face_change_count
&& !inhibit_free_realized_faces
)
2322 face_change_count
= 0;
2323 free_all_realized_faces (Qnil
);
2326 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2327 if (! NILP (Vface_remapping_alist
))
2328 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2330 /* Use one of the mode line rows of W's desired matrix if
2334 if (base_face_id
== MODE_LINE_FACE_ID
2335 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2336 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2337 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2338 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2342 memset (it
, 0, sizeof *it
);
2343 it
->current
.overlay_string_index
= -1;
2344 it
->current
.dpvec_index
= -1;
2345 it
->base_face_id
= remapped_base_face_id
;
2347 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2348 it
->paragraph_embedding
= L2R
;
2349 it
->bidi_it
.string
.lstring
= Qnil
;
2350 it
->bidi_it
.string
.s
= NULL
;
2351 it
->bidi_it
.string
.bufpos
= 0;
2353 /* The window in which we iterate over current_buffer: */
2354 XSETWINDOW (it
->window
, w
);
2356 it
->f
= XFRAME (w
->frame
);
2360 /* Extra space between lines (on window systems only). */
2361 if (base_face_id
== DEFAULT_FACE_ID
2362 && FRAME_WINDOW_P (it
->f
))
2364 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2365 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2366 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2367 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2368 * FRAME_LINE_HEIGHT (it
->f
));
2369 else if (it
->f
->extra_line_spacing
> 0)
2370 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2371 it
->max_extra_line_spacing
= 0;
2374 /* If realized faces have been removed, e.g. because of face
2375 attribute changes of named faces, recompute them. When running
2376 in batch mode, the face cache of the initial frame is null. If
2377 we happen to get called, make a dummy face cache. */
2378 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2379 init_frame_faces (it
->f
);
2380 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2381 recompute_basic_faces (it
->f
);
2383 /* Current value of the `slice', `space-width', and 'height' properties. */
2384 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2385 it
->space_width
= Qnil
;
2386 it
->font_height
= Qnil
;
2387 it
->override_ascent
= -1;
2389 /* Are control characters displayed as `^C'? */
2390 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2392 /* -1 means everything between a CR and the following line end
2393 is invisible. >0 means lines indented more than this value are
2395 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2396 ? XFASTINT (BVAR (current_buffer
, selective_display
))
2397 : (!NILP (BVAR (current_buffer
, selective_display
))
2399 it
->selective_display_ellipsis_p
2400 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2402 /* Display table to use. */
2403 it
->dp
= window_display_table (w
);
2405 /* Are multibyte characters enabled in current_buffer? */
2406 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2408 /* Non-zero if we should highlight the region. */
2410 = (!NILP (Vtransient_mark_mode
)
2411 && !NILP (BVAR (current_buffer
, mark_active
))
2412 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= 0);
2414 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2415 start and end of a visible region in window IT->w. Set both to
2416 -1 to indicate no region. */
2417 if (highlight_region_p
2418 /* Maybe highlight only in selected window. */
2419 && (/* Either show region everywhere. */
2420 highlight_nonselected_windows
2421 /* Or show region in the selected window. */
2422 || w
== XWINDOW (selected_window
)
2423 /* Or show the region if we are in the mini-buffer and W is
2424 the window the mini-buffer refers to. */
2425 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2426 && WINDOWP (minibuf_selected_window
)
2427 && w
== XWINDOW (minibuf_selected_window
))))
2429 EMACS_INT markpos
= marker_position (BVAR (current_buffer
, mark
));
2430 it
->region_beg_charpos
= min (PT
, markpos
);
2431 it
->region_end_charpos
= max (PT
, markpos
);
2434 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2436 /* Get the position at which the redisplay_end_trigger hook should
2437 be run, if it is to be run at all. */
2438 if (MARKERP (w
->redisplay_end_trigger
)
2439 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2440 it
->redisplay_end_trigger_charpos
2441 = marker_position (w
->redisplay_end_trigger
);
2442 else if (INTEGERP (w
->redisplay_end_trigger
))
2443 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2445 /* Correct bogus values of tab_width. */
2446 it
->tab_width
= XINT (BVAR (current_buffer
, tab_width
));
2447 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2450 /* Are lines in the display truncated? */
2451 if (base_face_id
!= DEFAULT_FACE_ID
2452 || XINT (it
->w
->hscroll
)
2453 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2454 && ((!NILP (Vtruncate_partial_width_windows
)
2455 && !INTEGERP (Vtruncate_partial_width_windows
))
2456 || (INTEGERP (Vtruncate_partial_width_windows
)
2457 && (WINDOW_TOTAL_COLS (it
->w
)
2458 < XINT (Vtruncate_partial_width_windows
))))))
2459 it
->line_wrap
= TRUNCATE
;
2460 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2461 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2462 ? WINDOW_WRAP
: WORD_WRAP
;
2464 it
->line_wrap
= TRUNCATE
;
2466 /* Get dimensions of truncation and continuation glyphs. These are
2467 displayed as fringe bitmaps under X, so we don't need them for such
2469 if (!FRAME_WINDOW_P (it
->f
))
2471 if (it
->line_wrap
== TRUNCATE
)
2473 /* We will need the truncation glyph. */
2474 xassert (it
->glyph_row
== NULL
);
2475 produce_special_glyphs (it
, IT_TRUNCATION
);
2476 it
->truncation_pixel_width
= it
->pixel_width
;
2480 /* We will need the continuation glyph. */
2481 xassert (it
->glyph_row
== NULL
);
2482 produce_special_glyphs (it
, IT_CONTINUATION
);
2483 it
->continuation_pixel_width
= it
->pixel_width
;
2486 /* Reset these values to zero because the produce_special_glyphs
2487 above has changed them. */
2488 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2489 it
->phys_ascent
= it
->phys_descent
= 0;
2492 /* Set this after getting the dimensions of truncation and
2493 continuation glyphs, so that we don't produce glyphs when calling
2494 produce_special_glyphs, above. */
2495 it
->glyph_row
= row
;
2496 it
->area
= TEXT_AREA
;
2498 /* Forget any previous info about this row being reversed. */
2500 it
->glyph_row
->reversed_p
= 0;
2502 /* Get the dimensions of the display area. The display area
2503 consists of the visible window area plus a horizontally scrolled
2504 part to the left of the window. All x-values are relative to the
2505 start of this total display area. */
2506 if (base_face_id
!= DEFAULT_FACE_ID
)
2508 /* Mode lines, menu bar in terminal frames. */
2509 it
->first_visible_x
= 0;
2510 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2515 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2516 it
->last_visible_x
= (it
->first_visible_x
2517 + window_box_width (w
, TEXT_AREA
));
2519 /* If we truncate lines, leave room for the truncator glyph(s) at
2520 the right margin. Otherwise, leave room for the continuation
2521 glyph(s). Truncation and continuation glyphs are not inserted
2522 for window-based redisplay. */
2523 if (!FRAME_WINDOW_P (it
->f
))
2525 if (it
->line_wrap
== TRUNCATE
)
2526 it
->last_visible_x
-= it
->truncation_pixel_width
;
2528 it
->last_visible_x
-= it
->continuation_pixel_width
;
2531 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2532 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2535 /* Leave room for a border glyph. */
2536 if (!FRAME_WINDOW_P (it
->f
)
2537 && !WINDOW_RIGHTMOST_P (it
->w
))
2538 it
->last_visible_x
-= 1;
2540 it
->last_visible_y
= window_text_bottom_y (w
);
2542 /* For mode lines and alike, arrange for the first glyph having a
2543 left box line if the face specifies a box. */
2544 if (base_face_id
!= DEFAULT_FACE_ID
)
2548 it
->face_id
= remapped_base_face_id
;
2550 /* If we have a boxed mode line, make the first character appear
2551 with a left box line. */
2552 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2553 if (face
->box
!= FACE_NO_BOX
)
2554 it
->start_of_box_run_p
= 1;
2557 /* If a buffer position was specified, set the iterator there,
2558 getting overlays and face properties from that position. */
2559 if (charpos
>= BUF_BEG (current_buffer
))
2561 it
->end_charpos
= ZV
;
2563 IT_CHARPOS (*it
) = charpos
;
2565 /* Compute byte position if not specified. */
2566 if (bytepos
< charpos
)
2567 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2569 IT_BYTEPOS (*it
) = bytepos
;
2571 it
->start
= it
->current
;
2572 /* Do we need to reorder bidirectional text? Not if this is a
2573 unibyte buffer: by definition, none of the single-byte
2574 characters are strong R2L, so no reordering is needed. And
2575 bidi.c doesn't support unibyte buffers anyway. */
2577 !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2580 /* If we are to reorder bidirectional text, init the bidi
2584 /* Note the paragraph direction that this buffer wants to
2586 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2588 it
->paragraph_embedding
= L2R
;
2589 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2591 it
->paragraph_embedding
= R2L
;
2593 it
->paragraph_embedding
= NEUTRAL_DIR
;
2594 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2598 /* Compute faces etc. */
2599 reseat (it
, it
->current
.pos
, 1);
2606 /* Initialize IT for the display of window W with window start POS. */
2609 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2611 struct glyph_row
*row
;
2612 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2614 row
= w
->desired_matrix
->rows
+ first_vpos
;
2615 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2616 it
->first_vpos
= first_vpos
;
2618 /* Don't reseat to previous visible line start if current start
2619 position is in a string or image. */
2620 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2622 int start_at_line_beg_p
;
2623 int first_y
= it
->current_y
;
2625 /* If window start is not at a line start, skip forward to POS to
2626 get the correct continuation lines width. */
2627 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2628 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2629 if (!start_at_line_beg_p
)
2633 reseat_at_previous_visible_line_start (it
);
2634 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2636 new_x
= it
->current_x
+ it
->pixel_width
;
2638 /* If lines are continued, this line may end in the middle
2639 of a multi-glyph character (e.g. a control character
2640 displayed as \003, or in the middle of an overlay
2641 string). In this case move_it_to above will not have
2642 taken us to the start of the continuation line but to the
2643 end of the continued line. */
2644 if (it
->current_x
> 0
2645 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2646 && (/* And glyph doesn't fit on the line. */
2647 new_x
> it
->last_visible_x
2648 /* Or it fits exactly and we're on a window
2650 || (new_x
== it
->last_visible_x
2651 && FRAME_WINDOW_P (it
->f
))))
2653 if (it
->current
.dpvec_index
>= 0
2654 || it
->current
.overlay_string_index
>= 0)
2656 set_iterator_to_next (it
, 1);
2657 move_it_in_display_line_to (it
, -1, -1, 0);
2660 it
->continuation_lines_width
+= it
->current_x
;
2663 /* We're starting a new display line, not affected by the
2664 height of the continued line, so clear the appropriate
2665 fields in the iterator structure. */
2666 it
->max_ascent
= it
->max_descent
= 0;
2667 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2669 it
->current_y
= first_y
;
2671 it
->current_x
= it
->hpos
= 0;
2677 /* Return 1 if POS is a position in ellipses displayed for invisible
2678 text. W is the window we display, for text property lookup. */
2681 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2683 Lisp_Object prop
, window
;
2685 EMACS_INT charpos
= CHARPOS (pos
->pos
);
2687 /* If POS specifies a position in a display vector, this might
2688 be for an ellipsis displayed for invisible text. We won't
2689 get the iterator set up for delivering that ellipsis unless
2690 we make sure that it gets aware of the invisible text. */
2691 if (pos
->dpvec_index
>= 0
2692 && pos
->overlay_string_index
< 0
2693 && CHARPOS (pos
->string_pos
) < 0
2695 && (XSETWINDOW (window
, w
),
2696 prop
= Fget_char_property (make_number (charpos
),
2697 Qinvisible
, window
),
2698 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2700 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2702 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2709 /* Initialize IT for stepping through current_buffer in window W,
2710 starting at position POS that includes overlay string and display
2711 vector/ control character translation position information. Value
2712 is zero if there are overlay strings with newlines at POS. */
2715 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
2717 EMACS_INT charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2718 int i
, overlay_strings_with_newlines
= 0;
2720 /* If POS specifies a position in a display vector, this might
2721 be for an ellipsis displayed for invisible text. We won't
2722 get the iterator set up for delivering that ellipsis unless
2723 we make sure that it gets aware of the invisible text. */
2724 if (in_ellipses_for_invisible_text_p (pos
, w
))
2730 /* Keep in mind: the call to reseat in init_iterator skips invisible
2731 text, so we might end up at a position different from POS. This
2732 is only a problem when POS is a row start after a newline and an
2733 overlay starts there with an after-string, and the overlay has an
2734 invisible property. Since we don't skip invisible text in
2735 display_line and elsewhere immediately after consuming the
2736 newline before the row start, such a POS will not be in a string,
2737 but the call to init_iterator below will move us to the
2739 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2741 /* This only scans the current chunk -- it should scan all chunks.
2742 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2743 to 16 in 22.1 to make this a lesser problem. */
2744 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2746 const char *s
= SSDATA (it
->overlay_strings
[i
]);
2747 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2749 while (s
< e
&& *s
!= '\n')
2754 overlay_strings_with_newlines
= 1;
2759 /* If position is within an overlay string, set up IT to the right
2761 if (pos
->overlay_string_index
>= 0)
2765 /* If the first overlay string happens to have a `display'
2766 property for an image, the iterator will be set up for that
2767 image, and we have to undo that setup first before we can
2768 correct the overlay string index. */
2769 if (it
->method
== GET_FROM_IMAGE
)
2772 /* We already have the first chunk of overlay strings in
2773 IT->overlay_strings. Load more until the one for
2774 pos->overlay_string_index is in IT->overlay_strings. */
2775 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2777 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2778 it
->current
.overlay_string_index
= 0;
2781 load_overlay_strings (it
, 0);
2782 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2786 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2787 relative_index
= (it
->current
.overlay_string_index
2788 % OVERLAY_STRING_CHUNK_SIZE
);
2789 it
->string
= it
->overlay_strings
[relative_index
];
2790 xassert (STRINGP (it
->string
));
2791 it
->current
.string_pos
= pos
->string_pos
;
2792 it
->method
= GET_FROM_STRING
;
2795 if (CHARPOS (pos
->string_pos
) >= 0)
2797 /* Recorded position is not in an overlay string, but in another
2798 string. This can only be a string from a `display' property.
2799 IT should already be filled with that string. */
2800 it
->current
.string_pos
= pos
->string_pos
;
2801 xassert (STRINGP (it
->string
));
2804 /* Restore position in display vector translations, control
2805 character translations or ellipses. */
2806 if (pos
->dpvec_index
>= 0)
2808 if (it
->dpvec
== NULL
)
2809 get_next_display_element (it
);
2810 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2811 it
->current
.dpvec_index
= pos
->dpvec_index
;
2815 return !overlay_strings_with_newlines
;
2819 /* Initialize IT for stepping through current_buffer in window W
2820 starting at ROW->start. */
2823 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
2825 init_from_display_pos (it
, w
, &row
->start
);
2826 it
->start
= row
->start
;
2827 it
->continuation_lines_width
= row
->continuation_lines_width
;
2832 /* Initialize IT for stepping through current_buffer in window W
2833 starting in the line following ROW, i.e. starting at ROW->end.
2834 Value is zero if there are overlay strings with newlines at ROW's
2838 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
2842 if (init_from_display_pos (it
, w
, &row
->end
))
2844 if (row
->continued_p
)
2845 it
->continuation_lines_width
2846 = row
->continuation_lines_width
+ row
->pixel_width
;
2857 /***********************************************************************
2859 ***********************************************************************/
2861 /* Called when IT reaches IT->stop_charpos. Handle text property and
2862 overlay changes. Set IT->stop_charpos to the next position where
2866 handle_stop (struct it
*it
)
2868 enum prop_handled handled
;
2869 int handle_overlay_change_p
;
2873 it
->current
.dpvec_index
= -1;
2874 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
2875 it
->ignore_overlay_strings_at_pos_p
= 0;
2878 /* Use face of preceding text for ellipsis (if invisible) */
2879 if (it
->selective_display_ellipsis_p
)
2880 it
->saved_face_id
= it
->face_id
;
2884 handled
= HANDLED_NORMALLY
;
2886 /* Call text property handlers. */
2887 for (p
= it_props
; p
->handler
; ++p
)
2889 handled
= p
->handler (it
);
2891 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2893 else if (handled
== HANDLED_RETURN
)
2895 /* We still want to show before and after strings from
2896 overlays even if the actual buffer text is replaced. */
2897 if (!handle_overlay_change_p
2899 || !get_overlay_strings_1 (it
, 0, 0))
2902 setup_for_ellipsis (it
, 0);
2903 /* When handling a display spec, we might load an
2904 empty string. In that case, discard it here. We
2905 used to discard it in handle_single_display_spec,
2906 but that causes get_overlay_strings_1, above, to
2907 ignore overlay strings that we must check. */
2908 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
2912 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
2916 it
->ignore_overlay_strings_at_pos_p
= 1;
2917 it
->string_from_display_prop_p
= 0;
2918 handle_overlay_change_p
= 0;
2920 handled
= HANDLED_RECOMPUTE_PROPS
;
2923 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2924 handle_overlay_change_p
= 0;
2927 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2929 /* Don't check for overlay strings below when set to deliver
2930 characters from a display vector. */
2931 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
2932 handle_overlay_change_p
= 0;
2934 /* Handle overlay changes.
2935 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
2936 if it finds overlays. */
2937 if (handle_overlay_change_p
)
2938 handled
= handle_overlay_change (it
);
2943 setup_for_ellipsis (it
, 0);
2947 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2949 /* Determine where to stop next. */
2950 if (handled
== HANDLED_NORMALLY
)
2951 compute_stop_pos (it
);
2955 /* Compute IT->stop_charpos from text property and overlay change
2956 information for IT's current position. */
2959 compute_stop_pos (struct it
*it
)
2961 register INTERVAL iv
, next_iv
;
2962 Lisp_Object object
, limit
, position
;
2963 EMACS_INT charpos
, bytepos
;
2965 /* If nowhere else, stop at the end. */
2966 it
->stop_charpos
= it
->end_charpos
;
2968 if (STRINGP (it
->string
))
2970 /* Strings are usually short, so don't limit the search for
2972 object
= it
->string
;
2974 charpos
= IT_STRING_CHARPOS (*it
);
2975 bytepos
= IT_STRING_BYTEPOS (*it
);
2981 /* If next overlay change is in front of the current stop pos
2982 (which is IT->end_charpos), stop there. Note: value of
2983 next_overlay_change is point-max if no overlay change
2985 charpos
= IT_CHARPOS (*it
);
2986 bytepos
= IT_BYTEPOS (*it
);
2987 pos
= next_overlay_change (charpos
);
2988 if (pos
< it
->stop_charpos
)
2989 it
->stop_charpos
= pos
;
2991 /* If showing the region, we have to stop at the region
2992 start or end because the face might change there. */
2993 if (it
->region_beg_charpos
> 0)
2995 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2996 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2997 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2998 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3001 /* Set up variables for computing the stop position from text
3002 property changes. */
3003 XSETBUFFER (object
, current_buffer
);
3004 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3007 /* Get the interval containing IT's position. Value is a null
3008 interval if there isn't such an interval. */
3009 position
= make_number (charpos
);
3010 iv
= validate_interval_range (object
, &position
, &position
, 0);
3011 if (!NULL_INTERVAL_P (iv
))
3013 Lisp_Object values_here
[LAST_PROP_IDX
];
3016 /* Get properties here. */
3017 for (p
= it_props
; p
->handler
; ++p
)
3018 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3020 /* Look for an interval following iv that has different
3022 for (next_iv
= next_interval (iv
);
3023 (!NULL_INTERVAL_P (next_iv
)
3025 || XFASTINT (limit
) > next_iv
->position
));
3026 next_iv
= next_interval (next_iv
))
3028 for (p
= it_props
; p
->handler
; ++p
)
3030 Lisp_Object new_value
;
3032 new_value
= textget (next_iv
->plist
, *p
->name
);
3033 if (!EQ (values_here
[p
->idx
], new_value
))
3041 if (!NULL_INTERVAL_P (next_iv
))
3043 if (INTEGERP (limit
)
3044 && next_iv
->position
>= XFASTINT (limit
))
3045 /* No text property change up to limit. */
3046 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3048 /* Text properties change in next_iv. */
3049 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3053 if (it
->cmp_it
.id
< 0)
3055 EMACS_INT stoppos
= it
->end_charpos
;
3057 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3059 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3060 stoppos
, it
->string
);
3063 xassert (STRINGP (it
->string
)
3064 || (it
->stop_charpos
>= BEGV
3065 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3069 /* Return the position of the next overlay change after POS in
3070 current_buffer. Value is point-max if no overlay change
3071 follows. This is like `next-overlay-change' but doesn't use
3075 next_overlay_change (EMACS_INT pos
)
3079 Lisp_Object
*overlays
;
3082 /* Get all overlays at the given position. */
3083 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3085 /* If any of these overlays ends before endpos,
3086 use its ending point instead. */
3087 for (i
= 0; i
< noverlays
; ++i
)
3092 oend
= OVERLAY_END (overlays
[i
]);
3093 oendpos
= OVERLAY_POSITION (oend
);
3094 endpos
= min (endpos
, oendpos
);
3100 /* Return the character position of a display string at or after
3101 position specified by POSITION. If no display string exists at or
3102 after POSITION, return ZV. A display string is either an overlay
3103 with `display' property whose value is a string, or a `display'
3104 text property whose value is a string. STRING is data about the
3105 string to iterate; if STRING->lstring is nil, we are iterating a
3106 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3109 compute_display_string_pos (struct text_pos
*position
,
3110 struct bidi_string_data
*string
, int frame_window_p
)
3112 /* OBJECT = nil means current buffer. */
3113 Lisp_Object object
=
3114 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3115 Lisp_Object pos
, spec
;
3116 EMACS_INT eob
= STRINGP (object
) ? string
->schars
: ZV
;
3117 EMACS_INT begb
= STRINGP (object
) ? 0 : BEGV
;
3118 EMACS_INT bufpos
, charpos
= CHARPOS (*position
);
3119 struct text_pos tpos
;
3122 /* We don't support display properties whose values are strings
3123 that have display string properties. */
3124 || string
->from_disp_str
3125 /* C strings cannot have display properties. */
3126 || (string
->s
&& !STRINGP (object
)))
3129 /* If the character at CHARPOS is where the display string begins,
3131 pos
= make_number (charpos
);
3132 if (STRINGP (object
))
3133 bufpos
= string
->bufpos
;
3137 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3139 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3142 && handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3146 /* Look forward for the first character with a `display' property
3147 that will replace the underlying text when displayed. */
3149 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3150 CHARPOS (tpos
) = XFASTINT (pos
);
3151 if (STRINGP (object
))
3152 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3154 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3155 if (CHARPOS (tpos
) >= eob
)
3157 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3158 if (!STRINGP (object
))
3159 bufpos
= CHARPOS (tpos
);
3160 } while (NILP (spec
)
3161 || !handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3164 return CHARPOS (tpos
);
3167 /* Return the character position of the end of the display string that
3168 started at CHARPOS. A display string is either an overlay with
3169 `display' property whose value is a string or a `display' text
3170 property whose value is a string. */
3172 compute_display_string_end (EMACS_INT charpos
, struct bidi_string_data
*string
)
3174 /* OBJECT = nil means current buffer. */
3175 Lisp_Object object
=
3176 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3177 Lisp_Object pos
= make_number (charpos
);
3178 EMACS_INT eob
= STRINGP (object
) ? string
->schars
: ZV
;
3180 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3183 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3186 /* Look forward for the first character where the `display' property
3188 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3190 return XFASTINT (pos
);
3195 /***********************************************************************
3197 ***********************************************************************/
3199 /* Handle changes in the `fontified' property of the current buffer by
3200 calling hook functions from Qfontification_functions to fontify
3203 static enum prop_handled
3204 handle_fontified_prop (struct it
*it
)
3206 Lisp_Object prop
, pos
;
3207 enum prop_handled handled
= HANDLED_NORMALLY
;
3209 if (!NILP (Vmemory_full
))
3212 /* Get the value of the `fontified' property at IT's current buffer
3213 position. (The `fontified' property doesn't have a special
3214 meaning in strings.) If the value is nil, call functions from
3215 Qfontification_functions. */
3216 if (!STRINGP (it
->string
)
3218 && !NILP (Vfontification_functions
)
3219 && !NILP (Vrun_hooks
)
3220 && (pos
= make_number (IT_CHARPOS (*it
)),
3221 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3222 /* Ignore the special cased nil value always present at EOB since
3223 no amount of fontifying will be able to change it. */
3224 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3226 int count
= SPECPDL_INDEX ();
3228 struct buffer
*obuf
= current_buffer
;
3229 int begv
= BEGV
, zv
= ZV
;
3230 int old_clip_changed
= current_buffer
->clip_changed
;
3232 val
= Vfontification_functions
;
3233 specbind (Qfontification_functions
, Qnil
);
3235 xassert (it
->end_charpos
== ZV
);
3237 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3238 safe_call1 (val
, pos
);
3241 Lisp_Object fns
, fn
;
3242 struct gcpro gcpro1
, gcpro2
;
3247 for (; CONSP (val
); val
= XCDR (val
))
3253 /* A value of t indicates this hook has a local
3254 binding; it means to run the global binding too.
3255 In a global value, t should not occur. If it
3256 does, we must ignore it to avoid an endless
3258 for (fns
= Fdefault_value (Qfontification_functions
);
3264 safe_call1 (fn
, pos
);
3268 safe_call1 (fn
, pos
);
3274 unbind_to (count
, Qnil
);
3276 /* Fontification functions routinely call `save-restriction'.
3277 Normally, this tags clip_changed, which can confuse redisplay
3278 (see discussion in Bug#6671). Since we don't perform any
3279 special handling of fontification changes in the case where
3280 `save-restriction' isn't called, there's no point doing so in
3281 this case either. So, if the buffer's restrictions are
3282 actually left unchanged, reset clip_changed. */
3283 if (obuf
== current_buffer
)
3285 if (begv
== BEGV
&& zv
== ZV
)
3286 current_buffer
->clip_changed
= old_clip_changed
;
3288 /* There isn't much we can reasonably do to protect against
3289 misbehaving fontification, but here's a fig leaf. */
3290 else if (!NILP (BVAR (obuf
, name
)))
3291 set_buffer_internal_1 (obuf
);
3293 /* The fontification code may have added/removed text.
3294 It could do even a lot worse, but let's at least protect against
3295 the most obvious case where only the text past `pos' gets changed',
3296 as is/was done in grep.el where some escapes sequences are turned
3297 into face properties (bug#7876). */
3298 it
->end_charpos
= ZV
;
3300 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3301 something. This avoids an endless loop if they failed to
3302 fontify the text for which reason ever. */
3303 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3304 handled
= HANDLED_RECOMPUTE_PROPS
;
3312 /***********************************************************************
3314 ***********************************************************************/
3316 /* Set up iterator IT from face properties at its current position.
3317 Called from handle_stop. */
3319 static enum prop_handled
3320 handle_face_prop (struct it
*it
)
3323 EMACS_INT next_stop
;
3325 if (!STRINGP (it
->string
))
3328 = face_at_buffer_position (it
->w
,
3330 it
->region_beg_charpos
,
3331 it
->region_end_charpos
,
3334 + TEXT_PROP_DISTANCE_LIMIT
),
3335 0, it
->base_face_id
);
3337 /* Is this a start of a run of characters with box face?
3338 Caveat: this can be called for a freshly initialized
3339 iterator; face_id is -1 in this case. We know that the new
3340 face will not change until limit, i.e. if the new face has a
3341 box, all characters up to limit will have one. But, as
3342 usual, we don't know whether limit is really the end. */
3343 if (new_face_id
!= it
->face_id
)
3345 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3347 /* If new face has a box but old face has not, this is
3348 the start of a run of characters with box, i.e. it has
3349 a shadow on the left side. The value of face_id of the
3350 iterator will be -1 if this is the initial call that gets
3351 the face. In this case, we have to look in front of IT's
3352 position and see whether there is a face != new_face_id. */
3353 it
->start_of_box_run_p
3354 = (new_face
->box
!= FACE_NO_BOX
3355 && (it
->face_id
>= 0
3356 || IT_CHARPOS (*it
) == BEG
3357 || new_face_id
!= face_before_it_pos (it
)));
3358 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3366 Lisp_Object from_overlay
3367 = (it
->current
.overlay_string_index
>= 0
3368 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3371 /* See if we got to this string directly or indirectly from
3372 an overlay property. That includes the before-string or
3373 after-string of an overlay, strings in display properties
3374 provided by an overlay, their text properties, etc.
3376 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3377 if (! NILP (from_overlay
))
3378 for (i
= it
->sp
- 1; i
>= 0; i
--)
3380 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3382 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3383 else if (! NILP (it
->stack
[i
].from_overlay
))
3384 from_overlay
= it
->stack
[i
].from_overlay
;
3386 if (!NILP (from_overlay
))
3390 if (! NILP (from_overlay
))
3392 bufpos
= IT_CHARPOS (*it
);
3393 /* For a string from an overlay, the base face depends
3394 only on text properties and ignores overlays. */
3396 = face_for_overlay_string (it
->w
,
3398 it
->region_beg_charpos
,
3399 it
->region_end_charpos
,
3402 + TEXT_PROP_DISTANCE_LIMIT
),
3410 /* For strings from a `display' property, use the face at
3411 IT's current buffer position as the base face to merge
3412 with, so that overlay strings appear in the same face as
3413 surrounding text, unless they specify their own
3415 base_face_id
= underlying_face_id (it
);
3418 new_face_id
= face_at_string_position (it
->w
,
3420 IT_STRING_CHARPOS (*it
),
3422 it
->region_beg_charpos
,
3423 it
->region_end_charpos
,
3427 /* Is this a start of a run of characters with box? Caveat:
3428 this can be called for a freshly allocated iterator; face_id
3429 is -1 is this case. We know that the new face will not
3430 change until the next check pos, i.e. if the new face has a
3431 box, all characters up to that position will have a
3432 box. But, as usual, we don't know whether that position
3433 is really the end. */
3434 if (new_face_id
!= it
->face_id
)
3436 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3437 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3439 /* If new face has a box but old face hasn't, this is the
3440 start of a run of characters with box, i.e. it has a
3441 shadow on the left side. */
3442 it
->start_of_box_run_p
3443 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3444 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3448 it
->face_id
= new_face_id
;
3449 return HANDLED_NORMALLY
;
3453 /* Return the ID of the face ``underlying'' IT's current position,
3454 which is in a string. If the iterator is associated with a
3455 buffer, return the face at IT's current buffer position.
3456 Otherwise, use the iterator's base_face_id. */
3459 underlying_face_id (struct it
*it
)
3461 int face_id
= it
->base_face_id
, i
;
3463 xassert (STRINGP (it
->string
));
3465 for (i
= it
->sp
- 1; i
>= 0; --i
)
3466 if (NILP (it
->stack
[i
].string
))
3467 face_id
= it
->stack
[i
].face_id
;
3473 /* Compute the face one character before or after the current position
3474 of IT, in the visual order. BEFORE_P non-zero means get the face
3475 in front (to the left in L2R paragraphs, to the right in R2L
3476 paragraphs) of IT's screen position. Value is the ID of the face. */
3479 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3482 EMACS_INT next_check_charpos
;
3485 xassert (it
->s
== NULL
);
3487 if (STRINGP (it
->string
))
3489 EMACS_INT bufpos
, charpos
;
3492 /* No face change past the end of the string (for the case
3493 we are padding with spaces). No face change before the
3495 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3496 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3501 /* Set charpos to the position before or after IT's current
3502 position, in the logical order, which in the non-bidi
3503 case is the same as the visual order. */
3505 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3506 else if (it
->what
== IT_COMPOSITION
)
3507 /* For composition, we must check the character after the
3509 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3511 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3517 /* With bidi iteration, the character before the current
3518 in the visual order cannot be found by simple
3519 iteration, because "reverse" reordering is not
3520 supported. Instead, we need to use the move_it_*
3521 family of functions. */
3522 /* Ignore face changes before the first visible
3523 character on this display line. */
3524 if (it
->current_x
<= it
->first_visible_x
)
3527 /* Implementation note: Since move_it_in_display_line
3528 works in the iterator geometry, and thinks the first
3529 character is always the leftmost, even in R2L lines,
3530 we don't need to distinguish between the R2L and L2R
3532 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3533 it_copy
.current_x
- 1, MOVE_TO_X
);
3534 charpos
= IT_STRING_CHARPOS (it_copy
);
3538 /* Set charpos to the string position of the character
3539 that comes after IT's current position in the visual
3541 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3545 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3547 charpos
= it_copy
.bidi_it
.charpos
;
3550 xassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3552 if (it
->current
.overlay_string_index
>= 0)
3553 bufpos
= IT_CHARPOS (*it
);
3557 base_face_id
= underlying_face_id (it
);
3559 /* Get the face for ASCII, or unibyte. */
3560 face_id
= face_at_string_position (it
->w
,
3564 it
->region_beg_charpos
,
3565 it
->region_end_charpos
,
3566 &next_check_charpos
,
3569 /* Correct the face for charsets different from ASCII. Do it
3570 for the multibyte case only. The face returned above is
3571 suitable for unibyte text if IT->string is unibyte. */
3572 if (STRING_MULTIBYTE (it
->string
))
3574 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3575 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3577 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3579 c
= string_char_and_length (p
, &len
);
3580 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3585 struct text_pos pos
;
3587 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3588 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3591 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3592 pos
= it
->current
.pos
;
3597 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3600 if (it
->what
== IT_COMPOSITION
)
3602 /* For composition, we must check the position after
3604 pos
.charpos
+= it
->cmp_it
.nchars
;
3605 pos
.bytepos
+= it
->len
;
3608 INC_TEXT_POS (pos
, it
->multibyte_p
);
3615 /* With bidi iteration, the character before the current
3616 in the visual order cannot be found by simple
3617 iteration, because "reverse" reordering is not
3618 supported. Instead, we need to use the move_it_*
3619 family of functions. */
3620 /* Ignore face changes before the first visible
3621 character on this display line. */
3622 if (it
->current_x
<= it
->first_visible_x
)
3625 /* Implementation note: Since move_it_in_display_line
3626 works in the iterator geometry, and thinks the first
3627 character is always the leftmost, even in R2L lines,
3628 we don't need to distinguish between the R2L and L2R
3630 move_it_in_display_line (&it_copy
, ZV
,
3631 it_copy
.current_x
- 1, MOVE_TO_X
);
3632 pos
= it_copy
.current
.pos
;
3636 /* Set charpos to the buffer position of the character
3637 that comes after IT's current position in the visual
3639 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3643 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3646 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
3649 xassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
3651 /* Determine face for CHARSET_ASCII, or unibyte. */
3652 face_id
= face_at_buffer_position (it
->w
,
3654 it
->region_beg_charpos
,
3655 it
->region_end_charpos
,
3656 &next_check_charpos
,
3659 /* Correct the face for charsets different from ASCII. Do it
3660 for the multibyte case only. The face returned above is
3661 suitable for unibyte text if current_buffer is unibyte. */
3662 if (it
->multibyte_p
)
3664 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3665 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3666 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3675 /***********************************************************************
3677 ***********************************************************************/
3679 /* Set up iterator IT from invisible properties at its current
3680 position. Called from handle_stop. */
3682 static enum prop_handled
3683 handle_invisible_prop (struct it
*it
)
3685 enum prop_handled handled
= HANDLED_NORMALLY
;
3687 if (STRINGP (it
->string
))
3689 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3691 /* Get the value of the invisible text property at the
3692 current position. Value will be nil if there is no such
3694 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3695 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3698 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3702 handled
= HANDLED_RECOMPUTE_PROPS
;
3704 /* Get the position at which the next change of the
3705 invisible text property can be found in IT->string.
3706 Value will be nil if the property value is the same for
3707 all the rest of IT->string. */
3708 XSETINT (limit
, SCHARS (it
->string
));
3709 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3712 /* Text at current position is invisible. The next
3713 change in the property is at position end_charpos.
3714 Move IT's current position to that position. */
3715 if (INTEGERP (end_charpos
)
3716 && (endpos
= XFASTINT (end_charpos
)) < XFASTINT (limit
))
3718 struct text_pos old
;
3721 old
= it
->current
.string_pos
;
3722 oldpos
= CHARPOS (old
);
3725 if (it
->bidi_it
.first_elt
3726 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
3727 bidi_paragraph_init (it
->paragraph_embedding
,
3729 /* Bidi-iterate out of the invisible text. */
3732 bidi_move_to_visually_next (&it
->bidi_it
);
3734 while (oldpos
<= it
->bidi_it
.charpos
3735 && it
->bidi_it
.charpos
< endpos
);
3737 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3738 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3739 if (IT_CHARPOS (*it
) >= endpos
)
3740 it
->prev_stop
= endpos
;
3744 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3745 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3750 /* The rest of the string is invisible. If this is an
3751 overlay string, proceed with the next overlay string
3752 or whatever comes and return a character from there. */
3753 if (it
->current
.overlay_string_index
>= 0)
3755 next_overlay_string (it
);
3756 /* Don't check for overlay strings when we just
3757 finished processing them. */
3758 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3762 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3763 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3771 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
3772 Lisp_Object pos
, prop
, overlay
;
3774 /* First of all, is there invisible text at this position? */
3775 tem
= start_charpos
= IT_CHARPOS (*it
);
3776 pos
= make_number (tem
);
3777 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3779 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3781 /* If we are on invisible text, skip over it. */
3782 if (invis_p
&& start_charpos
< it
->end_charpos
)
3784 /* Record whether we have to display an ellipsis for the
3786 int display_ellipsis_p
= invis_p
== 2;
3788 handled
= HANDLED_RECOMPUTE_PROPS
;
3790 /* Loop skipping over invisible text. The loop is left at
3791 ZV or with IT on the first char being visible again. */
3794 /* Try to skip some invisible text. Return value is the
3795 position reached which can be equal to where we start
3796 if there is nothing invisible there. This skips both
3797 over invisible text properties and overlays with
3798 invisible property. */
3799 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
3801 /* If we skipped nothing at all we weren't at invisible
3802 text in the first place. If everything to the end of
3803 the buffer was skipped, end the loop. */
3804 if (newpos
== tem
|| newpos
>= ZV
)
3808 /* We skipped some characters but not necessarily
3809 all there are. Check if we ended up on visible
3810 text. Fget_char_property returns the property of
3811 the char before the given position, i.e. if we
3812 get invis_p = 0, this means that the char at
3813 newpos is visible. */
3814 pos
= make_number (newpos
);
3815 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3816 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3819 /* If we ended up on invisible text, proceed to
3820 skip starting with next_stop. */
3824 /* If there are adjacent invisible texts, don't lose the
3825 second one's ellipsis. */
3827 display_ellipsis_p
= 1;
3831 /* The position newpos is now either ZV or on visible text. */
3832 if (it
->bidi_p
&& newpos
< ZV
)
3834 /* With bidi iteration, the region of invisible text
3835 could start and/or end in the middle of a non-base
3836 embedding level. Therefore, we need to skip
3837 invisible text using the bidi iterator, starting at
3838 IT's current position, until we find ourselves
3839 outside the invisible text. Skipping invisible text
3840 _after_ bidi iteration avoids affecting the visual
3841 order of the displayed text when invisible properties
3842 are added or removed. */
3843 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
3845 /* If we were `reseat'ed to a new paragraph,
3846 determine the paragraph base direction. We need
3847 to do it now because next_element_from_buffer may
3848 not have a chance to do it, if we are going to
3849 skip any text at the beginning, which resets the
3851 bidi_paragraph_init (it
->paragraph_embedding
,
3856 bidi_move_to_visually_next (&it
->bidi_it
);
3858 while (it
->stop_charpos
<= it
->bidi_it
.charpos
3859 && it
->bidi_it
.charpos
< newpos
);
3860 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3861 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3862 /* If we overstepped NEWPOS, record its position in the
3863 iterator, so that we skip invisible text if later the
3864 bidi iteration lands us in the invisible region
3866 if (IT_CHARPOS (*it
) >= newpos
)
3867 it
->prev_stop
= newpos
;
3871 IT_CHARPOS (*it
) = newpos
;
3872 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3875 /* If there are before-strings at the start of invisible
3876 text, and the text is invisible because of a text
3877 property, arrange to show before-strings because 20.x did
3878 it that way. (If the text is invisible because of an
3879 overlay property instead of a text property, this is
3880 already handled in the overlay code.) */
3882 && get_overlay_strings (it
, it
->stop_charpos
))
3884 handled
= HANDLED_RECOMPUTE_PROPS
;
3885 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3887 else if (display_ellipsis_p
)
3889 /* Make sure that the glyphs of the ellipsis will get
3890 correct `charpos' values. If we would not update
3891 it->position here, the glyphs would belong to the
3892 last visible character _before_ the invisible
3893 text, which confuses `set_cursor_from_row'.
3895 We use the last invisible position instead of the
3896 first because this way the cursor is always drawn on
3897 the first "." of the ellipsis, whenever PT is inside
3898 the invisible text. Otherwise the cursor would be
3899 placed _after_ the ellipsis when the point is after the
3900 first invisible character. */
3901 if (!STRINGP (it
->object
))
3903 it
->position
.charpos
= newpos
- 1;
3904 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3907 /* Let the ellipsis display before
3908 considering any properties of the following char.
3909 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3910 handled
= HANDLED_RETURN
;
3919 /* Make iterator IT return `...' next.
3920 Replaces LEN characters from buffer. */
3923 setup_for_ellipsis (struct it
*it
, int len
)
3925 /* Use the display table definition for `...'. Invalid glyphs
3926 will be handled by the method returning elements from dpvec. */
3927 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3929 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3930 it
->dpvec
= v
->contents
;
3931 it
->dpend
= v
->contents
+ v
->header
.size
;
3935 /* Default `...'. */
3936 it
->dpvec
= default_invis_vector
;
3937 it
->dpend
= default_invis_vector
+ 3;
3940 it
->dpvec_char_len
= len
;
3941 it
->current
.dpvec_index
= 0;
3942 it
->dpvec_face_id
= -1;
3944 /* Remember the current face id in case glyphs specify faces.
3945 IT's face is restored in set_iterator_to_next.
3946 saved_face_id was set to preceding char's face in handle_stop. */
3947 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3948 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3950 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3956 /***********************************************************************
3958 ***********************************************************************/
3960 /* Set up iterator IT from `display' property at its current position.
3961 Called from handle_stop.
3962 We return HANDLED_RETURN if some part of the display property
3963 overrides the display of the buffer text itself.
3964 Otherwise we return HANDLED_NORMALLY. */
3966 static enum prop_handled
3967 handle_display_prop (struct it
*it
)
3969 Lisp_Object propval
, object
, overlay
;
3970 struct text_pos
*position
;
3972 /* Nonzero if some property replaces the display of the text itself. */
3973 int display_replaced_p
= 0;
3975 if (STRINGP (it
->string
))
3977 object
= it
->string
;
3978 position
= &it
->current
.string_pos
;
3979 bufpos
= CHARPOS (it
->current
.pos
);
3983 XSETWINDOW (object
, it
->w
);
3984 position
= &it
->current
.pos
;
3985 bufpos
= CHARPOS (*position
);
3988 /* Reset those iterator values set from display property values. */
3989 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3990 it
->space_width
= Qnil
;
3991 it
->font_height
= Qnil
;
3994 /* We don't support recursive `display' properties, i.e. string
3995 values that have a string `display' property, that have a string
3996 `display' property etc. */
3997 if (!it
->string_from_display_prop_p
)
3998 it
->area
= TEXT_AREA
;
4000 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4001 Qdisplay
, object
, &overlay
);
4003 return HANDLED_NORMALLY
;
4004 /* Now OVERLAY is the overlay that gave us this property, or nil
4005 if it was a text property. */
4007 if (!STRINGP (it
->string
))
4008 object
= it
->w
->buffer
;
4010 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4012 FRAME_WINDOW_P (it
->f
));
4014 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4017 /* Subroutine of handle_display_prop. Returns non-zero if the display
4018 specification in SPEC is a replacing specification, i.e. it would
4019 replace the text covered by `display' property with something else,
4020 such as an image or a display string.
4022 See handle_single_display_spec for documentation of arguments.
4023 frame_window_p is non-zero if the window being redisplayed is on a
4024 GUI frame; this argument is used only if IT is NULL, see below.
4026 IT can be NULL, if this is called by the bidi reordering code
4027 through compute_display_string_pos, which see. In that case, this
4028 function only examines SPEC, but does not otherwise "handle" it, in
4029 the sense that it doesn't set up members of IT from the display
4032 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4033 Lisp_Object overlay
, struct text_pos
*position
,
4034 EMACS_INT bufpos
, int frame_window_p
)
4036 int replacing_p
= 0;
4039 /* Simple specerties. */
4040 && !EQ (XCAR (spec
), Qimage
)
4041 && !EQ (XCAR (spec
), Qspace
)
4042 && !EQ (XCAR (spec
), Qwhen
)
4043 && !EQ (XCAR (spec
), Qslice
)
4044 && !EQ (XCAR (spec
), Qspace_width
)
4045 && !EQ (XCAR (spec
), Qheight
)
4046 && !EQ (XCAR (spec
), Qraise
)
4047 /* Marginal area specifications. */
4048 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4049 && !EQ (XCAR (spec
), Qleft_fringe
)
4050 && !EQ (XCAR (spec
), Qright_fringe
)
4051 && !NILP (XCAR (spec
)))
4053 for (; CONSP (spec
); spec
= XCDR (spec
))
4055 if (handle_single_display_spec (it
, XCAR (spec
), object
, overlay
,
4056 position
, bufpos
, replacing_p
,
4060 /* If some text in a string is replaced, `position' no
4061 longer points to the position of `object'. */
4062 if (!it
|| STRINGP (object
))
4067 else if (VECTORP (spec
))
4070 for (i
= 0; i
< ASIZE (spec
); ++i
)
4071 if (handle_single_display_spec (it
, AREF (spec
, i
), object
, overlay
,
4072 position
, bufpos
, replacing_p
,
4076 /* If some text in a string is replaced, `position' no
4077 longer points to the position of `object'. */
4078 if (!it
|| STRINGP (object
))
4084 if (handle_single_display_spec (it
, spec
, object
, overlay
,
4085 position
, bufpos
, 0, frame_window_p
))
4092 /* Value is the position of the end of the `display' property starting
4093 at START_POS in OBJECT. */
4095 static struct text_pos
4096 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4099 struct text_pos end_pos
;
4101 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4102 Qdisplay
, object
, Qnil
);
4103 CHARPOS (end_pos
) = XFASTINT (end
);
4104 if (STRINGP (object
))
4105 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4107 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4113 /* Set up IT from a single `display' property specification SPEC. OBJECT
4114 is the object in which the `display' property was found. *POSITION
4115 is the position in OBJECT at which the `display' property was found.
4116 BUFPOS is the buffer position of OBJECT (different from POSITION if
4117 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4118 previously saw a display specification which already replaced text
4119 display with something else, for example an image; we ignore such
4120 properties after the first one has been processed.
4122 OVERLAY is the overlay this `display' property came from,
4123 or nil if it was a text property.
4125 If SPEC is a `space' or `image' specification, and in some other
4126 cases too, set *POSITION to the position where the `display'
4129 If IT is NULL, only examine the property specification in SPEC, but
4130 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4131 is intended to be displayed in a window on a GUI frame.
4133 Value is non-zero if something was found which replaces the display
4134 of buffer or string text. */
4137 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4138 Lisp_Object overlay
, struct text_pos
*position
,
4139 EMACS_INT bufpos
, int display_replaced_p
,
4143 Lisp_Object location
, value
;
4144 struct text_pos start_pos
= *position
;
4147 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4148 If the result is non-nil, use VALUE instead of SPEC. */
4150 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4159 if (!NILP (form
) && !EQ (form
, Qt
))
4161 int count
= SPECPDL_INDEX ();
4162 struct gcpro gcpro1
;
4164 /* Bind `object' to the object having the `display' property, a
4165 buffer or string. Bind `position' to the position in the
4166 object where the property was found, and `buffer-position'
4167 to the current position in the buffer. */
4170 XSETBUFFER (object
, current_buffer
);
4171 specbind (Qobject
, object
);
4172 specbind (Qposition
, make_number (CHARPOS (*position
)));
4173 specbind (Qbuffer_position
, make_number (bufpos
));
4175 form
= safe_eval (form
);
4177 unbind_to (count
, Qnil
);
4183 /* Handle `(height HEIGHT)' specifications. */
4185 && EQ (XCAR (spec
), Qheight
)
4186 && CONSP (XCDR (spec
)))
4190 if (!FRAME_WINDOW_P (it
->f
))
4193 it
->font_height
= XCAR (XCDR (spec
));
4194 if (!NILP (it
->font_height
))
4196 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4197 int new_height
= -1;
4199 if (CONSP (it
->font_height
)
4200 && (EQ (XCAR (it
->font_height
), Qplus
)
4201 || EQ (XCAR (it
->font_height
), Qminus
))
4202 && CONSP (XCDR (it
->font_height
))
4203 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4205 /* `(+ N)' or `(- N)' where N is an integer. */
4206 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4207 if (EQ (XCAR (it
->font_height
), Qplus
))
4209 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4211 else if (FUNCTIONP (it
->font_height
))
4213 /* Call function with current height as argument.
4214 Value is the new height. */
4216 height
= safe_call1 (it
->font_height
,
4217 face
->lface
[LFACE_HEIGHT_INDEX
]);
4218 if (NUMBERP (height
))
4219 new_height
= XFLOATINT (height
);
4221 else if (NUMBERP (it
->font_height
))
4223 /* Value is a multiple of the canonical char height. */
4226 f
= FACE_FROM_ID (it
->f
,
4227 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4228 new_height
= (XFLOATINT (it
->font_height
)
4229 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4233 /* Evaluate IT->font_height with `height' bound to the
4234 current specified height to get the new height. */
4235 int count
= SPECPDL_INDEX ();
4237 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4238 value
= safe_eval (it
->font_height
);
4239 unbind_to (count
, Qnil
);
4241 if (NUMBERP (value
))
4242 new_height
= XFLOATINT (value
);
4246 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4253 /* Handle `(space-width WIDTH)'. */
4255 && EQ (XCAR (spec
), Qspace_width
)
4256 && CONSP (XCDR (spec
)))
4260 if (!FRAME_WINDOW_P (it
->f
))
4263 value
= XCAR (XCDR (spec
));
4264 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4265 it
->space_width
= value
;
4271 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4273 && EQ (XCAR (spec
), Qslice
))
4279 if (!FRAME_WINDOW_P (it
->f
))
4282 if (tem
= XCDR (spec
), CONSP (tem
))
4284 it
->slice
.x
= XCAR (tem
);
4285 if (tem
= XCDR (tem
), CONSP (tem
))
4287 it
->slice
.y
= XCAR (tem
);
4288 if (tem
= XCDR (tem
), CONSP (tem
))
4290 it
->slice
.width
= XCAR (tem
);
4291 if (tem
= XCDR (tem
), CONSP (tem
))
4292 it
->slice
.height
= XCAR (tem
);
4301 /* Handle `(raise FACTOR)'. */
4303 && EQ (XCAR (spec
), Qraise
)
4304 && CONSP (XCDR (spec
)))
4308 if (!FRAME_WINDOW_P (it
->f
))
4311 #ifdef HAVE_WINDOW_SYSTEM
4312 value
= XCAR (XCDR (spec
));
4313 if (NUMBERP (value
))
4315 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4316 it
->voffset
= - (XFLOATINT (value
)
4317 * (FONT_HEIGHT (face
->font
)));
4319 #endif /* HAVE_WINDOW_SYSTEM */
4325 /* Don't handle the other kinds of display specifications
4326 inside a string that we got from a `display' property. */
4327 if (it
&& it
->string_from_display_prop_p
)
4330 /* Characters having this form of property are not displayed, so
4331 we have to find the end of the property. */
4334 start_pos
= *position
;
4335 *position
= display_prop_end (it
, object
, start_pos
);
4339 /* Stop the scan at that end position--we assume that all
4340 text properties change there. */
4342 it
->stop_charpos
= position
->charpos
;
4344 /* Handle `(left-fringe BITMAP [FACE])'
4345 and `(right-fringe BITMAP [FACE])'. */
4347 && (EQ (XCAR (spec
), Qleft_fringe
)
4348 || EQ (XCAR (spec
), Qright_fringe
))
4349 && CONSP (XCDR (spec
)))
4355 if (!FRAME_WINDOW_P (it
->f
))
4356 /* If we return here, POSITION has been advanced
4357 across the text with this property. */
4360 else if (!frame_window_p
)
4363 #ifdef HAVE_WINDOW_SYSTEM
4364 value
= XCAR (XCDR (spec
));
4365 if (!SYMBOLP (value
)
4366 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4367 /* If we return here, POSITION has been advanced
4368 across the text with this property. */
4373 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4375 if (CONSP (XCDR (XCDR (spec
))))
4377 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4378 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4384 /* Save current settings of IT so that we can restore them
4385 when we are finished with the glyph property value. */
4386 push_it (it
, position
);
4388 it
->area
= TEXT_AREA
;
4389 it
->what
= IT_IMAGE
;
4390 it
->image_id
= -1; /* no image */
4391 it
->position
= start_pos
;
4392 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4393 it
->method
= GET_FROM_IMAGE
;
4394 it
->from_overlay
= Qnil
;
4395 it
->face_id
= face_id
;
4397 /* Say that we haven't consumed the characters with
4398 `display' property yet. The call to pop_it in
4399 set_iterator_to_next will clean this up. */
4400 *position
= start_pos
;
4402 if (EQ (XCAR (spec
), Qleft_fringe
))
4404 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4405 it
->left_user_fringe_face_id
= face_id
;
4409 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4410 it
->right_user_fringe_face_id
= face_id
;
4413 #endif /* HAVE_WINDOW_SYSTEM */
4417 /* Prepare to handle `((margin left-margin) ...)',
4418 `((margin right-margin) ...)' and `((margin nil) ...)'
4419 prefixes for display specifications. */
4420 location
= Qunbound
;
4421 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4425 value
= XCDR (spec
);
4427 value
= XCAR (value
);
4430 if (EQ (XCAR (tem
), Qmargin
)
4431 && (tem
= XCDR (tem
),
4432 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4434 || EQ (tem
, Qleft_margin
)
4435 || EQ (tem
, Qright_margin
))))
4439 if (EQ (location
, Qunbound
))
4445 /* After this point, VALUE is the property after any
4446 margin prefix has been stripped. It must be a string,
4447 an image specification, or `(space ...)'.
4449 LOCATION specifies where to display: `left-margin',
4450 `right-margin' or nil. */
4452 valid_p
= (STRINGP (value
)
4453 #ifdef HAVE_WINDOW_SYSTEM
4454 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4455 && valid_image_p (value
))
4456 #endif /* not HAVE_WINDOW_SYSTEM */
4457 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4459 if (valid_p
&& !display_replaced_p
)
4464 /* Save current settings of IT so that we can restore them
4465 when we are finished with the glyph property value. */
4466 push_it (it
, position
);
4467 it
->from_overlay
= overlay
;
4469 if (NILP (location
))
4470 it
->area
= TEXT_AREA
;
4471 else if (EQ (location
, Qleft_margin
))
4472 it
->area
= LEFT_MARGIN_AREA
;
4474 it
->area
= RIGHT_MARGIN_AREA
;
4476 if (STRINGP (value
))
4479 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4480 it
->current
.overlay_string_index
= -1;
4481 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4482 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4483 it
->method
= GET_FROM_STRING
;
4484 it
->stop_charpos
= 0;
4486 it
->base_level_stop
= 0;
4487 it
->string_from_display_prop_p
= 1;
4488 /* Say that we haven't consumed the characters with
4489 `display' property yet. The call to pop_it in
4490 set_iterator_to_next will clean this up. */
4491 if (BUFFERP (object
))
4492 *position
= start_pos
;
4494 /* Force paragraph direction to be that of the parent
4496 it
->paragraph_embedding
=
4497 (it
->bidi_p
? it
->bidi_it
.paragraph_dir
: L2R
);
4499 /* Do we need to reorder this display string? */
4500 if (it
->multibyte_p
)
4502 if (BUFFERP (object
))
4504 !NILP (BVAR (XBUFFER (object
), bidi_display_reordering
));
4507 !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
4512 /* Set up the bidi iterator for this display string. */
4515 it
->bidi_it
.string
.lstring
= it
->string
;
4516 it
->bidi_it
.string
.s
= NULL
;
4517 it
->bidi_it
.string
.schars
= it
->end_charpos
;
4518 it
->bidi_it
.string
.bufpos
= bufpos
;
4519 it
->bidi_it
.string
.from_disp_str
= 1;
4520 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4523 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4525 it
->method
= GET_FROM_STRETCH
;
4527 *position
= it
->position
= start_pos
;
4529 #ifdef HAVE_WINDOW_SYSTEM
4532 it
->what
= IT_IMAGE
;
4533 it
->image_id
= lookup_image (it
->f
, value
);
4534 it
->position
= start_pos
;
4535 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4536 it
->method
= GET_FROM_IMAGE
;
4538 /* Say that we haven't consumed the characters with
4539 `display' property yet. The call to pop_it in
4540 set_iterator_to_next will clean this up. */
4541 *position
= start_pos
;
4543 #endif /* HAVE_WINDOW_SYSTEM */
4548 /* Invalid property or property not supported. Restore
4549 POSITION to what it was before. */
4550 *position
= start_pos
;
4554 /* Check if PROP is a display property value whose text should be
4555 treated as intangible. OVERLAY is the overlay from which PROP
4556 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4557 specify the buffer position covered by PROP. */
4560 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4561 EMACS_INT charpos
, EMACS_INT bytepos
)
4563 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4564 struct text_pos position
;
4566 SET_TEXT_POS (position
, charpos
, bytepos
);
4567 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4568 &position
, charpos
, frame_window_p
);
4572 /* Return 1 if PROP is a display sub-property value containing STRING.
4574 Implementation note: this and the following function are really
4575 special cases of handle_display_spec and
4576 handle_single_display_spec, and should ideally use the same code.
4577 Until they do, these two pairs must be consistent and must be
4578 modified in sync. */
4581 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4583 if (EQ (string
, prop
))
4586 /* Skip over `when FORM'. */
4587 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4592 /* Actually, the condition following `when' should be eval'ed,
4593 like handle_single_display_spec does, and we should return
4594 zero if it evaluates to nil. However, this function is
4595 called only when the buffer was already displayed and some
4596 glyph in the glyph matrix was found to come from a display
4597 string. Therefore, the condition was already evaluated, and
4598 the result was non-nil, otherwise the display string wouldn't
4599 have been displayed and we would have never been called for
4600 this property. Thus, we can skip the evaluation and assume
4601 its result is non-nil. */
4606 /* Skip over `margin LOCATION'. */
4607 if (EQ (XCAR (prop
), Qmargin
))
4618 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
4622 /* Return 1 if STRING appears in the `display' property PROP. */
4625 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4628 && !EQ (XCAR (prop
), Qwhen
)
4629 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
4631 /* A list of sub-properties. */
4632 while (CONSP (prop
))
4634 if (single_display_spec_string_p (XCAR (prop
), string
))
4639 else if (VECTORP (prop
))
4641 /* A vector of sub-properties. */
4643 for (i
= 0; i
< ASIZE (prop
); ++i
)
4644 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4648 return single_display_spec_string_p (prop
, string
);
4653 /* Look for STRING in overlays and text properties in the current
4654 buffer, between character positions FROM and TO (excluding TO).
4655 BACK_P non-zero means look back (in this case, TO is supposed to be
4657 Value is the first character position where STRING was found, or
4658 zero if it wasn't found before hitting TO.
4660 This function may only use code that doesn't eval because it is
4661 called asynchronously from note_mouse_highlight. */
4664 string_buffer_position_lim (Lisp_Object string
,
4665 EMACS_INT from
, EMACS_INT to
, int back_p
)
4667 Lisp_Object limit
, prop
, pos
;
4670 pos
= make_number (from
);
4672 if (!back_p
) /* looking forward */
4674 limit
= make_number (min (to
, ZV
));
4675 while (!found
&& !EQ (pos
, limit
))
4677 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4678 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4681 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4685 else /* looking back */
4687 limit
= make_number (max (to
, BEGV
));
4688 while (!found
&& !EQ (pos
, limit
))
4690 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4691 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4694 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4699 return found
? XINT (pos
) : 0;
4702 /* Determine which buffer position in current buffer STRING comes from.
4703 AROUND_CHARPOS is an approximate position where it could come from.
4704 Value is the buffer position or 0 if it couldn't be determined.
4706 This function is necessary because we don't record buffer positions
4707 in glyphs generated from strings (to keep struct glyph small).
4708 This function may only use code that doesn't eval because it is
4709 called asynchronously from note_mouse_highlight. */
4712 string_buffer_position (Lisp_Object string
, EMACS_INT around_charpos
)
4714 const int MAX_DISTANCE
= 1000;
4715 EMACS_INT found
= string_buffer_position_lim (string
, around_charpos
,
4716 around_charpos
+ MAX_DISTANCE
,
4720 found
= string_buffer_position_lim (string
, around_charpos
,
4721 around_charpos
- MAX_DISTANCE
, 1);
4727 /***********************************************************************
4728 `composition' property
4729 ***********************************************************************/
4731 /* Set up iterator IT from `composition' property at its current
4732 position. Called from handle_stop. */
4734 static enum prop_handled
4735 handle_composition_prop (struct it
*it
)
4737 Lisp_Object prop
, string
;
4738 EMACS_INT pos
, pos_byte
, start
, end
;
4740 if (STRINGP (it
->string
))
4744 pos
= IT_STRING_CHARPOS (*it
);
4745 pos_byte
= IT_STRING_BYTEPOS (*it
);
4746 string
= it
->string
;
4747 s
= SDATA (string
) + pos_byte
;
4748 it
->c
= STRING_CHAR (s
);
4752 pos
= IT_CHARPOS (*it
);
4753 pos_byte
= IT_BYTEPOS (*it
);
4755 it
->c
= FETCH_CHAR (pos_byte
);
4758 /* If there's a valid composition and point is not inside of the
4759 composition (in the case that the composition is from the current
4760 buffer), draw a glyph composed from the composition components. */
4761 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4762 && COMPOSITION_VALID_P (start
, end
, prop
)
4763 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4767 if (STRINGP (it
->string
))
4768 pos_byte
= string_char_to_byte (it
->string
, start
);
4770 pos_byte
= CHAR_TO_BYTE (start
);
4772 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4775 if (it
->cmp_it
.id
>= 0)
4778 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4779 it
->cmp_it
.nglyphs
= -1;
4783 return HANDLED_NORMALLY
;
4788 /***********************************************************************
4790 ***********************************************************************/
4792 /* The following structure is used to record overlay strings for
4793 later sorting in load_overlay_strings. */
4795 struct overlay_entry
4797 Lisp_Object overlay
;
4804 /* Set up iterator IT from overlay strings at its current position.
4805 Called from handle_stop. */
4807 static enum prop_handled
4808 handle_overlay_change (struct it
*it
)
4810 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4811 return HANDLED_RECOMPUTE_PROPS
;
4813 return HANDLED_NORMALLY
;
4817 /* Set up the next overlay string for delivery by IT, if there is an
4818 overlay string to deliver. Called by set_iterator_to_next when the
4819 end of the current overlay string is reached. If there are more
4820 overlay strings to display, IT->string and
4821 IT->current.overlay_string_index are set appropriately here.
4822 Otherwise IT->string is set to nil. */
4825 next_overlay_string (struct it
*it
)
4827 ++it
->current
.overlay_string_index
;
4828 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4830 /* No more overlay strings. Restore IT's settings to what
4831 they were before overlay strings were processed, and
4832 continue to deliver from current_buffer. */
4834 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4837 || (NILP (it
->string
)
4838 && it
->method
== GET_FROM_BUFFER
4839 && it
->stop_charpos
>= BEGV
4840 && it
->stop_charpos
<= it
->end_charpos
));
4841 it
->current
.overlay_string_index
= -1;
4842 it
->n_overlay_strings
= 0;
4843 it
->overlay_strings_charpos
= -1;
4845 /* If we're at the end of the buffer, record that we have
4846 processed the overlay strings there already, so that
4847 next_element_from_buffer doesn't try it again. */
4848 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4849 it
->overlay_strings_at_end_processed_p
= 1;
4853 /* There are more overlay strings to process. If
4854 IT->current.overlay_string_index has advanced to a position
4855 where we must load IT->overlay_strings with more strings, do
4856 it. We must load at the IT->overlay_strings_charpos where
4857 IT->n_overlay_strings was originally computed; when invisible
4858 text is present, this might not be IT_CHARPOS (Bug#7016). */
4859 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4861 if (it
->current
.overlay_string_index
&& i
== 0)
4862 load_overlay_strings (it
, it
->overlay_strings_charpos
);
4864 /* Initialize IT to deliver display elements from the overlay
4866 it
->string
= it
->overlay_strings
[i
];
4867 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4868 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4869 it
->method
= GET_FROM_STRING
;
4870 it
->stop_charpos
= 0;
4871 if (it
->cmp_it
.stop_pos
>= 0)
4872 it
->cmp_it
.stop_pos
= 0;
4874 it
->base_level_stop
= 0;
4876 /* Do we need to reorder this overlay string? */
4879 && !NILP (BVAR (current_buffer
, bidi_display_reordering
));
4881 /* Set up the bidi iterator for this overlay string. */
4884 it
->bidi_it
.string
.lstring
= it
->string
;
4885 it
->bidi_it
.string
.s
= NULL
;
4886 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
4887 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
4888 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
4889 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4897 /* Compare two overlay_entry structures E1 and E2. Used as a
4898 comparison function for qsort in load_overlay_strings. Overlay
4899 strings for the same position are sorted so that
4901 1. All after-strings come in front of before-strings, except
4902 when they come from the same overlay.
4904 2. Within after-strings, strings are sorted so that overlay strings
4905 from overlays with higher priorities come first.
4907 2. Within before-strings, strings are sorted so that overlay
4908 strings from overlays with higher priorities come last.
4910 Value is analogous to strcmp. */
4914 compare_overlay_entries (const void *e1
, const void *e2
)
4916 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4917 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4920 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4922 /* Let after-strings appear in front of before-strings if
4923 they come from different overlays. */
4924 if (EQ (entry1
->overlay
, entry2
->overlay
))
4925 result
= entry1
->after_string_p
? 1 : -1;
4927 result
= entry1
->after_string_p
? -1 : 1;
4929 else if (entry1
->after_string_p
)
4930 /* After-strings sorted in order of decreasing priority. */
4931 result
= entry2
->priority
- entry1
->priority
;
4933 /* Before-strings sorted in order of increasing priority. */
4934 result
= entry1
->priority
- entry2
->priority
;
4940 /* Load the vector IT->overlay_strings with overlay strings from IT's
4941 current buffer position, or from CHARPOS if that is > 0. Set
4942 IT->n_overlays to the total number of overlay strings found.
4944 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4945 a time. On entry into load_overlay_strings,
4946 IT->current.overlay_string_index gives the number of overlay
4947 strings that have already been loaded by previous calls to this
4950 IT->add_overlay_start contains an additional overlay start
4951 position to consider for taking overlay strings from, if non-zero.
4952 This position comes into play when the overlay has an `invisible'
4953 property, and both before and after-strings. When we've skipped to
4954 the end of the overlay, because of its `invisible' property, we
4955 nevertheless want its before-string to appear.
4956 IT->add_overlay_start will contain the overlay start position
4959 Overlay strings are sorted so that after-string strings come in
4960 front of before-string strings. Within before and after-strings,
4961 strings are sorted by overlay priority. See also function
4962 compare_overlay_entries. */
4965 load_overlay_strings (struct it
*it
, EMACS_INT charpos
)
4967 Lisp_Object overlay
, window
, str
, invisible
;
4968 struct Lisp_Overlay
*ov
;
4969 EMACS_INT start
, end
;
4971 int n
= 0, i
, j
, invis_p
;
4972 struct overlay_entry
*entries
4973 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4976 charpos
= IT_CHARPOS (*it
);
4978 /* Append the overlay string STRING of overlay OVERLAY to vector
4979 `entries' which has size `size' and currently contains `n'
4980 elements. AFTER_P non-zero means STRING is an after-string of
4982 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4985 Lisp_Object priority; \
4989 int new_size = 2 * size; \
4990 struct overlay_entry *old = entries; \
4992 (struct overlay_entry *) alloca (new_size \
4993 * sizeof *entries); \
4994 memcpy (entries, old, size * sizeof *entries); \
4998 entries[n].string = (STRING); \
4999 entries[n].overlay = (OVERLAY); \
5000 priority = Foverlay_get ((OVERLAY), Qpriority); \
5001 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5002 entries[n].after_string_p = (AFTER_P); \
5007 /* Process overlay before the overlay center. */
5008 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5010 XSETMISC (overlay
, ov
);
5011 xassert (OVERLAYP (overlay
));
5012 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5013 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5018 /* Skip this overlay if it doesn't start or end at IT's current
5020 if (end
!= charpos
&& start
!= charpos
)
5023 /* Skip this overlay if it doesn't apply to IT->w. */
5024 window
= Foverlay_get (overlay
, Qwindow
);
5025 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5028 /* If the text ``under'' the overlay is invisible, both before-
5029 and after-strings from this overlay are visible; start and
5030 end position are indistinguishable. */
5031 invisible
= Foverlay_get (overlay
, Qinvisible
);
5032 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5034 /* If overlay has a non-empty before-string, record it. */
5035 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5036 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5038 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5040 /* If overlay has a non-empty after-string, record it. */
5041 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5042 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5044 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5047 /* Process overlays after the overlay center. */
5048 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5050 XSETMISC (overlay
, ov
);
5051 xassert (OVERLAYP (overlay
));
5052 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5053 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5055 if (start
> charpos
)
5058 /* Skip this overlay if it doesn't start or end at IT's current
5060 if (end
!= charpos
&& start
!= charpos
)
5063 /* Skip this overlay if it doesn't apply to IT->w. */
5064 window
= Foverlay_get (overlay
, Qwindow
);
5065 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5068 /* If the text ``under'' the overlay is invisible, it has a zero
5069 dimension, and both before- and after-strings apply. */
5070 invisible
= Foverlay_get (overlay
, Qinvisible
);
5071 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5073 /* If overlay has a non-empty before-string, record it. */
5074 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5075 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5077 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5079 /* If overlay has a non-empty after-string, record it. */
5080 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5081 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5083 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5086 #undef RECORD_OVERLAY_STRING
5090 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5092 /* Record number of overlay strings, and where we computed it. */
5093 it
->n_overlay_strings
= n
;
5094 it
->overlay_strings_charpos
= charpos
;
5096 /* IT->current.overlay_string_index is the number of overlay strings
5097 that have already been consumed by IT. Copy some of the
5098 remaining overlay strings to IT->overlay_strings. */
5100 j
= it
->current
.overlay_string_index
;
5101 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5103 it
->overlay_strings
[i
] = entries
[j
].string
;
5104 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5111 /* Get the first chunk of overlay strings at IT's current buffer
5112 position, or at CHARPOS if that is > 0. Value is non-zero if at
5113 least one overlay string was found. */
5116 get_overlay_strings_1 (struct it
*it
, EMACS_INT charpos
, int compute_stop_p
)
5118 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5119 process. This fills IT->overlay_strings with strings, and sets
5120 IT->n_overlay_strings to the total number of strings to process.
5121 IT->pos.overlay_string_index has to be set temporarily to zero
5122 because load_overlay_strings needs this; it must be set to -1
5123 when no overlay strings are found because a zero value would
5124 indicate a position in the first overlay string. */
5125 it
->current
.overlay_string_index
= 0;
5126 load_overlay_strings (it
, charpos
);
5128 /* If we found overlay strings, set up IT to deliver display
5129 elements from the first one. Otherwise set up IT to deliver
5130 from current_buffer. */
5131 if (it
->n_overlay_strings
)
5133 /* Make sure we know settings in current_buffer, so that we can
5134 restore meaningful values when we're done with the overlay
5137 compute_stop_pos (it
);
5138 xassert (it
->face_id
>= 0);
5140 /* Save IT's settings. They are restored after all overlay
5141 strings have been processed. */
5142 xassert (!compute_stop_p
|| it
->sp
== 0);
5144 /* When called from handle_stop, there might be an empty display
5145 string loaded. In that case, don't bother saving it. */
5146 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5149 /* Set up IT to deliver display elements from the first overlay
5151 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5152 it
->string
= it
->overlay_strings
[0];
5153 it
->from_overlay
= Qnil
;
5154 it
->stop_charpos
= 0;
5155 xassert (STRINGP (it
->string
));
5156 it
->end_charpos
= SCHARS (it
->string
);
5158 it
->base_level_stop
= 0;
5159 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5160 it
->method
= GET_FROM_STRING
;
5162 /* Do we need to reorder this overlay string? */
5165 && !NILP (BVAR (current_buffer
, bidi_display_reordering
));
5167 /* Force paragraph direction to be that of the parent
5169 it
->paragraph_embedding
= (it
->bidi_p
? it
->bidi_it
.paragraph_dir
: L2R
);
5171 /* Set up the bidi iterator for this overlay string. */
5174 EMACS_INT pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5176 it
->bidi_it
.string
.lstring
= it
->string
;
5177 it
->bidi_it
.string
.s
= NULL
;
5178 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5179 it
->bidi_it
.string
.bufpos
= pos
;
5180 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5181 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5186 it
->current
.overlay_string_index
= -1;
5191 get_overlay_strings (struct it
*it
, EMACS_INT charpos
)
5194 it
->method
= GET_FROM_BUFFER
;
5196 (void) get_overlay_strings_1 (it
, charpos
, 1);
5200 /* Value is non-zero if we found at least one overlay string. */
5201 return STRINGP (it
->string
);
5206 /***********************************************************************
5207 Saving and restoring state
5208 ***********************************************************************/
5210 /* Save current settings of IT on IT->stack. Called, for example,
5211 before setting up IT for an overlay string, to be able to restore
5212 IT's settings to what they were after the overlay string has been
5213 processed. If POSITION is non-NULL, it is the position to save on
5214 the stack instead of IT->position. */
5217 push_it (struct it
*it
, struct text_pos
*position
)
5219 struct iterator_stack_entry
*p
;
5221 xassert (it
->sp
< IT_STACK_SIZE
);
5222 p
= it
->stack
+ it
->sp
;
5224 p
->stop_charpos
= it
->stop_charpos
;
5225 p
->prev_stop
= it
->prev_stop
;
5226 p
->base_level_stop
= it
->base_level_stop
;
5227 p
->cmp_it
= it
->cmp_it
;
5228 xassert (it
->face_id
>= 0);
5229 p
->face_id
= it
->face_id
;
5230 p
->string
= it
->string
;
5231 p
->method
= it
->method
;
5232 p
->from_overlay
= it
->from_overlay
;
5235 case GET_FROM_IMAGE
:
5236 p
->u
.image
.object
= it
->object
;
5237 p
->u
.image
.image_id
= it
->image_id
;
5238 p
->u
.image
.slice
= it
->slice
;
5240 case GET_FROM_STRETCH
:
5241 p
->u
.stretch
.object
= it
->object
;
5244 p
->position
= position
? *position
: it
->position
;
5245 p
->current
= it
->current
;
5246 p
->end_charpos
= it
->end_charpos
;
5247 p
->string_nchars
= it
->string_nchars
;
5249 p
->multibyte_p
= it
->multibyte_p
;
5250 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5251 p
->space_width
= it
->space_width
;
5252 p
->font_height
= it
->font_height
;
5253 p
->voffset
= it
->voffset
;
5254 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5255 p
->display_ellipsis_p
= 0;
5256 p
->line_wrap
= it
->line_wrap
;
5257 p
->bidi_p
= it
->bidi_p
;
5258 p
->paragraph_embedding
= it
->paragraph_embedding
;
5261 /* Save the state of the bidi iterator as well. */
5263 bidi_push_it (&it
->bidi_it
);
5267 iterate_out_of_display_property (struct it
*it
)
5269 int buffer_p
= BUFFERP (it
->object
);
5270 EMACS_INT eob
= (buffer_p
? ZV
: it
->end_charpos
);
5271 EMACS_INT bob
= (buffer_p
? BEGV
: 0);
5273 /* Maybe initialize paragraph direction. If we are at the beginning
5274 of a new paragraph, next_element_from_buffer may not have a
5275 chance to do that. */
5276 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5277 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5278 /* prev_stop can be zero, so check against BEGV as well. */
5279 while (it
->bidi_it
.charpos
>= bob
5280 && it
->prev_stop
<= it
->bidi_it
.charpos
5281 && it
->bidi_it
.charpos
< CHARPOS (it
->position
))
5282 bidi_move_to_visually_next (&it
->bidi_it
);
5283 /* Record the stop_pos we just crossed, for when we cross it
5285 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5286 it
->prev_stop
= CHARPOS (it
->position
);
5287 /* If we ended up not where pop_it put us, resync IT's
5288 positional members with the bidi iterator. */
5289 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5291 SET_TEXT_POS (it
->position
,
5292 it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5294 it
->current
.pos
= it
->position
;
5296 it
->current
.string_pos
= it
->position
;
5300 /* Restore IT's settings from IT->stack. Called, for example, when no
5301 more overlay strings must be processed, and we return to delivering
5302 display elements from a buffer, or when the end of a string from a
5303 `display' property is reached and we return to delivering display
5304 elements from an overlay string, or from a buffer. */
5307 pop_it (struct it
*it
)
5309 struct iterator_stack_entry
*p
;
5311 xassert (it
->sp
> 0);
5313 p
= it
->stack
+ it
->sp
;
5314 it
->stop_charpos
= p
->stop_charpos
;
5315 it
->prev_stop
= p
->prev_stop
;
5316 it
->base_level_stop
= p
->base_level_stop
;
5317 it
->cmp_it
= p
->cmp_it
;
5318 it
->face_id
= p
->face_id
;
5319 it
->current
= p
->current
;
5320 it
->position
= p
->position
;
5321 it
->string
= p
->string
;
5322 it
->from_overlay
= p
->from_overlay
;
5323 if (NILP (it
->string
))
5324 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5325 it
->method
= p
->method
;
5328 case GET_FROM_IMAGE
:
5329 it
->image_id
= p
->u
.image
.image_id
;
5330 it
->object
= p
->u
.image
.object
;
5331 it
->slice
= p
->u
.image
.slice
;
5333 case GET_FROM_STRETCH
:
5334 it
->object
= p
->u
.comp
.object
;
5336 case GET_FROM_BUFFER
:
5337 it
->object
= it
->w
->buffer
;
5339 case GET_FROM_STRING
:
5340 it
->object
= it
->string
;
5342 case GET_FROM_DISPLAY_VECTOR
:
5344 it
->method
= GET_FROM_C_STRING
;
5345 else if (STRINGP (it
->string
))
5346 it
->method
= GET_FROM_STRING
;
5349 it
->method
= GET_FROM_BUFFER
;
5350 it
->object
= it
->w
->buffer
;
5353 it
->end_charpos
= p
->end_charpos
;
5354 it
->string_nchars
= p
->string_nchars
;
5356 it
->multibyte_p
= p
->multibyte_p
;
5357 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5358 it
->space_width
= p
->space_width
;
5359 it
->font_height
= p
->font_height
;
5360 it
->voffset
= p
->voffset
;
5361 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5362 it
->line_wrap
= p
->line_wrap
;
5363 it
->bidi_p
= p
->bidi_p
;
5364 it
->paragraph_embedding
= p
->paragraph_embedding
;
5367 bidi_pop_it (&it
->bidi_it
);
5368 /* Bidi-iterate until we get out of the portion of text, if any,
5369 covered by a `display' text property or by an overlay with
5370 `display' property. (We cannot just jump there, because the
5371 internal coherency of the bidi iterator state can not be
5372 preserved across such jumps.) We also must determine the
5373 paragraph base direction if the overlay we just processed is
5374 at the beginning of a new paragraph. */
5375 if (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
)
5376 iterate_out_of_display_property (it
);
5382 /***********************************************************************
5384 ***********************************************************************/
5386 /* Set IT's current position to the previous line start. */
5389 back_to_previous_line_start (struct it
*it
)
5391 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5392 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5396 /* Move IT to the next line start.
5398 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5399 we skipped over part of the text (as opposed to moving the iterator
5400 continuously over the text). Otherwise, don't change the value
5403 Newlines may come from buffer text, overlay strings, or strings
5404 displayed via the `display' property. That's the reason we can't
5405 simply use find_next_newline_no_quit.
5407 Note that this function may not skip over invisible text that is so
5408 because of text properties and immediately follows a newline. If
5409 it would, function reseat_at_next_visible_line_start, when called
5410 from set_iterator_to_next, would effectively make invisible
5411 characters following a newline part of the wrong glyph row, which
5412 leads to wrong cursor motion. */
5415 forward_to_next_line_start (struct it
*it
, int *skipped_p
)
5417 int old_selective
, newline_found_p
, n
;
5418 const int MAX_NEWLINE_DISTANCE
= 500;
5420 /* If already on a newline, just consume it to avoid unintended
5421 skipping over invisible text below. */
5422 if (it
->what
== IT_CHARACTER
5424 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5426 set_iterator_to_next (it
, 0);
5431 /* Don't handle selective display in the following. It's (a)
5432 unnecessary because it's done by the caller, and (b) leads to an
5433 infinite recursion because next_element_from_ellipsis indirectly
5434 calls this function. */
5435 old_selective
= it
->selective
;
5438 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5439 from buffer text. */
5440 for (n
= newline_found_p
= 0;
5441 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5442 n
+= STRINGP (it
->string
) ? 0 : 1)
5444 if (!get_next_display_element (it
))
5446 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5447 set_iterator_to_next (it
, 0);
5450 /* If we didn't find a newline near enough, see if we can use a
5452 if (!newline_found_p
)
5454 EMACS_INT start
= IT_CHARPOS (*it
);
5455 EMACS_INT limit
= find_next_newline_no_quit (start
, 1);
5458 xassert (!STRINGP (it
->string
));
5460 /* If we are not bidi-reordering, and there isn't any `display'
5461 property in sight, and no overlays, we can just use the
5462 position of the newline in buffer text. */
5464 && (it
->stop_charpos
>= limit
5465 || ((pos
= Fnext_single_property_change (make_number (start
),
5467 make_number (limit
)),
5469 && next_overlay_change (start
) == ZV
)))
5471 IT_CHARPOS (*it
) = limit
;
5472 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5473 *skipped_p
= newline_found_p
= 1;
5477 while (get_next_display_element (it
)
5478 && !newline_found_p
)
5480 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5481 set_iterator_to_next (it
, 0);
5486 it
->selective
= old_selective
;
5487 return newline_found_p
;
5491 /* Set IT's current position to the previous visible line start. Skip
5492 invisible text that is so either due to text properties or due to
5493 selective display. Caution: this does not change IT->current_x and
5497 back_to_previous_visible_line_start (struct it
*it
)
5499 while (IT_CHARPOS (*it
) > BEGV
)
5501 back_to_previous_line_start (it
);
5503 if (IT_CHARPOS (*it
) <= BEGV
)
5506 /* If selective > 0, then lines indented more than its value are
5508 if (it
->selective
> 0
5509 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5510 (double) it
->selective
)) /* iftc */
5513 /* Check the newline before point for invisibility. */
5516 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5517 Qinvisible
, it
->window
);
5518 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5522 if (IT_CHARPOS (*it
) <= BEGV
)
5529 Lisp_Object val
, overlay
;
5531 /* If newline is part of a composition, continue from start of composition */
5532 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5533 && beg
< IT_CHARPOS (*it
))
5536 /* If newline is replaced by a display property, find start of overlay
5537 or interval and continue search from that point. */
5539 pos
= --IT_CHARPOS (it2
);
5542 it2
.string_from_display_prop_p
= 0;
5543 if (handle_display_prop (&it2
) == HANDLED_RETURN
5544 && !NILP (val
= get_char_property_and_overlay
5545 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5546 && (OVERLAYP (overlay
)
5547 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5548 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5550 /* If the call to handle_display_prop above pushed the
5551 iterator state, that causes side effects for the bidi
5552 iterator by calling bidi_push_it. Undo those side
5556 /* push_it calls bidi_push_it only if the bidi_p flag
5557 is set in the iterator being pushed. */
5558 if (it2
.stack
[--it2
.sp
].bidi_p
)
5559 bidi_pop_it (&it2
.bidi_it
);
5564 /* Newline is not replaced by anything -- so we are done. */
5570 IT_CHARPOS (*it
) = beg
;
5571 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5575 it
->continuation_lines_width
= 0;
5577 xassert (IT_CHARPOS (*it
) >= BEGV
);
5578 xassert (IT_CHARPOS (*it
) == BEGV
5579 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5584 /* Reseat iterator IT at the previous visible line start. Skip
5585 invisible text that is so either due to text properties or due to
5586 selective display. At the end, update IT's overlay information,
5587 face information etc. */
5590 reseat_at_previous_visible_line_start (struct it
*it
)
5592 back_to_previous_visible_line_start (it
);
5593 reseat (it
, it
->current
.pos
, 1);
5598 /* Reseat iterator IT on the next visible line start in the current
5599 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5600 preceding the line start. Skip over invisible text that is so
5601 because of selective display. Compute faces, overlays etc at the
5602 new position. Note that this function does not skip over text that
5603 is invisible because of text properties. */
5606 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5608 int newline_found_p
, skipped_p
= 0;
5610 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5612 /* Skip over lines that are invisible because they are indented
5613 more than the value of IT->selective. */
5614 if (it
->selective
> 0)
5615 while (IT_CHARPOS (*it
) < ZV
5616 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5617 (double) it
->selective
)) /* iftc */
5619 xassert (IT_BYTEPOS (*it
) == BEGV
5620 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5621 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5624 /* Position on the newline if that's what's requested. */
5625 if (on_newline_p
&& newline_found_p
)
5627 if (STRINGP (it
->string
))
5629 if (IT_STRING_CHARPOS (*it
) > 0)
5633 --IT_STRING_CHARPOS (*it
);
5634 --IT_STRING_BYTEPOS (*it
);
5637 /* Setting this flag will cause
5638 bidi_move_to_visually_next not to advance, but
5639 instead deliver the current character (newline),
5640 which is what the ON_NEWLINE_P flag wants. */
5641 it
->bidi_it
.first_elt
= 1;
5644 else if (IT_CHARPOS (*it
) > BEGV
)
5651 /* With bidi iteration, the call to `reseat' will cause
5652 bidi_move_to_visually_next deliver the current character,
5653 the newline, instead of advancing. */
5654 reseat (it
, it
->current
.pos
, 0);
5658 reseat (it
, it
->current
.pos
, 0);
5665 /***********************************************************************
5666 Changing an iterator's position
5667 ***********************************************************************/
5669 /* Change IT's current position to POS in current_buffer. If FORCE_P
5670 is non-zero, always check for text properties at the new position.
5671 Otherwise, text properties are only looked up if POS >=
5672 IT->check_charpos of a property. */
5675 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
5677 EMACS_INT original_pos
= IT_CHARPOS (*it
);
5679 reseat_1 (it
, pos
, 0);
5681 /* Determine where to check text properties. Avoid doing it
5682 where possible because text property lookup is very expensive. */
5684 || CHARPOS (pos
) > it
->stop_charpos
5685 || CHARPOS (pos
) < original_pos
)
5689 /* For bidi iteration, we need to prime prev_stop and
5690 base_level_stop with our best estimations. */
5691 if (CHARPOS (pos
) < it
->prev_stop
)
5693 handle_stop_backwards (it
, BEGV
);
5694 if (CHARPOS (pos
) < it
->base_level_stop
)
5695 it
->base_level_stop
= 0;
5697 else if (CHARPOS (pos
) > it
->stop_charpos
5698 && it
->stop_charpos
>= BEGV
)
5699 handle_stop_backwards (it
, it
->stop_charpos
);
5706 it
->prev_stop
= it
->base_level_stop
= 0;
5715 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5716 IT->stop_pos to POS, also. */
5719 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
5721 /* Don't call this function when scanning a C string. */
5722 xassert (it
->s
== NULL
);
5724 /* POS must be a reasonable value. */
5725 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5727 it
->current
.pos
= it
->position
= pos
;
5728 it
->end_charpos
= ZV
;
5730 it
->current
.dpvec_index
= -1;
5731 it
->current
.overlay_string_index
= -1;
5732 IT_STRING_CHARPOS (*it
) = -1;
5733 IT_STRING_BYTEPOS (*it
) = -1;
5735 it
->method
= GET_FROM_BUFFER
;
5736 it
->object
= it
->w
->buffer
;
5737 it
->area
= TEXT_AREA
;
5738 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
5740 it
->string_from_display_prop_p
= 0;
5741 it
->face_before_selective_p
= 0;
5744 it
->bidi_it
.first_elt
= 1;
5745 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5746 it
->bidi_it
.disp_pos
= -1;
5747 it
->bidi_it
.string
.s
= NULL
;
5748 it
->bidi_it
.string
.lstring
= Qnil
;
5749 it
->bidi_it
.string
.bufpos
= 0;
5754 it
->stop_charpos
= CHARPOS (pos
);
5755 it
->base_level_stop
= CHARPOS (pos
);
5760 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5761 If S is non-null, it is a C string to iterate over. Otherwise,
5762 STRING gives a Lisp string to iterate over.
5764 If PRECISION > 0, don't return more then PRECISION number of
5765 characters from the string.
5767 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5768 characters have been returned. FIELD_WIDTH < 0 means an infinite
5771 MULTIBYTE = 0 means disable processing of multibyte characters,
5772 MULTIBYTE > 0 means enable it,
5773 MULTIBYTE < 0 means use IT->multibyte_p.
5775 IT must be initialized via a prior call to init_iterator before
5776 calling this function. */
5779 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
5780 EMACS_INT charpos
, EMACS_INT precision
, int field_width
,
5783 /* No region in strings. */
5784 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5786 /* No text property checks performed by default, but see below. */
5787 it
->stop_charpos
= -1;
5789 /* Set iterator position and end position. */
5790 memset (&it
->current
, 0, sizeof it
->current
);
5791 it
->current
.overlay_string_index
= -1;
5792 it
->current
.dpvec_index
= -1;
5793 xassert (charpos
>= 0);
5795 /* If STRING is specified, use its multibyteness, otherwise use the
5796 setting of MULTIBYTE, if specified. */
5798 it
->multibyte_p
= multibyte
> 0;
5800 /* Bidirectional reordering of strings is controlled by the default
5801 value of bidi-display-reordering. */
5803 !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
))
5808 xassert (STRINGP (string
));
5809 it
->string
= string
;
5811 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5812 it
->method
= GET_FROM_STRING
;
5813 it
->current
.string_pos
= string_pos (charpos
, string
);
5817 it
->bidi_it
.string
.lstring
= string
;
5818 it
->bidi_it
.string
.s
= NULL
;
5819 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5820 it
->bidi_it
.string
.bufpos
= 0;
5821 it
->bidi_it
.string
.from_disp_str
= 0;
5822 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
5823 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5828 it
->s
= (const unsigned char *) s
;
5831 /* Note that we use IT->current.pos, not it->current.string_pos,
5832 for displaying C strings. */
5833 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5834 if (it
->multibyte_p
)
5836 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5837 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5841 it
->bidi_it
.string
.lstring
= Qnil
;
5842 it
->bidi_it
.string
.s
= s
;
5843 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5844 it
->bidi_it
.string
.bufpos
= 0;
5845 it
->bidi_it
.string
.from_disp_str
= 0;
5846 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
5852 /* Unibyte (a.k.a. ASCII) C strings are never bidi-reordered. */
5853 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5854 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5857 it
->method
= GET_FROM_C_STRING
;
5860 /* PRECISION > 0 means don't return more than PRECISION characters
5862 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5864 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5866 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5869 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5870 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5871 FIELD_WIDTH < 0 means infinite field width. This is useful for
5872 padding with `-' at the end of a mode line. */
5873 if (field_width
< 0)
5874 field_width
= INFINITY
;
5875 /* Implementation note: We deliberately don't enlarge
5876 it->bidi_it.string.schars here to fit it->end_charpos, because
5877 the bidi iterator cannot produce characters out of thin air. */
5878 if (field_width
> it
->end_charpos
- charpos
)
5879 it
->end_charpos
= charpos
+ field_width
;
5881 /* Use the standard display table for displaying strings. */
5882 if (DISP_TABLE_P (Vstandard_display_table
))
5883 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5885 it
->stop_charpos
= charpos
;
5886 it
->prev_stop
= charpos
;
5887 it
->base_level_stop
= 0;
5890 it
->bidi_it
.first_elt
= 1;
5891 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5892 it
->bidi_it
.disp_pos
= -1;
5894 if (s
== NULL
&& it
->multibyte_p
)
5896 EMACS_INT endpos
= SCHARS (it
->string
);
5897 if (endpos
> it
->end_charpos
)
5898 endpos
= it
->end_charpos
;
5899 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5907 /***********************************************************************
5909 ***********************************************************************/
5911 /* Map enum it_method value to corresponding next_element_from_* function. */
5913 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
5915 next_element_from_buffer
,
5916 next_element_from_display_vector
,
5917 next_element_from_string
,
5918 next_element_from_c_string
,
5919 next_element_from_image
,
5920 next_element_from_stretch
5923 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5926 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5927 (possibly with the following characters). */
5929 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5930 ((IT)->cmp_it.id >= 0 \
5931 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5932 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5933 END_CHARPOS, (IT)->w, \
5934 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5938 /* Lookup the char-table Vglyphless_char_display for character C (-1
5939 if we want information for no-font case), and return the display
5940 method symbol. By side-effect, update it->what and
5941 it->glyphless_method. This function is called from
5942 get_next_display_element for each character element, and from
5943 x_produce_glyphs when no suitable font was found. */
5946 lookup_glyphless_char_display (int c
, struct it
*it
)
5948 Lisp_Object glyphless_method
= Qnil
;
5950 if (CHAR_TABLE_P (Vglyphless_char_display
)
5951 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
5955 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
5956 if (CONSP (glyphless_method
))
5957 glyphless_method
= FRAME_WINDOW_P (it
->f
)
5958 ? XCAR (glyphless_method
)
5959 : XCDR (glyphless_method
);
5962 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
5966 if (NILP (glyphless_method
))
5969 /* The default is to display the character by a proper font. */
5971 /* The default for the no-font case is to display an empty box. */
5972 glyphless_method
= Qempty_box
;
5974 if (EQ (glyphless_method
, Qzero_width
))
5977 return glyphless_method
;
5978 /* This method can't be used for the no-font case. */
5979 glyphless_method
= Qempty_box
;
5981 if (EQ (glyphless_method
, Qthin_space
))
5982 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
5983 else if (EQ (glyphless_method
, Qempty_box
))
5984 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
5985 else if (EQ (glyphless_method
, Qhex_code
))
5986 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
5987 else if (STRINGP (glyphless_method
))
5988 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
5991 /* Invalid value. We use the default method. */
5992 glyphless_method
= Qnil
;
5995 it
->what
= IT_GLYPHLESS
;
5996 return glyphless_method
;
5999 /* Load IT's display element fields with information about the next
6000 display element from the current position of IT. Value is zero if
6001 end of buffer (or C string) is reached. */
6003 static struct frame
*last_escape_glyph_frame
= NULL
;
6004 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6005 static int last_escape_glyph_merged_face_id
= 0;
6007 struct frame
*last_glyphless_glyph_frame
= NULL
;
6008 unsigned last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6009 int last_glyphless_glyph_merged_face_id
= 0;
6012 get_next_display_element (struct it
*it
)
6014 /* Non-zero means that we found a display element. Zero means that
6015 we hit the end of what we iterate over. Performance note: the
6016 function pointer `method' used here turns out to be faster than
6017 using a sequence of if-statements. */
6021 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6023 if (it
->what
== IT_CHARACTER
)
6025 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6026 and only if (a) the resolved directionality of that character
6028 /* FIXME: Do we need an exception for characters from display
6030 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6031 it
->c
= bidi_mirror_char (it
->c
);
6032 /* Map via display table or translate control characters.
6033 IT->c, IT->len etc. have been set to the next character by
6034 the function call above. If we have a display table, and it
6035 contains an entry for IT->c, translate it. Don't do this if
6036 IT->c itself comes from a display table, otherwise we could
6037 end up in an infinite recursion. (An alternative could be to
6038 count the recursion depth of this function and signal an
6039 error when a certain maximum depth is reached.) Is it worth
6041 if (success_p
&& it
->dpvec
== NULL
)
6044 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6045 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
6046 nbsp_or_shy
= char_is_other
;
6047 int c
= it
->c
; /* This is the character to display. */
6049 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6051 xassert (SINGLE_BYTE_CHAR_P (c
));
6052 if (unibyte_display_via_language_environment
)
6054 c
= DECODE_CHAR (unibyte
, c
);
6056 c
= BYTE8_TO_CHAR (it
->c
);
6059 c
= BYTE8_TO_CHAR (it
->c
);
6063 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6066 struct Lisp_Vector
*v
= XVECTOR (dv
);
6068 /* Return the first character from the display table
6069 entry, if not empty. If empty, don't display the
6070 current character. */
6073 it
->dpvec_char_len
= it
->len
;
6074 it
->dpvec
= v
->contents
;
6075 it
->dpend
= v
->contents
+ v
->header
.size
;
6076 it
->current
.dpvec_index
= 0;
6077 it
->dpvec_face_id
= -1;
6078 it
->saved_face_id
= it
->face_id
;
6079 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6084 set_iterator_to_next (it
, 0);
6089 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6091 if (it
->what
== IT_GLYPHLESS
)
6093 /* Don't display this character. */
6094 set_iterator_to_next (it
, 0);
6098 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6099 nbsp_or_shy
= (c
== 0xA0 ? char_is_nbsp
6100 : c
== 0xAD ? char_is_soft_hyphen
6103 /* Translate control characters into `\003' or `^C' form.
6104 Control characters coming from a display table entry are
6105 currently not translated because we use IT->dpvec to hold
6106 the translation. This could easily be changed but I
6107 don't believe that it is worth doing.
6109 NBSP and SOFT-HYPEN are property translated too.
6111 Non-printable characters and raw-byte characters are also
6112 translated to octal form. */
6113 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6114 ? (it
->area
!= TEXT_AREA
6115 /* In mode line, treat \n, \t like other crl chars. */
6118 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6119 || (c
!= '\n' && c
!= '\t'))
6122 || ! CHAR_PRINTABLE_P (c
))))
6124 /* C is a control character, NBSP, SOFT-HYPEN, raw-byte,
6125 or a non-printable character which must be displayed
6126 either as '\003' or as `^C' where the '\\' and '^'
6127 can be defined in the display table. Fill
6128 IT->ctl_chars with glyphs for what we have to
6129 display. Then, set IT->dpvec to these glyphs. */
6132 int face_id
, lface_id
= 0 ;
6135 /* Handle control characters with ^. */
6137 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6141 g
= '^'; /* default glyph for Control */
6142 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6144 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6145 && GLYPH_CODE_CHAR_VALID_P (gc
))
6147 g
= GLYPH_CODE_CHAR (gc
);
6148 lface_id
= GLYPH_CODE_FACE (gc
);
6152 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6154 else if (it
->f
== last_escape_glyph_frame
6155 && it
->face_id
== last_escape_glyph_face_id
)
6157 face_id
= last_escape_glyph_merged_face_id
;
6161 /* Merge the escape-glyph face into the current face. */
6162 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6164 last_escape_glyph_frame
= it
->f
;
6165 last_escape_glyph_face_id
= it
->face_id
;
6166 last_escape_glyph_merged_face_id
= face_id
;
6169 XSETINT (it
->ctl_chars
[0], g
);
6170 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6172 goto display_control
;
6175 /* Handle non-break space in the mode where it only gets
6178 if (EQ (Vnobreak_char_display
, Qt
)
6179 && nbsp_or_shy
== char_is_nbsp
)
6181 /* Merge the no-break-space face into the current face. */
6182 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6186 XSETINT (it
->ctl_chars
[0], ' ');
6188 goto display_control
;
6191 /* Handle sequences that start with the "escape glyph". */
6193 /* the default escape glyph is \. */
6194 escape_glyph
= '\\';
6197 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6198 && GLYPH_CODE_CHAR_VALID_P (gc
))
6200 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6201 lface_id
= GLYPH_CODE_FACE (gc
);
6205 /* The display table specified a face.
6206 Merge it into face_id and also into escape_glyph. */
6207 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6210 else if (it
->f
== last_escape_glyph_frame
6211 && it
->face_id
== last_escape_glyph_face_id
)
6213 face_id
= last_escape_glyph_merged_face_id
;
6217 /* Merge the escape-glyph face into the current face. */
6218 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6220 last_escape_glyph_frame
= it
->f
;
6221 last_escape_glyph_face_id
= it
->face_id
;
6222 last_escape_glyph_merged_face_id
= face_id
;
6225 /* Handle soft hyphens in the mode where they only get
6228 if (EQ (Vnobreak_char_display
, Qt
)
6229 && nbsp_or_shy
== char_is_soft_hyphen
)
6231 XSETINT (it
->ctl_chars
[0], '-');
6233 goto display_control
;
6236 /* Handle non-break space and soft hyphen
6237 with the escape glyph. */
6241 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6242 c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
6243 XSETINT (it
->ctl_chars
[1], c
);
6245 goto display_control
;
6252 if (CHAR_BYTE8_P (c
))
6253 /* Display \200 instead of \17777600. */
6254 c
= CHAR_TO_BYTE8 (c
);
6255 len
= sprintf (str
, "%03o", c
);
6257 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6258 for (i
= 0; i
< len
; i
++)
6259 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6264 /* Set up IT->dpvec and return first character from it. */
6265 it
->dpvec_char_len
= it
->len
;
6266 it
->dpvec
= it
->ctl_chars
;
6267 it
->dpend
= it
->dpvec
+ ctl_len
;
6268 it
->current
.dpvec_index
= 0;
6269 it
->dpvec_face_id
= face_id
;
6270 it
->saved_face_id
= it
->face_id
;
6271 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6275 it
->char_to_display
= c
;
6279 it
->char_to_display
= it
->c
;
6283 /* Adjust face id for a multibyte character. There are no multibyte
6284 character in unibyte text. */
6285 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6288 && FRAME_WINDOW_P (it
->f
))
6290 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6292 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6294 /* Automatic composition with glyph-string. */
6295 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6297 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6301 EMACS_INT pos
= (it
->s
? -1
6302 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6303 : IT_CHARPOS (*it
));
6305 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
, pos
,
6311 /* Is this character the last one of a run of characters with
6312 box? If yes, set IT->end_of_box_run_p to 1. */
6316 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6318 int face_id
= underlying_face_id (it
);
6319 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6323 if (face
->box
== FACE_NO_BOX
)
6325 /* If the box comes from face properties in a
6326 display string, check faces in that string. */
6327 int string_face_id
= face_after_it_pos (it
);
6328 it
->end_of_box_run_p
6329 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6332 /* Otherwise, the box comes from the underlying face.
6333 If this is the last string character displayed, check
6334 the next buffer location. */
6335 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6336 && (it
->current
.overlay_string_index
6337 == it
->n_overlay_strings
- 1))
6341 struct text_pos pos
= it
->current
.pos
;
6342 INC_TEXT_POS (pos
, it
->multibyte_p
);
6344 next_face_id
= face_at_buffer_position
6345 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6346 it
->region_end_charpos
, &ignore
,
6347 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6349 it
->end_of_box_run_p
6350 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6357 int face_id
= face_after_it_pos (it
);
6358 it
->end_of_box_run_p
6359 = (face_id
!= it
->face_id
6360 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6364 /* Value is 0 if end of buffer or string reached. */
6369 /* Move IT to the next display element.
6371 RESEAT_P non-zero means if called on a newline in buffer text,
6372 skip to the next visible line start.
6374 Functions get_next_display_element and set_iterator_to_next are
6375 separate because I find this arrangement easier to handle than a
6376 get_next_display_element function that also increments IT's
6377 position. The way it is we can first look at an iterator's current
6378 display element, decide whether it fits on a line, and if it does,
6379 increment the iterator position. The other way around we probably
6380 would either need a flag indicating whether the iterator has to be
6381 incremented the next time, or we would have to implement a
6382 decrement position function which would not be easy to write. */
6385 set_iterator_to_next (struct it
*it
, int reseat_p
)
6387 /* Reset flags indicating start and end of a sequence of characters
6388 with box. Reset them at the start of this function because
6389 moving the iterator to a new position might set them. */
6390 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6394 case GET_FROM_BUFFER
:
6395 /* The current display element of IT is a character from
6396 current_buffer. Advance in the buffer, and maybe skip over
6397 invisible lines that are so because of selective display. */
6398 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6399 reseat_at_next_visible_line_start (it
, 0);
6400 else if (it
->cmp_it
.id
>= 0)
6402 /* We are currently getting glyphs from a composition. */
6407 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6408 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6409 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6411 it
->cmp_it
.from
= it
->cmp_it
.to
;
6416 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6418 it
->end_charpos
, Qnil
);
6421 else if (! it
->cmp_it
.reversed_p
)
6423 /* Composition created while scanning forward. */
6424 /* Update IT's char/byte positions to point to the first
6425 character of the next grapheme cluster, or to the
6426 character visually after the current composition. */
6427 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6428 bidi_move_to_visually_next (&it
->bidi_it
);
6429 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6430 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6432 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6434 /* Proceed to the next grapheme cluster. */
6435 it
->cmp_it
.from
= it
->cmp_it
.to
;
6439 /* No more grapheme clusters in this composition.
6440 Find the next stop position. */
6441 EMACS_INT stop
= it
->end_charpos
;
6442 if (it
->bidi_it
.scan_dir
< 0)
6443 /* Now we are scanning backward and don't know
6446 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6447 IT_BYTEPOS (*it
), stop
, Qnil
);
6452 /* Composition created while scanning backward. */
6453 /* Update IT's char/byte positions to point to the last
6454 character of the previous grapheme cluster, or the
6455 character visually after the current composition. */
6456 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6457 bidi_move_to_visually_next (&it
->bidi_it
);
6458 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6459 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6460 if (it
->cmp_it
.from
> 0)
6462 /* Proceed to the previous grapheme cluster. */
6463 it
->cmp_it
.to
= it
->cmp_it
.from
;
6467 /* No more grapheme clusters in this composition.
6468 Find the next stop position. */
6469 EMACS_INT stop
= it
->end_charpos
;
6470 if (it
->bidi_it
.scan_dir
< 0)
6471 /* Now we are scanning backward and don't know
6474 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6475 IT_BYTEPOS (*it
), stop
, Qnil
);
6481 xassert (it
->len
!= 0);
6485 IT_BYTEPOS (*it
) += it
->len
;
6486 IT_CHARPOS (*it
) += 1;
6490 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6491 /* If this is a new paragraph, determine its base
6492 direction (a.k.a. its base embedding level). */
6493 if (it
->bidi_it
.new_paragraph
)
6494 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6495 bidi_move_to_visually_next (&it
->bidi_it
);
6496 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6497 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6498 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6500 /* As the scan direction was changed, we must
6501 re-compute the stop position for composition. */
6502 EMACS_INT stop
= it
->end_charpos
;
6503 if (it
->bidi_it
.scan_dir
< 0)
6505 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6506 IT_BYTEPOS (*it
), stop
, Qnil
);
6509 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6513 case GET_FROM_C_STRING
:
6514 /* Current display element of IT is from a C string. */
6516 /* If the string position is beyond string's end, it means
6517 next_element_from_c_string is padding the string with
6518 blanks, in which case we bypass the bidi iterator,
6519 because it cannot deal with such virtual characters. */
6520 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
6522 IT_BYTEPOS (*it
) += it
->len
;
6523 IT_CHARPOS (*it
) += 1;
6527 bidi_move_to_visually_next (&it
->bidi_it
);
6528 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6529 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6533 case GET_FROM_DISPLAY_VECTOR
:
6534 /* Current display element of IT is from a display table entry.
6535 Advance in the display table definition. Reset it to null if
6536 end reached, and continue with characters from buffers/
6538 ++it
->current
.dpvec_index
;
6540 /* Restore face of the iterator to what they were before the
6541 display vector entry (these entries may contain faces). */
6542 it
->face_id
= it
->saved_face_id
;
6544 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6546 int recheck_faces
= it
->ellipsis_p
;
6549 it
->method
= GET_FROM_C_STRING
;
6550 else if (STRINGP (it
->string
))
6551 it
->method
= GET_FROM_STRING
;
6554 it
->method
= GET_FROM_BUFFER
;
6555 it
->object
= it
->w
->buffer
;
6559 it
->current
.dpvec_index
= -1;
6561 /* Skip over characters which were displayed via IT->dpvec. */
6562 if (it
->dpvec_char_len
< 0)
6563 reseat_at_next_visible_line_start (it
, 1);
6564 else if (it
->dpvec_char_len
> 0)
6566 if (it
->method
== GET_FROM_STRING
6567 && it
->n_overlay_strings
> 0)
6568 it
->ignore_overlay_strings_at_pos_p
= 1;
6569 it
->len
= it
->dpvec_char_len
;
6570 set_iterator_to_next (it
, reseat_p
);
6573 /* Maybe recheck faces after display vector */
6575 it
->stop_charpos
= IT_CHARPOS (*it
);
6579 case GET_FROM_STRING
:
6580 /* Current display element is a character from a Lisp string. */
6581 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6582 if (it
->cmp_it
.id
>= 0)
6588 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6589 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6590 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6591 it
->cmp_it
.from
= it
->cmp_it
.to
;
6595 composition_compute_stop_pos (&it
->cmp_it
,
6596 IT_STRING_CHARPOS (*it
),
6597 IT_STRING_BYTEPOS (*it
),
6598 it
->end_charpos
, it
->string
);
6601 else if (! it
->cmp_it
.reversed_p
)
6603 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6604 bidi_move_to_visually_next (&it
->bidi_it
);
6605 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6606 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6608 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6609 it
->cmp_it
.from
= it
->cmp_it
.to
;
6612 EMACS_INT stop
= it
->end_charpos
;
6613 if (it
->bidi_it
.scan_dir
< 0)
6615 composition_compute_stop_pos (&it
->cmp_it
,
6616 IT_STRING_CHARPOS (*it
),
6617 IT_STRING_BYTEPOS (*it
), stop
,
6623 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6624 bidi_move_to_visually_next (&it
->bidi_it
);
6625 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6626 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6627 if (it
->cmp_it
.from
> 0)
6628 it
->cmp_it
.to
= it
->cmp_it
.from
;
6631 EMACS_INT stop
= it
->end_charpos
;
6632 if (it
->bidi_it
.scan_dir
< 0)
6634 composition_compute_stop_pos (&it
->cmp_it
,
6635 IT_STRING_CHARPOS (*it
),
6636 IT_STRING_BYTEPOS (*it
), stop
,
6644 /* If the string position is beyond string's end, it
6645 means next_element_from_string is padding the string
6646 with blanks, in which case we bypass the bidi
6647 iterator, because it cannot deal with such virtual
6649 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
6651 IT_STRING_BYTEPOS (*it
) += it
->len
;
6652 IT_STRING_CHARPOS (*it
) += 1;
6656 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6658 bidi_move_to_visually_next (&it
->bidi_it
);
6659 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6660 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6661 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6663 EMACS_INT stop
= it
->end_charpos
;
6665 if (it
->bidi_it
.scan_dir
< 0)
6667 composition_compute_stop_pos (&it
->cmp_it
,
6668 IT_STRING_CHARPOS (*it
),
6669 IT_STRING_BYTEPOS (*it
), stop
,
6675 consider_string_end
:
6677 if (it
->current
.overlay_string_index
>= 0)
6679 /* IT->string is an overlay string. Advance to the
6680 next, if there is one. */
6681 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6684 next_overlay_string (it
);
6686 setup_for_ellipsis (it
, 0);
6691 /* IT->string is not an overlay string. If we reached
6692 its end, and there is something on IT->stack, proceed
6693 with what is on the stack. This can be either another
6694 string, this time an overlay string, or a buffer. */
6695 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6699 if (it
->method
== GET_FROM_STRING
)
6700 goto consider_string_end
;
6705 case GET_FROM_IMAGE
:
6706 case GET_FROM_STRETCH
:
6707 /* The position etc with which we have to proceed are on
6708 the stack. The position may be at the end of a string,
6709 if the `display' property takes up the whole string. */
6710 xassert (it
->sp
> 0);
6712 if (it
->method
== GET_FROM_STRING
)
6713 goto consider_string_end
;
6717 /* There are no other methods defined, so this should be a bug. */
6721 xassert (it
->method
!= GET_FROM_STRING
6722 || (STRINGP (it
->string
)
6723 && IT_STRING_CHARPOS (*it
) >= 0));
6726 /* Load IT's display element fields with information about the next
6727 display element which comes from a display table entry or from the
6728 result of translating a control character to one of the forms `^C'
6731 IT->dpvec holds the glyphs to return as characters.
6732 IT->saved_face_id holds the face id before the display vector--it
6733 is restored into IT->face_id in set_iterator_to_next. */
6736 next_element_from_display_vector (struct it
*it
)
6741 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6743 it
->face_id
= it
->saved_face_id
;
6745 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6746 That seemed totally bogus - so I changed it... */
6747 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6749 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6751 it
->c
= GLYPH_CODE_CHAR (gc
);
6752 it
->len
= CHAR_BYTES (it
->c
);
6754 /* The entry may contain a face id to use. Such a face id is
6755 the id of a Lisp face, not a realized face. A face id of
6756 zero means no face is specified. */
6757 if (it
->dpvec_face_id
>= 0)
6758 it
->face_id
= it
->dpvec_face_id
;
6761 int lface_id
= GLYPH_CODE_FACE (gc
);
6763 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6768 /* Display table entry is invalid. Return a space. */
6769 it
->c
= ' ', it
->len
= 1;
6771 /* Don't change position and object of the iterator here. They are
6772 still the values of the character that had this display table
6773 entry or was translated, and that's what we want. */
6774 it
->what
= IT_CHARACTER
;
6778 /* Get the first element of string/buffer in the visual order, after
6779 being reseated to a new position in a string or a buffer. */
6781 get_visually_first_element (struct it
*it
)
6783 int string_p
= STRINGP (it
->string
) || it
->s
;
6784 EMACS_INT eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
6785 EMACS_INT bob
= (string_p
? 0 : BEGV
);
6787 if (STRINGP (it
->string
))
6789 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
6790 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
6794 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6795 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6798 if (it
->bidi_it
.charpos
== eob
)
6800 /* Nothing to do, but reset the FIRST_ELT flag, like
6801 bidi_paragraph_init does, because we are not going to
6803 it
->bidi_it
.first_elt
= 0;
6805 else if (it
->bidi_it
.charpos
== bob
6807 /* FIXME: Should support all Unicode line separators. */
6808 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6809 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
6811 /* If we are at the beginning of a line/string, we can produce
6812 the next element right away. */
6813 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6814 bidi_move_to_visually_next (&it
->bidi_it
);
6818 EMACS_INT orig_bytepos
= it
->bidi_it
.bytepos
;
6820 /* We need to prime the bidi iterator starting at the line's or
6821 string's beginning, before we will be able to produce the
6824 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
6827 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
6829 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
6831 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6834 /* Now return to buffer/string position where we were asked
6835 to get the next display element, and produce that. */
6836 bidi_move_to_visually_next (&it
->bidi_it
);
6838 while (it
->bidi_it
.bytepos
!= orig_bytepos
6839 && it
->bidi_it
.charpos
< eob
);
6842 /* Adjust IT's position information to where we ended up. */
6843 if (STRINGP (it
->string
))
6845 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6846 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6850 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6851 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6854 if (STRINGP (it
->string
) || !it
->s
)
6856 EMACS_INT stop
, charpos
, bytepos
;
6858 if (STRINGP (it
->string
))
6861 stop
= SCHARS (it
->string
);
6862 if (stop
> it
->end_charpos
)
6863 stop
= it
->end_charpos
;
6864 charpos
= IT_STRING_CHARPOS (*it
);
6865 bytepos
= IT_STRING_BYTEPOS (*it
);
6869 stop
= it
->end_charpos
;
6870 charpos
= IT_CHARPOS (*it
);
6871 bytepos
= IT_BYTEPOS (*it
);
6873 if (it
->bidi_it
.scan_dir
< 0)
6875 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
6880 /* Load IT with the next display element from Lisp string IT->string.
6881 IT->current.string_pos is the current position within the string.
6882 If IT->current.overlay_string_index >= 0, the Lisp string is an
6886 next_element_from_string (struct it
*it
)
6888 struct text_pos position
;
6890 xassert (STRINGP (it
->string
));
6891 xassert (!it
->bidi_p
|| it
->string
== it
->bidi_it
.string
.lstring
);
6892 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6893 position
= it
->current
.string_pos
;
6895 /* With bidi reordering, the character to display might not be the
6896 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
6897 that we were reseat()ed to a new string, whose paragraph
6898 direction is not known. */
6899 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6901 get_visually_first_element (it
);
6902 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
6905 /* Time to check for invisible text? */
6906 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
6908 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
6911 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6912 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
6914 /* With bidi non-linear iteration, we could find
6915 ourselves far beyond the last computed stop_charpos,
6916 with several other stop positions in between that we
6917 missed. Scan them all now, in buffer's logical
6918 order, until we find and handle the last stop_charpos
6919 that precedes our current position. */
6920 handle_stop_backwards (it
, it
->stop_charpos
);
6921 return GET_NEXT_DISPLAY_ELEMENT (it
);
6927 /* Take note of the stop position we just moved
6928 across, for when we will move back across it. */
6929 it
->prev_stop
= it
->stop_charpos
;
6930 /* If we are at base paragraph embedding level, take
6931 note of the last stop position seen at this
6933 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6934 it
->base_level_stop
= it
->stop_charpos
;
6938 /* Since a handler may have changed IT->method, we must
6940 return GET_NEXT_DISPLAY_ELEMENT (it
);
6944 /* If we are before prev_stop, we may have overstepped
6945 on our way backwards a stop_pos, and if so, we need
6946 to handle that stop_pos. */
6947 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
6948 /* We can sometimes back up for reasons that have nothing
6949 to do with bidi reordering. E.g., compositions. The
6950 code below is only needed when we are above the base
6951 embedding level, so test for that explicitly. */
6952 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6954 /* If we lost track of base_level_stop, we have no better place
6955 for handle_stop_backwards to start from than BEGV. This
6956 happens, e.g., when we were reseated to the previous
6957 screenful of text by vertical-motion. */
6958 if (it
->base_level_stop
<= 0
6959 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
6960 it
->base_level_stop
= 0;
6961 handle_stop_backwards (it
, it
->base_level_stop
);
6962 return GET_NEXT_DISPLAY_ELEMENT (it
);
6966 if (it
->current
.overlay_string_index
>= 0)
6968 /* Get the next character from an overlay string. In overlay
6969 strings, There is no field width or padding with spaces to
6971 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6976 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6977 IT_STRING_BYTEPOS (*it
),
6978 it
->bidi_it
.scan_dir
< 0
6980 : SCHARS (it
->string
))
6981 && next_element_from_composition (it
))
6985 else if (STRING_MULTIBYTE (it
->string
))
6987 const unsigned char *s
= (SDATA (it
->string
)
6988 + IT_STRING_BYTEPOS (*it
));
6989 it
->c
= string_char_and_length (s
, &it
->len
);
6993 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6999 /* Get the next character from a Lisp string that is not an
7000 overlay string. Such strings come from the mode line, for
7001 example. We may have to pad with spaces, or truncate the
7002 string. See also next_element_from_c_string. */
7003 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7008 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7010 /* Pad with spaces. */
7011 it
->c
= ' ', it
->len
= 1;
7012 CHARPOS (position
) = BYTEPOS (position
) = -1;
7014 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7015 IT_STRING_BYTEPOS (*it
),
7016 it
->bidi_it
.scan_dir
< 0
7018 : it
->string_nchars
)
7019 && next_element_from_composition (it
))
7023 else if (STRING_MULTIBYTE (it
->string
))
7025 const unsigned char *s
= (SDATA (it
->string
)
7026 + IT_STRING_BYTEPOS (*it
));
7027 it
->c
= string_char_and_length (s
, &it
->len
);
7031 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7036 /* Record what we have and where it came from. */
7037 it
->what
= IT_CHARACTER
;
7038 it
->object
= it
->string
;
7039 it
->position
= position
;
7044 /* Load IT with next display element from C string IT->s.
7045 IT->string_nchars is the maximum number of characters to return
7046 from the string. IT->end_charpos may be greater than
7047 IT->string_nchars when this function is called, in which case we
7048 may have to return padding spaces. Value is zero if end of string
7049 reached, including padding spaces. */
7052 next_element_from_c_string (struct it
*it
)
7057 xassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7058 it
->what
= IT_CHARACTER
;
7059 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7062 /* With bidi reordering, the character to display might not be the
7063 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7064 we were reseated to a new string, whose paragraph direction is
7066 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7067 get_visually_first_element (it
);
7069 /* IT's position can be greater than IT->string_nchars in case a
7070 field width or precision has been specified when the iterator was
7072 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7074 /* End of the game. */
7078 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7080 /* Pad with spaces. */
7081 it
->c
= ' ', it
->len
= 1;
7082 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7084 else if (it
->multibyte_p
)
7085 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7087 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7093 /* Set up IT to return characters from an ellipsis, if appropriate.
7094 The definition of the ellipsis glyphs may come from a display table
7095 entry. This function fills IT with the first glyph from the
7096 ellipsis if an ellipsis is to be displayed. */
7099 next_element_from_ellipsis (struct it
*it
)
7101 if (it
->selective_display_ellipsis_p
)
7102 setup_for_ellipsis (it
, it
->len
);
7105 /* The face at the current position may be different from the
7106 face we find after the invisible text. Remember what it
7107 was in IT->saved_face_id, and signal that it's there by
7108 setting face_before_selective_p. */
7109 it
->saved_face_id
= it
->face_id
;
7110 it
->method
= GET_FROM_BUFFER
;
7111 it
->object
= it
->w
->buffer
;
7112 reseat_at_next_visible_line_start (it
, 1);
7113 it
->face_before_selective_p
= 1;
7116 return GET_NEXT_DISPLAY_ELEMENT (it
);
7120 /* Deliver an image display element. The iterator IT is already
7121 filled with image information (done in handle_display_prop). Value
7126 next_element_from_image (struct it
*it
)
7128 it
->what
= IT_IMAGE
;
7129 it
->ignore_overlay_strings_at_pos_p
= 0;
7134 /* Fill iterator IT with next display element from a stretch glyph
7135 property. IT->object is the value of the text property. Value is
7139 next_element_from_stretch (struct it
*it
)
7141 it
->what
= IT_STRETCH
;
7145 /* Scan forward from CHARPOS in the current buffer/string, until we
7146 find a stop position > current IT's position. Then handle the stop
7147 position before that. This is called when we bump into a stop
7148 position while reordering bidirectional text. CHARPOS should be
7149 the last previously processed stop_pos (or BEGV/0, if none were
7150 processed yet) whose position is less that IT's current
7154 handle_stop_backwards (struct it
*it
, EMACS_INT charpos
)
7156 int bufp
= !STRINGP (it
->string
);
7157 EMACS_INT where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7158 struct display_pos save_current
= it
->current
;
7159 struct text_pos save_position
= it
->position
;
7160 struct text_pos pos1
;
7161 EMACS_INT next_stop
;
7163 /* Scan in strict logical order. */
7167 it
->prev_stop
= charpos
;
7170 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7171 reseat_1 (it
, pos1
, 0);
7174 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7175 compute_stop_pos (it
);
7176 /* We must advance forward, right? */
7177 if (it
->stop_charpos
<= it
->prev_stop
)
7179 charpos
= it
->stop_charpos
;
7181 while (charpos
<= where_we_are
);
7183 next_stop
= it
->stop_charpos
;
7184 it
->stop_charpos
= it
->prev_stop
;
7186 it
->current
= save_current
;
7187 it
->position
= save_position
;
7189 it
->stop_charpos
= next_stop
;
7192 /* Load IT with the next display element from current_buffer. Value
7193 is zero if end of buffer reached. IT->stop_charpos is the next
7194 position at which to stop and check for text properties or buffer
7198 next_element_from_buffer (struct it
*it
)
7202 xassert (IT_CHARPOS (*it
) >= BEGV
);
7203 xassert (NILP (it
->string
) && !it
->s
);
7204 xassert (!it
->bidi_p
7205 || (it
->bidi_it
.string
.lstring
== Qnil
7206 && it
->bidi_it
.string
.s
== NULL
));
7208 /* With bidi reordering, the character to display might not be the
7209 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7210 we were reseat()ed to a new buffer position, which is potentially
7211 a different paragraph. */
7212 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7214 get_visually_first_element (it
);
7215 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7218 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7220 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7222 int overlay_strings_follow_p
;
7224 /* End of the game, except when overlay strings follow that
7225 haven't been returned yet. */
7226 if (it
->overlay_strings_at_end_processed_p
)
7227 overlay_strings_follow_p
= 0;
7230 it
->overlay_strings_at_end_processed_p
= 1;
7231 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7234 if (overlay_strings_follow_p
)
7235 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7239 it
->position
= it
->current
.pos
;
7243 else if (!(!it
->bidi_p
7244 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7245 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7247 /* With bidi non-linear iteration, we could find ourselves
7248 far beyond the last computed stop_charpos, with several
7249 other stop positions in between that we missed. Scan
7250 them all now, in buffer's logical order, until we find
7251 and handle the last stop_charpos that precedes our
7252 current position. */
7253 handle_stop_backwards (it
, it
->stop_charpos
);
7254 return GET_NEXT_DISPLAY_ELEMENT (it
);
7260 /* Take note of the stop position we just moved across,
7261 for when we will move back across it. */
7262 it
->prev_stop
= it
->stop_charpos
;
7263 /* If we are at base paragraph embedding level, take
7264 note of the last stop position seen at this
7266 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7267 it
->base_level_stop
= it
->stop_charpos
;
7270 return GET_NEXT_DISPLAY_ELEMENT (it
);
7274 /* If we are before prev_stop, we may have overstepped on
7275 our way backwards a stop_pos, and if so, we need to
7276 handle that stop_pos. */
7277 && IT_CHARPOS (*it
) < it
->prev_stop
7278 /* We can sometimes back up for reasons that have nothing
7279 to do with bidi reordering. E.g., compositions. The
7280 code below is only needed when we are above the base
7281 embedding level, so test for that explicitly. */
7282 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7284 /* If we lost track of base_level_stop, we have no better place
7285 for handle_stop_backwards to start from than BEGV. This
7286 happens, e.g., when we were reseated to the previous
7287 screenful of text by vertical-motion. */
7288 if (it
->base_level_stop
<= 0
7289 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7290 it
->base_level_stop
= BEGV
;
7291 handle_stop_backwards (it
, it
->base_level_stop
);
7292 return GET_NEXT_DISPLAY_ELEMENT (it
);
7296 /* No face changes, overlays etc. in sight, so just return a
7297 character from current_buffer. */
7301 /* Maybe run the redisplay end trigger hook. Performance note:
7302 This doesn't seem to cost measurable time. */
7303 if (it
->redisplay_end_trigger_charpos
7305 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7306 run_redisplay_end_trigger_hook (it
);
7308 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7309 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7311 && next_element_from_composition (it
))
7316 /* Get the next character, maybe multibyte. */
7317 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7318 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7319 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7321 it
->c
= *p
, it
->len
= 1;
7323 /* Record what we have and where it came from. */
7324 it
->what
= IT_CHARACTER
;
7325 it
->object
= it
->w
->buffer
;
7326 it
->position
= it
->current
.pos
;
7328 /* Normally we return the character found above, except when we
7329 really want to return an ellipsis for selective display. */
7334 /* A value of selective > 0 means hide lines indented more
7335 than that number of columns. */
7336 if (it
->selective
> 0
7337 && IT_CHARPOS (*it
) + 1 < ZV
7338 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7339 IT_BYTEPOS (*it
) + 1,
7340 (double) it
->selective
)) /* iftc */
7342 success_p
= next_element_from_ellipsis (it
);
7343 it
->dpvec_char_len
= -1;
7346 else if (it
->c
== '\r' && it
->selective
== -1)
7348 /* A value of selective == -1 means that everything from the
7349 CR to the end of the line is invisible, with maybe an
7350 ellipsis displayed for it. */
7351 success_p
= next_element_from_ellipsis (it
);
7352 it
->dpvec_char_len
= -1;
7357 /* Value is zero if end of buffer reached. */
7358 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7363 /* Run the redisplay end trigger hook for IT. */
7366 run_redisplay_end_trigger_hook (struct it
*it
)
7368 Lisp_Object args
[3];
7370 /* IT->glyph_row should be non-null, i.e. we should be actually
7371 displaying something, or otherwise we should not run the hook. */
7372 xassert (it
->glyph_row
);
7374 /* Set up hook arguments. */
7375 args
[0] = Qredisplay_end_trigger_functions
;
7376 args
[1] = it
->window
;
7377 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7378 it
->redisplay_end_trigger_charpos
= 0;
7380 /* Since we are *trying* to run these functions, don't try to run
7381 them again, even if they get an error. */
7382 it
->w
->redisplay_end_trigger
= Qnil
;
7383 Frun_hook_with_args (3, args
);
7385 /* Notice if it changed the face of the character we are on. */
7386 handle_face_prop (it
);
7390 /* Deliver a composition display element. Unlike the other
7391 next_element_from_XXX, this function is not registered in the array
7392 get_next_element[]. It is called from next_element_from_buffer and
7393 next_element_from_string when necessary. */
7396 next_element_from_composition (struct it
*it
)
7398 it
->what
= IT_COMPOSITION
;
7399 it
->len
= it
->cmp_it
.nbytes
;
7400 if (STRINGP (it
->string
))
7404 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7405 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7408 it
->position
= it
->current
.string_pos
;
7409 it
->object
= it
->string
;
7410 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
7411 IT_STRING_BYTEPOS (*it
), it
->string
);
7417 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7418 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7421 if (it
->bidi_it
.new_paragraph
)
7422 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7423 /* Resync the bidi iterator with IT's new position.
7424 FIXME: this doesn't support bidirectional text. */
7425 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
7426 bidi_move_to_visually_next (&it
->bidi_it
);
7430 it
->position
= it
->current
.pos
;
7431 it
->object
= it
->w
->buffer
;
7432 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
7433 IT_BYTEPOS (*it
), Qnil
);
7440 /***********************************************************************
7441 Moving an iterator without producing glyphs
7442 ***********************************************************************/
7444 /* Check if iterator is at a position corresponding to a valid buffer
7445 position after some move_it_ call. */
7447 #define IT_POS_VALID_AFTER_MOVE_P(it) \
7448 ((it)->method == GET_FROM_STRING \
7449 ? IT_STRING_CHARPOS (*it) == 0 \
7453 /* Move iterator IT to a specified buffer or X position within one
7454 line on the display without producing glyphs.
7456 OP should be a bit mask including some or all of these bits:
7457 MOVE_TO_X: Stop upon reaching x-position TO_X.
7458 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
7459 Regardless of OP's value, stop upon reaching the end of the display line.
7461 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
7462 This means, in particular, that TO_X includes window's horizontal
7465 The return value has several possible values that
7466 say what condition caused the scan to stop:
7468 MOVE_POS_MATCH_OR_ZV
7469 - when TO_POS or ZV was reached.
7472 -when TO_X was reached before TO_POS or ZV were reached.
7475 - when we reached the end of the display area and the line must
7479 - when we reached the end of the display area and the line is
7483 - when we stopped at a line end, i.e. a newline or a CR and selective
7486 static enum move_it_result
7487 move_it_in_display_line_to (struct it
*it
,
7488 EMACS_INT to_charpos
, int to_x
,
7489 enum move_operation_enum op
)
7491 enum move_it_result result
= MOVE_UNDEFINED
;
7492 struct glyph_row
*saved_glyph_row
;
7493 struct it wrap_it
, atpos_it
, atx_it
;
7495 enum it_method prev_method
= it
->method
;
7496 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
7498 /* Don't produce glyphs in produce_glyphs. */
7499 saved_glyph_row
= it
->glyph_row
;
7500 it
->glyph_row
= NULL
;
7502 /* Use wrap_it to save a copy of IT wherever a word wrap could
7503 occur. Use atpos_it to save a copy of IT at the desired buffer
7504 position, if found, so that we can scan ahead and check if the
7505 word later overshoots the window edge. Use atx_it similarly, for
7511 #define BUFFER_POS_REACHED_P() \
7512 ((op & MOVE_TO_POS) != 0 \
7513 && BUFFERP (it->object) \
7514 && (IT_CHARPOS (*it) == to_charpos \
7515 || (!it->bidi_p && IT_CHARPOS (*it) > to_charpos)) \
7516 && (it->method == GET_FROM_BUFFER \
7517 || (it->method == GET_FROM_DISPLAY_VECTOR \
7518 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
7520 /* If there's a line-/wrap-prefix, handle it. */
7521 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
7522 && it
->current_y
< it
->last_visible_y
)
7523 handle_line_prefix (it
);
7525 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7526 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7530 int x
, i
, ascent
= 0, descent
= 0;
7532 /* Utility macro to reset an iterator with x, ascent, and descent. */
7533 #define IT_RESET_X_ASCENT_DESCENT(IT) \
7534 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
7535 (IT)->max_descent = descent)
7537 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
7539 if ((op
& MOVE_TO_POS
) != 0
7540 && BUFFERP (it
->object
)
7541 && it
->method
== GET_FROM_BUFFER
7542 && ((!it
->bidi_p
&& IT_CHARPOS (*it
) > to_charpos
)
7544 && (prev_method
== GET_FROM_IMAGE
7545 || prev_method
== GET_FROM_STRETCH
)
7546 /* Passed TO_CHARPOS from left to right. */
7547 && ((prev_pos
< to_charpos
7548 && IT_CHARPOS (*it
) > to_charpos
)
7549 /* Passed TO_CHARPOS from right to left. */
7550 || (prev_pos
> to_charpos
7551 && IT_CHARPOS (*it
) < to_charpos
)))))
7553 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7555 result
= MOVE_POS_MATCH_OR_ZV
;
7558 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7559 /* If wrap_it is valid, the current position might be in a
7560 word that is wrapped. So, save the iterator in
7561 atpos_it and continue to see if wrapping happens. */
7565 prev_method
= it
->method
;
7566 if (it
->method
== GET_FROM_BUFFER
)
7567 prev_pos
= IT_CHARPOS (*it
);
7568 /* Stop when ZV reached.
7569 We used to stop here when TO_CHARPOS reached as well, but that is
7570 too soon if this glyph does not fit on this line. So we handle it
7571 explicitly below. */
7572 if (!get_next_display_element (it
))
7574 result
= MOVE_POS_MATCH_OR_ZV
;
7578 if (it
->line_wrap
== TRUNCATE
)
7580 if (BUFFER_POS_REACHED_P ())
7582 result
= MOVE_POS_MATCH_OR_ZV
;
7588 if (it
->line_wrap
== WORD_WRAP
)
7590 if (IT_DISPLAYING_WHITESPACE (it
))
7594 /* We have reached a glyph that follows one or more
7595 whitespace characters. If the position is
7596 already found, we are done. */
7597 if (atpos_it
.sp
>= 0)
7600 result
= MOVE_POS_MATCH_OR_ZV
;
7606 result
= MOVE_X_REACHED
;
7609 /* Otherwise, we can wrap here. */
7616 /* Remember the line height for the current line, in case
7617 the next element doesn't fit on the line. */
7618 ascent
= it
->max_ascent
;
7619 descent
= it
->max_descent
;
7621 /* The call to produce_glyphs will get the metrics of the
7622 display element IT is loaded with. Record the x-position
7623 before this display element, in case it doesn't fit on the
7627 PRODUCE_GLYPHS (it
);
7629 if (it
->area
!= TEXT_AREA
)
7631 set_iterator_to_next (it
, 1);
7632 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7633 SET_TEXT_POS (this_line_min_pos
,
7634 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7638 /* The number of glyphs we get back in IT->nglyphs will normally
7639 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7640 character on a terminal frame, or (iii) a line end. For the
7641 second case, IT->nglyphs - 1 padding glyphs will be present.
7642 (On X frames, there is only one glyph produced for a
7643 composite character.)
7645 The behavior implemented below means, for continuation lines,
7646 that as many spaces of a TAB as fit on the current line are
7647 displayed there. For terminal frames, as many glyphs of a
7648 multi-glyph character are displayed in the current line, too.
7649 This is what the old redisplay code did, and we keep it that
7650 way. Under X, the whole shape of a complex character must
7651 fit on the line or it will be completely displayed in the
7654 Note that both for tabs and padding glyphs, all glyphs have
7658 /* More than one glyph or glyph doesn't fit on line. All
7659 glyphs have the same width. */
7660 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7662 int x_before_this_char
= x
;
7663 int hpos_before_this_char
= it
->hpos
;
7665 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7667 new_x
= x
+ single_glyph_width
;
7669 /* We want to leave anything reaching TO_X to the caller. */
7670 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7672 if (BUFFER_POS_REACHED_P ())
7674 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7675 goto buffer_pos_reached
;
7676 if (atpos_it
.sp
< 0)
7679 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7684 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7687 result
= MOVE_X_REACHED
;
7693 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7698 if (/* Lines are continued. */
7699 it
->line_wrap
!= TRUNCATE
7700 && (/* And glyph doesn't fit on the line. */
7701 new_x
> it
->last_visible_x
7702 /* Or it fits exactly and we're on a window
7704 || (new_x
== it
->last_visible_x
7705 && FRAME_WINDOW_P (it
->f
))))
7707 if (/* IT->hpos == 0 means the very first glyph
7708 doesn't fit on the line, e.g. a wide image. */
7710 || (new_x
== it
->last_visible_x
7711 && FRAME_WINDOW_P (it
->f
)))
7714 it
->current_x
= new_x
;
7716 /* The character's last glyph just barely fits
7718 if (i
== it
->nglyphs
- 1)
7720 /* If this is the destination position,
7721 return a position *before* it in this row,
7722 now that we know it fits in this row. */
7723 if (BUFFER_POS_REACHED_P ())
7725 if (it
->line_wrap
!= WORD_WRAP
7728 it
->hpos
= hpos_before_this_char
;
7729 it
->current_x
= x_before_this_char
;
7730 result
= MOVE_POS_MATCH_OR_ZV
;
7733 if (it
->line_wrap
== WORD_WRAP
7737 atpos_it
.current_x
= x_before_this_char
;
7738 atpos_it
.hpos
= hpos_before_this_char
;
7742 set_iterator_to_next (it
, 1);
7743 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7744 SET_TEXT_POS (this_line_min_pos
,
7745 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7746 /* On graphical terminals, newlines may
7747 "overflow" into the fringe if
7748 overflow-newline-into-fringe is non-nil.
7749 On text-only terminals, newlines may
7750 overflow into the last glyph on the
7752 if (!FRAME_WINDOW_P (it
->f
)
7753 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7755 if (!get_next_display_element (it
))
7757 result
= MOVE_POS_MATCH_OR_ZV
;
7760 if (BUFFER_POS_REACHED_P ())
7762 if (ITERATOR_AT_END_OF_LINE_P (it
))
7763 result
= MOVE_POS_MATCH_OR_ZV
;
7765 result
= MOVE_LINE_CONTINUED
;
7768 if (ITERATOR_AT_END_OF_LINE_P (it
))
7770 result
= MOVE_NEWLINE_OR_CR
;
7777 IT_RESET_X_ASCENT_DESCENT (it
);
7779 if (wrap_it
.sp
>= 0)
7786 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7788 result
= MOVE_LINE_CONTINUED
;
7792 if (BUFFER_POS_REACHED_P ())
7794 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7795 goto buffer_pos_reached
;
7796 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7799 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7803 if (new_x
> it
->first_visible_x
)
7805 /* Glyph is visible. Increment number of glyphs that
7806 would be displayed. */
7811 if (result
!= MOVE_UNDEFINED
)
7814 else if (BUFFER_POS_REACHED_P ())
7817 IT_RESET_X_ASCENT_DESCENT (it
);
7818 result
= MOVE_POS_MATCH_OR_ZV
;
7821 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7823 /* Stop when TO_X specified and reached. This check is
7824 necessary here because of lines consisting of a line end,
7825 only. The line end will not produce any glyphs and we
7826 would never get MOVE_X_REACHED. */
7827 xassert (it
->nglyphs
== 0);
7828 result
= MOVE_X_REACHED
;
7832 /* Is this a line end? If yes, we're done. */
7833 if (ITERATOR_AT_END_OF_LINE_P (it
))
7835 result
= MOVE_NEWLINE_OR_CR
;
7839 if (it
->method
== GET_FROM_BUFFER
)
7840 prev_pos
= IT_CHARPOS (*it
);
7841 /* The current display element has been consumed. Advance
7843 set_iterator_to_next (it
, 1);
7844 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7845 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7847 /* Stop if lines are truncated and IT's current x-position is
7848 past the right edge of the window now. */
7849 if (it
->line_wrap
== TRUNCATE
7850 && it
->current_x
>= it
->last_visible_x
)
7852 if (!FRAME_WINDOW_P (it
->f
)
7853 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7855 if (!get_next_display_element (it
)
7856 || BUFFER_POS_REACHED_P ())
7858 result
= MOVE_POS_MATCH_OR_ZV
;
7861 if (ITERATOR_AT_END_OF_LINE_P (it
))
7863 result
= MOVE_NEWLINE_OR_CR
;
7867 result
= MOVE_LINE_TRUNCATED
;
7870 #undef IT_RESET_X_ASCENT_DESCENT
7873 #undef BUFFER_POS_REACHED_P
7875 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7876 restore the saved iterator. */
7877 if (atpos_it
.sp
>= 0)
7879 else if (atx_it
.sp
>= 0)
7884 /* Restore the iterator settings altered at the beginning of this
7886 it
->glyph_row
= saved_glyph_row
;
7890 /* For external use. */
7892 move_it_in_display_line (struct it
*it
,
7893 EMACS_INT to_charpos
, int to_x
,
7894 enum move_operation_enum op
)
7896 if (it
->line_wrap
== WORD_WRAP
7897 && (op
& MOVE_TO_X
))
7899 struct it save_it
= *it
;
7900 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7901 /* When word-wrap is on, TO_X may lie past the end
7902 of a wrapped line. Then it->current is the
7903 character on the next line, so backtrack to the
7904 space before the wrap point. */
7905 if (skip
== MOVE_LINE_CONTINUED
)
7907 int prev_x
= max (it
->current_x
- 1, 0);
7909 move_it_in_display_line_to
7910 (it
, -1, prev_x
, MOVE_TO_X
);
7914 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7918 /* Move IT forward until it satisfies one or more of the criteria in
7919 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7921 OP is a bit-mask that specifies where to stop, and in particular,
7922 which of those four position arguments makes a difference. See the
7923 description of enum move_operation_enum.
7925 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7926 screen line, this function will set IT to the next position >
7930 move_it_to (struct it
*it
, EMACS_INT to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
7932 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7933 int line_height
, line_start_x
= 0, reached
= 0;
7937 if (op
& MOVE_TO_VPOS
)
7939 /* If no TO_CHARPOS and no TO_X specified, stop at the
7940 start of the line TO_VPOS. */
7941 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7943 if (it
->vpos
== to_vpos
)
7949 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7953 /* TO_VPOS >= 0 means stop at TO_X in the line at
7954 TO_VPOS, or at TO_POS, whichever comes first. */
7955 if (it
->vpos
== to_vpos
)
7961 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7963 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7968 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7970 /* We have reached TO_X but not in the line we want. */
7971 skip
= move_it_in_display_line_to (it
, to_charpos
,
7973 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7981 else if (op
& MOVE_TO_Y
)
7983 struct it it_backup
;
7985 if (it
->line_wrap
== WORD_WRAP
)
7988 /* TO_Y specified means stop at TO_X in the line containing
7989 TO_Y---or at TO_CHARPOS if this is reached first. The
7990 problem is that we can't really tell whether the line
7991 contains TO_Y before we have completely scanned it, and
7992 this may skip past TO_X. What we do is to first scan to
7995 If TO_X is not specified, use a TO_X of zero. The reason
7996 is to make the outcome of this function more predictable.
7997 If we didn't use TO_X == 0, we would stop at the end of
7998 the line which is probably not what a caller would expect
8000 skip
= move_it_in_display_line_to
8001 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8002 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8004 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8005 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8007 else if (skip
== MOVE_X_REACHED
)
8009 /* If TO_X was reached, we want to know whether TO_Y is
8010 in the line. We know this is the case if the already
8011 scanned glyphs make the line tall enough. Otherwise,
8012 we must check by scanning the rest of the line. */
8013 line_height
= it
->max_ascent
+ it
->max_descent
;
8014 if (to_y
>= it
->current_y
8015 && to_y
< it
->current_y
+ line_height
)
8021 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8022 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8024 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8025 line_height
= it
->max_ascent
+ it
->max_descent
;
8026 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8028 if (to_y
>= it
->current_y
8029 && to_y
< it
->current_y
+ line_height
)
8031 /* If TO_Y is in this line and TO_X was reached
8032 above, we scanned too far. We have to restore
8033 IT's settings to the ones before skipping. */
8040 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8046 /* Check whether TO_Y is in this line. */
8047 line_height
= it
->max_ascent
+ it
->max_descent
;
8048 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8050 if (to_y
>= it
->current_y
8051 && to_y
< it
->current_y
+ line_height
)
8053 /* When word-wrap is on, TO_X may lie past the end
8054 of a wrapped line. Then it->current is the
8055 character on the next line, so backtrack to the
8056 space before the wrap point. */
8057 if (skip
== MOVE_LINE_CONTINUED
8058 && it
->line_wrap
== WORD_WRAP
)
8060 int prev_x
= max (it
->current_x
- 1, 0);
8062 skip
= move_it_in_display_line_to
8063 (it
, -1, prev_x
, MOVE_TO_X
);
8072 else if (BUFFERP (it
->object
)
8073 && (it
->method
== GET_FROM_BUFFER
8074 || it
->method
== GET_FROM_STRETCH
)
8075 && IT_CHARPOS (*it
) >= to_charpos
)
8076 skip
= MOVE_POS_MATCH_OR_ZV
;
8078 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8082 case MOVE_POS_MATCH_OR_ZV
:
8086 case MOVE_NEWLINE_OR_CR
:
8087 set_iterator_to_next (it
, 1);
8088 it
->continuation_lines_width
= 0;
8091 case MOVE_LINE_TRUNCATED
:
8092 it
->continuation_lines_width
= 0;
8093 reseat_at_next_visible_line_start (it
, 0);
8094 if ((op
& MOVE_TO_POS
) != 0
8095 && IT_CHARPOS (*it
) > to_charpos
)
8102 case MOVE_LINE_CONTINUED
:
8103 /* For continued lines ending in a tab, some of the glyphs
8104 associated with the tab are displayed on the current
8105 line. Since it->current_x does not include these glyphs,
8106 we use it->last_visible_x instead. */
8109 it
->continuation_lines_width
+= it
->last_visible_x
;
8110 /* When moving by vpos, ensure that the iterator really
8111 advances to the next line (bug#847, bug#969). Fixme:
8112 do we need to do this in other circumstances? */
8113 if (it
->current_x
!= it
->last_visible_x
8114 && (op
& MOVE_TO_VPOS
)
8115 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8117 line_start_x
= it
->current_x
+ it
->pixel_width
8118 - it
->last_visible_x
;
8119 set_iterator_to_next (it
, 0);
8123 it
->continuation_lines_width
+= it
->current_x
;
8130 /* Reset/increment for the next run. */
8131 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8132 it
->current_x
= line_start_x
;
8135 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8137 last_height
= it
->max_ascent
+ it
->max_descent
;
8138 last_max_ascent
= it
->max_ascent
;
8139 it
->max_ascent
= it
->max_descent
= 0;
8144 /* On text terminals, we may stop at the end of a line in the middle
8145 of a multi-character glyph. If the glyph itself is continued,
8146 i.e. it is actually displayed on the next line, don't treat this
8147 stopping point as valid; move to the next line instead (unless
8148 that brings us offscreen). */
8149 if (!FRAME_WINDOW_P (it
->f
)
8151 && IT_CHARPOS (*it
) == to_charpos
8152 && it
->what
== IT_CHARACTER
8154 && it
->line_wrap
== WINDOW_WRAP
8155 && it
->current_x
== it
->last_visible_x
- 1
8158 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8160 it
->continuation_lines_width
+= it
->current_x
;
8161 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8162 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8164 last_height
= it
->max_ascent
+ it
->max_descent
;
8165 last_max_ascent
= it
->max_ascent
;
8168 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8172 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8174 If DY > 0, move IT backward at least that many pixels. DY = 0
8175 means move IT backward to the preceding line start or BEGV. This
8176 function may move over more than DY pixels if IT->current_y - DY
8177 ends up in the middle of a line; in this case IT->current_y will be
8178 set to the top of the line moved to. */
8181 move_it_vertically_backward (struct it
*it
, int dy
)
8185 EMACS_INT start_pos
;
8190 start_pos
= IT_CHARPOS (*it
);
8192 /* Estimate how many newlines we must move back. */
8193 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8195 /* Set the iterator's position that many lines back. */
8196 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8197 back_to_previous_visible_line_start (it
);
8199 /* Reseat the iterator here. When moving backward, we don't want
8200 reseat to skip forward over invisible text, set up the iterator
8201 to deliver from overlay strings at the new position etc. So,
8202 use reseat_1 here. */
8203 reseat_1 (it
, it
->current
.pos
, 1);
8205 /* We are now surely at a line start. */
8206 it
->current_x
= it
->hpos
= 0;
8207 it
->continuation_lines_width
= 0;
8209 /* Move forward and see what y-distance we moved. First move to the
8210 start of the next line so that we get its height. We need this
8211 height to be able to tell whether we reached the specified
8214 it2
.max_ascent
= it2
.max_descent
= 0;
8217 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8218 MOVE_TO_POS
| MOVE_TO_VPOS
);
8220 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
8221 xassert (IT_CHARPOS (*it
) >= BEGV
);
8224 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8225 xassert (IT_CHARPOS (*it
) >= BEGV
);
8226 /* H is the actual vertical distance from the position in *IT
8227 and the starting position. */
8228 h
= it2
.current_y
- it
->current_y
;
8229 /* NLINES is the distance in number of lines. */
8230 nlines
= it2
.vpos
- it
->vpos
;
8232 /* Correct IT's y and vpos position
8233 so that they are relative to the starting point. */
8239 /* DY == 0 means move to the start of the screen line. The
8240 value of nlines is > 0 if continuation lines were involved. */
8242 move_it_by_lines (it
, nlines
);
8246 /* The y-position we try to reach, relative to *IT.
8247 Note that H has been subtracted in front of the if-statement. */
8248 int target_y
= it
->current_y
+ h
- dy
;
8249 int y0
= it3
.current_y
;
8250 int y1
= line_bottom_y (&it3
);
8251 int line_height
= y1
- y0
;
8253 /* If we did not reach target_y, try to move further backward if
8254 we can. If we moved too far backward, try to move forward. */
8255 if (target_y
< it
->current_y
8256 /* This is heuristic. In a window that's 3 lines high, with
8257 a line height of 13 pixels each, recentering with point
8258 on the bottom line will try to move -39/2 = 19 pixels
8259 backward. Try to avoid moving into the first line. */
8260 && (it
->current_y
- target_y
8261 > min (window_box_height (it
->w
), line_height
* 2 / 3))
8262 && IT_CHARPOS (*it
) > BEGV
)
8264 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
8265 target_y
- it
->current_y
));
8266 dy
= it
->current_y
- target_y
;
8267 goto move_further_back
;
8269 else if (target_y
>= it
->current_y
+ line_height
8270 && IT_CHARPOS (*it
) < ZV
)
8272 /* Should move forward by at least one line, maybe more.
8274 Note: Calling move_it_by_lines can be expensive on
8275 terminal frames, where compute_motion is used (via
8276 vmotion) to do the job, when there are very long lines
8277 and truncate-lines is nil. That's the reason for
8278 treating terminal frames specially here. */
8280 if (!FRAME_WINDOW_P (it
->f
))
8281 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
8286 move_it_by_lines (it
, 1);
8288 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
8295 /* Move IT by a specified amount of pixel lines DY. DY negative means
8296 move backwards. DY = 0 means move to start of screen line. At the
8297 end, IT will be on the start of a screen line. */
8300 move_it_vertically (struct it
*it
, int dy
)
8303 move_it_vertically_backward (it
, -dy
);
8306 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
8307 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
8308 MOVE_TO_POS
| MOVE_TO_Y
);
8309 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
8311 /* If buffer ends in ZV without a newline, move to the start of
8312 the line to satisfy the post-condition. */
8313 if (IT_CHARPOS (*it
) == ZV
8315 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8316 move_it_by_lines (it
, 0);
8321 /* Move iterator IT past the end of the text line it is in. */
8324 move_it_past_eol (struct it
*it
)
8326 enum move_it_result rc
;
8328 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
8329 if (rc
== MOVE_NEWLINE_OR_CR
)
8330 set_iterator_to_next (it
, 0);
8334 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
8335 negative means move up. DVPOS == 0 means move to the start of the
8338 Optimization idea: If we would know that IT->f doesn't use
8339 a face with proportional font, we could be faster for
8340 truncate-lines nil. */
8343 move_it_by_lines (struct it
*it
, int dvpos
)
8346 /* The commented-out optimization uses vmotion on terminals. This
8347 gives bad results, because elements like it->what, on which
8348 callers such as pos_visible_p rely, aren't updated. */
8349 /* struct position pos;
8350 if (!FRAME_WINDOW_P (it->f))
8352 struct text_pos textpos;
8354 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
8355 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
8356 reseat (it, textpos, 1);
8357 it->vpos += pos.vpos;
8358 it->current_y += pos.vpos;
8364 /* DVPOS == 0 means move to the start of the screen line. */
8365 move_it_vertically_backward (it
, 0);
8366 xassert (it
->current_x
== 0 && it
->hpos
== 0);
8367 /* Let next call to line_bottom_y calculate real line height */
8372 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
8373 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
8374 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
8379 EMACS_INT start_charpos
, i
;
8381 /* Start at the beginning of the screen line containing IT's
8382 position. This may actually move vertically backwards,
8383 in case of overlays, so adjust dvpos accordingly. */
8385 move_it_vertically_backward (it
, 0);
8388 /* Go back -DVPOS visible lines and reseat the iterator there. */
8389 start_charpos
= IT_CHARPOS (*it
);
8390 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
8391 back_to_previous_visible_line_start (it
);
8392 reseat (it
, it
->current
.pos
, 1);
8394 /* Move further back if we end up in a string or an image. */
8395 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
8397 /* First try to move to start of display line. */
8399 move_it_vertically_backward (it
, 0);
8401 if (IT_POS_VALID_AFTER_MOVE_P (it
))
8403 /* If start of line is still in string or image,
8404 move further back. */
8405 back_to_previous_visible_line_start (it
);
8406 reseat (it
, it
->current
.pos
, 1);
8410 it
->current_x
= it
->hpos
= 0;
8412 /* Above call may have moved too far if continuation lines
8413 are involved. Scan forward and see if it did. */
8415 it2
.vpos
= it2
.current_y
= 0;
8416 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
8417 it
->vpos
-= it2
.vpos
;
8418 it
->current_y
-= it2
.current_y
;
8419 it
->current_x
= it
->hpos
= 0;
8421 /* If we moved too far back, move IT some lines forward. */
8422 if (it2
.vpos
> -dvpos
)
8424 int delta
= it2
.vpos
+ dvpos
;
8426 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
8427 /* Move back again if we got too far ahead. */
8428 if (IT_CHARPOS (*it
) >= start_charpos
)
8434 /* Return 1 if IT points into the middle of a display vector. */
8437 in_display_vector_p (struct it
*it
)
8439 return (it
->method
== GET_FROM_DISPLAY_VECTOR
8440 && it
->current
.dpvec_index
> 0
8441 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
8445 /***********************************************************************
8447 ***********************************************************************/
8450 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
8454 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
8456 Lisp_Object args
[3];
8457 Lisp_Object msg
, fmt
;
8460 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
8463 /* Do nothing if called asynchronously. Inserting text into
8464 a buffer may call after-change-functions and alike and
8465 that would means running Lisp asynchronously. */
8466 if (handling_signal
)
8470 GCPRO4 (fmt
, msg
, arg1
, arg2
);
8472 args
[0] = fmt
= build_string (format
);
8475 msg
= Fformat (3, args
);
8477 len
= SBYTES (msg
) + 1;
8478 SAFE_ALLOCA (buffer
, char *, len
);
8479 memcpy (buffer
, SDATA (msg
), len
);
8481 message_dolog (buffer
, len
- 1, 1, 0);
8488 /* Output a newline in the *Messages* buffer if "needs" one. */
8491 message_log_maybe_newline (void)
8493 if (message_log_need_newline
)
8494 message_dolog ("", 0, 1, 0);
8498 /* Add a string M of length NBYTES to the message log, optionally
8499 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
8500 nonzero, means interpret the contents of M as multibyte. This
8501 function calls low-level routines in order to bypass text property
8502 hooks, etc. which might not be safe to run.
8504 This may GC (insert may run before/after change hooks),
8505 so the buffer M must NOT point to a Lisp string. */
8508 message_dolog (const char *m
, EMACS_INT nbytes
, int nlflag
, int multibyte
)
8510 const unsigned char *msg
= (const unsigned char *) m
;
8512 if (!NILP (Vmemory_full
))
8515 if (!NILP (Vmessage_log_max
))
8517 struct buffer
*oldbuf
;
8518 Lisp_Object oldpoint
, oldbegv
, oldzv
;
8519 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
8520 EMACS_INT point_at_end
= 0;
8521 EMACS_INT zv_at_end
= 0;
8522 Lisp_Object old_deactivate_mark
, tem
;
8523 struct gcpro gcpro1
;
8525 old_deactivate_mark
= Vdeactivate_mark
;
8526 oldbuf
= current_buffer
;
8527 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
8528 BVAR (current_buffer
, undo_list
) = Qt
;
8530 oldpoint
= message_dolog_marker1
;
8531 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
8532 oldbegv
= message_dolog_marker2
;
8533 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
8534 oldzv
= message_dolog_marker3
;
8535 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
8536 GCPRO1 (old_deactivate_mark
);
8544 BEGV_BYTE
= BEG_BYTE
;
8547 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8549 /* Insert the string--maybe converting multibyte to single byte
8550 or vice versa, so that all the text fits the buffer. */
8552 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8558 /* Convert a multibyte string to single-byte
8559 for the *Message* buffer. */
8560 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
8562 c
= string_char_and_length (msg
+ i
, &char_bytes
);
8563 work
[0] = (ASCII_CHAR_P (c
)
8565 : multibyte_char_to_unibyte (c
));
8566 insert_1_both (work
, 1, 1, 1, 0, 0);
8569 else if (! multibyte
8570 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8574 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8575 /* Convert a single-byte string to multibyte
8576 for the *Message* buffer. */
8577 for (i
= 0; i
< nbytes
; i
++)
8580 MAKE_CHAR_MULTIBYTE (c
);
8581 char_bytes
= CHAR_STRING (c
, str
);
8582 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
8586 insert_1 (m
, nbytes
, 1, 0, 0);
8590 EMACS_INT this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
8591 unsigned long int dups
;
8592 insert_1 ("\n", 1, 1, 0, 0);
8594 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8596 this_bol_byte
= PT_BYTE
;
8598 /* See if this line duplicates the previous one.
8599 If so, combine duplicates. */
8602 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8604 prev_bol_byte
= PT_BYTE
;
8606 dups
= message_log_check_duplicate (prev_bol_byte
,
8610 del_range_both (prev_bol
, prev_bol_byte
,
8611 this_bol
, this_bol_byte
, 0);
8617 /* If you change this format, don't forget to also
8618 change message_log_check_duplicate. */
8619 sprintf (dupstr
, " [%lu times]", dups
);
8620 duplen
= strlen (dupstr
);
8621 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8622 insert_1 (dupstr
, duplen
, 1, 0, 1);
8627 /* If we have more than the desired maximum number of lines
8628 in the *Messages* buffer now, delete the oldest ones.
8629 This is safe because we don't have undo in this buffer. */
8631 if (NATNUMP (Vmessage_log_max
))
8633 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8634 -XFASTINT (Vmessage_log_max
) - 1, 0);
8635 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8638 BEGV
= XMARKER (oldbegv
)->charpos
;
8639 BEGV_BYTE
= marker_byte_position (oldbegv
);
8648 ZV
= XMARKER (oldzv
)->charpos
;
8649 ZV_BYTE
= marker_byte_position (oldzv
);
8653 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8655 /* We can't do Fgoto_char (oldpoint) because it will run some
8657 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8658 XMARKER (oldpoint
)->bytepos
);
8661 unchain_marker (XMARKER (oldpoint
));
8662 unchain_marker (XMARKER (oldbegv
));
8663 unchain_marker (XMARKER (oldzv
));
8665 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8666 set_buffer_internal (oldbuf
);
8668 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8669 message_log_need_newline
= !nlflag
;
8670 Vdeactivate_mark
= old_deactivate_mark
;
8675 /* We are at the end of the buffer after just having inserted a newline.
8676 (Note: We depend on the fact we won't be crossing the gap.)
8677 Check to see if the most recent message looks a lot like the previous one.
8678 Return 0 if different, 1 if the new one should just replace it, or a
8679 value N > 1 if we should also append " [N times]". */
8681 static unsigned long int
8682 message_log_check_duplicate (EMACS_INT prev_bol_byte
, EMACS_INT this_bol_byte
)
8685 EMACS_INT len
= Z_BYTE
- 1 - this_bol_byte
;
8687 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8688 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8690 for (i
= 0; i
< len
; i
++)
8692 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8700 if (*p1
++ == ' ' && *p1
++ == '[')
8703 unsigned long int n
= strtoul ((char *) p1
, &pend
, 10);
8704 if (strncmp (pend
, " times]\n", 8) == 0)
8711 /* Display an echo area message M with a specified length of NBYTES
8712 bytes. The string may include null characters. If M is 0, clear
8713 out any existing message, and let the mini-buffer text show
8716 This may GC, so the buffer M must NOT point to a Lisp string. */
8719 message2 (const char *m
, EMACS_INT nbytes
, int multibyte
)
8721 /* First flush out any partial line written with print. */
8722 message_log_maybe_newline ();
8724 message_dolog (m
, nbytes
, 1, multibyte
);
8725 message2_nolog (m
, nbytes
, multibyte
);
8729 /* The non-logging counterpart of message2. */
8732 message2_nolog (const char *m
, EMACS_INT nbytes
, int multibyte
)
8734 struct frame
*sf
= SELECTED_FRAME ();
8735 message_enable_multibyte
= multibyte
;
8737 if (FRAME_INITIAL_P (sf
))
8739 if (noninteractive_need_newline
)
8740 putc ('\n', stderr
);
8741 noninteractive_need_newline
= 0;
8743 fwrite (m
, nbytes
, 1, stderr
);
8744 if (cursor_in_echo_area
== 0)
8745 fprintf (stderr
, "\n");
8748 /* A null message buffer means that the frame hasn't really been
8749 initialized yet. Error messages get reported properly by
8750 cmd_error, so this must be just an informative message; toss it. */
8751 else if (INTERACTIVE
8752 && sf
->glyphs_initialized_p
8753 && FRAME_MESSAGE_BUF (sf
))
8755 Lisp_Object mini_window
;
8758 /* Get the frame containing the mini-buffer
8759 that the selected frame is using. */
8760 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8761 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8763 FRAME_SAMPLE_VISIBILITY (f
);
8764 if (FRAME_VISIBLE_P (sf
)
8765 && ! FRAME_VISIBLE_P (f
))
8766 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8770 set_message (m
, Qnil
, nbytes
, multibyte
);
8771 if (minibuffer_auto_raise
)
8772 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8775 clear_message (1, 1);
8777 do_pending_window_change (0);
8778 echo_area_display (1);
8779 do_pending_window_change (0);
8780 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8781 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8786 /* Display an echo area message M with a specified length of NBYTES
8787 bytes. The string may include null characters. If M is not a
8788 string, clear out any existing message, and let the mini-buffer
8791 This function cancels echoing. */
8794 message3 (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8796 struct gcpro gcpro1
;
8799 clear_message (1,1);
8802 /* First flush out any partial line written with print. */
8803 message_log_maybe_newline ();
8809 SAFE_ALLOCA (buffer
, char *, nbytes
);
8810 memcpy (buffer
, SDATA (m
), nbytes
);
8811 message_dolog (buffer
, nbytes
, 1, multibyte
);
8814 message3_nolog (m
, nbytes
, multibyte
);
8820 /* The non-logging version of message3.
8821 This does not cancel echoing, because it is used for echoing.
8822 Perhaps we need to make a separate function for echoing
8823 and make this cancel echoing. */
8826 message3_nolog (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8828 struct frame
*sf
= SELECTED_FRAME ();
8829 message_enable_multibyte
= multibyte
;
8831 if (FRAME_INITIAL_P (sf
))
8833 if (noninteractive_need_newline
)
8834 putc ('\n', stderr
);
8835 noninteractive_need_newline
= 0;
8837 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8838 if (cursor_in_echo_area
== 0)
8839 fprintf (stderr
, "\n");
8842 /* A null message buffer means that the frame hasn't really been
8843 initialized yet. Error messages get reported properly by
8844 cmd_error, so this must be just an informative message; toss it. */
8845 else if (INTERACTIVE
8846 && sf
->glyphs_initialized_p
8847 && FRAME_MESSAGE_BUF (sf
))
8849 Lisp_Object mini_window
;
8853 /* Get the frame containing the mini-buffer
8854 that the selected frame is using. */
8855 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8856 frame
= XWINDOW (mini_window
)->frame
;
8859 FRAME_SAMPLE_VISIBILITY (f
);
8860 if (FRAME_VISIBLE_P (sf
)
8861 && !FRAME_VISIBLE_P (f
))
8862 Fmake_frame_visible (frame
);
8864 if (STRINGP (m
) && SCHARS (m
) > 0)
8866 set_message (NULL
, m
, nbytes
, multibyte
);
8867 if (minibuffer_auto_raise
)
8868 Fraise_frame (frame
);
8869 /* Assume we are not echoing.
8870 (If we are, echo_now will override this.) */
8871 echo_message_buffer
= Qnil
;
8874 clear_message (1, 1);
8876 do_pending_window_change (0);
8877 echo_area_display (1);
8878 do_pending_window_change (0);
8879 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8880 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8885 /* Display a null-terminated echo area message M. If M is 0, clear
8886 out any existing message, and let the mini-buffer text show through.
8888 The buffer M must continue to exist until after the echo area gets
8889 cleared or some other message gets displayed there. Do not pass
8890 text that is stored in a Lisp string. Do not pass text in a buffer
8891 that was alloca'd. */
8894 message1 (const char *m
)
8896 message2 (m
, (m
? strlen (m
) : 0), 0);
8900 /* The non-logging counterpart of message1. */
8903 message1_nolog (const char *m
)
8905 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8908 /* Display a message M which contains a single %s
8909 which gets replaced with STRING. */
8912 message_with_string (const char *m
, Lisp_Object string
, int log
)
8914 CHECK_STRING (string
);
8920 if (noninteractive_need_newline
)
8921 putc ('\n', stderr
);
8922 noninteractive_need_newline
= 0;
8923 fprintf (stderr
, m
, SDATA (string
));
8924 if (!cursor_in_echo_area
)
8925 fprintf (stderr
, "\n");
8929 else if (INTERACTIVE
)
8931 /* The frame whose minibuffer we're going to display the message on.
8932 It may be larger than the selected frame, so we need
8933 to use its buffer, not the selected frame's buffer. */
8934 Lisp_Object mini_window
;
8935 struct frame
*f
, *sf
= SELECTED_FRAME ();
8937 /* Get the frame containing the minibuffer
8938 that the selected frame is using. */
8939 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8940 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8942 /* A null message buffer means that the frame hasn't really been
8943 initialized yet. Error messages get reported properly by
8944 cmd_error, so this must be just an informative message; toss it. */
8945 if (FRAME_MESSAGE_BUF (f
))
8947 Lisp_Object args
[2], msg
;
8948 struct gcpro gcpro1
, gcpro2
;
8950 args
[0] = build_string (m
);
8951 args
[1] = msg
= string
;
8952 GCPRO2 (args
[0], msg
);
8955 msg
= Fformat (2, args
);
8958 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8960 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8964 /* Print should start at the beginning of the message
8965 buffer next time. */
8966 message_buf_print
= 0;
8972 /* Dump an informative message to the minibuf. If M is 0, clear out
8973 any existing message, and let the mini-buffer text show through. */
8976 vmessage (const char *m
, va_list ap
)
8982 if (noninteractive_need_newline
)
8983 putc ('\n', stderr
);
8984 noninteractive_need_newline
= 0;
8985 vfprintf (stderr
, m
, ap
);
8986 if (cursor_in_echo_area
== 0)
8987 fprintf (stderr
, "\n");
8991 else if (INTERACTIVE
)
8993 /* The frame whose mini-buffer we're going to display the message
8994 on. It may be larger than the selected frame, so we need to
8995 use its buffer, not the selected frame's buffer. */
8996 Lisp_Object mini_window
;
8997 struct frame
*f
, *sf
= SELECTED_FRAME ();
8999 /* Get the frame containing the mini-buffer
9000 that the selected frame is using. */
9001 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9002 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9004 /* A null message buffer means that the frame hasn't really been
9005 initialized yet. Error messages get reported properly by
9006 cmd_error, so this must be just an informative message; toss
9008 if (FRAME_MESSAGE_BUF (f
))
9014 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9015 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9017 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
9022 /* Print should start at the beginning of the message
9023 buffer next time. */
9024 message_buf_print
= 0;
9030 message (const char *m
, ...)
9040 /* The non-logging version of message. */
9043 message_nolog (const char *m
, ...)
9045 Lisp_Object old_log_max
;
9048 old_log_max
= Vmessage_log_max
;
9049 Vmessage_log_max
= Qnil
;
9051 Vmessage_log_max
= old_log_max
;
9057 /* Display the current message in the current mini-buffer. This is
9058 only called from error handlers in process.c, and is not time
9062 update_echo_area (void)
9064 if (!NILP (echo_area_buffer
[0]))
9067 string
= Fcurrent_message ();
9068 message3 (string
, SBYTES (string
),
9069 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9074 /* Make sure echo area buffers in `echo_buffers' are live.
9075 If they aren't, make new ones. */
9078 ensure_echo_area_buffers (void)
9082 for (i
= 0; i
< 2; ++i
)
9083 if (!BUFFERP (echo_buffer
[i
])
9084 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
9087 Lisp_Object old_buffer
;
9090 old_buffer
= echo_buffer
[i
];
9091 sprintf (name
, " *Echo Area %d*", i
);
9092 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
9093 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
9094 /* to force word wrap in echo area -
9095 it was decided to postpone this*/
9096 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9098 for (j
= 0; j
< 2; ++j
)
9099 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9100 echo_area_buffer
[j
] = echo_buffer
[i
];
9105 /* Call FN with args A1..A4 with either the current or last displayed
9106 echo_area_buffer as current buffer.
9108 WHICH zero means use the current message buffer
9109 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9110 from echo_buffer[] and clear it.
9112 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9113 suitable buffer from echo_buffer[] and clear it.
9115 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9116 that the current message becomes the last displayed one, make
9117 choose a suitable buffer for echo_area_buffer[0], and clear it.
9119 Value is what FN returns. */
9122 with_echo_area_buffer (struct window
*w
, int which
,
9123 int (*fn
) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
9124 EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9127 int this_one
, the_other
, clear_buffer_p
, rc
;
9128 int count
= SPECPDL_INDEX ();
9130 /* If buffers aren't live, make new ones. */
9131 ensure_echo_area_buffers ();
9136 this_one
= 0, the_other
= 1;
9138 this_one
= 1, the_other
= 0;
9141 this_one
= 0, the_other
= 1;
9144 /* We need a fresh one in case the current echo buffer equals
9145 the one containing the last displayed echo area message. */
9146 if (!NILP (echo_area_buffer
[this_one
])
9147 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9148 echo_area_buffer
[this_one
] = Qnil
;
9151 /* Choose a suitable buffer from echo_buffer[] is we don't
9153 if (NILP (echo_area_buffer
[this_one
]))
9155 echo_area_buffer
[this_one
]
9156 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9157 ? echo_buffer
[the_other
]
9158 : echo_buffer
[this_one
]);
9162 buffer
= echo_area_buffer
[this_one
];
9164 /* Don't get confused by reusing the buffer used for echoing
9165 for a different purpose. */
9166 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9169 record_unwind_protect (unwind_with_echo_area_buffer
,
9170 with_echo_area_buffer_unwind_data (w
));
9172 /* Make the echo area buffer current. Note that for display
9173 purposes, it is not necessary that the displayed window's buffer
9174 == current_buffer, except for text property lookup. So, let's
9175 only set that buffer temporarily here without doing a full
9176 Fset_window_buffer. We must also change w->pointm, though,
9177 because otherwise an assertions in unshow_buffer fails, and Emacs
9179 set_buffer_internal_1 (XBUFFER (buffer
));
9183 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9186 BVAR (current_buffer
, undo_list
) = Qt
;
9187 BVAR (current_buffer
, read_only
) = Qnil
;
9188 specbind (Qinhibit_read_only
, Qt
);
9189 specbind (Qinhibit_modification_hooks
, Qt
);
9191 if (clear_buffer_p
&& Z
> BEG
)
9194 xassert (BEGV
>= BEG
);
9195 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9197 rc
= fn (a1
, a2
, a3
, a4
);
9199 xassert (BEGV
>= BEG
);
9200 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9202 unbind_to (count
, Qnil
);
9207 /* Save state that should be preserved around the call to the function
9208 FN called in with_echo_area_buffer. */
9211 with_echo_area_buffer_unwind_data (struct window
*w
)
9214 Lisp_Object vector
, tmp
;
9216 /* Reduce consing by keeping one vector in
9217 Vwith_echo_area_save_vector. */
9218 vector
= Vwith_echo_area_save_vector
;
9219 Vwith_echo_area_save_vector
= Qnil
;
9222 vector
= Fmake_vector (make_number (7), Qnil
);
9224 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9225 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9226 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
9230 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
9231 ASET (vector
, i
, w
->buffer
); ++i
;
9232 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
9233 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
9238 for (; i
< end
; ++i
)
9239 ASET (vector
, i
, Qnil
);
9242 xassert (i
== ASIZE (vector
));
9247 /* Restore global state from VECTOR which was created by
9248 with_echo_area_buffer_unwind_data. */
9251 unwind_with_echo_area_buffer (Lisp_Object vector
)
9253 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
9254 Vdeactivate_mark
= AREF (vector
, 1);
9255 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
9257 if (WINDOWP (AREF (vector
, 3)))
9260 Lisp_Object buffer
, charpos
, bytepos
;
9262 w
= XWINDOW (AREF (vector
, 3));
9263 buffer
= AREF (vector
, 4);
9264 charpos
= AREF (vector
, 5);
9265 bytepos
= AREF (vector
, 6);
9268 set_marker_both (w
->pointm
, buffer
,
9269 XFASTINT (charpos
), XFASTINT (bytepos
));
9272 Vwith_echo_area_save_vector
= vector
;
9277 /* Set up the echo area for use by print functions. MULTIBYTE_P
9278 non-zero means we will print multibyte. */
9281 setup_echo_area_for_printing (int multibyte_p
)
9283 /* If we can't find an echo area any more, exit. */
9284 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9287 ensure_echo_area_buffers ();
9289 if (!message_buf_print
)
9291 /* A message has been output since the last time we printed.
9292 Choose a fresh echo area buffer. */
9293 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9294 echo_area_buffer
[0] = echo_buffer
[1];
9296 echo_area_buffer
[0] = echo_buffer
[0];
9298 /* Switch to that buffer and clear it. */
9299 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9300 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9304 int count
= SPECPDL_INDEX ();
9305 specbind (Qinhibit_read_only
, Qt
);
9306 /* Note that undo recording is always disabled. */
9308 unbind_to (count
, Qnil
);
9310 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9312 /* Set up the buffer for the multibyteness we need. */
9314 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9315 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
9317 /* Raise the frame containing the echo area. */
9318 if (minibuffer_auto_raise
)
9320 struct frame
*sf
= SELECTED_FRAME ();
9321 Lisp_Object mini_window
;
9322 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9323 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9326 message_log_maybe_newline ();
9327 message_buf_print
= 1;
9331 if (NILP (echo_area_buffer
[0]))
9333 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9334 echo_area_buffer
[0] = echo_buffer
[1];
9336 echo_area_buffer
[0] = echo_buffer
[0];
9339 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
9341 /* Someone switched buffers between print requests. */
9342 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9343 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9349 /* Display an echo area message in window W. Value is non-zero if W's
9350 height is changed. If display_last_displayed_message_p is
9351 non-zero, display the message that was last displayed, otherwise
9352 display the current message. */
9355 display_echo_area (struct window
*w
)
9357 int i
, no_message_p
, window_height_changed_p
, count
;
9359 /* Temporarily disable garbage collections while displaying the echo
9360 area. This is done because a GC can print a message itself.
9361 That message would modify the echo area buffer's contents while a
9362 redisplay of the buffer is going on, and seriously confuse
9364 count
= inhibit_garbage_collection ();
9366 /* If there is no message, we must call display_echo_area_1
9367 nevertheless because it resizes the window. But we will have to
9368 reset the echo_area_buffer in question to nil at the end because
9369 with_echo_area_buffer will sets it to an empty buffer. */
9370 i
= display_last_displayed_message_p
? 1 : 0;
9371 no_message_p
= NILP (echo_area_buffer
[i
]);
9373 window_height_changed_p
9374 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
9375 display_echo_area_1
,
9376 (intptr_t) w
, Qnil
, 0, 0);
9379 echo_area_buffer
[i
] = Qnil
;
9381 unbind_to (count
, Qnil
);
9382 return window_height_changed_p
;
9386 /* Helper for display_echo_area. Display the current buffer which
9387 contains the current echo area message in window W, a mini-window,
9388 a pointer to which is passed in A1. A2..A4 are currently not used.
9389 Change the height of W so that all of the message is displayed.
9390 Value is non-zero if height of W was changed. */
9393 display_echo_area_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9396 struct window
*w
= (struct window
*) i1
;
9398 struct text_pos start
;
9399 int window_height_changed_p
= 0;
9401 /* Do this before displaying, so that we have a large enough glyph
9402 matrix for the display. If we can't get enough space for the
9403 whole text, display the last N lines. That works by setting w->start. */
9404 window_height_changed_p
= resize_mini_window (w
, 0);
9406 /* Use the starting position chosen by resize_mini_window. */
9407 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
9410 clear_glyph_matrix (w
->desired_matrix
);
9411 XSETWINDOW (window
, w
);
9412 try_window (window
, start
, 0);
9414 return window_height_changed_p
;
9418 /* Resize the echo area window to exactly the size needed for the
9419 currently displayed message, if there is one. If a mini-buffer
9420 is active, don't shrink it. */
9423 resize_echo_area_exactly (void)
9425 if (BUFFERP (echo_area_buffer
[0])
9426 && WINDOWP (echo_area_window
))
9428 struct window
*w
= XWINDOW (echo_area_window
);
9430 Lisp_Object resize_exactly
;
9432 if (minibuf_level
== 0)
9433 resize_exactly
= Qt
;
9435 resize_exactly
= Qnil
;
9437 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
9438 (intptr_t) w
, resize_exactly
,
9442 ++windows_or_buffers_changed
;
9443 ++update_mode_lines
;
9444 redisplay_internal ();
9450 /* Callback function for with_echo_area_buffer, when used from
9451 resize_echo_area_exactly. A1 contains a pointer to the window to
9452 resize, EXACTLY non-nil means resize the mini-window exactly to the
9453 size of the text displayed. A3 and A4 are not used. Value is what
9454 resize_mini_window returns. */
9457 resize_mini_window_1 (EMACS_INT a1
, Lisp_Object exactly
, EMACS_INT a3
, EMACS_INT a4
)
9460 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
9464 /* Resize mini-window W to fit the size of its contents. EXACT_P
9465 means size the window exactly to the size needed. Otherwise, it's
9466 only enlarged until W's buffer is empty.
9468 Set W->start to the right place to begin display. If the whole
9469 contents fit, start at the beginning. Otherwise, start so as
9470 to make the end of the contents appear. This is particularly
9471 important for y-or-n-p, but seems desirable generally.
9473 Value is non-zero if the window height has been changed. */
9476 resize_mini_window (struct window
*w
, int exact_p
)
9478 struct frame
*f
= XFRAME (w
->frame
);
9479 int window_height_changed_p
= 0;
9481 xassert (MINI_WINDOW_P (w
));
9483 /* By default, start display at the beginning. */
9484 set_marker_both (w
->start
, w
->buffer
,
9485 BUF_BEGV (XBUFFER (w
->buffer
)),
9486 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
9488 /* Don't resize windows while redisplaying a window; it would
9489 confuse redisplay functions when the size of the window they are
9490 displaying changes from under them. Such a resizing can happen,
9491 for instance, when which-func prints a long message while
9492 we are running fontification-functions. We're running these
9493 functions with safe_call which binds inhibit-redisplay to t. */
9494 if (!NILP (Vinhibit_redisplay
))
9497 /* Nil means don't try to resize. */
9498 if (NILP (Vresize_mini_windows
)
9499 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
9502 if (!FRAME_MINIBUF_ONLY_P (f
))
9505 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
9506 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
9507 int height
, max_height
;
9508 int unit
= FRAME_LINE_HEIGHT (f
);
9509 struct text_pos start
;
9510 struct buffer
*old_current_buffer
= NULL
;
9512 if (current_buffer
!= XBUFFER (w
->buffer
))
9514 old_current_buffer
= current_buffer
;
9515 set_buffer_internal (XBUFFER (w
->buffer
));
9518 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9520 /* Compute the max. number of lines specified by the user. */
9521 if (FLOATP (Vmax_mini_window_height
))
9522 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
9523 else if (INTEGERP (Vmax_mini_window_height
))
9524 max_height
= XINT (Vmax_mini_window_height
);
9526 max_height
= total_height
/ 4;
9528 /* Correct that max. height if it's bogus. */
9529 max_height
= max (1, max_height
);
9530 max_height
= min (total_height
, max_height
);
9532 /* Find out the height of the text in the window. */
9533 if (it
.line_wrap
== TRUNCATE
)
9538 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
9539 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
9540 height
= it
.current_y
+ last_height
;
9542 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9543 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9544 height
= (height
+ unit
- 1) / unit
;
9547 /* Compute a suitable window start. */
9548 if (height
> max_height
)
9550 height
= max_height
;
9551 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9552 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9553 start
= it
.current
.pos
;
9556 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9557 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9559 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9561 /* Let it grow only, until we display an empty message, in which
9562 case the window shrinks again. */
9563 if (height
> WINDOW_TOTAL_LINES (w
))
9565 int old_height
= WINDOW_TOTAL_LINES (w
);
9566 freeze_window_starts (f
, 1);
9567 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9568 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9570 else if (height
< WINDOW_TOTAL_LINES (w
)
9571 && (exact_p
|| BEGV
== ZV
))
9573 int old_height
= WINDOW_TOTAL_LINES (w
);
9574 freeze_window_starts (f
, 0);
9575 shrink_mini_window (w
);
9576 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9581 /* Always resize to exact size needed. */
9582 if (height
> WINDOW_TOTAL_LINES (w
))
9584 int old_height
= WINDOW_TOTAL_LINES (w
);
9585 freeze_window_starts (f
, 1);
9586 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9587 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9589 else if (height
< WINDOW_TOTAL_LINES (w
))
9591 int old_height
= WINDOW_TOTAL_LINES (w
);
9592 freeze_window_starts (f
, 0);
9593 shrink_mini_window (w
);
9597 freeze_window_starts (f
, 1);
9598 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9601 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9605 if (old_current_buffer
)
9606 set_buffer_internal (old_current_buffer
);
9609 return window_height_changed_p
;
9613 /* Value is the current message, a string, or nil if there is no
9617 current_message (void)
9621 if (!BUFFERP (echo_area_buffer
[0]))
9625 with_echo_area_buffer (0, 0, current_message_1
,
9626 (intptr_t) &msg
, Qnil
, 0, 0);
9628 echo_area_buffer
[0] = Qnil
;
9636 current_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9639 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
9642 *msg
= make_buffer_string (BEG
, Z
, 1);
9649 /* Push the current message on Vmessage_stack for later restauration
9650 by restore_message. Value is non-zero if the current message isn't
9651 empty. This is a relatively infrequent operation, so it's not
9652 worth optimizing. */
9658 msg
= current_message ();
9659 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9660 return STRINGP (msg
);
9664 /* Restore message display from the top of Vmessage_stack. */
9667 restore_message (void)
9671 xassert (CONSP (Vmessage_stack
));
9672 msg
= XCAR (Vmessage_stack
);
9674 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9676 message3_nolog (msg
, 0, 0);
9680 /* Handler for record_unwind_protect calling pop_message. */
9683 pop_message_unwind (Lisp_Object dummy
)
9689 /* Pop the top-most entry off Vmessage_stack. */
9694 xassert (CONSP (Vmessage_stack
));
9695 Vmessage_stack
= XCDR (Vmessage_stack
);
9699 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9700 exits. If the stack is not empty, we have a missing pop_message
9704 check_message_stack (void)
9706 if (!NILP (Vmessage_stack
))
9711 /* Truncate to NCHARS what will be displayed in the echo area the next
9712 time we display it---but don't redisplay it now. */
9715 truncate_echo_area (EMACS_INT nchars
)
9718 echo_area_buffer
[0] = Qnil
;
9719 /* A null message buffer means that the frame hasn't really been
9720 initialized yet. Error messages get reported properly by
9721 cmd_error, so this must be just an informative message; toss it. */
9722 else if (!noninteractive
9724 && !NILP (echo_area_buffer
[0]))
9726 struct frame
*sf
= SELECTED_FRAME ();
9727 if (FRAME_MESSAGE_BUF (sf
))
9728 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9733 /* Helper function for truncate_echo_area. Truncate the current
9734 message to at most NCHARS characters. */
9737 truncate_message_1 (EMACS_INT nchars
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9739 if (BEG
+ nchars
< Z
)
9740 del_range (BEG
+ nchars
, Z
);
9742 echo_area_buffer
[0] = Qnil
;
9747 /* Set the current message to a substring of S or STRING.
9749 If STRING is a Lisp string, set the message to the first NBYTES
9750 bytes from STRING. NBYTES zero means use the whole string. If
9751 STRING is multibyte, the message will be displayed multibyte.
9753 If S is not null, set the message to the first LEN bytes of S. LEN
9754 zero means use the whole string. MULTIBYTE_P non-zero means S is
9755 multibyte. Display the message multibyte in that case.
9757 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9758 to t before calling set_message_1 (which calls insert).
9762 set_message (const char *s
, Lisp_Object string
,
9763 EMACS_INT nbytes
, int multibyte_p
)
9765 message_enable_multibyte
9766 = ((s
&& multibyte_p
)
9767 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9769 with_echo_area_buffer (0, -1, set_message_1
,
9770 (intptr_t) s
, string
, nbytes
, multibyte_p
);
9771 message_buf_print
= 0;
9772 help_echo_showing_p
= 0;
9776 /* Helper function for set_message. Arguments have the same meaning
9777 as there, with A1 corresponding to S and A2 corresponding to STRING
9778 This function is called with the echo area buffer being
9782 set_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT nbytes
, EMACS_INT multibyte_p
)
9785 const char *s
= (const char *) i1
;
9786 const unsigned char *msg
= (const unsigned char *) s
;
9787 Lisp_Object string
= a2
;
9789 /* Change multibyteness of the echo buffer appropriately. */
9790 if (message_enable_multibyte
9791 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9792 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9794 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
9795 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
9796 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
9798 /* Insert new message at BEG. */
9799 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9801 if (STRINGP (string
))
9806 nbytes
= SBYTES (string
);
9807 nchars
= string_byte_to_char (string
, nbytes
);
9809 /* This function takes care of single/multibyte conversion. We
9810 just have to ensure that the echo area buffer has the right
9811 setting of enable_multibyte_characters. */
9812 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9817 nbytes
= strlen (s
);
9819 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9821 /* Convert from multi-byte to single-byte. */
9826 /* Convert a multibyte string to single-byte. */
9827 for (i
= 0; i
< nbytes
; i
+= n
)
9829 c
= string_char_and_length (msg
+ i
, &n
);
9830 work
[0] = (ASCII_CHAR_P (c
)
9832 : multibyte_char_to_unibyte (c
));
9833 insert_1_both (work
, 1, 1, 1, 0, 0);
9836 else if (!multibyte_p
9837 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9839 /* Convert from single-byte to multi-byte. */
9842 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9844 /* Convert a single-byte string to multibyte. */
9845 for (i
= 0; i
< nbytes
; i
++)
9848 MAKE_CHAR_MULTIBYTE (c
);
9849 n
= CHAR_STRING (c
, str
);
9850 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
9854 insert_1 (s
, nbytes
, 1, 0, 0);
9861 /* Clear messages. CURRENT_P non-zero means clear the current
9862 message. LAST_DISPLAYED_P non-zero means clear the message
9866 clear_message (int current_p
, int last_displayed_p
)
9870 echo_area_buffer
[0] = Qnil
;
9871 message_cleared_p
= 1;
9874 if (last_displayed_p
)
9875 echo_area_buffer
[1] = Qnil
;
9877 message_buf_print
= 0;
9880 /* Clear garbaged frames.
9882 This function is used where the old redisplay called
9883 redraw_garbaged_frames which in turn called redraw_frame which in
9884 turn called clear_frame. The call to clear_frame was a source of
9885 flickering. I believe a clear_frame is not necessary. It should
9886 suffice in the new redisplay to invalidate all current matrices,
9887 and ensure a complete redisplay of all windows. */
9890 clear_garbaged_frames (void)
9894 Lisp_Object tail
, frame
;
9895 int changed_count
= 0;
9897 FOR_EACH_FRAME (tail
, frame
)
9899 struct frame
*f
= XFRAME (frame
);
9901 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9905 Fredraw_frame (frame
);
9906 f
->force_flush_display_p
= 1;
9908 clear_current_matrices (f
);
9917 ++windows_or_buffers_changed
;
9922 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9923 is non-zero update selected_frame. Value is non-zero if the
9924 mini-windows height has been changed. */
9927 echo_area_display (int update_frame_p
)
9929 Lisp_Object mini_window
;
9932 int window_height_changed_p
= 0;
9933 struct frame
*sf
= SELECTED_FRAME ();
9935 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9936 w
= XWINDOW (mini_window
);
9937 f
= XFRAME (WINDOW_FRAME (w
));
9939 /* Don't display if frame is invisible or not yet initialized. */
9940 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9943 #ifdef HAVE_WINDOW_SYSTEM
9944 /* When Emacs starts, selected_frame may be the initial terminal
9945 frame. If we let this through, a message would be displayed on
9947 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9949 #endif /* HAVE_WINDOW_SYSTEM */
9951 /* Redraw garbaged frames. */
9953 clear_garbaged_frames ();
9955 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9957 echo_area_window
= mini_window
;
9958 window_height_changed_p
= display_echo_area (w
);
9959 w
->must_be_updated_p
= 1;
9961 /* Update the display, unless called from redisplay_internal.
9962 Also don't update the screen during redisplay itself. The
9963 update will happen at the end of redisplay, and an update
9964 here could cause confusion. */
9965 if (update_frame_p
&& !redisplaying_p
)
9969 /* If the display update has been interrupted by pending
9970 input, update mode lines in the frame. Due to the
9971 pending input, it might have been that redisplay hasn't
9972 been called, so that mode lines above the echo area are
9973 garbaged. This looks odd, so we prevent it here. */
9974 if (!display_completed
)
9975 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9977 if (window_height_changed_p
9978 /* Don't do this if Emacs is shutting down. Redisplay
9979 needs to run hooks. */
9980 && !NILP (Vrun_hooks
))
9982 /* Must update other windows. Likewise as in other
9983 cases, don't let this update be interrupted by
9985 int count
= SPECPDL_INDEX ();
9986 specbind (Qredisplay_dont_pause
, Qt
);
9987 windows_or_buffers_changed
= 1;
9988 redisplay_internal ();
9989 unbind_to (count
, Qnil
);
9991 else if (FRAME_WINDOW_P (f
) && n
== 0)
9993 /* Window configuration is the same as before.
9994 Can do with a display update of the echo area,
9995 unless we displayed some mode lines. */
9996 update_single_window (w
, 1);
9997 FRAME_RIF (f
)->flush_display (f
);
10000 update_frame (f
, 1, 1);
10002 /* If cursor is in the echo area, make sure that the next
10003 redisplay displays the minibuffer, so that the cursor will
10004 be replaced with what the minibuffer wants. */
10005 if (cursor_in_echo_area
)
10006 ++windows_or_buffers_changed
;
10009 else if (!EQ (mini_window
, selected_window
))
10010 windows_or_buffers_changed
++;
10012 /* Last displayed message is now the current message. */
10013 echo_area_buffer
[1] = echo_area_buffer
[0];
10014 /* Inform read_char that we're not echoing. */
10015 echo_message_buffer
= Qnil
;
10017 /* Prevent redisplay optimization in redisplay_internal by resetting
10018 this_line_start_pos. This is done because the mini-buffer now
10019 displays the message instead of its buffer text. */
10020 if (EQ (mini_window
, selected_window
))
10021 CHARPOS (this_line_start_pos
) = 0;
10023 return window_height_changed_p
;
10028 /***********************************************************************
10029 Mode Lines and Frame Titles
10030 ***********************************************************************/
10032 /* A buffer for constructing non-propertized mode-line strings and
10033 frame titles in it; allocated from the heap in init_xdisp and
10034 resized as needed in store_mode_line_noprop_char. */
10036 static char *mode_line_noprop_buf
;
10038 /* The buffer's end, and a current output position in it. */
10040 static char *mode_line_noprop_buf_end
;
10041 static char *mode_line_noprop_ptr
;
10043 #define MODE_LINE_NOPROP_LEN(start) \
10044 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10047 MODE_LINE_DISPLAY
= 0,
10051 } mode_line_target
;
10053 /* Alist that caches the results of :propertize.
10054 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10055 static Lisp_Object mode_line_proptrans_alist
;
10057 /* List of strings making up the mode-line. */
10058 static Lisp_Object mode_line_string_list
;
10060 /* Base face property when building propertized mode line string. */
10061 static Lisp_Object mode_line_string_face
;
10062 static Lisp_Object mode_line_string_face_prop
;
10065 /* Unwind data for mode line strings */
10067 static Lisp_Object Vmode_line_unwind_vector
;
10070 format_mode_line_unwind_data (struct buffer
*obuf
,
10072 int save_proptrans
)
10074 Lisp_Object vector
, tmp
;
10076 /* Reduce consing by keeping one vector in
10077 Vwith_echo_area_save_vector. */
10078 vector
= Vmode_line_unwind_vector
;
10079 Vmode_line_unwind_vector
= Qnil
;
10082 vector
= Fmake_vector (make_number (8), Qnil
);
10084 ASET (vector
, 0, make_number (mode_line_target
));
10085 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10086 ASET (vector
, 2, mode_line_string_list
);
10087 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10088 ASET (vector
, 4, mode_line_string_face
);
10089 ASET (vector
, 5, mode_line_string_face_prop
);
10092 XSETBUFFER (tmp
, obuf
);
10095 ASET (vector
, 6, tmp
);
10096 ASET (vector
, 7, owin
);
10102 unwind_format_mode_line (Lisp_Object vector
)
10104 mode_line_target
= XINT (AREF (vector
, 0));
10105 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10106 mode_line_string_list
= AREF (vector
, 2);
10107 if (! EQ (AREF (vector
, 3), Qt
))
10108 mode_line_proptrans_alist
= AREF (vector
, 3);
10109 mode_line_string_face
= AREF (vector
, 4);
10110 mode_line_string_face_prop
= AREF (vector
, 5);
10112 if (!NILP (AREF (vector
, 7)))
10113 /* Select window before buffer, since it may change the buffer. */
10114 Fselect_window (AREF (vector
, 7), Qt
);
10116 if (!NILP (AREF (vector
, 6)))
10118 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10119 ASET (vector
, 6, Qnil
);
10122 Vmode_line_unwind_vector
= vector
;
10127 /* Store a single character C for the frame title in mode_line_noprop_buf.
10128 Re-allocate mode_line_noprop_buf if necessary. */
10131 store_mode_line_noprop_char (char c
)
10133 /* If output position has reached the end of the allocated buffer,
10134 double the buffer's size. */
10135 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10137 int len
= MODE_LINE_NOPROP_LEN (0);
10138 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
10139 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
10140 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
10141 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10144 *mode_line_noprop_ptr
++ = c
;
10148 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10149 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10150 characters that yield more columns than PRECISION; PRECISION <= 0
10151 means copy the whole string. Pad with spaces until FIELD_WIDTH
10152 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10153 pad. Called from display_mode_element when it is used to build a
10157 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10159 const unsigned char *str
= (const unsigned char *) string
;
10161 EMACS_INT dummy
, nbytes
;
10163 /* Copy at most PRECISION chars from STR. */
10164 nbytes
= strlen (string
);
10165 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10167 store_mode_line_noprop_char (*str
++);
10169 /* Fill up with spaces until FIELD_WIDTH reached. */
10170 while (field_width
> 0
10171 && n
< field_width
)
10173 store_mode_line_noprop_char (' ');
10180 /***********************************************************************
10182 ***********************************************************************/
10184 #ifdef HAVE_WINDOW_SYSTEM
10186 /* Set the title of FRAME, if it has changed. The title format is
10187 Vicon_title_format if FRAME is iconified, otherwise it is
10188 frame_title_format. */
10191 x_consider_frame_title (Lisp_Object frame
)
10193 struct frame
*f
= XFRAME (frame
);
10195 if (FRAME_WINDOW_P (f
)
10196 || FRAME_MINIBUF_ONLY_P (f
)
10197 || f
->explicit_name
)
10199 /* Do we have more than one visible frame on this X display? */
10206 int count
= SPECPDL_INDEX ();
10208 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
10210 Lisp_Object other_frame
= XCAR (tail
);
10211 struct frame
*tf
= XFRAME (other_frame
);
10214 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
10215 && !FRAME_MINIBUF_ONLY_P (tf
)
10216 && !EQ (other_frame
, tip_frame
)
10217 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
10221 /* Set global variable indicating that multiple frames exist. */
10222 multiple_frames
= CONSP (tail
);
10224 /* Switch to the buffer of selected window of the frame. Set up
10225 mode_line_target so that display_mode_element will output into
10226 mode_line_noprop_buf; then display the title. */
10227 record_unwind_protect (unwind_format_mode_line
,
10228 format_mode_line_unwind_data
10229 (current_buffer
, selected_window
, 0));
10231 Fselect_window (f
->selected_window
, Qt
);
10232 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
10233 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
10235 mode_line_target
= MODE_LINE_TITLE
;
10236 title_start
= MODE_LINE_NOPROP_LEN (0);
10237 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
10238 NULL
, DEFAULT_FACE_ID
);
10239 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
10240 len
= MODE_LINE_NOPROP_LEN (title_start
);
10241 title
= mode_line_noprop_buf
+ title_start
;
10242 unbind_to (count
, Qnil
);
10244 /* Set the title only if it's changed. This avoids consing in
10245 the common case where it hasn't. (If it turns out that we've
10246 already wasted too much time by walking through the list with
10247 display_mode_element, then we might need to optimize at a
10248 higher level than this.) */
10249 if (! STRINGP (f
->name
)
10250 || SBYTES (f
->name
) != len
10251 || memcmp (title
, SDATA (f
->name
), len
) != 0)
10252 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
10256 #endif /* not HAVE_WINDOW_SYSTEM */
10261 /***********************************************************************
10263 ***********************************************************************/
10266 /* Prepare for redisplay by updating menu-bar item lists when
10267 appropriate. This can call eval. */
10270 prepare_menu_bars (void)
10273 struct gcpro gcpro1
, gcpro2
;
10275 Lisp_Object tooltip_frame
;
10277 #ifdef HAVE_WINDOW_SYSTEM
10278 tooltip_frame
= tip_frame
;
10280 tooltip_frame
= Qnil
;
10283 /* Update all frame titles based on their buffer names, etc. We do
10284 this before the menu bars so that the buffer-menu will show the
10285 up-to-date frame titles. */
10286 #ifdef HAVE_WINDOW_SYSTEM
10287 if (windows_or_buffers_changed
|| update_mode_lines
)
10289 Lisp_Object tail
, frame
;
10291 FOR_EACH_FRAME (tail
, frame
)
10293 f
= XFRAME (frame
);
10294 if (!EQ (frame
, tooltip_frame
)
10295 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
10296 x_consider_frame_title (frame
);
10299 #endif /* HAVE_WINDOW_SYSTEM */
10301 /* Update the menu bar item lists, if appropriate. This has to be
10302 done before any actual redisplay or generation of display lines. */
10303 all_windows
= (update_mode_lines
10304 || buffer_shared
> 1
10305 || windows_or_buffers_changed
);
10308 Lisp_Object tail
, frame
;
10309 int count
= SPECPDL_INDEX ();
10310 /* 1 means that update_menu_bar has run its hooks
10311 so any further calls to update_menu_bar shouldn't do so again. */
10312 int menu_bar_hooks_run
= 0;
10314 record_unwind_save_match_data ();
10316 FOR_EACH_FRAME (tail
, frame
)
10318 f
= XFRAME (frame
);
10320 /* Ignore tooltip frame. */
10321 if (EQ (frame
, tooltip_frame
))
10324 /* If a window on this frame changed size, report that to
10325 the user and clear the size-change flag. */
10326 if (FRAME_WINDOW_SIZES_CHANGED (f
))
10328 Lisp_Object functions
;
10330 /* Clear flag first in case we get an error below. */
10331 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
10332 functions
= Vwindow_size_change_functions
;
10333 GCPRO2 (tail
, functions
);
10335 while (CONSP (functions
))
10337 if (!EQ (XCAR (functions
), Qt
))
10338 call1 (XCAR (functions
), frame
);
10339 functions
= XCDR (functions
);
10345 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
10346 #ifdef HAVE_WINDOW_SYSTEM
10347 update_tool_bar (f
, 0);
10350 if (windows_or_buffers_changed
10352 ns_set_doc_edited (f
, Fbuffer_modified_p
10353 (XWINDOW (f
->selected_window
)->buffer
));
10358 unbind_to (count
, Qnil
);
10362 struct frame
*sf
= SELECTED_FRAME ();
10363 update_menu_bar (sf
, 1, 0);
10364 #ifdef HAVE_WINDOW_SYSTEM
10365 update_tool_bar (sf
, 1);
10371 /* Update the menu bar item list for frame F. This has to be done
10372 before we start to fill in any display lines, because it can call
10375 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
10377 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
10378 already ran the menu bar hooks for this redisplay, so there
10379 is no need to run them again. The return value is the
10380 updated value of this flag, to pass to the next call. */
10383 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
10385 Lisp_Object window
;
10386 register struct window
*w
;
10388 /* If called recursively during a menu update, do nothing. This can
10389 happen when, for instance, an activate-menubar-hook causes a
10391 if (inhibit_menubar_update
)
10394 window
= FRAME_SELECTED_WINDOW (f
);
10395 w
= XWINDOW (window
);
10397 if (FRAME_WINDOW_P (f
)
10399 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10400 || defined (HAVE_NS) || defined (USE_GTK)
10401 FRAME_EXTERNAL_MENU_BAR (f
)
10403 FRAME_MENU_BAR_LINES (f
) > 0
10405 : FRAME_MENU_BAR_LINES (f
) > 0)
10407 /* If the user has switched buffers or windows, we need to
10408 recompute to reflect the new bindings. But we'll
10409 recompute when update_mode_lines is set too; that means
10410 that people can use force-mode-line-update to request
10411 that the menu bar be recomputed. The adverse effect on
10412 the rest of the redisplay algorithm is about the same as
10413 windows_or_buffers_changed anyway. */
10414 if (windows_or_buffers_changed
10415 /* This used to test w->update_mode_line, but we believe
10416 there is no need to recompute the menu in that case. */
10417 || update_mode_lines
10418 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10419 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10420 != !NILP (w
->last_had_star
))
10421 || ((!NILP (Vtransient_mark_mode
)
10422 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10423 != !NILP (w
->region_showing
)))
10425 struct buffer
*prev
= current_buffer
;
10426 int count
= SPECPDL_INDEX ();
10428 specbind (Qinhibit_menubar_update
, Qt
);
10430 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10431 if (save_match_data
)
10432 record_unwind_save_match_data ();
10433 if (NILP (Voverriding_local_map_menu_flag
))
10435 specbind (Qoverriding_terminal_local_map
, Qnil
);
10436 specbind (Qoverriding_local_map
, Qnil
);
10441 /* Run the Lucid hook. */
10442 safe_run_hooks (Qactivate_menubar_hook
);
10444 /* If it has changed current-menubar from previous value,
10445 really recompute the menu-bar from the value. */
10446 if (! NILP (Vlucid_menu_bar_dirty_flag
))
10447 call0 (Qrecompute_lucid_menubar
);
10449 safe_run_hooks (Qmenu_bar_update_hook
);
10454 XSETFRAME (Vmenu_updating_frame
, f
);
10455 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
10457 /* Redisplay the menu bar in case we changed it. */
10458 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10459 || defined (HAVE_NS) || defined (USE_GTK)
10460 if (FRAME_WINDOW_P (f
))
10462 #if defined (HAVE_NS)
10463 /* All frames on Mac OS share the same menubar. So only
10464 the selected frame should be allowed to set it. */
10465 if (f
== SELECTED_FRAME ())
10467 set_frame_menubar (f
, 0, 0);
10470 /* On a terminal screen, the menu bar is an ordinary screen
10471 line, and this makes it get updated. */
10472 w
->update_mode_line
= Qt
;
10473 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10474 /* In the non-toolkit version, the menu bar is an ordinary screen
10475 line, and this makes it get updated. */
10476 w
->update_mode_line
= Qt
;
10477 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10479 unbind_to (count
, Qnil
);
10480 set_buffer_internal_1 (prev
);
10489 /***********************************************************************
10491 ***********************************************************************/
10493 #ifdef HAVE_WINDOW_SYSTEM
10496 Nominal cursor position -- where to draw output.
10497 HPOS and VPOS are window relative glyph matrix coordinates.
10498 X and Y are window relative pixel coordinates. */
10500 struct cursor_pos output_cursor
;
10504 Set the global variable output_cursor to CURSOR. All cursor
10505 positions are relative to updated_window. */
10508 set_output_cursor (struct cursor_pos
*cursor
)
10510 output_cursor
.hpos
= cursor
->hpos
;
10511 output_cursor
.vpos
= cursor
->vpos
;
10512 output_cursor
.x
= cursor
->x
;
10513 output_cursor
.y
= cursor
->y
;
10518 Set a nominal cursor position.
10520 HPOS and VPOS are column/row positions in a window glyph matrix. X
10521 and Y are window text area relative pixel positions.
10523 If this is done during an update, updated_window will contain the
10524 window that is being updated and the position is the future output
10525 cursor position for that window. If updated_window is null, use
10526 selected_window and display the cursor at the given position. */
10529 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
10533 /* If updated_window is not set, work on selected_window. */
10534 if (updated_window
)
10535 w
= updated_window
;
10537 w
= XWINDOW (selected_window
);
10539 /* Set the output cursor. */
10540 output_cursor
.hpos
= hpos
;
10541 output_cursor
.vpos
= vpos
;
10542 output_cursor
.x
= x
;
10543 output_cursor
.y
= y
;
10545 /* If not called as part of an update, really display the cursor.
10546 This will also set the cursor position of W. */
10547 if (updated_window
== NULL
)
10550 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10551 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10552 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10557 #endif /* HAVE_WINDOW_SYSTEM */
10560 /***********************************************************************
10562 ***********************************************************************/
10564 #ifdef HAVE_WINDOW_SYSTEM
10566 /* Where the mouse was last time we reported a mouse event. */
10568 FRAME_PTR last_mouse_frame
;
10570 /* Tool-bar item index of the item on which a mouse button was pressed
10573 int last_tool_bar_item
;
10577 update_tool_bar_unwind (Lisp_Object frame
)
10579 selected_frame
= frame
;
10583 /* Update the tool-bar item list for frame F. This has to be done
10584 before we start to fill in any display lines. Called from
10585 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10586 and restore it here. */
10589 update_tool_bar (struct frame
*f
, int save_match_data
)
10591 #if defined (USE_GTK) || defined (HAVE_NS)
10592 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10594 int do_update
= WINDOWP (f
->tool_bar_window
)
10595 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10600 Lisp_Object window
;
10603 window
= FRAME_SELECTED_WINDOW (f
);
10604 w
= XWINDOW (window
);
10606 /* If the user has switched buffers or windows, we need to
10607 recompute to reflect the new bindings. But we'll
10608 recompute when update_mode_lines is set too; that means
10609 that people can use force-mode-line-update to request
10610 that the menu bar be recomputed. The adverse effect on
10611 the rest of the redisplay algorithm is about the same as
10612 windows_or_buffers_changed anyway. */
10613 if (windows_or_buffers_changed
10614 || !NILP (w
->update_mode_line
)
10615 || update_mode_lines
10616 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10617 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10618 != !NILP (w
->last_had_star
))
10619 || ((!NILP (Vtransient_mark_mode
)
10620 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10621 != !NILP (w
->region_showing
)))
10623 struct buffer
*prev
= current_buffer
;
10624 int count
= SPECPDL_INDEX ();
10625 Lisp_Object frame
, new_tool_bar
;
10626 int new_n_tool_bar
;
10627 struct gcpro gcpro1
;
10629 /* Set current_buffer to the buffer of the selected
10630 window of the frame, so that we get the right local
10632 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10634 /* Save match data, if we must. */
10635 if (save_match_data
)
10636 record_unwind_save_match_data ();
10638 /* Make sure that we don't accidentally use bogus keymaps. */
10639 if (NILP (Voverriding_local_map_menu_flag
))
10641 specbind (Qoverriding_terminal_local_map
, Qnil
);
10642 specbind (Qoverriding_local_map
, Qnil
);
10645 GCPRO1 (new_tool_bar
);
10647 /* We must temporarily set the selected frame to this frame
10648 before calling tool_bar_items, because the calculation of
10649 the tool-bar keymap uses the selected frame (see
10650 `tool-bar-make-keymap' in tool-bar.el). */
10651 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10652 XSETFRAME (frame
, f
);
10653 selected_frame
= frame
;
10655 /* Build desired tool-bar items from keymaps. */
10656 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10659 /* Redisplay the tool-bar if we changed it. */
10660 if (new_n_tool_bar
!= f
->n_tool_bar_items
10661 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10663 /* Redisplay that happens asynchronously due to an expose event
10664 may access f->tool_bar_items. Make sure we update both
10665 variables within BLOCK_INPUT so no such event interrupts. */
10667 f
->tool_bar_items
= new_tool_bar
;
10668 f
->n_tool_bar_items
= new_n_tool_bar
;
10669 w
->update_mode_line
= Qt
;
10675 unbind_to (count
, Qnil
);
10676 set_buffer_internal_1 (prev
);
10682 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10683 F's desired tool-bar contents. F->tool_bar_items must have
10684 been set up previously by calling prepare_menu_bars. */
10687 build_desired_tool_bar_string (struct frame
*f
)
10689 int i
, size
, size_needed
;
10690 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10691 Lisp_Object image
, plist
, props
;
10693 image
= plist
= props
= Qnil
;
10694 GCPRO3 (image
, plist
, props
);
10696 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10697 Otherwise, make a new string. */
10699 /* The size of the string we might be able to reuse. */
10700 size
= (STRINGP (f
->desired_tool_bar_string
)
10701 ? SCHARS (f
->desired_tool_bar_string
)
10704 /* We need one space in the string for each image. */
10705 size_needed
= f
->n_tool_bar_items
;
10707 /* Reuse f->desired_tool_bar_string, if possible. */
10708 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10709 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10710 make_number (' '));
10713 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10714 Fremove_text_properties (make_number (0), make_number (size
),
10715 props
, f
->desired_tool_bar_string
);
10718 /* Put a `display' property on the string for the images to display,
10719 put a `menu_item' property on tool-bar items with a value that
10720 is the index of the item in F's tool-bar item vector. */
10721 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10723 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10725 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10726 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10727 int hmargin
, vmargin
, relief
, idx
, end
;
10729 /* If image is a vector, choose the image according to the
10731 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10732 if (VECTORP (image
))
10736 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10737 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10740 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10741 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10743 xassert (ASIZE (image
) >= idx
);
10744 image
= AREF (image
, idx
);
10749 /* Ignore invalid image specifications. */
10750 if (!valid_image_p (image
))
10753 /* Display the tool-bar button pressed, or depressed. */
10754 plist
= Fcopy_sequence (XCDR (image
));
10756 /* Compute margin and relief to draw. */
10757 relief
= (tool_bar_button_relief
>= 0
10758 ? tool_bar_button_relief
10759 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10760 hmargin
= vmargin
= relief
;
10762 if (INTEGERP (Vtool_bar_button_margin
)
10763 && XINT (Vtool_bar_button_margin
) > 0)
10765 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10766 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10768 else if (CONSP (Vtool_bar_button_margin
))
10770 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10771 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10772 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10774 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10775 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10776 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10779 if (auto_raise_tool_bar_buttons_p
)
10781 /* Add a `:relief' property to the image spec if the item is
10785 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10792 /* If image is selected, display it pressed, i.e. with a
10793 negative relief. If it's not selected, display it with a
10795 plist
= Fplist_put (plist
, QCrelief
,
10797 ? make_number (-relief
)
10798 : make_number (relief
)));
10803 /* Put a margin around the image. */
10804 if (hmargin
|| vmargin
)
10806 if (hmargin
== vmargin
)
10807 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10809 plist
= Fplist_put (plist
, QCmargin
,
10810 Fcons (make_number (hmargin
),
10811 make_number (vmargin
)));
10814 /* If button is not enabled, and we don't have special images
10815 for the disabled state, make the image appear disabled by
10816 applying an appropriate algorithm to it. */
10817 if (!enabled_p
&& idx
< 0)
10818 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10820 /* Put a `display' text property on the string for the image to
10821 display. Put a `menu-item' property on the string that gives
10822 the start of this item's properties in the tool-bar items
10824 image
= Fcons (Qimage
, plist
);
10825 props
= list4 (Qdisplay
, image
,
10826 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10828 /* Let the last image hide all remaining spaces in the tool bar
10829 string. The string can be longer than needed when we reuse a
10830 previous string. */
10831 if (i
+ 1 == f
->n_tool_bar_items
)
10832 end
= SCHARS (f
->desired_tool_bar_string
);
10835 Fadd_text_properties (make_number (i
), make_number (end
),
10836 props
, f
->desired_tool_bar_string
);
10844 /* Display one line of the tool-bar of frame IT->f.
10846 HEIGHT specifies the desired height of the tool-bar line.
10847 If the actual height of the glyph row is less than HEIGHT, the
10848 row's height is increased to HEIGHT, and the icons are centered
10849 vertically in the new height.
10851 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10852 count a final empty row in case the tool-bar width exactly matches
10857 display_tool_bar_line (struct it
*it
, int height
)
10859 struct glyph_row
*row
= it
->glyph_row
;
10860 int max_x
= it
->last_visible_x
;
10861 struct glyph
*last
;
10863 prepare_desired_row (row
);
10864 row
->y
= it
->current_y
;
10866 /* Note that this isn't made use of if the face hasn't a box,
10867 so there's no need to check the face here. */
10868 it
->start_of_box_run_p
= 1;
10870 while (it
->current_x
< max_x
)
10872 int x
, n_glyphs_before
, i
, nglyphs
;
10873 struct it it_before
;
10875 /* Get the next display element. */
10876 if (!get_next_display_element (it
))
10878 /* Don't count empty row if we are counting needed tool-bar lines. */
10879 if (height
< 0 && !it
->hpos
)
10884 /* Produce glyphs. */
10885 n_glyphs_before
= row
->used
[TEXT_AREA
];
10888 PRODUCE_GLYPHS (it
);
10890 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10892 x
= it_before
.current_x
;
10893 while (i
< nglyphs
)
10895 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10897 if (x
+ glyph
->pixel_width
> max_x
)
10899 /* Glyph doesn't fit on line. Backtrack. */
10900 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10902 /* If this is the only glyph on this line, it will never fit on the
10903 tool-bar, so skip it. But ensure there is at least one glyph,
10904 so we don't accidentally disable the tool-bar. */
10905 if (n_glyphs_before
== 0
10906 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10912 x
+= glyph
->pixel_width
;
10916 /* Stop at line end. */
10917 if (ITERATOR_AT_END_OF_LINE_P (it
))
10920 set_iterator_to_next (it
, 1);
10925 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10927 /* Use default face for the border below the tool bar.
10929 FIXME: When auto-resize-tool-bars is grow-only, there is
10930 no additional border below the possibly empty tool-bar lines.
10931 So to make the extra empty lines look "normal", we have to
10932 use the tool-bar face for the border too. */
10933 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10934 it
->face_id
= DEFAULT_FACE_ID
;
10936 extend_face_to_end_of_line (it
);
10937 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10938 last
->right_box_line_p
= 1;
10939 if (last
== row
->glyphs
[TEXT_AREA
])
10940 last
->left_box_line_p
= 1;
10942 /* Make line the desired height and center it vertically. */
10943 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10945 /* Don't add more than one line height. */
10946 height
%= FRAME_LINE_HEIGHT (it
->f
);
10947 it
->max_ascent
+= height
/ 2;
10948 it
->max_descent
+= (height
+ 1) / 2;
10951 compute_line_metrics (it
);
10953 /* If line is empty, make it occupy the rest of the tool-bar. */
10954 if (!row
->displays_text_p
)
10956 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10957 row
->visible_height
= row
->height
;
10958 row
->ascent
= row
->phys_ascent
= 0;
10959 row
->extra_line_spacing
= 0;
10962 row
->full_width_p
= 1;
10963 row
->continued_p
= 0;
10964 row
->truncated_on_left_p
= 0;
10965 row
->truncated_on_right_p
= 0;
10967 it
->current_x
= it
->hpos
= 0;
10968 it
->current_y
+= row
->height
;
10974 /* Max tool-bar height. */
10976 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10977 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10979 /* Value is the number of screen lines needed to make all tool-bar
10980 items of frame F visible. The number of actual rows needed is
10981 returned in *N_ROWS if non-NULL. */
10984 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
10986 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10988 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10989 the desired matrix, so use (unused) mode-line row as temporary row to
10990 avoid destroying the first tool-bar row. */
10991 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10993 /* Initialize an iterator for iteration over
10994 F->desired_tool_bar_string in the tool-bar window of frame F. */
10995 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10996 it
.first_visible_x
= 0;
10997 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10998 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10999 it
.paragraph_embedding
= L2R
;
11001 while (!ITERATOR_AT_END_P (&it
))
11003 clear_glyph_row (temp_row
);
11004 it
.glyph_row
= temp_row
;
11005 display_tool_bar_line (&it
, -1);
11007 clear_glyph_row (temp_row
);
11009 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11011 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11013 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11017 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11019 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11020 (Lisp_Object frame
)
11027 frame
= selected_frame
;
11029 CHECK_FRAME (frame
);
11030 f
= XFRAME (frame
);
11032 if (WINDOWP (f
->tool_bar_window
)
11033 || (w
= XWINDOW (f
->tool_bar_window
),
11034 WINDOW_TOTAL_LINES (w
) > 0))
11036 update_tool_bar (f
, 1);
11037 if (f
->n_tool_bar_items
)
11039 build_desired_tool_bar_string (f
);
11040 nlines
= tool_bar_lines_needed (f
, NULL
);
11044 return make_number (nlines
);
11048 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11049 height should be changed. */
11052 redisplay_tool_bar (struct frame
*f
)
11056 struct glyph_row
*row
;
11058 #if defined (USE_GTK) || defined (HAVE_NS)
11059 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11060 update_frame_tool_bar (f
);
11064 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11065 do anything. This means you must start with tool-bar-lines
11066 non-zero to get the auto-sizing effect. Or in other words, you
11067 can turn off tool-bars by specifying tool-bar-lines zero. */
11068 if (!WINDOWP (f
->tool_bar_window
)
11069 || (w
= XWINDOW (f
->tool_bar_window
),
11070 WINDOW_TOTAL_LINES (w
) == 0))
11073 /* Set up an iterator for the tool-bar window. */
11074 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11075 it
.first_visible_x
= 0;
11076 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11077 row
= it
.glyph_row
;
11079 /* Build a string that represents the contents of the tool-bar. */
11080 build_desired_tool_bar_string (f
);
11081 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11082 /* FIXME: This should be controlled by a user option. But it
11083 doesn't make sense to have an R2L tool bar if the menu bar cannot
11084 be drawn also R2L, and making the menu bar R2L is tricky due to
11085 unibyte strings it uses and toolkit-specific code that implements
11086 it. If an R2L tool bar is ever supported, display_tool_bar_line
11087 should also be augmented to call unproduce_glyphs like
11088 display_line and display_string do. */
11089 it
.paragraph_embedding
= L2R
;
11091 if (f
->n_tool_bar_rows
== 0)
11095 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11096 nlines
!= WINDOW_TOTAL_LINES (w
)))
11099 int old_height
= WINDOW_TOTAL_LINES (w
);
11101 XSETFRAME (frame
, f
);
11102 Fmodify_frame_parameters (frame
,
11103 Fcons (Fcons (Qtool_bar_lines
,
11104 make_number (nlines
)),
11106 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11108 clear_glyph_matrix (w
->desired_matrix
);
11109 fonts_changed_p
= 1;
11115 /* Display as many lines as needed to display all tool-bar items. */
11117 if (f
->n_tool_bar_rows
> 0)
11119 int border
, rows
, height
, extra
;
11121 if (INTEGERP (Vtool_bar_border
))
11122 border
= XINT (Vtool_bar_border
);
11123 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11124 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11125 else if (EQ (Vtool_bar_border
, Qborder_width
))
11126 border
= f
->border_width
;
11132 rows
= f
->n_tool_bar_rows
;
11133 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11134 extra
= it
.last_visible_y
- border
- height
* rows
;
11136 while (it
.current_y
< it
.last_visible_y
)
11139 if (extra
> 0 && rows
-- > 0)
11141 h
= (extra
+ rows
- 1) / rows
;
11144 display_tool_bar_line (&it
, height
+ h
);
11149 while (it
.current_y
< it
.last_visible_y
)
11150 display_tool_bar_line (&it
, 0);
11153 /* It doesn't make much sense to try scrolling in the tool-bar
11154 window, so don't do it. */
11155 w
->desired_matrix
->no_scrolling_p
= 1;
11156 w
->must_be_updated_p
= 1;
11158 if (!NILP (Vauto_resize_tool_bars
))
11160 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11161 int change_height_p
= 0;
11163 /* If we couldn't display everything, change the tool-bar's
11164 height if there is room for more. */
11165 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11166 && it
.current_y
< max_tool_bar_height
)
11167 change_height_p
= 1;
11169 row
= it
.glyph_row
- 1;
11171 /* If there are blank lines at the end, except for a partially
11172 visible blank line at the end that is smaller than
11173 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11174 if (!row
->displays_text_p
11175 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11176 change_height_p
= 1;
11178 /* If row displays tool-bar items, but is partially visible,
11179 change the tool-bar's height. */
11180 if (row
->displays_text_p
11181 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11182 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11183 change_height_p
= 1;
11185 /* Resize windows as needed by changing the `tool-bar-lines'
11186 frame parameter. */
11187 if (change_height_p
)
11190 int old_height
= WINDOW_TOTAL_LINES (w
);
11192 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11194 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11195 && !f
->minimize_tool_bar_window_p
)
11196 ? (nlines
> old_height
)
11197 : (nlines
!= old_height
));
11198 f
->minimize_tool_bar_window_p
= 0;
11200 if (change_height_p
)
11202 XSETFRAME (frame
, f
);
11203 Fmodify_frame_parameters (frame
,
11204 Fcons (Fcons (Qtool_bar_lines
,
11205 make_number (nlines
)),
11207 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11209 clear_glyph_matrix (w
->desired_matrix
);
11210 f
->n_tool_bar_rows
= nrows
;
11211 fonts_changed_p
= 1;
11218 f
->minimize_tool_bar_window_p
= 0;
11223 /* Get information about the tool-bar item which is displayed in GLYPH
11224 on frame F. Return in *PROP_IDX the index where tool-bar item
11225 properties start in F->tool_bar_items. Value is zero if
11226 GLYPH doesn't display a tool-bar item. */
11229 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
11235 /* This function can be called asynchronously, which means we must
11236 exclude any possibility that Fget_text_property signals an
11238 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
11239 charpos
= max (0, charpos
);
11241 /* Get the text property `menu-item' at pos. The value of that
11242 property is the start index of this item's properties in
11243 F->tool_bar_items. */
11244 prop
= Fget_text_property (make_number (charpos
),
11245 Qmenu_item
, f
->current_tool_bar_string
);
11246 if (INTEGERP (prop
))
11248 *prop_idx
= XINT (prop
);
11258 /* Get information about the tool-bar item at position X/Y on frame F.
11259 Return in *GLYPH a pointer to the glyph of the tool-bar item in
11260 the current matrix of the tool-bar window of F, or NULL if not
11261 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
11262 item in F->tool_bar_items. Value is
11264 -1 if X/Y is not on a tool-bar item
11265 0 if X/Y is on the same item that was highlighted before.
11269 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
11270 int *hpos
, int *vpos
, int *prop_idx
)
11272 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11273 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11276 /* Find the glyph under X/Y. */
11277 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
11278 if (*glyph
== NULL
)
11281 /* Get the start of this tool-bar item's properties in
11282 f->tool_bar_items. */
11283 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
11286 /* Is mouse on the highlighted item? */
11287 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
11288 && *vpos
>= hlinfo
->mouse_face_beg_row
11289 && *vpos
<= hlinfo
->mouse_face_end_row
11290 && (*vpos
> hlinfo
->mouse_face_beg_row
11291 || *hpos
>= hlinfo
->mouse_face_beg_col
)
11292 && (*vpos
< hlinfo
->mouse_face_end_row
11293 || *hpos
< hlinfo
->mouse_face_end_col
11294 || hlinfo
->mouse_face_past_end
))
11302 Handle mouse button event on the tool-bar of frame F, at
11303 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
11304 0 for button release. MODIFIERS is event modifiers for button
11308 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
11309 unsigned int modifiers
)
11311 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11312 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11313 int hpos
, vpos
, prop_idx
;
11314 struct glyph
*glyph
;
11315 Lisp_Object enabled_p
;
11317 /* If not on the highlighted tool-bar item, return. */
11318 frame_to_window_pixel_xy (w
, &x
, &y
);
11319 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
11322 /* If item is disabled, do nothing. */
11323 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11324 if (NILP (enabled_p
))
11329 /* Show item in pressed state. */
11330 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
11331 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
11332 last_tool_bar_item
= prop_idx
;
11336 Lisp_Object key
, frame
;
11337 struct input_event event
;
11338 EVENT_INIT (event
);
11340 /* Show item in released state. */
11341 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
11342 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
11344 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
11346 XSETFRAME (frame
, f
);
11347 event
.kind
= TOOL_BAR_EVENT
;
11348 event
.frame_or_window
= frame
;
11350 kbd_buffer_store_event (&event
);
11352 event
.kind
= TOOL_BAR_EVENT
;
11353 event
.frame_or_window
= frame
;
11355 event
.modifiers
= modifiers
;
11356 kbd_buffer_store_event (&event
);
11357 last_tool_bar_item
= -1;
11362 /* Possibly highlight a tool-bar item on frame F when mouse moves to
11363 tool-bar window-relative coordinates X/Y. Called from
11364 note_mouse_highlight. */
11367 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
11369 Lisp_Object window
= f
->tool_bar_window
;
11370 struct window
*w
= XWINDOW (window
);
11371 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11372 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11374 struct glyph
*glyph
;
11375 struct glyph_row
*row
;
11377 Lisp_Object enabled_p
;
11379 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
11380 int mouse_down_p
, rc
;
11382 /* Function note_mouse_highlight is called with negative X/Y
11383 values when mouse moves outside of the frame. */
11384 if (x
<= 0 || y
<= 0)
11386 clear_mouse_face (hlinfo
);
11390 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
11393 /* Not on tool-bar item. */
11394 clear_mouse_face (hlinfo
);
11398 /* On same tool-bar item as before. */
11399 goto set_help_echo
;
11401 clear_mouse_face (hlinfo
);
11403 /* Mouse is down, but on different tool-bar item? */
11404 mouse_down_p
= (dpyinfo
->grabbed
11405 && f
== last_mouse_frame
11406 && FRAME_LIVE_P (f
));
11408 && last_tool_bar_item
!= prop_idx
)
11411 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
11412 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
11414 /* If tool-bar item is not enabled, don't highlight it. */
11415 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11416 if (!NILP (enabled_p
))
11418 /* Compute the x-position of the glyph. In front and past the
11419 image is a space. We include this in the highlighted area. */
11420 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
11421 for (i
= x
= 0; i
< hpos
; ++i
)
11422 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11424 /* Record this as the current active region. */
11425 hlinfo
->mouse_face_beg_col
= hpos
;
11426 hlinfo
->mouse_face_beg_row
= vpos
;
11427 hlinfo
->mouse_face_beg_x
= x
;
11428 hlinfo
->mouse_face_beg_y
= row
->y
;
11429 hlinfo
->mouse_face_past_end
= 0;
11431 hlinfo
->mouse_face_end_col
= hpos
+ 1;
11432 hlinfo
->mouse_face_end_row
= vpos
;
11433 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
11434 hlinfo
->mouse_face_end_y
= row
->y
;
11435 hlinfo
->mouse_face_window
= window
;
11436 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
11438 /* Display it as active. */
11439 show_mouse_face (hlinfo
, draw
);
11440 hlinfo
->mouse_face_image_state
= draw
;
11445 /* Set help_echo_string to a help string to display for this tool-bar item.
11446 XTread_socket does the rest. */
11447 help_echo_object
= help_echo_window
= Qnil
;
11448 help_echo_pos
= -1;
11449 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
11450 if (NILP (help_echo_string
))
11451 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
11454 #endif /* HAVE_WINDOW_SYSTEM */
11458 /************************************************************************
11459 Horizontal scrolling
11460 ************************************************************************/
11462 static int hscroll_window_tree (Lisp_Object
);
11463 static int hscroll_windows (Lisp_Object
);
11465 /* For all leaf windows in the window tree rooted at WINDOW, set their
11466 hscroll value so that PT is (i) visible in the window, and (ii) so
11467 that it is not within a certain margin at the window's left and
11468 right border. Value is non-zero if any window's hscroll has been
11472 hscroll_window_tree (Lisp_Object window
)
11474 int hscrolled_p
= 0;
11475 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
11476 int hscroll_step_abs
= 0;
11477 double hscroll_step_rel
= 0;
11479 if (hscroll_relative_p
)
11481 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
11482 if (hscroll_step_rel
< 0)
11484 hscroll_relative_p
= 0;
11485 hscroll_step_abs
= 0;
11488 else if (INTEGERP (Vhscroll_step
))
11490 hscroll_step_abs
= XINT (Vhscroll_step
);
11491 if (hscroll_step_abs
< 0)
11492 hscroll_step_abs
= 0;
11495 hscroll_step_abs
= 0;
11497 while (WINDOWP (window
))
11499 struct window
*w
= XWINDOW (window
);
11501 if (WINDOWP (w
->hchild
))
11502 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11503 else if (WINDOWP (w
->vchild
))
11504 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11505 else if (w
->cursor
.vpos
>= 0)
11508 int text_area_width
;
11509 struct glyph_row
*current_cursor_row
11510 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11511 struct glyph_row
*desired_cursor_row
11512 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11513 struct glyph_row
*cursor_row
11514 = (desired_cursor_row
->enabled_p
11515 ? desired_cursor_row
11516 : current_cursor_row
);
11518 text_area_width
= window_box_width (w
, TEXT_AREA
);
11520 /* Scroll when cursor is inside this scroll margin. */
11521 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11523 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11524 && ((XFASTINT (w
->hscroll
)
11525 && w
->cursor
.x
<= h_margin
)
11526 || (cursor_row
->enabled_p
11527 && cursor_row
->truncated_on_right_p
11528 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11532 struct buffer
*saved_current_buffer
;
11536 /* Find point in a display of infinite width. */
11537 saved_current_buffer
= current_buffer
;
11538 current_buffer
= XBUFFER (w
->buffer
);
11540 if (w
== XWINDOW (selected_window
))
11544 pt
= marker_position (w
->pointm
);
11545 pt
= max (BEGV
, pt
);
11549 /* Move iterator to pt starting at cursor_row->start in
11550 a line with infinite width. */
11551 init_to_row_start (&it
, w
, cursor_row
);
11552 it
.last_visible_x
= INFINITY
;
11553 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11554 current_buffer
= saved_current_buffer
;
11556 /* Position cursor in window. */
11557 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11558 hscroll
= max (0, (it
.current_x
11559 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11560 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11561 : (text_area_width
/ 2))))
11562 / FRAME_COLUMN_WIDTH (it
.f
);
11563 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11565 if (hscroll_relative_p
)
11566 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11569 wanted_x
= text_area_width
11570 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11573 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11577 if (hscroll_relative_p
)
11578 wanted_x
= text_area_width
* hscroll_step_rel
11581 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11584 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11586 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11588 /* Don't call Fset_window_hscroll if value hasn't
11589 changed because it will prevent redisplay
11591 if (XFASTINT (w
->hscroll
) != hscroll
)
11593 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11594 w
->hscroll
= make_number (hscroll
);
11603 /* Value is non-zero if hscroll of any leaf window has been changed. */
11604 return hscrolled_p
;
11608 /* Set hscroll so that cursor is visible and not inside horizontal
11609 scroll margins for all windows in the tree rooted at WINDOW. See
11610 also hscroll_window_tree above. Value is non-zero if any window's
11611 hscroll has been changed. If it has, desired matrices on the frame
11612 of WINDOW are cleared. */
11615 hscroll_windows (Lisp_Object window
)
11617 int hscrolled_p
= hscroll_window_tree (window
);
11619 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11620 return hscrolled_p
;
11625 /************************************************************************
11627 ************************************************************************/
11629 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11630 to a non-zero value. This is sometimes handy to have in a debugger
11635 /* First and last unchanged row for try_window_id. */
11637 int debug_first_unchanged_at_end_vpos
;
11638 int debug_last_unchanged_at_beg_vpos
;
11640 /* Delta vpos and y. */
11642 int debug_dvpos
, debug_dy
;
11644 /* Delta in characters and bytes for try_window_id. */
11646 EMACS_INT debug_delta
, debug_delta_bytes
;
11648 /* Values of window_end_pos and window_end_vpos at the end of
11651 EMACS_INT debug_end_vpos
;
11653 /* Append a string to W->desired_matrix->method. FMT is a printf
11654 format string. A1...A9 are a supplement for a variable-length
11655 argument list. If trace_redisplay_p is non-zero also printf the
11656 resulting string to stderr. */
11659 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11662 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11665 char *method
= w
->desired_matrix
->method
;
11666 int len
= strlen (method
);
11667 int size
= sizeof w
->desired_matrix
->method
;
11668 int remaining
= size
- len
- 1;
11670 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11671 if (len
&& remaining
)
11674 --remaining
, ++len
;
11677 strncpy (method
+ len
, buffer
, remaining
);
11679 if (trace_redisplay_p
)
11680 fprintf (stderr
, "%p (%s): %s\n",
11682 ((BUFFERP (w
->buffer
)
11683 && STRINGP (XBUFFER (w
->buffer
)->name
))
11684 ? SSDATA (XBUFFER (w
->buffer
)->name
)
11689 #endif /* GLYPH_DEBUG */
11692 /* Value is non-zero if all changes in window W, which displays
11693 current_buffer, are in the text between START and END. START is a
11694 buffer position, END is given as a distance from Z. Used in
11695 redisplay_internal for display optimization. */
11698 text_outside_line_unchanged_p (struct window
*w
,
11699 EMACS_INT start
, EMACS_INT end
)
11701 int unchanged_p
= 1;
11703 /* If text or overlays have changed, see where. */
11704 if (XFASTINT (w
->last_modified
) < MODIFF
11705 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11707 /* Gap in the line? */
11708 if (GPT
< start
|| Z
- GPT
< end
)
11711 /* Changes start in front of the line, or end after it? */
11713 && (BEG_UNCHANGED
< start
- 1
11714 || END_UNCHANGED
< end
))
11717 /* If selective display, can't optimize if changes start at the
11718 beginning of the line. */
11720 && INTEGERP (BVAR (current_buffer
, selective_display
))
11721 && XINT (BVAR (current_buffer
, selective_display
)) > 0
11722 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11725 /* If there are overlays at the start or end of the line, these
11726 may have overlay strings with newlines in them. A change at
11727 START, for instance, may actually concern the display of such
11728 overlay strings as well, and they are displayed on different
11729 lines. So, quickly rule out this case. (For the future, it
11730 might be desirable to implement something more telling than
11731 just BEG/END_UNCHANGED.) */
11734 if (BEG
+ BEG_UNCHANGED
== start
11735 && overlay_touches_p (start
))
11737 if (END_UNCHANGED
== end
11738 && overlay_touches_p (Z
- end
))
11742 /* Under bidi reordering, adding or deleting a character in the
11743 beginning of a paragraph, before the first strong directional
11744 character, can change the base direction of the paragraph (unless
11745 the buffer specifies a fixed paragraph direction), which will
11746 require to redisplay the whole paragraph. It might be worthwhile
11747 to find the paragraph limits and widen the range of redisplayed
11748 lines to that, but for now just give up this optimization. */
11749 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
11750 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
11754 return unchanged_p
;
11758 /* Do a frame update, taking possible shortcuts into account. This is
11759 the main external entry point for redisplay.
11761 If the last redisplay displayed an echo area message and that message
11762 is no longer requested, we clear the echo area or bring back the
11763 mini-buffer if that is in use. */
11768 redisplay_internal ();
11773 overlay_arrow_string_or_property (Lisp_Object var
)
11777 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11780 return Voverlay_arrow_string
;
11783 /* Return 1 if there are any overlay-arrows in current_buffer. */
11785 overlay_arrow_in_current_buffer_p (void)
11789 for (vlist
= Voverlay_arrow_variable_list
;
11791 vlist
= XCDR (vlist
))
11793 Lisp_Object var
= XCAR (vlist
);
11796 if (!SYMBOLP (var
))
11798 val
= find_symbol_value (var
);
11800 && current_buffer
== XMARKER (val
)->buffer
)
11807 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11811 overlay_arrows_changed_p (void)
11815 for (vlist
= Voverlay_arrow_variable_list
;
11817 vlist
= XCDR (vlist
))
11819 Lisp_Object var
= XCAR (vlist
);
11820 Lisp_Object val
, pstr
;
11822 if (!SYMBOLP (var
))
11824 val
= find_symbol_value (var
);
11825 if (!MARKERP (val
))
11827 if (! EQ (COERCE_MARKER (val
),
11828 Fget (var
, Qlast_arrow_position
))
11829 || ! (pstr
= overlay_arrow_string_or_property (var
),
11830 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11836 /* Mark overlay arrows to be updated on next redisplay. */
11839 update_overlay_arrows (int up_to_date
)
11843 for (vlist
= Voverlay_arrow_variable_list
;
11845 vlist
= XCDR (vlist
))
11847 Lisp_Object var
= XCAR (vlist
);
11849 if (!SYMBOLP (var
))
11852 if (up_to_date
> 0)
11854 Lisp_Object val
= find_symbol_value (var
);
11855 Fput (var
, Qlast_arrow_position
,
11856 COERCE_MARKER (val
));
11857 Fput (var
, Qlast_arrow_string
,
11858 overlay_arrow_string_or_property (var
));
11860 else if (up_to_date
< 0
11861 || !NILP (Fget (var
, Qlast_arrow_position
)))
11863 Fput (var
, Qlast_arrow_position
, Qt
);
11864 Fput (var
, Qlast_arrow_string
, Qt
);
11870 /* Return overlay arrow string to display at row.
11871 Return integer (bitmap number) for arrow bitmap in left fringe.
11872 Return nil if no overlay arrow. */
11875 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
11879 for (vlist
= Voverlay_arrow_variable_list
;
11881 vlist
= XCDR (vlist
))
11883 Lisp_Object var
= XCAR (vlist
);
11886 if (!SYMBOLP (var
))
11889 val
= find_symbol_value (var
);
11892 && current_buffer
== XMARKER (val
)->buffer
11893 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11895 if (FRAME_WINDOW_P (it
->f
)
11896 /* FIXME: if ROW->reversed_p is set, this should test
11897 the right fringe, not the left one. */
11898 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11900 #ifdef HAVE_WINDOW_SYSTEM
11901 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11904 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11905 return make_number (fringe_bitmap
);
11908 return make_number (-1); /* Use default arrow bitmap */
11910 return overlay_arrow_string_or_property (var
);
11917 /* Return 1 if point moved out of or into a composition. Otherwise
11918 return 0. PREV_BUF and PREV_PT are the last point buffer and
11919 position. BUF and PT are the current point buffer and position. */
11922 check_point_in_composition (struct buffer
*prev_buf
, EMACS_INT prev_pt
,
11923 struct buffer
*buf
, EMACS_INT pt
)
11925 EMACS_INT start
, end
;
11927 Lisp_Object buffer
;
11929 XSETBUFFER (buffer
, buf
);
11930 /* Check a composition at the last point if point moved within the
11932 if (prev_buf
== buf
)
11935 /* Point didn't move. */
11938 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11939 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11940 && COMPOSITION_VALID_P (start
, end
, prop
)
11941 && start
< prev_pt
&& end
> prev_pt
)
11942 /* The last point was within the composition. Return 1 iff
11943 point moved out of the composition. */
11944 return (pt
<= start
|| pt
>= end
);
11947 /* Check a composition at the current point. */
11948 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11949 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11950 && COMPOSITION_VALID_P (start
, end
, prop
)
11951 && start
< pt
&& end
> pt
);
11955 /* Reconsider the setting of B->clip_changed which is displayed
11959 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
11961 if (b
->clip_changed
11962 && !NILP (w
->window_end_valid
)
11963 && w
->current_matrix
->buffer
== b
11964 && w
->current_matrix
->zv
== BUF_ZV (b
)
11965 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11966 b
->clip_changed
= 0;
11968 /* If display wasn't paused, and W is not a tool bar window, see if
11969 point has been moved into or out of a composition. In that case,
11970 we set b->clip_changed to 1 to force updating the screen. If
11971 b->clip_changed has already been set to 1, we can skip this
11973 if (!b
->clip_changed
11974 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11978 if (w
== XWINDOW (selected_window
))
11981 pt
= marker_position (w
->pointm
);
11983 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11984 || pt
!= XINT (w
->last_point
))
11985 && check_point_in_composition (w
->current_matrix
->buffer
,
11986 XINT (w
->last_point
),
11987 XBUFFER (w
->buffer
), pt
))
11988 b
->clip_changed
= 1;
11993 /* Select FRAME to forward the values of frame-local variables into C
11994 variables so that the redisplay routines can access those values
11998 select_frame_for_redisplay (Lisp_Object frame
)
12000 Lisp_Object tail
, tem
;
12001 Lisp_Object old
= selected_frame
;
12002 struct Lisp_Symbol
*sym
;
12004 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12006 selected_frame
= frame
;
12009 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
12010 if (CONSP (XCAR (tail
))
12011 && (tem
= XCAR (XCAR (tail
)),
12013 && (sym
= indirect_variable (XSYMBOL (tem
)),
12014 sym
->redirect
== SYMBOL_LOCALIZED
)
12015 && sym
->val
.blv
->frame_local
)
12016 /* Use find_symbol_value rather than Fsymbol_value
12017 to avoid an error if it is void. */
12018 find_symbol_value (tem
);
12019 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12023 #define STOP_POLLING \
12024 do { if (! polling_stopped_here) stop_polling (); \
12025 polling_stopped_here = 1; } while (0)
12027 #define RESUME_POLLING \
12028 do { if (polling_stopped_here) start_polling (); \
12029 polling_stopped_here = 0; } while (0)
12032 /* Perhaps in the future avoid recentering windows if it
12033 is not necessary; currently that causes some problems. */
12036 redisplay_internal (void)
12038 struct window
*w
= XWINDOW (selected_window
);
12042 int must_finish
= 0;
12043 struct text_pos tlbufpos
, tlendpos
;
12044 int number_of_visible_frames
;
12047 int polling_stopped_here
= 0;
12048 Lisp_Object old_frame
= selected_frame
;
12050 /* Non-zero means redisplay has to consider all windows on all
12051 frames. Zero means, only selected_window is considered. */
12052 int consider_all_windows_p
;
12054 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12056 /* No redisplay if running in batch mode or frame is not yet fully
12057 initialized, or redisplay is explicitly turned off by setting
12058 Vinhibit_redisplay. */
12059 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12060 || !NILP (Vinhibit_redisplay
))
12063 /* Don't examine these until after testing Vinhibit_redisplay.
12064 When Emacs is shutting down, perhaps because its connection to
12065 X has dropped, we should not look at them at all. */
12066 fr
= XFRAME (w
->frame
);
12067 sf
= SELECTED_FRAME ();
12069 if (!fr
->glyphs_initialized_p
)
12072 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12073 if (popup_activated ())
12077 /* I don't think this happens but let's be paranoid. */
12078 if (redisplaying_p
)
12081 /* Record a function that resets redisplaying_p to its old value
12082 when we leave this function. */
12083 count
= SPECPDL_INDEX ();
12084 record_unwind_protect (unwind_redisplay
,
12085 Fcons (make_number (redisplaying_p
), selected_frame
));
12087 specbind (Qinhibit_free_realized_faces
, Qnil
);
12090 Lisp_Object tail
, frame
;
12092 FOR_EACH_FRAME (tail
, frame
)
12094 struct frame
*f
= XFRAME (frame
);
12095 f
->already_hscrolled_p
= 0;
12100 /* Remember the currently selected window. */
12103 if (!EQ (old_frame
, selected_frame
)
12104 && FRAME_LIVE_P (XFRAME (old_frame
)))
12105 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12106 selected_frame and selected_window to be temporarily out-of-sync so
12107 when we come back here via `goto retry', we need to resync because we
12108 may need to run Elisp code (via prepare_menu_bars). */
12109 select_frame_for_redisplay (old_frame
);
12112 reconsider_clip_changes (w
, current_buffer
);
12113 last_escape_glyph_frame
= NULL
;
12114 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12115 last_glyphless_glyph_frame
= NULL
;
12116 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12118 /* If new fonts have been loaded that make a glyph matrix adjustment
12119 necessary, do it. */
12120 if (fonts_changed_p
)
12122 adjust_glyphs (NULL
);
12123 ++windows_or_buffers_changed
;
12124 fonts_changed_p
= 0;
12127 /* If face_change_count is non-zero, init_iterator will free all
12128 realized faces, which includes the faces referenced from current
12129 matrices. So, we can't reuse current matrices in this case. */
12130 if (face_change_count
)
12131 ++windows_or_buffers_changed
;
12133 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12134 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12136 /* Since frames on a single ASCII terminal share the same
12137 display area, displaying a different frame means redisplay
12138 the whole thing. */
12139 windows_or_buffers_changed
++;
12140 SET_FRAME_GARBAGED (sf
);
12142 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12144 FRAME_TTY (sf
)->previous_frame
= sf
;
12147 /* Set the visible flags for all frames. Do this before checking
12148 for resized or garbaged frames; they want to know if their frames
12149 are visible. See the comment in frame.h for
12150 FRAME_SAMPLE_VISIBILITY. */
12152 Lisp_Object tail
, frame
;
12154 number_of_visible_frames
= 0;
12156 FOR_EACH_FRAME (tail
, frame
)
12158 struct frame
*f
= XFRAME (frame
);
12160 FRAME_SAMPLE_VISIBILITY (f
);
12161 if (FRAME_VISIBLE_P (f
))
12162 ++number_of_visible_frames
;
12163 clear_desired_matrices (f
);
12167 /* Notice any pending interrupt request to change frame size. */
12168 do_pending_window_change (1);
12170 /* do_pending_window_change could change the selected_window due to
12171 frame resizing which makes the selected window too small. */
12172 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12175 reconsider_clip_changes (w
, current_buffer
);
12178 /* Clear frames marked as garbaged. */
12179 if (frame_garbaged
)
12180 clear_garbaged_frames ();
12182 /* Build menubar and tool-bar items. */
12183 if (NILP (Vmemory_full
))
12184 prepare_menu_bars ();
12186 if (windows_or_buffers_changed
)
12187 update_mode_lines
++;
12189 /* Detect case that we need to write or remove a star in the mode line. */
12190 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
12192 w
->update_mode_line
= Qt
;
12193 if (buffer_shared
> 1)
12194 update_mode_lines
++;
12197 /* Avoid invocation of point motion hooks by `current_column' below. */
12198 count1
= SPECPDL_INDEX ();
12199 specbind (Qinhibit_point_motion_hooks
, Qt
);
12201 /* If %c is in the mode line, update it if needed. */
12202 if (!NILP (w
->column_number_displayed
)
12203 /* This alternative quickly identifies a common case
12204 where no change is needed. */
12205 && !(PT
== XFASTINT (w
->last_point
)
12206 && XFASTINT (w
->last_modified
) >= MODIFF
12207 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12208 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
12209 w
->update_mode_line
= Qt
;
12211 unbind_to (count1
, Qnil
);
12213 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
12215 /* The variable buffer_shared is set in redisplay_window and
12216 indicates that we redisplay a buffer in different windows. See
12218 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
12219 || cursor_type_changed
);
12221 /* If specs for an arrow have changed, do thorough redisplay
12222 to ensure we remove any arrow that should no longer exist. */
12223 if (overlay_arrows_changed_p ())
12224 consider_all_windows_p
= windows_or_buffers_changed
= 1;
12226 /* Normally the message* functions will have already displayed and
12227 updated the echo area, but the frame may have been trashed, or
12228 the update may have been preempted, so display the echo area
12229 again here. Checking message_cleared_p captures the case that
12230 the echo area should be cleared. */
12231 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
12232 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
12233 || (message_cleared_p
12234 && minibuf_level
== 0
12235 /* If the mini-window is currently selected, this means the
12236 echo-area doesn't show through. */
12237 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
12239 int window_height_changed_p
= echo_area_display (0);
12242 /* If we don't display the current message, don't clear the
12243 message_cleared_p flag, because, if we did, we wouldn't clear
12244 the echo area in the next redisplay which doesn't preserve
12246 if (!display_last_displayed_message_p
)
12247 message_cleared_p
= 0;
12249 if (fonts_changed_p
)
12251 else if (window_height_changed_p
)
12253 consider_all_windows_p
= 1;
12254 ++update_mode_lines
;
12255 ++windows_or_buffers_changed
;
12257 /* If window configuration was changed, frames may have been
12258 marked garbaged. Clear them or we will experience
12259 surprises wrt scrolling. */
12260 if (frame_garbaged
)
12261 clear_garbaged_frames ();
12264 else if (EQ (selected_window
, minibuf_window
)
12265 && (current_buffer
->clip_changed
12266 || XFASTINT (w
->last_modified
) < MODIFF
12267 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12268 && resize_mini_window (w
, 0))
12270 /* Resized active mini-window to fit the size of what it is
12271 showing if its contents might have changed. */
12273 /* FIXME: this causes all frames to be updated, which seems unnecessary
12274 since only the current frame needs to be considered. This function needs
12275 to be rewritten with two variables, consider_all_windows and
12276 consider_all_frames. */
12277 consider_all_windows_p
= 1;
12278 ++windows_or_buffers_changed
;
12279 ++update_mode_lines
;
12281 /* If window configuration was changed, frames may have been
12282 marked garbaged. Clear them or we will experience
12283 surprises wrt scrolling. */
12284 if (frame_garbaged
)
12285 clear_garbaged_frames ();
12289 /* If showing the region, and mark has changed, we must redisplay
12290 the whole window. The assignment to this_line_start_pos prevents
12291 the optimization directly below this if-statement. */
12292 if (((!NILP (Vtransient_mark_mode
)
12293 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
12294 != !NILP (w
->region_showing
))
12295 || (!NILP (w
->region_showing
)
12296 && !EQ (w
->region_showing
,
12297 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
12298 CHARPOS (this_line_start_pos
) = 0;
12300 /* Optimize the case that only the line containing the cursor in the
12301 selected window has changed. Variables starting with this_ are
12302 set in display_line and record information about the line
12303 containing the cursor. */
12304 tlbufpos
= this_line_start_pos
;
12305 tlendpos
= this_line_end_pos
;
12306 if (!consider_all_windows_p
12307 && CHARPOS (tlbufpos
) > 0
12308 && NILP (w
->update_mode_line
)
12309 && !current_buffer
->clip_changed
12310 && !current_buffer
->prevent_redisplay_optimizations_p
12311 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
12312 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
12313 /* Make sure recorded data applies to current buffer, etc. */
12314 && this_line_buffer
== current_buffer
12315 && current_buffer
== XBUFFER (w
->buffer
)
12316 && NILP (w
->force_start
)
12317 && NILP (w
->optional_new_start
)
12318 /* Point must be on the line that we have info recorded about. */
12319 && PT
>= CHARPOS (tlbufpos
)
12320 && PT
<= Z
- CHARPOS (tlendpos
)
12321 /* All text outside that line, including its final newline,
12322 must be unchanged. */
12323 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
12324 CHARPOS (tlendpos
)))
12326 if (CHARPOS (tlbufpos
) > BEGV
12327 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
12328 && (CHARPOS (tlbufpos
) == ZV
12329 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
12330 /* Former continuation line has disappeared by becoming empty. */
12332 else if (XFASTINT (w
->last_modified
) < MODIFF
12333 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
12334 || MINI_WINDOW_P (w
))
12336 /* We have to handle the case of continuation around a
12337 wide-column character (see the comment in indent.c around
12340 For instance, in the following case:
12342 -------- Insert --------
12343 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
12344 J_I_ ==> J_I_ `^^' are cursors.
12348 As we have to redraw the line above, we cannot use this
12352 int line_height_before
= this_line_pixel_height
;
12354 /* Note that start_display will handle the case that the
12355 line starting at tlbufpos is a continuation line. */
12356 start_display (&it
, w
, tlbufpos
);
12358 /* Implementation note: It this still necessary? */
12359 if (it
.current_x
!= this_line_start_x
)
12362 TRACE ((stderr
, "trying display optimization 1\n"));
12363 w
->cursor
.vpos
= -1;
12364 overlay_arrow_seen
= 0;
12365 it
.vpos
= this_line_vpos
;
12366 it
.current_y
= this_line_y
;
12367 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
12368 display_line (&it
);
12370 /* If line contains point, is not continued,
12371 and ends at same distance from eob as before, we win. */
12372 if (w
->cursor
.vpos
>= 0
12373 /* Line is not continued, otherwise this_line_start_pos
12374 would have been set to 0 in display_line. */
12375 && CHARPOS (this_line_start_pos
)
12376 /* Line ends as before. */
12377 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
12378 /* Line has same height as before. Otherwise other lines
12379 would have to be shifted up or down. */
12380 && this_line_pixel_height
== line_height_before
)
12382 /* If this is not the window's last line, we must adjust
12383 the charstarts of the lines below. */
12384 if (it
.current_y
< it
.last_visible_y
)
12386 struct glyph_row
*row
12387 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
12388 EMACS_INT delta
, delta_bytes
;
12390 /* We used to distinguish between two cases here,
12391 conditioned by Z - CHARPOS (tlendpos) == ZV, for
12392 when the line ends in a newline or the end of the
12393 buffer's accessible portion. But both cases did
12394 the same, so they were collapsed. */
12396 - CHARPOS (tlendpos
)
12397 - MATRIX_ROW_START_CHARPOS (row
));
12398 delta_bytes
= (Z_BYTE
12399 - BYTEPOS (tlendpos
)
12400 - MATRIX_ROW_START_BYTEPOS (row
));
12402 increment_matrix_positions (w
->current_matrix
,
12403 this_line_vpos
+ 1,
12404 w
->current_matrix
->nrows
,
12405 delta
, delta_bytes
);
12408 /* If this row displays text now but previously didn't,
12409 or vice versa, w->window_end_vpos may have to be
12411 if ((it
.glyph_row
- 1)->displays_text_p
)
12413 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
12414 XSETINT (w
->window_end_vpos
, this_line_vpos
);
12416 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
12417 && this_line_vpos
> 0)
12418 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
12419 w
->window_end_valid
= Qnil
;
12421 /* Update hint: No need to try to scroll in update_window. */
12422 w
->desired_matrix
->no_scrolling_p
= 1;
12425 *w
->desired_matrix
->method
= 0;
12426 debug_method_add (w
, "optimization 1");
12428 #ifdef HAVE_WINDOW_SYSTEM
12429 update_window_fringes (w
, 0);
12436 else if (/* Cursor position hasn't changed. */
12437 PT
== XFASTINT (w
->last_point
)
12438 /* Make sure the cursor was last displayed
12439 in this window. Otherwise we have to reposition it. */
12440 && 0 <= w
->cursor
.vpos
12441 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
12445 do_pending_window_change (1);
12446 /* If selected_window changed, redisplay again. */
12447 if (WINDOWP (selected_window
)
12448 && (w
= XWINDOW (selected_window
)) != sw
)
12451 /* We used to always goto end_of_redisplay here, but this
12452 isn't enough if we have a blinking cursor. */
12453 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
12454 goto end_of_redisplay
;
12458 /* If highlighting the region, or if the cursor is in the echo area,
12459 then we can't just move the cursor. */
12460 else if (! (!NILP (Vtransient_mark_mode
)
12461 && !NILP (BVAR (current_buffer
, mark_active
)))
12462 && (EQ (selected_window
, BVAR (current_buffer
, last_selected_window
))
12463 || highlight_nonselected_windows
)
12464 && NILP (w
->region_showing
)
12465 && NILP (Vshow_trailing_whitespace
)
12466 && !cursor_in_echo_area
)
12469 struct glyph_row
*row
;
12471 /* Skip from tlbufpos to PT and see where it is. Note that
12472 PT may be in invisible text. If so, we will end at the
12473 next visible position. */
12474 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
12475 NULL
, DEFAULT_FACE_ID
);
12476 it
.current_x
= this_line_start_x
;
12477 it
.current_y
= this_line_y
;
12478 it
.vpos
= this_line_vpos
;
12480 /* The call to move_it_to stops in front of PT, but
12481 moves over before-strings. */
12482 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
12484 if (it
.vpos
== this_line_vpos
12485 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12488 xassert (this_line_vpos
== it
.vpos
);
12489 xassert (this_line_y
== it
.current_y
);
12490 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12492 *w
->desired_matrix
->method
= 0;
12493 debug_method_add (w
, "optimization 3");
12502 /* Text changed drastically or point moved off of line. */
12503 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12506 CHARPOS (this_line_start_pos
) = 0;
12507 consider_all_windows_p
|= buffer_shared
> 1;
12508 ++clear_face_cache_count
;
12509 #ifdef HAVE_WINDOW_SYSTEM
12510 ++clear_image_cache_count
;
12513 /* Build desired matrices, and update the display. If
12514 consider_all_windows_p is non-zero, do it for all windows on all
12515 frames. Otherwise do it for selected_window, only. */
12517 if (consider_all_windows_p
)
12519 Lisp_Object tail
, frame
;
12521 FOR_EACH_FRAME (tail
, frame
)
12522 XFRAME (frame
)->updated_p
= 0;
12524 /* Recompute # windows showing selected buffer. This will be
12525 incremented each time such a window is displayed. */
12528 FOR_EACH_FRAME (tail
, frame
)
12530 struct frame
*f
= XFRAME (frame
);
12532 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12534 if (! EQ (frame
, selected_frame
))
12535 /* Select the frame, for the sake of frame-local
12537 select_frame_for_redisplay (frame
);
12539 /* Mark all the scroll bars to be removed; we'll redeem
12540 the ones we want when we redisplay their windows. */
12541 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12542 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12544 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12545 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12547 /* The X error handler may have deleted that frame. */
12548 if (!FRAME_LIVE_P (f
))
12551 /* Any scroll bars which redisplay_windows should have
12552 nuked should now go away. */
12553 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12554 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12556 /* If fonts changed, display again. */
12557 /* ??? rms: I suspect it is a mistake to jump all the way
12558 back to retry here. It should just retry this frame. */
12559 if (fonts_changed_p
)
12562 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12564 /* See if we have to hscroll. */
12565 if (!f
->already_hscrolled_p
)
12567 f
->already_hscrolled_p
= 1;
12568 if (hscroll_windows (f
->root_window
))
12572 /* Prevent various kinds of signals during display
12573 update. stdio is not robust about handling
12574 signals, which can cause an apparent I/O
12576 if (interrupt_input
)
12577 unrequest_sigio ();
12580 /* Update the display. */
12581 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12582 pending
|= update_frame (f
, 0, 0);
12588 if (!EQ (old_frame
, selected_frame
)
12589 && FRAME_LIVE_P (XFRAME (old_frame
)))
12590 /* We played a bit fast-and-loose above and allowed selected_frame
12591 and selected_window to be temporarily out-of-sync but let's make
12592 sure this stays contained. */
12593 select_frame_for_redisplay (old_frame
);
12594 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12598 /* Do the mark_window_display_accurate after all windows have
12599 been redisplayed because this call resets flags in buffers
12600 which are needed for proper redisplay. */
12601 FOR_EACH_FRAME (tail
, frame
)
12603 struct frame
*f
= XFRAME (frame
);
12606 mark_window_display_accurate (f
->root_window
, 1);
12607 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12608 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12613 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12615 Lisp_Object mini_window
;
12616 struct frame
*mini_frame
;
12618 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12619 /* Use list_of_error, not Qerror, so that
12620 we catch only errors and don't run the debugger. */
12621 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12623 redisplay_window_error
);
12625 /* Compare desired and current matrices, perform output. */
12628 /* If fonts changed, display again. */
12629 if (fonts_changed_p
)
12632 /* Prevent various kinds of signals during display update.
12633 stdio is not robust about handling signals,
12634 which can cause an apparent I/O error. */
12635 if (interrupt_input
)
12636 unrequest_sigio ();
12639 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12641 if (hscroll_windows (selected_window
))
12644 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12645 pending
= update_frame (sf
, 0, 0);
12648 /* We may have called echo_area_display at the top of this
12649 function. If the echo area is on another frame, that may
12650 have put text on a frame other than the selected one, so the
12651 above call to update_frame would not have caught it. Catch
12653 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12654 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12656 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12658 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12659 pending
|= update_frame (mini_frame
, 0, 0);
12660 if (!pending
&& hscroll_windows (mini_window
))
12665 /* If display was paused because of pending input, make sure we do a
12666 thorough update the next time. */
12669 /* Prevent the optimization at the beginning of
12670 redisplay_internal that tries a single-line update of the
12671 line containing the cursor in the selected window. */
12672 CHARPOS (this_line_start_pos
) = 0;
12674 /* Let the overlay arrow be updated the next time. */
12675 update_overlay_arrows (0);
12677 /* If we pause after scrolling, some rows in the current
12678 matrices of some windows are not valid. */
12679 if (!WINDOW_FULL_WIDTH_P (w
)
12680 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12681 update_mode_lines
= 1;
12685 if (!consider_all_windows_p
)
12687 /* This has already been done above if
12688 consider_all_windows_p is set. */
12689 mark_window_display_accurate_1 (w
, 1);
12691 /* Say overlay arrows are up to date. */
12692 update_overlay_arrows (1);
12694 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12695 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12698 update_mode_lines
= 0;
12699 windows_or_buffers_changed
= 0;
12700 cursor_type_changed
= 0;
12703 /* Start SIGIO interrupts coming again. Having them off during the
12704 code above makes it less likely one will discard output, but not
12705 impossible, since there might be stuff in the system buffer here.
12706 But it is much hairier to try to do anything about that. */
12707 if (interrupt_input
)
12711 /* If a frame has become visible which was not before, redisplay
12712 again, so that we display it. Expose events for such a frame
12713 (which it gets when becoming visible) don't call the parts of
12714 redisplay constructing glyphs, so simply exposing a frame won't
12715 display anything in this case. So, we have to display these
12716 frames here explicitly. */
12719 Lisp_Object tail
, frame
;
12722 FOR_EACH_FRAME (tail
, frame
)
12724 int this_is_visible
= 0;
12726 if (XFRAME (frame
)->visible
)
12727 this_is_visible
= 1;
12728 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12729 if (XFRAME (frame
)->visible
)
12730 this_is_visible
= 1;
12732 if (this_is_visible
)
12736 if (new_count
!= number_of_visible_frames
)
12737 windows_or_buffers_changed
++;
12740 /* Change frame size now if a change is pending. */
12741 do_pending_window_change (1);
12743 /* If we just did a pending size change, or have additional
12744 visible frames, or selected_window changed, redisplay again. */
12745 if ((windows_or_buffers_changed
&& !pending
)
12746 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
12749 /* Clear the face and image caches.
12751 We used to do this only if consider_all_windows_p. But the cache
12752 needs to be cleared if a timer creates images in the current
12753 buffer (e.g. the test case in Bug#6230). */
12755 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12757 clear_face_cache (0);
12758 clear_face_cache_count
= 0;
12761 #ifdef HAVE_WINDOW_SYSTEM
12762 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12764 clear_image_caches (Qnil
);
12765 clear_image_cache_count
= 0;
12767 #endif /* HAVE_WINDOW_SYSTEM */
12770 unbind_to (count
, Qnil
);
12775 /* Redisplay, but leave alone any recent echo area message unless
12776 another message has been requested in its place.
12778 This is useful in situations where you need to redisplay but no
12779 user action has occurred, making it inappropriate for the message
12780 area to be cleared. See tracking_off and
12781 wait_reading_process_output for examples of these situations.
12783 FROM_WHERE is an integer saying from where this function was
12784 called. This is useful for debugging. */
12787 redisplay_preserve_echo_area (int from_where
)
12789 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12791 if (!NILP (echo_area_buffer
[1]))
12793 /* We have a previously displayed message, but no current
12794 message. Redisplay the previous message. */
12795 display_last_displayed_message_p
= 1;
12796 redisplay_internal ();
12797 display_last_displayed_message_p
= 0;
12800 redisplay_internal ();
12802 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12803 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12804 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12808 /* Function registered with record_unwind_protect in
12809 redisplay_internal. Reset redisplaying_p to the value it had
12810 before redisplay_internal was called, and clear
12811 prevent_freeing_realized_faces_p. It also selects the previously
12812 selected frame, unless it has been deleted (by an X connection
12813 failure during redisplay, for example). */
12816 unwind_redisplay (Lisp_Object val
)
12818 Lisp_Object old_redisplaying_p
, old_frame
;
12820 old_redisplaying_p
= XCAR (val
);
12821 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12822 old_frame
= XCDR (val
);
12823 if (! EQ (old_frame
, selected_frame
)
12824 && FRAME_LIVE_P (XFRAME (old_frame
)))
12825 select_frame_for_redisplay (old_frame
);
12830 /* Mark the display of window W as accurate or inaccurate. If
12831 ACCURATE_P is non-zero mark display of W as accurate. If
12832 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12833 redisplay_internal is called. */
12836 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
12838 if (BUFFERP (w
->buffer
))
12840 struct buffer
*b
= XBUFFER (w
->buffer
);
12843 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12844 w
->last_overlay_modified
12845 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12847 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12851 b
->clip_changed
= 0;
12852 b
->prevent_redisplay_optimizations_p
= 0;
12854 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12855 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12856 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12857 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12859 w
->current_matrix
->buffer
= b
;
12860 w
->current_matrix
->begv
= BUF_BEGV (b
);
12861 w
->current_matrix
->zv
= BUF_ZV (b
);
12863 w
->last_cursor
= w
->cursor
;
12864 w
->last_cursor_off_p
= w
->cursor_off_p
;
12866 if (w
== XWINDOW (selected_window
))
12867 w
->last_point
= make_number (BUF_PT (b
));
12869 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12875 w
->window_end_valid
= w
->buffer
;
12876 w
->update_mode_line
= Qnil
;
12881 /* Mark the display of windows in the window tree rooted at WINDOW as
12882 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12883 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12884 be redisplayed the next time redisplay_internal is called. */
12887 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
12891 for (; !NILP (window
); window
= w
->next
)
12893 w
= XWINDOW (window
);
12894 mark_window_display_accurate_1 (w
, accurate_p
);
12896 if (!NILP (w
->vchild
))
12897 mark_window_display_accurate (w
->vchild
, accurate_p
);
12898 if (!NILP (w
->hchild
))
12899 mark_window_display_accurate (w
->hchild
, accurate_p
);
12904 update_overlay_arrows (1);
12908 /* Force a thorough redisplay the next time by setting
12909 last_arrow_position and last_arrow_string to t, which is
12910 unequal to any useful value of Voverlay_arrow_... */
12911 update_overlay_arrows (-1);
12916 /* Return value in display table DP (Lisp_Char_Table *) for character
12917 C. Since a display table doesn't have any parent, we don't have to
12918 follow parent. Do not call this function directly but use the
12919 macro DISP_CHAR_VECTOR. */
12922 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
12926 if (ASCII_CHAR_P (c
))
12929 if (SUB_CHAR_TABLE_P (val
))
12930 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12936 XSETCHAR_TABLE (table
, dp
);
12937 val
= char_table_ref (table
, c
);
12946 /***********************************************************************
12948 ***********************************************************************/
12950 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12953 redisplay_windows (Lisp_Object window
)
12955 while (!NILP (window
))
12957 struct window
*w
= XWINDOW (window
);
12959 if (!NILP (w
->hchild
))
12960 redisplay_windows (w
->hchild
);
12961 else if (!NILP (w
->vchild
))
12962 redisplay_windows (w
->vchild
);
12963 else if (!NILP (w
->buffer
))
12965 displayed_buffer
= XBUFFER (w
->buffer
);
12966 /* Use list_of_error, not Qerror, so that
12967 we catch only errors and don't run the debugger. */
12968 internal_condition_case_1 (redisplay_window_0
, window
,
12970 redisplay_window_error
);
12978 redisplay_window_error (Lisp_Object ignore
)
12980 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12985 redisplay_window_0 (Lisp_Object window
)
12987 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12988 redisplay_window (window
, 0);
12993 redisplay_window_1 (Lisp_Object window
)
12995 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12996 redisplay_window (window
, 1);
13001 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13002 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13003 which positions recorded in ROW differ from current buffer
13006 Return 0 if cursor is not on this row, 1 otherwise. */
13009 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13010 struct glyph_matrix
*matrix
,
13011 EMACS_INT delta
, EMACS_INT delta_bytes
,
13014 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13015 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13016 struct glyph
*cursor
= NULL
;
13017 /* The last known character position in row. */
13018 EMACS_INT last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13020 EMACS_INT pt_old
= PT
- delta
;
13021 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13022 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13023 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13024 /* A glyph beyond the edge of TEXT_AREA which we should never
13026 struct glyph
*glyphs_end
= end
;
13027 /* Non-zero means we've found a match for cursor position, but that
13028 glyph has the avoid_cursor_p flag set. */
13029 int match_with_avoid_cursor
= 0;
13030 /* Non-zero means we've seen at least one glyph that came from a
13032 int string_seen
= 0;
13033 /* Largest and smalles buffer positions seen so far during scan of
13035 EMACS_INT bpos_max
= pos_before
;
13036 EMACS_INT bpos_min
= pos_after
;
13037 /* Last buffer position covered by an overlay string with an integer
13038 `cursor' property. */
13039 EMACS_INT bpos_covered
= 0;
13041 /* Skip over glyphs not having an object at the start and the end of
13042 the row. These are special glyphs like truncation marks on
13043 terminal frames. */
13044 if (row
->displays_text_p
)
13046 if (!row
->reversed_p
)
13049 && INTEGERP (glyph
->object
)
13050 && glyph
->charpos
< 0)
13052 x
+= glyph
->pixel_width
;
13056 && INTEGERP ((end
- 1)->object
)
13057 /* CHARPOS is zero for blanks and stretch glyphs
13058 inserted by extend_face_to_end_of_line. */
13059 && (end
- 1)->charpos
<= 0)
13061 glyph_before
= glyph
- 1;
13068 /* If the glyph row is reversed, we need to process it from back
13069 to front, so swap the edge pointers. */
13070 glyphs_end
= end
= glyph
- 1;
13071 glyph
+= row
->used
[TEXT_AREA
] - 1;
13073 while (glyph
> end
+ 1
13074 && INTEGERP (glyph
->object
)
13075 && glyph
->charpos
< 0)
13078 x
-= glyph
->pixel_width
;
13080 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13082 /* By default, in reversed rows we put the cursor on the
13083 rightmost (first in the reading order) glyph. */
13084 for (g
= end
+ 1; g
< glyph
; g
++)
13085 x
+= g
->pixel_width
;
13087 && INTEGERP ((end
+ 1)->object
)
13088 && (end
+ 1)->charpos
<= 0)
13090 glyph_before
= glyph
+ 1;
13094 else if (row
->reversed_p
)
13096 /* In R2L rows that don't display text, put the cursor on the
13097 rightmost glyph. Case in point: an empty last line that is
13098 part of an R2L paragraph. */
13100 /* Avoid placing the cursor on the last glyph of the row, where
13101 on terminal frames we hold the vertical border between
13102 adjacent windows. */
13103 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13104 && !WINDOW_RIGHTMOST_P (w
)
13105 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13107 x
= -1; /* will be computed below, at label compute_x */
13110 /* Step 1: Try to find the glyph whose character position
13111 corresponds to point. If that's not possible, find 2 glyphs
13112 whose character positions are the closest to point, one before
13113 point, the other after it. */
13114 if (!row
->reversed_p
)
13115 while (/* not marched to end of glyph row */
13117 /* glyph was not inserted by redisplay for internal purposes */
13118 && !INTEGERP (glyph
->object
))
13120 if (BUFFERP (glyph
->object
))
13122 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
13124 if (glyph
->charpos
> bpos_max
)
13125 bpos_max
= glyph
->charpos
;
13126 if (glyph
->charpos
< bpos_min
)
13127 bpos_min
= glyph
->charpos
;
13128 if (!glyph
->avoid_cursor_p
)
13130 /* If we hit point, we've found the glyph on which to
13131 display the cursor. */
13134 match_with_avoid_cursor
= 0;
13137 /* See if we've found a better approximation to
13138 POS_BEFORE or to POS_AFTER. Note that we want the
13139 first (leftmost) glyph of all those that are the
13140 closest from below, and the last (rightmost) of all
13141 those from above. */
13142 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13144 pos_before
= glyph
->charpos
;
13145 glyph_before
= glyph
;
13147 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13149 pos_after
= glyph
->charpos
;
13150 glyph_after
= glyph
;
13153 else if (dpos
== 0)
13154 match_with_avoid_cursor
= 1;
13156 else if (STRINGP (glyph
->object
))
13158 Lisp_Object chprop
;
13159 EMACS_INT glyph_pos
= glyph
->charpos
;
13161 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13163 if (INTEGERP (chprop
))
13165 bpos_covered
= bpos_max
+ XINT (chprop
);
13166 /* If the `cursor' property covers buffer positions up
13167 to and including point, we should display cursor on
13168 this glyph. Note that overlays and text properties
13169 with string values stop bidi reordering, so every
13170 buffer position to the left of the string is always
13171 smaller than any position to the right of the
13172 string. Therefore, if a `cursor' property on one
13173 of the string's characters has an integer value, we
13174 will break out of the loop below _before_ we get to
13175 the position match above. IOW, integer values of
13176 the `cursor' property override the "exact match for
13177 point" strategy of positioning the cursor. */
13178 /* Implementation note: bpos_max == pt_old when, e.g.,
13179 we are in an empty line, where bpos_max is set to
13180 MATRIX_ROW_START_CHARPOS, see above. */
13181 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13190 x
+= glyph
->pixel_width
;
13193 else if (glyph
> end
) /* row is reversed */
13194 while (!INTEGERP (glyph
->object
))
13196 if (BUFFERP (glyph
->object
))
13198 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
13200 if (glyph
->charpos
> bpos_max
)
13201 bpos_max
= glyph
->charpos
;
13202 if (glyph
->charpos
< bpos_min
)
13203 bpos_min
= glyph
->charpos
;
13204 if (!glyph
->avoid_cursor_p
)
13208 match_with_avoid_cursor
= 0;
13211 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13213 pos_before
= glyph
->charpos
;
13214 glyph_before
= glyph
;
13216 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13218 pos_after
= glyph
->charpos
;
13219 glyph_after
= glyph
;
13222 else if (dpos
== 0)
13223 match_with_avoid_cursor
= 1;
13225 else if (STRINGP (glyph
->object
))
13227 Lisp_Object chprop
;
13228 EMACS_INT glyph_pos
= glyph
->charpos
;
13230 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13232 if (INTEGERP (chprop
))
13234 bpos_covered
= bpos_max
+ XINT (chprop
);
13235 /* If the `cursor' property covers buffer positions up
13236 to and including point, we should display cursor on
13238 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13247 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
13249 x
--; /* can't use any pixel_width */
13252 x
-= glyph
->pixel_width
;
13255 /* Step 2: If we didn't find an exact match for point, we need to
13256 look for a proper place to put the cursor among glyphs between
13257 GLYPH_BEFORE and GLYPH_AFTER. */
13258 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13259 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13260 && bpos_covered
< pt_old
)
13262 /* An empty line has a single glyph whose OBJECT is zero and
13263 whose CHARPOS is the position of a newline on that line.
13264 Note that on a TTY, there are more glyphs after that, which
13265 were produced by extend_face_to_end_of_line, but their
13266 CHARPOS is zero or negative. */
13268 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13269 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
13271 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
13273 EMACS_INT ellipsis_pos
;
13275 /* Scan back over the ellipsis glyphs. */
13276 if (!row
->reversed_p
)
13278 ellipsis_pos
= (glyph
- 1)->charpos
;
13279 while (glyph
> row
->glyphs
[TEXT_AREA
]
13280 && (glyph
- 1)->charpos
== ellipsis_pos
)
13281 glyph
--, x
-= glyph
->pixel_width
;
13282 /* That loop always goes one position too far, including
13283 the glyph before the ellipsis. So scan forward over
13285 x
+= glyph
->pixel_width
;
13288 else /* row is reversed */
13290 ellipsis_pos
= (glyph
+ 1)->charpos
;
13291 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
13292 && (glyph
+ 1)->charpos
== ellipsis_pos
)
13293 glyph
++, x
+= glyph
->pixel_width
;
13294 x
-= glyph
->pixel_width
;
13298 else if (match_with_avoid_cursor
13299 /* A truncated row may not include PT among its
13300 character positions. Setting the cursor inside the
13301 scroll margin will trigger recalculation of hscroll
13302 in hscroll_window_tree. */
13303 || (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
13304 || (row
->truncated_on_right_p
&& pt_old
> bpos_max
)
13305 /* Zero-width characters produce no glyphs. */
13308 && (row
->reversed_p
13309 ? glyph_after
> glyphs_end
13310 : glyph_after
< glyphs_end
)))
13312 cursor
= glyph_after
;
13315 else if (string_seen
)
13317 int incr
= row
->reversed_p
? -1 : +1;
13319 /* Need to find the glyph that came out of a string which is
13320 present at point. That glyph is somewhere between
13321 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
13322 positioned between POS_BEFORE and POS_AFTER in the
13324 struct glyph
*start
, *stop
;
13325 EMACS_INT pos
= pos_before
;
13329 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
13330 correspond to POS_BEFORE and POS_AFTER, respectively. We
13331 need START and STOP in the order that corresponds to the
13332 row's direction as given by its reversed_p flag. If the
13333 directionality of characters between POS_BEFORE and
13334 POS_AFTER is the opposite of the row's base direction,
13335 these characters will have been reordered for display,
13336 and we need to reverse START and STOP. */
13337 if (!row
->reversed_p
)
13339 start
= min (glyph_before
, glyph_after
);
13340 stop
= max (glyph_before
, glyph_after
);
13344 start
= max (glyph_before
, glyph_after
);
13345 stop
= min (glyph_before
, glyph_after
);
13347 for (glyph
= start
+ incr
;
13348 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
13351 /* Any glyphs that come from the buffer are here because
13352 of bidi reordering. Skip them, and only pay
13353 attention to glyphs that came from some string. */
13354 if (STRINGP (glyph
->object
))
13359 str
= glyph
->object
;
13360 tem
= string_buffer_position_lim (str
, pos
, pos_after
, 0);
13361 if (tem
== 0 /* from overlay */
13364 /* If the string from which this glyph came is
13365 found in the buffer at point, then we've
13366 found the glyph we've been looking for. If
13367 it comes from an overlay (tem == 0), and it
13368 has the `cursor' property on one of its
13369 glyphs, record that glyph as a candidate for
13370 displaying the cursor. (As in the
13371 unidirectional version, we will display the
13372 cursor on the last candidate we find.) */
13373 if (tem
== 0 || tem
== pt_old
)
13375 /* The glyphs from this string could have
13376 been reordered. Find the one with the
13377 smallest string position. Or there could
13378 be a character in the string with the
13379 `cursor' property, which means display
13380 cursor on that character's glyph. */
13381 EMACS_INT strpos
= glyph
->charpos
;
13386 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
13387 && EQ (glyph
->object
, str
);
13391 EMACS_INT gpos
= glyph
->charpos
;
13393 cprop
= Fget_char_property (make_number (gpos
),
13401 if (tem
&& glyph
->charpos
< strpos
)
13403 strpos
= glyph
->charpos
;
13412 pos
= tem
+ 1; /* don't find previous instances */
13414 /* This string is not what we want; skip all of the
13415 glyphs that came from it. */
13416 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
13417 && EQ (glyph
->object
, str
))
13424 /* If we reached the end of the line, and END was from a string,
13425 the cursor is not on this line. */
13427 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
13428 && STRINGP (end
->object
)
13429 && row
->continued_p
)
13435 if (cursor
!= NULL
)
13441 /* Need to compute x that corresponds to GLYPH. */
13442 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
13444 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
13446 x
+= g
->pixel_width
;
13450 /* ROW could be part of a continued line, which, under bidi
13451 reordering, might have other rows whose start and end charpos
13452 occlude point. Only set w->cursor if we found a better
13453 approximation to the cursor position than we have from previously
13454 examined candidate rows belonging to the same continued line. */
13455 if (/* we already have a candidate row */
13456 w
->cursor
.vpos
>= 0
13457 /* that candidate is not the row we are processing */
13458 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
13459 /* the row we are processing is part of a continued line */
13460 && (row
->continued_p
|| MATRIX_ROW_CONTINUATION_LINE_P (row
))
13461 /* Make sure cursor.vpos specifies a row whose start and end
13462 charpos occlude point. This is because some callers of this
13463 function leave cursor.vpos at the row where the cursor was
13464 displayed during the last redisplay cycle. */
13465 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
13466 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
13469 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
13471 /* Don't consider glyphs that are outside TEXT_AREA. */
13472 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
13474 /* Keep the candidate whose buffer position is the closest to
13476 if (/* previous candidate is a glyph in TEXT_AREA of that row */
13477 w
->cursor
.hpos
>= 0
13478 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
13479 && BUFFERP (g1
->object
)
13480 && (g1
->charpos
== pt_old
/* an exact match always wins */
13481 || (BUFFERP (glyph
->object
)
13482 && eabs (g1
->charpos
- pt_old
)
13483 < eabs (glyph
->charpos
- pt_old
))))
13485 /* If this candidate gives an exact match, use that. */
13486 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13487 /* Otherwise, keep the candidate that comes from a row
13488 spanning less buffer positions. This may win when one or
13489 both candidate positions are on glyphs that came from
13490 display strings, for which we cannot compare buffer
13492 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13493 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13494 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
13497 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
13499 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
13500 w
->cursor
.y
= row
->y
+ dy
;
13502 if (w
== XWINDOW (selected_window
))
13504 if (!row
->continued_p
13505 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
13508 this_line_buffer
= XBUFFER (w
->buffer
);
13510 CHARPOS (this_line_start_pos
)
13511 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
13512 BYTEPOS (this_line_start_pos
)
13513 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
13515 CHARPOS (this_line_end_pos
)
13516 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
13517 BYTEPOS (this_line_end_pos
)
13518 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
13520 this_line_y
= w
->cursor
.y
;
13521 this_line_pixel_height
= row
->height
;
13522 this_line_vpos
= w
->cursor
.vpos
;
13523 this_line_start_x
= row
->x
;
13526 CHARPOS (this_line_start_pos
) = 0;
13533 /* Run window scroll functions, if any, for WINDOW with new window
13534 start STARTP. Sets the window start of WINDOW to that position.
13536 We assume that the window's buffer is really current. */
13538 static INLINE
struct text_pos
13539 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
13541 struct window
*w
= XWINDOW (window
);
13542 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13544 if (current_buffer
!= XBUFFER (w
->buffer
))
13547 if (!NILP (Vwindow_scroll_functions
))
13549 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13550 make_number (CHARPOS (startp
)));
13551 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13552 /* In case the hook functions switch buffers. */
13553 if (current_buffer
!= XBUFFER (w
->buffer
))
13554 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13561 /* Make sure the line containing the cursor is fully visible.
13562 A value of 1 means there is nothing to be done.
13563 (Either the line is fully visible, or it cannot be made so,
13564 or we cannot tell.)
13566 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13567 is higher than window.
13569 A value of 0 means the caller should do scrolling
13570 as if point had gone off the screen. */
13573 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
13575 struct glyph_matrix
*matrix
;
13576 struct glyph_row
*row
;
13579 if (!make_cursor_line_fully_visible_p
)
13582 /* It's not always possible to find the cursor, e.g, when a window
13583 is full of overlay strings. Don't do anything in that case. */
13584 if (w
->cursor
.vpos
< 0)
13587 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13588 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13590 /* If the cursor row is not partially visible, there's nothing to do. */
13591 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13594 /* If the row the cursor is in is taller than the window's height,
13595 it's not clear what to do, so do nothing. */
13596 window_height
= window_box_height (w
);
13597 if (row
->height
>= window_height
)
13599 if (!force_p
|| MINI_WINDOW_P (w
)
13600 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13607 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13608 non-zero means only WINDOW is redisplayed in redisplay_internal.
13609 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
13610 in redisplay_window to bring a partially visible line into view in
13611 the case that only the cursor has moved.
13613 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13614 last screen line's vertical height extends past the end of the screen.
13618 1 if scrolling succeeded
13620 0 if scrolling didn't find point.
13622 -1 if new fonts have been loaded so that we must interrupt
13623 redisplay, adjust glyph matrices, and try again. */
13629 SCROLLING_NEED_LARGER_MATRICES
13632 /* If scroll-conservatively is more than this, never recenter.
13634 If you change this, don't forget to update the doc string of
13635 `scroll-conservatively' and the Emacs manual. */
13636 #define SCROLL_LIMIT 100
13639 try_scrolling (Lisp_Object window
, int just_this_one_p
,
13640 EMACS_INT arg_scroll_conservatively
, EMACS_INT scroll_step
,
13641 int temp_scroll_step
, int last_line_misfit
)
13643 struct window
*w
= XWINDOW (window
);
13644 struct frame
*f
= XFRAME (w
->frame
);
13645 struct text_pos pos
, startp
;
13647 int this_scroll_margin
, scroll_max
, rc
, height
;
13648 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13649 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13650 Lisp_Object aggressive
;
13651 /* We will never try scrolling more than this number of lines. */
13652 int scroll_limit
= SCROLL_LIMIT
;
13655 debug_method_add (w
, "try_scrolling");
13658 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13660 /* Compute scroll margin height in pixels. We scroll when point is
13661 within this distance from the top or bottom of the window. */
13662 if (scroll_margin
> 0)
13663 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13664 * FRAME_LINE_HEIGHT (f
);
13666 this_scroll_margin
= 0;
13668 /* Force arg_scroll_conservatively to have a reasonable value, to
13669 avoid scrolling too far away with slow move_it_* functions. Note
13670 that the user can supply scroll-conservatively equal to
13671 `most-positive-fixnum', which can be larger than INT_MAX. */
13672 if (arg_scroll_conservatively
> scroll_limit
)
13674 arg_scroll_conservatively
= scroll_limit
+ 1;
13675 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
13677 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
13678 /* Compute how much we should try to scroll maximally to bring
13679 point into view. */
13680 scroll_max
= (max (scroll_step
,
13681 max (arg_scroll_conservatively
, temp_scroll_step
))
13682 * FRAME_LINE_HEIGHT (f
));
13683 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
13684 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
13685 /* We're trying to scroll because of aggressive scrolling but no
13686 scroll_step is set. Choose an arbitrary one. */
13687 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13693 /* Decide whether to scroll down. */
13694 if (PT
> CHARPOS (startp
))
13696 int scroll_margin_y
;
13698 /* Compute the pixel ypos of the scroll margin, then move it to
13699 either that ypos or PT, whichever comes first. */
13700 start_display (&it
, w
, startp
);
13701 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13702 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13703 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13704 (MOVE_TO_POS
| MOVE_TO_Y
));
13706 if (PT
> CHARPOS (it
.current
.pos
))
13708 int y0
= line_bottom_y (&it
);
13709 /* Compute how many pixels below window bottom to stop searching
13710 for PT. This avoids costly search for PT that is far away if
13711 the user limited scrolling by a small number of lines, but
13712 always finds PT if scroll_conservatively is set to a large
13713 number, such as most-positive-fixnum. */
13714 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
13715 int y_to_move
= it
.last_visible_y
+ slack
;
13717 /* Compute the distance from the scroll margin to PT or to
13718 the scroll limit, whichever comes first. This should
13719 include the height of the cursor line, to make that line
13721 move_it_to (&it
, PT
, -1, y_to_move
,
13722 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13723 dy
= line_bottom_y (&it
) - y0
;
13725 if (dy
> scroll_max
)
13726 return SCROLLING_FAILED
;
13734 /* Point is in or below the bottom scroll margin, so move the
13735 window start down. If scrolling conservatively, move it just
13736 enough down to make point visible. If scroll_step is set,
13737 move it down by scroll_step. */
13738 if (arg_scroll_conservatively
)
13740 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13741 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
13742 else if (scroll_step
|| temp_scroll_step
)
13743 amount_to_scroll
= scroll_max
;
13746 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
13747 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13748 if (NUMBERP (aggressive
))
13750 double float_amount
= XFLOATINT (aggressive
) * height
;
13751 amount_to_scroll
= float_amount
;
13752 if (amount_to_scroll
== 0 && float_amount
> 0)
13753 amount_to_scroll
= 1;
13754 /* Don't let point enter the scroll margin near top of
13756 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13757 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13761 if (amount_to_scroll
<= 0)
13762 return SCROLLING_FAILED
;
13764 start_display (&it
, w
, startp
);
13765 if (arg_scroll_conservatively
<= scroll_limit
)
13766 move_it_vertically (&it
, amount_to_scroll
);
13769 /* Extra precision for users who set scroll-conservatively
13770 to a large number: make sure the amount we scroll
13771 the window start is never less than amount_to_scroll,
13772 which was computed as distance from window bottom to
13773 point. This matters when lines at window top and lines
13774 below window bottom have different height. */
13775 struct it it1
= it
;
13776 /* We use a temporary it1 because line_bottom_y can modify
13777 its argument, if it moves one line down; see there. */
13778 int start_y
= line_bottom_y (&it1
);
13781 move_it_by_lines (&it
, 1);
13783 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
13786 /* If STARTP is unchanged, move it down another screen line. */
13787 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13788 move_it_by_lines (&it
, 1);
13789 startp
= it
.current
.pos
;
13793 struct text_pos scroll_margin_pos
= startp
;
13795 /* See if point is inside the scroll margin at the top of the
13797 if (this_scroll_margin
)
13799 start_display (&it
, w
, startp
);
13800 move_it_vertically (&it
, this_scroll_margin
);
13801 scroll_margin_pos
= it
.current
.pos
;
13804 if (PT
< CHARPOS (scroll_margin_pos
))
13806 /* Point is in the scroll margin at the top of the window or
13807 above what is displayed in the window. */
13810 /* Compute the vertical distance from PT to the scroll
13811 margin position. Move as far as scroll_max allows, or
13812 one screenful, or 10 screen lines, whichever is largest.
13813 Give up if distance is greater than scroll_max. */
13814 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13815 start_display (&it
, w
, pos
);
13817 y_to_move
= max (it
.last_visible_y
,
13818 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
13819 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13821 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13822 dy
= it
.current_y
- y0
;
13823 if (dy
> scroll_max
)
13824 return SCROLLING_FAILED
;
13826 /* Compute new window start. */
13827 start_display (&it
, w
, startp
);
13829 if (arg_scroll_conservatively
)
13830 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
13831 max (scroll_step
, temp_scroll_step
));
13832 else if (scroll_step
|| temp_scroll_step
)
13833 amount_to_scroll
= scroll_max
;
13836 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
13837 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13838 if (NUMBERP (aggressive
))
13840 double float_amount
= XFLOATINT (aggressive
) * height
;
13841 amount_to_scroll
= float_amount
;
13842 if (amount_to_scroll
== 0 && float_amount
> 0)
13843 amount_to_scroll
= 1;
13844 amount_to_scroll
-=
13845 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
13846 /* Don't let point enter the scroll margin near
13847 bottom of the window. */
13848 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13849 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13853 if (amount_to_scroll
<= 0)
13854 return SCROLLING_FAILED
;
13856 move_it_vertically_backward (&it
, amount_to_scroll
);
13857 startp
= it
.current
.pos
;
13861 /* Run window scroll functions. */
13862 startp
= run_window_scroll_functions (window
, startp
);
13864 /* Display the window. Give up if new fonts are loaded, or if point
13866 if (!try_window (window
, startp
, 0))
13867 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13868 else if (w
->cursor
.vpos
< 0)
13870 clear_glyph_matrix (w
->desired_matrix
);
13871 rc
= SCROLLING_FAILED
;
13875 /* Maybe forget recorded base line for line number display. */
13876 if (!just_this_one_p
13877 || current_buffer
->clip_changed
13878 || BEG_UNCHANGED
< CHARPOS (startp
))
13879 w
->base_line_number
= Qnil
;
13881 /* If cursor ends up on a partially visible line,
13882 treat that as being off the bottom of the screen. */
13883 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
13884 /* It's possible that the cursor is on the first line of the
13885 buffer, which is partially obscured due to a vscroll
13886 (Bug#7537). In that case, avoid looping forever . */
13887 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
13889 clear_glyph_matrix (w
->desired_matrix
);
13890 ++extra_scroll_margin_lines
;
13893 rc
= SCROLLING_SUCCESS
;
13900 /* Compute a suitable window start for window W if display of W starts
13901 on a continuation line. Value is non-zero if a new window start
13904 The new window start will be computed, based on W's width, starting
13905 from the start of the continued line. It is the start of the
13906 screen line with the minimum distance from the old start W->start. */
13909 compute_window_start_on_continuation_line (struct window
*w
)
13911 struct text_pos pos
, start_pos
;
13912 int window_start_changed_p
= 0;
13914 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13916 /* If window start is on a continuation line... Window start may be
13917 < BEGV in case there's invisible text at the start of the
13918 buffer (M-x rmail, for example). */
13919 if (CHARPOS (start_pos
) > BEGV
13920 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13923 struct glyph_row
*row
;
13925 /* Handle the case that the window start is out of range. */
13926 if (CHARPOS (start_pos
) < BEGV
)
13927 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13928 else if (CHARPOS (start_pos
) > ZV
)
13929 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13931 /* Find the start of the continued line. This should be fast
13932 because scan_buffer is fast (newline cache). */
13933 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13934 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13935 row
, DEFAULT_FACE_ID
);
13936 reseat_at_previous_visible_line_start (&it
);
13938 /* If the line start is "too far" away from the window start,
13939 say it takes too much time to compute a new window start. */
13940 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13941 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13943 int min_distance
, distance
;
13945 /* Move forward by display lines to find the new window
13946 start. If window width was enlarged, the new start can
13947 be expected to be > the old start. If window width was
13948 decreased, the new window start will be < the old start.
13949 So, we're looking for the display line start with the
13950 minimum distance from the old window start. */
13951 pos
= it
.current
.pos
;
13952 min_distance
= INFINITY
;
13953 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13954 distance
< min_distance
)
13956 min_distance
= distance
;
13957 pos
= it
.current
.pos
;
13958 move_it_by_lines (&it
, 1);
13961 /* Set the window start there. */
13962 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13963 window_start_changed_p
= 1;
13967 return window_start_changed_p
;
13971 /* Try cursor movement in case text has not changed in window WINDOW,
13972 with window start STARTP. Value is
13974 CURSOR_MOVEMENT_SUCCESS if successful
13976 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13978 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13979 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13980 we want to scroll as if scroll-step were set to 1. See the code.
13982 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13983 which case we have to abort this redisplay, and adjust matrices
13988 CURSOR_MOVEMENT_SUCCESS
,
13989 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13990 CURSOR_MOVEMENT_MUST_SCROLL
,
13991 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13995 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
13997 struct window
*w
= XWINDOW (window
);
13998 struct frame
*f
= XFRAME (w
->frame
);
13999 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14002 if (inhibit_try_cursor_movement
)
14006 /* Handle case where text has not changed, only point, and it has
14007 not moved off the frame. */
14008 if (/* Point may be in this window. */
14009 PT
>= CHARPOS (startp
)
14010 /* Selective display hasn't changed. */
14011 && !current_buffer
->clip_changed
14012 /* Function force-mode-line-update is used to force a thorough
14013 redisplay. It sets either windows_or_buffers_changed or
14014 update_mode_lines. So don't take a shortcut here for these
14016 && !update_mode_lines
14017 && !windows_or_buffers_changed
14018 && !cursor_type_changed
14019 /* Can't use this case if highlighting a region. When a
14020 region exists, cursor movement has to do more than just
14022 && !(!NILP (Vtransient_mark_mode
)
14023 && !NILP (BVAR (current_buffer
, mark_active
)))
14024 && NILP (w
->region_showing
)
14025 && NILP (Vshow_trailing_whitespace
)
14026 /* Right after splitting windows, last_point may be nil. */
14027 && INTEGERP (w
->last_point
)
14028 /* This code is not used for mini-buffer for the sake of the case
14029 of redisplaying to replace an echo area message; since in
14030 that case the mini-buffer contents per se are usually
14031 unchanged. This code is of no real use in the mini-buffer
14032 since the handling of this_line_start_pos, etc., in redisplay
14033 handles the same cases. */
14034 && !EQ (window
, minibuf_window
)
14035 /* When splitting windows or for new windows, it happens that
14036 redisplay is called with a nil window_end_vpos or one being
14037 larger than the window. This should really be fixed in
14038 window.c. I don't have this on my list, now, so we do
14039 approximately the same as the old redisplay code. --gerd. */
14040 && INTEGERP (w
->window_end_vpos
)
14041 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14042 && (FRAME_WINDOW_P (f
)
14043 || !overlay_arrow_in_current_buffer_p ()))
14045 int this_scroll_margin
, top_scroll_margin
;
14046 struct glyph_row
*row
= NULL
;
14049 debug_method_add (w
, "cursor movement");
14052 /* Scroll if point within this distance from the top or bottom
14053 of the window. This is a pixel value. */
14054 if (scroll_margin
> 0)
14056 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14057 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14060 this_scroll_margin
= 0;
14062 top_scroll_margin
= this_scroll_margin
;
14063 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14064 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14066 /* Start with the row the cursor was displayed during the last
14067 not paused redisplay. Give up if that row is not valid. */
14068 if (w
->last_cursor
.vpos
< 0
14069 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
14070 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14073 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
14074 if (row
->mode_line_p
)
14076 if (!row
->enabled_p
)
14077 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14080 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14082 int scroll_p
= 0, must_scroll
= 0;
14083 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14085 if (PT
> XFASTINT (w
->last_point
))
14087 /* Point has moved forward. */
14088 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14089 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14091 xassert (row
->enabled_p
);
14095 /* If the end position of a row equals the start
14096 position of the next row, and PT is at that position,
14097 we would rather display cursor in the next line. */
14098 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14099 && MATRIX_ROW_END_CHARPOS (row
) == PT
14100 && row
< w
->current_matrix
->rows
14101 + w
->current_matrix
->nrows
- 1
14102 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14103 && !cursor_row_p (row
))
14106 /* If within the scroll margin, scroll. Note that
14107 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
14108 the next line would be drawn, and that
14109 this_scroll_margin can be zero. */
14110 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
14111 || PT
> MATRIX_ROW_END_CHARPOS (row
)
14112 /* Line is completely visible last line in window
14113 and PT is to be set in the next line. */
14114 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
14115 && PT
== MATRIX_ROW_END_CHARPOS (row
)
14116 && !row
->ends_at_zv_p
14117 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14120 else if (PT
< XFASTINT (w
->last_point
))
14122 /* Cursor has to be moved backward. Note that PT >=
14123 CHARPOS (startp) because of the outer if-statement. */
14124 while (!row
->mode_line_p
14125 && (MATRIX_ROW_START_CHARPOS (row
) > PT
14126 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14127 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
14128 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
14129 row
> w
->current_matrix
->rows
14130 && (row
-1)->ends_in_newline_from_string_p
))))
14131 && (row
->y
> top_scroll_margin
14132 || CHARPOS (startp
) == BEGV
))
14134 xassert (row
->enabled_p
);
14138 /* Consider the following case: Window starts at BEGV,
14139 there is invisible, intangible text at BEGV, so that
14140 display starts at some point START > BEGV. It can
14141 happen that we are called with PT somewhere between
14142 BEGV and START. Try to handle that case. */
14143 if (row
< w
->current_matrix
->rows
14144 || row
->mode_line_p
)
14146 row
= w
->current_matrix
->rows
;
14147 if (row
->mode_line_p
)
14151 /* Due to newlines in overlay strings, we may have to
14152 skip forward over overlay strings. */
14153 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14154 && MATRIX_ROW_END_CHARPOS (row
) == PT
14155 && !cursor_row_p (row
))
14158 /* If within the scroll margin, scroll. */
14159 if (row
->y
< top_scroll_margin
14160 && CHARPOS (startp
) != BEGV
)
14165 /* Cursor did not move. So don't scroll even if cursor line
14166 is partially visible, as it was so before. */
14167 rc
= CURSOR_MOVEMENT_SUCCESS
;
14170 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
14171 || PT
> MATRIX_ROW_END_CHARPOS (row
))
14173 /* if PT is not in the glyph row, give up. */
14174 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14177 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14178 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14180 /* If rows are bidi-reordered and point moved, back up
14181 until we find a row that does not belong to a
14182 continuation line. This is because we must consider
14183 all rows of a continued line as candidates for the
14184 new cursor positioning, since row start and end
14185 positions change non-linearly with vertical position
14187 /* FIXME: Revisit this when glyph ``spilling'' in
14188 continuation lines' rows is implemented for
14189 bidi-reordered rows. */
14190 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
14192 xassert (row
->enabled_p
);
14194 /* If we hit the beginning of the displayed portion
14195 without finding the first row of a continued
14197 if (row
<= w
->current_matrix
->rows
)
14199 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14207 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14208 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
14209 && make_cursor_line_fully_visible_p
)
14211 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
14212 && !row
->ends_at_zv_p
14213 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14214 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14215 else if (row
->height
> window_box_height (w
))
14217 /* If we end up in a partially visible line, let's
14218 make it fully visible, except when it's taller
14219 than the window, in which case we can't do much
14222 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14226 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14227 if (!cursor_row_fully_visible_p (w
, 0, 1))
14228 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14230 rc
= CURSOR_MOVEMENT_SUCCESS
;
14234 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14235 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14236 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14238 /* With bidi-reordered rows, there could be more than
14239 one candidate row whose start and end positions
14240 occlude point. We need to let set_cursor_from_row
14241 find the best candidate. */
14242 /* FIXME: Revisit this when glyph ``spilling'' in
14243 continuation lines' rows is implemented for
14244 bidi-reordered rows. */
14249 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
14250 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14251 && cursor_row_p (row
))
14252 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
14254 /* As soon as we've found the first suitable row
14255 whose ends_at_zv_p flag is set, we are done. */
14257 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
14259 rc
= CURSOR_MOVEMENT_SUCCESS
;
14264 while ((MATRIX_ROW_CONTINUATION_LINE_P (row
)
14265 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
14266 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14267 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
14268 /* If we didn't find any candidate rows, or exited the
14269 loop before all the candidates were examined, signal
14270 to the caller that this method failed. */
14271 if (rc
!= CURSOR_MOVEMENT_SUCCESS
14272 && (!rv
|| MATRIX_ROW_CONTINUATION_LINE_P (row
)))
14273 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14275 rc
= CURSOR_MOVEMENT_SUCCESS
;
14281 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
14283 rc
= CURSOR_MOVEMENT_SUCCESS
;
14288 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14289 && MATRIX_ROW_START_CHARPOS (row
) == PT
14290 && cursor_row_p (row
));
14298 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
14302 set_vertical_scroll_bar (struct window
*w
)
14304 EMACS_INT start
, end
, whole
;
14306 /* Calculate the start and end positions for the current window.
14307 At some point, it would be nice to choose between scrollbars
14308 which reflect the whole buffer size, with special markers
14309 indicating narrowing, and scrollbars which reflect only the
14312 Note that mini-buffers sometimes aren't displaying any text. */
14313 if (!MINI_WINDOW_P (w
)
14314 || (w
== XWINDOW (minibuf_window
)
14315 && NILP (echo_area_buffer
[0])))
14317 struct buffer
*buf
= XBUFFER (w
->buffer
);
14318 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
14319 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
14320 /* I don't think this is guaranteed to be right. For the
14321 moment, we'll pretend it is. */
14322 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
14326 if (whole
< (end
- start
))
14327 whole
= end
- start
;
14330 start
= end
= whole
= 0;
14332 /* Indicate what this scroll bar ought to be displaying now. */
14333 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
14334 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
14335 (w
, end
- start
, whole
, start
);
14339 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
14340 selected_window is redisplayed.
14342 We can return without actually redisplaying the window if
14343 fonts_changed_p is nonzero. In that case, redisplay_internal will
14347 redisplay_window (Lisp_Object window
, int just_this_one_p
)
14349 struct window
*w
= XWINDOW (window
);
14350 struct frame
*f
= XFRAME (w
->frame
);
14351 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14352 struct buffer
*old
= current_buffer
;
14353 struct text_pos lpoint
, opoint
, startp
;
14354 int update_mode_line
;
14357 /* Record it now because it's overwritten. */
14358 int current_matrix_up_to_date_p
= 0;
14359 int used_current_matrix_p
= 0;
14360 /* This is less strict than current_matrix_up_to_date_p.
14361 It indictes that the buffer contents and narrowing are unchanged. */
14362 int buffer_unchanged_p
= 0;
14363 int temp_scroll_step
= 0;
14364 int count
= SPECPDL_INDEX ();
14366 int centering_position
= -1;
14367 int last_line_misfit
= 0;
14368 EMACS_INT beg_unchanged
, end_unchanged
;
14370 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14373 /* W must be a leaf window here. */
14374 xassert (!NILP (w
->buffer
));
14376 *w
->desired_matrix
->method
= 0;
14380 reconsider_clip_changes (w
, buffer
);
14382 /* Has the mode line to be updated? */
14383 update_mode_line
= (!NILP (w
->update_mode_line
)
14384 || update_mode_lines
14385 || buffer
->clip_changed
14386 || buffer
->prevent_redisplay_optimizations_p
);
14388 if (MINI_WINDOW_P (w
))
14390 if (w
== XWINDOW (echo_area_window
)
14391 && !NILP (echo_area_buffer
[0]))
14393 if (update_mode_line
)
14394 /* We may have to update a tty frame's menu bar or a
14395 tool-bar. Example `M-x C-h C-h C-g'. */
14396 goto finish_menu_bars
;
14398 /* We've already displayed the echo area glyphs in this window. */
14399 goto finish_scroll_bars
;
14401 else if ((w
!= XWINDOW (minibuf_window
)
14402 || minibuf_level
== 0)
14403 /* When buffer is nonempty, redisplay window normally. */
14404 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
14405 /* Quail displays non-mini buffers in minibuffer window.
14406 In that case, redisplay the window normally. */
14407 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
14409 /* W is a mini-buffer window, but it's not active, so clear
14411 int yb
= window_text_bottom_y (w
);
14412 struct glyph_row
*row
;
14415 for (y
= 0, row
= w
->desired_matrix
->rows
;
14417 y
+= row
->height
, ++row
)
14418 blank_row (w
, row
, y
);
14419 goto finish_scroll_bars
;
14422 clear_glyph_matrix (w
->desired_matrix
);
14425 /* Otherwise set up data on this window; select its buffer and point
14427 /* Really select the buffer, for the sake of buffer-local
14429 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14431 current_matrix_up_to_date_p
14432 = (!NILP (w
->window_end_valid
)
14433 && !current_buffer
->clip_changed
14434 && !current_buffer
->prevent_redisplay_optimizations_p
14435 && XFASTINT (w
->last_modified
) >= MODIFF
14436 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
14438 /* Run the window-bottom-change-functions
14439 if it is possible that the text on the screen has changed
14440 (either due to modification of the text, or any other reason). */
14441 if (!current_matrix_up_to_date_p
14442 && !NILP (Vwindow_text_change_functions
))
14444 safe_run_hooks (Qwindow_text_change_functions
);
14448 beg_unchanged
= BEG_UNCHANGED
;
14449 end_unchanged
= END_UNCHANGED
;
14451 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
14453 specbind (Qinhibit_point_motion_hooks
, Qt
);
14456 = (!NILP (w
->window_end_valid
)
14457 && !current_buffer
->clip_changed
14458 && XFASTINT (w
->last_modified
) >= MODIFF
14459 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
14461 /* When windows_or_buffers_changed is non-zero, we can't rely on
14462 the window end being valid, so set it to nil there. */
14463 if (windows_or_buffers_changed
)
14465 /* If window starts on a continuation line, maybe adjust the
14466 window start in case the window's width changed. */
14467 if (XMARKER (w
->start
)->buffer
== current_buffer
)
14468 compute_window_start_on_continuation_line (w
);
14470 w
->window_end_valid
= Qnil
;
14473 /* Some sanity checks. */
14474 CHECK_WINDOW_END (w
);
14475 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
14477 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
14480 /* If %c is in mode line, update it if needed. */
14481 if (!NILP (w
->column_number_displayed
)
14482 /* This alternative quickly identifies a common case
14483 where no change is needed. */
14484 && !(PT
== XFASTINT (w
->last_point
)
14485 && XFASTINT (w
->last_modified
) >= MODIFF
14486 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
14487 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
14488 update_mode_line
= 1;
14490 /* Count number of windows showing the selected buffer. An indirect
14491 buffer counts as its base buffer. */
14492 if (!just_this_one_p
)
14494 struct buffer
*current_base
, *window_base
;
14495 current_base
= current_buffer
;
14496 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
14497 if (current_base
->base_buffer
)
14498 current_base
= current_base
->base_buffer
;
14499 if (window_base
->base_buffer
)
14500 window_base
= window_base
->base_buffer
;
14501 if (current_base
== window_base
)
14505 /* Point refers normally to the selected window. For any other
14506 window, set up appropriate value. */
14507 if (!EQ (window
, selected_window
))
14509 EMACS_INT new_pt
= XMARKER (w
->pointm
)->charpos
;
14510 EMACS_INT new_pt_byte
= marker_byte_position (w
->pointm
);
14514 new_pt_byte
= BEGV_BYTE
;
14515 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
14517 else if (new_pt
> (ZV
- 1))
14520 new_pt_byte
= ZV_BYTE
;
14521 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
14524 /* We don't use SET_PT so that the point-motion hooks don't run. */
14525 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
14528 /* If any of the character widths specified in the display table
14529 have changed, invalidate the width run cache. It's true that
14530 this may be a bit late to catch such changes, but the rest of
14531 redisplay goes (non-fatally) haywire when the display table is
14532 changed, so why should we worry about doing any better? */
14533 if (current_buffer
->width_run_cache
)
14535 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
14537 if (! disptab_matches_widthtab (disptab
,
14538 XVECTOR (BVAR (current_buffer
, width_table
))))
14540 invalidate_region_cache (current_buffer
,
14541 current_buffer
->width_run_cache
,
14543 recompute_width_table (current_buffer
, disptab
);
14547 /* If window-start is screwed up, choose a new one. */
14548 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
14551 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14553 /* If someone specified a new starting point but did not insist,
14554 check whether it can be used. */
14555 if (!NILP (w
->optional_new_start
)
14556 && CHARPOS (startp
) >= BEGV
14557 && CHARPOS (startp
) <= ZV
)
14559 w
->optional_new_start
= Qnil
;
14560 start_display (&it
, w
, startp
);
14561 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
14562 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14563 if (IT_CHARPOS (it
) == PT
)
14564 w
->force_start
= Qt
;
14565 /* IT may overshoot PT if text at PT is invisible. */
14566 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
14567 w
->force_start
= Qt
;
14572 /* Handle case where place to start displaying has been specified,
14573 unless the specified location is outside the accessible range. */
14574 if (!NILP (w
->force_start
)
14575 || w
->frozen_window_start_p
)
14577 /* We set this later on if we have to adjust point. */
14580 w
->force_start
= Qnil
;
14582 w
->window_end_valid
= Qnil
;
14584 /* Forget any recorded base line for line number display. */
14585 if (!buffer_unchanged_p
)
14586 w
->base_line_number
= Qnil
;
14588 /* Redisplay the mode line. Select the buffer properly for that.
14589 Also, run the hook window-scroll-functions
14590 because we have scrolled. */
14591 /* Note, we do this after clearing force_start because
14592 if there's an error, it is better to forget about force_start
14593 than to get into an infinite loop calling the hook functions
14594 and having them get more errors. */
14595 if (!update_mode_line
14596 || ! NILP (Vwindow_scroll_functions
))
14598 update_mode_line
= 1;
14599 w
->update_mode_line
= Qt
;
14600 startp
= run_window_scroll_functions (window
, startp
);
14603 w
->last_modified
= make_number (0);
14604 w
->last_overlay_modified
= make_number (0);
14605 if (CHARPOS (startp
) < BEGV
)
14606 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14607 else if (CHARPOS (startp
) > ZV
)
14608 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14610 /* Redisplay, then check if cursor has been set during the
14611 redisplay. Give up if new fonts were loaded. */
14612 /* We used to issue a CHECK_MARGINS argument to try_window here,
14613 but this causes scrolling to fail when point begins inside
14614 the scroll margin (bug#148) -- cyd */
14615 if (!try_window (window
, startp
, 0))
14617 w
->force_start
= Qt
;
14618 clear_glyph_matrix (w
->desired_matrix
);
14619 goto need_larger_matrices
;
14622 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14624 /* If point does not appear, try to move point so it does
14625 appear. The desired matrix has been built above, so we
14626 can use it here. */
14627 new_vpos
= window_box_height (w
) / 2;
14630 if (!cursor_row_fully_visible_p (w
, 0, 0))
14632 /* Point does appear, but on a line partly visible at end of window.
14633 Move it back to a fully-visible line. */
14634 new_vpos
= window_box_height (w
);
14637 /* If we need to move point for either of the above reasons,
14638 now actually do it. */
14641 struct glyph_row
*row
;
14643 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14644 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14647 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14648 MATRIX_ROW_START_BYTEPOS (row
));
14650 if (w
!= XWINDOW (selected_window
))
14651 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14652 else if (current_buffer
== old
)
14653 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14655 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14657 /* If we are highlighting the region, then we just changed
14658 the region, so redisplay to show it. */
14659 if (!NILP (Vtransient_mark_mode
)
14660 && !NILP (BVAR (current_buffer
, mark_active
)))
14662 clear_glyph_matrix (w
->desired_matrix
);
14663 if (!try_window (window
, startp
, 0))
14664 goto need_larger_matrices
;
14669 debug_method_add (w
, "forced window start");
14674 /* Handle case where text has not changed, only point, and it has
14675 not moved off the frame, and we are not retrying after hscroll.
14676 (current_matrix_up_to_date_p is nonzero when retrying.) */
14677 if (current_matrix_up_to_date_p
14678 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14679 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14683 case CURSOR_MOVEMENT_SUCCESS
:
14684 used_current_matrix_p
= 1;
14687 case CURSOR_MOVEMENT_MUST_SCROLL
:
14688 goto try_to_scroll
;
14694 /* If current starting point was originally the beginning of a line
14695 but no longer is, find a new starting point. */
14696 else if (!NILP (w
->start_at_line_beg
)
14697 && !(CHARPOS (startp
) <= BEGV
14698 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14701 debug_method_add (w
, "recenter 1");
14706 /* Try scrolling with try_window_id. Value is > 0 if update has
14707 been done, it is -1 if we know that the same window start will
14708 not work. It is 0 if unsuccessful for some other reason. */
14709 else if ((tem
= try_window_id (w
)) != 0)
14712 debug_method_add (w
, "try_window_id %d", tem
);
14715 if (fonts_changed_p
)
14716 goto need_larger_matrices
;
14720 /* Otherwise try_window_id has returned -1 which means that we
14721 don't want the alternative below this comment to execute. */
14723 else if (CHARPOS (startp
) >= BEGV
14724 && CHARPOS (startp
) <= ZV
14725 && PT
>= CHARPOS (startp
)
14726 && (CHARPOS (startp
) < ZV
14727 /* Avoid starting at end of buffer. */
14728 || CHARPOS (startp
) == BEGV
14729 || (XFASTINT (w
->last_modified
) >= MODIFF
14730 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14733 /* If first window line is a continuation line, and window start
14734 is inside the modified region, but the first change is before
14735 current window start, we must select a new window start.
14737 However, if this is the result of a down-mouse event (e.g. by
14738 extending the mouse-drag-overlay), we don't want to select a
14739 new window start, since that would change the position under
14740 the mouse, resulting in an unwanted mouse-movement rather
14741 than a simple mouse-click. */
14742 if (NILP (w
->start_at_line_beg
)
14743 && NILP (do_mouse_tracking
)
14744 && CHARPOS (startp
) > BEGV
14745 && CHARPOS (startp
) > BEG
+ beg_unchanged
14746 && CHARPOS (startp
) <= Z
- end_unchanged
14747 /* Even if w->start_at_line_beg is nil, a new window may
14748 start at a line_beg, since that's how set_buffer_window
14749 sets it. So, we need to check the return value of
14750 compute_window_start_on_continuation_line. (See also
14752 && XMARKER (w
->start
)->buffer
== current_buffer
14753 && compute_window_start_on_continuation_line (w
))
14755 w
->force_start
= Qt
;
14756 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14761 debug_method_add (w
, "same window start");
14764 /* Try to redisplay starting at same place as before.
14765 If point has not moved off frame, accept the results. */
14766 if (!current_matrix_up_to_date_p
14767 /* Don't use try_window_reusing_current_matrix in this case
14768 because a window scroll function can have changed the
14770 || !NILP (Vwindow_scroll_functions
)
14771 || MINI_WINDOW_P (w
)
14772 || !(used_current_matrix_p
14773 = try_window_reusing_current_matrix (w
)))
14775 IF_DEBUG (debug_method_add (w
, "1"));
14776 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
14777 /* -1 means we need to scroll.
14778 0 means we need new matrices, but fonts_changed_p
14779 is set in that case, so we will detect it below. */
14780 goto try_to_scroll
;
14783 if (fonts_changed_p
)
14784 goto need_larger_matrices
;
14786 if (w
->cursor
.vpos
>= 0)
14788 if (!just_this_one_p
14789 || current_buffer
->clip_changed
14790 || BEG_UNCHANGED
< CHARPOS (startp
))
14791 /* Forget any recorded base line for line number display. */
14792 w
->base_line_number
= Qnil
;
14794 if (!cursor_row_fully_visible_p (w
, 1, 0))
14796 clear_glyph_matrix (w
->desired_matrix
);
14797 last_line_misfit
= 1;
14799 /* Drop through and scroll. */
14804 clear_glyph_matrix (w
->desired_matrix
);
14809 w
->last_modified
= make_number (0);
14810 w
->last_overlay_modified
= make_number (0);
14812 /* Redisplay the mode line. Select the buffer properly for that. */
14813 if (!update_mode_line
)
14815 update_mode_line
= 1;
14816 w
->update_mode_line
= Qt
;
14819 /* Try to scroll by specified few lines. */
14820 if ((scroll_conservatively
14821 || emacs_scroll_step
14822 || temp_scroll_step
14823 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
14824 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
14825 && CHARPOS (startp
) >= BEGV
14826 && CHARPOS (startp
) <= ZV
)
14828 /* The function returns -1 if new fonts were loaded, 1 if
14829 successful, 0 if not successful. */
14830 int ss
= try_scrolling (window
, just_this_one_p
,
14831 scroll_conservatively
,
14833 temp_scroll_step
, last_line_misfit
);
14836 case SCROLLING_SUCCESS
:
14839 case SCROLLING_NEED_LARGER_MATRICES
:
14840 goto need_larger_matrices
;
14842 case SCROLLING_FAILED
:
14850 /* Finally, just choose a place to start which positions point
14851 according to user preferences. */
14856 debug_method_add (w
, "recenter");
14859 /* w->vscroll = 0; */
14861 /* Forget any previously recorded base line for line number display. */
14862 if (!buffer_unchanged_p
)
14863 w
->base_line_number
= Qnil
;
14865 /* Determine the window start relative to point. */
14866 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14867 it
.current_y
= it
.last_visible_y
;
14868 if (centering_position
< 0)
14872 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14874 EMACS_INT margin_pos
= CHARPOS (startp
);
14876 Lisp_Object aggressive
;
14878 /* If there is a scroll margin at the top of the window, find
14879 its character position. */
14881 /* Cannot call start_display if startp is not in the
14882 accessible region of the buffer. This can happen when we
14883 have just switched to a different buffer and/or changed
14884 its restriction. In that case, startp is initialized to
14885 the character position 1 (BEG) because we did not yet
14886 have chance to display the buffer even once. */
14887 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
14891 start_display (&it1
, w
, startp
);
14892 move_it_vertically (&it1
, margin
);
14893 margin_pos
= IT_CHARPOS (it1
);
14895 scrolling_up
= PT
> margin_pos
;
14898 ? BVAR (current_buffer
, scroll_up_aggressively
)
14899 : BVAR (current_buffer
, scroll_down_aggressively
);
14901 if (!MINI_WINDOW_P (w
)
14902 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
14906 /* Setting scroll-conservatively overrides
14907 scroll-*-aggressively. */
14908 if (!scroll_conservatively
&& NUMBERP (aggressive
))
14910 double float_amount
= XFLOATINT (aggressive
);
14912 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
14913 if (pt_offset
== 0 && float_amount
> 0)
14918 /* Compute how much to move the window start backward from
14919 point so that point will be displayed where the user
14923 centering_position
= it
.last_visible_y
;
14925 centering_position
-= pt_offset
;
14926 centering_position
-=
14927 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0));
14928 /* Don't let point enter the scroll margin near top of
14930 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
14931 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
14934 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
14937 /* Set the window start half the height of the window backward
14939 centering_position
= window_box_height (w
) / 2;
14941 move_it_vertically_backward (&it
, centering_position
);
14943 xassert (IT_CHARPOS (it
) >= BEGV
);
14945 /* The function move_it_vertically_backward may move over more
14946 than the specified y-distance. If it->w is small, e.g. a
14947 mini-buffer window, we may end up in front of the window's
14948 display area. Start displaying at the start of the line
14949 containing PT in this case. */
14950 if (it
.current_y
<= 0)
14952 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14953 move_it_vertically_backward (&it
, 0);
14957 it
.current_x
= it
.hpos
= 0;
14959 /* Set the window start position here explicitly, to avoid an
14960 infinite loop in case the functions in window-scroll-functions
14962 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14964 /* Run scroll hooks. */
14965 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14967 /* Redisplay the window. */
14968 if (!current_matrix_up_to_date_p
14969 || windows_or_buffers_changed
14970 || cursor_type_changed
14971 /* Don't use try_window_reusing_current_matrix in this case
14972 because it can have changed the buffer. */
14973 || !NILP (Vwindow_scroll_functions
)
14974 || !just_this_one_p
14975 || MINI_WINDOW_P (w
)
14976 || !(used_current_matrix_p
14977 = try_window_reusing_current_matrix (w
)))
14978 try_window (window
, startp
, 0);
14980 /* If new fonts have been loaded (due to fontsets), give up. We
14981 have to start a new redisplay since we need to re-adjust glyph
14983 if (fonts_changed_p
)
14984 goto need_larger_matrices
;
14986 /* If cursor did not appear assume that the middle of the window is
14987 in the first line of the window. Do it again with the next line.
14988 (Imagine a window of height 100, displaying two lines of height
14989 60. Moving back 50 from it->last_visible_y will end in the first
14991 if (w
->cursor
.vpos
< 0)
14993 if (!NILP (w
->window_end_valid
)
14994 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14996 clear_glyph_matrix (w
->desired_matrix
);
14997 move_it_by_lines (&it
, 1);
14998 try_window (window
, it
.current
.pos
, 0);
15000 else if (PT
< IT_CHARPOS (it
))
15002 clear_glyph_matrix (w
->desired_matrix
);
15003 move_it_by_lines (&it
, -1);
15004 try_window (window
, it
.current
.pos
, 0);
15008 /* Not much we can do about it. */
15012 /* Consider the following case: Window starts at BEGV, there is
15013 invisible, intangible text at BEGV, so that display starts at
15014 some point START > BEGV. It can happen that we are called with
15015 PT somewhere between BEGV and START. Try to handle that case. */
15016 if (w
->cursor
.vpos
< 0)
15018 struct glyph_row
*row
= w
->current_matrix
->rows
;
15019 if (row
->mode_line_p
)
15021 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15024 if (!cursor_row_fully_visible_p (w
, 0, 0))
15026 /* If vscroll is enabled, disable it and try again. */
15030 clear_glyph_matrix (w
->desired_matrix
);
15034 /* If centering point failed to make the whole line visible,
15035 put point at the top instead. That has to make the whole line
15036 visible, if it can be done. */
15037 if (centering_position
== 0)
15040 clear_glyph_matrix (w
->desired_matrix
);
15041 centering_position
= 0;
15047 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15048 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
15049 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
15052 /* Display the mode line, if we must. */
15053 if ((update_mode_line
15054 /* If window not full width, must redo its mode line
15055 if (a) the window to its side is being redone and
15056 (b) we do a frame-based redisplay. This is a consequence
15057 of how inverted lines are drawn in frame-based redisplay. */
15058 || (!just_this_one_p
15059 && !FRAME_WINDOW_P (f
)
15060 && !WINDOW_FULL_WIDTH_P (w
))
15061 /* Line number to display. */
15062 || INTEGERP (w
->base_line_pos
)
15063 /* Column number is displayed and different from the one displayed. */
15064 || (!NILP (w
->column_number_displayed
)
15065 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
15066 /* This means that the window has a mode line. */
15067 && (WINDOW_WANTS_MODELINE_P (w
)
15068 || WINDOW_WANTS_HEADER_LINE_P (w
)))
15070 display_mode_lines (w
);
15072 /* If mode line height has changed, arrange for a thorough
15073 immediate redisplay using the correct mode line height. */
15074 if (WINDOW_WANTS_MODELINE_P (w
)
15075 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
15077 fonts_changed_p
= 1;
15078 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
15079 = DESIRED_MODE_LINE_HEIGHT (w
);
15082 /* If header line height has changed, arrange for a thorough
15083 immediate redisplay using the correct header line height. */
15084 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15085 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
15087 fonts_changed_p
= 1;
15088 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
15089 = DESIRED_HEADER_LINE_HEIGHT (w
);
15092 if (fonts_changed_p
)
15093 goto need_larger_matrices
;
15096 if (!line_number_displayed
15097 && !BUFFERP (w
->base_line_pos
))
15099 w
->base_line_pos
= Qnil
;
15100 w
->base_line_number
= Qnil
;
15105 /* When we reach a frame's selected window, redo the frame's menu bar. */
15106 if (update_mode_line
15107 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
15109 int redisplay_menu_p
= 0;
15111 if (FRAME_WINDOW_P (f
))
15113 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
15114 || defined (HAVE_NS) || defined (USE_GTK)
15115 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
15117 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15121 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15123 if (redisplay_menu_p
)
15124 display_menu_bar (w
);
15126 #ifdef HAVE_WINDOW_SYSTEM
15127 if (FRAME_WINDOW_P (f
))
15129 #if defined (USE_GTK) || defined (HAVE_NS)
15130 if (FRAME_EXTERNAL_TOOL_BAR (f
))
15131 redisplay_tool_bar (f
);
15133 if (WINDOWP (f
->tool_bar_window
)
15134 && (FRAME_TOOL_BAR_LINES (f
) > 0
15135 || !NILP (Vauto_resize_tool_bars
))
15136 && redisplay_tool_bar (f
))
15137 ignore_mouse_drag_p
= 1;
15143 #ifdef HAVE_WINDOW_SYSTEM
15144 if (FRAME_WINDOW_P (f
)
15145 && update_window_fringes (w
, (just_this_one_p
15146 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
15147 || w
->pseudo_window_p
)))
15151 if (draw_window_fringes (w
, 1))
15152 x_draw_vertical_border (w
);
15156 #endif /* HAVE_WINDOW_SYSTEM */
15158 /* We go to this label, with fonts_changed_p nonzero,
15159 if it is necessary to try again using larger glyph matrices.
15160 We have to redeem the scroll bar even in this case,
15161 because the loop in redisplay_internal expects that. */
15162 need_larger_matrices
:
15164 finish_scroll_bars
:
15166 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
15168 /* Set the thumb's position and size. */
15169 set_vertical_scroll_bar (w
);
15171 /* Note that we actually used the scroll bar attached to this
15172 window, so it shouldn't be deleted at the end of redisplay. */
15173 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
15174 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
15177 /* Restore current_buffer and value of point in it. The window
15178 update may have changed the buffer, so first make sure `opoint'
15179 is still valid (Bug#6177). */
15180 if (CHARPOS (opoint
) < BEGV
)
15181 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15182 else if (CHARPOS (opoint
) > ZV
)
15183 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
15185 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
15187 set_buffer_internal_1 (old
);
15188 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
15189 shorter. This can be caused by log truncation in *Messages*. */
15190 if (CHARPOS (lpoint
) <= ZV
)
15191 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15193 unbind_to (count
, Qnil
);
15197 /* Build the complete desired matrix of WINDOW with a window start
15198 buffer position POS.
15200 Value is 1 if successful. It is zero if fonts were loaded during
15201 redisplay which makes re-adjusting glyph matrices necessary, and -1
15202 if point would appear in the scroll margins.
15203 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
15204 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
15208 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
15210 struct window
*w
= XWINDOW (window
);
15212 struct glyph_row
*last_text_row
= NULL
;
15213 struct frame
*f
= XFRAME (w
->frame
);
15215 /* Make POS the new window start. */
15216 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
15218 /* Mark cursor position as unknown. No overlay arrow seen. */
15219 w
->cursor
.vpos
= -1;
15220 overlay_arrow_seen
= 0;
15222 /* Initialize iterator and info to start at POS. */
15223 start_display (&it
, w
, pos
);
15225 /* Display all lines of W. */
15226 while (it
.current_y
< it
.last_visible_y
)
15228 if (display_line (&it
))
15229 last_text_row
= it
.glyph_row
- 1;
15230 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
15234 /* Don't let the cursor end in the scroll margins. */
15235 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
15236 && !MINI_WINDOW_P (w
))
15238 int this_scroll_margin
;
15240 if (scroll_margin
> 0)
15242 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15243 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15246 this_scroll_margin
= 0;
15248 if ((w
->cursor
.y
>= 0 /* not vscrolled */
15249 && w
->cursor
.y
< this_scroll_margin
15250 && CHARPOS (pos
) > BEGV
15251 && IT_CHARPOS (it
) < ZV
)
15252 /* rms: considering make_cursor_line_fully_visible_p here
15253 seems to give wrong results. We don't want to recenter
15254 when the last line is partly visible, we want to allow
15255 that case to be handled in the usual way. */
15256 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
15258 w
->cursor
.vpos
= -1;
15259 clear_glyph_matrix (w
->desired_matrix
);
15264 /* If bottom moved off end of frame, change mode line percentage. */
15265 if (XFASTINT (w
->window_end_pos
) <= 0
15266 && Z
!= IT_CHARPOS (it
))
15267 w
->update_mode_line
= Qt
;
15269 /* Set window_end_pos to the offset of the last character displayed
15270 on the window from the end of current_buffer. Set
15271 window_end_vpos to its row number. */
15274 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
15275 w
->window_end_bytepos
15276 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15278 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15280 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15281 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
15282 ->displays_text_p
);
15286 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
15287 w
->window_end_pos
= make_number (Z
- ZV
);
15288 w
->window_end_vpos
= make_number (0);
15291 /* But that is not valid info until redisplay finishes. */
15292 w
->window_end_valid
= Qnil
;
15298 /************************************************************************
15299 Window redisplay reusing current matrix when buffer has not changed
15300 ************************************************************************/
15302 /* Try redisplay of window W showing an unchanged buffer with a
15303 different window start than the last time it was displayed by
15304 reusing its current matrix. Value is non-zero if successful.
15305 W->start is the new window start. */
15308 try_window_reusing_current_matrix (struct window
*w
)
15310 struct frame
*f
= XFRAME (w
->frame
);
15311 struct glyph_row
*bottom_row
;
15314 struct text_pos start
, new_start
;
15315 int nrows_scrolled
, i
;
15316 struct glyph_row
*last_text_row
;
15317 struct glyph_row
*last_reused_text_row
;
15318 struct glyph_row
*start_row
;
15319 int start_vpos
, min_y
, max_y
;
15322 if (inhibit_try_window_reusing
)
15326 if (/* This function doesn't handle terminal frames. */
15327 !FRAME_WINDOW_P (f
)
15328 /* Don't try to reuse the display if windows have been split
15330 || windows_or_buffers_changed
15331 || cursor_type_changed
)
15334 /* Can't do this if region may have changed. */
15335 if ((!NILP (Vtransient_mark_mode
)
15336 && !NILP (BVAR (current_buffer
, mark_active
)))
15337 || !NILP (w
->region_showing
)
15338 || !NILP (Vshow_trailing_whitespace
))
15341 /* If top-line visibility has changed, give up. */
15342 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15343 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
15346 /* Give up if old or new display is scrolled vertically. We could
15347 make this function handle this, but right now it doesn't. */
15348 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15349 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
15352 /* The variable new_start now holds the new window start. The old
15353 start `start' can be determined from the current matrix. */
15354 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
15355 start
= start_row
->minpos
;
15356 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
15358 /* Clear the desired matrix for the display below. */
15359 clear_glyph_matrix (w
->desired_matrix
);
15361 if (CHARPOS (new_start
) <= CHARPOS (start
))
15363 /* Don't use this method if the display starts with an ellipsis
15364 displayed for invisible text. It's not easy to handle that case
15365 below, and it's certainly not worth the effort since this is
15366 not a frequent case. */
15367 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
15370 IF_DEBUG (debug_method_add (w
, "twu1"));
15372 /* Display up to a row that can be reused. The variable
15373 last_text_row is set to the last row displayed that displays
15374 text. Note that it.vpos == 0 if or if not there is a
15375 header-line; it's not the same as the MATRIX_ROW_VPOS! */
15376 start_display (&it
, w
, new_start
);
15377 w
->cursor
.vpos
= -1;
15378 last_text_row
= last_reused_text_row
= NULL
;
15380 while (it
.current_y
< it
.last_visible_y
15381 && !fonts_changed_p
)
15383 /* If we have reached into the characters in the START row,
15384 that means the line boundaries have changed. So we
15385 can't start copying with the row START. Maybe it will
15386 work to start copying with the following row. */
15387 while (IT_CHARPOS (it
) > CHARPOS (start
))
15389 /* Advance to the next row as the "start". */
15391 start
= start_row
->minpos
;
15392 /* If there are no more rows to try, or just one, give up. */
15393 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
15394 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
15395 || CHARPOS (start
) == ZV
)
15397 clear_glyph_matrix (w
->desired_matrix
);
15401 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
15403 /* If we have reached alignment,
15404 we can copy the rest of the rows. */
15405 if (IT_CHARPOS (it
) == CHARPOS (start
))
15408 if (display_line (&it
))
15409 last_text_row
= it
.glyph_row
- 1;
15412 /* A value of current_y < last_visible_y means that we stopped
15413 at the previous window start, which in turn means that we
15414 have at least one reusable row. */
15415 if (it
.current_y
< it
.last_visible_y
)
15417 struct glyph_row
*row
;
15419 /* IT.vpos always starts from 0; it counts text lines. */
15420 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
15422 /* Find PT if not already found in the lines displayed. */
15423 if (w
->cursor
.vpos
< 0)
15425 int dy
= it
.current_y
- start_row
->y
;
15427 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15428 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
15430 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
15431 dy
, nrows_scrolled
);
15434 clear_glyph_matrix (w
->desired_matrix
);
15439 /* Scroll the display. Do it before the current matrix is
15440 changed. The problem here is that update has not yet
15441 run, i.e. part of the current matrix is not up to date.
15442 scroll_run_hook will clear the cursor, and use the
15443 current matrix to get the height of the row the cursor is
15445 run
.current_y
= start_row
->y
;
15446 run
.desired_y
= it
.current_y
;
15447 run
.height
= it
.last_visible_y
- it
.current_y
;
15449 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
15452 FRAME_RIF (f
)->update_window_begin_hook (w
);
15453 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15454 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15455 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15459 /* Shift current matrix down by nrows_scrolled lines. */
15460 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15461 rotate_matrix (w
->current_matrix
,
15463 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15466 /* Disable lines that must be updated. */
15467 for (i
= 0; i
< nrows_scrolled
; ++i
)
15468 (start_row
+ i
)->enabled_p
= 0;
15470 /* Re-compute Y positions. */
15471 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15472 max_y
= it
.last_visible_y
;
15473 for (row
= start_row
+ nrows_scrolled
;
15477 row
->y
= it
.current_y
;
15478 row
->visible_height
= row
->height
;
15480 if (row
->y
< min_y
)
15481 row
->visible_height
-= min_y
- row
->y
;
15482 if (row
->y
+ row
->height
> max_y
)
15483 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15484 row
->redraw_fringe_bitmaps_p
= 1;
15486 it
.current_y
+= row
->height
;
15488 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15489 last_reused_text_row
= row
;
15490 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
15494 /* Disable lines in the current matrix which are now
15495 below the window. */
15496 for (++row
; row
< bottom_row
; ++row
)
15497 row
->enabled_p
= row
->mode_line_p
= 0;
15500 /* Update window_end_pos etc.; last_reused_text_row is the last
15501 reused row from the current matrix containing text, if any.
15502 The value of last_text_row is the last displayed line
15503 containing text. */
15504 if (last_reused_text_row
)
15506 w
->window_end_bytepos
15507 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
15509 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
15511 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
15512 w
->current_matrix
));
15514 else if (last_text_row
)
15516 w
->window_end_bytepos
15517 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15519 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15521 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15525 /* This window must be completely empty. */
15526 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
15527 w
->window_end_pos
= make_number (Z
- ZV
);
15528 w
->window_end_vpos
= make_number (0);
15530 w
->window_end_valid
= Qnil
;
15532 /* Update hint: don't try scrolling again in update_window. */
15533 w
->desired_matrix
->no_scrolling_p
= 1;
15536 debug_method_add (w
, "try_window_reusing_current_matrix 1");
15540 else if (CHARPOS (new_start
) > CHARPOS (start
))
15542 struct glyph_row
*pt_row
, *row
;
15543 struct glyph_row
*first_reusable_row
;
15544 struct glyph_row
*first_row_to_display
;
15546 int yb
= window_text_bottom_y (w
);
15548 /* Find the row starting at new_start, if there is one. Don't
15549 reuse a partially visible line at the end. */
15550 first_reusable_row
= start_row
;
15551 while (first_reusable_row
->enabled_p
15552 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
15553 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15554 < CHARPOS (new_start
)))
15555 ++first_reusable_row
;
15557 /* Give up if there is no row to reuse. */
15558 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
15559 || !first_reusable_row
->enabled_p
15560 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15561 != CHARPOS (new_start
)))
15564 /* We can reuse fully visible rows beginning with
15565 first_reusable_row to the end of the window. Set
15566 first_row_to_display to the first row that cannot be reused.
15567 Set pt_row to the row containing point, if there is any. */
15569 for (first_row_to_display
= first_reusable_row
;
15570 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
15571 ++first_row_to_display
)
15573 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
15574 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
15575 pt_row
= first_row_to_display
;
15578 /* Start displaying at the start of first_row_to_display. */
15579 xassert (first_row_to_display
->y
< yb
);
15580 init_to_row_start (&it
, w
, first_row_to_display
);
15582 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
15584 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
15586 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
15587 + WINDOW_HEADER_LINE_HEIGHT (w
));
15589 /* Display lines beginning with first_row_to_display in the
15590 desired matrix. Set last_text_row to the last row displayed
15591 that displays text. */
15592 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
15593 if (pt_row
== NULL
)
15594 w
->cursor
.vpos
= -1;
15595 last_text_row
= NULL
;
15596 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
15597 if (display_line (&it
))
15598 last_text_row
= it
.glyph_row
- 1;
15600 /* If point is in a reused row, adjust y and vpos of the cursor
15604 w
->cursor
.vpos
-= nrows_scrolled
;
15605 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
15608 /* Give up if point isn't in a row displayed or reused. (This
15609 also handles the case where w->cursor.vpos < nrows_scrolled
15610 after the calls to display_line, which can happen with scroll
15611 margins. See bug#1295.) */
15612 if (w
->cursor
.vpos
< 0)
15614 clear_glyph_matrix (w
->desired_matrix
);
15618 /* Scroll the display. */
15619 run
.current_y
= first_reusable_row
->y
;
15620 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15621 run
.height
= it
.last_visible_y
- run
.current_y
;
15622 dy
= run
.current_y
- run
.desired_y
;
15627 FRAME_RIF (f
)->update_window_begin_hook (w
);
15628 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15629 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15630 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15634 /* Adjust Y positions of reused rows. */
15635 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15636 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15637 max_y
= it
.last_visible_y
;
15638 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15641 row
->visible_height
= row
->height
;
15642 if (row
->y
< min_y
)
15643 row
->visible_height
-= min_y
- row
->y
;
15644 if (row
->y
+ row
->height
> max_y
)
15645 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15646 row
->redraw_fringe_bitmaps_p
= 1;
15649 /* Scroll the current matrix. */
15650 xassert (nrows_scrolled
> 0);
15651 rotate_matrix (w
->current_matrix
,
15653 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15656 /* Disable rows not reused. */
15657 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15658 row
->enabled_p
= 0;
15660 /* Point may have moved to a different line, so we cannot assume that
15661 the previous cursor position is valid; locate the correct row. */
15664 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15665 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15669 w
->cursor
.y
= row
->y
;
15671 if (row
< bottom_row
)
15673 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15674 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15676 /* Can't use this optimization with bidi-reordered glyph
15677 rows, unless cursor is already at point. */
15678 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15680 if (!(w
->cursor
.hpos
>= 0
15681 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
15682 && BUFFERP (glyph
->object
)
15683 && glyph
->charpos
== PT
))
15688 && (!BUFFERP (glyph
->object
)
15689 || glyph
->charpos
< PT
);
15693 w
->cursor
.x
+= glyph
->pixel_width
;
15698 /* Adjust window end. A null value of last_text_row means that
15699 the window end is in reused rows which in turn means that
15700 only its vpos can have changed. */
15703 w
->window_end_bytepos
15704 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15706 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15708 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15713 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15716 w
->window_end_valid
= Qnil
;
15717 w
->desired_matrix
->no_scrolling_p
= 1;
15720 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15730 /************************************************************************
15731 Window redisplay reusing current matrix when buffer has changed
15732 ************************************************************************/
15734 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
15735 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
15736 EMACS_INT
*, EMACS_INT
*);
15737 static struct glyph_row
*
15738 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
15739 struct glyph_row
*);
15742 /* Return the last row in MATRIX displaying text. If row START is
15743 non-null, start searching with that row. IT gives the dimensions
15744 of the display. Value is null if matrix is empty; otherwise it is
15745 a pointer to the row found. */
15747 static struct glyph_row
*
15748 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
15749 struct glyph_row
*start
)
15751 struct glyph_row
*row
, *row_found
;
15753 /* Set row_found to the last row in IT->w's current matrix
15754 displaying text. The loop looks funny but think of partially
15757 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15758 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15760 xassert (row
->enabled_p
);
15762 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15771 /* Return the last row in the current matrix of W that is not affected
15772 by changes at the start of current_buffer that occurred since W's
15773 current matrix was built. Value is null if no such row exists.
15775 BEG_UNCHANGED us the number of characters unchanged at the start of
15776 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15777 first changed character in current_buffer. Characters at positions <
15778 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15779 when the current matrix was built. */
15781 static struct glyph_row
*
15782 find_last_unchanged_at_beg_row (struct window
*w
)
15784 EMACS_INT first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15785 struct glyph_row
*row
;
15786 struct glyph_row
*row_found
= NULL
;
15787 int yb
= window_text_bottom_y (w
);
15789 /* Find the last row displaying unchanged text. */
15790 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15791 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15792 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15795 if (/* If row ends before first_changed_pos, it is unchanged,
15796 except in some case. */
15797 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15798 /* When row ends in ZV and we write at ZV it is not
15800 && !row
->ends_at_zv_p
15801 /* When first_changed_pos is the end of a continued line,
15802 row is not unchanged because it may be no longer
15804 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15805 && (row
->continued_p
15806 || row
->exact_window_width_line_p
)))
15809 /* Stop if last visible row. */
15810 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15818 /* Find the first glyph row in the current matrix of W that is not
15819 affected by changes at the end of current_buffer since the
15820 time W's current matrix was built.
15822 Return in *DELTA the number of chars by which buffer positions in
15823 unchanged text at the end of current_buffer must be adjusted.
15825 Return in *DELTA_BYTES the corresponding number of bytes.
15827 Value is null if no such row exists, i.e. all rows are affected by
15830 static struct glyph_row
*
15831 find_first_unchanged_at_end_row (struct window
*w
,
15832 EMACS_INT
*delta
, EMACS_INT
*delta_bytes
)
15834 struct glyph_row
*row
;
15835 struct glyph_row
*row_found
= NULL
;
15837 *delta
= *delta_bytes
= 0;
15839 /* Display must not have been paused, otherwise the current matrix
15840 is not up to date. */
15841 eassert (!NILP (w
->window_end_valid
));
15843 /* A value of window_end_pos >= END_UNCHANGED means that the window
15844 end is in the range of changed text. If so, there is no
15845 unchanged row at the end of W's current matrix. */
15846 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15849 /* Set row to the last row in W's current matrix displaying text. */
15850 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15852 /* If matrix is entirely empty, no unchanged row exists. */
15853 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15855 /* The value of row is the last glyph row in the matrix having a
15856 meaningful buffer position in it. The end position of row
15857 corresponds to window_end_pos. This allows us to translate
15858 buffer positions in the current matrix to current buffer
15859 positions for characters not in changed text. */
15861 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15862 EMACS_INT Z_BYTE_old
=
15863 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15864 EMACS_INT last_unchanged_pos
, last_unchanged_pos_old
;
15865 struct glyph_row
*first_text_row
15866 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15868 *delta
= Z
- Z_old
;
15869 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15871 /* Set last_unchanged_pos to the buffer position of the last
15872 character in the buffer that has not been changed. Z is the
15873 index + 1 of the last character in current_buffer, i.e. by
15874 subtracting END_UNCHANGED we get the index of the last
15875 unchanged character, and we have to add BEG to get its buffer
15877 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15878 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15880 /* Search backward from ROW for a row displaying a line that
15881 starts at a minimum position >= last_unchanged_pos_old. */
15882 for (; row
> first_text_row
; --row
)
15884 /* This used to abort, but it can happen.
15885 It is ok to just stop the search instead here. KFS. */
15886 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15889 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15894 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15900 /* Make sure that glyph rows in the current matrix of window W
15901 reference the same glyph memory as corresponding rows in the
15902 frame's frame matrix. This function is called after scrolling W's
15903 current matrix on a terminal frame in try_window_id and
15904 try_window_reusing_current_matrix. */
15907 sync_frame_with_window_matrix_rows (struct window
*w
)
15909 struct frame
*f
= XFRAME (w
->frame
);
15910 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15912 /* Preconditions: W must be a leaf window and full-width. Its frame
15913 must have a frame matrix. */
15914 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15915 xassert (WINDOW_FULL_WIDTH_P (w
));
15916 xassert (!FRAME_WINDOW_P (f
));
15918 /* If W is a full-width window, glyph pointers in W's current matrix
15919 have, by definition, to be the same as glyph pointers in the
15920 corresponding frame matrix. Note that frame matrices have no
15921 marginal areas (see build_frame_matrix). */
15922 window_row
= w
->current_matrix
->rows
;
15923 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15924 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15925 while (window_row
< window_row_end
)
15927 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15928 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15930 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15931 frame_row
->glyphs
[TEXT_AREA
] = start
;
15932 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15933 frame_row
->glyphs
[LAST_AREA
] = end
;
15935 /* Disable frame rows whose corresponding window rows have
15936 been disabled in try_window_id. */
15937 if (!window_row
->enabled_p
)
15938 frame_row
->enabled_p
= 0;
15940 ++window_row
, ++frame_row
;
15945 /* Find the glyph row in window W containing CHARPOS. Consider all
15946 rows between START and END (not inclusive). END null means search
15947 all rows to the end of the display area of W. Value is the row
15948 containing CHARPOS or null. */
15951 row_containing_pos (struct window
*w
, EMACS_INT charpos
,
15952 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
15954 struct glyph_row
*row
= start
;
15955 struct glyph_row
*best_row
= NULL
;
15956 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15959 /* If we happen to start on a header-line, skip that. */
15960 if (row
->mode_line_p
)
15963 if ((end
&& row
>= end
) || !row
->enabled_p
)
15966 last_y
= window_text_bottom_y (w
) - dy
;
15970 /* Give up if we have gone too far. */
15971 if (end
&& row
>= end
)
15973 /* This formerly returned if they were equal.
15974 I think that both quantities are of a "last plus one" type;
15975 if so, when they are equal, the row is within the screen. -- rms. */
15976 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15979 /* If it is in this row, return this row. */
15980 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15981 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15982 /* The end position of a row equals the start
15983 position of the next row. If CHARPOS is there, we
15984 would rather display it in the next line, except
15985 when this line ends in ZV. */
15986 && !row
->ends_at_zv_p
15987 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15988 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15992 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
15993 || (!best_row
&& !row
->continued_p
))
15995 /* In bidi-reordered rows, there could be several rows
15996 occluding point, all of them belonging to the same
15997 continued line. We need to find the row which fits
15998 CHARPOS the best. */
15999 for (g
= row
->glyphs
[TEXT_AREA
];
16000 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16003 if (!STRINGP (g
->object
))
16005 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
16007 mindif
= eabs (g
->charpos
- charpos
);
16009 /* Exact match always wins. */
16016 else if (best_row
&& !row
->continued_p
)
16023 /* Try to redisplay window W by reusing its existing display. W's
16024 current matrix must be up to date when this function is called,
16025 i.e. window_end_valid must not be nil.
16029 1 if display has been updated
16030 0 if otherwise unsuccessful
16031 -1 if redisplay with same window start is known not to succeed
16033 The following steps are performed:
16035 1. Find the last row in the current matrix of W that is not
16036 affected by changes at the start of current_buffer. If no such row
16039 2. Find the first row in W's current matrix that is not affected by
16040 changes at the end of current_buffer. Maybe there is no such row.
16042 3. Display lines beginning with the row + 1 found in step 1 to the
16043 row found in step 2 or, if step 2 didn't find a row, to the end of
16046 4. If cursor is not known to appear on the window, give up.
16048 5. If display stopped at the row found in step 2, scroll the
16049 display and current matrix as needed.
16051 6. Maybe display some lines at the end of W, if we must. This can
16052 happen under various circumstances, like a partially visible line
16053 becoming fully visible, or because newly displayed lines are displayed
16054 in smaller font sizes.
16056 7. Update W's window end information. */
16059 try_window_id (struct window
*w
)
16061 struct frame
*f
= XFRAME (w
->frame
);
16062 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
16063 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
16064 struct glyph_row
*last_unchanged_at_beg_row
;
16065 struct glyph_row
*first_unchanged_at_end_row
;
16066 struct glyph_row
*row
;
16067 struct glyph_row
*bottom_row
;
16070 EMACS_INT delta
= 0, delta_bytes
= 0, stop_pos
;
16072 struct text_pos start_pos
;
16074 int first_unchanged_at_end_vpos
= 0;
16075 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
16076 struct text_pos start
;
16077 EMACS_INT first_changed_charpos
, last_changed_charpos
;
16080 if (inhibit_try_window_id
)
16084 /* This is handy for debugging. */
16086 #define GIVE_UP(X) \
16088 fprintf (stderr, "try_window_id give up %d\n", (X)); \
16092 #define GIVE_UP(X) return 0
16095 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
16097 /* Don't use this for mini-windows because these can show
16098 messages and mini-buffers, and we don't handle that here. */
16099 if (MINI_WINDOW_P (w
))
16102 /* This flag is used to prevent redisplay optimizations. */
16103 if (windows_or_buffers_changed
|| cursor_type_changed
)
16106 /* Verify that narrowing has not changed.
16107 Also verify that we were not told to prevent redisplay optimizations.
16108 It would be nice to further
16109 reduce the number of cases where this prevents try_window_id. */
16110 if (current_buffer
->clip_changed
16111 || current_buffer
->prevent_redisplay_optimizations_p
)
16114 /* Window must either use window-based redisplay or be full width. */
16115 if (!FRAME_WINDOW_P (f
)
16116 && (!FRAME_LINE_INS_DEL_OK (f
)
16117 || !WINDOW_FULL_WIDTH_P (w
)))
16120 /* Give up if point is known NOT to appear in W. */
16121 if (PT
< CHARPOS (start
))
16124 /* Another way to prevent redisplay optimizations. */
16125 if (XFASTINT (w
->last_modified
) == 0)
16128 /* Verify that window is not hscrolled. */
16129 if (XFASTINT (w
->hscroll
) != 0)
16132 /* Verify that display wasn't paused. */
16133 if (NILP (w
->window_end_valid
))
16136 /* Can't use this if highlighting a region because a cursor movement
16137 will do more than just set the cursor. */
16138 if (!NILP (Vtransient_mark_mode
)
16139 && !NILP (BVAR (current_buffer
, mark_active
)))
16142 /* Likewise if highlighting trailing whitespace. */
16143 if (!NILP (Vshow_trailing_whitespace
))
16146 /* Likewise if showing a region. */
16147 if (!NILP (w
->region_showing
))
16150 /* Can't use this if overlay arrow position and/or string have
16152 if (overlay_arrows_changed_p ())
16155 /* When word-wrap is on, adding a space to the first word of a
16156 wrapped line can change the wrap position, altering the line
16157 above it. It might be worthwhile to handle this more
16158 intelligently, but for now just redisplay from scratch. */
16159 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
16162 /* Under bidi reordering, adding or deleting a character in the
16163 beginning of a paragraph, before the first strong directional
16164 character, can change the base direction of the paragraph (unless
16165 the buffer specifies a fixed paragraph direction), which will
16166 require to redisplay the whole paragraph. It might be worthwhile
16167 to find the paragraph limits and widen the range of redisplayed
16168 lines to that, but for now just give up this optimization and
16169 redisplay from scratch. */
16170 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16171 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
16174 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
16175 only if buffer has really changed. The reason is that the gap is
16176 initially at Z for freshly visited files. The code below would
16177 set end_unchanged to 0 in that case. */
16178 if (MODIFF
> SAVE_MODIFF
16179 /* This seems to happen sometimes after saving a buffer. */
16180 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
16182 if (GPT
- BEG
< BEG_UNCHANGED
)
16183 BEG_UNCHANGED
= GPT
- BEG
;
16184 if (Z
- GPT
< END_UNCHANGED
)
16185 END_UNCHANGED
= Z
- GPT
;
16188 /* The position of the first and last character that has been changed. */
16189 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
16190 last_changed_charpos
= Z
- END_UNCHANGED
;
16192 /* If window starts after a line end, and the last change is in
16193 front of that newline, then changes don't affect the display.
16194 This case happens with stealth-fontification. Note that although
16195 the display is unchanged, glyph positions in the matrix have to
16196 be adjusted, of course. */
16197 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16198 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16199 && ((last_changed_charpos
< CHARPOS (start
)
16200 && CHARPOS (start
) == BEGV
)
16201 || (last_changed_charpos
< CHARPOS (start
) - 1
16202 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
16204 EMACS_INT Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
16205 struct glyph_row
*r0
;
16207 /* Compute how many chars/bytes have been added to or removed
16208 from the buffer. */
16209 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16210 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16211 Z_delta
= Z
- Z_old
;
16212 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16214 /* Give up if PT is not in the window. Note that it already has
16215 been checked at the start of try_window_id that PT is not in
16216 front of the window start. */
16217 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
16220 /* If window start is unchanged, we can reuse the whole matrix
16221 as is, after adjusting glyph positions. No need to compute
16222 the window end again, since its offset from Z hasn't changed. */
16223 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16224 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
16225 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
16226 /* PT must not be in a partially visible line. */
16227 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
16228 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
16230 /* Adjust positions in the glyph matrix. */
16231 if (Z_delta
|| Z_delta_bytes
)
16233 struct glyph_row
*r1
16234 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16235 increment_matrix_positions (w
->current_matrix
,
16236 MATRIX_ROW_VPOS (r0
, current_matrix
),
16237 MATRIX_ROW_VPOS (r1
, current_matrix
),
16238 Z_delta
, Z_delta_bytes
);
16241 /* Set the cursor. */
16242 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
16244 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
16251 /* Handle the case that changes are all below what is displayed in
16252 the window, and that PT is in the window. This shortcut cannot
16253 be taken if ZV is visible in the window, and text has been added
16254 there that is visible in the window. */
16255 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
16256 /* ZV is not visible in the window, or there are no
16257 changes at ZV, actually. */
16258 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
16259 || first_changed_charpos
== last_changed_charpos
))
16261 struct glyph_row
*r0
;
16263 /* Give up if PT is not in the window. Note that it already has
16264 been checked at the start of try_window_id that PT is not in
16265 front of the window start. */
16266 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
16269 /* If window start is unchanged, we can reuse the whole matrix
16270 as is, without changing glyph positions since no text has
16271 been added/removed in front of the window end. */
16272 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16273 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
16274 /* PT must not be in a partially visible line. */
16275 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
16276 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
16278 /* We have to compute the window end anew since text
16279 could have been added/removed after it. */
16281 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16282 w
->window_end_bytepos
16283 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16285 /* Set the cursor. */
16286 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
16288 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
16295 /* Give up if window start is in the changed area.
16297 The condition used to read
16299 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
16301 but why that was tested escapes me at the moment. */
16302 if (CHARPOS (start
) >= first_changed_charpos
16303 && CHARPOS (start
) <= last_changed_charpos
)
16306 /* Check that window start agrees with the start of the first glyph
16307 row in its current matrix. Check this after we know the window
16308 start is not in changed text, otherwise positions would not be
16310 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16311 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
16314 /* Give up if the window ends in strings. Overlay strings
16315 at the end are difficult to handle, so don't try. */
16316 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
16317 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
16320 /* Compute the position at which we have to start displaying new
16321 lines. Some of the lines at the top of the window might be
16322 reusable because they are not displaying changed text. Find the
16323 last row in W's current matrix not affected by changes at the
16324 start of current_buffer. Value is null if changes start in the
16325 first line of window. */
16326 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
16327 if (last_unchanged_at_beg_row
)
16329 /* Avoid starting to display in the moddle of a character, a TAB
16330 for instance. This is easier than to set up the iterator
16331 exactly, and it's not a frequent case, so the additional
16332 effort wouldn't really pay off. */
16333 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
16334 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
16335 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
16336 --last_unchanged_at_beg_row
;
16338 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
16341 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
16343 start_pos
= it
.current
.pos
;
16345 /* Start displaying new lines in the desired matrix at the same
16346 vpos we would use in the current matrix, i.e. below
16347 last_unchanged_at_beg_row. */
16348 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
16350 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16351 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
16353 xassert (it
.hpos
== 0 && it
.current_x
== 0);
16357 /* There are no reusable lines at the start of the window.
16358 Start displaying in the first text line. */
16359 start_display (&it
, w
, start
);
16360 it
.vpos
= it
.first_vpos
;
16361 start_pos
= it
.current
.pos
;
16364 /* Find the first row that is not affected by changes at the end of
16365 the buffer. Value will be null if there is no unchanged row, in
16366 which case we must redisplay to the end of the window. delta
16367 will be set to the value by which buffer positions beginning with
16368 first_unchanged_at_end_row have to be adjusted due to text
16370 first_unchanged_at_end_row
16371 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
16372 IF_DEBUG (debug_delta
= delta
);
16373 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
16375 /* Set stop_pos to the buffer position up to which we will have to
16376 display new lines. If first_unchanged_at_end_row != NULL, this
16377 is the buffer position of the start of the line displayed in that
16378 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
16379 that we don't stop at a buffer position. */
16381 if (first_unchanged_at_end_row
)
16383 xassert (last_unchanged_at_beg_row
== NULL
16384 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
16386 /* If this is a continuation line, move forward to the next one
16387 that isn't. Changes in lines above affect this line.
16388 Caution: this may move first_unchanged_at_end_row to a row
16389 not displaying text. */
16390 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
16391 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
16392 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
16393 < it
.last_visible_y
))
16394 ++first_unchanged_at_end_row
;
16396 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
16397 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
16398 >= it
.last_visible_y
))
16399 first_unchanged_at_end_row
= NULL
;
16402 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
16404 first_unchanged_at_end_vpos
16405 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
16406 xassert (stop_pos
>= Z
- END_UNCHANGED
);
16409 else if (last_unchanged_at_beg_row
== NULL
)
16415 /* Either there is no unchanged row at the end, or the one we have
16416 now displays text. This is a necessary condition for the window
16417 end pos calculation at the end of this function. */
16418 xassert (first_unchanged_at_end_row
== NULL
16419 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
16421 debug_last_unchanged_at_beg_vpos
16422 = (last_unchanged_at_beg_row
16423 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
16425 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
16427 #endif /* GLYPH_DEBUG != 0 */
16430 /* Display new lines. Set last_text_row to the last new line
16431 displayed which has text on it, i.e. might end up as being the
16432 line where the window_end_vpos is. */
16433 w
->cursor
.vpos
= -1;
16434 last_text_row
= NULL
;
16435 overlay_arrow_seen
= 0;
16436 while (it
.current_y
< it
.last_visible_y
16437 && !fonts_changed_p
16438 && (first_unchanged_at_end_row
== NULL
16439 || IT_CHARPOS (it
) < stop_pos
))
16441 if (display_line (&it
))
16442 last_text_row
= it
.glyph_row
- 1;
16445 if (fonts_changed_p
)
16449 /* Compute differences in buffer positions, y-positions etc. for
16450 lines reused at the bottom of the window. Compute what we can
16452 if (first_unchanged_at_end_row
16453 /* No lines reused because we displayed everything up to the
16454 bottom of the window. */
16455 && it
.current_y
< it
.last_visible_y
)
16458 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
16460 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
16461 run
.current_y
= first_unchanged_at_end_row
->y
;
16462 run
.desired_y
= run
.current_y
+ dy
;
16463 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
16467 delta
= delta_bytes
= dvpos
= dy
16468 = run
.current_y
= run
.desired_y
= run
.height
= 0;
16469 first_unchanged_at_end_row
= NULL
;
16471 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
16474 /* Find the cursor if not already found. We have to decide whether
16475 PT will appear on this window (it sometimes doesn't, but this is
16476 not a very frequent case.) This decision has to be made before
16477 the current matrix is altered. A value of cursor.vpos < 0 means
16478 that PT is either in one of the lines beginning at
16479 first_unchanged_at_end_row or below the window. Don't care for
16480 lines that might be displayed later at the window end; as
16481 mentioned, this is not a frequent case. */
16482 if (w
->cursor
.vpos
< 0)
16484 /* Cursor in unchanged rows at the top? */
16485 if (PT
< CHARPOS (start_pos
)
16486 && last_unchanged_at_beg_row
)
16488 row
= row_containing_pos (w
, PT
,
16489 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
16490 last_unchanged_at_beg_row
+ 1, 0);
16492 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16495 /* Start from first_unchanged_at_end_row looking for PT. */
16496 else if (first_unchanged_at_end_row
)
16498 row
= row_containing_pos (w
, PT
- delta
,
16499 first_unchanged_at_end_row
, NULL
, 0);
16501 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
16502 delta_bytes
, dy
, dvpos
);
16505 /* Give up if cursor was not found. */
16506 if (w
->cursor
.vpos
< 0)
16508 clear_glyph_matrix (w
->desired_matrix
);
16513 /* Don't let the cursor end in the scroll margins. */
16515 int this_scroll_margin
, cursor_height
;
16517 this_scroll_margin
= max (0, scroll_margin
);
16518 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16519 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
16520 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
16522 if ((w
->cursor
.y
< this_scroll_margin
16523 && CHARPOS (start
) > BEGV
)
16524 /* Old redisplay didn't take scroll margin into account at the bottom,
16525 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
16526 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
16527 ? cursor_height
+ this_scroll_margin
16528 : 1)) > it
.last_visible_y
)
16530 w
->cursor
.vpos
= -1;
16531 clear_glyph_matrix (w
->desired_matrix
);
16536 /* Scroll the display. Do it before changing the current matrix so
16537 that xterm.c doesn't get confused about where the cursor glyph is
16539 if (dy
&& run
.height
)
16543 if (FRAME_WINDOW_P (f
))
16545 FRAME_RIF (f
)->update_window_begin_hook (w
);
16546 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16547 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16548 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16552 /* Terminal frame. In this case, dvpos gives the number of
16553 lines to scroll by; dvpos < 0 means scroll up. */
16555 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
16556 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
16557 int end
= (WINDOW_TOP_EDGE_LINE (w
)
16558 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
16559 + window_internal_height (w
));
16561 #if defined (HAVE_GPM) || defined (MSDOS)
16562 x_clear_window_mouse_face (w
);
16564 /* Perform the operation on the screen. */
16567 /* Scroll last_unchanged_at_beg_row to the end of the
16568 window down dvpos lines. */
16569 set_terminal_window (f
, end
);
16571 /* On dumb terminals delete dvpos lines at the end
16572 before inserting dvpos empty lines. */
16573 if (!FRAME_SCROLL_REGION_OK (f
))
16574 ins_del_lines (f
, end
- dvpos
, -dvpos
);
16576 /* Insert dvpos empty lines in front of
16577 last_unchanged_at_beg_row. */
16578 ins_del_lines (f
, from
, dvpos
);
16580 else if (dvpos
< 0)
16582 /* Scroll up last_unchanged_at_beg_vpos to the end of
16583 the window to last_unchanged_at_beg_vpos - |dvpos|. */
16584 set_terminal_window (f
, end
);
16586 /* Delete dvpos lines in front of
16587 last_unchanged_at_beg_vpos. ins_del_lines will set
16588 the cursor to the given vpos and emit |dvpos| delete
16590 ins_del_lines (f
, from
+ dvpos
, dvpos
);
16592 /* On a dumb terminal insert dvpos empty lines at the
16594 if (!FRAME_SCROLL_REGION_OK (f
))
16595 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
16598 set_terminal_window (f
, 0);
16604 /* Shift reused rows of the current matrix to the right position.
16605 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
16607 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16608 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
16611 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
16612 bottom_vpos
, dvpos
);
16613 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
16616 else if (dvpos
> 0)
16618 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
16619 bottom_vpos
, dvpos
);
16620 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
16621 first_unchanged_at_end_vpos
+ dvpos
, 0);
16624 /* For frame-based redisplay, make sure that current frame and window
16625 matrix are in sync with respect to glyph memory. */
16626 if (!FRAME_WINDOW_P (f
))
16627 sync_frame_with_window_matrix_rows (w
);
16629 /* Adjust buffer positions in reused rows. */
16630 if (delta
|| delta_bytes
)
16631 increment_matrix_positions (current_matrix
,
16632 first_unchanged_at_end_vpos
+ dvpos
,
16633 bottom_vpos
, delta
, delta_bytes
);
16635 /* Adjust Y positions. */
16637 shift_glyph_matrix (w
, current_matrix
,
16638 first_unchanged_at_end_vpos
+ dvpos
,
16641 if (first_unchanged_at_end_row
)
16643 first_unchanged_at_end_row
+= dvpos
;
16644 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16645 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16646 first_unchanged_at_end_row
= NULL
;
16649 /* If scrolling up, there may be some lines to display at the end of
16651 last_text_row_at_end
= NULL
;
16654 /* Scrolling up can leave for example a partially visible line
16655 at the end of the window to be redisplayed. */
16656 /* Set last_row to the glyph row in the current matrix where the
16657 window end line is found. It has been moved up or down in
16658 the matrix by dvpos. */
16659 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16660 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16662 /* If last_row is the window end line, it should display text. */
16663 xassert (last_row
->displays_text_p
);
16665 /* If window end line was partially visible before, begin
16666 displaying at that line. Otherwise begin displaying with the
16667 line following it. */
16668 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16670 init_to_row_start (&it
, w
, last_row
);
16671 it
.vpos
= last_vpos
;
16672 it
.current_y
= last_row
->y
;
16676 init_to_row_end (&it
, w
, last_row
);
16677 it
.vpos
= 1 + last_vpos
;
16678 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16682 /* We may start in a continuation line. If so, we have to
16683 get the right continuation_lines_width and current_x. */
16684 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16685 it
.hpos
= it
.current_x
= 0;
16687 /* Display the rest of the lines at the window end. */
16688 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16689 while (it
.current_y
< it
.last_visible_y
16690 && !fonts_changed_p
)
16692 /* Is it always sure that the display agrees with lines in
16693 the current matrix? I don't think so, so we mark rows
16694 displayed invalid in the current matrix by setting their
16695 enabled_p flag to zero. */
16696 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16697 if (display_line (&it
))
16698 last_text_row_at_end
= it
.glyph_row
- 1;
16702 /* Update window_end_pos and window_end_vpos. */
16703 if (first_unchanged_at_end_row
16704 && !last_text_row_at_end
)
16706 /* Window end line if one of the preserved rows from the current
16707 matrix. Set row to the last row displaying text in current
16708 matrix starting at first_unchanged_at_end_row, after
16710 xassert (first_unchanged_at_end_row
->displays_text_p
);
16711 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16712 first_unchanged_at_end_row
);
16713 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16715 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16716 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16718 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16719 xassert (w
->window_end_bytepos
>= 0);
16720 IF_DEBUG (debug_method_add (w
, "A"));
16722 else if (last_text_row_at_end
)
16725 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16726 w
->window_end_bytepos
16727 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16729 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16730 xassert (w
->window_end_bytepos
>= 0);
16731 IF_DEBUG (debug_method_add (w
, "B"));
16733 else if (last_text_row
)
16735 /* We have displayed either to the end of the window or at the
16736 end of the window, i.e. the last row with text is to be found
16737 in the desired matrix. */
16739 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16740 w
->window_end_bytepos
16741 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16743 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16744 xassert (w
->window_end_bytepos
>= 0);
16746 else if (first_unchanged_at_end_row
== NULL
16747 && last_text_row
== NULL
16748 && last_text_row_at_end
== NULL
)
16750 /* Displayed to end of window, but no line containing text was
16751 displayed. Lines were deleted at the end of the window. */
16752 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16753 int vpos
= XFASTINT (w
->window_end_vpos
);
16754 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16755 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16758 row
== NULL
&& vpos
>= first_vpos
;
16759 --vpos
, --current_row
, --desired_row
)
16761 if (desired_row
->enabled_p
)
16763 if (desired_row
->displays_text_p
)
16766 else if (current_row
->displays_text_p
)
16770 xassert (row
!= NULL
);
16771 w
->window_end_vpos
= make_number (vpos
+ 1);
16772 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16773 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16774 xassert (w
->window_end_bytepos
>= 0);
16775 IF_DEBUG (debug_method_add (w
, "C"));
16780 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16781 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16783 /* Record that display has not been completed. */
16784 w
->window_end_valid
= Qnil
;
16785 w
->desired_matrix
->no_scrolling_p
= 1;
16793 /***********************************************************************
16794 More debugging support
16795 ***********************************************************************/
16799 void dump_glyph_row (struct glyph_row
*, int, int);
16800 void dump_glyph_matrix (struct glyph_matrix
*, int);
16801 void dump_glyph (struct glyph_row
*, struct glyph
*, int);
16804 /* Dump the contents of glyph matrix MATRIX on stderr.
16806 GLYPHS 0 means don't show glyph contents.
16807 GLYPHS 1 means show glyphs in short form
16808 GLYPHS > 1 means show glyphs in long form. */
16811 dump_glyph_matrix (matrix
, glyphs
)
16812 struct glyph_matrix
*matrix
;
16816 for (i
= 0; i
< matrix
->nrows
; ++i
)
16817 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16821 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16822 the glyph row and area where the glyph comes from. */
16825 dump_glyph (row
, glyph
, area
)
16826 struct glyph_row
*row
;
16827 struct glyph
*glyph
;
16830 if (glyph
->type
== CHAR_GLYPH
)
16833 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16834 glyph
- row
->glyphs
[TEXT_AREA
],
16837 (BUFFERP (glyph
->object
)
16839 : (STRINGP (glyph
->object
)
16842 glyph
->pixel_width
,
16844 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16848 glyph
->left_box_line_p
,
16849 glyph
->right_box_line_p
);
16851 else if (glyph
->type
== STRETCH_GLYPH
)
16854 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16855 glyph
- row
->glyphs
[TEXT_AREA
],
16858 (BUFFERP (glyph
->object
)
16860 : (STRINGP (glyph
->object
)
16863 glyph
->pixel_width
,
16867 glyph
->left_box_line_p
,
16868 glyph
->right_box_line_p
);
16870 else if (glyph
->type
== IMAGE_GLYPH
)
16873 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16874 glyph
- row
->glyphs
[TEXT_AREA
],
16877 (BUFFERP (glyph
->object
)
16879 : (STRINGP (glyph
->object
)
16882 glyph
->pixel_width
,
16886 glyph
->left_box_line_p
,
16887 glyph
->right_box_line_p
);
16889 else if (glyph
->type
== COMPOSITE_GLYPH
)
16892 " %5d %4c %6d %c %3d 0x%05x",
16893 glyph
- row
->glyphs
[TEXT_AREA
],
16896 (BUFFERP (glyph
->object
)
16898 : (STRINGP (glyph
->object
)
16901 glyph
->pixel_width
,
16903 if (glyph
->u
.cmp
.automatic
)
16906 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
16907 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16909 glyph
->left_box_line_p
,
16910 glyph
->right_box_line_p
);
16915 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16916 GLYPHS 0 means don't show glyph contents.
16917 GLYPHS 1 means show glyphs in short form
16918 GLYPHS > 1 means show glyphs in long form. */
16921 dump_glyph_row (row
, vpos
, glyphs
)
16922 struct glyph_row
*row
;
16927 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16928 fprintf (stderr
, "======================================================================\n");
16930 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16931 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16933 MATRIX_ROW_START_CHARPOS (row
),
16934 MATRIX_ROW_END_CHARPOS (row
),
16935 row
->used
[TEXT_AREA
],
16936 row
->contains_overlapping_glyphs_p
,
16938 row
->truncated_on_left_p
,
16939 row
->truncated_on_right_p
,
16941 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16942 row
->displays_text_p
,
16945 row
->ends_in_middle_of_char_p
,
16946 row
->starts_in_middle_of_char_p
,
16952 row
->visible_height
,
16955 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16956 row
->end
.overlay_string_index
,
16957 row
->continuation_lines_width
);
16958 fprintf (stderr
, "%9d %5d\n",
16959 CHARPOS (row
->start
.string_pos
),
16960 CHARPOS (row
->end
.string_pos
));
16961 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16962 row
->end
.dpvec_index
);
16969 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16971 struct glyph
*glyph
= row
->glyphs
[area
];
16972 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16974 /* Glyph for a line end in text. */
16975 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16978 if (glyph
< glyph_end
)
16979 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16981 for (; glyph
< glyph_end
; ++glyph
)
16982 dump_glyph (row
, glyph
, area
);
16985 else if (glyphs
== 1)
16989 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16991 char *s
= (char *) alloca (row
->used
[area
] + 1);
16994 for (i
= 0; i
< row
->used
[area
]; ++i
)
16996 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16997 if (glyph
->type
== CHAR_GLYPH
16998 && glyph
->u
.ch
< 0x80
16999 && glyph
->u
.ch
>= ' ')
17000 s
[i
] = glyph
->u
.ch
;
17006 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
17012 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
17013 Sdump_glyph_matrix
, 0, 1, "p",
17014 doc
: /* Dump the current matrix of the selected window to stderr.
17015 Shows contents of glyph row structures. With non-nil
17016 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
17017 glyphs in short form, otherwise show glyphs in long form. */)
17018 (Lisp_Object glyphs
)
17020 struct window
*w
= XWINDOW (selected_window
);
17021 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17023 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
17024 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
17025 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
17026 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
17027 fprintf (stderr
, "=============================================\n");
17028 dump_glyph_matrix (w
->current_matrix
,
17029 NILP (glyphs
) ? 0 : XINT (glyphs
));
17034 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
17035 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
17038 struct frame
*f
= XFRAME (selected_frame
);
17039 dump_glyph_matrix (f
->current_matrix
, 1);
17044 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
17045 doc
: /* Dump glyph row ROW to stderr.
17046 GLYPH 0 means don't dump glyphs.
17047 GLYPH 1 means dump glyphs in short form.
17048 GLYPH > 1 or omitted means dump glyphs in long form. */)
17049 (Lisp_Object row
, Lisp_Object glyphs
)
17051 struct glyph_matrix
*matrix
;
17054 CHECK_NUMBER (row
);
17055 matrix
= XWINDOW (selected_window
)->current_matrix
;
17057 if (vpos
>= 0 && vpos
< matrix
->nrows
)
17058 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
17060 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
17065 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
17066 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
17067 GLYPH 0 means don't dump glyphs.
17068 GLYPH 1 means dump glyphs in short form.
17069 GLYPH > 1 or omitted means dump glyphs in long form. */)
17070 (Lisp_Object row
, Lisp_Object glyphs
)
17072 struct frame
*sf
= SELECTED_FRAME ();
17073 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
17076 CHECK_NUMBER (row
);
17078 if (vpos
>= 0 && vpos
< m
->nrows
)
17079 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
17080 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
17085 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
17086 doc
: /* Toggle tracing of redisplay.
17087 With ARG, turn tracing on if and only if ARG is positive. */)
17091 trace_redisplay_p
= !trace_redisplay_p
;
17094 arg
= Fprefix_numeric_value (arg
);
17095 trace_redisplay_p
= XINT (arg
) > 0;
17102 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
17103 doc
: /* Like `format', but print result to stderr.
17104 usage: (trace-to-stderr STRING &rest OBJECTS) */)
17105 (size_t nargs
, Lisp_Object
*args
)
17107 Lisp_Object s
= Fformat (nargs
, args
);
17108 fprintf (stderr
, "%s", SDATA (s
));
17112 #endif /* GLYPH_DEBUG */
17116 /***********************************************************************
17117 Building Desired Matrix Rows
17118 ***********************************************************************/
17120 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
17121 Used for non-window-redisplay windows, and for windows w/o left fringe. */
17123 static struct glyph_row
*
17124 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
17126 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17127 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17128 struct buffer
*old
= current_buffer
;
17129 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
17130 int arrow_len
= SCHARS (overlay_arrow_string
);
17131 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
17132 const unsigned char *p
;
17135 int n_glyphs_before
;
17137 set_buffer_temp (buffer
);
17138 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
17139 it
.glyph_row
->used
[TEXT_AREA
] = 0;
17140 SET_TEXT_POS (it
.position
, 0, 0);
17142 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
17144 while (p
< arrow_end
)
17146 Lisp_Object face
, ilisp
;
17148 /* Get the next character. */
17150 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
17153 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
17154 if (! ASCII_CHAR_P (it
.c
))
17155 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
17159 /* Get its face. */
17160 ilisp
= make_number (p
- arrow_string
);
17161 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
17162 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
17164 /* Compute its width, get its glyphs. */
17165 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
17166 SET_TEXT_POS (it
.position
, -1, -1);
17167 PRODUCE_GLYPHS (&it
);
17169 /* If this character doesn't fit any more in the line, we have
17170 to remove some glyphs. */
17171 if (it
.current_x
> it
.last_visible_x
)
17173 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17178 set_buffer_temp (old
);
17179 return it
.glyph_row
;
17183 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
17184 glyphs are only inserted for terminal frames since we can't really
17185 win with truncation glyphs when partially visible glyphs are
17186 involved. Which glyphs to insert is determined by
17187 produce_special_glyphs. */
17190 insert_left_trunc_glyphs (struct it
*it
)
17192 struct it truncate_it
;
17193 struct glyph
*from
, *end
, *to
, *toend
;
17195 xassert (!FRAME_WINDOW_P (it
->f
));
17197 /* Get the truncation glyphs. */
17199 truncate_it
.current_x
= 0;
17200 truncate_it
.face_id
= DEFAULT_FACE_ID
;
17201 truncate_it
.glyph_row
= &scratch_glyph_row
;
17202 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
17203 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
17204 truncate_it
.object
= make_number (0);
17205 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
17207 /* Overwrite glyphs from IT with truncation glyphs. */
17208 if (!it
->glyph_row
->reversed_p
)
17210 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17211 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
17212 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17213 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
17218 /* There may be padding glyphs left over. Overwrite them too. */
17219 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
17221 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17227 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
17231 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
17232 that back to front. */
17233 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17234 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17235 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17236 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17238 while (from
>= end
&& to
>= toend
)
17240 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
17243 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
17244 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17245 while (from
>= end
&& to
>= toend
)
17250 /* Need to free some room before prepending additional
17252 int move_by
= from
- end
+ 1;
17253 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17254 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17256 for ( ; g
>= g0
; g
--)
17258 while (from
>= end
)
17260 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
17266 /* Compute the pixel height and width of IT->glyph_row.
17268 Most of the time, ascent and height of a display line will be equal
17269 to the max_ascent and max_height values of the display iterator
17270 structure. This is not the case if
17272 1. We hit ZV without displaying anything. In this case, max_ascent
17273 and max_height will be zero.
17275 2. We have some glyphs that don't contribute to the line height.
17276 (The glyph row flag contributes_to_line_height_p is for future
17277 pixmap extensions).
17279 The first case is easily covered by using default values because in
17280 these cases, the line height does not really matter, except that it
17281 must not be zero. */
17284 compute_line_metrics (struct it
*it
)
17286 struct glyph_row
*row
= it
->glyph_row
;
17288 if (FRAME_WINDOW_P (it
->f
))
17290 int i
, min_y
, max_y
;
17292 /* The line may consist of one space only, that was added to
17293 place the cursor on it. If so, the row's height hasn't been
17295 if (row
->height
== 0)
17297 if (it
->max_ascent
+ it
->max_descent
== 0)
17298 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
17299 row
->ascent
= it
->max_ascent
;
17300 row
->height
= it
->max_ascent
+ it
->max_descent
;
17301 row
->phys_ascent
= it
->max_phys_ascent
;
17302 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17303 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17306 /* Compute the width of this line. */
17307 row
->pixel_width
= row
->x
;
17308 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
17309 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
17311 xassert (row
->pixel_width
>= 0);
17312 xassert (row
->ascent
>= 0 && row
->height
> 0);
17314 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
17315 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
17317 /* If first line's physical ascent is larger than its logical
17318 ascent, use the physical ascent, and make the row taller.
17319 This makes accented characters fully visible. */
17320 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
17321 && row
->phys_ascent
> row
->ascent
)
17323 row
->height
+= row
->phys_ascent
- row
->ascent
;
17324 row
->ascent
= row
->phys_ascent
;
17327 /* Compute how much of the line is visible. */
17328 row
->visible_height
= row
->height
;
17330 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
17331 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
17333 if (row
->y
< min_y
)
17334 row
->visible_height
-= min_y
- row
->y
;
17335 if (row
->y
+ row
->height
> max_y
)
17336 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17340 row
->pixel_width
= row
->used
[TEXT_AREA
];
17341 if (row
->continued_p
)
17342 row
->pixel_width
-= it
->continuation_pixel_width
;
17343 else if (row
->truncated_on_right_p
)
17344 row
->pixel_width
-= it
->truncation_pixel_width
;
17345 row
->ascent
= row
->phys_ascent
= 0;
17346 row
->height
= row
->phys_height
= row
->visible_height
= 1;
17347 row
->extra_line_spacing
= 0;
17350 /* Compute a hash code for this row. */
17354 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17355 for (i
= 0; i
< row
->used
[area
]; ++i
)
17356 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
17357 + row
->glyphs
[area
][i
].u
.val
17358 + row
->glyphs
[area
][i
].face_id
17359 + row
->glyphs
[area
][i
].padding_p
17360 + (row
->glyphs
[area
][i
].type
<< 2));
17363 it
->max_ascent
= it
->max_descent
= 0;
17364 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
17368 /* Append one space to the glyph row of iterator IT if doing a
17369 window-based redisplay. The space has the same face as
17370 IT->face_id. Value is non-zero if a space was added.
17372 This function is called to make sure that there is always one glyph
17373 at the end of a glyph row that the cursor can be set on under
17374 window-systems. (If there weren't such a glyph we would not know
17375 how wide and tall a box cursor should be displayed).
17377 At the same time this space let's a nicely handle clearing to the
17378 end of the line if the row ends in italic text. */
17381 append_space_for_newline (struct it
*it
, int default_face_p
)
17383 if (FRAME_WINDOW_P (it
->f
))
17385 int n
= it
->glyph_row
->used
[TEXT_AREA
];
17387 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
17388 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
17390 /* Save some values that must not be changed.
17391 Must save IT->c and IT->len because otherwise
17392 ITERATOR_AT_END_P wouldn't work anymore after
17393 append_space_for_newline has been called. */
17394 enum display_element_type saved_what
= it
->what
;
17395 int saved_c
= it
->c
, saved_len
= it
->len
;
17396 int saved_char_to_display
= it
->char_to_display
;
17397 int saved_x
= it
->current_x
;
17398 int saved_face_id
= it
->face_id
;
17399 struct text_pos saved_pos
;
17400 Lisp_Object saved_object
;
17403 saved_object
= it
->object
;
17404 saved_pos
= it
->position
;
17406 it
->what
= IT_CHARACTER
;
17407 memset (&it
->position
, 0, sizeof it
->position
);
17408 it
->object
= make_number (0);
17409 it
->c
= it
->char_to_display
= ' ';
17412 if (default_face_p
)
17413 it
->face_id
= DEFAULT_FACE_ID
;
17414 else if (it
->face_before_selective_p
)
17415 it
->face_id
= it
->saved_face_id
;
17416 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17417 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
17419 PRODUCE_GLYPHS (it
);
17421 it
->override_ascent
= -1;
17422 it
->constrain_row_ascent_descent_p
= 0;
17423 it
->current_x
= saved_x
;
17424 it
->object
= saved_object
;
17425 it
->position
= saved_pos
;
17426 it
->what
= saved_what
;
17427 it
->face_id
= saved_face_id
;
17428 it
->len
= saved_len
;
17430 it
->char_to_display
= saved_char_to_display
;
17439 /* Extend the face of the last glyph in the text area of IT->glyph_row
17440 to the end of the display line. Called from display_line. If the
17441 glyph row is empty, add a space glyph to it so that we know the
17442 face to draw. Set the glyph row flag fill_line_p. If the glyph
17443 row is R2L, prepend a stretch glyph to cover the empty space to the
17444 left of the leftmost glyph. */
17447 extend_face_to_end_of_line (struct it
*it
)
17450 struct frame
*f
= it
->f
;
17452 /* If line is already filled, do nothing. Non window-system frames
17453 get a grace of one more ``pixel'' because their characters are
17454 1-``pixel'' wide, so they hit the equality too early. This grace
17455 is needed only for R2L rows that are not continued, to produce
17456 one extra blank where we could display the cursor. */
17457 if (it
->current_x
>= it
->last_visible_x
17458 + (!FRAME_WINDOW_P (f
)
17459 && it
->glyph_row
->reversed_p
17460 && !it
->glyph_row
->continued_p
))
17463 /* Face extension extends the background and box of IT->face_id
17464 to the end of the line. If the background equals the background
17465 of the frame, we don't have to do anything. */
17466 if (it
->face_before_selective_p
)
17467 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
17469 face
= FACE_FROM_ID (f
, it
->face_id
);
17471 if (FRAME_WINDOW_P (f
)
17472 && it
->glyph_row
->displays_text_p
17473 && face
->box
== FACE_NO_BOX
17474 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
17476 && !it
->glyph_row
->reversed_p
)
17479 /* Set the glyph row flag indicating that the face of the last glyph
17480 in the text area has to be drawn to the end of the text area. */
17481 it
->glyph_row
->fill_line_p
= 1;
17483 /* If current character of IT is not ASCII, make sure we have the
17484 ASCII face. This will be automatically undone the next time
17485 get_next_display_element returns a multibyte character. Note
17486 that the character will always be single byte in unibyte
17488 if (!ASCII_CHAR_P (it
->c
))
17490 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
17493 if (FRAME_WINDOW_P (f
))
17495 /* If the row is empty, add a space with the current face of IT,
17496 so that we know which face to draw. */
17497 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
17499 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
17500 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
17501 it
->glyph_row
->used
[TEXT_AREA
] = 1;
17503 #ifdef HAVE_WINDOW_SYSTEM
17504 if (it
->glyph_row
->reversed_p
)
17506 /* Prepend a stretch glyph to the row, such that the
17507 rightmost glyph will be drawn flushed all the way to the
17508 right margin of the window. The stretch glyph that will
17509 occupy the empty space, if any, to the left of the
17511 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
17512 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17513 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
17515 int row_width
, stretch_ascent
, stretch_width
;
17516 struct text_pos saved_pos
;
17517 int saved_face_id
, saved_avoid_cursor
;
17519 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
17520 row_width
+= g
->pixel_width
;
17521 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
17522 if (stretch_width
> 0)
17525 (((it
->ascent
+ it
->descent
)
17526 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
17527 saved_pos
= it
->position
;
17528 memset (&it
->position
, 0, sizeof it
->position
);
17529 saved_avoid_cursor
= it
->avoid_cursor_p
;
17530 it
->avoid_cursor_p
= 1;
17531 saved_face_id
= it
->face_id
;
17532 /* The last row's stretch glyph should get the default
17533 face, to avoid painting the rest of the window with
17534 the region face, if the region ends at ZV. */
17535 if (it
->glyph_row
->ends_at_zv_p
)
17536 it
->face_id
= DEFAULT_FACE_ID
;
17538 it
->face_id
= face
->id
;
17539 append_stretch_glyph (it
, make_number (0), stretch_width
,
17540 it
->ascent
+ it
->descent
, stretch_ascent
);
17541 it
->position
= saved_pos
;
17542 it
->avoid_cursor_p
= saved_avoid_cursor
;
17543 it
->face_id
= saved_face_id
;
17546 #endif /* HAVE_WINDOW_SYSTEM */
17550 /* Save some values that must not be changed. */
17551 int saved_x
= it
->current_x
;
17552 struct text_pos saved_pos
;
17553 Lisp_Object saved_object
;
17554 enum display_element_type saved_what
= it
->what
;
17555 int saved_face_id
= it
->face_id
;
17557 saved_object
= it
->object
;
17558 saved_pos
= it
->position
;
17560 it
->what
= IT_CHARACTER
;
17561 memset (&it
->position
, 0, sizeof it
->position
);
17562 it
->object
= make_number (0);
17563 it
->c
= it
->char_to_display
= ' ';
17565 /* The last row's blank glyphs should get the default face, to
17566 avoid painting the rest of the window with the region face,
17567 if the region ends at ZV. */
17568 if (it
->glyph_row
->ends_at_zv_p
)
17569 it
->face_id
= DEFAULT_FACE_ID
;
17571 it
->face_id
= face
->id
;
17573 PRODUCE_GLYPHS (it
);
17575 while (it
->current_x
<= it
->last_visible_x
)
17576 PRODUCE_GLYPHS (it
);
17578 /* Don't count these blanks really. It would let us insert a left
17579 truncation glyph below and make us set the cursor on them, maybe. */
17580 it
->current_x
= saved_x
;
17581 it
->object
= saved_object
;
17582 it
->position
= saved_pos
;
17583 it
->what
= saved_what
;
17584 it
->face_id
= saved_face_id
;
17589 /* Value is non-zero if text starting at CHARPOS in current_buffer is
17590 trailing whitespace. */
17593 trailing_whitespace_p (EMACS_INT charpos
)
17595 EMACS_INT bytepos
= CHAR_TO_BYTE (charpos
);
17598 while (bytepos
< ZV_BYTE
17599 && (c
= FETCH_CHAR (bytepos
),
17600 c
== ' ' || c
== '\t'))
17603 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
17605 if (bytepos
!= PT_BYTE
)
17612 /* Highlight trailing whitespace, if any, in ROW. */
17615 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
17617 int used
= row
->used
[TEXT_AREA
];
17621 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
17622 struct glyph
*glyph
= start
+ used
- 1;
17624 if (row
->reversed_p
)
17626 /* Right-to-left rows need to be processed in the opposite
17627 direction, so swap the edge pointers. */
17629 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
17632 /* Skip over glyphs inserted to display the cursor at the
17633 end of a line, for extending the face of the last glyph
17634 to the end of the line on terminals, and for truncation
17635 and continuation glyphs. */
17636 if (!row
->reversed_p
)
17638 while (glyph
>= start
17639 && glyph
->type
== CHAR_GLYPH
17640 && INTEGERP (glyph
->object
))
17645 while (glyph
<= start
17646 && glyph
->type
== CHAR_GLYPH
17647 && INTEGERP (glyph
->object
))
17651 /* If last glyph is a space or stretch, and it's trailing
17652 whitespace, set the face of all trailing whitespace glyphs in
17653 IT->glyph_row to `trailing-whitespace'. */
17654 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
17655 && BUFFERP (glyph
->object
)
17656 && (glyph
->type
== STRETCH_GLYPH
17657 || (glyph
->type
== CHAR_GLYPH
17658 && glyph
->u
.ch
== ' '))
17659 && trailing_whitespace_p (glyph
->charpos
))
17661 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
17665 if (!row
->reversed_p
)
17667 while (glyph
>= start
17668 && BUFFERP (glyph
->object
)
17669 && (glyph
->type
== STRETCH_GLYPH
17670 || (glyph
->type
== CHAR_GLYPH
17671 && glyph
->u
.ch
== ' ')))
17672 (glyph
--)->face_id
= face_id
;
17676 while (glyph
<= start
17677 && BUFFERP (glyph
->object
)
17678 && (glyph
->type
== STRETCH_GLYPH
17679 || (glyph
->type
== CHAR_GLYPH
17680 && glyph
->u
.ch
== ' ')))
17681 (glyph
++)->face_id
= face_id
;
17688 /* Value is non-zero if glyph row ROW should be
17689 used to hold the cursor. */
17692 cursor_row_p (struct glyph_row
*row
)
17696 if (PT
== CHARPOS (row
->end
.pos
))
17698 /* Suppose the row ends on a string.
17699 Unless the row is continued, that means it ends on a newline
17700 in the string. If it's anything other than a display string
17701 (e.g. a before-string from an overlay), we don't want the
17702 cursor there. (This heuristic seems to give the optimal
17703 behavior for the various types of multi-line strings.) */
17704 if (CHARPOS (row
->end
.string_pos
) >= 0)
17706 if (row
->continued_p
)
17710 /* Check for `display' property. */
17711 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17712 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17713 struct glyph
*glyph
;
17716 for (glyph
= end
; glyph
>= beg
; --glyph
)
17717 if (STRINGP (glyph
->object
))
17720 = Fget_char_property (make_number (PT
),
17724 && display_prop_string_p (prop
, glyph
->object
));
17729 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17731 /* If the row ends in middle of a real character,
17732 and the line is continued, we want the cursor here.
17733 That's because CHARPOS (ROW->end.pos) would equal
17734 PT if PT is before the character. */
17735 if (!row
->ends_in_ellipsis_p
)
17736 result
= row
->continued_p
;
17738 /* If the row ends in an ellipsis, then
17739 CHARPOS (ROW->end.pos) will equal point after the
17740 invisible text. We want that position to be displayed
17741 after the ellipsis. */
17744 /* If the row ends at ZV, display the cursor at the end of that
17745 row instead of at the start of the row below. */
17746 else if (row
->ends_at_zv_p
)
17757 /* Push the display property PROP so that it will be rendered at the
17758 current position in IT. Return 1 if PROP was successfully pushed,
17762 push_display_prop (struct it
*it
, Lisp_Object prop
)
17764 xassert (it
->method
== GET_FROM_BUFFER
);
17766 push_it (it
, NULL
);
17768 if (STRINGP (prop
))
17770 if (SCHARS (prop
) == 0)
17777 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17778 it
->current
.overlay_string_index
= -1;
17779 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17780 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17781 it
->method
= GET_FROM_STRING
;
17782 it
->stop_charpos
= 0;
17784 it
->base_level_stop
= 0;
17785 it
->string_from_display_prop_p
= 1;
17787 /* Force paragraph direction to be that of the parent
17789 it
->paragraph_embedding
= (it
->bidi_p
? it
->bidi_it
.paragraph_dir
: L2R
);
17791 /* Do we need to reorder this string? */
17792 if (it
->multibyte_p
)
17793 it
->bidi_p
= !NILP (BVAR (current_buffer
, bidi_display_reordering
));
17797 /* Set up the bidi iterator for this display string. */
17800 it
->bidi_it
.string
.lstring
= it
->string
;
17801 it
->bidi_it
.string
.s
= NULL
;
17802 it
->bidi_it
.string
.schars
= it
->end_charpos
;
17803 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
17804 it
->bidi_it
.string
.from_disp_str
= 1;
17805 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
17808 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17810 it
->method
= GET_FROM_STRETCH
;
17813 #ifdef HAVE_WINDOW_SYSTEM
17814 else if (IMAGEP (prop
))
17816 it
->what
= IT_IMAGE
;
17817 it
->image_id
= lookup_image (it
->f
, prop
);
17818 it
->method
= GET_FROM_IMAGE
;
17820 #endif /* HAVE_WINDOW_SYSTEM */
17823 pop_it (it
); /* bogus display property, give up */
17830 /* Return the character-property PROP at the current position in IT. */
17833 get_it_property (struct it
*it
, Lisp_Object prop
)
17835 Lisp_Object position
;
17837 if (STRINGP (it
->object
))
17838 position
= make_number (IT_STRING_CHARPOS (*it
));
17839 else if (BUFFERP (it
->object
))
17840 position
= make_number (IT_CHARPOS (*it
));
17844 return Fget_char_property (position
, prop
, it
->object
);
17847 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17850 handle_line_prefix (struct it
*it
)
17852 Lisp_Object prefix
;
17854 if (it
->continuation_lines_width
> 0)
17856 prefix
= get_it_property (it
, Qwrap_prefix
);
17858 prefix
= Vwrap_prefix
;
17862 prefix
= get_it_property (it
, Qline_prefix
);
17864 prefix
= Vline_prefix
;
17866 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17868 /* If the prefix is wider than the window, and we try to wrap
17869 it, it would acquire its own wrap prefix, and so on till the
17870 iterator stack overflows. So, don't wrap the prefix. */
17871 it
->line_wrap
= TRUNCATE
;
17872 it
->avoid_cursor_p
= 1;
17878 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
17879 only for R2L lines from display_line and display_string, when they
17880 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
17881 the line/string needs to be continued on the next glyph row. */
17883 unproduce_glyphs (struct it
*it
, int n
)
17885 struct glyph
*glyph
, *end
;
17887 xassert (it
->glyph_row
);
17888 xassert (it
->glyph_row
->reversed_p
);
17889 xassert (it
->area
== TEXT_AREA
);
17890 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
17892 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
17893 n
= it
->glyph_row
->used
[TEXT_AREA
];
17894 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
17895 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
17896 for ( ; glyph
< end
; glyph
++)
17897 glyph
[-n
] = *glyph
;
17900 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
17901 and ROW->maxpos. */
17903 find_row_edges (struct it
*it
, struct glyph_row
*row
,
17904 EMACS_INT min_pos
, EMACS_INT min_bpos
,
17905 EMACS_INT max_pos
, EMACS_INT max_bpos
)
17907 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17908 lines' rows is implemented for bidi-reordered rows. */
17910 /* ROW->minpos is the value of min_pos, the minimal buffer position
17913 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
17915 /* We didn't find _any_ valid buffer positions in any of the
17916 glyphs, so we must trust the iterator's computed positions. */
17917 row
->minpos
= row
->start
.pos
;
17920 max_pos
= CHARPOS (it
->current
.pos
);
17921 max_bpos
= BYTEPOS (it
->current
.pos
);
17924 /* Here are the various use-cases for ending the row, and the
17925 corresponding values for ROW->maxpos:
17927 Line ends in a newline from buffer eol_pos + 1
17928 Line is continued from buffer max_pos + 1
17929 Line is truncated on right it->current.pos
17930 Line ends in a newline from string max_pos
17931 Line is continued from string max_pos
17932 Line is continued from display vector max_pos
17933 Line is entirely from a string min_pos == max_pos
17934 Line is entirely from a display vector min_pos == max_pos
17935 Line that ends at ZV ZV
17937 If you discover other use-cases, please add them here as
17939 if (row
->ends_at_zv_p
)
17940 row
->maxpos
= it
->current
.pos
;
17941 else if (row
->used
[TEXT_AREA
])
17943 if (row
->ends_in_newline_from_string_p
)
17944 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17945 else if (CHARPOS (it
->eol_pos
) > 0)
17946 SET_TEXT_POS (row
->maxpos
,
17947 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
17948 else if (row
->continued_p
)
17950 /* If max_pos is different from IT's current position, it
17951 means IT->method does not belong to the display element
17952 at max_pos. However, it also means that the display
17953 element at max_pos was displayed in its entirety on this
17954 line, which is equivalent to saying that the next line
17955 starts at the next buffer position. */
17956 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
17957 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17960 INC_BOTH (max_pos
, max_bpos
);
17961 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17964 else if (row
->truncated_on_right_p
)
17965 /* display_line already called reseat_at_next_visible_line_start,
17966 which puts the iterator at the beginning of the next line, in
17967 the logical order. */
17968 row
->maxpos
= it
->current
.pos
;
17969 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
17970 /* A line that is entirely from a string/image/stretch... */
17971 row
->maxpos
= row
->minpos
;
17976 row
->maxpos
= it
->current
.pos
;
17979 /* Construct the glyph row IT->glyph_row in the desired matrix of
17980 IT->w from text at the current position of IT. See dispextern.h
17981 for an overview of struct it. Value is non-zero if
17982 IT->glyph_row displays text, as opposed to a line displaying ZV
17986 display_line (struct it
*it
)
17988 struct glyph_row
*row
= it
->glyph_row
;
17989 Lisp_Object overlay_arrow_string
;
17991 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
17992 int wrap_row_used
= -1;
17993 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
17994 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
17995 int wrap_row_extra_line_spacing
IF_LINT (= 0);
17996 EMACS_INT wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
17997 EMACS_INT wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
17999 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
18000 EMACS_INT min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
18002 /* We always start displaying at hpos zero even if hscrolled. */
18003 xassert (it
->hpos
== 0 && it
->current_x
== 0);
18005 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
18006 >= it
->w
->desired_matrix
->nrows
)
18008 it
->w
->nrows_scale_factor
++;
18009 fonts_changed_p
= 1;
18013 /* Is IT->w showing the region? */
18014 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
18016 /* Clear the result glyph row and enable it. */
18017 prepare_desired_row (row
);
18019 row
->y
= it
->current_y
;
18020 row
->start
= it
->start
;
18021 row
->continuation_lines_width
= it
->continuation_lines_width
;
18022 row
->displays_text_p
= 1;
18023 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
18024 it
->starts_in_middle_of_char_p
= 0;
18026 /* Arrange the overlays nicely for our purposes. Usually, we call
18027 display_line on only one line at a time, in which case this
18028 can't really hurt too much, or we call it on lines which appear
18029 one after another in the buffer, in which case all calls to
18030 recenter_overlay_lists but the first will be pretty cheap. */
18031 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
18033 /* Move over display elements that are not visible because we are
18034 hscrolled. This may stop at an x-position < IT->first_visible_x
18035 if the first glyph is partially visible or if we hit a line end. */
18036 if (it
->current_x
< it
->first_visible_x
)
18038 this_line_min_pos
= row
->start
.pos
;
18039 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
18040 MOVE_TO_POS
| MOVE_TO_X
);
18041 /* Record the smallest positions seen while we moved over
18042 display elements that are not visible. This is needed by
18043 redisplay_internal for optimizing the case where the cursor
18044 stays inside the same line. The rest of this function only
18045 considers positions that are actually displayed, so
18046 RECORD_MAX_MIN_POS will not otherwise record positions that
18047 are hscrolled to the left of the left edge of the window. */
18048 min_pos
= CHARPOS (this_line_min_pos
);
18049 min_bpos
= BYTEPOS (this_line_min_pos
);
18053 /* We only do this when not calling `move_it_in_display_line_to'
18054 above, because move_it_in_display_line_to calls
18055 handle_line_prefix itself. */
18056 handle_line_prefix (it
);
18059 /* Get the initial row height. This is either the height of the
18060 text hscrolled, if there is any, or zero. */
18061 row
->ascent
= it
->max_ascent
;
18062 row
->height
= it
->max_ascent
+ it
->max_descent
;
18063 row
->phys_ascent
= it
->max_phys_ascent
;
18064 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18065 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18067 /* Utility macro to record max and min buffer positions seen until now. */
18068 #define RECORD_MAX_MIN_POS(IT) \
18071 if (IT_CHARPOS (*(IT)) < min_pos) \
18073 min_pos = IT_CHARPOS (*(IT)); \
18074 min_bpos = IT_BYTEPOS (*(IT)); \
18076 if (IT_CHARPOS (*(IT)) > max_pos) \
18078 max_pos = IT_CHARPOS (*(IT)); \
18079 max_bpos = IT_BYTEPOS (*(IT)); \
18084 /* Loop generating characters. The loop is left with IT on the next
18085 character to display. */
18088 int n_glyphs_before
, hpos_before
, x_before
;
18090 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
18092 /* Retrieve the next thing to display. Value is zero if end of
18094 if (!get_next_display_element (it
))
18096 /* Maybe add a space at the end of this line that is used to
18097 display the cursor there under X. Set the charpos of the
18098 first glyph of blank lines not corresponding to any text
18100 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18101 row
->exact_window_width_line_p
= 1;
18102 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
18103 || row
->used
[TEXT_AREA
] == 0)
18105 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
18106 row
->displays_text_p
= 0;
18108 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
18109 && (!MINI_WINDOW_P (it
->w
)
18110 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
18111 row
->indicate_empty_line_p
= 1;
18114 it
->continuation_lines_width
= 0;
18115 row
->ends_at_zv_p
= 1;
18116 /* A row that displays right-to-left text must always have
18117 its last face extended all the way to the end of line,
18118 even if this row ends in ZV, because we still write to
18119 the screen left to right. */
18120 if (row
->reversed_p
)
18121 extend_face_to_end_of_line (it
);
18125 /* Now, get the metrics of what we want to display. This also
18126 generates glyphs in `row' (which is IT->glyph_row). */
18127 n_glyphs_before
= row
->used
[TEXT_AREA
];
18130 /* Remember the line height so far in case the next element doesn't
18131 fit on the line. */
18132 if (it
->line_wrap
!= TRUNCATE
)
18134 ascent
= it
->max_ascent
;
18135 descent
= it
->max_descent
;
18136 phys_ascent
= it
->max_phys_ascent
;
18137 phys_descent
= it
->max_phys_descent
;
18139 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
18141 if (IT_DISPLAYING_WHITESPACE (it
))
18147 wrap_row_used
= row
->used
[TEXT_AREA
];
18148 wrap_row_ascent
= row
->ascent
;
18149 wrap_row_height
= row
->height
;
18150 wrap_row_phys_ascent
= row
->phys_ascent
;
18151 wrap_row_phys_height
= row
->phys_height
;
18152 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
18153 wrap_row_min_pos
= min_pos
;
18154 wrap_row_min_bpos
= min_bpos
;
18155 wrap_row_max_pos
= max_pos
;
18156 wrap_row_max_bpos
= max_bpos
;
18162 PRODUCE_GLYPHS (it
);
18164 /* If this display element was in marginal areas, continue with
18166 if (it
->area
!= TEXT_AREA
)
18168 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18169 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18170 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18171 row
->phys_height
= max (row
->phys_height
,
18172 it
->max_phys_ascent
+ it
->max_phys_descent
);
18173 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18174 it
->max_extra_line_spacing
);
18175 set_iterator_to_next (it
, 1);
18179 /* Does the display element fit on the line? If we truncate
18180 lines, we should draw past the right edge of the window. If
18181 we don't truncate, we want to stop so that we can display the
18182 continuation glyph before the right margin. If lines are
18183 continued, there are two possible strategies for characters
18184 resulting in more than 1 glyph (e.g. tabs): Display as many
18185 glyphs as possible in this line and leave the rest for the
18186 continuation line, or display the whole element in the next
18187 line. Original redisplay did the former, so we do it also. */
18188 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
18189 hpos_before
= it
->hpos
;
18192 if (/* Not a newline. */
18194 /* Glyphs produced fit entirely in the line. */
18195 && it
->current_x
< it
->last_visible_x
)
18197 it
->hpos
+= nglyphs
;
18198 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18199 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18200 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18201 row
->phys_height
= max (row
->phys_height
,
18202 it
->max_phys_ascent
+ it
->max_phys_descent
);
18203 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18204 it
->max_extra_line_spacing
);
18205 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
18206 row
->x
= x
- it
->first_visible_x
;
18207 /* Record the maximum and minimum buffer positions seen so
18208 far in glyphs that will be displayed by this row. */
18210 RECORD_MAX_MIN_POS (it
);
18215 struct glyph
*glyph
;
18217 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
18219 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18220 new_x
= x
+ glyph
->pixel_width
;
18222 if (/* Lines are continued. */
18223 it
->line_wrap
!= TRUNCATE
18224 && (/* Glyph doesn't fit on the line. */
18225 new_x
> it
->last_visible_x
18226 /* Or it fits exactly on a window system frame. */
18227 || (new_x
== it
->last_visible_x
18228 && FRAME_WINDOW_P (it
->f
))))
18230 /* End of a continued line. */
18233 || (new_x
== it
->last_visible_x
18234 && FRAME_WINDOW_P (it
->f
)))
18236 /* Current glyph is the only one on the line or
18237 fits exactly on the line. We must continue
18238 the line because we can't draw the cursor
18239 after the glyph. */
18240 row
->continued_p
= 1;
18241 it
->current_x
= new_x
;
18242 it
->continuation_lines_width
+= new_x
;
18244 /* Record the maximum and minimum buffer
18245 positions seen so far in glyphs that will be
18246 displayed by this row. */
18248 RECORD_MAX_MIN_POS (it
);
18249 if (i
== nglyphs
- 1)
18251 /* If line-wrap is on, check if a previous
18252 wrap point was found. */
18253 if (wrap_row_used
> 0
18254 /* Even if there is a previous wrap
18255 point, continue the line here as
18256 usual, if (i) the previous character
18257 was a space or tab AND (ii) the
18258 current character is not. */
18260 || IT_DISPLAYING_WHITESPACE (it
)))
18263 set_iterator_to_next (it
, 1);
18264 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18266 if (!get_next_display_element (it
))
18268 row
->exact_window_width_line_p
= 1;
18269 it
->continuation_lines_width
= 0;
18270 row
->continued_p
= 0;
18271 row
->ends_at_zv_p
= 1;
18273 else if (ITERATOR_AT_END_OF_LINE_P (it
))
18275 row
->continued_p
= 0;
18276 row
->exact_window_width_line_p
= 1;
18281 else if (CHAR_GLYPH_PADDING_P (*glyph
)
18282 && !FRAME_WINDOW_P (it
->f
))
18284 /* A padding glyph that doesn't fit on this line.
18285 This means the whole character doesn't fit
18287 if (row
->reversed_p
)
18288 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
18289 - n_glyphs_before
);
18290 row
->used
[TEXT_AREA
] = n_glyphs_before
;
18292 /* Fill the rest of the row with continuation
18293 glyphs like in 20.x. */
18294 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
18295 < row
->glyphs
[1 + TEXT_AREA
])
18296 produce_special_glyphs (it
, IT_CONTINUATION
);
18298 row
->continued_p
= 1;
18299 it
->current_x
= x_before
;
18300 it
->continuation_lines_width
+= x_before
;
18302 /* Restore the height to what it was before the
18303 element not fitting on the line. */
18304 it
->max_ascent
= ascent
;
18305 it
->max_descent
= descent
;
18306 it
->max_phys_ascent
= phys_ascent
;
18307 it
->max_phys_descent
= phys_descent
;
18309 else if (wrap_row_used
> 0)
18312 if (row
->reversed_p
)
18313 unproduce_glyphs (it
,
18314 row
->used
[TEXT_AREA
] - wrap_row_used
);
18316 it
->continuation_lines_width
+= wrap_x
;
18317 row
->used
[TEXT_AREA
] = wrap_row_used
;
18318 row
->ascent
= wrap_row_ascent
;
18319 row
->height
= wrap_row_height
;
18320 row
->phys_ascent
= wrap_row_phys_ascent
;
18321 row
->phys_height
= wrap_row_phys_height
;
18322 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
18323 min_pos
= wrap_row_min_pos
;
18324 min_bpos
= wrap_row_min_bpos
;
18325 max_pos
= wrap_row_max_pos
;
18326 max_bpos
= wrap_row_max_bpos
;
18327 row
->continued_p
= 1;
18328 row
->ends_at_zv_p
= 0;
18329 row
->exact_window_width_line_p
= 0;
18330 it
->continuation_lines_width
+= x
;
18332 /* Make sure that a non-default face is extended
18333 up to the right margin of the window. */
18334 extend_face_to_end_of_line (it
);
18336 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
18338 /* A TAB that extends past the right edge of the
18339 window. This produces a single glyph on
18340 window system frames. We leave the glyph in
18341 this row and let it fill the row, but don't
18342 consume the TAB. */
18343 it
->continuation_lines_width
+= it
->last_visible_x
;
18344 row
->ends_in_middle_of_char_p
= 1;
18345 row
->continued_p
= 1;
18346 glyph
->pixel_width
= it
->last_visible_x
- x
;
18347 it
->starts_in_middle_of_char_p
= 1;
18351 /* Something other than a TAB that draws past
18352 the right edge of the window. Restore
18353 positions to values before the element. */
18354 if (row
->reversed_p
)
18355 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
18356 - (n_glyphs_before
+ i
));
18357 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18359 /* Display continuation glyphs. */
18360 if (!FRAME_WINDOW_P (it
->f
))
18361 produce_special_glyphs (it
, IT_CONTINUATION
);
18362 row
->continued_p
= 1;
18364 it
->current_x
= x_before
;
18365 it
->continuation_lines_width
+= x
;
18366 extend_face_to_end_of_line (it
);
18368 if (nglyphs
> 1 && i
> 0)
18370 row
->ends_in_middle_of_char_p
= 1;
18371 it
->starts_in_middle_of_char_p
= 1;
18374 /* Restore the height to what it was before the
18375 element not fitting on the line. */
18376 it
->max_ascent
= ascent
;
18377 it
->max_descent
= descent
;
18378 it
->max_phys_ascent
= phys_ascent
;
18379 it
->max_phys_descent
= phys_descent
;
18384 else if (new_x
> it
->first_visible_x
)
18386 /* Increment number of glyphs actually displayed. */
18389 /* Record the maximum and minimum buffer positions
18390 seen so far in glyphs that will be displayed by
18393 RECORD_MAX_MIN_POS (it
);
18395 if (x
< it
->first_visible_x
)
18396 /* Glyph is partially visible, i.e. row starts at
18397 negative X position. */
18398 row
->x
= x
- it
->first_visible_x
;
18402 /* Glyph is completely off the left margin of the
18403 window. This should not happen because of the
18404 move_it_in_display_line at the start of this
18405 function, unless the text display area of the
18406 window is empty. */
18407 xassert (it
->first_visible_x
<= it
->last_visible_x
);
18411 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18412 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18413 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18414 row
->phys_height
= max (row
->phys_height
,
18415 it
->max_phys_ascent
+ it
->max_phys_descent
);
18416 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18417 it
->max_extra_line_spacing
);
18419 /* End of this display line if row is continued. */
18420 if (row
->continued_p
|| row
->ends_at_zv_p
)
18425 /* Is this a line end? If yes, we're also done, after making
18426 sure that a non-default face is extended up to the right
18427 margin of the window. */
18428 if (ITERATOR_AT_END_OF_LINE_P (it
))
18430 int used_before
= row
->used
[TEXT_AREA
];
18432 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
18434 /* Add a space at the end of the line that is used to
18435 display the cursor there. */
18436 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18437 append_space_for_newline (it
, 0);
18439 /* Extend the face to the end of the line. */
18440 extend_face_to_end_of_line (it
);
18442 /* Make sure we have the position. */
18443 if (used_before
== 0)
18444 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
18446 /* Record the position of the newline, for use in
18448 it
->eol_pos
= it
->current
.pos
;
18450 /* Consume the line end. This skips over invisible lines. */
18451 set_iterator_to_next (it
, 1);
18452 it
->continuation_lines_width
= 0;
18456 /* Proceed with next display element. Note that this skips
18457 over lines invisible because of selective display. */
18458 set_iterator_to_next (it
, 1);
18460 /* If we truncate lines, we are done when the last displayed
18461 glyphs reach past the right margin of the window. */
18462 if (it
->line_wrap
== TRUNCATE
18463 && (FRAME_WINDOW_P (it
->f
)
18464 ? (it
->current_x
>= it
->last_visible_x
)
18465 : (it
->current_x
> it
->last_visible_x
)))
18467 /* Maybe add truncation glyphs. */
18468 if (!FRAME_WINDOW_P (it
->f
))
18472 if (!row
->reversed_p
)
18474 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18475 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18480 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
18481 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18483 /* Remove any padding glyphs at the front of ROW, to
18484 make room for the truncation glyphs we will be
18485 adding below. The loop below always inserts at
18486 least one truncation glyph, so also remove the
18487 last glyph added to ROW. */
18488 unproduce_glyphs (it
, i
+ 1);
18489 /* Adjust i for the loop below. */
18490 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
18493 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18495 row
->used
[TEXT_AREA
] = i
;
18496 produce_special_glyphs (it
, IT_TRUNCATION
);
18499 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18501 /* Don't truncate if we can overflow newline into fringe. */
18502 if (!get_next_display_element (it
))
18504 it
->continuation_lines_width
= 0;
18505 row
->ends_at_zv_p
= 1;
18506 row
->exact_window_width_line_p
= 1;
18509 if (ITERATOR_AT_END_OF_LINE_P (it
))
18511 row
->exact_window_width_line_p
= 1;
18512 goto at_end_of_line
;
18516 row
->truncated_on_right_p
= 1;
18517 it
->continuation_lines_width
= 0;
18518 reseat_at_next_visible_line_start (it
, 0);
18519 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
18520 it
->hpos
= hpos_before
;
18521 it
->current_x
= x_before
;
18526 /* If line is not empty and hscrolled, maybe insert truncation glyphs
18527 at the left window margin. */
18528 if (it
->first_visible_x
18529 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
18531 if (!FRAME_WINDOW_P (it
->f
))
18532 insert_left_trunc_glyphs (it
);
18533 row
->truncated_on_left_p
= 1;
18536 /* Remember the position at which this line ends.
18538 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
18539 cannot be before the call to find_row_edges below, since that is
18540 where these positions are determined. */
18541 row
->end
= it
->current
;
18544 row
->minpos
= row
->start
.pos
;
18545 row
->maxpos
= row
->end
.pos
;
18549 /* ROW->minpos and ROW->maxpos must be the smallest and
18550 `1 + the largest' buffer positions in ROW. But if ROW was
18551 bidi-reordered, these two positions can be anywhere in the
18552 row, so we must determine them now. */
18553 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
18556 /* If the start of this line is the overlay arrow-position, then
18557 mark this glyph row as the one containing the overlay arrow.
18558 This is clearly a mess with variable size fonts. It would be
18559 better to let it be displayed like cursors under X. */
18560 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
18561 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
18562 !NILP (overlay_arrow_string
)))
18564 /* Overlay arrow in window redisplay is a fringe bitmap. */
18565 if (STRINGP (overlay_arrow_string
))
18567 struct glyph_row
*arrow_row
18568 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
18569 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
18570 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
18571 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
18572 struct glyph
*p2
, *end
;
18574 /* Copy the arrow glyphs. */
18575 while (glyph
< arrow_end
)
18578 /* Throw away padding glyphs. */
18580 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
18581 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
18587 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
18592 xassert (INTEGERP (overlay_arrow_string
));
18593 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
18595 overlay_arrow_seen
= 1;
18598 /* Compute pixel dimensions of this line. */
18599 compute_line_metrics (it
);
18601 /* Record whether this row ends inside an ellipsis. */
18602 row
->ends_in_ellipsis_p
18603 = (it
->method
== GET_FROM_DISPLAY_VECTOR
18604 && it
->ellipsis_p
);
18606 /* Save fringe bitmaps in this row. */
18607 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
18608 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
18609 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
18610 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
18612 it
->left_user_fringe_bitmap
= 0;
18613 it
->left_user_fringe_face_id
= 0;
18614 it
->right_user_fringe_bitmap
= 0;
18615 it
->right_user_fringe_face_id
= 0;
18617 /* Maybe set the cursor. */
18618 cvpos
= it
->w
->cursor
.vpos
;
18620 /* In bidi-reordered rows, keep checking for proper cursor
18621 position even if one has been found already, because buffer
18622 positions in such rows change non-linearly with ROW->VPOS,
18623 when a line is continued. One exception: when we are at ZV,
18624 display cursor on the first suitable glyph row, since all
18625 the empty rows after that also have their position set to ZV. */
18626 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18627 lines' rows is implemented for bidi-reordered rows. */
18629 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
18630 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
18631 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
18632 && cursor_row_p (row
))
18633 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
18635 /* Highlight trailing whitespace. */
18636 if (!NILP (Vshow_trailing_whitespace
))
18637 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
18639 /* Prepare for the next line. This line starts horizontally at (X
18640 HPOS) = (0 0). Vertical positions are incremented. As a
18641 convenience for the caller, IT->glyph_row is set to the next
18643 it
->current_x
= it
->hpos
= 0;
18644 it
->current_y
+= row
->height
;
18645 SET_TEXT_POS (it
->eol_pos
, 0, 0);
18648 /* The next row should by default use the same value of the
18649 reversed_p flag as this one. set_iterator_to_next decides when
18650 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
18651 the flag accordingly. */
18652 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
18653 it
->glyph_row
->reversed_p
= row
->reversed_p
;
18654 it
->start
= row
->end
;
18655 return row
->displays_text_p
;
18657 #undef RECORD_MAX_MIN_POS
18660 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
18661 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
18662 doc
: /* Return paragraph direction at point in BUFFER.
18663 Value is either `left-to-right' or `right-to-left'.
18664 If BUFFER is omitted or nil, it defaults to the current buffer.
18666 Paragraph direction determines how the text in the paragraph is displayed.
18667 In left-to-right paragraphs, text begins at the left margin of the window
18668 and the reading direction is generally left to right. In right-to-left
18669 paragraphs, text begins at the right margin and is read from right to left.
18671 See also `bidi-paragraph-direction'. */)
18672 (Lisp_Object buffer
)
18674 struct buffer
*buf
= current_buffer
;
18675 struct buffer
*old
= buf
;
18677 if (! NILP (buffer
))
18679 CHECK_BUFFER (buffer
);
18680 buf
= XBUFFER (buffer
);
18683 if (NILP (BVAR (buf
, bidi_display_reordering
)))
18684 return Qleft_to_right
;
18685 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
18686 return BVAR (buf
, bidi_paragraph_direction
);
18689 /* Determine the direction from buffer text. We could try to
18690 use current_matrix if it is up to date, but this seems fast
18691 enough as it is. */
18692 struct bidi_it itb
;
18693 EMACS_INT pos
= BUF_PT (buf
);
18694 EMACS_INT bytepos
= BUF_PT_BYTE (buf
);
18697 set_buffer_temp (buf
);
18698 /* bidi_paragraph_init finds the base direction of the paragraph
18699 by searching forward from paragraph start. We need the base
18700 direction of the current or _previous_ paragraph, so we need
18701 to make sure we are within that paragraph. To that end, find
18702 the previous non-empty line. */
18703 if (pos
>= ZV
&& pos
> BEGV
)
18706 bytepos
= CHAR_TO_BYTE (pos
);
18708 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
18709 || c
== ' ' || c
== '\t' || c
== '\f')
18711 if (bytepos
<= BEGV_BYTE
)
18716 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
18719 itb
.bytepos
= bytepos
;
18721 itb
.string
.s
= NULL
;
18722 itb
.string
.lstring
= Qnil
;
18723 itb
.frame_window_p
= FRAME_WINDOW_P (SELECTED_FRAME ()); /* guesswork */
18725 itb
.separator_limit
= -1;
18726 itb
.paragraph_dir
= NEUTRAL_DIR
;
18728 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
18729 set_buffer_temp (old
);
18730 switch (itb
.paragraph_dir
)
18733 return Qleft_to_right
;
18736 return Qright_to_left
;
18746 /***********************************************************************
18748 ***********************************************************************/
18750 /* Redisplay the menu bar in the frame for window W.
18752 The menu bar of X frames that don't have X toolkit support is
18753 displayed in a special window W->frame->menu_bar_window.
18755 The menu bar of terminal frames is treated specially as far as
18756 glyph matrices are concerned. Menu bar lines are not part of
18757 windows, so the update is done directly on the frame matrix rows
18758 for the menu bar. */
18761 display_menu_bar (struct window
*w
)
18763 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18768 /* Don't do all this for graphical frames. */
18770 if (FRAME_W32_P (f
))
18773 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
18779 if (FRAME_NS_P (f
))
18781 #endif /* HAVE_NS */
18783 #ifdef USE_X_TOOLKIT
18784 xassert (!FRAME_WINDOW_P (f
));
18785 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
18786 it
.first_visible_x
= 0;
18787 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18788 #else /* not USE_X_TOOLKIT */
18789 if (FRAME_WINDOW_P (f
))
18791 /* Menu bar lines are displayed in the desired matrix of the
18792 dummy window menu_bar_window. */
18793 struct window
*menu_w
;
18794 xassert (WINDOWP (f
->menu_bar_window
));
18795 menu_w
= XWINDOW (f
->menu_bar_window
);
18796 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
18798 it
.first_visible_x
= 0;
18799 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18803 /* This is a TTY frame, i.e. character hpos/vpos are used as
18805 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
18807 it
.first_visible_x
= 0;
18808 it
.last_visible_x
= FRAME_COLS (f
);
18810 #endif /* not USE_X_TOOLKIT */
18812 /* FIXME: This should be controlled by a user option. See the
18813 comments in redisplay_tool_bar and display_mode_line about
18815 it
.paragraph_embedding
= L2R
;
18817 if (! mode_line_inverse_video
)
18818 /* Force the menu-bar to be displayed in the default face. */
18819 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18821 /* Clear all rows of the menu bar. */
18822 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
18824 struct glyph_row
*row
= it
.glyph_row
+ i
;
18825 clear_glyph_row (row
);
18826 row
->enabled_p
= 1;
18827 row
->full_width_p
= 1;
18830 /* Display all items of the menu bar. */
18831 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
18832 for (i
= 0; i
< ASIZE (items
); i
+= 4)
18834 Lisp_Object string
;
18836 /* Stop at nil string. */
18837 string
= AREF (items
, i
+ 1);
18841 /* Remember where item was displayed. */
18842 ASET (items
, i
+ 3, make_number (it
.hpos
));
18844 /* Display the item, pad with one space. */
18845 if (it
.current_x
< it
.last_visible_x
)
18846 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
18847 SCHARS (string
) + 1, 0, 0, -1);
18850 /* Fill out the line with spaces. */
18851 if (it
.current_x
< it
.last_visible_x
)
18852 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
18854 /* Compute the total height of the lines. */
18855 compute_line_metrics (&it
);
18860 /***********************************************************************
18862 ***********************************************************************/
18864 /* Redisplay mode lines in the window tree whose root is WINDOW. If
18865 FORCE is non-zero, redisplay mode lines unconditionally.
18866 Otherwise, redisplay only mode lines that are garbaged. Value is
18867 the number of windows whose mode lines were redisplayed. */
18870 redisplay_mode_lines (Lisp_Object window
, int force
)
18874 while (!NILP (window
))
18876 struct window
*w
= XWINDOW (window
);
18878 if (WINDOWP (w
->hchild
))
18879 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
18880 else if (WINDOWP (w
->vchild
))
18881 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18883 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18884 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18886 struct text_pos lpoint
;
18887 struct buffer
*old
= current_buffer
;
18889 /* Set the window's buffer for the mode line display. */
18890 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18891 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18893 /* Point refers normally to the selected window. For any
18894 other window, set up appropriate value. */
18895 if (!EQ (window
, selected_window
))
18897 struct text_pos pt
;
18899 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18900 if (CHARPOS (pt
) < BEGV
)
18901 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18902 else if (CHARPOS (pt
) > (ZV
- 1))
18903 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18905 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18908 /* Display mode lines. */
18909 clear_glyph_matrix (w
->desired_matrix
);
18910 if (display_mode_lines (w
))
18913 w
->must_be_updated_p
= 1;
18916 /* Restore old settings. */
18917 set_buffer_internal_1 (old
);
18918 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18928 /* Display the mode and/or header line of window W. Value is the
18929 sum number of mode lines and header lines displayed. */
18932 display_mode_lines (struct window
*w
)
18934 Lisp_Object old_selected_window
, old_selected_frame
;
18937 old_selected_frame
= selected_frame
;
18938 selected_frame
= w
->frame
;
18939 old_selected_window
= selected_window
;
18940 XSETWINDOW (selected_window
, w
);
18942 /* These will be set while the mode line specs are processed. */
18943 line_number_displayed
= 0;
18944 w
->column_number_displayed
= Qnil
;
18946 if (WINDOW_WANTS_MODELINE_P (w
))
18948 struct window
*sel_w
= XWINDOW (old_selected_window
);
18950 /* Select mode line face based on the real selected window. */
18951 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18952 BVAR (current_buffer
, mode_line_format
));
18956 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18958 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18959 BVAR (current_buffer
, header_line_format
));
18963 selected_frame
= old_selected_frame
;
18964 selected_window
= old_selected_window
;
18969 /* Display mode or header line of window W. FACE_ID specifies which
18970 line to display; it is either MODE_LINE_FACE_ID or
18971 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18972 display. Value is the pixel height of the mode/header line
18976 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
18980 int count
= SPECPDL_INDEX ();
18982 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18983 /* Don't extend on a previously drawn mode-line.
18984 This may happen if called from pos_visible_p. */
18985 it
.glyph_row
->enabled_p
= 0;
18986 prepare_desired_row (it
.glyph_row
);
18988 it
.glyph_row
->mode_line_p
= 1;
18990 if (! mode_line_inverse_video
)
18991 /* Force the mode-line to be displayed in the default face. */
18992 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18994 /* FIXME: This should be controlled by a user option. But
18995 supporting such an option is not trivial, since the mode line is
18996 made up of many separate strings, most of which are normally
18997 unibyte, and unibyte strings currently don't get reordered for
18999 it
.paragraph_embedding
= L2R
;
19001 record_unwind_protect (unwind_format_mode_line
,
19002 format_mode_line_unwind_data (NULL
, Qnil
, 0));
19004 mode_line_target
= MODE_LINE_DISPLAY
;
19006 /* Temporarily make frame's keyboard the current kboard so that
19007 kboard-local variables in the mode_line_format will get the right
19009 push_kboard (FRAME_KBOARD (it
.f
));
19010 record_unwind_save_match_data ();
19011 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19014 unbind_to (count
, Qnil
);
19016 /* Fill up with spaces. */
19017 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
19019 compute_line_metrics (&it
);
19020 it
.glyph_row
->full_width_p
= 1;
19021 it
.glyph_row
->continued_p
= 0;
19022 it
.glyph_row
->truncated_on_left_p
= 0;
19023 it
.glyph_row
->truncated_on_right_p
= 0;
19025 /* Make a 3D mode-line have a shadow at its right end. */
19026 face
= FACE_FROM_ID (it
.f
, face_id
);
19027 extend_face_to_end_of_line (&it
);
19028 if (face
->box
!= FACE_NO_BOX
)
19030 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
19031 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
19032 last
->right_box_line_p
= 1;
19035 return it
.glyph_row
->height
;
19038 /* Move element ELT in LIST to the front of LIST.
19039 Return the updated list. */
19042 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
19044 register Lisp_Object tail
, prev
;
19045 register Lisp_Object tem
;
19049 while (CONSP (tail
))
19055 /* Splice out the link TAIL. */
19057 list
= XCDR (tail
);
19059 Fsetcdr (prev
, XCDR (tail
));
19061 /* Now make it the first. */
19062 Fsetcdr (tail
, list
);
19067 tail
= XCDR (tail
);
19071 /* Not found--return unchanged LIST. */
19075 /* Contribute ELT to the mode line for window IT->w. How it
19076 translates into text depends on its data type.
19078 IT describes the display environment in which we display, as usual.
19080 DEPTH is the depth in recursion. It is used to prevent
19081 infinite recursion here.
19083 FIELD_WIDTH is the number of characters the display of ELT should
19084 occupy in the mode line, and PRECISION is the maximum number of
19085 characters to display from ELT's representation. See
19086 display_string for details.
19088 Returns the hpos of the end of the text generated by ELT.
19090 PROPS is a property list to add to any string we encounter.
19092 If RISKY is nonzero, remove (disregard) any properties in any string
19093 we encounter, and ignore :eval and :propertize.
19095 The global variable `mode_line_target' determines whether the
19096 output is passed to `store_mode_line_noprop',
19097 `store_mode_line_string', or `display_string'. */
19100 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
19101 Lisp_Object elt
, Lisp_Object props
, int risky
)
19103 int n
= 0, field
, prec
;
19108 elt
= build_string ("*too-deep*");
19112 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
19116 /* A string: output it and check for %-constructs within it. */
19118 EMACS_INT offset
= 0;
19120 if (SCHARS (elt
) > 0
19121 && (!NILP (props
) || risky
))
19123 Lisp_Object oprops
, aelt
;
19124 oprops
= Ftext_properties_at (make_number (0), elt
);
19126 /* If the starting string's properties are not what
19127 we want, translate the string. Also, if the string
19128 is risky, do that anyway. */
19130 if (NILP (Fequal (props
, oprops
)) || risky
)
19132 /* If the starting string has properties,
19133 merge the specified ones onto the existing ones. */
19134 if (! NILP (oprops
) && !risky
)
19138 oprops
= Fcopy_sequence (oprops
);
19140 while (CONSP (tem
))
19142 oprops
= Fplist_put (oprops
, XCAR (tem
),
19143 XCAR (XCDR (tem
)));
19144 tem
= XCDR (XCDR (tem
));
19149 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
19150 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
19152 /* AELT is what we want. Move it to the front
19153 without consing. */
19155 mode_line_proptrans_alist
19156 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
19162 /* If AELT has the wrong props, it is useless.
19163 so get rid of it. */
19165 mode_line_proptrans_alist
19166 = Fdelq (aelt
, mode_line_proptrans_alist
);
19168 elt
= Fcopy_sequence (elt
);
19169 Fset_text_properties (make_number (0), Flength (elt
),
19171 /* Add this item to mode_line_proptrans_alist. */
19172 mode_line_proptrans_alist
19173 = Fcons (Fcons (elt
, props
),
19174 mode_line_proptrans_alist
);
19175 /* Truncate mode_line_proptrans_alist
19176 to at most 50 elements. */
19177 tem
= Fnthcdr (make_number (50),
19178 mode_line_proptrans_alist
);
19180 XSETCDR (tem
, Qnil
);
19189 prec
= precision
- n
;
19190 switch (mode_line_target
)
19192 case MODE_LINE_NOPROP
:
19193 case MODE_LINE_TITLE
:
19194 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
19196 case MODE_LINE_STRING
:
19197 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
19199 case MODE_LINE_DISPLAY
:
19200 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
19201 0, prec
, 0, STRING_MULTIBYTE (elt
));
19208 /* Handle the non-literal case. */
19210 while ((precision
<= 0 || n
< precision
)
19211 && SREF (elt
, offset
) != 0
19212 && (mode_line_target
!= MODE_LINE_DISPLAY
19213 || it
->current_x
< it
->last_visible_x
))
19215 EMACS_INT last_offset
= offset
;
19217 /* Advance to end of string or next format specifier. */
19218 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
19221 if (offset
- 1 != last_offset
)
19223 EMACS_INT nchars
, nbytes
;
19225 /* Output to end of string or up to '%'. Field width
19226 is length of string. Don't output more than
19227 PRECISION allows us. */
19230 prec
= c_string_width (SDATA (elt
) + last_offset
,
19231 offset
- last_offset
, precision
- n
,
19234 switch (mode_line_target
)
19236 case MODE_LINE_NOPROP
:
19237 case MODE_LINE_TITLE
:
19238 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
19240 case MODE_LINE_STRING
:
19242 EMACS_INT bytepos
= last_offset
;
19243 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
19244 EMACS_INT endpos
= (precision
<= 0
19245 ? string_byte_to_char (elt
, offset
)
19246 : charpos
+ nchars
);
19248 n
+= store_mode_line_string (NULL
,
19249 Fsubstring (elt
, make_number (charpos
),
19250 make_number (endpos
)),
19254 case MODE_LINE_DISPLAY
:
19256 EMACS_INT bytepos
= last_offset
;
19257 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
19259 if (precision
<= 0)
19260 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
19261 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
19263 STRING_MULTIBYTE (elt
));
19268 else /* c == '%' */
19270 EMACS_INT percent_position
= offset
;
19272 /* Get the specified minimum width. Zero means
19275 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
19276 field
= field
* 10 + c
- '0';
19278 /* Don't pad beyond the total padding allowed. */
19279 if (field_width
- n
> 0 && field
> field_width
- n
)
19280 field
= field_width
- n
;
19282 /* Note that either PRECISION <= 0 or N < PRECISION. */
19283 prec
= precision
- n
;
19286 n
+= display_mode_element (it
, depth
, field
, prec
,
19287 Vglobal_mode_string
, props
,
19292 EMACS_INT bytepos
, charpos
;
19294 Lisp_Object string
;
19296 bytepos
= percent_position
;
19297 charpos
= (STRING_MULTIBYTE (elt
)
19298 ? string_byte_to_char (elt
, bytepos
)
19300 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
19301 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
19303 switch (mode_line_target
)
19305 case MODE_LINE_NOPROP
:
19306 case MODE_LINE_TITLE
:
19307 n
+= store_mode_line_noprop (spec
, field
, prec
);
19309 case MODE_LINE_STRING
:
19311 int len
= strlen (spec
);
19312 Lisp_Object tem
= make_string (spec
, len
);
19313 props
= Ftext_properties_at (make_number (charpos
), elt
);
19314 /* Should only keep face property in props */
19315 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
19318 case MODE_LINE_DISPLAY
:
19320 int nglyphs_before
, nwritten
;
19322 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
19323 nwritten
= display_string (spec
, string
, elt
,
19328 /* Assign to the glyphs written above the
19329 string where the `%x' came from, position
19333 struct glyph
*glyph
19334 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
19338 for (i
= 0; i
< nwritten
; ++i
)
19340 glyph
[i
].object
= elt
;
19341 glyph
[i
].charpos
= charpos
;
19358 /* A symbol: process the value of the symbol recursively
19359 as if it appeared here directly. Avoid error if symbol void.
19360 Special case: if value of symbol is a string, output the string
19363 register Lisp_Object tem
;
19365 /* If the variable is not marked as risky to set
19366 then its contents are risky to use. */
19367 if (NILP (Fget (elt
, Qrisky_local_variable
)))
19370 tem
= Fboundp (elt
);
19373 tem
= Fsymbol_value (elt
);
19374 /* If value is a string, output that string literally:
19375 don't check for % within it. */
19379 if (!EQ (tem
, elt
))
19381 /* Give up right away for nil or t. */
19391 register Lisp_Object car
, tem
;
19393 /* A cons cell: five distinct cases.
19394 If first element is :eval or :propertize, do something special.
19395 If first element is a string or a cons, process all the elements
19396 and effectively concatenate them.
19397 If first element is a negative number, truncate displaying cdr to
19398 at most that many characters. If positive, pad (with spaces)
19399 to at least that many characters.
19400 If first element is a symbol, process the cadr or caddr recursively
19401 according to whether the symbol's value is non-nil or nil. */
19403 if (EQ (car
, QCeval
))
19405 /* An element of the form (:eval FORM) means evaluate FORM
19406 and use the result as mode line elements. */
19411 if (CONSP (XCDR (elt
)))
19414 spec
= safe_eval (XCAR (XCDR (elt
)));
19415 n
+= display_mode_element (it
, depth
, field_width
- n
,
19416 precision
- n
, spec
, props
,
19420 else if (EQ (car
, QCpropertize
))
19422 /* An element of the form (:propertize ELT PROPS...)
19423 means display ELT but applying properties PROPS. */
19428 if (CONSP (XCDR (elt
)))
19429 n
+= display_mode_element (it
, depth
, field_width
- n
,
19430 precision
- n
, XCAR (XCDR (elt
)),
19431 XCDR (XCDR (elt
)), risky
);
19433 else if (SYMBOLP (car
))
19435 tem
= Fboundp (car
);
19439 /* elt is now the cdr, and we know it is a cons cell.
19440 Use its car if CAR has a non-nil value. */
19443 tem
= Fsymbol_value (car
);
19450 /* Symbol's value is nil (or symbol is unbound)
19451 Get the cddr of the original list
19452 and if possible find the caddr and use that. */
19456 else if (!CONSP (elt
))
19461 else if (INTEGERP (car
))
19463 register int lim
= XINT (car
);
19467 /* Negative int means reduce maximum width. */
19468 if (precision
<= 0)
19471 precision
= min (precision
, -lim
);
19475 /* Padding specified. Don't let it be more than
19476 current maximum. */
19478 lim
= min (precision
, lim
);
19480 /* If that's more padding than already wanted, queue it.
19481 But don't reduce padding already specified even if
19482 that is beyond the current truncation point. */
19483 field_width
= max (lim
, field_width
);
19487 else if (STRINGP (car
) || CONSP (car
))
19489 Lisp_Object halftail
= elt
;
19493 && (precision
<= 0 || n
< precision
))
19495 n
+= display_mode_element (it
, depth
,
19496 /* Do padding only after the last
19497 element in the list. */
19498 (! CONSP (XCDR (elt
))
19501 precision
- n
, XCAR (elt
),
19505 if ((len
& 1) == 0)
19506 halftail
= XCDR (halftail
);
19507 /* Check for cycle. */
19508 if (EQ (halftail
, elt
))
19517 elt
= build_string ("*invalid*");
19521 /* Pad to FIELD_WIDTH. */
19522 if (field_width
> 0 && n
< field_width
)
19524 switch (mode_line_target
)
19526 case MODE_LINE_NOPROP
:
19527 case MODE_LINE_TITLE
:
19528 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
19530 case MODE_LINE_STRING
:
19531 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
19533 case MODE_LINE_DISPLAY
:
19534 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
19543 /* Store a mode-line string element in mode_line_string_list.
19545 If STRING is non-null, display that C string. Otherwise, the Lisp
19546 string LISP_STRING is displayed.
19548 FIELD_WIDTH is the minimum number of output glyphs to produce.
19549 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19550 with spaces. FIELD_WIDTH <= 0 means don't pad.
19552 PRECISION is the maximum number of characters to output from
19553 STRING. PRECISION <= 0 means don't truncate the string.
19555 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
19556 properties to the string.
19558 PROPS are the properties to add to the string.
19559 The mode_line_string_face face property is always added to the string.
19563 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
19564 int field_width
, int precision
, Lisp_Object props
)
19569 if (string
!= NULL
)
19571 len
= strlen (string
);
19572 if (precision
> 0 && len
> precision
)
19574 lisp_string
= make_string (string
, len
);
19576 props
= mode_line_string_face_prop
;
19577 else if (!NILP (mode_line_string_face
))
19579 Lisp_Object face
= Fplist_get (props
, Qface
);
19580 props
= Fcopy_sequence (props
);
19582 face
= mode_line_string_face
;
19584 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19585 props
= Fplist_put (props
, Qface
, face
);
19587 Fadd_text_properties (make_number (0), make_number (len
),
19588 props
, lisp_string
);
19592 len
= XFASTINT (Flength (lisp_string
));
19593 if (precision
> 0 && len
> precision
)
19596 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
19599 if (!NILP (mode_line_string_face
))
19603 props
= Ftext_properties_at (make_number (0), lisp_string
);
19604 face
= Fplist_get (props
, Qface
);
19606 face
= mode_line_string_face
;
19608 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19609 props
= Fcons (Qface
, Fcons (face
, Qnil
));
19611 lisp_string
= Fcopy_sequence (lisp_string
);
19614 Fadd_text_properties (make_number (0), make_number (len
),
19615 props
, lisp_string
);
19620 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19624 if (field_width
> len
)
19626 field_width
-= len
;
19627 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
19629 Fadd_text_properties (make_number (0), make_number (field_width
),
19630 props
, lisp_string
);
19631 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19639 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
19641 doc
: /* Format a string out of a mode line format specification.
19642 First arg FORMAT specifies the mode line format (see `mode-line-format'
19643 for details) to use.
19645 By default, the format is evaluated for the currently selected window.
19647 Optional second arg FACE specifies the face property to put on all
19648 characters for which no face is specified. The value nil means the
19649 default face. The value t means whatever face the window's mode line
19650 currently uses (either `mode-line' or `mode-line-inactive',
19651 depending on whether the window is the selected window or not).
19652 An integer value means the value string has no text
19655 Optional third and fourth args WINDOW and BUFFER specify the window
19656 and buffer to use as the context for the formatting (defaults
19657 are the selected window and the WINDOW's buffer). */)
19658 (Lisp_Object format
, Lisp_Object face
,
19659 Lisp_Object window
, Lisp_Object buffer
)
19664 struct buffer
*old_buffer
= NULL
;
19666 int no_props
= INTEGERP (face
);
19667 int count
= SPECPDL_INDEX ();
19669 int string_start
= 0;
19672 window
= selected_window
;
19673 CHECK_WINDOW (window
);
19674 w
= XWINDOW (window
);
19677 buffer
= w
->buffer
;
19678 CHECK_BUFFER (buffer
);
19680 /* Make formatting the modeline a non-op when noninteractive, otherwise
19681 there will be problems later caused by a partially initialized frame. */
19682 if (NILP (format
) || noninteractive
)
19683 return empty_unibyte_string
;
19688 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
19689 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
19690 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
19691 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
19692 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
19693 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
19694 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
19697 if (XBUFFER (buffer
) != current_buffer
)
19698 old_buffer
= current_buffer
;
19700 /* Save things including mode_line_proptrans_alist,
19701 and set that to nil so that we don't alter the outer value. */
19702 record_unwind_protect (unwind_format_mode_line
,
19703 format_mode_line_unwind_data
19704 (old_buffer
, selected_window
, 1));
19705 mode_line_proptrans_alist
= Qnil
;
19707 Fselect_window (window
, Qt
);
19709 set_buffer_internal_1 (XBUFFER (buffer
));
19711 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19715 mode_line_target
= MODE_LINE_NOPROP
;
19716 mode_line_string_face_prop
= Qnil
;
19717 mode_line_string_list
= Qnil
;
19718 string_start
= MODE_LINE_NOPROP_LEN (0);
19722 mode_line_target
= MODE_LINE_STRING
;
19723 mode_line_string_list
= Qnil
;
19724 mode_line_string_face
= face
;
19725 mode_line_string_face_prop
19726 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
19729 push_kboard (FRAME_KBOARD (it
.f
));
19730 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19735 len
= MODE_LINE_NOPROP_LEN (string_start
);
19736 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
19740 mode_line_string_list
= Fnreverse (mode_line_string_list
);
19741 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
19742 empty_unibyte_string
);
19745 unbind_to (count
, Qnil
);
19749 /* Write a null-terminated, right justified decimal representation of
19750 the positive integer D to BUF using a minimal field width WIDTH. */
19753 pint2str (register char *buf
, register int width
, register EMACS_INT d
)
19755 register char *p
= buf
;
19763 *p
++ = d
% 10 + '0';
19768 for (width
-= (int) (p
- buf
); width
> 0; --width
)
19779 /* Write a null-terminated, right justified decimal and "human
19780 readable" representation of the nonnegative integer D to BUF using
19781 a minimal field width WIDTH. D should be smaller than 999.5e24. */
19783 static const char power_letter
[] =
19797 pint2hrstr (char *buf
, int width
, EMACS_INT d
)
19799 /* We aim to represent the nonnegative integer D as
19800 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
19801 EMACS_INT quotient
= d
;
19803 /* -1 means: do not use TENTHS. */
19807 /* Length of QUOTIENT.TENTHS as a string. */
19813 if (1000 <= quotient
)
19815 /* Scale to the appropriate EXPONENT. */
19818 remainder
= quotient
% 1000;
19822 while (1000 <= quotient
);
19824 /* Round to nearest and decide whether to use TENTHS or not. */
19827 tenths
= remainder
/ 100;
19828 if (50 <= remainder
% 100)
19835 if (quotient
== 10)
19843 if (500 <= remainder
)
19845 if (quotient
< 999)
19856 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
19857 if (tenths
== -1 && quotient
<= 99)
19864 p
= psuffix
= buf
+ max (width
, length
);
19866 /* Print EXPONENT. */
19867 *psuffix
++ = power_letter
[exponent
];
19870 /* Print TENTHS. */
19873 *--p
= '0' + tenths
;
19877 /* Print QUOTIENT. */
19880 int digit
= quotient
% 10;
19881 *--p
= '0' + digit
;
19883 while ((quotient
/= 10) != 0);
19885 /* Print leading spaces. */
19890 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19891 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19892 type of CODING_SYSTEM. Return updated pointer into BUF. */
19894 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19897 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
19900 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
19901 const unsigned char *eol_str
;
19903 /* The EOL conversion we are using. */
19904 Lisp_Object eoltype
;
19906 val
= CODING_SYSTEM_SPEC (coding_system
);
19909 if (!VECTORP (val
)) /* Not yet decided. */
19914 eoltype
= eol_mnemonic_undecided
;
19915 /* Don't mention EOL conversion if it isn't decided. */
19920 Lisp_Object eolvalue
;
19922 attrs
= AREF (val
, 0);
19923 eolvalue
= AREF (val
, 2);
19926 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19930 /* The EOL conversion that is normal on this system. */
19932 if (NILP (eolvalue
)) /* Not yet decided. */
19933 eoltype
= eol_mnemonic_undecided
;
19934 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19935 eoltype
= eol_mnemonic_undecided
;
19936 else /* eolvalue is Qunix, Qdos, or Qmac. */
19937 eoltype
= (EQ (eolvalue
, Qunix
)
19938 ? eol_mnemonic_unix
19939 : (EQ (eolvalue
, Qdos
) == 1
19940 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19946 /* Mention the EOL conversion if it is not the usual one. */
19947 if (STRINGP (eoltype
))
19949 eol_str
= SDATA (eoltype
);
19950 eol_str_len
= SBYTES (eoltype
);
19952 else if (CHARACTERP (eoltype
))
19954 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19955 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19960 eol_str
= invalid_eol_type
;
19961 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19963 memcpy (buf
, eol_str
, eol_str_len
);
19964 buf
+= eol_str_len
;
19970 /* Return a string for the output of a mode line %-spec for window W,
19971 generated by character C. FIELD_WIDTH > 0 means pad the string
19972 returned with spaces to that value. Return a Lisp string in
19973 *STRING if the resulting string is taken from that Lisp string.
19975 Note we operate on the current buffer for most purposes,
19976 the exception being w->base_line_pos. */
19978 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19980 static const char *
19981 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
19982 Lisp_Object
*string
)
19985 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19986 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19987 struct buffer
*b
= current_buffer
;
19995 if (!NILP (BVAR (b
, read_only
)))
19997 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20002 /* This differs from %* only for a modified read-only buffer. */
20003 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20005 if (!NILP (BVAR (b
, read_only
)))
20010 /* This differs from %* in ignoring read-only-ness. */
20011 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20023 if (command_loop_level
> 5)
20025 p
= decode_mode_spec_buf
;
20026 for (i
= 0; i
< command_loop_level
; i
++)
20029 return decode_mode_spec_buf
;
20037 if (command_loop_level
> 5)
20039 p
= decode_mode_spec_buf
;
20040 for (i
= 0; i
< command_loop_level
; i
++)
20043 return decode_mode_spec_buf
;
20050 /* Let lots_of_dashes be a string of infinite length. */
20051 if (mode_line_target
== MODE_LINE_NOPROP
||
20052 mode_line_target
== MODE_LINE_STRING
)
20054 if (field_width
<= 0
20055 || field_width
> sizeof (lots_of_dashes
))
20057 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
20058 decode_mode_spec_buf
[i
] = '-';
20059 decode_mode_spec_buf
[i
] = '\0';
20060 return decode_mode_spec_buf
;
20063 return lots_of_dashes
;
20067 obj
= BVAR (b
, name
);
20071 /* %c and %l are ignored in `frame-title-format'.
20072 (In redisplay_internal, the frame title is drawn _before_ the
20073 windows are updated, so the stuff which depends on actual
20074 window contents (such as %l) may fail to render properly, or
20075 even crash emacs.) */
20076 if (mode_line_target
== MODE_LINE_TITLE
)
20080 EMACS_INT col
= current_column ();
20081 w
->column_number_displayed
= make_number (col
);
20082 pint2str (decode_mode_spec_buf
, field_width
, col
);
20083 return decode_mode_spec_buf
;
20087 #ifndef SYSTEM_MALLOC
20089 if (NILP (Vmemory_full
))
20092 return "!MEM FULL! ";
20099 /* %F displays the frame name. */
20100 if (!NILP (f
->title
))
20101 return SSDATA (f
->title
);
20102 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
20103 return SSDATA (f
->name
);
20107 obj
= BVAR (b
, filename
);
20112 EMACS_INT size
= ZV
- BEGV
;
20113 pint2str (decode_mode_spec_buf
, field_width
, size
);
20114 return decode_mode_spec_buf
;
20119 EMACS_INT size
= ZV
- BEGV
;
20120 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
20121 return decode_mode_spec_buf
;
20126 EMACS_INT startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
20127 EMACS_INT topline
, nlines
, height
;
20130 /* %c and %l are ignored in `frame-title-format'. */
20131 if (mode_line_target
== MODE_LINE_TITLE
)
20134 startpos
= XMARKER (w
->start
)->charpos
;
20135 startpos_byte
= marker_byte_position (w
->start
);
20136 height
= WINDOW_TOTAL_LINES (w
);
20138 /* If we decided that this buffer isn't suitable for line numbers,
20139 don't forget that too fast. */
20140 if (EQ (w
->base_line_pos
, w
->buffer
))
20142 /* But do forget it, if the window shows a different buffer now. */
20143 else if (BUFFERP (w
->base_line_pos
))
20144 w
->base_line_pos
= Qnil
;
20146 /* If the buffer is very big, don't waste time. */
20147 if (INTEGERP (Vline_number_display_limit
)
20148 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
20150 w
->base_line_pos
= Qnil
;
20151 w
->base_line_number
= Qnil
;
20155 if (INTEGERP (w
->base_line_number
)
20156 && INTEGERP (w
->base_line_pos
)
20157 && XFASTINT (w
->base_line_pos
) <= startpos
)
20159 line
= XFASTINT (w
->base_line_number
);
20160 linepos
= XFASTINT (w
->base_line_pos
);
20161 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
20166 linepos
= BUF_BEGV (b
);
20167 linepos_byte
= BUF_BEGV_BYTE (b
);
20170 /* Count lines from base line to window start position. */
20171 nlines
= display_count_lines (linepos_byte
,
20175 topline
= nlines
+ line
;
20177 /* Determine a new base line, if the old one is too close
20178 or too far away, or if we did not have one.
20179 "Too close" means it's plausible a scroll-down would
20180 go back past it. */
20181 if (startpos
== BUF_BEGV (b
))
20183 w
->base_line_number
= make_number (topline
);
20184 w
->base_line_pos
= make_number (BUF_BEGV (b
));
20186 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
20187 || linepos
== BUF_BEGV (b
))
20189 EMACS_INT limit
= BUF_BEGV (b
);
20190 EMACS_INT limit_byte
= BUF_BEGV_BYTE (b
);
20191 EMACS_INT position
;
20192 EMACS_INT distance
=
20193 (height
* 2 + 30) * line_number_display_limit_width
;
20195 if (startpos
- distance
> limit
)
20197 limit
= startpos
- distance
;
20198 limit_byte
= CHAR_TO_BYTE (limit
);
20201 nlines
= display_count_lines (startpos_byte
,
20203 - (height
* 2 + 30),
20205 /* If we couldn't find the lines we wanted within
20206 line_number_display_limit_width chars per line,
20207 give up on line numbers for this window. */
20208 if (position
== limit_byte
&& limit
== startpos
- distance
)
20210 w
->base_line_pos
= w
->buffer
;
20211 w
->base_line_number
= Qnil
;
20215 w
->base_line_number
= make_number (topline
- nlines
);
20216 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
20219 /* Now count lines from the start pos to point. */
20220 nlines
= display_count_lines (startpos_byte
,
20221 PT_BYTE
, PT
, &junk
);
20223 /* Record that we did display the line number. */
20224 line_number_displayed
= 1;
20226 /* Make the string to show. */
20227 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
20228 return decode_mode_spec_buf
;
20231 char* p
= decode_mode_spec_buf
;
20232 int pad
= field_width
- 2;
20238 return decode_mode_spec_buf
;
20244 obj
= BVAR (b
, mode_name
);
20248 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
20254 EMACS_INT pos
= marker_position (w
->start
);
20255 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
20257 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
20259 if (pos
<= BUF_BEGV (b
))
20264 else if (pos
<= BUF_BEGV (b
))
20268 if (total
> 1000000)
20269 /* Do it differently for a large value, to avoid overflow. */
20270 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
20272 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
20273 /* We can't normally display a 3-digit number,
20274 so get us a 2-digit number that is close. */
20277 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
20278 return decode_mode_spec_buf
;
20282 /* Display percentage of size above the bottom of the screen. */
20285 EMACS_INT toppos
= marker_position (w
->start
);
20286 EMACS_INT botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
20287 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
20289 if (botpos
>= BUF_ZV (b
))
20291 if (toppos
<= BUF_BEGV (b
))
20298 if (total
> 1000000)
20299 /* Do it differently for a large value, to avoid overflow. */
20300 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
20302 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
20303 /* We can't normally display a 3-digit number,
20304 so get us a 2-digit number that is close. */
20307 if (toppos
<= BUF_BEGV (b
))
20308 sprintf (decode_mode_spec_buf
, "Top%2"pI
"d%%", total
);
20310 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
20311 return decode_mode_spec_buf
;
20316 /* status of process */
20317 obj
= Fget_buffer_process (Fcurrent_buffer ());
20319 return "no process";
20321 obj
= Fsymbol_name (Fprocess_status (obj
));
20327 int count
= inhibit_garbage_collection ();
20328 Lisp_Object val
= call1 (intern ("file-remote-p"),
20329 BVAR (current_buffer
, directory
));
20330 unbind_to (count
, Qnil
);
20338 case 't': /* indicate TEXT or BINARY */
20342 /* coding-system (not including end-of-line format) */
20344 /* coding-system (including end-of-line type) */
20346 int eol_flag
= (c
== 'Z');
20347 char *p
= decode_mode_spec_buf
;
20349 if (! FRAME_WINDOW_P (f
))
20351 /* No need to mention EOL here--the terminal never needs
20352 to do EOL conversion. */
20353 p
= decode_mode_spec_coding (CODING_ID_NAME
20354 (FRAME_KEYBOARD_CODING (f
)->id
),
20356 p
= decode_mode_spec_coding (CODING_ID_NAME
20357 (FRAME_TERMINAL_CODING (f
)->id
),
20360 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
20363 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
20364 #ifdef subprocesses
20365 obj
= Fget_buffer_process (Fcurrent_buffer ());
20366 if (PROCESSP (obj
))
20368 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
20370 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
20373 #endif /* subprocesses */
20376 return decode_mode_spec_buf
;
20383 return SSDATA (obj
);
20390 /* Count up to COUNT lines starting from START_BYTE.
20391 But don't go beyond LIMIT_BYTE.
20392 Return the number of lines thus found (always nonnegative).
20394 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
20397 display_count_lines (EMACS_INT start_byte
,
20398 EMACS_INT limit_byte
, EMACS_INT count
,
20399 EMACS_INT
*byte_pos_ptr
)
20401 register unsigned char *cursor
;
20402 unsigned char *base
;
20404 register EMACS_INT ceiling
;
20405 register unsigned char *ceiling_addr
;
20406 EMACS_INT orig_count
= count
;
20408 /* If we are not in selective display mode,
20409 check only for newlines. */
20410 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
20411 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
20415 while (start_byte
< limit_byte
)
20417 ceiling
= BUFFER_CEILING_OF (start_byte
);
20418 ceiling
= min (limit_byte
- 1, ceiling
);
20419 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
20420 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
20423 if (selective_display
)
20424 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
20427 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
20430 if (cursor
!= ceiling_addr
)
20434 start_byte
+= cursor
- base
+ 1;
20435 *byte_pos_ptr
= start_byte
;
20439 if (++cursor
== ceiling_addr
)
20445 start_byte
+= cursor
- base
;
20450 while (start_byte
> limit_byte
)
20452 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
20453 ceiling
= max (limit_byte
, ceiling
);
20454 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
20455 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
20458 if (selective_display
)
20459 while (--cursor
!= ceiling_addr
20460 && *cursor
!= '\n' && *cursor
!= 015)
20463 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
20466 if (cursor
!= ceiling_addr
)
20470 start_byte
+= cursor
- base
+ 1;
20471 *byte_pos_ptr
= start_byte
;
20472 /* When scanning backwards, we should
20473 not count the newline posterior to which we stop. */
20474 return - orig_count
- 1;
20480 /* Here we add 1 to compensate for the last decrement
20481 of CURSOR, which took it past the valid range. */
20482 start_byte
+= cursor
- base
+ 1;
20486 *byte_pos_ptr
= limit_byte
;
20489 return - orig_count
+ count
;
20490 return orig_count
- count
;
20496 /***********************************************************************
20498 ***********************************************************************/
20500 /* Display a NUL-terminated string, starting with index START.
20502 If STRING is non-null, display that C string. Otherwise, the Lisp
20503 string LISP_STRING is displayed. There's a case that STRING is
20504 non-null and LISP_STRING is not nil. It means STRING is a string
20505 data of LISP_STRING. In that case, we display LISP_STRING while
20506 ignoring its text properties.
20508 If FACE_STRING is not nil, FACE_STRING_POS is a position in
20509 FACE_STRING. Display STRING or LISP_STRING with the face at
20510 FACE_STRING_POS in FACE_STRING:
20512 Display the string in the environment given by IT, but use the
20513 standard display table, temporarily.
20515 FIELD_WIDTH is the minimum number of output glyphs to produce.
20516 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20517 with spaces. If STRING has more characters, more than FIELD_WIDTH
20518 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
20520 PRECISION is the maximum number of characters to output from
20521 STRING. PRECISION < 0 means don't truncate the string.
20523 This is roughly equivalent to printf format specifiers:
20525 FIELD_WIDTH PRECISION PRINTF
20526 ----------------------------------------
20532 MULTIBYTE zero means do not display multibyte chars, > 0 means do
20533 display them, and < 0 means obey the current buffer's value of
20534 enable_multibyte_characters.
20536 Value is the number of columns displayed. */
20539 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
20540 EMACS_INT face_string_pos
, EMACS_INT start
, struct it
*it
,
20541 int field_width
, int precision
, int max_x
, int multibyte
)
20543 int hpos_at_start
= it
->hpos
;
20544 int saved_face_id
= it
->face_id
;
20545 struct glyph_row
*row
= it
->glyph_row
;
20546 EMACS_INT it_charpos
;
20548 /* Initialize the iterator IT for iteration over STRING beginning
20549 with index START. */
20550 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
20551 precision
, field_width
, multibyte
);
20552 if (string
&& STRINGP (lisp_string
))
20553 /* LISP_STRING is the one returned by decode_mode_spec. We should
20554 ignore its text properties. */
20555 it
->stop_charpos
= it
->end_charpos
;
20557 /* If displaying STRING, set up the face of the iterator from
20558 FACE_STRING, if that's given. */
20559 if (STRINGP (face_string
))
20565 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
20566 0, it
->region_beg_charpos
,
20567 it
->region_end_charpos
,
20568 &endptr
, it
->base_face_id
, 0);
20569 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20570 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
20573 /* Set max_x to the maximum allowed X position. Don't let it go
20574 beyond the right edge of the window. */
20576 max_x
= it
->last_visible_x
;
20578 max_x
= min (max_x
, it
->last_visible_x
);
20580 /* Skip over display elements that are not visible. because IT->w is
20582 if (it
->current_x
< it
->first_visible_x
)
20583 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
20584 MOVE_TO_POS
| MOVE_TO_X
);
20586 row
->ascent
= it
->max_ascent
;
20587 row
->height
= it
->max_ascent
+ it
->max_descent
;
20588 row
->phys_ascent
= it
->max_phys_ascent
;
20589 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20590 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20592 if (STRINGP (it
->string
))
20593 it_charpos
= IT_STRING_CHARPOS (*it
);
20595 it_charpos
= IT_CHARPOS (*it
);
20597 /* This condition is for the case that we are called with current_x
20598 past last_visible_x. */
20599 while (it
->current_x
< max_x
)
20601 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
20603 /* Get the next display element. */
20604 if (!get_next_display_element (it
))
20607 /* Produce glyphs. */
20608 x_before
= it
->current_x
;
20609 n_glyphs_before
= row
->used
[TEXT_AREA
];
20610 PRODUCE_GLYPHS (it
);
20612 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
20615 while (i
< nglyphs
)
20617 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20619 if (it
->line_wrap
!= TRUNCATE
20620 && x
+ glyph
->pixel_width
> max_x
)
20622 /* End of continued line or max_x reached. */
20623 if (CHAR_GLYPH_PADDING_P (*glyph
))
20625 /* A wide character is unbreakable. */
20626 if (row
->reversed_p
)
20627 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20628 - n_glyphs_before
);
20629 row
->used
[TEXT_AREA
] = n_glyphs_before
;
20630 it
->current_x
= x_before
;
20634 if (row
->reversed_p
)
20635 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20636 - (n_glyphs_before
+ i
));
20637 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20642 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
20644 /* Glyph is at least partially visible. */
20646 if (x
< it
->first_visible_x
)
20647 row
->x
= x
- it
->first_visible_x
;
20651 /* Glyph is off the left margin of the display area.
20652 Should not happen. */
20656 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20657 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20658 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20659 row
->phys_height
= max (row
->phys_height
,
20660 it
->max_phys_ascent
+ it
->max_phys_descent
);
20661 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20662 it
->max_extra_line_spacing
);
20663 x
+= glyph
->pixel_width
;
20667 /* Stop if max_x reached. */
20671 /* Stop at line ends. */
20672 if (ITERATOR_AT_END_OF_LINE_P (it
))
20674 it
->continuation_lines_width
= 0;
20678 set_iterator_to_next (it
, 1);
20679 if (STRINGP (it
->string
))
20680 it_charpos
= IT_STRING_CHARPOS (*it
);
20682 it_charpos
= IT_CHARPOS (*it
);
20684 /* Stop if truncating at the right edge. */
20685 if (it
->line_wrap
== TRUNCATE
20686 && it
->current_x
>= it
->last_visible_x
)
20688 /* Add truncation mark, but don't do it if the line is
20689 truncated at a padding space. */
20690 if (it_charpos
< it
->string_nchars
)
20692 if (!FRAME_WINDOW_P (it
->f
))
20696 if (it
->current_x
> it
->last_visible_x
)
20698 if (!row
->reversed_p
)
20700 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
20701 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20706 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
20707 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20709 unproduce_glyphs (it
, ii
+ 1);
20710 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
20712 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
20714 row
->used
[TEXT_AREA
] = ii
;
20715 produce_special_glyphs (it
, IT_TRUNCATION
);
20718 produce_special_glyphs (it
, IT_TRUNCATION
);
20720 row
->truncated_on_right_p
= 1;
20726 /* Maybe insert a truncation at the left. */
20727 if (it
->first_visible_x
20730 if (!FRAME_WINDOW_P (it
->f
))
20731 insert_left_trunc_glyphs (it
);
20732 row
->truncated_on_left_p
= 1;
20735 it
->face_id
= saved_face_id
;
20737 /* Value is number of columns displayed. */
20738 return it
->hpos
- hpos_at_start
;
20743 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
20744 appears as an element of LIST or as the car of an element of LIST.
20745 If PROPVAL is a list, compare each element against LIST in that
20746 way, and return 1/2 if any element of PROPVAL is found in LIST.
20747 Otherwise return 0. This function cannot quit.
20748 The return value is 2 if the text is invisible but with an ellipsis
20749 and 1 if it's invisible and without an ellipsis. */
20752 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
20754 register Lisp_Object tail
, proptail
;
20756 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20758 register Lisp_Object tem
;
20760 if (EQ (propval
, tem
))
20762 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
20763 return NILP (XCDR (tem
)) ? 1 : 2;
20766 if (CONSP (propval
))
20768 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
20770 Lisp_Object propelt
;
20771 propelt
= XCAR (proptail
);
20772 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20774 register Lisp_Object tem
;
20776 if (EQ (propelt
, tem
))
20778 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
20779 return NILP (XCDR (tem
)) ? 1 : 2;
20787 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
20788 doc
: /* Non-nil if the property makes the text invisible.
20789 POS-OR-PROP can be a marker or number, in which case it is taken to be
20790 a position in the current buffer and the value of the `invisible' property
20791 is checked; or it can be some other value, which is then presumed to be the
20792 value of the `invisible' property of the text of interest.
20793 The non-nil value returned can be t for truly invisible text or something
20794 else if the text is replaced by an ellipsis. */)
20795 (Lisp_Object pos_or_prop
)
20798 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
20799 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
20801 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
20802 return (invis
== 0 ? Qnil
20804 : make_number (invis
));
20807 /* Calculate a width or height in pixels from a specification using
20808 the following elements:
20811 NUM - a (fractional) multiple of the default font width/height
20812 (NUM) - specifies exactly NUM pixels
20813 UNIT - a fixed number of pixels, see below.
20814 ELEMENT - size of a display element in pixels, see below.
20815 (NUM . SPEC) - equals NUM * SPEC
20816 (+ SPEC SPEC ...) - add pixel values
20817 (- SPEC SPEC ...) - subtract pixel values
20818 (- SPEC) - negate pixel value
20821 INT or FLOAT - a number constant
20822 SYMBOL - use symbol's (buffer local) variable binding.
20825 in - pixels per inch *)
20826 mm - pixels per 1/1000 meter *)
20827 cm - pixels per 1/100 meter *)
20828 width - width of current font in pixels.
20829 height - height of current font in pixels.
20831 *) using the ratio(s) defined in display-pixels-per-inch.
20835 left-fringe - left fringe width in pixels
20836 right-fringe - right fringe width in pixels
20838 left-margin - left margin width in pixels
20839 right-margin - right margin width in pixels
20841 scroll-bar - scroll-bar area width in pixels
20845 Pixels corresponding to 5 inches:
20848 Total width of non-text areas on left side of window (if scroll-bar is on left):
20849 '(space :width (+ left-fringe left-margin scroll-bar))
20851 Align to first text column (in header line):
20852 '(space :align-to 0)
20854 Align to middle of text area minus half the width of variable `my-image'
20855 containing a loaded image:
20856 '(space :align-to (0.5 . (- text my-image)))
20858 Width of left margin minus width of 1 character in the default font:
20859 '(space :width (- left-margin 1))
20861 Width of left margin minus width of 2 characters in the current font:
20862 '(space :width (- left-margin (2 . width)))
20864 Center 1 character over left-margin (in header line):
20865 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
20867 Different ways to express width of left fringe plus left margin minus one pixel:
20868 '(space :width (- (+ left-fringe left-margin) (1)))
20869 '(space :width (+ left-fringe left-margin (- (1))))
20870 '(space :width (+ left-fringe left-margin (-1)))
20874 #define NUMVAL(X) \
20875 ((INTEGERP (X) || FLOATP (X)) \
20880 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
20881 struct font
*font
, int width_p
, int *align_to
)
20885 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20886 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20889 return OK_PIXELS (0);
20891 xassert (FRAME_LIVE_P (it
->f
));
20893 if (SYMBOLP (prop
))
20895 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20897 char *unit
= SSDATA (SYMBOL_NAME (prop
));
20899 if (unit
[0] == 'i' && unit
[1] == 'n')
20901 else if (unit
[0] == 'm' && unit
[1] == 'm')
20903 else if (unit
[0] == 'c' && unit
[1] == 'm')
20910 #ifdef HAVE_WINDOW_SYSTEM
20911 if (FRAME_WINDOW_P (it
->f
)
20913 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20914 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20916 return OK_PIXELS (ppi
/ pixels
);
20919 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20920 || (CONSP (Vdisplay_pixels_per_inch
)
20922 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20923 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20925 return OK_PIXELS (ppi
/ pixels
);
20931 #ifdef HAVE_WINDOW_SYSTEM
20932 if (EQ (prop
, Qheight
))
20933 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20934 if (EQ (prop
, Qwidth
))
20935 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20937 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20938 return OK_PIXELS (1);
20941 if (EQ (prop
, Qtext
))
20942 return OK_PIXELS (width_p
20943 ? window_box_width (it
->w
, TEXT_AREA
)
20944 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20946 if (align_to
&& *align_to
< 0)
20949 if (EQ (prop
, Qleft
))
20950 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20951 if (EQ (prop
, Qright
))
20952 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20953 if (EQ (prop
, Qcenter
))
20954 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20955 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20956 if (EQ (prop
, Qleft_fringe
))
20957 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20958 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20959 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20960 if (EQ (prop
, Qright_fringe
))
20961 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20962 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20963 : window_box_right_offset (it
->w
, TEXT_AREA
));
20964 if (EQ (prop
, Qleft_margin
))
20965 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20966 if (EQ (prop
, Qright_margin
))
20967 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20968 if (EQ (prop
, Qscroll_bar
))
20969 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20971 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20972 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20973 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20978 if (EQ (prop
, Qleft_fringe
))
20979 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20980 if (EQ (prop
, Qright_fringe
))
20981 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20982 if (EQ (prop
, Qleft_margin
))
20983 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20984 if (EQ (prop
, Qright_margin
))
20985 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20986 if (EQ (prop
, Qscroll_bar
))
20987 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20990 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20993 if (INTEGERP (prop
) || FLOATP (prop
))
20995 int base_unit
= (width_p
20996 ? FRAME_COLUMN_WIDTH (it
->f
)
20997 : FRAME_LINE_HEIGHT (it
->f
));
20998 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
21003 Lisp_Object car
= XCAR (prop
);
21004 Lisp_Object cdr
= XCDR (prop
);
21008 #ifdef HAVE_WINDOW_SYSTEM
21009 if (FRAME_WINDOW_P (it
->f
)
21010 && valid_image_p (prop
))
21012 int id
= lookup_image (it
->f
, prop
);
21013 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
21015 return OK_PIXELS (width_p
? img
->width
: img
->height
);
21018 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
21024 while (CONSP (cdr
))
21026 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
21027 font
, width_p
, align_to
))
21030 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
21035 if (EQ (car
, Qminus
))
21037 return OK_PIXELS (pixels
);
21040 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
21043 if (INTEGERP (car
) || FLOATP (car
))
21046 pixels
= XFLOATINT (car
);
21048 return OK_PIXELS (pixels
);
21049 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
21050 font
, width_p
, align_to
))
21051 return OK_PIXELS (pixels
* fact
);
21062 /***********************************************************************
21064 ***********************************************************************/
21066 #ifdef HAVE_WINDOW_SYSTEM
21071 dump_glyph_string (s
)
21072 struct glyph_string
*s
;
21074 fprintf (stderr
, "glyph string\n");
21075 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
21076 s
->x
, s
->y
, s
->width
, s
->height
);
21077 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
21078 fprintf (stderr
, " hl = %d\n", s
->hl
);
21079 fprintf (stderr
, " left overhang = %d, right = %d\n",
21080 s
->left_overhang
, s
->right_overhang
);
21081 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
21082 fprintf (stderr
, " extends to end of line = %d\n",
21083 s
->extends_to_end_of_line_p
);
21084 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
21085 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
21088 #endif /* GLYPH_DEBUG */
21090 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
21091 of XChar2b structures for S; it can't be allocated in
21092 init_glyph_string because it must be allocated via `alloca'. W
21093 is the window on which S is drawn. ROW and AREA are the glyph row
21094 and area within the row from which S is constructed. START is the
21095 index of the first glyph structure covered by S. HL is a
21096 face-override for drawing S. */
21099 #define OPTIONAL_HDC(hdc) HDC hdc,
21100 #define DECLARE_HDC(hdc) HDC hdc;
21101 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
21102 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
21105 #ifndef OPTIONAL_HDC
21106 #define OPTIONAL_HDC(hdc)
21107 #define DECLARE_HDC(hdc)
21108 #define ALLOCATE_HDC(hdc, f)
21109 #define RELEASE_HDC(hdc, f)
21113 init_glyph_string (struct glyph_string
*s
,
21115 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
21116 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
21118 memset (s
, 0, sizeof *s
);
21120 s
->f
= XFRAME (w
->frame
);
21124 s
->display
= FRAME_X_DISPLAY (s
->f
);
21125 s
->window
= FRAME_X_WINDOW (s
->f
);
21126 s
->char2b
= char2b
;
21130 s
->first_glyph
= row
->glyphs
[area
] + start
;
21131 s
->height
= row
->height
;
21132 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
21133 s
->ybase
= s
->y
+ row
->ascent
;
21137 /* Append the list of glyph strings with head H and tail T to the list
21138 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
21141 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
21142 struct glyph_string
*h
, struct glyph_string
*t
)
21156 /* Prepend the list of glyph strings with head H and tail T to the
21157 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
21161 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
21162 struct glyph_string
*h
, struct glyph_string
*t
)
21176 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
21177 Set *HEAD and *TAIL to the resulting list. */
21180 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
21181 struct glyph_string
*s
)
21183 s
->next
= s
->prev
= NULL
;
21184 append_glyph_string_lists (head
, tail
, s
, s
);
21188 /* Get face and two-byte form of character C in face FACE_ID on frame F.
21189 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
21190 make sure that X resources for the face returned are allocated.
21191 Value is a pointer to a realized face that is ready for display if
21192 DISPLAY_P is non-zero. */
21194 static INLINE
struct face
*
21195 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
21196 XChar2b
*char2b
, int display_p
)
21198 struct face
*face
= FACE_FROM_ID (f
, face_id
);
21202 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
21204 if (code
!= FONT_INVALID_CODE
)
21205 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21207 STORE_XCHAR2B (char2b
, 0, 0);
21210 /* Make sure X resources of the face are allocated. */
21211 #ifdef HAVE_X_WINDOWS
21215 xassert (face
!= NULL
);
21216 PREPARE_FACE_FOR_DISPLAY (f
, face
);
21223 /* Get face and two-byte form of character glyph GLYPH on frame F.
21224 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
21225 a pointer to a realized face that is ready for display. */
21227 static INLINE
struct face
*
21228 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
21229 XChar2b
*char2b
, int *two_byte_p
)
21233 xassert (glyph
->type
== CHAR_GLYPH
);
21234 face
= FACE_FROM_ID (f
, glyph
->face_id
);
21243 if (CHAR_BYTE8_P (glyph
->u
.ch
))
21244 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
21246 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
21248 if (code
!= FONT_INVALID_CODE
)
21249 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21251 STORE_XCHAR2B (char2b
, 0, 0);
21254 /* Make sure X resources of the face are allocated. */
21255 xassert (face
!= NULL
);
21256 PREPARE_FACE_FOR_DISPLAY (f
, face
);
21261 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
21262 Retunr 1 if FONT has a glyph for C, otherwise return 0. */
21265 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
21269 if (CHAR_BYTE8_P (c
))
21270 code
= CHAR_TO_BYTE8 (c
);
21272 code
= font
->driver
->encode_char (font
, c
);
21274 if (code
== FONT_INVALID_CODE
)
21276 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21281 /* Fill glyph string S with composition components specified by S->cmp.
21283 BASE_FACE is the base face of the composition.
21284 S->cmp_from is the index of the first component for S.
21286 OVERLAPS non-zero means S should draw the foreground only, and use
21287 its physical height for clipping. See also draw_glyphs.
21289 Value is the index of a component not in S. */
21292 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
21296 /* For all glyphs of this composition, starting at the offset
21297 S->cmp_from, until we reach the end of the definition or encounter a
21298 glyph that requires the different face, add it to S. */
21303 s
->for_overlaps
= overlaps
;
21306 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
21308 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
21312 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
21315 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
21322 s
->font
= s
->face
->font
;
21324 else if (s
->face
!= face
)
21332 /* All glyph strings for the same composition has the same width,
21333 i.e. the width set for the first component of the composition. */
21334 s
->width
= s
->first_glyph
->pixel_width
;
21336 /* If the specified font could not be loaded, use the frame's
21337 default font, but record the fact that we couldn't load it in
21338 the glyph string so that we can draw rectangles for the
21339 characters of the glyph string. */
21340 if (s
->font
== NULL
)
21342 s
->font_not_found_p
= 1;
21343 s
->font
= FRAME_FONT (s
->f
);
21346 /* Adjust base line for subscript/superscript text. */
21347 s
->ybase
+= s
->first_glyph
->voffset
;
21349 /* This glyph string must always be drawn with 16-bit functions. */
21356 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
21357 int start
, int end
, int overlaps
)
21359 struct glyph
*glyph
, *last
;
21360 Lisp_Object lgstring
;
21363 s
->for_overlaps
= overlaps
;
21364 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21365 last
= s
->row
->glyphs
[s
->area
] + end
;
21366 s
->cmp_id
= glyph
->u
.cmp
.id
;
21367 s
->cmp_from
= glyph
->slice
.cmp
.from
;
21368 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
21369 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21370 lgstring
= composition_gstring_from_id (s
->cmp_id
);
21371 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
21373 while (glyph
< last
21374 && glyph
->u
.cmp
.automatic
21375 && glyph
->u
.cmp
.id
== s
->cmp_id
21376 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
21377 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
21379 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
21381 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
21382 unsigned code
= LGLYPH_CODE (lglyph
);
21384 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
21386 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
21387 return glyph
- s
->row
->glyphs
[s
->area
];
21391 /* Fill glyph string S from a sequence glyphs for glyphless characters.
21392 See the comment of fill_glyph_string for arguments.
21393 Value is the index of the first glyph not in S. */
21397 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
21398 int start
, int end
, int overlaps
)
21400 struct glyph
*glyph
, *last
;
21403 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
21404 s
->for_overlaps
= overlaps
;
21405 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21406 last
= s
->row
->glyphs
[s
->area
] + end
;
21407 voffset
= glyph
->voffset
;
21408 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21409 s
->font
= s
->face
->font
;
21411 s
->width
= glyph
->pixel_width
;
21413 while (glyph
< last
21414 && glyph
->type
== GLYPHLESS_GLYPH
21415 && glyph
->voffset
== voffset
21416 && glyph
->face_id
== face_id
)
21419 s
->width
+= glyph
->pixel_width
;
21422 s
->ybase
+= voffset
;
21423 return glyph
- s
->row
->glyphs
[s
->area
];
21427 /* Fill glyph string S from a sequence of character glyphs.
21429 FACE_ID is the face id of the string. START is the index of the
21430 first glyph to consider, END is the index of the last + 1.
21431 OVERLAPS non-zero means S should draw the foreground only, and use
21432 its physical height for clipping. See also draw_glyphs.
21434 Value is the index of the first glyph not in S. */
21437 fill_glyph_string (struct glyph_string
*s
, int face_id
,
21438 int start
, int end
, int overlaps
)
21440 struct glyph
*glyph
, *last
;
21442 int glyph_not_available_p
;
21444 xassert (s
->f
== XFRAME (s
->w
->frame
));
21445 xassert (s
->nchars
== 0);
21446 xassert (start
>= 0 && end
> start
);
21448 s
->for_overlaps
= overlaps
;
21449 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21450 last
= s
->row
->glyphs
[s
->area
] + end
;
21451 voffset
= glyph
->voffset
;
21452 s
->padding_p
= glyph
->padding_p
;
21453 glyph_not_available_p
= glyph
->glyph_not_available_p
;
21455 while (glyph
< last
21456 && glyph
->type
== CHAR_GLYPH
21457 && glyph
->voffset
== voffset
21458 /* Same face id implies same font, nowadays. */
21459 && glyph
->face_id
== face_id
21460 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
21464 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
21465 s
->char2b
+ s
->nchars
,
21467 s
->two_byte_p
= two_byte_p
;
21469 xassert (s
->nchars
<= end
- start
);
21470 s
->width
+= glyph
->pixel_width
;
21471 if (glyph
++->padding_p
!= s
->padding_p
)
21475 s
->font
= s
->face
->font
;
21477 /* If the specified font could not be loaded, use the frame's font,
21478 but record the fact that we couldn't load it in
21479 S->font_not_found_p so that we can draw rectangles for the
21480 characters of the glyph string. */
21481 if (s
->font
== NULL
|| glyph_not_available_p
)
21483 s
->font_not_found_p
= 1;
21484 s
->font
= FRAME_FONT (s
->f
);
21487 /* Adjust base line for subscript/superscript text. */
21488 s
->ybase
+= voffset
;
21490 xassert (s
->face
&& s
->face
->gc
);
21491 return glyph
- s
->row
->glyphs
[s
->area
];
21495 /* Fill glyph string S from image glyph S->first_glyph. */
21498 fill_image_glyph_string (struct glyph_string
*s
)
21500 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
21501 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
21503 s
->slice
= s
->first_glyph
->slice
.img
;
21504 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
21505 s
->font
= s
->face
->font
;
21506 s
->width
= s
->first_glyph
->pixel_width
;
21508 /* Adjust base line for subscript/superscript text. */
21509 s
->ybase
+= s
->first_glyph
->voffset
;
21513 /* Fill glyph string S from a sequence of stretch glyphs.
21515 START is the index of the first glyph to consider,
21516 END is the index of the last + 1.
21518 Value is the index of the first glyph not in S. */
21521 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
21523 struct glyph
*glyph
, *last
;
21524 int voffset
, face_id
;
21526 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
21528 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21529 last
= s
->row
->glyphs
[s
->area
] + end
;
21530 face_id
= glyph
->face_id
;
21531 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21532 s
->font
= s
->face
->font
;
21533 s
->width
= glyph
->pixel_width
;
21535 voffset
= glyph
->voffset
;
21539 && glyph
->type
== STRETCH_GLYPH
21540 && glyph
->voffset
== voffset
21541 && glyph
->face_id
== face_id
);
21543 s
->width
+= glyph
->pixel_width
;
21545 /* Adjust base line for subscript/superscript text. */
21546 s
->ybase
+= voffset
;
21548 /* The case that face->gc == 0 is handled when drawing the glyph
21549 string by calling PREPARE_FACE_FOR_DISPLAY. */
21551 return glyph
- s
->row
->glyphs
[s
->area
];
21554 static struct font_metrics
*
21555 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
21557 static struct font_metrics metrics
;
21558 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
21560 if (! font
|| code
== FONT_INVALID_CODE
)
21562 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
21567 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
21568 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
21569 assumed to be zero. */
21572 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
21574 *left
= *right
= 0;
21576 if (glyph
->type
== CHAR_GLYPH
)
21580 struct font_metrics
*pcm
;
21582 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
21583 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
21585 if (pcm
->rbearing
> pcm
->width
)
21586 *right
= pcm
->rbearing
- pcm
->width
;
21587 if (pcm
->lbearing
< 0)
21588 *left
= -pcm
->lbearing
;
21591 else if (glyph
->type
== COMPOSITE_GLYPH
)
21593 if (! glyph
->u
.cmp
.automatic
)
21595 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
21597 if (cmp
->rbearing
> cmp
->pixel_width
)
21598 *right
= cmp
->rbearing
- cmp
->pixel_width
;
21599 if (cmp
->lbearing
< 0)
21600 *left
= - cmp
->lbearing
;
21604 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
21605 struct font_metrics metrics
;
21607 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
21608 glyph
->slice
.cmp
.to
+ 1, &metrics
);
21609 if (metrics
.rbearing
> metrics
.width
)
21610 *right
= metrics
.rbearing
- metrics
.width
;
21611 if (metrics
.lbearing
< 0)
21612 *left
= - metrics
.lbearing
;
21618 /* Return the index of the first glyph preceding glyph string S that
21619 is overwritten by S because of S's left overhang. Value is -1
21620 if no glyphs are overwritten. */
21623 left_overwritten (struct glyph_string
*s
)
21627 if (s
->left_overhang
)
21630 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21631 int first
= s
->first_glyph
- glyphs
;
21633 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
21634 x
-= glyphs
[i
].pixel_width
;
21645 /* Return the index of the first glyph preceding glyph string S that
21646 is overwriting S because of its right overhang. Value is -1 if no
21647 glyph in front of S overwrites S. */
21650 left_overwriting (struct glyph_string
*s
)
21653 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21654 int first
= s
->first_glyph
- glyphs
;
21658 for (i
= first
- 1; i
>= 0; --i
)
21661 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21664 x
-= glyphs
[i
].pixel_width
;
21671 /* Return the index of the last glyph following glyph string S that is
21672 overwritten by S because of S's right overhang. Value is -1 if
21673 no such glyph is found. */
21676 right_overwritten (struct glyph_string
*s
)
21680 if (s
->right_overhang
)
21683 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21684 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21685 int end
= s
->row
->used
[s
->area
];
21687 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
21688 x
+= glyphs
[i
].pixel_width
;
21697 /* Return the index of the last glyph following glyph string S that
21698 overwrites S because of its left overhang. Value is negative
21699 if no such glyph is found. */
21702 right_overwriting (struct glyph_string
*s
)
21705 int end
= s
->row
->used
[s
->area
];
21706 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21707 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21711 for (i
= first
; i
< end
; ++i
)
21714 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21717 x
+= glyphs
[i
].pixel_width
;
21724 /* Set background width of glyph string S. START is the index of the
21725 first glyph following S. LAST_X is the right-most x-position + 1
21726 in the drawing area. */
21729 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
21731 /* If the face of this glyph string has to be drawn to the end of
21732 the drawing area, set S->extends_to_end_of_line_p. */
21734 if (start
== s
->row
->used
[s
->area
]
21735 && s
->area
== TEXT_AREA
21736 && ((s
->row
->fill_line_p
21737 && (s
->hl
== DRAW_NORMAL_TEXT
21738 || s
->hl
== DRAW_IMAGE_RAISED
21739 || s
->hl
== DRAW_IMAGE_SUNKEN
))
21740 || s
->hl
== DRAW_MOUSE_FACE
))
21741 s
->extends_to_end_of_line_p
= 1;
21743 /* If S extends its face to the end of the line, set its
21744 background_width to the distance to the right edge of the drawing
21746 if (s
->extends_to_end_of_line_p
)
21747 s
->background_width
= last_x
- s
->x
+ 1;
21749 s
->background_width
= s
->width
;
21753 /* Compute overhangs and x-positions for glyph string S and its
21754 predecessors, or successors. X is the starting x-position for S.
21755 BACKWARD_P non-zero means process predecessors. */
21758 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
21764 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21765 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21775 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21776 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21786 /* The following macros are only called from draw_glyphs below.
21787 They reference the following parameters of that function directly:
21788 `w', `row', `area', and `overlap_p'
21789 as well as the following local variables:
21790 `s', `f', and `hdc' (in W32) */
21793 /* On W32, silently add local `hdc' variable to argument list of
21794 init_glyph_string. */
21795 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21796 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
21798 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21799 init_glyph_string (s, char2b, w, row, area, start, hl)
21802 /* Add a glyph string for a stretch glyph to the list of strings
21803 between HEAD and TAIL. START is the index of the stretch glyph in
21804 row area AREA of glyph row ROW. END is the index of the last glyph
21805 in that glyph row area. X is the current output position assigned
21806 to the new glyph string constructed. HL overrides that face of the
21807 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21808 is the right-most x-position of the drawing area. */
21810 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
21811 and below -- keep them on one line. */
21812 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21815 s = (struct glyph_string *) alloca (sizeof *s); \
21816 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21817 START = fill_stretch_glyph_string (s, START, END); \
21818 append_glyph_string (&HEAD, &TAIL, s); \
21824 /* Add a glyph string for an image glyph to the list of strings
21825 between HEAD and TAIL. START is the index of the image glyph in
21826 row area AREA of glyph row ROW. END is the index of the last glyph
21827 in that glyph row area. X is the current output position assigned
21828 to the new glyph string constructed. HL overrides that face of the
21829 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21830 is the right-most x-position of the drawing area. */
21832 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21835 s = (struct glyph_string *) alloca (sizeof *s); \
21836 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21837 fill_image_glyph_string (s); \
21838 append_glyph_string (&HEAD, &TAIL, s); \
21845 /* Add a glyph string for a sequence of character glyphs to the list
21846 of strings between HEAD and TAIL. START is the index of the first
21847 glyph in row area AREA of glyph row ROW that is part of the new
21848 glyph string. END is the index of the last glyph in that glyph row
21849 area. X is the current output position assigned to the new glyph
21850 string constructed. HL overrides that face of the glyph; e.g. it
21851 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
21852 right-most x-position of the drawing area. */
21854 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21860 face_id = (row)->glyphs[area][START].face_id; \
21862 s = (struct glyph_string *) alloca (sizeof *s); \
21863 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
21864 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21865 append_glyph_string (&HEAD, &TAIL, s); \
21867 START = fill_glyph_string (s, face_id, START, END, overlaps); \
21872 /* Add a glyph string for a composite sequence to the list of strings
21873 between HEAD and TAIL. START is the index of the first glyph in
21874 row area AREA of glyph row ROW that is part of the new glyph
21875 string. END is the index of the last glyph in that glyph row area.
21876 X is the current output position assigned to the new glyph string
21877 constructed. HL overrides that face of the glyph; e.g. it is
21878 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
21879 x-position of the drawing area. */
21881 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21883 int face_id = (row)->glyphs[area][START].face_id; \
21884 struct face *base_face = FACE_FROM_ID (f, face_id); \
21885 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
21886 struct composition *cmp = composition_table[cmp_id]; \
21888 struct glyph_string *first_s IF_LINT (= NULL); \
21891 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21893 /* Make glyph_strings for each glyph sequence that is drawable by \
21894 the same face, and append them to HEAD/TAIL. */ \
21895 for (n = 0; n < cmp->glyph_len;) \
21897 s = (struct glyph_string *) alloca (sizeof *s); \
21898 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21899 append_glyph_string (&(HEAD), &(TAIL), s); \
21905 n = fill_composite_glyph_string (s, base_face, overlaps); \
21913 /* Add a glyph string for a glyph-string sequence to the list of strings
21914 between HEAD and TAIL. */
21916 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21920 Lisp_Object gstring; \
21922 face_id = (row)->glyphs[area][START].face_id; \
21923 gstring = (composition_gstring_from_id \
21924 ((row)->glyphs[area][START].u.cmp.id)); \
21925 s = (struct glyph_string *) alloca (sizeof *s); \
21926 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21927 * LGSTRING_GLYPH_LEN (gstring)); \
21928 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21929 append_glyph_string (&(HEAD), &(TAIL), s); \
21931 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21935 /* Add a glyph string for a sequence of glyphless character's glyphs
21936 to the list of strings between HEAD and TAIL. The meanings of
21937 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
21939 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21944 face_id = (row)->glyphs[area][START].face_id; \
21946 s = (struct glyph_string *) alloca (sizeof *s); \
21947 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21948 append_glyph_string (&HEAD, &TAIL, s); \
21950 START = fill_glyphless_glyph_string (s, face_id, START, END, \
21956 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21957 of AREA of glyph row ROW on window W between indices START and END.
21958 HL overrides the face for drawing glyph strings, e.g. it is
21959 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21960 x-positions of the drawing area.
21962 This is an ugly monster macro construct because we must use alloca
21963 to allocate glyph strings (because draw_glyphs can be called
21964 asynchronously). */
21966 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21969 HEAD = TAIL = NULL; \
21970 while (START < END) \
21972 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21973 switch (first_glyph->type) \
21976 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21980 case COMPOSITE_GLYPH: \
21981 if (first_glyph->u.cmp.automatic) \
21982 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21985 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21989 case STRETCH_GLYPH: \
21990 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21994 case IMAGE_GLYPH: \
21995 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21999 case GLYPHLESS_GLYPH: \
22000 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
22010 set_glyph_string_background_width (s, START, LAST_X); \
22017 /* Draw glyphs between START and END in AREA of ROW on window W,
22018 starting at x-position X. X is relative to AREA in W. HL is a
22019 face-override with the following meaning:
22021 DRAW_NORMAL_TEXT draw normally
22022 DRAW_CURSOR draw in cursor face
22023 DRAW_MOUSE_FACE draw in mouse face.
22024 DRAW_INVERSE_VIDEO draw in mode line face
22025 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
22026 DRAW_IMAGE_RAISED draw an image with a raised relief around it
22028 If OVERLAPS is non-zero, draw only the foreground of characters and
22029 clip to the physical height of ROW. Non-zero value also defines
22030 the overlapping part to be drawn:
22032 OVERLAPS_PRED overlap with preceding rows
22033 OVERLAPS_SUCC overlap with succeeding rows
22034 OVERLAPS_BOTH overlap with both preceding/succeeding rows
22035 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
22037 Value is the x-position reached, relative to AREA of W. */
22040 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
22041 enum glyph_row_area area
, EMACS_INT start
, EMACS_INT end
,
22042 enum draw_glyphs_face hl
, int overlaps
)
22044 struct glyph_string
*head
, *tail
;
22045 struct glyph_string
*s
;
22046 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
22047 int i
, j
, x_reached
, last_x
, area_left
= 0;
22048 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22051 ALLOCATE_HDC (hdc
, f
);
22053 /* Let's rather be paranoid than getting a SEGV. */
22054 end
= min (end
, row
->used
[area
]);
22055 start
= max (0, start
);
22056 start
= min (end
, start
);
22058 /* Translate X to frame coordinates. Set last_x to the right
22059 end of the drawing area. */
22060 if (row
->full_width_p
)
22062 /* X is relative to the left edge of W, without scroll bars
22064 area_left
= WINDOW_LEFT_EDGE_X (w
);
22065 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
22069 area_left
= window_box_left (w
, area
);
22070 last_x
= area_left
+ window_box_width (w
, area
);
22074 /* Build a doubly-linked list of glyph_string structures between
22075 head and tail from what we have to draw. Note that the macro
22076 BUILD_GLYPH_STRINGS will modify its start parameter. That's
22077 the reason we use a separate variable `i'. */
22079 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
22081 x_reached
= tail
->x
+ tail
->background_width
;
22085 /* If there are any glyphs with lbearing < 0 or rbearing > width in
22086 the row, redraw some glyphs in front or following the glyph
22087 strings built above. */
22088 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
22090 struct glyph_string
*h
, *t
;
22091 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
22092 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
22093 int check_mouse_face
= 0;
22096 /* If mouse highlighting is on, we may need to draw adjacent
22097 glyphs using mouse-face highlighting. */
22098 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
22100 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
22102 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
22103 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
22105 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
22107 check_mouse_face
= 1;
22108 mouse_beg_col
= (row
== mouse_beg_row
)
22109 ? hlinfo
->mouse_face_beg_col
: 0;
22110 mouse_end_col
= (row
== mouse_end_row
)
22111 ? hlinfo
->mouse_face_end_col
22112 : row
->used
[TEXT_AREA
];
22116 /* Compute overhangs for all glyph strings. */
22117 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
22118 for (s
= head
; s
; s
= s
->next
)
22119 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
22121 /* Prepend glyph strings for glyphs in front of the first glyph
22122 string that are overwritten because of the first glyph
22123 string's left overhang. The background of all strings
22124 prepended must be drawn because the first glyph string
22126 i
= left_overwritten (head
);
22129 enum draw_glyphs_face overlap_hl
;
22131 /* If this row contains mouse highlighting, attempt to draw
22132 the overlapped glyphs with the correct highlight. This
22133 code fails if the overlap encompasses more than one glyph
22134 and mouse-highlight spans only some of these glyphs.
22135 However, making it work perfectly involves a lot more
22136 code, and I don't know if the pathological case occurs in
22137 practice, so we'll stick to this for now. --- cyd */
22138 if (check_mouse_face
22139 && mouse_beg_col
< start
&& mouse_end_col
> i
)
22140 overlap_hl
= DRAW_MOUSE_FACE
;
22142 overlap_hl
= DRAW_NORMAL_TEXT
;
22145 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
22146 overlap_hl
, dummy_x
, last_x
);
22148 compute_overhangs_and_x (t
, head
->x
, 1);
22149 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
22153 /* Prepend glyph strings for glyphs in front of the first glyph
22154 string that overwrite that glyph string because of their
22155 right overhang. For these strings, only the foreground must
22156 be drawn, because it draws over the glyph string at `head'.
22157 The background must not be drawn because this would overwrite
22158 right overhangs of preceding glyphs for which no glyph
22160 i
= left_overwriting (head
);
22163 enum draw_glyphs_face overlap_hl
;
22165 if (check_mouse_face
22166 && mouse_beg_col
< start
&& mouse_end_col
> i
)
22167 overlap_hl
= DRAW_MOUSE_FACE
;
22169 overlap_hl
= DRAW_NORMAL_TEXT
;
22172 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
22173 overlap_hl
, dummy_x
, last_x
);
22174 for (s
= h
; s
; s
= s
->next
)
22175 s
->background_filled_p
= 1;
22176 compute_overhangs_and_x (t
, head
->x
, 1);
22177 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
22180 /* Append glyphs strings for glyphs following the last glyph
22181 string tail that are overwritten by tail. The background of
22182 these strings has to be drawn because tail's foreground draws
22184 i
= right_overwritten (tail
);
22187 enum draw_glyphs_face overlap_hl
;
22189 if (check_mouse_face
22190 && mouse_beg_col
< i
&& mouse_end_col
> end
)
22191 overlap_hl
= DRAW_MOUSE_FACE
;
22193 overlap_hl
= DRAW_NORMAL_TEXT
;
22195 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
22196 overlap_hl
, x
, last_x
);
22197 /* Because BUILD_GLYPH_STRINGS updates the first argument,
22198 we don't have `end = i;' here. */
22199 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
22200 append_glyph_string_lists (&head
, &tail
, h
, t
);
22204 /* Append glyph strings for glyphs following the last glyph
22205 string tail that overwrite tail. The foreground of such
22206 glyphs has to be drawn because it writes into the background
22207 of tail. The background must not be drawn because it could
22208 paint over the foreground of following glyphs. */
22209 i
= right_overwriting (tail
);
22212 enum draw_glyphs_face overlap_hl
;
22213 if (check_mouse_face
22214 && mouse_beg_col
< i
&& mouse_end_col
> end
)
22215 overlap_hl
= DRAW_MOUSE_FACE
;
22217 overlap_hl
= DRAW_NORMAL_TEXT
;
22220 i
++; /* We must include the Ith glyph. */
22221 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
22222 overlap_hl
, x
, last_x
);
22223 for (s
= h
; s
; s
= s
->next
)
22224 s
->background_filled_p
= 1;
22225 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
22226 append_glyph_string_lists (&head
, &tail
, h
, t
);
22228 if (clip_head
|| clip_tail
)
22229 for (s
= head
; s
; s
= s
->next
)
22231 s
->clip_head
= clip_head
;
22232 s
->clip_tail
= clip_tail
;
22236 /* Draw all strings. */
22237 for (s
= head
; s
; s
= s
->next
)
22238 FRAME_RIF (f
)->draw_glyph_string (s
);
22241 /* When focus a sole frame and move horizontally, this sets on_p to 0
22242 causing a failure to erase prev cursor position. */
22243 if (area
== TEXT_AREA
22244 && !row
->full_width_p
22245 /* When drawing overlapping rows, only the glyph strings'
22246 foreground is drawn, which doesn't erase a cursor
22250 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
22251 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
22252 : (tail
? tail
->x
+ tail
->background_width
: x
));
22256 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
22257 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
22261 /* Value is the x-position up to which drawn, relative to AREA of W.
22262 This doesn't include parts drawn because of overhangs. */
22263 if (row
->full_width_p
)
22264 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
22266 x_reached
-= area_left
;
22268 RELEASE_HDC (hdc
, f
);
22273 /* Expand row matrix if too narrow. Don't expand if area
22276 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
22278 if (!fonts_changed_p \
22279 && (it->glyph_row->glyphs[area] \
22280 < it->glyph_row->glyphs[area + 1])) \
22282 it->w->ncols_scale_factor++; \
22283 fonts_changed_p = 1; \
22287 /* Store one glyph for IT->char_to_display in IT->glyph_row.
22288 Called from x_produce_glyphs when IT->glyph_row is non-null. */
22291 append_glyph (struct it
*it
)
22293 struct glyph
*glyph
;
22294 enum glyph_row_area area
= it
->area
;
22296 xassert (it
->glyph_row
);
22297 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
22299 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22300 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22302 /* If the glyph row is reversed, we need to prepend the glyph
22303 rather than append it. */
22304 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22308 /* Make room for the additional glyph. */
22309 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22311 glyph
= it
->glyph_row
->glyphs
[area
];
22313 glyph
->charpos
= CHARPOS (it
->position
);
22314 glyph
->object
= it
->object
;
22315 if (it
->pixel_width
> 0)
22317 glyph
->pixel_width
= it
->pixel_width
;
22318 glyph
->padding_p
= 0;
22322 /* Assure at least 1-pixel width. Otherwise, cursor can't
22323 be displayed correctly. */
22324 glyph
->pixel_width
= 1;
22325 glyph
->padding_p
= 1;
22327 glyph
->ascent
= it
->ascent
;
22328 glyph
->descent
= it
->descent
;
22329 glyph
->voffset
= it
->voffset
;
22330 glyph
->type
= CHAR_GLYPH
;
22331 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22332 glyph
->multibyte_p
= it
->multibyte_p
;
22333 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22334 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22335 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22336 || it
->phys_descent
> it
->descent
);
22337 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
22338 glyph
->face_id
= it
->face_id
;
22339 glyph
->u
.ch
= it
->char_to_display
;
22340 glyph
->slice
.img
= null_glyph_slice
;
22341 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22344 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22345 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22347 glyph
->bidi_type
= it
->bidi_it
.type
;
22351 glyph
->resolved_level
= 0;
22352 glyph
->bidi_type
= UNKNOWN_BT
;
22354 ++it
->glyph_row
->used
[area
];
22357 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22360 /* Store one glyph for the composition IT->cmp_it.id in
22361 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
22365 append_composite_glyph (struct it
*it
)
22367 struct glyph
*glyph
;
22368 enum glyph_row_area area
= it
->area
;
22370 xassert (it
->glyph_row
);
22372 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22373 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22375 /* If the glyph row is reversed, we need to prepend the glyph
22376 rather than append it. */
22377 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
22381 /* Make room for the new glyph. */
22382 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
22384 glyph
= it
->glyph_row
->glyphs
[it
->area
];
22386 glyph
->charpos
= it
->cmp_it
.charpos
;
22387 glyph
->object
= it
->object
;
22388 glyph
->pixel_width
= it
->pixel_width
;
22389 glyph
->ascent
= it
->ascent
;
22390 glyph
->descent
= it
->descent
;
22391 glyph
->voffset
= it
->voffset
;
22392 glyph
->type
= COMPOSITE_GLYPH
;
22393 if (it
->cmp_it
.ch
< 0)
22395 glyph
->u
.cmp
.automatic
= 0;
22396 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
22397 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
22401 glyph
->u
.cmp
.automatic
= 1;
22402 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
22403 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
22404 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
22406 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22407 glyph
->multibyte_p
= it
->multibyte_p
;
22408 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22409 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22410 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22411 || it
->phys_descent
> it
->descent
);
22412 glyph
->padding_p
= 0;
22413 glyph
->glyph_not_available_p
= 0;
22414 glyph
->face_id
= it
->face_id
;
22415 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22418 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22419 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22421 glyph
->bidi_type
= it
->bidi_it
.type
;
22423 ++it
->glyph_row
->used
[area
];
22426 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22430 /* Change IT->ascent and IT->height according to the setting of
22434 take_vertical_position_into_account (struct it
*it
)
22438 if (it
->voffset
< 0)
22439 /* Increase the ascent so that we can display the text higher
22441 it
->ascent
-= it
->voffset
;
22443 /* Increase the descent so that we can display the text lower
22445 it
->descent
+= it
->voffset
;
22450 /* Produce glyphs/get display metrics for the image IT is loaded with.
22451 See the description of struct display_iterator in dispextern.h for
22452 an overview of struct display_iterator. */
22455 produce_image_glyph (struct it
*it
)
22459 int glyph_ascent
, crop
;
22460 struct glyph_slice slice
;
22462 xassert (it
->what
== IT_IMAGE
);
22464 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22466 /* Make sure X resources of the face is loaded. */
22467 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22469 if (it
->image_id
< 0)
22471 /* Fringe bitmap. */
22472 it
->ascent
= it
->phys_ascent
= 0;
22473 it
->descent
= it
->phys_descent
= 0;
22474 it
->pixel_width
= 0;
22479 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
22481 /* Make sure X resources of the image is loaded. */
22482 prepare_image_for_display (it
->f
, img
);
22484 slice
.x
= slice
.y
= 0;
22485 slice
.width
= img
->width
;
22486 slice
.height
= img
->height
;
22488 if (INTEGERP (it
->slice
.x
))
22489 slice
.x
= XINT (it
->slice
.x
);
22490 else if (FLOATP (it
->slice
.x
))
22491 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
22493 if (INTEGERP (it
->slice
.y
))
22494 slice
.y
= XINT (it
->slice
.y
);
22495 else if (FLOATP (it
->slice
.y
))
22496 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
22498 if (INTEGERP (it
->slice
.width
))
22499 slice
.width
= XINT (it
->slice
.width
);
22500 else if (FLOATP (it
->slice
.width
))
22501 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
22503 if (INTEGERP (it
->slice
.height
))
22504 slice
.height
= XINT (it
->slice
.height
);
22505 else if (FLOATP (it
->slice
.height
))
22506 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
22508 if (slice
.x
>= img
->width
)
22509 slice
.x
= img
->width
;
22510 if (slice
.y
>= img
->height
)
22511 slice
.y
= img
->height
;
22512 if (slice
.x
+ slice
.width
>= img
->width
)
22513 slice
.width
= img
->width
- slice
.x
;
22514 if (slice
.y
+ slice
.height
> img
->height
)
22515 slice
.height
= img
->height
- slice
.y
;
22517 if (slice
.width
== 0 || slice
.height
== 0)
22520 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
22522 it
->descent
= slice
.height
- glyph_ascent
;
22524 it
->descent
+= img
->vmargin
;
22525 if (slice
.y
+ slice
.height
== img
->height
)
22526 it
->descent
+= img
->vmargin
;
22527 it
->phys_descent
= it
->descent
;
22529 it
->pixel_width
= slice
.width
;
22531 it
->pixel_width
+= img
->hmargin
;
22532 if (slice
.x
+ slice
.width
== img
->width
)
22533 it
->pixel_width
+= img
->hmargin
;
22535 /* It's quite possible for images to have an ascent greater than
22536 their height, so don't get confused in that case. */
22537 if (it
->descent
< 0)
22542 if (face
->box
!= FACE_NO_BOX
)
22544 if (face
->box_line_width
> 0)
22547 it
->ascent
+= face
->box_line_width
;
22548 if (slice
.y
+ slice
.height
== img
->height
)
22549 it
->descent
+= face
->box_line_width
;
22552 if (it
->start_of_box_run_p
&& slice
.x
== 0)
22553 it
->pixel_width
+= eabs (face
->box_line_width
);
22554 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
22555 it
->pixel_width
+= eabs (face
->box_line_width
);
22558 take_vertical_position_into_account (it
);
22560 /* Automatically crop wide image glyphs at right edge so we can
22561 draw the cursor on same display row. */
22562 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
22563 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
22565 it
->pixel_width
-= crop
;
22566 slice
.width
-= crop
;
22571 struct glyph
*glyph
;
22572 enum glyph_row_area area
= it
->area
;
22574 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22575 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22577 glyph
->charpos
= CHARPOS (it
->position
);
22578 glyph
->object
= it
->object
;
22579 glyph
->pixel_width
= it
->pixel_width
;
22580 glyph
->ascent
= glyph_ascent
;
22581 glyph
->descent
= it
->descent
;
22582 glyph
->voffset
= it
->voffset
;
22583 glyph
->type
= IMAGE_GLYPH
;
22584 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22585 glyph
->multibyte_p
= it
->multibyte_p
;
22586 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22587 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22588 glyph
->overlaps_vertically_p
= 0;
22589 glyph
->padding_p
= 0;
22590 glyph
->glyph_not_available_p
= 0;
22591 glyph
->face_id
= it
->face_id
;
22592 glyph
->u
.img_id
= img
->id
;
22593 glyph
->slice
.img
= slice
;
22594 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22597 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22598 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22600 glyph
->bidi_type
= it
->bidi_it
.type
;
22602 ++it
->glyph_row
->used
[area
];
22605 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22610 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
22611 of the glyph, WIDTH and HEIGHT are the width and height of the
22612 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
22615 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
22616 int width
, int height
, int ascent
)
22618 struct glyph
*glyph
;
22619 enum glyph_row_area area
= it
->area
;
22621 xassert (ascent
>= 0 && ascent
<= height
);
22623 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22624 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22626 /* If the glyph row is reversed, we need to prepend the glyph
22627 rather than append it. */
22628 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22632 /* Make room for the additional glyph. */
22633 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22635 glyph
= it
->glyph_row
->glyphs
[area
];
22637 glyph
->charpos
= CHARPOS (it
->position
);
22638 glyph
->object
= object
;
22639 glyph
->pixel_width
= width
;
22640 glyph
->ascent
= ascent
;
22641 glyph
->descent
= height
- ascent
;
22642 glyph
->voffset
= it
->voffset
;
22643 glyph
->type
= STRETCH_GLYPH
;
22644 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22645 glyph
->multibyte_p
= it
->multibyte_p
;
22646 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22647 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22648 glyph
->overlaps_vertically_p
= 0;
22649 glyph
->padding_p
= 0;
22650 glyph
->glyph_not_available_p
= 0;
22651 glyph
->face_id
= it
->face_id
;
22652 glyph
->u
.stretch
.ascent
= ascent
;
22653 glyph
->u
.stretch
.height
= height
;
22654 glyph
->slice
.img
= null_glyph_slice
;
22655 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22658 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22659 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22661 glyph
->bidi_type
= it
->bidi_it
.type
;
22665 glyph
->resolved_level
= 0;
22666 glyph
->bidi_type
= UNKNOWN_BT
;
22668 ++it
->glyph_row
->used
[area
];
22671 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22675 /* Produce a stretch glyph for iterator IT. IT->object is the value
22676 of the glyph property displayed. The value must be a list
22677 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
22680 1. `:width WIDTH' specifies that the space should be WIDTH *
22681 canonical char width wide. WIDTH may be an integer or floating
22684 2. `:relative-width FACTOR' specifies that the width of the stretch
22685 should be computed from the width of the first character having the
22686 `glyph' property, and should be FACTOR times that width.
22688 3. `:align-to HPOS' specifies that the space should be wide enough
22689 to reach HPOS, a value in canonical character units.
22691 Exactly one of the above pairs must be present.
22693 4. `:height HEIGHT' specifies that the height of the stretch produced
22694 should be HEIGHT, measured in canonical character units.
22696 5. `:relative-height FACTOR' specifies that the height of the
22697 stretch should be FACTOR times the height of the characters having
22698 the glyph property.
22700 Either none or exactly one of 4 or 5 must be present.
22702 6. `:ascent ASCENT' specifies that ASCENT percent of the height
22703 of the stretch should be used for the ascent of the stretch.
22704 ASCENT must be in the range 0 <= ASCENT <= 100. */
22707 produce_stretch_glyph (struct it
*it
)
22709 /* (space :width WIDTH :height HEIGHT ...) */
22710 Lisp_Object prop
, plist
;
22711 int width
= 0, height
= 0, align_to
= -1;
22712 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
22715 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22716 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22718 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22720 /* List should start with `space'. */
22721 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
22722 plist
= XCDR (it
->object
);
22724 /* Compute the width of the stretch. */
22725 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
22726 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
22728 /* Absolute width `:width WIDTH' specified and valid. */
22729 zero_width_ok_p
= 1;
22732 else if (prop
= Fplist_get (plist
, QCrelative_width
),
22735 /* Relative width `:relative-width FACTOR' specified and valid.
22736 Compute the width of the characters having the `glyph'
22739 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
22742 if (it
->multibyte_p
)
22743 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
22746 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
22747 if (! ASCII_CHAR_P (it2
.c
))
22748 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
22751 it2
.glyph_row
= NULL
;
22752 it2
.what
= IT_CHARACTER
;
22753 x_produce_glyphs (&it2
);
22754 width
= NUMVAL (prop
) * it2
.pixel_width
;
22756 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
22757 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
22759 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
22760 align_to
= (align_to
< 0
22762 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
22763 else if (align_to
< 0)
22764 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
22765 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
22766 zero_width_ok_p
= 1;
22769 /* Nothing specified -> width defaults to canonical char width. */
22770 width
= FRAME_COLUMN_WIDTH (it
->f
);
22772 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
22775 /* Compute height. */
22776 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
22777 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22780 zero_height_ok_p
= 1;
22782 else if (prop
= Fplist_get (plist
, QCrelative_height
),
22784 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
22786 height
= FONT_HEIGHT (font
);
22788 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
22791 /* Compute percentage of height used for ascent. If
22792 `:ascent ASCENT' is present and valid, use that. Otherwise,
22793 derive the ascent from the font in use. */
22794 if (prop
= Fplist_get (plist
, QCascent
),
22795 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
22796 ascent
= height
* NUMVAL (prop
) / 100.0;
22797 else if (!NILP (prop
)
22798 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22799 ascent
= min (max (0, (int)tem
), height
);
22801 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
22803 if (width
> 0 && it
->line_wrap
!= TRUNCATE
22804 && it
->current_x
+ width
> it
->last_visible_x
)
22805 width
= it
->last_visible_x
- it
->current_x
- 1;
22807 if (width
> 0 && height
> 0 && it
->glyph_row
)
22809 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
22810 if (!STRINGP (object
))
22811 object
= it
->w
->buffer
;
22812 append_stretch_glyph (it
, object
, width
, height
, ascent
);
22815 it
->pixel_width
= width
;
22816 it
->ascent
= it
->phys_ascent
= ascent
;
22817 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
22818 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
22820 take_vertical_position_into_account (it
);
22823 /* Calculate line-height and line-spacing properties.
22824 An integer value specifies explicit pixel value.
22825 A float value specifies relative value to current face height.
22826 A cons (float . face-name) specifies relative value to
22827 height of specified face font.
22829 Returns height in pixels, or nil. */
22833 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
22834 int boff
, int override
)
22836 Lisp_Object face_name
= Qnil
;
22837 int ascent
, descent
, height
;
22839 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
22844 face_name
= XCAR (val
);
22846 if (!NUMBERP (val
))
22847 val
= make_number (1);
22848 if (NILP (face_name
))
22850 height
= it
->ascent
+ it
->descent
;
22855 if (NILP (face_name
))
22857 font
= FRAME_FONT (it
->f
);
22858 boff
= FRAME_BASELINE_OFFSET (it
->f
);
22860 else if (EQ (face_name
, Qt
))
22869 face_id
= lookup_named_face (it
->f
, face_name
, 0);
22871 return make_number (-1);
22873 face
= FACE_FROM_ID (it
->f
, face_id
);
22876 return make_number (-1);
22877 boff
= font
->baseline_offset
;
22878 if (font
->vertical_centering
)
22879 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22882 ascent
= FONT_BASE (font
) + boff
;
22883 descent
= FONT_DESCENT (font
) - boff
;
22887 it
->override_ascent
= ascent
;
22888 it
->override_descent
= descent
;
22889 it
->override_boff
= boff
;
22892 height
= ascent
+ descent
;
22896 height
= (int)(XFLOAT_DATA (val
) * height
);
22897 else if (INTEGERP (val
))
22898 height
*= XINT (val
);
22900 return make_number (height
);
22904 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
22905 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
22906 and only if this is for a character for which no font was found.
22908 If the display method (it->glyphless_method) is
22909 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
22910 length of the acronym or the hexadecimal string, UPPER_XOFF and
22911 UPPER_YOFF are pixel offsets for the upper part of the string,
22912 LOWER_XOFF and LOWER_YOFF are for the lower part.
22914 For the other display methods, LEN through LOWER_YOFF are zero. */
22917 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
22918 short upper_xoff
, short upper_yoff
,
22919 short lower_xoff
, short lower_yoff
)
22921 struct glyph
*glyph
;
22922 enum glyph_row_area area
= it
->area
;
22924 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22925 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22927 /* If the glyph row is reversed, we need to prepend the glyph
22928 rather than append it. */
22929 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22933 /* Make room for the additional glyph. */
22934 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22936 glyph
= it
->glyph_row
->glyphs
[area
];
22938 glyph
->charpos
= CHARPOS (it
->position
);
22939 glyph
->object
= it
->object
;
22940 glyph
->pixel_width
= it
->pixel_width
;
22941 glyph
->ascent
= it
->ascent
;
22942 glyph
->descent
= it
->descent
;
22943 glyph
->voffset
= it
->voffset
;
22944 glyph
->type
= GLYPHLESS_GLYPH
;
22945 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
22946 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
22947 glyph
->u
.glyphless
.len
= len
;
22948 glyph
->u
.glyphless
.ch
= it
->c
;
22949 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
22950 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
22951 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
22952 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
22953 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22954 glyph
->multibyte_p
= it
->multibyte_p
;
22955 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22956 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22957 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22958 || it
->phys_descent
> it
->descent
);
22959 glyph
->padding_p
= 0;
22960 glyph
->glyph_not_available_p
= 0;
22961 glyph
->face_id
= face_id
;
22962 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22965 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22966 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22968 glyph
->bidi_type
= it
->bidi_it
.type
;
22970 ++it
->glyph_row
->used
[area
];
22973 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22977 /* Produce a glyph for a glyphless character for iterator IT.
22978 IT->glyphless_method specifies which method to use for displaying
22979 the character. See the description of enum
22980 glyphless_display_method in dispextern.h for the detail.
22982 FOR_NO_FONT is nonzero if and only if this is for a character for
22983 which no font was found. ACRONYM, if non-nil, is an acronym string
22984 for the character. */
22987 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
22992 int base_width
, base_height
, width
, height
;
22993 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
22996 /* Get the metrics of the base font. We always refer to the current
22998 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
22999 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23000 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
23001 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
23002 base_height
= it
->ascent
+ it
->descent
;
23003 base_width
= font
->average_width
;
23005 /* Get a face ID for the glyph by utilizing a cache (the same way as
23006 doen for `escape-glyph' in get_next_display_element). */
23007 if (it
->f
== last_glyphless_glyph_frame
23008 && it
->face_id
== last_glyphless_glyph_face_id
)
23010 face_id
= last_glyphless_glyph_merged_face_id
;
23014 /* Merge the `glyphless-char' face into the current face. */
23015 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
23016 last_glyphless_glyph_frame
= it
->f
;
23017 last_glyphless_glyph_face_id
= it
->face_id
;
23018 last_glyphless_glyph_merged_face_id
= face_id
;
23021 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
23023 it
->pixel_width
= THIN_SPACE_WIDTH
;
23025 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
23027 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
23029 width
= CHAR_WIDTH (it
->c
);
23032 else if (width
> 4)
23034 it
->pixel_width
= base_width
* width
;
23036 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
23042 unsigned int code
[6];
23044 int ascent
, descent
;
23045 struct font_metrics metrics_upper
, metrics_lower
;
23047 face
= FACE_FROM_ID (it
->f
, face_id
);
23048 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23049 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23051 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
23053 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
23054 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
23055 if (CONSP (acronym
))
23056 acronym
= XCAR (acronym
);
23057 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
23061 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
23062 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
23065 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
23066 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
23067 upper_len
= (len
+ 1) / 2;
23068 font
->driver
->text_extents (font
, code
, upper_len
,
23070 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
23075 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
23076 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
23077 upper_xoff
= upper_yoff
= 2; /* the typical case */
23078 if (base_width
>= width
)
23080 /* Align the upper to the left, the lower to the right. */
23081 it
->pixel_width
= base_width
;
23082 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
23086 /* Center the shorter one. */
23087 it
->pixel_width
= width
;
23088 if (metrics_upper
.width
>= metrics_lower
.width
)
23089 lower_xoff
= (width
- metrics_lower
.width
) / 2;
23092 /* FIXME: This code doesn't look right. It formerly was
23093 missing the "lower_xoff = 0;", which couldn't have
23094 been right since it left lower_xoff uninitialized. */
23096 upper_xoff
= (width
- metrics_upper
.width
) / 2;
23100 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
23101 top, bottom, and between upper and lower strings. */
23102 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
23103 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
23104 /* Center vertically.
23105 H:base_height, D:base_descent
23106 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
23108 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
23109 descent = D - H/2 + h/2;
23110 lower_yoff = descent - 2 - ld;
23111 upper_yoff = lower_yoff - la - 1 - ud; */
23112 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
23113 descent
= it
->descent
- (base_height
- height
) / 2;
23114 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
23115 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
23116 - metrics_upper
.descent
);
23117 /* Don't make the height shorter than the base height. */
23118 if (height
> base_height
)
23120 it
->ascent
= ascent
;
23121 it
->descent
= descent
;
23125 it
->phys_ascent
= it
->ascent
;
23126 it
->phys_descent
= it
->descent
;
23128 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
23129 upper_xoff
, upper_yoff
,
23130 lower_xoff
, lower_yoff
);
23132 take_vertical_position_into_account (it
);
23137 Produce glyphs/get display metrics for the display element IT is
23138 loaded with. See the description of struct it in dispextern.h
23139 for an overview of struct it. */
23142 x_produce_glyphs (struct it
*it
)
23144 int extra_line_spacing
= it
->extra_line_spacing
;
23146 it
->glyph_not_available_p
= 0;
23148 if (it
->what
== IT_CHARACTER
)
23151 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23152 struct font
*font
= face
->font
;
23153 struct font_metrics
*pcm
= NULL
;
23154 int boff
; /* baseline offset */
23158 /* When no suitable font is found, display this character by
23159 the method specified in the first extra slot of
23160 Vglyphless_char_display. */
23161 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
23163 xassert (it
->what
== IT_GLYPHLESS
);
23164 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
23168 boff
= font
->baseline_offset
;
23169 if (font
->vertical_centering
)
23170 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23172 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
23178 if (it
->override_ascent
>= 0)
23180 it
->ascent
= it
->override_ascent
;
23181 it
->descent
= it
->override_descent
;
23182 boff
= it
->override_boff
;
23186 it
->ascent
= FONT_BASE (font
) + boff
;
23187 it
->descent
= FONT_DESCENT (font
) - boff
;
23190 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
23192 pcm
= get_per_char_metric (font
, &char2b
);
23193 if (pcm
->width
== 0
23194 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
23200 it
->phys_ascent
= pcm
->ascent
+ boff
;
23201 it
->phys_descent
= pcm
->descent
- boff
;
23202 it
->pixel_width
= pcm
->width
;
23206 it
->glyph_not_available_p
= 1;
23207 it
->phys_ascent
= it
->ascent
;
23208 it
->phys_descent
= it
->descent
;
23209 it
->pixel_width
= font
->space_width
;
23212 if (it
->constrain_row_ascent_descent_p
)
23214 if (it
->descent
> it
->max_descent
)
23216 it
->ascent
+= it
->descent
- it
->max_descent
;
23217 it
->descent
= it
->max_descent
;
23219 if (it
->ascent
> it
->max_ascent
)
23221 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
23222 it
->ascent
= it
->max_ascent
;
23224 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
23225 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
23226 extra_line_spacing
= 0;
23229 /* If this is a space inside a region of text with
23230 `space-width' property, change its width. */
23231 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
23233 it
->pixel_width
*= XFLOATINT (it
->space_width
);
23235 /* If face has a box, add the box thickness to the character
23236 height. If character has a box line to the left and/or
23237 right, add the box line width to the character's width. */
23238 if (face
->box
!= FACE_NO_BOX
)
23240 int thick
= face
->box_line_width
;
23244 it
->ascent
+= thick
;
23245 it
->descent
+= thick
;
23250 if (it
->start_of_box_run_p
)
23251 it
->pixel_width
+= thick
;
23252 if (it
->end_of_box_run_p
)
23253 it
->pixel_width
+= thick
;
23256 /* If face has an overline, add the height of the overline
23257 (1 pixel) and a 1 pixel margin to the character height. */
23258 if (face
->overline_p
)
23259 it
->ascent
+= overline_margin
;
23261 if (it
->constrain_row_ascent_descent_p
)
23263 if (it
->ascent
> it
->max_ascent
)
23264 it
->ascent
= it
->max_ascent
;
23265 if (it
->descent
> it
->max_descent
)
23266 it
->descent
= it
->max_descent
;
23269 take_vertical_position_into_account (it
);
23271 /* If we have to actually produce glyphs, do it. */
23276 /* Translate a space with a `space-width' property
23277 into a stretch glyph. */
23278 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
23279 / FONT_HEIGHT (font
));
23280 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
23281 it
->ascent
+ it
->descent
, ascent
);
23286 /* If characters with lbearing or rbearing are displayed
23287 in this line, record that fact in a flag of the
23288 glyph row. This is used to optimize X output code. */
23289 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
23290 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23292 if (! stretched_p
&& it
->pixel_width
== 0)
23293 /* We assure that all visible glyphs have at least 1-pixel
23295 it
->pixel_width
= 1;
23297 else if (it
->char_to_display
== '\n')
23299 /* A newline has no width, but we need the height of the
23300 line. But if previous part of the line sets a height,
23301 don't increase that height */
23303 Lisp_Object height
;
23304 Lisp_Object total_height
= Qnil
;
23306 it
->override_ascent
= -1;
23307 it
->pixel_width
= 0;
23310 height
= get_it_property (it
, Qline_height
);
23311 /* Split (line-height total-height) list */
23313 && CONSP (XCDR (height
))
23314 && NILP (XCDR (XCDR (height
))))
23316 total_height
= XCAR (XCDR (height
));
23317 height
= XCAR (height
);
23319 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
23321 if (it
->override_ascent
>= 0)
23323 it
->ascent
= it
->override_ascent
;
23324 it
->descent
= it
->override_descent
;
23325 boff
= it
->override_boff
;
23329 it
->ascent
= FONT_BASE (font
) + boff
;
23330 it
->descent
= FONT_DESCENT (font
) - boff
;
23333 if (EQ (height
, Qt
))
23335 if (it
->descent
> it
->max_descent
)
23337 it
->ascent
+= it
->descent
- it
->max_descent
;
23338 it
->descent
= it
->max_descent
;
23340 if (it
->ascent
> it
->max_ascent
)
23342 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
23343 it
->ascent
= it
->max_ascent
;
23345 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
23346 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
23347 it
->constrain_row_ascent_descent_p
= 1;
23348 extra_line_spacing
= 0;
23352 Lisp_Object spacing
;
23354 it
->phys_ascent
= it
->ascent
;
23355 it
->phys_descent
= it
->descent
;
23357 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
23358 && face
->box
!= FACE_NO_BOX
23359 && face
->box_line_width
> 0)
23361 it
->ascent
+= face
->box_line_width
;
23362 it
->descent
+= face
->box_line_width
;
23365 && XINT (height
) > it
->ascent
+ it
->descent
)
23366 it
->ascent
= XINT (height
) - it
->descent
;
23368 if (!NILP (total_height
))
23369 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
23372 spacing
= get_it_property (it
, Qline_spacing
);
23373 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
23375 if (INTEGERP (spacing
))
23377 extra_line_spacing
= XINT (spacing
);
23378 if (!NILP (total_height
))
23379 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
23383 else /* i.e. (it->char_to_display == '\t') */
23385 if (font
->space_width
> 0)
23387 int tab_width
= it
->tab_width
* font
->space_width
;
23388 int x
= it
->current_x
+ it
->continuation_lines_width
;
23389 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
23391 /* If the distance from the current position to the next tab
23392 stop is less than a space character width, use the
23393 tab stop after that. */
23394 if (next_tab_x
- x
< font
->space_width
)
23395 next_tab_x
+= tab_width
;
23397 it
->pixel_width
= next_tab_x
- x
;
23399 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
23400 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
23404 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
23405 it
->ascent
+ it
->descent
, it
->ascent
);
23410 it
->pixel_width
= 0;
23415 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
23417 /* A static composition.
23419 Note: A composition is represented as one glyph in the
23420 glyph matrix. There are no padding glyphs.
23422 Important note: pixel_width, ascent, and descent are the
23423 values of what is drawn by draw_glyphs (i.e. the values of
23424 the overall glyphs composed). */
23425 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23426 int boff
; /* baseline offset */
23427 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
23428 int glyph_len
= cmp
->glyph_len
;
23429 struct font
*font
= face
->font
;
23433 /* If we have not yet calculated pixel size data of glyphs of
23434 the composition for the current face font, calculate them
23435 now. Theoretically, we have to check all fonts for the
23436 glyphs, but that requires much time and memory space. So,
23437 here we check only the font of the first glyph. This may
23438 lead to incorrect display, but it's very rare, and C-l
23439 (recenter-top-bottom) can correct the display anyway. */
23440 if (! cmp
->font
|| cmp
->font
!= font
)
23442 /* Ascent and descent of the font of the first character
23443 of this composition (adjusted by baseline offset).
23444 Ascent and descent of overall glyphs should not be less
23445 than these, respectively. */
23446 int font_ascent
, font_descent
, font_height
;
23447 /* Bounding box of the overall glyphs. */
23448 int leftmost
, rightmost
, lowest
, highest
;
23449 int lbearing
, rbearing
;
23450 int i
, width
, ascent
, descent
;
23451 int left_padded
= 0, right_padded
= 0;
23452 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
23454 struct font_metrics
*pcm
;
23455 int font_not_found_p
;
23458 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
23459 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
23461 if (glyph_len
< cmp
->glyph_len
)
23463 for (i
= 0; i
< glyph_len
; i
++)
23465 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
23467 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
23472 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
23473 : IT_CHARPOS (*it
));
23474 /* If no suitable font is found, use the default font. */
23475 font_not_found_p
= font
== NULL
;
23476 if (font_not_found_p
)
23478 face
= face
->ascii_face
;
23481 boff
= font
->baseline_offset
;
23482 if (font
->vertical_centering
)
23483 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23484 font_ascent
= FONT_BASE (font
) + boff
;
23485 font_descent
= FONT_DESCENT (font
) - boff
;
23486 font_height
= FONT_HEIGHT (font
);
23488 cmp
->font
= (void *) font
;
23491 if (! font_not_found_p
)
23493 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
23495 pcm
= get_per_char_metric (font
, &char2b
);
23498 /* Initialize the bounding box. */
23501 width
= pcm
->width
;
23502 ascent
= pcm
->ascent
;
23503 descent
= pcm
->descent
;
23504 lbearing
= pcm
->lbearing
;
23505 rbearing
= pcm
->rbearing
;
23509 width
= font
->space_width
;
23510 ascent
= FONT_BASE (font
);
23511 descent
= FONT_DESCENT (font
);
23518 lowest
= - descent
+ boff
;
23519 highest
= ascent
+ boff
;
23521 if (! font_not_found_p
23522 && font
->default_ascent
23523 && CHAR_TABLE_P (Vuse_default_ascent
)
23524 && !NILP (Faref (Vuse_default_ascent
,
23525 make_number (it
->char_to_display
))))
23526 highest
= font
->default_ascent
+ boff
;
23528 /* Draw the first glyph at the normal position. It may be
23529 shifted to right later if some other glyphs are drawn
23531 cmp
->offsets
[i
* 2] = 0;
23532 cmp
->offsets
[i
* 2 + 1] = boff
;
23533 cmp
->lbearing
= lbearing
;
23534 cmp
->rbearing
= rbearing
;
23536 /* Set cmp->offsets for the remaining glyphs. */
23537 for (i
++; i
< glyph_len
; i
++)
23539 int left
, right
, btm
, top
;
23540 int ch
= COMPOSITION_GLYPH (cmp
, i
);
23542 struct face
*this_face
;
23546 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
23547 this_face
= FACE_FROM_ID (it
->f
, face_id
);
23548 font
= this_face
->font
;
23554 get_char_face_and_encoding (it
->f
, ch
, face_id
,
23556 pcm
= get_per_char_metric (font
, &char2b
);
23559 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
23562 width
= pcm
->width
;
23563 ascent
= pcm
->ascent
;
23564 descent
= pcm
->descent
;
23565 lbearing
= pcm
->lbearing
;
23566 rbearing
= pcm
->rbearing
;
23567 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
23569 /* Relative composition with or without
23570 alternate chars. */
23571 left
= (leftmost
+ rightmost
- width
) / 2;
23572 btm
= - descent
+ boff
;
23573 if (font
->relative_compose
23574 && (! CHAR_TABLE_P (Vignore_relative_composition
)
23575 || NILP (Faref (Vignore_relative_composition
,
23576 make_number (ch
)))))
23579 if (- descent
>= font
->relative_compose
)
23580 /* One extra pixel between two glyphs. */
23582 else if (ascent
<= 0)
23583 /* One extra pixel between two glyphs. */
23584 btm
= lowest
- 1 - ascent
- descent
;
23589 /* A composition rule is specified by an integer
23590 value that encodes global and new reference
23591 points (GREF and NREF). GREF and NREF are
23592 specified by numbers as below:
23594 0---1---2 -- ascent
23598 9--10--11 -- center
23600 ---3---4---5--- baseline
23602 6---7---8 -- descent
23604 int rule
= COMPOSITION_RULE (cmp
, i
);
23605 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
23607 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
23608 grefx
= gref
% 3, nrefx
= nref
% 3;
23609 grefy
= gref
/ 3, nrefy
= nref
/ 3;
23611 xoff
= font_height
* (xoff
- 128) / 256;
23613 yoff
= font_height
* (yoff
- 128) / 256;
23616 + grefx
* (rightmost
- leftmost
) / 2
23617 - nrefx
* width
/ 2
23620 btm
= ((grefy
== 0 ? highest
23622 : grefy
== 2 ? lowest
23623 : (highest
+ lowest
) / 2)
23624 - (nrefy
== 0 ? ascent
+ descent
23625 : nrefy
== 1 ? descent
- boff
23627 : (ascent
+ descent
) / 2)
23631 cmp
->offsets
[i
* 2] = left
;
23632 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
23634 /* Update the bounding box of the overall glyphs. */
23637 right
= left
+ width
;
23638 if (left
< leftmost
)
23640 if (right
> rightmost
)
23643 top
= btm
+ descent
+ ascent
;
23649 if (cmp
->lbearing
> left
+ lbearing
)
23650 cmp
->lbearing
= left
+ lbearing
;
23651 if (cmp
->rbearing
< left
+ rbearing
)
23652 cmp
->rbearing
= left
+ rbearing
;
23656 /* If there are glyphs whose x-offsets are negative,
23657 shift all glyphs to the right and make all x-offsets
23661 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23662 cmp
->offsets
[i
* 2] -= leftmost
;
23663 rightmost
-= leftmost
;
23664 cmp
->lbearing
-= leftmost
;
23665 cmp
->rbearing
-= leftmost
;
23668 if (left_padded
&& cmp
->lbearing
< 0)
23670 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23671 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
23672 rightmost
-= cmp
->lbearing
;
23673 cmp
->rbearing
-= cmp
->lbearing
;
23676 if (right_padded
&& rightmost
< cmp
->rbearing
)
23678 rightmost
= cmp
->rbearing
;
23681 cmp
->pixel_width
= rightmost
;
23682 cmp
->ascent
= highest
;
23683 cmp
->descent
= - lowest
;
23684 if (cmp
->ascent
< font_ascent
)
23685 cmp
->ascent
= font_ascent
;
23686 if (cmp
->descent
< font_descent
)
23687 cmp
->descent
= font_descent
;
23691 && (cmp
->lbearing
< 0
23692 || cmp
->rbearing
> cmp
->pixel_width
))
23693 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23695 it
->pixel_width
= cmp
->pixel_width
;
23696 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
23697 it
->descent
= it
->phys_descent
= cmp
->descent
;
23698 if (face
->box
!= FACE_NO_BOX
)
23700 int thick
= face
->box_line_width
;
23704 it
->ascent
+= thick
;
23705 it
->descent
+= thick
;
23710 if (it
->start_of_box_run_p
)
23711 it
->pixel_width
+= thick
;
23712 if (it
->end_of_box_run_p
)
23713 it
->pixel_width
+= thick
;
23716 /* If face has an overline, add the height of the overline
23717 (1 pixel) and a 1 pixel margin to the character height. */
23718 if (face
->overline_p
)
23719 it
->ascent
+= overline_margin
;
23721 take_vertical_position_into_account (it
);
23722 if (it
->ascent
< 0)
23724 if (it
->descent
< 0)
23728 append_composite_glyph (it
);
23730 else if (it
->what
== IT_COMPOSITION
)
23732 /* A dynamic (automatic) composition. */
23733 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23734 Lisp_Object gstring
;
23735 struct font_metrics metrics
;
23737 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
23739 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
23742 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
23743 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23744 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
23745 it
->descent
= it
->phys_descent
= metrics
.descent
;
23746 if (face
->box
!= FACE_NO_BOX
)
23748 int thick
= face
->box_line_width
;
23752 it
->ascent
+= thick
;
23753 it
->descent
+= thick
;
23758 if (it
->start_of_box_run_p
)
23759 it
->pixel_width
+= thick
;
23760 if (it
->end_of_box_run_p
)
23761 it
->pixel_width
+= thick
;
23763 /* If face has an overline, add the height of the overline
23764 (1 pixel) and a 1 pixel margin to the character height. */
23765 if (face
->overline_p
)
23766 it
->ascent
+= overline_margin
;
23767 take_vertical_position_into_account (it
);
23768 if (it
->ascent
< 0)
23770 if (it
->descent
< 0)
23774 append_composite_glyph (it
);
23776 else if (it
->what
== IT_GLYPHLESS
)
23777 produce_glyphless_glyph (it
, 0, Qnil
);
23778 else if (it
->what
== IT_IMAGE
)
23779 produce_image_glyph (it
);
23780 else if (it
->what
== IT_STRETCH
)
23781 produce_stretch_glyph (it
);
23784 /* Accumulate dimensions. Note: can't assume that it->descent > 0
23785 because this isn't true for images with `:ascent 100'. */
23786 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
23787 if (it
->area
== TEXT_AREA
)
23788 it
->current_x
+= it
->pixel_width
;
23790 if (extra_line_spacing
> 0)
23792 it
->descent
+= extra_line_spacing
;
23793 if (extra_line_spacing
> it
->max_extra_line_spacing
)
23794 it
->max_extra_line_spacing
= extra_line_spacing
;
23797 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
23798 it
->max_descent
= max (it
->max_descent
, it
->descent
);
23799 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
23800 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
23804 Output LEN glyphs starting at START at the nominal cursor position.
23805 Advance the nominal cursor over the text. The global variable
23806 updated_window contains the window being updated, updated_row is
23807 the glyph row being updated, and updated_area is the area of that
23808 row being updated. */
23811 x_write_glyphs (struct glyph
*start
, int len
)
23815 xassert (updated_window
&& updated_row
);
23818 /* Write glyphs. */
23820 hpos
= start
- updated_row
->glyphs
[updated_area
];
23821 x
= draw_glyphs (updated_window
, output_cursor
.x
,
23822 updated_row
, updated_area
,
23824 DRAW_NORMAL_TEXT
, 0);
23826 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
23827 if (updated_area
== TEXT_AREA
23828 && updated_window
->phys_cursor_on_p
23829 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
23830 && updated_window
->phys_cursor
.hpos
>= hpos
23831 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
23832 updated_window
->phys_cursor_on_p
= 0;
23836 /* Advance the output cursor. */
23837 output_cursor
.hpos
+= len
;
23838 output_cursor
.x
= x
;
23843 Insert LEN glyphs from START at the nominal cursor position. */
23846 x_insert_glyphs (struct glyph
*start
, int len
)
23850 int line_height
, shift_by_width
, shifted_region_width
;
23851 struct glyph_row
*row
;
23852 struct glyph
*glyph
;
23853 int frame_x
, frame_y
;
23856 xassert (updated_window
&& updated_row
);
23858 w
= updated_window
;
23859 f
= XFRAME (WINDOW_FRAME (w
));
23861 /* Get the height of the line we are in. */
23863 line_height
= row
->height
;
23865 /* Get the width of the glyphs to insert. */
23866 shift_by_width
= 0;
23867 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
23868 shift_by_width
+= glyph
->pixel_width
;
23870 /* Get the width of the region to shift right. */
23871 shifted_region_width
= (window_box_width (w
, updated_area
)
23876 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
23877 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
23879 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
23880 line_height
, shift_by_width
);
23882 /* Write the glyphs. */
23883 hpos
= start
- row
->glyphs
[updated_area
];
23884 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
23886 DRAW_NORMAL_TEXT
, 0);
23888 /* Advance the output cursor. */
23889 output_cursor
.hpos
+= len
;
23890 output_cursor
.x
+= shift_by_width
;
23896 Erase the current text line from the nominal cursor position
23897 (inclusive) to pixel column TO_X (exclusive). The idea is that
23898 everything from TO_X onward is already erased.
23900 TO_X is a pixel position relative to updated_area of
23901 updated_window. TO_X == -1 means clear to the end of this area. */
23904 x_clear_end_of_line (int to_x
)
23907 struct window
*w
= updated_window
;
23908 int max_x
, min_y
, max_y
;
23909 int from_x
, from_y
, to_y
;
23911 xassert (updated_window
&& updated_row
);
23912 f
= XFRAME (w
->frame
);
23914 if (updated_row
->full_width_p
)
23915 max_x
= WINDOW_TOTAL_WIDTH (w
);
23917 max_x
= window_box_width (w
, updated_area
);
23918 max_y
= window_text_bottom_y (w
);
23920 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
23921 of window. For TO_X > 0, truncate to end of drawing area. */
23927 to_x
= min (to_x
, max_x
);
23929 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
23931 /* Notice if the cursor will be cleared by this operation. */
23932 if (!updated_row
->full_width_p
)
23933 notice_overwritten_cursor (w
, updated_area
,
23934 output_cursor
.x
, -1,
23936 MATRIX_ROW_BOTTOM_Y (updated_row
));
23938 from_x
= output_cursor
.x
;
23940 /* Translate to frame coordinates. */
23941 if (updated_row
->full_width_p
)
23943 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
23944 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
23948 int area_left
= window_box_left (w
, updated_area
);
23949 from_x
+= area_left
;
23953 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
23954 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
23955 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
23957 /* Prevent inadvertently clearing to end of the X window. */
23958 if (to_x
> from_x
&& to_y
> from_y
)
23961 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
23962 to_x
- from_x
, to_y
- from_y
);
23967 #endif /* HAVE_WINDOW_SYSTEM */
23971 /***********************************************************************
23973 ***********************************************************************/
23975 /* Value is the internal representation of the specified cursor type
23976 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
23977 of the bar cursor. */
23979 static enum text_cursor_kinds
23980 get_specified_cursor_type (Lisp_Object arg
, int *width
)
23982 enum text_cursor_kinds type
;
23987 if (EQ (arg
, Qbox
))
23988 return FILLED_BOX_CURSOR
;
23990 if (EQ (arg
, Qhollow
))
23991 return HOLLOW_BOX_CURSOR
;
23993 if (EQ (arg
, Qbar
))
24000 && EQ (XCAR (arg
), Qbar
)
24001 && INTEGERP (XCDR (arg
))
24002 && XINT (XCDR (arg
)) >= 0)
24004 *width
= XINT (XCDR (arg
));
24008 if (EQ (arg
, Qhbar
))
24011 return HBAR_CURSOR
;
24015 && EQ (XCAR (arg
), Qhbar
)
24016 && INTEGERP (XCDR (arg
))
24017 && XINT (XCDR (arg
)) >= 0)
24019 *width
= XINT (XCDR (arg
));
24020 return HBAR_CURSOR
;
24023 /* Treat anything unknown as "hollow box cursor".
24024 It was bad to signal an error; people have trouble fixing
24025 .Xdefaults with Emacs, when it has something bad in it. */
24026 type
= HOLLOW_BOX_CURSOR
;
24031 /* Set the default cursor types for specified frame. */
24033 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
24038 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
24039 FRAME_CURSOR_WIDTH (f
) = width
;
24041 /* By default, set up the blink-off state depending on the on-state. */
24043 tem
= Fassoc (arg
, Vblink_cursor_alist
);
24046 FRAME_BLINK_OFF_CURSOR (f
)
24047 = get_specified_cursor_type (XCDR (tem
), &width
);
24048 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
24051 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
24055 #ifdef HAVE_WINDOW_SYSTEM
24057 /* Return the cursor we want to be displayed in window W. Return
24058 width of bar/hbar cursor through WIDTH arg. Return with
24059 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
24060 (i.e. if the `system caret' should track this cursor).
24062 In a mini-buffer window, we want the cursor only to appear if we
24063 are reading input from this window. For the selected window, we
24064 want the cursor type given by the frame parameter or buffer local
24065 setting of cursor-type. If explicitly marked off, draw no cursor.
24066 In all other cases, we want a hollow box cursor. */
24068 static enum text_cursor_kinds
24069 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
24070 int *active_cursor
)
24072 struct frame
*f
= XFRAME (w
->frame
);
24073 struct buffer
*b
= XBUFFER (w
->buffer
);
24074 int cursor_type
= DEFAULT_CURSOR
;
24075 Lisp_Object alt_cursor
;
24076 int non_selected
= 0;
24078 *active_cursor
= 1;
24081 if (cursor_in_echo_area
24082 && FRAME_HAS_MINIBUF_P (f
)
24083 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
24085 if (w
== XWINDOW (echo_area_window
))
24087 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
24089 *width
= FRAME_CURSOR_WIDTH (f
);
24090 return FRAME_DESIRED_CURSOR (f
);
24093 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
24096 *active_cursor
= 0;
24100 /* Detect a nonselected window or nonselected frame. */
24101 else if (w
!= XWINDOW (f
->selected_window
)
24102 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
24104 *active_cursor
= 0;
24106 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
24112 /* Never display a cursor in a window in which cursor-type is nil. */
24113 if (NILP (BVAR (b
, cursor_type
)))
24116 /* Get the normal cursor type for this window. */
24117 if (EQ (BVAR (b
, cursor_type
), Qt
))
24119 cursor_type
= FRAME_DESIRED_CURSOR (f
);
24120 *width
= FRAME_CURSOR_WIDTH (f
);
24123 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
24125 /* Use cursor-in-non-selected-windows instead
24126 for non-selected window or frame. */
24129 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
24130 if (!EQ (Qt
, alt_cursor
))
24131 return get_specified_cursor_type (alt_cursor
, width
);
24132 /* t means modify the normal cursor type. */
24133 if (cursor_type
== FILLED_BOX_CURSOR
)
24134 cursor_type
= HOLLOW_BOX_CURSOR
;
24135 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
24137 return cursor_type
;
24140 /* Use normal cursor if not blinked off. */
24141 if (!w
->cursor_off_p
)
24143 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
24145 if (cursor_type
== FILLED_BOX_CURSOR
)
24147 /* Using a block cursor on large images can be very annoying.
24148 So use a hollow cursor for "large" images.
24149 If image is not transparent (no mask), also use hollow cursor. */
24150 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
24151 if (img
!= NULL
&& IMAGEP (img
->spec
))
24153 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
24154 where N = size of default frame font size.
24155 This should cover most of the "tiny" icons people may use. */
24157 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
24158 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
24159 cursor_type
= HOLLOW_BOX_CURSOR
;
24162 else if (cursor_type
!= NO_CURSOR
)
24164 /* Display current only supports BOX and HOLLOW cursors for images.
24165 So for now, unconditionally use a HOLLOW cursor when cursor is
24166 not a solid box cursor. */
24167 cursor_type
= HOLLOW_BOX_CURSOR
;
24170 return cursor_type
;
24173 /* Cursor is blinked off, so determine how to "toggle" it. */
24175 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
24176 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
24177 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
24179 /* Then see if frame has specified a specific blink off cursor type. */
24180 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
24182 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
24183 return FRAME_BLINK_OFF_CURSOR (f
);
24187 /* Some people liked having a permanently visible blinking cursor,
24188 while others had very strong opinions against it. So it was
24189 decided to remove it. KFS 2003-09-03 */
24191 /* Finally perform built-in cursor blinking:
24192 filled box <-> hollow box
24193 wide [h]bar <-> narrow [h]bar
24194 narrow [h]bar <-> no cursor
24195 other type <-> no cursor */
24197 if (cursor_type
== FILLED_BOX_CURSOR
)
24198 return HOLLOW_BOX_CURSOR
;
24200 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
24203 return cursor_type
;
24211 /* Notice when the text cursor of window W has been completely
24212 overwritten by a drawing operation that outputs glyphs in AREA
24213 starting at X0 and ending at X1 in the line starting at Y0 and
24214 ending at Y1. X coordinates are area-relative. X1 < 0 means all
24215 the rest of the line after X0 has been written. Y coordinates
24216 are window-relative. */
24219 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
24220 int x0
, int x1
, int y0
, int y1
)
24222 int cx0
, cx1
, cy0
, cy1
;
24223 struct glyph_row
*row
;
24225 if (!w
->phys_cursor_on_p
)
24227 if (area
!= TEXT_AREA
)
24230 if (w
->phys_cursor
.vpos
< 0
24231 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
24232 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
24233 !(row
->enabled_p
&& row
->displays_text_p
)))
24236 if (row
->cursor_in_fringe_p
)
24238 row
->cursor_in_fringe_p
= 0;
24239 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
24240 w
->phys_cursor_on_p
= 0;
24244 cx0
= w
->phys_cursor
.x
;
24245 cx1
= cx0
+ w
->phys_cursor_width
;
24246 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
24249 /* The cursor image will be completely removed from the
24250 screen if the output area intersects the cursor area in
24251 y-direction. When we draw in [y0 y1[, and some part of
24252 the cursor is at y < y0, that part must have been drawn
24253 before. When scrolling, the cursor is erased before
24254 actually scrolling, so we don't come here. When not
24255 scrolling, the rows above the old cursor row must have
24256 changed, and in this case these rows must have written
24257 over the cursor image.
24259 Likewise if part of the cursor is below y1, with the
24260 exception of the cursor being in the first blank row at
24261 the buffer and window end because update_text_area
24262 doesn't draw that row. (Except when it does, but
24263 that's handled in update_text_area.) */
24265 cy0
= w
->phys_cursor
.y
;
24266 cy1
= cy0
+ w
->phys_cursor_height
;
24267 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
24270 w
->phys_cursor_on_p
= 0;
24273 #endif /* HAVE_WINDOW_SYSTEM */
24276 /************************************************************************
24278 ************************************************************************/
24280 #ifdef HAVE_WINDOW_SYSTEM
24283 Fix the display of area AREA of overlapping row ROW in window W
24284 with respect to the overlapping part OVERLAPS. */
24287 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
24288 enum glyph_row_area area
, int overlaps
)
24295 for (i
= 0; i
< row
->used
[area
];)
24297 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
24299 int start
= i
, start_x
= x
;
24303 x
+= row
->glyphs
[area
][i
].pixel_width
;
24306 while (i
< row
->used
[area
]
24307 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
24309 draw_glyphs (w
, start_x
, row
, area
,
24311 DRAW_NORMAL_TEXT
, overlaps
);
24315 x
+= row
->glyphs
[area
][i
].pixel_width
;
24325 Draw the cursor glyph of window W in glyph row ROW. See the
24326 comment of draw_glyphs for the meaning of HL. */
24329 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
24330 enum draw_glyphs_face hl
)
24332 /* If cursor hpos is out of bounds, don't draw garbage. This can
24333 happen in mini-buffer windows when switching between echo area
24334 glyphs and mini-buffer. */
24335 if ((row
->reversed_p
24336 ? (w
->phys_cursor
.hpos
>= 0)
24337 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
24339 int on_p
= w
->phys_cursor_on_p
;
24341 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
24342 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
24344 w
->phys_cursor_on_p
= on_p
;
24346 if (hl
== DRAW_CURSOR
)
24347 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
24348 /* When we erase the cursor, and ROW is overlapped by other
24349 rows, make sure that these overlapping parts of other rows
24351 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
24353 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
24355 if (row
> w
->current_matrix
->rows
24356 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
24357 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
24358 OVERLAPS_ERASED_CURSOR
);
24360 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
24361 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
24362 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
24363 OVERLAPS_ERASED_CURSOR
);
24370 Erase the image of a cursor of window W from the screen. */
24373 erase_phys_cursor (struct window
*w
)
24375 struct frame
*f
= XFRAME (w
->frame
);
24376 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
24377 int hpos
= w
->phys_cursor
.hpos
;
24378 int vpos
= w
->phys_cursor
.vpos
;
24379 int mouse_face_here_p
= 0;
24380 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
24381 struct glyph_row
*cursor_row
;
24382 struct glyph
*cursor_glyph
;
24383 enum draw_glyphs_face hl
;
24385 /* No cursor displayed or row invalidated => nothing to do on the
24387 if (w
->phys_cursor_type
== NO_CURSOR
)
24388 goto mark_cursor_off
;
24390 /* VPOS >= active_glyphs->nrows means that window has been resized.
24391 Don't bother to erase the cursor. */
24392 if (vpos
>= active_glyphs
->nrows
)
24393 goto mark_cursor_off
;
24395 /* If row containing cursor is marked invalid, there is nothing we
24397 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
24398 if (!cursor_row
->enabled_p
)
24399 goto mark_cursor_off
;
24401 /* If line spacing is > 0, old cursor may only be partially visible in
24402 window after split-window. So adjust visible height. */
24403 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
24404 window_text_bottom_y (w
) - cursor_row
->y
);
24406 /* If row is completely invisible, don't attempt to delete a cursor which
24407 isn't there. This can happen if cursor is at top of a window, and
24408 we switch to a buffer with a header line in that window. */
24409 if (cursor_row
->visible_height
<= 0)
24410 goto mark_cursor_off
;
24412 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
24413 if (cursor_row
->cursor_in_fringe_p
)
24415 cursor_row
->cursor_in_fringe_p
= 0;
24416 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
24417 goto mark_cursor_off
;
24420 /* This can happen when the new row is shorter than the old one.
24421 In this case, either draw_glyphs or clear_end_of_line
24422 should have cleared the cursor. Note that we wouldn't be
24423 able to erase the cursor in this case because we don't have a
24424 cursor glyph at hand. */
24425 if ((cursor_row
->reversed_p
24426 ? (w
->phys_cursor
.hpos
< 0)
24427 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
24428 goto mark_cursor_off
;
24430 /* If the cursor is in the mouse face area, redisplay that when
24431 we clear the cursor. */
24432 if (! NILP (hlinfo
->mouse_face_window
)
24433 && coords_in_mouse_face_p (w
, hpos
, vpos
)
24434 /* Don't redraw the cursor's spot in mouse face if it is at the
24435 end of a line (on a newline). The cursor appears there, but
24436 mouse highlighting does not. */
24437 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
24438 mouse_face_here_p
= 1;
24440 /* Maybe clear the display under the cursor. */
24441 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
24444 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
24447 cursor_glyph
= get_phys_cursor_glyph (w
);
24448 if (cursor_glyph
== NULL
)
24449 goto mark_cursor_off
;
24451 width
= cursor_glyph
->pixel_width
;
24452 left_x
= window_box_left_offset (w
, TEXT_AREA
);
24453 x
= w
->phys_cursor
.x
;
24455 width
-= left_x
- x
;
24456 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
24457 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
24458 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
24461 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
24464 /* Erase the cursor by redrawing the character underneath it. */
24465 if (mouse_face_here_p
)
24466 hl
= DRAW_MOUSE_FACE
;
24468 hl
= DRAW_NORMAL_TEXT
;
24469 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
24472 w
->phys_cursor_on_p
= 0;
24473 w
->phys_cursor_type
= NO_CURSOR
;
24478 Display or clear cursor of window W. If ON is zero, clear the
24479 cursor. If it is non-zero, display the cursor. If ON is nonzero,
24480 where to put the cursor is specified by HPOS, VPOS, X and Y. */
24483 display_and_set_cursor (struct window
*w
, int on
,
24484 int hpos
, int vpos
, int x
, int y
)
24486 struct frame
*f
= XFRAME (w
->frame
);
24487 int new_cursor_type
;
24488 int new_cursor_width
;
24490 struct glyph_row
*glyph_row
;
24491 struct glyph
*glyph
;
24493 /* This is pointless on invisible frames, and dangerous on garbaged
24494 windows and frames; in the latter case, the frame or window may
24495 be in the midst of changing its size, and x and y may be off the
24497 if (! FRAME_VISIBLE_P (f
)
24498 || FRAME_GARBAGED_P (f
)
24499 || vpos
>= w
->current_matrix
->nrows
24500 || hpos
>= w
->current_matrix
->matrix_w
)
24503 /* If cursor is off and we want it off, return quickly. */
24504 if (!on
&& !w
->phys_cursor_on_p
)
24507 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
24508 /* If cursor row is not enabled, we don't really know where to
24509 display the cursor. */
24510 if (!glyph_row
->enabled_p
)
24512 w
->phys_cursor_on_p
= 0;
24517 if (!glyph_row
->exact_window_width_line_p
24518 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
24519 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
24521 xassert (interrupt_input_blocked
);
24523 /* Set new_cursor_type to the cursor we want to be displayed. */
24524 new_cursor_type
= get_window_cursor_type (w
, glyph
,
24525 &new_cursor_width
, &active_cursor
);
24527 /* If cursor is currently being shown and we don't want it to be or
24528 it is in the wrong place, or the cursor type is not what we want,
24530 if (w
->phys_cursor_on_p
24532 || w
->phys_cursor
.x
!= x
24533 || w
->phys_cursor
.y
!= y
24534 || new_cursor_type
!= w
->phys_cursor_type
24535 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
24536 && new_cursor_width
!= w
->phys_cursor_width
)))
24537 erase_phys_cursor (w
);
24539 /* Don't check phys_cursor_on_p here because that flag is only set
24540 to zero in some cases where we know that the cursor has been
24541 completely erased, to avoid the extra work of erasing the cursor
24542 twice. In other words, phys_cursor_on_p can be 1 and the cursor
24543 still not be visible, or it has only been partly erased. */
24546 w
->phys_cursor_ascent
= glyph_row
->ascent
;
24547 w
->phys_cursor_height
= glyph_row
->height
;
24549 /* Set phys_cursor_.* before x_draw_.* is called because some
24550 of them may need the information. */
24551 w
->phys_cursor
.x
= x
;
24552 w
->phys_cursor
.y
= glyph_row
->y
;
24553 w
->phys_cursor
.hpos
= hpos
;
24554 w
->phys_cursor
.vpos
= vpos
;
24557 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
24558 new_cursor_type
, new_cursor_width
,
24559 on
, active_cursor
);
24563 /* Switch the display of W's cursor on or off, according to the value
24567 update_window_cursor (struct window
*w
, int on
)
24569 /* Don't update cursor in windows whose frame is in the process
24570 of being deleted. */
24571 if (w
->current_matrix
)
24574 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24575 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24581 /* Call update_window_cursor with parameter ON_P on all leaf windows
24582 in the window tree rooted at W. */
24585 update_cursor_in_window_tree (struct window
*w
, int on_p
)
24589 if (!NILP (w
->hchild
))
24590 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
24591 else if (!NILP (w
->vchild
))
24592 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
24594 update_window_cursor (w
, on_p
);
24596 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
24602 Display the cursor on window W, or clear it, according to ON_P.
24603 Don't change the cursor's position. */
24606 x_update_cursor (struct frame
*f
, int on_p
)
24608 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
24613 Clear the cursor of window W to background color, and mark the
24614 cursor as not shown. This is used when the text where the cursor
24615 is about to be rewritten. */
24618 x_clear_cursor (struct window
*w
)
24620 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
24621 update_window_cursor (w
, 0);
24624 #endif /* HAVE_WINDOW_SYSTEM */
24626 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
24629 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
24630 int start_hpos
, int end_hpos
,
24631 enum draw_glyphs_face draw
)
24633 #ifdef HAVE_WINDOW_SYSTEM
24634 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
24636 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
24640 #if defined (HAVE_GPM) || defined (MSDOS)
24641 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
24645 /* Display the active region described by mouse_face_* according to DRAW. */
24648 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
24650 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
24651 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24653 if (/* If window is in the process of being destroyed, don't bother
24655 w
->current_matrix
!= NULL
24656 /* Don't update mouse highlight if hidden */
24657 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
24658 /* Recognize when we are called to operate on rows that don't exist
24659 anymore. This can happen when a window is split. */
24660 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
24662 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
24663 struct glyph_row
*row
, *first
, *last
;
24665 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
24666 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
24668 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
24670 int start_hpos
, end_hpos
, start_x
;
24672 /* For all but the first row, the highlight starts at column 0. */
24675 /* R2L rows have BEG and END in reversed order, but the
24676 screen drawing geometry is always left to right. So
24677 we need to mirror the beginning and end of the
24678 highlighted area in R2L rows. */
24679 if (!row
->reversed_p
)
24681 start_hpos
= hlinfo
->mouse_face_beg_col
;
24682 start_x
= hlinfo
->mouse_face_beg_x
;
24684 else if (row
== last
)
24686 start_hpos
= hlinfo
->mouse_face_end_col
;
24687 start_x
= hlinfo
->mouse_face_end_x
;
24695 else if (row
->reversed_p
&& row
== last
)
24697 start_hpos
= hlinfo
->mouse_face_end_col
;
24698 start_x
= hlinfo
->mouse_face_end_x
;
24708 if (!row
->reversed_p
)
24709 end_hpos
= hlinfo
->mouse_face_end_col
;
24710 else if (row
== first
)
24711 end_hpos
= hlinfo
->mouse_face_beg_col
;
24714 end_hpos
= row
->used
[TEXT_AREA
];
24715 if (draw
== DRAW_NORMAL_TEXT
)
24716 row
->fill_line_p
= 1; /* Clear to end of line */
24719 else if (row
->reversed_p
&& row
== first
)
24720 end_hpos
= hlinfo
->mouse_face_beg_col
;
24723 end_hpos
= row
->used
[TEXT_AREA
];
24724 if (draw
== DRAW_NORMAL_TEXT
)
24725 row
->fill_line_p
= 1; /* Clear to end of line */
24728 if (end_hpos
> start_hpos
)
24730 draw_row_with_mouse_face (w
, start_x
, row
,
24731 start_hpos
, end_hpos
, draw
);
24734 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
24738 #ifdef HAVE_WINDOW_SYSTEM
24739 /* When we've written over the cursor, arrange for it to
24740 be displayed again. */
24741 if (FRAME_WINDOW_P (f
)
24742 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
24745 display_and_set_cursor (w
, 1,
24746 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24747 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24750 #endif /* HAVE_WINDOW_SYSTEM */
24753 #ifdef HAVE_WINDOW_SYSTEM
24754 /* Change the mouse cursor. */
24755 if (FRAME_WINDOW_P (f
))
24757 if (draw
== DRAW_NORMAL_TEXT
24758 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
24759 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
24760 else if (draw
== DRAW_MOUSE_FACE
)
24761 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
24763 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
24765 #endif /* HAVE_WINDOW_SYSTEM */
24769 Clear out the mouse-highlighted active region.
24770 Redraw it un-highlighted first. Value is non-zero if mouse
24771 face was actually drawn unhighlighted. */
24774 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
24778 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
24780 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
24784 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
24785 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
24786 hlinfo
->mouse_face_window
= Qnil
;
24787 hlinfo
->mouse_face_overlay
= Qnil
;
24791 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
24792 within the mouse face on that window. */
24794 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
24796 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
24798 /* Quickly resolve the easy cases. */
24799 if (!(WINDOWP (hlinfo
->mouse_face_window
)
24800 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
24802 if (vpos
< hlinfo
->mouse_face_beg_row
24803 || vpos
> hlinfo
->mouse_face_end_row
)
24805 if (vpos
> hlinfo
->mouse_face_beg_row
24806 && vpos
< hlinfo
->mouse_face_end_row
)
24809 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
24811 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24813 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
24816 else if ((vpos
== hlinfo
->mouse_face_beg_row
24817 && hpos
>= hlinfo
->mouse_face_beg_col
)
24818 || (vpos
== hlinfo
->mouse_face_end_row
24819 && hpos
< hlinfo
->mouse_face_end_col
))
24824 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24826 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
24829 else if ((vpos
== hlinfo
->mouse_face_beg_row
24830 && hpos
<= hlinfo
->mouse_face_beg_col
)
24831 || (vpos
== hlinfo
->mouse_face_end_row
24832 && hpos
> hlinfo
->mouse_face_end_col
))
24840 Non-zero if physical cursor of window W is within mouse face. */
24843 cursor_in_mouse_face_p (struct window
*w
)
24845 return coords_in_mouse_face_p (w
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
);
24850 /* Find the glyph rows START_ROW and END_ROW of window W that display
24851 characters between buffer positions START_CHARPOS and END_CHARPOS
24852 (excluding END_CHARPOS). This is similar to row_containing_pos,
24853 but is more accurate when bidi reordering makes buffer positions
24854 change non-linearly with glyph rows. */
24856 rows_from_pos_range (struct window
*w
,
24857 EMACS_INT start_charpos
, EMACS_INT end_charpos
,
24858 struct glyph_row
**start
, struct glyph_row
**end
)
24860 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24861 int last_y
= window_text_bottom_y (w
);
24862 struct glyph_row
*row
;
24867 while (!first
->enabled_p
24868 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
24871 /* Find the START row. */
24873 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
24876 /* A row can potentially be the START row if the range of the
24877 characters it displays intersects the range
24878 [START_CHARPOS..END_CHARPOS). */
24879 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
24880 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
24881 /* See the commentary in row_containing_pos, for the
24882 explanation of the complicated way to check whether
24883 some position is beyond the end of the characters
24884 displayed by a row. */
24885 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24886 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24887 && !row
->ends_at_zv_p
24888 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
24889 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24890 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24891 && !row
->ends_at_zv_p
24892 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
24894 /* Found a candidate row. Now make sure at least one of the
24895 glyphs it displays has a charpos from the range
24896 [START_CHARPOS..END_CHARPOS).
24898 This is not obvious because bidi reordering could make
24899 buffer positions of a row be 1,2,3,102,101,100, and if we
24900 want to highlight characters in [50..60), we don't want
24901 this row, even though [50..60) does intersect [1..103),
24902 the range of character positions given by the row's start
24903 and end positions. */
24904 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
24905 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
24909 if (BUFFERP (g
->object
)
24910 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24919 /* Find the END row. */
24921 /* If the last row is partially visible, start looking for END
24922 from that row, instead of starting from FIRST. */
24923 && !(row
->enabled_p
24924 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
24926 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
24928 struct glyph_row
*next
= row
+ 1;
24930 if (!next
->enabled_p
24931 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
24932 /* The first row >= START whose range of displayed characters
24933 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
24934 is the row END + 1. */
24935 || (start_charpos
< MATRIX_ROW_START_CHARPOS (next
)
24936 && end_charpos
< MATRIX_ROW_START_CHARPOS (next
))
24937 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24938 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24939 && !next
->ends_at_zv_p
24940 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
24941 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24942 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24943 && !next
->ends_at_zv_p
24944 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
24951 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
24952 but none of the characters it displays are in the range, it is
24954 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
24955 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
24959 if (BUFFERP (g
->object
)
24960 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24973 /* This function sets the mouse_face_* elements of HLINFO, assuming
24974 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
24975 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
24976 for the overlay or run of text properties specifying the mouse
24977 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
24978 before-string and after-string that must also be highlighted.
24979 COVER_STRING, if non-nil, is a display string that may cover some
24980 or all of the highlighted text. */
24983 mouse_face_from_buffer_pos (Lisp_Object window
,
24984 Mouse_HLInfo
*hlinfo
,
24985 EMACS_INT mouse_charpos
,
24986 EMACS_INT start_charpos
,
24987 EMACS_INT end_charpos
,
24988 Lisp_Object before_string
,
24989 Lisp_Object after_string
,
24990 Lisp_Object cover_string
)
24992 struct window
*w
= XWINDOW (window
);
24993 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24994 struct glyph_row
*r1
, *r2
;
24995 struct glyph
*glyph
, *end
;
24996 EMACS_INT ignore
, pos
;
24999 xassert (NILP (cover_string
) || STRINGP (cover_string
));
25000 xassert (NILP (before_string
) || STRINGP (before_string
));
25001 xassert (NILP (after_string
) || STRINGP (after_string
));
25003 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
25004 rows_from_pos_range (w
, start_charpos
, end_charpos
, &r1
, &r2
);
25006 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
25007 /* If the before-string or display-string contains newlines,
25008 rows_from_pos_range skips to its last row. Move back. */
25009 if (!NILP (before_string
) || !NILP (cover_string
))
25011 struct glyph_row
*prev
;
25012 while ((prev
= r1
- 1, prev
>= first
)
25013 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
25014 && prev
->used
[TEXT_AREA
] > 0)
25016 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
25017 glyph
= beg
+ prev
->used
[TEXT_AREA
];
25018 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
25020 || !(EQ (glyph
->object
, before_string
)
25021 || EQ (glyph
->object
, cover_string
)))
25028 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
25029 hlinfo
->mouse_face_past_end
= 1;
25031 else if (!NILP (after_string
))
25033 /* If the after-string has newlines, advance to its last row. */
25034 struct glyph_row
*next
;
25035 struct glyph_row
*last
25036 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
25038 for (next
= r2
+ 1;
25040 && next
->used
[TEXT_AREA
] > 0
25041 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
25045 /* The rest of the display engine assumes that mouse_face_beg_row is
25046 either above below mouse_face_end_row or identical to it. But
25047 with bidi-reordered continued lines, the row for START_CHARPOS
25048 could be below the row for END_CHARPOS. If so, swap the rows and
25049 store them in correct order. */
25052 struct glyph_row
*tem
= r2
;
25058 hlinfo
->mouse_face_beg_y
= r1
->y
;
25059 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
25060 hlinfo
->mouse_face_end_y
= r2
->y
;
25061 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
25063 /* For a bidi-reordered row, the positions of BEFORE_STRING,
25064 AFTER_STRING, COVER_STRING, START_CHARPOS, and END_CHARPOS
25065 could be anywhere in the row and in any order. The strategy
25066 below is to find the leftmost and the rightmost glyph that
25067 belongs to either of these 3 strings, or whose position is
25068 between START_CHARPOS and END_CHARPOS, and highlight all the
25069 glyphs between those two. This may cover more than just the text
25070 between START_CHARPOS and END_CHARPOS if the range of characters
25071 strides the bidi level boundary, e.g. if the beginning is in R2L
25072 text while the end is in L2R text or vice versa. */
25073 if (!r1
->reversed_p
)
25075 /* This row is in a left to right paragraph. Scan it left to
25077 glyph
= r1
->glyphs
[TEXT_AREA
];
25078 end
= glyph
+ r1
->used
[TEXT_AREA
];
25081 /* Skip truncation glyphs at the start of the glyph row. */
25082 if (r1
->displays_text_p
)
25084 && INTEGERP (glyph
->object
)
25085 && glyph
->charpos
< 0;
25087 x
+= glyph
->pixel_width
;
25089 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
25090 or COVER_STRING, and the first glyph from buffer whose
25091 position is between START_CHARPOS and END_CHARPOS. */
25093 && !INTEGERP (glyph
->object
)
25094 && !EQ (glyph
->object
, cover_string
)
25095 && !(BUFFERP (glyph
->object
)
25096 && (glyph
->charpos
>= start_charpos
25097 && glyph
->charpos
< end_charpos
));
25100 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25101 are present at buffer positions between START_CHARPOS and
25102 END_CHARPOS, or if they come from an overlay. */
25103 if (EQ (glyph
->object
, before_string
))
25105 pos
= string_buffer_position (before_string
,
25107 /* If pos == 0, it means before_string came from an
25108 overlay, not from a buffer position. */
25109 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25112 else if (EQ (glyph
->object
, after_string
))
25114 pos
= string_buffer_position (after_string
, end_charpos
);
25115 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25118 x
+= glyph
->pixel_width
;
25120 hlinfo
->mouse_face_beg_x
= x
;
25121 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
25125 /* This row is in a right to left paragraph. Scan it right to
25129 end
= r1
->glyphs
[TEXT_AREA
] - 1;
25130 glyph
= end
+ r1
->used
[TEXT_AREA
];
25132 /* Skip truncation glyphs at the start of the glyph row. */
25133 if (r1
->displays_text_p
)
25135 && INTEGERP (glyph
->object
)
25136 && glyph
->charpos
< 0;
25140 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
25141 or COVER_STRING, and the first glyph from buffer whose
25142 position is between START_CHARPOS and END_CHARPOS. */
25144 && !INTEGERP (glyph
->object
)
25145 && !EQ (glyph
->object
, cover_string
)
25146 && !(BUFFERP (glyph
->object
)
25147 && (glyph
->charpos
>= start_charpos
25148 && glyph
->charpos
< end_charpos
));
25151 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25152 are present at buffer positions between START_CHARPOS and
25153 END_CHARPOS, or if they come from an overlay. */
25154 if (EQ (glyph
->object
, before_string
))
25156 pos
= string_buffer_position (before_string
, start_charpos
);
25157 /* If pos == 0, it means before_string came from an
25158 overlay, not from a buffer position. */
25159 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25162 else if (EQ (glyph
->object
, after_string
))
25164 pos
= string_buffer_position (after_string
, end_charpos
);
25165 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25170 glyph
++; /* first glyph to the right of the highlighted area */
25171 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
25172 x
+= g
->pixel_width
;
25173 hlinfo
->mouse_face_beg_x
= x
;
25174 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
25177 /* If the highlight ends in a different row, compute GLYPH and END
25178 for the end row. Otherwise, reuse the values computed above for
25179 the row where the highlight begins. */
25182 if (!r2
->reversed_p
)
25184 glyph
= r2
->glyphs
[TEXT_AREA
];
25185 end
= glyph
+ r2
->used
[TEXT_AREA
];
25190 end
= r2
->glyphs
[TEXT_AREA
] - 1;
25191 glyph
= end
+ r2
->used
[TEXT_AREA
];
25195 if (!r2
->reversed_p
)
25197 /* Skip truncation and continuation glyphs near the end of the
25198 row, and also blanks and stretch glyphs inserted by
25199 extend_face_to_end_of_line. */
25201 && INTEGERP ((end
- 1)->object
)
25202 && (end
- 1)->charpos
<= 0)
25204 /* Scan the rest of the glyph row from the end, looking for the
25205 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
25206 COVER_STRING, or whose position is between START_CHARPOS
25210 && !INTEGERP (end
->object
)
25211 && !EQ (end
->object
, cover_string
)
25212 && !(BUFFERP (end
->object
)
25213 && (end
->charpos
>= start_charpos
25214 && end
->charpos
< end_charpos
));
25217 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25218 are present at buffer positions between START_CHARPOS and
25219 END_CHARPOS, or if they come from an overlay. */
25220 if (EQ (end
->object
, before_string
))
25222 pos
= string_buffer_position (before_string
, start_charpos
);
25223 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25226 else if (EQ (end
->object
, after_string
))
25228 pos
= string_buffer_position (after_string
, end_charpos
);
25229 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25233 /* Find the X coordinate of the last glyph to be highlighted. */
25234 for (; glyph
<= end
; ++glyph
)
25235 x
+= glyph
->pixel_width
;
25237 hlinfo
->mouse_face_end_x
= x
;
25238 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
25242 /* Skip truncation and continuation glyphs near the end of the
25243 row, and also blanks and stretch glyphs inserted by
25244 extend_face_to_end_of_line. */
25248 && INTEGERP (end
->object
)
25249 && end
->charpos
<= 0)
25251 x
+= end
->pixel_width
;
25254 /* Scan the rest of the glyph row from the end, looking for the
25255 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
25256 COVER_STRING, or whose position is between START_CHARPOS
25260 && !INTEGERP (end
->object
)
25261 && !EQ (end
->object
, cover_string
)
25262 && !(BUFFERP (end
->object
)
25263 && (end
->charpos
>= start_charpos
25264 && end
->charpos
< end_charpos
));
25267 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25268 are present at buffer positions between START_CHARPOS and
25269 END_CHARPOS, or if they come from an overlay. */
25270 if (EQ (end
->object
, before_string
))
25272 pos
= string_buffer_position (before_string
, start_charpos
);
25273 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25276 else if (EQ (end
->object
, after_string
))
25278 pos
= string_buffer_position (after_string
, end_charpos
);
25279 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25282 x
+= end
->pixel_width
;
25284 hlinfo
->mouse_face_end_x
= x
;
25285 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
25288 hlinfo
->mouse_face_window
= window
;
25289 hlinfo
->mouse_face_face_id
25290 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
25292 !hlinfo
->mouse_face_hidden
, -1);
25293 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25296 /* The following function is not used anymore (replaced with
25297 mouse_face_from_string_pos), but I leave it here for the time
25298 being, in case someone would. */
25300 #if 0 /* not used */
25302 /* Find the position of the glyph for position POS in OBJECT in
25303 window W's current matrix, and return in *X, *Y the pixel
25304 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
25306 RIGHT_P non-zero means return the position of the right edge of the
25307 glyph, RIGHT_P zero means return the left edge position.
25309 If no glyph for POS exists in the matrix, return the position of
25310 the glyph with the next smaller position that is in the matrix, if
25311 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
25312 exists in the matrix, return the position of the glyph with the
25313 next larger position in OBJECT.
25315 Value is non-zero if a glyph was found. */
25318 fast_find_string_pos (struct window
*w
, EMACS_INT pos
, Lisp_Object object
,
25319 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
25321 int yb
= window_text_bottom_y (w
);
25322 struct glyph_row
*r
;
25323 struct glyph
*best_glyph
= NULL
;
25324 struct glyph_row
*best_row
= NULL
;
25327 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25328 r
->enabled_p
&& r
->y
< yb
;
25331 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
25332 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
25335 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
25336 if (EQ (g
->object
, object
))
25338 if (g
->charpos
== pos
)
25345 else if (best_glyph
== NULL
25346 || ((eabs (g
->charpos
- pos
)
25347 < eabs (best_glyph
->charpos
- pos
))
25350 : g
->charpos
> pos
)))
25364 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
25368 *x
+= best_glyph
->pixel_width
;
25373 *vpos
= best_row
- w
->current_matrix
->rows
;
25376 return best_glyph
!= NULL
;
25378 #endif /* not used */
25380 /* Find the positions of the first and the last glyphs in window W's
25381 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
25382 (assumed to be a string), and return in HLINFO's mouse_face_*
25383 members the pixel and column/row coordinates of those glyphs. */
25386 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
25387 Lisp_Object object
,
25388 EMACS_INT startpos
, EMACS_INT endpos
)
25390 int yb
= window_text_bottom_y (w
);
25391 struct glyph_row
*r
;
25392 struct glyph
*g
, *e
;
25396 /* Find the glyph row with at least one position in the range
25397 [STARTPOS..ENDPOS], and the first glyph in that row whose
25398 position belongs to that range. */
25399 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25400 r
->enabled_p
&& r
->y
< yb
;
25403 if (!r
->reversed_p
)
25405 g
= r
->glyphs
[TEXT_AREA
];
25406 e
= g
+ r
->used
[TEXT_AREA
];
25407 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
25408 if (EQ (g
->object
, object
)
25409 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
25411 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
25412 hlinfo
->mouse_face_beg_y
= r
->y
;
25413 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
25414 hlinfo
->mouse_face_beg_x
= gx
;
25423 e
= r
->glyphs
[TEXT_AREA
];
25424 g
= e
+ r
->used
[TEXT_AREA
];
25425 for ( ; g
> e
; --g
)
25426 if (EQ ((g
-1)->object
, object
)
25427 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
25429 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
25430 hlinfo
->mouse_face_beg_y
= r
->y
;
25431 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
25432 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
25433 gx
+= g1
->pixel_width
;
25434 hlinfo
->mouse_face_beg_x
= gx
;
25446 /* Starting with the next row, look for the first row which does NOT
25447 include any glyphs whose positions are in the range. */
25448 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
25450 g
= r
->glyphs
[TEXT_AREA
];
25451 e
= g
+ r
->used
[TEXT_AREA
];
25453 for ( ; g
< e
; ++g
)
25454 if (EQ (g
->object
, object
)
25455 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
25464 /* The highlighted region ends on the previous row. */
25467 /* Set the end row and its vertical pixel coordinate. */
25468 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
25469 hlinfo
->mouse_face_end_y
= r
->y
;
25471 /* Compute and set the end column and the end column's horizontal
25472 pixel coordinate. */
25473 if (!r
->reversed_p
)
25475 g
= r
->glyphs
[TEXT_AREA
];
25476 e
= g
+ r
->used
[TEXT_AREA
];
25477 for ( ; e
> g
; --e
)
25478 if (EQ ((e
-1)->object
, object
)
25479 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
25481 hlinfo
->mouse_face_end_col
= e
- g
;
25483 for (gx
= r
->x
; g
< e
; ++g
)
25484 gx
+= g
->pixel_width
;
25485 hlinfo
->mouse_face_end_x
= gx
;
25489 e
= r
->glyphs
[TEXT_AREA
];
25490 g
= e
+ r
->used
[TEXT_AREA
];
25491 for (gx
= r
->x
; e
< g
; ++e
)
25493 if (EQ (e
->object
, object
)
25494 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
25496 gx
+= e
->pixel_width
;
25498 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
25499 hlinfo
->mouse_face_end_x
= gx
;
25503 #ifdef HAVE_WINDOW_SYSTEM
25505 /* See if position X, Y is within a hot-spot of an image. */
25508 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
25510 if (!CONSP (hot_spot
))
25513 if (EQ (XCAR (hot_spot
), Qrect
))
25515 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
25516 Lisp_Object rect
= XCDR (hot_spot
);
25520 if (!CONSP (XCAR (rect
)))
25522 if (!CONSP (XCDR (rect
)))
25524 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
25526 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
25528 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
25530 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
25534 else if (EQ (XCAR (hot_spot
), Qcircle
))
25536 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
25537 Lisp_Object circ
= XCDR (hot_spot
);
25538 Lisp_Object lr
, lx0
, ly0
;
25540 && CONSP (XCAR (circ
))
25541 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
25542 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
25543 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
25545 double r
= XFLOATINT (lr
);
25546 double dx
= XINT (lx0
) - x
;
25547 double dy
= XINT (ly0
) - y
;
25548 return (dx
* dx
+ dy
* dy
<= r
* r
);
25551 else if (EQ (XCAR (hot_spot
), Qpoly
))
25553 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
25554 if (VECTORP (XCDR (hot_spot
)))
25556 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
25557 Lisp_Object
*poly
= v
->contents
;
25558 int n
= v
->header
.size
;
25561 Lisp_Object lx
, ly
;
25564 /* Need an even number of coordinates, and at least 3 edges. */
25565 if (n
< 6 || n
& 1)
25568 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
25569 If count is odd, we are inside polygon. Pixels on edges
25570 may or may not be included depending on actual geometry of the
25572 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
25573 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
25575 x0
= XINT (lx
), y0
= XINT (ly
);
25576 for (i
= 0; i
< n
; i
+= 2)
25578 int x1
= x0
, y1
= y0
;
25579 if ((lx
= poly
[i
], !INTEGERP (lx
))
25580 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
25582 x0
= XINT (lx
), y0
= XINT (ly
);
25584 /* Does this segment cross the X line? */
25592 if (y
> y0
&& y
> y1
)
25594 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
25604 find_hot_spot (Lisp_Object map
, int x
, int y
)
25606 while (CONSP (map
))
25608 if (CONSP (XCAR (map
))
25609 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
25617 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
25619 doc
: /* Lookup in image map MAP coordinates X and Y.
25620 An image map is an alist where each element has the format (AREA ID PLIST).
25621 An AREA is specified as either a rectangle, a circle, or a polygon:
25622 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
25623 pixel coordinates of the upper left and bottom right corners.
25624 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
25625 and the radius of the circle; r may be a float or integer.
25626 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
25627 vector describes one corner in the polygon.
25628 Returns the alist element for the first matching AREA in MAP. */)
25629 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
25637 return find_hot_spot (map
, XINT (x
), XINT (y
));
25641 /* Display frame CURSOR, optionally using shape defined by POINTER. */
25643 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
25645 /* Do not change cursor shape while dragging mouse. */
25646 if (!NILP (do_mouse_tracking
))
25649 if (!NILP (pointer
))
25651 if (EQ (pointer
, Qarrow
))
25652 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25653 else if (EQ (pointer
, Qhand
))
25654 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
25655 else if (EQ (pointer
, Qtext
))
25656 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25657 else if (EQ (pointer
, intern ("hdrag")))
25658 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25659 #ifdef HAVE_X_WINDOWS
25660 else if (EQ (pointer
, intern ("vdrag")))
25661 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
25663 else if (EQ (pointer
, intern ("hourglass")))
25664 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
25665 else if (EQ (pointer
, Qmodeline
))
25666 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
25668 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25671 if (cursor
!= No_Cursor
)
25672 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
25675 #endif /* HAVE_WINDOW_SYSTEM */
25677 /* Take proper action when mouse has moved to the mode or header line
25678 or marginal area AREA of window W, x-position X and y-position Y.
25679 X is relative to the start of the text display area of W, so the
25680 width of bitmap areas and scroll bars must be subtracted to get a
25681 position relative to the start of the mode line. */
25684 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
25685 enum window_part area
)
25687 struct window
*w
= XWINDOW (window
);
25688 struct frame
*f
= XFRAME (w
->frame
);
25689 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25690 #ifdef HAVE_WINDOW_SYSTEM
25691 Display_Info
*dpyinfo
;
25693 Cursor cursor
= No_Cursor
;
25694 Lisp_Object pointer
= Qnil
;
25695 int dx
, dy
, width
, height
;
25697 Lisp_Object string
, object
= Qnil
;
25698 Lisp_Object pos
, help
;
25700 Lisp_Object mouse_face
;
25701 int original_x_pixel
= x
;
25702 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
25703 struct glyph_row
*row
;
25705 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
25710 /* Kludge alert: mode_line_string takes X/Y in pixels, but
25711 returns them in row/column units! */
25712 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
25713 &object
, &dx
, &dy
, &width
, &height
);
25715 row
= (area
== ON_MODE_LINE
25716 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
25717 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
25719 /* Find the glyph under the mouse pointer. */
25720 if (row
->mode_line_p
&& row
->enabled_p
)
25722 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
25723 end
= glyph
+ row
->used
[TEXT_AREA
];
25725 for (x0
= original_x_pixel
;
25726 glyph
< end
&& x0
>= glyph
->pixel_width
;
25728 x0
-= glyph
->pixel_width
;
25736 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
25737 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
25738 returns them in row/column units! */
25739 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
25740 &object
, &dx
, &dy
, &width
, &height
);
25745 #ifdef HAVE_WINDOW_SYSTEM
25746 if (IMAGEP (object
))
25748 Lisp_Object image_map
, hotspot
;
25749 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
25751 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
25753 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25757 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
25758 If so, we could look for mouse-enter, mouse-leave
25759 properties in PLIST (and do something...). */
25760 hotspot
= XCDR (hotspot
);
25761 if (CONSP (hotspot
)
25762 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25764 pointer
= Fplist_get (plist
, Qpointer
);
25765 if (NILP (pointer
))
25767 help
= Fplist_get (plist
, Qhelp_echo
);
25770 help_echo_string
= help
;
25771 /* Is this correct? ++kfs */
25772 XSETWINDOW (help_echo_window
, w
);
25773 help_echo_object
= w
->buffer
;
25774 help_echo_pos
= charpos
;
25778 if (NILP (pointer
))
25779 pointer
= Fplist_get (XCDR (object
), QCpointer
);
25781 #endif /* HAVE_WINDOW_SYSTEM */
25783 if (STRINGP (string
))
25785 pos
= make_number (charpos
);
25786 /* If we're on a string with `help-echo' text property, arrange
25787 for the help to be displayed. This is done by setting the
25788 global variable help_echo_string to the help string. */
25791 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
25794 help_echo_string
= help
;
25795 XSETWINDOW (help_echo_window
, w
);
25796 help_echo_object
= string
;
25797 help_echo_pos
= charpos
;
25801 #ifdef HAVE_WINDOW_SYSTEM
25802 if (FRAME_WINDOW_P (f
))
25804 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25805 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25806 if (NILP (pointer
))
25807 pointer
= Fget_text_property (pos
, Qpointer
, string
);
25809 /* Change the mouse pointer according to what is under X/Y. */
25811 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
25814 map
= Fget_text_property (pos
, Qlocal_map
, string
);
25815 if (!KEYMAPP (map
))
25816 map
= Fget_text_property (pos
, Qkeymap
, string
);
25817 if (!KEYMAPP (map
))
25818 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
25823 /* Change the mouse face according to what is under X/Y. */
25824 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
25825 if (!NILP (mouse_face
)
25826 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25831 struct glyph
* tmp_glyph
;
25835 int total_pixel_width
;
25836 EMACS_INT begpos
, endpos
, ignore
;
25840 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
25841 Qmouse_face
, string
, Qnil
);
25847 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
25849 endpos
= SCHARS (string
);
25853 /* Calculate the glyph position GPOS of GLYPH in the
25854 displayed string, relative to the beginning of the
25855 highlighted part of the string.
25857 Note: GPOS is different from CHARPOS. CHARPOS is the
25858 position of GLYPH in the internal string object. A mode
25859 line string format has structures which are converted to
25860 a flattened string by the Emacs Lisp interpreter. The
25861 internal string is an element of those structures. The
25862 displayed string is the flattened string. */
25863 tmp_glyph
= row_start_glyph
;
25864 while (tmp_glyph
< glyph
25865 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25866 && begpos
<= tmp_glyph
->charpos
25867 && tmp_glyph
->charpos
< endpos
)))
25869 gpos
= glyph
- tmp_glyph
;
25871 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
25872 the highlighted part of the displayed string to which
25873 GLYPH belongs. Note: GSEQ_LENGTH is different from
25874 SCHARS (STRING), because the latter returns the length of
25875 the internal string. */
25876 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
25878 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25879 && begpos
<= tmp_glyph
->charpos
25880 && tmp_glyph
->charpos
< endpos
));
25883 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
25885 /* Calculate the total pixel width of all the glyphs between
25886 the beginning of the highlighted area and GLYPH. */
25887 total_pixel_width
= 0;
25888 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
25889 total_pixel_width
+= tmp_glyph
->pixel_width
;
25891 /* Pre calculation of re-rendering position. Note: X is in
25892 column units here, after the call to mode_line_string or
25893 marginal_area_string. */
25895 vpos
= (area
== ON_MODE_LINE
25896 ? (w
->current_matrix
)->nrows
- 1
25899 /* If GLYPH's position is included in the region that is
25900 already drawn in mouse face, we have nothing to do. */
25901 if ( EQ (window
, hlinfo
->mouse_face_window
)
25902 && (!row
->reversed_p
25903 ? (hlinfo
->mouse_face_beg_col
<= hpos
25904 && hpos
< hlinfo
->mouse_face_end_col
)
25905 /* In R2L rows we swap BEG and END, see below. */
25906 : (hlinfo
->mouse_face_end_col
<= hpos
25907 && hpos
< hlinfo
->mouse_face_beg_col
))
25908 && hlinfo
->mouse_face_beg_row
== vpos
)
25911 if (clear_mouse_face (hlinfo
))
25912 cursor
= No_Cursor
;
25914 if (!row
->reversed_p
)
25916 hlinfo
->mouse_face_beg_col
= hpos
;
25917 hlinfo
->mouse_face_beg_x
= original_x_pixel
25918 - (total_pixel_width
+ dx
);
25919 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
25920 hlinfo
->mouse_face_end_x
= 0;
25924 /* In R2L rows, show_mouse_face expects BEG and END
25925 coordinates to be swapped. */
25926 hlinfo
->mouse_face_end_col
= hpos
;
25927 hlinfo
->mouse_face_end_x
= original_x_pixel
25928 - (total_pixel_width
+ dx
);
25929 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
25930 hlinfo
->mouse_face_beg_x
= 0;
25933 hlinfo
->mouse_face_beg_row
= vpos
;
25934 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
25935 hlinfo
->mouse_face_beg_y
= 0;
25936 hlinfo
->mouse_face_end_y
= 0;
25937 hlinfo
->mouse_face_past_end
= 0;
25938 hlinfo
->mouse_face_window
= window
;
25940 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
25946 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25948 if (NILP (pointer
))
25951 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25952 clear_mouse_face (hlinfo
);
25954 #ifdef HAVE_WINDOW_SYSTEM
25955 if (FRAME_WINDOW_P (f
))
25956 define_frame_cursor1 (f
, cursor
, pointer
);
25962 Take proper action when the mouse has moved to position X, Y on
25963 frame F as regards highlighting characters that have mouse-face
25964 properties. Also de-highlighting chars where the mouse was before.
25965 X and Y can be negative or out of range. */
25968 note_mouse_highlight (struct frame
*f
, int x
, int y
)
25970 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25971 enum window_part part
;
25972 Lisp_Object window
;
25974 Cursor cursor
= No_Cursor
;
25975 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
25978 /* When a menu is active, don't highlight because this looks odd. */
25979 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
25980 if (popup_activated ())
25984 if (NILP (Vmouse_highlight
)
25985 || !f
->glyphs_initialized_p
25986 || f
->pointer_invisible
)
25989 hlinfo
->mouse_face_mouse_x
= x
;
25990 hlinfo
->mouse_face_mouse_y
= y
;
25991 hlinfo
->mouse_face_mouse_frame
= f
;
25993 if (hlinfo
->mouse_face_defer
)
25996 if (gc_in_progress
)
25998 hlinfo
->mouse_face_deferred_gc
= 1;
26002 /* Which window is that in? */
26003 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
26005 /* If we were displaying active text in another window, clear that.
26006 Also clear if we move out of text area in same window. */
26007 if (! EQ (window
, hlinfo
->mouse_face_window
)
26008 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
26009 && !NILP (hlinfo
->mouse_face_window
)))
26010 clear_mouse_face (hlinfo
);
26012 /* Not on a window -> return. */
26013 if (!WINDOWP (window
))
26016 /* Reset help_echo_string. It will get recomputed below. */
26017 help_echo_string
= Qnil
;
26019 /* Convert to window-relative pixel coordinates. */
26020 w
= XWINDOW (window
);
26021 frame_to_window_pixel_xy (w
, &x
, &y
);
26023 #ifdef HAVE_WINDOW_SYSTEM
26024 /* Handle tool-bar window differently since it doesn't display a
26026 if (EQ (window
, f
->tool_bar_window
))
26028 note_tool_bar_highlight (f
, x
, y
);
26033 /* Mouse is on the mode, header line or margin? */
26034 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
26035 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
26037 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
26041 #ifdef HAVE_WINDOW_SYSTEM
26042 if (part
== ON_VERTICAL_BORDER
)
26044 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
26045 help_echo_string
= build_string ("drag-mouse-1: resize");
26047 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
26048 || part
== ON_SCROLL_BAR
)
26049 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26051 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
26054 /* Are we in a window whose display is up to date?
26055 And verify the buffer's text has not changed. */
26056 b
= XBUFFER (w
->buffer
);
26057 if (part
== ON_TEXT
26058 && EQ (w
->window_end_valid
, w
->buffer
)
26059 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
26060 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
26062 int hpos
, vpos
, i
, dx
, dy
, area
;
26064 struct glyph
*glyph
;
26065 Lisp_Object object
;
26066 Lisp_Object mouse_face
= Qnil
, position
;
26067 Lisp_Object
*overlay_vec
= NULL
;
26069 struct buffer
*obuf
;
26070 EMACS_INT obegv
, ozv
;
26073 /* Find the glyph under X/Y. */
26074 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
26076 #ifdef HAVE_WINDOW_SYSTEM
26077 /* Look for :pointer property on image. */
26078 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26080 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26081 if (img
!= NULL
&& IMAGEP (img
->spec
))
26083 Lisp_Object image_map
, hotspot
;
26084 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
26086 && (hotspot
= find_hot_spot (image_map
,
26087 glyph
->slice
.img
.x
+ dx
,
26088 glyph
->slice
.img
.y
+ dy
),
26090 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
26094 /* Could check XCAR (hotspot) to see if we enter/leave
26096 If so, we could look for mouse-enter, mouse-leave
26097 properties in PLIST (and do something...). */
26098 hotspot
= XCDR (hotspot
);
26099 if (CONSP (hotspot
)
26100 && (plist
= XCAR (hotspot
), CONSP (plist
)))
26102 pointer
= Fplist_get (plist
, Qpointer
);
26103 if (NILP (pointer
))
26105 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
26106 if (!NILP (help_echo_string
))
26108 help_echo_window
= window
;
26109 help_echo_object
= glyph
->object
;
26110 help_echo_pos
= glyph
->charpos
;
26114 if (NILP (pointer
))
26115 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
26118 #endif /* HAVE_WINDOW_SYSTEM */
26120 /* Clear mouse face if X/Y not over text. */
26122 || area
!= TEXT_AREA
26123 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
26124 /* Glyph's OBJECT is an integer for glyphs inserted by the
26125 display engine for its internal purposes, like truncation
26126 and continuation glyphs and blanks beyond the end of
26127 line's text on text terminals. If we are over such a
26128 glyph, we are not over any text. */
26129 || INTEGERP (glyph
->object
)
26130 /* R2L rows have a stretch glyph at their front, which
26131 stands for no text, whereas L2R rows have no glyphs at
26132 all beyond the end of text. Treat such stretch glyphs
26133 like we do with NULL glyphs in L2R rows. */
26134 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
26135 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
26136 && glyph
->type
== STRETCH_GLYPH
26137 && glyph
->avoid_cursor_p
))
26139 if (clear_mouse_face (hlinfo
))
26140 cursor
= No_Cursor
;
26141 #ifdef HAVE_WINDOW_SYSTEM
26142 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
26144 if (area
!= TEXT_AREA
)
26145 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26147 pointer
= Vvoid_text_area_pointer
;
26153 pos
= glyph
->charpos
;
26154 object
= glyph
->object
;
26155 if (!STRINGP (object
) && !BUFFERP (object
))
26158 /* If we get an out-of-range value, return now; avoid an error. */
26159 if (BUFFERP (object
) && pos
> BUF_Z (b
))
26162 /* Make the window's buffer temporarily current for
26163 overlays_at and compute_char_face. */
26164 obuf
= current_buffer
;
26165 current_buffer
= b
;
26171 /* Is this char mouse-active or does it have help-echo? */
26172 position
= make_number (pos
);
26174 if (BUFFERP (object
))
26176 /* Put all the overlays we want in a vector in overlay_vec. */
26177 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
26178 /* Sort overlays into increasing priority order. */
26179 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
26184 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
26187 cursor
= No_Cursor
;
26189 /* Check mouse-face highlighting. */
26191 /* If there exists an overlay with mouse-face overlapping
26192 the one we are currently highlighting, we have to
26193 check if we enter the overlapping overlay, and then
26194 highlight only that. */
26195 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
26196 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
26198 /* Find the highest priority overlay with a mouse-face. */
26199 Lisp_Object overlay
= Qnil
;
26200 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
26202 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
26203 if (!NILP (mouse_face
))
26204 overlay
= overlay_vec
[i
];
26207 /* If we're highlighting the same overlay as before, there's
26208 no need to do that again. */
26209 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
26210 goto check_help_echo
;
26211 hlinfo
->mouse_face_overlay
= overlay
;
26213 /* Clear the display of the old active region, if any. */
26214 if (clear_mouse_face (hlinfo
))
26215 cursor
= No_Cursor
;
26217 /* If no overlay applies, get a text property. */
26218 if (NILP (overlay
))
26219 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
26221 /* Next, compute the bounds of the mouse highlighting and
26223 if (!NILP (mouse_face
) && STRINGP (object
))
26225 /* The mouse-highlighting comes from a display string
26226 with a mouse-face. */
26230 s
= Fprevious_single_property_change
26231 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
26232 e
= Fnext_single_property_change
26233 (position
, Qmouse_face
, object
, Qnil
);
26235 s
= make_number (0);
26237 e
= make_number (SCHARS (object
) - 1);
26238 mouse_face_from_string_pos (w
, hlinfo
, object
,
26239 XINT (s
), XINT (e
));
26240 hlinfo
->mouse_face_past_end
= 0;
26241 hlinfo
->mouse_face_window
= window
;
26242 hlinfo
->mouse_face_face_id
26243 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
26244 glyph
->face_id
, 1);
26245 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26246 cursor
= No_Cursor
;
26250 /* The mouse-highlighting, if any, comes from an overlay
26251 or text property in the buffer. */
26252 Lisp_Object buffer
IF_LINT (= Qnil
);
26253 Lisp_Object cover_string
IF_LINT (= Qnil
);
26255 if (STRINGP (object
))
26257 /* If we are on a display string with no mouse-face,
26258 check if the text under it has one. */
26259 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
26260 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26261 pos
= string_buffer_position (object
, start
);
26264 mouse_face
= get_char_property_and_overlay
26265 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
26266 buffer
= w
->buffer
;
26267 cover_string
= object
;
26273 cover_string
= Qnil
;
26276 if (!NILP (mouse_face
))
26278 Lisp_Object before
, after
;
26279 Lisp_Object before_string
, after_string
;
26280 /* To correctly find the limits of mouse highlight
26281 in a bidi-reordered buffer, we must not use the
26282 optimization of limiting the search in
26283 previous-single-property-change and
26284 next-single-property-change, because
26285 rows_from_pos_range needs the real start and end
26286 positions to DTRT in this case. That's because
26287 the first row visible in a window does not
26288 necessarily display the character whose position
26289 is the smallest. */
26291 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
26292 ? Fmarker_position (w
->start
)
26295 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
26296 ? make_number (BUF_Z (XBUFFER (buffer
))
26297 - XFASTINT (w
->window_end_pos
))
26300 if (NILP (overlay
))
26302 /* Handle the text property case. */
26303 before
= Fprevious_single_property_change
26304 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
26305 after
= Fnext_single_property_change
26306 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
26307 before_string
= after_string
= Qnil
;
26311 /* Handle the overlay case. */
26312 before
= Foverlay_start (overlay
);
26313 after
= Foverlay_end (overlay
);
26314 before_string
= Foverlay_get (overlay
, Qbefore_string
);
26315 after_string
= Foverlay_get (overlay
, Qafter_string
);
26317 if (!STRINGP (before_string
)) before_string
= Qnil
;
26318 if (!STRINGP (after_string
)) after_string
= Qnil
;
26321 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
26324 before_string
, after_string
,
26326 cursor
= No_Cursor
;
26333 /* Look for a `help-echo' property. */
26334 if (NILP (help_echo_string
)) {
26335 Lisp_Object help
, overlay
;
26337 /* Check overlays first. */
26338 help
= overlay
= Qnil
;
26339 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
26341 overlay
= overlay_vec
[i
];
26342 help
= Foverlay_get (overlay
, Qhelp_echo
);
26347 help_echo_string
= help
;
26348 help_echo_window
= window
;
26349 help_echo_object
= overlay
;
26350 help_echo_pos
= pos
;
26354 Lisp_Object obj
= glyph
->object
;
26355 EMACS_INT charpos
= glyph
->charpos
;
26357 /* Try text properties. */
26360 && charpos
< SCHARS (obj
))
26362 help
= Fget_text_property (make_number (charpos
),
26366 /* If the string itself doesn't specify a help-echo,
26367 see if the buffer text ``under'' it does. */
26368 struct glyph_row
*r
26369 = MATRIX_ROW (w
->current_matrix
, vpos
);
26370 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26371 EMACS_INT p
= string_buffer_position (obj
, start
);
26374 help
= Fget_char_property (make_number (p
),
26375 Qhelp_echo
, w
->buffer
);
26384 else if (BUFFERP (obj
)
26387 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
26392 help_echo_string
= help
;
26393 help_echo_window
= window
;
26394 help_echo_object
= obj
;
26395 help_echo_pos
= charpos
;
26400 #ifdef HAVE_WINDOW_SYSTEM
26401 /* Look for a `pointer' property. */
26402 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
26404 /* Check overlays first. */
26405 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
26406 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
26408 if (NILP (pointer
))
26410 Lisp_Object obj
= glyph
->object
;
26411 EMACS_INT charpos
= glyph
->charpos
;
26413 /* Try text properties. */
26416 && charpos
< SCHARS (obj
))
26418 pointer
= Fget_text_property (make_number (charpos
),
26420 if (NILP (pointer
))
26422 /* If the string itself doesn't specify a pointer,
26423 see if the buffer text ``under'' it does. */
26424 struct glyph_row
*r
26425 = MATRIX_ROW (w
->current_matrix
, vpos
);
26426 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26427 EMACS_INT p
= string_buffer_position (obj
, start
);
26429 pointer
= Fget_char_property (make_number (p
),
26430 Qpointer
, w
->buffer
);
26433 else if (BUFFERP (obj
)
26436 pointer
= Fget_text_property (make_number (charpos
),
26440 #endif /* HAVE_WINDOW_SYSTEM */
26444 current_buffer
= obuf
;
26449 #ifdef HAVE_WINDOW_SYSTEM
26450 if (FRAME_WINDOW_P (f
))
26451 define_frame_cursor1 (f
, cursor
, pointer
);
26453 /* This is here to prevent a compiler error, about "label at end of
26454 compound statement". */
26461 Clear any mouse-face on window W. This function is part of the
26462 redisplay interface, and is called from try_window_id and similar
26463 functions to ensure the mouse-highlight is off. */
26466 x_clear_window_mouse_face (struct window
*w
)
26468 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26469 Lisp_Object window
;
26472 XSETWINDOW (window
, w
);
26473 if (EQ (window
, hlinfo
->mouse_face_window
))
26474 clear_mouse_face (hlinfo
);
26480 Just discard the mouse face information for frame F, if any.
26481 This is used when the size of F is changed. */
26484 cancel_mouse_face (struct frame
*f
)
26486 Lisp_Object window
;
26487 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26489 window
= hlinfo
->mouse_face_window
;
26490 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
26492 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26493 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26494 hlinfo
->mouse_face_window
= Qnil
;
26500 /***********************************************************************
26502 ***********************************************************************/
26504 #ifdef HAVE_WINDOW_SYSTEM
26506 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
26507 which intersects rectangle R. R is in window-relative coordinates. */
26510 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
26511 enum glyph_row_area area
)
26513 struct glyph
*first
= row
->glyphs
[area
];
26514 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
26515 struct glyph
*last
;
26516 int first_x
, start_x
, x
;
26518 if (area
== TEXT_AREA
&& row
->fill_line_p
)
26519 /* If row extends face to end of line write the whole line. */
26520 draw_glyphs (w
, 0, row
, area
,
26521 0, row
->used
[area
],
26522 DRAW_NORMAL_TEXT
, 0);
26525 /* Set START_X to the window-relative start position for drawing glyphs of
26526 AREA. The first glyph of the text area can be partially visible.
26527 The first glyphs of other areas cannot. */
26528 start_x
= window_box_left_offset (w
, area
);
26530 if (area
== TEXT_AREA
)
26533 /* Find the first glyph that must be redrawn. */
26535 && x
+ first
->pixel_width
< r
->x
)
26537 x
+= first
->pixel_width
;
26541 /* Find the last one. */
26545 && x
< r
->x
+ r
->width
)
26547 x
+= last
->pixel_width
;
26553 draw_glyphs (w
, first_x
- start_x
, row
, area
,
26554 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
26555 DRAW_NORMAL_TEXT
, 0);
26560 /* Redraw the parts of the glyph row ROW on window W intersecting
26561 rectangle R. R is in window-relative coordinates. Value is
26562 non-zero if mouse-face was overwritten. */
26565 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
26567 xassert (row
->enabled_p
);
26569 if (row
->mode_line_p
|| w
->pseudo_window_p
)
26570 draw_glyphs (w
, 0, row
, TEXT_AREA
,
26571 0, row
->used
[TEXT_AREA
],
26572 DRAW_NORMAL_TEXT
, 0);
26575 if (row
->used
[LEFT_MARGIN_AREA
])
26576 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
26577 if (row
->used
[TEXT_AREA
])
26578 expose_area (w
, row
, r
, TEXT_AREA
);
26579 if (row
->used
[RIGHT_MARGIN_AREA
])
26580 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
26581 draw_row_fringe_bitmaps (w
, row
);
26584 return row
->mouse_face_p
;
26588 /* Redraw those parts of glyphs rows during expose event handling that
26589 overlap other rows. Redrawing of an exposed line writes over parts
26590 of lines overlapping that exposed line; this function fixes that.
26592 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
26593 row in W's current matrix that is exposed and overlaps other rows.
26594 LAST_OVERLAPPING_ROW is the last such row. */
26597 expose_overlaps (struct window
*w
,
26598 struct glyph_row
*first_overlapping_row
,
26599 struct glyph_row
*last_overlapping_row
,
26602 struct glyph_row
*row
;
26604 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
26605 if (row
->overlapping_p
)
26607 xassert (row
->enabled_p
&& !row
->mode_line_p
);
26610 if (row
->used
[LEFT_MARGIN_AREA
])
26611 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
26613 if (row
->used
[TEXT_AREA
])
26614 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
26616 if (row
->used
[RIGHT_MARGIN_AREA
])
26617 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
26623 /* Return non-zero if W's cursor intersects rectangle R. */
26626 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
26628 XRectangle cr
, result
;
26629 struct glyph
*cursor_glyph
;
26630 struct glyph_row
*row
;
26632 if (w
->phys_cursor
.vpos
>= 0
26633 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
26634 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
26636 && row
->cursor_in_fringe_p
)
26638 /* Cursor is in the fringe. */
26639 cr
.x
= window_box_right_offset (w
,
26640 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
26641 ? RIGHT_MARGIN_AREA
26644 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
26645 cr
.height
= row
->height
;
26646 return x_intersect_rectangles (&cr
, r
, &result
);
26649 cursor_glyph
= get_phys_cursor_glyph (w
);
26652 /* r is relative to W's box, but w->phys_cursor.x is relative
26653 to left edge of W's TEXT area. Adjust it. */
26654 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
26655 cr
.y
= w
->phys_cursor
.y
;
26656 cr
.width
= cursor_glyph
->pixel_width
;
26657 cr
.height
= w
->phys_cursor_height
;
26658 /* ++KFS: W32 version used W32-specific IntersectRect here, but
26659 I assume the effect is the same -- and this is portable. */
26660 return x_intersect_rectangles (&cr
, r
, &result
);
26662 /* If we don't understand the format, pretend we're not in the hot-spot. */
26668 Draw a vertical window border to the right of window W if W doesn't
26669 have vertical scroll bars. */
26672 x_draw_vertical_border (struct window
*w
)
26674 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26676 /* We could do better, if we knew what type of scroll-bar the adjacent
26677 windows (on either side) have... But we don't :-(
26678 However, I think this works ok. ++KFS 2003-04-25 */
26680 /* Redraw borders between horizontally adjacent windows. Don't
26681 do it for frames with vertical scroll bars because either the
26682 right scroll bar of a window, or the left scroll bar of its
26683 neighbor will suffice as a border. */
26684 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
26687 if (!WINDOW_RIGHTMOST_P (w
)
26688 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
26690 int x0
, x1
, y0
, y1
;
26692 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26695 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26698 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
26700 else if (!WINDOW_LEFTMOST_P (w
)
26701 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
26703 int x0
, x1
, y0
, y1
;
26705 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26708 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26711 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
26716 /* Redraw the part of window W intersection rectangle FR. Pixel
26717 coordinates in FR are frame-relative. Call this function with
26718 input blocked. Value is non-zero if the exposure overwrites
26722 expose_window (struct window
*w
, XRectangle
*fr
)
26724 struct frame
*f
= XFRAME (w
->frame
);
26726 int mouse_face_overwritten_p
= 0;
26728 /* If window is not yet fully initialized, do nothing. This can
26729 happen when toolkit scroll bars are used and a window is split.
26730 Reconfiguring the scroll bar will generate an expose for a newly
26732 if (w
->current_matrix
== NULL
)
26735 /* When we're currently updating the window, display and current
26736 matrix usually don't agree. Arrange for a thorough display
26738 if (w
== updated_window
)
26740 SET_FRAME_GARBAGED (f
);
26744 /* Frame-relative pixel rectangle of W. */
26745 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
26746 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
26747 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
26748 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
26750 if (x_intersect_rectangles (fr
, &wr
, &r
))
26752 int yb
= window_text_bottom_y (w
);
26753 struct glyph_row
*row
;
26754 int cursor_cleared_p
;
26755 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
26757 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
26758 r
.x
, r
.y
, r
.width
, r
.height
));
26760 /* Convert to window coordinates. */
26761 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
26762 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
26764 /* Turn off the cursor. */
26765 if (!w
->pseudo_window_p
26766 && phys_cursor_in_rect_p (w
, &r
))
26768 x_clear_cursor (w
);
26769 cursor_cleared_p
= 1;
26772 cursor_cleared_p
= 0;
26774 /* Update lines intersecting rectangle R. */
26775 first_overlapping_row
= last_overlapping_row
= NULL
;
26776 for (row
= w
->current_matrix
->rows
;
26781 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
26783 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
26784 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
26785 || (r
.y
>= y0
&& r
.y
< y1
)
26786 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
26788 /* A header line may be overlapping, but there is no need
26789 to fix overlapping areas for them. KFS 2005-02-12 */
26790 if (row
->overlapping_p
&& !row
->mode_line_p
)
26792 if (first_overlapping_row
== NULL
)
26793 first_overlapping_row
= row
;
26794 last_overlapping_row
= row
;
26798 if (expose_line (w
, row
, &r
))
26799 mouse_face_overwritten_p
= 1;
26802 else if (row
->overlapping_p
)
26804 /* We must redraw a row overlapping the exposed area. */
26806 ? y0
+ row
->phys_height
> r
.y
26807 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
26809 if (first_overlapping_row
== NULL
)
26810 first_overlapping_row
= row
;
26811 last_overlapping_row
= row
;
26819 /* Display the mode line if there is one. */
26820 if (WINDOW_WANTS_MODELINE_P (w
)
26821 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
26823 && row
->y
< r
.y
+ r
.height
)
26825 if (expose_line (w
, row
, &r
))
26826 mouse_face_overwritten_p
= 1;
26829 if (!w
->pseudo_window_p
)
26831 /* Fix the display of overlapping rows. */
26832 if (first_overlapping_row
)
26833 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
26836 /* Draw border between windows. */
26837 x_draw_vertical_border (w
);
26839 /* Turn the cursor on again. */
26840 if (cursor_cleared_p
)
26841 update_window_cursor (w
, 1);
26845 return mouse_face_overwritten_p
;
26850 /* Redraw (parts) of all windows in the window tree rooted at W that
26851 intersect R. R contains frame pixel coordinates. Value is
26852 non-zero if the exposure overwrites mouse-face. */
26855 expose_window_tree (struct window
*w
, XRectangle
*r
)
26857 struct frame
*f
= XFRAME (w
->frame
);
26858 int mouse_face_overwritten_p
= 0;
26860 while (w
&& !FRAME_GARBAGED_P (f
))
26862 if (!NILP (w
->hchild
))
26863 mouse_face_overwritten_p
26864 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
26865 else if (!NILP (w
->vchild
))
26866 mouse_face_overwritten_p
26867 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
26869 mouse_face_overwritten_p
|= expose_window (w
, r
);
26871 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
26874 return mouse_face_overwritten_p
;
26879 Redisplay an exposed area of frame F. X and Y are the upper-left
26880 corner of the exposed rectangle. W and H are width and height of
26881 the exposed area. All are pixel values. W or H zero means redraw
26882 the entire frame. */
26885 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
26888 int mouse_face_overwritten_p
= 0;
26890 TRACE ((stderr
, "expose_frame "));
26892 /* No need to redraw if frame will be redrawn soon. */
26893 if (FRAME_GARBAGED_P (f
))
26895 TRACE ((stderr
, " garbaged\n"));
26899 /* If basic faces haven't been realized yet, there is no point in
26900 trying to redraw anything. This can happen when we get an expose
26901 event while Emacs is starting, e.g. by moving another window. */
26902 if (FRAME_FACE_CACHE (f
) == NULL
26903 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
26905 TRACE ((stderr
, " no faces\n"));
26909 if (w
== 0 || h
== 0)
26912 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
26913 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
26923 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
26924 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
26926 if (WINDOWP (f
->tool_bar_window
))
26927 mouse_face_overwritten_p
26928 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
26930 #ifdef HAVE_X_WINDOWS
26932 #ifndef USE_X_TOOLKIT
26933 if (WINDOWP (f
->menu_bar_window
))
26934 mouse_face_overwritten_p
26935 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
26936 #endif /* not USE_X_TOOLKIT */
26940 /* Some window managers support a focus-follows-mouse style with
26941 delayed raising of frames. Imagine a partially obscured frame,
26942 and moving the mouse into partially obscured mouse-face on that
26943 frame. The visible part of the mouse-face will be highlighted,
26944 then the WM raises the obscured frame. With at least one WM, KDE
26945 2.1, Emacs is not getting any event for the raising of the frame
26946 (even tried with SubstructureRedirectMask), only Expose events.
26947 These expose events will draw text normally, i.e. not
26948 highlighted. Which means we must redo the highlight here.
26949 Subsume it under ``we love X''. --gerd 2001-08-15 */
26950 /* Included in Windows version because Windows most likely does not
26951 do the right thing if any third party tool offers
26952 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
26953 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
26955 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26956 if (f
== hlinfo
->mouse_face_mouse_frame
)
26958 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
26959 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
26960 clear_mouse_face (hlinfo
);
26961 note_mouse_highlight (f
, mouse_x
, mouse_y
);
26968 Determine the intersection of two rectangles R1 and R2. Return
26969 the intersection in *RESULT. Value is non-zero if RESULT is not
26973 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
26975 XRectangle
*left
, *right
;
26976 XRectangle
*upper
, *lower
;
26977 int intersection_p
= 0;
26979 /* Rearrange so that R1 is the left-most rectangle. */
26981 left
= r1
, right
= r2
;
26983 left
= r2
, right
= r1
;
26985 /* X0 of the intersection is right.x0, if this is inside R1,
26986 otherwise there is no intersection. */
26987 if (right
->x
<= left
->x
+ left
->width
)
26989 result
->x
= right
->x
;
26991 /* The right end of the intersection is the minimum of the
26992 the right ends of left and right. */
26993 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
26996 /* Same game for Y. */
26998 upper
= r1
, lower
= r2
;
27000 upper
= r2
, lower
= r1
;
27002 /* The upper end of the intersection is lower.y0, if this is inside
27003 of upper. Otherwise, there is no intersection. */
27004 if (lower
->y
<= upper
->y
+ upper
->height
)
27006 result
->y
= lower
->y
;
27008 /* The lower end of the intersection is the minimum of the lower
27009 ends of upper and lower. */
27010 result
->height
= (min (lower
->y
+ lower
->height
,
27011 upper
->y
+ upper
->height
)
27013 intersection_p
= 1;
27017 return intersection_p
;
27020 #endif /* HAVE_WINDOW_SYSTEM */
27023 /***********************************************************************
27025 ***********************************************************************/
27028 syms_of_xdisp (void)
27030 Vwith_echo_area_save_vector
= Qnil
;
27031 staticpro (&Vwith_echo_area_save_vector
);
27033 Vmessage_stack
= Qnil
;
27034 staticpro (&Vmessage_stack
);
27036 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
27037 staticpro (&Qinhibit_redisplay
);
27039 message_dolog_marker1
= Fmake_marker ();
27040 staticpro (&message_dolog_marker1
);
27041 message_dolog_marker2
= Fmake_marker ();
27042 staticpro (&message_dolog_marker2
);
27043 message_dolog_marker3
= Fmake_marker ();
27044 staticpro (&message_dolog_marker3
);
27047 defsubr (&Sdump_frame_glyph_matrix
);
27048 defsubr (&Sdump_glyph_matrix
);
27049 defsubr (&Sdump_glyph_row
);
27050 defsubr (&Sdump_tool_bar_row
);
27051 defsubr (&Strace_redisplay
);
27052 defsubr (&Strace_to_stderr
);
27054 #ifdef HAVE_WINDOW_SYSTEM
27055 defsubr (&Stool_bar_lines_needed
);
27056 defsubr (&Slookup_image_map
);
27058 defsubr (&Sformat_mode_line
);
27059 defsubr (&Sinvisible_p
);
27060 defsubr (&Scurrent_bidi_paragraph_direction
);
27062 staticpro (&Qmenu_bar_update_hook
);
27063 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
27065 staticpro (&Qoverriding_terminal_local_map
);
27066 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
27068 staticpro (&Qoverriding_local_map
);
27069 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
27071 staticpro (&Qwindow_scroll_functions
);
27072 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
27074 staticpro (&Qwindow_text_change_functions
);
27075 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
27077 staticpro (&Qredisplay_end_trigger_functions
);
27078 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
27080 staticpro (&Qinhibit_point_motion_hooks
);
27081 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
27083 Qeval
= intern_c_string ("eval");
27084 staticpro (&Qeval
);
27086 QCdata
= intern_c_string (":data");
27087 staticpro (&QCdata
);
27088 Qdisplay
= intern_c_string ("display");
27089 staticpro (&Qdisplay
);
27090 Qspace_width
= intern_c_string ("space-width");
27091 staticpro (&Qspace_width
);
27092 Qraise
= intern_c_string ("raise");
27093 staticpro (&Qraise
);
27094 Qslice
= intern_c_string ("slice");
27095 staticpro (&Qslice
);
27096 Qspace
= intern_c_string ("space");
27097 staticpro (&Qspace
);
27098 Qmargin
= intern_c_string ("margin");
27099 staticpro (&Qmargin
);
27100 Qpointer
= intern_c_string ("pointer");
27101 staticpro (&Qpointer
);
27102 Qleft_margin
= intern_c_string ("left-margin");
27103 staticpro (&Qleft_margin
);
27104 Qright_margin
= intern_c_string ("right-margin");
27105 staticpro (&Qright_margin
);
27106 Qcenter
= intern_c_string ("center");
27107 staticpro (&Qcenter
);
27108 Qline_height
= intern_c_string ("line-height");
27109 staticpro (&Qline_height
);
27110 QCalign_to
= intern_c_string (":align-to");
27111 staticpro (&QCalign_to
);
27112 QCrelative_width
= intern_c_string (":relative-width");
27113 staticpro (&QCrelative_width
);
27114 QCrelative_height
= intern_c_string (":relative-height");
27115 staticpro (&QCrelative_height
);
27116 QCeval
= intern_c_string (":eval");
27117 staticpro (&QCeval
);
27118 QCpropertize
= intern_c_string (":propertize");
27119 staticpro (&QCpropertize
);
27120 QCfile
= intern_c_string (":file");
27121 staticpro (&QCfile
);
27122 Qfontified
= intern_c_string ("fontified");
27123 staticpro (&Qfontified
);
27124 Qfontification_functions
= intern_c_string ("fontification-functions");
27125 staticpro (&Qfontification_functions
);
27126 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
27127 staticpro (&Qtrailing_whitespace
);
27128 Qescape_glyph
= intern_c_string ("escape-glyph");
27129 staticpro (&Qescape_glyph
);
27130 Qnobreak_space
= intern_c_string ("nobreak-space");
27131 staticpro (&Qnobreak_space
);
27132 Qimage
= intern_c_string ("image");
27133 staticpro (&Qimage
);
27134 Qtext
= intern_c_string ("text");
27135 staticpro (&Qtext
);
27136 Qboth
= intern_c_string ("both");
27137 staticpro (&Qboth
);
27138 Qboth_horiz
= intern_c_string ("both-horiz");
27139 staticpro (&Qboth_horiz
);
27140 Qtext_image_horiz
= intern_c_string ("text-image-horiz");
27141 staticpro (&Qtext_image_horiz
);
27142 QCmap
= intern_c_string (":map");
27143 staticpro (&QCmap
);
27144 QCpointer
= intern_c_string (":pointer");
27145 staticpro (&QCpointer
);
27146 Qrect
= intern_c_string ("rect");
27147 staticpro (&Qrect
);
27148 Qcircle
= intern_c_string ("circle");
27149 staticpro (&Qcircle
);
27150 Qpoly
= intern_c_string ("poly");
27151 staticpro (&Qpoly
);
27152 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
27153 staticpro (&Qmessage_truncate_lines
);
27154 Qgrow_only
= intern_c_string ("grow-only");
27155 staticpro (&Qgrow_only
);
27156 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
27157 staticpro (&Qinhibit_menubar_update
);
27158 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
27159 staticpro (&Qinhibit_eval_during_redisplay
);
27160 Qposition
= intern_c_string ("position");
27161 staticpro (&Qposition
);
27162 Qbuffer_position
= intern_c_string ("buffer-position");
27163 staticpro (&Qbuffer_position
);
27164 Qobject
= intern_c_string ("object");
27165 staticpro (&Qobject
);
27166 Qbar
= intern_c_string ("bar");
27168 Qhbar
= intern_c_string ("hbar");
27169 staticpro (&Qhbar
);
27170 Qbox
= intern_c_string ("box");
27172 Qhollow
= intern_c_string ("hollow");
27173 staticpro (&Qhollow
);
27174 Qhand
= intern_c_string ("hand");
27175 staticpro (&Qhand
);
27176 Qarrow
= intern_c_string ("arrow");
27177 staticpro (&Qarrow
);
27178 Qtext
= intern_c_string ("text");
27179 staticpro (&Qtext
);
27180 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
27181 staticpro (&Qinhibit_free_realized_faces
);
27183 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
27184 Fcons (intern_c_string ("void-variable"), Qnil
)),
27186 staticpro (&list_of_error
);
27188 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
27189 staticpro (&Qlast_arrow_position
);
27190 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
27191 staticpro (&Qlast_arrow_string
);
27193 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
27194 staticpro (&Qoverlay_arrow_string
);
27195 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
27196 staticpro (&Qoverlay_arrow_bitmap
);
27198 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
27199 staticpro (&echo_buffer
[0]);
27200 staticpro (&echo_buffer
[1]);
27202 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
27203 staticpro (&echo_area_buffer
[0]);
27204 staticpro (&echo_area_buffer
[1]);
27206 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
27207 staticpro (&Vmessages_buffer_name
);
27209 mode_line_proptrans_alist
= Qnil
;
27210 staticpro (&mode_line_proptrans_alist
);
27211 mode_line_string_list
= Qnil
;
27212 staticpro (&mode_line_string_list
);
27213 mode_line_string_face
= Qnil
;
27214 staticpro (&mode_line_string_face
);
27215 mode_line_string_face_prop
= Qnil
;
27216 staticpro (&mode_line_string_face_prop
);
27217 Vmode_line_unwind_vector
= Qnil
;
27218 staticpro (&Vmode_line_unwind_vector
);
27220 help_echo_string
= Qnil
;
27221 staticpro (&help_echo_string
);
27222 help_echo_object
= Qnil
;
27223 staticpro (&help_echo_object
);
27224 help_echo_window
= Qnil
;
27225 staticpro (&help_echo_window
);
27226 previous_help_echo_string
= Qnil
;
27227 staticpro (&previous_help_echo_string
);
27228 help_echo_pos
= -1;
27230 Qright_to_left
= intern_c_string ("right-to-left");
27231 staticpro (&Qright_to_left
);
27232 Qleft_to_right
= intern_c_string ("left-to-right");
27233 staticpro (&Qleft_to_right
);
27235 #ifdef HAVE_WINDOW_SYSTEM
27236 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
27237 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
27238 For example, if a block cursor is over a tab, it will be drawn as
27239 wide as that tab on the display. */);
27240 x_stretch_cursor_p
= 0;
27243 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
27244 doc
: /* *Non-nil means highlight trailing whitespace.
27245 The face used for trailing whitespace is `trailing-whitespace'. */);
27246 Vshow_trailing_whitespace
= Qnil
;
27248 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
27249 doc
: /* *Control highlighting of nobreak space and soft hyphen.
27250 A value of t means highlight the character itself (for nobreak space,
27251 use face `nobreak-space').
27252 A value of nil means no highlighting.
27253 Other values mean display the escape glyph followed by an ordinary
27254 space or ordinary hyphen. */);
27255 Vnobreak_char_display
= Qt
;
27257 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
27258 doc
: /* *The pointer shape to show in void text areas.
27259 A value of nil means to show the text pointer. Other options are `arrow',
27260 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
27261 Vvoid_text_area_pointer
= Qarrow
;
27263 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
27264 doc
: /* Non-nil means don't actually do any redisplay.
27265 This is used for internal purposes. */);
27266 Vinhibit_redisplay
= Qnil
;
27268 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
27269 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
27270 Vglobal_mode_string
= Qnil
;
27272 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
27273 doc
: /* Marker for where to display an arrow on top of the buffer text.
27274 This must be the beginning of a line in order to work.
27275 See also `overlay-arrow-string'. */);
27276 Voverlay_arrow_position
= Qnil
;
27278 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
27279 doc
: /* String to display as an arrow in non-window frames.
27280 See also `overlay-arrow-position'. */);
27281 Voverlay_arrow_string
= make_pure_c_string ("=>");
27283 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
27284 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
27285 The symbols on this list are examined during redisplay to determine
27286 where to display overlay arrows. */);
27287 Voverlay_arrow_variable_list
27288 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
27290 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
27291 doc
: /* *The number of lines to try scrolling a window by when point moves out.
27292 If that fails to bring point back on frame, point is centered instead.
27293 If this is zero, point is always centered after it moves off frame.
27294 If you want scrolling to always be a line at a time, you should set
27295 `scroll-conservatively' to a large value rather than set this to 1. */);
27297 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
27298 doc
: /* *Scroll up to this many lines, to bring point back on screen.
27299 If point moves off-screen, redisplay will scroll by up to
27300 `scroll-conservatively' lines in order to bring point just barely
27301 onto the screen again. If that cannot be done, then redisplay
27302 recenters point as usual.
27304 If the value is greater than 100, redisplay will never recenter point,
27305 but will always scroll just enough text to bring point into view, even
27306 if you move far away.
27308 A value of zero means always recenter point if it moves off screen. */);
27309 scroll_conservatively
= 0;
27311 DEFVAR_INT ("scroll-margin", scroll_margin
,
27312 doc
: /* *Number of lines of margin at the top and bottom of a window.
27313 Recenter the window whenever point gets within this many lines
27314 of the top or bottom of the window. */);
27317 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
27318 doc
: /* Pixels per inch value for non-window system displays.
27319 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
27320 Vdisplay_pixels_per_inch
= make_float (72.0);
27323 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
27326 DEFVAR_LISP ("truncate-partial-width-windows",
27327 Vtruncate_partial_width_windows
,
27328 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
27329 For an integer value, truncate lines in each window narrower than the
27330 full frame width, provided the window width is less than that integer;
27331 otherwise, respect the value of `truncate-lines'.
27333 For any other non-nil value, truncate lines in all windows that do
27334 not span the full frame width.
27336 A value of nil means to respect the value of `truncate-lines'.
27338 If `word-wrap' is enabled, you might want to reduce this. */);
27339 Vtruncate_partial_width_windows
= make_number (50);
27341 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
27342 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
27343 Any other value means to use the appropriate face, `mode-line',
27344 `header-line', or `menu' respectively. */);
27345 mode_line_inverse_video
= 1;
27347 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
27348 doc
: /* *Maximum buffer size for which line number should be displayed.
27349 If the buffer is bigger than this, the line number does not appear
27350 in the mode line. A value of nil means no limit. */);
27351 Vline_number_display_limit
= Qnil
;
27353 DEFVAR_INT ("line-number-display-limit-width",
27354 line_number_display_limit_width
,
27355 doc
: /* *Maximum line width (in characters) for line number display.
27356 If the average length of the lines near point is bigger than this, then the
27357 line number may be omitted from the mode line. */);
27358 line_number_display_limit_width
= 200;
27360 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
27361 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
27362 highlight_nonselected_windows
= 0;
27364 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
27365 doc
: /* Non-nil if more than one frame is visible on this display.
27366 Minibuffer-only frames don't count, but iconified frames do.
27367 This variable is not guaranteed to be accurate except while processing
27368 `frame-title-format' and `icon-title-format'. */);
27370 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
27371 doc
: /* Template for displaying the title bar of visible frames.
27372 \(Assuming the window manager supports this feature.)
27374 This variable has the same structure as `mode-line-format', except that
27375 the %c and %l constructs are ignored. It is used only on frames for
27376 which no explicit name has been set \(see `modify-frame-parameters'). */);
27378 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
27379 doc
: /* Template for displaying the title bar of an iconified frame.
27380 \(Assuming the window manager supports this feature.)
27381 This variable has the same structure as `mode-line-format' (which see),
27382 and is used only on frames for which no explicit name has been set
27383 \(see `modify-frame-parameters'). */);
27385 = Vframe_title_format
27386 = pure_cons (intern_c_string ("multiple-frames"),
27387 pure_cons (make_pure_c_string ("%b"),
27388 pure_cons (pure_cons (empty_unibyte_string
,
27389 pure_cons (intern_c_string ("invocation-name"),
27390 pure_cons (make_pure_c_string ("@"),
27391 pure_cons (intern_c_string ("system-name"),
27395 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
27396 doc
: /* Maximum number of lines to keep in the message log buffer.
27397 If nil, disable message logging. If t, log messages but don't truncate
27398 the buffer when it becomes large. */);
27399 Vmessage_log_max
= make_number (100);
27401 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
27402 doc
: /* Functions called before redisplay, if window sizes have changed.
27403 The value should be a list of functions that take one argument.
27404 Just before redisplay, for each frame, if any of its windows have changed
27405 size since the last redisplay, or have been split or deleted,
27406 all the functions in the list are called, with the frame as argument. */);
27407 Vwindow_size_change_functions
= Qnil
;
27409 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
27410 doc
: /* List of functions to call before redisplaying a window with scrolling.
27411 Each function is called with two arguments, the window and its new
27412 display-start position. Note that these functions are also called by
27413 `set-window-buffer'. Also note that the value of `window-end' is not
27414 valid when these functions are called. */);
27415 Vwindow_scroll_functions
= Qnil
;
27417 DEFVAR_LISP ("window-text-change-functions",
27418 Vwindow_text_change_functions
,
27419 doc
: /* Functions to call in redisplay when text in the window might change. */);
27420 Vwindow_text_change_functions
= Qnil
;
27422 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
27423 doc
: /* Functions called when redisplay of a window reaches the end trigger.
27424 Each function is called with two arguments, the window and the end trigger value.
27425 See `set-window-redisplay-end-trigger'. */);
27426 Vredisplay_end_trigger_functions
= Qnil
;
27428 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
27429 doc
: /* *Non-nil means autoselect window with mouse pointer.
27430 If nil, do not autoselect windows.
27431 A positive number means delay autoselection by that many seconds: a
27432 window is autoselected only after the mouse has remained in that
27433 window for the duration of the delay.
27434 A negative number has a similar effect, but causes windows to be
27435 autoselected only after the mouse has stopped moving. \(Because of
27436 the way Emacs compares mouse events, you will occasionally wait twice
27437 that time before the window gets selected.\)
27438 Any other value means to autoselect window instantaneously when the
27439 mouse pointer enters it.
27441 Autoselection selects the minibuffer only if it is active, and never
27442 unselects the minibuffer if it is active.
27444 When customizing this variable make sure that the actual value of
27445 `focus-follows-mouse' matches the behavior of your window manager. */);
27446 Vmouse_autoselect_window
= Qnil
;
27448 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
27449 doc
: /* *Non-nil means automatically resize tool-bars.
27450 This dynamically changes the tool-bar's height to the minimum height
27451 that is needed to make all tool-bar items visible.
27452 If value is `grow-only', the tool-bar's height is only increased
27453 automatically; to decrease the tool-bar height, use \\[recenter]. */);
27454 Vauto_resize_tool_bars
= Qt
;
27456 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
27457 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
27458 auto_raise_tool_bar_buttons_p
= 1;
27460 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
27461 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
27462 make_cursor_line_fully_visible_p
= 1;
27464 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
27465 doc
: /* *Border below tool-bar in pixels.
27466 If an integer, use it as the height of the border.
27467 If it is one of `internal-border-width' or `border-width', use the
27468 value of the corresponding frame parameter.
27469 Otherwise, no border is added below the tool-bar. */);
27470 Vtool_bar_border
= Qinternal_border_width
;
27472 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
27473 doc
: /* *Margin around tool-bar buttons in pixels.
27474 If an integer, use that for both horizontal and vertical margins.
27475 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
27476 HORZ specifying the horizontal margin, and VERT specifying the
27477 vertical margin. */);
27478 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
27480 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
27481 doc
: /* *Relief thickness of tool-bar buttons. */);
27482 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
27484 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
27485 doc
: /* Tool bar style to use.
27487 image - show images only
27488 text - show text only
27489 both - show both, text below image
27490 both-horiz - show text to the right of the image
27491 text-image-horiz - show text to the left of the image
27492 any other - use system default or image if no system default. */);
27493 Vtool_bar_style
= Qnil
;
27495 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
27496 doc
: /* *Maximum number of characters a label can have to be shown.
27497 The tool bar style must also show labels for this to have any effect, see
27498 `tool-bar-style'. */);
27499 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
27501 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
27502 doc
: /* List of functions to call to fontify regions of text.
27503 Each function is called with one argument POS. Functions must
27504 fontify a region starting at POS in the current buffer, and give
27505 fontified regions the property `fontified'. */);
27506 Vfontification_functions
= Qnil
;
27507 Fmake_variable_buffer_local (Qfontification_functions
);
27509 DEFVAR_BOOL ("unibyte-display-via-language-environment",
27510 unibyte_display_via_language_environment
,
27511 doc
: /* *Non-nil means display unibyte text according to language environment.
27512 Specifically, this means that raw bytes in the range 160-255 decimal
27513 are displayed by converting them to the equivalent multibyte characters
27514 according to the current language environment. As a result, they are
27515 displayed according to the current fontset.
27517 Note that this variable affects only how these bytes are displayed,
27518 but does not change the fact they are interpreted as raw bytes. */);
27519 unibyte_display_via_language_environment
= 0;
27521 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
27522 doc
: /* *Maximum height for resizing mini-windows.
27523 If a float, it specifies a fraction of the mini-window frame's height.
27524 If an integer, it specifies a number of lines. */);
27525 Vmax_mini_window_height
= make_float (0.25);
27527 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
27528 doc
: /* *How to resize mini-windows.
27529 A value of nil means don't automatically resize mini-windows.
27530 A value of t means resize them to fit the text displayed in them.
27531 A value of `grow-only', the default, means let mini-windows grow
27532 only, until their display becomes empty, at which point the windows
27533 go back to their normal size. */);
27534 Vresize_mini_windows
= Qgrow_only
;
27536 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
27537 doc
: /* Alist specifying how to blink the cursor off.
27538 Each element has the form (ON-STATE . OFF-STATE). Whenever the
27539 `cursor-type' frame-parameter or variable equals ON-STATE,
27540 comparing using `equal', Emacs uses OFF-STATE to specify
27541 how to blink it off. ON-STATE and OFF-STATE are values for
27542 the `cursor-type' frame parameter.
27544 If a frame's ON-STATE has no entry in this list,
27545 the frame's other specifications determine how to blink the cursor off. */);
27546 Vblink_cursor_alist
= Qnil
;
27548 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
27549 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
27550 If non-nil, windows are automatically scrolled horizontally to make
27551 point visible. */);
27552 automatic_hscrolling_p
= 1;
27553 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
27554 staticpro (&Qauto_hscroll_mode
);
27556 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
27557 doc
: /* *How many columns away from the window edge point is allowed to get
27558 before automatic hscrolling will horizontally scroll the window. */);
27559 hscroll_margin
= 5;
27561 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
27562 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
27563 When point is less than `hscroll-margin' columns from the window
27564 edge, automatic hscrolling will scroll the window by the amount of columns
27565 determined by this variable. If its value is a positive integer, scroll that
27566 many columns. If it's a positive floating-point number, it specifies the
27567 fraction of the window's width to scroll. If it's nil or zero, point will be
27568 centered horizontally after the scroll. Any other value, including negative
27569 numbers, are treated as if the value were zero.
27571 Automatic hscrolling always moves point outside the scroll margin, so if
27572 point was more than scroll step columns inside the margin, the window will
27573 scroll more than the value given by the scroll step.
27575 Note that the lower bound for automatic hscrolling specified by `scroll-left'
27576 and `scroll-right' overrides this variable's effect. */);
27577 Vhscroll_step
= make_number (0);
27579 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
27580 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
27581 Bind this around calls to `message' to let it take effect. */);
27582 message_truncate_lines
= 0;
27584 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
27585 doc
: /* Normal hook run to update the menu bar definitions.
27586 Redisplay runs this hook before it redisplays the menu bar.
27587 This is used to update submenus such as Buffers,
27588 whose contents depend on various data. */);
27589 Vmenu_bar_update_hook
= Qnil
;
27591 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
27592 doc
: /* Frame for which we are updating a menu.
27593 The enable predicate for a menu binding should check this variable. */);
27594 Vmenu_updating_frame
= Qnil
;
27596 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
27597 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
27598 inhibit_menubar_update
= 0;
27600 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
27601 doc
: /* Prefix prepended to all continuation lines at display time.
27602 The value may be a string, an image, or a stretch-glyph; it is
27603 interpreted in the same way as the value of a `display' text property.
27605 This variable is overridden by any `wrap-prefix' text or overlay
27608 To add a prefix to non-continuation lines, use `line-prefix'. */);
27609 Vwrap_prefix
= Qnil
;
27610 staticpro (&Qwrap_prefix
);
27611 Qwrap_prefix
= intern_c_string ("wrap-prefix");
27612 Fmake_variable_buffer_local (Qwrap_prefix
);
27614 DEFVAR_LISP ("line-prefix", Vline_prefix
,
27615 doc
: /* Prefix prepended to all non-continuation lines at display time.
27616 The value may be a string, an image, or a stretch-glyph; it is
27617 interpreted in the same way as the value of a `display' text property.
27619 This variable is overridden by any `line-prefix' text or overlay
27622 To add a prefix to continuation lines, use `wrap-prefix'. */);
27623 Vline_prefix
= Qnil
;
27624 staticpro (&Qline_prefix
);
27625 Qline_prefix
= intern_c_string ("line-prefix");
27626 Fmake_variable_buffer_local (Qline_prefix
);
27628 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
27629 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
27630 inhibit_eval_during_redisplay
= 0;
27632 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
27633 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
27634 inhibit_free_realized_faces
= 0;
27637 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
27638 doc
: /* Inhibit try_window_id display optimization. */);
27639 inhibit_try_window_id
= 0;
27641 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
27642 doc
: /* Inhibit try_window_reusing display optimization. */);
27643 inhibit_try_window_reusing
= 0;
27645 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
27646 doc
: /* Inhibit try_cursor_movement display optimization. */);
27647 inhibit_try_cursor_movement
= 0;
27648 #endif /* GLYPH_DEBUG */
27650 DEFVAR_INT ("overline-margin", overline_margin
,
27651 doc
: /* *Space between overline and text, in pixels.
27652 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
27653 margin to the caracter height. */);
27654 overline_margin
= 2;
27656 DEFVAR_INT ("underline-minimum-offset",
27657 underline_minimum_offset
,
27658 doc
: /* Minimum distance between baseline and underline.
27659 This can improve legibility of underlined text at small font sizes,
27660 particularly when using variable `x-use-underline-position-properties'
27661 with fonts that specify an UNDERLINE_POSITION relatively close to the
27662 baseline. The default value is 1. */);
27663 underline_minimum_offset
= 1;
27665 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
27666 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
27667 This feature only works when on a window system that can change
27668 cursor shapes. */);
27669 display_hourglass_p
= 1;
27671 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
27672 doc
: /* *Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
27673 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
27675 hourglass_atimer
= NULL
;
27676 hourglass_shown_p
= 0;
27678 DEFSYM (Qglyphless_char
, "glyphless-char");
27679 DEFSYM (Qhex_code
, "hex-code");
27680 DEFSYM (Qempty_box
, "empty-box");
27681 DEFSYM (Qthin_space
, "thin-space");
27682 DEFSYM (Qzero_width
, "zero-width");
27684 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
27685 /* Intern this now in case it isn't already done.
27686 Setting this variable twice is harmless.
27687 But don't staticpro it here--that is done in alloc.c. */
27688 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
27689 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
27691 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
27692 doc
: /* Char-table defining glyphless characters.
27693 Each element, if non-nil, should be one of the following:
27694 an ASCII acronym string: display this string in a box
27695 `hex-code': display the hexadecimal code of a character in a box
27696 `empty-box': display as an empty box
27697 `thin-space': display as 1-pixel width space
27698 `zero-width': don't display
27699 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
27700 display method for graphical terminals and text terminals respectively.
27701 GRAPHICAL and TEXT should each have one of the values listed above.
27703 The char-table has one extra slot to control the display of a character for
27704 which no font is found. This slot only takes effect on graphical terminals.
27705 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
27706 `thin-space'. The default is `empty-box'. */);
27707 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
27708 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
27713 /* Initialize this module when Emacs starts. */
27718 Lisp_Object root_window
;
27719 struct window
*mini_w
;
27721 current_header_line_height
= current_mode_line_height
= -1;
27723 CHARPOS (this_line_start_pos
) = 0;
27725 mini_w
= XWINDOW (minibuf_window
);
27726 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
27727 echo_area_window
= minibuf_window
;
27729 if (!noninteractive
)
27731 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
27734 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
27735 set_window_height (root_window
,
27736 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
27738 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
27739 set_window_height (minibuf_window
, 1, 0);
27741 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
27742 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
27744 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
27745 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
27746 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
27748 /* The default ellipsis glyphs `...'. */
27749 for (i
= 0; i
< 3; ++i
)
27750 default_invis_vector
[i
] = make_number ('.');
27754 /* Allocate the buffer for frame titles.
27755 Also used for `format-mode-line'. */
27757 mode_line_noprop_buf
= (char *) xmalloc (size
);
27758 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
27759 mode_line_noprop_ptr
= mode_line_noprop_buf
;
27760 mode_line_target
= MODE_LINE_DISPLAY
;
27763 help_echo_showing_p
= 0;
27766 /* Since w32 does not support atimers, it defines its own implementation of
27767 the following three functions in w32fns.c. */
27770 /* Platform-independent portion of hourglass implementation. */
27772 /* Return non-zero if houglass timer has been started or hourglass is shown. */
27774 hourglass_started (void)
27776 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
27779 /* Cancel a currently active hourglass timer, and start a new one. */
27781 start_hourglass (void)
27783 #if defined (HAVE_WINDOW_SYSTEM)
27785 int secs
, usecs
= 0;
27787 cancel_hourglass ();
27789 if (INTEGERP (Vhourglass_delay
)
27790 && XINT (Vhourglass_delay
) > 0)
27791 secs
= XFASTINT (Vhourglass_delay
);
27792 else if (FLOATP (Vhourglass_delay
)
27793 && XFLOAT_DATA (Vhourglass_delay
) > 0)
27796 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
27797 secs
= XFASTINT (tem
);
27798 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
27801 secs
= DEFAULT_HOURGLASS_DELAY
;
27803 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
27804 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
27805 show_hourglass
, NULL
);
27810 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
27813 cancel_hourglass (void)
27815 #if defined (HAVE_WINDOW_SYSTEM)
27816 if (hourglass_atimer
)
27818 cancel_atimer (hourglass_atimer
);
27819 hourglass_atimer
= NULL
;
27822 if (hourglass_shown_p
)
27826 #endif /* ! WINDOWSNT */