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;
4485 it
->string_from_display_prop_p
= 1;
4486 /* Say that we haven't consumed the characters with
4487 `display' property yet. The call to pop_it in
4488 set_iterator_to_next will clean this up. */
4489 if (BUFFERP (object
))
4490 *position
= start_pos
;
4492 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4494 it
->method
= GET_FROM_STRETCH
;
4496 *position
= it
->position
= start_pos
;
4498 #ifdef HAVE_WINDOW_SYSTEM
4501 it
->what
= IT_IMAGE
;
4502 it
->image_id
= lookup_image (it
->f
, value
);
4503 it
->position
= start_pos
;
4504 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4505 it
->method
= GET_FROM_IMAGE
;
4507 /* Say that we haven't consumed the characters with
4508 `display' property yet. The call to pop_it in
4509 set_iterator_to_next will clean this up. */
4510 *position
= start_pos
;
4512 #endif /* HAVE_WINDOW_SYSTEM */
4517 /* Invalid property or property not supported. Restore
4518 POSITION to what it was before. */
4519 *position
= start_pos
;
4523 /* Check if PROP is a display property value whose text should be
4524 treated as intangible. OVERLAY is the overlay from which PROP
4525 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4526 specify the buffer position covered by PROP. */
4529 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4530 EMACS_INT charpos
, EMACS_INT bytepos
)
4532 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4533 struct text_pos position
;
4535 SET_TEXT_POS (position
, charpos
, bytepos
);
4536 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4537 &position
, charpos
, frame_window_p
);
4541 /* Return 1 if PROP is a display sub-property value containing STRING.
4543 Implementation note: this and the following function are really
4544 special cases of handle_display_spec and
4545 handle_single_display_spec, and should ideally use the same code.
4546 Until they do, these two pairs must be consistent and must be
4547 modified in sync. */
4550 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4552 if (EQ (string
, prop
))
4555 /* Skip over `when FORM'. */
4556 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4561 /* Actually, the condition following `when' should be eval'ed,
4562 like handle_single_display_spec does, and we should return
4563 zero if it evaluates to nil. However, this function is
4564 called only when the buffer was already displayed and some
4565 glyph in the glyph matrix was found to come from a display
4566 string. Therefore, the condition was already evaluated, and
4567 the result was non-nil, otherwise the display string wouldn't
4568 have been displayed and we would have never been called for
4569 this property. Thus, we can skip the evaluation and assume
4570 its result is non-nil. */
4575 /* Skip over `margin LOCATION'. */
4576 if (EQ (XCAR (prop
), Qmargin
))
4587 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
4591 /* Return 1 if STRING appears in the `display' property PROP. */
4594 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4597 && !EQ (XCAR (prop
), Qwhen
)
4598 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
4600 /* A list of sub-properties. */
4601 while (CONSP (prop
))
4603 if (single_display_spec_string_p (XCAR (prop
), string
))
4608 else if (VECTORP (prop
))
4610 /* A vector of sub-properties. */
4612 for (i
= 0; i
< ASIZE (prop
); ++i
)
4613 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4617 return single_display_spec_string_p (prop
, string
);
4622 /* Look for STRING in overlays and text properties in the current
4623 buffer, between character positions FROM and TO (excluding TO).
4624 BACK_P non-zero means look back (in this case, TO is supposed to be
4626 Value is the first character position where STRING was found, or
4627 zero if it wasn't found before hitting TO.
4629 This function may only use code that doesn't eval because it is
4630 called asynchronously from note_mouse_highlight. */
4633 string_buffer_position_lim (Lisp_Object string
,
4634 EMACS_INT from
, EMACS_INT to
, int back_p
)
4636 Lisp_Object limit
, prop
, pos
;
4639 pos
= make_number (from
);
4641 if (!back_p
) /* looking forward */
4643 limit
= make_number (min (to
, ZV
));
4644 while (!found
&& !EQ (pos
, limit
))
4646 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4647 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4650 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4654 else /* looking back */
4656 limit
= make_number (max (to
, BEGV
));
4657 while (!found
&& !EQ (pos
, limit
))
4659 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4660 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4663 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4668 return found
? XINT (pos
) : 0;
4671 /* Determine which buffer position in current buffer STRING comes from.
4672 AROUND_CHARPOS is an approximate position where it could come from.
4673 Value is the buffer position or 0 if it couldn't be determined.
4675 This function is necessary because we don't record buffer positions
4676 in glyphs generated from strings (to keep struct glyph small).
4677 This function may only use code that doesn't eval because it is
4678 called asynchronously from note_mouse_highlight. */
4681 string_buffer_position (Lisp_Object string
, EMACS_INT around_charpos
)
4683 const int MAX_DISTANCE
= 1000;
4684 EMACS_INT found
= string_buffer_position_lim (string
, around_charpos
,
4685 around_charpos
+ MAX_DISTANCE
,
4689 found
= string_buffer_position_lim (string
, around_charpos
,
4690 around_charpos
- MAX_DISTANCE
, 1);
4696 /***********************************************************************
4697 `composition' property
4698 ***********************************************************************/
4700 /* Set up iterator IT from `composition' property at its current
4701 position. Called from handle_stop. */
4703 static enum prop_handled
4704 handle_composition_prop (struct it
*it
)
4706 Lisp_Object prop
, string
;
4707 EMACS_INT pos
, pos_byte
, start
, end
;
4709 if (STRINGP (it
->string
))
4713 pos
= IT_STRING_CHARPOS (*it
);
4714 pos_byte
= IT_STRING_BYTEPOS (*it
);
4715 string
= it
->string
;
4716 s
= SDATA (string
) + pos_byte
;
4717 it
->c
= STRING_CHAR (s
);
4721 pos
= IT_CHARPOS (*it
);
4722 pos_byte
= IT_BYTEPOS (*it
);
4724 it
->c
= FETCH_CHAR (pos_byte
);
4727 /* If there's a valid composition and point is not inside of the
4728 composition (in the case that the composition is from the current
4729 buffer), draw a glyph composed from the composition components. */
4730 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4731 && COMPOSITION_VALID_P (start
, end
, prop
)
4732 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4736 if (STRINGP (it
->string
))
4737 pos_byte
= string_char_to_byte (it
->string
, start
);
4739 pos_byte
= CHAR_TO_BYTE (start
);
4741 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4744 if (it
->cmp_it
.id
>= 0)
4747 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4748 it
->cmp_it
.nglyphs
= -1;
4752 return HANDLED_NORMALLY
;
4757 /***********************************************************************
4759 ***********************************************************************/
4761 /* The following structure is used to record overlay strings for
4762 later sorting in load_overlay_strings. */
4764 struct overlay_entry
4766 Lisp_Object overlay
;
4773 /* Set up iterator IT from overlay strings at its current position.
4774 Called from handle_stop. */
4776 static enum prop_handled
4777 handle_overlay_change (struct it
*it
)
4779 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4780 return HANDLED_RECOMPUTE_PROPS
;
4782 return HANDLED_NORMALLY
;
4786 /* Set up the next overlay string for delivery by IT, if there is an
4787 overlay string to deliver. Called by set_iterator_to_next when the
4788 end of the current overlay string is reached. If there are more
4789 overlay strings to display, IT->string and
4790 IT->current.overlay_string_index are set appropriately here.
4791 Otherwise IT->string is set to nil. */
4794 next_overlay_string (struct it
*it
)
4796 ++it
->current
.overlay_string_index
;
4797 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4799 /* No more overlay strings. Restore IT's settings to what
4800 they were before overlay strings were processed, and
4801 continue to deliver from current_buffer. */
4803 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4806 || (NILP (it
->string
)
4807 && it
->method
== GET_FROM_BUFFER
4808 && it
->stop_charpos
>= BEGV
4809 && it
->stop_charpos
<= it
->end_charpos
));
4810 it
->current
.overlay_string_index
= -1;
4811 it
->n_overlay_strings
= 0;
4812 it
->overlay_strings_charpos
= -1;
4814 /* If we're at the end of the buffer, record that we have
4815 processed the overlay strings there already, so that
4816 next_element_from_buffer doesn't try it again. */
4817 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4818 it
->overlay_strings_at_end_processed_p
= 1;
4822 /* There are more overlay strings to process. If
4823 IT->current.overlay_string_index has advanced to a position
4824 where we must load IT->overlay_strings with more strings, do
4825 it. We must load at the IT->overlay_strings_charpos where
4826 IT->n_overlay_strings was originally computed; when invisible
4827 text is present, this might not be IT_CHARPOS (Bug#7016). */
4828 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4830 if (it
->current
.overlay_string_index
&& i
== 0)
4831 load_overlay_strings (it
, it
->overlay_strings_charpos
);
4833 /* Initialize IT to deliver display elements from the overlay
4835 it
->string
= it
->overlay_strings
[i
];
4836 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4837 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4838 it
->method
= GET_FROM_STRING
;
4839 it
->stop_charpos
= 0;
4840 if (it
->cmp_it
.stop_pos
>= 0)
4841 it
->cmp_it
.stop_pos
= 0;
4848 /* Compare two overlay_entry structures E1 and E2. Used as a
4849 comparison function for qsort in load_overlay_strings. Overlay
4850 strings for the same position are sorted so that
4852 1. All after-strings come in front of before-strings, except
4853 when they come from the same overlay.
4855 2. Within after-strings, strings are sorted so that overlay strings
4856 from overlays with higher priorities come first.
4858 2. Within before-strings, strings are sorted so that overlay
4859 strings from overlays with higher priorities come last.
4861 Value is analogous to strcmp. */
4865 compare_overlay_entries (const void *e1
, const void *e2
)
4867 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4868 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4871 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4873 /* Let after-strings appear in front of before-strings if
4874 they come from different overlays. */
4875 if (EQ (entry1
->overlay
, entry2
->overlay
))
4876 result
= entry1
->after_string_p
? 1 : -1;
4878 result
= entry1
->after_string_p
? -1 : 1;
4880 else if (entry1
->after_string_p
)
4881 /* After-strings sorted in order of decreasing priority. */
4882 result
= entry2
->priority
- entry1
->priority
;
4884 /* Before-strings sorted in order of increasing priority. */
4885 result
= entry1
->priority
- entry2
->priority
;
4891 /* Load the vector IT->overlay_strings with overlay strings from IT's
4892 current buffer position, or from CHARPOS if that is > 0. Set
4893 IT->n_overlays to the total number of overlay strings found.
4895 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4896 a time. On entry into load_overlay_strings,
4897 IT->current.overlay_string_index gives the number of overlay
4898 strings that have already been loaded by previous calls to this
4901 IT->add_overlay_start contains an additional overlay start
4902 position to consider for taking overlay strings from, if non-zero.
4903 This position comes into play when the overlay has an `invisible'
4904 property, and both before and after-strings. When we've skipped to
4905 the end of the overlay, because of its `invisible' property, we
4906 nevertheless want its before-string to appear.
4907 IT->add_overlay_start will contain the overlay start position
4910 Overlay strings are sorted so that after-string strings come in
4911 front of before-string strings. Within before and after-strings,
4912 strings are sorted by overlay priority. See also function
4913 compare_overlay_entries. */
4916 load_overlay_strings (struct it
*it
, EMACS_INT charpos
)
4918 Lisp_Object overlay
, window
, str
, invisible
;
4919 struct Lisp_Overlay
*ov
;
4920 EMACS_INT start
, end
;
4922 int n
= 0, i
, j
, invis_p
;
4923 struct overlay_entry
*entries
4924 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4927 charpos
= IT_CHARPOS (*it
);
4929 /* Append the overlay string STRING of overlay OVERLAY to vector
4930 `entries' which has size `size' and currently contains `n'
4931 elements. AFTER_P non-zero means STRING is an after-string of
4933 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4936 Lisp_Object priority; \
4940 int new_size = 2 * size; \
4941 struct overlay_entry *old = entries; \
4943 (struct overlay_entry *) alloca (new_size \
4944 * sizeof *entries); \
4945 memcpy (entries, old, size * sizeof *entries); \
4949 entries[n].string = (STRING); \
4950 entries[n].overlay = (OVERLAY); \
4951 priority = Foverlay_get ((OVERLAY), Qpriority); \
4952 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4953 entries[n].after_string_p = (AFTER_P); \
4958 /* Process overlay before the overlay center. */
4959 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4961 XSETMISC (overlay
, ov
);
4962 xassert (OVERLAYP (overlay
));
4963 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4964 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4969 /* Skip this overlay if it doesn't start or end at IT's current
4971 if (end
!= charpos
&& start
!= charpos
)
4974 /* Skip this overlay if it doesn't apply to IT->w. */
4975 window
= Foverlay_get (overlay
, Qwindow
);
4976 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4979 /* If the text ``under'' the overlay is invisible, both before-
4980 and after-strings from this overlay are visible; start and
4981 end position are indistinguishable. */
4982 invisible
= Foverlay_get (overlay
, Qinvisible
);
4983 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4985 /* If overlay has a non-empty before-string, record it. */
4986 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4987 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4989 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4991 /* If overlay has a non-empty after-string, record it. */
4992 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4993 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4995 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4998 /* Process overlays after the overlay center. */
4999 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5001 XSETMISC (overlay
, ov
);
5002 xassert (OVERLAYP (overlay
));
5003 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5004 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5006 if (start
> charpos
)
5009 /* Skip this overlay if it doesn't start or end at IT's current
5011 if (end
!= charpos
&& start
!= charpos
)
5014 /* Skip this overlay if it doesn't apply to IT->w. */
5015 window
= Foverlay_get (overlay
, Qwindow
);
5016 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5019 /* If the text ``under'' the overlay is invisible, it has a zero
5020 dimension, and both before- and after-strings apply. */
5021 invisible
= Foverlay_get (overlay
, Qinvisible
);
5022 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5024 /* If overlay has a non-empty before-string, record it. */
5025 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5026 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5028 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5030 /* If overlay has a non-empty after-string, record it. */
5031 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5032 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5034 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5037 #undef RECORD_OVERLAY_STRING
5041 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5043 /* Record number of overlay strings, and where we computed it. */
5044 it
->n_overlay_strings
= n
;
5045 it
->overlay_strings_charpos
= charpos
;
5047 /* IT->current.overlay_string_index is the number of overlay strings
5048 that have already been consumed by IT. Copy some of the
5049 remaining overlay strings to IT->overlay_strings. */
5051 j
= it
->current
.overlay_string_index
;
5052 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5054 it
->overlay_strings
[i
] = entries
[j
].string
;
5055 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5062 /* Get the first chunk of overlay strings at IT's current buffer
5063 position, or at CHARPOS if that is > 0. Value is non-zero if at
5064 least one overlay string was found. */
5067 get_overlay_strings_1 (struct it
*it
, EMACS_INT charpos
, int compute_stop_p
)
5069 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5070 process. This fills IT->overlay_strings with strings, and sets
5071 IT->n_overlay_strings to the total number of strings to process.
5072 IT->pos.overlay_string_index has to be set temporarily to zero
5073 because load_overlay_strings needs this; it must be set to -1
5074 when no overlay strings are found because a zero value would
5075 indicate a position in the first overlay string. */
5076 it
->current
.overlay_string_index
= 0;
5077 load_overlay_strings (it
, charpos
);
5079 /* If we found overlay strings, set up IT to deliver display
5080 elements from the first one. Otherwise set up IT to deliver
5081 from current_buffer. */
5082 if (it
->n_overlay_strings
)
5084 /* Make sure we know settings in current_buffer, so that we can
5085 restore meaningful values when we're done with the overlay
5088 compute_stop_pos (it
);
5089 xassert (it
->face_id
>= 0);
5091 /* Save IT's settings. They are restored after all overlay
5092 strings have been processed. */
5093 xassert (!compute_stop_p
|| it
->sp
== 0);
5095 /* When called from handle_stop, there might be an empty display
5096 string loaded. In that case, don't bother saving it. */
5097 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5100 /* Set up IT to deliver display elements from the first overlay
5102 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5103 it
->string
= it
->overlay_strings
[0];
5104 it
->from_overlay
= Qnil
;
5105 it
->stop_charpos
= 0;
5106 xassert (STRINGP (it
->string
));
5107 it
->end_charpos
= SCHARS (it
->string
);
5108 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5109 it
->method
= GET_FROM_STRING
;
5113 it
->current
.overlay_string_index
= -1;
5118 get_overlay_strings (struct it
*it
, EMACS_INT charpos
)
5121 it
->method
= GET_FROM_BUFFER
;
5123 (void) get_overlay_strings_1 (it
, charpos
, 1);
5127 /* Value is non-zero if we found at least one overlay string. */
5128 return STRINGP (it
->string
);
5133 /***********************************************************************
5134 Saving and restoring state
5135 ***********************************************************************/
5137 /* Save current settings of IT on IT->stack. Called, for example,
5138 before setting up IT for an overlay string, to be able to restore
5139 IT's settings to what they were after the overlay string has been
5140 processed. If POSITION is non-NULL, it is the position to save on
5141 the stack instead of IT->position. */
5144 push_it (struct it
*it
, struct text_pos
*position
)
5146 struct iterator_stack_entry
*p
;
5148 xassert (it
->sp
< IT_STACK_SIZE
);
5149 p
= it
->stack
+ it
->sp
;
5151 p
->stop_charpos
= it
->stop_charpos
;
5152 p
->prev_stop
= it
->prev_stop
;
5153 p
->base_level_stop
= it
->base_level_stop
;
5154 p
->cmp_it
= it
->cmp_it
;
5155 xassert (it
->face_id
>= 0);
5156 p
->face_id
= it
->face_id
;
5157 p
->string
= it
->string
;
5158 p
->method
= it
->method
;
5159 p
->from_overlay
= it
->from_overlay
;
5162 case GET_FROM_IMAGE
:
5163 p
->u
.image
.object
= it
->object
;
5164 p
->u
.image
.image_id
= it
->image_id
;
5165 p
->u
.image
.slice
= it
->slice
;
5167 case GET_FROM_STRETCH
:
5168 p
->u
.stretch
.object
= it
->object
;
5171 p
->position
= position
? *position
: it
->position
;
5172 p
->current
= it
->current
;
5173 p
->end_charpos
= it
->end_charpos
;
5174 p
->string_nchars
= it
->string_nchars
;
5176 p
->multibyte_p
= it
->multibyte_p
;
5177 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5178 p
->space_width
= it
->space_width
;
5179 p
->font_height
= it
->font_height
;
5180 p
->voffset
= it
->voffset
;
5181 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5182 p
->display_ellipsis_p
= 0;
5183 p
->line_wrap
= it
->line_wrap
;
5188 iterate_out_of_display_property (struct it
*it
)
5190 /* Maybe initialize paragraph direction. If we are at the beginning
5191 of a new paragraph, next_element_from_buffer may not have a
5192 chance to do that. */
5193 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
5194 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5195 /* prev_stop can be zero, so check against BEGV as well. */
5196 while (it
->bidi_it
.charpos
>= BEGV
5197 && it
->prev_stop
<= it
->bidi_it
.charpos
5198 && it
->bidi_it
.charpos
< CHARPOS (it
->position
))
5199 bidi_move_to_visually_next (&it
->bidi_it
);
5200 /* Record the stop_pos we just crossed, for when we cross it
5202 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5203 it
->prev_stop
= CHARPOS (it
->position
);
5204 /* If we ended up not where pop_it put us, resync IT's
5205 positional members with the bidi iterator. */
5206 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5208 SET_TEXT_POS (it
->position
,
5209 it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5210 it
->current
.pos
= it
->position
;
5214 /* Restore IT's settings from IT->stack. Called, for example, when no
5215 more overlay strings must be processed, and we return to delivering
5216 display elements from a buffer, or when the end of a string from a
5217 `display' property is reached and we return to delivering display
5218 elements from an overlay string, or from a buffer. */
5221 pop_it (struct it
*it
)
5223 struct iterator_stack_entry
*p
;
5225 xassert (it
->sp
> 0);
5227 p
= it
->stack
+ it
->sp
;
5228 it
->stop_charpos
= p
->stop_charpos
;
5229 it
->prev_stop
= p
->prev_stop
;
5230 it
->base_level_stop
= p
->base_level_stop
;
5231 it
->cmp_it
= p
->cmp_it
;
5232 it
->face_id
= p
->face_id
;
5233 it
->current
= p
->current
;
5234 it
->position
= p
->position
;
5235 it
->string
= p
->string
;
5236 it
->from_overlay
= p
->from_overlay
;
5237 if (NILP (it
->string
))
5238 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5239 it
->method
= p
->method
;
5242 case GET_FROM_IMAGE
:
5243 it
->image_id
= p
->u
.image
.image_id
;
5244 it
->object
= p
->u
.image
.object
;
5245 it
->slice
= p
->u
.image
.slice
;
5247 case GET_FROM_STRETCH
:
5248 it
->object
= p
->u
.comp
.object
;
5250 case GET_FROM_BUFFER
:
5251 it
->object
= it
->w
->buffer
;
5254 /* Bidi-iterate until we get out of the portion of text, if
5255 any, covered by a `display' text property or an overlay
5256 with `display' property. (We cannot just jump there,
5257 because the internal coherency of the bidi iterator state
5258 can not be preserved across such jumps.) We also must
5259 determine the paragraph base direction if the overlay we
5260 just processed is at the beginning of a new
5262 iterate_out_of_display_property (it
);
5265 case GET_FROM_STRING
:
5266 it
->object
= it
->string
;
5268 case GET_FROM_DISPLAY_VECTOR
:
5270 it
->method
= GET_FROM_C_STRING
;
5271 else if (STRINGP (it
->string
))
5272 it
->method
= GET_FROM_STRING
;
5275 it
->method
= GET_FROM_BUFFER
;
5276 it
->object
= it
->w
->buffer
;
5279 it
->end_charpos
= p
->end_charpos
;
5280 it
->string_nchars
= p
->string_nchars
;
5282 it
->multibyte_p
= p
->multibyte_p
;
5283 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5284 it
->space_width
= p
->space_width
;
5285 it
->font_height
= p
->font_height
;
5286 it
->voffset
= p
->voffset
;
5287 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5288 it
->line_wrap
= p
->line_wrap
;
5293 /***********************************************************************
5295 ***********************************************************************/
5297 /* Set IT's current position to the previous line start. */
5300 back_to_previous_line_start (struct it
*it
)
5302 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5303 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5307 /* Move IT to the next line start.
5309 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5310 we skipped over part of the text (as opposed to moving the iterator
5311 continuously over the text). Otherwise, don't change the value
5314 Newlines may come from buffer text, overlay strings, or strings
5315 displayed via the `display' property. That's the reason we can't
5316 simply use find_next_newline_no_quit.
5318 Note that this function may not skip over invisible text that is so
5319 because of text properties and immediately follows a newline. If
5320 it would, function reseat_at_next_visible_line_start, when called
5321 from set_iterator_to_next, would effectively make invisible
5322 characters following a newline part of the wrong glyph row, which
5323 leads to wrong cursor motion. */
5326 forward_to_next_line_start (struct it
*it
, int *skipped_p
)
5328 int old_selective
, newline_found_p
, n
;
5329 const int MAX_NEWLINE_DISTANCE
= 500;
5331 /* If already on a newline, just consume it to avoid unintended
5332 skipping over invisible text below. */
5333 if (it
->what
== IT_CHARACTER
5335 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5337 set_iterator_to_next (it
, 0);
5342 /* Don't handle selective display in the following. It's (a)
5343 unnecessary because it's done by the caller, and (b) leads to an
5344 infinite recursion because next_element_from_ellipsis indirectly
5345 calls this function. */
5346 old_selective
= it
->selective
;
5349 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5350 from buffer text. */
5351 for (n
= newline_found_p
= 0;
5352 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5353 n
+= STRINGP (it
->string
) ? 0 : 1)
5355 if (!get_next_display_element (it
))
5357 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5358 set_iterator_to_next (it
, 0);
5361 /* If we didn't find a newline near enough, see if we can use a
5363 if (!newline_found_p
)
5365 EMACS_INT start
= IT_CHARPOS (*it
);
5366 EMACS_INT limit
= find_next_newline_no_quit (start
, 1);
5369 xassert (!STRINGP (it
->string
));
5371 /* If there isn't any `display' property in sight, and no
5372 overlays, we can just use the position of the newline in
5374 if (it
->stop_charpos
>= limit
5375 || ((pos
= Fnext_single_property_change (make_number (start
),
5377 Qnil
, make_number (limit
)),
5379 && next_overlay_change (start
) == ZV
))
5381 IT_CHARPOS (*it
) = limit
;
5382 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5383 *skipped_p
= newline_found_p
= 1;
5387 while (get_next_display_element (it
)
5388 && !newline_found_p
)
5390 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5391 set_iterator_to_next (it
, 0);
5396 it
->selective
= old_selective
;
5397 return newline_found_p
;
5401 /* Set IT's current position to the previous visible line start. Skip
5402 invisible text that is so either due to text properties or due to
5403 selective display. Caution: this does not change IT->current_x and
5407 back_to_previous_visible_line_start (struct it
*it
)
5409 while (IT_CHARPOS (*it
) > BEGV
)
5411 back_to_previous_line_start (it
);
5413 if (IT_CHARPOS (*it
) <= BEGV
)
5416 /* If selective > 0, then lines indented more than its value are
5418 if (it
->selective
> 0
5419 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5420 (double) it
->selective
)) /* iftc */
5423 /* Check the newline before point for invisibility. */
5426 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5427 Qinvisible
, it
->window
);
5428 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5432 if (IT_CHARPOS (*it
) <= BEGV
)
5439 Lisp_Object val
, overlay
;
5441 /* If newline is part of a composition, continue from start of composition */
5442 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5443 && beg
< IT_CHARPOS (*it
))
5446 /* If newline is replaced by a display property, find start of overlay
5447 or interval and continue search from that point. */
5449 pos
= --IT_CHARPOS (it2
);
5452 it2
.string_from_display_prop_p
= 0;
5453 if (handle_display_prop (&it2
) == HANDLED_RETURN
5454 && !NILP (val
= get_char_property_and_overlay
5455 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5456 && (OVERLAYP (overlay
)
5457 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5458 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5461 /* Newline is not replaced by anything -- so we are done. */
5467 IT_CHARPOS (*it
) = beg
;
5468 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5472 it
->continuation_lines_width
= 0;
5474 xassert (IT_CHARPOS (*it
) >= BEGV
);
5475 xassert (IT_CHARPOS (*it
) == BEGV
5476 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5481 /* Reseat iterator IT at the previous visible line start. Skip
5482 invisible text that is so either due to text properties or due to
5483 selective display. At the end, update IT's overlay information,
5484 face information etc. */
5487 reseat_at_previous_visible_line_start (struct it
*it
)
5489 back_to_previous_visible_line_start (it
);
5490 reseat (it
, it
->current
.pos
, 1);
5495 /* Reseat iterator IT on the next visible line start in the current
5496 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5497 preceding the line start. Skip over invisible text that is so
5498 because of selective display. Compute faces, overlays etc at the
5499 new position. Note that this function does not skip over text that
5500 is invisible because of text properties. */
5503 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5505 int newline_found_p
, skipped_p
= 0;
5507 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5509 /* Skip over lines that are invisible because they are indented
5510 more than the value of IT->selective. */
5511 if (it
->selective
> 0)
5512 while (IT_CHARPOS (*it
) < ZV
5513 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5514 (double) it
->selective
)) /* iftc */
5516 xassert (IT_BYTEPOS (*it
) == BEGV
5517 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5518 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5521 /* Position on the newline if that's what's requested. */
5522 if (on_newline_p
&& newline_found_p
)
5524 if (STRINGP (it
->string
))
5526 if (IT_STRING_CHARPOS (*it
) > 0)
5528 --IT_STRING_CHARPOS (*it
);
5529 --IT_STRING_BYTEPOS (*it
);
5532 else if (IT_CHARPOS (*it
) > BEGV
)
5536 reseat (it
, it
->current
.pos
, 0);
5540 reseat (it
, it
->current
.pos
, 0);
5547 /***********************************************************************
5548 Changing an iterator's position
5549 ***********************************************************************/
5551 /* Change IT's current position to POS in current_buffer. If FORCE_P
5552 is non-zero, always check for text properties at the new position.
5553 Otherwise, text properties are only looked up if POS >=
5554 IT->check_charpos of a property. */
5557 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
5559 EMACS_INT original_pos
= IT_CHARPOS (*it
);
5561 reseat_1 (it
, pos
, 0);
5563 /* Determine where to check text properties. Avoid doing it
5564 where possible because text property lookup is very expensive. */
5566 || CHARPOS (pos
) > it
->stop_charpos
5567 || CHARPOS (pos
) < original_pos
)
5571 /* For bidi iteration, we need to prime prev_stop and
5572 base_level_stop with our best estimations. */
5573 if (CHARPOS (pos
) < it
->prev_stop
)
5575 handle_stop_backwards (it
, BEGV
);
5576 if (CHARPOS (pos
) < it
->base_level_stop
)
5577 it
->base_level_stop
= 0;
5579 else if (CHARPOS (pos
) > it
->stop_charpos
5580 && it
->stop_charpos
>= BEGV
)
5581 handle_stop_backwards (it
, it
->stop_charpos
);
5588 it
->prev_stop
= it
->base_level_stop
= 0;
5597 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5598 IT->stop_pos to POS, also. */
5601 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
5603 /* Don't call this function when scanning a C string. */
5604 xassert (it
->s
== NULL
);
5606 /* POS must be a reasonable value. */
5607 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5609 it
->current
.pos
= it
->position
= pos
;
5610 it
->end_charpos
= ZV
;
5612 it
->current
.dpvec_index
= -1;
5613 it
->current
.overlay_string_index
= -1;
5614 IT_STRING_CHARPOS (*it
) = -1;
5615 IT_STRING_BYTEPOS (*it
) = -1;
5617 it
->string_from_display_prop_p
= 0;
5618 it
->method
= GET_FROM_BUFFER
;
5619 it
->object
= it
->w
->buffer
;
5620 it
->area
= TEXT_AREA
;
5621 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
5623 it
->string_from_display_prop_p
= 0;
5624 it
->face_before_selective_p
= 0;
5627 it
->bidi_it
.first_elt
= 1;
5628 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5629 it
->bidi_it
.disp_pos
= -1;
5630 it
->bidi_it
.string
.s
= NULL
;
5631 it
->bidi_it
.string
.lstring
= Qnil
;
5632 it
->bidi_it
.string
.bufpos
= 0;
5637 it
->stop_charpos
= CHARPOS (pos
);
5638 it
->base_level_stop
= CHARPOS (pos
);
5643 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5644 If S is non-null, it is a C string to iterate over. Otherwise,
5645 STRING gives a Lisp string to iterate over.
5647 If PRECISION > 0, don't return more then PRECISION number of
5648 characters from the string.
5650 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5651 characters have been returned. FIELD_WIDTH < 0 means an infinite
5654 MULTIBYTE = 0 means disable processing of multibyte characters,
5655 MULTIBYTE > 0 means enable it,
5656 MULTIBYTE < 0 means use IT->multibyte_p.
5658 IT must be initialized via a prior call to init_iterator before
5659 calling this function. */
5662 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
5663 EMACS_INT charpos
, EMACS_INT precision
, int field_width
,
5666 /* No region in strings. */
5667 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5669 /* No text property checks performed by default, but see below. */
5670 it
->stop_charpos
= -1;
5672 /* Set iterator position and end position. */
5673 memset (&it
->current
, 0, sizeof it
->current
);
5674 it
->current
.overlay_string_index
= -1;
5675 it
->current
.dpvec_index
= -1;
5676 xassert (charpos
>= 0);
5678 /* If STRING is specified, use its multibyteness, otherwise use the
5679 setting of MULTIBYTE, if specified. */
5681 it
->multibyte_p
= multibyte
> 0;
5683 /* Bidirectional reordering of strings is controlled by the default
5684 value of bidi-display-reordering. */
5686 !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
))
5691 xassert (STRINGP (string
));
5692 it
->string
= string
;
5694 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5695 it
->method
= GET_FROM_STRING
;
5696 it
->current
.string_pos
= string_pos (charpos
, string
);
5700 it
->bidi_it
.string
.lstring
= string
;
5701 it
->bidi_it
.string
.s
= NULL
;
5702 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5703 it
->bidi_it
.string
.bufpos
= 0;
5704 it
->bidi_it
.string
.from_disp_str
= 0;
5705 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
5706 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5711 it
->s
= (const unsigned char *) s
;
5714 /* Note that we use IT->current.pos, not it->current.string_pos,
5715 for displaying C strings. */
5716 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5717 if (it
->multibyte_p
)
5719 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5720 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5724 it
->bidi_it
.string
.lstring
= Qnil
;
5725 it
->bidi_it
.string
.s
= s
;
5726 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5727 it
->bidi_it
.string
.bufpos
= 0;
5728 it
->bidi_it
.string
.from_disp_str
= 0;
5729 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
5735 /* Unibyte (a.k.a. ASCII) C strings are never bidi-reordered. */
5736 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5737 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5740 it
->method
= GET_FROM_C_STRING
;
5743 /* PRECISION > 0 means don't return more than PRECISION characters
5745 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5747 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5749 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5752 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5753 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5754 FIELD_WIDTH < 0 means infinite field width. This is useful for
5755 padding with `-' at the end of a mode line. */
5756 if (field_width
< 0)
5757 field_width
= INFINITY
;
5758 /* Implementation note: We deliberately don't enlarge
5759 it->bidi_it.string.schars here to fit it->end_charpos, because
5760 the bidi iterator cannot produce characters out of thin air. */
5761 if (field_width
> it
->end_charpos
- charpos
)
5762 it
->end_charpos
= charpos
+ field_width
;
5764 /* Use the standard display table for displaying strings. */
5765 if (DISP_TABLE_P (Vstandard_display_table
))
5766 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5768 it
->stop_charpos
= charpos
;
5769 it
->prev_stop
= charpos
;
5770 it
->base_level_stop
= 0;
5773 it
->bidi_it
.first_elt
= 1;
5774 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5775 it
->bidi_it
.disp_pos
= -1;
5777 if (s
== NULL
&& it
->multibyte_p
)
5779 EMACS_INT endpos
= SCHARS (it
->string
);
5780 if (endpos
> it
->end_charpos
)
5781 endpos
= it
->end_charpos
;
5782 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5790 /***********************************************************************
5792 ***********************************************************************/
5794 /* Map enum it_method value to corresponding next_element_from_* function. */
5796 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
5798 next_element_from_buffer
,
5799 next_element_from_display_vector
,
5800 next_element_from_string
,
5801 next_element_from_c_string
,
5802 next_element_from_image
,
5803 next_element_from_stretch
5806 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5809 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5810 (possibly with the following characters). */
5812 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5813 ((IT)->cmp_it.id >= 0 \
5814 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5815 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5816 END_CHARPOS, (IT)->w, \
5817 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5821 /* Lookup the char-table Vglyphless_char_display for character C (-1
5822 if we want information for no-font case), and return the display
5823 method symbol. By side-effect, update it->what and
5824 it->glyphless_method. This function is called from
5825 get_next_display_element for each character element, and from
5826 x_produce_glyphs when no suitable font was found. */
5829 lookup_glyphless_char_display (int c
, struct it
*it
)
5831 Lisp_Object glyphless_method
= Qnil
;
5833 if (CHAR_TABLE_P (Vglyphless_char_display
)
5834 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
5838 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
5839 if (CONSP (glyphless_method
))
5840 glyphless_method
= FRAME_WINDOW_P (it
->f
)
5841 ? XCAR (glyphless_method
)
5842 : XCDR (glyphless_method
);
5845 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
5849 if (NILP (glyphless_method
))
5852 /* The default is to display the character by a proper font. */
5854 /* The default for the no-font case is to display an empty box. */
5855 glyphless_method
= Qempty_box
;
5857 if (EQ (glyphless_method
, Qzero_width
))
5860 return glyphless_method
;
5861 /* This method can't be used for the no-font case. */
5862 glyphless_method
= Qempty_box
;
5864 if (EQ (glyphless_method
, Qthin_space
))
5865 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
5866 else if (EQ (glyphless_method
, Qempty_box
))
5867 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
5868 else if (EQ (glyphless_method
, Qhex_code
))
5869 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
5870 else if (STRINGP (glyphless_method
))
5871 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
5874 /* Invalid value. We use the default method. */
5875 glyphless_method
= Qnil
;
5878 it
->what
= IT_GLYPHLESS
;
5879 return glyphless_method
;
5882 /* Load IT's display element fields with information about the next
5883 display element from the current position of IT. Value is zero if
5884 end of buffer (or C string) is reached. */
5886 static struct frame
*last_escape_glyph_frame
= NULL
;
5887 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5888 static int last_escape_glyph_merged_face_id
= 0;
5890 struct frame
*last_glyphless_glyph_frame
= NULL
;
5891 unsigned last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
5892 int last_glyphless_glyph_merged_face_id
= 0;
5895 get_next_display_element (struct it
*it
)
5897 /* Non-zero means that we found a display element. Zero means that
5898 we hit the end of what we iterate over. Performance note: the
5899 function pointer `method' used here turns out to be faster than
5900 using a sequence of if-statements. */
5904 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5906 if (it
->what
== IT_CHARACTER
)
5908 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
5909 and only if (a) the resolved directionality of that character
5911 /* FIXME: Do we need an exception for characters from display
5913 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
5914 it
->c
= bidi_mirror_char (it
->c
);
5915 /* Map via display table or translate control characters.
5916 IT->c, IT->len etc. have been set to the next character by
5917 the function call above. If we have a display table, and it
5918 contains an entry for IT->c, translate it. Don't do this if
5919 IT->c itself comes from a display table, otherwise we could
5920 end up in an infinite recursion. (An alternative could be to
5921 count the recursion depth of this function and signal an
5922 error when a certain maximum depth is reached.) Is it worth
5924 if (success_p
&& it
->dpvec
== NULL
)
5927 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5928 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5929 nbsp_or_shy
= char_is_other
;
5930 int c
= it
->c
; /* This is the character to display. */
5932 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
5934 xassert (SINGLE_BYTE_CHAR_P (c
));
5935 if (unibyte_display_via_language_environment
)
5937 c
= DECODE_CHAR (unibyte
, c
);
5939 c
= BYTE8_TO_CHAR (it
->c
);
5942 c
= BYTE8_TO_CHAR (it
->c
);
5946 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
5949 struct Lisp_Vector
*v
= XVECTOR (dv
);
5951 /* Return the first character from the display table
5952 entry, if not empty. If empty, don't display the
5953 current character. */
5956 it
->dpvec_char_len
= it
->len
;
5957 it
->dpvec
= v
->contents
;
5958 it
->dpend
= v
->contents
+ v
->header
.size
;
5959 it
->current
.dpvec_index
= 0;
5960 it
->dpvec_face_id
= -1;
5961 it
->saved_face_id
= it
->face_id
;
5962 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5967 set_iterator_to_next (it
, 0);
5972 if (! NILP (lookup_glyphless_char_display (c
, it
)))
5974 if (it
->what
== IT_GLYPHLESS
)
5976 /* Don't display this character. */
5977 set_iterator_to_next (it
, 0);
5981 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
5982 nbsp_or_shy
= (c
== 0xA0 ? char_is_nbsp
5983 : c
== 0xAD ? char_is_soft_hyphen
5986 /* Translate control characters into `\003' or `^C' form.
5987 Control characters coming from a display table entry are
5988 currently not translated because we use IT->dpvec to hold
5989 the translation. This could easily be changed but I
5990 don't believe that it is worth doing.
5992 NBSP and SOFT-HYPEN are property translated too.
5994 Non-printable characters and raw-byte characters are also
5995 translated to octal form. */
5996 if (((c
< ' ' || c
== 127) /* ASCII control chars */
5997 ? (it
->area
!= TEXT_AREA
5998 /* In mode line, treat \n, \t like other crl chars. */
6001 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6002 || (c
!= '\n' && c
!= '\t'))
6005 || ! CHAR_PRINTABLE_P (c
))))
6007 /* C is a control character, NBSP, SOFT-HYPEN, raw-byte,
6008 or a non-printable character which must be displayed
6009 either as '\003' or as `^C' where the '\\' and '^'
6010 can be defined in the display table. Fill
6011 IT->ctl_chars with glyphs for what we have to
6012 display. Then, set IT->dpvec to these glyphs. */
6015 int face_id
, lface_id
= 0 ;
6018 /* Handle control characters with ^. */
6020 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6024 g
= '^'; /* default glyph for Control */
6025 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6027 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6028 && GLYPH_CODE_CHAR_VALID_P (gc
))
6030 g
= GLYPH_CODE_CHAR (gc
);
6031 lface_id
= GLYPH_CODE_FACE (gc
);
6035 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6037 else if (it
->f
== last_escape_glyph_frame
6038 && it
->face_id
== last_escape_glyph_face_id
)
6040 face_id
= last_escape_glyph_merged_face_id
;
6044 /* Merge the escape-glyph face into the current face. */
6045 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6047 last_escape_glyph_frame
= it
->f
;
6048 last_escape_glyph_face_id
= it
->face_id
;
6049 last_escape_glyph_merged_face_id
= face_id
;
6052 XSETINT (it
->ctl_chars
[0], g
);
6053 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6055 goto display_control
;
6058 /* Handle non-break space in the mode where it only gets
6061 if (EQ (Vnobreak_char_display
, Qt
)
6062 && nbsp_or_shy
== char_is_nbsp
)
6064 /* Merge the no-break-space face into the current face. */
6065 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6069 XSETINT (it
->ctl_chars
[0], ' ');
6071 goto display_control
;
6074 /* Handle sequences that start with the "escape glyph". */
6076 /* the default escape glyph is \. */
6077 escape_glyph
= '\\';
6080 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6081 && GLYPH_CODE_CHAR_VALID_P (gc
))
6083 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6084 lface_id
= GLYPH_CODE_FACE (gc
);
6088 /* The display table specified a face.
6089 Merge it into face_id and also into escape_glyph. */
6090 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6093 else if (it
->f
== last_escape_glyph_frame
6094 && it
->face_id
== last_escape_glyph_face_id
)
6096 face_id
= last_escape_glyph_merged_face_id
;
6100 /* Merge the escape-glyph face into the current face. */
6101 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6103 last_escape_glyph_frame
= it
->f
;
6104 last_escape_glyph_face_id
= it
->face_id
;
6105 last_escape_glyph_merged_face_id
= face_id
;
6108 /* Handle soft hyphens in the mode where they only get
6111 if (EQ (Vnobreak_char_display
, Qt
)
6112 && nbsp_or_shy
== char_is_soft_hyphen
)
6114 XSETINT (it
->ctl_chars
[0], '-');
6116 goto display_control
;
6119 /* Handle non-break space and soft hyphen
6120 with the escape glyph. */
6124 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6125 c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
6126 XSETINT (it
->ctl_chars
[1], c
);
6128 goto display_control
;
6135 if (CHAR_BYTE8_P (c
))
6136 /* Display \200 instead of \17777600. */
6137 c
= CHAR_TO_BYTE8 (c
);
6138 len
= sprintf (str
, "%03o", c
);
6140 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6141 for (i
= 0; i
< len
; i
++)
6142 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6147 /* Set up IT->dpvec and return first character from it. */
6148 it
->dpvec_char_len
= it
->len
;
6149 it
->dpvec
= it
->ctl_chars
;
6150 it
->dpend
= it
->dpvec
+ ctl_len
;
6151 it
->current
.dpvec_index
= 0;
6152 it
->dpvec_face_id
= face_id
;
6153 it
->saved_face_id
= it
->face_id
;
6154 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6158 it
->char_to_display
= c
;
6162 it
->char_to_display
= it
->c
;
6166 /* Adjust face id for a multibyte character. There are no multibyte
6167 character in unibyte text. */
6168 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6171 && FRAME_WINDOW_P (it
->f
))
6173 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6175 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6177 /* Automatic composition with glyph-string. */
6178 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6180 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6184 EMACS_INT pos
= (it
->s
? -1
6185 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6186 : IT_CHARPOS (*it
));
6188 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
, pos
,
6194 /* Is this character the last one of a run of characters with
6195 box? If yes, set IT->end_of_box_run_p to 1. */
6199 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6201 int face_id
= underlying_face_id (it
);
6202 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6206 if (face
->box
== FACE_NO_BOX
)
6208 /* If the box comes from face properties in a
6209 display string, check faces in that string. */
6210 int string_face_id
= face_after_it_pos (it
);
6211 it
->end_of_box_run_p
6212 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6215 /* Otherwise, the box comes from the underlying face.
6216 If this is the last string character displayed, check
6217 the next buffer location. */
6218 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6219 && (it
->current
.overlay_string_index
6220 == it
->n_overlay_strings
- 1))
6224 struct text_pos pos
= it
->current
.pos
;
6225 INC_TEXT_POS (pos
, it
->multibyte_p
);
6227 next_face_id
= face_at_buffer_position
6228 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6229 it
->region_end_charpos
, &ignore
,
6230 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6232 it
->end_of_box_run_p
6233 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6240 int face_id
= face_after_it_pos (it
);
6241 it
->end_of_box_run_p
6242 = (face_id
!= it
->face_id
6243 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6247 /* Value is 0 if end of buffer or string reached. */
6252 /* Move IT to the next display element.
6254 RESEAT_P non-zero means if called on a newline in buffer text,
6255 skip to the next visible line start.
6257 Functions get_next_display_element and set_iterator_to_next are
6258 separate because I find this arrangement easier to handle than a
6259 get_next_display_element function that also increments IT's
6260 position. The way it is we can first look at an iterator's current
6261 display element, decide whether it fits on a line, and if it does,
6262 increment the iterator position. The other way around we probably
6263 would either need a flag indicating whether the iterator has to be
6264 incremented the next time, or we would have to implement a
6265 decrement position function which would not be easy to write. */
6268 set_iterator_to_next (struct it
*it
, int reseat_p
)
6270 /* Reset flags indicating start and end of a sequence of characters
6271 with box. Reset them at the start of this function because
6272 moving the iterator to a new position might set them. */
6273 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6277 case GET_FROM_BUFFER
:
6278 /* The current display element of IT is a character from
6279 current_buffer. Advance in the buffer, and maybe skip over
6280 invisible lines that are so because of selective display. */
6281 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6282 reseat_at_next_visible_line_start (it
, 0);
6283 else if (it
->cmp_it
.id
>= 0)
6285 /* We are currently getting glyphs from a composition. */
6290 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6291 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6292 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6294 it
->cmp_it
.from
= it
->cmp_it
.to
;
6299 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6301 it
->end_charpos
, Qnil
);
6304 else if (! it
->cmp_it
.reversed_p
)
6306 /* Composition created while scanning forward. */
6307 /* Update IT's char/byte positions to point to the first
6308 character of the next grapheme cluster, or to the
6309 character visually after the current composition. */
6310 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6311 bidi_move_to_visually_next (&it
->bidi_it
);
6312 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6313 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6315 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6317 /* Proceed to the next grapheme cluster. */
6318 it
->cmp_it
.from
= it
->cmp_it
.to
;
6322 /* No more grapheme clusters in this composition.
6323 Find the next stop position. */
6324 EMACS_INT stop
= it
->end_charpos
;
6325 if (it
->bidi_it
.scan_dir
< 0)
6326 /* Now we are scanning backward and don't know
6329 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6330 IT_BYTEPOS (*it
), stop
, Qnil
);
6335 /* Composition created while scanning backward. */
6336 /* Update IT's char/byte positions to point to the last
6337 character of the previous grapheme cluster, or the
6338 character visually after the current composition. */
6339 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6340 bidi_move_to_visually_next (&it
->bidi_it
);
6341 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6342 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6343 if (it
->cmp_it
.from
> 0)
6345 /* Proceed to the previous grapheme cluster. */
6346 it
->cmp_it
.to
= it
->cmp_it
.from
;
6350 /* No more grapheme clusters in this composition.
6351 Find the next stop position. */
6352 EMACS_INT stop
= it
->end_charpos
;
6353 if (it
->bidi_it
.scan_dir
< 0)
6354 /* Now we are scanning backward and don't know
6357 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6358 IT_BYTEPOS (*it
), stop
, Qnil
);
6364 xassert (it
->len
!= 0);
6368 IT_BYTEPOS (*it
) += it
->len
;
6369 IT_CHARPOS (*it
) += 1;
6373 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6374 /* If this is a new paragraph, determine its base
6375 direction (a.k.a. its base embedding level). */
6376 if (it
->bidi_it
.new_paragraph
)
6377 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6378 bidi_move_to_visually_next (&it
->bidi_it
);
6379 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6380 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6381 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6383 /* As the scan direction was changed, we must
6384 re-compute the stop position for composition. */
6385 EMACS_INT stop
= it
->end_charpos
;
6386 if (it
->bidi_it
.scan_dir
< 0)
6388 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6389 IT_BYTEPOS (*it
), stop
, Qnil
);
6392 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6396 case GET_FROM_C_STRING
:
6397 /* Current display element of IT is from a C string. */
6399 /* If the string position is beyond string_nchars, it means
6400 next_element_from_c_string is padding the string with
6401 blanks, in which case we bypass the bidi iterator,
6402 because it cannot deal with such virtual characters. */
6403 || IT_CHARPOS (*it
) >= it
->string_nchars
)
6405 IT_BYTEPOS (*it
) += it
->len
;
6406 IT_CHARPOS (*it
) += 1;
6410 bidi_move_to_visually_next (&it
->bidi_it
);
6411 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6412 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6416 case GET_FROM_DISPLAY_VECTOR
:
6417 /* Current display element of IT is from a display table entry.
6418 Advance in the display table definition. Reset it to null if
6419 end reached, and continue with characters from buffers/
6421 ++it
->current
.dpvec_index
;
6423 /* Restore face of the iterator to what they were before the
6424 display vector entry (these entries may contain faces). */
6425 it
->face_id
= it
->saved_face_id
;
6427 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6429 int recheck_faces
= it
->ellipsis_p
;
6432 it
->method
= GET_FROM_C_STRING
;
6433 else if (STRINGP (it
->string
))
6434 it
->method
= GET_FROM_STRING
;
6437 it
->method
= GET_FROM_BUFFER
;
6438 it
->object
= it
->w
->buffer
;
6442 it
->current
.dpvec_index
= -1;
6444 /* Skip over characters which were displayed via IT->dpvec. */
6445 if (it
->dpvec_char_len
< 0)
6446 reseat_at_next_visible_line_start (it
, 1);
6447 else if (it
->dpvec_char_len
> 0)
6449 if (it
->method
== GET_FROM_STRING
6450 && it
->n_overlay_strings
> 0)
6451 it
->ignore_overlay_strings_at_pos_p
= 1;
6452 it
->len
= it
->dpvec_char_len
;
6453 set_iterator_to_next (it
, reseat_p
);
6456 /* Maybe recheck faces after display vector */
6458 it
->stop_charpos
= IT_CHARPOS (*it
);
6462 case GET_FROM_STRING
:
6463 /* Current display element is a character from a Lisp string. */
6464 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6465 if (it
->cmp_it
.id
>= 0)
6471 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6472 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6473 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6474 it
->cmp_it
.from
= it
->cmp_it
.to
;
6478 composition_compute_stop_pos (&it
->cmp_it
,
6479 IT_STRING_CHARPOS (*it
),
6480 IT_STRING_BYTEPOS (*it
),
6481 it
->end_charpos
, it
->string
);
6484 else if (! it
->cmp_it
.reversed_p
)
6486 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6487 bidi_move_to_visually_next (&it
->bidi_it
);
6488 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6489 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6491 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6492 it
->cmp_it
.from
= it
->cmp_it
.to
;
6495 EMACS_INT stop
= it
->end_charpos
;
6496 if (it
->bidi_it
.scan_dir
< 0)
6498 composition_compute_stop_pos (&it
->cmp_it
,
6499 IT_STRING_CHARPOS (*it
),
6500 IT_STRING_BYTEPOS (*it
), stop
,
6506 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6507 bidi_move_to_visually_next (&it
->bidi_it
);
6508 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6509 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6510 if (it
->cmp_it
.from
> 0)
6511 it
->cmp_it
.to
= it
->cmp_it
.from
;
6514 EMACS_INT stop
= it
->end_charpos
;
6515 if (it
->bidi_it
.scan_dir
< 0)
6517 composition_compute_stop_pos (&it
->cmp_it
,
6518 IT_STRING_CHARPOS (*it
),
6519 IT_STRING_BYTEPOS (*it
), stop
,
6527 /* If the string position is beyond string_nchars, it
6528 means next_element_from_string is padding the string
6529 with blanks, in which case we bypass the bidi
6530 iterator, because it cannot deal with such virtual
6532 || IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6534 IT_STRING_BYTEPOS (*it
) += it
->len
;
6535 IT_STRING_CHARPOS (*it
) += 1;
6539 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6541 bidi_move_to_visually_next (&it
->bidi_it
);
6542 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6543 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6544 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6546 EMACS_INT stop
= it
->end_charpos
;
6548 if (it
->bidi_it
.scan_dir
< 0)
6550 composition_compute_stop_pos (&it
->cmp_it
,
6551 IT_STRING_CHARPOS (*it
),
6552 IT_STRING_BYTEPOS (*it
), stop
,
6558 consider_string_end
:
6560 if (it
->current
.overlay_string_index
>= 0)
6562 /* IT->string is an overlay string. Advance to the
6563 next, if there is one. */
6564 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6567 next_overlay_string (it
);
6569 setup_for_ellipsis (it
, 0);
6574 /* IT->string is not an overlay string. If we reached
6575 its end, and there is something on IT->stack, proceed
6576 with what is on the stack. This can be either another
6577 string, this time an overlay string, or a buffer. */
6578 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6582 if (it
->method
== GET_FROM_STRING
)
6583 goto consider_string_end
;
6588 case GET_FROM_IMAGE
:
6589 case GET_FROM_STRETCH
:
6590 /* The position etc with which we have to proceed are on
6591 the stack. The position may be at the end of a string,
6592 if the `display' property takes up the whole string. */
6593 xassert (it
->sp
> 0);
6595 if (it
->method
== GET_FROM_STRING
)
6596 goto consider_string_end
;
6600 /* There are no other methods defined, so this should be a bug. */
6604 xassert (it
->method
!= GET_FROM_STRING
6605 || (STRINGP (it
->string
)
6606 && IT_STRING_CHARPOS (*it
) >= 0));
6609 /* Load IT's display element fields with information about the next
6610 display element which comes from a display table entry or from the
6611 result of translating a control character to one of the forms `^C'
6614 IT->dpvec holds the glyphs to return as characters.
6615 IT->saved_face_id holds the face id before the display vector--it
6616 is restored into IT->face_id in set_iterator_to_next. */
6619 next_element_from_display_vector (struct it
*it
)
6624 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6626 it
->face_id
= it
->saved_face_id
;
6628 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6629 That seemed totally bogus - so I changed it... */
6630 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6632 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6634 it
->c
= GLYPH_CODE_CHAR (gc
);
6635 it
->len
= CHAR_BYTES (it
->c
);
6637 /* The entry may contain a face id to use. Such a face id is
6638 the id of a Lisp face, not a realized face. A face id of
6639 zero means no face is specified. */
6640 if (it
->dpvec_face_id
>= 0)
6641 it
->face_id
= it
->dpvec_face_id
;
6644 int lface_id
= GLYPH_CODE_FACE (gc
);
6646 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6651 /* Display table entry is invalid. Return a space. */
6652 it
->c
= ' ', it
->len
= 1;
6654 /* Don't change position and object of the iterator here. They are
6655 still the values of the character that had this display table
6656 entry or was translated, and that's what we want. */
6657 it
->what
= IT_CHARACTER
;
6661 /* Get the first element of string/buffer in the visual order, after
6662 being reseated to a new position in a string or a buffer. */
6664 get_visually_first_element (struct it
*it
)
6666 int string_p
= STRINGP (it
->string
) || it
->s
;
6667 EMACS_INT eob
= (string_p
? it
->string_nchars
: ZV
);
6668 EMACS_INT bob
= (string_p
? 0 : BEGV
);
6670 if (STRINGP (it
->string
))
6672 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
6673 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
6677 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6678 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6681 if (it
->bidi_it
.charpos
== eob
)
6683 /* Nothing to do, but reset the FIRST_ELT flag, like
6684 bidi_paragraph_init does, because we are not going to
6686 it
->bidi_it
.first_elt
= 0;
6688 else if (it
->bidi_it
.charpos
== bob
6690 /* FIXME: Should support all Unicode line separators. */
6691 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6692 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
6694 /* If we are at the beginning of a line/string, we can produce
6695 the next element right away. */
6696 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6697 bidi_move_to_visually_next (&it
->bidi_it
);
6701 EMACS_INT orig_bytepos
= it
->bidi_it
.bytepos
;
6703 /* We need to prime the bidi iterator starting at the line's or
6704 string's beginning, before we will be able to produce the
6707 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
6710 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
6712 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
6714 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6717 /* Now return to buffer/string position where we were asked
6718 to get the next display element, and produce that. */
6719 bidi_move_to_visually_next (&it
->bidi_it
);
6721 while (it
->bidi_it
.bytepos
!= orig_bytepos
6722 && it
->bidi_it
.charpos
< eob
);
6725 /* Adjust IT's position information to where we ended up. */
6726 if (STRINGP (it
->string
))
6728 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6729 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6733 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6734 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6737 if (STRINGP (it
->string
) || !it
->s
)
6739 EMACS_INT stop
, charpos
, bytepos
;
6741 if (STRINGP (it
->string
))
6744 stop
= SCHARS (it
->string
);
6745 if (stop
> it
->end_charpos
)
6746 stop
= it
->end_charpos
;
6747 charpos
= IT_STRING_CHARPOS (*it
);
6748 bytepos
= IT_STRING_BYTEPOS (*it
);
6752 stop
= it
->end_charpos
;
6753 charpos
= IT_CHARPOS (*it
);
6754 bytepos
= IT_BYTEPOS (*it
);
6756 if (it
->bidi_it
.scan_dir
< 0)
6758 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
6763 /* Load IT with the next display element from Lisp string IT->string.
6764 IT->current.string_pos is the current position within the string.
6765 If IT->current.overlay_string_index >= 0, the Lisp string is an
6769 next_element_from_string (struct it
*it
)
6771 struct text_pos position
;
6773 xassert (STRINGP (it
->string
));
6774 xassert (!it
->bidi_p
|| it
->string
== it
->bidi_it
.string
.lstring
);
6775 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6776 position
= it
->current
.string_pos
;
6778 /* With bidi reordering, the character to display might not be the
6779 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
6780 that we were reseat()ed to a new string, whose paragraph
6781 direction is not known. */
6782 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6784 get_visually_first_element (it
);
6785 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
6788 /* Time to check for invisible text? */
6789 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
6791 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
6794 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6795 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
6797 /* With bidi non-linear iteration, we could find
6798 ourselves far beyond the last computed stop_charpos,
6799 with several other stop positions in between that we
6800 missed. Scan them all now, in buffer's logical
6801 order, until we find and handle the last stop_charpos
6802 that precedes our current position. */
6803 handle_stop_backwards (it
, it
->stop_charpos
);
6804 return GET_NEXT_DISPLAY_ELEMENT (it
);
6810 /* Take note of the stop position we just moved
6811 across, for when we will move back across it. */
6812 it
->prev_stop
= it
->stop_charpos
;
6813 /* If we are at base paragraph embedding level, take
6814 note of the last stop position seen at this
6816 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6817 it
->base_level_stop
= it
->stop_charpos
;
6821 /* Since a handler may have changed IT->method, we must
6823 return GET_NEXT_DISPLAY_ELEMENT (it
);
6827 /* If we are before prev_stop, we may have overstepped
6828 on our way backwards a stop_pos, and if so, we need
6829 to handle that stop_pos. */
6830 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
6831 /* We can sometimes back up for reasons that have nothing
6832 to do with bidi reordering. E.g., compositions. The
6833 code below is only needed when we are above the base
6834 embedding level, so test for that explicitly. */
6835 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6837 /* If we lost track of base_level_stop, we have no better place
6838 for handle_stop_backwards to start from than BEGV. This
6839 happens, e.g., when we were reseated to the previous
6840 screenful of text by vertical-motion. */
6841 if (it
->base_level_stop
<= 0
6842 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
6843 it
->base_level_stop
= 0;
6844 handle_stop_backwards (it
, it
->base_level_stop
);
6845 return GET_NEXT_DISPLAY_ELEMENT (it
);
6849 if (it
->current
.overlay_string_index
>= 0)
6851 /* Get the next character from an overlay string. In overlay
6852 strings, There is no field width or padding with spaces to
6854 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6859 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6860 IT_STRING_BYTEPOS (*it
),
6861 it
->bidi_it
.scan_dir
< 0
6863 : SCHARS (it
->string
))
6864 && next_element_from_composition (it
))
6868 else if (STRING_MULTIBYTE (it
->string
))
6870 const unsigned char *s
= (SDATA (it
->string
)
6871 + IT_STRING_BYTEPOS (*it
));
6872 it
->c
= string_char_and_length (s
, &it
->len
);
6876 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6882 /* Get the next character from a Lisp string that is not an
6883 overlay string. Such strings come from the mode line, for
6884 example. We may have to pad with spaces, or truncate the
6885 string. See also next_element_from_c_string. */
6886 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6891 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6893 /* Pad with spaces. */
6894 it
->c
= ' ', it
->len
= 1;
6895 CHARPOS (position
) = BYTEPOS (position
) = -1;
6897 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6898 IT_STRING_BYTEPOS (*it
),
6899 it
->bidi_it
.scan_dir
< 0
6901 : it
->string_nchars
)
6902 && next_element_from_composition (it
))
6906 else if (STRING_MULTIBYTE (it
->string
))
6908 const unsigned char *s
= (SDATA (it
->string
)
6909 + IT_STRING_BYTEPOS (*it
));
6910 it
->c
= string_char_and_length (s
, &it
->len
);
6914 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6919 /* Record what we have and where it came from. */
6920 it
->what
= IT_CHARACTER
;
6921 it
->object
= it
->string
;
6922 it
->position
= position
;
6927 /* Load IT with next display element from C string IT->s.
6928 IT->string_nchars is the maximum number of characters to return
6929 from the string. IT->end_charpos may be greater than
6930 IT->string_nchars when this function is called, in which case we
6931 may have to return padding spaces. Value is zero if end of string
6932 reached, including padding spaces. */
6935 next_element_from_c_string (struct it
*it
)
6940 xassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
6941 it
->what
= IT_CHARACTER
;
6942 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6945 /* With bidi reordering, the character to display might not be the
6946 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
6947 we were reseated to a new string, whose paragraph direction is
6949 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6950 get_visually_first_element (it
);
6952 /* IT's position can be greater than IT->string_nchars in case a
6953 field width or precision has been specified when the iterator was
6955 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6957 /* End of the game. */
6961 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6963 /* Pad with spaces. */
6964 it
->c
= ' ', it
->len
= 1;
6965 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6967 else if (it
->multibyte_p
)
6968 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6970 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6976 /* Set up IT to return characters from an ellipsis, if appropriate.
6977 The definition of the ellipsis glyphs may come from a display table
6978 entry. This function fills IT with the first glyph from the
6979 ellipsis if an ellipsis is to be displayed. */
6982 next_element_from_ellipsis (struct it
*it
)
6984 if (it
->selective_display_ellipsis_p
)
6985 setup_for_ellipsis (it
, it
->len
);
6988 /* The face at the current position may be different from the
6989 face we find after the invisible text. Remember what it
6990 was in IT->saved_face_id, and signal that it's there by
6991 setting face_before_selective_p. */
6992 it
->saved_face_id
= it
->face_id
;
6993 it
->method
= GET_FROM_BUFFER
;
6994 it
->object
= it
->w
->buffer
;
6995 reseat_at_next_visible_line_start (it
, 1);
6996 it
->face_before_selective_p
= 1;
6999 return GET_NEXT_DISPLAY_ELEMENT (it
);
7003 /* Deliver an image display element. The iterator IT is already
7004 filled with image information (done in handle_display_prop). Value
7009 next_element_from_image (struct it
*it
)
7011 it
->what
= IT_IMAGE
;
7012 it
->ignore_overlay_strings_at_pos_p
= 0;
7017 /* Fill iterator IT with next display element from a stretch glyph
7018 property. IT->object is the value of the text property. Value is
7022 next_element_from_stretch (struct it
*it
)
7024 it
->what
= IT_STRETCH
;
7028 /* Scan forward from CHARPOS in the current buffer/string, until we
7029 find a stop position > current IT's position. Then handle the stop
7030 position before that. This is called when we bump into a stop
7031 position while reordering bidirectional text. CHARPOS should be
7032 the last previously processed stop_pos (or BEGV/0, if none were
7033 processed yet) whose position is less that IT's current
7037 handle_stop_backwards (struct it
*it
, EMACS_INT charpos
)
7039 int bufp
= !STRINGP (it
->string
);
7040 EMACS_INT where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7041 struct display_pos save_current
= it
->current
;
7042 struct text_pos save_position
= it
->position
;
7043 struct text_pos pos1
;
7044 EMACS_INT next_stop
;
7046 /* Scan in strict logical order. */
7050 it
->prev_stop
= charpos
;
7053 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7054 reseat_1 (it
, pos1
, 0);
7057 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7058 compute_stop_pos (it
);
7059 /* We must advance forward, right? */
7060 if (it
->stop_charpos
<= it
->prev_stop
)
7062 charpos
= it
->stop_charpos
;
7064 while (charpos
<= where_we_are
);
7066 next_stop
= it
->stop_charpos
;
7067 it
->stop_charpos
= it
->prev_stop
;
7069 it
->current
= save_current
;
7070 it
->position
= save_position
;
7072 it
->stop_charpos
= next_stop
;
7075 /* Load IT with the next display element from current_buffer. Value
7076 is zero if end of buffer reached. IT->stop_charpos is the next
7077 position at which to stop and check for text properties or buffer
7081 next_element_from_buffer (struct it
*it
)
7085 xassert (IT_CHARPOS (*it
) >= BEGV
);
7086 xassert (NILP (it
->string
) && !it
->s
);
7087 xassert (!it
->bidi_p
7088 || (it
->bidi_it
.string
.lstring
== Qnil
7089 && it
->bidi_it
.string
.s
== NULL
));
7091 /* With bidi reordering, the character to display might not be the
7092 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7093 we were reseat()ed to a new buffer position, which is potentially
7094 a different paragraph. */
7095 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7097 get_visually_first_element (it
);
7098 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7101 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7103 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7105 int overlay_strings_follow_p
;
7107 /* End of the game, except when overlay strings follow that
7108 haven't been returned yet. */
7109 if (it
->overlay_strings_at_end_processed_p
)
7110 overlay_strings_follow_p
= 0;
7113 it
->overlay_strings_at_end_processed_p
= 1;
7114 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7117 if (overlay_strings_follow_p
)
7118 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7122 it
->position
= it
->current
.pos
;
7126 else if (!(!it
->bidi_p
7127 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7128 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7130 /* With bidi non-linear iteration, we could find ourselves
7131 far beyond the last computed stop_charpos, with several
7132 other stop positions in between that we missed. Scan
7133 them all now, in buffer's logical order, until we find
7134 and handle the last stop_charpos that precedes our
7135 current position. */
7136 handle_stop_backwards (it
, it
->stop_charpos
);
7137 return GET_NEXT_DISPLAY_ELEMENT (it
);
7143 /* Take note of the stop position we just moved across,
7144 for when we will move back across it. */
7145 it
->prev_stop
= it
->stop_charpos
;
7146 /* If we are at base paragraph embedding level, take
7147 note of the last stop position seen at this
7149 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7150 it
->base_level_stop
= it
->stop_charpos
;
7153 return GET_NEXT_DISPLAY_ELEMENT (it
);
7157 /* If we are before prev_stop, we may have overstepped on
7158 our way backwards a stop_pos, and if so, we need to
7159 handle that stop_pos. */
7160 && IT_CHARPOS (*it
) < it
->prev_stop
7161 /* We can sometimes back up for reasons that have nothing
7162 to do with bidi reordering. E.g., compositions. The
7163 code below is only needed when we are above the base
7164 embedding level, so test for that explicitly. */
7165 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7167 /* If we lost track of base_level_stop, we have no better place
7168 for handle_stop_backwards to start from than BEGV. This
7169 happens, e.g., when we were reseated to the previous
7170 screenful of text by vertical-motion. */
7171 if (it
->base_level_stop
<= 0
7172 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7173 it
->base_level_stop
= BEGV
;
7174 handle_stop_backwards (it
, it
->base_level_stop
);
7175 return GET_NEXT_DISPLAY_ELEMENT (it
);
7179 /* No face changes, overlays etc. in sight, so just return a
7180 character from current_buffer. */
7184 /* Maybe run the redisplay end trigger hook. Performance note:
7185 This doesn't seem to cost measurable time. */
7186 if (it
->redisplay_end_trigger_charpos
7188 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7189 run_redisplay_end_trigger_hook (it
);
7191 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7192 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7194 && next_element_from_composition (it
))
7199 /* Get the next character, maybe multibyte. */
7200 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7201 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7202 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7204 it
->c
= *p
, it
->len
= 1;
7206 /* Record what we have and where it came from. */
7207 it
->what
= IT_CHARACTER
;
7208 it
->object
= it
->w
->buffer
;
7209 it
->position
= it
->current
.pos
;
7211 /* Normally we return the character found above, except when we
7212 really want to return an ellipsis for selective display. */
7217 /* A value of selective > 0 means hide lines indented more
7218 than that number of columns. */
7219 if (it
->selective
> 0
7220 && IT_CHARPOS (*it
) + 1 < ZV
7221 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7222 IT_BYTEPOS (*it
) + 1,
7223 (double) it
->selective
)) /* iftc */
7225 success_p
= next_element_from_ellipsis (it
);
7226 it
->dpvec_char_len
= -1;
7229 else if (it
->c
== '\r' && it
->selective
== -1)
7231 /* A value of selective == -1 means that everything from the
7232 CR to the end of the line is invisible, with maybe an
7233 ellipsis displayed for it. */
7234 success_p
= next_element_from_ellipsis (it
);
7235 it
->dpvec_char_len
= -1;
7240 /* Value is zero if end of buffer reached. */
7241 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7246 /* Run the redisplay end trigger hook for IT. */
7249 run_redisplay_end_trigger_hook (struct it
*it
)
7251 Lisp_Object args
[3];
7253 /* IT->glyph_row should be non-null, i.e. we should be actually
7254 displaying something, or otherwise we should not run the hook. */
7255 xassert (it
->glyph_row
);
7257 /* Set up hook arguments. */
7258 args
[0] = Qredisplay_end_trigger_functions
;
7259 args
[1] = it
->window
;
7260 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7261 it
->redisplay_end_trigger_charpos
= 0;
7263 /* Since we are *trying* to run these functions, don't try to run
7264 them again, even if they get an error. */
7265 it
->w
->redisplay_end_trigger
= Qnil
;
7266 Frun_hook_with_args (3, args
);
7268 /* Notice if it changed the face of the character we are on. */
7269 handle_face_prop (it
);
7273 /* Deliver a composition display element. Unlike the other
7274 next_element_from_XXX, this function is not registered in the array
7275 get_next_element[]. It is called from next_element_from_buffer and
7276 next_element_from_string when necessary. */
7279 next_element_from_composition (struct it
*it
)
7281 it
->what
= IT_COMPOSITION
;
7282 it
->len
= it
->cmp_it
.nbytes
;
7283 if (STRINGP (it
->string
))
7287 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7288 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7291 it
->position
= it
->current
.string_pos
;
7292 it
->object
= it
->string
;
7293 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
7294 IT_STRING_BYTEPOS (*it
), it
->string
);
7300 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7301 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7304 if (it
->bidi_it
.new_paragraph
)
7305 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7306 /* Resync the bidi iterator with IT's new position.
7307 FIXME: this doesn't support bidirectional text. */
7308 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
7309 bidi_move_to_visually_next (&it
->bidi_it
);
7313 it
->position
= it
->current
.pos
;
7314 it
->object
= it
->w
->buffer
;
7315 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
7316 IT_BYTEPOS (*it
), Qnil
);
7323 /***********************************************************************
7324 Moving an iterator without producing glyphs
7325 ***********************************************************************/
7327 /* Check if iterator is at a position corresponding to a valid buffer
7328 position after some move_it_ call. */
7330 #define IT_POS_VALID_AFTER_MOVE_P(it) \
7331 ((it)->method == GET_FROM_STRING \
7332 ? IT_STRING_CHARPOS (*it) == 0 \
7336 /* Move iterator IT to a specified buffer or X position within one
7337 line on the display without producing glyphs.
7339 OP should be a bit mask including some or all of these bits:
7340 MOVE_TO_X: Stop upon reaching x-position TO_X.
7341 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
7342 Regardless of OP's value, stop upon reaching the end of the display line.
7344 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
7345 This means, in particular, that TO_X includes window's horizontal
7348 The return value has several possible values that
7349 say what condition caused the scan to stop:
7351 MOVE_POS_MATCH_OR_ZV
7352 - when TO_POS or ZV was reached.
7355 -when TO_X was reached before TO_POS or ZV were reached.
7358 - when we reached the end of the display area and the line must
7362 - when we reached the end of the display area and the line is
7366 - when we stopped at a line end, i.e. a newline or a CR and selective
7369 static enum move_it_result
7370 move_it_in_display_line_to (struct it
*it
,
7371 EMACS_INT to_charpos
, int to_x
,
7372 enum move_operation_enum op
)
7374 enum move_it_result result
= MOVE_UNDEFINED
;
7375 struct glyph_row
*saved_glyph_row
;
7376 struct it wrap_it
, atpos_it
, atx_it
;
7378 enum it_method prev_method
= it
->method
;
7379 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
7381 /* Don't produce glyphs in produce_glyphs. */
7382 saved_glyph_row
= it
->glyph_row
;
7383 it
->glyph_row
= NULL
;
7385 /* Use wrap_it to save a copy of IT wherever a word wrap could
7386 occur. Use atpos_it to save a copy of IT at the desired buffer
7387 position, if found, so that we can scan ahead and check if the
7388 word later overshoots the window edge. Use atx_it similarly, for
7394 #define BUFFER_POS_REACHED_P() \
7395 ((op & MOVE_TO_POS) != 0 \
7396 && BUFFERP (it->object) \
7397 && (IT_CHARPOS (*it) == to_charpos \
7398 || (!it->bidi_p && IT_CHARPOS (*it) > to_charpos)) \
7399 && (it->method == GET_FROM_BUFFER \
7400 || (it->method == GET_FROM_DISPLAY_VECTOR \
7401 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
7403 /* If there's a line-/wrap-prefix, handle it. */
7404 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
7405 && it
->current_y
< it
->last_visible_y
)
7406 handle_line_prefix (it
);
7408 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7409 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7413 int x
, i
, ascent
= 0, descent
= 0;
7415 /* Utility macro to reset an iterator with x, ascent, and descent. */
7416 #define IT_RESET_X_ASCENT_DESCENT(IT) \
7417 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
7418 (IT)->max_descent = descent)
7420 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
7422 if ((op
& MOVE_TO_POS
) != 0
7423 && BUFFERP (it
->object
)
7424 && it
->method
== GET_FROM_BUFFER
7425 && ((!it
->bidi_p
&& IT_CHARPOS (*it
) > to_charpos
)
7427 && (prev_method
== GET_FROM_IMAGE
7428 || prev_method
== GET_FROM_STRETCH
)
7429 /* Passed TO_CHARPOS from left to right. */
7430 && ((prev_pos
< to_charpos
7431 && IT_CHARPOS (*it
) > to_charpos
)
7432 /* Passed TO_CHARPOS from right to left. */
7433 || (prev_pos
> to_charpos
7434 && IT_CHARPOS (*it
) < to_charpos
)))))
7436 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7438 result
= MOVE_POS_MATCH_OR_ZV
;
7441 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7442 /* If wrap_it is valid, the current position might be in a
7443 word that is wrapped. So, save the iterator in
7444 atpos_it and continue to see if wrapping happens. */
7448 prev_method
= it
->method
;
7449 if (it
->method
== GET_FROM_BUFFER
)
7450 prev_pos
= IT_CHARPOS (*it
);
7451 /* Stop when ZV reached.
7452 We used to stop here when TO_CHARPOS reached as well, but that is
7453 too soon if this glyph does not fit on this line. So we handle it
7454 explicitly below. */
7455 if (!get_next_display_element (it
))
7457 result
= MOVE_POS_MATCH_OR_ZV
;
7461 if (it
->line_wrap
== TRUNCATE
)
7463 if (BUFFER_POS_REACHED_P ())
7465 result
= MOVE_POS_MATCH_OR_ZV
;
7471 if (it
->line_wrap
== WORD_WRAP
)
7473 if (IT_DISPLAYING_WHITESPACE (it
))
7477 /* We have reached a glyph that follows one or more
7478 whitespace characters. If the position is
7479 already found, we are done. */
7480 if (atpos_it
.sp
>= 0)
7483 result
= MOVE_POS_MATCH_OR_ZV
;
7489 result
= MOVE_X_REACHED
;
7492 /* Otherwise, we can wrap here. */
7499 /* Remember the line height for the current line, in case
7500 the next element doesn't fit on the line. */
7501 ascent
= it
->max_ascent
;
7502 descent
= it
->max_descent
;
7504 /* The call to produce_glyphs will get the metrics of the
7505 display element IT is loaded with. Record the x-position
7506 before this display element, in case it doesn't fit on the
7510 PRODUCE_GLYPHS (it
);
7512 if (it
->area
!= TEXT_AREA
)
7514 set_iterator_to_next (it
, 1);
7515 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7516 SET_TEXT_POS (this_line_min_pos
,
7517 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7521 /* The number of glyphs we get back in IT->nglyphs will normally
7522 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7523 character on a terminal frame, or (iii) a line end. For the
7524 second case, IT->nglyphs - 1 padding glyphs will be present.
7525 (On X frames, there is only one glyph produced for a
7526 composite character.)
7528 The behavior implemented below means, for continuation lines,
7529 that as many spaces of a TAB as fit on the current line are
7530 displayed there. For terminal frames, as many glyphs of a
7531 multi-glyph character are displayed in the current line, too.
7532 This is what the old redisplay code did, and we keep it that
7533 way. Under X, the whole shape of a complex character must
7534 fit on the line or it will be completely displayed in the
7537 Note that both for tabs and padding glyphs, all glyphs have
7541 /* More than one glyph or glyph doesn't fit on line. All
7542 glyphs have the same width. */
7543 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7545 int x_before_this_char
= x
;
7546 int hpos_before_this_char
= it
->hpos
;
7548 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7550 new_x
= x
+ single_glyph_width
;
7552 /* We want to leave anything reaching TO_X to the caller. */
7553 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7555 if (BUFFER_POS_REACHED_P ())
7557 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7558 goto buffer_pos_reached
;
7559 if (atpos_it
.sp
< 0)
7562 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7567 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7570 result
= MOVE_X_REACHED
;
7576 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7581 if (/* Lines are continued. */
7582 it
->line_wrap
!= TRUNCATE
7583 && (/* And glyph doesn't fit on the line. */
7584 new_x
> it
->last_visible_x
7585 /* Or it fits exactly and we're on a window
7587 || (new_x
== it
->last_visible_x
7588 && FRAME_WINDOW_P (it
->f
))))
7590 if (/* IT->hpos == 0 means the very first glyph
7591 doesn't fit on the line, e.g. a wide image. */
7593 || (new_x
== it
->last_visible_x
7594 && FRAME_WINDOW_P (it
->f
)))
7597 it
->current_x
= new_x
;
7599 /* The character's last glyph just barely fits
7601 if (i
== it
->nglyphs
- 1)
7603 /* If this is the destination position,
7604 return a position *before* it in this row,
7605 now that we know it fits in this row. */
7606 if (BUFFER_POS_REACHED_P ())
7608 if (it
->line_wrap
!= WORD_WRAP
7611 it
->hpos
= hpos_before_this_char
;
7612 it
->current_x
= x_before_this_char
;
7613 result
= MOVE_POS_MATCH_OR_ZV
;
7616 if (it
->line_wrap
== WORD_WRAP
7620 atpos_it
.current_x
= x_before_this_char
;
7621 atpos_it
.hpos
= hpos_before_this_char
;
7625 set_iterator_to_next (it
, 1);
7626 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7627 SET_TEXT_POS (this_line_min_pos
,
7628 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7629 /* On graphical terminals, newlines may
7630 "overflow" into the fringe if
7631 overflow-newline-into-fringe is non-nil.
7632 On text-only terminals, newlines may
7633 overflow into the last glyph on the
7635 if (!FRAME_WINDOW_P (it
->f
)
7636 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7638 if (!get_next_display_element (it
))
7640 result
= MOVE_POS_MATCH_OR_ZV
;
7643 if (BUFFER_POS_REACHED_P ())
7645 if (ITERATOR_AT_END_OF_LINE_P (it
))
7646 result
= MOVE_POS_MATCH_OR_ZV
;
7648 result
= MOVE_LINE_CONTINUED
;
7651 if (ITERATOR_AT_END_OF_LINE_P (it
))
7653 result
= MOVE_NEWLINE_OR_CR
;
7660 IT_RESET_X_ASCENT_DESCENT (it
);
7662 if (wrap_it
.sp
>= 0)
7669 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7671 result
= MOVE_LINE_CONTINUED
;
7675 if (BUFFER_POS_REACHED_P ())
7677 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7678 goto buffer_pos_reached
;
7679 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7682 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7686 if (new_x
> it
->first_visible_x
)
7688 /* Glyph is visible. Increment number of glyphs that
7689 would be displayed. */
7694 if (result
!= MOVE_UNDEFINED
)
7697 else if (BUFFER_POS_REACHED_P ())
7700 IT_RESET_X_ASCENT_DESCENT (it
);
7701 result
= MOVE_POS_MATCH_OR_ZV
;
7704 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7706 /* Stop when TO_X specified and reached. This check is
7707 necessary here because of lines consisting of a line end,
7708 only. The line end will not produce any glyphs and we
7709 would never get MOVE_X_REACHED. */
7710 xassert (it
->nglyphs
== 0);
7711 result
= MOVE_X_REACHED
;
7715 /* Is this a line end? If yes, we're done. */
7716 if (ITERATOR_AT_END_OF_LINE_P (it
))
7718 result
= MOVE_NEWLINE_OR_CR
;
7722 if (it
->method
== GET_FROM_BUFFER
)
7723 prev_pos
= IT_CHARPOS (*it
);
7724 /* The current display element has been consumed. Advance
7726 set_iterator_to_next (it
, 1);
7727 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7728 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7730 /* Stop if lines are truncated and IT's current x-position is
7731 past the right edge of the window now. */
7732 if (it
->line_wrap
== TRUNCATE
7733 && it
->current_x
>= it
->last_visible_x
)
7735 if (!FRAME_WINDOW_P (it
->f
)
7736 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7738 if (!get_next_display_element (it
)
7739 || BUFFER_POS_REACHED_P ())
7741 result
= MOVE_POS_MATCH_OR_ZV
;
7744 if (ITERATOR_AT_END_OF_LINE_P (it
))
7746 result
= MOVE_NEWLINE_OR_CR
;
7750 result
= MOVE_LINE_TRUNCATED
;
7753 #undef IT_RESET_X_ASCENT_DESCENT
7756 #undef BUFFER_POS_REACHED_P
7758 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7759 restore the saved iterator. */
7760 if (atpos_it
.sp
>= 0)
7762 else if (atx_it
.sp
>= 0)
7767 /* Restore the iterator settings altered at the beginning of this
7769 it
->glyph_row
= saved_glyph_row
;
7773 /* For external use. */
7775 move_it_in_display_line (struct it
*it
,
7776 EMACS_INT to_charpos
, int to_x
,
7777 enum move_operation_enum op
)
7779 if (it
->line_wrap
== WORD_WRAP
7780 && (op
& MOVE_TO_X
))
7782 struct it save_it
= *it
;
7783 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7784 /* When word-wrap is on, TO_X may lie past the end
7785 of a wrapped line. Then it->current is the
7786 character on the next line, so backtrack to the
7787 space before the wrap point. */
7788 if (skip
== MOVE_LINE_CONTINUED
)
7790 int prev_x
= max (it
->current_x
- 1, 0);
7792 move_it_in_display_line_to
7793 (it
, -1, prev_x
, MOVE_TO_X
);
7797 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7801 /* Move IT forward until it satisfies one or more of the criteria in
7802 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7804 OP is a bit-mask that specifies where to stop, and in particular,
7805 which of those four position arguments makes a difference. See the
7806 description of enum move_operation_enum.
7808 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7809 screen line, this function will set IT to the next position >
7813 move_it_to (struct it
*it
, EMACS_INT to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
7815 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7816 int line_height
, line_start_x
= 0, reached
= 0;
7820 if (op
& MOVE_TO_VPOS
)
7822 /* If no TO_CHARPOS and no TO_X specified, stop at the
7823 start of the line TO_VPOS. */
7824 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7826 if (it
->vpos
== to_vpos
)
7832 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7836 /* TO_VPOS >= 0 means stop at TO_X in the line at
7837 TO_VPOS, or at TO_POS, whichever comes first. */
7838 if (it
->vpos
== to_vpos
)
7844 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7846 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7851 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7853 /* We have reached TO_X but not in the line we want. */
7854 skip
= move_it_in_display_line_to (it
, to_charpos
,
7856 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7864 else if (op
& MOVE_TO_Y
)
7866 struct it it_backup
;
7868 if (it
->line_wrap
== WORD_WRAP
)
7871 /* TO_Y specified means stop at TO_X in the line containing
7872 TO_Y---or at TO_CHARPOS if this is reached first. The
7873 problem is that we can't really tell whether the line
7874 contains TO_Y before we have completely scanned it, and
7875 this may skip past TO_X. What we do is to first scan to
7878 If TO_X is not specified, use a TO_X of zero. The reason
7879 is to make the outcome of this function more predictable.
7880 If we didn't use TO_X == 0, we would stop at the end of
7881 the line which is probably not what a caller would expect
7883 skip
= move_it_in_display_line_to
7884 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7885 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7887 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7888 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7890 else if (skip
== MOVE_X_REACHED
)
7892 /* If TO_X was reached, we want to know whether TO_Y is
7893 in the line. We know this is the case if the already
7894 scanned glyphs make the line tall enough. Otherwise,
7895 we must check by scanning the rest of the line. */
7896 line_height
= it
->max_ascent
+ it
->max_descent
;
7897 if (to_y
>= it
->current_y
7898 && to_y
< it
->current_y
+ line_height
)
7904 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7905 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7907 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7908 line_height
= it
->max_ascent
+ it
->max_descent
;
7909 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7911 if (to_y
>= it
->current_y
7912 && to_y
< it
->current_y
+ line_height
)
7914 /* If TO_Y is in this line and TO_X was reached
7915 above, we scanned too far. We have to restore
7916 IT's settings to the ones before skipping. */
7923 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7929 /* Check whether TO_Y is in this line. */
7930 line_height
= it
->max_ascent
+ it
->max_descent
;
7931 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7933 if (to_y
>= it
->current_y
7934 && to_y
< it
->current_y
+ line_height
)
7936 /* When word-wrap is on, TO_X may lie past the end
7937 of a wrapped line. Then it->current is the
7938 character on the next line, so backtrack to the
7939 space before the wrap point. */
7940 if (skip
== MOVE_LINE_CONTINUED
7941 && it
->line_wrap
== WORD_WRAP
)
7943 int prev_x
= max (it
->current_x
- 1, 0);
7945 skip
= move_it_in_display_line_to
7946 (it
, -1, prev_x
, MOVE_TO_X
);
7955 else if (BUFFERP (it
->object
)
7956 && (it
->method
== GET_FROM_BUFFER
7957 || it
->method
== GET_FROM_STRETCH
)
7958 && IT_CHARPOS (*it
) >= to_charpos
)
7959 skip
= MOVE_POS_MATCH_OR_ZV
;
7961 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7965 case MOVE_POS_MATCH_OR_ZV
:
7969 case MOVE_NEWLINE_OR_CR
:
7970 set_iterator_to_next (it
, 1);
7971 it
->continuation_lines_width
= 0;
7974 case MOVE_LINE_TRUNCATED
:
7975 it
->continuation_lines_width
= 0;
7976 reseat_at_next_visible_line_start (it
, 0);
7977 if ((op
& MOVE_TO_POS
) != 0
7978 && IT_CHARPOS (*it
) > to_charpos
)
7985 case MOVE_LINE_CONTINUED
:
7986 /* For continued lines ending in a tab, some of the glyphs
7987 associated with the tab are displayed on the current
7988 line. Since it->current_x does not include these glyphs,
7989 we use it->last_visible_x instead. */
7992 it
->continuation_lines_width
+= it
->last_visible_x
;
7993 /* When moving by vpos, ensure that the iterator really
7994 advances to the next line (bug#847, bug#969). Fixme:
7995 do we need to do this in other circumstances? */
7996 if (it
->current_x
!= it
->last_visible_x
7997 && (op
& MOVE_TO_VPOS
)
7998 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8000 line_start_x
= it
->current_x
+ it
->pixel_width
8001 - it
->last_visible_x
;
8002 set_iterator_to_next (it
, 0);
8006 it
->continuation_lines_width
+= it
->current_x
;
8013 /* Reset/increment for the next run. */
8014 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8015 it
->current_x
= line_start_x
;
8018 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8020 last_height
= it
->max_ascent
+ it
->max_descent
;
8021 last_max_ascent
= it
->max_ascent
;
8022 it
->max_ascent
= it
->max_descent
= 0;
8027 /* On text terminals, we may stop at the end of a line in the middle
8028 of a multi-character glyph. If the glyph itself is continued,
8029 i.e. it is actually displayed on the next line, don't treat this
8030 stopping point as valid; move to the next line instead (unless
8031 that brings us offscreen). */
8032 if (!FRAME_WINDOW_P (it
->f
)
8034 && IT_CHARPOS (*it
) == to_charpos
8035 && it
->what
== IT_CHARACTER
8037 && it
->line_wrap
== WINDOW_WRAP
8038 && it
->current_x
== it
->last_visible_x
- 1
8041 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8043 it
->continuation_lines_width
+= it
->current_x
;
8044 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8045 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8047 last_height
= it
->max_ascent
+ it
->max_descent
;
8048 last_max_ascent
= it
->max_ascent
;
8051 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8055 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8057 If DY > 0, move IT backward at least that many pixels. DY = 0
8058 means move IT backward to the preceding line start or BEGV. This
8059 function may move over more than DY pixels if IT->current_y - DY
8060 ends up in the middle of a line; in this case IT->current_y will be
8061 set to the top of the line moved to. */
8064 move_it_vertically_backward (struct it
*it
, int dy
)
8068 EMACS_INT start_pos
;
8073 start_pos
= IT_CHARPOS (*it
);
8075 /* Estimate how many newlines we must move back. */
8076 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8078 /* Set the iterator's position that many lines back. */
8079 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8080 back_to_previous_visible_line_start (it
);
8082 /* Reseat the iterator here. When moving backward, we don't want
8083 reseat to skip forward over invisible text, set up the iterator
8084 to deliver from overlay strings at the new position etc. So,
8085 use reseat_1 here. */
8086 reseat_1 (it
, it
->current
.pos
, 1);
8088 /* We are now surely at a line start. */
8089 it
->current_x
= it
->hpos
= 0;
8090 it
->continuation_lines_width
= 0;
8092 /* Move forward and see what y-distance we moved. First move to the
8093 start of the next line so that we get its height. We need this
8094 height to be able to tell whether we reached the specified
8097 it2
.max_ascent
= it2
.max_descent
= 0;
8100 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8101 MOVE_TO_POS
| MOVE_TO_VPOS
);
8103 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
8104 xassert (IT_CHARPOS (*it
) >= BEGV
);
8107 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8108 xassert (IT_CHARPOS (*it
) >= BEGV
);
8109 /* H is the actual vertical distance from the position in *IT
8110 and the starting position. */
8111 h
= it2
.current_y
- it
->current_y
;
8112 /* NLINES is the distance in number of lines. */
8113 nlines
= it2
.vpos
- it
->vpos
;
8115 /* Correct IT's y and vpos position
8116 so that they are relative to the starting point. */
8122 /* DY == 0 means move to the start of the screen line. The
8123 value of nlines is > 0 if continuation lines were involved. */
8125 move_it_by_lines (it
, nlines
);
8129 /* The y-position we try to reach, relative to *IT.
8130 Note that H has been subtracted in front of the if-statement. */
8131 int target_y
= it
->current_y
+ h
- dy
;
8132 int y0
= it3
.current_y
;
8133 int y1
= line_bottom_y (&it3
);
8134 int line_height
= y1
- y0
;
8136 /* If we did not reach target_y, try to move further backward if
8137 we can. If we moved too far backward, try to move forward. */
8138 if (target_y
< it
->current_y
8139 /* This is heuristic. In a window that's 3 lines high, with
8140 a line height of 13 pixels each, recentering with point
8141 on the bottom line will try to move -39/2 = 19 pixels
8142 backward. Try to avoid moving into the first line. */
8143 && (it
->current_y
- target_y
8144 > min (window_box_height (it
->w
), line_height
* 2 / 3))
8145 && IT_CHARPOS (*it
) > BEGV
)
8147 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
8148 target_y
- it
->current_y
));
8149 dy
= it
->current_y
- target_y
;
8150 goto move_further_back
;
8152 else if (target_y
>= it
->current_y
+ line_height
8153 && IT_CHARPOS (*it
) < ZV
)
8155 /* Should move forward by at least one line, maybe more.
8157 Note: Calling move_it_by_lines can be expensive on
8158 terminal frames, where compute_motion is used (via
8159 vmotion) to do the job, when there are very long lines
8160 and truncate-lines is nil. That's the reason for
8161 treating terminal frames specially here. */
8163 if (!FRAME_WINDOW_P (it
->f
))
8164 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
8169 move_it_by_lines (it
, 1);
8171 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
8178 /* Move IT by a specified amount of pixel lines DY. DY negative means
8179 move backwards. DY = 0 means move to start of screen line. At the
8180 end, IT will be on the start of a screen line. */
8183 move_it_vertically (struct it
*it
, int dy
)
8186 move_it_vertically_backward (it
, -dy
);
8189 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
8190 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
8191 MOVE_TO_POS
| MOVE_TO_Y
);
8192 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
8194 /* If buffer ends in ZV without a newline, move to the start of
8195 the line to satisfy the post-condition. */
8196 if (IT_CHARPOS (*it
) == ZV
8198 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8199 move_it_by_lines (it
, 0);
8204 /* Move iterator IT past the end of the text line it is in. */
8207 move_it_past_eol (struct it
*it
)
8209 enum move_it_result rc
;
8211 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
8212 if (rc
== MOVE_NEWLINE_OR_CR
)
8213 set_iterator_to_next (it
, 0);
8217 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
8218 negative means move up. DVPOS == 0 means move to the start of the
8221 Optimization idea: If we would know that IT->f doesn't use
8222 a face with proportional font, we could be faster for
8223 truncate-lines nil. */
8226 move_it_by_lines (struct it
*it
, int dvpos
)
8229 /* The commented-out optimization uses vmotion on terminals. This
8230 gives bad results, because elements like it->what, on which
8231 callers such as pos_visible_p rely, aren't updated. */
8232 /* struct position pos;
8233 if (!FRAME_WINDOW_P (it->f))
8235 struct text_pos textpos;
8237 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
8238 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
8239 reseat (it, textpos, 1);
8240 it->vpos += pos.vpos;
8241 it->current_y += pos.vpos;
8247 /* DVPOS == 0 means move to the start of the screen line. */
8248 move_it_vertically_backward (it
, 0);
8249 xassert (it
->current_x
== 0 && it
->hpos
== 0);
8250 /* Let next call to line_bottom_y calculate real line height */
8255 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
8256 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
8257 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
8262 EMACS_INT start_charpos
, i
;
8264 /* Start at the beginning of the screen line containing IT's
8265 position. This may actually move vertically backwards,
8266 in case of overlays, so adjust dvpos accordingly. */
8268 move_it_vertically_backward (it
, 0);
8271 /* Go back -DVPOS visible lines and reseat the iterator there. */
8272 start_charpos
= IT_CHARPOS (*it
);
8273 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
8274 back_to_previous_visible_line_start (it
);
8275 reseat (it
, it
->current
.pos
, 1);
8277 /* Move further back if we end up in a string or an image. */
8278 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
8280 /* First try to move to start of display line. */
8282 move_it_vertically_backward (it
, 0);
8284 if (IT_POS_VALID_AFTER_MOVE_P (it
))
8286 /* If start of line is still in string or image,
8287 move further back. */
8288 back_to_previous_visible_line_start (it
);
8289 reseat (it
, it
->current
.pos
, 1);
8293 it
->current_x
= it
->hpos
= 0;
8295 /* Above call may have moved too far if continuation lines
8296 are involved. Scan forward and see if it did. */
8298 it2
.vpos
= it2
.current_y
= 0;
8299 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
8300 it
->vpos
-= it2
.vpos
;
8301 it
->current_y
-= it2
.current_y
;
8302 it
->current_x
= it
->hpos
= 0;
8304 /* If we moved too far back, move IT some lines forward. */
8305 if (it2
.vpos
> -dvpos
)
8307 int delta
= it2
.vpos
+ dvpos
;
8309 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
8310 /* Move back again if we got too far ahead. */
8311 if (IT_CHARPOS (*it
) >= start_charpos
)
8317 /* Return 1 if IT points into the middle of a display vector. */
8320 in_display_vector_p (struct it
*it
)
8322 return (it
->method
== GET_FROM_DISPLAY_VECTOR
8323 && it
->current
.dpvec_index
> 0
8324 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
8328 /***********************************************************************
8330 ***********************************************************************/
8333 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
8337 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
8339 Lisp_Object args
[3];
8340 Lisp_Object msg
, fmt
;
8343 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
8346 /* Do nothing if called asynchronously. Inserting text into
8347 a buffer may call after-change-functions and alike and
8348 that would means running Lisp asynchronously. */
8349 if (handling_signal
)
8353 GCPRO4 (fmt
, msg
, arg1
, arg2
);
8355 args
[0] = fmt
= build_string (format
);
8358 msg
= Fformat (3, args
);
8360 len
= SBYTES (msg
) + 1;
8361 SAFE_ALLOCA (buffer
, char *, len
);
8362 memcpy (buffer
, SDATA (msg
), len
);
8364 message_dolog (buffer
, len
- 1, 1, 0);
8371 /* Output a newline in the *Messages* buffer if "needs" one. */
8374 message_log_maybe_newline (void)
8376 if (message_log_need_newline
)
8377 message_dolog ("", 0, 1, 0);
8381 /* Add a string M of length NBYTES to the message log, optionally
8382 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
8383 nonzero, means interpret the contents of M as multibyte. This
8384 function calls low-level routines in order to bypass text property
8385 hooks, etc. which might not be safe to run.
8387 This may GC (insert may run before/after change hooks),
8388 so the buffer M must NOT point to a Lisp string. */
8391 message_dolog (const char *m
, EMACS_INT nbytes
, int nlflag
, int multibyte
)
8393 const unsigned char *msg
= (const unsigned char *) m
;
8395 if (!NILP (Vmemory_full
))
8398 if (!NILP (Vmessage_log_max
))
8400 struct buffer
*oldbuf
;
8401 Lisp_Object oldpoint
, oldbegv
, oldzv
;
8402 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
8403 EMACS_INT point_at_end
= 0;
8404 EMACS_INT zv_at_end
= 0;
8405 Lisp_Object old_deactivate_mark
, tem
;
8406 struct gcpro gcpro1
;
8408 old_deactivate_mark
= Vdeactivate_mark
;
8409 oldbuf
= current_buffer
;
8410 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
8411 BVAR (current_buffer
, undo_list
) = Qt
;
8413 oldpoint
= message_dolog_marker1
;
8414 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
8415 oldbegv
= message_dolog_marker2
;
8416 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
8417 oldzv
= message_dolog_marker3
;
8418 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
8419 GCPRO1 (old_deactivate_mark
);
8427 BEGV_BYTE
= BEG_BYTE
;
8430 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8432 /* Insert the string--maybe converting multibyte to single byte
8433 or vice versa, so that all the text fits the buffer. */
8435 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8441 /* Convert a multibyte string to single-byte
8442 for the *Message* buffer. */
8443 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
8445 c
= string_char_and_length (msg
+ i
, &char_bytes
);
8446 work
[0] = (ASCII_CHAR_P (c
)
8448 : multibyte_char_to_unibyte (c
));
8449 insert_1_both (work
, 1, 1, 1, 0, 0);
8452 else if (! multibyte
8453 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8457 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8458 /* Convert a single-byte string to multibyte
8459 for the *Message* buffer. */
8460 for (i
= 0; i
< nbytes
; i
++)
8463 MAKE_CHAR_MULTIBYTE (c
);
8464 char_bytes
= CHAR_STRING (c
, str
);
8465 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
8469 insert_1 (m
, nbytes
, 1, 0, 0);
8473 EMACS_INT this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
8474 unsigned long int dups
;
8475 insert_1 ("\n", 1, 1, 0, 0);
8477 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8479 this_bol_byte
= PT_BYTE
;
8481 /* See if this line duplicates the previous one.
8482 If so, combine duplicates. */
8485 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8487 prev_bol_byte
= PT_BYTE
;
8489 dups
= message_log_check_duplicate (prev_bol_byte
,
8493 del_range_both (prev_bol
, prev_bol_byte
,
8494 this_bol
, this_bol_byte
, 0);
8500 /* If you change this format, don't forget to also
8501 change message_log_check_duplicate. */
8502 sprintf (dupstr
, " [%lu times]", dups
);
8503 duplen
= strlen (dupstr
);
8504 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8505 insert_1 (dupstr
, duplen
, 1, 0, 1);
8510 /* If we have more than the desired maximum number of lines
8511 in the *Messages* buffer now, delete the oldest ones.
8512 This is safe because we don't have undo in this buffer. */
8514 if (NATNUMP (Vmessage_log_max
))
8516 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8517 -XFASTINT (Vmessage_log_max
) - 1, 0);
8518 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8521 BEGV
= XMARKER (oldbegv
)->charpos
;
8522 BEGV_BYTE
= marker_byte_position (oldbegv
);
8531 ZV
= XMARKER (oldzv
)->charpos
;
8532 ZV_BYTE
= marker_byte_position (oldzv
);
8536 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8538 /* We can't do Fgoto_char (oldpoint) because it will run some
8540 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8541 XMARKER (oldpoint
)->bytepos
);
8544 unchain_marker (XMARKER (oldpoint
));
8545 unchain_marker (XMARKER (oldbegv
));
8546 unchain_marker (XMARKER (oldzv
));
8548 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8549 set_buffer_internal (oldbuf
);
8551 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8552 message_log_need_newline
= !nlflag
;
8553 Vdeactivate_mark
= old_deactivate_mark
;
8558 /* We are at the end of the buffer after just having inserted a newline.
8559 (Note: We depend on the fact we won't be crossing the gap.)
8560 Check to see if the most recent message looks a lot like the previous one.
8561 Return 0 if different, 1 if the new one should just replace it, or a
8562 value N > 1 if we should also append " [N times]". */
8564 static unsigned long int
8565 message_log_check_duplicate (EMACS_INT prev_bol_byte
, EMACS_INT this_bol_byte
)
8568 EMACS_INT len
= Z_BYTE
- 1 - this_bol_byte
;
8570 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8571 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8573 for (i
= 0; i
< len
; i
++)
8575 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8583 if (*p1
++ == ' ' && *p1
++ == '[')
8586 unsigned long int n
= strtoul ((char *) p1
, &pend
, 10);
8587 if (strncmp (pend
, " times]\n", 8) == 0)
8594 /* Display an echo area message M with a specified length of NBYTES
8595 bytes. The string may include null characters. If M is 0, clear
8596 out any existing message, and let the mini-buffer text show
8599 This may GC, so the buffer M must NOT point to a Lisp string. */
8602 message2 (const char *m
, EMACS_INT nbytes
, int multibyte
)
8604 /* First flush out any partial line written with print. */
8605 message_log_maybe_newline ();
8607 message_dolog (m
, nbytes
, 1, multibyte
);
8608 message2_nolog (m
, nbytes
, multibyte
);
8612 /* The non-logging counterpart of message2. */
8615 message2_nolog (const char *m
, EMACS_INT nbytes
, int multibyte
)
8617 struct frame
*sf
= SELECTED_FRAME ();
8618 message_enable_multibyte
= multibyte
;
8620 if (FRAME_INITIAL_P (sf
))
8622 if (noninteractive_need_newline
)
8623 putc ('\n', stderr
);
8624 noninteractive_need_newline
= 0;
8626 fwrite (m
, nbytes
, 1, stderr
);
8627 if (cursor_in_echo_area
== 0)
8628 fprintf (stderr
, "\n");
8631 /* A null message buffer means that the frame hasn't really been
8632 initialized yet. Error messages get reported properly by
8633 cmd_error, so this must be just an informative message; toss it. */
8634 else if (INTERACTIVE
8635 && sf
->glyphs_initialized_p
8636 && FRAME_MESSAGE_BUF (sf
))
8638 Lisp_Object mini_window
;
8641 /* Get the frame containing the mini-buffer
8642 that the selected frame is using. */
8643 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8644 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8646 FRAME_SAMPLE_VISIBILITY (f
);
8647 if (FRAME_VISIBLE_P (sf
)
8648 && ! FRAME_VISIBLE_P (f
))
8649 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8653 set_message (m
, Qnil
, nbytes
, multibyte
);
8654 if (minibuffer_auto_raise
)
8655 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8658 clear_message (1, 1);
8660 do_pending_window_change (0);
8661 echo_area_display (1);
8662 do_pending_window_change (0);
8663 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8664 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8669 /* Display an echo area message M with a specified length of NBYTES
8670 bytes. The string may include null characters. If M is not a
8671 string, clear out any existing message, and let the mini-buffer
8674 This function cancels echoing. */
8677 message3 (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8679 struct gcpro gcpro1
;
8682 clear_message (1,1);
8685 /* First flush out any partial line written with print. */
8686 message_log_maybe_newline ();
8692 SAFE_ALLOCA (buffer
, char *, nbytes
);
8693 memcpy (buffer
, SDATA (m
), nbytes
);
8694 message_dolog (buffer
, nbytes
, 1, multibyte
);
8697 message3_nolog (m
, nbytes
, multibyte
);
8703 /* The non-logging version of message3.
8704 This does not cancel echoing, because it is used for echoing.
8705 Perhaps we need to make a separate function for echoing
8706 and make this cancel echoing. */
8709 message3_nolog (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8711 struct frame
*sf
= SELECTED_FRAME ();
8712 message_enable_multibyte
= multibyte
;
8714 if (FRAME_INITIAL_P (sf
))
8716 if (noninteractive_need_newline
)
8717 putc ('\n', stderr
);
8718 noninteractive_need_newline
= 0;
8720 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8721 if (cursor_in_echo_area
== 0)
8722 fprintf (stderr
, "\n");
8725 /* A null message buffer means that the frame hasn't really been
8726 initialized yet. Error messages get reported properly by
8727 cmd_error, so this must be just an informative message; toss it. */
8728 else if (INTERACTIVE
8729 && sf
->glyphs_initialized_p
8730 && FRAME_MESSAGE_BUF (sf
))
8732 Lisp_Object mini_window
;
8736 /* Get the frame containing the mini-buffer
8737 that the selected frame is using. */
8738 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8739 frame
= XWINDOW (mini_window
)->frame
;
8742 FRAME_SAMPLE_VISIBILITY (f
);
8743 if (FRAME_VISIBLE_P (sf
)
8744 && !FRAME_VISIBLE_P (f
))
8745 Fmake_frame_visible (frame
);
8747 if (STRINGP (m
) && SCHARS (m
) > 0)
8749 set_message (NULL
, m
, nbytes
, multibyte
);
8750 if (minibuffer_auto_raise
)
8751 Fraise_frame (frame
);
8752 /* Assume we are not echoing.
8753 (If we are, echo_now will override this.) */
8754 echo_message_buffer
= Qnil
;
8757 clear_message (1, 1);
8759 do_pending_window_change (0);
8760 echo_area_display (1);
8761 do_pending_window_change (0);
8762 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8763 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8768 /* Display a null-terminated echo area message M. If M is 0, clear
8769 out any existing message, and let the mini-buffer text show through.
8771 The buffer M must continue to exist until after the echo area gets
8772 cleared or some other message gets displayed there. Do not pass
8773 text that is stored in a Lisp string. Do not pass text in a buffer
8774 that was alloca'd. */
8777 message1 (const char *m
)
8779 message2 (m
, (m
? strlen (m
) : 0), 0);
8783 /* The non-logging counterpart of message1. */
8786 message1_nolog (const char *m
)
8788 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8791 /* Display a message M which contains a single %s
8792 which gets replaced with STRING. */
8795 message_with_string (const char *m
, Lisp_Object string
, int log
)
8797 CHECK_STRING (string
);
8803 if (noninteractive_need_newline
)
8804 putc ('\n', stderr
);
8805 noninteractive_need_newline
= 0;
8806 fprintf (stderr
, m
, SDATA (string
));
8807 if (!cursor_in_echo_area
)
8808 fprintf (stderr
, "\n");
8812 else if (INTERACTIVE
)
8814 /* The frame whose minibuffer we're going to display the message on.
8815 It may be larger than the selected frame, so we need
8816 to use its buffer, not the selected frame's buffer. */
8817 Lisp_Object mini_window
;
8818 struct frame
*f
, *sf
= SELECTED_FRAME ();
8820 /* Get the frame containing the minibuffer
8821 that the selected frame is using. */
8822 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8823 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8825 /* A null message buffer means that the frame hasn't really been
8826 initialized yet. Error messages get reported properly by
8827 cmd_error, so this must be just an informative message; toss it. */
8828 if (FRAME_MESSAGE_BUF (f
))
8830 Lisp_Object args
[2], msg
;
8831 struct gcpro gcpro1
, gcpro2
;
8833 args
[0] = build_string (m
);
8834 args
[1] = msg
= string
;
8835 GCPRO2 (args
[0], msg
);
8838 msg
= Fformat (2, args
);
8841 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8843 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8847 /* Print should start at the beginning of the message
8848 buffer next time. */
8849 message_buf_print
= 0;
8855 /* Dump an informative message to the minibuf. If M is 0, clear out
8856 any existing message, and let the mini-buffer text show through. */
8859 vmessage (const char *m
, va_list ap
)
8865 if (noninteractive_need_newline
)
8866 putc ('\n', stderr
);
8867 noninteractive_need_newline
= 0;
8868 vfprintf (stderr
, m
, ap
);
8869 if (cursor_in_echo_area
== 0)
8870 fprintf (stderr
, "\n");
8874 else if (INTERACTIVE
)
8876 /* The frame whose mini-buffer we're going to display the message
8877 on. It may be larger than the selected frame, so we need to
8878 use its buffer, not the selected frame's buffer. */
8879 Lisp_Object mini_window
;
8880 struct frame
*f
, *sf
= SELECTED_FRAME ();
8882 /* Get the frame containing the mini-buffer
8883 that the selected frame is using. */
8884 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8885 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8887 /* A null message buffer means that the frame hasn't really been
8888 initialized yet. Error messages get reported properly by
8889 cmd_error, so this must be just an informative message; toss
8891 if (FRAME_MESSAGE_BUF (f
))
8897 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8898 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
8900 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8905 /* Print should start at the beginning of the message
8906 buffer next time. */
8907 message_buf_print
= 0;
8913 message (const char *m
, ...)
8923 /* The non-logging version of message. */
8926 message_nolog (const char *m
, ...)
8928 Lisp_Object old_log_max
;
8931 old_log_max
= Vmessage_log_max
;
8932 Vmessage_log_max
= Qnil
;
8934 Vmessage_log_max
= old_log_max
;
8940 /* Display the current message in the current mini-buffer. This is
8941 only called from error handlers in process.c, and is not time
8945 update_echo_area (void)
8947 if (!NILP (echo_area_buffer
[0]))
8950 string
= Fcurrent_message ();
8951 message3 (string
, SBYTES (string
),
8952 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
8957 /* Make sure echo area buffers in `echo_buffers' are live.
8958 If they aren't, make new ones. */
8961 ensure_echo_area_buffers (void)
8965 for (i
= 0; i
< 2; ++i
)
8966 if (!BUFFERP (echo_buffer
[i
])
8967 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
8970 Lisp_Object old_buffer
;
8973 old_buffer
= echo_buffer
[i
];
8974 sprintf (name
, " *Echo Area %d*", i
);
8975 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8976 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
8977 /* to force word wrap in echo area -
8978 it was decided to postpone this*/
8979 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8981 for (j
= 0; j
< 2; ++j
)
8982 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8983 echo_area_buffer
[j
] = echo_buffer
[i
];
8988 /* Call FN with args A1..A4 with either the current or last displayed
8989 echo_area_buffer as current buffer.
8991 WHICH zero means use the current message buffer
8992 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8993 from echo_buffer[] and clear it.
8995 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8996 suitable buffer from echo_buffer[] and clear it.
8998 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8999 that the current message becomes the last displayed one, make
9000 choose a suitable buffer for echo_area_buffer[0], and clear it.
9002 Value is what FN returns. */
9005 with_echo_area_buffer (struct window
*w
, int which
,
9006 int (*fn
) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
9007 EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9010 int this_one
, the_other
, clear_buffer_p
, rc
;
9011 int count
= SPECPDL_INDEX ();
9013 /* If buffers aren't live, make new ones. */
9014 ensure_echo_area_buffers ();
9019 this_one
= 0, the_other
= 1;
9021 this_one
= 1, the_other
= 0;
9024 this_one
= 0, the_other
= 1;
9027 /* We need a fresh one in case the current echo buffer equals
9028 the one containing the last displayed echo area message. */
9029 if (!NILP (echo_area_buffer
[this_one
])
9030 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9031 echo_area_buffer
[this_one
] = Qnil
;
9034 /* Choose a suitable buffer from echo_buffer[] is we don't
9036 if (NILP (echo_area_buffer
[this_one
]))
9038 echo_area_buffer
[this_one
]
9039 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9040 ? echo_buffer
[the_other
]
9041 : echo_buffer
[this_one
]);
9045 buffer
= echo_area_buffer
[this_one
];
9047 /* Don't get confused by reusing the buffer used for echoing
9048 for a different purpose. */
9049 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9052 record_unwind_protect (unwind_with_echo_area_buffer
,
9053 with_echo_area_buffer_unwind_data (w
));
9055 /* Make the echo area buffer current. Note that for display
9056 purposes, it is not necessary that the displayed window's buffer
9057 == current_buffer, except for text property lookup. So, let's
9058 only set that buffer temporarily here without doing a full
9059 Fset_window_buffer. We must also change w->pointm, though,
9060 because otherwise an assertions in unshow_buffer fails, and Emacs
9062 set_buffer_internal_1 (XBUFFER (buffer
));
9066 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9069 BVAR (current_buffer
, undo_list
) = Qt
;
9070 BVAR (current_buffer
, read_only
) = Qnil
;
9071 specbind (Qinhibit_read_only
, Qt
);
9072 specbind (Qinhibit_modification_hooks
, Qt
);
9074 if (clear_buffer_p
&& Z
> BEG
)
9077 xassert (BEGV
>= BEG
);
9078 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9080 rc
= fn (a1
, a2
, a3
, a4
);
9082 xassert (BEGV
>= BEG
);
9083 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9085 unbind_to (count
, Qnil
);
9090 /* Save state that should be preserved around the call to the function
9091 FN called in with_echo_area_buffer. */
9094 with_echo_area_buffer_unwind_data (struct window
*w
)
9097 Lisp_Object vector
, tmp
;
9099 /* Reduce consing by keeping one vector in
9100 Vwith_echo_area_save_vector. */
9101 vector
= Vwith_echo_area_save_vector
;
9102 Vwith_echo_area_save_vector
= Qnil
;
9105 vector
= Fmake_vector (make_number (7), Qnil
);
9107 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9108 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9109 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
9113 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
9114 ASET (vector
, i
, w
->buffer
); ++i
;
9115 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
9116 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
9121 for (; i
< end
; ++i
)
9122 ASET (vector
, i
, Qnil
);
9125 xassert (i
== ASIZE (vector
));
9130 /* Restore global state from VECTOR which was created by
9131 with_echo_area_buffer_unwind_data. */
9134 unwind_with_echo_area_buffer (Lisp_Object vector
)
9136 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
9137 Vdeactivate_mark
= AREF (vector
, 1);
9138 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
9140 if (WINDOWP (AREF (vector
, 3)))
9143 Lisp_Object buffer
, charpos
, bytepos
;
9145 w
= XWINDOW (AREF (vector
, 3));
9146 buffer
= AREF (vector
, 4);
9147 charpos
= AREF (vector
, 5);
9148 bytepos
= AREF (vector
, 6);
9151 set_marker_both (w
->pointm
, buffer
,
9152 XFASTINT (charpos
), XFASTINT (bytepos
));
9155 Vwith_echo_area_save_vector
= vector
;
9160 /* Set up the echo area for use by print functions. MULTIBYTE_P
9161 non-zero means we will print multibyte. */
9164 setup_echo_area_for_printing (int multibyte_p
)
9166 /* If we can't find an echo area any more, exit. */
9167 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9170 ensure_echo_area_buffers ();
9172 if (!message_buf_print
)
9174 /* A message has been output since the last time we printed.
9175 Choose a fresh echo area buffer. */
9176 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9177 echo_area_buffer
[0] = echo_buffer
[1];
9179 echo_area_buffer
[0] = echo_buffer
[0];
9181 /* Switch to that buffer and clear it. */
9182 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9183 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9187 int count
= SPECPDL_INDEX ();
9188 specbind (Qinhibit_read_only
, Qt
);
9189 /* Note that undo recording is always disabled. */
9191 unbind_to (count
, Qnil
);
9193 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9195 /* Set up the buffer for the multibyteness we need. */
9197 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9198 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
9200 /* Raise the frame containing the echo area. */
9201 if (minibuffer_auto_raise
)
9203 struct frame
*sf
= SELECTED_FRAME ();
9204 Lisp_Object mini_window
;
9205 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9206 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9209 message_log_maybe_newline ();
9210 message_buf_print
= 1;
9214 if (NILP (echo_area_buffer
[0]))
9216 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9217 echo_area_buffer
[0] = echo_buffer
[1];
9219 echo_area_buffer
[0] = echo_buffer
[0];
9222 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
9224 /* Someone switched buffers between print requests. */
9225 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9226 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9232 /* Display an echo area message in window W. Value is non-zero if W's
9233 height is changed. If display_last_displayed_message_p is
9234 non-zero, display the message that was last displayed, otherwise
9235 display the current message. */
9238 display_echo_area (struct window
*w
)
9240 int i
, no_message_p
, window_height_changed_p
, count
;
9242 /* Temporarily disable garbage collections while displaying the echo
9243 area. This is done because a GC can print a message itself.
9244 That message would modify the echo area buffer's contents while a
9245 redisplay of the buffer is going on, and seriously confuse
9247 count
= inhibit_garbage_collection ();
9249 /* If there is no message, we must call display_echo_area_1
9250 nevertheless because it resizes the window. But we will have to
9251 reset the echo_area_buffer in question to nil at the end because
9252 with_echo_area_buffer will sets it to an empty buffer. */
9253 i
= display_last_displayed_message_p
? 1 : 0;
9254 no_message_p
= NILP (echo_area_buffer
[i
]);
9256 window_height_changed_p
9257 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
9258 display_echo_area_1
,
9259 (intptr_t) w
, Qnil
, 0, 0);
9262 echo_area_buffer
[i
] = Qnil
;
9264 unbind_to (count
, Qnil
);
9265 return window_height_changed_p
;
9269 /* Helper for display_echo_area. Display the current buffer which
9270 contains the current echo area message in window W, a mini-window,
9271 a pointer to which is passed in A1. A2..A4 are currently not used.
9272 Change the height of W so that all of the message is displayed.
9273 Value is non-zero if height of W was changed. */
9276 display_echo_area_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9279 struct window
*w
= (struct window
*) i1
;
9281 struct text_pos start
;
9282 int window_height_changed_p
= 0;
9284 /* Do this before displaying, so that we have a large enough glyph
9285 matrix for the display. If we can't get enough space for the
9286 whole text, display the last N lines. That works by setting w->start. */
9287 window_height_changed_p
= resize_mini_window (w
, 0);
9289 /* Use the starting position chosen by resize_mini_window. */
9290 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
9293 clear_glyph_matrix (w
->desired_matrix
);
9294 XSETWINDOW (window
, w
);
9295 try_window (window
, start
, 0);
9297 return window_height_changed_p
;
9301 /* Resize the echo area window to exactly the size needed for the
9302 currently displayed message, if there is one. If a mini-buffer
9303 is active, don't shrink it. */
9306 resize_echo_area_exactly (void)
9308 if (BUFFERP (echo_area_buffer
[0])
9309 && WINDOWP (echo_area_window
))
9311 struct window
*w
= XWINDOW (echo_area_window
);
9313 Lisp_Object resize_exactly
;
9315 if (minibuf_level
== 0)
9316 resize_exactly
= Qt
;
9318 resize_exactly
= Qnil
;
9320 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
9321 (intptr_t) w
, resize_exactly
,
9325 ++windows_or_buffers_changed
;
9326 ++update_mode_lines
;
9327 redisplay_internal ();
9333 /* Callback function for with_echo_area_buffer, when used from
9334 resize_echo_area_exactly. A1 contains a pointer to the window to
9335 resize, EXACTLY non-nil means resize the mini-window exactly to the
9336 size of the text displayed. A3 and A4 are not used. Value is what
9337 resize_mini_window returns. */
9340 resize_mini_window_1 (EMACS_INT a1
, Lisp_Object exactly
, EMACS_INT a3
, EMACS_INT a4
)
9343 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
9347 /* Resize mini-window W to fit the size of its contents. EXACT_P
9348 means size the window exactly to the size needed. Otherwise, it's
9349 only enlarged until W's buffer is empty.
9351 Set W->start to the right place to begin display. If the whole
9352 contents fit, start at the beginning. Otherwise, start so as
9353 to make the end of the contents appear. This is particularly
9354 important for y-or-n-p, but seems desirable generally.
9356 Value is non-zero if the window height has been changed. */
9359 resize_mini_window (struct window
*w
, int exact_p
)
9361 struct frame
*f
= XFRAME (w
->frame
);
9362 int window_height_changed_p
= 0;
9364 xassert (MINI_WINDOW_P (w
));
9366 /* By default, start display at the beginning. */
9367 set_marker_both (w
->start
, w
->buffer
,
9368 BUF_BEGV (XBUFFER (w
->buffer
)),
9369 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
9371 /* Don't resize windows while redisplaying a window; it would
9372 confuse redisplay functions when the size of the window they are
9373 displaying changes from under them. Such a resizing can happen,
9374 for instance, when which-func prints a long message while
9375 we are running fontification-functions. We're running these
9376 functions with safe_call which binds inhibit-redisplay to t. */
9377 if (!NILP (Vinhibit_redisplay
))
9380 /* Nil means don't try to resize. */
9381 if (NILP (Vresize_mini_windows
)
9382 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
9385 if (!FRAME_MINIBUF_ONLY_P (f
))
9388 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
9389 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
9390 int height
, max_height
;
9391 int unit
= FRAME_LINE_HEIGHT (f
);
9392 struct text_pos start
;
9393 struct buffer
*old_current_buffer
= NULL
;
9395 if (current_buffer
!= XBUFFER (w
->buffer
))
9397 old_current_buffer
= current_buffer
;
9398 set_buffer_internal (XBUFFER (w
->buffer
));
9401 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9403 /* Compute the max. number of lines specified by the user. */
9404 if (FLOATP (Vmax_mini_window_height
))
9405 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
9406 else if (INTEGERP (Vmax_mini_window_height
))
9407 max_height
= XINT (Vmax_mini_window_height
);
9409 max_height
= total_height
/ 4;
9411 /* Correct that max. height if it's bogus. */
9412 max_height
= max (1, max_height
);
9413 max_height
= min (total_height
, max_height
);
9415 /* Find out the height of the text in the window. */
9416 if (it
.line_wrap
== TRUNCATE
)
9421 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
9422 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
9423 height
= it
.current_y
+ last_height
;
9425 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9426 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9427 height
= (height
+ unit
- 1) / unit
;
9430 /* Compute a suitable window start. */
9431 if (height
> max_height
)
9433 height
= max_height
;
9434 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9435 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9436 start
= it
.current
.pos
;
9439 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9440 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9442 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9444 /* Let it grow only, until we display an empty message, in which
9445 case the window shrinks again. */
9446 if (height
> WINDOW_TOTAL_LINES (w
))
9448 int old_height
= WINDOW_TOTAL_LINES (w
);
9449 freeze_window_starts (f
, 1);
9450 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9451 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9453 else if (height
< WINDOW_TOTAL_LINES (w
)
9454 && (exact_p
|| BEGV
== ZV
))
9456 int old_height
= WINDOW_TOTAL_LINES (w
);
9457 freeze_window_starts (f
, 0);
9458 shrink_mini_window (w
);
9459 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9464 /* Always resize to exact size needed. */
9465 if (height
> WINDOW_TOTAL_LINES (w
))
9467 int old_height
= WINDOW_TOTAL_LINES (w
);
9468 freeze_window_starts (f
, 1);
9469 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9470 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9472 else if (height
< WINDOW_TOTAL_LINES (w
))
9474 int old_height
= WINDOW_TOTAL_LINES (w
);
9475 freeze_window_starts (f
, 0);
9476 shrink_mini_window (w
);
9480 freeze_window_starts (f
, 1);
9481 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9484 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9488 if (old_current_buffer
)
9489 set_buffer_internal (old_current_buffer
);
9492 return window_height_changed_p
;
9496 /* Value is the current message, a string, or nil if there is no
9500 current_message (void)
9504 if (!BUFFERP (echo_area_buffer
[0]))
9508 with_echo_area_buffer (0, 0, current_message_1
,
9509 (intptr_t) &msg
, Qnil
, 0, 0);
9511 echo_area_buffer
[0] = Qnil
;
9519 current_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9522 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
9525 *msg
= make_buffer_string (BEG
, Z
, 1);
9532 /* Push the current message on Vmessage_stack for later restauration
9533 by restore_message. Value is non-zero if the current message isn't
9534 empty. This is a relatively infrequent operation, so it's not
9535 worth optimizing. */
9541 msg
= current_message ();
9542 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9543 return STRINGP (msg
);
9547 /* Restore message display from the top of Vmessage_stack. */
9550 restore_message (void)
9554 xassert (CONSP (Vmessage_stack
));
9555 msg
= XCAR (Vmessage_stack
);
9557 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9559 message3_nolog (msg
, 0, 0);
9563 /* Handler for record_unwind_protect calling pop_message. */
9566 pop_message_unwind (Lisp_Object dummy
)
9572 /* Pop the top-most entry off Vmessage_stack. */
9577 xassert (CONSP (Vmessage_stack
));
9578 Vmessage_stack
= XCDR (Vmessage_stack
);
9582 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9583 exits. If the stack is not empty, we have a missing pop_message
9587 check_message_stack (void)
9589 if (!NILP (Vmessage_stack
))
9594 /* Truncate to NCHARS what will be displayed in the echo area the next
9595 time we display it---but don't redisplay it now. */
9598 truncate_echo_area (EMACS_INT nchars
)
9601 echo_area_buffer
[0] = Qnil
;
9602 /* A null message buffer means that the frame hasn't really been
9603 initialized yet. Error messages get reported properly by
9604 cmd_error, so this must be just an informative message; toss it. */
9605 else if (!noninteractive
9607 && !NILP (echo_area_buffer
[0]))
9609 struct frame
*sf
= SELECTED_FRAME ();
9610 if (FRAME_MESSAGE_BUF (sf
))
9611 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9616 /* Helper function for truncate_echo_area. Truncate the current
9617 message to at most NCHARS characters. */
9620 truncate_message_1 (EMACS_INT nchars
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9622 if (BEG
+ nchars
< Z
)
9623 del_range (BEG
+ nchars
, Z
);
9625 echo_area_buffer
[0] = Qnil
;
9630 /* Set the current message to a substring of S or STRING.
9632 If STRING is a Lisp string, set the message to the first NBYTES
9633 bytes from STRING. NBYTES zero means use the whole string. If
9634 STRING is multibyte, the message will be displayed multibyte.
9636 If S is not null, set the message to the first LEN bytes of S. LEN
9637 zero means use the whole string. MULTIBYTE_P non-zero means S is
9638 multibyte. Display the message multibyte in that case.
9640 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9641 to t before calling set_message_1 (which calls insert).
9645 set_message (const char *s
, Lisp_Object string
,
9646 EMACS_INT nbytes
, int multibyte_p
)
9648 message_enable_multibyte
9649 = ((s
&& multibyte_p
)
9650 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9652 with_echo_area_buffer (0, -1, set_message_1
,
9653 (intptr_t) s
, string
, nbytes
, multibyte_p
);
9654 message_buf_print
= 0;
9655 help_echo_showing_p
= 0;
9659 /* Helper function for set_message. Arguments have the same meaning
9660 as there, with A1 corresponding to S and A2 corresponding to STRING
9661 This function is called with the echo area buffer being
9665 set_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT nbytes
, EMACS_INT multibyte_p
)
9668 const char *s
= (const char *) i1
;
9669 const unsigned char *msg
= (const unsigned char *) s
;
9670 Lisp_Object string
= a2
;
9672 /* Change multibyteness of the echo buffer appropriately. */
9673 if (message_enable_multibyte
9674 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9675 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9677 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
9678 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
9679 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
9681 /* Insert new message at BEG. */
9682 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9684 if (STRINGP (string
))
9689 nbytes
= SBYTES (string
);
9690 nchars
= string_byte_to_char (string
, nbytes
);
9692 /* This function takes care of single/multibyte conversion. We
9693 just have to ensure that the echo area buffer has the right
9694 setting of enable_multibyte_characters. */
9695 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9700 nbytes
= strlen (s
);
9702 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9704 /* Convert from multi-byte to single-byte. */
9709 /* Convert a multibyte string to single-byte. */
9710 for (i
= 0; i
< nbytes
; i
+= n
)
9712 c
= string_char_and_length (msg
+ i
, &n
);
9713 work
[0] = (ASCII_CHAR_P (c
)
9715 : multibyte_char_to_unibyte (c
));
9716 insert_1_both (work
, 1, 1, 1, 0, 0);
9719 else if (!multibyte_p
9720 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9722 /* Convert from single-byte to multi-byte. */
9725 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9727 /* Convert a single-byte string to multibyte. */
9728 for (i
= 0; i
< nbytes
; i
++)
9731 MAKE_CHAR_MULTIBYTE (c
);
9732 n
= CHAR_STRING (c
, str
);
9733 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
9737 insert_1 (s
, nbytes
, 1, 0, 0);
9744 /* Clear messages. CURRENT_P non-zero means clear the current
9745 message. LAST_DISPLAYED_P non-zero means clear the message
9749 clear_message (int current_p
, int last_displayed_p
)
9753 echo_area_buffer
[0] = Qnil
;
9754 message_cleared_p
= 1;
9757 if (last_displayed_p
)
9758 echo_area_buffer
[1] = Qnil
;
9760 message_buf_print
= 0;
9763 /* Clear garbaged frames.
9765 This function is used where the old redisplay called
9766 redraw_garbaged_frames which in turn called redraw_frame which in
9767 turn called clear_frame. The call to clear_frame was a source of
9768 flickering. I believe a clear_frame is not necessary. It should
9769 suffice in the new redisplay to invalidate all current matrices,
9770 and ensure a complete redisplay of all windows. */
9773 clear_garbaged_frames (void)
9777 Lisp_Object tail
, frame
;
9778 int changed_count
= 0;
9780 FOR_EACH_FRAME (tail
, frame
)
9782 struct frame
*f
= XFRAME (frame
);
9784 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9788 Fredraw_frame (frame
);
9789 f
->force_flush_display_p
= 1;
9791 clear_current_matrices (f
);
9800 ++windows_or_buffers_changed
;
9805 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9806 is non-zero update selected_frame. Value is non-zero if the
9807 mini-windows height has been changed. */
9810 echo_area_display (int update_frame_p
)
9812 Lisp_Object mini_window
;
9815 int window_height_changed_p
= 0;
9816 struct frame
*sf
= SELECTED_FRAME ();
9818 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9819 w
= XWINDOW (mini_window
);
9820 f
= XFRAME (WINDOW_FRAME (w
));
9822 /* Don't display if frame is invisible or not yet initialized. */
9823 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9826 #ifdef HAVE_WINDOW_SYSTEM
9827 /* When Emacs starts, selected_frame may be the initial terminal
9828 frame. If we let this through, a message would be displayed on
9830 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9832 #endif /* HAVE_WINDOW_SYSTEM */
9834 /* Redraw garbaged frames. */
9836 clear_garbaged_frames ();
9838 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9840 echo_area_window
= mini_window
;
9841 window_height_changed_p
= display_echo_area (w
);
9842 w
->must_be_updated_p
= 1;
9844 /* Update the display, unless called from redisplay_internal.
9845 Also don't update the screen during redisplay itself. The
9846 update will happen at the end of redisplay, and an update
9847 here could cause confusion. */
9848 if (update_frame_p
&& !redisplaying_p
)
9852 /* If the display update has been interrupted by pending
9853 input, update mode lines in the frame. Due to the
9854 pending input, it might have been that redisplay hasn't
9855 been called, so that mode lines above the echo area are
9856 garbaged. This looks odd, so we prevent it here. */
9857 if (!display_completed
)
9858 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9860 if (window_height_changed_p
9861 /* Don't do this if Emacs is shutting down. Redisplay
9862 needs to run hooks. */
9863 && !NILP (Vrun_hooks
))
9865 /* Must update other windows. Likewise as in other
9866 cases, don't let this update be interrupted by
9868 int count
= SPECPDL_INDEX ();
9869 specbind (Qredisplay_dont_pause
, Qt
);
9870 windows_or_buffers_changed
= 1;
9871 redisplay_internal ();
9872 unbind_to (count
, Qnil
);
9874 else if (FRAME_WINDOW_P (f
) && n
== 0)
9876 /* Window configuration is the same as before.
9877 Can do with a display update of the echo area,
9878 unless we displayed some mode lines. */
9879 update_single_window (w
, 1);
9880 FRAME_RIF (f
)->flush_display (f
);
9883 update_frame (f
, 1, 1);
9885 /* If cursor is in the echo area, make sure that the next
9886 redisplay displays the minibuffer, so that the cursor will
9887 be replaced with what the minibuffer wants. */
9888 if (cursor_in_echo_area
)
9889 ++windows_or_buffers_changed
;
9892 else if (!EQ (mini_window
, selected_window
))
9893 windows_or_buffers_changed
++;
9895 /* Last displayed message is now the current message. */
9896 echo_area_buffer
[1] = echo_area_buffer
[0];
9897 /* Inform read_char that we're not echoing. */
9898 echo_message_buffer
= Qnil
;
9900 /* Prevent redisplay optimization in redisplay_internal by resetting
9901 this_line_start_pos. This is done because the mini-buffer now
9902 displays the message instead of its buffer text. */
9903 if (EQ (mini_window
, selected_window
))
9904 CHARPOS (this_line_start_pos
) = 0;
9906 return window_height_changed_p
;
9911 /***********************************************************************
9912 Mode Lines and Frame Titles
9913 ***********************************************************************/
9915 /* A buffer for constructing non-propertized mode-line strings and
9916 frame titles in it; allocated from the heap in init_xdisp and
9917 resized as needed in store_mode_line_noprop_char. */
9919 static char *mode_line_noprop_buf
;
9921 /* The buffer's end, and a current output position in it. */
9923 static char *mode_line_noprop_buf_end
;
9924 static char *mode_line_noprop_ptr
;
9926 #define MODE_LINE_NOPROP_LEN(start) \
9927 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9930 MODE_LINE_DISPLAY
= 0,
9936 /* Alist that caches the results of :propertize.
9937 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9938 static Lisp_Object mode_line_proptrans_alist
;
9940 /* List of strings making up the mode-line. */
9941 static Lisp_Object mode_line_string_list
;
9943 /* Base face property when building propertized mode line string. */
9944 static Lisp_Object mode_line_string_face
;
9945 static Lisp_Object mode_line_string_face_prop
;
9948 /* Unwind data for mode line strings */
9950 static Lisp_Object Vmode_line_unwind_vector
;
9953 format_mode_line_unwind_data (struct buffer
*obuf
,
9957 Lisp_Object vector
, tmp
;
9959 /* Reduce consing by keeping one vector in
9960 Vwith_echo_area_save_vector. */
9961 vector
= Vmode_line_unwind_vector
;
9962 Vmode_line_unwind_vector
= Qnil
;
9965 vector
= Fmake_vector (make_number (8), Qnil
);
9967 ASET (vector
, 0, make_number (mode_line_target
));
9968 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9969 ASET (vector
, 2, mode_line_string_list
);
9970 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9971 ASET (vector
, 4, mode_line_string_face
);
9972 ASET (vector
, 5, mode_line_string_face_prop
);
9975 XSETBUFFER (tmp
, obuf
);
9978 ASET (vector
, 6, tmp
);
9979 ASET (vector
, 7, owin
);
9985 unwind_format_mode_line (Lisp_Object vector
)
9987 mode_line_target
= XINT (AREF (vector
, 0));
9988 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9989 mode_line_string_list
= AREF (vector
, 2);
9990 if (! EQ (AREF (vector
, 3), Qt
))
9991 mode_line_proptrans_alist
= AREF (vector
, 3);
9992 mode_line_string_face
= AREF (vector
, 4);
9993 mode_line_string_face_prop
= AREF (vector
, 5);
9995 if (!NILP (AREF (vector
, 7)))
9996 /* Select window before buffer, since it may change the buffer. */
9997 Fselect_window (AREF (vector
, 7), Qt
);
9999 if (!NILP (AREF (vector
, 6)))
10001 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10002 ASET (vector
, 6, Qnil
);
10005 Vmode_line_unwind_vector
= vector
;
10010 /* Store a single character C for the frame title in mode_line_noprop_buf.
10011 Re-allocate mode_line_noprop_buf if necessary. */
10014 store_mode_line_noprop_char (char c
)
10016 /* If output position has reached the end of the allocated buffer,
10017 double the buffer's size. */
10018 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10020 int len
= MODE_LINE_NOPROP_LEN (0);
10021 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
10022 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
10023 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
10024 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10027 *mode_line_noprop_ptr
++ = c
;
10031 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10032 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10033 characters that yield more columns than PRECISION; PRECISION <= 0
10034 means copy the whole string. Pad with spaces until FIELD_WIDTH
10035 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10036 pad. Called from display_mode_element when it is used to build a
10040 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10042 const unsigned char *str
= (const unsigned char *) string
;
10044 EMACS_INT dummy
, nbytes
;
10046 /* Copy at most PRECISION chars from STR. */
10047 nbytes
= strlen (string
);
10048 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10050 store_mode_line_noprop_char (*str
++);
10052 /* Fill up with spaces until FIELD_WIDTH reached. */
10053 while (field_width
> 0
10054 && n
< field_width
)
10056 store_mode_line_noprop_char (' ');
10063 /***********************************************************************
10065 ***********************************************************************/
10067 #ifdef HAVE_WINDOW_SYSTEM
10069 /* Set the title of FRAME, if it has changed. The title format is
10070 Vicon_title_format if FRAME is iconified, otherwise it is
10071 frame_title_format. */
10074 x_consider_frame_title (Lisp_Object frame
)
10076 struct frame
*f
= XFRAME (frame
);
10078 if (FRAME_WINDOW_P (f
)
10079 || FRAME_MINIBUF_ONLY_P (f
)
10080 || f
->explicit_name
)
10082 /* Do we have more than one visible frame on this X display? */
10089 int count
= SPECPDL_INDEX ();
10091 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
10093 Lisp_Object other_frame
= XCAR (tail
);
10094 struct frame
*tf
= XFRAME (other_frame
);
10097 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
10098 && !FRAME_MINIBUF_ONLY_P (tf
)
10099 && !EQ (other_frame
, tip_frame
)
10100 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
10104 /* Set global variable indicating that multiple frames exist. */
10105 multiple_frames
= CONSP (tail
);
10107 /* Switch to the buffer of selected window of the frame. Set up
10108 mode_line_target so that display_mode_element will output into
10109 mode_line_noprop_buf; then display the title. */
10110 record_unwind_protect (unwind_format_mode_line
,
10111 format_mode_line_unwind_data
10112 (current_buffer
, selected_window
, 0));
10114 Fselect_window (f
->selected_window
, Qt
);
10115 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
10116 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
10118 mode_line_target
= MODE_LINE_TITLE
;
10119 title_start
= MODE_LINE_NOPROP_LEN (0);
10120 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
10121 NULL
, DEFAULT_FACE_ID
);
10122 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
10123 len
= MODE_LINE_NOPROP_LEN (title_start
);
10124 title
= mode_line_noprop_buf
+ title_start
;
10125 unbind_to (count
, Qnil
);
10127 /* Set the title only if it's changed. This avoids consing in
10128 the common case where it hasn't. (If it turns out that we've
10129 already wasted too much time by walking through the list with
10130 display_mode_element, then we might need to optimize at a
10131 higher level than this.) */
10132 if (! STRINGP (f
->name
)
10133 || SBYTES (f
->name
) != len
10134 || memcmp (title
, SDATA (f
->name
), len
) != 0)
10135 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
10139 #endif /* not HAVE_WINDOW_SYSTEM */
10144 /***********************************************************************
10146 ***********************************************************************/
10149 /* Prepare for redisplay by updating menu-bar item lists when
10150 appropriate. This can call eval. */
10153 prepare_menu_bars (void)
10156 struct gcpro gcpro1
, gcpro2
;
10158 Lisp_Object tooltip_frame
;
10160 #ifdef HAVE_WINDOW_SYSTEM
10161 tooltip_frame
= tip_frame
;
10163 tooltip_frame
= Qnil
;
10166 /* Update all frame titles based on their buffer names, etc. We do
10167 this before the menu bars so that the buffer-menu will show the
10168 up-to-date frame titles. */
10169 #ifdef HAVE_WINDOW_SYSTEM
10170 if (windows_or_buffers_changed
|| update_mode_lines
)
10172 Lisp_Object tail
, frame
;
10174 FOR_EACH_FRAME (tail
, frame
)
10176 f
= XFRAME (frame
);
10177 if (!EQ (frame
, tooltip_frame
)
10178 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
10179 x_consider_frame_title (frame
);
10182 #endif /* HAVE_WINDOW_SYSTEM */
10184 /* Update the menu bar item lists, if appropriate. This has to be
10185 done before any actual redisplay or generation of display lines. */
10186 all_windows
= (update_mode_lines
10187 || buffer_shared
> 1
10188 || windows_or_buffers_changed
);
10191 Lisp_Object tail
, frame
;
10192 int count
= SPECPDL_INDEX ();
10193 /* 1 means that update_menu_bar has run its hooks
10194 so any further calls to update_menu_bar shouldn't do so again. */
10195 int menu_bar_hooks_run
= 0;
10197 record_unwind_save_match_data ();
10199 FOR_EACH_FRAME (tail
, frame
)
10201 f
= XFRAME (frame
);
10203 /* Ignore tooltip frame. */
10204 if (EQ (frame
, tooltip_frame
))
10207 /* If a window on this frame changed size, report that to
10208 the user and clear the size-change flag. */
10209 if (FRAME_WINDOW_SIZES_CHANGED (f
))
10211 Lisp_Object functions
;
10213 /* Clear flag first in case we get an error below. */
10214 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
10215 functions
= Vwindow_size_change_functions
;
10216 GCPRO2 (tail
, functions
);
10218 while (CONSP (functions
))
10220 if (!EQ (XCAR (functions
), Qt
))
10221 call1 (XCAR (functions
), frame
);
10222 functions
= XCDR (functions
);
10228 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
10229 #ifdef HAVE_WINDOW_SYSTEM
10230 update_tool_bar (f
, 0);
10233 if (windows_or_buffers_changed
10235 ns_set_doc_edited (f
, Fbuffer_modified_p
10236 (XWINDOW (f
->selected_window
)->buffer
));
10241 unbind_to (count
, Qnil
);
10245 struct frame
*sf
= SELECTED_FRAME ();
10246 update_menu_bar (sf
, 1, 0);
10247 #ifdef HAVE_WINDOW_SYSTEM
10248 update_tool_bar (sf
, 1);
10254 /* Update the menu bar item list for frame F. This has to be done
10255 before we start to fill in any display lines, because it can call
10258 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
10260 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
10261 already ran the menu bar hooks for this redisplay, so there
10262 is no need to run them again. The return value is the
10263 updated value of this flag, to pass to the next call. */
10266 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
10268 Lisp_Object window
;
10269 register struct window
*w
;
10271 /* If called recursively during a menu update, do nothing. This can
10272 happen when, for instance, an activate-menubar-hook causes a
10274 if (inhibit_menubar_update
)
10277 window
= FRAME_SELECTED_WINDOW (f
);
10278 w
= XWINDOW (window
);
10280 if (FRAME_WINDOW_P (f
)
10282 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10283 || defined (HAVE_NS) || defined (USE_GTK)
10284 FRAME_EXTERNAL_MENU_BAR (f
)
10286 FRAME_MENU_BAR_LINES (f
) > 0
10288 : FRAME_MENU_BAR_LINES (f
) > 0)
10290 /* If the user has switched buffers or windows, we need to
10291 recompute to reflect the new bindings. But we'll
10292 recompute when update_mode_lines is set too; that means
10293 that people can use force-mode-line-update to request
10294 that the menu bar be recomputed. The adverse effect on
10295 the rest of the redisplay algorithm is about the same as
10296 windows_or_buffers_changed anyway. */
10297 if (windows_or_buffers_changed
10298 /* This used to test w->update_mode_line, but we believe
10299 there is no need to recompute the menu in that case. */
10300 || update_mode_lines
10301 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10302 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10303 != !NILP (w
->last_had_star
))
10304 || ((!NILP (Vtransient_mark_mode
)
10305 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10306 != !NILP (w
->region_showing
)))
10308 struct buffer
*prev
= current_buffer
;
10309 int count
= SPECPDL_INDEX ();
10311 specbind (Qinhibit_menubar_update
, Qt
);
10313 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10314 if (save_match_data
)
10315 record_unwind_save_match_data ();
10316 if (NILP (Voverriding_local_map_menu_flag
))
10318 specbind (Qoverriding_terminal_local_map
, Qnil
);
10319 specbind (Qoverriding_local_map
, Qnil
);
10324 /* Run the Lucid hook. */
10325 safe_run_hooks (Qactivate_menubar_hook
);
10327 /* If it has changed current-menubar from previous value,
10328 really recompute the menu-bar from the value. */
10329 if (! NILP (Vlucid_menu_bar_dirty_flag
))
10330 call0 (Qrecompute_lucid_menubar
);
10332 safe_run_hooks (Qmenu_bar_update_hook
);
10337 XSETFRAME (Vmenu_updating_frame
, f
);
10338 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
10340 /* Redisplay the menu bar in case we changed it. */
10341 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10342 || defined (HAVE_NS) || defined (USE_GTK)
10343 if (FRAME_WINDOW_P (f
))
10345 #if defined (HAVE_NS)
10346 /* All frames on Mac OS share the same menubar. So only
10347 the selected frame should be allowed to set it. */
10348 if (f
== SELECTED_FRAME ())
10350 set_frame_menubar (f
, 0, 0);
10353 /* On a terminal screen, the menu bar is an ordinary screen
10354 line, and this makes it get updated. */
10355 w
->update_mode_line
= Qt
;
10356 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10357 /* In the non-toolkit version, the menu bar is an ordinary screen
10358 line, and this makes it get updated. */
10359 w
->update_mode_line
= Qt
;
10360 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10362 unbind_to (count
, Qnil
);
10363 set_buffer_internal_1 (prev
);
10372 /***********************************************************************
10374 ***********************************************************************/
10376 #ifdef HAVE_WINDOW_SYSTEM
10379 Nominal cursor position -- where to draw output.
10380 HPOS and VPOS are window relative glyph matrix coordinates.
10381 X and Y are window relative pixel coordinates. */
10383 struct cursor_pos output_cursor
;
10387 Set the global variable output_cursor to CURSOR. All cursor
10388 positions are relative to updated_window. */
10391 set_output_cursor (struct cursor_pos
*cursor
)
10393 output_cursor
.hpos
= cursor
->hpos
;
10394 output_cursor
.vpos
= cursor
->vpos
;
10395 output_cursor
.x
= cursor
->x
;
10396 output_cursor
.y
= cursor
->y
;
10401 Set a nominal cursor position.
10403 HPOS and VPOS are column/row positions in a window glyph matrix. X
10404 and Y are window text area relative pixel positions.
10406 If this is done during an update, updated_window will contain the
10407 window that is being updated and the position is the future output
10408 cursor position for that window. If updated_window is null, use
10409 selected_window and display the cursor at the given position. */
10412 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
10416 /* If updated_window is not set, work on selected_window. */
10417 if (updated_window
)
10418 w
= updated_window
;
10420 w
= XWINDOW (selected_window
);
10422 /* Set the output cursor. */
10423 output_cursor
.hpos
= hpos
;
10424 output_cursor
.vpos
= vpos
;
10425 output_cursor
.x
= x
;
10426 output_cursor
.y
= y
;
10428 /* If not called as part of an update, really display the cursor.
10429 This will also set the cursor position of W. */
10430 if (updated_window
== NULL
)
10433 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10434 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10435 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10440 #endif /* HAVE_WINDOW_SYSTEM */
10443 /***********************************************************************
10445 ***********************************************************************/
10447 #ifdef HAVE_WINDOW_SYSTEM
10449 /* Where the mouse was last time we reported a mouse event. */
10451 FRAME_PTR last_mouse_frame
;
10453 /* Tool-bar item index of the item on which a mouse button was pressed
10456 int last_tool_bar_item
;
10460 update_tool_bar_unwind (Lisp_Object frame
)
10462 selected_frame
= frame
;
10466 /* Update the tool-bar item list for frame F. This has to be done
10467 before we start to fill in any display lines. Called from
10468 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10469 and restore it here. */
10472 update_tool_bar (struct frame
*f
, int save_match_data
)
10474 #if defined (USE_GTK) || defined (HAVE_NS)
10475 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10477 int do_update
= WINDOWP (f
->tool_bar_window
)
10478 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10483 Lisp_Object window
;
10486 window
= FRAME_SELECTED_WINDOW (f
);
10487 w
= XWINDOW (window
);
10489 /* If the user has switched buffers or windows, we need to
10490 recompute to reflect the new bindings. But we'll
10491 recompute when update_mode_lines is set too; that means
10492 that people can use force-mode-line-update to request
10493 that the menu bar be recomputed. The adverse effect on
10494 the rest of the redisplay algorithm is about the same as
10495 windows_or_buffers_changed anyway. */
10496 if (windows_or_buffers_changed
10497 || !NILP (w
->update_mode_line
)
10498 || update_mode_lines
10499 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10500 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10501 != !NILP (w
->last_had_star
))
10502 || ((!NILP (Vtransient_mark_mode
)
10503 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10504 != !NILP (w
->region_showing
)))
10506 struct buffer
*prev
= current_buffer
;
10507 int count
= SPECPDL_INDEX ();
10508 Lisp_Object frame
, new_tool_bar
;
10509 int new_n_tool_bar
;
10510 struct gcpro gcpro1
;
10512 /* Set current_buffer to the buffer of the selected
10513 window of the frame, so that we get the right local
10515 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10517 /* Save match data, if we must. */
10518 if (save_match_data
)
10519 record_unwind_save_match_data ();
10521 /* Make sure that we don't accidentally use bogus keymaps. */
10522 if (NILP (Voverriding_local_map_menu_flag
))
10524 specbind (Qoverriding_terminal_local_map
, Qnil
);
10525 specbind (Qoverriding_local_map
, Qnil
);
10528 GCPRO1 (new_tool_bar
);
10530 /* We must temporarily set the selected frame to this frame
10531 before calling tool_bar_items, because the calculation of
10532 the tool-bar keymap uses the selected frame (see
10533 `tool-bar-make-keymap' in tool-bar.el). */
10534 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10535 XSETFRAME (frame
, f
);
10536 selected_frame
= frame
;
10538 /* Build desired tool-bar items from keymaps. */
10539 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10542 /* Redisplay the tool-bar if we changed it. */
10543 if (new_n_tool_bar
!= f
->n_tool_bar_items
10544 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10546 /* Redisplay that happens asynchronously due to an expose event
10547 may access f->tool_bar_items. Make sure we update both
10548 variables within BLOCK_INPUT so no such event interrupts. */
10550 f
->tool_bar_items
= new_tool_bar
;
10551 f
->n_tool_bar_items
= new_n_tool_bar
;
10552 w
->update_mode_line
= Qt
;
10558 unbind_to (count
, Qnil
);
10559 set_buffer_internal_1 (prev
);
10565 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10566 F's desired tool-bar contents. F->tool_bar_items must have
10567 been set up previously by calling prepare_menu_bars. */
10570 build_desired_tool_bar_string (struct frame
*f
)
10572 int i
, size
, size_needed
;
10573 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10574 Lisp_Object image
, plist
, props
;
10576 image
= plist
= props
= Qnil
;
10577 GCPRO3 (image
, plist
, props
);
10579 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10580 Otherwise, make a new string. */
10582 /* The size of the string we might be able to reuse. */
10583 size
= (STRINGP (f
->desired_tool_bar_string
)
10584 ? SCHARS (f
->desired_tool_bar_string
)
10587 /* We need one space in the string for each image. */
10588 size_needed
= f
->n_tool_bar_items
;
10590 /* Reuse f->desired_tool_bar_string, if possible. */
10591 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10592 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10593 make_number (' '));
10596 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10597 Fremove_text_properties (make_number (0), make_number (size
),
10598 props
, f
->desired_tool_bar_string
);
10601 /* Put a `display' property on the string for the images to display,
10602 put a `menu_item' property on tool-bar items with a value that
10603 is the index of the item in F's tool-bar item vector. */
10604 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10606 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10608 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10609 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10610 int hmargin
, vmargin
, relief
, idx
, end
;
10612 /* If image is a vector, choose the image according to the
10614 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10615 if (VECTORP (image
))
10619 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10620 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10623 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10624 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10626 xassert (ASIZE (image
) >= idx
);
10627 image
= AREF (image
, idx
);
10632 /* Ignore invalid image specifications. */
10633 if (!valid_image_p (image
))
10636 /* Display the tool-bar button pressed, or depressed. */
10637 plist
= Fcopy_sequence (XCDR (image
));
10639 /* Compute margin and relief to draw. */
10640 relief
= (tool_bar_button_relief
>= 0
10641 ? tool_bar_button_relief
10642 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10643 hmargin
= vmargin
= relief
;
10645 if (INTEGERP (Vtool_bar_button_margin
)
10646 && XINT (Vtool_bar_button_margin
) > 0)
10648 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10649 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10651 else if (CONSP (Vtool_bar_button_margin
))
10653 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10654 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10655 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10657 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10658 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10659 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10662 if (auto_raise_tool_bar_buttons_p
)
10664 /* Add a `:relief' property to the image spec if the item is
10668 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10675 /* If image is selected, display it pressed, i.e. with a
10676 negative relief. If it's not selected, display it with a
10678 plist
= Fplist_put (plist
, QCrelief
,
10680 ? make_number (-relief
)
10681 : make_number (relief
)));
10686 /* Put a margin around the image. */
10687 if (hmargin
|| vmargin
)
10689 if (hmargin
== vmargin
)
10690 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10692 plist
= Fplist_put (plist
, QCmargin
,
10693 Fcons (make_number (hmargin
),
10694 make_number (vmargin
)));
10697 /* If button is not enabled, and we don't have special images
10698 for the disabled state, make the image appear disabled by
10699 applying an appropriate algorithm to it. */
10700 if (!enabled_p
&& idx
< 0)
10701 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10703 /* Put a `display' text property on the string for the image to
10704 display. Put a `menu-item' property on the string that gives
10705 the start of this item's properties in the tool-bar items
10707 image
= Fcons (Qimage
, plist
);
10708 props
= list4 (Qdisplay
, image
,
10709 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10711 /* Let the last image hide all remaining spaces in the tool bar
10712 string. The string can be longer than needed when we reuse a
10713 previous string. */
10714 if (i
+ 1 == f
->n_tool_bar_items
)
10715 end
= SCHARS (f
->desired_tool_bar_string
);
10718 Fadd_text_properties (make_number (i
), make_number (end
),
10719 props
, f
->desired_tool_bar_string
);
10727 /* Display one line of the tool-bar of frame IT->f.
10729 HEIGHT specifies the desired height of the tool-bar line.
10730 If the actual height of the glyph row is less than HEIGHT, the
10731 row's height is increased to HEIGHT, and the icons are centered
10732 vertically in the new height.
10734 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10735 count a final empty row in case the tool-bar width exactly matches
10740 display_tool_bar_line (struct it
*it
, int height
)
10742 struct glyph_row
*row
= it
->glyph_row
;
10743 int max_x
= it
->last_visible_x
;
10744 struct glyph
*last
;
10746 prepare_desired_row (row
);
10747 row
->y
= it
->current_y
;
10749 /* Note that this isn't made use of if the face hasn't a box,
10750 so there's no need to check the face here. */
10751 it
->start_of_box_run_p
= 1;
10753 while (it
->current_x
< max_x
)
10755 int x
, n_glyphs_before
, i
, nglyphs
;
10756 struct it it_before
;
10758 /* Get the next display element. */
10759 if (!get_next_display_element (it
))
10761 /* Don't count empty row if we are counting needed tool-bar lines. */
10762 if (height
< 0 && !it
->hpos
)
10767 /* Produce glyphs. */
10768 n_glyphs_before
= row
->used
[TEXT_AREA
];
10771 PRODUCE_GLYPHS (it
);
10773 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10775 x
= it_before
.current_x
;
10776 while (i
< nglyphs
)
10778 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10780 if (x
+ glyph
->pixel_width
> max_x
)
10782 /* Glyph doesn't fit on line. Backtrack. */
10783 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10785 /* If this is the only glyph on this line, it will never fit on the
10786 tool-bar, so skip it. But ensure there is at least one glyph,
10787 so we don't accidentally disable the tool-bar. */
10788 if (n_glyphs_before
== 0
10789 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10795 x
+= glyph
->pixel_width
;
10799 /* Stop at line end. */
10800 if (ITERATOR_AT_END_OF_LINE_P (it
))
10803 set_iterator_to_next (it
, 1);
10808 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10810 /* Use default face for the border below the tool bar.
10812 FIXME: When auto-resize-tool-bars is grow-only, there is
10813 no additional border below the possibly empty tool-bar lines.
10814 So to make the extra empty lines look "normal", we have to
10815 use the tool-bar face for the border too. */
10816 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10817 it
->face_id
= DEFAULT_FACE_ID
;
10819 extend_face_to_end_of_line (it
);
10820 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10821 last
->right_box_line_p
= 1;
10822 if (last
== row
->glyphs
[TEXT_AREA
])
10823 last
->left_box_line_p
= 1;
10825 /* Make line the desired height and center it vertically. */
10826 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10828 /* Don't add more than one line height. */
10829 height
%= FRAME_LINE_HEIGHT (it
->f
);
10830 it
->max_ascent
+= height
/ 2;
10831 it
->max_descent
+= (height
+ 1) / 2;
10834 compute_line_metrics (it
);
10836 /* If line is empty, make it occupy the rest of the tool-bar. */
10837 if (!row
->displays_text_p
)
10839 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10840 row
->visible_height
= row
->height
;
10841 row
->ascent
= row
->phys_ascent
= 0;
10842 row
->extra_line_spacing
= 0;
10845 row
->full_width_p
= 1;
10846 row
->continued_p
= 0;
10847 row
->truncated_on_left_p
= 0;
10848 row
->truncated_on_right_p
= 0;
10850 it
->current_x
= it
->hpos
= 0;
10851 it
->current_y
+= row
->height
;
10857 /* Max tool-bar height. */
10859 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10860 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10862 /* Value is the number of screen lines needed to make all tool-bar
10863 items of frame F visible. The number of actual rows needed is
10864 returned in *N_ROWS if non-NULL. */
10867 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
10869 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10871 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10872 the desired matrix, so use (unused) mode-line row as temporary row to
10873 avoid destroying the first tool-bar row. */
10874 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10876 /* Initialize an iterator for iteration over
10877 F->desired_tool_bar_string in the tool-bar window of frame F. */
10878 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10879 it
.first_visible_x
= 0;
10880 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10881 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10882 it
.paragraph_embedding
= L2R
;
10884 while (!ITERATOR_AT_END_P (&it
))
10886 clear_glyph_row (temp_row
);
10887 it
.glyph_row
= temp_row
;
10888 display_tool_bar_line (&it
, -1);
10890 clear_glyph_row (temp_row
);
10892 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10894 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10896 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10900 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10902 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10903 (Lisp_Object frame
)
10910 frame
= selected_frame
;
10912 CHECK_FRAME (frame
);
10913 f
= XFRAME (frame
);
10915 if (WINDOWP (f
->tool_bar_window
)
10916 || (w
= XWINDOW (f
->tool_bar_window
),
10917 WINDOW_TOTAL_LINES (w
) > 0))
10919 update_tool_bar (f
, 1);
10920 if (f
->n_tool_bar_items
)
10922 build_desired_tool_bar_string (f
);
10923 nlines
= tool_bar_lines_needed (f
, NULL
);
10927 return make_number (nlines
);
10931 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10932 height should be changed. */
10935 redisplay_tool_bar (struct frame
*f
)
10939 struct glyph_row
*row
;
10941 #if defined (USE_GTK) || defined (HAVE_NS)
10942 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10943 update_frame_tool_bar (f
);
10947 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10948 do anything. This means you must start with tool-bar-lines
10949 non-zero to get the auto-sizing effect. Or in other words, you
10950 can turn off tool-bars by specifying tool-bar-lines zero. */
10951 if (!WINDOWP (f
->tool_bar_window
)
10952 || (w
= XWINDOW (f
->tool_bar_window
),
10953 WINDOW_TOTAL_LINES (w
) == 0))
10956 /* Set up an iterator for the tool-bar window. */
10957 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10958 it
.first_visible_x
= 0;
10959 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10960 row
= it
.glyph_row
;
10962 /* Build a string that represents the contents of the tool-bar. */
10963 build_desired_tool_bar_string (f
);
10964 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10965 /* FIXME: This should be controlled by a user option. But it
10966 doesn't make sense to have an R2L tool bar if the menu bar cannot
10967 be drawn also R2L, and making the menu bar R2L is tricky due to
10968 unibyte strings it uses and toolkit-specific code that implements
10969 it. If an R2L tool bar is ever supported, display_tool_bar_line
10970 should also be augmented to call unproduce_glyphs like
10971 display_line and display_string do. */
10972 it
.paragraph_embedding
= L2R
;
10974 if (f
->n_tool_bar_rows
== 0)
10978 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10979 nlines
!= WINDOW_TOTAL_LINES (w
)))
10982 int old_height
= WINDOW_TOTAL_LINES (w
);
10984 XSETFRAME (frame
, f
);
10985 Fmodify_frame_parameters (frame
,
10986 Fcons (Fcons (Qtool_bar_lines
,
10987 make_number (nlines
)),
10989 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10991 clear_glyph_matrix (w
->desired_matrix
);
10992 fonts_changed_p
= 1;
10998 /* Display as many lines as needed to display all tool-bar items. */
11000 if (f
->n_tool_bar_rows
> 0)
11002 int border
, rows
, height
, extra
;
11004 if (INTEGERP (Vtool_bar_border
))
11005 border
= XINT (Vtool_bar_border
);
11006 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11007 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11008 else if (EQ (Vtool_bar_border
, Qborder_width
))
11009 border
= f
->border_width
;
11015 rows
= f
->n_tool_bar_rows
;
11016 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11017 extra
= it
.last_visible_y
- border
- height
* rows
;
11019 while (it
.current_y
< it
.last_visible_y
)
11022 if (extra
> 0 && rows
-- > 0)
11024 h
= (extra
+ rows
- 1) / rows
;
11027 display_tool_bar_line (&it
, height
+ h
);
11032 while (it
.current_y
< it
.last_visible_y
)
11033 display_tool_bar_line (&it
, 0);
11036 /* It doesn't make much sense to try scrolling in the tool-bar
11037 window, so don't do it. */
11038 w
->desired_matrix
->no_scrolling_p
= 1;
11039 w
->must_be_updated_p
= 1;
11041 if (!NILP (Vauto_resize_tool_bars
))
11043 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11044 int change_height_p
= 0;
11046 /* If we couldn't display everything, change the tool-bar's
11047 height if there is room for more. */
11048 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11049 && it
.current_y
< max_tool_bar_height
)
11050 change_height_p
= 1;
11052 row
= it
.glyph_row
- 1;
11054 /* If there are blank lines at the end, except for a partially
11055 visible blank line at the end that is smaller than
11056 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11057 if (!row
->displays_text_p
11058 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11059 change_height_p
= 1;
11061 /* If row displays tool-bar items, but is partially visible,
11062 change the tool-bar's height. */
11063 if (row
->displays_text_p
11064 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11065 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11066 change_height_p
= 1;
11068 /* Resize windows as needed by changing the `tool-bar-lines'
11069 frame parameter. */
11070 if (change_height_p
)
11073 int old_height
= WINDOW_TOTAL_LINES (w
);
11075 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11077 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11078 && !f
->minimize_tool_bar_window_p
)
11079 ? (nlines
> old_height
)
11080 : (nlines
!= old_height
));
11081 f
->minimize_tool_bar_window_p
= 0;
11083 if (change_height_p
)
11085 XSETFRAME (frame
, f
);
11086 Fmodify_frame_parameters (frame
,
11087 Fcons (Fcons (Qtool_bar_lines
,
11088 make_number (nlines
)),
11090 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11092 clear_glyph_matrix (w
->desired_matrix
);
11093 f
->n_tool_bar_rows
= nrows
;
11094 fonts_changed_p
= 1;
11101 f
->minimize_tool_bar_window_p
= 0;
11106 /* Get information about the tool-bar item which is displayed in GLYPH
11107 on frame F. Return in *PROP_IDX the index where tool-bar item
11108 properties start in F->tool_bar_items. Value is zero if
11109 GLYPH doesn't display a tool-bar item. */
11112 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
11118 /* This function can be called asynchronously, which means we must
11119 exclude any possibility that Fget_text_property signals an
11121 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
11122 charpos
= max (0, charpos
);
11124 /* Get the text property `menu-item' at pos. The value of that
11125 property is the start index of this item's properties in
11126 F->tool_bar_items. */
11127 prop
= Fget_text_property (make_number (charpos
),
11128 Qmenu_item
, f
->current_tool_bar_string
);
11129 if (INTEGERP (prop
))
11131 *prop_idx
= XINT (prop
);
11141 /* Get information about the tool-bar item at position X/Y on frame F.
11142 Return in *GLYPH a pointer to the glyph of the tool-bar item in
11143 the current matrix of the tool-bar window of F, or NULL if not
11144 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
11145 item in F->tool_bar_items. Value is
11147 -1 if X/Y is not on a tool-bar item
11148 0 if X/Y is on the same item that was highlighted before.
11152 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
11153 int *hpos
, int *vpos
, int *prop_idx
)
11155 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11156 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11159 /* Find the glyph under X/Y. */
11160 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
11161 if (*glyph
== NULL
)
11164 /* Get the start of this tool-bar item's properties in
11165 f->tool_bar_items. */
11166 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
11169 /* Is mouse on the highlighted item? */
11170 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
11171 && *vpos
>= hlinfo
->mouse_face_beg_row
11172 && *vpos
<= hlinfo
->mouse_face_end_row
11173 && (*vpos
> hlinfo
->mouse_face_beg_row
11174 || *hpos
>= hlinfo
->mouse_face_beg_col
)
11175 && (*vpos
< hlinfo
->mouse_face_end_row
11176 || *hpos
< hlinfo
->mouse_face_end_col
11177 || hlinfo
->mouse_face_past_end
))
11185 Handle mouse button event on the tool-bar of frame F, at
11186 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
11187 0 for button release. MODIFIERS is event modifiers for button
11191 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
11192 unsigned int modifiers
)
11194 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11195 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11196 int hpos
, vpos
, prop_idx
;
11197 struct glyph
*glyph
;
11198 Lisp_Object enabled_p
;
11200 /* If not on the highlighted tool-bar item, return. */
11201 frame_to_window_pixel_xy (w
, &x
, &y
);
11202 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
11205 /* If item is disabled, do nothing. */
11206 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11207 if (NILP (enabled_p
))
11212 /* Show item in pressed state. */
11213 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
11214 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
11215 last_tool_bar_item
= prop_idx
;
11219 Lisp_Object key
, frame
;
11220 struct input_event event
;
11221 EVENT_INIT (event
);
11223 /* Show item in released state. */
11224 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
11225 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
11227 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
11229 XSETFRAME (frame
, f
);
11230 event
.kind
= TOOL_BAR_EVENT
;
11231 event
.frame_or_window
= frame
;
11233 kbd_buffer_store_event (&event
);
11235 event
.kind
= TOOL_BAR_EVENT
;
11236 event
.frame_or_window
= frame
;
11238 event
.modifiers
= modifiers
;
11239 kbd_buffer_store_event (&event
);
11240 last_tool_bar_item
= -1;
11245 /* Possibly highlight a tool-bar item on frame F when mouse moves to
11246 tool-bar window-relative coordinates X/Y. Called from
11247 note_mouse_highlight. */
11250 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
11252 Lisp_Object window
= f
->tool_bar_window
;
11253 struct window
*w
= XWINDOW (window
);
11254 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11255 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11257 struct glyph
*glyph
;
11258 struct glyph_row
*row
;
11260 Lisp_Object enabled_p
;
11262 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
11263 int mouse_down_p
, rc
;
11265 /* Function note_mouse_highlight is called with negative X/Y
11266 values when mouse moves outside of the frame. */
11267 if (x
<= 0 || y
<= 0)
11269 clear_mouse_face (hlinfo
);
11273 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
11276 /* Not on tool-bar item. */
11277 clear_mouse_face (hlinfo
);
11281 /* On same tool-bar item as before. */
11282 goto set_help_echo
;
11284 clear_mouse_face (hlinfo
);
11286 /* Mouse is down, but on different tool-bar item? */
11287 mouse_down_p
= (dpyinfo
->grabbed
11288 && f
== last_mouse_frame
11289 && FRAME_LIVE_P (f
));
11291 && last_tool_bar_item
!= prop_idx
)
11294 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
11295 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
11297 /* If tool-bar item is not enabled, don't highlight it. */
11298 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11299 if (!NILP (enabled_p
))
11301 /* Compute the x-position of the glyph. In front and past the
11302 image is a space. We include this in the highlighted area. */
11303 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
11304 for (i
= x
= 0; i
< hpos
; ++i
)
11305 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11307 /* Record this as the current active region. */
11308 hlinfo
->mouse_face_beg_col
= hpos
;
11309 hlinfo
->mouse_face_beg_row
= vpos
;
11310 hlinfo
->mouse_face_beg_x
= x
;
11311 hlinfo
->mouse_face_beg_y
= row
->y
;
11312 hlinfo
->mouse_face_past_end
= 0;
11314 hlinfo
->mouse_face_end_col
= hpos
+ 1;
11315 hlinfo
->mouse_face_end_row
= vpos
;
11316 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
11317 hlinfo
->mouse_face_end_y
= row
->y
;
11318 hlinfo
->mouse_face_window
= window
;
11319 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
11321 /* Display it as active. */
11322 show_mouse_face (hlinfo
, draw
);
11323 hlinfo
->mouse_face_image_state
= draw
;
11328 /* Set help_echo_string to a help string to display for this tool-bar item.
11329 XTread_socket does the rest. */
11330 help_echo_object
= help_echo_window
= Qnil
;
11331 help_echo_pos
= -1;
11332 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
11333 if (NILP (help_echo_string
))
11334 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
11337 #endif /* HAVE_WINDOW_SYSTEM */
11341 /************************************************************************
11342 Horizontal scrolling
11343 ************************************************************************/
11345 static int hscroll_window_tree (Lisp_Object
);
11346 static int hscroll_windows (Lisp_Object
);
11348 /* For all leaf windows in the window tree rooted at WINDOW, set their
11349 hscroll value so that PT is (i) visible in the window, and (ii) so
11350 that it is not within a certain margin at the window's left and
11351 right border. Value is non-zero if any window's hscroll has been
11355 hscroll_window_tree (Lisp_Object window
)
11357 int hscrolled_p
= 0;
11358 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
11359 int hscroll_step_abs
= 0;
11360 double hscroll_step_rel
= 0;
11362 if (hscroll_relative_p
)
11364 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
11365 if (hscroll_step_rel
< 0)
11367 hscroll_relative_p
= 0;
11368 hscroll_step_abs
= 0;
11371 else if (INTEGERP (Vhscroll_step
))
11373 hscroll_step_abs
= XINT (Vhscroll_step
);
11374 if (hscroll_step_abs
< 0)
11375 hscroll_step_abs
= 0;
11378 hscroll_step_abs
= 0;
11380 while (WINDOWP (window
))
11382 struct window
*w
= XWINDOW (window
);
11384 if (WINDOWP (w
->hchild
))
11385 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11386 else if (WINDOWP (w
->vchild
))
11387 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11388 else if (w
->cursor
.vpos
>= 0)
11391 int text_area_width
;
11392 struct glyph_row
*current_cursor_row
11393 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11394 struct glyph_row
*desired_cursor_row
11395 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11396 struct glyph_row
*cursor_row
11397 = (desired_cursor_row
->enabled_p
11398 ? desired_cursor_row
11399 : current_cursor_row
);
11401 text_area_width
= window_box_width (w
, TEXT_AREA
);
11403 /* Scroll when cursor is inside this scroll margin. */
11404 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11406 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11407 && ((XFASTINT (w
->hscroll
)
11408 && w
->cursor
.x
<= h_margin
)
11409 || (cursor_row
->enabled_p
11410 && cursor_row
->truncated_on_right_p
11411 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11415 struct buffer
*saved_current_buffer
;
11419 /* Find point in a display of infinite width. */
11420 saved_current_buffer
= current_buffer
;
11421 current_buffer
= XBUFFER (w
->buffer
);
11423 if (w
== XWINDOW (selected_window
))
11427 pt
= marker_position (w
->pointm
);
11428 pt
= max (BEGV
, pt
);
11432 /* Move iterator to pt starting at cursor_row->start in
11433 a line with infinite width. */
11434 init_to_row_start (&it
, w
, cursor_row
);
11435 it
.last_visible_x
= INFINITY
;
11436 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11437 current_buffer
= saved_current_buffer
;
11439 /* Position cursor in window. */
11440 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11441 hscroll
= max (0, (it
.current_x
11442 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11443 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11444 : (text_area_width
/ 2))))
11445 / FRAME_COLUMN_WIDTH (it
.f
);
11446 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11448 if (hscroll_relative_p
)
11449 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11452 wanted_x
= text_area_width
11453 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11456 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11460 if (hscroll_relative_p
)
11461 wanted_x
= text_area_width
* hscroll_step_rel
11464 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11467 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11469 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11471 /* Don't call Fset_window_hscroll if value hasn't
11472 changed because it will prevent redisplay
11474 if (XFASTINT (w
->hscroll
) != hscroll
)
11476 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11477 w
->hscroll
= make_number (hscroll
);
11486 /* Value is non-zero if hscroll of any leaf window has been changed. */
11487 return hscrolled_p
;
11491 /* Set hscroll so that cursor is visible and not inside horizontal
11492 scroll margins for all windows in the tree rooted at WINDOW. See
11493 also hscroll_window_tree above. Value is non-zero if any window's
11494 hscroll has been changed. If it has, desired matrices on the frame
11495 of WINDOW are cleared. */
11498 hscroll_windows (Lisp_Object window
)
11500 int hscrolled_p
= hscroll_window_tree (window
);
11502 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11503 return hscrolled_p
;
11508 /************************************************************************
11510 ************************************************************************/
11512 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11513 to a non-zero value. This is sometimes handy to have in a debugger
11518 /* First and last unchanged row for try_window_id. */
11520 int debug_first_unchanged_at_end_vpos
;
11521 int debug_last_unchanged_at_beg_vpos
;
11523 /* Delta vpos and y. */
11525 int debug_dvpos
, debug_dy
;
11527 /* Delta in characters and bytes for try_window_id. */
11529 EMACS_INT debug_delta
, debug_delta_bytes
;
11531 /* Values of window_end_pos and window_end_vpos at the end of
11534 EMACS_INT debug_end_vpos
;
11536 /* Append a string to W->desired_matrix->method. FMT is a printf
11537 format string. A1...A9 are a supplement for a variable-length
11538 argument list. If trace_redisplay_p is non-zero also printf the
11539 resulting string to stderr. */
11542 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11545 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11548 char *method
= w
->desired_matrix
->method
;
11549 int len
= strlen (method
);
11550 int size
= sizeof w
->desired_matrix
->method
;
11551 int remaining
= size
- len
- 1;
11553 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11554 if (len
&& remaining
)
11557 --remaining
, ++len
;
11560 strncpy (method
+ len
, buffer
, remaining
);
11562 if (trace_redisplay_p
)
11563 fprintf (stderr
, "%p (%s): %s\n",
11565 ((BUFFERP (w
->buffer
)
11566 && STRINGP (XBUFFER (w
->buffer
)->name
))
11567 ? SSDATA (XBUFFER (w
->buffer
)->name
)
11572 #endif /* GLYPH_DEBUG */
11575 /* Value is non-zero if all changes in window W, which displays
11576 current_buffer, are in the text between START and END. START is a
11577 buffer position, END is given as a distance from Z. Used in
11578 redisplay_internal for display optimization. */
11581 text_outside_line_unchanged_p (struct window
*w
,
11582 EMACS_INT start
, EMACS_INT end
)
11584 int unchanged_p
= 1;
11586 /* If text or overlays have changed, see where. */
11587 if (XFASTINT (w
->last_modified
) < MODIFF
11588 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11590 /* Gap in the line? */
11591 if (GPT
< start
|| Z
- GPT
< end
)
11594 /* Changes start in front of the line, or end after it? */
11596 && (BEG_UNCHANGED
< start
- 1
11597 || END_UNCHANGED
< end
))
11600 /* If selective display, can't optimize if changes start at the
11601 beginning of the line. */
11603 && INTEGERP (BVAR (current_buffer
, selective_display
))
11604 && XINT (BVAR (current_buffer
, selective_display
)) > 0
11605 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11608 /* If there are overlays at the start or end of the line, these
11609 may have overlay strings with newlines in them. A change at
11610 START, for instance, may actually concern the display of such
11611 overlay strings as well, and they are displayed on different
11612 lines. So, quickly rule out this case. (For the future, it
11613 might be desirable to implement something more telling than
11614 just BEG/END_UNCHANGED.) */
11617 if (BEG
+ BEG_UNCHANGED
== start
11618 && overlay_touches_p (start
))
11620 if (END_UNCHANGED
== end
11621 && overlay_touches_p (Z
- end
))
11625 /* Under bidi reordering, adding or deleting a character in the
11626 beginning of a paragraph, before the first strong directional
11627 character, can change the base direction of the paragraph (unless
11628 the buffer specifies a fixed paragraph direction), which will
11629 require to redisplay the whole paragraph. It might be worthwhile
11630 to find the paragraph limits and widen the range of redisplayed
11631 lines to that, but for now just give up this optimization. */
11632 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
11633 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
11637 return unchanged_p
;
11641 /* Do a frame update, taking possible shortcuts into account. This is
11642 the main external entry point for redisplay.
11644 If the last redisplay displayed an echo area message and that message
11645 is no longer requested, we clear the echo area or bring back the
11646 mini-buffer if that is in use. */
11651 redisplay_internal ();
11656 overlay_arrow_string_or_property (Lisp_Object var
)
11660 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11663 return Voverlay_arrow_string
;
11666 /* Return 1 if there are any overlay-arrows in current_buffer. */
11668 overlay_arrow_in_current_buffer_p (void)
11672 for (vlist
= Voverlay_arrow_variable_list
;
11674 vlist
= XCDR (vlist
))
11676 Lisp_Object var
= XCAR (vlist
);
11679 if (!SYMBOLP (var
))
11681 val
= find_symbol_value (var
);
11683 && current_buffer
== XMARKER (val
)->buffer
)
11690 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11694 overlay_arrows_changed_p (void)
11698 for (vlist
= Voverlay_arrow_variable_list
;
11700 vlist
= XCDR (vlist
))
11702 Lisp_Object var
= XCAR (vlist
);
11703 Lisp_Object val
, pstr
;
11705 if (!SYMBOLP (var
))
11707 val
= find_symbol_value (var
);
11708 if (!MARKERP (val
))
11710 if (! EQ (COERCE_MARKER (val
),
11711 Fget (var
, Qlast_arrow_position
))
11712 || ! (pstr
= overlay_arrow_string_or_property (var
),
11713 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11719 /* Mark overlay arrows to be updated on next redisplay. */
11722 update_overlay_arrows (int up_to_date
)
11726 for (vlist
= Voverlay_arrow_variable_list
;
11728 vlist
= XCDR (vlist
))
11730 Lisp_Object var
= XCAR (vlist
);
11732 if (!SYMBOLP (var
))
11735 if (up_to_date
> 0)
11737 Lisp_Object val
= find_symbol_value (var
);
11738 Fput (var
, Qlast_arrow_position
,
11739 COERCE_MARKER (val
));
11740 Fput (var
, Qlast_arrow_string
,
11741 overlay_arrow_string_or_property (var
));
11743 else if (up_to_date
< 0
11744 || !NILP (Fget (var
, Qlast_arrow_position
)))
11746 Fput (var
, Qlast_arrow_position
, Qt
);
11747 Fput (var
, Qlast_arrow_string
, Qt
);
11753 /* Return overlay arrow string to display at row.
11754 Return integer (bitmap number) for arrow bitmap in left fringe.
11755 Return nil if no overlay arrow. */
11758 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
11762 for (vlist
= Voverlay_arrow_variable_list
;
11764 vlist
= XCDR (vlist
))
11766 Lisp_Object var
= XCAR (vlist
);
11769 if (!SYMBOLP (var
))
11772 val
= find_symbol_value (var
);
11775 && current_buffer
== XMARKER (val
)->buffer
11776 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11778 if (FRAME_WINDOW_P (it
->f
)
11779 /* FIXME: if ROW->reversed_p is set, this should test
11780 the right fringe, not the left one. */
11781 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11783 #ifdef HAVE_WINDOW_SYSTEM
11784 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11787 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11788 return make_number (fringe_bitmap
);
11791 return make_number (-1); /* Use default arrow bitmap */
11793 return overlay_arrow_string_or_property (var
);
11800 /* Return 1 if point moved out of or into a composition. Otherwise
11801 return 0. PREV_BUF and PREV_PT are the last point buffer and
11802 position. BUF and PT are the current point buffer and position. */
11805 check_point_in_composition (struct buffer
*prev_buf
, EMACS_INT prev_pt
,
11806 struct buffer
*buf
, EMACS_INT pt
)
11808 EMACS_INT start
, end
;
11810 Lisp_Object buffer
;
11812 XSETBUFFER (buffer
, buf
);
11813 /* Check a composition at the last point if point moved within the
11815 if (prev_buf
== buf
)
11818 /* Point didn't move. */
11821 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11822 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11823 && COMPOSITION_VALID_P (start
, end
, prop
)
11824 && start
< prev_pt
&& end
> prev_pt
)
11825 /* The last point was within the composition. Return 1 iff
11826 point moved out of the composition. */
11827 return (pt
<= start
|| pt
>= end
);
11830 /* Check a composition at the current point. */
11831 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11832 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11833 && COMPOSITION_VALID_P (start
, end
, prop
)
11834 && start
< pt
&& end
> pt
);
11838 /* Reconsider the setting of B->clip_changed which is displayed
11842 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
11844 if (b
->clip_changed
11845 && !NILP (w
->window_end_valid
)
11846 && w
->current_matrix
->buffer
== b
11847 && w
->current_matrix
->zv
== BUF_ZV (b
)
11848 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11849 b
->clip_changed
= 0;
11851 /* If display wasn't paused, and W is not a tool bar window, see if
11852 point has been moved into or out of a composition. In that case,
11853 we set b->clip_changed to 1 to force updating the screen. If
11854 b->clip_changed has already been set to 1, we can skip this
11856 if (!b
->clip_changed
11857 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11861 if (w
== XWINDOW (selected_window
))
11864 pt
= marker_position (w
->pointm
);
11866 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11867 || pt
!= XINT (w
->last_point
))
11868 && check_point_in_composition (w
->current_matrix
->buffer
,
11869 XINT (w
->last_point
),
11870 XBUFFER (w
->buffer
), pt
))
11871 b
->clip_changed
= 1;
11876 /* Select FRAME to forward the values of frame-local variables into C
11877 variables so that the redisplay routines can access those values
11881 select_frame_for_redisplay (Lisp_Object frame
)
11883 Lisp_Object tail
, tem
;
11884 Lisp_Object old
= selected_frame
;
11885 struct Lisp_Symbol
*sym
;
11887 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11889 selected_frame
= frame
;
11892 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11893 if (CONSP (XCAR (tail
))
11894 && (tem
= XCAR (XCAR (tail
)),
11896 && (sym
= indirect_variable (XSYMBOL (tem
)),
11897 sym
->redirect
== SYMBOL_LOCALIZED
)
11898 && sym
->val
.blv
->frame_local
)
11899 /* Use find_symbol_value rather than Fsymbol_value
11900 to avoid an error if it is void. */
11901 find_symbol_value (tem
);
11902 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11906 #define STOP_POLLING \
11907 do { if (! polling_stopped_here) stop_polling (); \
11908 polling_stopped_here = 1; } while (0)
11910 #define RESUME_POLLING \
11911 do { if (polling_stopped_here) start_polling (); \
11912 polling_stopped_here = 0; } while (0)
11915 /* Perhaps in the future avoid recentering windows if it
11916 is not necessary; currently that causes some problems. */
11919 redisplay_internal (void)
11921 struct window
*w
= XWINDOW (selected_window
);
11925 int must_finish
= 0;
11926 struct text_pos tlbufpos
, tlendpos
;
11927 int number_of_visible_frames
;
11930 int polling_stopped_here
= 0;
11931 Lisp_Object old_frame
= selected_frame
;
11933 /* Non-zero means redisplay has to consider all windows on all
11934 frames. Zero means, only selected_window is considered. */
11935 int consider_all_windows_p
;
11937 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11939 /* No redisplay if running in batch mode or frame is not yet fully
11940 initialized, or redisplay is explicitly turned off by setting
11941 Vinhibit_redisplay. */
11942 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11943 || !NILP (Vinhibit_redisplay
))
11946 /* Don't examine these until after testing Vinhibit_redisplay.
11947 When Emacs is shutting down, perhaps because its connection to
11948 X has dropped, we should not look at them at all. */
11949 fr
= XFRAME (w
->frame
);
11950 sf
= SELECTED_FRAME ();
11952 if (!fr
->glyphs_initialized_p
)
11955 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11956 if (popup_activated ())
11960 /* I don't think this happens but let's be paranoid. */
11961 if (redisplaying_p
)
11964 /* Record a function that resets redisplaying_p to its old value
11965 when we leave this function. */
11966 count
= SPECPDL_INDEX ();
11967 record_unwind_protect (unwind_redisplay
,
11968 Fcons (make_number (redisplaying_p
), selected_frame
));
11970 specbind (Qinhibit_free_realized_faces
, Qnil
);
11973 Lisp_Object tail
, frame
;
11975 FOR_EACH_FRAME (tail
, frame
)
11977 struct frame
*f
= XFRAME (frame
);
11978 f
->already_hscrolled_p
= 0;
11983 /* Remember the currently selected window. */
11986 if (!EQ (old_frame
, selected_frame
)
11987 && FRAME_LIVE_P (XFRAME (old_frame
)))
11988 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11989 selected_frame and selected_window to be temporarily out-of-sync so
11990 when we come back here via `goto retry', we need to resync because we
11991 may need to run Elisp code (via prepare_menu_bars). */
11992 select_frame_for_redisplay (old_frame
);
11995 reconsider_clip_changes (w
, current_buffer
);
11996 last_escape_glyph_frame
= NULL
;
11997 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11998 last_glyphless_glyph_frame
= NULL
;
11999 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12001 /* If new fonts have been loaded that make a glyph matrix adjustment
12002 necessary, do it. */
12003 if (fonts_changed_p
)
12005 adjust_glyphs (NULL
);
12006 ++windows_or_buffers_changed
;
12007 fonts_changed_p
= 0;
12010 /* If face_change_count is non-zero, init_iterator will free all
12011 realized faces, which includes the faces referenced from current
12012 matrices. So, we can't reuse current matrices in this case. */
12013 if (face_change_count
)
12014 ++windows_or_buffers_changed
;
12016 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12017 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12019 /* Since frames on a single ASCII terminal share the same
12020 display area, displaying a different frame means redisplay
12021 the whole thing. */
12022 windows_or_buffers_changed
++;
12023 SET_FRAME_GARBAGED (sf
);
12025 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12027 FRAME_TTY (sf
)->previous_frame
= sf
;
12030 /* Set the visible flags for all frames. Do this before checking
12031 for resized or garbaged frames; they want to know if their frames
12032 are visible. See the comment in frame.h for
12033 FRAME_SAMPLE_VISIBILITY. */
12035 Lisp_Object tail
, frame
;
12037 number_of_visible_frames
= 0;
12039 FOR_EACH_FRAME (tail
, frame
)
12041 struct frame
*f
= XFRAME (frame
);
12043 FRAME_SAMPLE_VISIBILITY (f
);
12044 if (FRAME_VISIBLE_P (f
))
12045 ++number_of_visible_frames
;
12046 clear_desired_matrices (f
);
12050 /* Notice any pending interrupt request to change frame size. */
12051 do_pending_window_change (1);
12053 /* do_pending_window_change could change the selected_window due to
12054 frame resizing which makes the selected window too small. */
12055 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12058 reconsider_clip_changes (w
, current_buffer
);
12061 /* Clear frames marked as garbaged. */
12062 if (frame_garbaged
)
12063 clear_garbaged_frames ();
12065 /* Build menubar and tool-bar items. */
12066 if (NILP (Vmemory_full
))
12067 prepare_menu_bars ();
12069 if (windows_or_buffers_changed
)
12070 update_mode_lines
++;
12072 /* Detect case that we need to write or remove a star in the mode line. */
12073 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
12075 w
->update_mode_line
= Qt
;
12076 if (buffer_shared
> 1)
12077 update_mode_lines
++;
12080 /* Avoid invocation of point motion hooks by `current_column' below. */
12081 count1
= SPECPDL_INDEX ();
12082 specbind (Qinhibit_point_motion_hooks
, Qt
);
12084 /* If %c is in the mode line, update it if needed. */
12085 if (!NILP (w
->column_number_displayed
)
12086 /* This alternative quickly identifies a common case
12087 where no change is needed. */
12088 && !(PT
== XFASTINT (w
->last_point
)
12089 && XFASTINT (w
->last_modified
) >= MODIFF
12090 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12091 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
12092 w
->update_mode_line
= Qt
;
12094 unbind_to (count1
, Qnil
);
12096 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
12098 /* The variable buffer_shared is set in redisplay_window and
12099 indicates that we redisplay a buffer in different windows. See
12101 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
12102 || cursor_type_changed
);
12104 /* If specs for an arrow have changed, do thorough redisplay
12105 to ensure we remove any arrow that should no longer exist. */
12106 if (overlay_arrows_changed_p ())
12107 consider_all_windows_p
= windows_or_buffers_changed
= 1;
12109 /* Normally the message* functions will have already displayed and
12110 updated the echo area, but the frame may have been trashed, or
12111 the update may have been preempted, so display the echo area
12112 again here. Checking message_cleared_p captures the case that
12113 the echo area should be cleared. */
12114 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
12115 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
12116 || (message_cleared_p
12117 && minibuf_level
== 0
12118 /* If the mini-window is currently selected, this means the
12119 echo-area doesn't show through. */
12120 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
12122 int window_height_changed_p
= echo_area_display (0);
12125 /* If we don't display the current message, don't clear the
12126 message_cleared_p flag, because, if we did, we wouldn't clear
12127 the echo area in the next redisplay which doesn't preserve
12129 if (!display_last_displayed_message_p
)
12130 message_cleared_p
= 0;
12132 if (fonts_changed_p
)
12134 else if (window_height_changed_p
)
12136 consider_all_windows_p
= 1;
12137 ++update_mode_lines
;
12138 ++windows_or_buffers_changed
;
12140 /* If window configuration was changed, frames may have been
12141 marked garbaged. Clear them or we will experience
12142 surprises wrt scrolling. */
12143 if (frame_garbaged
)
12144 clear_garbaged_frames ();
12147 else if (EQ (selected_window
, minibuf_window
)
12148 && (current_buffer
->clip_changed
12149 || XFASTINT (w
->last_modified
) < MODIFF
12150 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12151 && resize_mini_window (w
, 0))
12153 /* Resized active mini-window to fit the size of what it is
12154 showing if its contents might have changed. */
12156 /* FIXME: this causes all frames to be updated, which seems unnecessary
12157 since only the current frame needs to be considered. This function needs
12158 to be rewritten with two variables, consider_all_windows and
12159 consider_all_frames. */
12160 consider_all_windows_p
= 1;
12161 ++windows_or_buffers_changed
;
12162 ++update_mode_lines
;
12164 /* If window configuration was changed, frames may have been
12165 marked garbaged. Clear them or we will experience
12166 surprises wrt scrolling. */
12167 if (frame_garbaged
)
12168 clear_garbaged_frames ();
12172 /* If showing the region, and mark has changed, we must redisplay
12173 the whole window. The assignment to this_line_start_pos prevents
12174 the optimization directly below this if-statement. */
12175 if (((!NILP (Vtransient_mark_mode
)
12176 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
12177 != !NILP (w
->region_showing
))
12178 || (!NILP (w
->region_showing
)
12179 && !EQ (w
->region_showing
,
12180 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
12181 CHARPOS (this_line_start_pos
) = 0;
12183 /* Optimize the case that only the line containing the cursor in the
12184 selected window has changed. Variables starting with this_ are
12185 set in display_line and record information about the line
12186 containing the cursor. */
12187 tlbufpos
= this_line_start_pos
;
12188 tlendpos
= this_line_end_pos
;
12189 if (!consider_all_windows_p
12190 && CHARPOS (tlbufpos
) > 0
12191 && NILP (w
->update_mode_line
)
12192 && !current_buffer
->clip_changed
12193 && !current_buffer
->prevent_redisplay_optimizations_p
12194 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
12195 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
12196 /* Make sure recorded data applies to current buffer, etc. */
12197 && this_line_buffer
== current_buffer
12198 && current_buffer
== XBUFFER (w
->buffer
)
12199 && NILP (w
->force_start
)
12200 && NILP (w
->optional_new_start
)
12201 /* Point must be on the line that we have info recorded about. */
12202 && PT
>= CHARPOS (tlbufpos
)
12203 && PT
<= Z
- CHARPOS (tlendpos
)
12204 /* All text outside that line, including its final newline,
12205 must be unchanged. */
12206 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
12207 CHARPOS (tlendpos
)))
12209 if (CHARPOS (tlbufpos
) > BEGV
12210 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
12211 && (CHARPOS (tlbufpos
) == ZV
12212 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
12213 /* Former continuation line has disappeared by becoming empty. */
12215 else if (XFASTINT (w
->last_modified
) < MODIFF
12216 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
12217 || MINI_WINDOW_P (w
))
12219 /* We have to handle the case of continuation around a
12220 wide-column character (see the comment in indent.c around
12223 For instance, in the following case:
12225 -------- Insert --------
12226 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
12227 J_I_ ==> J_I_ `^^' are cursors.
12231 As we have to redraw the line above, we cannot use this
12235 int line_height_before
= this_line_pixel_height
;
12237 /* Note that start_display will handle the case that the
12238 line starting at tlbufpos is a continuation line. */
12239 start_display (&it
, w
, tlbufpos
);
12241 /* Implementation note: It this still necessary? */
12242 if (it
.current_x
!= this_line_start_x
)
12245 TRACE ((stderr
, "trying display optimization 1\n"));
12246 w
->cursor
.vpos
= -1;
12247 overlay_arrow_seen
= 0;
12248 it
.vpos
= this_line_vpos
;
12249 it
.current_y
= this_line_y
;
12250 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
12251 display_line (&it
);
12253 /* If line contains point, is not continued,
12254 and ends at same distance from eob as before, we win. */
12255 if (w
->cursor
.vpos
>= 0
12256 /* Line is not continued, otherwise this_line_start_pos
12257 would have been set to 0 in display_line. */
12258 && CHARPOS (this_line_start_pos
)
12259 /* Line ends as before. */
12260 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
12261 /* Line has same height as before. Otherwise other lines
12262 would have to be shifted up or down. */
12263 && this_line_pixel_height
== line_height_before
)
12265 /* If this is not the window's last line, we must adjust
12266 the charstarts of the lines below. */
12267 if (it
.current_y
< it
.last_visible_y
)
12269 struct glyph_row
*row
12270 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
12271 EMACS_INT delta
, delta_bytes
;
12273 /* We used to distinguish between two cases here,
12274 conditioned by Z - CHARPOS (tlendpos) == ZV, for
12275 when the line ends in a newline or the end of the
12276 buffer's accessible portion. But both cases did
12277 the same, so they were collapsed. */
12279 - CHARPOS (tlendpos
)
12280 - MATRIX_ROW_START_CHARPOS (row
));
12281 delta_bytes
= (Z_BYTE
12282 - BYTEPOS (tlendpos
)
12283 - MATRIX_ROW_START_BYTEPOS (row
));
12285 increment_matrix_positions (w
->current_matrix
,
12286 this_line_vpos
+ 1,
12287 w
->current_matrix
->nrows
,
12288 delta
, delta_bytes
);
12291 /* If this row displays text now but previously didn't,
12292 or vice versa, w->window_end_vpos may have to be
12294 if ((it
.glyph_row
- 1)->displays_text_p
)
12296 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
12297 XSETINT (w
->window_end_vpos
, this_line_vpos
);
12299 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
12300 && this_line_vpos
> 0)
12301 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
12302 w
->window_end_valid
= Qnil
;
12304 /* Update hint: No need to try to scroll in update_window. */
12305 w
->desired_matrix
->no_scrolling_p
= 1;
12308 *w
->desired_matrix
->method
= 0;
12309 debug_method_add (w
, "optimization 1");
12311 #ifdef HAVE_WINDOW_SYSTEM
12312 update_window_fringes (w
, 0);
12319 else if (/* Cursor position hasn't changed. */
12320 PT
== XFASTINT (w
->last_point
)
12321 /* Make sure the cursor was last displayed
12322 in this window. Otherwise we have to reposition it. */
12323 && 0 <= w
->cursor
.vpos
12324 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
12328 do_pending_window_change (1);
12329 /* If selected_window changed, redisplay again. */
12330 if (WINDOWP (selected_window
)
12331 && (w
= XWINDOW (selected_window
)) != sw
)
12334 /* We used to always goto end_of_redisplay here, but this
12335 isn't enough if we have a blinking cursor. */
12336 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
12337 goto end_of_redisplay
;
12341 /* If highlighting the region, or if the cursor is in the echo area,
12342 then we can't just move the cursor. */
12343 else if (! (!NILP (Vtransient_mark_mode
)
12344 && !NILP (BVAR (current_buffer
, mark_active
)))
12345 && (EQ (selected_window
, BVAR (current_buffer
, last_selected_window
))
12346 || highlight_nonselected_windows
)
12347 && NILP (w
->region_showing
)
12348 && NILP (Vshow_trailing_whitespace
)
12349 && !cursor_in_echo_area
)
12352 struct glyph_row
*row
;
12354 /* Skip from tlbufpos to PT and see where it is. Note that
12355 PT may be in invisible text. If so, we will end at the
12356 next visible position. */
12357 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
12358 NULL
, DEFAULT_FACE_ID
);
12359 it
.current_x
= this_line_start_x
;
12360 it
.current_y
= this_line_y
;
12361 it
.vpos
= this_line_vpos
;
12363 /* The call to move_it_to stops in front of PT, but
12364 moves over before-strings. */
12365 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
12367 if (it
.vpos
== this_line_vpos
12368 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12371 xassert (this_line_vpos
== it
.vpos
);
12372 xassert (this_line_y
== it
.current_y
);
12373 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12375 *w
->desired_matrix
->method
= 0;
12376 debug_method_add (w
, "optimization 3");
12385 /* Text changed drastically or point moved off of line. */
12386 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12389 CHARPOS (this_line_start_pos
) = 0;
12390 consider_all_windows_p
|= buffer_shared
> 1;
12391 ++clear_face_cache_count
;
12392 #ifdef HAVE_WINDOW_SYSTEM
12393 ++clear_image_cache_count
;
12396 /* Build desired matrices, and update the display. If
12397 consider_all_windows_p is non-zero, do it for all windows on all
12398 frames. Otherwise do it for selected_window, only. */
12400 if (consider_all_windows_p
)
12402 Lisp_Object tail
, frame
;
12404 FOR_EACH_FRAME (tail
, frame
)
12405 XFRAME (frame
)->updated_p
= 0;
12407 /* Recompute # windows showing selected buffer. This will be
12408 incremented each time such a window is displayed. */
12411 FOR_EACH_FRAME (tail
, frame
)
12413 struct frame
*f
= XFRAME (frame
);
12415 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12417 if (! EQ (frame
, selected_frame
))
12418 /* Select the frame, for the sake of frame-local
12420 select_frame_for_redisplay (frame
);
12422 /* Mark all the scroll bars to be removed; we'll redeem
12423 the ones we want when we redisplay their windows. */
12424 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12425 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12427 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12428 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12430 /* The X error handler may have deleted that frame. */
12431 if (!FRAME_LIVE_P (f
))
12434 /* Any scroll bars which redisplay_windows should have
12435 nuked should now go away. */
12436 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12437 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12439 /* If fonts changed, display again. */
12440 /* ??? rms: I suspect it is a mistake to jump all the way
12441 back to retry here. It should just retry this frame. */
12442 if (fonts_changed_p
)
12445 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12447 /* See if we have to hscroll. */
12448 if (!f
->already_hscrolled_p
)
12450 f
->already_hscrolled_p
= 1;
12451 if (hscroll_windows (f
->root_window
))
12455 /* Prevent various kinds of signals during display
12456 update. stdio is not robust about handling
12457 signals, which can cause an apparent I/O
12459 if (interrupt_input
)
12460 unrequest_sigio ();
12463 /* Update the display. */
12464 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12465 pending
|= update_frame (f
, 0, 0);
12471 if (!EQ (old_frame
, selected_frame
)
12472 && FRAME_LIVE_P (XFRAME (old_frame
)))
12473 /* We played a bit fast-and-loose above and allowed selected_frame
12474 and selected_window to be temporarily out-of-sync but let's make
12475 sure this stays contained. */
12476 select_frame_for_redisplay (old_frame
);
12477 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12481 /* Do the mark_window_display_accurate after all windows have
12482 been redisplayed because this call resets flags in buffers
12483 which are needed for proper redisplay. */
12484 FOR_EACH_FRAME (tail
, frame
)
12486 struct frame
*f
= XFRAME (frame
);
12489 mark_window_display_accurate (f
->root_window
, 1);
12490 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12491 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12496 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12498 Lisp_Object mini_window
;
12499 struct frame
*mini_frame
;
12501 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12502 /* Use list_of_error, not Qerror, so that
12503 we catch only errors and don't run the debugger. */
12504 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12506 redisplay_window_error
);
12508 /* Compare desired and current matrices, perform output. */
12511 /* If fonts changed, display again. */
12512 if (fonts_changed_p
)
12515 /* Prevent various kinds of signals during display update.
12516 stdio is not robust about handling signals,
12517 which can cause an apparent I/O error. */
12518 if (interrupt_input
)
12519 unrequest_sigio ();
12522 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12524 if (hscroll_windows (selected_window
))
12527 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12528 pending
= update_frame (sf
, 0, 0);
12531 /* We may have called echo_area_display at the top of this
12532 function. If the echo area is on another frame, that may
12533 have put text on a frame other than the selected one, so the
12534 above call to update_frame would not have caught it. Catch
12536 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12537 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12539 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12541 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12542 pending
|= update_frame (mini_frame
, 0, 0);
12543 if (!pending
&& hscroll_windows (mini_window
))
12548 /* If display was paused because of pending input, make sure we do a
12549 thorough update the next time. */
12552 /* Prevent the optimization at the beginning of
12553 redisplay_internal that tries a single-line update of the
12554 line containing the cursor in the selected window. */
12555 CHARPOS (this_line_start_pos
) = 0;
12557 /* Let the overlay arrow be updated the next time. */
12558 update_overlay_arrows (0);
12560 /* If we pause after scrolling, some rows in the current
12561 matrices of some windows are not valid. */
12562 if (!WINDOW_FULL_WIDTH_P (w
)
12563 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12564 update_mode_lines
= 1;
12568 if (!consider_all_windows_p
)
12570 /* This has already been done above if
12571 consider_all_windows_p is set. */
12572 mark_window_display_accurate_1 (w
, 1);
12574 /* Say overlay arrows are up to date. */
12575 update_overlay_arrows (1);
12577 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12578 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12581 update_mode_lines
= 0;
12582 windows_or_buffers_changed
= 0;
12583 cursor_type_changed
= 0;
12586 /* Start SIGIO interrupts coming again. Having them off during the
12587 code above makes it less likely one will discard output, but not
12588 impossible, since there might be stuff in the system buffer here.
12589 But it is much hairier to try to do anything about that. */
12590 if (interrupt_input
)
12594 /* If a frame has become visible which was not before, redisplay
12595 again, so that we display it. Expose events for such a frame
12596 (which it gets when becoming visible) don't call the parts of
12597 redisplay constructing glyphs, so simply exposing a frame won't
12598 display anything in this case. So, we have to display these
12599 frames here explicitly. */
12602 Lisp_Object tail
, frame
;
12605 FOR_EACH_FRAME (tail
, frame
)
12607 int this_is_visible
= 0;
12609 if (XFRAME (frame
)->visible
)
12610 this_is_visible
= 1;
12611 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12612 if (XFRAME (frame
)->visible
)
12613 this_is_visible
= 1;
12615 if (this_is_visible
)
12619 if (new_count
!= number_of_visible_frames
)
12620 windows_or_buffers_changed
++;
12623 /* Change frame size now if a change is pending. */
12624 do_pending_window_change (1);
12626 /* If we just did a pending size change, or have additional
12627 visible frames, or selected_window changed, redisplay again. */
12628 if ((windows_or_buffers_changed
&& !pending
)
12629 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
12632 /* Clear the face and image caches.
12634 We used to do this only if consider_all_windows_p. But the cache
12635 needs to be cleared if a timer creates images in the current
12636 buffer (e.g. the test case in Bug#6230). */
12638 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12640 clear_face_cache (0);
12641 clear_face_cache_count
= 0;
12644 #ifdef HAVE_WINDOW_SYSTEM
12645 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12647 clear_image_caches (Qnil
);
12648 clear_image_cache_count
= 0;
12650 #endif /* HAVE_WINDOW_SYSTEM */
12653 unbind_to (count
, Qnil
);
12658 /* Redisplay, but leave alone any recent echo area message unless
12659 another message has been requested in its place.
12661 This is useful in situations where you need to redisplay but no
12662 user action has occurred, making it inappropriate for the message
12663 area to be cleared. See tracking_off and
12664 wait_reading_process_output for examples of these situations.
12666 FROM_WHERE is an integer saying from where this function was
12667 called. This is useful for debugging. */
12670 redisplay_preserve_echo_area (int from_where
)
12672 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12674 if (!NILP (echo_area_buffer
[1]))
12676 /* We have a previously displayed message, but no current
12677 message. Redisplay the previous message. */
12678 display_last_displayed_message_p
= 1;
12679 redisplay_internal ();
12680 display_last_displayed_message_p
= 0;
12683 redisplay_internal ();
12685 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12686 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12687 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12691 /* Function registered with record_unwind_protect in
12692 redisplay_internal. Reset redisplaying_p to the value it had
12693 before redisplay_internal was called, and clear
12694 prevent_freeing_realized_faces_p. It also selects the previously
12695 selected frame, unless it has been deleted (by an X connection
12696 failure during redisplay, for example). */
12699 unwind_redisplay (Lisp_Object val
)
12701 Lisp_Object old_redisplaying_p
, old_frame
;
12703 old_redisplaying_p
= XCAR (val
);
12704 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12705 old_frame
= XCDR (val
);
12706 if (! EQ (old_frame
, selected_frame
)
12707 && FRAME_LIVE_P (XFRAME (old_frame
)))
12708 select_frame_for_redisplay (old_frame
);
12713 /* Mark the display of window W as accurate or inaccurate. If
12714 ACCURATE_P is non-zero mark display of W as accurate. If
12715 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12716 redisplay_internal is called. */
12719 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
12721 if (BUFFERP (w
->buffer
))
12723 struct buffer
*b
= XBUFFER (w
->buffer
);
12726 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12727 w
->last_overlay_modified
12728 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12730 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12734 b
->clip_changed
= 0;
12735 b
->prevent_redisplay_optimizations_p
= 0;
12737 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12738 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12739 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12740 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12742 w
->current_matrix
->buffer
= b
;
12743 w
->current_matrix
->begv
= BUF_BEGV (b
);
12744 w
->current_matrix
->zv
= BUF_ZV (b
);
12746 w
->last_cursor
= w
->cursor
;
12747 w
->last_cursor_off_p
= w
->cursor_off_p
;
12749 if (w
== XWINDOW (selected_window
))
12750 w
->last_point
= make_number (BUF_PT (b
));
12752 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12758 w
->window_end_valid
= w
->buffer
;
12759 w
->update_mode_line
= Qnil
;
12764 /* Mark the display of windows in the window tree rooted at WINDOW as
12765 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12766 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12767 be redisplayed the next time redisplay_internal is called. */
12770 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
12774 for (; !NILP (window
); window
= w
->next
)
12776 w
= XWINDOW (window
);
12777 mark_window_display_accurate_1 (w
, accurate_p
);
12779 if (!NILP (w
->vchild
))
12780 mark_window_display_accurate (w
->vchild
, accurate_p
);
12781 if (!NILP (w
->hchild
))
12782 mark_window_display_accurate (w
->hchild
, accurate_p
);
12787 update_overlay_arrows (1);
12791 /* Force a thorough redisplay the next time by setting
12792 last_arrow_position and last_arrow_string to t, which is
12793 unequal to any useful value of Voverlay_arrow_... */
12794 update_overlay_arrows (-1);
12799 /* Return value in display table DP (Lisp_Char_Table *) for character
12800 C. Since a display table doesn't have any parent, we don't have to
12801 follow parent. Do not call this function directly but use the
12802 macro DISP_CHAR_VECTOR. */
12805 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
12809 if (ASCII_CHAR_P (c
))
12812 if (SUB_CHAR_TABLE_P (val
))
12813 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12819 XSETCHAR_TABLE (table
, dp
);
12820 val
= char_table_ref (table
, c
);
12829 /***********************************************************************
12831 ***********************************************************************/
12833 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12836 redisplay_windows (Lisp_Object window
)
12838 while (!NILP (window
))
12840 struct window
*w
= XWINDOW (window
);
12842 if (!NILP (w
->hchild
))
12843 redisplay_windows (w
->hchild
);
12844 else if (!NILP (w
->vchild
))
12845 redisplay_windows (w
->vchild
);
12846 else if (!NILP (w
->buffer
))
12848 displayed_buffer
= XBUFFER (w
->buffer
);
12849 /* Use list_of_error, not Qerror, so that
12850 we catch only errors and don't run the debugger. */
12851 internal_condition_case_1 (redisplay_window_0
, window
,
12853 redisplay_window_error
);
12861 redisplay_window_error (Lisp_Object ignore
)
12863 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12868 redisplay_window_0 (Lisp_Object window
)
12870 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12871 redisplay_window (window
, 0);
12876 redisplay_window_1 (Lisp_Object window
)
12878 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12879 redisplay_window (window
, 1);
12884 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12885 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12886 which positions recorded in ROW differ from current buffer
12889 Return 0 if cursor is not on this row, 1 otherwise. */
12892 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
12893 struct glyph_matrix
*matrix
,
12894 EMACS_INT delta
, EMACS_INT delta_bytes
,
12897 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12898 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12899 struct glyph
*cursor
= NULL
;
12900 /* The last known character position in row. */
12901 EMACS_INT last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12903 EMACS_INT pt_old
= PT
- delta
;
12904 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12905 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12906 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
12907 /* A glyph beyond the edge of TEXT_AREA which we should never
12909 struct glyph
*glyphs_end
= end
;
12910 /* Non-zero means we've found a match for cursor position, but that
12911 glyph has the avoid_cursor_p flag set. */
12912 int match_with_avoid_cursor
= 0;
12913 /* Non-zero means we've seen at least one glyph that came from a
12915 int string_seen
= 0;
12916 /* Largest and smalles buffer positions seen so far during scan of
12918 EMACS_INT bpos_max
= pos_before
;
12919 EMACS_INT bpos_min
= pos_after
;
12920 /* Last buffer position covered by an overlay string with an integer
12921 `cursor' property. */
12922 EMACS_INT bpos_covered
= 0;
12924 /* Skip over glyphs not having an object at the start and the end of
12925 the row. These are special glyphs like truncation marks on
12926 terminal frames. */
12927 if (row
->displays_text_p
)
12929 if (!row
->reversed_p
)
12932 && INTEGERP (glyph
->object
)
12933 && glyph
->charpos
< 0)
12935 x
+= glyph
->pixel_width
;
12939 && INTEGERP ((end
- 1)->object
)
12940 /* CHARPOS is zero for blanks and stretch glyphs
12941 inserted by extend_face_to_end_of_line. */
12942 && (end
- 1)->charpos
<= 0)
12944 glyph_before
= glyph
- 1;
12951 /* If the glyph row is reversed, we need to process it from back
12952 to front, so swap the edge pointers. */
12953 glyphs_end
= end
= glyph
- 1;
12954 glyph
+= row
->used
[TEXT_AREA
] - 1;
12956 while (glyph
> end
+ 1
12957 && INTEGERP (glyph
->object
)
12958 && glyph
->charpos
< 0)
12961 x
-= glyph
->pixel_width
;
12963 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
12965 /* By default, in reversed rows we put the cursor on the
12966 rightmost (first in the reading order) glyph. */
12967 for (g
= end
+ 1; g
< glyph
; g
++)
12968 x
+= g
->pixel_width
;
12970 && INTEGERP ((end
+ 1)->object
)
12971 && (end
+ 1)->charpos
<= 0)
12973 glyph_before
= glyph
+ 1;
12977 else if (row
->reversed_p
)
12979 /* In R2L rows that don't display text, put the cursor on the
12980 rightmost glyph. Case in point: an empty last line that is
12981 part of an R2L paragraph. */
12983 /* Avoid placing the cursor on the last glyph of the row, where
12984 on terminal frames we hold the vertical border between
12985 adjacent windows. */
12986 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
12987 && !WINDOW_RIGHTMOST_P (w
)
12988 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
12990 x
= -1; /* will be computed below, at label compute_x */
12993 /* Step 1: Try to find the glyph whose character position
12994 corresponds to point. If that's not possible, find 2 glyphs
12995 whose character positions are the closest to point, one before
12996 point, the other after it. */
12997 if (!row
->reversed_p
)
12998 while (/* not marched to end of glyph row */
13000 /* glyph was not inserted by redisplay for internal purposes */
13001 && !INTEGERP (glyph
->object
))
13003 if (BUFFERP (glyph
->object
))
13005 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
13007 if (glyph
->charpos
> bpos_max
)
13008 bpos_max
= glyph
->charpos
;
13009 if (glyph
->charpos
< bpos_min
)
13010 bpos_min
= glyph
->charpos
;
13011 if (!glyph
->avoid_cursor_p
)
13013 /* If we hit point, we've found the glyph on which to
13014 display the cursor. */
13017 match_with_avoid_cursor
= 0;
13020 /* See if we've found a better approximation to
13021 POS_BEFORE or to POS_AFTER. Note that we want the
13022 first (leftmost) glyph of all those that are the
13023 closest from below, and the last (rightmost) of all
13024 those from above. */
13025 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13027 pos_before
= glyph
->charpos
;
13028 glyph_before
= glyph
;
13030 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13032 pos_after
= glyph
->charpos
;
13033 glyph_after
= glyph
;
13036 else if (dpos
== 0)
13037 match_with_avoid_cursor
= 1;
13039 else if (STRINGP (glyph
->object
))
13041 Lisp_Object chprop
;
13042 EMACS_INT glyph_pos
= glyph
->charpos
;
13044 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13046 if (INTEGERP (chprop
))
13048 bpos_covered
= bpos_max
+ XINT (chprop
);
13049 /* If the `cursor' property covers buffer positions up
13050 to and including point, we should display cursor on
13051 this glyph. Note that overlays and text properties
13052 with string values stop bidi reordering, so every
13053 buffer position to the left of the string is always
13054 smaller than any position to the right of the
13055 string. Therefore, if a `cursor' property on one
13056 of the string's characters has an integer value, we
13057 will break out of the loop below _before_ we get to
13058 the position match above. IOW, integer values of
13059 the `cursor' property override the "exact match for
13060 point" strategy of positioning the cursor. */
13061 /* Implementation note: bpos_max == pt_old when, e.g.,
13062 we are in an empty line, where bpos_max is set to
13063 MATRIX_ROW_START_CHARPOS, see above. */
13064 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13073 x
+= glyph
->pixel_width
;
13076 else if (glyph
> end
) /* row is reversed */
13077 while (!INTEGERP (glyph
->object
))
13079 if (BUFFERP (glyph
->object
))
13081 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
13083 if (glyph
->charpos
> bpos_max
)
13084 bpos_max
= glyph
->charpos
;
13085 if (glyph
->charpos
< bpos_min
)
13086 bpos_min
= glyph
->charpos
;
13087 if (!glyph
->avoid_cursor_p
)
13091 match_with_avoid_cursor
= 0;
13094 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13096 pos_before
= glyph
->charpos
;
13097 glyph_before
= glyph
;
13099 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13101 pos_after
= glyph
->charpos
;
13102 glyph_after
= glyph
;
13105 else if (dpos
== 0)
13106 match_with_avoid_cursor
= 1;
13108 else if (STRINGP (glyph
->object
))
13110 Lisp_Object chprop
;
13111 EMACS_INT glyph_pos
= glyph
->charpos
;
13113 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13115 if (INTEGERP (chprop
))
13117 bpos_covered
= bpos_max
+ XINT (chprop
);
13118 /* If the `cursor' property covers buffer positions up
13119 to and including point, we should display cursor on
13121 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13130 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
13132 x
--; /* can't use any pixel_width */
13135 x
-= glyph
->pixel_width
;
13138 /* Step 2: If we didn't find an exact match for point, we need to
13139 look for a proper place to put the cursor among glyphs between
13140 GLYPH_BEFORE and GLYPH_AFTER. */
13141 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13142 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13143 && bpos_covered
< pt_old
)
13145 /* An empty line has a single glyph whose OBJECT is zero and
13146 whose CHARPOS is the position of a newline on that line.
13147 Note that on a TTY, there are more glyphs after that, which
13148 were produced by extend_face_to_end_of_line, but their
13149 CHARPOS is zero or negative. */
13151 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13152 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
13154 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
13156 EMACS_INT ellipsis_pos
;
13158 /* Scan back over the ellipsis glyphs. */
13159 if (!row
->reversed_p
)
13161 ellipsis_pos
= (glyph
- 1)->charpos
;
13162 while (glyph
> row
->glyphs
[TEXT_AREA
]
13163 && (glyph
- 1)->charpos
== ellipsis_pos
)
13164 glyph
--, x
-= glyph
->pixel_width
;
13165 /* That loop always goes one position too far, including
13166 the glyph before the ellipsis. So scan forward over
13168 x
+= glyph
->pixel_width
;
13171 else /* row is reversed */
13173 ellipsis_pos
= (glyph
+ 1)->charpos
;
13174 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
13175 && (glyph
+ 1)->charpos
== ellipsis_pos
)
13176 glyph
++, x
+= glyph
->pixel_width
;
13177 x
-= glyph
->pixel_width
;
13181 else if (match_with_avoid_cursor
13182 /* A truncated row may not include PT among its
13183 character positions. Setting the cursor inside the
13184 scroll margin will trigger recalculation of hscroll
13185 in hscroll_window_tree. */
13186 || (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
13187 || (row
->truncated_on_right_p
&& pt_old
> bpos_max
)
13188 /* Zero-width characters produce no glyphs. */
13191 && (row
->reversed_p
13192 ? glyph_after
> glyphs_end
13193 : glyph_after
< glyphs_end
)))
13195 cursor
= glyph_after
;
13198 else if (string_seen
)
13200 int incr
= row
->reversed_p
? -1 : +1;
13202 /* Need to find the glyph that came out of a string which is
13203 present at point. That glyph is somewhere between
13204 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
13205 positioned between POS_BEFORE and POS_AFTER in the
13207 struct glyph
*start
, *stop
;
13208 EMACS_INT pos
= pos_before
;
13212 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
13213 correspond to POS_BEFORE and POS_AFTER, respectively. We
13214 need START and STOP in the order that corresponds to the
13215 row's direction as given by its reversed_p flag. If the
13216 directionality of characters between POS_BEFORE and
13217 POS_AFTER is the opposite of the row's base direction,
13218 these characters will have been reordered for display,
13219 and we need to reverse START and STOP. */
13220 if (!row
->reversed_p
)
13222 start
= min (glyph_before
, glyph_after
);
13223 stop
= max (glyph_before
, glyph_after
);
13227 start
= max (glyph_before
, glyph_after
);
13228 stop
= min (glyph_before
, glyph_after
);
13230 for (glyph
= start
+ incr
;
13231 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
13234 /* Any glyphs that come from the buffer are here because
13235 of bidi reordering. Skip them, and only pay
13236 attention to glyphs that came from some string. */
13237 if (STRINGP (glyph
->object
))
13242 str
= glyph
->object
;
13243 tem
= string_buffer_position_lim (str
, pos
, pos_after
, 0);
13244 if (tem
== 0 /* from overlay */
13247 /* If the string from which this glyph came is
13248 found in the buffer at point, then we've
13249 found the glyph we've been looking for. If
13250 it comes from an overlay (tem == 0), and it
13251 has the `cursor' property on one of its
13252 glyphs, record that glyph as a candidate for
13253 displaying the cursor. (As in the
13254 unidirectional version, we will display the
13255 cursor on the last candidate we find.) */
13256 if (tem
== 0 || tem
== pt_old
)
13258 /* The glyphs from this string could have
13259 been reordered. Find the one with the
13260 smallest string position. Or there could
13261 be a character in the string with the
13262 `cursor' property, which means display
13263 cursor on that character's glyph. */
13264 EMACS_INT strpos
= glyph
->charpos
;
13269 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
13270 && EQ (glyph
->object
, str
);
13274 EMACS_INT gpos
= glyph
->charpos
;
13276 cprop
= Fget_char_property (make_number (gpos
),
13284 if (tem
&& glyph
->charpos
< strpos
)
13286 strpos
= glyph
->charpos
;
13295 pos
= tem
+ 1; /* don't find previous instances */
13297 /* This string is not what we want; skip all of the
13298 glyphs that came from it. */
13299 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
13300 && EQ (glyph
->object
, str
))
13307 /* If we reached the end of the line, and END was from a string,
13308 the cursor is not on this line. */
13310 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
13311 && STRINGP (end
->object
)
13312 && row
->continued_p
)
13318 if (cursor
!= NULL
)
13324 /* Need to compute x that corresponds to GLYPH. */
13325 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
13327 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
13329 x
+= g
->pixel_width
;
13333 /* ROW could be part of a continued line, which, under bidi
13334 reordering, might have other rows whose start and end charpos
13335 occlude point. Only set w->cursor if we found a better
13336 approximation to the cursor position than we have from previously
13337 examined candidate rows belonging to the same continued line. */
13338 if (/* we already have a candidate row */
13339 w
->cursor
.vpos
>= 0
13340 /* that candidate is not the row we are processing */
13341 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
13342 /* the row we are processing is part of a continued line */
13343 && (row
->continued_p
|| MATRIX_ROW_CONTINUATION_LINE_P (row
))
13344 /* Make sure cursor.vpos specifies a row whose start and end
13345 charpos occlude point. This is because some callers of this
13346 function leave cursor.vpos at the row where the cursor was
13347 displayed during the last redisplay cycle. */
13348 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
13349 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
13352 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
13354 /* Don't consider glyphs that are outside TEXT_AREA. */
13355 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
13357 /* Keep the candidate whose buffer position is the closest to
13359 if (/* previous candidate is a glyph in TEXT_AREA of that row */
13360 w
->cursor
.hpos
>= 0
13361 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
13362 && BUFFERP (g1
->object
)
13363 && (g1
->charpos
== pt_old
/* an exact match always wins */
13364 || (BUFFERP (glyph
->object
)
13365 && eabs (g1
->charpos
- pt_old
)
13366 < eabs (glyph
->charpos
- pt_old
))))
13368 /* If this candidate gives an exact match, use that. */
13369 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13370 /* Otherwise, keep the candidate that comes from a row
13371 spanning less buffer positions. This may win when one or
13372 both candidate positions are on glyphs that came from
13373 display strings, for which we cannot compare buffer
13375 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13376 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13377 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
13380 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
13382 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
13383 w
->cursor
.y
= row
->y
+ dy
;
13385 if (w
== XWINDOW (selected_window
))
13387 if (!row
->continued_p
13388 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
13391 this_line_buffer
= XBUFFER (w
->buffer
);
13393 CHARPOS (this_line_start_pos
)
13394 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
13395 BYTEPOS (this_line_start_pos
)
13396 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
13398 CHARPOS (this_line_end_pos
)
13399 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
13400 BYTEPOS (this_line_end_pos
)
13401 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
13403 this_line_y
= w
->cursor
.y
;
13404 this_line_pixel_height
= row
->height
;
13405 this_line_vpos
= w
->cursor
.vpos
;
13406 this_line_start_x
= row
->x
;
13409 CHARPOS (this_line_start_pos
) = 0;
13416 /* Run window scroll functions, if any, for WINDOW with new window
13417 start STARTP. Sets the window start of WINDOW to that position.
13419 We assume that the window's buffer is really current. */
13421 static INLINE
struct text_pos
13422 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
13424 struct window
*w
= XWINDOW (window
);
13425 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13427 if (current_buffer
!= XBUFFER (w
->buffer
))
13430 if (!NILP (Vwindow_scroll_functions
))
13432 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13433 make_number (CHARPOS (startp
)));
13434 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13435 /* In case the hook functions switch buffers. */
13436 if (current_buffer
!= XBUFFER (w
->buffer
))
13437 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13444 /* Make sure the line containing the cursor is fully visible.
13445 A value of 1 means there is nothing to be done.
13446 (Either the line is fully visible, or it cannot be made so,
13447 or we cannot tell.)
13449 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13450 is higher than window.
13452 A value of 0 means the caller should do scrolling
13453 as if point had gone off the screen. */
13456 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
13458 struct glyph_matrix
*matrix
;
13459 struct glyph_row
*row
;
13462 if (!make_cursor_line_fully_visible_p
)
13465 /* It's not always possible to find the cursor, e.g, when a window
13466 is full of overlay strings. Don't do anything in that case. */
13467 if (w
->cursor
.vpos
< 0)
13470 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13471 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13473 /* If the cursor row is not partially visible, there's nothing to do. */
13474 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13477 /* If the row the cursor is in is taller than the window's height,
13478 it's not clear what to do, so do nothing. */
13479 window_height
= window_box_height (w
);
13480 if (row
->height
>= window_height
)
13482 if (!force_p
|| MINI_WINDOW_P (w
)
13483 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13490 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13491 non-zero means only WINDOW is redisplayed in redisplay_internal.
13492 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
13493 in redisplay_window to bring a partially visible line into view in
13494 the case that only the cursor has moved.
13496 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13497 last screen line's vertical height extends past the end of the screen.
13501 1 if scrolling succeeded
13503 0 if scrolling didn't find point.
13505 -1 if new fonts have been loaded so that we must interrupt
13506 redisplay, adjust glyph matrices, and try again. */
13512 SCROLLING_NEED_LARGER_MATRICES
13515 /* If scroll-conservatively is more than this, never recenter.
13517 If you change this, don't forget to update the doc string of
13518 `scroll-conservatively' and the Emacs manual. */
13519 #define SCROLL_LIMIT 100
13522 try_scrolling (Lisp_Object window
, int just_this_one_p
,
13523 EMACS_INT arg_scroll_conservatively
, EMACS_INT scroll_step
,
13524 int temp_scroll_step
, int last_line_misfit
)
13526 struct window
*w
= XWINDOW (window
);
13527 struct frame
*f
= XFRAME (w
->frame
);
13528 struct text_pos pos
, startp
;
13530 int this_scroll_margin
, scroll_max
, rc
, height
;
13531 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13532 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13533 Lisp_Object aggressive
;
13534 /* We will never try scrolling more than this number of lines. */
13535 int scroll_limit
= SCROLL_LIMIT
;
13538 debug_method_add (w
, "try_scrolling");
13541 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13543 /* Compute scroll margin height in pixels. We scroll when point is
13544 within this distance from the top or bottom of the window. */
13545 if (scroll_margin
> 0)
13546 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13547 * FRAME_LINE_HEIGHT (f
);
13549 this_scroll_margin
= 0;
13551 /* Force arg_scroll_conservatively to have a reasonable value, to
13552 avoid scrolling too far away with slow move_it_* functions. Note
13553 that the user can supply scroll-conservatively equal to
13554 `most-positive-fixnum', which can be larger than INT_MAX. */
13555 if (arg_scroll_conservatively
> scroll_limit
)
13557 arg_scroll_conservatively
= scroll_limit
+ 1;
13558 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
13560 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
13561 /* Compute how much we should try to scroll maximally to bring
13562 point into view. */
13563 scroll_max
= (max (scroll_step
,
13564 max (arg_scroll_conservatively
, temp_scroll_step
))
13565 * FRAME_LINE_HEIGHT (f
));
13566 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
13567 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
13568 /* We're trying to scroll because of aggressive scrolling but no
13569 scroll_step is set. Choose an arbitrary one. */
13570 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13576 /* Decide whether to scroll down. */
13577 if (PT
> CHARPOS (startp
))
13579 int scroll_margin_y
;
13581 /* Compute the pixel ypos of the scroll margin, then move it to
13582 either that ypos or PT, whichever comes first. */
13583 start_display (&it
, w
, startp
);
13584 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13585 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13586 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13587 (MOVE_TO_POS
| MOVE_TO_Y
));
13589 if (PT
> CHARPOS (it
.current
.pos
))
13591 int y0
= line_bottom_y (&it
);
13592 /* Compute how many pixels below window bottom to stop searching
13593 for PT. This avoids costly search for PT that is far away if
13594 the user limited scrolling by a small number of lines, but
13595 always finds PT if scroll_conservatively is set to a large
13596 number, such as most-positive-fixnum. */
13597 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
13598 int y_to_move
= it
.last_visible_y
+ slack
;
13600 /* Compute the distance from the scroll margin to PT or to
13601 the scroll limit, whichever comes first. This should
13602 include the height of the cursor line, to make that line
13604 move_it_to (&it
, PT
, -1, y_to_move
,
13605 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13606 dy
= line_bottom_y (&it
) - y0
;
13608 if (dy
> scroll_max
)
13609 return SCROLLING_FAILED
;
13617 /* Point is in or below the bottom scroll margin, so move the
13618 window start down. If scrolling conservatively, move it just
13619 enough down to make point visible. If scroll_step is set,
13620 move it down by scroll_step. */
13621 if (arg_scroll_conservatively
)
13623 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13624 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
13625 else if (scroll_step
|| temp_scroll_step
)
13626 amount_to_scroll
= scroll_max
;
13629 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
13630 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13631 if (NUMBERP (aggressive
))
13633 double float_amount
= XFLOATINT (aggressive
) * height
;
13634 amount_to_scroll
= float_amount
;
13635 if (amount_to_scroll
== 0 && float_amount
> 0)
13636 amount_to_scroll
= 1;
13637 /* Don't let point enter the scroll margin near top of
13639 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13640 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13644 if (amount_to_scroll
<= 0)
13645 return SCROLLING_FAILED
;
13647 start_display (&it
, w
, startp
);
13648 if (arg_scroll_conservatively
<= scroll_limit
)
13649 move_it_vertically (&it
, amount_to_scroll
);
13652 /* Extra precision for users who set scroll-conservatively
13653 to a large number: make sure the amount we scroll
13654 the window start is never less than amount_to_scroll,
13655 which was computed as distance from window bottom to
13656 point. This matters when lines at window top and lines
13657 below window bottom have different height. */
13658 struct it it1
= it
;
13659 /* We use a temporary it1 because line_bottom_y can modify
13660 its argument, if it moves one line down; see there. */
13661 int start_y
= line_bottom_y (&it1
);
13664 move_it_by_lines (&it
, 1);
13666 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
13669 /* If STARTP is unchanged, move it down another screen line. */
13670 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13671 move_it_by_lines (&it
, 1);
13672 startp
= it
.current
.pos
;
13676 struct text_pos scroll_margin_pos
= startp
;
13678 /* See if point is inside the scroll margin at the top of the
13680 if (this_scroll_margin
)
13682 start_display (&it
, w
, startp
);
13683 move_it_vertically (&it
, this_scroll_margin
);
13684 scroll_margin_pos
= it
.current
.pos
;
13687 if (PT
< CHARPOS (scroll_margin_pos
))
13689 /* Point is in the scroll margin at the top of the window or
13690 above what is displayed in the window. */
13693 /* Compute the vertical distance from PT to the scroll
13694 margin position. Move as far as scroll_max allows, or
13695 one screenful, or 10 screen lines, whichever is largest.
13696 Give up if distance is greater than scroll_max. */
13697 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13698 start_display (&it
, w
, pos
);
13700 y_to_move
= max (it
.last_visible_y
,
13701 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
13702 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13704 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13705 dy
= it
.current_y
- y0
;
13706 if (dy
> scroll_max
)
13707 return SCROLLING_FAILED
;
13709 /* Compute new window start. */
13710 start_display (&it
, w
, startp
);
13712 if (arg_scroll_conservatively
)
13713 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
13714 max (scroll_step
, temp_scroll_step
));
13715 else if (scroll_step
|| temp_scroll_step
)
13716 amount_to_scroll
= scroll_max
;
13719 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
13720 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13721 if (NUMBERP (aggressive
))
13723 double float_amount
= XFLOATINT (aggressive
) * height
;
13724 amount_to_scroll
= float_amount
;
13725 if (amount_to_scroll
== 0 && float_amount
> 0)
13726 amount_to_scroll
= 1;
13727 amount_to_scroll
-=
13728 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
13729 /* Don't let point enter the scroll margin near
13730 bottom of the window. */
13731 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13732 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13736 if (amount_to_scroll
<= 0)
13737 return SCROLLING_FAILED
;
13739 move_it_vertically_backward (&it
, amount_to_scroll
);
13740 startp
= it
.current
.pos
;
13744 /* Run window scroll functions. */
13745 startp
= run_window_scroll_functions (window
, startp
);
13747 /* Display the window. Give up if new fonts are loaded, or if point
13749 if (!try_window (window
, startp
, 0))
13750 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13751 else if (w
->cursor
.vpos
< 0)
13753 clear_glyph_matrix (w
->desired_matrix
);
13754 rc
= SCROLLING_FAILED
;
13758 /* Maybe forget recorded base line for line number display. */
13759 if (!just_this_one_p
13760 || current_buffer
->clip_changed
13761 || BEG_UNCHANGED
< CHARPOS (startp
))
13762 w
->base_line_number
= Qnil
;
13764 /* If cursor ends up on a partially visible line,
13765 treat that as being off the bottom of the screen. */
13766 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
13767 /* It's possible that the cursor is on the first line of the
13768 buffer, which is partially obscured due to a vscroll
13769 (Bug#7537). In that case, avoid looping forever . */
13770 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
13772 clear_glyph_matrix (w
->desired_matrix
);
13773 ++extra_scroll_margin_lines
;
13776 rc
= SCROLLING_SUCCESS
;
13783 /* Compute a suitable window start for window W if display of W starts
13784 on a continuation line. Value is non-zero if a new window start
13787 The new window start will be computed, based on W's width, starting
13788 from the start of the continued line. It is the start of the
13789 screen line with the minimum distance from the old start W->start. */
13792 compute_window_start_on_continuation_line (struct window
*w
)
13794 struct text_pos pos
, start_pos
;
13795 int window_start_changed_p
= 0;
13797 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13799 /* If window start is on a continuation line... Window start may be
13800 < BEGV in case there's invisible text at the start of the
13801 buffer (M-x rmail, for example). */
13802 if (CHARPOS (start_pos
) > BEGV
13803 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13806 struct glyph_row
*row
;
13808 /* Handle the case that the window start is out of range. */
13809 if (CHARPOS (start_pos
) < BEGV
)
13810 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13811 else if (CHARPOS (start_pos
) > ZV
)
13812 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13814 /* Find the start of the continued line. This should be fast
13815 because scan_buffer is fast (newline cache). */
13816 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13817 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13818 row
, DEFAULT_FACE_ID
);
13819 reseat_at_previous_visible_line_start (&it
);
13821 /* If the line start is "too far" away from the window start,
13822 say it takes too much time to compute a new window start. */
13823 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13824 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13826 int min_distance
, distance
;
13828 /* Move forward by display lines to find the new window
13829 start. If window width was enlarged, the new start can
13830 be expected to be > the old start. If window width was
13831 decreased, the new window start will be < the old start.
13832 So, we're looking for the display line start with the
13833 minimum distance from the old window start. */
13834 pos
= it
.current
.pos
;
13835 min_distance
= INFINITY
;
13836 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13837 distance
< min_distance
)
13839 min_distance
= distance
;
13840 pos
= it
.current
.pos
;
13841 move_it_by_lines (&it
, 1);
13844 /* Set the window start there. */
13845 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13846 window_start_changed_p
= 1;
13850 return window_start_changed_p
;
13854 /* Try cursor movement in case text has not changed in window WINDOW,
13855 with window start STARTP. Value is
13857 CURSOR_MOVEMENT_SUCCESS if successful
13859 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13861 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13862 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13863 we want to scroll as if scroll-step were set to 1. See the code.
13865 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13866 which case we have to abort this redisplay, and adjust matrices
13871 CURSOR_MOVEMENT_SUCCESS
,
13872 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13873 CURSOR_MOVEMENT_MUST_SCROLL
,
13874 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13878 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
13880 struct window
*w
= XWINDOW (window
);
13881 struct frame
*f
= XFRAME (w
->frame
);
13882 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13885 if (inhibit_try_cursor_movement
)
13889 /* Handle case where text has not changed, only point, and it has
13890 not moved off the frame. */
13891 if (/* Point may be in this window. */
13892 PT
>= CHARPOS (startp
)
13893 /* Selective display hasn't changed. */
13894 && !current_buffer
->clip_changed
13895 /* Function force-mode-line-update is used to force a thorough
13896 redisplay. It sets either windows_or_buffers_changed or
13897 update_mode_lines. So don't take a shortcut here for these
13899 && !update_mode_lines
13900 && !windows_or_buffers_changed
13901 && !cursor_type_changed
13902 /* Can't use this case if highlighting a region. When a
13903 region exists, cursor movement has to do more than just
13905 && !(!NILP (Vtransient_mark_mode
)
13906 && !NILP (BVAR (current_buffer
, mark_active
)))
13907 && NILP (w
->region_showing
)
13908 && NILP (Vshow_trailing_whitespace
)
13909 /* Right after splitting windows, last_point may be nil. */
13910 && INTEGERP (w
->last_point
)
13911 /* This code is not used for mini-buffer for the sake of the case
13912 of redisplaying to replace an echo area message; since in
13913 that case the mini-buffer contents per se are usually
13914 unchanged. This code is of no real use in the mini-buffer
13915 since the handling of this_line_start_pos, etc., in redisplay
13916 handles the same cases. */
13917 && !EQ (window
, minibuf_window
)
13918 /* When splitting windows or for new windows, it happens that
13919 redisplay is called with a nil window_end_vpos or one being
13920 larger than the window. This should really be fixed in
13921 window.c. I don't have this on my list, now, so we do
13922 approximately the same as the old redisplay code. --gerd. */
13923 && INTEGERP (w
->window_end_vpos
)
13924 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13925 && (FRAME_WINDOW_P (f
)
13926 || !overlay_arrow_in_current_buffer_p ()))
13928 int this_scroll_margin
, top_scroll_margin
;
13929 struct glyph_row
*row
= NULL
;
13932 debug_method_add (w
, "cursor movement");
13935 /* Scroll if point within this distance from the top or bottom
13936 of the window. This is a pixel value. */
13937 if (scroll_margin
> 0)
13939 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13940 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13943 this_scroll_margin
= 0;
13945 top_scroll_margin
= this_scroll_margin
;
13946 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13947 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13949 /* Start with the row the cursor was displayed during the last
13950 not paused redisplay. Give up if that row is not valid. */
13951 if (w
->last_cursor
.vpos
< 0
13952 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13953 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13956 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13957 if (row
->mode_line_p
)
13959 if (!row
->enabled_p
)
13960 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13963 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13965 int scroll_p
= 0, must_scroll
= 0;
13966 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13968 if (PT
> XFASTINT (w
->last_point
))
13970 /* Point has moved forward. */
13971 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13972 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13974 xassert (row
->enabled_p
);
13978 /* If the end position of a row equals the start
13979 position of the next row, and PT is at that position,
13980 we would rather display cursor in the next line. */
13981 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13982 && MATRIX_ROW_END_CHARPOS (row
) == PT
13983 && row
< w
->current_matrix
->rows
13984 + w
->current_matrix
->nrows
- 1
13985 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
13986 && !cursor_row_p (row
))
13989 /* If within the scroll margin, scroll. Note that
13990 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13991 the next line would be drawn, and that
13992 this_scroll_margin can be zero. */
13993 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13994 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13995 /* Line is completely visible last line in window
13996 and PT is to be set in the next line. */
13997 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13998 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13999 && !row
->ends_at_zv_p
14000 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14003 else if (PT
< XFASTINT (w
->last_point
))
14005 /* Cursor has to be moved backward. Note that PT >=
14006 CHARPOS (startp) because of the outer if-statement. */
14007 while (!row
->mode_line_p
14008 && (MATRIX_ROW_START_CHARPOS (row
) > PT
14009 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14010 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
14011 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
14012 row
> w
->current_matrix
->rows
14013 && (row
-1)->ends_in_newline_from_string_p
))))
14014 && (row
->y
> top_scroll_margin
14015 || CHARPOS (startp
) == BEGV
))
14017 xassert (row
->enabled_p
);
14021 /* Consider the following case: Window starts at BEGV,
14022 there is invisible, intangible text at BEGV, so that
14023 display starts at some point START > BEGV. It can
14024 happen that we are called with PT somewhere between
14025 BEGV and START. Try to handle that case. */
14026 if (row
< w
->current_matrix
->rows
14027 || row
->mode_line_p
)
14029 row
= w
->current_matrix
->rows
;
14030 if (row
->mode_line_p
)
14034 /* Due to newlines in overlay strings, we may have to
14035 skip forward over overlay strings. */
14036 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14037 && MATRIX_ROW_END_CHARPOS (row
) == PT
14038 && !cursor_row_p (row
))
14041 /* If within the scroll margin, scroll. */
14042 if (row
->y
< top_scroll_margin
14043 && CHARPOS (startp
) != BEGV
)
14048 /* Cursor did not move. So don't scroll even if cursor line
14049 is partially visible, as it was so before. */
14050 rc
= CURSOR_MOVEMENT_SUCCESS
;
14053 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
14054 || PT
> MATRIX_ROW_END_CHARPOS (row
))
14056 /* if PT is not in the glyph row, give up. */
14057 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14060 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14061 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14063 /* If rows are bidi-reordered and point moved, back up
14064 until we find a row that does not belong to a
14065 continuation line. This is because we must consider
14066 all rows of a continued line as candidates for the
14067 new cursor positioning, since row start and end
14068 positions change non-linearly with vertical position
14070 /* FIXME: Revisit this when glyph ``spilling'' in
14071 continuation lines' rows is implemented for
14072 bidi-reordered rows. */
14073 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
14075 xassert (row
->enabled_p
);
14077 /* If we hit the beginning of the displayed portion
14078 without finding the first row of a continued
14080 if (row
<= w
->current_matrix
->rows
)
14082 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14090 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14091 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
14092 && make_cursor_line_fully_visible_p
)
14094 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
14095 && !row
->ends_at_zv_p
14096 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14097 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14098 else if (row
->height
> window_box_height (w
))
14100 /* If we end up in a partially visible line, let's
14101 make it fully visible, except when it's taller
14102 than the window, in which case we can't do much
14105 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14109 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14110 if (!cursor_row_fully_visible_p (w
, 0, 1))
14111 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14113 rc
= CURSOR_MOVEMENT_SUCCESS
;
14117 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14118 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14119 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14121 /* With bidi-reordered rows, there could be more than
14122 one candidate row whose start and end positions
14123 occlude point. We need to let set_cursor_from_row
14124 find the best candidate. */
14125 /* FIXME: Revisit this when glyph ``spilling'' in
14126 continuation lines' rows is implemented for
14127 bidi-reordered rows. */
14132 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
14133 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14134 && cursor_row_p (row
))
14135 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
14137 /* As soon as we've found the first suitable row
14138 whose ends_at_zv_p flag is set, we are done. */
14140 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
14142 rc
= CURSOR_MOVEMENT_SUCCESS
;
14147 while ((MATRIX_ROW_CONTINUATION_LINE_P (row
)
14148 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
14149 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14150 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
14151 /* If we didn't find any candidate rows, or exited the
14152 loop before all the candidates were examined, signal
14153 to the caller that this method failed. */
14154 if (rc
!= CURSOR_MOVEMENT_SUCCESS
14155 && (!rv
|| MATRIX_ROW_CONTINUATION_LINE_P (row
)))
14156 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14158 rc
= CURSOR_MOVEMENT_SUCCESS
;
14164 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
14166 rc
= CURSOR_MOVEMENT_SUCCESS
;
14171 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14172 && MATRIX_ROW_START_CHARPOS (row
) == PT
14173 && cursor_row_p (row
));
14181 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
14185 set_vertical_scroll_bar (struct window
*w
)
14187 EMACS_INT start
, end
, whole
;
14189 /* Calculate the start and end positions for the current window.
14190 At some point, it would be nice to choose between scrollbars
14191 which reflect the whole buffer size, with special markers
14192 indicating narrowing, and scrollbars which reflect only the
14195 Note that mini-buffers sometimes aren't displaying any text. */
14196 if (!MINI_WINDOW_P (w
)
14197 || (w
== XWINDOW (minibuf_window
)
14198 && NILP (echo_area_buffer
[0])))
14200 struct buffer
*buf
= XBUFFER (w
->buffer
);
14201 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
14202 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
14203 /* I don't think this is guaranteed to be right. For the
14204 moment, we'll pretend it is. */
14205 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
14209 if (whole
< (end
- start
))
14210 whole
= end
- start
;
14213 start
= end
= whole
= 0;
14215 /* Indicate what this scroll bar ought to be displaying now. */
14216 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
14217 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
14218 (w
, end
- start
, whole
, start
);
14222 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
14223 selected_window is redisplayed.
14225 We can return without actually redisplaying the window if
14226 fonts_changed_p is nonzero. In that case, redisplay_internal will
14230 redisplay_window (Lisp_Object window
, int just_this_one_p
)
14232 struct window
*w
= XWINDOW (window
);
14233 struct frame
*f
= XFRAME (w
->frame
);
14234 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14235 struct buffer
*old
= current_buffer
;
14236 struct text_pos lpoint
, opoint
, startp
;
14237 int update_mode_line
;
14240 /* Record it now because it's overwritten. */
14241 int current_matrix_up_to_date_p
= 0;
14242 int used_current_matrix_p
= 0;
14243 /* This is less strict than current_matrix_up_to_date_p.
14244 It indictes that the buffer contents and narrowing are unchanged. */
14245 int buffer_unchanged_p
= 0;
14246 int temp_scroll_step
= 0;
14247 int count
= SPECPDL_INDEX ();
14249 int centering_position
= -1;
14250 int last_line_misfit
= 0;
14251 EMACS_INT beg_unchanged
, end_unchanged
;
14253 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14256 /* W must be a leaf window here. */
14257 xassert (!NILP (w
->buffer
));
14259 *w
->desired_matrix
->method
= 0;
14263 reconsider_clip_changes (w
, buffer
);
14265 /* Has the mode line to be updated? */
14266 update_mode_line
= (!NILP (w
->update_mode_line
)
14267 || update_mode_lines
14268 || buffer
->clip_changed
14269 || buffer
->prevent_redisplay_optimizations_p
);
14271 if (MINI_WINDOW_P (w
))
14273 if (w
== XWINDOW (echo_area_window
)
14274 && !NILP (echo_area_buffer
[0]))
14276 if (update_mode_line
)
14277 /* We may have to update a tty frame's menu bar or a
14278 tool-bar. Example `M-x C-h C-h C-g'. */
14279 goto finish_menu_bars
;
14281 /* We've already displayed the echo area glyphs in this window. */
14282 goto finish_scroll_bars
;
14284 else if ((w
!= XWINDOW (minibuf_window
)
14285 || minibuf_level
== 0)
14286 /* When buffer is nonempty, redisplay window normally. */
14287 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
14288 /* Quail displays non-mini buffers in minibuffer window.
14289 In that case, redisplay the window normally. */
14290 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
14292 /* W is a mini-buffer window, but it's not active, so clear
14294 int yb
= window_text_bottom_y (w
);
14295 struct glyph_row
*row
;
14298 for (y
= 0, row
= w
->desired_matrix
->rows
;
14300 y
+= row
->height
, ++row
)
14301 blank_row (w
, row
, y
);
14302 goto finish_scroll_bars
;
14305 clear_glyph_matrix (w
->desired_matrix
);
14308 /* Otherwise set up data on this window; select its buffer and point
14310 /* Really select the buffer, for the sake of buffer-local
14312 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14314 current_matrix_up_to_date_p
14315 = (!NILP (w
->window_end_valid
)
14316 && !current_buffer
->clip_changed
14317 && !current_buffer
->prevent_redisplay_optimizations_p
14318 && XFASTINT (w
->last_modified
) >= MODIFF
14319 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
14321 /* Run the window-bottom-change-functions
14322 if it is possible that the text on the screen has changed
14323 (either due to modification of the text, or any other reason). */
14324 if (!current_matrix_up_to_date_p
14325 && !NILP (Vwindow_text_change_functions
))
14327 safe_run_hooks (Qwindow_text_change_functions
);
14331 beg_unchanged
= BEG_UNCHANGED
;
14332 end_unchanged
= END_UNCHANGED
;
14334 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
14336 specbind (Qinhibit_point_motion_hooks
, Qt
);
14339 = (!NILP (w
->window_end_valid
)
14340 && !current_buffer
->clip_changed
14341 && XFASTINT (w
->last_modified
) >= MODIFF
14342 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
14344 /* When windows_or_buffers_changed is non-zero, we can't rely on
14345 the window end being valid, so set it to nil there. */
14346 if (windows_or_buffers_changed
)
14348 /* If window starts on a continuation line, maybe adjust the
14349 window start in case the window's width changed. */
14350 if (XMARKER (w
->start
)->buffer
== current_buffer
)
14351 compute_window_start_on_continuation_line (w
);
14353 w
->window_end_valid
= Qnil
;
14356 /* Some sanity checks. */
14357 CHECK_WINDOW_END (w
);
14358 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
14360 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
14363 /* If %c is in mode line, update it if needed. */
14364 if (!NILP (w
->column_number_displayed
)
14365 /* This alternative quickly identifies a common case
14366 where no change is needed. */
14367 && !(PT
== XFASTINT (w
->last_point
)
14368 && XFASTINT (w
->last_modified
) >= MODIFF
14369 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
14370 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
14371 update_mode_line
= 1;
14373 /* Count number of windows showing the selected buffer. An indirect
14374 buffer counts as its base buffer. */
14375 if (!just_this_one_p
)
14377 struct buffer
*current_base
, *window_base
;
14378 current_base
= current_buffer
;
14379 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
14380 if (current_base
->base_buffer
)
14381 current_base
= current_base
->base_buffer
;
14382 if (window_base
->base_buffer
)
14383 window_base
= window_base
->base_buffer
;
14384 if (current_base
== window_base
)
14388 /* Point refers normally to the selected window. For any other
14389 window, set up appropriate value. */
14390 if (!EQ (window
, selected_window
))
14392 EMACS_INT new_pt
= XMARKER (w
->pointm
)->charpos
;
14393 EMACS_INT new_pt_byte
= marker_byte_position (w
->pointm
);
14397 new_pt_byte
= BEGV_BYTE
;
14398 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
14400 else if (new_pt
> (ZV
- 1))
14403 new_pt_byte
= ZV_BYTE
;
14404 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
14407 /* We don't use SET_PT so that the point-motion hooks don't run. */
14408 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
14411 /* If any of the character widths specified in the display table
14412 have changed, invalidate the width run cache. It's true that
14413 this may be a bit late to catch such changes, but the rest of
14414 redisplay goes (non-fatally) haywire when the display table is
14415 changed, so why should we worry about doing any better? */
14416 if (current_buffer
->width_run_cache
)
14418 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
14420 if (! disptab_matches_widthtab (disptab
,
14421 XVECTOR (BVAR (current_buffer
, width_table
))))
14423 invalidate_region_cache (current_buffer
,
14424 current_buffer
->width_run_cache
,
14426 recompute_width_table (current_buffer
, disptab
);
14430 /* If window-start is screwed up, choose a new one. */
14431 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
14434 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14436 /* If someone specified a new starting point but did not insist,
14437 check whether it can be used. */
14438 if (!NILP (w
->optional_new_start
)
14439 && CHARPOS (startp
) >= BEGV
14440 && CHARPOS (startp
) <= ZV
)
14442 w
->optional_new_start
= Qnil
;
14443 start_display (&it
, w
, startp
);
14444 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
14445 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14446 if (IT_CHARPOS (it
) == PT
)
14447 w
->force_start
= Qt
;
14448 /* IT may overshoot PT if text at PT is invisible. */
14449 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
14450 w
->force_start
= Qt
;
14455 /* Handle case where place to start displaying has been specified,
14456 unless the specified location is outside the accessible range. */
14457 if (!NILP (w
->force_start
)
14458 || w
->frozen_window_start_p
)
14460 /* We set this later on if we have to adjust point. */
14463 w
->force_start
= Qnil
;
14465 w
->window_end_valid
= Qnil
;
14467 /* Forget any recorded base line for line number display. */
14468 if (!buffer_unchanged_p
)
14469 w
->base_line_number
= Qnil
;
14471 /* Redisplay the mode line. Select the buffer properly for that.
14472 Also, run the hook window-scroll-functions
14473 because we have scrolled. */
14474 /* Note, we do this after clearing force_start because
14475 if there's an error, it is better to forget about force_start
14476 than to get into an infinite loop calling the hook functions
14477 and having them get more errors. */
14478 if (!update_mode_line
14479 || ! NILP (Vwindow_scroll_functions
))
14481 update_mode_line
= 1;
14482 w
->update_mode_line
= Qt
;
14483 startp
= run_window_scroll_functions (window
, startp
);
14486 w
->last_modified
= make_number (0);
14487 w
->last_overlay_modified
= make_number (0);
14488 if (CHARPOS (startp
) < BEGV
)
14489 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14490 else if (CHARPOS (startp
) > ZV
)
14491 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14493 /* Redisplay, then check if cursor has been set during the
14494 redisplay. Give up if new fonts were loaded. */
14495 /* We used to issue a CHECK_MARGINS argument to try_window here,
14496 but this causes scrolling to fail when point begins inside
14497 the scroll margin (bug#148) -- cyd */
14498 if (!try_window (window
, startp
, 0))
14500 w
->force_start
= Qt
;
14501 clear_glyph_matrix (w
->desired_matrix
);
14502 goto need_larger_matrices
;
14505 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14507 /* If point does not appear, try to move point so it does
14508 appear. The desired matrix has been built above, so we
14509 can use it here. */
14510 new_vpos
= window_box_height (w
) / 2;
14513 if (!cursor_row_fully_visible_p (w
, 0, 0))
14515 /* Point does appear, but on a line partly visible at end of window.
14516 Move it back to a fully-visible line. */
14517 new_vpos
= window_box_height (w
);
14520 /* If we need to move point for either of the above reasons,
14521 now actually do it. */
14524 struct glyph_row
*row
;
14526 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14527 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14530 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14531 MATRIX_ROW_START_BYTEPOS (row
));
14533 if (w
!= XWINDOW (selected_window
))
14534 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14535 else if (current_buffer
== old
)
14536 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14538 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14540 /* If we are highlighting the region, then we just changed
14541 the region, so redisplay to show it. */
14542 if (!NILP (Vtransient_mark_mode
)
14543 && !NILP (BVAR (current_buffer
, mark_active
)))
14545 clear_glyph_matrix (w
->desired_matrix
);
14546 if (!try_window (window
, startp
, 0))
14547 goto need_larger_matrices
;
14552 debug_method_add (w
, "forced window start");
14557 /* Handle case where text has not changed, only point, and it has
14558 not moved off the frame, and we are not retrying after hscroll.
14559 (current_matrix_up_to_date_p is nonzero when retrying.) */
14560 if (current_matrix_up_to_date_p
14561 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14562 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14566 case CURSOR_MOVEMENT_SUCCESS
:
14567 used_current_matrix_p
= 1;
14570 case CURSOR_MOVEMENT_MUST_SCROLL
:
14571 goto try_to_scroll
;
14577 /* If current starting point was originally the beginning of a line
14578 but no longer is, find a new starting point. */
14579 else if (!NILP (w
->start_at_line_beg
)
14580 && !(CHARPOS (startp
) <= BEGV
14581 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14584 debug_method_add (w
, "recenter 1");
14589 /* Try scrolling with try_window_id. Value is > 0 if update has
14590 been done, it is -1 if we know that the same window start will
14591 not work. It is 0 if unsuccessful for some other reason. */
14592 else if ((tem
= try_window_id (w
)) != 0)
14595 debug_method_add (w
, "try_window_id %d", tem
);
14598 if (fonts_changed_p
)
14599 goto need_larger_matrices
;
14603 /* Otherwise try_window_id has returned -1 which means that we
14604 don't want the alternative below this comment to execute. */
14606 else if (CHARPOS (startp
) >= BEGV
14607 && CHARPOS (startp
) <= ZV
14608 && PT
>= CHARPOS (startp
)
14609 && (CHARPOS (startp
) < ZV
14610 /* Avoid starting at end of buffer. */
14611 || CHARPOS (startp
) == BEGV
14612 || (XFASTINT (w
->last_modified
) >= MODIFF
14613 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14616 /* If first window line is a continuation line, and window start
14617 is inside the modified region, but the first change is before
14618 current window start, we must select a new window start.
14620 However, if this is the result of a down-mouse event (e.g. by
14621 extending the mouse-drag-overlay), we don't want to select a
14622 new window start, since that would change the position under
14623 the mouse, resulting in an unwanted mouse-movement rather
14624 than a simple mouse-click. */
14625 if (NILP (w
->start_at_line_beg
)
14626 && NILP (do_mouse_tracking
)
14627 && CHARPOS (startp
) > BEGV
14628 && CHARPOS (startp
) > BEG
+ beg_unchanged
14629 && CHARPOS (startp
) <= Z
- end_unchanged
14630 /* Even if w->start_at_line_beg is nil, a new window may
14631 start at a line_beg, since that's how set_buffer_window
14632 sets it. So, we need to check the return value of
14633 compute_window_start_on_continuation_line. (See also
14635 && XMARKER (w
->start
)->buffer
== current_buffer
14636 && compute_window_start_on_continuation_line (w
))
14638 w
->force_start
= Qt
;
14639 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14644 debug_method_add (w
, "same window start");
14647 /* Try to redisplay starting at same place as before.
14648 If point has not moved off frame, accept the results. */
14649 if (!current_matrix_up_to_date_p
14650 /* Don't use try_window_reusing_current_matrix in this case
14651 because a window scroll function can have changed the
14653 || !NILP (Vwindow_scroll_functions
)
14654 || MINI_WINDOW_P (w
)
14655 || !(used_current_matrix_p
14656 = try_window_reusing_current_matrix (w
)))
14658 IF_DEBUG (debug_method_add (w
, "1"));
14659 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
14660 /* -1 means we need to scroll.
14661 0 means we need new matrices, but fonts_changed_p
14662 is set in that case, so we will detect it below. */
14663 goto try_to_scroll
;
14666 if (fonts_changed_p
)
14667 goto need_larger_matrices
;
14669 if (w
->cursor
.vpos
>= 0)
14671 if (!just_this_one_p
14672 || current_buffer
->clip_changed
14673 || BEG_UNCHANGED
< CHARPOS (startp
))
14674 /* Forget any recorded base line for line number display. */
14675 w
->base_line_number
= Qnil
;
14677 if (!cursor_row_fully_visible_p (w
, 1, 0))
14679 clear_glyph_matrix (w
->desired_matrix
);
14680 last_line_misfit
= 1;
14682 /* Drop through and scroll. */
14687 clear_glyph_matrix (w
->desired_matrix
);
14692 w
->last_modified
= make_number (0);
14693 w
->last_overlay_modified
= make_number (0);
14695 /* Redisplay the mode line. Select the buffer properly for that. */
14696 if (!update_mode_line
)
14698 update_mode_line
= 1;
14699 w
->update_mode_line
= Qt
;
14702 /* Try to scroll by specified few lines. */
14703 if ((scroll_conservatively
14704 || emacs_scroll_step
14705 || temp_scroll_step
14706 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
14707 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
14708 && CHARPOS (startp
) >= BEGV
14709 && CHARPOS (startp
) <= ZV
)
14711 /* The function returns -1 if new fonts were loaded, 1 if
14712 successful, 0 if not successful. */
14713 int ss
= try_scrolling (window
, just_this_one_p
,
14714 scroll_conservatively
,
14716 temp_scroll_step
, last_line_misfit
);
14719 case SCROLLING_SUCCESS
:
14722 case SCROLLING_NEED_LARGER_MATRICES
:
14723 goto need_larger_matrices
;
14725 case SCROLLING_FAILED
:
14733 /* Finally, just choose a place to start which positions point
14734 according to user preferences. */
14739 debug_method_add (w
, "recenter");
14742 /* w->vscroll = 0; */
14744 /* Forget any previously recorded base line for line number display. */
14745 if (!buffer_unchanged_p
)
14746 w
->base_line_number
= Qnil
;
14748 /* Determine the window start relative to point. */
14749 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14750 it
.current_y
= it
.last_visible_y
;
14751 if (centering_position
< 0)
14755 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14757 EMACS_INT margin_pos
= CHARPOS (startp
);
14759 Lisp_Object aggressive
;
14761 /* If there is a scroll margin at the top of the window, find
14762 its character position. */
14764 /* Cannot call start_display if startp is not in the
14765 accessible region of the buffer. This can happen when we
14766 have just switched to a different buffer and/or changed
14767 its restriction. In that case, startp is initialized to
14768 the character position 1 (BEG) because we did not yet
14769 have chance to display the buffer even once. */
14770 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
14774 start_display (&it1
, w
, startp
);
14775 move_it_vertically (&it1
, margin
);
14776 margin_pos
= IT_CHARPOS (it1
);
14778 scrolling_up
= PT
> margin_pos
;
14781 ? BVAR (current_buffer
, scroll_up_aggressively
)
14782 : BVAR (current_buffer
, scroll_down_aggressively
);
14784 if (!MINI_WINDOW_P (w
)
14785 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
14789 /* Setting scroll-conservatively overrides
14790 scroll-*-aggressively. */
14791 if (!scroll_conservatively
&& NUMBERP (aggressive
))
14793 double float_amount
= XFLOATINT (aggressive
);
14795 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
14796 if (pt_offset
== 0 && float_amount
> 0)
14801 /* Compute how much to move the window start backward from
14802 point so that point will be displayed where the user
14806 centering_position
= it
.last_visible_y
;
14808 centering_position
-= pt_offset
;
14809 centering_position
-=
14810 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0));
14811 /* Don't let point enter the scroll margin near top of
14813 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
14814 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
14817 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
14820 /* Set the window start half the height of the window backward
14822 centering_position
= window_box_height (w
) / 2;
14824 move_it_vertically_backward (&it
, centering_position
);
14826 xassert (IT_CHARPOS (it
) >= BEGV
);
14828 /* The function move_it_vertically_backward may move over more
14829 than the specified y-distance. If it->w is small, e.g. a
14830 mini-buffer window, we may end up in front of the window's
14831 display area. Start displaying at the start of the line
14832 containing PT in this case. */
14833 if (it
.current_y
<= 0)
14835 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14836 move_it_vertically_backward (&it
, 0);
14840 it
.current_x
= it
.hpos
= 0;
14842 /* Set the window start position here explicitly, to avoid an
14843 infinite loop in case the functions in window-scroll-functions
14845 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14847 /* Run scroll hooks. */
14848 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14850 /* Redisplay the window. */
14851 if (!current_matrix_up_to_date_p
14852 || windows_or_buffers_changed
14853 || cursor_type_changed
14854 /* Don't use try_window_reusing_current_matrix in this case
14855 because it can have changed the buffer. */
14856 || !NILP (Vwindow_scroll_functions
)
14857 || !just_this_one_p
14858 || MINI_WINDOW_P (w
)
14859 || !(used_current_matrix_p
14860 = try_window_reusing_current_matrix (w
)))
14861 try_window (window
, startp
, 0);
14863 /* If new fonts have been loaded (due to fontsets), give up. We
14864 have to start a new redisplay since we need to re-adjust glyph
14866 if (fonts_changed_p
)
14867 goto need_larger_matrices
;
14869 /* If cursor did not appear assume that the middle of the window is
14870 in the first line of the window. Do it again with the next line.
14871 (Imagine a window of height 100, displaying two lines of height
14872 60. Moving back 50 from it->last_visible_y will end in the first
14874 if (w
->cursor
.vpos
< 0)
14876 if (!NILP (w
->window_end_valid
)
14877 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14879 clear_glyph_matrix (w
->desired_matrix
);
14880 move_it_by_lines (&it
, 1);
14881 try_window (window
, it
.current
.pos
, 0);
14883 else if (PT
< IT_CHARPOS (it
))
14885 clear_glyph_matrix (w
->desired_matrix
);
14886 move_it_by_lines (&it
, -1);
14887 try_window (window
, it
.current
.pos
, 0);
14891 /* Not much we can do about it. */
14895 /* Consider the following case: Window starts at BEGV, there is
14896 invisible, intangible text at BEGV, so that display starts at
14897 some point START > BEGV. It can happen that we are called with
14898 PT somewhere between BEGV and START. Try to handle that case. */
14899 if (w
->cursor
.vpos
< 0)
14901 struct glyph_row
*row
= w
->current_matrix
->rows
;
14902 if (row
->mode_line_p
)
14904 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14907 if (!cursor_row_fully_visible_p (w
, 0, 0))
14909 /* If vscroll is enabled, disable it and try again. */
14913 clear_glyph_matrix (w
->desired_matrix
);
14917 /* If centering point failed to make the whole line visible,
14918 put point at the top instead. That has to make the whole line
14919 visible, if it can be done. */
14920 if (centering_position
== 0)
14923 clear_glyph_matrix (w
->desired_matrix
);
14924 centering_position
= 0;
14930 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14931 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14932 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14935 /* Display the mode line, if we must. */
14936 if ((update_mode_line
14937 /* If window not full width, must redo its mode line
14938 if (a) the window to its side is being redone and
14939 (b) we do a frame-based redisplay. This is a consequence
14940 of how inverted lines are drawn in frame-based redisplay. */
14941 || (!just_this_one_p
14942 && !FRAME_WINDOW_P (f
)
14943 && !WINDOW_FULL_WIDTH_P (w
))
14944 /* Line number to display. */
14945 || INTEGERP (w
->base_line_pos
)
14946 /* Column number is displayed and different from the one displayed. */
14947 || (!NILP (w
->column_number_displayed
)
14948 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
14949 /* This means that the window has a mode line. */
14950 && (WINDOW_WANTS_MODELINE_P (w
)
14951 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14953 display_mode_lines (w
);
14955 /* If mode line height has changed, arrange for a thorough
14956 immediate redisplay using the correct mode line height. */
14957 if (WINDOW_WANTS_MODELINE_P (w
)
14958 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14960 fonts_changed_p
= 1;
14961 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14962 = DESIRED_MODE_LINE_HEIGHT (w
);
14965 /* If header line height has changed, arrange for a thorough
14966 immediate redisplay using the correct header line height. */
14967 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14968 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14970 fonts_changed_p
= 1;
14971 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14972 = DESIRED_HEADER_LINE_HEIGHT (w
);
14975 if (fonts_changed_p
)
14976 goto need_larger_matrices
;
14979 if (!line_number_displayed
14980 && !BUFFERP (w
->base_line_pos
))
14982 w
->base_line_pos
= Qnil
;
14983 w
->base_line_number
= Qnil
;
14988 /* When we reach a frame's selected window, redo the frame's menu bar. */
14989 if (update_mode_line
14990 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14992 int redisplay_menu_p
= 0;
14994 if (FRAME_WINDOW_P (f
))
14996 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14997 || defined (HAVE_NS) || defined (USE_GTK)
14998 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
15000 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15004 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15006 if (redisplay_menu_p
)
15007 display_menu_bar (w
);
15009 #ifdef HAVE_WINDOW_SYSTEM
15010 if (FRAME_WINDOW_P (f
))
15012 #if defined (USE_GTK) || defined (HAVE_NS)
15013 if (FRAME_EXTERNAL_TOOL_BAR (f
))
15014 redisplay_tool_bar (f
);
15016 if (WINDOWP (f
->tool_bar_window
)
15017 && (FRAME_TOOL_BAR_LINES (f
) > 0
15018 || !NILP (Vauto_resize_tool_bars
))
15019 && redisplay_tool_bar (f
))
15020 ignore_mouse_drag_p
= 1;
15026 #ifdef HAVE_WINDOW_SYSTEM
15027 if (FRAME_WINDOW_P (f
)
15028 && update_window_fringes (w
, (just_this_one_p
15029 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
15030 || w
->pseudo_window_p
)))
15034 if (draw_window_fringes (w
, 1))
15035 x_draw_vertical_border (w
);
15039 #endif /* HAVE_WINDOW_SYSTEM */
15041 /* We go to this label, with fonts_changed_p nonzero,
15042 if it is necessary to try again using larger glyph matrices.
15043 We have to redeem the scroll bar even in this case,
15044 because the loop in redisplay_internal expects that. */
15045 need_larger_matrices
:
15047 finish_scroll_bars
:
15049 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
15051 /* Set the thumb's position and size. */
15052 set_vertical_scroll_bar (w
);
15054 /* Note that we actually used the scroll bar attached to this
15055 window, so it shouldn't be deleted at the end of redisplay. */
15056 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
15057 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
15060 /* Restore current_buffer and value of point in it. The window
15061 update may have changed the buffer, so first make sure `opoint'
15062 is still valid (Bug#6177). */
15063 if (CHARPOS (opoint
) < BEGV
)
15064 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15065 else if (CHARPOS (opoint
) > ZV
)
15066 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
15068 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
15070 set_buffer_internal_1 (old
);
15071 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
15072 shorter. This can be caused by log truncation in *Messages*. */
15073 if (CHARPOS (lpoint
) <= ZV
)
15074 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15076 unbind_to (count
, Qnil
);
15080 /* Build the complete desired matrix of WINDOW with a window start
15081 buffer position POS.
15083 Value is 1 if successful. It is zero if fonts were loaded during
15084 redisplay which makes re-adjusting glyph matrices necessary, and -1
15085 if point would appear in the scroll margins.
15086 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
15087 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
15091 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
15093 struct window
*w
= XWINDOW (window
);
15095 struct glyph_row
*last_text_row
= NULL
;
15096 struct frame
*f
= XFRAME (w
->frame
);
15098 /* Make POS the new window start. */
15099 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
15101 /* Mark cursor position as unknown. No overlay arrow seen. */
15102 w
->cursor
.vpos
= -1;
15103 overlay_arrow_seen
= 0;
15105 /* Initialize iterator and info to start at POS. */
15106 start_display (&it
, w
, pos
);
15108 /* Display all lines of W. */
15109 while (it
.current_y
< it
.last_visible_y
)
15111 if (display_line (&it
))
15112 last_text_row
= it
.glyph_row
- 1;
15113 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
15117 /* Don't let the cursor end in the scroll margins. */
15118 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
15119 && !MINI_WINDOW_P (w
))
15121 int this_scroll_margin
;
15123 if (scroll_margin
> 0)
15125 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15126 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15129 this_scroll_margin
= 0;
15131 if ((w
->cursor
.y
>= 0 /* not vscrolled */
15132 && w
->cursor
.y
< this_scroll_margin
15133 && CHARPOS (pos
) > BEGV
15134 && IT_CHARPOS (it
) < ZV
)
15135 /* rms: considering make_cursor_line_fully_visible_p here
15136 seems to give wrong results. We don't want to recenter
15137 when the last line is partly visible, we want to allow
15138 that case to be handled in the usual way. */
15139 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
15141 w
->cursor
.vpos
= -1;
15142 clear_glyph_matrix (w
->desired_matrix
);
15147 /* If bottom moved off end of frame, change mode line percentage. */
15148 if (XFASTINT (w
->window_end_pos
) <= 0
15149 && Z
!= IT_CHARPOS (it
))
15150 w
->update_mode_line
= Qt
;
15152 /* Set window_end_pos to the offset of the last character displayed
15153 on the window from the end of current_buffer. Set
15154 window_end_vpos to its row number. */
15157 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
15158 w
->window_end_bytepos
15159 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15161 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15163 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15164 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
15165 ->displays_text_p
);
15169 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
15170 w
->window_end_pos
= make_number (Z
- ZV
);
15171 w
->window_end_vpos
= make_number (0);
15174 /* But that is not valid info until redisplay finishes. */
15175 w
->window_end_valid
= Qnil
;
15181 /************************************************************************
15182 Window redisplay reusing current matrix when buffer has not changed
15183 ************************************************************************/
15185 /* Try redisplay of window W showing an unchanged buffer with a
15186 different window start than the last time it was displayed by
15187 reusing its current matrix. Value is non-zero if successful.
15188 W->start is the new window start. */
15191 try_window_reusing_current_matrix (struct window
*w
)
15193 struct frame
*f
= XFRAME (w
->frame
);
15194 struct glyph_row
*bottom_row
;
15197 struct text_pos start
, new_start
;
15198 int nrows_scrolled
, i
;
15199 struct glyph_row
*last_text_row
;
15200 struct glyph_row
*last_reused_text_row
;
15201 struct glyph_row
*start_row
;
15202 int start_vpos
, min_y
, max_y
;
15205 if (inhibit_try_window_reusing
)
15209 if (/* This function doesn't handle terminal frames. */
15210 !FRAME_WINDOW_P (f
)
15211 /* Don't try to reuse the display if windows have been split
15213 || windows_or_buffers_changed
15214 || cursor_type_changed
)
15217 /* Can't do this if region may have changed. */
15218 if ((!NILP (Vtransient_mark_mode
)
15219 && !NILP (BVAR (current_buffer
, mark_active
)))
15220 || !NILP (w
->region_showing
)
15221 || !NILP (Vshow_trailing_whitespace
))
15224 /* If top-line visibility has changed, give up. */
15225 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15226 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
15229 /* Give up if old or new display is scrolled vertically. We could
15230 make this function handle this, but right now it doesn't. */
15231 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15232 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
15235 /* The variable new_start now holds the new window start. The old
15236 start `start' can be determined from the current matrix. */
15237 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
15238 start
= start_row
->minpos
;
15239 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
15241 /* Clear the desired matrix for the display below. */
15242 clear_glyph_matrix (w
->desired_matrix
);
15244 if (CHARPOS (new_start
) <= CHARPOS (start
))
15246 /* Don't use this method if the display starts with an ellipsis
15247 displayed for invisible text. It's not easy to handle that case
15248 below, and it's certainly not worth the effort since this is
15249 not a frequent case. */
15250 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
15253 IF_DEBUG (debug_method_add (w
, "twu1"));
15255 /* Display up to a row that can be reused. The variable
15256 last_text_row is set to the last row displayed that displays
15257 text. Note that it.vpos == 0 if or if not there is a
15258 header-line; it's not the same as the MATRIX_ROW_VPOS! */
15259 start_display (&it
, w
, new_start
);
15260 w
->cursor
.vpos
= -1;
15261 last_text_row
= last_reused_text_row
= NULL
;
15263 while (it
.current_y
< it
.last_visible_y
15264 && !fonts_changed_p
)
15266 /* If we have reached into the characters in the START row,
15267 that means the line boundaries have changed. So we
15268 can't start copying with the row START. Maybe it will
15269 work to start copying with the following row. */
15270 while (IT_CHARPOS (it
) > CHARPOS (start
))
15272 /* Advance to the next row as the "start". */
15274 start
= start_row
->minpos
;
15275 /* If there are no more rows to try, or just one, give up. */
15276 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
15277 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
15278 || CHARPOS (start
) == ZV
)
15280 clear_glyph_matrix (w
->desired_matrix
);
15284 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
15286 /* If we have reached alignment,
15287 we can copy the rest of the rows. */
15288 if (IT_CHARPOS (it
) == CHARPOS (start
))
15291 if (display_line (&it
))
15292 last_text_row
= it
.glyph_row
- 1;
15295 /* A value of current_y < last_visible_y means that we stopped
15296 at the previous window start, which in turn means that we
15297 have at least one reusable row. */
15298 if (it
.current_y
< it
.last_visible_y
)
15300 struct glyph_row
*row
;
15302 /* IT.vpos always starts from 0; it counts text lines. */
15303 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
15305 /* Find PT if not already found in the lines displayed. */
15306 if (w
->cursor
.vpos
< 0)
15308 int dy
= it
.current_y
- start_row
->y
;
15310 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15311 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
15313 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
15314 dy
, nrows_scrolled
);
15317 clear_glyph_matrix (w
->desired_matrix
);
15322 /* Scroll the display. Do it before the current matrix is
15323 changed. The problem here is that update has not yet
15324 run, i.e. part of the current matrix is not up to date.
15325 scroll_run_hook will clear the cursor, and use the
15326 current matrix to get the height of the row the cursor is
15328 run
.current_y
= start_row
->y
;
15329 run
.desired_y
= it
.current_y
;
15330 run
.height
= it
.last_visible_y
- it
.current_y
;
15332 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
15335 FRAME_RIF (f
)->update_window_begin_hook (w
);
15336 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15337 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15338 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15342 /* Shift current matrix down by nrows_scrolled lines. */
15343 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15344 rotate_matrix (w
->current_matrix
,
15346 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15349 /* Disable lines that must be updated. */
15350 for (i
= 0; i
< nrows_scrolled
; ++i
)
15351 (start_row
+ i
)->enabled_p
= 0;
15353 /* Re-compute Y positions. */
15354 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15355 max_y
= it
.last_visible_y
;
15356 for (row
= start_row
+ nrows_scrolled
;
15360 row
->y
= it
.current_y
;
15361 row
->visible_height
= row
->height
;
15363 if (row
->y
< min_y
)
15364 row
->visible_height
-= min_y
- row
->y
;
15365 if (row
->y
+ row
->height
> max_y
)
15366 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15367 row
->redraw_fringe_bitmaps_p
= 1;
15369 it
.current_y
+= row
->height
;
15371 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15372 last_reused_text_row
= row
;
15373 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
15377 /* Disable lines in the current matrix which are now
15378 below the window. */
15379 for (++row
; row
< bottom_row
; ++row
)
15380 row
->enabled_p
= row
->mode_line_p
= 0;
15383 /* Update window_end_pos etc.; last_reused_text_row is the last
15384 reused row from the current matrix containing text, if any.
15385 The value of last_text_row is the last displayed line
15386 containing text. */
15387 if (last_reused_text_row
)
15389 w
->window_end_bytepos
15390 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
15392 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
15394 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
15395 w
->current_matrix
));
15397 else if (last_text_row
)
15399 w
->window_end_bytepos
15400 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15402 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15404 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15408 /* This window must be completely empty. */
15409 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
15410 w
->window_end_pos
= make_number (Z
- ZV
);
15411 w
->window_end_vpos
= make_number (0);
15413 w
->window_end_valid
= Qnil
;
15415 /* Update hint: don't try scrolling again in update_window. */
15416 w
->desired_matrix
->no_scrolling_p
= 1;
15419 debug_method_add (w
, "try_window_reusing_current_matrix 1");
15423 else if (CHARPOS (new_start
) > CHARPOS (start
))
15425 struct glyph_row
*pt_row
, *row
;
15426 struct glyph_row
*first_reusable_row
;
15427 struct glyph_row
*first_row_to_display
;
15429 int yb
= window_text_bottom_y (w
);
15431 /* Find the row starting at new_start, if there is one. Don't
15432 reuse a partially visible line at the end. */
15433 first_reusable_row
= start_row
;
15434 while (first_reusable_row
->enabled_p
15435 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
15436 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15437 < CHARPOS (new_start
)))
15438 ++first_reusable_row
;
15440 /* Give up if there is no row to reuse. */
15441 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
15442 || !first_reusable_row
->enabled_p
15443 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15444 != CHARPOS (new_start
)))
15447 /* We can reuse fully visible rows beginning with
15448 first_reusable_row to the end of the window. Set
15449 first_row_to_display to the first row that cannot be reused.
15450 Set pt_row to the row containing point, if there is any. */
15452 for (first_row_to_display
= first_reusable_row
;
15453 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
15454 ++first_row_to_display
)
15456 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
15457 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
15458 pt_row
= first_row_to_display
;
15461 /* Start displaying at the start of first_row_to_display. */
15462 xassert (first_row_to_display
->y
< yb
);
15463 init_to_row_start (&it
, w
, first_row_to_display
);
15465 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
15467 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
15469 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
15470 + WINDOW_HEADER_LINE_HEIGHT (w
));
15472 /* Display lines beginning with first_row_to_display in the
15473 desired matrix. Set last_text_row to the last row displayed
15474 that displays text. */
15475 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
15476 if (pt_row
== NULL
)
15477 w
->cursor
.vpos
= -1;
15478 last_text_row
= NULL
;
15479 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
15480 if (display_line (&it
))
15481 last_text_row
= it
.glyph_row
- 1;
15483 /* If point is in a reused row, adjust y and vpos of the cursor
15487 w
->cursor
.vpos
-= nrows_scrolled
;
15488 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
15491 /* Give up if point isn't in a row displayed or reused. (This
15492 also handles the case where w->cursor.vpos < nrows_scrolled
15493 after the calls to display_line, which can happen with scroll
15494 margins. See bug#1295.) */
15495 if (w
->cursor
.vpos
< 0)
15497 clear_glyph_matrix (w
->desired_matrix
);
15501 /* Scroll the display. */
15502 run
.current_y
= first_reusable_row
->y
;
15503 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15504 run
.height
= it
.last_visible_y
- run
.current_y
;
15505 dy
= run
.current_y
- run
.desired_y
;
15510 FRAME_RIF (f
)->update_window_begin_hook (w
);
15511 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15512 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15513 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15517 /* Adjust Y positions of reused rows. */
15518 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15519 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15520 max_y
= it
.last_visible_y
;
15521 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15524 row
->visible_height
= row
->height
;
15525 if (row
->y
< min_y
)
15526 row
->visible_height
-= min_y
- row
->y
;
15527 if (row
->y
+ row
->height
> max_y
)
15528 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15529 row
->redraw_fringe_bitmaps_p
= 1;
15532 /* Scroll the current matrix. */
15533 xassert (nrows_scrolled
> 0);
15534 rotate_matrix (w
->current_matrix
,
15536 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15539 /* Disable rows not reused. */
15540 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15541 row
->enabled_p
= 0;
15543 /* Point may have moved to a different line, so we cannot assume that
15544 the previous cursor position is valid; locate the correct row. */
15547 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15548 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15552 w
->cursor
.y
= row
->y
;
15554 if (row
< bottom_row
)
15556 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15557 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15559 /* Can't use this optimization with bidi-reordered glyph
15560 rows, unless cursor is already at point. */
15561 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15563 if (!(w
->cursor
.hpos
>= 0
15564 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
15565 && BUFFERP (glyph
->object
)
15566 && glyph
->charpos
== PT
))
15571 && (!BUFFERP (glyph
->object
)
15572 || glyph
->charpos
< PT
);
15576 w
->cursor
.x
+= glyph
->pixel_width
;
15581 /* Adjust window end. A null value of last_text_row means that
15582 the window end is in reused rows which in turn means that
15583 only its vpos can have changed. */
15586 w
->window_end_bytepos
15587 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15589 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15591 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15596 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15599 w
->window_end_valid
= Qnil
;
15600 w
->desired_matrix
->no_scrolling_p
= 1;
15603 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15613 /************************************************************************
15614 Window redisplay reusing current matrix when buffer has changed
15615 ************************************************************************/
15617 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
15618 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
15619 EMACS_INT
*, EMACS_INT
*);
15620 static struct glyph_row
*
15621 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
15622 struct glyph_row
*);
15625 /* Return the last row in MATRIX displaying text. If row START is
15626 non-null, start searching with that row. IT gives the dimensions
15627 of the display. Value is null if matrix is empty; otherwise it is
15628 a pointer to the row found. */
15630 static struct glyph_row
*
15631 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
15632 struct glyph_row
*start
)
15634 struct glyph_row
*row
, *row_found
;
15636 /* Set row_found to the last row in IT->w's current matrix
15637 displaying text. The loop looks funny but think of partially
15640 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15641 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15643 xassert (row
->enabled_p
);
15645 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15654 /* Return the last row in the current matrix of W that is not affected
15655 by changes at the start of current_buffer that occurred since W's
15656 current matrix was built. Value is null if no such row exists.
15658 BEG_UNCHANGED us the number of characters unchanged at the start of
15659 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15660 first changed character in current_buffer. Characters at positions <
15661 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15662 when the current matrix was built. */
15664 static struct glyph_row
*
15665 find_last_unchanged_at_beg_row (struct window
*w
)
15667 EMACS_INT first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15668 struct glyph_row
*row
;
15669 struct glyph_row
*row_found
= NULL
;
15670 int yb
= window_text_bottom_y (w
);
15672 /* Find the last row displaying unchanged text. */
15673 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15674 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15675 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15678 if (/* If row ends before first_changed_pos, it is unchanged,
15679 except in some case. */
15680 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15681 /* When row ends in ZV and we write at ZV it is not
15683 && !row
->ends_at_zv_p
15684 /* When first_changed_pos is the end of a continued line,
15685 row is not unchanged because it may be no longer
15687 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15688 && (row
->continued_p
15689 || row
->exact_window_width_line_p
)))
15692 /* Stop if last visible row. */
15693 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15701 /* Find the first glyph row in the current matrix of W that is not
15702 affected by changes at the end of current_buffer since the
15703 time W's current matrix was built.
15705 Return in *DELTA the number of chars by which buffer positions in
15706 unchanged text at the end of current_buffer must be adjusted.
15708 Return in *DELTA_BYTES the corresponding number of bytes.
15710 Value is null if no such row exists, i.e. all rows are affected by
15713 static struct glyph_row
*
15714 find_first_unchanged_at_end_row (struct window
*w
,
15715 EMACS_INT
*delta
, EMACS_INT
*delta_bytes
)
15717 struct glyph_row
*row
;
15718 struct glyph_row
*row_found
= NULL
;
15720 *delta
= *delta_bytes
= 0;
15722 /* Display must not have been paused, otherwise the current matrix
15723 is not up to date. */
15724 eassert (!NILP (w
->window_end_valid
));
15726 /* A value of window_end_pos >= END_UNCHANGED means that the window
15727 end is in the range of changed text. If so, there is no
15728 unchanged row at the end of W's current matrix. */
15729 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15732 /* Set row to the last row in W's current matrix displaying text. */
15733 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15735 /* If matrix is entirely empty, no unchanged row exists. */
15736 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15738 /* The value of row is the last glyph row in the matrix having a
15739 meaningful buffer position in it. The end position of row
15740 corresponds to window_end_pos. This allows us to translate
15741 buffer positions in the current matrix to current buffer
15742 positions for characters not in changed text. */
15744 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15745 EMACS_INT Z_BYTE_old
=
15746 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15747 EMACS_INT last_unchanged_pos
, last_unchanged_pos_old
;
15748 struct glyph_row
*first_text_row
15749 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15751 *delta
= Z
- Z_old
;
15752 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15754 /* Set last_unchanged_pos to the buffer position of the last
15755 character in the buffer that has not been changed. Z is the
15756 index + 1 of the last character in current_buffer, i.e. by
15757 subtracting END_UNCHANGED we get the index of the last
15758 unchanged character, and we have to add BEG to get its buffer
15760 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15761 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15763 /* Search backward from ROW for a row displaying a line that
15764 starts at a minimum position >= last_unchanged_pos_old. */
15765 for (; row
> first_text_row
; --row
)
15767 /* This used to abort, but it can happen.
15768 It is ok to just stop the search instead here. KFS. */
15769 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15772 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15777 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15783 /* Make sure that glyph rows in the current matrix of window W
15784 reference the same glyph memory as corresponding rows in the
15785 frame's frame matrix. This function is called after scrolling W's
15786 current matrix on a terminal frame in try_window_id and
15787 try_window_reusing_current_matrix. */
15790 sync_frame_with_window_matrix_rows (struct window
*w
)
15792 struct frame
*f
= XFRAME (w
->frame
);
15793 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15795 /* Preconditions: W must be a leaf window and full-width. Its frame
15796 must have a frame matrix. */
15797 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15798 xassert (WINDOW_FULL_WIDTH_P (w
));
15799 xassert (!FRAME_WINDOW_P (f
));
15801 /* If W is a full-width window, glyph pointers in W's current matrix
15802 have, by definition, to be the same as glyph pointers in the
15803 corresponding frame matrix. Note that frame matrices have no
15804 marginal areas (see build_frame_matrix). */
15805 window_row
= w
->current_matrix
->rows
;
15806 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15807 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15808 while (window_row
< window_row_end
)
15810 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15811 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15813 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15814 frame_row
->glyphs
[TEXT_AREA
] = start
;
15815 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15816 frame_row
->glyphs
[LAST_AREA
] = end
;
15818 /* Disable frame rows whose corresponding window rows have
15819 been disabled in try_window_id. */
15820 if (!window_row
->enabled_p
)
15821 frame_row
->enabled_p
= 0;
15823 ++window_row
, ++frame_row
;
15828 /* Find the glyph row in window W containing CHARPOS. Consider all
15829 rows between START and END (not inclusive). END null means search
15830 all rows to the end of the display area of W. Value is the row
15831 containing CHARPOS or null. */
15834 row_containing_pos (struct window
*w
, EMACS_INT charpos
,
15835 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
15837 struct glyph_row
*row
= start
;
15838 struct glyph_row
*best_row
= NULL
;
15839 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15842 /* If we happen to start on a header-line, skip that. */
15843 if (row
->mode_line_p
)
15846 if ((end
&& row
>= end
) || !row
->enabled_p
)
15849 last_y
= window_text_bottom_y (w
) - dy
;
15853 /* Give up if we have gone too far. */
15854 if (end
&& row
>= end
)
15856 /* This formerly returned if they were equal.
15857 I think that both quantities are of a "last plus one" type;
15858 if so, when they are equal, the row is within the screen. -- rms. */
15859 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15862 /* If it is in this row, return this row. */
15863 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15864 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15865 /* The end position of a row equals the start
15866 position of the next row. If CHARPOS is there, we
15867 would rather display it in the next line, except
15868 when this line ends in ZV. */
15869 && !row
->ends_at_zv_p
15870 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15871 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15875 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
15876 || (!best_row
&& !row
->continued_p
))
15878 /* In bidi-reordered rows, there could be several rows
15879 occluding point, all of them belonging to the same
15880 continued line. We need to find the row which fits
15881 CHARPOS the best. */
15882 for (g
= row
->glyphs
[TEXT_AREA
];
15883 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15886 if (!STRINGP (g
->object
))
15888 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
15890 mindif
= eabs (g
->charpos
- charpos
);
15892 /* Exact match always wins. */
15899 else if (best_row
&& !row
->continued_p
)
15906 /* Try to redisplay window W by reusing its existing display. W's
15907 current matrix must be up to date when this function is called,
15908 i.e. window_end_valid must not be nil.
15912 1 if display has been updated
15913 0 if otherwise unsuccessful
15914 -1 if redisplay with same window start is known not to succeed
15916 The following steps are performed:
15918 1. Find the last row in the current matrix of W that is not
15919 affected by changes at the start of current_buffer. If no such row
15922 2. Find the first row in W's current matrix that is not affected by
15923 changes at the end of current_buffer. Maybe there is no such row.
15925 3. Display lines beginning with the row + 1 found in step 1 to the
15926 row found in step 2 or, if step 2 didn't find a row, to the end of
15929 4. If cursor is not known to appear on the window, give up.
15931 5. If display stopped at the row found in step 2, scroll the
15932 display and current matrix as needed.
15934 6. Maybe display some lines at the end of W, if we must. This can
15935 happen under various circumstances, like a partially visible line
15936 becoming fully visible, or because newly displayed lines are displayed
15937 in smaller font sizes.
15939 7. Update W's window end information. */
15942 try_window_id (struct window
*w
)
15944 struct frame
*f
= XFRAME (w
->frame
);
15945 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15946 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15947 struct glyph_row
*last_unchanged_at_beg_row
;
15948 struct glyph_row
*first_unchanged_at_end_row
;
15949 struct glyph_row
*row
;
15950 struct glyph_row
*bottom_row
;
15953 EMACS_INT delta
= 0, delta_bytes
= 0, stop_pos
;
15955 struct text_pos start_pos
;
15957 int first_unchanged_at_end_vpos
= 0;
15958 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15959 struct text_pos start
;
15960 EMACS_INT first_changed_charpos
, last_changed_charpos
;
15963 if (inhibit_try_window_id
)
15967 /* This is handy for debugging. */
15969 #define GIVE_UP(X) \
15971 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15975 #define GIVE_UP(X) return 0
15978 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15980 /* Don't use this for mini-windows because these can show
15981 messages and mini-buffers, and we don't handle that here. */
15982 if (MINI_WINDOW_P (w
))
15985 /* This flag is used to prevent redisplay optimizations. */
15986 if (windows_or_buffers_changed
|| cursor_type_changed
)
15989 /* Verify that narrowing has not changed.
15990 Also verify that we were not told to prevent redisplay optimizations.
15991 It would be nice to further
15992 reduce the number of cases where this prevents try_window_id. */
15993 if (current_buffer
->clip_changed
15994 || current_buffer
->prevent_redisplay_optimizations_p
)
15997 /* Window must either use window-based redisplay or be full width. */
15998 if (!FRAME_WINDOW_P (f
)
15999 && (!FRAME_LINE_INS_DEL_OK (f
)
16000 || !WINDOW_FULL_WIDTH_P (w
)))
16003 /* Give up if point is known NOT to appear in W. */
16004 if (PT
< CHARPOS (start
))
16007 /* Another way to prevent redisplay optimizations. */
16008 if (XFASTINT (w
->last_modified
) == 0)
16011 /* Verify that window is not hscrolled. */
16012 if (XFASTINT (w
->hscroll
) != 0)
16015 /* Verify that display wasn't paused. */
16016 if (NILP (w
->window_end_valid
))
16019 /* Can't use this if highlighting a region because a cursor movement
16020 will do more than just set the cursor. */
16021 if (!NILP (Vtransient_mark_mode
)
16022 && !NILP (BVAR (current_buffer
, mark_active
)))
16025 /* Likewise if highlighting trailing whitespace. */
16026 if (!NILP (Vshow_trailing_whitespace
))
16029 /* Likewise if showing a region. */
16030 if (!NILP (w
->region_showing
))
16033 /* Can't use this if overlay arrow position and/or string have
16035 if (overlay_arrows_changed_p ())
16038 /* When word-wrap is on, adding a space to the first word of a
16039 wrapped line can change the wrap position, altering the line
16040 above it. It might be worthwhile to handle this more
16041 intelligently, but for now just redisplay from scratch. */
16042 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
16045 /* Under bidi reordering, adding or deleting a character in the
16046 beginning of a paragraph, before the first strong directional
16047 character, can change the base direction of the paragraph (unless
16048 the buffer specifies a fixed paragraph direction), which will
16049 require to redisplay the whole paragraph. It might be worthwhile
16050 to find the paragraph limits and widen the range of redisplayed
16051 lines to that, but for now just give up this optimization and
16052 redisplay from scratch. */
16053 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16054 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
16057 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
16058 only if buffer has really changed. The reason is that the gap is
16059 initially at Z for freshly visited files. The code below would
16060 set end_unchanged to 0 in that case. */
16061 if (MODIFF
> SAVE_MODIFF
16062 /* This seems to happen sometimes after saving a buffer. */
16063 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
16065 if (GPT
- BEG
< BEG_UNCHANGED
)
16066 BEG_UNCHANGED
= GPT
- BEG
;
16067 if (Z
- GPT
< END_UNCHANGED
)
16068 END_UNCHANGED
= Z
- GPT
;
16071 /* The position of the first and last character that has been changed. */
16072 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
16073 last_changed_charpos
= Z
- END_UNCHANGED
;
16075 /* If window starts after a line end, and the last change is in
16076 front of that newline, then changes don't affect the display.
16077 This case happens with stealth-fontification. Note that although
16078 the display is unchanged, glyph positions in the matrix have to
16079 be adjusted, of course. */
16080 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16081 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16082 && ((last_changed_charpos
< CHARPOS (start
)
16083 && CHARPOS (start
) == BEGV
)
16084 || (last_changed_charpos
< CHARPOS (start
) - 1
16085 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
16087 EMACS_INT Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
16088 struct glyph_row
*r0
;
16090 /* Compute how many chars/bytes have been added to or removed
16091 from the buffer. */
16092 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16093 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16094 Z_delta
= Z
- Z_old
;
16095 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16097 /* Give up if PT is not in the window. Note that it already has
16098 been checked at the start of try_window_id that PT is not in
16099 front of the window start. */
16100 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
16103 /* If window start is unchanged, we can reuse the whole matrix
16104 as is, after adjusting glyph positions. No need to compute
16105 the window end again, since its offset from Z hasn't changed. */
16106 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16107 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
16108 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
16109 /* PT must not be in a partially visible line. */
16110 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
16111 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
16113 /* Adjust positions in the glyph matrix. */
16114 if (Z_delta
|| Z_delta_bytes
)
16116 struct glyph_row
*r1
16117 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16118 increment_matrix_positions (w
->current_matrix
,
16119 MATRIX_ROW_VPOS (r0
, current_matrix
),
16120 MATRIX_ROW_VPOS (r1
, current_matrix
),
16121 Z_delta
, Z_delta_bytes
);
16124 /* Set the cursor. */
16125 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
16127 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
16134 /* Handle the case that changes are all below what is displayed in
16135 the window, and that PT is in the window. This shortcut cannot
16136 be taken if ZV is visible in the window, and text has been added
16137 there that is visible in the window. */
16138 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
16139 /* ZV is not visible in the window, or there are no
16140 changes at ZV, actually. */
16141 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
16142 || first_changed_charpos
== last_changed_charpos
))
16144 struct glyph_row
*r0
;
16146 /* Give up if PT is not in the window. Note that it already has
16147 been checked at the start of try_window_id that PT is not in
16148 front of the window start. */
16149 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
16152 /* If window start is unchanged, we can reuse the whole matrix
16153 as is, without changing glyph positions since no text has
16154 been added/removed in front of the window end. */
16155 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16156 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
16157 /* PT must not be in a partially visible line. */
16158 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
16159 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
16161 /* We have to compute the window end anew since text
16162 could have been added/removed after it. */
16164 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16165 w
->window_end_bytepos
16166 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16168 /* Set the cursor. */
16169 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
16171 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
16178 /* Give up if window start is in the changed area.
16180 The condition used to read
16182 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
16184 but why that was tested escapes me at the moment. */
16185 if (CHARPOS (start
) >= first_changed_charpos
16186 && CHARPOS (start
) <= last_changed_charpos
)
16189 /* Check that window start agrees with the start of the first glyph
16190 row in its current matrix. Check this after we know the window
16191 start is not in changed text, otherwise positions would not be
16193 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16194 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
16197 /* Give up if the window ends in strings. Overlay strings
16198 at the end are difficult to handle, so don't try. */
16199 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
16200 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
16203 /* Compute the position at which we have to start displaying new
16204 lines. Some of the lines at the top of the window might be
16205 reusable because they are not displaying changed text. Find the
16206 last row in W's current matrix not affected by changes at the
16207 start of current_buffer. Value is null if changes start in the
16208 first line of window. */
16209 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
16210 if (last_unchanged_at_beg_row
)
16212 /* Avoid starting to display in the moddle of a character, a TAB
16213 for instance. This is easier than to set up the iterator
16214 exactly, and it's not a frequent case, so the additional
16215 effort wouldn't really pay off. */
16216 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
16217 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
16218 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
16219 --last_unchanged_at_beg_row
;
16221 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
16224 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
16226 start_pos
= it
.current
.pos
;
16228 /* Start displaying new lines in the desired matrix at the same
16229 vpos we would use in the current matrix, i.e. below
16230 last_unchanged_at_beg_row. */
16231 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
16233 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16234 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
16236 xassert (it
.hpos
== 0 && it
.current_x
== 0);
16240 /* There are no reusable lines at the start of the window.
16241 Start displaying in the first text line. */
16242 start_display (&it
, w
, start
);
16243 it
.vpos
= it
.first_vpos
;
16244 start_pos
= it
.current
.pos
;
16247 /* Find the first row that is not affected by changes at the end of
16248 the buffer. Value will be null if there is no unchanged row, in
16249 which case we must redisplay to the end of the window. delta
16250 will be set to the value by which buffer positions beginning with
16251 first_unchanged_at_end_row have to be adjusted due to text
16253 first_unchanged_at_end_row
16254 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
16255 IF_DEBUG (debug_delta
= delta
);
16256 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
16258 /* Set stop_pos to the buffer position up to which we will have to
16259 display new lines. If first_unchanged_at_end_row != NULL, this
16260 is the buffer position of the start of the line displayed in that
16261 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
16262 that we don't stop at a buffer position. */
16264 if (first_unchanged_at_end_row
)
16266 xassert (last_unchanged_at_beg_row
== NULL
16267 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
16269 /* If this is a continuation line, move forward to the next one
16270 that isn't. Changes in lines above affect this line.
16271 Caution: this may move first_unchanged_at_end_row to a row
16272 not displaying text. */
16273 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
16274 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
16275 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
16276 < it
.last_visible_y
))
16277 ++first_unchanged_at_end_row
;
16279 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
16280 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
16281 >= it
.last_visible_y
))
16282 first_unchanged_at_end_row
= NULL
;
16285 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
16287 first_unchanged_at_end_vpos
16288 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
16289 xassert (stop_pos
>= Z
- END_UNCHANGED
);
16292 else if (last_unchanged_at_beg_row
== NULL
)
16298 /* Either there is no unchanged row at the end, or the one we have
16299 now displays text. This is a necessary condition for the window
16300 end pos calculation at the end of this function. */
16301 xassert (first_unchanged_at_end_row
== NULL
16302 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
16304 debug_last_unchanged_at_beg_vpos
16305 = (last_unchanged_at_beg_row
16306 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
16308 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
16310 #endif /* GLYPH_DEBUG != 0 */
16313 /* Display new lines. Set last_text_row to the last new line
16314 displayed which has text on it, i.e. might end up as being the
16315 line where the window_end_vpos is. */
16316 w
->cursor
.vpos
= -1;
16317 last_text_row
= NULL
;
16318 overlay_arrow_seen
= 0;
16319 while (it
.current_y
< it
.last_visible_y
16320 && !fonts_changed_p
16321 && (first_unchanged_at_end_row
== NULL
16322 || IT_CHARPOS (it
) < stop_pos
))
16324 if (display_line (&it
))
16325 last_text_row
= it
.glyph_row
- 1;
16328 if (fonts_changed_p
)
16332 /* Compute differences in buffer positions, y-positions etc. for
16333 lines reused at the bottom of the window. Compute what we can
16335 if (first_unchanged_at_end_row
16336 /* No lines reused because we displayed everything up to the
16337 bottom of the window. */
16338 && it
.current_y
< it
.last_visible_y
)
16341 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
16343 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
16344 run
.current_y
= first_unchanged_at_end_row
->y
;
16345 run
.desired_y
= run
.current_y
+ dy
;
16346 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
16350 delta
= delta_bytes
= dvpos
= dy
16351 = run
.current_y
= run
.desired_y
= run
.height
= 0;
16352 first_unchanged_at_end_row
= NULL
;
16354 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
16357 /* Find the cursor if not already found. We have to decide whether
16358 PT will appear on this window (it sometimes doesn't, but this is
16359 not a very frequent case.) This decision has to be made before
16360 the current matrix is altered. A value of cursor.vpos < 0 means
16361 that PT is either in one of the lines beginning at
16362 first_unchanged_at_end_row or below the window. Don't care for
16363 lines that might be displayed later at the window end; as
16364 mentioned, this is not a frequent case. */
16365 if (w
->cursor
.vpos
< 0)
16367 /* Cursor in unchanged rows at the top? */
16368 if (PT
< CHARPOS (start_pos
)
16369 && last_unchanged_at_beg_row
)
16371 row
= row_containing_pos (w
, PT
,
16372 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
16373 last_unchanged_at_beg_row
+ 1, 0);
16375 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16378 /* Start from first_unchanged_at_end_row looking for PT. */
16379 else if (first_unchanged_at_end_row
)
16381 row
= row_containing_pos (w
, PT
- delta
,
16382 first_unchanged_at_end_row
, NULL
, 0);
16384 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
16385 delta_bytes
, dy
, dvpos
);
16388 /* Give up if cursor was not found. */
16389 if (w
->cursor
.vpos
< 0)
16391 clear_glyph_matrix (w
->desired_matrix
);
16396 /* Don't let the cursor end in the scroll margins. */
16398 int this_scroll_margin
, cursor_height
;
16400 this_scroll_margin
= max (0, scroll_margin
);
16401 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16402 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
16403 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
16405 if ((w
->cursor
.y
< this_scroll_margin
16406 && CHARPOS (start
) > BEGV
)
16407 /* Old redisplay didn't take scroll margin into account at the bottom,
16408 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
16409 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
16410 ? cursor_height
+ this_scroll_margin
16411 : 1)) > it
.last_visible_y
)
16413 w
->cursor
.vpos
= -1;
16414 clear_glyph_matrix (w
->desired_matrix
);
16419 /* Scroll the display. Do it before changing the current matrix so
16420 that xterm.c doesn't get confused about where the cursor glyph is
16422 if (dy
&& run
.height
)
16426 if (FRAME_WINDOW_P (f
))
16428 FRAME_RIF (f
)->update_window_begin_hook (w
);
16429 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16430 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16431 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16435 /* Terminal frame. In this case, dvpos gives the number of
16436 lines to scroll by; dvpos < 0 means scroll up. */
16438 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
16439 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
16440 int end
= (WINDOW_TOP_EDGE_LINE (w
)
16441 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
16442 + window_internal_height (w
));
16444 #if defined (HAVE_GPM) || defined (MSDOS)
16445 x_clear_window_mouse_face (w
);
16447 /* Perform the operation on the screen. */
16450 /* Scroll last_unchanged_at_beg_row to the end of the
16451 window down dvpos lines. */
16452 set_terminal_window (f
, end
);
16454 /* On dumb terminals delete dvpos lines at the end
16455 before inserting dvpos empty lines. */
16456 if (!FRAME_SCROLL_REGION_OK (f
))
16457 ins_del_lines (f
, end
- dvpos
, -dvpos
);
16459 /* Insert dvpos empty lines in front of
16460 last_unchanged_at_beg_row. */
16461 ins_del_lines (f
, from
, dvpos
);
16463 else if (dvpos
< 0)
16465 /* Scroll up last_unchanged_at_beg_vpos to the end of
16466 the window to last_unchanged_at_beg_vpos - |dvpos|. */
16467 set_terminal_window (f
, end
);
16469 /* Delete dvpos lines in front of
16470 last_unchanged_at_beg_vpos. ins_del_lines will set
16471 the cursor to the given vpos and emit |dvpos| delete
16473 ins_del_lines (f
, from
+ dvpos
, dvpos
);
16475 /* On a dumb terminal insert dvpos empty lines at the
16477 if (!FRAME_SCROLL_REGION_OK (f
))
16478 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
16481 set_terminal_window (f
, 0);
16487 /* Shift reused rows of the current matrix to the right position.
16488 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
16490 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16491 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
16494 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
16495 bottom_vpos
, dvpos
);
16496 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
16499 else if (dvpos
> 0)
16501 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
16502 bottom_vpos
, dvpos
);
16503 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
16504 first_unchanged_at_end_vpos
+ dvpos
, 0);
16507 /* For frame-based redisplay, make sure that current frame and window
16508 matrix are in sync with respect to glyph memory. */
16509 if (!FRAME_WINDOW_P (f
))
16510 sync_frame_with_window_matrix_rows (w
);
16512 /* Adjust buffer positions in reused rows. */
16513 if (delta
|| delta_bytes
)
16514 increment_matrix_positions (current_matrix
,
16515 first_unchanged_at_end_vpos
+ dvpos
,
16516 bottom_vpos
, delta
, delta_bytes
);
16518 /* Adjust Y positions. */
16520 shift_glyph_matrix (w
, current_matrix
,
16521 first_unchanged_at_end_vpos
+ dvpos
,
16524 if (first_unchanged_at_end_row
)
16526 first_unchanged_at_end_row
+= dvpos
;
16527 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16528 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16529 first_unchanged_at_end_row
= NULL
;
16532 /* If scrolling up, there may be some lines to display at the end of
16534 last_text_row_at_end
= NULL
;
16537 /* Scrolling up can leave for example a partially visible line
16538 at the end of the window to be redisplayed. */
16539 /* Set last_row to the glyph row in the current matrix where the
16540 window end line is found. It has been moved up or down in
16541 the matrix by dvpos. */
16542 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16543 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16545 /* If last_row is the window end line, it should display text. */
16546 xassert (last_row
->displays_text_p
);
16548 /* If window end line was partially visible before, begin
16549 displaying at that line. Otherwise begin displaying with the
16550 line following it. */
16551 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16553 init_to_row_start (&it
, w
, last_row
);
16554 it
.vpos
= last_vpos
;
16555 it
.current_y
= last_row
->y
;
16559 init_to_row_end (&it
, w
, last_row
);
16560 it
.vpos
= 1 + last_vpos
;
16561 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16565 /* We may start in a continuation line. If so, we have to
16566 get the right continuation_lines_width and current_x. */
16567 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16568 it
.hpos
= it
.current_x
= 0;
16570 /* Display the rest of the lines at the window end. */
16571 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16572 while (it
.current_y
< it
.last_visible_y
16573 && !fonts_changed_p
)
16575 /* Is it always sure that the display agrees with lines in
16576 the current matrix? I don't think so, so we mark rows
16577 displayed invalid in the current matrix by setting their
16578 enabled_p flag to zero. */
16579 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16580 if (display_line (&it
))
16581 last_text_row_at_end
= it
.glyph_row
- 1;
16585 /* Update window_end_pos and window_end_vpos. */
16586 if (first_unchanged_at_end_row
16587 && !last_text_row_at_end
)
16589 /* Window end line if one of the preserved rows from the current
16590 matrix. Set row to the last row displaying text in current
16591 matrix starting at first_unchanged_at_end_row, after
16593 xassert (first_unchanged_at_end_row
->displays_text_p
);
16594 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16595 first_unchanged_at_end_row
);
16596 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16598 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16599 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16601 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16602 xassert (w
->window_end_bytepos
>= 0);
16603 IF_DEBUG (debug_method_add (w
, "A"));
16605 else if (last_text_row_at_end
)
16608 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16609 w
->window_end_bytepos
16610 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16612 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16613 xassert (w
->window_end_bytepos
>= 0);
16614 IF_DEBUG (debug_method_add (w
, "B"));
16616 else if (last_text_row
)
16618 /* We have displayed either to the end of the window or at the
16619 end of the window, i.e. the last row with text is to be found
16620 in the desired matrix. */
16622 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16623 w
->window_end_bytepos
16624 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16626 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16627 xassert (w
->window_end_bytepos
>= 0);
16629 else if (first_unchanged_at_end_row
== NULL
16630 && last_text_row
== NULL
16631 && last_text_row_at_end
== NULL
)
16633 /* Displayed to end of window, but no line containing text was
16634 displayed. Lines were deleted at the end of the window. */
16635 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16636 int vpos
= XFASTINT (w
->window_end_vpos
);
16637 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16638 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16641 row
== NULL
&& vpos
>= first_vpos
;
16642 --vpos
, --current_row
, --desired_row
)
16644 if (desired_row
->enabled_p
)
16646 if (desired_row
->displays_text_p
)
16649 else if (current_row
->displays_text_p
)
16653 xassert (row
!= NULL
);
16654 w
->window_end_vpos
= make_number (vpos
+ 1);
16655 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16656 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16657 xassert (w
->window_end_bytepos
>= 0);
16658 IF_DEBUG (debug_method_add (w
, "C"));
16663 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16664 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16666 /* Record that display has not been completed. */
16667 w
->window_end_valid
= Qnil
;
16668 w
->desired_matrix
->no_scrolling_p
= 1;
16676 /***********************************************************************
16677 More debugging support
16678 ***********************************************************************/
16682 void dump_glyph_row (struct glyph_row
*, int, int);
16683 void dump_glyph_matrix (struct glyph_matrix
*, int);
16684 void dump_glyph (struct glyph_row
*, struct glyph
*, int);
16687 /* Dump the contents of glyph matrix MATRIX on stderr.
16689 GLYPHS 0 means don't show glyph contents.
16690 GLYPHS 1 means show glyphs in short form
16691 GLYPHS > 1 means show glyphs in long form. */
16694 dump_glyph_matrix (matrix
, glyphs
)
16695 struct glyph_matrix
*matrix
;
16699 for (i
= 0; i
< matrix
->nrows
; ++i
)
16700 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16704 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16705 the glyph row and area where the glyph comes from. */
16708 dump_glyph (row
, glyph
, area
)
16709 struct glyph_row
*row
;
16710 struct glyph
*glyph
;
16713 if (glyph
->type
== CHAR_GLYPH
)
16716 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16717 glyph
- row
->glyphs
[TEXT_AREA
],
16720 (BUFFERP (glyph
->object
)
16722 : (STRINGP (glyph
->object
)
16725 glyph
->pixel_width
,
16727 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16731 glyph
->left_box_line_p
,
16732 glyph
->right_box_line_p
);
16734 else if (glyph
->type
== STRETCH_GLYPH
)
16737 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16738 glyph
- row
->glyphs
[TEXT_AREA
],
16741 (BUFFERP (glyph
->object
)
16743 : (STRINGP (glyph
->object
)
16746 glyph
->pixel_width
,
16750 glyph
->left_box_line_p
,
16751 glyph
->right_box_line_p
);
16753 else if (glyph
->type
== IMAGE_GLYPH
)
16756 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16757 glyph
- row
->glyphs
[TEXT_AREA
],
16760 (BUFFERP (glyph
->object
)
16762 : (STRINGP (glyph
->object
)
16765 glyph
->pixel_width
,
16769 glyph
->left_box_line_p
,
16770 glyph
->right_box_line_p
);
16772 else if (glyph
->type
== COMPOSITE_GLYPH
)
16775 " %5d %4c %6d %c %3d 0x%05x",
16776 glyph
- row
->glyphs
[TEXT_AREA
],
16779 (BUFFERP (glyph
->object
)
16781 : (STRINGP (glyph
->object
)
16784 glyph
->pixel_width
,
16786 if (glyph
->u
.cmp
.automatic
)
16789 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
16790 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16792 glyph
->left_box_line_p
,
16793 glyph
->right_box_line_p
);
16798 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16799 GLYPHS 0 means don't show glyph contents.
16800 GLYPHS 1 means show glyphs in short form
16801 GLYPHS > 1 means show glyphs in long form. */
16804 dump_glyph_row (row
, vpos
, glyphs
)
16805 struct glyph_row
*row
;
16810 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16811 fprintf (stderr
, "======================================================================\n");
16813 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16814 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16816 MATRIX_ROW_START_CHARPOS (row
),
16817 MATRIX_ROW_END_CHARPOS (row
),
16818 row
->used
[TEXT_AREA
],
16819 row
->contains_overlapping_glyphs_p
,
16821 row
->truncated_on_left_p
,
16822 row
->truncated_on_right_p
,
16824 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16825 row
->displays_text_p
,
16828 row
->ends_in_middle_of_char_p
,
16829 row
->starts_in_middle_of_char_p
,
16835 row
->visible_height
,
16838 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16839 row
->end
.overlay_string_index
,
16840 row
->continuation_lines_width
);
16841 fprintf (stderr
, "%9d %5d\n",
16842 CHARPOS (row
->start
.string_pos
),
16843 CHARPOS (row
->end
.string_pos
));
16844 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16845 row
->end
.dpvec_index
);
16852 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16854 struct glyph
*glyph
= row
->glyphs
[area
];
16855 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16857 /* Glyph for a line end in text. */
16858 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16861 if (glyph
< glyph_end
)
16862 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16864 for (; glyph
< glyph_end
; ++glyph
)
16865 dump_glyph (row
, glyph
, area
);
16868 else if (glyphs
== 1)
16872 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16874 char *s
= (char *) alloca (row
->used
[area
] + 1);
16877 for (i
= 0; i
< row
->used
[area
]; ++i
)
16879 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16880 if (glyph
->type
== CHAR_GLYPH
16881 && glyph
->u
.ch
< 0x80
16882 && glyph
->u
.ch
>= ' ')
16883 s
[i
] = glyph
->u
.ch
;
16889 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16895 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16896 Sdump_glyph_matrix
, 0, 1, "p",
16897 doc
: /* Dump the current matrix of the selected window to stderr.
16898 Shows contents of glyph row structures. With non-nil
16899 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16900 glyphs in short form, otherwise show glyphs in long form. */)
16901 (Lisp_Object glyphs
)
16903 struct window
*w
= XWINDOW (selected_window
);
16904 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16906 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
16907 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16908 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16909 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16910 fprintf (stderr
, "=============================================\n");
16911 dump_glyph_matrix (w
->current_matrix
,
16912 NILP (glyphs
) ? 0 : XINT (glyphs
));
16917 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16918 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16921 struct frame
*f
= XFRAME (selected_frame
);
16922 dump_glyph_matrix (f
->current_matrix
, 1);
16927 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16928 doc
: /* Dump glyph row ROW to stderr.
16929 GLYPH 0 means don't dump glyphs.
16930 GLYPH 1 means dump glyphs in short form.
16931 GLYPH > 1 or omitted means dump glyphs in long form. */)
16932 (Lisp_Object row
, Lisp_Object glyphs
)
16934 struct glyph_matrix
*matrix
;
16937 CHECK_NUMBER (row
);
16938 matrix
= XWINDOW (selected_window
)->current_matrix
;
16940 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16941 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16943 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16948 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16949 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16950 GLYPH 0 means don't dump glyphs.
16951 GLYPH 1 means dump glyphs in short form.
16952 GLYPH > 1 or omitted means dump glyphs in long form. */)
16953 (Lisp_Object row
, Lisp_Object glyphs
)
16955 struct frame
*sf
= SELECTED_FRAME ();
16956 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16959 CHECK_NUMBER (row
);
16961 if (vpos
>= 0 && vpos
< m
->nrows
)
16962 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16963 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16968 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16969 doc
: /* Toggle tracing of redisplay.
16970 With ARG, turn tracing on if and only if ARG is positive. */)
16974 trace_redisplay_p
= !trace_redisplay_p
;
16977 arg
= Fprefix_numeric_value (arg
);
16978 trace_redisplay_p
= XINT (arg
) > 0;
16985 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16986 doc
: /* Like `format', but print result to stderr.
16987 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16988 (size_t nargs
, Lisp_Object
*args
)
16990 Lisp_Object s
= Fformat (nargs
, args
);
16991 fprintf (stderr
, "%s", SDATA (s
));
16995 #endif /* GLYPH_DEBUG */
16999 /***********************************************************************
17000 Building Desired Matrix Rows
17001 ***********************************************************************/
17003 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
17004 Used for non-window-redisplay windows, and for windows w/o left fringe. */
17006 static struct glyph_row
*
17007 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
17009 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17010 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17011 struct buffer
*old
= current_buffer
;
17012 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
17013 int arrow_len
= SCHARS (overlay_arrow_string
);
17014 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
17015 const unsigned char *p
;
17018 int n_glyphs_before
;
17020 set_buffer_temp (buffer
);
17021 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
17022 it
.glyph_row
->used
[TEXT_AREA
] = 0;
17023 SET_TEXT_POS (it
.position
, 0, 0);
17025 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
17027 while (p
< arrow_end
)
17029 Lisp_Object face
, ilisp
;
17031 /* Get the next character. */
17033 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
17036 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
17037 if (! ASCII_CHAR_P (it
.c
))
17038 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
17042 /* Get its face. */
17043 ilisp
= make_number (p
- arrow_string
);
17044 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
17045 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
17047 /* Compute its width, get its glyphs. */
17048 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
17049 SET_TEXT_POS (it
.position
, -1, -1);
17050 PRODUCE_GLYPHS (&it
);
17052 /* If this character doesn't fit any more in the line, we have
17053 to remove some glyphs. */
17054 if (it
.current_x
> it
.last_visible_x
)
17056 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17061 set_buffer_temp (old
);
17062 return it
.glyph_row
;
17066 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
17067 glyphs are only inserted for terminal frames since we can't really
17068 win with truncation glyphs when partially visible glyphs are
17069 involved. Which glyphs to insert is determined by
17070 produce_special_glyphs. */
17073 insert_left_trunc_glyphs (struct it
*it
)
17075 struct it truncate_it
;
17076 struct glyph
*from
, *end
, *to
, *toend
;
17078 xassert (!FRAME_WINDOW_P (it
->f
));
17080 /* Get the truncation glyphs. */
17082 truncate_it
.current_x
= 0;
17083 truncate_it
.face_id
= DEFAULT_FACE_ID
;
17084 truncate_it
.glyph_row
= &scratch_glyph_row
;
17085 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
17086 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
17087 truncate_it
.object
= make_number (0);
17088 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
17090 /* Overwrite glyphs from IT with truncation glyphs. */
17091 if (!it
->glyph_row
->reversed_p
)
17093 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17094 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
17095 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17096 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
17101 /* There may be padding glyphs left over. Overwrite them too. */
17102 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
17104 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17110 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
17114 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
17115 that back to front. */
17116 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17117 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17118 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17119 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17121 while (from
>= end
&& to
>= toend
)
17123 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
17126 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
17127 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17128 while (from
>= end
&& to
>= toend
)
17133 /* Need to free some room before prepending additional
17135 int move_by
= from
- end
+ 1;
17136 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17137 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17139 for ( ; g
>= g0
; g
--)
17141 while (from
>= end
)
17143 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
17149 /* Compute the pixel height and width of IT->glyph_row.
17151 Most of the time, ascent and height of a display line will be equal
17152 to the max_ascent and max_height values of the display iterator
17153 structure. This is not the case if
17155 1. We hit ZV without displaying anything. In this case, max_ascent
17156 and max_height will be zero.
17158 2. We have some glyphs that don't contribute to the line height.
17159 (The glyph row flag contributes_to_line_height_p is for future
17160 pixmap extensions).
17162 The first case is easily covered by using default values because in
17163 these cases, the line height does not really matter, except that it
17164 must not be zero. */
17167 compute_line_metrics (struct it
*it
)
17169 struct glyph_row
*row
= it
->glyph_row
;
17171 if (FRAME_WINDOW_P (it
->f
))
17173 int i
, min_y
, max_y
;
17175 /* The line may consist of one space only, that was added to
17176 place the cursor on it. If so, the row's height hasn't been
17178 if (row
->height
== 0)
17180 if (it
->max_ascent
+ it
->max_descent
== 0)
17181 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
17182 row
->ascent
= it
->max_ascent
;
17183 row
->height
= it
->max_ascent
+ it
->max_descent
;
17184 row
->phys_ascent
= it
->max_phys_ascent
;
17185 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17186 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17189 /* Compute the width of this line. */
17190 row
->pixel_width
= row
->x
;
17191 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
17192 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
17194 xassert (row
->pixel_width
>= 0);
17195 xassert (row
->ascent
>= 0 && row
->height
> 0);
17197 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
17198 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
17200 /* If first line's physical ascent is larger than its logical
17201 ascent, use the physical ascent, and make the row taller.
17202 This makes accented characters fully visible. */
17203 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
17204 && row
->phys_ascent
> row
->ascent
)
17206 row
->height
+= row
->phys_ascent
- row
->ascent
;
17207 row
->ascent
= row
->phys_ascent
;
17210 /* Compute how much of the line is visible. */
17211 row
->visible_height
= row
->height
;
17213 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
17214 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
17216 if (row
->y
< min_y
)
17217 row
->visible_height
-= min_y
- row
->y
;
17218 if (row
->y
+ row
->height
> max_y
)
17219 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17223 row
->pixel_width
= row
->used
[TEXT_AREA
];
17224 if (row
->continued_p
)
17225 row
->pixel_width
-= it
->continuation_pixel_width
;
17226 else if (row
->truncated_on_right_p
)
17227 row
->pixel_width
-= it
->truncation_pixel_width
;
17228 row
->ascent
= row
->phys_ascent
= 0;
17229 row
->height
= row
->phys_height
= row
->visible_height
= 1;
17230 row
->extra_line_spacing
= 0;
17233 /* Compute a hash code for this row. */
17237 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17238 for (i
= 0; i
< row
->used
[area
]; ++i
)
17239 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
17240 + row
->glyphs
[area
][i
].u
.val
17241 + row
->glyphs
[area
][i
].face_id
17242 + row
->glyphs
[area
][i
].padding_p
17243 + (row
->glyphs
[area
][i
].type
<< 2));
17246 it
->max_ascent
= it
->max_descent
= 0;
17247 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
17251 /* Append one space to the glyph row of iterator IT if doing a
17252 window-based redisplay. The space has the same face as
17253 IT->face_id. Value is non-zero if a space was added.
17255 This function is called to make sure that there is always one glyph
17256 at the end of a glyph row that the cursor can be set on under
17257 window-systems. (If there weren't such a glyph we would not know
17258 how wide and tall a box cursor should be displayed).
17260 At the same time this space let's a nicely handle clearing to the
17261 end of the line if the row ends in italic text. */
17264 append_space_for_newline (struct it
*it
, int default_face_p
)
17266 if (FRAME_WINDOW_P (it
->f
))
17268 int n
= it
->glyph_row
->used
[TEXT_AREA
];
17270 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
17271 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
17273 /* Save some values that must not be changed.
17274 Must save IT->c and IT->len because otherwise
17275 ITERATOR_AT_END_P wouldn't work anymore after
17276 append_space_for_newline has been called. */
17277 enum display_element_type saved_what
= it
->what
;
17278 int saved_c
= it
->c
, saved_len
= it
->len
;
17279 int saved_char_to_display
= it
->char_to_display
;
17280 int saved_x
= it
->current_x
;
17281 int saved_face_id
= it
->face_id
;
17282 struct text_pos saved_pos
;
17283 Lisp_Object saved_object
;
17286 saved_object
= it
->object
;
17287 saved_pos
= it
->position
;
17289 it
->what
= IT_CHARACTER
;
17290 memset (&it
->position
, 0, sizeof it
->position
);
17291 it
->object
= make_number (0);
17292 it
->c
= it
->char_to_display
= ' ';
17295 if (default_face_p
)
17296 it
->face_id
= DEFAULT_FACE_ID
;
17297 else if (it
->face_before_selective_p
)
17298 it
->face_id
= it
->saved_face_id
;
17299 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17300 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
17302 PRODUCE_GLYPHS (it
);
17304 it
->override_ascent
= -1;
17305 it
->constrain_row_ascent_descent_p
= 0;
17306 it
->current_x
= saved_x
;
17307 it
->object
= saved_object
;
17308 it
->position
= saved_pos
;
17309 it
->what
= saved_what
;
17310 it
->face_id
= saved_face_id
;
17311 it
->len
= saved_len
;
17313 it
->char_to_display
= saved_char_to_display
;
17322 /* Extend the face of the last glyph in the text area of IT->glyph_row
17323 to the end of the display line. Called from display_line. If the
17324 glyph row is empty, add a space glyph to it so that we know the
17325 face to draw. Set the glyph row flag fill_line_p. If the glyph
17326 row is R2L, prepend a stretch glyph to cover the empty space to the
17327 left of the leftmost glyph. */
17330 extend_face_to_end_of_line (struct it
*it
)
17333 struct frame
*f
= it
->f
;
17335 /* If line is already filled, do nothing. Non window-system frames
17336 get a grace of one more ``pixel'' because their characters are
17337 1-``pixel'' wide, so they hit the equality too early. This grace
17338 is needed only for R2L rows that are not continued, to produce
17339 one extra blank where we could display the cursor. */
17340 if (it
->current_x
>= it
->last_visible_x
17341 + (!FRAME_WINDOW_P (f
)
17342 && it
->glyph_row
->reversed_p
17343 && !it
->glyph_row
->continued_p
))
17346 /* Face extension extends the background and box of IT->face_id
17347 to the end of the line. If the background equals the background
17348 of the frame, we don't have to do anything. */
17349 if (it
->face_before_selective_p
)
17350 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
17352 face
= FACE_FROM_ID (f
, it
->face_id
);
17354 if (FRAME_WINDOW_P (f
)
17355 && it
->glyph_row
->displays_text_p
17356 && face
->box
== FACE_NO_BOX
17357 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
17359 && !it
->glyph_row
->reversed_p
)
17362 /* Set the glyph row flag indicating that the face of the last glyph
17363 in the text area has to be drawn to the end of the text area. */
17364 it
->glyph_row
->fill_line_p
= 1;
17366 /* If current character of IT is not ASCII, make sure we have the
17367 ASCII face. This will be automatically undone the next time
17368 get_next_display_element returns a multibyte character. Note
17369 that the character will always be single byte in unibyte
17371 if (!ASCII_CHAR_P (it
->c
))
17373 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
17376 if (FRAME_WINDOW_P (f
))
17378 /* If the row is empty, add a space with the current face of IT,
17379 so that we know which face to draw. */
17380 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
17382 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
17383 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
17384 it
->glyph_row
->used
[TEXT_AREA
] = 1;
17386 #ifdef HAVE_WINDOW_SYSTEM
17387 if (it
->glyph_row
->reversed_p
)
17389 /* Prepend a stretch glyph to the row, such that the
17390 rightmost glyph will be drawn flushed all the way to the
17391 right margin of the window. The stretch glyph that will
17392 occupy the empty space, if any, to the left of the
17394 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
17395 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17396 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
17398 int row_width
, stretch_ascent
, stretch_width
;
17399 struct text_pos saved_pos
;
17400 int saved_face_id
, saved_avoid_cursor
;
17402 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
17403 row_width
+= g
->pixel_width
;
17404 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
17405 if (stretch_width
> 0)
17408 (((it
->ascent
+ it
->descent
)
17409 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
17410 saved_pos
= it
->position
;
17411 memset (&it
->position
, 0, sizeof it
->position
);
17412 saved_avoid_cursor
= it
->avoid_cursor_p
;
17413 it
->avoid_cursor_p
= 1;
17414 saved_face_id
= it
->face_id
;
17415 /* The last row's stretch glyph should get the default
17416 face, to avoid painting the rest of the window with
17417 the region face, if the region ends at ZV. */
17418 if (it
->glyph_row
->ends_at_zv_p
)
17419 it
->face_id
= DEFAULT_FACE_ID
;
17421 it
->face_id
= face
->id
;
17422 append_stretch_glyph (it
, make_number (0), stretch_width
,
17423 it
->ascent
+ it
->descent
, stretch_ascent
);
17424 it
->position
= saved_pos
;
17425 it
->avoid_cursor_p
= saved_avoid_cursor
;
17426 it
->face_id
= saved_face_id
;
17429 #endif /* HAVE_WINDOW_SYSTEM */
17433 /* Save some values that must not be changed. */
17434 int saved_x
= it
->current_x
;
17435 struct text_pos saved_pos
;
17436 Lisp_Object saved_object
;
17437 enum display_element_type saved_what
= it
->what
;
17438 int saved_face_id
= it
->face_id
;
17440 saved_object
= it
->object
;
17441 saved_pos
= it
->position
;
17443 it
->what
= IT_CHARACTER
;
17444 memset (&it
->position
, 0, sizeof it
->position
);
17445 it
->object
= make_number (0);
17446 it
->c
= it
->char_to_display
= ' ';
17448 /* The last row's blank glyphs should get the default face, to
17449 avoid painting the rest of the window with the region face,
17450 if the region ends at ZV. */
17451 if (it
->glyph_row
->ends_at_zv_p
)
17452 it
->face_id
= DEFAULT_FACE_ID
;
17454 it
->face_id
= face
->id
;
17456 PRODUCE_GLYPHS (it
);
17458 while (it
->current_x
<= it
->last_visible_x
)
17459 PRODUCE_GLYPHS (it
);
17461 /* Don't count these blanks really. It would let us insert a left
17462 truncation glyph below and make us set the cursor on them, maybe. */
17463 it
->current_x
= saved_x
;
17464 it
->object
= saved_object
;
17465 it
->position
= saved_pos
;
17466 it
->what
= saved_what
;
17467 it
->face_id
= saved_face_id
;
17472 /* Value is non-zero if text starting at CHARPOS in current_buffer is
17473 trailing whitespace. */
17476 trailing_whitespace_p (EMACS_INT charpos
)
17478 EMACS_INT bytepos
= CHAR_TO_BYTE (charpos
);
17481 while (bytepos
< ZV_BYTE
17482 && (c
= FETCH_CHAR (bytepos
),
17483 c
== ' ' || c
== '\t'))
17486 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
17488 if (bytepos
!= PT_BYTE
)
17495 /* Highlight trailing whitespace, if any, in ROW. */
17498 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
17500 int used
= row
->used
[TEXT_AREA
];
17504 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
17505 struct glyph
*glyph
= start
+ used
- 1;
17507 if (row
->reversed_p
)
17509 /* Right-to-left rows need to be processed in the opposite
17510 direction, so swap the edge pointers. */
17512 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
17515 /* Skip over glyphs inserted to display the cursor at the
17516 end of a line, for extending the face of the last glyph
17517 to the end of the line on terminals, and for truncation
17518 and continuation glyphs. */
17519 if (!row
->reversed_p
)
17521 while (glyph
>= start
17522 && glyph
->type
== CHAR_GLYPH
17523 && INTEGERP (glyph
->object
))
17528 while (glyph
<= start
17529 && glyph
->type
== CHAR_GLYPH
17530 && INTEGERP (glyph
->object
))
17534 /* If last glyph is a space or stretch, and it's trailing
17535 whitespace, set the face of all trailing whitespace glyphs in
17536 IT->glyph_row to `trailing-whitespace'. */
17537 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
17538 && BUFFERP (glyph
->object
)
17539 && (glyph
->type
== STRETCH_GLYPH
17540 || (glyph
->type
== CHAR_GLYPH
17541 && glyph
->u
.ch
== ' '))
17542 && trailing_whitespace_p (glyph
->charpos
))
17544 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
17548 if (!row
->reversed_p
)
17550 while (glyph
>= start
17551 && BUFFERP (glyph
->object
)
17552 && (glyph
->type
== STRETCH_GLYPH
17553 || (glyph
->type
== CHAR_GLYPH
17554 && glyph
->u
.ch
== ' ')))
17555 (glyph
--)->face_id
= face_id
;
17559 while (glyph
<= start
17560 && BUFFERP (glyph
->object
)
17561 && (glyph
->type
== STRETCH_GLYPH
17562 || (glyph
->type
== CHAR_GLYPH
17563 && glyph
->u
.ch
== ' ')))
17564 (glyph
++)->face_id
= face_id
;
17571 /* Value is non-zero if glyph row ROW should be
17572 used to hold the cursor. */
17575 cursor_row_p (struct glyph_row
*row
)
17579 if (PT
== CHARPOS (row
->end
.pos
))
17581 /* Suppose the row ends on a string.
17582 Unless the row is continued, that means it ends on a newline
17583 in the string. If it's anything other than a display string
17584 (e.g. a before-string from an overlay), we don't want the
17585 cursor there. (This heuristic seems to give the optimal
17586 behavior for the various types of multi-line strings.) */
17587 if (CHARPOS (row
->end
.string_pos
) >= 0)
17589 if (row
->continued_p
)
17593 /* Check for `display' property. */
17594 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17595 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17596 struct glyph
*glyph
;
17599 for (glyph
= end
; glyph
>= beg
; --glyph
)
17600 if (STRINGP (glyph
->object
))
17603 = Fget_char_property (make_number (PT
),
17607 && display_prop_string_p (prop
, glyph
->object
));
17612 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17614 /* If the row ends in middle of a real character,
17615 and the line is continued, we want the cursor here.
17616 That's because CHARPOS (ROW->end.pos) would equal
17617 PT if PT is before the character. */
17618 if (!row
->ends_in_ellipsis_p
)
17619 result
= row
->continued_p
;
17621 /* If the row ends in an ellipsis, then
17622 CHARPOS (ROW->end.pos) will equal point after the
17623 invisible text. We want that position to be displayed
17624 after the ellipsis. */
17627 /* If the row ends at ZV, display the cursor at the end of that
17628 row instead of at the start of the row below. */
17629 else if (row
->ends_at_zv_p
)
17640 /* Push the display property PROP so that it will be rendered at the
17641 current position in IT. Return 1 if PROP was successfully pushed,
17645 push_display_prop (struct it
*it
, Lisp_Object prop
)
17647 push_it (it
, NULL
);
17649 if (STRINGP (prop
))
17651 if (SCHARS (prop
) == 0)
17658 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17659 it
->current
.overlay_string_index
= -1;
17660 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17661 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17662 it
->method
= GET_FROM_STRING
;
17663 it
->stop_charpos
= 0;
17665 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17667 it
->method
= GET_FROM_STRETCH
;
17670 #ifdef HAVE_WINDOW_SYSTEM
17671 else if (IMAGEP (prop
))
17673 it
->what
= IT_IMAGE
;
17674 it
->image_id
= lookup_image (it
->f
, prop
);
17675 it
->method
= GET_FROM_IMAGE
;
17677 #endif /* HAVE_WINDOW_SYSTEM */
17680 pop_it (it
); /* bogus display property, give up */
17687 /* Return the character-property PROP at the current position in IT. */
17690 get_it_property (struct it
*it
, Lisp_Object prop
)
17692 Lisp_Object position
;
17694 if (STRINGP (it
->object
))
17695 position
= make_number (IT_STRING_CHARPOS (*it
));
17696 else if (BUFFERP (it
->object
))
17697 position
= make_number (IT_CHARPOS (*it
));
17701 return Fget_char_property (position
, prop
, it
->object
);
17704 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17707 handle_line_prefix (struct it
*it
)
17709 Lisp_Object prefix
;
17710 if (it
->continuation_lines_width
> 0)
17712 prefix
= get_it_property (it
, Qwrap_prefix
);
17714 prefix
= Vwrap_prefix
;
17718 prefix
= get_it_property (it
, Qline_prefix
);
17720 prefix
= Vline_prefix
;
17722 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17724 /* If the prefix is wider than the window, and we try to wrap
17725 it, it would acquire its own wrap prefix, and so on till the
17726 iterator stack overflows. So, don't wrap the prefix. */
17727 it
->line_wrap
= TRUNCATE
;
17728 it
->avoid_cursor_p
= 1;
17734 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
17735 only for R2L lines from display_line and display_string, when they
17736 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
17737 the line/string needs to be continued on the next glyph row. */
17739 unproduce_glyphs (struct it
*it
, int n
)
17741 struct glyph
*glyph
, *end
;
17743 xassert (it
->glyph_row
);
17744 xassert (it
->glyph_row
->reversed_p
);
17745 xassert (it
->area
== TEXT_AREA
);
17746 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
17748 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
17749 n
= it
->glyph_row
->used
[TEXT_AREA
];
17750 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
17751 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
17752 for ( ; glyph
< end
; glyph
++)
17753 glyph
[-n
] = *glyph
;
17756 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
17757 and ROW->maxpos. */
17759 find_row_edges (struct it
*it
, struct glyph_row
*row
,
17760 EMACS_INT min_pos
, EMACS_INT min_bpos
,
17761 EMACS_INT max_pos
, EMACS_INT max_bpos
)
17763 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17764 lines' rows is implemented for bidi-reordered rows. */
17766 /* ROW->minpos is the value of min_pos, the minimal buffer position
17769 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
17771 /* We didn't find _any_ valid buffer positions in any of the
17772 glyphs, so we must trust the iterator's computed positions. */
17773 row
->minpos
= row
->start
.pos
;
17776 max_pos
= CHARPOS (it
->current
.pos
);
17777 max_bpos
= BYTEPOS (it
->current
.pos
);
17780 /* Here are the various use-cases for ending the row, and the
17781 corresponding values for ROW->maxpos:
17783 Line ends in a newline from buffer eol_pos + 1
17784 Line is continued from buffer max_pos + 1
17785 Line is truncated on right it->current.pos
17786 Line ends in a newline from string max_pos
17787 Line is continued from string max_pos
17788 Line is continued from display vector max_pos
17789 Line is entirely from a string min_pos == max_pos
17790 Line is entirely from a display vector min_pos == max_pos
17791 Line that ends at ZV ZV
17793 If you discover other use-cases, please add them here as
17795 if (row
->ends_at_zv_p
)
17796 row
->maxpos
= it
->current
.pos
;
17797 else if (row
->used
[TEXT_AREA
])
17799 if (row
->ends_in_newline_from_string_p
)
17800 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17801 else if (CHARPOS (it
->eol_pos
) > 0)
17802 SET_TEXT_POS (row
->maxpos
,
17803 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
17804 else if (row
->continued_p
)
17806 /* If max_pos is different from IT's current position, it
17807 means IT->method does not belong to the display element
17808 at max_pos. However, it also means that the display
17809 element at max_pos was displayed in its entirety on this
17810 line, which is equivalent to saying that the next line
17811 starts at the next buffer position. */
17812 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
17813 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17816 INC_BOTH (max_pos
, max_bpos
);
17817 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17820 else if (row
->truncated_on_right_p
)
17821 /* display_line already called reseat_at_next_visible_line_start,
17822 which puts the iterator at the beginning of the next line, in
17823 the logical order. */
17824 row
->maxpos
= it
->current
.pos
;
17825 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
17826 /* A line that is entirely from a string/image/stretch... */
17827 row
->maxpos
= row
->minpos
;
17832 row
->maxpos
= it
->current
.pos
;
17835 /* Construct the glyph row IT->glyph_row in the desired matrix of
17836 IT->w from text at the current position of IT. See dispextern.h
17837 for an overview of struct it. Value is non-zero if
17838 IT->glyph_row displays text, as opposed to a line displaying ZV
17842 display_line (struct it
*it
)
17844 struct glyph_row
*row
= it
->glyph_row
;
17845 Lisp_Object overlay_arrow_string
;
17847 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
17848 int wrap_row_used
= -1;
17849 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
17850 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
17851 int wrap_row_extra_line_spacing
IF_LINT (= 0);
17852 EMACS_INT wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
17853 EMACS_INT wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
17855 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
17856 EMACS_INT min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
17858 /* We always start displaying at hpos zero even if hscrolled. */
17859 xassert (it
->hpos
== 0 && it
->current_x
== 0);
17861 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
17862 >= it
->w
->desired_matrix
->nrows
)
17864 it
->w
->nrows_scale_factor
++;
17865 fonts_changed_p
= 1;
17869 /* Is IT->w showing the region? */
17870 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
17872 /* Clear the result glyph row and enable it. */
17873 prepare_desired_row (row
);
17875 row
->y
= it
->current_y
;
17876 row
->start
= it
->start
;
17877 row
->continuation_lines_width
= it
->continuation_lines_width
;
17878 row
->displays_text_p
= 1;
17879 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
17880 it
->starts_in_middle_of_char_p
= 0;
17882 /* Arrange the overlays nicely for our purposes. Usually, we call
17883 display_line on only one line at a time, in which case this
17884 can't really hurt too much, or we call it on lines which appear
17885 one after another in the buffer, in which case all calls to
17886 recenter_overlay_lists but the first will be pretty cheap. */
17887 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
17889 /* Move over display elements that are not visible because we are
17890 hscrolled. This may stop at an x-position < IT->first_visible_x
17891 if the first glyph is partially visible or if we hit a line end. */
17892 if (it
->current_x
< it
->first_visible_x
)
17894 this_line_min_pos
= row
->start
.pos
;
17895 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
17896 MOVE_TO_POS
| MOVE_TO_X
);
17897 /* Record the smallest positions seen while we moved over
17898 display elements that are not visible. This is needed by
17899 redisplay_internal for optimizing the case where the cursor
17900 stays inside the same line. The rest of this function only
17901 considers positions that are actually displayed, so
17902 RECORD_MAX_MIN_POS will not otherwise record positions that
17903 are hscrolled to the left of the left edge of the window. */
17904 min_pos
= CHARPOS (this_line_min_pos
);
17905 min_bpos
= BYTEPOS (this_line_min_pos
);
17909 /* We only do this when not calling `move_it_in_display_line_to'
17910 above, because move_it_in_display_line_to calls
17911 handle_line_prefix itself. */
17912 handle_line_prefix (it
);
17915 /* Get the initial row height. This is either the height of the
17916 text hscrolled, if there is any, or zero. */
17917 row
->ascent
= it
->max_ascent
;
17918 row
->height
= it
->max_ascent
+ it
->max_descent
;
17919 row
->phys_ascent
= it
->max_phys_ascent
;
17920 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17921 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17923 /* Utility macro to record max and min buffer positions seen until now. */
17924 #define RECORD_MAX_MIN_POS(IT) \
17927 if (IT_CHARPOS (*(IT)) < min_pos) \
17929 min_pos = IT_CHARPOS (*(IT)); \
17930 min_bpos = IT_BYTEPOS (*(IT)); \
17932 if (IT_CHARPOS (*(IT)) > max_pos) \
17934 max_pos = IT_CHARPOS (*(IT)); \
17935 max_bpos = IT_BYTEPOS (*(IT)); \
17940 /* Loop generating characters. The loop is left with IT on the next
17941 character to display. */
17944 int n_glyphs_before
, hpos_before
, x_before
;
17946 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17948 /* Retrieve the next thing to display. Value is zero if end of
17950 if (!get_next_display_element (it
))
17952 /* Maybe add a space at the end of this line that is used to
17953 display the cursor there under X. Set the charpos of the
17954 first glyph of blank lines not corresponding to any text
17956 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17957 row
->exact_window_width_line_p
= 1;
17958 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17959 || row
->used
[TEXT_AREA
] == 0)
17961 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17962 row
->displays_text_p
= 0;
17964 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
17965 && (!MINI_WINDOW_P (it
->w
)
17966 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17967 row
->indicate_empty_line_p
= 1;
17970 it
->continuation_lines_width
= 0;
17971 row
->ends_at_zv_p
= 1;
17972 /* A row that displays right-to-left text must always have
17973 its last face extended all the way to the end of line,
17974 even if this row ends in ZV, because we still write to
17975 the screen left to right. */
17976 if (row
->reversed_p
)
17977 extend_face_to_end_of_line (it
);
17981 /* Now, get the metrics of what we want to display. This also
17982 generates glyphs in `row' (which is IT->glyph_row). */
17983 n_glyphs_before
= row
->used
[TEXT_AREA
];
17986 /* Remember the line height so far in case the next element doesn't
17987 fit on the line. */
17988 if (it
->line_wrap
!= TRUNCATE
)
17990 ascent
= it
->max_ascent
;
17991 descent
= it
->max_descent
;
17992 phys_ascent
= it
->max_phys_ascent
;
17993 phys_descent
= it
->max_phys_descent
;
17995 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17997 if (IT_DISPLAYING_WHITESPACE (it
))
18003 wrap_row_used
= row
->used
[TEXT_AREA
];
18004 wrap_row_ascent
= row
->ascent
;
18005 wrap_row_height
= row
->height
;
18006 wrap_row_phys_ascent
= row
->phys_ascent
;
18007 wrap_row_phys_height
= row
->phys_height
;
18008 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
18009 wrap_row_min_pos
= min_pos
;
18010 wrap_row_min_bpos
= min_bpos
;
18011 wrap_row_max_pos
= max_pos
;
18012 wrap_row_max_bpos
= max_bpos
;
18018 PRODUCE_GLYPHS (it
);
18020 /* If this display element was in marginal areas, continue with
18022 if (it
->area
!= TEXT_AREA
)
18024 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18025 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18026 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18027 row
->phys_height
= max (row
->phys_height
,
18028 it
->max_phys_ascent
+ it
->max_phys_descent
);
18029 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18030 it
->max_extra_line_spacing
);
18031 set_iterator_to_next (it
, 1);
18035 /* Does the display element fit on the line? If we truncate
18036 lines, we should draw past the right edge of the window. If
18037 we don't truncate, we want to stop so that we can display the
18038 continuation glyph before the right margin. If lines are
18039 continued, there are two possible strategies for characters
18040 resulting in more than 1 glyph (e.g. tabs): Display as many
18041 glyphs as possible in this line and leave the rest for the
18042 continuation line, or display the whole element in the next
18043 line. Original redisplay did the former, so we do it also. */
18044 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
18045 hpos_before
= it
->hpos
;
18048 if (/* Not a newline. */
18050 /* Glyphs produced fit entirely in the line. */
18051 && it
->current_x
< it
->last_visible_x
)
18053 it
->hpos
+= nglyphs
;
18054 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18055 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18056 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18057 row
->phys_height
= max (row
->phys_height
,
18058 it
->max_phys_ascent
+ it
->max_phys_descent
);
18059 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18060 it
->max_extra_line_spacing
);
18061 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
18062 row
->x
= x
- it
->first_visible_x
;
18063 /* Record the maximum and minimum buffer positions seen so
18064 far in glyphs that will be displayed by this row. */
18066 RECORD_MAX_MIN_POS (it
);
18071 struct glyph
*glyph
;
18073 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
18075 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18076 new_x
= x
+ glyph
->pixel_width
;
18078 if (/* Lines are continued. */
18079 it
->line_wrap
!= TRUNCATE
18080 && (/* Glyph doesn't fit on the line. */
18081 new_x
> it
->last_visible_x
18082 /* Or it fits exactly on a window system frame. */
18083 || (new_x
== it
->last_visible_x
18084 && FRAME_WINDOW_P (it
->f
))))
18086 /* End of a continued line. */
18089 || (new_x
== it
->last_visible_x
18090 && FRAME_WINDOW_P (it
->f
)))
18092 /* Current glyph is the only one on the line or
18093 fits exactly on the line. We must continue
18094 the line because we can't draw the cursor
18095 after the glyph. */
18096 row
->continued_p
= 1;
18097 it
->current_x
= new_x
;
18098 it
->continuation_lines_width
+= new_x
;
18100 /* Record the maximum and minimum buffer
18101 positions seen so far in glyphs that will be
18102 displayed by this row. */
18104 RECORD_MAX_MIN_POS (it
);
18105 if (i
== nglyphs
- 1)
18107 /* If line-wrap is on, check if a previous
18108 wrap point was found. */
18109 if (wrap_row_used
> 0
18110 /* Even if there is a previous wrap
18111 point, continue the line here as
18112 usual, if (i) the previous character
18113 was a space or tab AND (ii) the
18114 current character is not. */
18116 || IT_DISPLAYING_WHITESPACE (it
)))
18119 set_iterator_to_next (it
, 1);
18120 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18122 if (!get_next_display_element (it
))
18124 row
->exact_window_width_line_p
= 1;
18125 it
->continuation_lines_width
= 0;
18126 row
->continued_p
= 0;
18127 row
->ends_at_zv_p
= 1;
18129 else if (ITERATOR_AT_END_OF_LINE_P (it
))
18131 row
->continued_p
= 0;
18132 row
->exact_window_width_line_p
= 1;
18137 else if (CHAR_GLYPH_PADDING_P (*glyph
)
18138 && !FRAME_WINDOW_P (it
->f
))
18140 /* A padding glyph that doesn't fit on this line.
18141 This means the whole character doesn't fit
18143 if (row
->reversed_p
)
18144 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
18145 - n_glyphs_before
);
18146 row
->used
[TEXT_AREA
] = n_glyphs_before
;
18148 /* Fill the rest of the row with continuation
18149 glyphs like in 20.x. */
18150 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
18151 < row
->glyphs
[1 + TEXT_AREA
])
18152 produce_special_glyphs (it
, IT_CONTINUATION
);
18154 row
->continued_p
= 1;
18155 it
->current_x
= x_before
;
18156 it
->continuation_lines_width
+= x_before
;
18158 /* Restore the height to what it was before the
18159 element not fitting on the line. */
18160 it
->max_ascent
= ascent
;
18161 it
->max_descent
= descent
;
18162 it
->max_phys_ascent
= phys_ascent
;
18163 it
->max_phys_descent
= phys_descent
;
18165 else if (wrap_row_used
> 0)
18168 if (row
->reversed_p
)
18169 unproduce_glyphs (it
,
18170 row
->used
[TEXT_AREA
] - wrap_row_used
);
18172 it
->continuation_lines_width
+= wrap_x
;
18173 row
->used
[TEXT_AREA
] = wrap_row_used
;
18174 row
->ascent
= wrap_row_ascent
;
18175 row
->height
= wrap_row_height
;
18176 row
->phys_ascent
= wrap_row_phys_ascent
;
18177 row
->phys_height
= wrap_row_phys_height
;
18178 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
18179 min_pos
= wrap_row_min_pos
;
18180 min_bpos
= wrap_row_min_bpos
;
18181 max_pos
= wrap_row_max_pos
;
18182 max_bpos
= wrap_row_max_bpos
;
18183 row
->continued_p
= 1;
18184 row
->ends_at_zv_p
= 0;
18185 row
->exact_window_width_line_p
= 0;
18186 it
->continuation_lines_width
+= x
;
18188 /* Make sure that a non-default face is extended
18189 up to the right margin of the window. */
18190 extend_face_to_end_of_line (it
);
18192 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
18194 /* A TAB that extends past the right edge of the
18195 window. This produces a single glyph on
18196 window system frames. We leave the glyph in
18197 this row and let it fill the row, but don't
18198 consume the TAB. */
18199 it
->continuation_lines_width
+= it
->last_visible_x
;
18200 row
->ends_in_middle_of_char_p
= 1;
18201 row
->continued_p
= 1;
18202 glyph
->pixel_width
= it
->last_visible_x
- x
;
18203 it
->starts_in_middle_of_char_p
= 1;
18207 /* Something other than a TAB that draws past
18208 the right edge of the window. Restore
18209 positions to values before the element. */
18210 if (row
->reversed_p
)
18211 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
18212 - (n_glyphs_before
+ i
));
18213 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18215 /* Display continuation glyphs. */
18216 if (!FRAME_WINDOW_P (it
->f
))
18217 produce_special_glyphs (it
, IT_CONTINUATION
);
18218 row
->continued_p
= 1;
18220 it
->current_x
= x_before
;
18221 it
->continuation_lines_width
+= x
;
18222 extend_face_to_end_of_line (it
);
18224 if (nglyphs
> 1 && i
> 0)
18226 row
->ends_in_middle_of_char_p
= 1;
18227 it
->starts_in_middle_of_char_p
= 1;
18230 /* Restore the height to what it was before the
18231 element not fitting on the line. */
18232 it
->max_ascent
= ascent
;
18233 it
->max_descent
= descent
;
18234 it
->max_phys_ascent
= phys_ascent
;
18235 it
->max_phys_descent
= phys_descent
;
18240 else if (new_x
> it
->first_visible_x
)
18242 /* Increment number of glyphs actually displayed. */
18245 /* Record the maximum and minimum buffer positions
18246 seen so far in glyphs that will be displayed by
18249 RECORD_MAX_MIN_POS (it
);
18251 if (x
< it
->first_visible_x
)
18252 /* Glyph is partially visible, i.e. row starts at
18253 negative X position. */
18254 row
->x
= x
- it
->first_visible_x
;
18258 /* Glyph is completely off the left margin of the
18259 window. This should not happen because of the
18260 move_it_in_display_line at the start of this
18261 function, unless the text display area of the
18262 window is empty. */
18263 xassert (it
->first_visible_x
<= it
->last_visible_x
);
18267 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18268 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18269 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18270 row
->phys_height
= max (row
->phys_height
,
18271 it
->max_phys_ascent
+ it
->max_phys_descent
);
18272 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18273 it
->max_extra_line_spacing
);
18275 /* End of this display line if row is continued. */
18276 if (row
->continued_p
|| row
->ends_at_zv_p
)
18281 /* Is this a line end? If yes, we're also done, after making
18282 sure that a non-default face is extended up to the right
18283 margin of the window. */
18284 if (ITERATOR_AT_END_OF_LINE_P (it
))
18286 int used_before
= row
->used
[TEXT_AREA
];
18288 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
18290 /* Add a space at the end of the line that is used to
18291 display the cursor there. */
18292 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18293 append_space_for_newline (it
, 0);
18295 /* Extend the face to the end of the line. */
18296 extend_face_to_end_of_line (it
);
18298 /* Make sure we have the position. */
18299 if (used_before
== 0)
18300 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
18302 /* Record the position of the newline, for use in
18304 it
->eol_pos
= it
->current
.pos
;
18306 /* Consume the line end. This skips over invisible lines. */
18307 set_iterator_to_next (it
, 1);
18308 it
->continuation_lines_width
= 0;
18312 /* Proceed with next display element. Note that this skips
18313 over lines invisible because of selective display. */
18314 set_iterator_to_next (it
, 1);
18316 /* If we truncate lines, we are done when the last displayed
18317 glyphs reach past the right margin of the window. */
18318 if (it
->line_wrap
== TRUNCATE
18319 && (FRAME_WINDOW_P (it
->f
)
18320 ? (it
->current_x
>= it
->last_visible_x
)
18321 : (it
->current_x
> it
->last_visible_x
)))
18323 /* Maybe add truncation glyphs. */
18324 if (!FRAME_WINDOW_P (it
->f
))
18328 if (!row
->reversed_p
)
18330 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18331 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18336 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
18337 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18339 /* Remove any padding glyphs at the front of ROW, to
18340 make room for the truncation glyphs we will be
18341 adding below. The loop below always inserts at
18342 least one truncation glyph, so also remove the
18343 last glyph added to ROW. */
18344 unproduce_glyphs (it
, i
+ 1);
18345 /* Adjust i for the loop below. */
18346 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
18349 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18351 row
->used
[TEXT_AREA
] = i
;
18352 produce_special_glyphs (it
, IT_TRUNCATION
);
18355 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18357 /* Don't truncate if we can overflow newline into fringe. */
18358 if (!get_next_display_element (it
))
18360 it
->continuation_lines_width
= 0;
18361 row
->ends_at_zv_p
= 1;
18362 row
->exact_window_width_line_p
= 1;
18365 if (ITERATOR_AT_END_OF_LINE_P (it
))
18367 row
->exact_window_width_line_p
= 1;
18368 goto at_end_of_line
;
18372 row
->truncated_on_right_p
= 1;
18373 it
->continuation_lines_width
= 0;
18374 reseat_at_next_visible_line_start (it
, 0);
18375 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
18376 it
->hpos
= hpos_before
;
18377 it
->current_x
= x_before
;
18382 /* If line is not empty and hscrolled, maybe insert truncation glyphs
18383 at the left window margin. */
18384 if (it
->first_visible_x
18385 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
18387 if (!FRAME_WINDOW_P (it
->f
))
18388 insert_left_trunc_glyphs (it
);
18389 row
->truncated_on_left_p
= 1;
18392 /* Remember the position at which this line ends.
18394 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
18395 cannot be before the call to find_row_edges below, since that is
18396 where these positions are determined. */
18397 row
->end
= it
->current
;
18400 row
->minpos
= row
->start
.pos
;
18401 row
->maxpos
= row
->end
.pos
;
18405 /* ROW->minpos and ROW->maxpos must be the smallest and
18406 `1 + the largest' buffer positions in ROW. But if ROW was
18407 bidi-reordered, these two positions can be anywhere in the
18408 row, so we must determine them now. */
18409 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
18412 /* If the start of this line is the overlay arrow-position, then
18413 mark this glyph row as the one containing the overlay arrow.
18414 This is clearly a mess with variable size fonts. It would be
18415 better to let it be displayed like cursors under X. */
18416 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
18417 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
18418 !NILP (overlay_arrow_string
)))
18420 /* Overlay arrow in window redisplay is a fringe bitmap. */
18421 if (STRINGP (overlay_arrow_string
))
18423 struct glyph_row
*arrow_row
18424 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
18425 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
18426 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
18427 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
18428 struct glyph
*p2
, *end
;
18430 /* Copy the arrow glyphs. */
18431 while (glyph
< arrow_end
)
18434 /* Throw away padding glyphs. */
18436 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
18437 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
18443 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
18448 xassert (INTEGERP (overlay_arrow_string
));
18449 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
18451 overlay_arrow_seen
= 1;
18454 /* Compute pixel dimensions of this line. */
18455 compute_line_metrics (it
);
18457 /* Record whether this row ends inside an ellipsis. */
18458 row
->ends_in_ellipsis_p
18459 = (it
->method
== GET_FROM_DISPLAY_VECTOR
18460 && it
->ellipsis_p
);
18462 /* Save fringe bitmaps in this row. */
18463 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
18464 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
18465 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
18466 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
18468 it
->left_user_fringe_bitmap
= 0;
18469 it
->left_user_fringe_face_id
= 0;
18470 it
->right_user_fringe_bitmap
= 0;
18471 it
->right_user_fringe_face_id
= 0;
18473 /* Maybe set the cursor. */
18474 cvpos
= it
->w
->cursor
.vpos
;
18476 /* In bidi-reordered rows, keep checking for proper cursor
18477 position even if one has been found already, because buffer
18478 positions in such rows change non-linearly with ROW->VPOS,
18479 when a line is continued. One exception: when we are at ZV,
18480 display cursor on the first suitable glyph row, since all
18481 the empty rows after that also have their position set to ZV. */
18482 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18483 lines' rows is implemented for bidi-reordered rows. */
18485 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
18486 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
18487 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
18488 && cursor_row_p (row
))
18489 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
18491 /* Highlight trailing whitespace. */
18492 if (!NILP (Vshow_trailing_whitespace
))
18493 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
18495 /* Prepare for the next line. This line starts horizontally at (X
18496 HPOS) = (0 0). Vertical positions are incremented. As a
18497 convenience for the caller, IT->glyph_row is set to the next
18499 it
->current_x
= it
->hpos
= 0;
18500 it
->current_y
+= row
->height
;
18501 SET_TEXT_POS (it
->eol_pos
, 0, 0);
18504 /* The next row should by default use the same value of the
18505 reversed_p flag as this one. set_iterator_to_next decides when
18506 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
18507 the flag accordingly. */
18508 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
18509 it
->glyph_row
->reversed_p
= row
->reversed_p
;
18510 it
->start
= row
->end
;
18511 return row
->displays_text_p
;
18513 #undef RECORD_MAX_MIN_POS
18516 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
18517 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
18518 doc
: /* Return paragraph direction at point in BUFFER.
18519 Value is either `left-to-right' or `right-to-left'.
18520 If BUFFER is omitted or nil, it defaults to the current buffer.
18522 Paragraph direction determines how the text in the paragraph is displayed.
18523 In left-to-right paragraphs, text begins at the left margin of the window
18524 and the reading direction is generally left to right. In right-to-left
18525 paragraphs, text begins at the right margin and is read from right to left.
18527 See also `bidi-paragraph-direction'. */)
18528 (Lisp_Object buffer
)
18530 struct buffer
*buf
= current_buffer
;
18531 struct buffer
*old
= buf
;
18533 if (! NILP (buffer
))
18535 CHECK_BUFFER (buffer
);
18536 buf
= XBUFFER (buffer
);
18539 if (NILP (BVAR (buf
, bidi_display_reordering
)))
18540 return Qleft_to_right
;
18541 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
18542 return BVAR (buf
, bidi_paragraph_direction
);
18545 /* Determine the direction from buffer text. We could try to
18546 use current_matrix if it is up to date, but this seems fast
18547 enough as it is. */
18548 struct bidi_it itb
;
18549 EMACS_INT pos
= BUF_PT (buf
);
18550 EMACS_INT bytepos
= BUF_PT_BYTE (buf
);
18553 set_buffer_temp (buf
);
18554 /* bidi_paragraph_init finds the base direction of the paragraph
18555 by searching forward from paragraph start. We need the base
18556 direction of the current or _previous_ paragraph, so we need
18557 to make sure we are within that paragraph. To that end, find
18558 the previous non-empty line. */
18559 if (pos
>= ZV
&& pos
> BEGV
)
18562 bytepos
= CHAR_TO_BYTE (pos
);
18564 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
18565 || c
== ' ' || c
== '\t' || c
== '\f')
18567 if (bytepos
<= BEGV_BYTE
)
18572 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
18575 itb
.bytepos
= bytepos
;
18577 itb
.string
.s
= NULL
;
18578 itb
.string
.lstring
= Qnil
;
18579 itb
.frame_window_p
= FRAME_WINDOW_P (SELECTED_FRAME ()); /* guesswork */
18581 itb
.separator_limit
= -1;
18582 itb
.paragraph_dir
= NEUTRAL_DIR
;
18584 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
18585 set_buffer_temp (old
);
18586 switch (itb
.paragraph_dir
)
18589 return Qleft_to_right
;
18592 return Qright_to_left
;
18602 /***********************************************************************
18604 ***********************************************************************/
18606 /* Redisplay the menu bar in the frame for window W.
18608 The menu bar of X frames that don't have X toolkit support is
18609 displayed in a special window W->frame->menu_bar_window.
18611 The menu bar of terminal frames is treated specially as far as
18612 glyph matrices are concerned. Menu bar lines are not part of
18613 windows, so the update is done directly on the frame matrix rows
18614 for the menu bar. */
18617 display_menu_bar (struct window
*w
)
18619 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18624 /* Don't do all this for graphical frames. */
18626 if (FRAME_W32_P (f
))
18629 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
18635 if (FRAME_NS_P (f
))
18637 #endif /* HAVE_NS */
18639 #ifdef USE_X_TOOLKIT
18640 xassert (!FRAME_WINDOW_P (f
));
18641 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
18642 it
.first_visible_x
= 0;
18643 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18644 #else /* not USE_X_TOOLKIT */
18645 if (FRAME_WINDOW_P (f
))
18647 /* Menu bar lines are displayed in the desired matrix of the
18648 dummy window menu_bar_window. */
18649 struct window
*menu_w
;
18650 xassert (WINDOWP (f
->menu_bar_window
));
18651 menu_w
= XWINDOW (f
->menu_bar_window
);
18652 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
18654 it
.first_visible_x
= 0;
18655 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18659 /* This is a TTY frame, i.e. character hpos/vpos are used as
18661 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
18663 it
.first_visible_x
= 0;
18664 it
.last_visible_x
= FRAME_COLS (f
);
18666 #endif /* not USE_X_TOOLKIT */
18668 /* FIXME: This should be controlled by a user option. See the
18669 comments in redisplay_tool_bar and display_mode_line about
18671 it
.paragraph_embedding
= L2R
;
18673 if (! mode_line_inverse_video
)
18674 /* Force the menu-bar to be displayed in the default face. */
18675 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18677 /* Clear all rows of the menu bar. */
18678 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
18680 struct glyph_row
*row
= it
.glyph_row
+ i
;
18681 clear_glyph_row (row
);
18682 row
->enabled_p
= 1;
18683 row
->full_width_p
= 1;
18686 /* Display all items of the menu bar. */
18687 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
18688 for (i
= 0; i
< ASIZE (items
); i
+= 4)
18690 Lisp_Object string
;
18692 /* Stop at nil string. */
18693 string
= AREF (items
, i
+ 1);
18697 /* Remember where item was displayed. */
18698 ASET (items
, i
+ 3, make_number (it
.hpos
));
18700 /* Display the item, pad with one space. */
18701 if (it
.current_x
< it
.last_visible_x
)
18702 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
18703 SCHARS (string
) + 1, 0, 0, -1);
18706 /* Fill out the line with spaces. */
18707 if (it
.current_x
< it
.last_visible_x
)
18708 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
18710 /* Compute the total height of the lines. */
18711 compute_line_metrics (&it
);
18716 /***********************************************************************
18718 ***********************************************************************/
18720 /* Redisplay mode lines in the window tree whose root is WINDOW. If
18721 FORCE is non-zero, redisplay mode lines unconditionally.
18722 Otherwise, redisplay only mode lines that are garbaged. Value is
18723 the number of windows whose mode lines were redisplayed. */
18726 redisplay_mode_lines (Lisp_Object window
, int force
)
18730 while (!NILP (window
))
18732 struct window
*w
= XWINDOW (window
);
18734 if (WINDOWP (w
->hchild
))
18735 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
18736 else if (WINDOWP (w
->vchild
))
18737 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18739 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18740 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18742 struct text_pos lpoint
;
18743 struct buffer
*old
= current_buffer
;
18745 /* Set the window's buffer for the mode line display. */
18746 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18747 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18749 /* Point refers normally to the selected window. For any
18750 other window, set up appropriate value. */
18751 if (!EQ (window
, selected_window
))
18753 struct text_pos pt
;
18755 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18756 if (CHARPOS (pt
) < BEGV
)
18757 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18758 else if (CHARPOS (pt
) > (ZV
- 1))
18759 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18761 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18764 /* Display mode lines. */
18765 clear_glyph_matrix (w
->desired_matrix
);
18766 if (display_mode_lines (w
))
18769 w
->must_be_updated_p
= 1;
18772 /* Restore old settings. */
18773 set_buffer_internal_1 (old
);
18774 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18784 /* Display the mode and/or header line of window W. Value is the
18785 sum number of mode lines and header lines displayed. */
18788 display_mode_lines (struct window
*w
)
18790 Lisp_Object old_selected_window
, old_selected_frame
;
18793 old_selected_frame
= selected_frame
;
18794 selected_frame
= w
->frame
;
18795 old_selected_window
= selected_window
;
18796 XSETWINDOW (selected_window
, w
);
18798 /* These will be set while the mode line specs are processed. */
18799 line_number_displayed
= 0;
18800 w
->column_number_displayed
= Qnil
;
18802 if (WINDOW_WANTS_MODELINE_P (w
))
18804 struct window
*sel_w
= XWINDOW (old_selected_window
);
18806 /* Select mode line face based on the real selected window. */
18807 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18808 BVAR (current_buffer
, mode_line_format
));
18812 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18814 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18815 BVAR (current_buffer
, header_line_format
));
18819 selected_frame
= old_selected_frame
;
18820 selected_window
= old_selected_window
;
18825 /* Display mode or header line of window W. FACE_ID specifies which
18826 line to display; it is either MODE_LINE_FACE_ID or
18827 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18828 display. Value is the pixel height of the mode/header line
18832 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
18836 int count
= SPECPDL_INDEX ();
18838 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18839 /* Don't extend on a previously drawn mode-line.
18840 This may happen if called from pos_visible_p. */
18841 it
.glyph_row
->enabled_p
= 0;
18842 prepare_desired_row (it
.glyph_row
);
18844 it
.glyph_row
->mode_line_p
= 1;
18846 if (! mode_line_inverse_video
)
18847 /* Force the mode-line to be displayed in the default face. */
18848 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18850 /* FIXME: This should be controlled by a user option. But
18851 supporting such an option is not trivial, since the mode line is
18852 made up of many separate strings, most of which are normally
18853 unibyte, and unibyte strings currently don't get reordered for
18855 it
.paragraph_embedding
= L2R
;
18857 record_unwind_protect (unwind_format_mode_line
,
18858 format_mode_line_unwind_data (NULL
, Qnil
, 0));
18860 mode_line_target
= MODE_LINE_DISPLAY
;
18862 /* Temporarily make frame's keyboard the current kboard so that
18863 kboard-local variables in the mode_line_format will get the right
18865 push_kboard (FRAME_KBOARD (it
.f
));
18866 record_unwind_save_match_data ();
18867 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18870 unbind_to (count
, Qnil
);
18872 /* Fill up with spaces. */
18873 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
18875 compute_line_metrics (&it
);
18876 it
.glyph_row
->full_width_p
= 1;
18877 it
.glyph_row
->continued_p
= 0;
18878 it
.glyph_row
->truncated_on_left_p
= 0;
18879 it
.glyph_row
->truncated_on_right_p
= 0;
18881 /* Make a 3D mode-line have a shadow at its right end. */
18882 face
= FACE_FROM_ID (it
.f
, face_id
);
18883 extend_face_to_end_of_line (&it
);
18884 if (face
->box
!= FACE_NO_BOX
)
18886 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
18887 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
18888 last
->right_box_line_p
= 1;
18891 return it
.glyph_row
->height
;
18894 /* Move element ELT in LIST to the front of LIST.
18895 Return the updated list. */
18898 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
18900 register Lisp_Object tail
, prev
;
18901 register Lisp_Object tem
;
18905 while (CONSP (tail
))
18911 /* Splice out the link TAIL. */
18913 list
= XCDR (tail
);
18915 Fsetcdr (prev
, XCDR (tail
));
18917 /* Now make it the first. */
18918 Fsetcdr (tail
, list
);
18923 tail
= XCDR (tail
);
18927 /* Not found--return unchanged LIST. */
18931 /* Contribute ELT to the mode line for window IT->w. How it
18932 translates into text depends on its data type.
18934 IT describes the display environment in which we display, as usual.
18936 DEPTH is the depth in recursion. It is used to prevent
18937 infinite recursion here.
18939 FIELD_WIDTH is the number of characters the display of ELT should
18940 occupy in the mode line, and PRECISION is the maximum number of
18941 characters to display from ELT's representation. See
18942 display_string for details.
18944 Returns the hpos of the end of the text generated by ELT.
18946 PROPS is a property list to add to any string we encounter.
18948 If RISKY is nonzero, remove (disregard) any properties in any string
18949 we encounter, and ignore :eval and :propertize.
18951 The global variable `mode_line_target' determines whether the
18952 output is passed to `store_mode_line_noprop',
18953 `store_mode_line_string', or `display_string'. */
18956 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
18957 Lisp_Object elt
, Lisp_Object props
, int risky
)
18959 int n
= 0, field
, prec
;
18964 elt
= build_string ("*too-deep*");
18968 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
18972 /* A string: output it and check for %-constructs within it. */
18974 EMACS_INT offset
= 0;
18976 if (SCHARS (elt
) > 0
18977 && (!NILP (props
) || risky
))
18979 Lisp_Object oprops
, aelt
;
18980 oprops
= Ftext_properties_at (make_number (0), elt
);
18982 /* If the starting string's properties are not what
18983 we want, translate the string. Also, if the string
18984 is risky, do that anyway. */
18986 if (NILP (Fequal (props
, oprops
)) || risky
)
18988 /* If the starting string has properties,
18989 merge the specified ones onto the existing ones. */
18990 if (! NILP (oprops
) && !risky
)
18994 oprops
= Fcopy_sequence (oprops
);
18996 while (CONSP (tem
))
18998 oprops
= Fplist_put (oprops
, XCAR (tem
),
18999 XCAR (XCDR (tem
)));
19000 tem
= XCDR (XCDR (tem
));
19005 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
19006 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
19008 /* AELT is what we want. Move it to the front
19009 without consing. */
19011 mode_line_proptrans_alist
19012 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
19018 /* If AELT has the wrong props, it is useless.
19019 so get rid of it. */
19021 mode_line_proptrans_alist
19022 = Fdelq (aelt
, mode_line_proptrans_alist
);
19024 elt
= Fcopy_sequence (elt
);
19025 Fset_text_properties (make_number (0), Flength (elt
),
19027 /* Add this item to mode_line_proptrans_alist. */
19028 mode_line_proptrans_alist
19029 = Fcons (Fcons (elt
, props
),
19030 mode_line_proptrans_alist
);
19031 /* Truncate mode_line_proptrans_alist
19032 to at most 50 elements. */
19033 tem
= Fnthcdr (make_number (50),
19034 mode_line_proptrans_alist
);
19036 XSETCDR (tem
, Qnil
);
19045 prec
= precision
- n
;
19046 switch (mode_line_target
)
19048 case MODE_LINE_NOPROP
:
19049 case MODE_LINE_TITLE
:
19050 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
19052 case MODE_LINE_STRING
:
19053 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
19055 case MODE_LINE_DISPLAY
:
19056 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
19057 0, prec
, 0, STRING_MULTIBYTE (elt
));
19064 /* Handle the non-literal case. */
19066 while ((precision
<= 0 || n
< precision
)
19067 && SREF (elt
, offset
) != 0
19068 && (mode_line_target
!= MODE_LINE_DISPLAY
19069 || it
->current_x
< it
->last_visible_x
))
19071 EMACS_INT last_offset
= offset
;
19073 /* Advance to end of string or next format specifier. */
19074 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
19077 if (offset
- 1 != last_offset
)
19079 EMACS_INT nchars
, nbytes
;
19081 /* Output to end of string or up to '%'. Field width
19082 is length of string. Don't output more than
19083 PRECISION allows us. */
19086 prec
= c_string_width (SDATA (elt
) + last_offset
,
19087 offset
- last_offset
, precision
- n
,
19090 switch (mode_line_target
)
19092 case MODE_LINE_NOPROP
:
19093 case MODE_LINE_TITLE
:
19094 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
19096 case MODE_LINE_STRING
:
19098 EMACS_INT bytepos
= last_offset
;
19099 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
19100 EMACS_INT endpos
= (precision
<= 0
19101 ? string_byte_to_char (elt
, offset
)
19102 : charpos
+ nchars
);
19104 n
+= store_mode_line_string (NULL
,
19105 Fsubstring (elt
, make_number (charpos
),
19106 make_number (endpos
)),
19110 case MODE_LINE_DISPLAY
:
19112 EMACS_INT bytepos
= last_offset
;
19113 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
19115 if (precision
<= 0)
19116 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
19117 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
19119 STRING_MULTIBYTE (elt
));
19124 else /* c == '%' */
19126 EMACS_INT percent_position
= offset
;
19128 /* Get the specified minimum width. Zero means
19131 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
19132 field
= field
* 10 + c
- '0';
19134 /* Don't pad beyond the total padding allowed. */
19135 if (field_width
- n
> 0 && field
> field_width
- n
)
19136 field
= field_width
- n
;
19138 /* Note that either PRECISION <= 0 or N < PRECISION. */
19139 prec
= precision
- n
;
19142 n
+= display_mode_element (it
, depth
, field
, prec
,
19143 Vglobal_mode_string
, props
,
19148 EMACS_INT bytepos
, charpos
;
19150 Lisp_Object string
;
19152 bytepos
= percent_position
;
19153 charpos
= (STRING_MULTIBYTE (elt
)
19154 ? string_byte_to_char (elt
, bytepos
)
19156 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
19157 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
19159 switch (mode_line_target
)
19161 case MODE_LINE_NOPROP
:
19162 case MODE_LINE_TITLE
:
19163 n
+= store_mode_line_noprop (spec
, field
, prec
);
19165 case MODE_LINE_STRING
:
19167 int len
= strlen (spec
);
19168 Lisp_Object tem
= make_string (spec
, len
);
19169 props
= Ftext_properties_at (make_number (charpos
), elt
);
19170 /* Should only keep face property in props */
19171 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
19174 case MODE_LINE_DISPLAY
:
19176 int nglyphs_before
, nwritten
;
19178 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
19179 nwritten
= display_string (spec
, string
, elt
,
19184 /* Assign to the glyphs written above the
19185 string where the `%x' came from, position
19189 struct glyph
*glyph
19190 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
19194 for (i
= 0; i
< nwritten
; ++i
)
19196 glyph
[i
].object
= elt
;
19197 glyph
[i
].charpos
= charpos
;
19214 /* A symbol: process the value of the symbol recursively
19215 as if it appeared here directly. Avoid error if symbol void.
19216 Special case: if value of symbol is a string, output the string
19219 register Lisp_Object tem
;
19221 /* If the variable is not marked as risky to set
19222 then its contents are risky to use. */
19223 if (NILP (Fget (elt
, Qrisky_local_variable
)))
19226 tem
= Fboundp (elt
);
19229 tem
= Fsymbol_value (elt
);
19230 /* If value is a string, output that string literally:
19231 don't check for % within it. */
19235 if (!EQ (tem
, elt
))
19237 /* Give up right away for nil or t. */
19247 register Lisp_Object car
, tem
;
19249 /* A cons cell: five distinct cases.
19250 If first element is :eval or :propertize, do something special.
19251 If first element is a string or a cons, process all the elements
19252 and effectively concatenate them.
19253 If first element is a negative number, truncate displaying cdr to
19254 at most that many characters. If positive, pad (with spaces)
19255 to at least that many characters.
19256 If first element is a symbol, process the cadr or caddr recursively
19257 according to whether the symbol's value is non-nil or nil. */
19259 if (EQ (car
, QCeval
))
19261 /* An element of the form (:eval FORM) means evaluate FORM
19262 and use the result as mode line elements. */
19267 if (CONSP (XCDR (elt
)))
19270 spec
= safe_eval (XCAR (XCDR (elt
)));
19271 n
+= display_mode_element (it
, depth
, field_width
- n
,
19272 precision
- n
, spec
, props
,
19276 else if (EQ (car
, QCpropertize
))
19278 /* An element of the form (:propertize ELT PROPS...)
19279 means display ELT but applying properties PROPS. */
19284 if (CONSP (XCDR (elt
)))
19285 n
+= display_mode_element (it
, depth
, field_width
- n
,
19286 precision
- n
, XCAR (XCDR (elt
)),
19287 XCDR (XCDR (elt
)), risky
);
19289 else if (SYMBOLP (car
))
19291 tem
= Fboundp (car
);
19295 /* elt is now the cdr, and we know it is a cons cell.
19296 Use its car if CAR has a non-nil value. */
19299 tem
= Fsymbol_value (car
);
19306 /* Symbol's value is nil (or symbol is unbound)
19307 Get the cddr of the original list
19308 and if possible find the caddr and use that. */
19312 else if (!CONSP (elt
))
19317 else if (INTEGERP (car
))
19319 register int lim
= XINT (car
);
19323 /* Negative int means reduce maximum width. */
19324 if (precision
<= 0)
19327 precision
= min (precision
, -lim
);
19331 /* Padding specified. Don't let it be more than
19332 current maximum. */
19334 lim
= min (precision
, lim
);
19336 /* If that's more padding than already wanted, queue it.
19337 But don't reduce padding already specified even if
19338 that is beyond the current truncation point. */
19339 field_width
= max (lim
, field_width
);
19343 else if (STRINGP (car
) || CONSP (car
))
19345 Lisp_Object halftail
= elt
;
19349 && (precision
<= 0 || n
< precision
))
19351 n
+= display_mode_element (it
, depth
,
19352 /* Do padding only after the last
19353 element in the list. */
19354 (! CONSP (XCDR (elt
))
19357 precision
- n
, XCAR (elt
),
19361 if ((len
& 1) == 0)
19362 halftail
= XCDR (halftail
);
19363 /* Check for cycle. */
19364 if (EQ (halftail
, elt
))
19373 elt
= build_string ("*invalid*");
19377 /* Pad to FIELD_WIDTH. */
19378 if (field_width
> 0 && n
< field_width
)
19380 switch (mode_line_target
)
19382 case MODE_LINE_NOPROP
:
19383 case MODE_LINE_TITLE
:
19384 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
19386 case MODE_LINE_STRING
:
19387 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
19389 case MODE_LINE_DISPLAY
:
19390 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
19399 /* Store a mode-line string element in mode_line_string_list.
19401 If STRING is non-null, display that C string. Otherwise, the Lisp
19402 string LISP_STRING is displayed.
19404 FIELD_WIDTH is the minimum number of output glyphs to produce.
19405 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19406 with spaces. FIELD_WIDTH <= 0 means don't pad.
19408 PRECISION is the maximum number of characters to output from
19409 STRING. PRECISION <= 0 means don't truncate the string.
19411 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
19412 properties to the string.
19414 PROPS are the properties to add to the string.
19415 The mode_line_string_face face property is always added to the string.
19419 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
19420 int field_width
, int precision
, Lisp_Object props
)
19425 if (string
!= NULL
)
19427 len
= strlen (string
);
19428 if (precision
> 0 && len
> precision
)
19430 lisp_string
= make_string (string
, len
);
19432 props
= mode_line_string_face_prop
;
19433 else if (!NILP (mode_line_string_face
))
19435 Lisp_Object face
= Fplist_get (props
, Qface
);
19436 props
= Fcopy_sequence (props
);
19438 face
= mode_line_string_face
;
19440 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19441 props
= Fplist_put (props
, Qface
, face
);
19443 Fadd_text_properties (make_number (0), make_number (len
),
19444 props
, lisp_string
);
19448 len
= XFASTINT (Flength (lisp_string
));
19449 if (precision
> 0 && len
> precision
)
19452 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
19455 if (!NILP (mode_line_string_face
))
19459 props
= Ftext_properties_at (make_number (0), lisp_string
);
19460 face
= Fplist_get (props
, Qface
);
19462 face
= mode_line_string_face
;
19464 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19465 props
= Fcons (Qface
, Fcons (face
, Qnil
));
19467 lisp_string
= Fcopy_sequence (lisp_string
);
19470 Fadd_text_properties (make_number (0), make_number (len
),
19471 props
, lisp_string
);
19476 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19480 if (field_width
> len
)
19482 field_width
-= len
;
19483 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
19485 Fadd_text_properties (make_number (0), make_number (field_width
),
19486 props
, lisp_string
);
19487 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19495 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
19497 doc
: /* Format a string out of a mode line format specification.
19498 First arg FORMAT specifies the mode line format (see `mode-line-format'
19499 for details) to use.
19501 By default, the format is evaluated for the currently selected window.
19503 Optional second arg FACE specifies the face property to put on all
19504 characters for which no face is specified. The value nil means the
19505 default face. The value t means whatever face the window's mode line
19506 currently uses (either `mode-line' or `mode-line-inactive',
19507 depending on whether the window is the selected window or not).
19508 An integer value means the value string has no text
19511 Optional third and fourth args WINDOW and BUFFER specify the window
19512 and buffer to use as the context for the formatting (defaults
19513 are the selected window and the WINDOW's buffer). */)
19514 (Lisp_Object format
, Lisp_Object face
,
19515 Lisp_Object window
, Lisp_Object buffer
)
19520 struct buffer
*old_buffer
= NULL
;
19522 int no_props
= INTEGERP (face
);
19523 int count
= SPECPDL_INDEX ();
19525 int string_start
= 0;
19528 window
= selected_window
;
19529 CHECK_WINDOW (window
);
19530 w
= XWINDOW (window
);
19533 buffer
= w
->buffer
;
19534 CHECK_BUFFER (buffer
);
19536 /* Make formatting the modeline a non-op when noninteractive, otherwise
19537 there will be problems later caused by a partially initialized frame. */
19538 if (NILP (format
) || noninteractive
)
19539 return empty_unibyte_string
;
19544 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
19545 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
19546 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
19547 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
19548 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
19549 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
19550 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
19553 if (XBUFFER (buffer
) != current_buffer
)
19554 old_buffer
= current_buffer
;
19556 /* Save things including mode_line_proptrans_alist,
19557 and set that to nil so that we don't alter the outer value. */
19558 record_unwind_protect (unwind_format_mode_line
,
19559 format_mode_line_unwind_data
19560 (old_buffer
, selected_window
, 1));
19561 mode_line_proptrans_alist
= Qnil
;
19563 Fselect_window (window
, Qt
);
19565 set_buffer_internal_1 (XBUFFER (buffer
));
19567 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19571 mode_line_target
= MODE_LINE_NOPROP
;
19572 mode_line_string_face_prop
= Qnil
;
19573 mode_line_string_list
= Qnil
;
19574 string_start
= MODE_LINE_NOPROP_LEN (0);
19578 mode_line_target
= MODE_LINE_STRING
;
19579 mode_line_string_list
= Qnil
;
19580 mode_line_string_face
= face
;
19581 mode_line_string_face_prop
19582 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
19585 push_kboard (FRAME_KBOARD (it
.f
));
19586 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19591 len
= MODE_LINE_NOPROP_LEN (string_start
);
19592 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
19596 mode_line_string_list
= Fnreverse (mode_line_string_list
);
19597 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
19598 empty_unibyte_string
);
19601 unbind_to (count
, Qnil
);
19605 /* Write a null-terminated, right justified decimal representation of
19606 the positive integer D to BUF using a minimal field width WIDTH. */
19609 pint2str (register char *buf
, register int width
, register EMACS_INT d
)
19611 register char *p
= buf
;
19619 *p
++ = d
% 10 + '0';
19624 for (width
-= (int) (p
- buf
); width
> 0; --width
)
19635 /* Write a null-terminated, right justified decimal and "human
19636 readable" representation of the nonnegative integer D to BUF using
19637 a minimal field width WIDTH. D should be smaller than 999.5e24. */
19639 static const char power_letter
[] =
19653 pint2hrstr (char *buf
, int width
, EMACS_INT d
)
19655 /* We aim to represent the nonnegative integer D as
19656 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
19657 EMACS_INT quotient
= d
;
19659 /* -1 means: do not use TENTHS. */
19663 /* Length of QUOTIENT.TENTHS as a string. */
19669 if (1000 <= quotient
)
19671 /* Scale to the appropriate EXPONENT. */
19674 remainder
= quotient
% 1000;
19678 while (1000 <= quotient
);
19680 /* Round to nearest and decide whether to use TENTHS or not. */
19683 tenths
= remainder
/ 100;
19684 if (50 <= remainder
% 100)
19691 if (quotient
== 10)
19699 if (500 <= remainder
)
19701 if (quotient
< 999)
19712 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
19713 if (tenths
== -1 && quotient
<= 99)
19720 p
= psuffix
= buf
+ max (width
, length
);
19722 /* Print EXPONENT. */
19723 *psuffix
++ = power_letter
[exponent
];
19726 /* Print TENTHS. */
19729 *--p
= '0' + tenths
;
19733 /* Print QUOTIENT. */
19736 int digit
= quotient
% 10;
19737 *--p
= '0' + digit
;
19739 while ((quotient
/= 10) != 0);
19741 /* Print leading spaces. */
19746 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19747 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19748 type of CODING_SYSTEM. Return updated pointer into BUF. */
19750 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19753 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
19756 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
19757 const unsigned char *eol_str
;
19759 /* The EOL conversion we are using. */
19760 Lisp_Object eoltype
;
19762 val
= CODING_SYSTEM_SPEC (coding_system
);
19765 if (!VECTORP (val
)) /* Not yet decided. */
19770 eoltype
= eol_mnemonic_undecided
;
19771 /* Don't mention EOL conversion if it isn't decided. */
19776 Lisp_Object eolvalue
;
19778 attrs
= AREF (val
, 0);
19779 eolvalue
= AREF (val
, 2);
19782 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19786 /* The EOL conversion that is normal on this system. */
19788 if (NILP (eolvalue
)) /* Not yet decided. */
19789 eoltype
= eol_mnemonic_undecided
;
19790 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19791 eoltype
= eol_mnemonic_undecided
;
19792 else /* eolvalue is Qunix, Qdos, or Qmac. */
19793 eoltype
= (EQ (eolvalue
, Qunix
)
19794 ? eol_mnemonic_unix
19795 : (EQ (eolvalue
, Qdos
) == 1
19796 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19802 /* Mention the EOL conversion if it is not the usual one. */
19803 if (STRINGP (eoltype
))
19805 eol_str
= SDATA (eoltype
);
19806 eol_str_len
= SBYTES (eoltype
);
19808 else if (CHARACTERP (eoltype
))
19810 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19811 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19816 eol_str
= invalid_eol_type
;
19817 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19819 memcpy (buf
, eol_str
, eol_str_len
);
19820 buf
+= eol_str_len
;
19826 /* Return a string for the output of a mode line %-spec for window W,
19827 generated by character C. FIELD_WIDTH > 0 means pad the string
19828 returned with spaces to that value. Return a Lisp string in
19829 *STRING if the resulting string is taken from that Lisp string.
19831 Note we operate on the current buffer for most purposes,
19832 the exception being w->base_line_pos. */
19834 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19836 static const char *
19837 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
19838 Lisp_Object
*string
)
19841 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19842 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19843 struct buffer
*b
= current_buffer
;
19851 if (!NILP (BVAR (b
, read_only
)))
19853 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19858 /* This differs from %* only for a modified read-only buffer. */
19859 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19861 if (!NILP (BVAR (b
, read_only
)))
19866 /* This differs from %* in ignoring read-only-ness. */
19867 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19879 if (command_loop_level
> 5)
19881 p
= decode_mode_spec_buf
;
19882 for (i
= 0; i
< command_loop_level
; i
++)
19885 return decode_mode_spec_buf
;
19893 if (command_loop_level
> 5)
19895 p
= decode_mode_spec_buf
;
19896 for (i
= 0; i
< command_loop_level
; i
++)
19899 return decode_mode_spec_buf
;
19906 /* Let lots_of_dashes be a string of infinite length. */
19907 if (mode_line_target
== MODE_LINE_NOPROP
||
19908 mode_line_target
== MODE_LINE_STRING
)
19910 if (field_width
<= 0
19911 || field_width
> sizeof (lots_of_dashes
))
19913 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
19914 decode_mode_spec_buf
[i
] = '-';
19915 decode_mode_spec_buf
[i
] = '\0';
19916 return decode_mode_spec_buf
;
19919 return lots_of_dashes
;
19923 obj
= BVAR (b
, name
);
19927 /* %c and %l are ignored in `frame-title-format'.
19928 (In redisplay_internal, the frame title is drawn _before_ the
19929 windows are updated, so the stuff which depends on actual
19930 window contents (such as %l) may fail to render properly, or
19931 even crash emacs.) */
19932 if (mode_line_target
== MODE_LINE_TITLE
)
19936 EMACS_INT col
= current_column ();
19937 w
->column_number_displayed
= make_number (col
);
19938 pint2str (decode_mode_spec_buf
, field_width
, col
);
19939 return decode_mode_spec_buf
;
19943 #ifndef SYSTEM_MALLOC
19945 if (NILP (Vmemory_full
))
19948 return "!MEM FULL! ";
19955 /* %F displays the frame name. */
19956 if (!NILP (f
->title
))
19957 return SSDATA (f
->title
);
19958 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
19959 return SSDATA (f
->name
);
19963 obj
= BVAR (b
, filename
);
19968 EMACS_INT size
= ZV
- BEGV
;
19969 pint2str (decode_mode_spec_buf
, field_width
, size
);
19970 return decode_mode_spec_buf
;
19975 EMACS_INT size
= ZV
- BEGV
;
19976 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
19977 return decode_mode_spec_buf
;
19982 EMACS_INT startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
19983 EMACS_INT topline
, nlines
, height
;
19986 /* %c and %l are ignored in `frame-title-format'. */
19987 if (mode_line_target
== MODE_LINE_TITLE
)
19990 startpos
= XMARKER (w
->start
)->charpos
;
19991 startpos_byte
= marker_byte_position (w
->start
);
19992 height
= WINDOW_TOTAL_LINES (w
);
19994 /* If we decided that this buffer isn't suitable for line numbers,
19995 don't forget that too fast. */
19996 if (EQ (w
->base_line_pos
, w
->buffer
))
19998 /* But do forget it, if the window shows a different buffer now. */
19999 else if (BUFFERP (w
->base_line_pos
))
20000 w
->base_line_pos
= Qnil
;
20002 /* If the buffer is very big, don't waste time. */
20003 if (INTEGERP (Vline_number_display_limit
)
20004 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
20006 w
->base_line_pos
= Qnil
;
20007 w
->base_line_number
= Qnil
;
20011 if (INTEGERP (w
->base_line_number
)
20012 && INTEGERP (w
->base_line_pos
)
20013 && XFASTINT (w
->base_line_pos
) <= startpos
)
20015 line
= XFASTINT (w
->base_line_number
);
20016 linepos
= XFASTINT (w
->base_line_pos
);
20017 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
20022 linepos
= BUF_BEGV (b
);
20023 linepos_byte
= BUF_BEGV_BYTE (b
);
20026 /* Count lines from base line to window start position. */
20027 nlines
= display_count_lines (linepos_byte
,
20031 topline
= nlines
+ line
;
20033 /* Determine a new base line, if the old one is too close
20034 or too far away, or if we did not have one.
20035 "Too close" means it's plausible a scroll-down would
20036 go back past it. */
20037 if (startpos
== BUF_BEGV (b
))
20039 w
->base_line_number
= make_number (topline
);
20040 w
->base_line_pos
= make_number (BUF_BEGV (b
));
20042 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
20043 || linepos
== BUF_BEGV (b
))
20045 EMACS_INT limit
= BUF_BEGV (b
);
20046 EMACS_INT limit_byte
= BUF_BEGV_BYTE (b
);
20047 EMACS_INT position
;
20048 EMACS_INT distance
=
20049 (height
* 2 + 30) * line_number_display_limit_width
;
20051 if (startpos
- distance
> limit
)
20053 limit
= startpos
- distance
;
20054 limit_byte
= CHAR_TO_BYTE (limit
);
20057 nlines
= display_count_lines (startpos_byte
,
20059 - (height
* 2 + 30),
20061 /* If we couldn't find the lines we wanted within
20062 line_number_display_limit_width chars per line,
20063 give up on line numbers for this window. */
20064 if (position
== limit_byte
&& limit
== startpos
- distance
)
20066 w
->base_line_pos
= w
->buffer
;
20067 w
->base_line_number
= Qnil
;
20071 w
->base_line_number
= make_number (topline
- nlines
);
20072 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
20075 /* Now count lines from the start pos to point. */
20076 nlines
= display_count_lines (startpos_byte
,
20077 PT_BYTE
, PT
, &junk
);
20079 /* Record that we did display the line number. */
20080 line_number_displayed
= 1;
20082 /* Make the string to show. */
20083 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
20084 return decode_mode_spec_buf
;
20087 char* p
= decode_mode_spec_buf
;
20088 int pad
= field_width
- 2;
20094 return decode_mode_spec_buf
;
20100 obj
= BVAR (b
, mode_name
);
20104 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
20110 EMACS_INT pos
= marker_position (w
->start
);
20111 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
20113 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
20115 if (pos
<= BUF_BEGV (b
))
20120 else if (pos
<= BUF_BEGV (b
))
20124 if (total
> 1000000)
20125 /* Do it differently for a large value, to avoid overflow. */
20126 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
20128 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
20129 /* We can't normally display a 3-digit number,
20130 so get us a 2-digit number that is close. */
20133 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
20134 return decode_mode_spec_buf
;
20138 /* Display percentage of size above the bottom of the screen. */
20141 EMACS_INT toppos
= marker_position (w
->start
);
20142 EMACS_INT botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
20143 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
20145 if (botpos
>= BUF_ZV (b
))
20147 if (toppos
<= BUF_BEGV (b
))
20154 if (total
> 1000000)
20155 /* Do it differently for a large value, to avoid overflow. */
20156 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
20158 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
20159 /* We can't normally display a 3-digit number,
20160 so get us a 2-digit number that is close. */
20163 if (toppos
<= BUF_BEGV (b
))
20164 sprintf (decode_mode_spec_buf
, "Top%2"pI
"d%%", total
);
20166 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
20167 return decode_mode_spec_buf
;
20172 /* status of process */
20173 obj
= Fget_buffer_process (Fcurrent_buffer ());
20175 return "no process";
20177 obj
= Fsymbol_name (Fprocess_status (obj
));
20183 int count
= inhibit_garbage_collection ();
20184 Lisp_Object val
= call1 (intern ("file-remote-p"),
20185 BVAR (current_buffer
, directory
));
20186 unbind_to (count
, Qnil
);
20194 case 't': /* indicate TEXT or BINARY */
20198 /* coding-system (not including end-of-line format) */
20200 /* coding-system (including end-of-line type) */
20202 int eol_flag
= (c
== 'Z');
20203 char *p
= decode_mode_spec_buf
;
20205 if (! FRAME_WINDOW_P (f
))
20207 /* No need to mention EOL here--the terminal never needs
20208 to do EOL conversion. */
20209 p
= decode_mode_spec_coding (CODING_ID_NAME
20210 (FRAME_KEYBOARD_CODING (f
)->id
),
20212 p
= decode_mode_spec_coding (CODING_ID_NAME
20213 (FRAME_TERMINAL_CODING (f
)->id
),
20216 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
20219 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
20220 #ifdef subprocesses
20221 obj
= Fget_buffer_process (Fcurrent_buffer ());
20222 if (PROCESSP (obj
))
20224 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
20226 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
20229 #endif /* subprocesses */
20232 return decode_mode_spec_buf
;
20239 return SSDATA (obj
);
20246 /* Count up to COUNT lines starting from START_BYTE.
20247 But don't go beyond LIMIT_BYTE.
20248 Return the number of lines thus found (always nonnegative).
20250 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
20253 display_count_lines (EMACS_INT start_byte
,
20254 EMACS_INT limit_byte
, EMACS_INT count
,
20255 EMACS_INT
*byte_pos_ptr
)
20257 register unsigned char *cursor
;
20258 unsigned char *base
;
20260 register EMACS_INT ceiling
;
20261 register unsigned char *ceiling_addr
;
20262 EMACS_INT orig_count
= count
;
20264 /* If we are not in selective display mode,
20265 check only for newlines. */
20266 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
20267 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
20271 while (start_byte
< limit_byte
)
20273 ceiling
= BUFFER_CEILING_OF (start_byte
);
20274 ceiling
= min (limit_byte
- 1, ceiling
);
20275 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
20276 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
20279 if (selective_display
)
20280 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
20283 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
20286 if (cursor
!= ceiling_addr
)
20290 start_byte
+= cursor
- base
+ 1;
20291 *byte_pos_ptr
= start_byte
;
20295 if (++cursor
== ceiling_addr
)
20301 start_byte
+= cursor
- base
;
20306 while (start_byte
> limit_byte
)
20308 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
20309 ceiling
= max (limit_byte
, ceiling
);
20310 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
20311 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
20314 if (selective_display
)
20315 while (--cursor
!= ceiling_addr
20316 && *cursor
!= '\n' && *cursor
!= 015)
20319 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
20322 if (cursor
!= ceiling_addr
)
20326 start_byte
+= cursor
- base
+ 1;
20327 *byte_pos_ptr
= start_byte
;
20328 /* When scanning backwards, we should
20329 not count the newline posterior to which we stop. */
20330 return - orig_count
- 1;
20336 /* Here we add 1 to compensate for the last decrement
20337 of CURSOR, which took it past the valid range. */
20338 start_byte
+= cursor
- base
+ 1;
20342 *byte_pos_ptr
= limit_byte
;
20345 return - orig_count
+ count
;
20346 return orig_count
- count
;
20352 /***********************************************************************
20354 ***********************************************************************/
20356 /* Display a NUL-terminated string, starting with index START.
20358 If STRING is non-null, display that C string. Otherwise, the Lisp
20359 string LISP_STRING is displayed. There's a case that STRING is
20360 non-null and LISP_STRING is not nil. It means STRING is a string
20361 data of LISP_STRING. In that case, we display LISP_STRING while
20362 ignoring its text properties.
20364 If FACE_STRING is not nil, FACE_STRING_POS is a position in
20365 FACE_STRING. Display STRING or LISP_STRING with the face at
20366 FACE_STRING_POS in FACE_STRING:
20368 Display the string in the environment given by IT, but use the
20369 standard display table, temporarily.
20371 FIELD_WIDTH is the minimum number of output glyphs to produce.
20372 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20373 with spaces. If STRING has more characters, more than FIELD_WIDTH
20374 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
20376 PRECISION is the maximum number of characters to output from
20377 STRING. PRECISION < 0 means don't truncate the string.
20379 This is roughly equivalent to printf format specifiers:
20381 FIELD_WIDTH PRECISION PRINTF
20382 ----------------------------------------
20388 MULTIBYTE zero means do not display multibyte chars, > 0 means do
20389 display them, and < 0 means obey the current buffer's value of
20390 enable_multibyte_characters.
20392 Value is the number of columns displayed. */
20395 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
20396 EMACS_INT face_string_pos
, EMACS_INT start
, struct it
*it
,
20397 int field_width
, int precision
, int max_x
, int multibyte
)
20399 int hpos_at_start
= it
->hpos
;
20400 int saved_face_id
= it
->face_id
;
20401 struct glyph_row
*row
= it
->glyph_row
;
20402 EMACS_INT it_charpos
;
20404 /* Initialize the iterator IT for iteration over STRING beginning
20405 with index START. */
20406 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
20407 precision
, field_width
, multibyte
);
20408 if (string
&& STRINGP (lisp_string
))
20409 /* LISP_STRING is the one returned by decode_mode_spec. We should
20410 ignore its text properties. */
20411 it
->stop_charpos
= it
->end_charpos
;
20413 /* If displaying STRING, set up the face of the iterator from
20414 FACE_STRING, if that's given. */
20415 if (STRINGP (face_string
))
20421 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
20422 0, it
->region_beg_charpos
,
20423 it
->region_end_charpos
,
20424 &endptr
, it
->base_face_id
, 0);
20425 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20426 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
20429 /* Set max_x to the maximum allowed X position. Don't let it go
20430 beyond the right edge of the window. */
20432 max_x
= it
->last_visible_x
;
20434 max_x
= min (max_x
, it
->last_visible_x
);
20436 /* Skip over display elements that are not visible. because IT->w is
20438 if (it
->current_x
< it
->first_visible_x
)
20439 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
20440 MOVE_TO_POS
| MOVE_TO_X
);
20442 row
->ascent
= it
->max_ascent
;
20443 row
->height
= it
->max_ascent
+ it
->max_descent
;
20444 row
->phys_ascent
= it
->max_phys_ascent
;
20445 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20446 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20448 if (STRINGP (it
->string
))
20449 it_charpos
= IT_STRING_CHARPOS (*it
);
20451 it_charpos
= IT_CHARPOS (*it
);
20453 /* This condition is for the case that we are called with current_x
20454 past last_visible_x. */
20455 while (it
->current_x
< max_x
)
20457 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
20459 /* Get the next display element. */
20460 if (!get_next_display_element (it
))
20463 /* Produce glyphs. */
20464 x_before
= it
->current_x
;
20465 n_glyphs_before
= row
->used
[TEXT_AREA
];
20466 PRODUCE_GLYPHS (it
);
20468 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
20471 while (i
< nglyphs
)
20473 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20475 if (it
->line_wrap
!= TRUNCATE
20476 && x
+ glyph
->pixel_width
> max_x
)
20478 /* End of continued line or max_x reached. */
20479 if (CHAR_GLYPH_PADDING_P (*glyph
))
20481 /* A wide character is unbreakable. */
20482 if (row
->reversed_p
)
20483 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20484 - n_glyphs_before
);
20485 row
->used
[TEXT_AREA
] = n_glyphs_before
;
20486 it
->current_x
= x_before
;
20490 if (row
->reversed_p
)
20491 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20492 - (n_glyphs_before
+ i
));
20493 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20498 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
20500 /* Glyph is at least partially visible. */
20502 if (x
< it
->first_visible_x
)
20503 row
->x
= x
- it
->first_visible_x
;
20507 /* Glyph is off the left margin of the display area.
20508 Should not happen. */
20512 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20513 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20514 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20515 row
->phys_height
= max (row
->phys_height
,
20516 it
->max_phys_ascent
+ it
->max_phys_descent
);
20517 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20518 it
->max_extra_line_spacing
);
20519 x
+= glyph
->pixel_width
;
20523 /* Stop if max_x reached. */
20527 /* Stop at line ends. */
20528 if (ITERATOR_AT_END_OF_LINE_P (it
))
20530 it
->continuation_lines_width
= 0;
20534 set_iterator_to_next (it
, 1);
20535 if (STRINGP (it
->string
))
20536 it_charpos
= IT_STRING_CHARPOS (*it
);
20538 it_charpos
= IT_CHARPOS (*it
);
20540 /* Stop if truncating at the right edge. */
20541 if (it
->line_wrap
== TRUNCATE
20542 && it
->current_x
>= it
->last_visible_x
)
20544 /* Add truncation mark, but don't do it if the line is
20545 truncated at a padding space. */
20546 if (it_charpos
< it
->string_nchars
)
20548 if (!FRAME_WINDOW_P (it
->f
))
20552 if (it
->current_x
> it
->last_visible_x
)
20554 if (!row
->reversed_p
)
20556 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
20557 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20562 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
20563 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20565 unproduce_glyphs (it
, ii
+ 1);
20566 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
20568 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
20570 row
->used
[TEXT_AREA
] = ii
;
20571 produce_special_glyphs (it
, IT_TRUNCATION
);
20574 produce_special_glyphs (it
, IT_TRUNCATION
);
20576 row
->truncated_on_right_p
= 1;
20582 /* Maybe insert a truncation at the left. */
20583 if (it
->first_visible_x
20586 if (!FRAME_WINDOW_P (it
->f
))
20587 insert_left_trunc_glyphs (it
);
20588 row
->truncated_on_left_p
= 1;
20591 it
->face_id
= saved_face_id
;
20593 /* Value is number of columns displayed. */
20594 return it
->hpos
- hpos_at_start
;
20599 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
20600 appears as an element of LIST or as the car of an element of LIST.
20601 If PROPVAL is a list, compare each element against LIST in that
20602 way, and return 1/2 if any element of PROPVAL is found in LIST.
20603 Otherwise return 0. This function cannot quit.
20604 The return value is 2 if the text is invisible but with an ellipsis
20605 and 1 if it's invisible and without an ellipsis. */
20608 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
20610 register Lisp_Object tail
, proptail
;
20612 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20614 register Lisp_Object tem
;
20616 if (EQ (propval
, tem
))
20618 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
20619 return NILP (XCDR (tem
)) ? 1 : 2;
20622 if (CONSP (propval
))
20624 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
20626 Lisp_Object propelt
;
20627 propelt
= XCAR (proptail
);
20628 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20630 register Lisp_Object tem
;
20632 if (EQ (propelt
, tem
))
20634 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
20635 return NILP (XCDR (tem
)) ? 1 : 2;
20643 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
20644 doc
: /* Non-nil if the property makes the text invisible.
20645 POS-OR-PROP can be a marker or number, in which case it is taken to be
20646 a position in the current buffer and the value of the `invisible' property
20647 is checked; or it can be some other value, which is then presumed to be the
20648 value of the `invisible' property of the text of interest.
20649 The non-nil value returned can be t for truly invisible text or something
20650 else if the text is replaced by an ellipsis. */)
20651 (Lisp_Object pos_or_prop
)
20654 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
20655 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
20657 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
20658 return (invis
== 0 ? Qnil
20660 : make_number (invis
));
20663 /* Calculate a width or height in pixels from a specification using
20664 the following elements:
20667 NUM - a (fractional) multiple of the default font width/height
20668 (NUM) - specifies exactly NUM pixels
20669 UNIT - a fixed number of pixels, see below.
20670 ELEMENT - size of a display element in pixels, see below.
20671 (NUM . SPEC) - equals NUM * SPEC
20672 (+ SPEC SPEC ...) - add pixel values
20673 (- SPEC SPEC ...) - subtract pixel values
20674 (- SPEC) - negate pixel value
20677 INT or FLOAT - a number constant
20678 SYMBOL - use symbol's (buffer local) variable binding.
20681 in - pixels per inch *)
20682 mm - pixels per 1/1000 meter *)
20683 cm - pixels per 1/100 meter *)
20684 width - width of current font in pixels.
20685 height - height of current font in pixels.
20687 *) using the ratio(s) defined in display-pixels-per-inch.
20691 left-fringe - left fringe width in pixels
20692 right-fringe - right fringe width in pixels
20694 left-margin - left margin width in pixels
20695 right-margin - right margin width in pixels
20697 scroll-bar - scroll-bar area width in pixels
20701 Pixels corresponding to 5 inches:
20704 Total width of non-text areas on left side of window (if scroll-bar is on left):
20705 '(space :width (+ left-fringe left-margin scroll-bar))
20707 Align to first text column (in header line):
20708 '(space :align-to 0)
20710 Align to middle of text area minus half the width of variable `my-image'
20711 containing a loaded image:
20712 '(space :align-to (0.5 . (- text my-image)))
20714 Width of left margin minus width of 1 character in the default font:
20715 '(space :width (- left-margin 1))
20717 Width of left margin minus width of 2 characters in the current font:
20718 '(space :width (- left-margin (2 . width)))
20720 Center 1 character over left-margin (in header line):
20721 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
20723 Different ways to express width of left fringe plus left margin minus one pixel:
20724 '(space :width (- (+ left-fringe left-margin) (1)))
20725 '(space :width (+ left-fringe left-margin (- (1))))
20726 '(space :width (+ left-fringe left-margin (-1)))
20730 #define NUMVAL(X) \
20731 ((INTEGERP (X) || FLOATP (X)) \
20736 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
20737 struct font
*font
, int width_p
, int *align_to
)
20741 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20742 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20745 return OK_PIXELS (0);
20747 xassert (FRAME_LIVE_P (it
->f
));
20749 if (SYMBOLP (prop
))
20751 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20753 char *unit
= SSDATA (SYMBOL_NAME (prop
));
20755 if (unit
[0] == 'i' && unit
[1] == 'n')
20757 else if (unit
[0] == 'm' && unit
[1] == 'm')
20759 else if (unit
[0] == 'c' && unit
[1] == 'm')
20766 #ifdef HAVE_WINDOW_SYSTEM
20767 if (FRAME_WINDOW_P (it
->f
)
20769 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20770 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20772 return OK_PIXELS (ppi
/ pixels
);
20775 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20776 || (CONSP (Vdisplay_pixels_per_inch
)
20778 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20779 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20781 return OK_PIXELS (ppi
/ pixels
);
20787 #ifdef HAVE_WINDOW_SYSTEM
20788 if (EQ (prop
, Qheight
))
20789 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20790 if (EQ (prop
, Qwidth
))
20791 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20793 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20794 return OK_PIXELS (1);
20797 if (EQ (prop
, Qtext
))
20798 return OK_PIXELS (width_p
20799 ? window_box_width (it
->w
, TEXT_AREA
)
20800 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20802 if (align_to
&& *align_to
< 0)
20805 if (EQ (prop
, Qleft
))
20806 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20807 if (EQ (prop
, Qright
))
20808 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20809 if (EQ (prop
, Qcenter
))
20810 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20811 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20812 if (EQ (prop
, Qleft_fringe
))
20813 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20814 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20815 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20816 if (EQ (prop
, Qright_fringe
))
20817 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20818 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20819 : window_box_right_offset (it
->w
, TEXT_AREA
));
20820 if (EQ (prop
, Qleft_margin
))
20821 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20822 if (EQ (prop
, Qright_margin
))
20823 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20824 if (EQ (prop
, Qscroll_bar
))
20825 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20827 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20828 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20829 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20834 if (EQ (prop
, Qleft_fringe
))
20835 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20836 if (EQ (prop
, Qright_fringe
))
20837 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20838 if (EQ (prop
, Qleft_margin
))
20839 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20840 if (EQ (prop
, Qright_margin
))
20841 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20842 if (EQ (prop
, Qscroll_bar
))
20843 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20846 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20849 if (INTEGERP (prop
) || FLOATP (prop
))
20851 int base_unit
= (width_p
20852 ? FRAME_COLUMN_WIDTH (it
->f
)
20853 : FRAME_LINE_HEIGHT (it
->f
));
20854 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
20859 Lisp_Object car
= XCAR (prop
);
20860 Lisp_Object cdr
= XCDR (prop
);
20864 #ifdef HAVE_WINDOW_SYSTEM
20865 if (FRAME_WINDOW_P (it
->f
)
20866 && valid_image_p (prop
))
20868 int id
= lookup_image (it
->f
, prop
);
20869 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
20871 return OK_PIXELS (width_p
? img
->width
: img
->height
);
20874 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
20880 while (CONSP (cdr
))
20882 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
20883 font
, width_p
, align_to
))
20886 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
20891 if (EQ (car
, Qminus
))
20893 return OK_PIXELS (pixels
);
20896 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
20899 if (INTEGERP (car
) || FLOATP (car
))
20902 pixels
= XFLOATINT (car
);
20904 return OK_PIXELS (pixels
);
20905 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
20906 font
, width_p
, align_to
))
20907 return OK_PIXELS (pixels
* fact
);
20918 /***********************************************************************
20920 ***********************************************************************/
20922 #ifdef HAVE_WINDOW_SYSTEM
20927 dump_glyph_string (s
)
20928 struct glyph_string
*s
;
20930 fprintf (stderr
, "glyph string\n");
20931 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
20932 s
->x
, s
->y
, s
->width
, s
->height
);
20933 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
20934 fprintf (stderr
, " hl = %d\n", s
->hl
);
20935 fprintf (stderr
, " left overhang = %d, right = %d\n",
20936 s
->left_overhang
, s
->right_overhang
);
20937 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
20938 fprintf (stderr
, " extends to end of line = %d\n",
20939 s
->extends_to_end_of_line_p
);
20940 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
20941 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
20944 #endif /* GLYPH_DEBUG */
20946 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
20947 of XChar2b structures for S; it can't be allocated in
20948 init_glyph_string because it must be allocated via `alloca'. W
20949 is the window on which S is drawn. ROW and AREA are the glyph row
20950 and area within the row from which S is constructed. START is the
20951 index of the first glyph structure covered by S. HL is a
20952 face-override for drawing S. */
20955 #define OPTIONAL_HDC(hdc) HDC hdc,
20956 #define DECLARE_HDC(hdc) HDC hdc;
20957 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
20958 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
20961 #ifndef OPTIONAL_HDC
20962 #define OPTIONAL_HDC(hdc)
20963 #define DECLARE_HDC(hdc)
20964 #define ALLOCATE_HDC(hdc, f)
20965 #define RELEASE_HDC(hdc, f)
20969 init_glyph_string (struct glyph_string
*s
,
20971 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
20972 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
20974 memset (s
, 0, sizeof *s
);
20976 s
->f
= XFRAME (w
->frame
);
20980 s
->display
= FRAME_X_DISPLAY (s
->f
);
20981 s
->window
= FRAME_X_WINDOW (s
->f
);
20982 s
->char2b
= char2b
;
20986 s
->first_glyph
= row
->glyphs
[area
] + start
;
20987 s
->height
= row
->height
;
20988 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
20989 s
->ybase
= s
->y
+ row
->ascent
;
20993 /* Append the list of glyph strings with head H and tail T to the list
20994 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
20997 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20998 struct glyph_string
*h
, struct glyph_string
*t
)
21012 /* Prepend the list of glyph strings with head H and tail T to the
21013 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
21017 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
21018 struct glyph_string
*h
, struct glyph_string
*t
)
21032 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
21033 Set *HEAD and *TAIL to the resulting list. */
21036 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
21037 struct glyph_string
*s
)
21039 s
->next
= s
->prev
= NULL
;
21040 append_glyph_string_lists (head
, tail
, s
, s
);
21044 /* Get face and two-byte form of character C in face FACE_ID on frame F.
21045 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
21046 make sure that X resources for the face returned are allocated.
21047 Value is a pointer to a realized face that is ready for display if
21048 DISPLAY_P is non-zero. */
21050 static INLINE
struct face
*
21051 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
21052 XChar2b
*char2b
, int display_p
)
21054 struct face
*face
= FACE_FROM_ID (f
, face_id
);
21058 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
21060 if (code
!= FONT_INVALID_CODE
)
21061 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21063 STORE_XCHAR2B (char2b
, 0, 0);
21066 /* Make sure X resources of the face are allocated. */
21067 #ifdef HAVE_X_WINDOWS
21071 xassert (face
!= NULL
);
21072 PREPARE_FACE_FOR_DISPLAY (f
, face
);
21079 /* Get face and two-byte form of character glyph GLYPH on frame F.
21080 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
21081 a pointer to a realized face that is ready for display. */
21083 static INLINE
struct face
*
21084 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
21085 XChar2b
*char2b
, int *two_byte_p
)
21089 xassert (glyph
->type
== CHAR_GLYPH
);
21090 face
= FACE_FROM_ID (f
, glyph
->face_id
);
21099 if (CHAR_BYTE8_P (glyph
->u
.ch
))
21100 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
21102 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
21104 if (code
!= FONT_INVALID_CODE
)
21105 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21107 STORE_XCHAR2B (char2b
, 0, 0);
21110 /* Make sure X resources of the face are allocated. */
21111 xassert (face
!= NULL
);
21112 PREPARE_FACE_FOR_DISPLAY (f
, face
);
21117 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
21118 Retunr 1 if FONT has a glyph for C, otherwise return 0. */
21121 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
21125 if (CHAR_BYTE8_P (c
))
21126 code
= CHAR_TO_BYTE8 (c
);
21128 code
= font
->driver
->encode_char (font
, c
);
21130 if (code
== FONT_INVALID_CODE
)
21132 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21137 /* Fill glyph string S with composition components specified by S->cmp.
21139 BASE_FACE is the base face of the composition.
21140 S->cmp_from is the index of the first component for S.
21142 OVERLAPS non-zero means S should draw the foreground only, and use
21143 its physical height for clipping. See also draw_glyphs.
21145 Value is the index of a component not in S. */
21148 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
21152 /* For all glyphs of this composition, starting at the offset
21153 S->cmp_from, until we reach the end of the definition or encounter a
21154 glyph that requires the different face, add it to S. */
21159 s
->for_overlaps
= overlaps
;
21162 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
21164 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
21168 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
21171 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
21178 s
->font
= s
->face
->font
;
21180 else if (s
->face
!= face
)
21188 /* All glyph strings for the same composition has the same width,
21189 i.e. the width set for the first component of the composition. */
21190 s
->width
= s
->first_glyph
->pixel_width
;
21192 /* If the specified font could not be loaded, use the frame's
21193 default font, but record the fact that we couldn't load it in
21194 the glyph string so that we can draw rectangles for the
21195 characters of the glyph string. */
21196 if (s
->font
== NULL
)
21198 s
->font_not_found_p
= 1;
21199 s
->font
= FRAME_FONT (s
->f
);
21202 /* Adjust base line for subscript/superscript text. */
21203 s
->ybase
+= s
->first_glyph
->voffset
;
21205 /* This glyph string must always be drawn with 16-bit functions. */
21212 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
21213 int start
, int end
, int overlaps
)
21215 struct glyph
*glyph
, *last
;
21216 Lisp_Object lgstring
;
21219 s
->for_overlaps
= overlaps
;
21220 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21221 last
= s
->row
->glyphs
[s
->area
] + end
;
21222 s
->cmp_id
= glyph
->u
.cmp
.id
;
21223 s
->cmp_from
= glyph
->slice
.cmp
.from
;
21224 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
21225 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21226 lgstring
= composition_gstring_from_id (s
->cmp_id
);
21227 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
21229 while (glyph
< last
21230 && glyph
->u
.cmp
.automatic
21231 && glyph
->u
.cmp
.id
== s
->cmp_id
21232 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
21233 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
21235 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
21237 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
21238 unsigned code
= LGLYPH_CODE (lglyph
);
21240 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
21242 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
21243 return glyph
- s
->row
->glyphs
[s
->area
];
21247 /* Fill glyph string S from a sequence glyphs for glyphless characters.
21248 See the comment of fill_glyph_string for arguments.
21249 Value is the index of the first glyph not in S. */
21253 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
21254 int start
, int end
, int overlaps
)
21256 struct glyph
*glyph
, *last
;
21259 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
21260 s
->for_overlaps
= overlaps
;
21261 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21262 last
= s
->row
->glyphs
[s
->area
] + end
;
21263 voffset
= glyph
->voffset
;
21264 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21265 s
->font
= s
->face
->font
;
21267 s
->width
= glyph
->pixel_width
;
21269 while (glyph
< last
21270 && glyph
->type
== GLYPHLESS_GLYPH
21271 && glyph
->voffset
== voffset
21272 && glyph
->face_id
== face_id
)
21275 s
->width
+= glyph
->pixel_width
;
21278 s
->ybase
+= voffset
;
21279 return glyph
- s
->row
->glyphs
[s
->area
];
21283 /* Fill glyph string S from a sequence of character glyphs.
21285 FACE_ID is the face id of the string. START is the index of the
21286 first glyph to consider, END is the index of the last + 1.
21287 OVERLAPS non-zero means S should draw the foreground only, and use
21288 its physical height for clipping. See also draw_glyphs.
21290 Value is the index of the first glyph not in S. */
21293 fill_glyph_string (struct glyph_string
*s
, int face_id
,
21294 int start
, int end
, int overlaps
)
21296 struct glyph
*glyph
, *last
;
21298 int glyph_not_available_p
;
21300 xassert (s
->f
== XFRAME (s
->w
->frame
));
21301 xassert (s
->nchars
== 0);
21302 xassert (start
>= 0 && end
> start
);
21304 s
->for_overlaps
= overlaps
;
21305 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21306 last
= s
->row
->glyphs
[s
->area
] + end
;
21307 voffset
= glyph
->voffset
;
21308 s
->padding_p
= glyph
->padding_p
;
21309 glyph_not_available_p
= glyph
->glyph_not_available_p
;
21311 while (glyph
< last
21312 && glyph
->type
== CHAR_GLYPH
21313 && glyph
->voffset
== voffset
21314 /* Same face id implies same font, nowadays. */
21315 && glyph
->face_id
== face_id
21316 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
21320 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
21321 s
->char2b
+ s
->nchars
,
21323 s
->two_byte_p
= two_byte_p
;
21325 xassert (s
->nchars
<= end
- start
);
21326 s
->width
+= glyph
->pixel_width
;
21327 if (glyph
++->padding_p
!= s
->padding_p
)
21331 s
->font
= s
->face
->font
;
21333 /* If the specified font could not be loaded, use the frame's font,
21334 but record the fact that we couldn't load it in
21335 S->font_not_found_p so that we can draw rectangles for the
21336 characters of the glyph string. */
21337 if (s
->font
== NULL
|| glyph_not_available_p
)
21339 s
->font_not_found_p
= 1;
21340 s
->font
= FRAME_FONT (s
->f
);
21343 /* Adjust base line for subscript/superscript text. */
21344 s
->ybase
+= voffset
;
21346 xassert (s
->face
&& s
->face
->gc
);
21347 return glyph
- s
->row
->glyphs
[s
->area
];
21351 /* Fill glyph string S from image glyph S->first_glyph. */
21354 fill_image_glyph_string (struct glyph_string
*s
)
21356 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
21357 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
21359 s
->slice
= s
->first_glyph
->slice
.img
;
21360 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
21361 s
->font
= s
->face
->font
;
21362 s
->width
= s
->first_glyph
->pixel_width
;
21364 /* Adjust base line for subscript/superscript text. */
21365 s
->ybase
+= s
->first_glyph
->voffset
;
21369 /* Fill glyph string S from a sequence of stretch glyphs.
21371 START is the index of the first glyph to consider,
21372 END is the index of the last + 1.
21374 Value is the index of the first glyph not in S. */
21377 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
21379 struct glyph
*glyph
, *last
;
21380 int voffset
, face_id
;
21382 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
21384 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21385 last
= s
->row
->glyphs
[s
->area
] + end
;
21386 face_id
= glyph
->face_id
;
21387 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21388 s
->font
= s
->face
->font
;
21389 s
->width
= glyph
->pixel_width
;
21391 voffset
= glyph
->voffset
;
21395 && glyph
->type
== STRETCH_GLYPH
21396 && glyph
->voffset
== voffset
21397 && glyph
->face_id
== face_id
);
21399 s
->width
+= glyph
->pixel_width
;
21401 /* Adjust base line for subscript/superscript text. */
21402 s
->ybase
+= voffset
;
21404 /* The case that face->gc == 0 is handled when drawing the glyph
21405 string by calling PREPARE_FACE_FOR_DISPLAY. */
21407 return glyph
- s
->row
->glyphs
[s
->area
];
21410 static struct font_metrics
*
21411 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
21413 static struct font_metrics metrics
;
21414 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
21416 if (! font
|| code
== FONT_INVALID_CODE
)
21418 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
21423 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
21424 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
21425 assumed to be zero. */
21428 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
21430 *left
= *right
= 0;
21432 if (glyph
->type
== CHAR_GLYPH
)
21436 struct font_metrics
*pcm
;
21438 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
21439 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
21441 if (pcm
->rbearing
> pcm
->width
)
21442 *right
= pcm
->rbearing
- pcm
->width
;
21443 if (pcm
->lbearing
< 0)
21444 *left
= -pcm
->lbearing
;
21447 else if (glyph
->type
== COMPOSITE_GLYPH
)
21449 if (! glyph
->u
.cmp
.automatic
)
21451 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
21453 if (cmp
->rbearing
> cmp
->pixel_width
)
21454 *right
= cmp
->rbearing
- cmp
->pixel_width
;
21455 if (cmp
->lbearing
< 0)
21456 *left
= - cmp
->lbearing
;
21460 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
21461 struct font_metrics metrics
;
21463 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
21464 glyph
->slice
.cmp
.to
+ 1, &metrics
);
21465 if (metrics
.rbearing
> metrics
.width
)
21466 *right
= metrics
.rbearing
- metrics
.width
;
21467 if (metrics
.lbearing
< 0)
21468 *left
= - metrics
.lbearing
;
21474 /* Return the index of the first glyph preceding glyph string S that
21475 is overwritten by S because of S's left overhang. Value is -1
21476 if no glyphs are overwritten. */
21479 left_overwritten (struct glyph_string
*s
)
21483 if (s
->left_overhang
)
21486 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21487 int first
= s
->first_glyph
- glyphs
;
21489 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
21490 x
-= glyphs
[i
].pixel_width
;
21501 /* Return the index of the first glyph preceding glyph string S that
21502 is overwriting S because of its right overhang. Value is -1 if no
21503 glyph in front of S overwrites S. */
21506 left_overwriting (struct glyph_string
*s
)
21509 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21510 int first
= s
->first_glyph
- glyphs
;
21514 for (i
= first
- 1; i
>= 0; --i
)
21517 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21520 x
-= glyphs
[i
].pixel_width
;
21527 /* Return the index of the last glyph following glyph string S that is
21528 overwritten by S because of S's right overhang. Value is -1 if
21529 no such glyph is found. */
21532 right_overwritten (struct glyph_string
*s
)
21536 if (s
->right_overhang
)
21539 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21540 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21541 int end
= s
->row
->used
[s
->area
];
21543 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
21544 x
+= glyphs
[i
].pixel_width
;
21553 /* Return the index of the last glyph following glyph string S that
21554 overwrites S because of its left overhang. Value is negative
21555 if no such glyph is found. */
21558 right_overwriting (struct glyph_string
*s
)
21561 int end
= s
->row
->used
[s
->area
];
21562 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21563 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21567 for (i
= first
; i
< end
; ++i
)
21570 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21573 x
+= glyphs
[i
].pixel_width
;
21580 /* Set background width of glyph string S. START is the index of the
21581 first glyph following S. LAST_X is the right-most x-position + 1
21582 in the drawing area. */
21585 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
21587 /* If the face of this glyph string has to be drawn to the end of
21588 the drawing area, set S->extends_to_end_of_line_p. */
21590 if (start
== s
->row
->used
[s
->area
]
21591 && s
->area
== TEXT_AREA
21592 && ((s
->row
->fill_line_p
21593 && (s
->hl
== DRAW_NORMAL_TEXT
21594 || s
->hl
== DRAW_IMAGE_RAISED
21595 || s
->hl
== DRAW_IMAGE_SUNKEN
))
21596 || s
->hl
== DRAW_MOUSE_FACE
))
21597 s
->extends_to_end_of_line_p
= 1;
21599 /* If S extends its face to the end of the line, set its
21600 background_width to the distance to the right edge of the drawing
21602 if (s
->extends_to_end_of_line_p
)
21603 s
->background_width
= last_x
- s
->x
+ 1;
21605 s
->background_width
= s
->width
;
21609 /* Compute overhangs and x-positions for glyph string S and its
21610 predecessors, or successors. X is the starting x-position for S.
21611 BACKWARD_P non-zero means process predecessors. */
21614 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
21620 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21621 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21631 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21632 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21642 /* The following macros are only called from draw_glyphs below.
21643 They reference the following parameters of that function directly:
21644 `w', `row', `area', and `overlap_p'
21645 as well as the following local variables:
21646 `s', `f', and `hdc' (in W32) */
21649 /* On W32, silently add local `hdc' variable to argument list of
21650 init_glyph_string. */
21651 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21652 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
21654 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21655 init_glyph_string (s, char2b, w, row, area, start, hl)
21658 /* Add a glyph string for a stretch glyph to the list of strings
21659 between HEAD and TAIL. START is the index of the stretch glyph in
21660 row area AREA of glyph row ROW. END is the index of the last glyph
21661 in that glyph row area. X is the current output position assigned
21662 to the new glyph string constructed. HL overrides that face of the
21663 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21664 is the right-most x-position of the drawing area. */
21666 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
21667 and below -- keep them on one line. */
21668 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21671 s = (struct glyph_string *) alloca (sizeof *s); \
21672 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21673 START = fill_stretch_glyph_string (s, START, END); \
21674 append_glyph_string (&HEAD, &TAIL, s); \
21680 /* Add a glyph string for an image glyph to the list of strings
21681 between HEAD and TAIL. START is the index of the image glyph in
21682 row area AREA of glyph row ROW. END is the index of the last glyph
21683 in that glyph row area. X is the current output position assigned
21684 to the new glyph string constructed. HL overrides that face of the
21685 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21686 is the right-most x-position of the drawing area. */
21688 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21691 s = (struct glyph_string *) alloca (sizeof *s); \
21692 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21693 fill_image_glyph_string (s); \
21694 append_glyph_string (&HEAD, &TAIL, s); \
21701 /* Add a glyph string for a sequence of character glyphs to the list
21702 of strings between HEAD and TAIL. START is the index of the first
21703 glyph in row area AREA of glyph row ROW that is part of the new
21704 glyph string. END is the index of the last glyph in that glyph row
21705 area. X is the current output position assigned to the new glyph
21706 string constructed. HL overrides that face of the glyph; e.g. it
21707 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
21708 right-most x-position of the drawing area. */
21710 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21716 face_id = (row)->glyphs[area][START].face_id; \
21718 s = (struct glyph_string *) alloca (sizeof *s); \
21719 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
21720 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21721 append_glyph_string (&HEAD, &TAIL, s); \
21723 START = fill_glyph_string (s, face_id, START, END, overlaps); \
21728 /* Add a glyph string for a composite sequence to the list of strings
21729 between HEAD and TAIL. START is the index of the first glyph in
21730 row area AREA of glyph row ROW that is part of the new glyph
21731 string. END is the index of the last glyph in that glyph row area.
21732 X is the current output position assigned to the new glyph string
21733 constructed. HL overrides that face of the glyph; e.g. it is
21734 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
21735 x-position of the drawing area. */
21737 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21739 int face_id = (row)->glyphs[area][START].face_id; \
21740 struct face *base_face = FACE_FROM_ID (f, face_id); \
21741 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
21742 struct composition *cmp = composition_table[cmp_id]; \
21744 struct glyph_string *first_s IF_LINT (= NULL); \
21747 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21749 /* Make glyph_strings for each glyph sequence that is drawable by \
21750 the same face, and append them to HEAD/TAIL. */ \
21751 for (n = 0; n < cmp->glyph_len;) \
21753 s = (struct glyph_string *) alloca (sizeof *s); \
21754 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21755 append_glyph_string (&(HEAD), &(TAIL), s); \
21761 n = fill_composite_glyph_string (s, base_face, overlaps); \
21769 /* Add a glyph string for a glyph-string sequence to the list of strings
21770 between HEAD and TAIL. */
21772 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21776 Lisp_Object gstring; \
21778 face_id = (row)->glyphs[area][START].face_id; \
21779 gstring = (composition_gstring_from_id \
21780 ((row)->glyphs[area][START].u.cmp.id)); \
21781 s = (struct glyph_string *) alloca (sizeof *s); \
21782 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21783 * LGSTRING_GLYPH_LEN (gstring)); \
21784 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21785 append_glyph_string (&(HEAD), &(TAIL), s); \
21787 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21791 /* Add a glyph string for a sequence of glyphless character's glyphs
21792 to the list of strings between HEAD and TAIL. The meanings of
21793 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
21795 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21800 face_id = (row)->glyphs[area][START].face_id; \
21802 s = (struct glyph_string *) alloca (sizeof *s); \
21803 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21804 append_glyph_string (&HEAD, &TAIL, s); \
21806 START = fill_glyphless_glyph_string (s, face_id, START, END, \
21812 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21813 of AREA of glyph row ROW on window W between indices START and END.
21814 HL overrides the face for drawing glyph strings, e.g. it is
21815 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21816 x-positions of the drawing area.
21818 This is an ugly monster macro construct because we must use alloca
21819 to allocate glyph strings (because draw_glyphs can be called
21820 asynchronously). */
21822 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21825 HEAD = TAIL = NULL; \
21826 while (START < END) \
21828 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21829 switch (first_glyph->type) \
21832 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21836 case COMPOSITE_GLYPH: \
21837 if (first_glyph->u.cmp.automatic) \
21838 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21841 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21845 case STRETCH_GLYPH: \
21846 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21850 case IMAGE_GLYPH: \
21851 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21855 case GLYPHLESS_GLYPH: \
21856 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
21866 set_glyph_string_background_width (s, START, LAST_X); \
21873 /* Draw glyphs between START and END in AREA of ROW on window W,
21874 starting at x-position X. X is relative to AREA in W. HL is a
21875 face-override with the following meaning:
21877 DRAW_NORMAL_TEXT draw normally
21878 DRAW_CURSOR draw in cursor face
21879 DRAW_MOUSE_FACE draw in mouse face.
21880 DRAW_INVERSE_VIDEO draw in mode line face
21881 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
21882 DRAW_IMAGE_RAISED draw an image with a raised relief around it
21884 If OVERLAPS is non-zero, draw only the foreground of characters and
21885 clip to the physical height of ROW. Non-zero value also defines
21886 the overlapping part to be drawn:
21888 OVERLAPS_PRED overlap with preceding rows
21889 OVERLAPS_SUCC overlap with succeeding rows
21890 OVERLAPS_BOTH overlap with both preceding/succeeding rows
21891 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
21893 Value is the x-position reached, relative to AREA of W. */
21896 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
21897 enum glyph_row_area area
, EMACS_INT start
, EMACS_INT end
,
21898 enum draw_glyphs_face hl
, int overlaps
)
21900 struct glyph_string
*head
, *tail
;
21901 struct glyph_string
*s
;
21902 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
21903 int i
, j
, x_reached
, last_x
, area_left
= 0;
21904 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21907 ALLOCATE_HDC (hdc
, f
);
21909 /* Let's rather be paranoid than getting a SEGV. */
21910 end
= min (end
, row
->used
[area
]);
21911 start
= max (0, start
);
21912 start
= min (end
, start
);
21914 /* Translate X to frame coordinates. Set last_x to the right
21915 end of the drawing area. */
21916 if (row
->full_width_p
)
21918 /* X is relative to the left edge of W, without scroll bars
21920 area_left
= WINDOW_LEFT_EDGE_X (w
);
21921 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
21925 area_left
= window_box_left (w
, area
);
21926 last_x
= area_left
+ window_box_width (w
, area
);
21930 /* Build a doubly-linked list of glyph_string structures between
21931 head and tail from what we have to draw. Note that the macro
21932 BUILD_GLYPH_STRINGS will modify its start parameter. That's
21933 the reason we use a separate variable `i'. */
21935 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
21937 x_reached
= tail
->x
+ tail
->background_width
;
21941 /* If there are any glyphs with lbearing < 0 or rbearing > width in
21942 the row, redraw some glyphs in front or following the glyph
21943 strings built above. */
21944 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
21946 struct glyph_string
*h
, *t
;
21947 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
21948 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
21949 int check_mouse_face
= 0;
21952 /* If mouse highlighting is on, we may need to draw adjacent
21953 glyphs using mouse-face highlighting. */
21954 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
21956 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
21958 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
21959 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
21961 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
21963 check_mouse_face
= 1;
21964 mouse_beg_col
= (row
== mouse_beg_row
)
21965 ? hlinfo
->mouse_face_beg_col
: 0;
21966 mouse_end_col
= (row
== mouse_end_row
)
21967 ? hlinfo
->mouse_face_end_col
21968 : row
->used
[TEXT_AREA
];
21972 /* Compute overhangs for all glyph strings. */
21973 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
21974 for (s
= head
; s
; s
= s
->next
)
21975 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
21977 /* Prepend glyph strings for glyphs in front of the first glyph
21978 string that are overwritten because of the first glyph
21979 string's left overhang. The background of all strings
21980 prepended must be drawn because the first glyph string
21982 i
= left_overwritten (head
);
21985 enum draw_glyphs_face overlap_hl
;
21987 /* If this row contains mouse highlighting, attempt to draw
21988 the overlapped glyphs with the correct highlight. This
21989 code fails if the overlap encompasses more than one glyph
21990 and mouse-highlight spans only some of these glyphs.
21991 However, making it work perfectly involves a lot more
21992 code, and I don't know if the pathological case occurs in
21993 practice, so we'll stick to this for now. --- cyd */
21994 if (check_mouse_face
21995 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21996 overlap_hl
= DRAW_MOUSE_FACE
;
21998 overlap_hl
= DRAW_NORMAL_TEXT
;
22001 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
22002 overlap_hl
, dummy_x
, last_x
);
22004 compute_overhangs_and_x (t
, head
->x
, 1);
22005 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
22009 /* Prepend glyph strings for glyphs in front of the first glyph
22010 string that overwrite that glyph string because of their
22011 right overhang. For these strings, only the foreground must
22012 be drawn, because it draws over the glyph string at `head'.
22013 The background must not be drawn because this would overwrite
22014 right overhangs of preceding glyphs for which no glyph
22016 i
= left_overwriting (head
);
22019 enum draw_glyphs_face overlap_hl
;
22021 if (check_mouse_face
22022 && mouse_beg_col
< start
&& mouse_end_col
> i
)
22023 overlap_hl
= DRAW_MOUSE_FACE
;
22025 overlap_hl
= DRAW_NORMAL_TEXT
;
22028 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
22029 overlap_hl
, dummy_x
, last_x
);
22030 for (s
= h
; s
; s
= s
->next
)
22031 s
->background_filled_p
= 1;
22032 compute_overhangs_and_x (t
, head
->x
, 1);
22033 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
22036 /* Append glyphs strings for glyphs following the last glyph
22037 string tail that are overwritten by tail. The background of
22038 these strings has to be drawn because tail's foreground draws
22040 i
= right_overwritten (tail
);
22043 enum draw_glyphs_face overlap_hl
;
22045 if (check_mouse_face
22046 && mouse_beg_col
< i
&& mouse_end_col
> end
)
22047 overlap_hl
= DRAW_MOUSE_FACE
;
22049 overlap_hl
= DRAW_NORMAL_TEXT
;
22051 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
22052 overlap_hl
, x
, last_x
);
22053 /* Because BUILD_GLYPH_STRINGS updates the first argument,
22054 we don't have `end = i;' here. */
22055 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
22056 append_glyph_string_lists (&head
, &tail
, h
, t
);
22060 /* Append glyph strings for glyphs following the last glyph
22061 string tail that overwrite tail. The foreground of such
22062 glyphs has to be drawn because it writes into the background
22063 of tail. The background must not be drawn because it could
22064 paint over the foreground of following glyphs. */
22065 i
= right_overwriting (tail
);
22068 enum draw_glyphs_face overlap_hl
;
22069 if (check_mouse_face
22070 && mouse_beg_col
< i
&& mouse_end_col
> end
)
22071 overlap_hl
= DRAW_MOUSE_FACE
;
22073 overlap_hl
= DRAW_NORMAL_TEXT
;
22076 i
++; /* We must include the Ith glyph. */
22077 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
22078 overlap_hl
, x
, last_x
);
22079 for (s
= h
; s
; s
= s
->next
)
22080 s
->background_filled_p
= 1;
22081 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
22082 append_glyph_string_lists (&head
, &tail
, h
, t
);
22084 if (clip_head
|| clip_tail
)
22085 for (s
= head
; s
; s
= s
->next
)
22087 s
->clip_head
= clip_head
;
22088 s
->clip_tail
= clip_tail
;
22092 /* Draw all strings. */
22093 for (s
= head
; s
; s
= s
->next
)
22094 FRAME_RIF (f
)->draw_glyph_string (s
);
22097 /* When focus a sole frame and move horizontally, this sets on_p to 0
22098 causing a failure to erase prev cursor position. */
22099 if (area
== TEXT_AREA
22100 && !row
->full_width_p
22101 /* When drawing overlapping rows, only the glyph strings'
22102 foreground is drawn, which doesn't erase a cursor
22106 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
22107 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
22108 : (tail
? tail
->x
+ tail
->background_width
: x
));
22112 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
22113 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
22117 /* Value is the x-position up to which drawn, relative to AREA of W.
22118 This doesn't include parts drawn because of overhangs. */
22119 if (row
->full_width_p
)
22120 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
22122 x_reached
-= area_left
;
22124 RELEASE_HDC (hdc
, f
);
22129 /* Expand row matrix if too narrow. Don't expand if area
22132 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
22134 if (!fonts_changed_p \
22135 && (it->glyph_row->glyphs[area] \
22136 < it->glyph_row->glyphs[area + 1])) \
22138 it->w->ncols_scale_factor++; \
22139 fonts_changed_p = 1; \
22143 /* Store one glyph for IT->char_to_display in IT->glyph_row.
22144 Called from x_produce_glyphs when IT->glyph_row is non-null. */
22147 append_glyph (struct it
*it
)
22149 struct glyph
*glyph
;
22150 enum glyph_row_area area
= it
->area
;
22152 xassert (it
->glyph_row
);
22153 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
22155 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22156 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22158 /* If the glyph row is reversed, we need to prepend the glyph
22159 rather than append it. */
22160 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22164 /* Make room for the additional glyph. */
22165 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22167 glyph
= it
->glyph_row
->glyphs
[area
];
22169 glyph
->charpos
= CHARPOS (it
->position
);
22170 glyph
->object
= it
->object
;
22171 if (it
->pixel_width
> 0)
22173 glyph
->pixel_width
= it
->pixel_width
;
22174 glyph
->padding_p
= 0;
22178 /* Assure at least 1-pixel width. Otherwise, cursor can't
22179 be displayed correctly. */
22180 glyph
->pixel_width
= 1;
22181 glyph
->padding_p
= 1;
22183 glyph
->ascent
= it
->ascent
;
22184 glyph
->descent
= it
->descent
;
22185 glyph
->voffset
= it
->voffset
;
22186 glyph
->type
= CHAR_GLYPH
;
22187 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22188 glyph
->multibyte_p
= it
->multibyte_p
;
22189 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22190 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22191 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22192 || it
->phys_descent
> it
->descent
);
22193 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
22194 glyph
->face_id
= it
->face_id
;
22195 glyph
->u
.ch
= it
->char_to_display
;
22196 glyph
->slice
.img
= null_glyph_slice
;
22197 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22200 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22201 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22203 glyph
->bidi_type
= it
->bidi_it
.type
;
22207 glyph
->resolved_level
= 0;
22208 glyph
->bidi_type
= UNKNOWN_BT
;
22210 ++it
->glyph_row
->used
[area
];
22213 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22216 /* Store one glyph for the composition IT->cmp_it.id in
22217 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
22221 append_composite_glyph (struct it
*it
)
22223 struct glyph
*glyph
;
22224 enum glyph_row_area area
= it
->area
;
22226 xassert (it
->glyph_row
);
22228 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22229 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22231 /* If the glyph row is reversed, we need to prepend the glyph
22232 rather than append it. */
22233 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
22237 /* Make room for the new glyph. */
22238 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
22240 glyph
= it
->glyph_row
->glyphs
[it
->area
];
22242 glyph
->charpos
= it
->cmp_it
.charpos
;
22243 glyph
->object
= it
->object
;
22244 glyph
->pixel_width
= it
->pixel_width
;
22245 glyph
->ascent
= it
->ascent
;
22246 glyph
->descent
= it
->descent
;
22247 glyph
->voffset
= it
->voffset
;
22248 glyph
->type
= COMPOSITE_GLYPH
;
22249 if (it
->cmp_it
.ch
< 0)
22251 glyph
->u
.cmp
.automatic
= 0;
22252 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
22253 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
22257 glyph
->u
.cmp
.automatic
= 1;
22258 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
22259 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
22260 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
22262 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22263 glyph
->multibyte_p
= it
->multibyte_p
;
22264 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22265 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22266 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22267 || it
->phys_descent
> it
->descent
);
22268 glyph
->padding_p
= 0;
22269 glyph
->glyph_not_available_p
= 0;
22270 glyph
->face_id
= it
->face_id
;
22271 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22274 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22275 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22277 glyph
->bidi_type
= it
->bidi_it
.type
;
22279 ++it
->glyph_row
->used
[area
];
22282 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22286 /* Change IT->ascent and IT->height according to the setting of
22290 take_vertical_position_into_account (struct it
*it
)
22294 if (it
->voffset
< 0)
22295 /* Increase the ascent so that we can display the text higher
22297 it
->ascent
-= it
->voffset
;
22299 /* Increase the descent so that we can display the text lower
22301 it
->descent
+= it
->voffset
;
22306 /* Produce glyphs/get display metrics for the image IT is loaded with.
22307 See the description of struct display_iterator in dispextern.h for
22308 an overview of struct display_iterator. */
22311 produce_image_glyph (struct it
*it
)
22315 int glyph_ascent
, crop
;
22316 struct glyph_slice slice
;
22318 xassert (it
->what
== IT_IMAGE
);
22320 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22322 /* Make sure X resources of the face is loaded. */
22323 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22325 if (it
->image_id
< 0)
22327 /* Fringe bitmap. */
22328 it
->ascent
= it
->phys_ascent
= 0;
22329 it
->descent
= it
->phys_descent
= 0;
22330 it
->pixel_width
= 0;
22335 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
22337 /* Make sure X resources of the image is loaded. */
22338 prepare_image_for_display (it
->f
, img
);
22340 slice
.x
= slice
.y
= 0;
22341 slice
.width
= img
->width
;
22342 slice
.height
= img
->height
;
22344 if (INTEGERP (it
->slice
.x
))
22345 slice
.x
= XINT (it
->slice
.x
);
22346 else if (FLOATP (it
->slice
.x
))
22347 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
22349 if (INTEGERP (it
->slice
.y
))
22350 slice
.y
= XINT (it
->slice
.y
);
22351 else if (FLOATP (it
->slice
.y
))
22352 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
22354 if (INTEGERP (it
->slice
.width
))
22355 slice
.width
= XINT (it
->slice
.width
);
22356 else if (FLOATP (it
->slice
.width
))
22357 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
22359 if (INTEGERP (it
->slice
.height
))
22360 slice
.height
= XINT (it
->slice
.height
);
22361 else if (FLOATP (it
->slice
.height
))
22362 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
22364 if (slice
.x
>= img
->width
)
22365 slice
.x
= img
->width
;
22366 if (slice
.y
>= img
->height
)
22367 slice
.y
= img
->height
;
22368 if (slice
.x
+ slice
.width
>= img
->width
)
22369 slice
.width
= img
->width
- slice
.x
;
22370 if (slice
.y
+ slice
.height
> img
->height
)
22371 slice
.height
= img
->height
- slice
.y
;
22373 if (slice
.width
== 0 || slice
.height
== 0)
22376 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
22378 it
->descent
= slice
.height
- glyph_ascent
;
22380 it
->descent
+= img
->vmargin
;
22381 if (slice
.y
+ slice
.height
== img
->height
)
22382 it
->descent
+= img
->vmargin
;
22383 it
->phys_descent
= it
->descent
;
22385 it
->pixel_width
= slice
.width
;
22387 it
->pixel_width
+= img
->hmargin
;
22388 if (slice
.x
+ slice
.width
== img
->width
)
22389 it
->pixel_width
+= img
->hmargin
;
22391 /* It's quite possible for images to have an ascent greater than
22392 their height, so don't get confused in that case. */
22393 if (it
->descent
< 0)
22398 if (face
->box
!= FACE_NO_BOX
)
22400 if (face
->box_line_width
> 0)
22403 it
->ascent
+= face
->box_line_width
;
22404 if (slice
.y
+ slice
.height
== img
->height
)
22405 it
->descent
+= face
->box_line_width
;
22408 if (it
->start_of_box_run_p
&& slice
.x
== 0)
22409 it
->pixel_width
+= eabs (face
->box_line_width
);
22410 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
22411 it
->pixel_width
+= eabs (face
->box_line_width
);
22414 take_vertical_position_into_account (it
);
22416 /* Automatically crop wide image glyphs at right edge so we can
22417 draw the cursor on same display row. */
22418 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
22419 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
22421 it
->pixel_width
-= crop
;
22422 slice
.width
-= crop
;
22427 struct glyph
*glyph
;
22428 enum glyph_row_area area
= it
->area
;
22430 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22431 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22433 glyph
->charpos
= CHARPOS (it
->position
);
22434 glyph
->object
= it
->object
;
22435 glyph
->pixel_width
= it
->pixel_width
;
22436 glyph
->ascent
= glyph_ascent
;
22437 glyph
->descent
= it
->descent
;
22438 glyph
->voffset
= it
->voffset
;
22439 glyph
->type
= IMAGE_GLYPH
;
22440 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22441 glyph
->multibyte_p
= it
->multibyte_p
;
22442 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22443 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22444 glyph
->overlaps_vertically_p
= 0;
22445 glyph
->padding_p
= 0;
22446 glyph
->glyph_not_available_p
= 0;
22447 glyph
->face_id
= it
->face_id
;
22448 glyph
->u
.img_id
= img
->id
;
22449 glyph
->slice
.img
= slice
;
22450 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22453 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22454 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22456 glyph
->bidi_type
= it
->bidi_it
.type
;
22458 ++it
->glyph_row
->used
[area
];
22461 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22466 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
22467 of the glyph, WIDTH and HEIGHT are the width and height of the
22468 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
22471 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
22472 int width
, int height
, int ascent
)
22474 struct glyph
*glyph
;
22475 enum glyph_row_area area
= it
->area
;
22477 xassert (ascent
>= 0 && ascent
<= height
);
22479 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22480 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22482 /* If the glyph row is reversed, we need to prepend the glyph
22483 rather than append it. */
22484 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22488 /* Make room for the additional glyph. */
22489 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22491 glyph
= it
->glyph_row
->glyphs
[area
];
22493 glyph
->charpos
= CHARPOS (it
->position
);
22494 glyph
->object
= object
;
22495 glyph
->pixel_width
= width
;
22496 glyph
->ascent
= ascent
;
22497 glyph
->descent
= height
- ascent
;
22498 glyph
->voffset
= it
->voffset
;
22499 glyph
->type
= STRETCH_GLYPH
;
22500 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22501 glyph
->multibyte_p
= it
->multibyte_p
;
22502 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22503 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22504 glyph
->overlaps_vertically_p
= 0;
22505 glyph
->padding_p
= 0;
22506 glyph
->glyph_not_available_p
= 0;
22507 glyph
->face_id
= it
->face_id
;
22508 glyph
->u
.stretch
.ascent
= ascent
;
22509 glyph
->u
.stretch
.height
= height
;
22510 glyph
->slice
.img
= null_glyph_slice
;
22511 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22514 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22515 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22517 glyph
->bidi_type
= it
->bidi_it
.type
;
22521 glyph
->resolved_level
= 0;
22522 glyph
->bidi_type
= UNKNOWN_BT
;
22524 ++it
->glyph_row
->used
[area
];
22527 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22531 /* Produce a stretch glyph for iterator IT. IT->object is the value
22532 of the glyph property displayed. The value must be a list
22533 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
22536 1. `:width WIDTH' specifies that the space should be WIDTH *
22537 canonical char width wide. WIDTH may be an integer or floating
22540 2. `:relative-width FACTOR' specifies that the width of the stretch
22541 should be computed from the width of the first character having the
22542 `glyph' property, and should be FACTOR times that width.
22544 3. `:align-to HPOS' specifies that the space should be wide enough
22545 to reach HPOS, a value in canonical character units.
22547 Exactly one of the above pairs must be present.
22549 4. `:height HEIGHT' specifies that the height of the stretch produced
22550 should be HEIGHT, measured in canonical character units.
22552 5. `:relative-height FACTOR' specifies that the height of the
22553 stretch should be FACTOR times the height of the characters having
22554 the glyph property.
22556 Either none or exactly one of 4 or 5 must be present.
22558 6. `:ascent ASCENT' specifies that ASCENT percent of the height
22559 of the stretch should be used for the ascent of the stretch.
22560 ASCENT must be in the range 0 <= ASCENT <= 100. */
22563 produce_stretch_glyph (struct it
*it
)
22565 /* (space :width WIDTH :height HEIGHT ...) */
22566 Lisp_Object prop
, plist
;
22567 int width
= 0, height
= 0, align_to
= -1;
22568 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
22571 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22572 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22574 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22576 /* List should start with `space'. */
22577 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
22578 plist
= XCDR (it
->object
);
22580 /* Compute the width of the stretch. */
22581 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
22582 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
22584 /* Absolute width `:width WIDTH' specified and valid. */
22585 zero_width_ok_p
= 1;
22588 else if (prop
= Fplist_get (plist
, QCrelative_width
),
22591 /* Relative width `:relative-width FACTOR' specified and valid.
22592 Compute the width of the characters having the `glyph'
22595 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
22598 if (it
->multibyte_p
)
22599 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
22602 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
22603 if (! ASCII_CHAR_P (it2
.c
))
22604 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
22607 it2
.glyph_row
= NULL
;
22608 it2
.what
= IT_CHARACTER
;
22609 x_produce_glyphs (&it2
);
22610 width
= NUMVAL (prop
) * it2
.pixel_width
;
22612 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
22613 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
22615 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
22616 align_to
= (align_to
< 0
22618 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
22619 else if (align_to
< 0)
22620 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
22621 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
22622 zero_width_ok_p
= 1;
22625 /* Nothing specified -> width defaults to canonical char width. */
22626 width
= FRAME_COLUMN_WIDTH (it
->f
);
22628 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
22631 /* Compute height. */
22632 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
22633 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22636 zero_height_ok_p
= 1;
22638 else if (prop
= Fplist_get (plist
, QCrelative_height
),
22640 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
22642 height
= FONT_HEIGHT (font
);
22644 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
22647 /* Compute percentage of height used for ascent. If
22648 `:ascent ASCENT' is present and valid, use that. Otherwise,
22649 derive the ascent from the font in use. */
22650 if (prop
= Fplist_get (plist
, QCascent
),
22651 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
22652 ascent
= height
* NUMVAL (prop
) / 100.0;
22653 else if (!NILP (prop
)
22654 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22655 ascent
= min (max (0, (int)tem
), height
);
22657 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
22659 if (width
> 0 && it
->line_wrap
!= TRUNCATE
22660 && it
->current_x
+ width
> it
->last_visible_x
)
22661 width
= it
->last_visible_x
- it
->current_x
- 1;
22663 if (width
> 0 && height
> 0 && it
->glyph_row
)
22665 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
22666 if (!STRINGP (object
))
22667 object
= it
->w
->buffer
;
22668 append_stretch_glyph (it
, object
, width
, height
, ascent
);
22671 it
->pixel_width
= width
;
22672 it
->ascent
= it
->phys_ascent
= ascent
;
22673 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
22674 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
22676 take_vertical_position_into_account (it
);
22679 /* Calculate line-height and line-spacing properties.
22680 An integer value specifies explicit pixel value.
22681 A float value specifies relative value to current face height.
22682 A cons (float . face-name) specifies relative value to
22683 height of specified face font.
22685 Returns height in pixels, or nil. */
22689 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
22690 int boff
, int override
)
22692 Lisp_Object face_name
= Qnil
;
22693 int ascent
, descent
, height
;
22695 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
22700 face_name
= XCAR (val
);
22702 if (!NUMBERP (val
))
22703 val
= make_number (1);
22704 if (NILP (face_name
))
22706 height
= it
->ascent
+ it
->descent
;
22711 if (NILP (face_name
))
22713 font
= FRAME_FONT (it
->f
);
22714 boff
= FRAME_BASELINE_OFFSET (it
->f
);
22716 else if (EQ (face_name
, Qt
))
22725 face_id
= lookup_named_face (it
->f
, face_name
, 0);
22727 return make_number (-1);
22729 face
= FACE_FROM_ID (it
->f
, face_id
);
22732 return make_number (-1);
22733 boff
= font
->baseline_offset
;
22734 if (font
->vertical_centering
)
22735 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22738 ascent
= FONT_BASE (font
) + boff
;
22739 descent
= FONT_DESCENT (font
) - boff
;
22743 it
->override_ascent
= ascent
;
22744 it
->override_descent
= descent
;
22745 it
->override_boff
= boff
;
22748 height
= ascent
+ descent
;
22752 height
= (int)(XFLOAT_DATA (val
) * height
);
22753 else if (INTEGERP (val
))
22754 height
*= XINT (val
);
22756 return make_number (height
);
22760 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
22761 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
22762 and only if this is for a character for which no font was found.
22764 If the display method (it->glyphless_method) is
22765 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
22766 length of the acronym or the hexadecimal string, UPPER_XOFF and
22767 UPPER_YOFF are pixel offsets for the upper part of the string,
22768 LOWER_XOFF and LOWER_YOFF are for the lower part.
22770 For the other display methods, LEN through LOWER_YOFF are zero. */
22773 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
22774 short upper_xoff
, short upper_yoff
,
22775 short lower_xoff
, short lower_yoff
)
22777 struct glyph
*glyph
;
22778 enum glyph_row_area area
= it
->area
;
22780 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22781 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22783 /* If the glyph row is reversed, we need to prepend the glyph
22784 rather than append it. */
22785 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22789 /* Make room for the additional glyph. */
22790 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22792 glyph
= it
->glyph_row
->glyphs
[area
];
22794 glyph
->charpos
= CHARPOS (it
->position
);
22795 glyph
->object
= it
->object
;
22796 glyph
->pixel_width
= it
->pixel_width
;
22797 glyph
->ascent
= it
->ascent
;
22798 glyph
->descent
= it
->descent
;
22799 glyph
->voffset
= it
->voffset
;
22800 glyph
->type
= GLYPHLESS_GLYPH
;
22801 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
22802 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
22803 glyph
->u
.glyphless
.len
= len
;
22804 glyph
->u
.glyphless
.ch
= it
->c
;
22805 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
22806 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
22807 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
22808 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
22809 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22810 glyph
->multibyte_p
= it
->multibyte_p
;
22811 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22812 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22813 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22814 || it
->phys_descent
> it
->descent
);
22815 glyph
->padding_p
= 0;
22816 glyph
->glyph_not_available_p
= 0;
22817 glyph
->face_id
= face_id
;
22818 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22821 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22822 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22824 glyph
->bidi_type
= it
->bidi_it
.type
;
22826 ++it
->glyph_row
->used
[area
];
22829 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22833 /* Produce a glyph for a glyphless character for iterator IT.
22834 IT->glyphless_method specifies which method to use for displaying
22835 the character. See the description of enum
22836 glyphless_display_method in dispextern.h for the detail.
22838 FOR_NO_FONT is nonzero if and only if this is for a character for
22839 which no font was found. ACRONYM, if non-nil, is an acronym string
22840 for the character. */
22843 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
22848 int base_width
, base_height
, width
, height
;
22849 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
22852 /* Get the metrics of the base font. We always refer to the current
22854 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
22855 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22856 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
22857 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
22858 base_height
= it
->ascent
+ it
->descent
;
22859 base_width
= font
->average_width
;
22861 /* Get a face ID for the glyph by utilizing a cache (the same way as
22862 doen for `escape-glyph' in get_next_display_element). */
22863 if (it
->f
== last_glyphless_glyph_frame
22864 && it
->face_id
== last_glyphless_glyph_face_id
)
22866 face_id
= last_glyphless_glyph_merged_face_id
;
22870 /* Merge the `glyphless-char' face into the current face. */
22871 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
22872 last_glyphless_glyph_frame
= it
->f
;
22873 last_glyphless_glyph_face_id
= it
->face_id
;
22874 last_glyphless_glyph_merged_face_id
= face_id
;
22877 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
22879 it
->pixel_width
= THIN_SPACE_WIDTH
;
22881 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22883 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
22885 width
= CHAR_WIDTH (it
->c
);
22888 else if (width
> 4)
22890 it
->pixel_width
= base_width
* width
;
22892 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22898 unsigned int code
[6];
22900 int ascent
, descent
;
22901 struct font_metrics metrics_upper
, metrics_lower
;
22903 face
= FACE_FROM_ID (it
->f
, face_id
);
22904 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22905 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22907 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
22909 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
22910 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
22911 if (CONSP (acronym
))
22912 acronym
= XCAR (acronym
);
22913 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
22917 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
22918 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
22921 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
22922 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
22923 upper_len
= (len
+ 1) / 2;
22924 font
->driver
->text_extents (font
, code
, upper_len
,
22926 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
22931 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
22932 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
22933 upper_xoff
= upper_yoff
= 2; /* the typical case */
22934 if (base_width
>= width
)
22936 /* Align the upper to the left, the lower to the right. */
22937 it
->pixel_width
= base_width
;
22938 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
22942 /* Center the shorter one. */
22943 it
->pixel_width
= width
;
22944 if (metrics_upper
.width
>= metrics_lower
.width
)
22945 lower_xoff
= (width
- metrics_lower
.width
) / 2;
22948 /* FIXME: This code doesn't look right. It formerly was
22949 missing the "lower_xoff = 0;", which couldn't have
22950 been right since it left lower_xoff uninitialized. */
22952 upper_xoff
= (width
- metrics_upper
.width
) / 2;
22956 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
22957 top, bottom, and between upper and lower strings. */
22958 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
22959 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
22960 /* Center vertically.
22961 H:base_height, D:base_descent
22962 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
22964 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
22965 descent = D - H/2 + h/2;
22966 lower_yoff = descent - 2 - ld;
22967 upper_yoff = lower_yoff - la - 1 - ud; */
22968 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
22969 descent
= it
->descent
- (base_height
- height
) / 2;
22970 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
22971 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
22972 - metrics_upper
.descent
);
22973 /* Don't make the height shorter than the base height. */
22974 if (height
> base_height
)
22976 it
->ascent
= ascent
;
22977 it
->descent
= descent
;
22981 it
->phys_ascent
= it
->ascent
;
22982 it
->phys_descent
= it
->descent
;
22984 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
22985 upper_xoff
, upper_yoff
,
22986 lower_xoff
, lower_yoff
);
22988 take_vertical_position_into_account (it
);
22993 Produce glyphs/get display metrics for the display element IT is
22994 loaded with. See the description of struct it in dispextern.h
22995 for an overview of struct it. */
22998 x_produce_glyphs (struct it
*it
)
23000 int extra_line_spacing
= it
->extra_line_spacing
;
23002 it
->glyph_not_available_p
= 0;
23004 if (it
->what
== IT_CHARACTER
)
23007 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23008 struct font
*font
= face
->font
;
23009 struct font_metrics
*pcm
= NULL
;
23010 int boff
; /* baseline offset */
23014 /* When no suitable font is found, display this character by
23015 the method specified in the first extra slot of
23016 Vglyphless_char_display. */
23017 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
23019 xassert (it
->what
== IT_GLYPHLESS
);
23020 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
23024 boff
= font
->baseline_offset
;
23025 if (font
->vertical_centering
)
23026 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23028 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
23034 if (it
->override_ascent
>= 0)
23036 it
->ascent
= it
->override_ascent
;
23037 it
->descent
= it
->override_descent
;
23038 boff
= it
->override_boff
;
23042 it
->ascent
= FONT_BASE (font
) + boff
;
23043 it
->descent
= FONT_DESCENT (font
) - boff
;
23046 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
23048 pcm
= get_per_char_metric (font
, &char2b
);
23049 if (pcm
->width
== 0
23050 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
23056 it
->phys_ascent
= pcm
->ascent
+ boff
;
23057 it
->phys_descent
= pcm
->descent
- boff
;
23058 it
->pixel_width
= pcm
->width
;
23062 it
->glyph_not_available_p
= 1;
23063 it
->phys_ascent
= it
->ascent
;
23064 it
->phys_descent
= it
->descent
;
23065 it
->pixel_width
= font
->space_width
;
23068 if (it
->constrain_row_ascent_descent_p
)
23070 if (it
->descent
> it
->max_descent
)
23072 it
->ascent
+= it
->descent
- it
->max_descent
;
23073 it
->descent
= it
->max_descent
;
23075 if (it
->ascent
> it
->max_ascent
)
23077 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
23078 it
->ascent
= it
->max_ascent
;
23080 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
23081 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
23082 extra_line_spacing
= 0;
23085 /* If this is a space inside a region of text with
23086 `space-width' property, change its width. */
23087 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
23089 it
->pixel_width
*= XFLOATINT (it
->space_width
);
23091 /* If face has a box, add the box thickness to the character
23092 height. If character has a box line to the left and/or
23093 right, add the box line width to the character's width. */
23094 if (face
->box
!= FACE_NO_BOX
)
23096 int thick
= face
->box_line_width
;
23100 it
->ascent
+= thick
;
23101 it
->descent
+= thick
;
23106 if (it
->start_of_box_run_p
)
23107 it
->pixel_width
+= thick
;
23108 if (it
->end_of_box_run_p
)
23109 it
->pixel_width
+= thick
;
23112 /* If face has an overline, add the height of the overline
23113 (1 pixel) and a 1 pixel margin to the character height. */
23114 if (face
->overline_p
)
23115 it
->ascent
+= overline_margin
;
23117 if (it
->constrain_row_ascent_descent_p
)
23119 if (it
->ascent
> it
->max_ascent
)
23120 it
->ascent
= it
->max_ascent
;
23121 if (it
->descent
> it
->max_descent
)
23122 it
->descent
= it
->max_descent
;
23125 take_vertical_position_into_account (it
);
23127 /* If we have to actually produce glyphs, do it. */
23132 /* Translate a space with a `space-width' property
23133 into a stretch glyph. */
23134 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
23135 / FONT_HEIGHT (font
));
23136 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
23137 it
->ascent
+ it
->descent
, ascent
);
23142 /* If characters with lbearing or rbearing are displayed
23143 in this line, record that fact in a flag of the
23144 glyph row. This is used to optimize X output code. */
23145 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
23146 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23148 if (! stretched_p
&& it
->pixel_width
== 0)
23149 /* We assure that all visible glyphs have at least 1-pixel
23151 it
->pixel_width
= 1;
23153 else if (it
->char_to_display
== '\n')
23155 /* A newline has no width, but we need the height of the
23156 line. But if previous part of the line sets a height,
23157 don't increase that height */
23159 Lisp_Object height
;
23160 Lisp_Object total_height
= Qnil
;
23162 it
->override_ascent
= -1;
23163 it
->pixel_width
= 0;
23166 height
= get_it_property (it
, Qline_height
);
23167 /* Split (line-height total-height) list */
23169 && CONSP (XCDR (height
))
23170 && NILP (XCDR (XCDR (height
))))
23172 total_height
= XCAR (XCDR (height
));
23173 height
= XCAR (height
);
23175 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
23177 if (it
->override_ascent
>= 0)
23179 it
->ascent
= it
->override_ascent
;
23180 it
->descent
= it
->override_descent
;
23181 boff
= it
->override_boff
;
23185 it
->ascent
= FONT_BASE (font
) + boff
;
23186 it
->descent
= FONT_DESCENT (font
) - boff
;
23189 if (EQ (height
, Qt
))
23191 if (it
->descent
> it
->max_descent
)
23193 it
->ascent
+= it
->descent
- it
->max_descent
;
23194 it
->descent
= it
->max_descent
;
23196 if (it
->ascent
> it
->max_ascent
)
23198 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
23199 it
->ascent
= it
->max_ascent
;
23201 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
23202 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
23203 it
->constrain_row_ascent_descent_p
= 1;
23204 extra_line_spacing
= 0;
23208 Lisp_Object spacing
;
23210 it
->phys_ascent
= it
->ascent
;
23211 it
->phys_descent
= it
->descent
;
23213 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
23214 && face
->box
!= FACE_NO_BOX
23215 && face
->box_line_width
> 0)
23217 it
->ascent
+= face
->box_line_width
;
23218 it
->descent
+= face
->box_line_width
;
23221 && XINT (height
) > it
->ascent
+ it
->descent
)
23222 it
->ascent
= XINT (height
) - it
->descent
;
23224 if (!NILP (total_height
))
23225 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
23228 spacing
= get_it_property (it
, Qline_spacing
);
23229 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
23231 if (INTEGERP (spacing
))
23233 extra_line_spacing
= XINT (spacing
);
23234 if (!NILP (total_height
))
23235 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
23239 else /* i.e. (it->char_to_display == '\t') */
23241 if (font
->space_width
> 0)
23243 int tab_width
= it
->tab_width
* font
->space_width
;
23244 int x
= it
->current_x
+ it
->continuation_lines_width
;
23245 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
23247 /* If the distance from the current position to the next tab
23248 stop is less than a space character width, use the
23249 tab stop after that. */
23250 if (next_tab_x
- x
< font
->space_width
)
23251 next_tab_x
+= tab_width
;
23253 it
->pixel_width
= next_tab_x
- x
;
23255 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
23256 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
23260 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
23261 it
->ascent
+ it
->descent
, it
->ascent
);
23266 it
->pixel_width
= 0;
23271 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
23273 /* A static composition.
23275 Note: A composition is represented as one glyph in the
23276 glyph matrix. There are no padding glyphs.
23278 Important note: pixel_width, ascent, and descent are the
23279 values of what is drawn by draw_glyphs (i.e. the values of
23280 the overall glyphs composed). */
23281 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23282 int boff
; /* baseline offset */
23283 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
23284 int glyph_len
= cmp
->glyph_len
;
23285 struct font
*font
= face
->font
;
23289 /* If we have not yet calculated pixel size data of glyphs of
23290 the composition for the current face font, calculate them
23291 now. Theoretically, we have to check all fonts for the
23292 glyphs, but that requires much time and memory space. So,
23293 here we check only the font of the first glyph. This may
23294 lead to incorrect display, but it's very rare, and C-l
23295 (recenter-top-bottom) can correct the display anyway. */
23296 if (! cmp
->font
|| cmp
->font
!= font
)
23298 /* Ascent and descent of the font of the first character
23299 of this composition (adjusted by baseline offset).
23300 Ascent and descent of overall glyphs should not be less
23301 than these, respectively. */
23302 int font_ascent
, font_descent
, font_height
;
23303 /* Bounding box of the overall glyphs. */
23304 int leftmost
, rightmost
, lowest
, highest
;
23305 int lbearing
, rbearing
;
23306 int i
, width
, ascent
, descent
;
23307 int left_padded
= 0, right_padded
= 0;
23308 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
23310 struct font_metrics
*pcm
;
23311 int font_not_found_p
;
23314 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
23315 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
23317 if (glyph_len
< cmp
->glyph_len
)
23319 for (i
= 0; i
< glyph_len
; i
++)
23321 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
23323 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
23328 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
23329 : IT_CHARPOS (*it
));
23330 /* If no suitable font is found, use the default font. */
23331 font_not_found_p
= font
== NULL
;
23332 if (font_not_found_p
)
23334 face
= face
->ascii_face
;
23337 boff
= font
->baseline_offset
;
23338 if (font
->vertical_centering
)
23339 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23340 font_ascent
= FONT_BASE (font
) + boff
;
23341 font_descent
= FONT_DESCENT (font
) - boff
;
23342 font_height
= FONT_HEIGHT (font
);
23344 cmp
->font
= (void *) font
;
23347 if (! font_not_found_p
)
23349 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
23351 pcm
= get_per_char_metric (font
, &char2b
);
23354 /* Initialize the bounding box. */
23357 width
= pcm
->width
;
23358 ascent
= pcm
->ascent
;
23359 descent
= pcm
->descent
;
23360 lbearing
= pcm
->lbearing
;
23361 rbearing
= pcm
->rbearing
;
23365 width
= font
->space_width
;
23366 ascent
= FONT_BASE (font
);
23367 descent
= FONT_DESCENT (font
);
23374 lowest
= - descent
+ boff
;
23375 highest
= ascent
+ boff
;
23377 if (! font_not_found_p
23378 && font
->default_ascent
23379 && CHAR_TABLE_P (Vuse_default_ascent
)
23380 && !NILP (Faref (Vuse_default_ascent
,
23381 make_number (it
->char_to_display
))))
23382 highest
= font
->default_ascent
+ boff
;
23384 /* Draw the first glyph at the normal position. It may be
23385 shifted to right later if some other glyphs are drawn
23387 cmp
->offsets
[i
* 2] = 0;
23388 cmp
->offsets
[i
* 2 + 1] = boff
;
23389 cmp
->lbearing
= lbearing
;
23390 cmp
->rbearing
= rbearing
;
23392 /* Set cmp->offsets for the remaining glyphs. */
23393 for (i
++; i
< glyph_len
; i
++)
23395 int left
, right
, btm
, top
;
23396 int ch
= COMPOSITION_GLYPH (cmp
, i
);
23398 struct face
*this_face
;
23402 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
23403 this_face
= FACE_FROM_ID (it
->f
, face_id
);
23404 font
= this_face
->font
;
23410 get_char_face_and_encoding (it
->f
, ch
, face_id
,
23412 pcm
= get_per_char_metric (font
, &char2b
);
23415 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
23418 width
= pcm
->width
;
23419 ascent
= pcm
->ascent
;
23420 descent
= pcm
->descent
;
23421 lbearing
= pcm
->lbearing
;
23422 rbearing
= pcm
->rbearing
;
23423 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
23425 /* Relative composition with or without
23426 alternate chars. */
23427 left
= (leftmost
+ rightmost
- width
) / 2;
23428 btm
= - descent
+ boff
;
23429 if (font
->relative_compose
23430 && (! CHAR_TABLE_P (Vignore_relative_composition
)
23431 || NILP (Faref (Vignore_relative_composition
,
23432 make_number (ch
)))))
23435 if (- descent
>= font
->relative_compose
)
23436 /* One extra pixel between two glyphs. */
23438 else if (ascent
<= 0)
23439 /* One extra pixel between two glyphs. */
23440 btm
= lowest
- 1 - ascent
- descent
;
23445 /* A composition rule is specified by an integer
23446 value that encodes global and new reference
23447 points (GREF and NREF). GREF and NREF are
23448 specified by numbers as below:
23450 0---1---2 -- ascent
23454 9--10--11 -- center
23456 ---3---4---5--- baseline
23458 6---7---8 -- descent
23460 int rule
= COMPOSITION_RULE (cmp
, i
);
23461 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
23463 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
23464 grefx
= gref
% 3, nrefx
= nref
% 3;
23465 grefy
= gref
/ 3, nrefy
= nref
/ 3;
23467 xoff
= font_height
* (xoff
- 128) / 256;
23469 yoff
= font_height
* (yoff
- 128) / 256;
23472 + grefx
* (rightmost
- leftmost
) / 2
23473 - nrefx
* width
/ 2
23476 btm
= ((grefy
== 0 ? highest
23478 : grefy
== 2 ? lowest
23479 : (highest
+ lowest
) / 2)
23480 - (nrefy
== 0 ? ascent
+ descent
23481 : nrefy
== 1 ? descent
- boff
23483 : (ascent
+ descent
) / 2)
23487 cmp
->offsets
[i
* 2] = left
;
23488 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
23490 /* Update the bounding box of the overall glyphs. */
23493 right
= left
+ width
;
23494 if (left
< leftmost
)
23496 if (right
> rightmost
)
23499 top
= btm
+ descent
+ ascent
;
23505 if (cmp
->lbearing
> left
+ lbearing
)
23506 cmp
->lbearing
= left
+ lbearing
;
23507 if (cmp
->rbearing
< left
+ rbearing
)
23508 cmp
->rbearing
= left
+ rbearing
;
23512 /* If there are glyphs whose x-offsets are negative,
23513 shift all glyphs to the right and make all x-offsets
23517 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23518 cmp
->offsets
[i
* 2] -= leftmost
;
23519 rightmost
-= leftmost
;
23520 cmp
->lbearing
-= leftmost
;
23521 cmp
->rbearing
-= leftmost
;
23524 if (left_padded
&& cmp
->lbearing
< 0)
23526 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23527 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
23528 rightmost
-= cmp
->lbearing
;
23529 cmp
->rbearing
-= cmp
->lbearing
;
23532 if (right_padded
&& rightmost
< cmp
->rbearing
)
23534 rightmost
= cmp
->rbearing
;
23537 cmp
->pixel_width
= rightmost
;
23538 cmp
->ascent
= highest
;
23539 cmp
->descent
= - lowest
;
23540 if (cmp
->ascent
< font_ascent
)
23541 cmp
->ascent
= font_ascent
;
23542 if (cmp
->descent
< font_descent
)
23543 cmp
->descent
= font_descent
;
23547 && (cmp
->lbearing
< 0
23548 || cmp
->rbearing
> cmp
->pixel_width
))
23549 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23551 it
->pixel_width
= cmp
->pixel_width
;
23552 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
23553 it
->descent
= it
->phys_descent
= cmp
->descent
;
23554 if (face
->box
!= FACE_NO_BOX
)
23556 int thick
= face
->box_line_width
;
23560 it
->ascent
+= thick
;
23561 it
->descent
+= thick
;
23566 if (it
->start_of_box_run_p
)
23567 it
->pixel_width
+= thick
;
23568 if (it
->end_of_box_run_p
)
23569 it
->pixel_width
+= thick
;
23572 /* If face has an overline, add the height of the overline
23573 (1 pixel) and a 1 pixel margin to the character height. */
23574 if (face
->overline_p
)
23575 it
->ascent
+= overline_margin
;
23577 take_vertical_position_into_account (it
);
23578 if (it
->ascent
< 0)
23580 if (it
->descent
< 0)
23584 append_composite_glyph (it
);
23586 else if (it
->what
== IT_COMPOSITION
)
23588 /* A dynamic (automatic) composition. */
23589 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23590 Lisp_Object gstring
;
23591 struct font_metrics metrics
;
23593 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
23595 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
23598 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
23599 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23600 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
23601 it
->descent
= it
->phys_descent
= metrics
.descent
;
23602 if (face
->box
!= FACE_NO_BOX
)
23604 int thick
= face
->box_line_width
;
23608 it
->ascent
+= thick
;
23609 it
->descent
+= thick
;
23614 if (it
->start_of_box_run_p
)
23615 it
->pixel_width
+= thick
;
23616 if (it
->end_of_box_run_p
)
23617 it
->pixel_width
+= thick
;
23619 /* If face has an overline, add the height of the overline
23620 (1 pixel) and a 1 pixel margin to the character height. */
23621 if (face
->overline_p
)
23622 it
->ascent
+= overline_margin
;
23623 take_vertical_position_into_account (it
);
23624 if (it
->ascent
< 0)
23626 if (it
->descent
< 0)
23630 append_composite_glyph (it
);
23632 else if (it
->what
== IT_GLYPHLESS
)
23633 produce_glyphless_glyph (it
, 0, Qnil
);
23634 else if (it
->what
== IT_IMAGE
)
23635 produce_image_glyph (it
);
23636 else if (it
->what
== IT_STRETCH
)
23637 produce_stretch_glyph (it
);
23640 /* Accumulate dimensions. Note: can't assume that it->descent > 0
23641 because this isn't true for images with `:ascent 100'. */
23642 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
23643 if (it
->area
== TEXT_AREA
)
23644 it
->current_x
+= it
->pixel_width
;
23646 if (extra_line_spacing
> 0)
23648 it
->descent
+= extra_line_spacing
;
23649 if (extra_line_spacing
> it
->max_extra_line_spacing
)
23650 it
->max_extra_line_spacing
= extra_line_spacing
;
23653 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
23654 it
->max_descent
= max (it
->max_descent
, it
->descent
);
23655 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
23656 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
23660 Output LEN glyphs starting at START at the nominal cursor position.
23661 Advance the nominal cursor over the text. The global variable
23662 updated_window contains the window being updated, updated_row is
23663 the glyph row being updated, and updated_area is the area of that
23664 row being updated. */
23667 x_write_glyphs (struct glyph
*start
, int len
)
23671 xassert (updated_window
&& updated_row
);
23674 /* Write glyphs. */
23676 hpos
= start
- updated_row
->glyphs
[updated_area
];
23677 x
= draw_glyphs (updated_window
, output_cursor
.x
,
23678 updated_row
, updated_area
,
23680 DRAW_NORMAL_TEXT
, 0);
23682 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
23683 if (updated_area
== TEXT_AREA
23684 && updated_window
->phys_cursor_on_p
23685 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
23686 && updated_window
->phys_cursor
.hpos
>= hpos
23687 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
23688 updated_window
->phys_cursor_on_p
= 0;
23692 /* Advance the output cursor. */
23693 output_cursor
.hpos
+= len
;
23694 output_cursor
.x
= x
;
23699 Insert LEN glyphs from START at the nominal cursor position. */
23702 x_insert_glyphs (struct glyph
*start
, int len
)
23706 int line_height
, shift_by_width
, shifted_region_width
;
23707 struct glyph_row
*row
;
23708 struct glyph
*glyph
;
23709 int frame_x
, frame_y
;
23712 xassert (updated_window
&& updated_row
);
23714 w
= updated_window
;
23715 f
= XFRAME (WINDOW_FRAME (w
));
23717 /* Get the height of the line we are in. */
23719 line_height
= row
->height
;
23721 /* Get the width of the glyphs to insert. */
23722 shift_by_width
= 0;
23723 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
23724 shift_by_width
+= glyph
->pixel_width
;
23726 /* Get the width of the region to shift right. */
23727 shifted_region_width
= (window_box_width (w
, updated_area
)
23732 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
23733 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
23735 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
23736 line_height
, shift_by_width
);
23738 /* Write the glyphs. */
23739 hpos
= start
- row
->glyphs
[updated_area
];
23740 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
23742 DRAW_NORMAL_TEXT
, 0);
23744 /* Advance the output cursor. */
23745 output_cursor
.hpos
+= len
;
23746 output_cursor
.x
+= shift_by_width
;
23752 Erase the current text line from the nominal cursor position
23753 (inclusive) to pixel column TO_X (exclusive). The idea is that
23754 everything from TO_X onward is already erased.
23756 TO_X is a pixel position relative to updated_area of
23757 updated_window. TO_X == -1 means clear to the end of this area. */
23760 x_clear_end_of_line (int to_x
)
23763 struct window
*w
= updated_window
;
23764 int max_x
, min_y
, max_y
;
23765 int from_x
, from_y
, to_y
;
23767 xassert (updated_window
&& updated_row
);
23768 f
= XFRAME (w
->frame
);
23770 if (updated_row
->full_width_p
)
23771 max_x
= WINDOW_TOTAL_WIDTH (w
);
23773 max_x
= window_box_width (w
, updated_area
);
23774 max_y
= window_text_bottom_y (w
);
23776 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
23777 of window. For TO_X > 0, truncate to end of drawing area. */
23783 to_x
= min (to_x
, max_x
);
23785 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
23787 /* Notice if the cursor will be cleared by this operation. */
23788 if (!updated_row
->full_width_p
)
23789 notice_overwritten_cursor (w
, updated_area
,
23790 output_cursor
.x
, -1,
23792 MATRIX_ROW_BOTTOM_Y (updated_row
));
23794 from_x
= output_cursor
.x
;
23796 /* Translate to frame coordinates. */
23797 if (updated_row
->full_width_p
)
23799 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
23800 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
23804 int area_left
= window_box_left (w
, updated_area
);
23805 from_x
+= area_left
;
23809 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
23810 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
23811 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
23813 /* Prevent inadvertently clearing to end of the X window. */
23814 if (to_x
> from_x
&& to_y
> from_y
)
23817 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
23818 to_x
- from_x
, to_y
- from_y
);
23823 #endif /* HAVE_WINDOW_SYSTEM */
23827 /***********************************************************************
23829 ***********************************************************************/
23831 /* Value is the internal representation of the specified cursor type
23832 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
23833 of the bar cursor. */
23835 static enum text_cursor_kinds
23836 get_specified_cursor_type (Lisp_Object arg
, int *width
)
23838 enum text_cursor_kinds type
;
23843 if (EQ (arg
, Qbox
))
23844 return FILLED_BOX_CURSOR
;
23846 if (EQ (arg
, Qhollow
))
23847 return HOLLOW_BOX_CURSOR
;
23849 if (EQ (arg
, Qbar
))
23856 && EQ (XCAR (arg
), Qbar
)
23857 && INTEGERP (XCDR (arg
))
23858 && XINT (XCDR (arg
)) >= 0)
23860 *width
= XINT (XCDR (arg
));
23864 if (EQ (arg
, Qhbar
))
23867 return HBAR_CURSOR
;
23871 && EQ (XCAR (arg
), Qhbar
)
23872 && INTEGERP (XCDR (arg
))
23873 && XINT (XCDR (arg
)) >= 0)
23875 *width
= XINT (XCDR (arg
));
23876 return HBAR_CURSOR
;
23879 /* Treat anything unknown as "hollow box cursor".
23880 It was bad to signal an error; people have trouble fixing
23881 .Xdefaults with Emacs, when it has something bad in it. */
23882 type
= HOLLOW_BOX_CURSOR
;
23887 /* Set the default cursor types for specified frame. */
23889 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
23894 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
23895 FRAME_CURSOR_WIDTH (f
) = width
;
23897 /* By default, set up the blink-off state depending on the on-state. */
23899 tem
= Fassoc (arg
, Vblink_cursor_alist
);
23902 FRAME_BLINK_OFF_CURSOR (f
)
23903 = get_specified_cursor_type (XCDR (tem
), &width
);
23904 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
23907 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
23911 #ifdef HAVE_WINDOW_SYSTEM
23913 /* Return the cursor we want to be displayed in window W. Return
23914 width of bar/hbar cursor through WIDTH arg. Return with
23915 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
23916 (i.e. if the `system caret' should track this cursor).
23918 In a mini-buffer window, we want the cursor only to appear if we
23919 are reading input from this window. For the selected window, we
23920 want the cursor type given by the frame parameter or buffer local
23921 setting of cursor-type. If explicitly marked off, draw no cursor.
23922 In all other cases, we want a hollow box cursor. */
23924 static enum text_cursor_kinds
23925 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
23926 int *active_cursor
)
23928 struct frame
*f
= XFRAME (w
->frame
);
23929 struct buffer
*b
= XBUFFER (w
->buffer
);
23930 int cursor_type
= DEFAULT_CURSOR
;
23931 Lisp_Object alt_cursor
;
23932 int non_selected
= 0;
23934 *active_cursor
= 1;
23937 if (cursor_in_echo_area
23938 && FRAME_HAS_MINIBUF_P (f
)
23939 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
23941 if (w
== XWINDOW (echo_area_window
))
23943 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
23945 *width
= FRAME_CURSOR_WIDTH (f
);
23946 return FRAME_DESIRED_CURSOR (f
);
23949 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
23952 *active_cursor
= 0;
23956 /* Detect a nonselected window or nonselected frame. */
23957 else if (w
!= XWINDOW (f
->selected_window
)
23958 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
23960 *active_cursor
= 0;
23962 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
23968 /* Never display a cursor in a window in which cursor-type is nil. */
23969 if (NILP (BVAR (b
, cursor_type
)))
23972 /* Get the normal cursor type for this window. */
23973 if (EQ (BVAR (b
, cursor_type
), Qt
))
23975 cursor_type
= FRAME_DESIRED_CURSOR (f
);
23976 *width
= FRAME_CURSOR_WIDTH (f
);
23979 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
23981 /* Use cursor-in-non-selected-windows instead
23982 for non-selected window or frame. */
23985 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
23986 if (!EQ (Qt
, alt_cursor
))
23987 return get_specified_cursor_type (alt_cursor
, width
);
23988 /* t means modify the normal cursor type. */
23989 if (cursor_type
== FILLED_BOX_CURSOR
)
23990 cursor_type
= HOLLOW_BOX_CURSOR
;
23991 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
23993 return cursor_type
;
23996 /* Use normal cursor if not blinked off. */
23997 if (!w
->cursor_off_p
)
23999 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
24001 if (cursor_type
== FILLED_BOX_CURSOR
)
24003 /* Using a block cursor on large images can be very annoying.
24004 So use a hollow cursor for "large" images.
24005 If image is not transparent (no mask), also use hollow cursor. */
24006 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
24007 if (img
!= NULL
&& IMAGEP (img
->spec
))
24009 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
24010 where N = size of default frame font size.
24011 This should cover most of the "tiny" icons people may use. */
24013 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
24014 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
24015 cursor_type
= HOLLOW_BOX_CURSOR
;
24018 else if (cursor_type
!= NO_CURSOR
)
24020 /* Display current only supports BOX and HOLLOW cursors for images.
24021 So for now, unconditionally use a HOLLOW cursor when cursor is
24022 not a solid box cursor. */
24023 cursor_type
= HOLLOW_BOX_CURSOR
;
24026 return cursor_type
;
24029 /* Cursor is blinked off, so determine how to "toggle" it. */
24031 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
24032 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
24033 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
24035 /* Then see if frame has specified a specific blink off cursor type. */
24036 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
24038 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
24039 return FRAME_BLINK_OFF_CURSOR (f
);
24043 /* Some people liked having a permanently visible blinking cursor,
24044 while others had very strong opinions against it. So it was
24045 decided to remove it. KFS 2003-09-03 */
24047 /* Finally perform built-in cursor blinking:
24048 filled box <-> hollow box
24049 wide [h]bar <-> narrow [h]bar
24050 narrow [h]bar <-> no cursor
24051 other type <-> no cursor */
24053 if (cursor_type
== FILLED_BOX_CURSOR
)
24054 return HOLLOW_BOX_CURSOR
;
24056 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
24059 return cursor_type
;
24067 /* Notice when the text cursor of window W has been completely
24068 overwritten by a drawing operation that outputs glyphs in AREA
24069 starting at X0 and ending at X1 in the line starting at Y0 and
24070 ending at Y1. X coordinates are area-relative. X1 < 0 means all
24071 the rest of the line after X0 has been written. Y coordinates
24072 are window-relative. */
24075 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
24076 int x0
, int x1
, int y0
, int y1
)
24078 int cx0
, cx1
, cy0
, cy1
;
24079 struct glyph_row
*row
;
24081 if (!w
->phys_cursor_on_p
)
24083 if (area
!= TEXT_AREA
)
24086 if (w
->phys_cursor
.vpos
< 0
24087 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
24088 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
24089 !(row
->enabled_p
&& row
->displays_text_p
)))
24092 if (row
->cursor_in_fringe_p
)
24094 row
->cursor_in_fringe_p
= 0;
24095 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
24096 w
->phys_cursor_on_p
= 0;
24100 cx0
= w
->phys_cursor
.x
;
24101 cx1
= cx0
+ w
->phys_cursor_width
;
24102 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
24105 /* The cursor image will be completely removed from the
24106 screen if the output area intersects the cursor area in
24107 y-direction. When we draw in [y0 y1[, and some part of
24108 the cursor is at y < y0, that part must have been drawn
24109 before. When scrolling, the cursor is erased before
24110 actually scrolling, so we don't come here. When not
24111 scrolling, the rows above the old cursor row must have
24112 changed, and in this case these rows must have written
24113 over the cursor image.
24115 Likewise if part of the cursor is below y1, with the
24116 exception of the cursor being in the first blank row at
24117 the buffer and window end because update_text_area
24118 doesn't draw that row. (Except when it does, but
24119 that's handled in update_text_area.) */
24121 cy0
= w
->phys_cursor
.y
;
24122 cy1
= cy0
+ w
->phys_cursor_height
;
24123 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
24126 w
->phys_cursor_on_p
= 0;
24129 #endif /* HAVE_WINDOW_SYSTEM */
24132 /************************************************************************
24134 ************************************************************************/
24136 #ifdef HAVE_WINDOW_SYSTEM
24139 Fix the display of area AREA of overlapping row ROW in window W
24140 with respect to the overlapping part OVERLAPS. */
24143 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
24144 enum glyph_row_area area
, int overlaps
)
24151 for (i
= 0; i
< row
->used
[area
];)
24153 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
24155 int start
= i
, start_x
= x
;
24159 x
+= row
->glyphs
[area
][i
].pixel_width
;
24162 while (i
< row
->used
[area
]
24163 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
24165 draw_glyphs (w
, start_x
, row
, area
,
24167 DRAW_NORMAL_TEXT
, overlaps
);
24171 x
+= row
->glyphs
[area
][i
].pixel_width
;
24181 Draw the cursor glyph of window W in glyph row ROW. See the
24182 comment of draw_glyphs for the meaning of HL. */
24185 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
24186 enum draw_glyphs_face hl
)
24188 /* If cursor hpos is out of bounds, don't draw garbage. This can
24189 happen in mini-buffer windows when switching between echo area
24190 glyphs and mini-buffer. */
24191 if ((row
->reversed_p
24192 ? (w
->phys_cursor
.hpos
>= 0)
24193 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
24195 int on_p
= w
->phys_cursor_on_p
;
24197 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
24198 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
24200 w
->phys_cursor_on_p
= on_p
;
24202 if (hl
== DRAW_CURSOR
)
24203 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
24204 /* When we erase the cursor, and ROW is overlapped by other
24205 rows, make sure that these overlapping parts of other rows
24207 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
24209 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
24211 if (row
> w
->current_matrix
->rows
24212 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
24213 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
24214 OVERLAPS_ERASED_CURSOR
);
24216 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
24217 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
24218 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
24219 OVERLAPS_ERASED_CURSOR
);
24226 Erase the image of a cursor of window W from the screen. */
24229 erase_phys_cursor (struct window
*w
)
24231 struct frame
*f
= XFRAME (w
->frame
);
24232 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
24233 int hpos
= w
->phys_cursor
.hpos
;
24234 int vpos
= w
->phys_cursor
.vpos
;
24235 int mouse_face_here_p
= 0;
24236 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
24237 struct glyph_row
*cursor_row
;
24238 struct glyph
*cursor_glyph
;
24239 enum draw_glyphs_face hl
;
24241 /* No cursor displayed or row invalidated => nothing to do on the
24243 if (w
->phys_cursor_type
== NO_CURSOR
)
24244 goto mark_cursor_off
;
24246 /* VPOS >= active_glyphs->nrows means that window has been resized.
24247 Don't bother to erase the cursor. */
24248 if (vpos
>= active_glyphs
->nrows
)
24249 goto mark_cursor_off
;
24251 /* If row containing cursor is marked invalid, there is nothing we
24253 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
24254 if (!cursor_row
->enabled_p
)
24255 goto mark_cursor_off
;
24257 /* If line spacing is > 0, old cursor may only be partially visible in
24258 window after split-window. So adjust visible height. */
24259 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
24260 window_text_bottom_y (w
) - cursor_row
->y
);
24262 /* If row is completely invisible, don't attempt to delete a cursor which
24263 isn't there. This can happen if cursor is at top of a window, and
24264 we switch to a buffer with a header line in that window. */
24265 if (cursor_row
->visible_height
<= 0)
24266 goto mark_cursor_off
;
24268 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
24269 if (cursor_row
->cursor_in_fringe_p
)
24271 cursor_row
->cursor_in_fringe_p
= 0;
24272 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
24273 goto mark_cursor_off
;
24276 /* This can happen when the new row is shorter than the old one.
24277 In this case, either draw_glyphs or clear_end_of_line
24278 should have cleared the cursor. Note that we wouldn't be
24279 able to erase the cursor in this case because we don't have a
24280 cursor glyph at hand. */
24281 if ((cursor_row
->reversed_p
24282 ? (w
->phys_cursor
.hpos
< 0)
24283 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
24284 goto mark_cursor_off
;
24286 /* If the cursor is in the mouse face area, redisplay that when
24287 we clear the cursor. */
24288 if (! NILP (hlinfo
->mouse_face_window
)
24289 && coords_in_mouse_face_p (w
, hpos
, vpos
)
24290 /* Don't redraw the cursor's spot in mouse face if it is at the
24291 end of a line (on a newline). The cursor appears there, but
24292 mouse highlighting does not. */
24293 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
24294 mouse_face_here_p
= 1;
24296 /* Maybe clear the display under the cursor. */
24297 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
24300 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
24303 cursor_glyph
= get_phys_cursor_glyph (w
);
24304 if (cursor_glyph
== NULL
)
24305 goto mark_cursor_off
;
24307 width
= cursor_glyph
->pixel_width
;
24308 left_x
= window_box_left_offset (w
, TEXT_AREA
);
24309 x
= w
->phys_cursor
.x
;
24311 width
-= left_x
- x
;
24312 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
24313 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
24314 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
24317 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
24320 /* Erase the cursor by redrawing the character underneath it. */
24321 if (mouse_face_here_p
)
24322 hl
= DRAW_MOUSE_FACE
;
24324 hl
= DRAW_NORMAL_TEXT
;
24325 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
24328 w
->phys_cursor_on_p
= 0;
24329 w
->phys_cursor_type
= NO_CURSOR
;
24334 Display or clear cursor of window W. If ON is zero, clear the
24335 cursor. If it is non-zero, display the cursor. If ON is nonzero,
24336 where to put the cursor is specified by HPOS, VPOS, X and Y. */
24339 display_and_set_cursor (struct window
*w
, int on
,
24340 int hpos
, int vpos
, int x
, int y
)
24342 struct frame
*f
= XFRAME (w
->frame
);
24343 int new_cursor_type
;
24344 int new_cursor_width
;
24346 struct glyph_row
*glyph_row
;
24347 struct glyph
*glyph
;
24349 /* This is pointless on invisible frames, and dangerous on garbaged
24350 windows and frames; in the latter case, the frame or window may
24351 be in the midst of changing its size, and x and y may be off the
24353 if (! FRAME_VISIBLE_P (f
)
24354 || FRAME_GARBAGED_P (f
)
24355 || vpos
>= w
->current_matrix
->nrows
24356 || hpos
>= w
->current_matrix
->matrix_w
)
24359 /* If cursor is off and we want it off, return quickly. */
24360 if (!on
&& !w
->phys_cursor_on_p
)
24363 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
24364 /* If cursor row is not enabled, we don't really know where to
24365 display the cursor. */
24366 if (!glyph_row
->enabled_p
)
24368 w
->phys_cursor_on_p
= 0;
24373 if (!glyph_row
->exact_window_width_line_p
24374 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
24375 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
24377 xassert (interrupt_input_blocked
);
24379 /* Set new_cursor_type to the cursor we want to be displayed. */
24380 new_cursor_type
= get_window_cursor_type (w
, glyph
,
24381 &new_cursor_width
, &active_cursor
);
24383 /* If cursor is currently being shown and we don't want it to be or
24384 it is in the wrong place, or the cursor type is not what we want,
24386 if (w
->phys_cursor_on_p
24388 || w
->phys_cursor
.x
!= x
24389 || w
->phys_cursor
.y
!= y
24390 || new_cursor_type
!= w
->phys_cursor_type
24391 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
24392 && new_cursor_width
!= w
->phys_cursor_width
)))
24393 erase_phys_cursor (w
);
24395 /* Don't check phys_cursor_on_p here because that flag is only set
24396 to zero in some cases where we know that the cursor has been
24397 completely erased, to avoid the extra work of erasing the cursor
24398 twice. In other words, phys_cursor_on_p can be 1 and the cursor
24399 still not be visible, or it has only been partly erased. */
24402 w
->phys_cursor_ascent
= glyph_row
->ascent
;
24403 w
->phys_cursor_height
= glyph_row
->height
;
24405 /* Set phys_cursor_.* before x_draw_.* is called because some
24406 of them may need the information. */
24407 w
->phys_cursor
.x
= x
;
24408 w
->phys_cursor
.y
= glyph_row
->y
;
24409 w
->phys_cursor
.hpos
= hpos
;
24410 w
->phys_cursor
.vpos
= vpos
;
24413 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
24414 new_cursor_type
, new_cursor_width
,
24415 on
, active_cursor
);
24419 /* Switch the display of W's cursor on or off, according to the value
24423 update_window_cursor (struct window
*w
, int on
)
24425 /* Don't update cursor in windows whose frame is in the process
24426 of being deleted. */
24427 if (w
->current_matrix
)
24430 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24431 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24437 /* Call update_window_cursor with parameter ON_P on all leaf windows
24438 in the window tree rooted at W. */
24441 update_cursor_in_window_tree (struct window
*w
, int on_p
)
24445 if (!NILP (w
->hchild
))
24446 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
24447 else if (!NILP (w
->vchild
))
24448 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
24450 update_window_cursor (w
, on_p
);
24452 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
24458 Display the cursor on window W, or clear it, according to ON_P.
24459 Don't change the cursor's position. */
24462 x_update_cursor (struct frame
*f
, int on_p
)
24464 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
24469 Clear the cursor of window W to background color, and mark the
24470 cursor as not shown. This is used when the text where the cursor
24471 is about to be rewritten. */
24474 x_clear_cursor (struct window
*w
)
24476 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
24477 update_window_cursor (w
, 0);
24480 #endif /* HAVE_WINDOW_SYSTEM */
24482 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
24485 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
24486 int start_hpos
, int end_hpos
,
24487 enum draw_glyphs_face draw
)
24489 #ifdef HAVE_WINDOW_SYSTEM
24490 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
24492 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
24496 #if defined (HAVE_GPM) || defined (MSDOS)
24497 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
24501 /* Display the active region described by mouse_face_* according to DRAW. */
24504 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
24506 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
24507 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24509 if (/* If window is in the process of being destroyed, don't bother
24511 w
->current_matrix
!= NULL
24512 /* Don't update mouse highlight if hidden */
24513 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
24514 /* Recognize when we are called to operate on rows that don't exist
24515 anymore. This can happen when a window is split. */
24516 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
24518 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
24519 struct glyph_row
*row
, *first
, *last
;
24521 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
24522 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
24524 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
24526 int start_hpos
, end_hpos
, start_x
;
24528 /* For all but the first row, the highlight starts at column 0. */
24531 /* R2L rows have BEG and END in reversed order, but the
24532 screen drawing geometry is always left to right. So
24533 we need to mirror the beginning and end of the
24534 highlighted area in R2L rows. */
24535 if (!row
->reversed_p
)
24537 start_hpos
= hlinfo
->mouse_face_beg_col
;
24538 start_x
= hlinfo
->mouse_face_beg_x
;
24540 else if (row
== last
)
24542 start_hpos
= hlinfo
->mouse_face_end_col
;
24543 start_x
= hlinfo
->mouse_face_end_x
;
24551 else if (row
->reversed_p
&& row
== last
)
24553 start_hpos
= hlinfo
->mouse_face_end_col
;
24554 start_x
= hlinfo
->mouse_face_end_x
;
24564 if (!row
->reversed_p
)
24565 end_hpos
= hlinfo
->mouse_face_end_col
;
24566 else if (row
== first
)
24567 end_hpos
= hlinfo
->mouse_face_beg_col
;
24570 end_hpos
= row
->used
[TEXT_AREA
];
24571 if (draw
== DRAW_NORMAL_TEXT
)
24572 row
->fill_line_p
= 1; /* Clear to end of line */
24575 else if (row
->reversed_p
&& row
== first
)
24576 end_hpos
= hlinfo
->mouse_face_beg_col
;
24579 end_hpos
= row
->used
[TEXT_AREA
];
24580 if (draw
== DRAW_NORMAL_TEXT
)
24581 row
->fill_line_p
= 1; /* Clear to end of line */
24584 if (end_hpos
> start_hpos
)
24586 draw_row_with_mouse_face (w
, start_x
, row
,
24587 start_hpos
, end_hpos
, draw
);
24590 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
24594 #ifdef HAVE_WINDOW_SYSTEM
24595 /* When we've written over the cursor, arrange for it to
24596 be displayed again. */
24597 if (FRAME_WINDOW_P (f
)
24598 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
24601 display_and_set_cursor (w
, 1,
24602 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24603 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24606 #endif /* HAVE_WINDOW_SYSTEM */
24609 #ifdef HAVE_WINDOW_SYSTEM
24610 /* Change the mouse cursor. */
24611 if (FRAME_WINDOW_P (f
))
24613 if (draw
== DRAW_NORMAL_TEXT
24614 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
24615 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
24616 else if (draw
== DRAW_MOUSE_FACE
)
24617 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
24619 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
24621 #endif /* HAVE_WINDOW_SYSTEM */
24625 Clear out the mouse-highlighted active region.
24626 Redraw it un-highlighted first. Value is non-zero if mouse
24627 face was actually drawn unhighlighted. */
24630 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
24634 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
24636 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
24640 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
24641 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
24642 hlinfo
->mouse_face_window
= Qnil
;
24643 hlinfo
->mouse_face_overlay
= Qnil
;
24647 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
24648 within the mouse face on that window. */
24650 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
24652 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
24654 /* Quickly resolve the easy cases. */
24655 if (!(WINDOWP (hlinfo
->mouse_face_window
)
24656 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
24658 if (vpos
< hlinfo
->mouse_face_beg_row
24659 || vpos
> hlinfo
->mouse_face_end_row
)
24661 if (vpos
> hlinfo
->mouse_face_beg_row
24662 && vpos
< hlinfo
->mouse_face_end_row
)
24665 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
24667 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24669 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
24672 else if ((vpos
== hlinfo
->mouse_face_beg_row
24673 && hpos
>= hlinfo
->mouse_face_beg_col
)
24674 || (vpos
== hlinfo
->mouse_face_end_row
24675 && hpos
< hlinfo
->mouse_face_end_col
))
24680 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24682 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
24685 else if ((vpos
== hlinfo
->mouse_face_beg_row
24686 && hpos
<= hlinfo
->mouse_face_beg_col
)
24687 || (vpos
== hlinfo
->mouse_face_end_row
24688 && hpos
> hlinfo
->mouse_face_end_col
))
24696 Non-zero if physical cursor of window W is within mouse face. */
24699 cursor_in_mouse_face_p (struct window
*w
)
24701 return coords_in_mouse_face_p (w
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
);
24706 /* Find the glyph rows START_ROW and END_ROW of window W that display
24707 characters between buffer positions START_CHARPOS and END_CHARPOS
24708 (excluding END_CHARPOS). This is similar to row_containing_pos,
24709 but is more accurate when bidi reordering makes buffer positions
24710 change non-linearly with glyph rows. */
24712 rows_from_pos_range (struct window
*w
,
24713 EMACS_INT start_charpos
, EMACS_INT end_charpos
,
24714 struct glyph_row
**start
, struct glyph_row
**end
)
24716 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24717 int last_y
= window_text_bottom_y (w
);
24718 struct glyph_row
*row
;
24723 while (!first
->enabled_p
24724 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
24727 /* Find the START row. */
24729 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
24732 /* A row can potentially be the START row if the range of the
24733 characters it displays intersects the range
24734 [START_CHARPOS..END_CHARPOS). */
24735 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
24736 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
24737 /* See the commentary in row_containing_pos, for the
24738 explanation of the complicated way to check whether
24739 some position is beyond the end of the characters
24740 displayed by a row. */
24741 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24742 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24743 && !row
->ends_at_zv_p
24744 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
24745 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24746 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24747 && !row
->ends_at_zv_p
24748 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
24750 /* Found a candidate row. Now make sure at least one of the
24751 glyphs it displays has a charpos from the range
24752 [START_CHARPOS..END_CHARPOS).
24754 This is not obvious because bidi reordering could make
24755 buffer positions of a row be 1,2,3,102,101,100, and if we
24756 want to highlight characters in [50..60), we don't want
24757 this row, even though [50..60) does intersect [1..103),
24758 the range of character positions given by the row's start
24759 and end positions. */
24760 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
24761 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
24765 if (BUFFERP (g
->object
)
24766 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24775 /* Find the END row. */
24777 /* If the last row is partially visible, start looking for END
24778 from that row, instead of starting from FIRST. */
24779 && !(row
->enabled_p
24780 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
24782 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
24784 struct glyph_row
*next
= row
+ 1;
24786 if (!next
->enabled_p
24787 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
24788 /* The first row >= START whose range of displayed characters
24789 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
24790 is the row END + 1. */
24791 || (start_charpos
< MATRIX_ROW_START_CHARPOS (next
)
24792 && end_charpos
< MATRIX_ROW_START_CHARPOS (next
))
24793 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24794 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24795 && !next
->ends_at_zv_p
24796 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
24797 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24798 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24799 && !next
->ends_at_zv_p
24800 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
24807 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
24808 but none of the characters it displays are in the range, it is
24810 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
24811 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
24815 if (BUFFERP (g
->object
)
24816 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24829 /* This function sets the mouse_face_* elements of HLINFO, assuming
24830 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
24831 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
24832 for the overlay or run of text properties specifying the mouse
24833 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
24834 before-string and after-string that must also be highlighted.
24835 COVER_STRING, if non-nil, is a display string that may cover some
24836 or all of the highlighted text. */
24839 mouse_face_from_buffer_pos (Lisp_Object window
,
24840 Mouse_HLInfo
*hlinfo
,
24841 EMACS_INT mouse_charpos
,
24842 EMACS_INT start_charpos
,
24843 EMACS_INT end_charpos
,
24844 Lisp_Object before_string
,
24845 Lisp_Object after_string
,
24846 Lisp_Object cover_string
)
24848 struct window
*w
= XWINDOW (window
);
24849 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24850 struct glyph_row
*r1
, *r2
;
24851 struct glyph
*glyph
, *end
;
24852 EMACS_INT ignore
, pos
;
24855 xassert (NILP (cover_string
) || STRINGP (cover_string
));
24856 xassert (NILP (before_string
) || STRINGP (before_string
));
24857 xassert (NILP (after_string
) || STRINGP (after_string
));
24859 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
24860 rows_from_pos_range (w
, start_charpos
, end_charpos
, &r1
, &r2
);
24862 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24863 /* If the before-string or display-string contains newlines,
24864 rows_from_pos_range skips to its last row. Move back. */
24865 if (!NILP (before_string
) || !NILP (cover_string
))
24867 struct glyph_row
*prev
;
24868 while ((prev
= r1
- 1, prev
>= first
)
24869 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
24870 && prev
->used
[TEXT_AREA
] > 0)
24872 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
24873 glyph
= beg
+ prev
->used
[TEXT_AREA
];
24874 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
24876 || !(EQ (glyph
->object
, before_string
)
24877 || EQ (glyph
->object
, cover_string
)))
24884 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24885 hlinfo
->mouse_face_past_end
= 1;
24887 else if (!NILP (after_string
))
24889 /* If the after-string has newlines, advance to its last row. */
24890 struct glyph_row
*next
;
24891 struct glyph_row
*last
24892 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24894 for (next
= r2
+ 1;
24896 && next
->used
[TEXT_AREA
] > 0
24897 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
24901 /* The rest of the display engine assumes that mouse_face_beg_row is
24902 either above below mouse_face_end_row or identical to it. But
24903 with bidi-reordered continued lines, the row for START_CHARPOS
24904 could be below the row for END_CHARPOS. If so, swap the rows and
24905 store them in correct order. */
24908 struct glyph_row
*tem
= r2
;
24914 hlinfo
->mouse_face_beg_y
= r1
->y
;
24915 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
24916 hlinfo
->mouse_face_end_y
= r2
->y
;
24917 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
24919 /* For a bidi-reordered row, the positions of BEFORE_STRING,
24920 AFTER_STRING, COVER_STRING, START_CHARPOS, and END_CHARPOS
24921 could be anywhere in the row and in any order. The strategy
24922 below is to find the leftmost and the rightmost glyph that
24923 belongs to either of these 3 strings, or whose position is
24924 between START_CHARPOS and END_CHARPOS, and highlight all the
24925 glyphs between those two. This may cover more than just the text
24926 between START_CHARPOS and END_CHARPOS if the range of characters
24927 strides the bidi level boundary, e.g. if the beginning is in R2L
24928 text while the end is in L2R text or vice versa. */
24929 if (!r1
->reversed_p
)
24931 /* This row is in a left to right paragraph. Scan it left to
24933 glyph
= r1
->glyphs
[TEXT_AREA
];
24934 end
= glyph
+ r1
->used
[TEXT_AREA
];
24937 /* Skip truncation glyphs at the start of the glyph row. */
24938 if (r1
->displays_text_p
)
24940 && INTEGERP (glyph
->object
)
24941 && glyph
->charpos
< 0;
24943 x
+= glyph
->pixel_width
;
24945 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24946 or COVER_STRING, and the first glyph from buffer whose
24947 position is between START_CHARPOS and END_CHARPOS. */
24949 && !INTEGERP (glyph
->object
)
24950 && !EQ (glyph
->object
, cover_string
)
24951 && !(BUFFERP (glyph
->object
)
24952 && (glyph
->charpos
>= start_charpos
24953 && glyph
->charpos
< end_charpos
));
24956 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24957 are present at buffer positions between START_CHARPOS and
24958 END_CHARPOS, or if they come from an overlay. */
24959 if (EQ (glyph
->object
, before_string
))
24961 pos
= string_buffer_position (before_string
,
24963 /* If pos == 0, it means before_string came from an
24964 overlay, not from a buffer position. */
24965 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24968 else if (EQ (glyph
->object
, after_string
))
24970 pos
= string_buffer_position (after_string
, end_charpos
);
24971 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24974 x
+= glyph
->pixel_width
;
24976 hlinfo
->mouse_face_beg_x
= x
;
24977 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24981 /* This row is in a right to left paragraph. Scan it right to
24985 end
= r1
->glyphs
[TEXT_AREA
] - 1;
24986 glyph
= end
+ r1
->used
[TEXT_AREA
];
24988 /* Skip truncation glyphs at the start of the glyph row. */
24989 if (r1
->displays_text_p
)
24991 && INTEGERP (glyph
->object
)
24992 && glyph
->charpos
< 0;
24996 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24997 or COVER_STRING, and the first glyph from buffer whose
24998 position is between START_CHARPOS and END_CHARPOS. */
25000 && !INTEGERP (glyph
->object
)
25001 && !EQ (glyph
->object
, cover_string
)
25002 && !(BUFFERP (glyph
->object
)
25003 && (glyph
->charpos
>= start_charpos
25004 && glyph
->charpos
< end_charpos
));
25007 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25008 are present at buffer positions between START_CHARPOS and
25009 END_CHARPOS, or if they come from an overlay. */
25010 if (EQ (glyph
->object
, before_string
))
25012 pos
= string_buffer_position (before_string
, start_charpos
);
25013 /* If pos == 0, it means before_string came from an
25014 overlay, not from a buffer position. */
25015 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25018 else if (EQ (glyph
->object
, after_string
))
25020 pos
= string_buffer_position (after_string
, end_charpos
);
25021 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25026 glyph
++; /* first glyph to the right of the highlighted area */
25027 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
25028 x
+= g
->pixel_width
;
25029 hlinfo
->mouse_face_beg_x
= x
;
25030 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
25033 /* If the highlight ends in a different row, compute GLYPH and END
25034 for the end row. Otherwise, reuse the values computed above for
25035 the row where the highlight begins. */
25038 if (!r2
->reversed_p
)
25040 glyph
= r2
->glyphs
[TEXT_AREA
];
25041 end
= glyph
+ r2
->used
[TEXT_AREA
];
25046 end
= r2
->glyphs
[TEXT_AREA
] - 1;
25047 glyph
= end
+ r2
->used
[TEXT_AREA
];
25051 if (!r2
->reversed_p
)
25053 /* Skip truncation and continuation glyphs near the end of the
25054 row, and also blanks and stretch glyphs inserted by
25055 extend_face_to_end_of_line. */
25057 && INTEGERP ((end
- 1)->object
)
25058 && (end
- 1)->charpos
<= 0)
25060 /* Scan the rest of the glyph row from the end, looking for the
25061 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
25062 COVER_STRING, or whose position is between START_CHARPOS
25066 && !INTEGERP (end
->object
)
25067 && !EQ (end
->object
, cover_string
)
25068 && !(BUFFERP (end
->object
)
25069 && (end
->charpos
>= start_charpos
25070 && end
->charpos
< end_charpos
));
25073 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25074 are present at buffer positions between START_CHARPOS and
25075 END_CHARPOS, or if they come from an overlay. */
25076 if (EQ (end
->object
, before_string
))
25078 pos
= string_buffer_position (before_string
, start_charpos
);
25079 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25082 else if (EQ (end
->object
, after_string
))
25084 pos
= string_buffer_position (after_string
, end_charpos
);
25085 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25089 /* Find the X coordinate of the last glyph to be highlighted. */
25090 for (; glyph
<= end
; ++glyph
)
25091 x
+= glyph
->pixel_width
;
25093 hlinfo
->mouse_face_end_x
= x
;
25094 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
25098 /* Skip truncation and continuation glyphs near the end of the
25099 row, and also blanks and stretch glyphs inserted by
25100 extend_face_to_end_of_line. */
25104 && INTEGERP (end
->object
)
25105 && end
->charpos
<= 0)
25107 x
+= end
->pixel_width
;
25110 /* Scan the rest of the glyph row from the end, looking for the
25111 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
25112 COVER_STRING, or whose position is between START_CHARPOS
25116 && !INTEGERP (end
->object
)
25117 && !EQ (end
->object
, cover_string
)
25118 && !(BUFFERP (end
->object
)
25119 && (end
->charpos
>= start_charpos
25120 && end
->charpos
< end_charpos
));
25123 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25124 are present at buffer positions between START_CHARPOS and
25125 END_CHARPOS, or if they come from an overlay. */
25126 if (EQ (end
->object
, before_string
))
25128 pos
= string_buffer_position (before_string
, start_charpos
);
25129 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25132 else if (EQ (end
->object
, after_string
))
25134 pos
= string_buffer_position (after_string
, end_charpos
);
25135 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25138 x
+= end
->pixel_width
;
25140 hlinfo
->mouse_face_end_x
= x
;
25141 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
25144 hlinfo
->mouse_face_window
= window
;
25145 hlinfo
->mouse_face_face_id
25146 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
25148 !hlinfo
->mouse_face_hidden
, -1);
25149 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25152 /* The following function is not used anymore (replaced with
25153 mouse_face_from_string_pos), but I leave it here for the time
25154 being, in case someone would. */
25156 #if 0 /* not used */
25158 /* Find the position of the glyph for position POS in OBJECT in
25159 window W's current matrix, and return in *X, *Y the pixel
25160 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
25162 RIGHT_P non-zero means return the position of the right edge of the
25163 glyph, RIGHT_P zero means return the left edge position.
25165 If no glyph for POS exists in the matrix, return the position of
25166 the glyph with the next smaller position that is in the matrix, if
25167 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
25168 exists in the matrix, return the position of the glyph with the
25169 next larger position in OBJECT.
25171 Value is non-zero if a glyph was found. */
25174 fast_find_string_pos (struct window
*w
, EMACS_INT pos
, Lisp_Object object
,
25175 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
25177 int yb
= window_text_bottom_y (w
);
25178 struct glyph_row
*r
;
25179 struct glyph
*best_glyph
= NULL
;
25180 struct glyph_row
*best_row
= NULL
;
25183 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25184 r
->enabled_p
&& r
->y
< yb
;
25187 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
25188 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
25191 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
25192 if (EQ (g
->object
, object
))
25194 if (g
->charpos
== pos
)
25201 else if (best_glyph
== NULL
25202 || ((eabs (g
->charpos
- pos
)
25203 < eabs (best_glyph
->charpos
- pos
))
25206 : g
->charpos
> pos
)))
25220 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
25224 *x
+= best_glyph
->pixel_width
;
25229 *vpos
= best_row
- w
->current_matrix
->rows
;
25232 return best_glyph
!= NULL
;
25234 #endif /* not used */
25236 /* Find the positions of the first and the last glyphs in window W's
25237 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
25238 (assumed to be a string), and return in HLINFO's mouse_face_*
25239 members the pixel and column/row coordinates of those glyphs. */
25242 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
25243 Lisp_Object object
,
25244 EMACS_INT startpos
, EMACS_INT endpos
)
25246 int yb
= window_text_bottom_y (w
);
25247 struct glyph_row
*r
;
25248 struct glyph
*g
, *e
;
25252 /* Find the glyph row with at least one position in the range
25253 [STARTPOS..ENDPOS], and the first glyph in that row whose
25254 position belongs to that range. */
25255 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25256 r
->enabled_p
&& r
->y
< yb
;
25259 if (!r
->reversed_p
)
25261 g
= r
->glyphs
[TEXT_AREA
];
25262 e
= g
+ r
->used
[TEXT_AREA
];
25263 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
25264 if (EQ (g
->object
, object
)
25265 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
25267 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
25268 hlinfo
->mouse_face_beg_y
= r
->y
;
25269 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
25270 hlinfo
->mouse_face_beg_x
= gx
;
25279 e
= r
->glyphs
[TEXT_AREA
];
25280 g
= e
+ r
->used
[TEXT_AREA
];
25281 for ( ; g
> e
; --g
)
25282 if (EQ ((g
-1)->object
, object
)
25283 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
25285 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
25286 hlinfo
->mouse_face_beg_y
= r
->y
;
25287 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
25288 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
25289 gx
+= g1
->pixel_width
;
25290 hlinfo
->mouse_face_beg_x
= gx
;
25302 /* Starting with the next row, look for the first row which does NOT
25303 include any glyphs whose positions are in the range. */
25304 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
25306 g
= r
->glyphs
[TEXT_AREA
];
25307 e
= g
+ r
->used
[TEXT_AREA
];
25309 for ( ; g
< e
; ++g
)
25310 if (EQ (g
->object
, object
)
25311 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
25320 /* The highlighted region ends on the previous row. */
25323 /* Set the end row and its vertical pixel coordinate. */
25324 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
25325 hlinfo
->mouse_face_end_y
= r
->y
;
25327 /* Compute and set the end column and the end column's horizontal
25328 pixel coordinate. */
25329 if (!r
->reversed_p
)
25331 g
= r
->glyphs
[TEXT_AREA
];
25332 e
= g
+ r
->used
[TEXT_AREA
];
25333 for ( ; e
> g
; --e
)
25334 if (EQ ((e
-1)->object
, object
)
25335 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
25337 hlinfo
->mouse_face_end_col
= e
- g
;
25339 for (gx
= r
->x
; g
< e
; ++g
)
25340 gx
+= g
->pixel_width
;
25341 hlinfo
->mouse_face_end_x
= gx
;
25345 e
= r
->glyphs
[TEXT_AREA
];
25346 g
= e
+ r
->used
[TEXT_AREA
];
25347 for (gx
= r
->x
; e
< g
; ++e
)
25349 if (EQ (e
->object
, object
)
25350 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
25352 gx
+= e
->pixel_width
;
25354 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
25355 hlinfo
->mouse_face_end_x
= gx
;
25359 #ifdef HAVE_WINDOW_SYSTEM
25361 /* See if position X, Y is within a hot-spot of an image. */
25364 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
25366 if (!CONSP (hot_spot
))
25369 if (EQ (XCAR (hot_spot
), Qrect
))
25371 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
25372 Lisp_Object rect
= XCDR (hot_spot
);
25376 if (!CONSP (XCAR (rect
)))
25378 if (!CONSP (XCDR (rect
)))
25380 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
25382 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
25384 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
25386 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
25390 else if (EQ (XCAR (hot_spot
), Qcircle
))
25392 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
25393 Lisp_Object circ
= XCDR (hot_spot
);
25394 Lisp_Object lr
, lx0
, ly0
;
25396 && CONSP (XCAR (circ
))
25397 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
25398 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
25399 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
25401 double r
= XFLOATINT (lr
);
25402 double dx
= XINT (lx0
) - x
;
25403 double dy
= XINT (ly0
) - y
;
25404 return (dx
* dx
+ dy
* dy
<= r
* r
);
25407 else if (EQ (XCAR (hot_spot
), Qpoly
))
25409 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
25410 if (VECTORP (XCDR (hot_spot
)))
25412 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
25413 Lisp_Object
*poly
= v
->contents
;
25414 int n
= v
->header
.size
;
25417 Lisp_Object lx
, ly
;
25420 /* Need an even number of coordinates, and at least 3 edges. */
25421 if (n
< 6 || n
& 1)
25424 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
25425 If count is odd, we are inside polygon. Pixels on edges
25426 may or may not be included depending on actual geometry of the
25428 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
25429 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
25431 x0
= XINT (lx
), y0
= XINT (ly
);
25432 for (i
= 0; i
< n
; i
+= 2)
25434 int x1
= x0
, y1
= y0
;
25435 if ((lx
= poly
[i
], !INTEGERP (lx
))
25436 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
25438 x0
= XINT (lx
), y0
= XINT (ly
);
25440 /* Does this segment cross the X line? */
25448 if (y
> y0
&& y
> y1
)
25450 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
25460 find_hot_spot (Lisp_Object map
, int x
, int y
)
25462 while (CONSP (map
))
25464 if (CONSP (XCAR (map
))
25465 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
25473 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
25475 doc
: /* Lookup in image map MAP coordinates X and Y.
25476 An image map is an alist where each element has the format (AREA ID PLIST).
25477 An AREA is specified as either a rectangle, a circle, or a polygon:
25478 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
25479 pixel coordinates of the upper left and bottom right corners.
25480 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
25481 and the radius of the circle; r may be a float or integer.
25482 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
25483 vector describes one corner in the polygon.
25484 Returns the alist element for the first matching AREA in MAP. */)
25485 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
25493 return find_hot_spot (map
, XINT (x
), XINT (y
));
25497 /* Display frame CURSOR, optionally using shape defined by POINTER. */
25499 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
25501 /* Do not change cursor shape while dragging mouse. */
25502 if (!NILP (do_mouse_tracking
))
25505 if (!NILP (pointer
))
25507 if (EQ (pointer
, Qarrow
))
25508 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25509 else if (EQ (pointer
, Qhand
))
25510 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
25511 else if (EQ (pointer
, Qtext
))
25512 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25513 else if (EQ (pointer
, intern ("hdrag")))
25514 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25515 #ifdef HAVE_X_WINDOWS
25516 else if (EQ (pointer
, intern ("vdrag")))
25517 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
25519 else if (EQ (pointer
, intern ("hourglass")))
25520 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
25521 else if (EQ (pointer
, Qmodeline
))
25522 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
25524 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25527 if (cursor
!= No_Cursor
)
25528 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
25531 #endif /* HAVE_WINDOW_SYSTEM */
25533 /* Take proper action when mouse has moved to the mode or header line
25534 or marginal area AREA of window W, x-position X and y-position Y.
25535 X is relative to the start of the text display area of W, so the
25536 width of bitmap areas and scroll bars must be subtracted to get a
25537 position relative to the start of the mode line. */
25540 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
25541 enum window_part area
)
25543 struct window
*w
= XWINDOW (window
);
25544 struct frame
*f
= XFRAME (w
->frame
);
25545 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25546 #ifdef HAVE_WINDOW_SYSTEM
25547 Display_Info
*dpyinfo
;
25549 Cursor cursor
= No_Cursor
;
25550 Lisp_Object pointer
= Qnil
;
25551 int dx
, dy
, width
, height
;
25553 Lisp_Object string
, object
= Qnil
;
25554 Lisp_Object pos
, help
;
25556 Lisp_Object mouse_face
;
25557 int original_x_pixel
= x
;
25558 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
25559 struct glyph_row
*row
;
25561 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
25566 /* Kludge alert: mode_line_string takes X/Y in pixels, but
25567 returns them in row/column units! */
25568 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
25569 &object
, &dx
, &dy
, &width
, &height
);
25571 row
= (area
== ON_MODE_LINE
25572 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
25573 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
25575 /* Find the glyph under the mouse pointer. */
25576 if (row
->mode_line_p
&& row
->enabled_p
)
25578 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
25579 end
= glyph
+ row
->used
[TEXT_AREA
];
25581 for (x0
= original_x_pixel
;
25582 glyph
< end
&& x0
>= glyph
->pixel_width
;
25584 x0
-= glyph
->pixel_width
;
25592 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
25593 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
25594 returns them in row/column units! */
25595 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
25596 &object
, &dx
, &dy
, &width
, &height
);
25601 #ifdef HAVE_WINDOW_SYSTEM
25602 if (IMAGEP (object
))
25604 Lisp_Object image_map
, hotspot
;
25605 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
25607 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
25609 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25613 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
25614 If so, we could look for mouse-enter, mouse-leave
25615 properties in PLIST (and do something...). */
25616 hotspot
= XCDR (hotspot
);
25617 if (CONSP (hotspot
)
25618 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25620 pointer
= Fplist_get (plist
, Qpointer
);
25621 if (NILP (pointer
))
25623 help
= Fplist_get (plist
, Qhelp_echo
);
25626 help_echo_string
= help
;
25627 /* Is this correct? ++kfs */
25628 XSETWINDOW (help_echo_window
, w
);
25629 help_echo_object
= w
->buffer
;
25630 help_echo_pos
= charpos
;
25634 if (NILP (pointer
))
25635 pointer
= Fplist_get (XCDR (object
), QCpointer
);
25637 #endif /* HAVE_WINDOW_SYSTEM */
25639 if (STRINGP (string
))
25641 pos
= make_number (charpos
);
25642 /* If we're on a string with `help-echo' text property, arrange
25643 for the help to be displayed. This is done by setting the
25644 global variable help_echo_string to the help string. */
25647 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
25650 help_echo_string
= help
;
25651 XSETWINDOW (help_echo_window
, w
);
25652 help_echo_object
= string
;
25653 help_echo_pos
= charpos
;
25657 #ifdef HAVE_WINDOW_SYSTEM
25658 if (FRAME_WINDOW_P (f
))
25660 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25661 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25662 if (NILP (pointer
))
25663 pointer
= Fget_text_property (pos
, Qpointer
, string
);
25665 /* Change the mouse pointer according to what is under X/Y. */
25667 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
25670 map
= Fget_text_property (pos
, Qlocal_map
, string
);
25671 if (!KEYMAPP (map
))
25672 map
= Fget_text_property (pos
, Qkeymap
, string
);
25673 if (!KEYMAPP (map
))
25674 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
25679 /* Change the mouse face according to what is under X/Y. */
25680 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
25681 if (!NILP (mouse_face
)
25682 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25687 struct glyph
* tmp_glyph
;
25691 int total_pixel_width
;
25692 EMACS_INT begpos
, endpos
, ignore
;
25696 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
25697 Qmouse_face
, string
, Qnil
);
25703 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
25705 endpos
= SCHARS (string
);
25709 /* Calculate the glyph position GPOS of GLYPH in the
25710 displayed string, relative to the beginning of the
25711 highlighted part of the string.
25713 Note: GPOS is different from CHARPOS. CHARPOS is the
25714 position of GLYPH in the internal string object. A mode
25715 line string format has structures which are converted to
25716 a flattened string by the Emacs Lisp interpreter. The
25717 internal string is an element of those structures. The
25718 displayed string is the flattened string. */
25719 tmp_glyph
= row_start_glyph
;
25720 while (tmp_glyph
< glyph
25721 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25722 && begpos
<= tmp_glyph
->charpos
25723 && tmp_glyph
->charpos
< endpos
)))
25725 gpos
= glyph
- tmp_glyph
;
25727 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
25728 the highlighted part of the displayed string to which
25729 GLYPH belongs. Note: GSEQ_LENGTH is different from
25730 SCHARS (STRING), because the latter returns the length of
25731 the internal string. */
25732 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
25734 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25735 && begpos
<= tmp_glyph
->charpos
25736 && tmp_glyph
->charpos
< endpos
));
25739 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
25741 /* Calculate the total pixel width of all the glyphs between
25742 the beginning of the highlighted area and GLYPH. */
25743 total_pixel_width
= 0;
25744 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
25745 total_pixel_width
+= tmp_glyph
->pixel_width
;
25747 /* Pre calculation of re-rendering position. Note: X is in
25748 column units here, after the call to mode_line_string or
25749 marginal_area_string. */
25751 vpos
= (area
== ON_MODE_LINE
25752 ? (w
->current_matrix
)->nrows
- 1
25755 /* If GLYPH's position is included in the region that is
25756 already drawn in mouse face, we have nothing to do. */
25757 if ( EQ (window
, hlinfo
->mouse_face_window
)
25758 && (!row
->reversed_p
25759 ? (hlinfo
->mouse_face_beg_col
<= hpos
25760 && hpos
< hlinfo
->mouse_face_end_col
)
25761 /* In R2L rows we swap BEG and END, see below. */
25762 : (hlinfo
->mouse_face_end_col
<= hpos
25763 && hpos
< hlinfo
->mouse_face_beg_col
))
25764 && hlinfo
->mouse_face_beg_row
== vpos
)
25767 if (clear_mouse_face (hlinfo
))
25768 cursor
= No_Cursor
;
25770 if (!row
->reversed_p
)
25772 hlinfo
->mouse_face_beg_col
= hpos
;
25773 hlinfo
->mouse_face_beg_x
= original_x_pixel
25774 - (total_pixel_width
+ dx
);
25775 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
25776 hlinfo
->mouse_face_end_x
= 0;
25780 /* In R2L rows, show_mouse_face expects BEG and END
25781 coordinates to be swapped. */
25782 hlinfo
->mouse_face_end_col
= hpos
;
25783 hlinfo
->mouse_face_end_x
= original_x_pixel
25784 - (total_pixel_width
+ dx
);
25785 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
25786 hlinfo
->mouse_face_beg_x
= 0;
25789 hlinfo
->mouse_face_beg_row
= vpos
;
25790 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
25791 hlinfo
->mouse_face_beg_y
= 0;
25792 hlinfo
->mouse_face_end_y
= 0;
25793 hlinfo
->mouse_face_past_end
= 0;
25794 hlinfo
->mouse_face_window
= window
;
25796 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
25802 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25804 if (NILP (pointer
))
25807 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25808 clear_mouse_face (hlinfo
);
25810 #ifdef HAVE_WINDOW_SYSTEM
25811 if (FRAME_WINDOW_P (f
))
25812 define_frame_cursor1 (f
, cursor
, pointer
);
25818 Take proper action when the mouse has moved to position X, Y on
25819 frame F as regards highlighting characters that have mouse-face
25820 properties. Also de-highlighting chars where the mouse was before.
25821 X and Y can be negative or out of range. */
25824 note_mouse_highlight (struct frame
*f
, int x
, int y
)
25826 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25827 enum window_part part
;
25828 Lisp_Object window
;
25830 Cursor cursor
= No_Cursor
;
25831 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
25834 /* When a menu is active, don't highlight because this looks odd. */
25835 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
25836 if (popup_activated ())
25840 if (NILP (Vmouse_highlight
)
25841 || !f
->glyphs_initialized_p
25842 || f
->pointer_invisible
)
25845 hlinfo
->mouse_face_mouse_x
= x
;
25846 hlinfo
->mouse_face_mouse_y
= y
;
25847 hlinfo
->mouse_face_mouse_frame
= f
;
25849 if (hlinfo
->mouse_face_defer
)
25852 if (gc_in_progress
)
25854 hlinfo
->mouse_face_deferred_gc
= 1;
25858 /* Which window is that in? */
25859 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
25861 /* If we were displaying active text in another window, clear that.
25862 Also clear if we move out of text area in same window. */
25863 if (! EQ (window
, hlinfo
->mouse_face_window
)
25864 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
25865 && !NILP (hlinfo
->mouse_face_window
)))
25866 clear_mouse_face (hlinfo
);
25868 /* Not on a window -> return. */
25869 if (!WINDOWP (window
))
25872 /* Reset help_echo_string. It will get recomputed below. */
25873 help_echo_string
= Qnil
;
25875 /* Convert to window-relative pixel coordinates. */
25876 w
= XWINDOW (window
);
25877 frame_to_window_pixel_xy (w
, &x
, &y
);
25879 #ifdef HAVE_WINDOW_SYSTEM
25880 /* Handle tool-bar window differently since it doesn't display a
25882 if (EQ (window
, f
->tool_bar_window
))
25884 note_tool_bar_highlight (f
, x
, y
);
25889 /* Mouse is on the mode, header line or margin? */
25890 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
25891 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
25893 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
25897 #ifdef HAVE_WINDOW_SYSTEM
25898 if (part
== ON_VERTICAL_BORDER
)
25900 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25901 help_echo_string
= build_string ("drag-mouse-1: resize");
25903 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
25904 || part
== ON_SCROLL_BAR
)
25905 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25907 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25910 /* Are we in a window whose display is up to date?
25911 And verify the buffer's text has not changed. */
25912 b
= XBUFFER (w
->buffer
);
25913 if (part
== ON_TEXT
25914 && EQ (w
->window_end_valid
, w
->buffer
)
25915 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
25916 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
25918 int hpos
, vpos
, i
, dx
, dy
, area
;
25920 struct glyph
*glyph
;
25921 Lisp_Object object
;
25922 Lisp_Object mouse_face
= Qnil
, position
;
25923 Lisp_Object
*overlay_vec
= NULL
;
25925 struct buffer
*obuf
;
25926 EMACS_INT obegv
, ozv
;
25929 /* Find the glyph under X/Y. */
25930 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
25932 #ifdef HAVE_WINDOW_SYSTEM
25933 /* Look for :pointer property on image. */
25934 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25936 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25937 if (img
!= NULL
&& IMAGEP (img
->spec
))
25939 Lisp_Object image_map
, hotspot
;
25940 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
25942 && (hotspot
= find_hot_spot (image_map
,
25943 glyph
->slice
.img
.x
+ dx
,
25944 glyph
->slice
.img
.y
+ dy
),
25946 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25950 /* Could check XCAR (hotspot) to see if we enter/leave
25952 If so, we could look for mouse-enter, mouse-leave
25953 properties in PLIST (and do something...). */
25954 hotspot
= XCDR (hotspot
);
25955 if (CONSP (hotspot
)
25956 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25958 pointer
= Fplist_get (plist
, Qpointer
);
25959 if (NILP (pointer
))
25961 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
25962 if (!NILP (help_echo_string
))
25964 help_echo_window
= window
;
25965 help_echo_object
= glyph
->object
;
25966 help_echo_pos
= glyph
->charpos
;
25970 if (NILP (pointer
))
25971 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
25974 #endif /* HAVE_WINDOW_SYSTEM */
25976 /* Clear mouse face if X/Y not over text. */
25978 || area
!= TEXT_AREA
25979 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
25980 /* Glyph's OBJECT is an integer for glyphs inserted by the
25981 display engine for its internal purposes, like truncation
25982 and continuation glyphs and blanks beyond the end of
25983 line's text on text terminals. If we are over such a
25984 glyph, we are not over any text. */
25985 || INTEGERP (glyph
->object
)
25986 /* R2L rows have a stretch glyph at their front, which
25987 stands for no text, whereas L2R rows have no glyphs at
25988 all beyond the end of text. Treat such stretch glyphs
25989 like we do with NULL glyphs in L2R rows. */
25990 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
25991 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
25992 && glyph
->type
== STRETCH_GLYPH
25993 && glyph
->avoid_cursor_p
))
25995 if (clear_mouse_face (hlinfo
))
25996 cursor
= No_Cursor
;
25997 #ifdef HAVE_WINDOW_SYSTEM
25998 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
26000 if (area
!= TEXT_AREA
)
26001 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26003 pointer
= Vvoid_text_area_pointer
;
26009 pos
= glyph
->charpos
;
26010 object
= glyph
->object
;
26011 if (!STRINGP (object
) && !BUFFERP (object
))
26014 /* If we get an out-of-range value, return now; avoid an error. */
26015 if (BUFFERP (object
) && pos
> BUF_Z (b
))
26018 /* Make the window's buffer temporarily current for
26019 overlays_at and compute_char_face. */
26020 obuf
= current_buffer
;
26021 current_buffer
= b
;
26027 /* Is this char mouse-active or does it have help-echo? */
26028 position
= make_number (pos
);
26030 if (BUFFERP (object
))
26032 /* Put all the overlays we want in a vector in overlay_vec. */
26033 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
26034 /* Sort overlays into increasing priority order. */
26035 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
26040 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
26043 cursor
= No_Cursor
;
26045 /* Check mouse-face highlighting. */
26047 /* If there exists an overlay with mouse-face overlapping
26048 the one we are currently highlighting, we have to
26049 check if we enter the overlapping overlay, and then
26050 highlight only that. */
26051 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
26052 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
26054 /* Find the highest priority overlay with a mouse-face. */
26055 Lisp_Object overlay
= Qnil
;
26056 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
26058 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
26059 if (!NILP (mouse_face
))
26060 overlay
= overlay_vec
[i
];
26063 /* If we're highlighting the same overlay as before, there's
26064 no need to do that again. */
26065 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
26066 goto check_help_echo
;
26067 hlinfo
->mouse_face_overlay
= overlay
;
26069 /* Clear the display of the old active region, if any. */
26070 if (clear_mouse_face (hlinfo
))
26071 cursor
= No_Cursor
;
26073 /* If no overlay applies, get a text property. */
26074 if (NILP (overlay
))
26075 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
26077 /* Next, compute the bounds of the mouse highlighting and
26079 if (!NILP (mouse_face
) && STRINGP (object
))
26081 /* The mouse-highlighting comes from a display string
26082 with a mouse-face. */
26086 s
= Fprevious_single_property_change
26087 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
26088 e
= Fnext_single_property_change
26089 (position
, Qmouse_face
, object
, Qnil
);
26091 s
= make_number (0);
26093 e
= make_number (SCHARS (object
) - 1);
26094 mouse_face_from_string_pos (w
, hlinfo
, object
,
26095 XINT (s
), XINT (e
));
26096 hlinfo
->mouse_face_past_end
= 0;
26097 hlinfo
->mouse_face_window
= window
;
26098 hlinfo
->mouse_face_face_id
26099 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
26100 glyph
->face_id
, 1);
26101 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26102 cursor
= No_Cursor
;
26106 /* The mouse-highlighting, if any, comes from an overlay
26107 or text property in the buffer. */
26108 Lisp_Object buffer
IF_LINT (= Qnil
);
26109 Lisp_Object cover_string
IF_LINT (= Qnil
);
26111 if (STRINGP (object
))
26113 /* If we are on a display string with no mouse-face,
26114 check if the text under it has one. */
26115 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
26116 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26117 pos
= string_buffer_position (object
, start
);
26120 mouse_face
= get_char_property_and_overlay
26121 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
26122 buffer
= w
->buffer
;
26123 cover_string
= object
;
26129 cover_string
= Qnil
;
26132 if (!NILP (mouse_face
))
26134 Lisp_Object before
, after
;
26135 Lisp_Object before_string
, after_string
;
26136 /* To correctly find the limits of mouse highlight
26137 in a bidi-reordered buffer, we must not use the
26138 optimization of limiting the search in
26139 previous-single-property-change and
26140 next-single-property-change, because
26141 rows_from_pos_range needs the real start and end
26142 positions to DTRT in this case. That's because
26143 the first row visible in a window does not
26144 necessarily display the character whose position
26145 is the smallest. */
26147 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
26148 ? Fmarker_position (w
->start
)
26151 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
26152 ? make_number (BUF_Z (XBUFFER (buffer
))
26153 - XFASTINT (w
->window_end_pos
))
26156 if (NILP (overlay
))
26158 /* Handle the text property case. */
26159 before
= Fprevious_single_property_change
26160 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
26161 after
= Fnext_single_property_change
26162 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
26163 before_string
= after_string
= Qnil
;
26167 /* Handle the overlay case. */
26168 before
= Foverlay_start (overlay
);
26169 after
= Foverlay_end (overlay
);
26170 before_string
= Foverlay_get (overlay
, Qbefore_string
);
26171 after_string
= Foverlay_get (overlay
, Qafter_string
);
26173 if (!STRINGP (before_string
)) before_string
= Qnil
;
26174 if (!STRINGP (after_string
)) after_string
= Qnil
;
26177 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
26180 before_string
, after_string
,
26182 cursor
= No_Cursor
;
26189 /* Look for a `help-echo' property. */
26190 if (NILP (help_echo_string
)) {
26191 Lisp_Object help
, overlay
;
26193 /* Check overlays first. */
26194 help
= overlay
= Qnil
;
26195 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
26197 overlay
= overlay_vec
[i
];
26198 help
= Foverlay_get (overlay
, Qhelp_echo
);
26203 help_echo_string
= help
;
26204 help_echo_window
= window
;
26205 help_echo_object
= overlay
;
26206 help_echo_pos
= pos
;
26210 Lisp_Object obj
= glyph
->object
;
26211 EMACS_INT charpos
= glyph
->charpos
;
26213 /* Try text properties. */
26216 && charpos
< SCHARS (obj
))
26218 help
= Fget_text_property (make_number (charpos
),
26222 /* If the string itself doesn't specify a help-echo,
26223 see if the buffer text ``under'' it does. */
26224 struct glyph_row
*r
26225 = MATRIX_ROW (w
->current_matrix
, vpos
);
26226 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26227 EMACS_INT p
= string_buffer_position (obj
, start
);
26230 help
= Fget_char_property (make_number (p
),
26231 Qhelp_echo
, w
->buffer
);
26240 else if (BUFFERP (obj
)
26243 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
26248 help_echo_string
= help
;
26249 help_echo_window
= window
;
26250 help_echo_object
= obj
;
26251 help_echo_pos
= charpos
;
26256 #ifdef HAVE_WINDOW_SYSTEM
26257 /* Look for a `pointer' property. */
26258 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
26260 /* Check overlays first. */
26261 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
26262 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
26264 if (NILP (pointer
))
26266 Lisp_Object obj
= glyph
->object
;
26267 EMACS_INT charpos
= glyph
->charpos
;
26269 /* Try text properties. */
26272 && charpos
< SCHARS (obj
))
26274 pointer
= Fget_text_property (make_number (charpos
),
26276 if (NILP (pointer
))
26278 /* If the string itself doesn't specify a pointer,
26279 see if the buffer text ``under'' it does. */
26280 struct glyph_row
*r
26281 = MATRIX_ROW (w
->current_matrix
, vpos
);
26282 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26283 EMACS_INT p
= string_buffer_position (obj
, start
);
26285 pointer
= Fget_char_property (make_number (p
),
26286 Qpointer
, w
->buffer
);
26289 else if (BUFFERP (obj
)
26292 pointer
= Fget_text_property (make_number (charpos
),
26296 #endif /* HAVE_WINDOW_SYSTEM */
26300 current_buffer
= obuf
;
26305 #ifdef HAVE_WINDOW_SYSTEM
26306 if (FRAME_WINDOW_P (f
))
26307 define_frame_cursor1 (f
, cursor
, pointer
);
26309 /* This is here to prevent a compiler error, about "label at end of
26310 compound statement". */
26317 Clear any mouse-face on window W. This function is part of the
26318 redisplay interface, and is called from try_window_id and similar
26319 functions to ensure the mouse-highlight is off. */
26322 x_clear_window_mouse_face (struct window
*w
)
26324 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26325 Lisp_Object window
;
26328 XSETWINDOW (window
, w
);
26329 if (EQ (window
, hlinfo
->mouse_face_window
))
26330 clear_mouse_face (hlinfo
);
26336 Just discard the mouse face information for frame F, if any.
26337 This is used when the size of F is changed. */
26340 cancel_mouse_face (struct frame
*f
)
26342 Lisp_Object window
;
26343 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26345 window
= hlinfo
->mouse_face_window
;
26346 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
26348 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26349 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26350 hlinfo
->mouse_face_window
= Qnil
;
26356 /***********************************************************************
26358 ***********************************************************************/
26360 #ifdef HAVE_WINDOW_SYSTEM
26362 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
26363 which intersects rectangle R. R is in window-relative coordinates. */
26366 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
26367 enum glyph_row_area area
)
26369 struct glyph
*first
= row
->glyphs
[area
];
26370 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
26371 struct glyph
*last
;
26372 int first_x
, start_x
, x
;
26374 if (area
== TEXT_AREA
&& row
->fill_line_p
)
26375 /* If row extends face to end of line write the whole line. */
26376 draw_glyphs (w
, 0, row
, area
,
26377 0, row
->used
[area
],
26378 DRAW_NORMAL_TEXT
, 0);
26381 /* Set START_X to the window-relative start position for drawing glyphs of
26382 AREA. The first glyph of the text area can be partially visible.
26383 The first glyphs of other areas cannot. */
26384 start_x
= window_box_left_offset (w
, area
);
26386 if (area
== TEXT_AREA
)
26389 /* Find the first glyph that must be redrawn. */
26391 && x
+ first
->pixel_width
< r
->x
)
26393 x
+= first
->pixel_width
;
26397 /* Find the last one. */
26401 && x
< r
->x
+ r
->width
)
26403 x
+= last
->pixel_width
;
26409 draw_glyphs (w
, first_x
- start_x
, row
, area
,
26410 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
26411 DRAW_NORMAL_TEXT
, 0);
26416 /* Redraw the parts of the glyph row ROW on window W intersecting
26417 rectangle R. R is in window-relative coordinates. Value is
26418 non-zero if mouse-face was overwritten. */
26421 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
26423 xassert (row
->enabled_p
);
26425 if (row
->mode_line_p
|| w
->pseudo_window_p
)
26426 draw_glyphs (w
, 0, row
, TEXT_AREA
,
26427 0, row
->used
[TEXT_AREA
],
26428 DRAW_NORMAL_TEXT
, 0);
26431 if (row
->used
[LEFT_MARGIN_AREA
])
26432 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
26433 if (row
->used
[TEXT_AREA
])
26434 expose_area (w
, row
, r
, TEXT_AREA
);
26435 if (row
->used
[RIGHT_MARGIN_AREA
])
26436 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
26437 draw_row_fringe_bitmaps (w
, row
);
26440 return row
->mouse_face_p
;
26444 /* Redraw those parts of glyphs rows during expose event handling that
26445 overlap other rows. Redrawing of an exposed line writes over parts
26446 of lines overlapping that exposed line; this function fixes that.
26448 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
26449 row in W's current matrix that is exposed and overlaps other rows.
26450 LAST_OVERLAPPING_ROW is the last such row. */
26453 expose_overlaps (struct window
*w
,
26454 struct glyph_row
*first_overlapping_row
,
26455 struct glyph_row
*last_overlapping_row
,
26458 struct glyph_row
*row
;
26460 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
26461 if (row
->overlapping_p
)
26463 xassert (row
->enabled_p
&& !row
->mode_line_p
);
26466 if (row
->used
[LEFT_MARGIN_AREA
])
26467 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
26469 if (row
->used
[TEXT_AREA
])
26470 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
26472 if (row
->used
[RIGHT_MARGIN_AREA
])
26473 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
26479 /* Return non-zero if W's cursor intersects rectangle R. */
26482 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
26484 XRectangle cr
, result
;
26485 struct glyph
*cursor_glyph
;
26486 struct glyph_row
*row
;
26488 if (w
->phys_cursor
.vpos
>= 0
26489 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
26490 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
26492 && row
->cursor_in_fringe_p
)
26494 /* Cursor is in the fringe. */
26495 cr
.x
= window_box_right_offset (w
,
26496 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
26497 ? RIGHT_MARGIN_AREA
26500 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
26501 cr
.height
= row
->height
;
26502 return x_intersect_rectangles (&cr
, r
, &result
);
26505 cursor_glyph
= get_phys_cursor_glyph (w
);
26508 /* r is relative to W's box, but w->phys_cursor.x is relative
26509 to left edge of W's TEXT area. Adjust it. */
26510 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
26511 cr
.y
= w
->phys_cursor
.y
;
26512 cr
.width
= cursor_glyph
->pixel_width
;
26513 cr
.height
= w
->phys_cursor_height
;
26514 /* ++KFS: W32 version used W32-specific IntersectRect here, but
26515 I assume the effect is the same -- and this is portable. */
26516 return x_intersect_rectangles (&cr
, r
, &result
);
26518 /* If we don't understand the format, pretend we're not in the hot-spot. */
26524 Draw a vertical window border to the right of window W if W doesn't
26525 have vertical scroll bars. */
26528 x_draw_vertical_border (struct window
*w
)
26530 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26532 /* We could do better, if we knew what type of scroll-bar the adjacent
26533 windows (on either side) have... But we don't :-(
26534 However, I think this works ok. ++KFS 2003-04-25 */
26536 /* Redraw borders between horizontally adjacent windows. Don't
26537 do it for frames with vertical scroll bars because either the
26538 right scroll bar of a window, or the left scroll bar of its
26539 neighbor will suffice as a border. */
26540 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
26543 if (!WINDOW_RIGHTMOST_P (w
)
26544 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
26546 int x0
, x1
, y0
, y1
;
26548 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26551 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26554 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
26556 else if (!WINDOW_LEFTMOST_P (w
)
26557 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
26559 int x0
, x1
, y0
, y1
;
26561 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26564 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26567 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
26572 /* Redraw the part of window W intersection rectangle FR. Pixel
26573 coordinates in FR are frame-relative. Call this function with
26574 input blocked. Value is non-zero if the exposure overwrites
26578 expose_window (struct window
*w
, XRectangle
*fr
)
26580 struct frame
*f
= XFRAME (w
->frame
);
26582 int mouse_face_overwritten_p
= 0;
26584 /* If window is not yet fully initialized, do nothing. This can
26585 happen when toolkit scroll bars are used and a window is split.
26586 Reconfiguring the scroll bar will generate an expose for a newly
26588 if (w
->current_matrix
== NULL
)
26591 /* When we're currently updating the window, display and current
26592 matrix usually don't agree. Arrange for a thorough display
26594 if (w
== updated_window
)
26596 SET_FRAME_GARBAGED (f
);
26600 /* Frame-relative pixel rectangle of W. */
26601 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
26602 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
26603 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
26604 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
26606 if (x_intersect_rectangles (fr
, &wr
, &r
))
26608 int yb
= window_text_bottom_y (w
);
26609 struct glyph_row
*row
;
26610 int cursor_cleared_p
;
26611 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
26613 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
26614 r
.x
, r
.y
, r
.width
, r
.height
));
26616 /* Convert to window coordinates. */
26617 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
26618 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
26620 /* Turn off the cursor. */
26621 if (!w
->pseudo_window_p
26622 && phys_cursor_in_rect_p (w
, &r
))
26624 x_clear_cursor (w
);
26625 cursor_cleared_p
= 1;
26628 cursor_cleared_p
= 0;
26630 /* Update lines intersecting rectangle R. */
26631 first_overlapping_row
= last_overlapping_row
= NULL
;
26632 for (row
= w
->current_matrix
->rows
;
26637 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
26639 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
26640 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
26641 || (r
.y
>= y0
&& r
.y
< y1
)
26642 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
26644 /* A header line may be overlapping, but there is no need
26645 to fix overlapping areas for them. KFS 2005-02-12 */
26646 if (row
->overlapping_p
&& !row
->mode_line_p
)
26648 if (first_overlapping_row
== NULL
)
26649 first_overlapping_row
= row
;
26650 last_overlapping_row
= row
;
26654 if (expose_line (w
, row
, &r
))
26655 mouse_face_overwritten_p
= 1;
26658 else if (row
->overlapping_p
)
26660 /* We must redraw a row overlapping the exposed area. */
26662 ? y0
+ row
->phys_height
> r
.y
26663 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
26665 if (first_overlapping_row
== NULL
)
26666 first_overlapping_row
= row
;
26667 last_overlapping_row
= row
;
26675 /* Display the mode line if there is one. */
26676 if (WINDOW_WANTS_MODELINE_P (w
)
26677 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
26679 && row
->y
< r
.y
+ r
.height
)
26681 if (expose_line (w
, row
, &r
))
26682 mouse_face_overwritten_p
= 1;
26685 if (!w
->pseudo_window_p
)
26687 /* Fix the display of overlapping rows. */
26688 if (first_overlapping_row
)
26689 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
26692 /* Draw border between windows. */
26693 x_draw_vertical_border (w
);
26695 /* Turn the cursor on again. */
26696 if (cursor_cleared_p
)
26697 update_window_cursor (w
, 1);
26701 return mouse_face_overwritten_p
;
26706 /* Redraw (parts) of all windows in the window tree rooted at W that
26707 intersect R. R contains frame pixel coordinates. Value is
26708 non-zero if the exposure overwrites mouse-face. */
26711 expose_window_tree (struct window
*w
, XRectangle
*r
)
26713 struct frame
*f
= XFRAME (w
->frame
);
26714 int mouse_face_overwritten_p
= 0;
26716 while (w
&& !FRAME_GARBAGED_P (f
))
26718 if (!NILP (w
->hchild
))
26719 mouse_face_overwritten_p
26720 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
26721 else if (!NILP (w
->vchild
))
26722 mouse_face_overwritten_p
26723 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
26725 mouse_face_overwritten_p
|= expose_window (w
, r
);
26727 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
26730 return mouse_face_overwritten_p
;
26735 Redisplay an exposed area of frame F. X and Y are the upper-left
26736 corner of the exposed rectangle. W and H are width and height of
26737 the exposed area. All are pixel values. W or H zero means redraw
26738 the entire frame. */
26741 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
26744 int mouse_face_overwritten_p
= 0;
26746 TRACE ((stderr
, "expose_frame "));
26748 /* No need to redraw if frame will be redrawn soon. */
26749 if (FRAME_GARBAGED_P (f
))
26751 TRACE ((stderr
, " garbaged\n"));
26755 /* If basic faces haven't been realized yet, there is no point in
26756 trying to redraw anything. This can happen when we get an expose
26757 event while Emacs is starting, e.g. by moving another window. */
26758 if (FRAME_FACE_CACHE (f
) == NULL
26759 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
26761 TRACE ((stderr
, " no faces\n"));
26765 if (w
== 0 || h
== 0)
26768 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
26769 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
26779 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
26780 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
26782 if (WINDOWP (f
->tool_bar_window
))
26783 mouse_face_overwritten_p
26784 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
26786 #ifdef HAVE_X_WINDOWS
26788 #ifndef USE_X_TOOLKIT
26789 if (WINDOWP (f
->menu_bar_window
))
26790 mouse_face_overwritten_p
26791 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
26792 #endif /* not USE_X_TOOLKIT */
26796 /* Some window managers support a focus-follows-mouse style with
26797 delayed raising of frames. Imagine a partially obscured frame,
26798 and moving the mouse into partially obscured mouse-face on that
26799 frame. The visible part of the mouse-face will be highlighted,
26800 then the WM raises the obscured frame. With at least one WM, KDE
26801 2.1, Emacs is not getting any event for the raising of the frame
26802 (even tried with SubstructureRedirectMask), only Expose events.
26803 These expose events will draw text normally, i.e. not
26804 highlighted. Which means we must redo the highlight here.
26805 Subsume it under ``we love X''. --gerd 2001-08-15 */
26806 /* Included in Windows version because Windows most likely does not
26807 do the right thing if any third party tool offers
26808 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
26809 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
26811 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26812 if (f
== hlinfo
->mouse_face_mouse_frame
)
26814 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
26815 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
26816 clear_mouse_face (hlinfo
);
26817 note_mouse_highlight (f
, mouse_x
, mouse_y
);
26824 Determine the intersection of two rectangles R1 and R2. Return
26825 the intersection in *RESULT. Value is non-zero if RESULT is not
26829 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
26831 XRectangle
*left
, *right
;
26832 XRectangle
*upper
, *lower
;
26833 int intersection_p
= 0;
26835 /* Rearrange so that R1 is the left-most rectangle. */
26837 left
= r1
, right
= r2
;
26839 left
= r2
, right
= r1
;
26841 /* X0 of the intersection is right.x0, if this is inside R1,
26842 otherwise there is no intersection. */
26843 if (right
->x
<= left
->x
+ left
->width
)
26845 result
->x
= right
->x
;
26847 /* The right end of the intersection is the minimum of the
26848 the right ends of left and right. */
26849 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
26852 /* Same game for Y. */
26854 upper
= r1
, lower
= r2
;
26856 upper
= r2
, lower
= r1
;
26858 /* The upper end of the intersection is lower.y0, if this is inside
26859 of upper. Otherwise, there is no intersection. */
26860 if (lower
->y
<= upper
->y
+ upper
->height
)
26862 result
->y
= lower
->y
;
26864 /* The lower end of the intersection is the minimum of the lower
26865 ends of upper and lower. */
26866 result
->height
= (min (lower
->y
+ lower
->height
,
26867 upper
->y
+ upper
->height
)
26869 intersection_p
= 1;
26873 return intersection_p
;
26876 #endif /* HAVE_WINDOW_SYSTEM */
26879 /***********************************************************************
26881 ***********************************************************************/
26884 syms_of_xdisp (void)
26886 Vwith_echo_area_save_vector
= Qnil
;
26887 staticpro (&Vwith_echo_area_save_vector
);
26889 Vmessage_stack
= Qnil
;
26890 staticpro (&Vmessage_stack
);
26892 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
26893 staticpro (&Qinhibit_redisplay
);
26895 message_dolog_marker1
= Fmake_marker ();
26896 staticpro (&message_dolog_marker1
);
26897 message_dolog_marker2
= Fmake_marker ();
26898 staticpro (&message_dolog_marker2
);
26899 message_dolog_marker3
= Fmake_marker ();
26900 staticpro (&message_dolog_marker3
);
26903 defsubr (&Sdump_frame_glyph_matrix
);
26904 defsubr (&Sdump_glyph_matrix
);
26905 defsubr (&Sdump_glyph_row
);
26906 defsubr (&Sdump_tool_bar_row
);
26907 defsubr (&Strace_redisplay
);
26908 defsubr (&Strace_to_stderr
);
26910 #ifdef HAVE_WINDOW_SYSTEM
26911 defsubr (&Stool_bar_lines_needed
);
26912 defsubr (&Slookup_image_map
);
26914 defsubr (&Sformat_mode_line
);
26915 defsubr (&Sinvisible_p
);
26916 defsubr (&Scurrent_bidi_paragraph_direction
);
26918 staticpro (&Qmenu_bar_update_hook
);
26919 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
26921 staticpro (&Qoverriding_terminal_local_map
);
26922 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
26924 staticpro (&Qoverriding_local_map
);
26925 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
26927 staticpro (&Qwindow_scroll_functions
);
26928 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
26930 staticpro (&Qwindow_text_change_functions
);
26931 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
26933 staticpro (&Qredisplay_end_trigger_functions
);
26934 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
26936 staticpro (&Qinhibit_point_motion_hooks
);
26937 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
26939 Qeval
= intern_c_string ("eval");
26940 staticpro (&Qeval
);
26942 QCdata
= intern_c_string (":data");
26943 staticpro (&QCdata
);
26944 Qdisplay
= intern_c_string ("display");
26945 staticpro (&Qdisplay
);
26946 Qspace_width
= intern_c_string ("space-width");
26947 staticpro (&Qspace_width
);
26948 Qraise
= intern_c_string ("raise");
26949 staticpro (&Qraise
);
26950 Qslice
= intern_c_string ("slice");
26951 staticpro (&Qslice
);
26952 Qspace
= intern_c_string ("space");
26953 staticpro (&Qspace
);
26954 Qmargin
= intern_c_string ("margin");
26955 staticpro (&Qmargin
);
26956 Qpointer
= intern_c_string ("pointer");
26957 staticpro (&Qpointer
);
26958 Qleft_margin
= intern_c_string ("left-margin");
26959 staticpro (&Qleft_margin
);
26960 Qright_margin
= intern_c_string ("right-margin");
26961 staticpro (&Qright_margin
);
26962 Qcenter
= intern_c_string ("center");
26963 staticpro (&Qcenter
);
26964 Qline_height
= intern_c_string ("line-height");
26965 staticpro (&Qline_height
);
26966 QCalign_to
= intern_c_string (":align-to");
26967 staticpro (&QCalign_to
);
26968 QCrelative_width
= intern_c_string (":relative-width");
26969 staticpro (&QCrelative_width
);
26970 QCrelative_height
= intern_c_string (":relative-height");
26971 staticpro (&QCrelative_height
);
26972 QCeval
= intern_c_string (":eval");
26973 staticpro (&QCeval
);
26974 QCpropertize
= intern_c_string (":propertize");
26975 staticpro (&QCpropertize
);
26976 QCfile
= intern_c_string (":file");
26977 staticpro (&QCfile
);
26978 Qfontified
= intern_c_string ("fontified");
26979 staticpro (&Qfontified
);
26980 Qfontification_functions
= intern_c_string ("fontification-functions");
26981 staticpro (&Qfontification_functions
);
26982 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
26983 staticpro (&Qtrailing_whitespace
);
26984 Qescape_glyph
= intern_c_string ("escape-glyph");
26985 staticpro (&Qescape_glyph
);
26986 Qnobreak_space
= intern_c_string ("nobreak-space");
26987 staticpro (&Qnobreak_space
);
26988 Qimage
= intern_c_string ("image");
26989 staticpro (&Qimage
);
26990 Qtext
= intern_c_string ("text");
26991 staticpro (&Qtext
);
26992 Qboth
= intern_c_string ("both");
26993 staticpro (&Qboth
);
26994 Qboth_horiz
= intern_c_string ("both-horiz");
26995 staticpro (&Qboth_horiz
);
26996 Qtext_image_horiz
= intern_c_string ("text-image-horiz");
26997 staticpro (&Qtext_image_horiz
);
26998 QCmap
= intern_c_string (":map");
26999 staticpro (&QCmap
);
27000 QCpointer
= intern_c_string (":pointer");
27001 staticpro (&QCpointer
);
27002 Qrect
= intern_c_string ("rect");
27003 staticpro (&Qrect
);
27004 Qcircle
= intern_c_string ("circle");
27005 staticpro (&Qcircle
);
27006 Qpoly
= intern_c_string ("poly");
27007 staticpro (&Qpoly
);
27008 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
27009 staticpro (&Qmessage_truncate_lines
);
27010 Qgrow_only
= intern_c_string ("grow-only");
27011 staticpro (&Qgrow_only
);
27012 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
27013 staticpro (&Qinhibit_menubar_update
);
27014 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
27015 staticpro (&Qinhibit_eval_during_redisplay
);
27016 Qposition
= intern_c_string ("position");
27017 staticpro (&Qposition
);
27018 Qbuffer_position
= intern_c_string ("buffer-position");
27019 staticpro (&Qbuffer_position
);
27020 Qobject
= intern_c_string ("object");
27021 staticpro (&Qobject
);
27022 Qbar
= intern_c_string ("bar");
27024 Qhbar
= intern_c_string ("hbar");
27025 staticpro (&Qhbar
);
27026 Qbox
= intern_c_string ("box");
27028 Qhollow
= intern_c_string ("hollow");
27029 staticpro (&Qhollow
);
27030 Qhand
= intern_c_string ("hand");
27031 staticpro (&Qhand
);
27032 Qarrow
= intern_c_string ("arrow");
27033 staticpro (&Qarrow
);
27034 Qtext
= intern_c_string ("text");
27035 staticpro (&Qtext
);
27036 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
27037 staticpro (&Qinhibit_free_realized_faces
);
27039 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
27040 Fcons (intern_c_string ("void-variable"), Qnil
)),
27042 staticpro (&list_of_error
);
27044 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
27045 staticpro (&Qlast_arrow_position
);
27046 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
27047 staticpro (&Qlast_arrow_string
);
27049 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
27050 staticpro (&Qoverlay_arrow_string
);
27051 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
27052 staticpro (&Qoverlay_arrow_bitmap
);
27054 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
27055 staticpro (&echo_buffer
[0]);
27056 staticpro (&echo_buffer
[1]);
27058 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
27059 staticpro (&echo_area_buffer
[0]);
27060 staticpro (&echo_area_buffer
[1]);
27062 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
27063 staticpro (&Vmessages_buffer_name
);
27065 mode_line_proptrans_alist
= Qnil
;
27066 staticpro (&mode_line_proptrans_alist
);
27067 mode_line_string_list
= Qnil
;
27068 staticpro (&mode_line_string_list
);
27069 mode_line_string_face
= Qnil
;
27070 staticpro (&mode_line_string_face
);
27071 mode_line_string_face_prop
= Qnil
;
27072 staticpro (&mode_line_string_face_prop
);
27073 Vmode_line_unwind_vector
= Qnil
;
27074 staticpro (&Vmode_line_unwind_vector
);
27076 help_echo_string
= Qnil
;
27077 staticpro (&help_echo_string
);
27078 help_echo_object
= Qnil
;
27079 staticpro (&help_echo_object
);
27080 help_echo_window
= Qnil
;
27081 staticpro (&help_echo_window
);
27082 previous_help_echo_string
= Qnil
;
27083 staticpro (&previous_help_echo_string
);
27084 help_echo_pos
= -1;
27086 Qright_to_left
= intern_c_string ("right-to-left");
27087 staticpro (&Qright_to_left
);
27088 Qleft_to_right
= intern_c_string ("left-to-right");
27089 staticpro (&Qleft_to_right
);
27091 #ifdef HAVE_WINDOW_SYSTEM
27092 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
27093 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
27094 For example, if a block cursor is over a tab, it will be drawn as
27095 wide as that tab on the display. */);
27096 x_stretch_cursor_p
= 0;
27099 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
27100 doc
: /* *Non-nil means highlight trailing whitespace.
27101 The face used for trailing whitespace is `trailing-whitespace'. */);
27102 Vshow_trailing_whitespace
= Qnil
;
27104 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
27105 doc
: /* *Control highlighting of nobreak space and soft hyphen.
27106 A value of t means highlight the character itself (for nobreak space,
27107 use face `nobreak-space').
27108 A value of nil means no highlighting.
27109 Other values mean display the escape glyph followed by an ordinary
27110 space or ordinary hyphen. */);
27111 Vnobreak_char_display
= Qt
;
27113 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
27114 doc
: /* *The pointer shape to show in void text areas.
27115 A value of nil means to show the text pointer. Other options are `arrow',
27116 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
27117 Vvoid_text_area_pointer
= Qarrow
;
27119 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
27120 doc
: /* Non-nil means don't actually do any redisplay.
27121 This is used for internal purposes. */);
27122 Vinhibit_redisplay
= Qnil
;
27124 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
27125 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
27126 Vglobal_mode_string
= Qnil
;
27128 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
27129 doc
: /* Marker for where to display an arrow on top of the buffer text.
27130 This must be the beginning of a line in order to work.
27131 See also `overlay-arrow-string'. */);
27132 Voverlay_arrow_position
= Qnil
;
27134 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
27135 doc
: /* String to display as an arrow in non-window frames.
27136 See also `overlay-arrow-position'. */);
27137 Voverlay_arrow_string
= make_pure_c_string ("=>");
27139 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
27140 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
27141 The symbols on this list are examined during redisplay to determine
27142 where to display overlay arrows. */);
27143 Voverlay_arrow_variable_list
27144 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
27146 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
27147 doc
: /* *The number of lines to try scrolling a window by when point moves out.
27148 If that fails to bring point back on frame, point is centered instead.
27149 If this is zero, point is always centered after it moves off frame.
27150 If you want scrolling to always be a line at a time, you should set
27151 `scroll-conservatively' to a large value rather than set this to 1. */);
27153 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
27154 doc
: /* *Scroll up to this many lines, to bring point back on screen.
27155 If point moves off-screen, redisplay will scroll by up to
27156 `scroll-conservatively' lines in order to bring point just barely
27157 onto the screen again. If that cannot be done, then redisplay
27158 recenters point as usual.
27160 If the value is greater than 100, redisplay will never recenter point,
27161 but will always scroll just enough text to bring point into view, even
27162 if you move far away.
27164 A value of zero means always recenter point if it moves off screen. */);
27165 scroll_conservatively
= 0;
27167 DEFVAR_INT ("scroll-margin", scroll_margin
,
27168 doc
: /* *Number of lines of margin at the top and bottom of a window.
27169 Recenter the window whenever point gets within this many lines
27170 of the top or bottom of the window. */);
27173 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
27174 doc
: /* Pixels per inch value for non-window system displays.
27175 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
27176 Vdisplay_pixels_per_inch
= make_float (72.0);
27179 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
27182 DEFVAR_LISP ("truncate-partial-width-windows",
27183 Vtruncate_partial_width_windows
,
27184 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
27185 For an integer value, truncate lines in each window narrower than the
27186 full frame width, provided the window width is less than that integer;
27187 otherwise, respect the value of `truncate-lines'.
27189 For any other non-nil value, truncate lines in all windows that do
27190 not span the full frame width.
27192 A value of nil means to respect the value of `truncate-lines'.
27194 If `word-wrap' is enabled, you might want to reduce this. */);
27195 Vtruncate_partial_width_windows
= make_number (50);
27197 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
27198 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
27199 Any other value means to use the appropriate face, `mode-line',
27200 `header-line', or `menu' respectively. */);
27201 mode_line_inverse_video
= 1;
27203 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
27204 doc
: /* *Maximum buffer size for which line number should be displayed.
27205 If the buffer is bigger than this, the line number does not appear
27206 in the mode line. A value of nil means no limit. */);
27207 Vline_number_display_limit
= Qnil
;
27209 DEFVAR_INT ("line-number-display-limit-width",
27210 line_number_display_limit_width
,
27211 doc
: /* *Maximum line width (in characters) for line number display.
27212 If the average length of the lines near point is bigger than this, then the
27213 line number may be omitted from the mode line. */);
27214 line_number_display_limit_width
= 200;
27216 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
27217 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
27218 highlight_nonselected_windows
= 0;
27220 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
27221 doc
: /* Non-nil if more than one frame is visible on this display.
27222 Minibuffer-only frames don't count, but iconified frames do.
27223 This variable is not guaranteed to be accurate except while processing
27224 `frame-title-format' and `icon-title-format'. */);
27226 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
27227 doc
: /* Template for displaying the title bar of visible frames.
27228 \(Assuming the window manager supports this feature.)
27230 This variable has the same structure as `mode-line-format', except that
27231 the %c and %l constructs are ignored. It is used only on frames for
27232 which no explicit name has been set \(see `modify-frame-parameters'). */);
27234 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
27235 doc
: /* Template for displaying the title bar of an iconified frame.
27236 \(Assuming the window manager supports this feature.)
27237 This variable has the same structure as `mode-line-format' (which see),
27238 and is used only on frames for which no explicit name has been set
27239 \(see `modify-frame-parameters'). */);
27241 = Vframe_title_format
27242 = pure_cons (intern_c_string ("multiple-frames"),
27243 pure_cons (make_pure_c_string ("%b"),
27244 pure_cons (pure_cons (empty_unibyte_string
,
27245 pure_cons (intern_c_string ("invocation-name"),
27246 pure_cons (make_pure_c_string ("@"),
27247 pure_cons (intern_c_string ("system-name"),
27251 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
27252 doc
: /* Maximum number of lines to keep in the message log buffer.
27253 If nil, disable message logging. If t, log messages but don't truncate
27254 the buffer when it becomes large. */);
27255 Vmessage_log_max
= make_number (100);
27257 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
27258 doc
: /* Functions called before redisplay, if window sizes have changed.
27259 The value should be a list of functions that take one argument.
27260 Just before redisplay, for each frame, if any of its windows have changed
27261 size since the last redisplay, or have been split or deleted,
27262 all the functions in the list are called, with the frame as argument. */);
27263 Vwindow_size_change_functions
= Qnil
;
27265 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
27266 doc
: /* List of functions to call before redisplaying a window with scrolling.
27267 Each function is called with two arguments, the window and its new
27268 display-start position. Note that these functions are also called by
27269 `set-window-buffer'. Also note that the value of `window-end' is not
27270 valid when these functions are called. */);
27271 Vwindow_scroll_functions
= Qnil
;
27273 DEFVAR_LISP ("window-text-change-functions",
27274 Vwindow_text_change_functions
,
27275 doc
: /* Functions to call in redisplay when text in the window might change. */);
27276 Vwindow_text_change_functions
= Qnil
;
27278 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
27279 doc
: /* Functions called when redisplay of a window reaches the end trigger.
27280 Each function is called with two arguments, the window and the end trigger value.
27281 See `set-window-redisplay-end-trigger'. */);
27282 Vredisplay_end_trigger_functions
= Qnil
;
27284 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
27285 doc
: /* *Non-nil means autoselect window with mouse pointer.
27286 If nil, do not autoselect windows.
27287 A positive number means delay autoselection by that many seconds: a
27288 window is autoselected only after the mouse has remained in that
27289 window for the duration of the delay.
27290 A negative number has a similar effect, but causes windows to be
27291 autoselected only after the mouse has stopped moving. \(Because of
27292 the way Emacs compares mouse events, you will occasionally wait twice
27293 that time before the window gets selected.\)
27294 Any other value means to autoselect window instantaneously when the
27295 mouse pointer enters it.
27297 Autoselection selects the minibuffer only if it is active, and never
27298 unselects the minibuffer if it is active.
27300 When customizing this variable make sure that the actual value of
27301 `focus-follows-mouse' matches the behavior of your window manager. */);
27302 Vmouse_autoselect_window
= Qnil
;
27304 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
27305 doc
: /* *Non-nil means automatically resize tool-bars.
27306 This dynamically changes the tool-bar's height to the minimum height
27307 that is needed to make all tool-bar items visible.
27308 If value is `grow-only', the tool-bar's height is only increased
27309 automatically; to decrease the tool-bar height, use \\[recenter]. */);
27310 Vauto_resize_tool_bars
= Qt
;
27312 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
27313 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
27314 auto_raise_tool_bar_buttons_p
= 1;
27316 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
27317 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
27318 make_cursor_line_fully_visible_p
= 1;
27320 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
27321 doc
: /* *Border below tool-bar in pixels.
27322 If an integer, use it as the height of the border.
27323 If it is one of `internal-border-width' or `border-width', use the
27324 value of the corresponding frame parameter.
27325 Otherwise, no border is added below the tool-bar. */);
27326 Vtool_bar_border
= Qinternal_border_width
;
27328 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
27329 doc
: /* *Margin around tool-bar buttons in pixels.
27330 If an integer, use that for both horizontal and vertical margins.
27331 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
27332 HORZ specifying the horizontal margin, and VERT specifying the
27333 vertical margin. */);
27334 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
27336 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
27337 doc
: /* *Relief thickness of tool-bar buttons. */);
27338 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
27340 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
27341 doc
: /* Tool bar style to use.
27343 image - show images only
27344 text - show text only
27345 both - show both, text below image
27346 both-horiz - show text to the right of the image
27347 text-image-horiz - show text to the left of the image
27348 any other - use system default or image if no system default. */);
27349 Vtool_bar_style
= Qnil
;
27351 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
27352 doc
: /* *Maximum number of characters a label can have to be shown.
27353 The tool bar style must also show labels for this to have any effect, see
27354 `tool-bar-style'. */);
27355 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
27357 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
27358 doc
: /* List of functions to call to fontify regions of text.
27359 Each function is called with one argument POS. Functions must
27360 fontify a region starting at POS in the current buffer, and give
27361 fontified regions the property `fontified'. */);
27362 Vfontification_functions
= Qnil
;
27363 Fmake_variable_buffer_local (Qfontification_functions
);
27365 DEFVAR_BOOL ("unibyte-display-via-language-environment",
27366 unibyte_display_via_language_environment
,
27367 doc
: /* *Non-nil means display unibyte text according to language environment.
27368 Specifically, this means that raw bytes in the range 160-255 decimal
27369 are displayed by converting them to the equivalent multibyte characters
27370 according to the current language environment. As a result, they are
27371 displayed according to the current fontset.
27373 Note that this variable affects only how these bytes are displayed,
27374 but does not change the fact they are interpreted as raw bytes. */);
27375 unibyte_display_via_language_environment
= 0;
27377 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
27378 doc
: /* *Maximum height for resizing mini-windows.
27379 If a float, it specifies a fraction of the mini-window frame's height.
27380 If an integer, it specifies a number of lines. */);
27381 Vmax_mini_window_height
= make_float (0.25);
27383 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
27384 doc
: /* *How to resize mini-windows.
27385 A value of nil means don't automatically resize mini-windows.
27386 A value of t means resize them to fit the text displayed in them.
27387 A value of `grow-only', the default, means let mini-windows grow
27388 only, until their display becomes empty, at which point the windows
27389 go back to their normal size. */);
27390 Vresize_mini_windows
= Qgrow_only
;
27392 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
27393 doc
: /* Alist specifying how to blink the cursor off.
27394 Each element has the form (ON-STATE . OFF-STATE). Whenever the
27395 `cursor-type' frame-parameter or variable equals ON-STATE,
27396 comparing using `equal', Emacs uses OFF-STATE to specify
27397 how to blink it off. ON-STATE and OFF-STATE are values for
27398 the `cursor-type' frame parameter.
27400 If a frame's ON-STATE has no entry in this list,
27401 the frame's other specifications determine how to blink the cursor off. */);
27402 Vblink_cursor_alist
= Qnil
;
27404 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
27405 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
27406 If non-nil, windows are automatically scrolled horizontally to make
27407 point visible. */);
27408 automatic_hscrolling_p
= 1;
27409 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
27410 staticpro (&Qauto_hscroll_mode
);
27412 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
27413 doc
: /* *How many columns away from the window edge point is allowed to get
27414 before automatic hscrolling will horizontally scroll the window. */);
27415 hscroll_margin
= 5;
27417 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
27418 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
27419 When point is less than `hscroll-margin' columns from the window
27420 edge, automatic hscrolling will scroll the window by the amount of columns
27421 determined by this variable. If its value is a positive integer, scroll that
27422 many columns. If it's a positive floating-point number, it specifies the
27423 fraction of the window's width to scroll. If it's nil or zero, point will be
27424 centered horizontally after the scroll. Any other value, including negative
27425 numbers, are treated as if the value were zero.
27427 Automatic hscrolling always moves point outside the scroll margin, so if
27428 point was more than scroll step columns inside the margin, the window will
27429 scroll more than the value given by the scroll step.
27431 Note that the lower bound for automatic hscrolling specified by `scroll-left'
27432 and `scroll-right' overrides this variable's effect. */);
27433 Vhscroll_step
= make_number (0);
27435 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
27436 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
27437 Bind this around calls to `message' to let it take effect. */);
27438 message_truncate_lines
= 0;
27440 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
27441 doc
: /* Normal hook run to update the menu bar definitions.
27442 Redisplay runs this hook before it redisplays the menu bar.
27443 This is used to update submenus such as Buffers,
27444 whose contents depend on various data. */);
27445 Vmenu_bar_update_hook
= Qnil
;
27447 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
27448 doc
: /* Frame for which we are updating a menu.
27449 The enable predicate for a menu binding should check this variable. */);
27450 Vmenu_updating_frame
= Qnil
;
27452 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
27453 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
27454 inhibit_menubar_update
= 0;
27456 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
27457 doc
: /* Prefix prepended to all continuation lines at display time.
27458 The value may be a string, an image, or a stretch-glyph; it is
27459 interpreted in the same way as the value of a `display' text property.
27461 This variable is overridden by any `wrap-prefix' text or overlay
27464 To add a prefix to non-continuation lines, use `line-prefix'. */);
27465 Vwrap_prefix
= Qnil
;
27466 staticpro (&Qwrap_prefix
);
27467 Qwrap_prefix
= intern_c_string ("wrap-prefix");
27468 Fmake_variable_buffer_local (Qwrap_prefix
);
27470 DEFVAR_LISP ("line-prefix", Vline_prefix
,
27471 doc
: /* Prefix prepended to all non-continuation lines at display time.
27472 The value may be a string, an image, or a stretch-glyph; it is
27473 interpreted in the same way as the value of a `display' text property.
27475 This variable is overridden by any `line-prefix' text or overlay
27478 To add a prefix to continuation lines, use `wrap-prefix'. */);
27479 Vline_prefix
= Qnil
;
27480 staticpro (&Qline_prefix
);
27481 Qline_prefix
= intern_c_string ("line-prefix");
27482 Fmake_variable_buffer_local (Qline_prefix
);
27484 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
27485 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
27486 inhibit_eval_during_redisplay
= 0;
27488 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
27489 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
27490 inhibit_free_realized_faces
= 0;
27493 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
27494 doc
: /* Inhibit try_window_id display optimization. */);
27495 inhibit_try_window_id
= 0;
27497 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
27498 doc
: /* Inhibit try_window_reusing display optimization. */);
27499 inhibit_try_window_reusing
= 0;
27501 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
27502 doc
: /* Inhibit try_cursor_movement display optimization. */);
27503 inhibit_try_cursor_movement
= 0;
27504 #endif /* GLYPH_DEBUG */
27506 DEFVAR_INT ("overline-margin", overline_margin
,
27507 doc
: /* *Space between overline and text, in pixels.
27508 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
27509 margin to the caracter height. */);
27510 overline_margin
= 2;
27512 DEFVAR_INT ("underline-minimum-offset",
27513 underline_minimum_offset
,
27514 doc
: /* Minimum distance between baseline and underline.
27515 This can improve legibility of underlined text at small font sizes,
27516 particularly when using variable `x-use-underline-position-properties'
27517 with fonts that specify an UNDERLINE_POSITION relatively close to the
27518 baseline. The default value is 1. */);
27519 underline_minimum_offset
= 1;
27521 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
27522 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
27523 This feature only works when on a window system that can change
27524 cursor shapes. */);
27525 display_hourglass_p
= 1;
27527 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
27528 doc
: /* *Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
27529 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
27531 hourglass_atimer
= NULL
;
27532 hourglass_shown_p
= 0;
27534 DEFSYM (Qglyphless_char
, "glyphless-char");
27535 DEFSYM (Qhex_code
, "hex-code");
27536 DEFSYM (Qempty_box
, "empty-box");
27537 DEFSYM (Qthin_space
, "thin-space");
27538 DEFSYM (Qzero_width
, "zero-width");
27540 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
27541 /* Intern this now in case it isn't already done.
27542 Setting this variable twice is harmless.
27543 But don't staticpro it here--that is done in alloc.c. */
27544 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
27545 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
27547 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
27548 doc
: /* Char-table defining glyphless characters.
27549 Each element, if non-nil, should be one of the following:
27550 an ASCII acronym string: display this string in a box
27551 `hex-code': display the hexadecimal code of a character in a box
27552 `empty-box': display as an empty box
27553 `thin-space': display as 1-pixel width space
27554 `zero-width': don't display
27555 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
27556 display method for graphical terminals and text terminals respectively.
27557 GRAPHICAL and TEXT should each have one of the values listed above.
27559 The char-table has one extra slot to control the display of a character for
27560 which no font is found. This slot only takes effect on graphical terminals.
27561 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
27562 `thin-space'. The default is `empty-box'. */);
27563 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
27564 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
27569 /* Initialize this module when Emacs starts. */
27574 Lisp_Object root_window
;
27575 struct window
*mini_w
;
27577 current_header_line_height
= current_mode_line_height
= -1;
27579 CHARPOS (this_line_start_pos
) = 0;
27581 mini_w
= XWINDOW (minibuf_window
);
27582 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
27583 echo_area_window
= minibuf_window
;
27585 if (!noninteractive
)
27587 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
27590 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
27591 set_window_height (root_window
,
27592 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
27594 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
27595 set_window_height (minibuf_window
, 1, 0);
27597 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
27598 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
27600 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
27601 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
27602 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
27604 /* The default ellipsis glyphs `...'. */
27605 for (i
= 0; i
< 3; ++i
)
27606 default_invis_vector
[i
] = make_number ('.');
27610 /* Allocate the buffer for frame titles.
27611 Also used for `format-mode-line'. */
27613 mode_line_noprop_buf
= (char *) xmalloc (size
);
27614 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
27615 mode_line_noprop_ptr
= mode_line_noprop_buf
;
27616 mode_line_target
= MODE_LINE_DISPLAY
;
27619 help_echo_showing_p
= 0;
27622 /* Since w32 does not support atimers, it defines its own implementation of
27623 the following three functions in w32fns.c. */
27626 /* Platform-independent portion of hourglass implementation. */
27628 /* Return non-zero if houglass timer has been started or hourglass is shown. */
27630 hourglass_started (void)
27632 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
27635 /* Cancel a currently active hourglass timer, and start a new one. */
27637 start_hourglass (void)
27639 #if defined (HAVE_WINDOW_SYSTEM)
27641 int secs
, usecs
= 0;
27643 cancel_hourglass ();
27645 if (INTEGERP (Vhourglass_delay
)
27646 && XINT (Vhourglass_delay
) > 0)
27647 secs
= XFASTINT (Vhourglass_delay
);
27648 else if (FLOATP (Vhourglass_delay
)
27649 && XFLOAT_DATA (Vhourglass_delay
) > 0)
27652 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
27653 secs
= XFASTINT (tem
);
27654 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
27657 secs
= DEFAULT_HOURGLASS_DELAY
;
27659 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
27660 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
27661 show_hourglass
, NULL
);
27666 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
27669 cancel_hourglass (void)
27671 #if defined (HAVE_WINDOW_SYSTEM)
27672 if (hourglass_atimer
)
27674 cancel_atimer (hourglass_atimer
);
27675 hourglass_atimer
= NULL
;
27678 if (hourglass_shown_p
)
27682 #endif /* ! WINDOWSNT */