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 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3117 EMACS_INT eob
= string_p
? string
->schars
: ZV
;
3118 EMACS_INT begb
= string_p
? 0 : BEGV
;
3119 EMACS_INT bufpos
, charpos
= CHARPOS (*position
);
3120 struct text_pos tpos
;
3123 /* We don't support display properties whose values are strings
3124 that have display string properties. */
3125 || string
->from_disp_str
3126 /* C strings cannot have display properties. */
3127 || (string
->s
&& !STRINGP (object
)))
3130 /* If the character at CHARPOS is where the display string begins,
3132 pos
= make_number (charpos
);
3133 if (STRINGP (object
))
3134 bufpos
= string
->bufpos
;
3138 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3140 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3143 && handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3147 /* Look forward for the first character with a `display' property
3148 that will replace the underlying text when displayed. */
3150 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3151 CHARPOS (tpos
) = XFASTINT (pos
);
3152 if (STRINGP (object
))
3153 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3155 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3156 if (CHARPOS (tpos
) >= eob
)
3158 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3159 if (!STRINGP (object
))
3160 bufpos
= CHARPOS (tpos
);
3161 } while (NILP (spec
)
3162 || !handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3165 return CHARPOS (tpos
);
3168 /* Return the character position of the end of the display string that
3169 started at CHARPOS. A display string is either an overlay with
3170 `display' property whose value is a string or a `display' text
3171 property whose value is a string. */
3173 compute_display_string_end (EMACS_INT charpos
, struct bidi_string_data
*string
)
3175 /* OBJECT = nil means current buffer. */
3176 Lisp_Object object
=
3177 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3178 Lisp_Object pos
= make_number (charpos
);
3180 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3182 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3185 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3188 /* Look forward for the first character where the `display' property
3190 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3192 return XFASTINT (pos
);
3197 /***********************************************************************
3199 ***********************************************************************/
3201 /* Handle changes in the `fontified' property of the current buffer by
3202 calling hook functions from Qfontification_functions to fontify
3205 static enum prop_handled
3206 handle_fontified_prop (struct it
*it
)
3208 Lisp_Object prop
, pos
;
3209 enum prop_handled handled
= HANDLED_NORMALLY
;
3211 if (!NILP (Vmemory_full
))
3214 /* Get the value of the `fontified' property at IT's current buffer
3215 position. (The `fontified' property doesn't have a special
3216 meaning in strings.) If the value is nil, call functions from
3217 Qfontification_functions. */
3218 if (!STRINGP (it
->string
)
3220 && !NILP (Vfontification_functions
)
3221 && !NILP (Vrun_hooks
)
3222 && (pos
= make_number (IT_CHARPOS (*it
)),
3223 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3224 /* Ignore the special cased nil value always present at EOB since
3225 no amount of fontifying will be able to change it. */
3226 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3228 int count
= SPECPDL_INDEX ();
3230 struct buffer
*obuf
= current_buffer
;
3231 int begv
= BEGV
, zv
= ZV
;
3232 int old_clip_changed
= current_buffer
->clip_changed
;
3234 val
= Vfontification_functions
;
3235 specbind (Qfontification_functions
, Qnil
);
3237 xassert (it
->end_charpos
== ZV
);
3239 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3240 safe_call1 (val
, pos
);
3243 Lisp_Object fns
, fn
;
3244 struct gcpro gcpro1
, gcpro2
;
3249 for (; CONSP (val
); val
= XCDR (val
))
3255 /* A value of t indicates this hook has a local
3256 binding; it means to run the global binding too.
3257 In a global value, t should not occur. If it
3258 does, we must ignore it to avoid an endless
3260 for (fns
= Fdefault_value (Qfontification_functions
);
3266 safe_call1 (fn
, pos
);
3270 safe_call1 (fn
, pos
);
3276 unbind_to (count
, Qnil
);
3278 /* Fontification functions routinely call `save-restriction'.
3279 Normally, this tags clip_changed, which can confuse redisplay
3280 (see discussion in Bug#6671). Since we don't perform any
3281 special handling of fontification changes in the case where
3282 `save-restriction' isn't called, there's no point doing so in
3283 this case either. So, if the buffer's restrictions are
3284 actually left unchanged, reset clip_changed. */
3285 if (obuf
== current_buffer
)
3287 if (begv
== BEGV
&& zv
== ZV
)
3288 current_buffer
->clip_changed
= old_clip_changed
;
3290 /* There isn't much we can reasonably do to protect against
3291 misbehaving fontification, but here's a fig leaf. */
3292 else if (!NILP (BVAR (obuf
, name
)))
3293 set_buffer_internal_1 (obuf
);
3295 /* The fontification code may have added/removed text.
3296 It could do even a lot worse, but let's at least protect against
3297 the most obvious case where only the text past `pos' gets changed',
3298 as is/was done in grep.el where some escapes sequences are turned
3299 into face properties (bug#7876). */
3300 it
->end_charpos
= ZV
;
3302 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3303 something. This avoids an endless loop if they failed to
3304 fontify the text for which reason ever. */
3305 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3306 handled
= HANDLED_RECOMPUTE_PROPS
;
3314 /***********************************************************************
3316 ***********************************************************************/
3318 /* Set up iterator IT from face properties at its current position.
3319 Called from handle_stop. */
3321 static enum prop_handled
3322 handle_face_prop (struct it
*it
)
3325 EMACS_INT next_stop
;
3327 if (!STRINGP (it
->string
))
3330 = face_at_buffer_position (it
->w
,
3332 it
->region_beg_charpos
,
3333 it
->region_end_charpos
,
3336 + TEXT_PROP_DISTANCE_LIMIT
),
3337 0, it
->base_face_id
);
3339 /* Is this a start of a run of characters with box face?
3340 Caveat: this can be called for a freshly initialized
3341 iterator; face_id is -1 in this case. We know that the new
3342 face will not change until limit, i.e. if the new face has a
3343 box, all characters up to limit will have one. But, as
3344 usual, we don't know whether limit is really the end. */
3345 if (new_face_id
!= it
->face_id
)
3347 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3349 /* If new face has a box but old face has not, this is
3350 the start of a run of characters with box, i.e. it has
3351 a shadow on the left side. The value of face_id of the
3352 iterator will be -1 if this is the initial call that gets
3353 the face. In this case, we have to look in front of IT's
3354 position and see whether there is a face != new_face_id. */
3355 it
->start_of_box_run_p
3356 = (new_face
->box
!= FACE_NO_BOX
3357 && (it
->face_id
>= 0
3358 || IT_CHARPOS (*it
) == BEG
3359 || new_face_id
!= face_before_it_pos (it
)));
3360 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3368 Lisp_Object from_overlay
3369 = (it
->current
.overlay_string_index
>= 0
3370 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3373 /* See if we got to this string directly or indirectly from
3374 an overlay property. That includes the before-string or
3375 after-string of an overlay, strings in display properties
3376 provided by an overlay, their text properties, etc.
3378 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3379 if (! NILP (from_overlay
))
3380 for (i
= it
->sp
- 1; i
>= 0; i
--)
3382 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3384 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3385 else if (! NILP (it
->stack
[i
].from_overlay
))
3386 from_overlay
= it
->stack
[i
].from_overlay
;
3388 if (!NILP (from_overlay
))
3392 if (! NILP (from_overlay
))
3394 bufpos
= IT_CHARPOS (*it
);
3395 /* For a string from an overlay, the base face depends
3396 only on text properties and ignores overlays. */
3398 = face_for_overlay_string (it
->w
,
3400 it
->region_beg_charpos
,
3401 it
->region_end_charpos
,
3404 + TEXT_PROP_DISTANCE_LIMIT
),
3412 /* For strings from a `display' property, use the face at
3413 IT's current buffer position as the base face to merge
3414 with, so that overlay strings appear in the same face as
3415 surrounding text, unless they specify their own
3417 base_face_id
= underlying_face_id (it
);
3420 new_face_id
= face_at_string_position (it
->w
,
3422 IT_STRING_CHARPOS (*it
),
3424 it
->region_beg_charpos
,
3425 it
->region_end_charpos
,
3429 /* Is this a start of a run of characters with box? Caveat:
3430 this can be called for a freshly allocated iterator; face_id
3431 is -1 is this case. We know that the new face will not
3432 change until the next check pos, i.e. if the new face has a
3433 box, all characters up to that position will have a
3434 box. But, as usual, we don't know whether that position
3435 is really the end. */
3436 if (new_face_id
!= it
->face_id
)
3438 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3439 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3441 /* If new face has a box but old face hasn't, this is the
3442 start of a run of characters with box, i.e. it has a
3443 shadow on the left side. */
3444 it
->start_of_box_run_p
3445 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3446 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3450 it
->face_id
= new_face_id
;
3451 return HANDLED_NORMALLY
;
3455 /* Return the ID of the face ``underlying'' IT's current position,
3456 which is in a string. If the iterator is associated with a
3457 buffer, return the face at IT's current buffer position.
3458 Otherwise, use the iterator's base_face_id. */
3461 underlying_face_id (struct it
*it
)
3463 int face_id
= it
->base_face_id
, i
;
3465 xassert (STRINGP (it
->string
));
3467 for (i
= it
->sp
- 1; i
>= 0; --i
)
3468 if (NILP (it
->stack
[i
].string
))
3469 face_id
= it
->stack
[i
].face_id
;
3475 /* Compute the face one character before or after the current position
3476 of IT, in the visual order. BEFORE_P non-zero means get the face
3477 in front (to the left in L2R paragraphs, to the right in R2L
3478 paragraphs) of IT's screen position. Value is the ID of the face. */
3481 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3484 EMACS_INT next_check_charpos
;
3487 xassert (it
->s
== NULL
);
3489 if (STRINGP (it
->string
))
3491 EMACS_INT bufpos
, charpos
;
3494 /* No face change past the end of the string (for the case
3495 we are padding with spaces). No face change before the
3497 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3498 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3503 /* Set charpos to the position before or after IT's current
3504 position, in the logical order, which in the non-bidi
3505 case is the same as the visual order. */
3507 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3508 else if (it
->what
== IT_COMPOSITION
)
3509 /* For composition, we must check the character after the
3511 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3513 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3519 /* With bidi iteration, the character before the current
3520 in the visual order cannot be found by simple
3521 iteration, because "reverse" reordering is not
3522 supported. Instead, we need to use the move_it_*
3523 family of functions. */
3524 /* Ignore face changes before the first visible
3525 character on this display line. */
3526 if (it
->current_x
<= it
->first_visible_x
)
3529 /* Implementation note: Since move_it_in_display_line
3530 works in the iterator geometry, and thinks the first
3531 character is always the leftmost, even in R2L lines,
3532 we don't need to distinguish between the R2L and L2R
3534 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3535 it_copy
.current_x
- 1, MOVE_TO_X
);
3536 charpos
= IT_STRING_CHARPOS (it_copy
);
3540 /* Set charpos to the string position of the character
3541 that comes after IT's current position in the visual
3543 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3547 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3549 charpos
= it_copy
.bidi_it
.charpos
;
3552 xassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3554 if (it
->current
.overlay_string_index
>= 0)
3555 bufpos
= IT_CHARPOS (*it
);
3559 base_face_id
= underlying_face_id (it
);
3561 /* Get the face for ASCII, or unibyte. */
3562 face_id
= face_at_string_position (it
->w
,
3566 it
->region_beg_charpos
,
3567 it
->region_end_charpos
,
3568 &next_check_charpos
,
3571 /* Correct the face for charsets different from ASCII. Do it
3572 for the multibyte case only. The face returned above is
3573 suitable for unibyte text if IT->string is unibyte. */
3574 if (STRING_MULTIBYTE (it
->string
))
3576 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3577 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3579 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3581 c
= string_char_and_length (p
, &len
);
3582 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3587 struct text_pos pos
;
3589 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3590 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3593 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3594 pos
= it
->current
.pos
;
3599 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3602 if (it
->what
== IT_COMPOSITION
)
3604 /* For composition, we must check the position after
3606 pos
.charpos
+= it
->cmp_it
.nchars
;
3607 pos
.bytepos
+= it
->len
;
3610 INC_TEXT_POS (pos
, it
->multibyte_p
);
3617 /* With bidi iteration, the character before the current
3618 in the visual order cannot be found by simple
3619 iteration, because "reverse" reordering is not
3620 supported. Instead, we need to use the move_it_*
3621 family of functions. */
3622 /* Ignore face changes before the first visible
3623 character on this display line. */
3624 if (it
->current_x
<= it
->first_visible_x
)
3627 /* Implementation note: Since move_it_in_display_line
3628 works in the iterator geometry, and thinks the first
3629 character is always the leftmost, even in R2L lines,
3630 we don't need to distinguish between the R2L and L2R
3632 move_it_in_display_line (&it_copy
, ZV
,
3633 it_copy
.current_x
- 1, MOVE_TO_X
);
3634 pos
= it_copy
.current
.pos
;
3638 /* Set charpos to the buffer position of the character
3639 that comes after IT's current position in the visual
3641 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3645 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3648 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
3651 xassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
3653 /* Determine face for CHARSET_ASCII, or unibyte. */
3654 face_id
= face_at_buffer_position (it
->w
,
3656 it
->region_beg_charpos
,
3657 it
->region_end_charpos
,
3658 &next_check_charpos
,
3661 /* Correct the face for charsets different from ASCII. Do it
3662 for the multibyte case only. The face returned above is
3663 suitable for unibyte text if current_buffer is unibyte. */
3664 if (it
->multibyte_p
)
3666 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3667 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3668 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3677 /***********************************************************************
3679 ***********************************************************************/
3681 /* Set up iterator IT from invisible properties at its current
3682 position. Called from handle_stop. */
3684 static enum prop_handled
3685 handle_invisible_prop (struct it
*it
)
3687 enum prop_handled handled
= HANDLED_NORMALLY
;
3689 if (STRINGP (it
->string
))
3691 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3693 /* Get the value of the invisible text property at the
3694 current position. Value will be nil if there is no such
3696 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3697 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3700 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3704 handled
= HANDLED_RECOMPUTE_PROPS
;
3706 /* Get the position at which the next change of the
3707 invisible text property can be found in IT->string.
3708 Value will be nil if the property value is the same for
3709 all the rest of IT->string. */
3710 XSETINT (limit
, SCHARS (it
->string
));
3711 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3714 /* Text at current position is invisible. The next
3715 change in the property is at position end_charpos.
3716 Move IT's current position to that position. */
3717 if (INTEGERP (end_charpos
)
3718 && (endpos
= XFASTINT (end_charpos
)) < XFASTINT (limit
))
3720 struct text_pos old
;
3723 old
= it
->current
.string_pos
;
3724 oldpos
= CHARPOS (old
);
3727 if (it
->bidi_it
.first_elt
3728 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
3729 bidi_paragraph_init (it
->paragraph_embedding
,
3731 /* Bidi-iterate out of the invisible text. */
3734 bidi_move_to_visually_next (&it
->bidi_it
);
3736 while (oldpos
<= it
->bidi_it
.charpos
3737 && it
->bidi_it
.charpos
< endpos
);
3739 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3740 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3741 if (IT_CHARPOS (*it
) >= endpos
)
3742 it
->prev_stop
= endpos
;
3746 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3747 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3752 /* The rest of the string is invisible. If this is an
3753 overlay string, proceed with the next overlay string
3754 or whatever comes and return a character from there. */
3755 if (it
->current
.overlay_string_index
>= 0)
3757 next_overlay_string (it
);
3758 /* Don't check for overlay strings when we just
3759 finished processing them. */
3760 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3764 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3765 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3773 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
3774 Lisp_Object pos
, prop
, overlay
;
3776 /* First of all, is there invisible text at this position? */
3777 tem
= start_charpos
= IT_CHARPOS (*it
);
3778 pos
= make_number (tem
);
3779 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3781 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3783 /* If we are on invisible text, skip over it. */
3784 if (invis_p
&& start_charpos
< it
->end_charpos
)
3786 /* Record whether we have to display an ellipsis for the
3788 int display_ellipsis_p
= invis_p
== 2;
3790 handled
= HANDLED_RECOMPUTE_PROPS
;
3792 /* Loop skipping over invisible text. The loop is left at
3793 ZV or with IT on the first char being visible again. */
3796 /* Try to skip some invisible text. Return value is the
3797 position reached which can be equal to where we start
3798 if there is nothing invisible there. This skips both
3799 over invisible text properties and overlays with
3800 invisible property. */
3801 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
3803 /* If we skipped nothing at all we weren't at invisible
3804 text in the first place. If everything to the end of
3805 the buffer was skipped, end the loop. */
3806 if (newpos
== tem
|| newpos
>= ZV
)
3810 /* We skipped some characters but not necessarily
3811 all there are. Check if we ended up on visible
3812 text. Fget_char_property returns the property of
3813 the char before the given position, i.e. if we
3814 get invis_p = 0, this means that the char at
3815 newpos is visible. */
3816 pos
= make_number (newpos
);
3817 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3818 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3821 /* If we ended up on invisible text, proceed to
3822 skip starting with next_stop. */
3826 /* If there are adjacent invisible texts, don't lose the
3827 second one's ellipsis. */
3829 display_ellipsis_p
= 1;
3833 /* The position newpos is now either ZV or on visible text. */
3834 if (it
->bidi_p
&& newpos
< ZV
)
3836 /* With bidi iteration, the region of invisible text
3837 could start and/or end in the middle of a non-base
3838 embedding level. Therefore, we need to skip
3839 invisible text using the bidi iterator, starting at
3840 IT's current position, until we find ourselves
3841 outside the invisible text. Skipping invisible text
3842 _after_ bidi iteration avoids affecting the visual
3843 order of the displayed text when invisible properties
3844 are added or removed. */
3845 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
3847 /* If we were `reseat'ed to a new paragraph,
3848 determine the paragraph base direction. We need
3849 to do it now because next_element_from_buffer may
3850 not have a chance to do it, if we are going to
3851 skip any text at the beginning, which resets the
3853 bidi_paragraph_init (it
->paragraph_embedding
,
3858 bidi_move_to_visually_next (&it
->bidi_it
);
3860 while (it
->stop_charpos
<= it
->bidi_it
.charpos
3861 && it
->bidi_it
.charpos
< newpos
);
3862 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3863 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3864 /* If we overstepped NEWPOS, record its position in the
3865 iterator, so that we skip invisible text if later the
3866 bidi iteration lands us in the invisible region
3868 if (IT_CHARPOS (*it
) >= newpos
)
3869 it
->prev_stop
= newpos
;
3873 IT_CHARPOS (*it
) = newpos
;
3874 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3877 /* If there are before-strings at the start of invisible
3878 text, and the text is invisible because of a text
3879 property, arrange to show before-strings because 20.x did
3880 it that way. (If the text is invisible because of an
3881 overlay property instead of a text property, this is
3882 already handled in the overlay code.) */
3884 && get_overlay_strings (it
, it
->stop_charpos
))
3886 handled
= HANDLED_RECOMPUTE_PROPS
;
3887 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3889 else if (display_ellipsis_p
)
3891 /* Make sure that the glyphs of the ellipsis will get
3892 correct `charpos' values. If we would not update
3893 it->position here, the glyphs would belong to the
3894 last visible character _before_ the invisible
3895 text, which confuses `set_cursor_from_row'.
3897 We use the last invisible position instead of the
3898 first because this way the cursor is always drawn on
3899 the first "." of the ellipsis, whenever PT is inside
3900 the invisible text. Otherwise the cursor would be
3901 placed _after_ the ellipsis when the point is after the
3902 first invisible character. */
3903 if (!STRINGP (it
->object
))
3905 it
->position
.charpos
= newpos
- 1;
3906 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3909 /* Let the ellipsis display before
3910 considering any properties of the following char.
3911 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3912 handled
= HANDLED_RETURN
;
3921 /* Make iterator IT return `...' next.
3922 Replaces LEN characters from buffer. */
3925 setup_for_ellipsis (struct it
*it
, int len
)
3927 /* Use the display table definition for `...'. Invalid glyphs
3928 will be handled by the method returning elements from dpvec. */
3929 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3931 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3932 it
->dpvec
= v
->contents
;
3933 it
->dpend
= v
->contents
+ v
->header
.size
;
3937 /* Default `...'. */
3938 it
->dpvec
= default_invis_vector
;
3939 it
->dpend
= default_invis_vector
+ 3;
3942 it
->dpvec_char_len
= len
;
3943 it
->current
.dpvec_index
= 0;
3944 it
->dpvec_face_id
= -1;
3946 /* Remember the current face id in case glyphs specify faces.
3947 IT's face is restored in set_iterator_to_next.
3948 saved_face_id was set to preceding char's face in handle_stop. */
3949 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3950 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3952 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3958 /***********************************************************************
3960 ***********************************************************************/
3962 /* Set up iterator IT from `display' property at its current position.
3963 Called from handle_stop.
3964 We return HANDLED_RETURN if some part of the display property
3965 overrides the display of the buffer text itself.
3966 Otherwise we return HANDLED_NORMALLY. */
3968 static enum prop_handled
3969 handle_display_prop (struct it
*it
)
3971 Lisp_Object propval
, object
, overlay
;
3972 struct text_pos
*position
;
3974 /* Nonzero if some property replaces the display of the text itself. */
3975 int display_replaced_p
= 0;
3977 if (STRINGP (it
->string
))
3979 object
= it
->string
;
3980 position
= &it
->current
.string_pos
;
3981 bufpos
= CHARPOS (it
->current
.pos
);
3985 XSETWINDOW (object
, it
->w
);
3986 position
= &it
->current
.pos
;
3987 bufpos
= CHARPOS (*position
);
3990 /* Reset those iterator values set from display property values. */
3991 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3992 it
->space_width
= Qnil
;
3993 it
->font_height
= Qnil
;
3996 /* We don't support recursive `display' properties, i.e. string
3997 values that have a string `display' property, that have a string
3998 `display' property etc. */
3999 if (!it
->string_from_display_prop_p
)
4000 it
->area
= TEXT_AREA
;
4002 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4003 Qdisplay
, object
, &overlay
);
4005 return HANDLED_NORMALLY
;
4006 /* Now OVERLAY is the overlay that gave us this property, or nil
4007 if it was a text property. */
4009 if (!STRINGP (it
->string
))
4010 object
= it
->w
->buffer
;
4012 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4014 FRAME_WINDOW_P (it
->f
));
4016 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4019 /* Subroutine of handle_display_prop. Returns non-zero if the display
4020 specification in SPEC is a replacing specification, i.e. it would
4021 replace the text covered by `display' property with something else,
4022 such as an image or a display string.
4024 See handle_single_display_spec for documentation of arguments.
4025 frame_window_p is non-zero if the window being redisplayed is on a
4026 GUI frame; this argument is used only if IT is NULL, see below.
4028 IT can be NULL, if this is called by the bidi reordering code
4029 through compute_display_string_pos, which see. In that case, this
4030 function only examines SPEC, but does not otherwise "handle" it, in
4031 the sense that it doesn't set up members of IT from the display
4034 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4035 Lisp_Object overlay
, struct text_pos
*position
,
4036 EMACS_INT bufpos
, int frame_window_p
)
4038 int replacing_p
= 0;
4041 /* Simple specerties. */
4042 && !EQ (XCAR (spec
), Qimage
)
4043 && !EQ (XCAR (spec
), Qspace
)
4044 && !EQ (XCAR (spec
), Qwhen
)
4045 && !EQ (XCAR (spec
), Qslice
)
4046 && !EQ (XCAR (spec
), Qspace_width
)
4047 && !EQ (XCAR (spec
), Qheight
)
4048 && !EQ (XCAR (spec
), Qraise
)
4049 /* Marginal area specifications. */
4050 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4051 && !EQ (XCAR (spec
), Qleft_fringe
)
4052 && !EQ (XCAR (spec
), Qright_fringe
)
4053 && !NILP (XCAR (spec
)))
4055 for (; CONSP (spec
); spec
= XCDR (spec
))
4057 if (handle_single_display_spec (it
, XCAR (spec
), object
, overlay
,
4058 position
, bufpos
, replacing_p
,
4062 /* If some text in a string is replaced, `position' no
4063 longer points to the position of `object'. */
4064 if (!it
|| STRINGP (object
))
4069 else if (VECTORP (spec
))
4072 for (i
= 0; i
< ASIZE (spec
); ++i
)
4073 if (handle_single_display_spec (it
, AREF (spec
, i
), object
, overlay
,
4074 position
, bufpos
, replacing_p
,
4078 /* If some text in a string is replaced, `position' no
4079 longer points to the position of `object'. */
4080 if (!it
|| STRINGP (object
))
4086 if (handle_single_display_spec (it
, spec
, object
, overlay
,
4087 position
, bufpos
, 0, frame_window_p
))
4094 /* Value is the position of the end of the `display' property starting
4095 at START_POS in OBJECT. */
4097 static struct text_pos
4098 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4101 struct text_pos end_pos
;
4103 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4104 Qdisplay
, object
, Qnil
);
4105 CHARPOS (end_pos
) = XFASTINT (end
);
4106 if (STRINGP (object
))
4107 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4109 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4115 /* Set up IT from a single `display' property specification SPEC. OBJECT
4116 is the object in which the `display' property was found. *POSITION
4117 is the position in OBJECT at which the `display' property was found.
4118 BUFPOS is the buffer position of OBJECT (different from POSITION if
4119 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4120 previously saw a display specification which already replaced text
4121 display with something else, for example an image; we ignore such
4122 properties after the first one has been processed.
4124 OVERLAY is the overlay this `display' property came from,
4125 or nil if it was a text property.
4127 If SPEC is a `space' or `image' specification, and in some other
4128 cases too, set *POSITION to the position where the `display'
4131 If IT is NULL, only examine the property specification in SPEC, but
4132 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4133 is intended to be displayed in a window on a GUI frame.
4135 Value is non-zero if something was found which replaces the display
4136 of buffer or string text. */
4139 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4140 Lisp_Object overlay
, struct text_pos
*position
,
4141 EMACS_INT bufpos
, int display_replaced_p
,
4145 Lisp_Object location
, value
;
4146 struct text_pos start_pos
= *position
;
4149 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4150 If the result is non-nil, use VALUE instead of SPEC. */
4152 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4161 if (!NILP (form
) && !EQ (form
, Qt
))
4163 int count
= SPECPDL_INDEX ();
4164 struct gcpro gcpro1
;
4166 /* Bind `object' to the object having the `display' property, a
4167 buffer or string. Bind `position' to the position in the
4168 object where the property was found, and `buffer-position'
4169 to the current position in the buffer. */
4172 XSETBUFFER (object
, current_buffer
);
4173 specbind (Qobject
, object
);
4174 specbind (Qposition
, make_number (CHARPOS (*position
)));
4175 specbind (Qbuffer_position
, make_number (bufpos
));
4177 form
= safe_eval (form
);
4179 unbind_to (count
, Qnil
);
4185 /* Handle `(height HEIGHT)' specifications. */
4187 && EQ (XCAR (spec
), Qheight
)
4188 && CONSP (XCDR (spec
)))
4192 if (!FRAME_WINDOW_P (it
->f
))
4195 it
->font_height
= XCAR (XCDR (spec
));
4196 if (!NILP (it
->font_height
))
4198 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4199 int new_height
= -1;
4201 if (CONSP (it
->font_height
)
4202 && (EQ (XCAR (it
->font_height
), Qplus
)
4203 || EQ (XCAR (it
->font_height
), Qminus
))
4204 && CONSP (XCDR (it
->font_height
))
4205 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4207 /* `(+ N)' or `(- N)' where N is an integer. */
4208 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4209 if (EQ (XCAR (it
->font_height
), Qplus
))
4211 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4213 else if (FUNCTIONP (it
->font_height
))
4215 /* Call function with current height as argument.
4216 Value is the new height. */
4218 height
= safe_call1 (it
->font_height
,
4219 face
->lface
[LFACE_HEIGHT_INDEX
]);
4220 if (NUMBERP (height
))
4221 new_height
= XFLOATINT (height
);
4223 else if (NUMBERP (it
->font_height
))
4225 /* Value is a multiple of the canonical char height. */
4228 f
= FACE_FROM_ID (it
->f
,
4229 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4230 new_height
= (XFLOATINT (it
->font_height
)
4231 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4235 /* Evaluate IT->font_height with `height' bound to the
4236 current specified height to get the new height. */
4237 int count
= SPECPDL_INDEX ();
4239 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4240 value
= safe_eval (it
->font_height
);
4241 unbind_to (count
, Qnil
);
4243 if (NUMBERP (value
))
4244 new_height
= XFLOATINT (value
);
4248 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4255 /* Handle `(space-width WIDTH)'. */
4257 && EQ (XCAR (spec
), Qspace_width
)
4258 && CONSP (XCDR (spec
)))
4262 if (!FRAME_WINDOW_P (it
->f
))
4265 value
= XCAR (XCDR (spec
));
4266 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4267 it
->space_width
= value
;
4273 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4275 && EQ (XCAR (spec
), Qslice
))
4281 if (!FRAME_WINDOW_P (it
->f
))
4284 if (tem
= XCDR (spec
), CONSP (tem
))
4286 it
->slice
.x
= XCAR (tem
);
4287 if (tem
= XCDR (tem
), CONSP (tem
))
4289 it
->slice
.y
= XCAR (tem
);
4290 if (tem
= XCDR (tem
), CONSP (tem
))
4292 it
->slice
.width
= XCAR (tem
);
4293 if (tem
= XCDR (tem
), CONSP (tem
))
4294 it
->slice
.height
= XCAR (tem
);
4303 /* Handle `(raise FACTOR)'. */
4305 && EQ (XCAR (spec
), Qraise
)
4306 && CONSP (XCDR (spec
)))
4310 if (!FRAME_WINDOW_P (it
->f
))
4313 #ifdef HAVE_WINDOW_SYSTEM
4314 value
= XCAR (XCDR (spec
));
4315 if (NUMBERP (value
))
4317 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4318 it
->voffset
= - (XFLOATINT (value
)
4319 * (FONT_HEIGHT (face
->font
)));
4321 #endif /* HAVE_WINDOW_SYSTEM */
4327 /* Don't handle the other kinds of display specifications
4328 inside a string that we got from a `display' property. */
4329 if (it
&& it
->string_from_display_prop_p
)
4332 /* Characters having this form of property are not displayed, so
4333 we have to find the end of the property. */
4336 start_pos
= *position
;
4337 *position
= display_prop_end (it
, object
, start_pos
);
4341 /* Stop the scan at that end position--we assume that all
4342 text properties change there. */
4344 it
->stop_charpos
= position
->charpos
;
4346 /* Handle `(left-fringe BITMAP [FACE])'
4347 and `(right-fringe BITMAP [FACE])'. */
4349 && (EQ (XCAR (spec
), Qleft_fringe
)
4350 || EQ (XCAR (spec
), Qright_fringe
))
4351 && CONSP (XCDR (spec
)))
4357 if (!FRAME_WINDOW_P (it
->f
))
4358 /* If we return here, POSITION has been advanced
4359 across the text with this property. */
4362 else if (!frame_window_p
)
4365 #ifdef HAVE_WINDOW_SYSTEM
4366 value
= XCAR (XCDR (spec
));
4367 if (!SYMBOLP (value
)
4368 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4369 /* If we return here, POSITION has been advanced
4370 across the text with this property. */
4375 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4377 if (CONSP (XCDR (XCDR (spec
))))
4379 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4380 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4386 /* Save current settings of IT so that we can restore them
4387 when we are finished with the glyph property value. */
4388 push_it (it
, position
);
4390 it
->area
= TEXT_AREA
;
4391 it
->what
= IT_IMAGE
;
4392 it
->image_id
= -1; /* no image */
4393 it
->position
= start_pos
;
4394 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4395 it
->method
= GET_FROM_IMAGE
;
4396 it
->from_overlay
= Qnil
;
4397 it
->face_id
= face_id
;
4398 it
->from_disp_prop_p
= 1;
4400 /* Say that we haven't consumed the characters with
4401 `display' property yet. The call to pop_it in
4402 set_iterator_to_next will clean this up. */
4403 *position
= start_pos
;
4405 if (EQ (XCAR (spec
), Qleft_fringe
))
4407 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4408 it
->left_user_fringe_face_id
= face_id
;
4412 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4413 it
->right_user_fringe_face_id
= face_id
;
4416 #endif /* HAVE_WINDOW_SYSTEM */
4420 /* Prepare to handle `((margin left-margin) ...)',
4421 `((margin right-margin) ...)' and `((margin nil) ...)'
4422 prefixes for display specifications. */
4423 location
= Qunbound
;
4424 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4428 value
= XCDR (spec
);
4430 value
= XCAR (value
);
4433 if (EQ (XCAR (tem
), Qmargin
)
4434 && (tem
= XCDR (tem
),
4435 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4437 || EQ (tem
, Qleft_margin
)
4438 || EQ (tem
, Qright_margin
))))
4442 if (EQ (location
, Qunbound
))
4448 /* After this point, VALUE is the property after any
4449 margin prefix has been stripped. It must be a string,
4450 an image specification, or `(space ...)'.
4452 LOCATION specifies where to display: `left-margin',
4453 `right-margin' or nil. */
4455 valid_p
= (STRINGP (value
)
4456 #ifdef HAVE_WINDOW_SYSTEM
4457 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4458 && valid_image_p (value
))
4459 #endif /* not HAVE_WINDOW_SYSTEM */
4460 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4462 if (valid_p
&& !display_replaced_p
)
4467 /* Save current settings of IT so that we can restore them
4468 when we are finished with the glyph property value. */
4469 push_it (it
, position
);
4470 it
->from_overlay
= overlay
;
4471 it
->from_disp_prop_p
= 1;
4473 if (NILP (location
))
4474 it
->area
= TEXT_AREA
;
4475 else if (EQ (location
, Qleft_margin
))
4476 it
->area
= LEFT_MARGIN_AREA
;
4478 it
->area
= RIGHT_MARGIN_AREA
;
4480 if (STRINGP (value
))
4483 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4484 it
->current
.overlay_string_index
= -1;
4485 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4486 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4487 it
->method
= GET_FROM_STRING
;
4488 it
->stop_charpos
= 0;
4490 it
->base_level_stop
= 0;
4491 it
->string_from_display_prop_p
= 1;
4492 /* Say that we haven't consumed the characters with
4493 `display' property yet. The call to pop_it in
4494 set_iterator_to_next will clean this up. */
4495 if (BUFFERP (object
))
4496 *position
= start_pos
;
4498 /* Force paragraph direction to be that of the parent
4499 object. If the parent object's paragraph direction is
4500 not yet determined, default to L2R. */
4501 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
4502 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
4504 it
->paragraph_embedding
= L2R
;
4506 /* Set up the bidi iterator for this display string. */
4509 it
->bidi_it
.string
.lstring
= it
->string
;
4510 it
->bidi_it
.string
.s
= NULL
;
4511 it
->bidi_it
.string
.schars
= it
->end_charpos
;
4512 it
->bidi_it
.string
.bufpos
= bufpos
;
4513 it
->bidi_it
.string
.from_disp_str
= 1;
4514 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
4515 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4518 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4520 it
->method
= GET_FROM_STRETCH
;
4522 *position
= it
->position
= start_pos
;
4524 #ifdef HAVE_WINDOW_SYSTEM
4527 it
->what
= IT_IMAGE
;
4528 it
->image_id
= lookup_image (it
->f
, value
);
4529 it
->position
= start_pos
;
4530 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4531 it
->method
= GET_FROM_IMAGE
;
4533 /* Say that we haven't consumed the characters with
4534 `display' property yet. The call to pop_it in
4535 set_iterator_to_next will clean this up. */
4536 *position
= start_pos
;
4538 #endif /* HAVE_WINDOW_SYSTEM */
4543 /* Invalid property or property not supported. Restore
4544 POSITION to what it was before. */
4545 *position
= start_pos
;
4549 /* Check if PROP is a display property value whose text should be
4550 treated as intangible. OVERLAY is the overlay from which PROP
4551 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4552 specify the buffer position covered by PROP. */
4555 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4556 EMACS_INT charpos
, EMACS_INT bytepos
)
4558 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4559 struct text_pos position
;
4561 SET_TEXT_POS (position
, charpos
, bytepos
);
4562 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4563 &position
, charpos
, frame_window_p
);
4567 /* Return 1 if PROP is a display sub-property value containing STRING.
4569 Implementation note: this and the following function are really
4570 special cases of handle_display_spec and
4571 handle_single_display_spec, and should ideally use the same code.
4572 Until they do, these two pairs must be consistent and must be
4573 modified in sync. */
4576 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4578 if (EQ (string
, prop
))
4581 /* Skip over `when FORM'. */
4582 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4587 /* Actually, the condition following `when' should be eval'ed,
4588 like handle_single_display_spec does, and we should return
4589 zero if it evaluates to nil. However, this function is
4590 called only when the buffer was already displayed and some
4591 glyph in the glyph matrix was found to come from a display
4592 string. Therefore, the condition was already evaluated, and
4593 the result was non-nil, otherwise the display string wouldn't
4594 have been displayed and we would have never been called for
4595 this property. Thus, we can skip the evaluation and assume
4596 its result is non-nil. */
4601 /* Skip over `margin LOCATION'. */
4602 if (EQ (XCAR (prop
), Qmargin
))
4613 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
4617 /* Return 1 if STRING appears in the `display' property PROP. */
4620 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4623 && !EQ (XCAR (prop
), Qwhen
)
4624 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
4626 /* A list of sub-properties. */
4627 while (CONSP (prop
))
4629 if (single_display_spec_string_p (XCAR (prop
), string
))
4634 else if (VECTORP (prop
))
4636 /* A vector of sub-properties. */
4638 for (i
= 0; i
< ASIZE (prop
); ++i
)
4639 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4643 return single_display_spec_string_p (prop
, string
);
4648 /* Look for STRING in overlays and text properties in the current
4649 buffer, between character positions FROM and TO (excluding TO).
4650 BACK_P non-zero means look back (in this case, TO is supposed to be
4652 Value is the first character position where STRING was found, or
4653 zero if it wasn't found before hitting TO.
4655 This function may only use code that doesn't eval because it is
4656 called asynchronously from note_mouse_highlight. */
4659 string_buffer_position_lim (Lisp_Object string
,
4660 EMACS_INT from
, EMACS_INT to
, int back_p
)
4662 Lisp_Object limit
, prop
, pos
;
4665 pos
= make_number (from
);
4667 if (!back_p
) /* looking forward */
4669 limit
= make_number (min (to
, ZV
));
4670 while (!found
&& !EQ (pos
, limit
))
4672 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4673 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4676 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4680 else /* looking back */
4682 limit
= make_number (max (to
, BEGV
));
4683 while (!found
&& !EQ (pos
, limit
))
4685 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4686 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4689 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4694 return found
? XINT (pos
) : 0;
4697 /* Determine which buffer position in current buffer STRING comes from.
4698 AROUND_CHARPOS is an approximate position where it could come from.
4699 Value is the buffer position or 0 if it couldn't be determined.
4701 This function is necessary because we don't record buffer positions
4702 in glyphs generated from strings (to keep struct glyph small).
4703 This function may only use code that doesn't eval because it is
4704 called asynchronously from note_mouse_highlight. */
4707 string_buffer_position (Lisp_Object string
, EMACS_INT around_charpos
)
4709 const int MAX_DISTANCE
= 1000;
4710 EMACS_INT found
= string_buffer_position_lim (string
, around_charpos
,
4711 around_charpos
+ MAX_DISTANCE
,
4715 found
= string_buffer_position_lim (string
, around_charpos
,
4716 around_charpos
- MAX_DISTANCE
, 1);
4722 /***********************************************************************
4723 `composition' property
4724 ***********************************************************************/
4726 /* Set up iterator IT from `composition' property at its current
4727 position. Called from handle_stop. */
4729 static enum prop_handled
4730 handle_composition_prop (struct it
*it
)
4732 Lisp_Object prop
, string
;
4733 EMACS_INT pos
, pos_byte
, start
, end
;
4735 if (STRINGP (it
->string
))
4739 pos
= IT_STRING_CHARPOS (*it
);
4740 pos_byte
= IT_STRING_BYTEPOS (*it
);
4741 string
= it
->string
;
4742 s
= SDATA (string
) + pos_byte
;
4743 it
->c
= STRING_CHAR (s
);
4747 pos
= IT_CHARPOS (*it
);
4748 pos_byte
= IT_BYTEPOS (*it
);
4750 it
->c
= FETCH_CHAR (pos_byte
);
4753 /* If there's a valid composition and point is not inside of the
4754 composition (in the case that the composition is from the current
4755 buffer), draw a glyph composed from the composition components. */
4756 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4757 && COMPOSITION_VALID_P (start
, end
, prop
)
4758 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4762 if (STRINGP (it
->string
))
4763 pos_byte
= string_char_to_byte (it
->string
, start
);
4765 pos_byte
= CHAR_TO_BYTE (start
);
4767 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4770 if (it
->cmp_it
.id
>= 0)
4773 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4774 it
->cmp_it
.nglyphs
= -1;
4778 return HANDLED_NORMALLY
;
4783 /***********************************************************************
4785 ***********************************************************************/
4787 /* The following structure is used to record overlay strings for
4788 later sorting in load_overlay_strings. */
4790 struct overlay_entry
4792 Lisp_Object overlay
;
4799 /* Set up iterator IT from overlay strings at its current position.
4800 Called from handle_stop. */
4802 static enum prop_handled
4803 handle_overlay_change (struct it
*it
)
4805 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4806 return HANDLED_RECOMPUTE_PROPS
;
4808 return HANDLED_NORMALLY
;
4812 /* Set up the next overlay string for delivery by IT, if there is an
4813 overlay string to deliver. Called by set_iterator_to_next when the
4814 end of the current overlay string is reached. If there are more
4815 overlay strings to display, IT->string and
4816 IT->current.overlay_string_index are set appropriately here.
4817 Otherwise IT->string is set to nil. */
4820 next_overlay_string (struct it
*it
)
4822 ++it
->current
.overlay_string_index
;
4823 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4825 /* No more overlay strings. Restore IT's settings to what
4826 they were before overlay strings were processed, and
4827 continue to deliver from current_buffer. */
4829 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4832 || (NILP (it
->string
)
4833 && it
->method
== GET_FROM_BUFFER
4834 && it
->stop_charpos
>= BEGV
4835 && it
->stop_charpos
<= it
->end_charpos
));
4836 it
->current
.overlay_string_index
= -1;
4837 it
->n_overlay_strings
= 0;
4838 it
->overlay_strings_charpos
= -1;
4840 /* If we're at the end of the buffer, record that we have
4841 processed the overlay strings there already, so that
4842 next_element_from_buffer doesn't try it again. */
4843 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4844 it
->overlay_strings_at_end_processed_p
= 1;
4848 /* There are more overlay strings to process. If
4849 IT->current.overlay_string_index has advanced to a position
4850 where we must load IT->overlay_strings with more strings, do
4851 it. We must load at the IT->overlay_strings_charpos where
4852 IT->n_overlay_strings was originally computed; when invisible
4853 text is present, this might not be IT_CHARPOS (Bug#7016). */
4854 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4856 if (it
->current
.overlay_string_index
&& i
== 0)
4857 load_overlay_strings (it
, it
->overlay_strings_charpos
);
4859 /* Initialize IT to deliver display elements from the overlay
4861 it
->string
= it
->overlay_strings
[i
];
4862 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4863 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4864 it
->method
= GET_FROM_STRING
;
4865 it
->stop_charpos
= 0;
4866 if (it
->cmp_it
.stop_pos
>= 0)
4867 it
->cmp_it
.stop_pos
= 0;
4869 it
->base_level_stop
= 0;
4871 /* Set up the bidi iterator for this overlay string. */
4874 it
->bidi_it
.string
.lstring
= it
->string
;
4875 it
->bidi_it
.string
.s
= NULL
;
4876 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
4877 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
4878 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
4879 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
4880 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4888 /* Compare two overlay_entry structures E1 and E2. Used as a
4889 comparison function for qsort in load_overlay_strings. Overlay
4890 strings for the same position are sorted so that
4892 1. All after-strings come in front of before-strings, except
4893 when they come from the same overlay.
4895 2. Within after-strings, strings are sorted so that overlay strings
4896 from overlays with higher priorities come first.
4898 2. Within before-strings, strings are sorted so that overlay
4899 strings from overlays with higher priorities come last.
4901 Value is analogous to strcmp. */
4905 compare_overlay_entries (const void *e1
, const void *e2
)
4907 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4908 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4911 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4913 /* Let after-strings appear in front of before-strings if
4914 they come from different overlays. */
4915 if (EQ (entry1
->overlay
, entry2
->overlay
))
4916 result
= entry1
->after_string_p
? 1 : -1;
4918 result
= entry1
->after_string_p
? -1 : 1;
4920 else if (entry1
->after_string_p
)
4921 /* After-strings sorted in order of decreasing priority. */
4922 result
= entry2
->priority
- entry1
->priority
;
4924 /* Before-strings sorted in order of increasing priority. */
4925 result
= entry1
->priority
- entry2
->priority
;
4931 /* Load the vector IT->overlay_strings with overlay strings from IT's
4932 current buffer position, or from CHARPOS if that is > 0. Set
4933 IT->n_overlays to the total number of overlay strings found.
4935 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4936 a time. On entry into load_overlay_strings,
4937 IT->current.overlay_string_index gives the number of overlay
4938 strings that have already been loaded by previous calls to this
4941 IT->add_overlay_start contains an additional overlay start
4942 position to consider for taking overlay strings from, if non-zero.
4943 This position comes into play when the overlay has an `invisible'
4944 property, and both before and after-strings. When we've skipped to
4945 the end of the overlay, because of its `invisible' property, we
4946 nevertheless want its before-string to appear.
4947 IT->add_overlay_start will contain the overlay start position
4950 Overlay strings are sorted so that after-string strings come in
4951 front of before-string strings. Within before and after-strings,
4952 strings are sorted by overlay priority. See also function
4953 compare_overlay_entries. */
4956 load_overlay_strings (struct it
*it
, EMACS_INT charpos
)
4958 Lisp_Object overlay
, window
, str
, invisible
;
4959 struct Lisp_Overlay
*ov
;
4960 EMACS_INT start
, end
;
4962 int n
= 0, i
, j
, invis_p
;
4963 struct overlay_entry
*entries
4964 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4967 charpos
= IT_CHARPOS (*it
);
4969 /* Append the overlay string STRING of overlay OVERLAY to vector
4970 `entries' which has size `size' and currently contains `n'
4971 elements. AFTER_P non-zero means STRING is an after-string of
4973 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4976 Lisp_Object priority; \
4980 int new_size = 2 * size; \
4981 struct overlay_entry *old = entries; \
4983 (struct overlay_entry *) alloca (new_size \
4984 * sizeof *entries); \
4985 memcpy (entries, old, size * sizeof *entries); \
4989 entries[n].string = (STRING); \
4990 entries[n].overlay = (OVERLAY); \
4991 priority = Foverlay_get ((OVERLAY), Qpriority); \
4992 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4993 entries[n].after_string_p = (AFTER_P); \
4998 /* Process overlay before the overlay center. */
4999 for (ov
= current_buffer
->overlays_before
; 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
));
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, both before-
5020 and after-strings from this overlay are visible; start and
5021 end position are indistinguishable. */
5022 invisible
= Foverlay_get (overlay
, Qinvisible
);
5023 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5025 /* If overlay has a non-empty before-string, record it. */
5026 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5027 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5029 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5031 /* If overlay has a non-empty after-string, record it. */
5032 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5033 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5035 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5038 /* Process overlays after the overlay center. */
5039 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5041 XSETMISC (overlay
, ov
);
5042 xassert (OVERLAYP (overlay
));
5043 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5044 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5046 if (start
> charpos
)
5049 /* Skip this overlay if it doesn't start or end at IT's current
5051 if (end
!= charpos
&& start
!= charpos
)
5054 /* Skip this overlay if it doesn't apply to IT->w. */
5055 window
= Foverlay_get (overlay
, Qwindow
);
5056 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5059 /* If the text ``under'' the overlay is invisible, it has a zero
5060 dimension, and both before- and after-strings apply. */
5061 invisible
= Foverlay_get (overlay
, Qinvisible
);
5062 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5064 /* If overlay has a non-empty before-string, record it. */
5065 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5066 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5068 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5070 /* If overlay has a non-empty after-string, record it. */
5071 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5072 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5074 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5077 #undef RECORD_OVERLAY_STRING
5081 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5083 /* Record number of overlay strings, and where we computed it. */
5084 it
->n_overlay_strings
= n
;
5085 it
->overlay_strings_charpos
= charpos
;
5087 /* IT->current.overlay_string_index is the number of overlay strings
5088 that have already been consumed by IT. Copy some of the
5089 remaining overlay strings to IT->overlay_strings. */
5091 j
= it
->current
.overlay_string_index
;
5092 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5094 it
->overlay_strings
[i
] = entries
[j
].string
;
5095 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5102 /* Get the first chunk of overlay strings at IT's current buffer
5103 position, or at CHARPOS if that is > 0. Value is non-zero if at
5104 least one overlay string was found. */
5107 get_overlay_strings_1 (struct it
*it
, EMACS_INT charpos
, int compute_stop_p
)
5109 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5110 process. This fills IT->overlay_strings with strings, and sets
5111 IT->n_overlay_strings to the total number of strings to process.
5112 IT->pos.overlay_string_index has to be set temporarily to zero
5113 because load_overlay_strings needs this; it must be set to -1
5114 when no overlay strings are found because a zero value would
5115 indicate a position in the first overlay string. */
5116 it
->current
.overlay_string_index
= 0;
5117 load_overlay_strings (it
, charpos
);
5119 /* If we found overlay strings, set up IT to deliver display
5120 elements from the first one. Otherwise set up IT to deliver
5121 from current_buffer. */
5122 if (it
->n_overlay_strings
)
5124 /* Make sure we know settings in current_buffer, so that we can
5125 restore meaningful values when we're done with the overlay
5128 compute_stop_pos (it
);
5129 xassert (it
->face_id
>= 0);
5131 /* Save IT's settings. They are restored after all overlay
5132 strings have been processed. */
5133 xassert (!compute_stop_p
|| it
->sp
== 0);
5135 /* When called from handle_stop, there might be an empty display
5136 string loaded. In that case, don't bother saving it. */
5137 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5140 /* Set up IT to deliver display elements from the first overlay
5142 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5143 it
->string
= it
->overlay_strings
[0];
5144 it
->from_overlay
= Qnil
;
5145 it
->stop_charpos
= 0;
5146 xassert (STRINGP (it
->string
));
5147 it
->end_charpos
= SCHARS (it
->string
);
5149 it
->base_level_stop
= 0;
5150 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5151 it
->method
= GET_FROM_STRING
;
5152 it
->from_disp_prop_p
= 0;
5154 /* Force paragraph direction to be that of the parent
5156 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5157 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5159 it
->paragraph_embedding
= L2R
;
5161 /* Set up the bidi iterator for this overlay string. */
5164 EMACS_INT pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5166 it
->bidi_it
.string
.lstring
= it
->string
;
5167 it
->bidi_it
.string
.s
= NULL
;
5168 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5169 it
->bidi_it
.string
.bufpos
= pos
;
5170 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5171 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5172 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5177 it
->current
.overlay_string_index
= -1;
5182 get_overlay_strings (struct it
*it
, EMACS_INT charpos
)
5185 it
->method
= GET_FROM_BUFFER
;
5187 (void) get_overlay_strings_1 (it
, charpos
, 1);
5191 /* Value is non-zero if we found at least one overlay string. */
5192 return STRINGP (it
->string
);
5197 /***********************************************************************
5198 Saving and restoring state
5199 ***********************************************************************/
5201 /* Save current settings of IT on IT->stack. Called, for example,
5202 before setting up IT for an overlay string, to be able to restore
5203 IT's settings to what they were after the overlay string has been
5204 processed. If POSITION is non-NULL, it is the position to save on
5205 the stack instead of IT->position. */
5208 push_it (struct it
*it
, struct text_pos
*position
)
5210 struct iterator_stack_entry
*p
;
5212 xassert (it
->sp
< IT_STACK_SIZE
);
5213 p
= it
->stack
+ it
->sp
;
5215 p
->stop_charpos
= it
->stop_charpos
;
5216 p
->prev_stop
= it
->prev_stop
;
5217 p
->base_level_stop
= it
->base_level_stop
;
5218 p
->cmp_it
= it
->cmp_it
;
5219 xassert (it
->face_id
>= 0);
5220 p
->face_id
= it
->face_id
;
5221 p
->string
= it
->string
;
5222 p
->method
= it
->method
;
5223 p
->from_overlay
= it
->from_overlay
;
5226 case GET_FROM_IMAGE
:
5227 p
->u
.image
.object
= it
->object
;
5228 p
->u
.image
.image_id
= it
->image_id
;
5229 p
->u
.image
.slice
= it
->slice
;
5231 case GET_FROM_STRETCH
:
5232 p
->u
.stretch
.object
= it
->object
;
5235 p
->position
= position
? *position
: it
->position
;
5236 p
->current
= it
->current
;
5237 p
->end_charpos
= it
->end_charpos
;
5238 p
->string_nchars
= it
->string_nchars
;
5240 p
->multibyte_p
= it
->multibyte_p
;
5241 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5242 p
->space_width
= it
->space_width
;
5243 p
->font_height
= it
->font_height
;
5244 p
->voffset
= it
->voffset
;
5245 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5246 p
->display_ellipsis_p
= 0;
5247 p
->line_wrap
= it
->line_wrap
;
5248 p
->bidi_p
= it
->bidi_p
;
5249 p
->paragraph_embedding
= it
->paragraph_embedding
;
5250 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5253 /* Save the state of the bidi iterator as well. */
5255 bidi_push_it (&it
->bidi_it
);
5259 iterate_out_of_display_property (struct it
*it
)
5261 int buffer_p
= BUFFERP (it
->object
);
5262 EMACS_INT eob
= (buffer_p
? ZV
: it
->end_charpos
);
5263 EMACS_INT bob
= (buffer_p
? BEGV
: 0);
5265 /* Maybe initialize paragraph direction. If we are at the beginning
5266 of a new paragraph, next_element_from_buffer may not have a
5267 chance to do that. */
5268 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5269 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5270 /* prev_stop can be zero, so check against BEGV as well. */
5271 while (it
->bidi_it
.charpos
>= bob
5272 && it
->prev_stop
<= it
->bidi_it
.charpos
5273 && it
->bidi_it
.charpos
< CHARPOS (it
->position
))
5274 bidi_move_to_visually_next (&it
->bidi_it
);
5275 /* Record the stop_pos we just crossed, for when we cross it
5277 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5278 it
->prev_stop
= CHARPOS (it
->position
);
5279 /* If we ended up not where pop_it put us, resync IT's
5280 positional members with the bidi iterator. */
5281 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5283 SET_TEXT_POS (it
->position
,
5284 it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5286 it
->current
.pos
= it
->position
;
5288 it
->current
.string_pos
= it
->position
;
5292 /* Restore IT's settings from IT->stack. Called, for example, when no
5293 more overlay strings must be processed, and we return to delivering
5294 display elements from a buffer, or when the end of a string from a
5295 `display' property is reached and we return to delivering display
5296 elements from an overlay string, or from a buffer. */
5299 pop_it (struct it
*it
)
5301 struct iterator_stack_entry
*p
;
5302 int from_display_prop
= it
->from_disp_prop_p
;
5304 xassert (it
->sp
> 0);
5306 p
= it
->stack
+ it
->sp
;
5307 it
->stop_charpos
= p
->stop_charpos
;
5308 it
->prev_stop
= p
->prev_stop
;
5309 it
->base_level_stop
= p
->base_level_stop
;
5310 it
->cmp_it
= p
->cmp_it
;
5311 it
->face_id
= p
->face_id
;
5312 it
->current
= p
->current
;
5313 it
->position
= p
->position
;
5314 it
->string
= p
->string
;
5315 it
->from_overlay
= p
->from_overlay
;
5316 if (NILP (it
->string
))
5317 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5318 it
->method
= p
->method
;
5321 case GET_FROM_IMAGE
:
5322 it
->image_id
= p
->u
.image
.image_id
;
5323 it
->object
= p
->u
.image
.object
;
5324 it
->slice
= p
->u
.image
.slice
;
5326 case GET_FROM_STRETCH
:
5327 it
->object
= p
->u
.stretch
.object
;
5329 case GET_FROM_BUFFER
:
5330 it
->object
= it
->w
->buffer
;
5332 case GET_FROM_STRING
:
5333 it
->object
= it
->string
;
5335 case GET_FROM_DISPLAY_VECTOR
:
5337 it
->method
= GET_FROM_C_STRING
;
5338 else if (STRINGP (it
->string
))
5339 it
->method
= GET_FROM_STRING
;
5342 it
->method
= GET_FROM_BUFFER
;
5343 it
->object
= it
->w
->buffer
;
5346 it
->end_charpos
= p
->end_charpos
;
5347 it
->string_nchars
= p
->string_nchars
;
5349 it
->multibyte_p
= p
->multibyte_p
;
5350 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5351 it
->space_width
= p
->space_width
;
5352 it
->font_height
= p
->font_height
;
5353 it
->voffset
= p
->voffset
;
5354 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5355 it
->line_wrap
= p
->line_wrap
;
5356 it
->bidi_p
= p
->bidi_p
;
5357 it
->paragraph_embedding
= p
->paragraph_embedding
;
5358 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5361 bidi_pop_it (&it
->bidi_it
);
5362 /* Bidi-iterate until we get out of the portion of text, if any,
5363 covered by a `display' text property or by an overlay with
5364 `display' property. (We cannot just jump there, because the
5365 internal coherency of the bidi iterator state can not be
5366 preserved across such jumps.) We also must determine the
5367 paragraph base direction if the overlay we just processed is
5368 at the beginning of a new paragraph. */
5369 if (from_display_prop
5370 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5371 iterate_out_of_display_property (it
);
5373 xassert ((BUFFERP (it
->object
)
5374 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5375 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5376 || (STRINGP (it
->object
)
5377 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5378 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
));
5384 /***********************************************************************
5386 ***********************************************************************/
5388 /* Set IT's current position to the previous line start. */
5391 back_to_previous_line_start (struct it
*it
)
5393 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5394 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5398 /* Move IT to the next line start.
5400 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5401 we skipped over part of the text (as opposed to moving the iterator
5402 continuously over the text). Otherwise, don't change the value
5405 Newlines may come from buffer text, overlay strings, or strings
5406 displayed via the `display' property. That's the reason we can't
5407 simply use find_next_newline_no_quit.
5409 Note that this function may not skip over invisible text that is so
5410 because of text properties and immediately follows a newline. If
5411 it would, function reseat_at_next_visible_line_start, when called
5412 from set_iterator_to_next, would effectively make invisible
5413 characters following a newline part of the wrong glyph row, which
5414 leads to wrong cursor motion. */
5417 forward_to_next_line_start (struct it
*it
, int *skipped_p
)
5419 int old_selective
, newline_found_p
, n
;
5420 const int MAX_NEWLINE_DISTANCE
= 500;
5422 /* If already on a newline, just consume it to avoid unintended
5423 skipping over invisible text below. */
5424 if (it
->what
== IT_CHARACTER
5426 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5428 set_iterator_to_next (it
, 0);
5433 /* Don't handle selective display in the following. It's (a)
5434 unnecessary because it's done by the caller, and (b) leads to an
5435 infinite recursion because next_element_from_ellipsis indirectly
5436 calls this function. */
5437 old_selective
= it
->selective
;
5440 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5441 from buffer text. */
5442 for (n
= newline_found_p
= 0;
5443 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5444 n
+= STRINGP (it
->string
) ? 0 : 1)
5446 if (!get_next_display_element (it
))
5448 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5449 set_iterator_to_next (it
, 0);
5452 /* If we didn't find a newline near enough, see if we can use a
5454 if (!newline_found_p
)
5456 EMACS_INT start
= IT_CHARPOS (*it
);
5457 EMACS_INT limit
= find_next_newline_no_quit (start
, 1);
5460 xassert (!STRINGP (it
->string
));
5462 /* If we are not bidi-reordering, and there isn't any `display'
5463 property in sight, and no overlays, we can just use the
5464 position of the newline in buffer text. */
5466 && (it
->stop_charpos
>= limit
5467 || ((pos
= Fnext_single_property_change (make_number (start
),
5469 make_number (limit
)),
5471 && next_overlay_change (start
) == ZV
)))
5473 IT_CHARPOS (*it
) = limit
;
5474 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5475 *skipped_p
= newline_found_p
= 1;
5479 while (get_next_display_element (it
)
5480 && !newline_found_p
)
5482 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5483 set_iterator_to_next (it
, 0);
5488 it
->selective
= old_selective
;
5489 return newline_found_p
;
5493 /* Set IT's current position to the previous visible line start. Skip
5494 invisible text that is so either due to text properties or due to
5495 selective display. Caution: this does not change IT->current_x and
5499 back_to_previous_visible_line_start (struct it
*it
)
5501 while (IT_CHARPOS (*it
) > BEGV
)
5503 back_to_previous_line_start (it
);
5505 if (IT_CHARPOS (*it
) <= BEGV
)
5508 /* If selective > 0, then lines indented more than its value are
5510 if (it
->selective
> 0
5511 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5512 (double) it
->selective
)) /* iftc */
5515 /* Check the newline before point for invisibility. */
5518 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5519 Qinvisible
, it
->window
);
5520 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5524 if (IT_CHARPOS (*it
) <= BEGV
)
5531 Lisp_Object val
, overlay
;
5533 /* If newline is part of a composition, continue from start of composition */
5534 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5535 && beg
< IT_CHARPOS (*it
))
5538 /* If newline is replaced by a display property, find start of overlay
5539 or interval and continue search from that point. */
5541 pos
= --IT_CHARPOS (it2
);
5544 it2
.string_from_display_prop_p
= 0;
5545 if (handle_display_prop (&it2
) == HANDLED_RETURN
5546 && !NILP (val
= get_char_property_and_overlay
5547 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5548 && (OVERLAYP (overlay
)
5549 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5550 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5552 /* If the call to handle_display_prop above pushed the
5553 iterator state, that causes side effects for the bidi
5554 iterator by calling bidi_push_it. Undo those side
5558 /* push_it calls bidi_push_it only if the bidi_p flag
5559 is set in the iterator being pushed. */
5560 if (it2
.stack
[--it2
.sp
].bidi_p
)
5561 bidi_pop_it (&it2
.bidi_it
);
5566 /* Newline is not replaced by anything -- so we are done. */
5572 IT_CHARPOS (*it
) = beg
;
5573 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5577 it
->continuation_lines_width
= 0;
5579 xassert (IT_CHARPOS (*it
) >= BEGV
);
5580 xassert (IT_CHARPOS (*it
) == BEGV
5581 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5586 /* Reseat iterator IT at the previous visible line start. Skip
5587 invisible text that is so either due to text properties or due to
5588 selective display. At the end, update IT's overlay information,
5589 face information etc. */
5592 reseat_at_previous_visible_line_start (struct it
*it
)
5594 back_to_previous_visible_line_start (it
);
5595 reseat (it
, it
->current
.pos
, 1);
5600 /* Reseat iterator IT on the next visible line start in the current
5601 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5602 preceding the line start. Skip over invisible text that is so
5603 because of selective display. Compute faces, overlays etc at the
5604 new position. Note that this function does not skip over text that
5605 is invisible because of text properties. */
5608 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5610 int newline_found_p
, skipped_p
= 0;
5612 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5614 /* Skip over lines that are invisible because they are indented
5615 more than the value of IT->selective. */
5616 if (it
->selective
> 0)
5617 while (IT_CHARPOS (*it
) < ZV
5618 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5619 (double) it
->selective
)) /* iftc */
5621 xassert (IT_BYTEPOS (*it
) == BEGV
5622 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5623 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5626 /* Position on the newline if that's what's requested. */
5627 if (on_newline_p
&& newline_found_p
)
5629 if (STRINGP (it
->string
))
5631 if (IT_STRING_CHARPOS (*it
) > 0)
5635 --IT_STRING_CHARPOS (*it
);
5636 --IT_STRING_BYTEPOS (*it
);
5639 /* Setting this flag will cause
5640 bidi_move_to_visually_next not to advance, but
5641 instead deliver the current character (newline),
5642 which is what the ON_NEWLINE_P flag wants. */
5643 it
->bidi_it
.first_elt
= 1;
5646 else if (IT_CHARPOS (*it
) > BEGV
)
5653 /* With bidi iteration, the call to `reseat' will cause
5654 bidi_move_to_visually_next deliver the current character,
5655 the newline, instead of advancing. */
5656 reseat (it
, it
->current
.pos
, 0);
5660 reseat (it
, it
->current
.pos
, 0);
5667 /***********************************************************************
5668 Changing an iterator's position
5669 ***********************************************************************/
5671 /* Change IT's current position to POS in current_buffer. If FORCE_P
5672 is non-zero, always check for text properties at the new position.
5673 Otherwise, text properties are only looked up if POS >=
5674 IT->check_charpos of a property. */
5677 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
5679 EMACS_INT original_pos
= IT_CHARPOS (*it
);
5681 reseat_1 (it
, pos
, 0);
5683 /* Determine where to check text properties. Avoid doing it
5684 where possible because text property lookup is very expensive. */
5686 || CHARPOS (pos
) > it
->stop_charpos
5687 || CHARPOS (pos
) < original_pos
)
5691 /* For bidi iteration, we need to prime prev_stop and
5692 base_level_stop with our best estimations. */
5693 if (CHARPOS (pos
) < it
->prev_stop
)
5695 handle_stop_backwards (it
, BEGV
);
5696 if (CHARPOS (pos
) < it
->base_level_stop
)
5697 it
->base_level_stop
= 0;
5699 else if (CHARPOS (pos
) > it
->stop_charpos
5700 && it
->stop_charpos
>= BEGV
)
5701 handle_stop_backwards (it
, it
->stop_charpos
);
5708 it
->prev_stop
= it
->base_level_stop
= 0;
5717 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5718 IT->stop_pos to POS, also. */
5721 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
5723 /* Don't call this function when scanning a C string. */
5724 xassert (it
->s
== NULL
);
5726 /* POS must be a reasonable value. */
5727 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5729 it
->current
.pos
= it
->position
= pos
;
5730 it
->end_charpos
= ZV
;
5732 it
->current
.dpvec_index
= -1;
5733 it
->current
.overlay_string_index
= -1;
5734 IT_STRING_CHARPOS (*it
) = -1;
5735 IT_STRING_BYTEPOS (*it
) = -1;
5737 it
->method
= GET_FROM_BUFFER
;
5738 it
->object
= it
->w
->buffer
;
5739 it
->area
= TEXT_AREA
;
5740 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
5742 it
->string_from_display_prop_p
= 0;
5743 it
->face_before_selective_p
= 0;
5746 it
->bidi_it
.first_elt
= 1;
5747 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5748 it
->bidi_it
.disp_pos
= -1;
5749 it
->bidi_it
.string
.s
= NULL
;
5750 it
->bidi_it
.string
.lstring
= Qnil
;
5751 it
->bidi_it
.string
.bufpos
= 0;
5752 it
->bidi_it
.string
.unibyte
= 0;
5757 it
->stop_charpos
= CHARPOS (pos
);
5758 it
->base_level_stop
= CHARPOS (pos
);
5763 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5764 If S is non-null, it is a C string to iterate over. Otherwise,
5765 STRING gives a Lisp string to iterate over.
5767 If PRECISION > 0, don't return more then PRECISION number of
5768 characters from the string.
5770 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5771 characters have been returned. FIELD_WIDTH < 0 means an infinite
5774 MULTIBYTE = 0 means disable processing of multibyte characters,
5775 MULTIBYTE > 0 means enable it,
5776 MULTIBYTE < 0 means use IT->multibyte_p.
5778 IT must be initialized via a prior call to init_iterator before
5779 calling this function. */
5782 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
5783 EMACS_INT charpos
, EMACS_INT precision
, int field_width
,
5786 /* No region in strings. */
5787 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5789 /* No text property checks performed by default, but see below. */
5790 it
->stop_charpos
= -1;
5792 /* Set iterator position and end position. */
5793 memset (&it
->current
, 0, sizeof it
->current
);
5794 it
->current
.overlay_string_index
= -1;
5795 it
->current
.dpvec_index
= -1;
5796 xassert (charpos
>= 0);
5798 /* If STRING is specified, use its multibyteness, otherwise use the
5799 setting of MULTIBYTE, if specified. */
5801 it
->multibyte_p
= multibyte
> 0;
5803 /* Bidirectional reordering of strings is controlled by the default
5804 value of bidi-display-reordering. */
5805 it
->bidi_p
= !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
5809 xassert (STRINGP (string
));
5810 it
->string
= string
;
5812 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5813 it
->method
= GET_FROM_STRING
;
5814 it
->current
.string_pos
= string_pos (charpos
, string
);
5818 it
->bidi_it
.string
.lstring
= string
;
5819 it
->bidi_it
.string
.s
= NULL
;
5820 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5821 it
->bidi_it
.string
.bufpos
= 0;
5822 it
->bidi_it
.string
.from_disp_str
= 0;
5823 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5824 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
5825 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5830 it
->s
= (const unsigned char *) s
;
5833 /* Note that we use IT->current.pos, not it->current.string_pos,
5834 for displaying C strings. */
5835 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5836 if (it
->multibyte_p
)
5838 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5839 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5843 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5844 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5849 it
->bidi_it
.string
.lstring
= Qnil
;
5850 it
->bidi_it
.string
.s
= s
;
5851 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5852 it
->bidi_it
.string
.bufpos
= 0;
5853 it
->bidi_it
.string
.from_disp_str
= 0;
5854 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5855 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
5858 it
->method
= GET_FROM_C_STRING
;
5861 /* PRECISION > 0 means don't return more than PRECISION characters
5863 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5865 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5867 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5870 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5871 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5872 FIELD_WIDTH < 0 means infinite field width. This is useful for
5873 padding with `-' at the end of a mode line. */
5874 if (field_width
< 0)
5875 field_width
= INFINITY
;
5876 /* Implementation note: We deliberately don't enlarge
5877 it->bidi_it.string.schars here to fit it->end_charpos, because
5878 the bidi iterator cannot produce characters out of thin air. */
5879 if (field_width
> it
->end_charpos
- charpos
)
5880 it
->end_charpos
= charpos
+ field_width
;
5882 /* Use the standard display table for displaying strings. */
5883 if (DISP_TABLE_P (Vstandard_display_table
))
5884 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5886 it
->stop_charpos
= charpos
;
5887 it
->prev_stop
= charpos
;
5888 it
->base_level_stop
= 0;
5891 it
->bidi_it
.first_elt
= 1;
5892 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5893 it
->bidi_it
.disp_pos
= -1;
5895 if (s
== NULL
&& it
->multibyte_p
)
5897 EMACS_INT endpos
= SCHARS (it
->string
);
5898 if (endpos
> it
->end_charpos
)
5899 endpos
= it
->end_charpos
;
5900 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5908 /***********************************************************************
5910 ***********************************************************************/
5912 /* Map enum it_method value to corresponding next_element_from_* function. */
5914 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
5916 next_element_from_buffer
,
5917 next_element_from_display_vector
,
5918 next_element_from_string
,
5919 next_element_from_c_string
,
5920 next_element_from_image
,
5921 next_element_from_stretch
5924 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5927 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5928 (possibly with the following characters). */
5930 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5931 ((IT)->cmp_it.id >= 0 \
5932 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5933 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5934 END_CHARPOS, (IT)->w, \
5935 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5939 /* Lookup the char-table Vglyphless_char_display for character C (-1
5940 if we want information for no-font case), and return the display
5941 method symbol. By side-effect, update it->what and
5942 it->glyphless_method. This function is called from
5943 get_next_display_element for each character element, and from
5944 x_produce_glyphs when no suitable font was found. */
5947 lookup_glyphless_char_display (int c
, struct it
*it
)
5949 Lisp_Object glyphless_method
= Qnil
;
5951 if (CHAR_TABLE_P (Vglyphless_char_display
)
5952 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
5956 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
5957 if (CONSP (glyphless_method
))
5958 glyphless_method
= FRAME_WINDOW_P (it
->f
)
5959 ? XCAR (glyphless_method
)
5960 : XCDR (glyphless_method
);
5963 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
5967 if (NILP (glyphless_method
))
5970 /* The default is to display the character by a proper font. */
5972 /* The default for the no-font case is to display an empty box. */
5973 glyphless_method
= Qempty_box
;
5975 if (EQ (glyphless_method
, Qzero_width
))
5978 return glyphless_method
;
5979 /* This method can't be used for the no-font case. */
5980 glyphless_method
= Qempty_box
;
5982 if (EQ (glyphless_method
, Qthin_space
))
5983 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
5984 else if (EQ (glyphless_method
, Qempty_box
))
5985 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
5986 else if (EQ (glyphless_method
, Qhex_code
))
5987 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
5988 else if (STRINGP (glyphless_method
))
5989 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
5992 /* Invalid value. We use the default method. */
5993 glyphless_method
= Qnil
;
5996 it
->what
= IT_GLYPHLESS
;
5997 return glyphless_method
;
6000 /* Load IT's display element fields with information about the next
6001 display element from the current position of IT. Value is zero if
6002 end of buffer (or C string) is reached. */
6004 static struct frame
*last_escape_glyph_frame
= NULL
;
6005 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6006 static int last_escape_glyph_merged_face_id
= 0;
6008 struct frame
*last_glyphless_glyph_frame
= NULL
;
6009 unsigned last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6010 int last_glyphless_glyph_merged_face_id
= 0;
6013 get_next_display_element (struct it
*it
)
6015 /* Non-zero means that we found a display element. Zero means that
6016 we hit the end of what we iterate over. Performance note: the
6017 function pointer `method' used here turns out to be faster than
6018 using a sequence of if-statements. */
6022 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6024 if (it
->what
== IT_CHARACTER
)
6026 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6027 and only if (a) the resolved directionality of that character
6029 /* FIXME: Do we need an exception for characters from display
6031 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6032 it
->c
= bidi_mirror_char (it
->c
);
6033 /* Map via display table or translate control characters.
6034 IT->c, IT->len etc. have been set to the next character by
6035 the function call above. If we have a display table, and it
6036 contains an entry for IT->c, translate it. Don't do this if
6037 IT->c itself comes from a display table, otherwise we could
6038 end up in an infinite recursion. (An alternative could be to
6039 count the recursion depth of this function and signal an
6040 error when a certain maximum depth is reached.) Is it worth
6042 if (success_p
&& it
->dpvec
== NULL
)
6045 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6046 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
6047 nbsp_or_shy
= char_is_other
;
6048 int c
= it
->c
; /* This is the character to display. */
6050 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6052 xassert (SINGLE_BYTE_CHAR_P (c
));
6053 if (unibyte_display_via_language_environment
)
6055 c
= DECODE_CHAR (unibyte
, c
);
6057 c
= BYTE8_TO_CHAR (it
->c
);
6060 c
= BYTE8_TO_CHAR (it
->c
);
6064 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6067 struct Lisp_Vector
*v
= XVECTOR (dv
);
6069 /* Return the first character from the display table
6070 entry, if not empty. If empty, don't display the
6071 current character. */
6074 it
->dpvec_char_len
= it
->len
;
6075 it
->dpvec
= v
->contents
;
6076 it
->dpend
= v
->contents
+ v
->header
.size
;
6077 it
->current
.dpvec_index
= 0;
6078 it
->dpvec_face_id
= -1;
6079 it
->saved_face_id
= it
->face_id
;
6080 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6085 set_iterator_to_next (it
, 0);
6090 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6092 if (it
->what
== IT_GLYPHLESS
)
6094 /* Don't display this character. */
6095 set_iterator_to_next (it
, 0);
6099 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6100 nbsp_or_shy
= (c
== 0xA0 ? char_is_nbsp
6101 : c
== 0xAD ? char_is_soft_hyphen
6104 /* Translate control characters into `\003' or `^C' form.
6105 Control characters coming from a display table entry are
6106 currently not translated because we use IT->dpvec to hold
6107 the translation. This could easily be changed but I
6108 don't believe that it is worth doing.
6110 NBSP and SOFT-HYPEN are property translated too.
6112 Non-printable characters and raw-byte characters are also
6113 translated to octal form. */
6114 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6115 ? (it
->area
!= TEXT_AREA
6116 /* In mode line, treat \n, \t like other crl chars. */
6119 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6120 || (c
!= '\n' && c
!= '\t'))
6123 || ! CHAR_PRINTABLE_P (c
))))
6125 /* C is a control character, NBSP, SOFT-HYPEN, raw-byte,
6126 or a non-printable character which must be displayed
6127 either as '\003' or as `^C' where the '\\' and '^'
6128 can be defined in the display table. Fill
6129 IT->ctl_chars with glyphs for what we have to
6130 display. Then, set IT->dpvec to these glyphs. */
6133 int face_id
, lface_id
= 0 ;
6136 /* Handle control characters with ^. */
6138 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6142 g
= '^'; /* default glyph for Control */
6143 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6145 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6146 && GLYPH_CODE_CHAR_VALID_P (gc
))
6148 g
= GLYPH_CODE_CHAR (gc
);
6149 lface_id
= GLYPH_CODE_FACE (gc
);
6153 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6155 else if (it
->f
== last_escape_glyph_frame
6156 && it
->face_id
== last_escape_glyph_face_id
)
6158 face_id
= last_escape_glyph_merged_face_id
;
6162 /* Merge the escape-glyph face into the current face. */
6163 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6165 last_escape_glyph_frame
= it
->f
;
6166 last_escape_glyph_face_id
= it
->face_id
;
6167 last_escape_glyph_merged_face_id
= face_id
;
6170 XSETINT (it
->ctl_chars
[0], g
);
6171 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6173 goto display_control
;
6176 /* Handle non-break space in the mode where it only gets
6179 if (EQ (Vnobreak_char_display
, Qt
)
6180 && nbsp_or_shy
== char_is_nbsp
)
6182 /* Merge the no-break-space face into the current face. */
6183 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6187 XSETINT (it
->ctl_chars
[0], ' ');
6189 goto display_control
;
6192 /* Handle sequences that start with the "escape glyph". */
6194 /* the default escape glyph is \. */
6195 escape_glyph
= '\\';
6198 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6199 && GLYPH_CODE_CHAR_VALID_P (gc
))
6201 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6202 lface_id
= GLYPH_CODE_FACE (gc
);
6206 /* The display table specified a face.
6207 Merge it into face_id and also into escape_glyph. */
6208 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6211 else if (it
->f
== last_escape_glyph_frame
6212 && it
->face_id
== last_escape_glyph_face_id
)
6214 face_id
= last_escape_glyph_merged_face_id
;
6218 /* Merge the escape-glyph face into the current face. */
6219 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6221 last_escape_glyph_frame
= it
->f
;
6222 last_escape_glyph_face_id
= it
->face_id
;
6223 last_escape_glyph_merged_face_id
= face_id
;
6226 /* Handle soft hyphens in the mode where they only get
6229 if (EQ (Vnobreak_char_display
, Qt
)
6230 && nbsp_or_shy
== char_is_soft_hyphen
)
6232 XSETINT (it
->ctl_chars
[0], '-');
6234 goto display_control
;
6237 /* Handle non-break space and soft hyphen
6238 with the escape glyph. */
6242 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6243 c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
6244 XSETINT (it
->ctl_chars
[1], c
);
6246 goto display_control
;
6253 if (CHAR_BYTE8_P (c
))
6254 /* Display \200 instead of \17777600. */
6255 c
= CHAR_TO_BYTE8 (c
);
6256 len
= sprintf (str
, "%03o", c
);
6258 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6259 for (i
= 0; i
< len
; i
++)
6260 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6265 /* Set up IT->dpvec and return first character from it. */
6266 it
->dpvec_char_len
= it
->len
;
6267 it
->dpvec
= it
->ctl_chars
;
6268 it
->dpend
= it
->dpvec
+ ctl_len
;
6269 it
->current
.dpvec_index
= 0;
6270 it
->dpvec_face_id
= face_id
;
6271 it
->saved_face_id
= it
->face_id
;
6272 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6276 it
->char_to_display
= c
;
6280 it
->char_to_display
= it
->c
;
6284 /* Adjust face id for a multibyte character. There are no multibyte
6285 character in unibyte text. */
6286 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6289 && FRAME_WINDOW_P (it
->f
))
6291 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6293 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6295 /* Automatic composition with glyph-string. */
6296 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6298 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6302 EMACS_INT pos
= (it
->s
? -1
6303 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6304 : IT_CHARPOS (*it
));
6306 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
, pos
,
6312 /* Is this character the last one of a run of characters with
6313 box? If yes, set IT->end_of_box_run_p to 1. */
6317 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6319 int face_id
= underlying_face_id (it
);
6320 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6324 if (face
->box
== FACE_NO_BOX
)
6326 /* If the box comes from face properties in a
6327 display string, check faces in that string. */
6328 int string_face_id
= face_after_it_pos (it
);
6329 it
->end_of_box_run_p
6330 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6333 /* Otherwise, the box comes from the underlying face.
6334 If this is the last string character displayed, check
6335 the next buffer location. */
6336 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6337 && (it
->current
.overlay_string_index
6338 == it
->n_overlay_strings
- 1))
6342 struct text_pos pos
= it
->current
.pos
;
6343 INC_TEXT_POS (pos
, it
->multibyte_p
);
6345 next_face_id
= face_at_buffer_position
6346 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6347 it
->region_end_charpos
, &ignore
,
6348 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6350 it
->end_of_box_run_p
6351 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6358 int face_id
= face_after_it_pos (it
);
6359 it
->end_of_box_run_p
6360 = (face_id
!= it
->face_id
6361 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6365 /* Value is 0 if end of buffer or string reached. */
6370 /* Move IT to the next display element.
6372 RESEAT_P non-zero means if called on a newline in buffer text,
6373 skip to the next visible line start.
6375 Functions get_next_display_element and set_iterator_to_next are
6376 separate because I find this arrangement easier to handle than a
6377 get_next_display_element function that also increments IT's
6378 position. The way it is we can first look at an iterator's current
6379 display element, decide whether it fits on a line, and if it does,
6380 increment the iterator position. The other way around we probably
6381 would either need a flag indicating whether the iterator has to be
6382 incremented the next time, or we would have to implement a
6383 decrement position function which would not be easy to write. */
6386 set_iterator_to_next (struct it
*it
, int reseat_p
)
6388 /* Reset flags indicating start and end of a sequence of characters
6389 with box. Reset them at the start of this function because
6390 moving the iterator to a new position might set them. */
6391 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6395 case GET_FROM_BUFFER
:
6396 /* The current display element of IT is a character from
6397 current_buffer. Advance in the buffer, and maybe skip over
6398 invisible lines that are so because of selective display. */
6399 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6400 reseat_at_next_visible_line_start (it
, 0);
6401 else if (it
->cmp_it
.id
>= 0)
6403 /* We are currently getting glyphs from a composition. */
6408 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6409 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6410 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6412 it
->cmp_it
.from
= it
->cmp_it
.to
;
6417 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6419 it
->end_charpos
, Qnil
);
6422 else if (! it
->cmp_it
.reversed_p
)
6424 /* Composition created while scanning forward. */
6425 /* Update IT's char/byte positions to point to the first
6426 character of the next grapheme cluster, or to the
6427 character visually after the current composition. */
6428 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6429 bidi_move_to_visually_next (&it
->bidi_it
);
6430 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6431 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6433 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6435 /* Proceed to the next grapheme cluster. */
6436 it
->cmp_it
.from
= it
->cmp_it
.to
;
6440 /* No more grapheme clusters in this composition.
6441 Find the next stop position. */
6442 EMACS_INT stop
= it
->end_charpos
;
6443 if (it
->bidi_it
.scan_dir
< 0)
6444 /* Now we are scanning backward and don't know
6447 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6448 IT_BYTEPOS (*it
), stop
, Qnil
);
6453 /* Composition created while scanning backward. */
6454 /* Update IT's char/byte positions to point to the last
6455 character of the previous grapheme cluster, or the
6456 character visually after the current composition. */
6457 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6458 bidi_move_to_visually_next (&it
->bidi_it
);
6459 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6460 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6461 if (it
->cmp_it
.from
> 0)
6463 /* Proceed to the previous grapheme cluster. */
6464 it
->cmp_it
.to
= it
->cmp_it
.from
;
6468 /* No more grapheme clusters in this composition.
6469 Find the next stop position. */
6470 EMACS_INT stop
= it
->end_charpos
;
6471 if (it
->bidi_it
.scan_dir
< 0)
6472 /* Now we are scanning backward and don't know
6475 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6476 IT_BYTEPOS (*it
), stop
, Qnil
);
6482 xassert (it
->len
!= 0);
6486 IT_BYTEPOS (*it
) += it
->len
;
6487 IT_CHARPOS (*it
) += 1;
6491 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6492 /* If this is a new paragraph, determine its base
6493 direction (a.k.a. its base embedding level). */
6494 if (it
->bidi_it
.new_paragraph
)
6495 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6496 bidi_move_to_visually_next (&it
->bidi_it
);
6497 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6498 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6499 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6501 /* As the scan direction was changed, we must
6502 re-compute the stop position for composition. */
6503 EMACS_INT stop
= it
->end_charpos
;
6504 if (it
->bidi_it
.scan_dir
< 0)
6506 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6507 IT_BYTEPOS (*it
), stop
, Qnil
);
6510 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6514 case GET_FROM_C_STRING
:
6515 /* Current display element of IT is from a C string. */
6517 /* If the string position is beyond string's end, it means
6518 next_element_from_c_string is padding the string with
6519 blanks, in which case we bypass the bidi iterator,
6520 because it cannot deal with such virtual characters. */
6521 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
6523 IT_BYTEPOS (*it
) += it
->len
;
6524 IT_CHARPOS (*it
) += 1;
6528 bidi_move_to_visually_next (&it
->bidi_it
);
6529 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6530 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6534 case GET_FROM_DISPLAY_VECTOR
:
6535 /* Current display element of IT is from a display table entry.
6536 Advance in the display table definition. Reset it to null if
6537 end reached, and continue with characters from buffers/
6539 ++it
->current
.dpvec_index
;
6541 /* Restore face of the iterator to what they were before the
6542 display vector entry (these entries may contain faces). */
6543 it
->face_id
= it
->saved_face_id
;
6545 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6547 int recheck_faces
= it
->ellipsis_p
;
6550 it
->method
= GET_FROM_C_STRING
;
6551 else if (STRINGP (it
->string
))
6552 it
->method
= GET_FROM_STRING
;
6555 it
->method
= GET_FROM_BUFFER
;
6556 it
->object
= it
->w
->buffer
;
6560 it
->current
.dpvec_index
= -1;
6562 /* Skip over characters which were displayed via IT->dpvec. */
6563 if (it
->dpvec_char_len
< 0)
6564 reseat_at_next_visible_line_start (it
, 1);
6565 else if (it
->dpvec_char_len
> 0)
6567 if (it
->method
== GET_FROM_STRING
6568 && it
->n_overlay_strings
> 0)
6569 it
->ignore_overlay_strings_at_pos_p
= 1;
6570 it
->len
= it
->dpvec_char_len
;
6571 set_iterator_to_next (it
, reseat_p
);
6574 /* Maybe recheck faces after display vector */
6576 it
->stop_charpos
= IT_CHARPOS (*it
);
6580 case GET_FROM_STRING
:
6581 /* Current display element is a character from a Lisp string. */
6582 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6583 if (it
->cmp_it
.id
>= 0)
6589 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6590 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6591 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6592 it
->cmp_it
.from
= it
->cmp_it
.to
;
6596 composition_compute_stop_pos (&it
->cmp_it
,
6597 IT_STRING_CHARPOS (*it
),
6598 IT_STRING_BYTEPOS (*it
),
6599 it
->end_charpos
, it
->string
);
6602 else if (! it
->cmp_it
.reversed_p
)
6604 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6605 bidi_move_to_visually_next (&it
->bidi_it
);
6606 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6607 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6609 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6610 it
->cmp_it
.from
= it
->cmp_it
.to
;
6613 EMACS_INT stop
= it
->end_charpos
;
6614 if (it
->bidi_it
.scan_dir
< 0)
6616 composition_compute_stop_pos (&it
->cmp_it
,
6617 IT_STRING_CHARPOS (*it
),
6618 IT_STRING_BYTEPOS (*it
), stop
,
6624 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6625 bidi_move_to_visually_next (&it
->bidi_it
);
6626 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6627 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6628 if (it
->cmp_it
.from
> 0)
6629 it
->cmp_it
.to
= it
->cmp_it
.from
;
6632 EMACS_INT stop
= it
->end_charpos
;
6633 if (it
->bidi_it
.scan_dir
< 0)
6635 composition_compute_stop_pos (&it
->cmp_it
,
6636 IT_STRING_CHARPOS (*it
),
6637 IT_STRING_BYTEPOS (*it
), stop
,
6645 /* If the string position is beyond string's end, it
6646 means next_element_from_string is padding the string
6647 with blanks, in which case we bypass the bidi
6648 iterator, because it cannot deal with such virtual
6650 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
6652 IT_STRING_BYTEPOS (*it
) += it
->len
;
6653 IT_STRING_CHARPOS (*it
) += 1;
6657 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6659 bidi_move_to_visually_next (&it
->bidi_it
);
6660 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6661 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6662 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6664 EMACS_INT stop
= it
->end_charpos
;
6666 if (it
->bidi_it
.scan_dir
< 0)
6668 composition_compute_stop_pos (&it
->cmp_it
,
6669 IT_STRING_CHARPOS (*it
),
6670 IT_STRING_BYTEPOS (*it
), stop
,
6676 consider_string_end
:
6678 if (it
->current
.overlay_string_index
>= 0)
6680 /* IT->string is an overlay string. Advance to the
6681 next, if there is one. */
6682 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6685 next_overlay_string (it
);
6687 setup_for_ellipsis (it
, 0);
6692 /* IT->string is not an overlay string. If we reached
6693 its end, and there is something on IT->stack, proceed
6694 with what is on the stack. This can be either another
6695 string, this time an overlay string, or a buffer. */
6696 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6700 if (it
->method
== GET_FROM_STRING
)
6701 goto consider_string_end
;
6706 case GET_FROM_IMAGE
:
6707 case GET_FROM_STRETCH
:
6708 /* The position etc with which we have to proceed are on
6709 the stack. The position may be at the end of a string,
6710 if the `display' property takes up the whole string. */
6711 xassert (it
->sp
> 0);
6713 if (it
->method
== GET_FROM_STRING
)
6714 goto consider_string_end
;
6718 /* There are no other methods defined, so this should be a bug. */
6722 xassert (it
->method
!= GET_FROM_STRING
6723 || (STRINGP (it
->string
)
6724 && IT_STRING_CHARPOS (*it
) >= 0));
6727 /* Load IT's display element fields with information about the next
6728 display element which comes from a display table entry or from the
6729 result of translating a control character to one of the forms `^C'
6732 IT->dpvec holds the glyphs to return as characters.
6733 IT->saved_face_id holds the face id before the display vector--it
6734 is restored into IT->face_id in set_iterator_to_next. */
6737 next_element_from_display_vector (struct it
*it
)
6742 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6744 it
->face_id
= it
->saved_face_id
;
6746 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6747 That seemed totally bogus - so I changed it... */
6748 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6750 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6752 it
->c
= GLYPH_CODE_CHAR (gc
);
6753 it
->len
= CHAR_BYTES (it
->c
);
6755 /* The entry may contain a face id to use. Such a face id is
6756 the id of a Lisp face, not a realized face. A face id of
6757 zero means no face is specified. */
6758 if (it
->dpvec_face_id
>= 0)
6759 it
->face_id
= it
->dpvec_face_id
;
6762 int lface_id
= GLYPH_CODE_FACE (gc
);
6764 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6769 /* Display table entry is invalid. Return a space. */
6770 it
->c
= ' ', it
->len
= 1;
6772 /* Don't change position and object of the iterator here. They are
6773 still the values of the character that had this display table
6774 entry or was translated, and that's what we want. */
6775 it
->what
= IT_CHARACTER
;
6779 /* Get the first element of string/buffer in the visual order, after
6780 being reseated to a new position in a string or a buffer. */
6782 get_visually_first_element (struct it
*it
)
6784 int string_p
= STRINGP (it
->string
) || it
->s
;
6785 EMACS_INT eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
6786 EMACS_INT bob
= (string_p
? 0 : BEGV
);
6788 if (STRINGP (it
->string
))
6790 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
6791 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
6795 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6796 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6799 if (it
->bidi_it
.charpos
== eob
)
6801 /* Nothing to do, but reset the FIRST_ELT flag, like
6802 bidi_paragraph_init does, because we are not going to
6804 it
->bidi_it
.first_elt
= 0;
6806 else if (it
->bidi_it
.charpos
== bob
6808 /* FIXME: Should support all Unicode line separators. */
6809 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6810 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
6812 /* If we are at the beginning of a line/string, we can produce
6813 the next element right away. */
6814 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6815 bidi_move_to_visually_next (&it
->bidi_it
);
6819 EMACS_INT orig_bytepos
= it
->bidi_it
.bytepos
;
6821 /* We need to prime the bidi iterator starting at the line's or
6822 string's beginning, before we will be able to produce the
6825 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
6828 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
6830 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
6832 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6835 /* Now return to buffer/string position where we were asked
6836 to get the next display element, and produce that. */
6837 bidi_move_to_visually_next (&it
->bidi_it
);
6839 while (it
->bidi_it
.bytepos
!= orig_bytepos
6840 && it
->bidi_it
.charpos
< eob
);
6843 /* Adjust IT's position information to where we ended up. */
6844 if (STRINGP (it
->string
))
6846 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6847 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6851 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6852 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6855 if (STRINGP (it
->string
) || !it
->s
)
6857 EMACS_INT stop
, charpos
, bytepos
;
6859 if (STRINGP (it
->string
))
6862 stop
= SCHARS (it
->string
);
6863 if (stop
> it
->end_charpos
)
6864 stop
= it
->end_charpos
;
6865 charpos
= IT_STRING_CHARPOS (*it
);
6866 bytepos
= IT_STRING_BYTEPOS (*it
);
6870 stop
= it
->end_charpos
;
6871 charpos
= IT_CHARPOS (*it
);
6872 bytepos
= IT_BYTEPOS (*it
);
6874 if (it
->bidi_it
.scan_dir
< 0)
6876 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
6881 /* Load IT with the next display element from Lisp string IT->string.
6882 IT->current.string_pos is the current position within the string.
6883 If IT->current.overlay_string_index >= 0, the Lisp string is an
6887 next_element_from_string (struct it
*it
)
6889 struct text_pos position
;
6891 xassert (STRINGP (it
->string
));
6892 xassert (!it
->bidi_p
|| it
->string
== it
->bidi_it
.string
.lstring
);
6893 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6894 position
= it
->current
.string_pos
;
6896 /* With bidi reordering, the character to display might not be the
6897 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
6898 that we were reseat()ed to a new string, whose paragraph
6899 direction is not known. */
6900 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6902 get_visually_first_element (it
);
6903 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
6906 /* Time to check for invisible text? */
6907 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
6909 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
6912 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6913 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
6915 /* With bidi non-linear iteration, we could find
6916 ourselves far beyond the last computed stop_charpos,
6917 with several other stop positions in between that we
6918 missed. Scan them all now, in buffer's logical
6919 order, until we find and handle the last stop_charpos
6920 that precedes our current position. */
6921 handle_stop_backwards (it
, it
->stop_charpos
);
6922 return GET_NEXT_DISPLAY_ELEMENT (it
);
6928 /* Take note of the stop position we just moved
6929 across, for when we will move back across it. */
6930 it
->prev_stop
= it
->stop_charpos
;
6931 /* If we are at base paragraph embedding level, take
6932 note of the last stop position seen at this
6934 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6935 it
->base_level_stop
= it
->stop_charpos
;
6939 /* Since a handler may have changed IT->method, we must
6941 return GET_NEXT_DISPLAY_ELEMENT (it
);
6945 /* If we are before prev_stop, we may have overstepped
6946 on our way backwards a stop_pos, and if so, we need
6947 to handle that stop_pos. */
6948 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
6949 /* We can sometimes back up for reasons that have nothing
6950 to do with bidi reordering. E.g., compositions. The
6951 code below is only needed when we are above the base
6952 embedding level, so test for that explicitly. */
6953 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6955 /* If we lost track of base_level_stop, we have no better place
6956 for handle_stop_backwards to start from than BEGV. This
6957 happens, e.g., when we were reseated to the previous
6958 screenful of text by vertical-motion. */
6959 if (it
->base_level_stop
<= 0
6960 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
6961 it
->base_level_stop
= 0;
6962 handle_stop_backwards (it
, it
->base_level_stop
);
6963 return GET_NEXT_DISPLAY_ELEMENT (it
);
6967 if (it
->current
.overlay_string_index
>= 0)
6969 /* Get the next character from an overlay string. In overlay
6970 strings, There is no field width or padding with spaces to
6972 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6977 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6978 IT_STRING_BYTEPOS (*it
),
6979 it
->bidi_it
.scan_dir
< 0
6981 : SCHARS (it
->string
))
6982 && next_element_from_composition (it
))
6986 else if (STRING_MULTIBYTE (it
->string
))
6988 const unsigned char *s
= (SDATA (it
->string
)
6989 + IT_STRING_BYTEPOS (*it
));
6990 it
->c
= string_char_and_length (s
, &it
->len
);
6994 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7000 /* Get the next character from a Lisp string that is not an
7001 overlay string. Such strings come from the mode line, for
7002 example. We may have to pad with spaces, or truncate the
7003 string. See also next_element_from_c_string. */
7004 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7009 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7011 /* Pad with spaces. */
7012 it
->c
= ' ', it
->len
= 1;
7013 CHARPOS (position
) = BYTEPOS (position
) = -1;
7015 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7016 IT_STRING_BYTEPOS (*it
),
7017 it
->bidi_it
.scan_dir
< 0
7019 : it
->string_nchars
)
7020 && next_element_from_composition (it
))
7024 else if (STRING_MULTIBYTE (it
->string
))
7026 const unsigned char *s
= (SDATA (it
->string
)
7027 + IT_STRING_BYTEPOS (*it
));
7028 it
->c
= string_char_and_length (s
, &it
->len
);
7032 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7037 /* Record what we have and where it came from. */
7038 it
->what
= IT_CHARACTER
;
7039 it
->object
= it
->string
;
7040 it
->position
= position
;
7045 /* Load IT with next display element from C string IT->s.
7046 IT->string_nchars is the maximum number of characters to return
7047 from the string. IT->end_charpos may be greater than
7048 IT->string_nchars when this function is called, in which case we
7049 may have to return padding spaces. Value is zero if end of string
7050 reached, including padding spaces. */
7053 next_element_from_c_string (struct it
*it
)
7058 xassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7059 it
->what
= IT_CHARACTER
;
7060 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7063 /* With bidi reordering, the character to display might not be the
7064 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7065 we were reseated to a new string, whose paragraph direction is
7067 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7068 get_visually_first_element (it
);
7070 /* IT's position can be greater than IT->string_nchars in case a
7071 field width or precision has been specified when the iterator was
7073 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7075 /* End of the game. */
7079 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7081 /* Pad with spaces. */
7082 it
->c
= ' ', it
->len
= 1;
7083 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7085 else if (it
->multibyte_p
)
7086 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7088 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7094 /* Set up IT to return characters from an ellipsis, if appropriate.
7095 The definition of the ellipsis glyphs may come from a display table
7096 entry. This function fills IT with the first glyph from the
7097 ellipsis if an ellipsis is to be displayed. */
7100 next_element_from_ellipsis (struct it
*it
)
7102 if (it
->selective_display_ellipsis_p
)
7103 setup_for_ellipsis (it
, it
->len
);
7106 /* The face at the current position may be different from the
7107 face we find after the invisible text. Remember what it
7108 was in IT->saved_face_id, and signal that it's there by
7109 setting face_before_selective_p. */
7110 it
->saved_face_id
= it
->face_id
;
7111 it
->method
= GET_FROM_BUFFER
;
7112 it
->object
= it
->w
->buffer
;
7113 reseat_at_next_visible_line_start (it
, 1);
7114 it
->face_before_selective_p
= 1;
7117 return GET_NEXT_DISPLAY_ELEMENT (it
);
7121 /* Deliver an image display element. The iterator IT is already
7122 filled with image information (done in handle_display_prop). Value
7127 next_element_from_image (struct it
*it
)
7129 it
->what
= IT_IMAGE
;
7130 it
->ignore_overlay_strings_at_pos_p
= 0;
7135 /* Fill iterator IT with next display element from a stretch glyph
7136 property. IT->object is the value of the text property. Value is
7140 next_element_from_stretch (struct it
*it
)
7142 it
->what
= IT_STRETCH
;
7146 /* Scan forward from CHARPOS in the current buffer/string, until we
7147 find a stop position > current IT's position. Then handle the stop
7148 position before that. This is called when we bump into a stop
7149 position while reordering bidirectional text. CHARPOS should be
7150 the last previously processed stop_pos (or BEGV/0, if none were
7151 processed yet) whose position is less that IT's current
7155 handle_stop_backwards (struct it
*it
, EMACS_INT charpos
)
7157 int bufp
= !STRINGP (it
->string
);
7158 EMACS_INT where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7159 struct display_pos save_current
= it
->current
;
7160 struct text_pos save_position
= it
->position
;
7161 struct text_pos pos1
;
7162 EMACS_INT next_stop
;
7164 /* Scan in strict logical order. */
7168 it
->prev_stop
= charpos
;
7171 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7172 reseat_1 (it
, pos1
, 0);
7175 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7176 compute_stop_pos (it
);
7177 /* We must advance forward, right? */
7178 if (it
->stop_charpos
<= it
->prev_stop
)
7180 charpos
= it
->stop_charpos
;
7182 while (charpos
<= where_we_are
);
7184 next_stop
= it
->stop_charpos
;
7185 it
->stop_charpos
= it
->prev_stop
;
7187 it
->current
= save_current
;
7188 it
->position
= save_position
;
7190 it
->stop_charpos
= next_stop
;
7193 /* Load IT with the next display element from current_buffer. Value
7194 is zero if end of buffer reached. IT->stop_charpos is the next
7195 position at which to stop and check for text properties or buffer
7199 next_element_from_buffer (struct it
*it
)
7203 xassert (IT_CHARPOS (*it
) >= BEGV
);
7204 xassert (NILP (it
->string
) && !it
->s
);
7205 xassert (!it
->bidi_p
7206 || (it
->bidi_it
.string
.lstring
== Qnil
7207 && it
->bidi_it
.string
.s
== NULL
));
7209 /* With bidi reordering, the character to display might not be the
7210 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7211 we were reseat()ed to a new buffer position, which is potentially
7212 a different paragraph. */
7213 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7215 get_visually_first_element (it
);
7216 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7219 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7221 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7223 int overlay_strings_follow_p
;
7225 /* End of the game, except when overlay strings follow that
7226 haven't been returned yet. */
7227 if (it
->overlay_strings_at_end_processed_p
)
7228 overlay_strings_follow_p
= 0;
7231 it
->overlay_strings_at_end_processed_p
= 1;
7232 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7235 if (overlay_strings_follow_p
)
7236 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7240 it
->position
= it
->current
.pos
;
7244 else if (!(!it
->bidi_p
7245 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7246 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7248 /* With bidi non-linear iteration, we could find ourselves
7249 far beyond the last computed stop_charpos, with several
7250 other stop positions in between that we missed. Scan
7251 them all now, in buffer's logical order, until we find
7252 and handle the last stop_charpos that precedes our
7253 current position. */
7254 handle_stop_backwards (it
, it
->stop_charpos
);
7255 return GET_NEXT_DISPLAY_ELEMENT (it
);
7261 /* Take note of the stop position we just moved across,
7262 for when we will move back across it. */
7263 it
->prev_stop
= it
->stop_charpos
;
7264 /* If we are at base paragraph embedding level, take
7265 note of the last stop position seen at this
7267 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7268 it
->base_level_stop
= it
->stop_charpos
;
7271 return GET_NEXT_DISPLAY_ELEMENT (it
);
7275 /* If we are before prev_stop, we may have overstepped on
7276 our way backwards a stop_pos, and if so, we need to
7277 handle that stop_pos. */
7278 && IT_CHARPOS (*it
) < it
->prev_stop
7279 /* We can sometimes back up for reasons that have nothing
7280 to do with bidi reordering. E.g., compositions. The
7281 code below is only needed when we are above the base
7282 embedding level, so test for that explicitly. */
7283 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7285 /* If we lost track of base_level_stop, we have no better place
7286 for handle_stop_backwards to start from than BEGV. This
7287 happens, e.g., when we were reseated to the previous
7288 screenful of text by vertical-motion. */
7289 if (it
->base_level_stop
<= 0
7290 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7291 it
->base_level_stop
= BEGV
;
7292 handle_stop_backwards (it
, it
->base_level_stop
);
7293 return GET_NEXT_DISPLAY_ELEMENT (it
);
7297 /* No face changes, overlays etc. in sight, so just return a
7298 character from current_buffer. */
7302 /* Maybe run the redisplay end trigger hook. Performance note:
7303 This doesn't seem to cost measurable time. */
7304 if (it
->redisplay_end_trigger_charpos
7306 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7307 run_redisplay_end_trigger_hook (it
);
7309 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7310 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7312 && next_element_from_composition (it
))
7317 /* Get the next character, maybe multibyte. */
7318 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7319 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7320 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7322 it
->c
= *p
, it
->len
= 1;
7324 /* Record what we have and where it came from. */
7325 it
->what
= IT_CHARACTER
;
7326 it
->object
= it
->w
->buffer
;
7327 it
->position
= it
->current
.pos
;
7329 /* Normally we return the character found above, except when we
7330 really want to return an ellipsis for selective display. */
7335 /* A value of selective > 0 means hide lines indented more
7336 than that number of columns. */
7337 if (it
->selective
> 0
7338 && IT_CHARPOS (*it
) + 1 < ZV
7339 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7340 IT_BYTEPOS (*it
) + 1,
7341 (double) it
->selective
)) /* iftc */
7343 success_p
= next_element_from_ellipsis (it
);
7344 it
->dpvec_char_len
= -1;
7347 else if (it
->c
== '\r' && it
->selective
== -1)
7349 /* A value of selective == -1 means that everything from the
7350 CR to the end of the line is invisible, with maybe an
7351 ellipsis displayed for it. */
7352 success_p
= next_element_from_ellipsis (it
);
7353 it
->dpvec_char_len
= -1;
7358 /* Value is zero if end of buffer reached. */
7359 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7364 /* Run the redisplay end trigger hook for IT. */
7367 run_redisplay_end_trigger_hook (struct it
*it
)
7369 Lisp_Object args
[3];
7371 /* IT->glyph_row should be non-null, i.e. we should be actually
7372 displaying something, or otherwise we should not run the hook. */
7373 xassert (it
->glyph_row
);
7375 /* Set up hook arguments. */
7376 args
[0] = Qredisplay_end_trigger_functions
;
7377 args
[1] = it
->window
;
7378 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7379 it
->redisplay_end_trigger_charpos
= 0;
7381 /* Since we are *trying* to run these functions, don't try to run
7382 them again, even if they get an error. */
7383 it
->w
->redisplay_end_trigger
= Qnil
;
7384 Frun_hook_with_args (3, args
);
7386 /* Notice if it changed the face of the character we are on. */
7387 handle_face_prop (it
);
7391 /* Deliver a composition display element. Unlike the other
7392 next_element_from_XXX, this function is not registered in the array
7393 get_next_element[]. It is called from next_element_from_buffer and
7394 next_element_from_string when necessary. */
7397 next_element_from_composition (struct it
*it
)
7399 it
->what
= IT_COMPOSITION
;
7400 it
->len
= it
->cmp_it
.nbytes
;
7401 if (STRINGP (it
->string
))
7405 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7406 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7409 it
->position
= it
->current
.string_pos
;
7410 it
->object
= it
->string
;
7411 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
7412 IT_STRING_BYTEPOS (*it
), it
->string
);
7418 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7419 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7422 if (it
->bidi_it
.new_paragraph
)
7423 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7424 /* Resync the bidi iterator with IT's new position.
7425 FIXME: this doesn't support bidirectional text. */
7426 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
7427 bidi_move_to_visually_next (&it
->bidi_it
);
7431 it
->position
= it
->current
.pos
;
7432 it
->object
= it
->w
->buffer
;
7433 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
7434 IT_BYTEPOS (*it
), Qnil
);
7441 /***********************************************************************
7442 Moving an iterator without producing glyphs
7443 ***********************************************************************/
7445 /* Check if iterator is at a position corresponding to a valid buffer
7446 position after some move_it_ call. */
7448 #define IT_POS_VALID_AFTER_MOVE_P(it) \
7449 ((it)->method == GET_FROM_STRING \
7450 ? IT_STRING_CHARPOS (*it) == 0 \
7454 /* Move iterator IT to a specified buffer or X position within one
7455 line on the display without producing glyphs.
7457 OP should be a bit mask including some or all of these bits:
7458 MOVE_TO_X: Stop upon reaching x-position TO_X.
7459 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
7460 Regardless of OP's value, stop upon reaching the end of the display line.
7462 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
7463 This means, in particular, that TO_X includes window's horizontal
7466 The return value has several possible values that
7467 say what condition caused the scan to stop:
7469 MOVE_POS_MATCH_OR_ZV
7470 - when TO_POS or ZV was reached.
7473 -when TO_X was reached before TO_POS or ZV were reached.
7476 - when we reached the end of the display area and the line must
7480 - when we reached the end of the display area and the line is
7484 - when we stopped at a line end, i.e. a newline or a CR and selective
7487 static enum move_it_result
7488 move_it_in_display_line_to (struct it
*it
,
7489 EMACS_INT to_charpos
, int to_x
,
7490 enum move_operation_enum op
)
7492 enum move_it_result result
= MOVE_UNDEFINED
;
7493 struct glyph_row
*saved_glyph_row
;
7494 struct it wrap_it
, atpos_it
, atx_it
;
7496 enum it_method prev_method
= it
->method
;
7497 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
7499 /* Don't produce glyphs in produce_glyphs. */
7500 saved_glyph_row
= it
->glyph_row
;
7501 it
->glyph_row
= NULL
;
7503 /* Use wrap_it to save a copy of IT wherever a word wrap could
7504 occur. Use atpos_it to save a copy of IT at the desired buffer
7505 position, if found, so that we can scan ahead and check if the
7506 word later overshoots the window edge. Use atx_it similarly, for
7512 #define BUFFER_POS_REACHED_P() \
7513 ((op & MOVE_TO_POS) != 0 \
7514 && BUFFERP (it->object) \
7515 && (IT_CHARPOS (*it) == to_charpos \
7516 || (!it->bidi_p && IT_CHARPOS (*it) > to_charpos)) \
7517 && (it->method == GET_FROM_BUFFER \
7518 || (it->method == GET_FROM_DISPLAY_VECTOR \
7519 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
7521 /* If there's a line-/wrap-prefix, handle it. */
7522 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
7523 && it
->current_y
< it
->last_visible_y
)
7524 handle_line_prefix (it
);
7526 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7527 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7531 int x
, i
, ascent
= 0, descent
= 0;
7533 /* Utility macro to reset an iterator with x, ascent, and descent. */
7534 #define IT_RESET_X_ASCENT_DESCENT(IT) \
7535 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
7536 (IT)->max_descent = descent)
7538 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
7540 if ((op
& MOVE_TO_POS
) != 0
7541 && BUFFERP (it
->object
)
7542 && it
->method
== GET_FROM_BUFFER
7543 && ((!it
->bidi_p
&& IT_CHARPOS (*it
) > to_charpos
)
7545 && (prev_method
== GET_FROM_IMAGE
7546 || prev_method
== GET_FROM_STRETCH
)
7547 /* Passed TO_CHARPOS from left to right. */
7548 && ((prev_pos
< to_charpos
7549 && IT_CHARPOS (*it
) > to_charpos
)
7550 /* Passed TO_CHARPOS from right to left. */
7551 || (prev_pos
> to_charpos
7552 && IT_CHARPOS (*it
) < to_charpos
)))))
7554 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7556 result
= MOVE_POS_MATCH_OR_ZV
;
7559 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7560 /* If wrap_it is valid, the current position might be in a
7561 word that is wrapped. So, save the iterator in
7562 atpos_it and continue to see if wrapping happens. */
7566 prev_method
= it
->method
;
7567 if (it
->method
== GET_FROM_BUFFER
)
7568 prev_pos
= IT_CHARPOS (*it
);
7569 /* Stop when ZV reached.
7570 We used to stop here when TO_CHARPOS reached as well, but that is
7571 too soon if this glyph does not fit on this line. So we handle it
7572 explicitly below. */
7573 if (!get_next_display_element (it
))
7575 result
= MOVE_POS_MATCH_OR_ZV
;
7579 if (it
->line_wrap
== TRUNCATE
)
7581 if (BUFFER_POS_REACHED_P ())
7583 result
= MOVE_POS_MATCH_OR_ZV
;
7589 if (it
->line_wrap
== WORD_WRAP
)
7591 if (IT_DISPLAYING_WHITESPACE (it
))
7595 /* We have reached a glyph that follows one or more
7596 whitespace characters. If the position is
7597 already found, we are done. */
7598 if (atpos_it
.sp
>= 0)
7601 result
= MOVE_POS_MATCH_OR_ZV
;
7607 result
= MOVE_X_REACHED
;
7610 /* Otherwise, we can wrap here. */
7617 /* Remember the line height for the current line, in case
7618 the next element doesn't fit on the line. */
7619 ascent
= it
->max_ascent
;
7620 descent
= it
->max_descent
;
7622 /* The call to produce_glyphs will get the metrics of the
7623 display element IT is loaded with. Record the x-position
7624 before this display element, in case it doesn't fit on the
7628 PRODUCE_GLYPHS (it
);
7630 if (it
->area
!= TEXT_AREA
)
7632 set_iterator_to_next (it
, 1);
7633 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7634 SET_TEXT_POS (this_line_min_pos
,
7635 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7639 /* The number of glyphs we get back in IT->nglyphs will normally
7640 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7641 character on a terminal frame, or (iii) a line end. For the
7642 second case, IT->nglyphs - 1 padding glyphs will be present.
7643 (On X frames, there is only one glyph produced for a
7644 composite character.)
7646 The behavior implemented below means, for continuation lines,
7647 that as many spaces of a TAB as fit on the current line are
7648 displayed there. For terminal frames, as many glyphs of a
7649 multi-glyph character are displayed in the current line, too.
7650 This is what the old redisplay code did, and we keep it that
7651 way. Under X, the whole shape of a complex character must
7652 fit on the line or it will be completely displayed in the
7655 Note that both for tabs and padding glyphs, all glyphs have
7659 /* More than one glyph or glyph doesn't fit on line. All
7660 glyphs have the same width. */
7661 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7663 int x_before_this_char
= x
;
7664 int hpos_before_this_char
= it
->hpos
;
7666 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7668 new_x
= x
+ single_glyph_width
;
7670 /* We want to leave anything reaching TO_X to the caller. */
7671 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7673 if (BUFFER_POS_REACHED_P ())
7675 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7676 goto buffer_pos_reached
;
7677 if (atpos_it
.sp
< 0)
7680 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7685 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7688 result
= MOVE_X_REACHED
;
7694 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7699 if (/* Lines are continued. */
7700 it
->line_wrap
!= TRUNCATE
7701 && (/* And glyph doesn't fit on the line. */
7702 new_x
> it
->last_visible_x
7703 /* Or it fits exactly and we're on a window
7705 || (new_x
== it
->last_visible_x
7706 && FRAME_WINDOW_P (it
->f
))))
7708 if (/* IT->hpos == 0 means the very first glyph
7709 doesn't fit on the line, e.g. a wide image. */
7711 || (new_x
== it
->last_visible_x
7712 && FRAME_WINDOW_P (it
->f
)))
7715 it
->current_x
= new_x
;
7717 /* The character's last glyph just barely fits
7719 if (i
== it
->nglyphs
- 1)
7721 /* If this is the destination position,
7722 return a position *before* it in this row,
7723 now that we know it fits in this row. */
7724 if (BUFFER_POS_REACHED_P ())
7726 if (it
->line_wrap
!= WORD_WRAP
7729 it
->hpos
= hpos_before_this_char
;
7730 it
->current_x
= x_before_this_char
;
7731 result
= MOVE_POS_MATCH_OR_ZV
;
7734 if (it
->line_wrap
== WORD_WRAP
7738 atpos_it
.current_x
= x_before_this_char
;
7739 atpos_it
.hpos
= hpos_before_this_char
;
7743 set_iterator_to_next (it
, 1);
7744 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7745 SET_TEXT_POS (this_line_min_pos
,
7746 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7747 /* On graphical terminals, newlines may
7748 "overflow" into the fringe if
7749 overflow-newline-into-fringe is non-nil.
7750 On text-only terminals, newlines may
7751 overflow into the last glyph on the
7753 if (!FRAME_WINDOW_P (it
->f
)
7754 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7756 if (!get_next_display_element (it
))
7758 result
= MOVE_POS_MATCH_OR_ZV
;
7761 if (BUFFER_POS_REACHED_P ())
7763 if (ITERATOR_AT_END_OF_LINE_P (it
))
7764 result
= MOVE_POS_MATCH_OR_ZV
;
7766 result
= MOVE_LINE_CONTINUED
;
7769 if (ITERATOR_AT_END_OF_LINE_P (it
))
7771 result
= MOVE_NEWLINE_OR_CR
;
7778 IT_RESET_X_ASCENT_DESCENT (it
);
7780 if (wrap_it
.sp
>= 0)
7787 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7789 result
= MOVE_LINE_CONTINUED
;
7793 if (BUFFER_POS_REACHED_P ())
7795 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7796 goto buffer_pos_reached
;
7797 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7800 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7804 if (new_x
> it
->first_visible_x
)
7806 /* Glyph is visible. Increment number of glyphs that
7807 would be displayed. */
7812 if (result
!= MOVE_UNDEFINED
)
7815 else if (BUFFER_POS_REACHED_P ())
7818 IT_RESET_X_ASCENT_DESCENT (it
);
7819 result
= MOVE_POS_MATCH_OR_ZV
;
7822 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7824 /* Stop when TO_X specified and reached. This check is
7825 necessary here because of lines consisting of a line end,
7826 only. The line end will not produce any glyphs and we
7827 would never get MOVE_X_REACHED. */
7828 xassert (it
->nglyphs
== 0);
7829 result
= MOVE_X_REACHED
;
7833 /* Is this a line end? If yes, we're done. */
7834 if (ITERATOR_AT_END_OF_LINE_P (it
))
7836 result
= MOVE_NEWLINE_OR_CR
;
7840 if (it
->method
== GET_FROM_BUFFER
)
7841 prev_pos
= IT_CHARPOS (*it
);
7842 /* The current display element has been consumed. Advance
7844 set_iterator_to_next (it
, 1);
7845 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7846 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7848 /* Stop if lines are truncated and IT's current x-position is
7849 past the right edge of the window now. */
7850 if (it
->line_wrap
== TRUNCATE
7851 && it
->current_x
>= it
->last_visible_x
)
7853 if (!FRAME_WINDOW_P (it
->f
)
7854 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7856 if (!get_next_display_element (it
)
7857 || BUFFER_POS_REACHED_P ())
7859 result
= MOVE_POS_MATCH_OR_ZV
;
7862 if (ITERATOR_AT_END_OF_LINE_P (it
))
7864 result
= MOVE_NEWLINE_OR_CR
;
7868 result
= MOVE_LINE_TRUNCATED
;
7871 #undef IT_RESET_X_ASCENT_DESCENT
7874 #undef BUFFER_POS_REACHED_P
7876 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7877 restore the saved iterator. */
7878 if (atpos_it
.sp
>= 0)
7880 else if (atx_it
.sp
>= 0)
7885 /* Restore the iterator settings altered at the beginning of this
7887 it
->glyph_row
= saved_glyph_row
;
7891 /* For external use. */
7893 move_it_in_display_line (struct it
*it
,
7894 EMACS_INT to_charpos
, int to_x
,
7895 enum move_operation_enum op
)
7897 if (it
->line_wrap
== WORD_WRAP
7898 && (op
& MOVE_TO_X
))
7900 struct it save_it
= *it
;
7901 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7902 /* When word-wrap is on, TO_X may lie past the end
7903 of a wrapped line. Then it->current is the
7904 character on the next line, so backtrack to the
7905 space before the wrap point. */
7906 if (skip
== MOVE_LINE_CONTINUED
)
7908 int prev_x
= max (it
->current_x
- 1, 0);
7910 move_it_in_display_line_to
7911 (it
, -1, prev_x
, MOVE_TO_X
);
7915 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7919 /* Move IT forward until it satisfies one or more of the criteria in
7920 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7922 OP is a bit-mask that specifies where to stop, and in particular,
7923 which of those four position arguments makes a difference. See the
7924 description of enum move_operation_enum.
7926 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7927 screen line, this function will set IT to the next position >
7931 move_it_to (struct it
*it
, EMACS_INT to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
7933 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7934 int line_height
, line_start_x
= 0, reached
= 0;
7938 if (op
& MOVE_TO_VPOS
)
7940 /* If no TO_CHARPOS and no TO_X specified, stop at the
7941 start of the line TO_VPOS. */
7942 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7944 if (it
->vpos
== to_vpos
)
7950 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7954 /* TO_VPOS >= 0 means stop at TO_X in the line at
7955 TO_VPOS, or at TO_POS, whichever comes first. */
7956 if (it
->vpos
== to_vpos
)
7962 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7964 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7969 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7971 /* We have reached TO_X but not in the line we want. */
7972 skip
= move_it_in_display_line_to (it
, to_charpos
,
7974 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7982 else if (op
& MOVE_TO_Y
)
7984 struct it it_backup
;
7986 if (it
->line_wrap
== WORD_WRAP
)
7989 /* TO_Y specified means stop at TO_X in the line containing
7990 TO_Y---or at TO_CHARPOS if this is reached first. The
7991 problem is that we can't really tell whether the line
7992 contains TO_Y before we have completely scanned it, and
7993 this may skip past TO_X. What we do is to first scan to
7996 If TO_X is not specified, use a TO_X of zero. The reason
7997 is to make the outcome of this function more predictable.
7998 If we didn't use TO_X == 0, we would stop at the end of
7999 the line which is probably not what a caller would expect
8001 skip
= move_it_in_display_line_to
8002 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8003 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8005 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8006 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8008 else if (skip
== MOVE_X_REACHED
)
8010 /* If TO_X was reached, we want to know whether TO_Y is
8011 in the line. We know this is the case if the already
8012 scanned glyphs make the line tall enough. Otherwise,
8013 we must check by scanning the rest of the line. */
8014 line_height
= it
->max_ascent
+ it
->max_descent
;
8015 if (to_y
>= it
->current_y
8016 && to_y
< it
->current_y
+ line_height
)
8022 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8023 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8025 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8026 line_height
= it
->max_ascent
+ it
->max_descent
;
8027 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8029 if (to_y
>= it
->current_y
8030 && to_y
< it
->current_y
+ line_height
)
8032 /* If TO_Y is in this line and TO_X was reached
8033 above, we scanned too far. We have to restore
8034 IT's settings to the ones before skipping. */
8041 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8047 /* Check whether TO_Y is in this line. */
8048 line_height
= it
->max_ascent
+ it
->max_descent
;
8049 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8051 if (to_y
>= it
->current_y
8052 && to_y
< it
->current_y
+ line_height
)
8054 /* When word-wrap is on, TO_X may lie past the end
8055 of a wrapped line. Then it->current is the
8056 character on the next line, so backtrack to the
8057 space before the wrap point. */
8058 if (skip
== MOVE_LINE_CONTINUED
8059 && it
->line_wrap
== WORD_WRAP
)
8061 int prev_x
= max (it
->current_x
- 1, 0);
8063 skip
= move_it_in_display_line_to
8064 (it
, -1, prev_x
, MOVE_TO_X
);
8073 else if (BUFFERP (it
->object
)
8074 && (it
->method
== GET_FROM_BUFFER
8075 || it
->method
== GET_FROM_STRETCH
)
8076 && IT_CHARPOS (*it
) >= to_charpos
)
8077 skip
= MOVE_POS_MATCH_OR_ZV
;
8079 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8083 case MOVE_POS_MATCH_OR_ZV
:
8087 case MOVE_NEWLINE_OR_CR
:
8088 set_iterator_to_next (it
, 1);
8089 it
->continuation_lines_width
= 0;
8092 case MOVE_LINE_TRUNCATED
:
8093 it
->continuation_lines_width
= 0;
8094 reseat_at_next_visible_line_start (it
, 0);
8095 if ((op
& MOVE_TO_POS
) != 0
8096 && IT_CHARPOS (*it
) > to_charpos
)
8103 case MOVE_LINE_CONTINUED
:
8104 /* For continued lines ending in a tab, some of the glyphs
8105 associated with the tab are displayed on the current
8106 line. Since it->current_x does not include these glyphs,
8107 we use it->last_visible_x instead. */
8110 it
->continuation_lines_width
+= it
->last_visible_x
;
8111 /* When moving by vpos, ensure that the iterator really
8112 advances to the next line (bug#847, bug#969). Fixme:
8113 do we need to do this in other circumstances? */
8114 if (it
->current_x
!= it
->last_visible_x
8115 && (op
& MOVE_TO_VPOS
)
8116 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8118 line_start_x
= it
->current_x
+ it
->pixel_width
8119 - it
->last_visible_x
;
8120 set_iterator_to_next (it
, 0);
8124 it
->continuation_lines_width
+= it
->current_x
;
8131 /* Reset/increment for the next run. */
8132 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8133 it
->current_x
= line_start_x
;
8136 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8138 last_height
= it
->max_ascent
+ it
->max_descent
;
8139 last_max_ascent
= it
->max_ascent
;
8140 it
->max_ascent
= it
->max_descent
= 0;
8145 /* On text terminals, we may stop at the end of a line in the middle
8146 of a multi-character glyph. If the glyph itself is continued,
8147 i.e. it is actually displayed on the next line, don't treat this
8148 stopping point as valid; move to the next line instead (unless
8149 that brings us offscreen). */
8150 if (!FRAME_WINDOW_P (it
->f
)
8152 && IT_CHARPOS (*it
) == to_charpos
8153 && it
->what
== IT_CHARACTER
8155 && it
->line_wrap
== WINDOW_WRAP
8156 && it
->current_x
== it
->last_visible_x
- 1
8159 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8161 it
->continuation_lines_width
+= it
->current_x
;
8162 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8163 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8165 last_height
= it
->max_ascent
+ it
->max_descent
;
8166 last_max_ascent
= it
->max_ascent
;
8169 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8173 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8175 If DY > 0, move IT backward at least that many pixels. DY = 0
8176 means move IT backward to the preceding line start or BEGV. This
8177 function may move over more than DY pixels if IT->current_y - DY
8178 ends up in the middle of a line; in this case IT->current_y will be
8179 set to the top of the line moved to. */
8182 move_it_vertically_backward (struct it
*it
, int dy
)
8186 EMACS_INT start_pos
;
8191 start_pos
= IT_CHARPOS (*it
);
8193 /* Estimate how many newlines we must move back. */
8194 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8196 /* Set the iterator's position that many lines back. */
8197 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8198 back_to_previous_visible_line_start (it
);
8200 /* Reseat the iterator here. When moving backward, we don't want
8201 reseat to skip forward over invisible text, set up the iterator
8202 to deliver from overlay strings at the new position etc. So,
8203 use reseat_1 here. */
8204 reseat_1 (it
, it
->current
.pos
, 1);
8206 /* We are now surely at a line start. */
8207 it
->current_x
= it
->hpos
= 0;
8208 it
->continuation_lines_width
= 0;
8210 /* Move forward and see what y-distance we moved. First move to the
8211 start of the next line so that we get its height. We need this
8212 height to be able to tell whether we reached the specified
8215 it2
.max_ascent
= it2
.max_descent
= 0;
8218 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8219 MOVE_TO_POS
| MOVE_TO_VPOS
);
8221 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
8222 xassert (IT_CHARPOS (*it
) >= BEGV
);
8225 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8226 xassert (IT_CHARPOS (*it
) >= BEGV
);
8227 /* H is the actual vertical distance from the position in *IT
8228 and the starting position. */
8229 h
= it2
.current_y
- it
->current_y
;
8230 /* NLINES is the distance in number of lines. */
8231 nlines
= it2
.vpos
- it
->vpos
;
8233 /* Correct IT's y and vpos position
8234 so that they are relative to the starting point. */
8240 /* DY == 0 means move to the start of the screen line. The
8241 value of nlines is > 0 if continuation lines were involved. */
8243 move_it_by_lines (it
, nlines
);
8247 /* The y-position we try to reach, relative to *IT.
8248 Note that H has been subtracted in front of the if-statement. */
8249 int target_y
= it
->current_y
+ h
- dy
;
8250 int y0
= it3
.current_y
;
8251 int y1
= line_bottom_y (&it3
);
8252 int line_height
= y1
- y0
;
8254 /* If we did not reach target_y, try to move further backward if
8255 we can. If we moved too far backward, try to move forward. */
8256 if (target_y
< it
->current_y
8257 /* This is heuristic. In a window that's 3 lines high, with
8258 a line height of 13 pixels each, recentering with point
8259 on the bottom line will try to move -39/2 = 19 pixels
8260 backward. Try to avoid moving into the first line. */
8261 && (it
->current_y
- target_y
8262 > min (window_box_height (it
->w
), line_height
* 2 / 3))
8263 && IT_CHARPOS (*it
) > BEGV
)
8265 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
8266 target_y
- it
->current_y
));
8267 dy
= it
->current_y
- target_y
;
8268 goto move_further_back
;
8270 else if (target_y
>= it
->current_y
+ line_height
8271 && IT_CHARPOS (*it
) < ZV
)
8273 /* Should move forward by at least one line, maybe more.
8275 Note: Calling move_it_by_lines can be expensive on
8276 terminal frames, where compute_motion is used (via
8277 vmotion) to do the job, when there are very long lines
8278 and truncate-lines is nil. That's the reason for
8279 treating terminal frames specially here. */
8281 if (!FRAME_WINDOW_P (it
->f
))
8282 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
8287 move_it_by_lines (it
, 1);
8289 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
8296 /* Move IT by a specified amount of pixel lines DY. DY negative means
8297 move backwards. DY = 0 means move to start of screen line. At the
8298 end, IT will be on the start of a screen line. */
8301 move_it_vertically (struct it
*it
, int dy
)
8304 move_it_vertically_backward (it
, -dy
);
8307 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
8308 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
8309 MOVE_TO_POS
| MOVE_TO_Y
);
8310 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
8312 /* If buffer ends in ZV without a newline, move to the start of
8313 the line to satisfy the post-condition. */
8314 if (IT_CHARPOS (*it
) == ZV
8316 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8317 move_it_by_lines (it
, 0);
8322 /* Move iterator IT past the end of the text line it is in. */
8325 move_it_past_eol (struct it
*it
)
8327 enum move_it_result rc
;
8329 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
8330 if (rc
== MOVE_NEWLINE_OR_CR
)
8331 set_iterator_to_next (it
, 0);
8335 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
8336 negative means move up. DVPOS == 0 means move to the start of the
8339 Optimization idea: If we would know that IT->f doesn't use
8340 a face with proportional font, we could be faster for
8341 truncate-lines nil. */
8344 move_it_by_lines (struct it
*it
, int dvpos
)
8347 /* The commented-out optimization uses vmotion on terminals. This
8348 gives bad results, because elements like it->what, on which
8349 callers such as pos_visible_p rely, aren't updated. */
8350 /* struct position pos;
8351 if (!FRAME_WINDOW_P (it->f))
8353 struct text_pos textpos;
8355 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
8356 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
8357 reseat (it, textpos, 1);
8358 it->vpos += pos.vpos;
8359 it->current_y += pos.vpos;
8365 /* DVPOS == 0 means move to the start of the screen line. */
8366 move_it_vertically_backward (it
, 0);
8367 xassert (it
->current_x
== 0 && it
->hpos
== 0);
8368 /* Let next call to line_bottom_y calculate real line height */
8373 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
8374 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
8375 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
8380 EMACS_INT start_charpos
, i
;
8382 /* Start at the beginning of the screen line containing IT's
8383 position. This may actually move vertically backwards,
8384 in case of overlays, so adjust dvpos accordingly. */
8386 move_it_vertically_backward (it
, 0);
8389 /* Go back -DVPOS visible lines and reseat the iterator there. */
8390 start_charpos
= IT_CHARPOS (*it
);
8391 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
8392 back_to_previous_visible_line_start (it
);
8393 reseat (it
, it
->current
.pos
, 1);
8395 /* Move further back if we end up in a string or an image. */
8396 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
8398 /* First try to move to start of display line. */
8400 move_it_vertically_backward (it
, 0);
8402 if (IT_POS_VALID_AFTER_MOVE_P (it
))
8404 /* If start of line is still in string or image,
8405 move further back. */
8406 back_to_previous_visible_line_start (it
);
8407 reseat (it
, it
->current
.pos
, 1);
8411 it
->current_x
= it
->hpos
= 0;
8413 /* Above call may have moved too far if continuation lines
8414 are involved. Scan forward and see if it did. */
8416 it2
.vpos
= it2
.current_y
= 0;
8417 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
8418 it
->vpos
-= it2
.vpos
;
8419 it
->current_y
-= it2
.current_y
;
8420 it
->current_x
= it
->hpos
= 0;
8422 /* If we moved too far back, move IT some lines forward. */
8423 if (it2
.vpos
> -dvpos
)
8425 int delta
= it2
.vpos
+ dvpos
;
8427 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
8428 /* Move back again if we got too far ahead. */
8429 if (IT_CHARPOS (*it
) >= start_charpos
)
8435 /* Return 1 if IT points into the middle of a display vector. */
8438 in_display_vector_p (struct it
*it
)
8440 return (it
->method
== GET_FROM_DISPLAY_VECTOR
8441 && it
->current
.dpvec_index
> 0
8442 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
8446 /***********************************************************************
8448 ***********************************************************************/
8451 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
8455 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
8457 Lisp_Object args
[3];
8458 Lisp_Object msg
, fmt
;
8461 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
8464 /* Do nothing if called asynchronously. Inserting text into
8465 a buffer may call after-change-functions and alike and
8466 that would means running Lisp asynchronously. */
8467 if (handling_signal
)
8471 GCPRO4 (fmt
, msg
, arg1
, arg2
);
8473 args
[0] = fmt
= build_string (format
);
8476 msg
= Fformat (3, args
);
8478 len
= SBYTES (msg
) + 1;
8479 SAFE_ALLOCA (buffer
, char *, len
);
8480 memcpy (buffer
, SDATA (msg
), len
);
8482 message_dolog (buffer
, len
- 1, 1, 0);
8489 /* Output a newline in the *Messages* buffer if "needs" one. */
8492 message_log_maybe_newline (void)
8494 if (message_log_need_newline
)
8495 message_dolog ("", 0, 1, 0);
8499 /* Add a string M of length NBYTES to the message log, optionally
8500 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
8501 nonzero, means interpret the contents of M as multibyte. This
8502 function calls low-level routines in order to bypass text property
8503 hooks, etc. which might not be safe to run.
8505 This may GC (insert may run before/after change hooks),
8506 so the buffer M must NOT point to a Lisp string. */
8509 message_dolog (const char *m
, EMACS_INT nbytes
, int nlflag
, int multibyte
)
8511 const unsigned char *msg
= (const unsigned char *) m
;
8513 if (!NILP (Vmemory_full
))
8516 if (!NILP (Vmessage_log_max
))
8518 struct buffer
*oldbuf
;
8519 Lisp_Object oldpoint
, oldbegv
, oldzv
;
8520 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
8521 EMACS_INT point_at_end
= 0;
8522 EMACS_INT zv_at_end
= 0;
8523 Lisp_Object old_deactivate_mark
, tem
;
8524 struct gcpro gcpro1
;
8526 old_deactivate_mark
= Vdeactivate_mark
;
8527 oldbuf
= current_buffer
;
8528 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
8529 BVAR (current_buffer
, undo_list
) = Qt
;
8531 oldpoint
= message_dolog_marker1
;
8532 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
8533 oldbegv
= message_dolog_marker2
;
8534 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
8535 oldzv
= message_dolog_marker3
;
8536 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
8537 GCPRO1 (old_deactivate_mark
);
8545 BEGV_BYTE
= BEG_BYTE
;
8548 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8550 /* Insert the string--maybe converting multibyte to single byte
8551 or vice versa, so that all the text fits the buffer. */
8553 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8559 /* Convert a multibyte string to single-byte
8560 for the *Message* buffer. */
8561 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
8563 c
= string_char_and_length (msg
+ i
, &char_bytes
);
8564 work
[0] = (ASCII_CHAR_P (c
)
8566 : multibyte_char_to_unibyte (c
));
8567 insert_1_both (work
, 1, 1, 1, 0, 0);
8570 else if (! multibyte
8571 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8575 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8576 /* Convert a single-byte string to multibyte
8577 for the *Message* buffer. */
8578 for (i
= 0; i
< nbytes
; i
++)
8581 MAKE_CHAR_MULTIBYTE (c
);
8582 char_bytes
= CHAR_STRING (c
, str
);
8583 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
8587 insert_1 (m
, nbytes
, 1, 0, 0);
8591 EMACS_INT this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
8592 unsigned long int dups
;
8593 insert_1 ("\n", 1, 1, 0, 0);
8595 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8597 this_bol_byte
= PT_BYTE
;
8599 /* See if this line duplicates the previous one.
8600 If so, combine duplicates. */
8603 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8605 prev_bol_byte
= PT_BYTE
;
8607 dups
= message_log_check_duplicate (prev_bol_byte
,
8611 del_range_both (prev_bol
, prev_bol_byte
,
8612 this_bol
, this_bol_byte
, 0);
8618 /* If you change this format, don't forget to also
8619 change message_log_check_duplicate. */
8620 sprintf (dupstr
, " [%lu times]", dups
);
8621 duplen
= strlen (dupstr
);
8622 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8623 insert_1 (dupstr
, duplen
, 1, 0, 1);
8628 /* If we have more than the desired maximum number of lines
8629 in the *Messages* buffer now, delete the oldest ones.
8630 This is safe because we don't have undo in this buffer. */
8632 if (NATNUMP (Vmessage_log_max
))
8634 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8635 -XFASTINT (Vmessage_log_max
) - 1, 0);
8636 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8639 BEGV
= XMARKER (oldbegv
)->charpos
;
8640 BEGV_BYTE
= marker_byte_position (oldbegv
);
8649 ZV
= XMARKER (oldzv
)->charpos
;
8650 ZV_BYTE
= marker_byte_position (oldzv
);
8654 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8656 /* We can't do Fgoto_char (oldpoint) because it will run some
8658 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8659 XMARKER (oldpoint
)->bytepos
);
8662 unchain_marker (XMARKER (oldpoint
));
8663 unchain_marker (XMARKER (oldbegv
));
8664 unchain_marker (XMARKER (oldzv
));
8666 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8667 set_buffer_internal (oldbuf
);
8669 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8670 message_log_need_newline
= !nlflag
;
8671 Vdeactivate_mark
= old_deactivate_mark
;
8676 /* We are at the end of the buffer after just having inserted a newline.
8677 (Note: We depend on the fact we won't be crossing the gap.)
8678 Check to see if the most recent message looks a lot like the previous one.
8679 Return 0 if different, 1 if the new one should just replace it, or a
8680 value N > 1 if we should also append " [N times]". */
8682 static unsigned long int
8683 message_log_check_duplicate (EMACS_INT prev_bol_byte
, EMACS_INT this_bol_byte
)
8686 EMACS_INT len
= Z_BYTE
- 1 - this_bol_byte
;
8688 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8689 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8691 for (i
= 0; i
< len
; i
++)
8693 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8701 if (*p1
++ == ' ' && *p1
++ == '[')
8704 unsigned long int n
= strtoul ((char *) p1
, &pend
, 10);
8705 if (strncmp (pend
, " times]\n", 8) == 0)
8712 /* Display an echo area message M with a specified length of NBYTES
8713 bytes. The string may include null characters. If M is 0, clear
8714 out any existing message, and let the mini-buffer text show
8717 This may GC, so the buffer M must NOT point to a Lisp string. */
8720 message2 (const char *m
, EMACS_INT nbytes
, int multibyte
)
8722 /* First flush out any partial line written with print. */
8723 message_log_maybe_newline ();
8725 message_dolog (m
, nbytes
, 1, multibyte
);
8726 message2_nolog (m
, nbytes
, multibyte
);
8730 /* The non-logging counterpart of message2. */
8733 message2_nolog (const char *m
, EMACS_INT nbytes
, int multibyte
)
8735 struct frame
*sf
= SELECTED_FRAME ();
8736 message_enable_multibyte
= multibyte
;
8738 if (FRAME_INITIAL_P (sf
))
8740 if (noninteractive_need_newline
)
8741 putc ('\n', stderr
);
8742 noninteractive_need_newline
= 0;
8744 fwrite (m
, nbytes
, 1, stderr
);
8745 if (cursor_in_echo_area
== 0)
8746 fprintf (stderr
, "\n");
8749 /* A null message buffer means that the frame hasn't really been
8750 initialized yet. Error messages get reported properly by
8751 cmd_error, so this must be just an informative message; toss it. */
8752 else if (INTERACTIVE
8753 && sf
->glyphs_initialized_p
8754 && FRAME_MESSAGE_BUF (sf
))
8756 Lisp_Object mini_window
;
8759 /* Get the frame containing the mini-buffer
8760 that the selected frame is using. */
8761 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8762 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8764 FRAME_SAMPLE_VISIBILITY (f
);
8765 if (FRAME_VISIBLE_P (sf
)
8766 && ! FRAME_VISIBLE_P (f
))
8767 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8771 set_message (m
, Qnil
, nbytes
, multibyte
);
8772 if (minibuffer_auto_raise
)
8773 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8776 clear_message (1, 1);
8778 do_pending_window_change (0);
8779 echo_area_display (1);
8780 do_pending_window_change (0);
8781 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8782 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8787 /* Display an echo area message M with a specified length of NBYTES
8788 bytes. The string may include null characters. If M is not a
8789 string, clear out any existing message, and let the mini-buffer
8792 This function cancels echoing. */
8795 message3 (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8797 struct gcpro gcpro1
;
8800 clear_message (1,1);
8803 /* First flush out any partial line written with print. */
8804 message_log_maybe_newline ();
8810 SAFE_ALLOCA (buffer
, char *, nbytes
);
8811 memcpy (buffer
, SDATA (m
), nbytes
);
8812 message_dolog (buffer
, nbytes
, 1, multibyte
);
8815 message3_nolog (m
, nbytes
, multibyte
);
8821 /* The non-logging version of message3.
8822 This does not cancel echoing, because it is used for echoing.
8823 Perhaps we need to make a separate function for echoing
8824 and make this cancel echoing. */
8827 message3_nolog (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8829 struct frame
*sf
= SELECTED_FRAME ();
8830 message_enable_multibyte
= multibyte
;
8832 if (FRAME_INITIAL_P (sf
))
8834 if (noninteractive_need_newline
)
8835 putc ('\n', stderr
);
8836 noninteractive_need_newline
= 0;
8838 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8839 if (cursor_in_echo_area
== 0)
8840 fprintf (stderr
, "\n");
8843 /* A null message buffer means that the frame hasn't really been
8844 initialized yet. Error messages get reported properly by
8845 cmd_error, so this must be just an informative message; toss it. */
8846 else if (INTERACTIVE
8847 && sf
->glyphs_initialized_p
8848 && FRAME_MESSAGE_BUF (sf
))
8850 Lisp_Object mini_window
;
8854 /* Get the frame containing the mini-buffer
8855 that the selected frame is using. */
8856 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8857 frame
= XWINDOW (mini_window
)->frame
;
8860 FRAME_SAMPLE_VISIBILITY (f
);
8861 if (FRAME_VISIBLE_P (sf
)
8862 && !FRAME_VISIBLE_P (f
))
8863 Fmake_frame_visible (frame
);
8865 if (STRINGP (m
) && SCHARS (m
) > 0)
8867 set_message (NULL
, m
, nbytes
, multibyte
);
8868 if (minibuffer_auto_raise
)
8869 Fraise_frame (frame
);
8870 /* Assume we are not echoing.
8871 (If we are, echo_now will override this.) */
8872 echo_message_buffer
= Qnil
;
8875 clear_message (1, 1);
8877 do_pending_window_change (0);
8878 echo_area_display (1);
8879 do_pending_window_change (0);
8880 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8881 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8886 /* Display a null-terminated echo area message M. If M is 0, clear
8887 out any existing message, and let the mini-buffer text show through.
8889 The buffer M must continue to exist until after the echo area gets
8890 cleared or some other message gets displayed there. Do not pass
8891 text that is stored in a Lisp string. Do not pass text in a buffer
8892 that was alloca'd. */
8895 message1 (const char *m
)
8897 message2 (m
, (m
? strlen (m
) : 0), 0);
8901 /* The non-logging counterpart of message1. */
8904 message1_nolog (const char *m
)
8906 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8909 /* Display a message M which contains a single %s
8910 which gets replaced with STRING. */
8913 message_with_string (const char *m
, Lisp_Object string
, int log
)
8915 CHECK_STRING (string
);
8921 if (noninteractive_need_newline
)
8922 putc ('\n', stderr
);
8923 noninteractive_need_newline
= 0;
8924 fprintf (stderr
, m
, SDATA (string
));
8925 if (!cursor_in_echo_area
)
8926 fprintf (stderr
, "\n");
8930 else if (INTERACTIVE
)
8932 /* The frame whose minibuffer we're going to display the message on.
8933 It may be larger than the selected frame, so we need
8934 to use its buffer, not the selected frame's buffer. */
8935 Lisp_Object mini_window
;
8936 struct frame
*f
, *sf
= SELECTED_FRAME ();
8938 /* Get the frame containing the minibuffer
8939 that the selected frame is using. */
8940 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8941 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8943 /* A null message buffer means that the frame hasn't really been
8944 initialized yet. Error messages get reported properly by
8945 cmd_error, so this must be just an informative message; toss it. */
8946 if (FRAME_MESSAGE_BUF (f
))
8948 Lisp_Object args
[2], msg
;
8949 struct gcpro gcpro1
, gcpro2
;
8951 args
[0] = build_string (m
);
8952 args
[1] = msg
= string
;
8953 GCPRO2 (args
[0], msg
);
8956 msg
= Fformat (2, args
);
8959 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8961 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8965 /* Print should start at the beginning of the message
8966 buffer next time. */
8967 message_buf_print
= 0;
8973 /* Dump an informative message to the minibuf. If M is 0, clear out
8974 any existing message, and let the mini-buffer text show through. */
8977 vmessage (const char *m
, va_list ap
)
8983 if (noninteractive_need_newline
)
8984 putc ('\n', stderr
);
8985 noninteractive_need_newline
= 0;
8986 vfprintf (stderr
, m
, ap
);
8987 if (cursor_in_echo_area
== 0)
8988 fprintf (stderr
, "\n");
8992 else if (INTERACTIVE
)
8994 /* The frame whose mini-buffer we're going to display the message
8995 on. It may be larger than the selected frame, so we need to
8996 use its buffer, not the selected frame's buffer. */
8997 Lisp_Object mini_window
;
8998 struct frame
*f
, *sf
= SELECTED_FRAME ();
9000 /* Get the frame containing the mini-buffer
9001 that the selected frame is using. */
9002 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9003 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9005 /* A null message buffer means that the frame hasn't really been
9006 initialized yet. Error messages get reported properly by
9007 cmd_error, so this must be just an informative message; toss
9009 if (FRAME_MESSAGE_BUF (f
))
9015 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9016 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9018 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
9023 /* Print should start at the beginning of the message
9024 buffer next time. */
9025 message_buf_print
= 0;
9031 message (const char *m
, ...)
9041 /* The non-logging version of message. */
9044 message_nolog (const char *m
, ...)
9046 Lisp_Object old_log_max
;
9049 old_log_max
= Vmessage_log_max
;
9050 Vmessage_log_max
= Qnil
;
9052 Vmessage_log_max
= old_log_max
;
9058 /* Display the current message in the current mini-buffer. This is
9059 only called from error handlers in process.c, and is not time
9063 update_echo_area (void)
9065 if (!NILP (echo_area_buffer
[0]))
9068 string
= Fcurrent_message ();
9069 message3 (string
, SBYTES (string
),
9070 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9075 /* Make sure echo area buffers in `echo_buffers' are live.
9076 If they aren't, make new ones. */
9079 ensure_echo_area_buffers (void)
9083 for (i
= 0; i
< 2; ++i
)
9084 if (!BUFFERP (echo_buffer
[i
])
9085 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
9088 Lisp_Object old_buffer
;
9091 old_buffer
= echo_buffer
[i
];
9092 sprintf (name
, " *Echo Area %d*", i
);
9093 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
9094 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
9095 /* to force word wrap in echo area -
9096 it was decided to postpone this*/
9097 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9099 for (j
= 0; j
< 2; ++j
)
9100 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9101 echo_area_buffer
[j
] = echo_buffer
[i
];
9106 /* Call FN with args A1..A4 with either the current or last displayed
9107 echo_area_buffer as current buffer.
9109 WHICH zero means use the current message buffer
9110 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9111 from echo_buffer[] and clear it.
9113 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9114 suitable buffer from echo_buffer[] and clear it.
9116 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9117 that the current message becomes the last displayed one, make
9118 choose a suitable buffer for echo_area_buffer[0], and clear it.
9120 Value is what FN returns. */
9123 with_echo_area_buffer (struct window
*w
, int which
,
9124 int (*fn
) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
9125 EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9128 int this_one
, the_other
, clear_buffer_p
, rc
;
9129 int count
= SPECPDL_INDEX ();
9131 /* If buffers aren't live, make new ones. */
9132 ensure_echo_area_buffers ();
9137 this_one
= 0, the_other
= 1;
9139 this_one
= 1, the_other
= 0;
9142 this_one
= 0, the_other
= 1;
9145 /* We need a fresh one in case the current echo buffer equals
9146 the one containing the last displayed echo area message. */
9147 if (!NILP (echo_area_buffer
[this_one
])
9148 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9149 echo_area_buffer
[this_one
] = Qnil
;
9152 /* Choose a suitable buffer from echo_buffer[] is we don't
9154 if (NILP (echo_area_buffer
[this_one
]))
9156 echo_area_buffer
[this_one
]
9157 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9158 ? echo_buffer
[the_other
]
9159 : echo_buffer
[this_one
]);
9163 buffer
= echo_area_buffer
[this_one
];
9165 /* Don't get confused by reusing the buffer used for echoing
9166 for a different purpose. */
9167 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9170 record_unwind_protect (unwind_with_echo_area_buffer
,
9171 with_echo_area_buffer_unwind_data (w
));
9173 /* Make the echo area buffer current. Note that for display
9174 purposes, it is not necessary that the displayed window's buffer
9175 == current_buffer, except for text property lookup. So, let's
9176 only set that buffer temporarily here without doing a full
9177 Fset_window_buffer. We must also change w->pointm, though,
9178 because otherwise an assertions in unshow_buffer fails, and Emacs
9180 set_buffer_internal_1 (XBUFFER (buffer
));
9184 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9187 BVAR (current_buffer
, undo_list
) = Qt
;
9188 BVAR (current_buffer
, read_only
) = Qnil
;
9189 specbind (Qinhibit_read_only
, Qt
);
9190 specbind (Qinhibit_modification_hooks
, Qt
);
9192 if (clear_buffer_p
&& Z
> BEG
)
9195 xassert (BEGV
>= BEG
);
9196 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9198 rc
= fn (a1
, a2
, a3
, a4
);
9200 xassert (BEGV
>= BEG
);
9201 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9203 unbind_to (count
, Qnil
);
9208 /* Save state that should be preserved around the call to the function
9209 FN called in with_echo_area_buffer. */
9212 with_echo_area_buffer_unwind_data (struct window
*w
)
9215 Lisp_Object vector
, tmp
;
9217 /* Reduce consing by keeping one vector in
9218 Vwith_echo_area_save_vector. */
9219 vector
= Vwith_echo_area_save_vector
;
9220 Vwith_echo_area_save_vector
= Qnil
;
9223 vector
= Fmake_vector (make_number (7), Qnil
);
9225 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9226 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9227 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
9231 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
9232 ASET (vector
, i
, w
->buffer
); ++i
;
9233 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
9234 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
9239 for (; i
< end
; ++i
)
9240 ASET (vector
, i
, Qnil
);
9243 xassert (i
== ASIZE (vector
));
9248 /* Restore global state from VECTOR which was created by
9249 with_echo_area_buffer_unwind_data. */
9252 unwind_with_echo_area_buffer (Lisp_Object vector
)
9254 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
9255 Vdeactivate_mark
= AREF (vector
, 1);
9256 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
9258 if (WINDOWP (AREF (vector
, 3)))
9261 Lisp_Object buffer
, charpos
, bytepos
;
9263 w
= XWINDOW (AREF (vector
, 3));
9264 buffer
= AREF (vector
, 4);
9265 charpos
= AREF (vector
, 5);
9266 bytepos
= AREF (vector
, 6);
9269 set_marker_both (w
->pointm
, buffer
,
9270 XFASTINT (charpos
), XFASTINT (bytepos
));
9273 Vwith_echo_area_save_vector
= vector
;
9278 /* Set up the echo area for use by print functions. MULTIBYTE_P
9279 non-zero means we will print multibyte. */
9282 setup_echo_area_for_printing (int multibyte_p
)
9284 /* If we can't find an echo area any more, exit. */
9285 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9288 ensure_echo_area_buffers ();
9290 if (!message_buf_print
)
9292 /* A message has been output since the last time we printed.
9293 Choose a fresh echo area buffer. */
9294 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9295 echo_area_buffer
[0] = echo_buffer
[1];
9297 echo_area_buffer
[0] = echo_buffer
[0];
9299 /* Switch to that buffer and clear it. */
9300 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9301 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9305 int count
= SPECPDL_INDEX ();
9306 specbind (Qinhibit_read_only
, Qt
);
9307 /* Note that undo recording is always disabled. */
9309 unbind_to (count
, Qnil
);
9311 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9313 /* Set up the buffer for the multibyteness we need. */
9315 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9316 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
9318 /* Raise the frame containing the echo area. */
9319 if (minibuffer_auto_raise
)
9321 struct frame
*sf
= SELECTED_FRAME ();
9322 Lisp_Object mini_window
;
9323 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9324 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9327 message_log_maybe_newline ();
9328 message_buf_print
= 1;
9332 if (NILP (echo_area_buffer
[0]))
9334 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9335 echo_area_buffer
[0] = echo_buffer
[1];
9337 echo_area_buffer
[0] = echo_buffer
[0];
9340 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
9342 /* Someone switched buffers between print requests. */
9343 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9344 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9350 /* Display an echo area message in window W. Value is non-zero if W's
9351 height is changed. If display_last_displayed_message_p is
9352 non-zero, display the message that was last displayed, otherwise
9353 display the current message. */
9356 display_echo_area (struct window
*w
)
9358 int i
, no_message_p
, window_height_changed_p
, count
;
9360 /* Temporarily disable garbage collections while displaying the echo
9361 area. This is done because a GC can print a message itself.
9362 That message would modify the echo area buffer's contents while a
9363 redisplay of the buffer is going on, and seriously confuse
9365 count
= inhibit_garbage_collection ();
9367 /* If there is no message, we must call display_echo_area_1
9368 nevertheless because it resizes the window. But we will have to
9369 reset the echo_area_buffer in question to nil at the end because
9370 with_echo_area_buffer will sets it to an empty buffer. */
9371 i
= display_last_displayed_message_p
? 1 : 0;
9372 no_message_p
= NILP (echo_area_buffer
[i
]);
9374 window_height_changed_p
9375 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
9376 display_echo_area_1
,
9377 (intptr_t) w
, Qnil
, 0, 0);
9380 echo_area_buffer
[i
] = Qnil
;
9382 unbind_to (count
, Qnil
);
9383 return window_height_changed_p
;
9387 /* Helper for display_echo_area. Display the current buffer which
9388 contains the current echo area message in window W, a mini-window,
9389 a pointer to which is passed in A1. A2..A4 are currently not used.
9390 Change the height of W so that all of the message is displayed.
9391 Value is non-zero if height of W was changed. */
9394 display_echo_area_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9397 struct window
*w
= (struct window
*) i1
;
9399 struct text_pos start
;
9400 int window_height_changed_p
= 0;
9402 /* Do this before displaying, so that we have a large enough glyph
9403 matrix for the display. If we can't get enough space for the
9404 whole text, display the last N lines. That works by setting w->start. */
9405 window_height_changed_p
= resize_mini_window (w
, 0);
9407 /* Use the starting position chosen by resize_mini_window. */
9408 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
9411 clear_glyph_matrix (w
->desired_matrix
);
9412 XSETWINDOW (window
, w
);
9413 try_window (window
, start
, 0);
9415 return window_height_changed_p
;
9419 /* Resize the echo area window to exactly the size needed for the
9420 currently displayed message, if there is one. If a mini-buffer
9421 is active, don't shrink it. */
9424 resize_echo_area_exactly (void)
9426 if (BUFFERP (echo_area_buffer
[0])
9427 && WINDOWP (echo_area_window
))
9429 struct window
*w
= XWINDOW (echo_area_window
);
9431 Lisp_Object resize_exactly
;
9433 if (minibuf_level
== 0)
9434 resize_exactly
= Qt
;
9436 resize_exactly
= Qnil
;
9438 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
9439 (intptr_t) w
, resize_exactly
,
9443 ++windows_or_buffers_changed
;
9444 ++update_mode_lines
;
9445 redisplay_internal ();
9451 /* Callback function for with_echo_area_buffer, when used from
9452 resize_echo_area_exactly. A1 contains a pointer to the window to
9453 resize, EXACTLY non-nil means resize the mini-window exactly to the
9454 size of the text displayed. A3 and A4 are not used. Value is what
9455 resize_mini_window returns. */
9458 resize_mini_window_1 (EMACS_INT a1
, Lisp_Object exactly
, EMACS_INT a3
, EMACS_INT a4
)
9461 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
9465 /* Resize mini-window W to fit the size of its contents. EXACT_P
9466 means size the window exactly to the size needed. Otherwise, it's
9467 only enlarged until W's buffer is empty.
9469 Set W->start to the right place to begin display. If the whole
9470 contents fit, start at the beginning. Otherwise, start so as
9471 to make the end of the contents appear. This is particularly
9472 important for y-or-n-p, but seems desirable generally.
9474 Value is non-zero if the window height has been changed. */
9477 resize_mini_window (struct window
*w
, int exact_p
)
9479 struct frame
*f
= XFRAME (w
->frame
);
9480 int window_height_changed_p
= 0;
9482 xassert (MINI_WINDOW_P (w
));
9484 /* By default, start display at the beginning. */
9485 set_marker_both (w
->start
, w
->buffer
,
9486 BUF_BEGV (XBUFFER (w
->buffer
)),
9487 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
9489 /* Don't resize windows while redisplaying a window; it would
9490 confuse redisplay functions when the size of the window they are
9491 displaying changes from under them. Such a resizing can happen,
9492 for instance, when which-func prints a long message while
9493 we are running fontification-functions. We're running these
9494 functions with safe_call which binds inhibit-redisplay to t. */
9495 if (!NILP (Vinhibit_redisplay
))
9498 /* Nil means don't try to resize. */
9499 if (NILP (Vresize_mini_windows
)
9500 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
9503 if (!FRAME_MINIBUF_ONLY_P (f
))
9506 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
9507 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
9508 int height
, max_height
;
9509 int unit
= FRAME_LINE_HEIGHT (f
);
9510 struct text_pos start
;
9511 struct buffer
*old_current_buffer
= NULL
;
9513 if (current_buffer
!= XBUFFER (w
->buffer
))
9515 old_current_buffer
= current_buffer
;
9516 set_buffer_internal (XBUFFER (w
->buffer
));
9519 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9521 /* Compute the max. number of lines specified by the user. */
9522 if (FLOATP (Vmax_mini_window_height
))
9523 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
9524 else if (INTEGERP (Vmax_mini_window_height
))
9525 max_height
= XINT (Vmax_mini_window_height
);
9527 max_height
= total_height
/ 4;
9529 /* Correct that max. height if it's bogus. */
9530 max_height
= max (1, max_height
);
9531 max_height
= min (total_height
, max_height
);
9533 /* Find out the height of the text in the window. */
9534 if (it
.line_wrap
== TRUNCATE
)
9539 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
9540 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
9541 height
= it
.current_y
+ last_height
;
9543 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9544 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9545 height
= (height
+ unit
- 1) / unit
;
9548 /* Compute a suitable window start. */
9549 if (height
> max_height
)
9551 height
= max_height
;
9552 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9553 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9554 start
= it
.current
.pos
;
9557 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9558 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9560 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9562 /* Let it grow only, until we display an empty message, in which
9563 case the window shrinks again. */
9564 if (height
> WINDOW_TOTAL_LINES (w
))
9566 int old_height
= WINDOW_TOTAL_LINES (w
);
9567 freeze_window_starts (f
, 1);
9568 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9569 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9571 else if (height
< WINDOW_TOTAL_LINES (w
)
9572 && (exact_p
|| BEGV
== ZV
))
9574 int old_height
= WINDOW_TOTAL_LINES (w
);
9575 freeze_window_starts (f
, 0);
9576 shrink_mini_window (w
);
9577 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9582 /* Always resize to exact size needed. */
9583 if (height
> WINDOW_TOTAL_LINES (w
))
9585 int old_height
= WINDOW_TOTAL_LINES (w
);
9586 freeze_window_starts (f
, 1);
9587 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9588 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9590 else if (height
< WINDOW_TOTAL_LINES (w
))
9592 int old_height
= WINDOW_TOTAL_LINES (w
);
9593 freeze_window_starts (f
, 0);
9594 shrink_mini_window (w
);
9598 freeze_window_starts (f
, 1);
9599 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9602 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9606 if (old_current_buffer
)
9607 set_buffer_internal (old_current_buffer
);
9610 return window_height_changed_p
;
9614 /* Value is the current message, a string, or nil if there is no
9618 current_message (void)
9622 if (!BUFFERP (echo_area_buffer
[0]))
9626 with_echo_area_buffer (0, 0, current_message_1
,
9627 (intptr_t) &msg
, Qnil
, 0, 0);
9629 echo_area_buffer
[0] = Qnil
;
9637 current_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9640 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
9643 *msg
= make_buffer_string (BEG
, Z
, 1);
9650 /* Push the current message on Vmessage_stack for later restauration
9651 by restore_message. Value is non-zero if the current message isn't
9652 empty. This is a relatively infrequent operation, so it's not
9653 worth optimizing. */
9659 msg
= current_message ();
9660 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9661 return STRINGP (msg
);
9665 /* Restore message display from the top of Vmessage_stack. */
9668 restore_message (void)
9672 xassert (CONSP (Vmessage_stack
));
9673 msg
= XCAR (Vmessage_stack
);
9675 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9677 message3_nolog (msg
, 0, 0);
9681 /* Handler for record_unwind_protect calling pop_message. */
9684 pop_message_unwind (Lisp_Object dummy
)
9690 /* Pop the top-most entry off Vmessage_stack. */
9695 xassert (CONSP (Vmessage_stack
));
9696 Vmessage_stack
= XCDR (Vmessage_stack
);
9700 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9701 exits. If the stack is not empty, we have a missing pop_message
9705 check_message_stack (void)
9707 if (!NILP (Vmessage_stack
))
9712 /* Truncate to NCHARS what will be displayed in the echo area the next
9713 time we display it---but don't redisplay it now. */
9716 truncate_echo_area (EMACS_INT nchars
)
9719 echo_area_buffer
[0] = Qnil
;
9720 /* A null message buffer means that the frame hasn't really been
9721 initialized yet. Error messages get reported properly by
9722 cmd_error, so this must be just an informative message; toss it. */
9723 else if (!noninteractive
9725 && !NILP (echo_area_buffer
[0]))
9727 struct frame
*sf
= SELECTED_FRAME ();
9728 if (FRAME_MESSAGE_BUF (sf
))
9729 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9734 /* Helper function for truncate_echo_area. Truncate the current
9735 message to at most NCHARS characters. */
9738 truncate_message_1 (EMACS_INT nchars
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9740 if (BEG
+ nchars
< Z
)
9741 del_range (BEG
+ nchars
, Z
);
9743 echo_area_buffer
[0] = Qnil
;
9748 /* Set the current message to a substring of S or STRING.
9750 If STRING is a Lisp string, set the message to the first NBYTES
9751 bytes from STRING. NBYTES zero means use the whole string. If
9752 STRING is multibyte, the message will be displayed multibyte.
9754 If S is not null, set the message to the first LEN bytes of S. LEN
9755 zero means use the whole string. MULTIBYTE_P non-zero means S is
9756 multibyte. Display the message multibyte in that case.
9758 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9759 to t before calling set_message_1 (which calls insert).
9763 set_message (const char *s
, Lisp_Object string
,
9764 EMACS_INT nbytes
, int multibyte_p
)
9766 message_enable_multibyte
9767 = ((s
&& multibyte_p
)
9768 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9770 with_echo_area_buffer (0, -1, set_message_1
,
9771 (intptr_t) s
, string
, nbytes
, multibyte_p
);
9772 message_buf_print
= 0;
9773 help_echo_showing_p
= 0;
9777 /* Helper function for set_message. Arguments have the same meaning
9778 as there, with A1 corresponding to S and A2 corresponding to STRING
9779 This function is called with the echo area buffer being
9783 set_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT nbytes
, EMACS_INT multibyte_p
)
9786 const char *s
= (const char *) i1
;
9787 const unsigned char *msg
= (const unsigned char *) s
;
9788 Lisp_Object string
= a2
;
9790 /* Change multibyteness of the echo buffer appropriately. */
9791 if (message_enable_multibyte
9792 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9793 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9795 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
9796 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
9797 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
9799 /* Insert new message at BEG. */
9800 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9802 if (STRINGP (string
))
9807 nbytes
= SBYTES (string
);
9808 nchars
= string_byte_to_char (string
, nbytes
);
9810 /* This function takes care of single/multibyte conversion. We
9811 just have to ensure that the echo area buffer has the right
9812 setting of enable_multibyte_characters. */
9813 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9818 nbytes
= strlen (s
);
9820 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9822 /* Convert from multi-byte to single-byte. */
9827 /* Convert a multibyte string to single-byte. */
9828 for (i
= 0; i
< nbytes
; i
+= n
)
9830 c
= string_char_and_length (msg
+ i
, &n
);
9831 work
[0] = (ASCII_CHAR_P (c
)
9833 : multibyte_char_to_unibyte (c
));
9834 insert_1_both (work
, 1, 1, 1, 0, 0);
9837 else if (!multibyte_p
9838 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9840 /* Convert from single-byte to multi-byte. */
9843 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9845 /* Convert a single-byte string to multibyte. */
9846 for (i
= 0; i
< nbytes
; i
++)
9849 MAKE_CHAR_MULTIBYTE (c
);
9850 n
= CHAR_STRING (c
, str
);
9851 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
9855 insert_1 (s
, nbytes
, 1, 0, 0);
9862 /* Clear messages. CURRENT_P non-zero means clear the current
9863 message. LAST_DISPLAYED_P non-zero means clear the message
9867 clear_message (int current_p
, int last_displayed_p
)
9871 echo_area_buffer
[0] = Qnil
;
9872 message_cleared_p
= 1;
9875 if (last_displayed_p
)
9876 echo_area_buffer
[1] = Qnil
;
9878 message_buf_print
= 0;
9881 /* Clear garbaged frames.
9883 This function is used where the old redisplay called
9884 redraw_garbaged_frames which in turn called redraw_frame which in
9885 turn called clear_frame. The call to clear_frame was a source of
9886 flickering. I believe a clear_frame is not necessary. It should
9887 suffice in the new redisplay to invalidate all current matrices,
9888 and ensure a complete redisplay of all windows. */
9891 clear_garbaged_frames (void)
9895 Lisp_Object tail
, frame
;
9896 int changed_count
= 0;
9898 FOR_EACH_FRAME (tail
, frame
)
9900 struct frame
*f
= XFRAME (frame
);
9902 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9906 Fredraw_frame (frame
);
9907 f
->force_flush_display_p
= 1;
9909 clear_current_matrices (f
);
9918 ++windows_or_buffers_changed
;
9923 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9924 is non-zero update selected_frame. Value is non-zero if the
9925 mini-windows height has been changed. */
9928 echo_area_display (int update_frame_p
)
9930 Lisp_Object mini_window
;
9933 int window_height_changed_p
= 0;
9934 struct frame
*sf
= SELECTED_FRAME ();
9936 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9937 w
= XWINDOW (mini_window
);
9938 f
= XFRAME (WINDOW_FRAME (w
));
9940 /* Don't display if frame is invisible or not yet initialized. */
9941 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9944 #ifdef HAVE_WINDOW_SYSTEM
9945 /* When Emacs starts, selected_frame may be the initial terminal
9946 frame. If we let this through, a message would be displayed on
9948 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9950 #endif /* HAVE_WINDOW_SYSTEM */
9952 /* Redraw garbaged frames. */
9954 clear_garbaged_frames ();
9956 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9958 echo_area_window
= mini_window
;
9959 window_height_changed_p
= display_echo_area (w
);
9960 w
->must_be_updated_p
= 1;
9962 /* Update the display, unless called from redisplay_internal.
9963 Also don't update the screen during redisplay itself. The
9964 update will happen at the end of redisplay, and an update
9965 here could cause confusion. */
9966 if (update_frame_p
&& !redisplaying_p
)
9970 /* If the display update has been interrupted by pending
9971 input, update mode lines in the frame. Due to the
9972 pending input, it might have been that redisplay hasn't
9973 been called, so that mode lines above the echo area are
9974 garbaged. This looks odd, so we prevent it here. */
9975 if (!display_completed
)
9976 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9978 if (window_height_changed_p
9979 /* Don't do this if Emacs is shutting down. Redisplay
9980 needs to run hooks. */
9981 && !NILP (Vrun_hooks
))
9983 /* Must update other windows. Likewise as in other
9984 cases, don't let this update be interrupted by
9986 int count
= SPECPDL_INDEX ();
9987 specbind (Qredisplay_dont_pause
, Qt
);
9988 windows_or_buffers_changed
= 1;
9989 redisplay_internal ();
9990 unbind_to (count
, Qnil
);
9992 else if (FRAME_WINDOW_P (f
) && n
== 0)
9994 /* Window configuration is the same as before.
9995 Can do with a display update of the echo area,
9996 unless we displayed some mode lines. */
9997 update_single_window (w
, 1);
9998 FRAME_RIF (f
)->flush_display (f
);
10001 update_frame (f
, 1, 1);
10003 /* If cursor is in the echo area, make sure that the next
10004 redisplay displays the minibuffer, so that the cursor will
10005 be replaced with what the minibuffer wants. */
10006 if (cursor_in_echo_area
)
10007 ++windows_or_buffers_changed
;
10010 else if (!EQ (mini_window
, selected_window
))
10011 windows_or_buffers_changed
++;
10013 /* Last displayed message is now the current message. */
10014 echo_area_buffer
[1] = echo_area_buffer
[0];
10015 /* Inform read_char that we're not echoing. */
10016 echo_message_buffer
= Qnil
;
10018 /* Prevent redisplay optimization in redisplay_internal by resetting
10019 this_line_start_pos. This is done because the mini-buffer now
10020 displays the message instead of its buffer text. */
10021 if (EQ (mini_window
, selected_window
))
10022 CHARPOS (this_line_start_pos
) = 0;
10024 return window_height_changed_p
;
10029 /***********************************************************************
10030 Mode Lines and Frame Titles
10031 ***********************************************************************/
10033 /* A buffer for constructing non-propertized mode-line strings and
10034 frame titles in it; allocated from the heap in init_xdisp and
10035 resized as needed in store_mode_line_noprop_char. */
10037 static char *mode_line_noprop_buf
;
10039 /* The buffer's end, and a current output position in it. */
10041 static char *mode_line_noprop_buf_end
;
10042 static char *mode_line_noprop_ptr
;
10044 #define MODE_LINE_NOPROP_LEN(start) \
10045 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10048 MODE_LINE_DISPLAY
= 0,
10052 } mode_line_target
;
10054 /* Alist that caches the results of :propertize.
10055 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10056 static Lisp_Object mode_line_proptrans_alist
;
10058 /* List of strings making up the mode-line. */
10059 static Lisp_Object mode_line_string_list
;
10061 /* Base face property when building propertized mode line string. */
10062 static Lisp_Object mode_line_string_face
;
10063 static Lisp_Object mode_line_string_face_prop
;
10066 /* Unwind data for mode line strings */
10068 static Lisp_Object Vmode_line_unwind_vector
;
10071 format_mode_line_unwind_data (struct buffer
*obuf
,
10073 int save_proptrans
)
10075 Lisp_Object vector
, tmp
;
10077 /* Reduce consing by keeping one vector in
10078 Vwith_echo_area_save_vector. */
10079 vector
= Vmode_line_unwind_vector
;
10080 Vmode_line_unwind_vector
= Qnil
;
10083 vector
= Fmake_vector (make_number (8), Qnil
);
10085 ASET (vector
, 0, make_number (mode_line_target
));
10086 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10087 ASET (vector
, 2, mode_line_string_list
);
10088 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10089 ASET (vector
, 4, mode_line_string_face
);
10090 ASET (vector
, 5, mode_line_string_face_prop
);
10093 XSETBUFFER (tmp
, obuf
);
10096 ASET (vector
, 6, tmp
);
10097 ASET (vector
, 7, owin
);
10103 unwind_format_mode_line (Lisp_Object vector
)
10105 mode_line_target
= XINT (AREF (vector
, 0));
10106 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10107 mode_line_string_list
= AREF (vector
, 2);
10108 if (! EQ (AREF (vector
, 3), Qt
))
10109 mode_line_proptrans_alist
= AREF (vector
, 3);
10110 mode_line_string_face
= AREF (vector
, 4);
10111 mode_line_string_face_prop
= AREF (vector
, 5);
10113 if (!NILP (AREF (vector
, 7)))
10114 /* Select window before buffer, since it may change the buffer. */
10115 Fselect_window (AREF (vector
, 7), Qt
);
10117 if (!NILP (AREF (vector
, 6)))
10119 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10120 ASET (vector
, 6, Qnil
);
10123 Vmode_line_unwind_vector
= vector
;
10128 /* Store a single character C for the frame title in mode_line_noprop_buf.
10129 Re-allocate mode_line_noprop_buf if necessary. */
10132 store_mode_line_noprop_char (char c
)
10134 /* If output position has reached the end of the allocated buffer,
10135 double the buffer's size. */
10136 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10138 int len
= MODE_LINE_NOPROP_LEN (0);
10139 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
10140 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
10141 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
10142 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10145 *mode_line_noprop_ptr
++ = c
;
10149 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10150 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10151 characters that yield more columns than PRECISION; PRECISION <= 0
10152 means copy the whole string. Pad with spaces until FIELD_WIDTH
10153 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10154 pad. Called from display_mode_element when it is used to build a
10158 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10160 const unsigned char *str
= (const unsigned char *) string
;
10162 EMACS_INT dummy
, nbytes
;
10164 /* Copy at most PRECISION chars from STR. */
10165 nbytes
= strlen (string
);
10166 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10168 store_mode_line_noprop_char (*str
++);
10170 /* Fill up with spaces until FIELD_WIDTH reached. */
10171 while (field_width
> 0
10172 && n
< field_width
)
10174 store_mode_line_noprop_char (' ');
10181 /***********************************************************************
10183 ***********************************************************************/
10185 #ifdef HAVE_WINDOW_SYSTEM
10187 /* Set the title of FRAME, if it has changed. The title format is
10188 Vicon_title_format if FRAME is iconified, otherwise it is
10189 frame_title_format. */
10192 x_consider_frame_title (Lisp_Object frame
)
10194 struct frame
*f
= XFRAME (frame
);
10196 if (FRAME_WINDOW_P (f
)
10197 || FRAME_MINIBUF_ONLY_P (f
)
10198 || f
->explicit_name
)
10200 /* Do we have more than one visible frame on this X display? */
10207 int count
= SPECPDL_INDEX ();
10209 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
10211 Lisp_Object other_frame
= XCAR (tail
);
10212 struct frame
*tf
= XFRAME (other_frame
);
10215 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
10216 && !FRAME_MINIBUF_ONLY_P (tf
)
10217 && !EQ (other_frame
, tip_frame
)
10218 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
10222 /* Set global variable indicating that multiple frames exist. */
10223 multiple_frames
= CONSP (tail
);
10225 /* Switch to the buffer of selected window of the frame. Set up
10226 mode_line_target so that display_mode_element will output into
10227 mode_line_noprop_buf; then display the title. */
10228 record_unwind_protect (unwind_format_mode_line
,
10229 format_mode_line_unwind_data
10230 (current_buffer
, selected_window
, 0));
10232 Fselect_window (f
->selected_window
, Qt
);
10233 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
10234 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
10236 mode_line_target
= MODE_LINE_TITLE
;
10237 title_start
= MODE_LINE_NOPROP_LEN (0);
10238 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
10239 NULL
, DEFAULT_FACE_ID
);
10240 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
10241 len
= MODE_LINE_NOPROP_LEN (title_start
);
10242 title
= mode_line_noprop_buf
+ title_start
;
10243 unbind_to (count
, Qnil
);
10245 /* Set the title only if it's changed. This avoids consing in
10246 the common case where it hasn't. (If it turns out that we've
10247 already wasted too much time by walking through the list with
10248 display_mode_element, then we might need to optimize at a
10249 higher level than this.) */
10250 if (! STRINGP (f
->name
)
10251 || SBYTES (f
->name
) != len
10252 || memcmp (title
, SDATA (f
->name
), len
) != 0)
10253 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
10257 #endif /* not HAVE_WINDOW_SYSTEM */
10262 /***********************************************************************
10264 ***********************************************************************/
10267 /* Prepare for redisplay by updating menu-bar item lists when
10268 appropriate. This can call eval. */
10271 prepare_menu_bars (void)
10274 struct gcpro gcpro1
, gcpro2
;
10276 Lisp_Object tooltip_frame
;
10278 #ifdef HAVE_WINDOW_SYSTEM
10279 tooltip_frame
= tip_frame
;
10281 tooltip_frame
= Qnil
;
10284 /* Update all frame titles based on their buffer names, etc. We do
10285 this before the menu bars so that the buffer-menu will show the
10286 up-to-date frame titles. */
10287 #ifdef HAVE_WINDOW_SYSTEM
10288 if (windows_or_buffers_changed
|| update_mode_lines
)
10290 Lisp_Object tail
, frame
;
10292 FOR_EACH_FRAME (tail
, frame
)
10294 f
= XFRAME (frame
);
10295 if (!EQ (frame
, tooltip_frame
)
10296 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
10297 x_consider_frame_title (frame
);
10300 #endif /* HAVE_WINDOW_SYSTEM */
10302 /* Update the menu bar item lists, if appropriate. This has to be
10303 done before any actual redisplay or generation of display lines. */
10304 all_windows
= (update_mode_lines
10305 || buffer_shared
> 1
10306 || windows_or_buffers_changed
);
10309 Lisp_Object tail
, frame
;
10310 int count
= SPECPDL_INDEX ();
10311 /* 1 means that update_menu_bar has run its hooks
10312 so any further calls to update_menu_bar shouldn't do so again. */
10313 int menu_bar_hooks_run
= 0;
10315 record_unwind_save_match_data ();
10317 FOR_EACH_FRAME (tail
, frame
)
10319 f
= XFRAME (frame
);
10321 /* Ignore tooltip frame. */
10322 if (EQ (frame
, tooltip_frame
))
10325 /* If a window on this frame changed size, report that to
10326 the user and clear the size-change flag. */
10327 if (FRAME_WINDOW_SIZES_CHANGED (f
))
10329 Lisp_Object functions
;
10331 /* Clear flag first in case we get an error below. */
10332 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
10333 functions
= Vwindow_size_change_functions
;
10334 GCPRO2 (tail
, functions
);
10336 while (CONSP (functions
))
10338 if (!EQ (XCAR (functions
), Qt
))
10339 call1 (XCAR (functions
), frame
);
10340 functions
= XCDR (functions
);
10346 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
10347 #ifdef HAVE_WINDOW_SYSTEM
10348 update_tool_bar (f
, 0);
10351 if (windows_or_buffers_changed
10353 ns_set_doc_edited (f
, Fbuffer_modified_p
10354 (XWINDOW (f
->selected_window
)->buffer
));
10359 unbind_to (count
, Qnil
);
10363 struct frame
*sf
= SELECTED_FRAME ();
10364 update_menu_bar (sf
, 1, 0);
10365 #ifdef HAVE_WINDOW_SYSTEM
10366 update_tool_bar (sf
, 1);
10372 /* Update the menu bar item list for frame F. This has to be done
10373 before we start to fill in any display lines, because it can call
10376 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
10378 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
10379 already ran the menu bar hooks for this redisplay, so there
10380 is no need to run them again. The return value is the
10381 updated value of this flag, to pass to the next call. */
10384 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
10386 Lisp_Object window
;
10387 register struct window
*w
;
10389 /* If called recursively during a menu update, do nothing. This can
10390 happen when, for instance, an activate-menubar-hook causes a
10392 if (inhibit_menubar_update
)
10395 window
= FRAME_SELECTED_WINDOW (f
);
10396 w
= XWINDOW (window
);
10398 if (FRAME_WINDOW_P (f
)
10400 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10401 || defined (HAVE_NS) || defined (USE_GTK)
10402 FRAME_EXTERNAL_MENU_BAR (f
)
10404 FRAME_MENU_BAR_LINES (f
) > 0
10406 : FRAME_MENU_BAR_LINES (f
) > 0)
10408 /* If the user has switched buffers or windows, we need to
10409 recompute to reflect the new bindings. But we'll
10410 recompute when update_mode_lines is set too; that means
10411 that people can use force-mode-line-update to request
10412 that the menu bar be recomputed. The adverse effect on
10413 the rest of the redisplay algorithm is about the same as
10414 windows_or_buffers_changed anyway. */
10415 if (windows_or_buffers_changed
10416 /* This used to test w->update_mode_line, but we believe
10417 there is no need to recompute the menu in that case. */
10418 || update_mode_lines
10419 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10420 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10421 != !NILP (w
->last_had_star
))
10422 || ((!NILP (Vtransient_mark_mode
)
10423 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10424 != !NILP (w
->region_showing
)))
10426 struct buffer
*prev
= current_buffer
;
10427 int count
= SPECPDL_INDEX ();
10429 specbind (Qinhibit_menubar_update
, Qt
);
10431 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10432 if (save_match_data
)
10433 record_unwind_save_match_data ();
10434 if (NILP (Voverriding_local_map_menu_flag
))
10436 specbind (Qoverriding_terminal_local_map
, Qnil
);
10437 specbind (Qoverriding_local_map
, Qnil
);
10442 /* Run the Lucid hook. */
10443 safe_run_hooks (Qactivate_menubar_hook
);
10445 /* If it has changed current-menubar from previous value,
10446 really recompute the menu-bar from the value. */
10447 if (! NILP (Vlucid_menu_bar_dirty_flag
))
10448 call0 (Qrecompute_lucid_menubar
);
10450 safe_run_hooks (Qmenu_bar_update_hook
);
10455 XSETFRAME (Vmenu_updating_frame
, f
);
10456 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
10458 /* Redisplay the menu bar in case we changed it. */
10459 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10460 || defined (HAVE_NS) || defined (USE_GTK)
10461 if (FRAME_WINDOW_P (f
))
10463 #if defined (HAVE_NS)
10464 /* All frames on Mac OS share the same menubar. So only
10465 the selected frame should be allowed to set it. */
10466 if (f
== SELECTED_FRAME ())
10468 set_frame_menubar (f
, 0, 0);
10471 /* On a terminal screen, the menu bar is an ordinary screen
10472 line, and this makes it get updated. */
10473 w
->update_mode_line
= Qt
;
10474 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10475 /* In the non-toolkit version, the menu bar is an ordinary screen
10476 line, and this makes it get updated. */
10477 w
->update_mode_line
= Qt
;
10478 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10480 unbind_to (count
, Qnil
);
10481 set_buffer_internal_1 (prev
);
10490 /***********************************************************************
10492 ***********************************************************************/
10494 #ifdef HAVE_WINDOW_SYSTEM
10497 Nominal cursor position -- where to draw output.
10498 HPOS and VPOS are window relative glyph matrix coordinates.
10499 X and Y are window relative pixel coordinates. */
10501 struct cursor_pos output_cursor
;
10505 Set the global variable output_cursor to CURSOR. All cursor
10506 positions are relative to updated_window. */
10509 set_output_cursor (struct cursor_pos
*cursor
)
10511 output_cursor
.hpos
= cursor
->hpos
;
10512 output_cursor
.vpos
= cursor
->vpos
;
10513 output_cursor
.x
= cursor
->x
;
10514 output_cursor
.y
= cursor
->y
;
10519 Set a nominal cursor position.
10521 HPOS and VPOS are column/row positions in a window glyph matrix. X
10522 and Y are window text area relative pixel positions.
10524 If this is done during an update, updated_window will contain the
10525 window that is being updated and the position is the future output
10526 cursor position for that window. If updated_window is null, use
10527 selected_window and display the cursor at the given position. */
10530 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
10534 /* If updated_window is not set, work on selected_window. */
10535 if (updated_window
)
10536 w
= updated_window
;
10538 w
= XWINDOW (selected_window
);
10540 /* Set the output cursor. */
10541 output_cursor
.hpos
= hpos
;
10542 output_cursor
.vpos
= vpos
;
10543 output_cursor
.x
= x
;
10544 output_cursor
.y
= y
;
10546 /* If not called as part of an update, really display the cursor.
10547 This will also set the cursor position of W. */
10548 if (updated_window
== NULL
)
10551 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10552 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10553 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10558 #endif /* HAVE_WINDOW_SYSTEM */
10561 /***********************************************************************
10563 ***********************************************************************/
10565 #ifdef HAVE_WINDOW_SYSTEM
10567 /* Where the mouse was last time we reported a mouse event. */
10569 FRAME_PTR last_mouse_frame
;
10571 /* Tool-bar item index of the item on which a mouse button was pressed
10574 int last_tool_bar_item
;
10578 update_tool_bar_unwind (Lisp_Object frame
)
10580 selected_frame
= frame
;
10584 /* Update the tool-bar item list for frame F. This has to be done
10585 before we start to fill in any display lines. Called from
10586 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10587 and restore it here. */
10590 update_tool_bar (struct frame
*f
, int save_match_data
)
10592 #if defined (USE_GTK) || defined (HAVE_NS)
10593 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10595 int do_update
= WINDOWP (f
->tool_bar_window
)
10596 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10601 Lisp_Object window
;
10604 window
= FRAME_SELECTED_WINDOW (f
);
10605 w
= XWINDOW (window
);
10607 /* If the user has switched buffers or windows, we need to
10608 recompute to reflect the new bindings. But we'll
10609 recompute when update_mode_lines is set too; that means
10610 that people can use force-mode-line-update to request
10611 that the menu bar be recomputed. The adverse effect on
10612 the rest of the redisplay algorithm is about the same as
10613 windows_or_buffers_changed anyway. */
10614 if (windows_or_buffers_changed
10615 || !NILP (w
->update_mode_line
)
10616 || update_mode_lines
10617 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10618 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10619 != !NILP (w
->last_had_star
))
10620 || ((!NILP (Vtransient_mark_mode
)
10621 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10622 != !NILP (w
->region_showing
)))
10624 struct buffer
*prev
= current_buffer
;
10625 int count
= SPECPDL_INDEX ();
10626 Lisp_Object frame
, new_tool_bar
;
10627 int new_n_tool_bar
;
10628 struct gcpro gcpro1
;
10630 /* Set current_buffer to the buffer of the selected
10631 window of the frame, so that we get the right local
10633 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10635 /* Save match data, if we must. */
10636 if (save_match_data
)
10637 record_unwind_save_match_data ();
10639 /* Make sure that we don't accidentally use bogus keymaps. */
10640 if (NILP (Voverriding_local_map_menu_flag
))
10642 specbind (Qoverriding_terminal_local_map
, Qnil
);
10643 specbind (Qoverriding_local_map
, Qnil
);
10646 GCPRO1 (new_tool_bar
);
10648 /* We must temporarily set the selected frame to this frame
10649 before calling tool_bar_items, because the calculation of
10650 the tool-bar keymap uses the selected frame (see
10651 `tool-bar-make-keymap' in tool-bar.el). */
10652 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10653 XSETFRAME (frame
, f
);
10654 selected_frame
= frame
;
10656 /* Build desired tool-bar items from keymaps. */
10657 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10660 /* Redisplay the tool-bar if we changed it. */
10661 if (new_n_tool_bar
!= f
->n_tool_bar_items
10662 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10664 /* Redisplay that happens asynchronously due to an expose event
10665 may access f->tool_bar_items. Make sure we update both
10666 variables within BLOCK_INPUT so no such event interrupts. */
10668 f
->tool_bar_items
= new_tool_bar
;
10669 f
->n_tool_bar_items
= new_n_tool_bar
;
10670 w
->update_mode_line
= Qt
;
10676 unbind_to (count
, Qnil
);
10677 set_buffer_internal_1 (prev
);
10683 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10684 F's desired tool-bar contents. F->tool_bar_items must have
10685 been set up previously by calling prepare_menu_bars. */
10688 build_desired_tool_bar_string (struct frame
*f
)
10690 int i
, size
, size_needed
;
10691 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10692 Lisp_Object image
, plist
, props
;
10694 image
= plist
= props
= Qnil
;
10695 GCPRO3 (image
, plist
, props
);
10697 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10698 Otherwise, make a new string. */
10700 /* The size of the string we might be able to reuse. */
10701 size
= (STRINGP (f
->desired_tool_bar_string
)
10702 ? SCHARS (f
->desired_tool_bar_string
)
10705 /* We need one space in the string for each image. */
10706 size_needed
= f
->n_tool_bar_items
;
10708 /* Reuse f->desired_tool_bar_string, if possible. */
10709 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10710 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10711 make_number (' '));
10714 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10715 Fremove_text_properties (make_number (0), make_number (size
),
10716 props
, f
->desired_tool_bar_string
);
10719 /* Put a `display' property on the string for the images to display,
10720 put a `menu_item' property on tool-bar items with a value that
10721 is the index of the item in F's tool-bar item vector. */
10722 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10724 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10726 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10727 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10728 int hmargin
, vmargin
, relief
, idx
, end
;
10730 /* If image is a vector, choose the image according to the
10732 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10733 if (VECTORP (image
))
10737 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10738 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10741 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10742 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10744 xassert (ASIZE (image
) >= idx
);
10745 image
= AREF (image
, idx
);
10750 /* Ignore invalid image specifications. */
10751 if (!valid_image_p (image
))
10754 /* Display the tool-bar button pressed, or depressed. */
10755 plist
= Fcopy_sequence (XCDR (image
));
10757 /* Compute margin and relief to draw. */
10758 relief
= (tool_bar_button_relief
>= 0
10759 ? tool_bar_button_relief
10760 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10761 hmargin
= vmargin
= relief
;
10763 if (INTEGERP (Vtool_bar_button_margin
)
10764 && XINT (Vtool_bar_button_margin
) > 0)
10766 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10767 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10769 else if (CONSP (Vtool_bar_button_margin
))
10771 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10772 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10773 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10775 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10776 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10777 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10780 if (auto_raise_tool_bar_buttons_p
)
10782 /* Add a `:relief' property to the image spec if the item is
10786 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10793 /* If image is selected, display it pressed, i.e. with a
10794 negative relief. If it's not selected, display it with a
10796 plist
= Fplist_put (plist
, QCrelief
,
10798 ? make_number (-relief
)
10799 : make_number (relief
)));
10804 /* Put a margin around the image. */
10805 if (hmargin
|| vmargin
)
10807 if (hmargin
== vmargin
)
10808 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10810 plist
= Fplist_put (plist
, QCmargin
,
10811 Fcons (make_number (hmargin
),
10812 make_number (vmargin
)));
10815 /* If button is not enabled, and we don't have special images
10816 for the disabled state, make the image appear disabled by
10817 applying an appropriate algorithm to it. */
10818 if (!enabled_p
&& idx
< 0)
10819 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10821 /* Put a `display' text property on the string for the image to
10822 display. Put a `menu-item' property on the string that gives
10823 the start of this item's properties in the tool-bar items
10825 image
= Fcons (Qimage
, plist
);
10826 props
= list4 (Qdisplay
, image
,
10827 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10829 /* Let the last image hide all remaining spaces in the tool bar
10830 string. The string can be longer than needed when we reuse a
10831 previous string. */
10832 if (i
+ 1 == f
->n_tool_bar_items
)
10833 end
= SCHARS (f
->desired_tool_bar_string
);
10836 Fadd_text_properties (make_number (i
), make_number (end
),
10837 props
, f
->desired_tool_bar_string
);
10845 /* Display one line of the tool-bar of frame IT->f.
10847 HEIGHT specifies the desired height of the tool-bar line.
10848 If the actual height of the glyph row is less than HEIGHT, the
10849 row's height is increased to HEIGHT, and the icons are centered
10850 vertically in the new height.
10852 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10853 count a final empty row in case the tool-bar width exactly matches
10858 display_tool_bar_line (struct it
*it
, int height
)
10860 struct glyph_row
*row
= it
->glyph_row
;
10861 int max_x
= it
->last_visible_x
;
10862 struct glyph
*last
;
10864 prepare_desired_row (row
);
10865 row
->y
= it
->current_y
;
10867 /* Note that this isn't made use of if the face hasn't a box,
10868 so there's no need to check the face here. */
10869 it
->start_of_box_run_p
= 1;
10871 while (it
->current_x
< max_x
)
10873 int x
, n_glyphs_before
, i
, nglyphs
;
10874 struct it it_before
;
10876 /* Get the next display element. */
10877 if (!get_next_display_element (it
))
10879 /* Don't count empty row if we are counting needed tool-bar lines. */
10880 if (height
< 0 && !it
->hpos
)
10885 /* Produce glyphs. */
10886 n_glyphs_before
= row
->used
[TEXT_AREA
];
10889 PRODUCE_GLYPHS (it
);
10891 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10893 x
= it_before
.current_x
;
10894 while (i
< nglyphs
)
10896 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10898 if (x
+ glyph
->pixel_width
> max_x
)
10900 /* Glyph doesn't fit on line. Backtrack. */
10901 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10903 /* If this is the only glyph on this line, it will never fit on the
10904 tool-bar, so skip it. But ensure there is at least one glyph,
10905 so we don't accidentally disable the tool-bar. */
10906 if (n_glyphs_before
== 0
10907 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10913 x
+= glyph
->pixel_width
;
10917 /* Stop at line end. */
10918 if (ITERATOR_AT_END_OF_LINE_P (it
))
10921 set_iterator_to_next (it
, 1);
10926 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10928 /* Use default face for the border below the tool bar.
10930 FIXME: When auto-resize-tool-bars is grow-only, there is
10931 no additional border below the possibly empty tool-bar lines.
10932 So to make the extra empty lines look "normal", we have to
10933 use the tool-bar face for the border too. */
10934 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10935 it
->face_id
= DEFAULT_FACE_ID
;
10937 extend_face_to_end_of_line (it
);
10938 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10939 last
->right_box_line_p
= 1;
10940 if (last
== row
->glyphs
[TEXT_AREA
])
10941 last
->left_box_line_p
= 1;
10943 /* Make line the desired height and center it vertically. */
10944 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10946 /* Don't add more than one line height. */
10947 height
%= FRAME_LINE_HEIGHT (it
->f
);
10948 it
->max_ascent
+= height
/ 2;
10949 it
->max_descent
+= (height
+ 1) / 2;
10952 compute_line_metrics (it
);
10954 /* If line is empty, make it occupy the rest of the tool-bar. */
10955 if (!row
->displays_text_p
)
10957 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10958 row
->visible_height
= row
->height
;
10959 row
->ascent
= row
->phys_ascent
= 0;
10960 row
->extra_line_spacing
= 0;
10963 row
->full_width_p
= 1;
10964 row
->continued_p
= 0;
10965 row
->truncated_on_left_p
= 0;
10966 row
->truncated_on_right_p
= 0;
10968 it
->current_x
= it
->hpos
= 0;
10969 it
->current_y
+= row
->height
;
10975 /* Max tool-bar height. */
10977 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10978 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10980 /* Value is the number of screen lines needed to make all tool-bar
10981 items of frame F visible. The number of actual rows needed is
10982 returned in *N_ROWS if non-NULL. */
10985 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
10987 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10989 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10990 the desired matrix, so use (unused) mode-line row as temporary row to
10991 avoid destroying the first tool-bar row. */
10992 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10994 /* Initialize an iterator for iteration over
10995 F->desired_tool_bar_string in the tool-bar window of frame F. */
10996 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10997 it
.first_visible_x
= 0;
10998 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10999 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11000 it
.paragraph_embedding
= L2R
;
11002 while (!ITERATOR_AT_END_P (&it
))
11004 clear_glyph_row (temp_row
);
11005 it
.glyph_row
= temp_row
;
11006 display_tool_bar_line (&it
, -1);
11008 clear_glyph_row (temp_row
);
11010 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11012 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11014 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11018 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11020 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11021 (Lisp_Object frame
)
11028 frame
= selected_frame
;
11030 CHECK_FRAME (frame
);
11031 f
= XFRAME (frame
);
11033 if (WINDOWP (f
->tool_bar_window
)
11034 || (w
= XWINDOW (f
->tool_bar_window
),
11035 WINDOW_TOTAL_LINES (w
) > 0))
11037 update_tool_bar (f
, 1);
11038 if (f
->n_tool_bar_items
)
11040 build_desired_tool_bar_string (f
);
11041 nlines
= tool_bar_lines_needed (f
, NULL
);
11045 return make_number (nlines
);
11049 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11050 height should be changed. */
11053 redisplay_tool_bar (struct frame
*f
)
11057 struct glyph_row
*row
;
11059 #if defined (USE_GTK) || defined (HAVE_NS)
11060 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11061 update_frame_tool_bar (f
);
11065 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11066 do anything. This means you must start with tool-bar-lines
11067 non-zero to get the auto-sizing effect. Or in other words, you
11068 can turn off tool-bars by specifying tool-bar-lines zero. */
11069 if (!WINDOWP (f
->tool_bar_window
)
11070 || (w
= XWINDOW (f
->tool_bar_window
),
11071 WINDOW_TOTAL_LINES (w
) == 0))
11074 /* Set up an iterator for the tool-bar window. */
11075 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11076 it
.first_visible_x
= 0;
11077 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11078 row
= it
.glyph_row
;
11080 /* Build a string that represents the contents of the tool-bar. */
11081 build_desired_tool_bar_string (f
);
11082 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11083 /* FIXME: This should be controlled by a user option. But it
11084 doesn't make sense to have an R2L tool bar if the menu bar cannot
11085 be drawn also R2L, and making the menu bar R2L is tricky due
11086 toolkit-specific code that implements it. If an R2L tool bar is
11087 ever supported, display_tool_bar_line should also be augmented to
11088 call unproduce_glyphs like display_line and display_string
11090 it
.paragraph_embedding
= L2R
;
11092 if (f
->n_tool_bar_rows
== 0)
11096 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11097 nlines
!= WINDOW_TOTAL_LINES (w
)))
11100 int old_height
= WINDOW_TOTAL_LINES (w
);
11102 XSETFRAME (frame
, f
);
11103 Fmodify_frame_parameters (frame
,
11104 Fcons (Fcons (Qtool_bar_lines
,
11105 make_number (nlines
)),
11107 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11109 clear_glyph_matrix (w
->desired_matrix
);
11110 fonts_changed_p
= 1;
11116 /* Display as many lines as needed to display all tool-bar items. */
11118 if (f
->n_tool_bar_rows
> 0)
11120 int border
, rows
, height
, extra
;
11122 if (INTEGERP (Vtool_bar_border
))
11123 border
= XINT (Vtool_bar_border
);
11124 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11125 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11126 else if (EQ (Vtool_bar_border
, Qborder_width
))
11127 border
= f
->border_width
;
11133 rows
= f
->n_tool_bar_rows
;
11134 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11135 extra
= it
.last_visible_y
- border
- height
* rows
;
11137 while (it
.current_y
< it
.last_visible_y
)
11140 if (extra
> 0 && rows
-- > 0)
11142 h
= (extra
+ rows
- 1) / rows
;
11145 display_tool_bar_line (&it
, height
+ h
);
11150 while (it
.current_y
< it
.last_visible_y
)
11151 display_tool_bar_line (&it
, 0);
11154 /* It doesn't make much sense to try scrolling in the tool-bar
11155 window, so don't do it. */
11156 w
->desired_matrix
->no_scrolling_p
= 1;
11157 w
->must_be_updated_p
= 1;
11159 if (!NILP (Vauto_resize_tool_bars
))
11161 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11162 int change_height_p
= 0;
11164 /* If we couldn't display everything, change the tool-bar's
11165 height if there is room for more. */
11166 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11167 && it
.current_y
< max_tool_bar_height
)
11168 change_height_p
= 1;
11170 row
= it
.glyph_row
- 1;
11172 /* If there are blank lines at the end, except for a partially
11173 visible blank line at the end that is smaller than
11174 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11175 if (!row
->displays_text_p
11176 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11177 change_height_p
= 1;
11179 /* If row displays tool-bar items, but is partially visible,
11180 change the tool-bar's height. */
11181 if (row
->displays_text_p
11182 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11183 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11184 change_height_p
= 1;
11186 /* Resize windows as needed by changing the `tool-bar-lines'
11187 frame parameter. */
11188 if (change_height_p
)
11191 int old_height
= WINDOW_TOTAL_LINES (w
);
11193 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11195 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11196 && !f
->minimize_tool_bar_window_p
)
11197 ? (nlines
> old_height
)
11198 : (nlines
!= old_height
));
11199 f
->minimize_tool_bar_window_p
= 0;
11201 if (change_height_p
)
11203 XSETFRAME (frame
, f
);
11204 Fmodify_frame_parameters (frame
,
11205 Fcons (Fcons (Qtool_bar_lines
,
11206 make_number (nlines
)),
11208 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11210 clear_glyph_matrix (w
->desired_matrix
);
11211 f
->n_tool_bar_rows
= nrows
;
11212 fonts_changed_p
= 1;
11219 f
->minimize_tool_bar_window_p
= 0;
11224 /* Get information about the tool-bar item which is displayed in GLYPH
11225 on frame F. Return in *PROP_IDX the index where tool-bar item
11226 properties start in F->tool_bar_items. Value is zero if
11227 GLYPH doesn't display a tool-bar item. */
11230 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
11236 /* This function can be called asynchronously, which means we must
11237 exclude any possibility that Fget_text_property signals an
11239 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
11240 charpos
= max (0, charpos
);
11242 /* Get the text property `menu-item' at pos. The value of that
11243 property is the start index of this item's properties in
11244 F->tool_bar_items. */
11245 prop
= Fget_text_property (make_number (charpos
),
11246 Qmenu_item
, f
->current_tool_bar_string
);
11247 if (INTEGERP (prop
))
11249 *prop_idx
= XINT (prop
);
11259 /* Get information about the tool-bar item at position X/Y on frame F.
11260 Return in *GLYPH a pointer to the glyph of the tool-bar item in
11261 the current matrix of the tool-bar window of F, or NULL if not
11262 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
11263 item in F->tool_bar_items. Value is
11265 -1 if X/Y is not on a tool-bar item
11266 0 if X/Y is on the same item that was highlighted before.
11270 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
11271 int *hpos
, int *vpos
, int *prop_idx
)
11273 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11274 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11277 /* Find the glyph under X/Y. */
11278 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
11279 if (*glyph
== NULL
)
11282 /* Get the start of this tool-bar item's properties in
11283 f->tool_bar_items. */
11284 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
11287 /* Is mouse on the highlighted item? */
11288 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
11289 && *vpos
>= hlinfo
->mouse_face_beg_row
11290 && *vpos
<= hlinfo
->mouse_face_end_row
11291 && (*vpos
> hlinfo
->mouse_face_beg_row
11292 || *hpos
>= hlinfo
->mouse_face_beg_col
)
11293 && (*vpos
< hlinfo
->mouse_face_end_row
11294 || *hpos
< hlinfo
->mouse_face_end_col
11295 || hlinfo
->mouse_face_past_end
))
11303 Handle mouse button event on the tool-bar of frame F, at
11304 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
11305 0 for button release. MODIFIERS is event modifiers for button
11309 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
11310 unsigned int modifiers
)
11312 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11313 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11314 int hpos
, vpos
, prop_idx
;
11315 struct glyph
*glyph
;
11316 Lisp_Object enabled_p
;
11318 /* If not on the highlighted tool-bar item, return. */
11319 frame_to_window_pixel_xy (w
, &x
, &y
);
11320 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
11323 /* If item is disabled, do nothing. */
11324 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11325 if (NILP (enabled_p
))
11330 /* Show item in pressed state. */
11331 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
11332 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
11333 last_tool_bar_item
= prop_idx
;
11337 Lisp_Object key
, frame
;
11338 struct input_event event
;
11339 EVENT_INIT (event
);
11341 /* Show item in released state. */
11342 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
11343 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
11345 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
11347 XSETFRAME (frame
, f
);
11348 event
.kind
= TOOL_BAR_EVENT
;
11349 event
.frame_or_window
= frame
;
11351 kbd_buffer_store_event (&event
);
11353 event
.kind
= TOOL_BAR_EVENT
;
11354 event
.frame_or_window
= frame
;
11356 event
.modifiers
= modifiers
;
11357 kbd_buffer_store_event (&event
);
11358 last_tool_bar_item
= -1;
11363 /* Possibly highlight a tool-bar item on frame F when mouse moves to
11364 tool-bar window-relative coordinates X/Y. Called from
11365 note_mouse_highlight. */
11368 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
11370 Lisp_Object window
= f
->tool_bar_window
;
11371 struct window
*w
= XWINDOW (window
);
11372 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11373 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11375 struct glyph
*glyph
;
11376 struct glyph_row
*row
;
11378 Lisp_Object enabled_p
;
11380 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
11381 int mouse_down_p
, rc
;
11383 /* Function note_mouse_highlight is called with negative X/Y
11384 values when mouse moves outside of the frame. */
11385 if (x
<= 0 || y
<= 0)
11387 clear_mouse_face (hlinfo
);
11391 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
11394 /* Not on tool-bar item. */
11395 clear_mouse_face (hlinfo
);
11399 /* On same tool-bar item as before. */
11400 goto set_help_echo
;
11402 clear_mouse_face (hlinfo
);
11404 /* Mouse is down, but on different tool-bar item? */
11405 mouse_down_p
= (dpyinfo
->grabbed
11406 && f
== last_mouse_frame
11407 && FRAME_LIVE_P (f
));
11409 && last_tool_bar_item
!= prop_idx
)
11412 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
11413 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
11415 /* If tool-bar item is not enabled, don't highlight it. */
11416 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11417 if (!NILP (enabled_p
))
11419 /* Compute the x-position of the glyph. In front and past the
11420 image is a space. We include this in the highlighted area. */
11421 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
11422 for (i
= x
= 0; i
< hpos
; ++i
)
11423 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11425 /* Record this as the current active region. */
11426 hlinfo
->mouse_face_beg_col
= hpos
;
11427 hlinfo
->mouse_face_beg_row
= vpos
;
11428 hlinfo
->mouse_face_beg_x
= x
;
11429 hlinfo
->mouse_face_beg_y
= row
->y
;
11430 hlinfo
->mouse_face_past_end
= 0;
11432 hlinfo
->mouse_face_end_col
= hpos
+ 1;
11433 hlinfo
->mouse_face_end_row
= vpos
;
11434 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
11435 hlinfo
->mouse_face_end_y
= row
->y
;
11436 hlinfo
->mouse_face_window
= window
;
11437 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
11439 /* Display it as active. */
11440 show_mouse_face (hlinfo
, draw
);
11441 hlinfo
->mouse_face_image_state
= draw
;
11446 /* Set help_echo_string to a help string to display for this tool-bar item.
11447 XTread_socket does the rest. */
11448 help_echo_object
= help_echo_window
= Qnil
;
11449 help_echo_pos
= -1;
11450 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
11451 if (NILP (help_echo_string
))
11452 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
11455 #endif /* HAVE_WINDOW_SYSTEM */
11459 /************************************************************************
11460 Horizontal scrolling
11461 ************************************************************************/
11463 static int hscroll_window_tree (Lisp_Object
);
11464 static int hscroll_windows (Lisp_Object
);
11466 /* For all leaf windows in the window tree rooted at WINDOW, set their
11467 hscroll value so that PT is (i) visible in the window, and (ii) so
11468 that it is not within a certain margin at the window's left and
11469 right border. Value is non-zero if any window's hscroll has been
11473 hscroll_window_tree (Lisp_Object window
)
11475 int hscrolled_p
= 0;
11476 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
11477 int hscroll_step_abs
= 0;
11478 double hscroll_step_rel
= 0;
11480 if (hscroll_relative_p
)
11482 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
11483 if (hscroll_step_rel
< 0)
11485 hscroll_relative_p
= 0;
11486 hscroll_step_abs
= 0;
11489 else if (INTEGERP (Vhscroll_step
))
11491 hscroll_step_abs
= XINT (Vhscroll_step
);
11492 if (hscroll_step_abs
< 0)
11493 hscroll_step_abs
= 0;
11496 hscroll_step_abs
= 0;
11498 while (WINDOWP (window
))
11500 struct window
*w
= XWINDOW (window
);
11502 if (WINDOWP (w
->hchild
))
11503 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11504 else if (WINDOWP (w
->vchild
))
11505 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11506 else if (w
->cursor
.vpos
>= 0)
11509 int text_area_width
;
11510 struct glyph_row
*current_cursor_row
11511 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11512 struct glyph_row
*desired_cursor_row
11513 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11514 struct glyph_row
*cursor_row
11515 = (desired_cursor_row
->enabled_p
11516 ? desired_cursor_row
11517 : current_cursor_row
);
11519 text_area_width
= window_box_width (w
, TEXT_AREA
);
11521 /* Scroll when cursor is inside this scroll margin. */
11522 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11524 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11525 && ((XFASTINT (w
->hscroll
)
11526 && w
->cursor
.x
<= h_margin
)
11527 || (cursor_row
->enabled_p
11528 && cursor_row
->truncated_on_right_p
11529 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11533 struct buffer
*saved_current_buffer
;
11537 /* Find point in a display of infinite width. */
11538 saved_current_buffer
= current_buffer
;
11539 current_buffer
= XBUFFER (w
->buffer
);
11541 if (w
== XWINDOW (selected_window
))
11545 pt
= marker_position (w
->pointm
);
11546 pt
= max (BEGV
, pt
);
11550 /* Move iterator to pt starting at cursor_row->start in
11551 a line with infinite width. */
11552 init_to_row_start (&it
, w
, cursor_row
);
11553 it
.last_visible_x
= INFINITY
;
11554 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11555 current_buffer
= saved_current_buffer
;
11557 /* Position cursor in window. */
11558 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11559 hscroll
= max (0, (it
.current_x
11560 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11561 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11562 : (text_area_width
/ 2))))
11563 / FRAME_COLUMN_WIDTH (it
.f
);
11564 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11566 if (hscroll_relative_p
)
11567 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11570 wanted_x
= text_area_width
11571 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11574 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11578 if (hscroll_relative_p
)
11579 wanted_x
= text_area_width
* hscroll_step_rel
11582 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11585 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11587 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11589 /* Don't call Fset_window_hscroll if value hasn't
11590 changed because it will prevent redisplay
11592 if (XFASTINT (w
->hscroll
) != hscroll
)
11594 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11595 w
->hscroll
= make_number (hscroll
);
11604 /* Value is non-zero if hscroll of any leaf window has been changed. */
11605 return hscrolled_p
;
11609 /* Set hscroll so that cursor is visible and not inside horizontal
11610 scroll margins for all windows in the tree rooted at WINDOW. See
11611 also hscroll_window_tree above. Value is non-zero if any window's
11612 hscroll has been changed. If it has, desired matrices on the frame
11613 of WINDOW are cleared. */
11616 hscroll_windows (Lisp_Object window
)
11618 int hscrolled_p
= hscroll_window_tree (window
);
11620 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11621 return hscrolled_p
;
11626 /************************************************************************
11628 ************************************************************************/
11630 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11631 to a non-zero value. This is sometimes handy to have in a debugger
11636 /* First and last unchanged row for try_window_id. */
11638 int debug_first_unchanged_at_end_vpos
;
11639 int debug_last_unchanged_at_beg_vpos
;
11641 /* Delta vpos and y. */
11643 int debug_dvpos
, debug_dy
;
11645 /* Delta in characters and bytes for try_window_id. */
11647 EMACS_INT debug_delta
, debug_delta_bytes
;
11649 /* Values of window_end_pos and window_end_vpos at the end of
11652 EMACS_INT debug_end_vpos
;
11654 /* Append a string to W->desired_matrix->method. FMT is a printf
11655 format string. A1...A9 are a supplement for a variable-length
11656 argument list. If trace_redisplay_p is non-zero also printf the
11657 resulting string to stderr. */
11660 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11663 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11666 char *method
= w
->desired_matrix
->method
;
11667 int len
= strlen (method
);
11668 int size
= sizeof w
->desired_matrix
->method
;
11669 int remaining
= size
- len
- 1;
11671 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11672 if (len
&& remaining
)
11675 --remaining
, ++len
;
11678 strncpy (method
+ len
, buffer
, remaining
);
11680 if (trace_redisplay_p
)
11681 fprintf (stderr
, "%p (%s): %s\n",
11683 ((BUFFERP (w
->buffer
)
11684 && STRINGP (XBUFFER (w
->buffer
)->name
))
11685 ? SSDATA (XBUFFER (w
->buffer
)->name
)
11690 #endif /* GLYPH_DEBUG */
11693 /* Value is non-zero if all changes in window W, which displays
11694 current_buffer, are in the text between START and END. START is a
11695 buffer position, END is given as a distance from Z. Used in
11696 redisplay_internal for display optimization. */
11699 text_outside_line_unchanged_p (struct window
*w
,
11700 EMACS_INT start
, EMACS_INT end
)
11702 int unchanged_p
= 1;
11704 /* If text or overlays have changed, see where. */
11705 if (XFASTINT (w
->last_modified
) < MODIFF
11706 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11708 /* Gap in the line? */
11709 if (GPT
< start
|| Z
- GPT
< end
)
11712 /* Changes start in front of the line, or end after it? */
11714 && (BEG_UNCHANGED
< start
- 1
11715 || END_UNCHANGED
< end
))
11718 /* If selective display, can't optimize if changes start at the
11719 beginning of the line. */
11721 && INTEGERP (BVAR (current_buffer
, selective_display
))
11722 && XINT (BVAR (current_buffer
, selective_display
)) > 0
11723 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11726 /* If there are overlays at the start or end of the line, these
11727 may have overlay strings with newlines in them. A change at
11728 START, for instance, may actually concern the display of such
11729 overlay strings as well, and they are displayed on different
11730 lines. So, quickly rule out this case. (For the future, it
11731 might be desirable to implement something more telling than
11732 just BEG/END_UNCHANGED.) */
11735 if (BEG
+ BEG_UNCHANGED
== start
11736 && overlay_touches_p (start
))
11738 if (END_UNCHANGED
== end
11739 && overlay_touches_p (Z
- end
))
11743 /* Under bidi reordering, adding or deleting a character in the
11744 beginning of a paragraph, before the first strong directional
11745 character, can change the base direction of the paragraph (unless
11746 the buffer specifies a fixed paragraph direction), which will
11747 require to redisplay the whole paragraph. It might be worthwhile
11748 to find the paragraph limits and widen the range of redisplayed
11749 lines to that, but for now just give up this optimization. */
11750 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
11751 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
11755 return unchanged_p
;
11759 /* Do a frame update, taking possible shortcuts into account. This is
11760 the main external entry point for redisplay.
11762 If the last redisplay displayed an echo area message and that message
11763 is no longer requested, we clear the echo area or bring back the
11764 mini-buffer if that is in use. */
11769 redisplay_internal ();
11774 overlay_arrow_string_or_property (Lisp_Object var
)
11778 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11781 return Voverlay_arrow_string
;
11784 /* Return 1 if there are any overlay-arrows in current_buffer. */
11786 overlay_arrow_in_current_buffer_p (void)
11790 for (vlist
= Voverlay_arrow_variable_list
;
11792 vlist
= XCDR (vlist
))
11794 Lisp_Object var
= XCAR (vlist
);
11797 if (!SYMBOLP (var
))
11799 val
= find_symbol_value (var
);
11801 && current_buffer
== XMARKER (val
)->buffer
)
11808 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11812 overlay_arrows_changed_p (void)
11816 for (vlist
= Voverlay_arrow_variable_list
;
11818 vlist
= XCDR (vlist
))
11820 Lisp_Object var
= XCAR (vlist
);
11821 Lisp_Object val
, pstr
;
11823 if (!SYMBOLP (var
))
11825 val
= find_symbol_value (var
);
11826 if (!MARKERP (val
))
11828 if (! EQ (COERCE_MARKER (val
),
11829 Fget (var
, Qlast_arrow_position
))
11830 || ! (pstr
= overlay_arrow_string_or_property (var
),
11831 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11837 /* Mark overlay arrows to be updated on next redisplay. */
11840 update_overlay_arrows (int up_to_date
)
11844 for (vlist
= Voverlay_arrow_variable_list
;
11846 vlist
= XCDR (vlist
))
11848 Lisp_Object var
= XCAR (vlist
);
11850 if (!SYMBOLP (var
))
11853 if (up_to_date
> 0)
11855 Lisp_Object val
= find_symbol_value (var
);
11856 Fput (var
, Qlast_arrow_position
,
11857 COERCE_MARKER (val
));
11858 Fput (var
, Qlast_arrow_string
,
11859 overlay_arrow_string_or_property (var
));
11861 else if (up_to_date
< 0
11862 || !NILP (Fget (var
, Qlast_arrow_position
)))
11864 Fput (var
, Qlast_arrow_position
, Qt
);
11865 Fput (var
, Qlast_arrow_string
, Qt
);
11871 /* Return overlay arrow string to display at row.
11872 Return integer (bitmap number) for arrow bitmap in left fringe.
11873 Return nil if no overlay arrow. */
11876 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
11880 for (vlist
= Voverlay_arrow_variable_list
;
11882 vlist
= XCDR (vlist
))
11884 Lisp_Object var
= XCAR (vlist
);
11887 if (!SYMBOLP (var
))
11890 val
= find_symbol_value (var
);
11893 && current_buffer
== XMARKER (val
)->buffer
11894 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11896 if (FRAME_WINDOW_P (it
->f
)
11897 /* FIXME: if ROW->reversed_p is set, this should test
11898 the right fringe, not the left one. */
11899 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11901 #ifdef HAVE_WINDOW_SYSTEM
11902 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11905 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11906 return make_number (fringe_bitmap
);
11909 return make_number (-1); /* Use default arrow bitmap */
11911 return overlay_arrow_string_or_property (var
);
11918 /* Return 1 if point moved out of or into a composition. Otherwise
11919 return 0. PREV_BUF and PREV_PT are the last point buffer and
11920 position. BUF and PT are the current point buffer and position. */
11923 check_point_in_composition (struct buffer
*prev_buf
, EMACS_INT prev_pt
,
11924 struct buffer
*buf
, EMACS_INT pt
)
11926 EMACS_INT start
, end
;
11928 Lisp_Object buffer
;
11930 XSETBUFFER (buffer
, buf
);
11931 /* Check a composition at the last point if point moved within the
11933 if (prev_buf
== buf
)
11936 /* Point didn't move. */
11939 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11940 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11941 && COMPOSITION_VALID_P (start
, end
, prop
)
11942 && start
< prev_pt
&& end
> prev_pt
)
11943 /* The last point was within the composition. Return 1 iff
11944 point moved out of the composition. */
11945 return (pt
<= start
|| pt
>= end
);
11948 /* Check a composition at the current point. */
11949 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11950 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11951 && COMPOSITION_VALID_P (start
, end
, prop
)
11952 && start
< pt
&& end
> pt
);
11956 /* Reconsider the setting of B->clip_changed which is displayed
11960 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
11962 if (b
->clip_changed
11963 && !NILP (w
->window_end_valid
)
11964 && w
->current_matrix
->buffer
== b
11965 && w
->current_matrix
->zv
== BUF_ZV (b
)
11966 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11967 b
->clip_changed
= 0;
11969 /* If display wasn't paused, and W is not a tool bar window, see if
11970 point has been moved into or out of a composition. In that case,
11971 we set b->clip_changed to 1 to force updating the screen. If
11972 b->clip_changed has already been set to 1, we can skip this
11974 if (!b
->clip_changed
11975 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11979 if (w
== XWINDOW (selected_window
))
11982 pt
= marker_position (w
->pointm
);
11984 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11985 || pt
!= XINT (w
->last_point
))
11986 && check_point_in_composition (w
->current_matrix
->buffer
,
11987 XINT (w
->last_point
),
11988 XBUFFER (w
->buffer
), pt
))
11989 b
->clip_changed
= 1;
11994 /* Select FRAME to forward the values of frame-local variables into C
11995 variables so that the redisplay routines can access those values
11999 select_frame_for_redisplay (Lisp_Object frame
)
12001 Lisp_Object tail
, tem
;
12002 Lisp_Object old
= selected_frame
;
12003 struct Lisp_Symbol
*sym
;
12005 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12007 selected_frame
= frame
;
12010 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
12011 if (CONSP (XCAR (tail
))
12012 && (tem
= XCAR (XCAR (tail
)),
12014 && (sym
= indirect_variable (XSYMBOL (tem
)),
12015 sym
->redirect
== SYMBOL_LOCALIZED
)
12016 && sym
->val
.blv
->frame_local
)
12017 /* Use find_symbol_value rather than Fsymbol_value
12018 to avoid an error if it is void. */
12019 find_symbol_value (tem
);
12020 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12024 #define STOP_POLLING \
12025 do { if (! polling_stopped_here) stop_polling (); \
12026 polling_stopped_here = 1; } while (0)
12028 #define RESUME_POLLING \
12029 do { if (polling_stopped_here) start_polling (); \
12030 polling_stopped_here = 0; } while (0)
12033 /* Perhaps in the future avoid recentering windows if it
12034 is not necessary; currently that causes some problems. */
12037 redisplay_internal (void)
12039 struct window
*w
= XWINDOW (selected_window
);
12043 int must_finish
= 0;
12044 struct text_pos tlbufpos
, tlendpos
;
12045 int number_of_visible_frames
;
12048 int polling_stopped_here
= 0;
12049 Lisp_Object old_frame
= selected_frame
;
12051 /* Non-zero means redisplay has to consider all windows on all
12052 frames. Zero means, only selected_window is considered. */
12053 int consider_all_windows_p
;
12055 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12057 /* No redisplay if running in batch mode or frame is not yet fully
12058 initialized, or redisplay is explicitly turned off by setting
12059 Vinhibit_redisplay. */
12060 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12061 || !NILP (Vinhibit_redisplay
))
12064 /* Don't examine these until after testing Vinhibit_redisplay.
12065 When Emacs is shutting down, perhaps because its connection to
12066 X has dropped, we should not look at them at all. */
12067 fr
= XFRAME (w
->frame
);
12068 sf
= SELECTED_FRAME ();
12070 if (!fr
->glyphs_initialized_p
)
12073 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12074 if (popup_activated ())
12078 /* I don't think this happens but let's be paranoid. */
12079 if (redisplaying_p
)
12082 /* Record a function that resets redisplaying_p to its old value
12083 when we leave this function. */
12084 count
= SPECPDL_INDEX ();
12085 record_unwind_protect (unwind_redisplay
,
12086 Fcons (make_number (redisplaying_p
), selected_frame
));
12088 specbind (Qinhibit_free_realized_faces
, Qnil
);
12091 Lisp_Object tail
, frame
;
12093 FOR_EACH_FRAME (tail
, frame
)
12095 struct frame
*f
= XFRAME (frame
);
12096 f
->already_hscrolled_p
= 0;
12101 /* Remember the currently selected window. */
12104 if (!EQ (old_frame
, selected_frame
)
12105 && FRAME_LIVE_P (XFRAME (old_frame
)))
12106 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12107 selected_frame and selected_window to be temporarily out-of-sync so
12108 when we come back here via `goto retry', we need to resync because we
12109 may need to run Elisp code (via prepare_menu_bars). */
12110 select_frame_for_redisplay (old_frame
);
12113 reconsider_clip_changes (w
, current_buffer
);
12114 last_escape_glyph_frame
= NULL
;
12115 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12116 last_glyphless_glyph_frame
= NULL
;
12117 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12119 /* If new fonts have been loaded that make a glyph matrix adjustment
12120 necessary, do it. */
12121 if (fonts_changed_p
)
12123 adjust_glyphs (NULL
);
12124 ++windows_or_buffers_changed
;
12125 fonts_changed_p
= 0;
12128 /* If face_change_count is non-zero, init_iterator will free all
12129 realized faces, which includes the faces referenced from current
12130 matrices. So, we can't reuse current matrices in this case. */
12131 if (face_change_count
)
12132 ++windows_or_buffers_changed
;
12134 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12135 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12137 /* Since frames on a single ASCII terminal share the same
12138 display area, displaying a different frame means redisplay
12139 the whole thing. */
12140 windows_or_buffers_changed
++;
12141 SET_FRAME_GARBAGED (sf
);
12143 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12145 FRAME_TTY (sf
)->previous_frame
= sf
;
12148 /* Set the visible flags for all frames. Do this before checking
12149 for resized or garbaged frames; they want to know if their frames
12150 are visible. See the comment in frame.h for
12151 FRAME_SAMPLE_VISIBILITY. */
12153 Lisp_Object tail
, frame
;
12155 number_of_visible_frames
= 0;
12157 FOR_EACH_FRAME (tail
, frame
)
12159 struct frame
*f
= XFRAME (frame
);
12161 FRAME_SAMPLE_VISIBILITY (f
);
12162 if (FRAME_VISIBLE_P (f
))
12163 ++number_of_visible_frames
;
12164 clear_desired_matrices (f
);
12168 /* Notice any pending interrupt request to change frame size. */
12169 do_pending_window_change (1);
12171 /* do_pending_window_change could change the selected_window due to
12172 frame resizing which makes the selected window too small. */
12173 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12176 reconsider_clip_changes (w
, current_buffer
);
12179 /* Clear frames marked as garbaged. */
12180 if (frame_garbaged
)
12181 clear_garbaged_frames ();
12183 /* Build menubar and tool-bar items. */
12184 if (NILP (Vmemory_full
))
12185 prepare_menu_bars ();
12187 if (windows_or_buffers_changed
)
12188 update_mode_lines
++;
12190 /* Detect case that we need to write or remove a star in the mode line. */
12191 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
12193 w
->update_mode_line
= Qt
;
12194 if (buffer_shared
> 1)
12195 update_mode_lines
++;
12198 /* Avoid invocation of point motion hooks by `current_column' below. */
12199 count1
= SPECPDL_INDEX ();
12200 specbind (Qinhibit_point_motion_hooks
, Qt
);
12202 /* If %c is in the mode line, update it if needed. */
12203 if (!NILP (w
->column_number_displayed
)
12204 /* This alternative quickly identifies a common case
12205 where no change is needed. */
12206 && !(PT
== XFASTINT (w
->last_point
)
12207 && XFASTINT (w
->last_modified
) >= MODIFF
12208 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12209 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
12210 w
->update_mode_line
= Qt
;
12212 unbind_to (count1
, Qnil
);
12214 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
12216 /* The variable buffer_shared is set in redisplay_window and
12217 indicates that we redisplay a buffer in different windows. See
12219 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
12220 || cursor_type_changed
);
12222 /* If specs for an arrow have changed, do thorough redisplay
12223 to ensure we remove any arrow that should no longer exist. */
12224 if (overlay_arrows_changed_p ())
12225 consider_all_windows_p
= windows_or_buffers_changed
= 1;
12227 /* Normally the message* functions will have already displayed and
12228 updated the echo area, but the frame may have been trashed, or
12229 the update may have been preempted, so display the echo area
12230 again here. Checking message_cleared_p captures the case that
12231 the echo area should be cleared. */
12232 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
12233 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
12234 || (message_cleared_p
12235 && minibuf_level
== 0
12236 /* If the mini-window is currently selected, this means the
12237 echo-area doesn't show through. */
12238 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
12240 int window_height_changed_p
= echo_area_display (0);
12243 /* If we don't display the current message, don't clear the
12244 message_cleared_p flag, because, if we did, we wouldn't clear
12245 the echo area in the next redisplay which doesn't preserve
12247 if (!display_last_displayed_message_p
)
12248 message_cleared_p
= 0;
12250 if (fonts_changed_p
)
12252 else if (window_height_changed_p
)
12254 consider_all_windows_p
= 1;
12255 ++update_mode_lines
;
12256 ++windows_or_buffers_changed
;
12258 /* If window configuration was changed, frames may have been
12259 marked garbaged. Clear them or we will experience
12260 surprises wrt scrolling. */
12261 if (frame_garbaged
)
12262 clear_garbaged_frames ();
12265 else if (EQ (selected_window
, minibuf_window
)
12266 && (current_buffer
->clip_changed
12267 || XFASTINT (w
->last_modified
) < MODIFF
12268 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12269 && resize_mini_window (w
, 0))
12271 /* Resized active mini-window to fit the size of what it is
12272 showing if its contents might have changed. */
12274 /* FIXME: this causes all frames to be updated, which seems unnecessary
12275 since only the current frame needs to be considered. This function needs
12276 to be rewritten with two variables, consider_all_windows and
12277 consider_all_frames. */
12278 consider_all_windows_p
= 1;
12279 ++windows_or_buffers_changed
;
12280 ++update_mode_lines
;
12282 /* If window configuration was changed, frames may have been
12283 marked garbaged. Clear them or we will experience
12284 surprises wrt scrolling. */
12285 if (frame_garbaged
)
12286 clear_garbaged_frames ();
12290 /* If showing the region, and mark has changed, we must redisplay
12291 the whole window. The assignment to this_line_start_pos prevents
12292 the optimization directly below this if-statement. */
12293 if (((!NILP (Vtransient_mark_mode
)
12294 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
12295 != !NILP (w
->region_showing
))
12296 || (!NILP (w
->region_showing
)
12297 && !EQ (w
->region_showing
,
12298 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
12299 CHARPOS (this_line_start_pos
) = 0;
12301 /* Optimize the case that only the line containing the cursor in the
12302 selected window has changed. Variables starting with this_ are
12303 set in display_line and record information about the line
12304 containing the cursor. */
12305 tlbufpos
= this_line_start_pos
;
12306 tlendpos
= this_line_end_pos
;
12307 if (!consider_all_windows_p
12308 && CHARPOS (tlbufpos
) > 0
12309 && NILP (w
->update_mode_line
)
12310 && !current_buffer
->clip_changed
12311 && !current_buffer
->prevent_redisplay_optimizations_p
12312 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
12313 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
12314 /* Make sure recorded data applies to current buffer, etc. */
12315 && this_line_buffer
== current_buffer
12316 && current_buffer
== XBUFFER (w
->buffer
)
12317 && NILP (w
->force_start
)
12318 && NILP (w
->optional_new_start
)
12319 /* Point must be on the line that we have info recorded about. */
12320 && PT
>= CHARPOS (tlbufpos
)
12321 && PT
<= Z
- CHARPOS (tlendpos
)
12322 /* All text outside that line, including its final newline,
12323 must be unchanged. */
12324 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
12325 CHARPOS (tlendpos
)))
12327 if (CHARPOS (tlbufpos
) > BEGV
12328 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
12329 && (CHARPOS (tlbufpos
) == ZV
12330 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
12331 /* Former continuation line has disappeared by becoming empty. */
12333 else if (XFASTINT (w
->last_modified
) < MODIFF
12334 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
12335 || MINI_WINDOW_P (w
))
12337 /* We have to handle the case of continuation around a
12338 wide-column character (see the comment in indent.c around
12341 For instance, in the following case:
12343 -------- Insert --------
12344 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
12345 J_I_ ==> J_I_ `^^' are cursors.
12349 As we have to redraw the line above, we cannot use this
12353 int line_height_before
= this_line_pixel_height
;
12355 /* Note that start_display will handle the case that the
12356 line starting at tlbufpos is a continuation line. */
12357 start_display (&it
, w
, tlbufpos
);
12359 /* Implementation note: It this still necessary? */
12360 if (it
.current_x
!= this_line_start_x
)
12363 TRACE ((stderr
, "trying display optimization 1\n"));
12364 w
->cursor
.vpos
= -1;
12365 overlay_arrow_seen
= 0;
12366 it
.vpos
= this_line_vpos
;
12367 it
.current_y
= this_line_y
;
12368 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
12369 display_line (&it
);
12371 /* If line contains point, is not continued,
12372 and ends at same distance from eob as before, we win. */
12373 if (w
->cursor
.vpos
>= 0
12374 /* Line is not continued, otherwise this_line_start_pos
12375 would have been set to 0 in display_line. */
12376 && CHARPOS (this_line_start_pos
)
12377 /* Line ends as before. */
12378 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
12379 /* Line has same height as before. Otherwise other lines
12380 would have to be shifted up or down. */
12381 && this_line_pixel_height
== line_height_before
)
12383 /* If this is not the window's last line, we must adjust
12384 the charstarts of the lines below. */
12385 if (it
.current_y
< it
.last_visible_y
)
12387 struct glyph_row
*row
12388 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
12389 EMACS_INT delta
, delta_bytes
;
12391 /* We used to distinguish between two cases here,
12392 conditioned by Z - CHARPOS (tlendpos) == ZV, for
12393 when the line ends in a newline or the end of the
12394 buffer's accessible portion. But both cases did
12395 the same, so they were collapsed. */
12397 - CHARPOS (tlendpos
)
12398 - MATRIX_ROW_START_CHARPOS (row
));
12399 delta_bytes
= (Z_BYTE
12400 - BYTEPOS (tlendpos
)
12401 - MATRIX_ROW_START_BYTEPOS (row
));
12403 increment_matrix_positions (w
->current_matrix
,
12404 this_line_vpos
+ 1,
12405 w
->current_matrix
->nrows
,
12406 delta
, delta_bytes
);
12409 /* If this row displays text now but previously didn't,
12410 or vice versa, w->window_end_vpos may have to be
12412 if ((it
.glyph_row
- 1)->displays_text_p
)
12414 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
12415 XSETINT (w
->window_end_vpos
, this_line_vpos
);
12417 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
12418 && this_line_vpos
> 0)
12419 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
12420 w
->window_end_valid
= Qnil
;
12422 /* Update hint: No need to try to scroll in update_window. */
12423 w
->desired_matrix
->no_scrolling_p
= 1;
12426 *w
->desired_matrix
->method
= 0;
12427 debug_method_add (w
, "optimization 1");
12429 #ifdef HAVE_WINDOW_SYSTEM
12430 update_window_fringes (w
, 0);
12437 else if (/* Cursor position hasn't changed. */
12438 PT
== XFASTINT (w
->last_point
)
12439 /* Make sure the cursor was last displayed
12440 in this window. Otherwise we have to reposition it. */
12441 && 0 <= w
->cursor
.vpos
12442 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
12446 do_pending_window_change (1);
12447 /* If selected_window changed, redisplay again. */
12448 if (WINDOWP (selected_window
)
12449 && (w
= XWINDOW (selected_window
)) != sw
)
12452 /* We used to always goto end_of_redisplay here, but this
12453 isn't enough if we have a blinking cursor. */
12454 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
12455 goto end_of_redisplay
;
12459 /* If highlighting the region, or if the cursor is in the echo area,
12460 then we can't just move the cursor. */
12461 else if (! (!NILP (Vtransient_mark_mode
)
12462 && !NILP (BVAR (current_buffer
, mark_active
)))
12463 && (EQ (selected_window
, BVAR (current_buffer
, last_selected_window
))
12464 || highlight_nonselected_windows
)
12465 && NILP (w
->region_showing
)
12466 && NILP (Vshow_trailing_whitespace
)
12467 && !cursor_in_echo_area
)
12470 struct glyph_row
*row
;
12472 /* Skip from tlbufpos to PT and see where it is. Note that
12473 PT may be in invisible text. If so, we will end at the
12474 next visible position. */
12475 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
12476 NULL
, DEFAULT_FACE_ID
);
12477 it
.current_x
= this_line_start_x
;
12478 it
.current_y
= this_line_y
;
12479 it
.vpos
= this_line_vpos
;
12481 /* The call to move_it_to stops in front of PT, but
12482 moves over before-strings. */
12483 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
12485 if (it
.vpos
== this_line_vpos
12486 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12489 xassert (this_line_vpos
== it
.vpos
);
12490 xassert (this_line_y
== it
.current_y
);
12491 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12493 *w
->desired_matrix
->method
= 0;
12494 debug_method_add (w
, "optimization 3");
12503 /* Text changed drastically or point moved off of line. */
12504 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12507 CHARPOS (this_line_start_pos
) = 0;
12508 consider_all_windows_p
|= buffer_shared
> 1;
12509 ++clear_face_cache_count
;
12510 #ifdef HAVE_WINDOW_SYSTEM
12511 ++clear_image_cache_count
;
12514 /* Build desired matrices, and update the display. If
12515 consider_all_windows_p is non-zero, do it for all windows on all
12516 frames. Otherwise do it for selected_window, only. */
12518 if (consider_all_windows_p
)
12520 Lisp_Object tail
, frame
;
12522 FOR_EACH_FRAME (tail
, frame
)
12523 XFRAME (frame
)->updated_p
= 0;
12525 /* Recompute # windows showing selected buffer. This will be
12526 incremented each time such a window is displayed. */
12529 FOR_EACH_FRAME (tail
, frame
)
12531 struct frame
*f
= XFRAME (frame
);
12533 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12535 if (! EQ (frame
, selected_frame
))
12536 /* Select the frame, for the sake of frame-local
12538 select_frame_for_redisplay (frame
);
12540 /* Mark all the scroll bars to be removed; we'll redeem
12541 the ones we want when we redisplay their windows. */
12542 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12543 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12545 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12546 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12548 /* The X error handler may have deleted that frame. */
12549 if (!FRAME_LIVE_P (f
))
12552 /* Any scroll bars which redisplay_windows should have
12553 nuked should now go away. */
12554 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12555 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12557 /* If fonts changed, display again. */
12558 /* ??? rms: I suspect it is a mistake to jump all the way
12559 back to retry here. It should just retry this frame. */
12560 if (fonts_changed_p
)
12563 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12565 /* See if we have to hscroll. */
12566 if (!f
->already_hscrolled_p
)
12568 f
->already_hscrolled_p
= 1;
12569 if (hscroll_windows (f
->root_window
))
12573 /* Prevent various kinds of signals during display
12574 update. stdio is not robust about handling
12575 signals, which can cause an apparent I/O
12577 if (interrupt_input
)
12578 unrequest_sigio ();
12581 /* Update the display. */
12582 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12583 pending
|= update_frame (f
, 0, 0);
12589 if (!EQ (old_frame
, selected_frame
)
12590 && FRAME_LIVE_P (XFRAME (old_frame
)))
12591 /* We played a bit fast-and-loose above and allowed selected_frame
12592 and selected_window to be temporarily out-of-sync but let's make
12593 sure this stays contained. */
12594 select_frame_for_redisplay (old_frame
);
12595 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12599 /* Do the mark_window_display_accurate after all windows have
12600 been redisplayed because this call resets flags in buffers
12601 which are needed for proper redisplay. */
12602 FOR_EACH_FRAME (tail
, frame
)
12604 struct frame
*f
= XFRAME (frame
);
12607 mark_window_display_accurate (f
->root_window
, 1);
12608 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12609 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12614 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12616 Lisp_Object mini_window
;
12617 struct frame
*mini_frame
;
12619 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12620 /* Use list_of_error, not Qerror, so that
12621 we catch only errors and don't run the debugger. */
12622 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12624 redisplay_window_error
);
12626 /* Compare desired and current matrices, perform output. */
12629 /* If fonts changed, display again. */
12630 if (fonts_changed_p
)
12633 /* Prevent various kinds of signals during display update.
12634 stdio is not robust about handling signals,
12635 which can cause an apparent I/O error. */
12636 if (interrupt_input
)
12637 unrequest_sigio ();
12640 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12642 if (hscroll_windows (selected_window
))
12645 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12646 pending
= update_frame (sf
, 0, 0);
12649 /* We may have called echo_area_display at the top of this
12650 function. If the echo area is on another frame, that may
12651 have put text on a frame other than the selected one, so the
12652 above call to update_frame would not have caught it. Catch
12654 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12655 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12657 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12659 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12660 pending
|= update_frame (mini_frame
, 0, 0);
12661 if (!pending
&& hscroll_windows (mini_window
))
12666 /* If display was paused because of pending input, make sure we do a
12667 thorough update the next time. */
12670 /* Prevent the optimization at the beginning of
12671 redisplay_internal that tries a single-line update of the
12672 line containing the cursor in the selected window. */
12673 CHARPOS (this_line_start_pos
) = 0;
12675 /* Let the overlay arrow be updated the next time. */
12676 update_overlay_arrows (0);
12678 /* If we pause after scrolling, some rows in the current
12679 matrices of some windows are not valid. */
12680 if (!WINDOW_FULL_WIDTH_P (w
)
12681 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12682 update_mode_lines
= 1;
12686 if (!consider_all_windows_p
)
12688 /* This has already been done above if
12689 consider_all_windows_p is set. */
12690 mark_window_display_accurate_1 (w
, 1);
12692 /* Say overlay arrows are up to date. */
12693 update_overlay_arrows (1);
12695 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12696 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12699 update_mode_lines
= 0;
12700 windows_or_buffers_changed
= 0;
12701 cursor_type_changed
= 0;
12704 /* Start SIGIO interrupts coming again. Having them off during the
12705 code above makes it less likely one will discard output, but not
12706 impossible, since there might be stuff in the system buffer here.
12707 But it is much hairier to try to do anything about that. */
12708 if (interrupt_input
)
12712 /* If a frame has become visible which was not before, redisplay
12713 again, so that we display it. Expose events for such a frame
12714 (which it gets when becoming visible) don't call the parts of
12715 redisplay constructing glyphs, so simply exposing a frame won't
12716 display anything in this case. So, we have to display these
12717 frames here explicitly. */
12720 Lisp_Object tail
, frame
;
12723 FOR_EACH_FRAME (tail
, frame
)
12725 int this_is_visible
= 0;
12727 if (XFRAME (frame
)->visible
)
12728 this_is_visible
= 1;
12729 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12730 if (XFRAME (frame
)->visible
)
12731 this_is_visible
= 1;
12733 if (this_is_visible
)
12737 if (new_count
!= number_of_visible_frames
)
12738 windows_or_buffers_changed
++;
12741 /* Change frame size now if a change is pending. */
12742 do_pending_window_change (1);
12744 /* If we just did a pending size change, or have additional
12745 visible frames, or selected_window changed, redisplay again. */
12746 if ((windows_or_buffers_changed
&& !pending
)
12747 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
12750 /* Clear the face and image caches.
12752 We used to do this only if consider_all_windows_p. But the cache
12753 needs to be cleared if a timer creates images in the current
12754 buffer (e.g. the test case in Bug#6230). */
12756 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12758 clear_face_cache (0);
12759 clear_face_cache_count
= 0;
12762 #ifdef HAVE_WINDOW_SYSTEM
12763 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12765 clear_image_caches (Qnil
);
12766 clear_image_cache_count
= 0;
12768 #endif /* HAVE_WINDOW_SYSTEM */
12771 unbind_to (count
, Qnil
);
12776 /* Redisplay, but leave alone any recent echo area message unless
12777 another message has been requested in its place.
12779 This is useful in situations where you need to redisplay but no
12780 user action has occurred, making it inappropriate for the message
12781 area to be cleared. See tracking_off and
12782 wait_reading_process_output for examples of these situations.
12784 FROM_WHERE is an integer saying from where this function was
12785 called. This is useful for debugging. */
12788 redisplay_preserve_echo_area (int from_where
)
12790 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12792 if (!NILP (echo_area_buffer
[1]))
12794 /* We have a previously displayed message, but no current
12795 message. Redisplay the previous message. */
12796 display_last_displayed_message_p
= 1;
12797 redisplay_internal ();
12798 display_last_displayed_message_p
= 0;
12801 redisplay_internal ();
12803 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12804 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12805 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12809 /* Function registered with record_unwind_protect in
12810 redisplay_internal. Reset redisplaying_p to the value it had
12811 before redisplay_internal was called, and clear
12812 prevent_freeing_realized_faces_p. It also selects the previously
12813 selected frame, unless it has been deleted (by an X connection
12814 failure during redisplay, for example). */
12817 unwind_redisplay (Lisp_Object val
)
12819 Lisp_Object old_redisplaying_p
, old_frame
;
12821 old_redisplaying_p
= XCAR (val
);
12822 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12823 old_frame
= XCDR (val
);
12824 if (! EQ (old_frame
, selected_frame
)
12825 && FRAME_LIVE_P (XFRAME (old_frame
)))
12826 select_frame_for_redisplay (old_frame
);
12831 /* Mark the display of window W as accurate or inaccurate. If
12832 ACCURATE_P is non-zero mark display of W as accurate. If
12833 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12834 redisplay_internal is called. */
12837 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
12839 if (BUFFERP (w
->buffer
))
12841 struct buffer
*b
= XBUFFER (w
->buffer
);
12844 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12845 w
->last_overlay_modified
12846 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12848 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12852 b
->clip_changed
= 0;
12853 b
->prevent_redisplay_optimizations_p
= 0;
12855 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12856 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12857 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12858 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12860 w
->current_matrix
->buffer
= b
;
12861 w
->current_matrix
->begv
= BUF_BEGV (b
);
12862 w
->current_matrix
->zv
= BUF_ZV (b
);
12864 w
->last_cursor
= w
->cursor
;
12865 w
->last_cursor_off_p
= w
->cursor_off_p
;
12867 if (w
== XWINDOW (selected_window
))
12868 w
->last_point
= make_number (BUF_PT (b
));
12870 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12876 w
->window_end_valid
= w
->buffer
;
12877 w
->update_mode_line
= Qnil
;
12882 /* Mark the display of windows in the window tree rooted at WINDOW as
12883 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12884 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12885 be redisplayed the next time redisplay_internal is called. */
12888 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
12892 for (; !NILP (window
); window
= w
->next
)
12894 w
= XWINDOW (window
);
12895 mark_window_display_accurate_1 (w
, accurate_p
);
12897 if (!NILP (w
->vchild
))
12898 mark_window_display_accurate (w
->vchild
, accurate_p
);
12899 if (!NILP (w
->hchild
))
12900 mark_window_display_accurate (w
->hchild
, accurate_p
);
12905 update_overlay_arrows (1);
12909 /* Force a thorough redisplay the next time by setting
12910 last_arrow_position and last_arrow_string to t, which is
12911 unequal to any useful value of Voverlay_arrow_... */
12912 update_overlay_arrows (-1);
12917 /* Return value in display table DP (Lisp_Char_Table *) for character
12918 C. Since a display table doesn't have any parent, we don't have to
12919 follow parent. Do not call this function directly but use the
12920 macro DISP_CHAR_VECTOR. */
12923 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
12927 if (ASCII_CHAR_P (c
))
12930 if (SUB_CHAR_TABLE_P (val
))
12931 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12937 XSETCHAR_TABLE (table
, dp
);
12938 val
= char_table_ref (table
, c
);
12947 /***********************************************************************
12949 ***********************************************************************/
12951 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12954 redisplay_windows (Lisp_Object window
)
12956 while (!NILP (window
))
12958 struct window
*w
= XWINDOW (window
);
12960 if (!NILP (w
->hchild
))
12961 redisplay_windows (w
->hchild
);
12962 else if (!NILP (w
->vchild
))
12963 redisplay_windows (w
->vchild
);
12964 else if (!NILP (w
->buffer
))
12966 displayed_buffer
= XBUFFER (w
->buffer
);
12967 /* Use list_of_error, not Qerror, so that
12968 we catch only errors and don't run the debugger. */
12969 internal_condition_case_1 (redisplay_window_0
, window
,
12971 redisplay_window_error
);
12979 redisplay_window_error (Lisp_Object ignore
)
12981 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12986 redisplay_window_0 (Lisp_Object window
)
12988 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12989 redisplay_window (window
, 0);
12994 redisplay_window_1 (Lisp_Object window
)
12996 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12997 redisplay_window (window
, 1);
13002 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13003 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13004 which positions recorded in ROW differ from current buffer
13007 Return 0 if cursor is not on this row, 1 otherwise. */
13010 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13011 struct glyph_matrix
*matrix
,
13012 EMACS_INT delta
, EMACS_INT delta_bytes
,
13015 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13016 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13017 struct glyph
*cursor
= NULL
;
13018 /* The last known character position in row. */
13019 EMACS_INT last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13021 EMACS_INT pt_old
= PT
- delta
;
13022 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13023 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13024 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13025 /* A glyph beyond the edge of TEXT_AREA which we should never
13027 struct glyph
*glyphs_end
= end
;
13028 /* Non-zero means we've found a match for cursor position, but that
13029 glyph has the avoid_cursor_p flag set. */
13030 int match_with_avoid_cursor
= 0;
13031 /* Non-zero means we've seen at least one glyph that came from a
13033 int string_seen
= 0;
13034 /* Largest and smalles buffer positions seen so far during scan of
13036 EMACS_INT bpos_max
= pos_before
;
13037 EMACS_INT bpos_min
= pos_after
;
13038 /* Last buffer position covered by an overlay string with an integer
13039 `cursor' property. */
13040 EMACS_INT bpos_covered
= 0;
13042 /* Skip over glyphs not having an object at the start and the end of
13043 the row. These are special glyphs like truncation marks on
13044 terminal frames. */
13045 if (row
->displays_text_p
)
13047 if (!row
->reversed_p
)
13050 && INTEGERP (glyph
->object
)
13051 && glyph
->charpos
< 0)
13053 x
+= glyph
->pixel_width
;
13057 && INTEGERP ((end
- 1)->object
)
13058 /* CHARPOS is zero for blanks and stretch glyphs
13059 inserted by extend_face_to_end_of_line. */
13060 && (end
- 1)->charpos
<= 0)
13062 glyph_before
= glyph
- 1;
13069 /* If the glyph row is reversed, we need to process it from back
13070 to front, so swap the edge pointers. */
13071 glyphs_end
= end
= glyph
- 1;
13072 glyph
+= row
->used
[TEXT_AREA
] - 1;
13074 while (glyph
> end
+ 1
13075 && INTEGERP (glyph
->object
)
13076 && glyph
->charpos
< 0)
13079 x
-= glyph
->pixel_width
;
13081 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13083 /* By default, in reversed rows we put the cursor on the
13084 rightmost (first in the reading order) glyph. */
13085 for (g
= end
+ 1; g
< glyph
; g
++)
13086 x
+= g
->pixel_width
;
13088 && INTEGERP ((end
+ 1)->object
)
13089 && (end
+ 1)->charpos
<= 0)
13091 glyph_before
= glyph
+ 1;
13095 else if (row
->reversed_p
)
13097 /* In R2L rows that don't display text, put the cursor on the
13098 rightmost glyph. Case in point: an empty last line that is
13099 part of an R2L paragraph. */
13101 /* Avoid placing the cursor on the last glyph of the row, where
13102 on terminal frames we hold the vertical border between
13103 adjacent windows. */
13104 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13105 && !WINDOW_RIGHTMOST_P (w
)
13106 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13108 x
= -1; /* will be computed below, at label compute_x */
13111 /* Step 1: Try to find the glyph whose character position
13112 corresponds to point. If that's not possible, find 2 glyphs
13113 whose character positions are the closest to point, one before
13114 point, the other after it. */
13115 if (!row
->reversed_p
)
13116 while (/* not marched to end of glyph row */
13118 /* glyph was not inserted by redisplay for internal purposes */
13119 && !INTEGERP (glyph
->object
))
13121 if (BUFFERP (glyph
->object
))
13123 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
13125 if (glyph
->charpos
> bpos_max
)
13126 bpos_max
= glyph
->charpos
;
13127 if (glyph
->charpos
< bpos_min
)
13128 bpos_min
= glyph
->charpos
;
13129 if (!glyph
->avoid_cursor_p
)
13131 /* If we hit point, we've found the glyph on which to
13132 display the cursor. */
13135 match_with_avoid_cursor
= 0;
13138 /* See if we've found a better approximation to
13139 POS_BEFORE or to POS_AFTER. Note that we want the
13140 first (leftmost) glyph of all those that are the
13141 closest from below, and the last (rightmost) of all
13142 those from above. */
13143 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13145 pos_before
= glyph
->charpos
;
13146 glyph_before
= glyph
;
13148 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13150 pos_after
= glyph
->charpos
;
13151 glyph_after
= glyph
;
13154 else if (dpos
== 0)
13155 match_with_avoid_cursor
= 1;
13157 else if (STRINGP (glyph
->object
))
13159 Lisp_Object chprop
;
13160 EMACS_INT glyph_pos
= glyph
->charpos
;
13162 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13164 if (INTEGERP (chprop
))
13166 bpos_covered
= bpos_max
+ XINT (chprop
);
13167 /* If the `cursor' property covers buffer positions up
13168 to and including point, we should display cursor on
13169 this glyph. Note that overlays and text properties
13170 with string values stop bidi reordering, so every
13171 buffer position to the left of the string is always
13172 smaller than any position to the right of the
13173 string. Therefore, if a `cursor' property on one
13174 of the string's characters has an integer value, we
13175 will break out of the loop below _before_ we get to
13176 the position match above. IOW, integer values of
13177 the `cursor' property override the "exact match for
13178 point" strategy of positioning the cursor. */
13179 /* Implementation note: bpos_max == pt_old when, e.g.,
13180 we are in an empty line, where bpos_max is set to
13181 MATRIX_ROW_START_CHARPOS, see above. */
13182 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13191 x
+= glyph
->pixel_width
;
13194 else if (glyph
> end
) /* row is reversed */
13195 while (!INTEGERP (glyph
->object
))
13197 if (BUFFERP (glyph
->object
))
13199 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
13201 if (glyph
->charpos
> bpos_max
)
13202 bpos_max
= glyph
->charpos
;
13203 if (glyph
->charpos
< bpos_min
)
13204 bpos_min
= glyph
->charpos
;
13205 if (!glyph
->avoid_cursor_p
)
13209 match_with_avoid_cursor
= 0;
13212 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13214 pos_before
= glyph
->charpos
;
13215 glyph_before
= glyph
;
13217 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13219 pos_after
= glyph
->charpos
;
13220 glyph_after
= glyph
;
13223 else if (dpos
== 0)
13224 match_with_avoid_cursor
= 1;
13226 else if (STRINGP (glyph
->object
))
13228 Lisp_Object chprop
;
13229 EMACS_INT glyph_pos
= glyph
->charpos
;
13231 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13233 if (INTEGERP (chprop
))
13235 bpos_covered
= bpos_max
+ XINT (chprop
);
13236 /* If the `cursor' property covers buffer positions up
13237 to and including point, we should display cursor on
13239 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13248 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
13250 x
--; /* can't use any pixel_width */
13253 x
-= glyph
->pixel_width
;
13256 /* Step 2: If we didn't find an exact match for point, we need to
13257 look for a proper place to put the cursor among glyphs between
13258 GLYPH_BEFORE and GLYPH_AFTER. */
13259 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13260 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13261 && bpos_covered
< pt_old
)
13263 /* An empty line has a single glyph whose OBJECT is zero and
13264 whose CHARPOS is the position of a newline on that line.
13265 Note that on a TTY, there are more glyphs after that, which
13266 were produced by extend_face_to_end_of_line, but their
13267 CHARPOS is zero or negative. */
13269 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13270 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
13272 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
13274 EMACS_INT ellipsis_pos
;
13276 /* Scan back over the ellipsis glyphs. */
13277 if (!row
->reversed_p
)
13279 ellipsis_pos
= (glyph
- 1)->charpos
;
13280 while (glyph
> row
->glyphs
[TEXT_AREA
]
13281 && (glyph
- 1)->charpos
== ellipsis_pos
)
13282 glyph
--, x
-= glyph
->pixel_width
;
13283 /* That loop always goes one position too far, including
13284 the glyph before the ellipsis. So scan forward over
13286 x
+= glyph
->pixel_width
;
13289 else /* row is reversed */
13291 ellipsis_pos
= (glyph
+ 1)->charpos
;
13292 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
13293 && (glyph
+ 1)->charpos
== ellipsis_pos
)
13294 glyph
++, x
+= glyph
->pixel_width
;
13295 x
-= glyph
->pixel_width
;
13299 else if (match_with_avoid_cursor
13300 /* A truncated row may not include PT among its
13301 character positions. Setting the cursor inside the
13302 scroll margin will trigger recalculation of hscroll
13303 in hscroll_window_tree. */
13304 || (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
13305 || (row
->truncated_on_right_p
&& pt_old
> bpos_max
)
13306 /* Zero-width characters produce no glyphs. */
13309 && (row
->reversed_p
13310 ? glyph_after
> glyphs_end
13311 : glyph_after
< glyphs_end
)))
13313 cursor
= glyph_after
;
13316 else if (string_seen
)
13318 int incr
= row
->reversed_p
? -1 : +1;
13320 /* Need to find the glyph that came out of a string which is
13321 present at point. That glyph is somewhere between
13322 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
13323 positioned between POS_BEFORE and POS_AFTER in the
13325 struct glyph
*start
, *stop
;
13326 EMACS_INT pos
= pos_before
;
13330 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
13331 correspond to POS_BEFORE and POS_AFTER, respectively. We
13332 need START and STOP in the order that corresponds to the
13333 row's direction as given by its reversed_p flag. If the
13334 directionality of characters between POS_BEFORE and
13335 POS_AFTER is the opposite of the row's base direction,
13336 these characters will have been reordered for display,
13337 and we need to reverse START and STOP. */
13338 if (!row
->reversed_p
)
13340 start
= min (glyph_before
, glyph_after
);
13341 stop
= max (glyph_before
, glyph_after
);
13345 start
= max (glyph_before
, glyph_after
);
13346 stop
= min (glyph_before
, glyph_after
);
13348 for (glyph
= start
+ incr
;
13349 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
13352 /* Any glyphs that come from the buffer are here because
13353 of bidi reordering. Skip them, and only pay
13354 attention to glyphs that came from some string. */
13355 if (STRINGP (glyph
->object
))
13360 str
= glyph
->object
;
13361 tem
= string_buffer_position_lim (str
, pos
, pos_after
, 0);
13362 if (tem
== 0 /* from overlay */
13365 /* If the string from which this glyph came is
13366 found in the buffer at point, then we've
13367 found the glyph we've been looking for. If
13368 it comes from an overlay (tem == 0), and it
13369 has the `cursor' property on one of its
13370 glyphs, record that glyph as a candidate for
13371 displaying the cursor. (As in the
13372 unidirectional version, we will display the
13373 cursor on the last candidate we find.) */
13374 if (tem
== 0 || tem
== pt_old
)
13376 /* The glyphs from this string could have
13377 been reordered. Find the one with the
13378 smallest string position. Or there could
13379 be a character in the string with the
13380 `cursor' property, which means display
13381 cursor on that character's glyph. */
13382 EMACS_INT strpos
= glyph
->charpos
;
13387 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
13388 && EQ (glyph
->object
, str
);
13392 EMACS_INT gpos
= glyph
->charpos
;
13394 cprop
= Fget_char_property (make_number (gpos
),
13402 if (tem
&& glyph
->charpos
< strpos
)
13404 strpos
= glyph
->charpos
;
13413 pos
= tem
+ 1; /* don't find previous instances */
13415 /* This string is not what we want; skip all of the
13416 glyphs that came from it. */
13417 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
13418 && EQ (glyph
->object
, str
))
13425 /* If we reached the end of the line, and END was from a string,
13426 the cursor is not on this line. */
13428 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
13429 && STRINGP (end
->object
)
13430 && row
->continued_p
)
13436 if (cursor
!= NULL
)
13442 /* Need to compute x that corresponds to GLYPH. */
13443 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
13445 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
13447 x
+= g
->pixel_width
;
13451 /* ROW could be part of a continued line, which, under bidi
13452 reordering, might have other rows whose start and end charpos
13453 occlude point. Only set w->cursor if we found a better
13454 approximation to the cursor position than we have from previously
13455 examined candidate rows belonging to the same continued line. */
13456 if (/* we already have a candidate row */
13457 w
->cursor
.vpos
>= 0
13458 /* that candidate is not the row we are processing */
13459 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
13460 /* the row we are processing is part of a continued line */
13461 && (row
->continued_p
|| MATRIX_ROW_CONTINUATION_LINE_P (row
))
13462 /* Make sure cursor.vpos specifies a row whose start and end
13463 charpos occlude point. This is because some callers of this
13464 function leave cursor.vpos at the row where the cursor was
13465 displayed during the last redisplay cycle. */
13466 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
13467 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
13470 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
13472 /* Don't consider glyphs that are outside TEXT_AREA. */
13473 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
13475 /* Keep the candidate whose buffer position is the closest to
13477 if (/* previous candidate is a glyph in TEXT_AREA of that row */
13478 w
->cursor
.hpos
>= 0
13479 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
13480 && BUFFERP (g1
->object
)
13481 && (g1
->charpos
== pt_old
/* an exact match always wins */
13482 || (BUFFERP (glyph
->object
)
13483 && eabs (g1
->charpos
- pt_old
)
13484 < eabs (glyph
->charpos
- pt_old
))))
13486 /* If this candidate gives an exact match, use that. */
13487 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13488 /* Otherwise, keep the candidate that comes from a row
13489 spanning less buffer positions. This may win when one or
13490 both candidate positions are on glyphs that came from
13491 display strings, for which we cannot compare buffer
13493 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13494 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13495 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
13498 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
13500 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
13501 w
->cursor
.y
= row
->y
+ dy
;
13503 if (w
== XWINDOW (selected_window
))
13505 if (!row
->continued_p
13506 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
13509 this_line_buffer
= XBUFFER (w
->buffer
);
13511 CHARPOS (this_line_start_pos
)
13512 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
13513 BYTEPOS (this_line_start_pos
)
13514 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
13516 CHARPOS (this_line_end_pos
)
13517 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
13518 BYTEPOS (this_line_end_pos
)
13519 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
13521 this_line_y
= w
->cursor
.y
;
13522 this_line_pixel_height
= row
->height
;
13523 this_line_vpos
= w
->cursor
.vpos
;
13524 this_line_start_x
= row
->x
;
13527 CHARPOS (this_line_start_pos
) = 0;
13534 /* Run window scroll functions, if any, for WINDOW with new window
13535 start STARTP. Sets the window start of WINDOW to that position.
13537 We assume that the window's buffer is really current. */
13539 static INLINE
struct text_pos
13540 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
13542 struct window
*w
= XWINDOW (window
);
13543 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13545 if (current_buffer
!= XBUFFER (w
->buffer
))
13548 if (!NILP (Vwindow_scroll_functions
))
13550 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13551 make_number (CHARPOS (startp
)));
13552 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13553 /* In case the hook functions switch buffers. */
13554 if (current_buffer
!= XBUFFER (w
->buffer
))
13555 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13562 /* Make sure the line containing the cursor is fully visible.
13563 A value of 1 means there is nothing to be done.
13564 (Either the line is fully visible, or it cannot be made so,
13565 or we cannot tell.)
13567 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13568 is higher than window.
13570 A value of 0 means the caller should do scrolling
13571 as if point had gone off the screen. */
13574 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
13576 struct glyph_matrix
*matrix
;
13577 struct glyph_row
*row
;
13580 if (!make_cursor_line_fully_visible_p
)
13583 /* It's not always possible to find the cursor, e.g, when a window
13584 is full of overlay strings. Don't do anything in that case. */
13585 if (w
->cursor
.vpos
< 0)
13588 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13589 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13591 /* If the cursor row is not partially visible, there's nothing to do. */
13592 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13595 /* If the row the cursor is in is taller than the window's height,
13596 it's not clear what to do, so do nothing. */
13597 window_height
= window_box_height (w
);
13598 if (row
->height
>= window_height
)
13600 if (!force_p
|| MINI_WINDOW_P (w
)
13601 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13608 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13609 non-zero means only WINDOW is redisplayed in redisplay_internal.
13610 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
13611 in redisplay_window to bring a partially visible line into view in
13612 the case that only the cursor has moved.
13614 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13615 last screen line's vertical height extends past the end of the screen.
13619 1 if scrolling succeeded
13621 0 if scrolling didn't find point.
13623 -1 if new fonts have been loaded so that we must interrupt
13624 redisplay, adjust glyph matrices, and try again. */
13630 SCROLLING_NEED_LARGER_MATRICES
13633 /* If scroll-conservatively is more than this, never recenter.
13635 If you change this, don't forget to update the doc string of
13636 `scroll-conservatively' and the Emacs manual. */
13637 #define SCROLL_LIMIT 100
13640 try_scrolling (Lisp_Object window
, int just_this_one_p
,
13641 EMACS_INT arg_scroll_conservatively
, EMACS_INT scroll_step
,
13642 int temp_scroll_step
, int last_line_misfit
)
13644 struct window
*w
= XWINDOW (window
);
13645 struct frame
*f
= XFRAME (w
->frame
);
13646 struct text_pos pos
, startp
;
13648 int this_scroll_margin
, scroll_max
, rc
, height
;
13649 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13650 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13651 Lisp_Object aggressive
;
13652 /* We will never try scrolling more than this number of lines. */
13653 int scroll_limit
= SCROLL_LIMIT
;
13656 debug_method_add (w
, "try_scrolling");
13659 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13661 /* Compute scroll margin height in pixels. We scroll when point is
13662 within this distance from the top or bottom of the window. */
13663 if (scroll_margin
> 0)
13664 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13665 * FRAME_LINE_HEIGHT (f
);
13667 this_scroll_margin
= 0;
13669 /* Force arg_scroll_conservatively to have a reasonable value, to
13670 avoid scrolling too far away with slow move_it_* functions. Note
13671 that the user can supply scroll-conservatively equal to
13672 `most-positive-fixnum', which can be larger than INT_MAX. */
13673 if (arg_scroll_conservatively
> scroll_limit
)
13675 arg_scroll_conservatively
= scroll_limit
+ 1;
13676 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
13678 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
13679 /* Compute how much we should try to scroll maximally to bring
13680 point into view. */
13681 scroll_max
= (max (scroll_step
,
13682 max (arg_scroll_conservatively
, temp_scroll_step
))
13683 * FRAME_LINE_HEIGHT (f
));
13684 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
13685 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
13686 /* We're trying to scroll because of aggressive scrolling but no
13687 scroll_step is set. Choose an arbitrary one. */
13688 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13694 /* Decide whether to scroll down. */
13695 if (PT
> CHARPOS (startp
))
13697 int scroll_margin_y
;
13699 /* Compute the pixel ypos of the scroll margin, then move it to
13700 either that ypos or PT, whichever comes first. */
13701 start_display (&it
, w
, startp
);
13702 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13703 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13704 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13705 (MOVE_TO_POS
| MOVE_TO_Y
));
13707 if (PT
> CHARPOS (it
.current
.pos
))
13709 int y0
= line_bottom_y (&it
);
13710 /* Compute how many pixels below window bottom to stop searching
13711 for PT. This avoids costly search for PT that is far away if
13712 the user limited scrolling by a small number of lines, but
13713 always finds PT if scroll_conservatively is set to a large
13714 number, such as most-positive-fixnum. */
13715 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
13716 int y_to_move
= it
.last_visible_y
+ slack
;
13718 /* Compute the distance from the scroll margin to PT or to
13719 the scroll limit, whichever comes first. This should
13720 include the height of the cursor line, to make that line
13722 move_it_to (&it
, PT
, -1, y_to_move
,
13723 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13724 dy
= line_bottom_y (&it
) - y0
;
13726 if (dy
> scroll_max
)
13727 return SCROLLING_FAILED
;
13735 /* Point is in or below the bottom scroll margin, so move the
13736 window start down. If scrolling conservatively, move it just
13737 enough down to make point visible. If scroll_step is set,
13738 move it down by scroll_step. */
13739 if (arg_scroll_conservatively
)
13741 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13742 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
13743 else if (scroll_step
|| temp_scroll_step
)
13744 amount_to_scroll
= scroll_max
;
13747 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
13748 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13749 if (NUMBERP (aggressive
))
13751 double float_amount
= XFLOATINT (aggressive
) * height
;
13752 amount_to_scroll
= float_amount
;
13753 if (amount_to_scroll
== 0 && float_amount
> 0)
13754 amount_to_scroll
= 1;
13755 /* Don't let point enter the scroll margin near top of
13757 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13758 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13762 if (amount_to_scroll
<= 0)
13763 return SCROLLING_FAILED
;
13765 start_display (&it
, w
, startp
);
13766 if (arg_scroll_conservatively
<= scroll_limit
)
13767 move_it_vertically (&it
, amount_to_scroll
);
13770 /* Extra precision for users who set scroll-conservatively
13771 to a large number: make sure the amount we scroll
13772 the window start is never less than amount_to_scroll,
13773 which was computed as distance from window bottom to
13774 point. This matters when lines at window top and lines
13775 below window bottom have different height. */
13776 struct it it1
= it
;
13777 /* We use a temporary it1 because line_bottom_y can modify
13778 its argument, if it moves one line down; see there. */
13779 int start_y
= line_bottom_y (&it1
);
13782 move_it_by_lines (&it
, 1);
13784 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
13787 /* If STARTP is unchanged, move it down another screen line. */
13788 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13789 move_it_by_lines (&it
, 1);
13790 startp
= it
.current
.pos
;
13794 struct text_pos scroll_margin_pos
= startp
;
13796 /* See if point is inside the scroll margin at the top of the
13798 if (this_scroll_margin
)
13800 start_display (&it
, w
, startp
);
13801 move_it_vertically (&it
, this_scroll_margin
);
13802 scroll_margin_pos
= it
.current
.pos
;
13805 if (PT
< CHARPOS (scroll_margin_pos
))
13807 /* Point is in the scroll margin at the top of the window or
13808 above what is displayed in the window. */
13811 /* Compute the vertical distance from PT to the scroll
13812 margin position. Move as far as scroll_max allows, or
13813 one screenful, or 10 screen lines, whichever is largest.
13814 Give up if distance is greater than scroll_max. */
13815 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13816 start_display (&it
, w
, pos
);
13818 y_to_move
= max (it
.last_visible_y
,
13819 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
13820 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13822 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13823 dy
= it
.current_y
- y0
;
13824 if (dy
> scroll_max
)
13825 return SCROLLING_FAILED
;
13827 /* Compute new window start. */
13828 start_display (&it
, w
, startp
);
13830 if (arg_scroll_conservatively
)
13831 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
13832 max (scroll_step
, temp_scroll_step
));
13833 else if (scroll_step
|| temp_scroll_step
)
13834 amount_to_scroll
= scroll_max
;
13837 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
13838 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13839 if (NUMBERP (aggressive
))
13841 double float_amount
= XFLOATINT (aggressive
) * height
;
13842 amount_to_scroll
= float_amount
;
13843 if (amount_to_scroll
== 0 && float_amount
> 0)
13844 amount_to_scroll
= 1;
13845 amount_to_scroll
-=
13846 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
13847 /* Don't let point enter the scroll margin near
13848 bottom of the window. */
13849 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13850 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13854 if (amount_to_scroll
<= 0)
13855 return SCROLLING_FAILED
;
13857 move_it_vertically_backward (&it
, amount_to_scroll
);
13858 startp
= it
.current
.pos
;
13862 /* Run window scroll functions. */
13863 startp
= run_window_scroll_functions (window
, startp
);
13865 /* Display the window. Give up if new fonts are loaded, or if point
13867 if (!try_window (window
, startp
, 0))
13868 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13869 else if (w
->cursor
.vpos
< 0)
13871 clear_glyph_matrix (w
->desired_matrix
);
13872 rc
= SCROLLING_FAILED
;
13876 /* Maybe forget recorded base line for line number display. */
13877 if (!just_this_one_p
13878 || current_buffer
->clip_changed
13879 || BEG_UNCHANGED
< CHARPOS (startp
))
13880 w
->base_line_number
= Qnil
;
13882 /* If cursor ends up on a partially visible line,
13883 treat that as being off the bottom of the screen. */
13884 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
13885 /* It's possible that the cursor is on the first line of the
13886 buffer, which is partially obscured due to a vscroll
13887 (Bug#7537). In that case, avoid looping forever . */
13888 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
13890 clear_glyph_matrix (w
->desired_matrix
);
13891 ++extra_scroll_margin_lines
;
13894 rc
= SCROLLING_SUCCESS
;
13901 /* Compute a suitable window start for window W if display of W starts
13902 on a continuation line. Value is non-zero if a new window start
13905 The new window start will be computed, based on W's width, starting
13906 from the start of the continued line. It is the start of the
13907 screen line with the minimum distance from the old start W->start. */
13910 compute_window_start_on_continuation_line (struct window
*w
)
13912 struct text_pos pos
, start_pos
;
13913 int window_start_changed_p
= 0;
13915 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13917 /* If window start is on a continuation line... Window start may be
13918 < BEGV in case there's invisible text at the start of the
13919 buffer (M-x rmail, for example). */
13920 if (CHARPOS (start_pos
) > BEGV
13921 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13924 struct glyph_row
*row
;
13926 /* Handle the case that the window start is out of range. */
13927 if (CHARPOS (start_pos
) < BEGV
)
13928 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13929 else if (CHARPOS (start_pos
) > ZV
)
13930 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13932 /* Find the start of the continued line. This should be fast
13933 because scan_buffer is fast (newline cache). */
13934 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13935 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13936 row
, DEFAULT_FACE_ID
);
13937 reseat_at_previous_visible_line_start (&it
);
13939 /* If the line start is "too far" away from the window start,
13940 say it takes too much time to compute a new window start. */
13941 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13942 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13944 int min_distance
, distance
;
13946 /* Move forward by display lines to find the new window
13947 start. If window width was enlarged, the new start can
13948 be expected to be > the old start. If window width was
13949 decreased, the new window start will be < the old start.
13950 So, we're looking for the display line start with the
13951 minimum distance from the old window start. */
13952 pos
= it
.current
.pos
;
13953 min_distance
= INFINITY
;
13954 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13955 distance
< min_distance
)
13957 min_distance
= distance
;
13958 pos
= it
.current
.pos
;
13959 move_it_by_lines (&it
, 1);
13962 /* Set the window start there. */
13963 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13964 window_start_changed_p
= 1;
13968 return window_start_changed_p
;
13972 /* Try cursor movement in case text has not changed in window WINDOW,
13973 with window start STARTP. Value is
13975 CURSOR_MOVEMENT_SUCCESS if successful
13977 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13979 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13980 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13981 we want to scroll as if scroll-step were set to 1. See the code.
13983 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13984 which case we have to abort this redisplay, and adjust matrices
13989 CURSOR_MOVEMENT_SUCCESS
,
13990 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13991 CURSOR_MOVEMENT_MUST_SCROLL
,
13992 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13996 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
13998 struct window
*w
= XWINDOW (window
);
13999 struct frame
*f
= XFRAME (w
->frame
);
14000 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14003 if (inhibit_try_cursor_movement
)
14007 /* Handle case where text has not changed, only point, and it has
14008 not moved off the frame. */
14009 if (/* Point may be in this window. */
14010 PT
>= CHARPOS (startp
)
14011 /* Selective display hasn't changed. */
14012 && !current_buffer
->clip_changed
14013 /* Function force-mode-line-update is used to force a thorough
14014 redisplay. It sets either windows_or_buffers_changed or
14015 update_mode_lines. So don't take a shortcut here for these
14017 && !update_mode_lines
14018 && !windows_or_buffers_changed
14019 && !cursor_type_changed
14020 /* Can't use this case if highlighting a region. When a
14021 region exists, cursor movement has to do more than just
14023 && !(!NILP (Vtransient_mark_mode
)
14024 && !NILP (BVAR (current_buffer
, mark_active
)))
14025 && NILP (w
->region_showing
)
14026 && NILP (Vshow_trailing_whitespace
)
14027 /* Right after splitting windows, last_point may be nil. */
14028 && INTEGERP (w
->last_point
)
14029 /* This code is not used for mini-buffer for the sake of the case
14030 of redisplaying to replace an echo area message; since in
14031 that case the mini-buffer contents per se are usually
14032 unchanged. This code is of no real use in the mini-buffer
14033 since the handling of this_line_start_pos, etc., in redisplay
14034 handles the same cases. */
14035 && !EQ (window
, minibuf_window
)
14036 /* When splitting windows or for new windows, it happens that
14037 redisplay is called with a nil window_end_vpos or one being
14038 larger than the window. This should really be fixed in
14039 window.c. I don't have this on my list, now, so we do
14040 approximately the same as the old redisplay code. --gerd. */
14041 && INTEGERP (w
->window_end_vpos
)
14042 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14043 && (FRAME_WINDOW_P (f
)
14044 || !overlay_arrow_in_current_buffer_p ()))
14046 int this_scroll_margin
, top_scroll_margin
;
14047 struct glyph_row
*row
= NULL
;
14050 debug_method_add (w
, "cursor movement");
14053 /* Scroll if point within this distance from the top or bottom
14054 of the window. This is a pixel value. */
14055 if (scroll_margin
> 0)
14057 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14058 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14061 this_scroll_margin
= 0;
14063 top_scroll_margin
= this_scroll_margin
;
14064 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14065 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14067 /* Start with the row the cursor was displayed during the last
14068 not paused redisplay. Give up if that row is not valid. */
14069 if (w
->last_cursor
.vpos
< 0
14070 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
14071 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14074 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
14075 if (row
->mode_line_p
)
14077 if (!row
->enabled_p
)
14078 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14081 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14083 int scroll_p
= 0, must_scroll
= 0;
14084 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14086 if (PT
> XFASTINT (w
->last_point
))
14088 /* Point has moved forward. */
14089 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14090 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14092 xassert (row
->enabled_p
);
14096 /* If the end position of a row equals the start
14097 position of the next row, and PT is at that position,
14098 we would rather display cursor in the next line. */
14099 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14100 && MATRIX_ROW_END_CHARPOS (row
) == PT
14101 && row
< w
->current_matrix
->rows
14102 + w
->current_matrix
->nrows
- 1
14103 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14104 && !cursor_row_p (row
))
14107 /* If within the scroll margin, scroll. Note that
14108 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
14109 the next line would be drawn, and that
14110 this_scroll_margin can be zero. */
14111 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
14112 || PT
> MATRIX_ROW_END_CHARPOS (row
)
14113 /* Line is completely visible last line in window
14114 and PT is to be set in the next line. */
14115 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
14116 && PT
== MATRIX_ROW_END_CHARPOS (row
)
14117 && !row
->ends_at_zv_p
14118 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14121 else if (PT
< XFASTINT (w
->last_point
))
14123 /* Cursor has to be moved backward. Note that PT >=
14124 CHARPOS (startp) because of the outer if-statement. */
14125 while (!row
->mode_line_p
14126 && (MATRIX_ROW_START_CHARPOS (row
) > PT
14127 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14128 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
14129 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
14130 row
> w
->current_matrix
->rows
14131 && (row
-1)->ends_in_newline_from_string_p
))))
14132 && (row
->y
> top_scroll_margin
14133 || CHARPOS (startp
) == BEGV
))
14135 xassert (row
->enabled_p
);
14139 /* Consider the following case: Window starts at BEGV,
14140 there is invisible, intangible text at BEGV, so that
14141 display starts at some point START > BEGV. It can
14142 happen that we are called with PT somewhere between
14143 BEGV and START. Try to handle that case. */
14144 if (row
< w
->current_matrix
->rows
14145 || row
->mode_line_p
)
14147 row
= w
->current_matrix
->rows
;
14148 if (row
->mode_line_p
)
14152 /* Due to newlines in overlay strings, we may have to
14153 skip forward over overlay strings. */
14154 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14155 && MATRIX_ROW_END_CHARPOS (row
) == PT
14156 && !cursor_row_p (row
))
14159 /* If within the scroll margin, scroll. */
14160 if (row
->y
< top_scroll_margin
14161 && CHARPOS (startp
) != BEGV
)
14166 /* Cursor did not move. So don't scroll even if cursor line
14167 is partially visible, as it was so before. */
14168 rc
= CURSOR_MOVEMENT_SUCCESS
;
14171 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
14172 || PT
> MATRIX_ROW_END_CHARPOS (row
))
14174 /* if PT is not in the glyph row, give up. */
14175 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14178 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14179 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14181 /* If rows are bidi-reordered and point moved, back up
14182 until we find a row that does not belong to a
14183 continuation line. This is because we must consider
14184 all rows of a continued line as candidates for the
14185 new cursor positioning, since row start and end
14186 positions change non-linearly with vertical position
14188 /* FIXME: Revisit this when glyph ``spilling'' in
14189 continuation lines' rows is implemented for
14190 bidi-reordered rows. */
14191 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
14193 xassert (row
->enabled_p
);
14195 /* If we hit the beginning of the displayed portion
14196 without finding the first row of a continued
14198 if (row
<= w
->current_matrix
->rows
)
14200 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14208 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14209 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
14210 && make_cursor_line_fully_visible_p
)
14212 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
14213 && !row
->ends_at_zv_p
14214 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14215 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14216 else if (row
->height
> window_box_height (w
))
14218 /* If we end up in a partially visible line, let's
14219 make it fully visible, except when it's taller
14220 than the window, in which case we can't do much
14223 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14227 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14228 if (!cursor_row_fully_visible_p (w
, 0, 1))
14229 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14231 rc
= CURSOR_MOVEMENT_SUCCESS
;
14235 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14236 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14237 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14239 /* With bidi-reordered rows, there could be more than
14240 one candidate row whose start and end positions
14241 occlude point. We need to let set_cursor_from_row
14242 find the best candidate. */
14243 /* FIXME: Revisit this when glyph ``spilling'' in
14244 continuation lines' rows is implemented for
14245 bidi-reordered rows. */
14250 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
14251 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14252 && cursor_row_p (row
))
14253 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
14255 /* As soon as we've found the first suitable row
14256 whose ends_at_zv_p flag is set, we are done. */
14258 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
14260 rc
= CURSOR_MOVEMENT_SUCCESS
;
14265 while ((MATRIX_ROW_CONTINUATION_LINE_P (row
)
14266 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
14267 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14268 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
14269 /* If we didn't find any candidate rows, or exited the
14270 loop before all the candidates were examined, signal
14271 to the caller that this method failed. */
14272 if (rc
!= CURSOR_MOVEMENT_SUCCESS
14273 && (!rv
|| MATRIX_ROW_CONTINUATION_LINE_P (row
)))
14274 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14276 rc
= CURSOR_MOVEMENT_SUCCESS
;
14282 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
14284 rc
= CURSOR_MOVEMENT_SUCCESS
;
14289 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14290 && MATRIX_ROW_START_CHARPOS (row
) == PT
14291 && cursor_row_p (row
));
14299 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
14303 set_vertical_scroll_bar (struct window
*w
)
14305 EMACS_INT start
, end
, whole
;
14307 /* Calculate the start and end positions for the current window.
14308 At some point, it would be nice to choose between scrollbars
14309 which reflect the whole buffer size, with special markers
14310 indicating narrowing, and scrollbars which reflect only the
14313 Note that mini-buffers sometimes aren't displaying any text. */
14314 if (!MINI_WINDOW_P (w
)
14315 || (w
== XWINDOW (minibuf_window
)
14316 && NILP (echo_area_buffer
[0])))
14318 struct buffer
*buf
= XBUFFER (w
->buffer
);
14319 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
14320 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
14321 /* I don't think this is guaranteed to be right. For the
14322 moment, we'll pretend it is. */
14323 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
14327 if (whole
< (end
- start
))
14328 whole
= end
- start
;
14331 start
= end
= whole
= 0;
14333 /* Indicate what this scroll bar ought to be displaying now. */
14334 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
14335 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
14336 (w
, end
- start
, whole
, start
);
14340 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
14341 selected_window is redisplayed.
14343 We can return without actually redisplaying the window if
14344 fonts_changed_p is nonzero. In that case, redisplay_internal will
14348 redisplay_window (Lisp_Object window
, int just_this_one_p
)
14350 struct window
*w
= XWINDOW (window
);
14351 struct frame
*f
= XFRAME (w
->frame
);
14352 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14353 struct buffer
*old
= current_buffer
;
14354 struct text_pos lpoint
, opoint
, startp
;
14355 int update_mode_line
;
14358 /* Record it now because it's overwritten. */
14359 int current_matrix_up_to_date_p
= 0;
14360 int used_current_matrix_p
= 0;
14361 /* This is less strict than current_matrix_up_to_date_p.
14362 It indictes that the buffer contents and narrowing are unchanged. */
14363 int buffer_unchanged_p
= 0;
14364 int temp_scroll_step
= 0;
14365 int count
= SPECPDL_INDEX ();
14367 int centering_position
= -1;
14368 int last_line_misfit
= 0;
14369 EMACS_INT beg_unchanged
, end_unchanged
;
14371 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14374 /* W must be a leaf window here. */
14375 xassert (!NILP (w
->buffer
));
14377 *w
->desired_matrix
->method
= 0;
14381 reconsider_clip_changes (w
, buffer
);
14383 /* Has the mode line to be updated? */
14384 update_mode_line
= (!NILP (w
->update_mode_line
)
14385 || update_mode_lines
14386 || buffer
->clip_changed
14387 || buffer
->prevent_redisplay_optimizations_p
);
14389 if (MINI_WINDOW_P (w
))
14391 if (w
== XWINDOW (echo_area_window
)
14392 && !NILP (echo_area_buffer
[0]))
14394 if (update_mode_line
)
14395 /* We may have to update a tty frame's menu bar or a
14396 tool-bar. Example `M-x C-h C-h C-g'. */
14397 goto finish_menu_bars
;
14399 /* We've already displayed the echo area glyphs in this window. */
14400 goto finish_scroll_bars
;
14402 else if ((w
!= XWINDOW (minibuf_window
)
14403 || minibuf_level
== 0)
14404 /* When buffer is nonempty, redisplay window normally. */
14405 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
14406 /* Quail displays non-mini buffers in minibuffer window.
14407 In that case, redisplay the window normally. */
14408 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
14410 /* W is a mini-buffer window, but it's not active, so clear
14412 int yb
= window_text_bottom_y (w
);
14413 struct glyph_row
*row
;
14416 for (y
= 0, row
= w
->desired_matrix
->rows
;
14418 y
+= row
->height
, ++row
)
14419 blank_row (w
, row
, y
);
14420 goto finish_scroll_bars
;
14423 clear_glyph_matrix (w
->desired_matrix
);
14426 /* Otherwise set up data on this window; select its buffer and point
14428 /* Really select the buffer, for the sake of buffer-local
14430 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14432 current_matrix_up_to_date_p
14433 = (!NILP (w
->window_end_valid
)
14434 && !current_buffer
->clip_changed
14435 && !current_buffer
->prevent_redisplay_optimizations_p
14436 && XFASTINT (w
->last_modified
) >= MODIFF
14437 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
14439 /* Run the window-bottom-change-functions
14440 if it is possible that the text on the screen has changed
14441 (either due to modification of the text, or any other reason). */
14442 if (!current_matrix_up_to_date_p
14443 && !NILP (Vwindow_text_change_functions
))
14445 safe_run_hooks (Qwindow_text_change_functions
);
14449 beg_unchanged
= BEG_UNCHANGED
;
14450 end_unchanged
= END_UNCHANGED
;
14452 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
14454 specbind (Qinhibit_point_motion_hooks
, Qt
);
14457 = (!NILP (w
->window_end_valid
)
14458 && !current_buffer
->clip_changed
14459 && XFASTINT (w
->last_modified
) >= MODIFF
14460 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
14462 /* When windows_or_buffers_changed is non-zero, we can't rely on
14463 the window end being valid, so set it to nil there. */
14464 if (windows_or_buffers_changed
)
14466 /* If window starts on a continuation line, maybe adjust the
14467 window start in case the window's width changed. */
14468 if (XMARKER (w
->start
)->buffer
== current_buffer
)
14469 compute_window_start_on_continuation_line (w
);
14471 w
->window_end_valid
= Qnil
;
14474 /* Some sanity checks. */
14475 CHECK_WINDOW_END (w
);
14476 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
14478 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
14481 /* If %c is in mode line, update it if needed. */
14482 if (!NILP (w
->column_number_displayed
)
14483 /* This alternative quickly identifies a common case
14484 where no change is needed. */
14485 && !(PT
== XFASTINT (w
->last_point
)
14486 && XFASTINT (w
->last_modified
) >= MODIFF
14487 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
14488 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
14489 update_mode_line
= 1;
14491 /* Count number of windows showing the selected buffer. An indirect
14492 buffer counts as its base buffer. */
14493 if (!just_this_one_p
)
14495 struct buffer
*current_base
, *window_base
;
14496 current_base
= current_buffer
;
14497 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
14498 if (current_base
->base_buffer
)
14499 current_base
= current_base
->base_buffer
;
14500 if (window_base
->base_buffer
)
14501 window_base
= window_base
->base_buffer
;
14502 if (current_base
== window_base
)
14506 /* Point refers normally to the selected window. For any other
14507 window, set up appropriate value. */
14508 if (!EQ (window
, selected_window
))
14510 EMACS_INT new_pt
= XMARKER (w
->pointm
)->charpos
;
14511 EMACS_INT new_pt_byte
= marker_byte_position (w
->pointm
);
14515 new_pt_byte
= BEGV_BYTE
;
14516 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
14518 else if (new_pt
> (ZV
- 1))
14521 new_pt_byte
= ZV_BYTE
;
14522 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
14525 /* We don't use SET_PT so that the point-motion hooks don't run. */
14526 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
14529 /* If any of the character widths specified in the display table
14530 have changed, invalidate the width run cache. It's true that
14531 this may be a bit late to catch such changes, but the rest of
14532 redisplay goes (non-fatally) haywire when the display table is
14533 changed, so why should we worry about doing any better? */
14534 if (current_buffer
->width_run_cache
)
14536 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
14538 if (! disptab_matches_widthtab (disptab
,
14539 XVECTOR (BVAR (current_buffer
, width_table
))))
14541 invalidate_region_cache (current_buffer
,
14542 current_buffer
->width_run_cache
,
14544 recompute_width_table (current_buffer
, disptab
);
14548 /* If window-start is screwed up, choose a new one. */
14549 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
14552 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14554 /* If someone specified a new starting point but did not insist,
14555 check whether it can be used. */
14556 if (!NILP (w
->optional_new_start
)
14557 && CHARPOS (startp
) >= BEGV
14558 && CHARPOS (startp
) <= ZV
)
14560 w
->optional_new_start
= Qnil
;
14561 start_display (&it
, w
, startp
);
14562 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
14563 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14564 if (IT_CHARPOS (it
) == PT
)
14565 w
->force_start
= Qt
;
14566 /* IT may overshoot PT if text at PT is invisible. */
14567 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
14568 w
->force_start
= Qt
;
14573 /* Handle case where place to start displaying has been specified,
14574 unless the specified location is outside the accessible range. */
14575 if (!NILP (w
->force_start
)
14576 || w
->frozen_window_start_p
)
14578 /* We set this later on if we have to adjust point. */
14581 w
->force_start
= Qnil
;
14583 w
->window_end_valid
= Qnil
;
14585 /* Forget any recorded base line for line number display. */
14586 if (!buffer_unchanged_p
)
14587 w
->base_line_number
= Qnil
;
14589 /* Redisplay the mode line. Select the buffer properly for that.
14590 Also, run the hook window-scroll-functions
14591 because we have scrolled. */
14592 /* Note, we do this after clearing force_start because
14593 if there's an error, it is better to forget about force_start
14594 than to get into an infinite loop calling the hook functions
14595 and having them get more errors. */
14596 if (!update_mode_line
14597 || ! NILP (Vwindow_scroll_functions
))
14599 update_mode_line
= 1;
14600 w
->update_mode_line
= Qt
;
14601 startp
= run_window_scroll_functions (window
, startp
);
14604 w
->last_modified
= make_number (0);
14605 w
->last_overlay_modified
= make_number (0);
14606 if (CHARPOS (startp
) < BEGV
)
14607 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14608 else if (CHARPOS (startp
) > ZV
)
14609 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14611 /* Redisplay, then check if cursor has been set during the
14612 redisplay. Give up if new fonts were loaded. */
14613 /* We used to issue a CHECK_MARGINS argument to try_window here,
14614 but this causes scrolling to fail when point begins inside
14615 the scroll margin (bug#148) -- cyd */
14616 if (!try_window (window
, startp
, 0))
14618 w
->force_start
= Qt
;
14619 clear_glyph_matrix (w
->desired_matrix
);
14620 goto need_larger_matrices
;
14623 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14625 /* If point does not appear, try to move point so it does
14626 appear. The desired matrix has been built above, so we
14627 can use it here. */
14628 new_vpos
= window_box_height (w
) / 2;
14631 if (!cursor_row_fully_visible_p (w
, 0, 0))
14633 /* Point does appear, but on a line partly visible at end of window.
14634 Move it back to a fully-visible line. */
14635 new_vpos
= window_box_height (w
);
14638 /* If we need to move point for either of the above reasons,
14639 now actually do it. */
14642 struct glyph_row
*row
;
14644 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14645 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14648 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14649 MATRIX_ROW_START_BYTEPOS (row
));
14651 if (w
!= XWINDOW (selected_window
))
14652 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14653 else if (current_buffer
== old
)
14654 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14656 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14658 /* If we are highlighting the region, then we just changed
14659 the region, so redisplay to show it. */
14660 if (!NILP (Vtransient_mark_mode
)
14661 && !NILP (BVAR (current_buffer
, mark_active
)))
14663 clear_glyph_matrix (w
->desired_matrix
);
14664 if (!try_window (window
, startp
, 0))
14665 goto need_larger_matrices
;
14670 debug_method_add (w
, "forced window start");
14675 /* Handle case where text has not changed, only point, and it has
14676 not moved off the frame, and we are not retrying after hscroll.
14677 (current_matrix_up_to_date_p is nonzero when retrying.) */
14678 if (current_matrix_up_to_date_p
14679 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14680 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14684 case CURSOR_MOVEMENT_SUCCESS
:
14685 used_current_matrix_p
= 1;
14688 case CURSOR_MOVEMENT_MUST_SCROLL
:
14689 goto try_to_scroll
;
14695 /* If current starting point was originally the beginning of a line
14696 but no longer is, find a new starting point. */
14697 else if (!NILP (w
->start_at_line_beg
)
14698 && !(CHARPOS (startp
) <= BEGV
14699 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14702 debug_method_add (w
, "recenter 1");
14707 /* Try scrolling with try_window_id. Value is > 0 if update has
14708 been done, it is -1 if we know that the same window start will
14709 not work. It is 0 if unsuccessful for some other reason. */
14710 else if ((tem
= try_window_id (w
)) != 0)
14713 debug_method_add (w
, "try_window_id %d", tem
);
14716 if (fonts_changed_p
)
14717 goto need_larger_matrices
;
14721 /* Otherwise try_window_id has returned -1 which means that we
14722 don't want the alternative below this comment to execute. */
14724 else if (CHARPOS (startp
) >= BEGV
14725 && CHARPOS (startp
) <= ZV
14726 && PT
>= CHARPOS (startp
)
14727 && (CHARPOS (startp
) < ZV
14728 /* Avoid starting at end of buffer. */
14729 || CHARPOS (startp
) == BEGV
14730 || (XFASTINT (w
->last_modified
) >= MODIFF
14731 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14734 /* If first window line is a continuation line, and window start
14735 is inside the modified region, but the first change is before
14736 current window start, we must select a new window start.
14738 However, if this is the result of a down-mouse event (e.g. by
14739 extending the mouse-drag-overlay), we don't want to select a
14740 new window start, since that would change the position under
14741 the mouse, resulting in an unwanted mouse-movement rather
14742 than a simple mouse-click. */
14743 if (NILP (w
->start_at_line_beg
)
14744 && NILP (do_mouse_tracking
)
14745 && CHARPOS (startp
) > BEGV
14746 && CHARPOS (startp
) > BEG
+ beg_unchanged
14747 && CHARPOS (startp
) <= Z
- end_unchanged
14748 /* Even if w->start_at_line_beg is nil, a new window may
14749 start at a line_beg, since that's how set_buffer_window
14750 sets it. So, we need to check the return value of
14751 compute_window_start_on_continuation_line. (See also
14753 && XMARKER (w
->start
)->buffer
== current_buffer
14754 && compute_window_start_on_continuation_line (w
))
14756 w
->force_start
= Qt
;
14757 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14762 debug_method_add (w
, "same window start");
14765 /* Try to redisplay starting at same place as before.
14766 If point has not moved off frame, accept the results. */
14767 if (!current_matrix_up_to_date_p
14768 /* Don't use try_window_reusing_current_matrix in this case
14769 because a window scroll function can have changed the
14771 || !NILP (Vwindow_scroll_functions
)
14772 || MINI_WINDOW_P (w
)
14773 || !(used_current_matrix_p
14774 = try_window_reusing_current_matrix (w
)))
14776 IF_DEBUG (debug_method_add (w
, "1"));
14777 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
14778 /* -1 means we need to scroll.
14779 0 means we need new matrices, but fonts_changed_p
14780 is set in that case, so we will detect it below. */
14781 goto try_to_scroll
;
14784 if (fonts_changed_p
)
14785 goto need_larger_matrices
;
14787 if (w
->cursor
.vpos
>= 0)
14789 if (!just_this_one_p
14790 || current_buffer
->clip_changed
14791 || BEG_UNCHANGED
< CHARPOS (startp
))
14792 /* Forget any recorded base line for line number display. */
14793 w
->base_line_number
= Qnil
;
14795 if (!cursor_row_fully_visible_p (w
, 1, 0))
14797 clear_glyph_matrix (w
->desired_matrix
);
14798 last_line_misfit
= 1;
14800 /* Drop through and scroll. */
14805 clear_glyph_matrix (w
->desired_matrix
);
14810 w
->last_modified
= make_number (0);
14811 w
->last_overlay_modified
= make_number (0);
14813 /* Redisplay the mode line. Select the buffer properly for that. */
14814 if (!update_mode_line
)
14816 update_mode_line
= 1;
14817 w
->update_mode_line
= Qt
;
14820 /* Try to scroll by specified few lines. */
14821 if ((scroll_conservatively
14822 || emacs_scroll_step
14823 || temp_scroll_step
14824 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
14825 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
14826 && CHARPOS (startp
) >= BEGV
14827 && CHARPOS (startp
) <= ZV
)
14829 /* The function returns -1 if new fonts were loaded, 1 if
14830 successful, 0 if not successful. */
14831 int ss
= try_scrolling (window
, just_this_one_p
,
14832 scroll_conservatively
,
14834 temp_scroll_step
, last_line_misfit
);
14837 case SCROLLING_SUCCESS
:
14840 case SCROLLING_NEED_LARGER_MATRICES
:
14841 goto need_larger_matrices
;
14843 case SCROLLING_FAILED
:
14851 /* Finally, just choose a place to start which positions point
14852 according to user preferences. */
14857 debug_method_add (w
, "recenter");
14860 /* w->vscroll = 0; */
14862 /* Forget any previously recorded base line for line number display. */
14863 if (!buffer_unchanged_p
)
14864 w
->base_line_number
= Qnil
;
14866 /* Determine the window start relative to point. */
14867 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14868 it
.current_y
= it
.last_visible_y
;
14869 if (centering_position
< 0)
14873 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14875 EMACS_INT margin_pos
= CHARPOS (startp
);
14877 Lisp_Object aggressive
;
14879 /* If there is a scroll margin at the top of the window, find
14880 its character position. */
14882 /* Cannot call start_display if startp is not in the
14883 accessible region of the buffer. This can happen when we
14884 have just switched to a different buffer and/or changed
14885 its restriction. In that case, startp is initialized to
14886 the character position 1 (BEG) because we did not yet
14887 have chance to display the buffer even once. */
14888 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
14892 start_display (&it1
, w
, startp
);
14893 move_it_vertically (&it1
, margin
);
14894 margin_pos
= IT_CHARPOS (it1
);
14896 scrolling_up
= PT
> margin_pos
;
14899 ? BVAR (current_buffer
, scroll_up_aggressively
)
14900 : BVAR (current_buffer
, scroll_down_aggressively
);
14902 if (!MINI_WINDOW_P (w
)
14903 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
14907 /* Setting scroll-conservatively overrides
14908 scroll-*-aggressively. */
14909 if (!scroll_conservatively
&& NUMBERP (aggressive
))
14911 double float_amount
= XFLOATINT (aggressive
);
14913 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
14914 if (pt_offset
== 0 && float_amount
> 0)
14919 /* Compute how much to move the window start backward from
14920 point so that point will be displayed where the user
14924 centering_position
= it
.last_visible_y
;
14926 centering_position
-= pt_offset
;
14927 centering_position
-=
14928 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0));
14929 /* Don't let point enter the scroll margin near top of
14931 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
14932 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
14935 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
14938 /* Set the window start half the height of the window backward
14940 centering_position
= window_box_height (w
) / 2;
14942 move_it_vertically_backward (&it
, centering_position
);
14944 xassert (IT_CHARPOS (it
) >= BEGV
);
14946 /* The function move_it_vertically_backward may move over more
14947 than the specified y-distance. If it->w is small, e.g. a
14948 mini-buffer window, we may end up in front of the window's
14949 display area. Start displaying at the start of the line
14950 containing PT in this case. */
14951 if (it
.current_y
<= 0)
14953 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14954 move_it_vertically_backward (&it
, 0);
14958 it
.current_x
= it
.hpos
= 0;
14960 /* Set the window start position here explicitly, to avoid an
14961 infinite loop in case the functions in window-scroll-functions
14963 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14965 /* Run scroll hooks. */
14966 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14968 /* Redisplay the window. */
14969 if (!current_matrix_up_to_date_p
14970 || windows_or_buffers_changed
14971 || cursor_type_changed
14972 /* Don't use try_window_reusing_current_matrix in this case
14973 because it can have changed the buffer. */
14974 || !NILP (Vwindow_scroll_functions
)
14975 || !just_this_one_p
14976 || MINI_WINDOW_P (w
)
14977 || !(used_current_matrix_p
14978 = try_window_reusing_current_matrix (w
)))
14979 try_window (window
, startp
, 0);
14981 /* If new fonts have been loaded (due to fontsets), give up. We
14982 have to start a new redisplay since we need to re-adjust glyph
14984 if (fonts_changed_p
)
14985 goto need_larger_matrices
;
14987 /* If cursor did not appear assume that the middle of the window is
14988 in the first line of the window. Do it again with the next line.
14989 (Imagine a window of height 100, displaying two lines of height
14990 60. Moving back 50 from it->last_visible_y will end in the first
14992 if (w
->cursor
.vpos
< 0)
14994 if (!NILP (w
->window_end_valid
)
14995 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14997 clear_glyph_matrix (w
->desired_matrix
);
14998 move_it_by_lines (&it
, 1);
14999 try_window (window
, it
.current
.pos
, 0);
15001 else if (PT
< IT_CHARPOS (it
))
15003 clear_glyph_matrix (w
->desired_matrix
);
15004 move_it_by_lines (&it
, -1);
15005 try_window (window
, it
.current
.pos
, 0);
15009 /* Not much we can do about it. */
15013 /* Consider the following case: Window starts at BEGV, there is
15014 invisible, intangible text at BEGV, so that display starts at
15015 some point START > BEGV. It can happen that we are called with
15016 PT somewhere between BEGV and START. Try to handle that case. */
15017 if (w
->cursor
.vpos
< 0)
15019 struct glyph_row
*row
= w
->current_matrix
->rows
;
15020 if (row
->mode_line_p
)
15022 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15025 if (!cursor_row_fully_visible_p (w
, 0, 0))
15027 /* If vscroll is enabled, disable it and try again. */
15031 clear_glyph_matrix (w
->desired_matrix
);
15035 /* If centering point failed to make the whole line visible,
15036 put point at the top instead. That has to make the whole line
15037 visible, if it can be done. */
15038 if (centering_position
== 0)
15041 clear_glyph_matrix (w
->desired_matrix
);
15042 centering_position
= 0;
15048 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15049 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
15050 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
15053 /* Display the mode line, if we must. */
15054 if ((update_mode_line
15055 /* If window not full width, must redo its mode line
15056 if (a) the window to its side is being redone and
15057 (b) we do a frame-based redisplay. This is a consequence
15058 of how inverted lines are drawn in frame-based redisplay. */
15059 || (!just_this_one_p
15060 && !FRAME_WINDOW_P (f
)
15061 && !WINDOW_FULL_WIDTH_P (w
))
15062 /* Line number to display. */
15063 || INTEGERP (w
->base_line_pos
)
15064 /* Column number is displayed and different from the one displayed. */
15065 || (!NILP (w
->column_number_displayed
)
15066 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
15067 /* This means that the window has a mode line. */
15068 && (WINDOW_WANTS_MODELINE_P (w
)
15069 || WINDOW_WANTS_HEADER_LINE_P (w
)))
15071 display_mode_lines (w
);
15073 /* If mode line height has changed, arrange for a thorough
15074 immediate redisplay using the correct mode line height. */
15075 if (WINDOW_WANTS_MODELINE_P (w
)
15076 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
15078 fonts_changed_p
= 1;
15079 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
15080 = DESIRED_MODE_LINE_HEIGHT (w
);
15083 /* If header line height has changed, arrange for a thorough
15084 immediate redisplay using the correct header line height. */
15085 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15086 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
15088 fonts_changed_p
= 1;
15089 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
15090 = DESIRED_HEADER_LINE_HEIGHT (w
);
15093 if (fonts_changed_p
)
15094 goto need_larger_matrices
;
15097 if (!line_number_displayed
15098 && !BUFFERP (w
->base_line_pos
))
15100 w
->base_line_pos
= Qnil
;
15101 w
->base_line_number
= Qnil
;
15106 /* When we reach a frame's selected window, redo the frame's menu bar. */
15107 if (update_mode_line
15108 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
15110 int redisplay_menu_p
= 0;
15112 if (FRAME_WINDOW_P (f
))
15114 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
15115 || defined (HAVE_NS) || defined (USE_GTK)
15116 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
15118 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15122 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15124 if (redisplay_menu_p
)
15125 display_menu_bar (w
);
15127 #ifdef HAVE_WINDOW_SYSTEM
15128 if (FRAME_WINDOW_P (f
))
15130 #if defined (USE_GTK) || defined (HAVE_NS)
15131 if (FRAME_EXTERNAL_TOOL_BAR (f
))
15132 redisplay_tool_bar (f
);
15134 if (WINDOWP (f
->tool_bar_window
)
15135 && (FRAME_TOOL_BAR_LINES (f
) > 0
15136 || !NILP (Vauto_resize_tool_bars
))
15137 && redisplay_tool_bar (f
))
15138 ignore_mouse_drag_p
= 1;
15144 #ifdef HAVE_WINDOW_SYSTEM
15145 if (FRAME_WINDOW_P (f
)
15146 && update_window_fringes (w
, (just_this_one_p
15147 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
15148 || w
->pseudo_window_p
)))
15152 if (draw_window_fringes (w
, 1))
15153 x_draw_vertical_border (w
);
15157 #endif /* HAVE_WINDOW_SYSTEM */
15159 /* We go to this label, with fonts_changed_p nonzero,
15160 if it is necessary to try again using larger glyph matrices.
15161 We have to redeem the scroll bar even in this case,
15162 because the loop in redisplay_internal expects that. */
15163 need_larger_matrices
:
15165 finish_scroll_bars
:
15167 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
15169 /* Set the thumb's position and size. */
15170 set_vertical_scroll_bar (w
);
15172 /* Note that we actually used the scroll bar attached to this
15173 window, so it shouldn't be deleted at the end of redisplay. */
15174 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
15175 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
15178 /* Restore current_buffer and value of point in it. The window
15179 update may have changed the buffer, so first make sure `opoint'
15180 is still valid (Bug#6177). */
15181 if (CHARPOS (opoint
) < BEGV
)
15182 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15183 else if (CHARPOS (opoint
) > ZV
)
15184 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
15186 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
15188 set_buffer_internal_1 (old
);
15189 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
15190 shorter. This can be caused by log truncation in *Messages*. */
15191 if (CHARPOS (lpoint
) <= ZV
)
15192 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15194 unbind_to (count
, Qnil
);
15198 /* Build the complete desired matrix of WINDOW with a window start
15199 buffer position POS.
15201 Value is 1 if successful. It is zero if fonts were loaded during
15202 redisplay which makes re-adjusting glyph matrices necessary, and -1
15203 if point would appear in the scroll margins.
15204 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
15205 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
15209 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
15211 struct window
*w
= XWINDOW (window
);
15213 struct glyph_row
*last_text_row
= NULL
;
15214 struct frame
*f
= XFRAME (w
->frame
);
15216 /* Make POS the new window start. */
15217 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
15219 /* Mark cursor position as unknown. No overlay arrow seen. */
15220 w
->cursor
.vpos
= -1;
15221 overlay_arrow_seen
= 0;
15223 /* Initialize iterator and info to start at POS. */
15224 start_display (&it
, w
, pos
);
15226 /* Display all lines of W. */
15227 while (it
.current_y
< it
.last_visible_y
)
15229 if (display_line (&it
))
15230 last_text_row
= it
.glyph_row
- 1;
15231 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
15235 /* Don't let the cursor end in the scroll margins. */
15236 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
15237 && !MINI_WINDOW_P (w
))
15239 int this_scroll_margin
;
15241 if (scroll_margin
> 0)
15243 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15244 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15247 this_scroll_margin
= 0;
15249 if ((w
->cursor
.y
>= 0 /* not vscrolled */
15250 && w
->cursor
.y
< this_scroll_margin
15251 && CHARPOS (pos
) > BEGV
15252 && IT_CHARPOS (it
) < ZV
)
15253 /* rms: considering make_cursor_line_fully_visible_p here
15254 seems to give wrong results. We don't want to recenter
15255 when the last line is partly visible, we want to allow
15256 that case to be handled in the usual way. */
15257 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
15259 w
->cursor
.vpos
= -1;
15260 clear_glyph_matrix (w
->desired_matrix
);
15265 /* If bottom moved off end of frame, change mode line percentage. */
15266 if (XFASTINT (w
->window_end_pos
) <= 0
15267 && Z
!= IT_CHARPOS (it
))
15268 w
->update_mode_line
= Qt
;
15270 /* Set window_end_pos to the offset of the last character displayed
15271 on the window from the end of current_buffer. Set
15272 window_end_vpos to its row number. */
15275 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
15276 w
->window_end_bytepos
15277 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15279 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15281 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15282 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
15283 ->displays_text_p
);
15287 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
15288 w
->window_end_pos
= make_number (Z
- ZV
);
15289 w
->window_end_vpos
= make_number (0);
15292 /* But that is not valid info until redisplay finishes. */
15293 w
->window_end_valid
= Qnil
;
15299 /************************************************************************
15300 Window redisplay reusing current matrix when buffer has not changed
15301 ************************************************************************/
15303 /* Try redisplay of window W showing an unchanged buffer with a
15304 different window start than the last time it was displayed by
15305 reusing its current matrix. Value is non-zero if successful.
15306 W->start is the new window start. */
15309 try_window_reusing_current_matrix (struct window
*w
)
15311 struct frame
*f
= XFRAME (w
->frame
);
15312 struct glyph_row
*bottom_row
;
15315 struct text_pos start
, new_start
;
15316 int nrows_scrolled
, i
;
15317 struct glyph_row
*last_text_row
;
15318 struct glyph_row
*last_reused_text_row
;
15319 struct glyph_row
*start_row
;
15320 int start_vpos
, min_y
, max_y
;
15323 if (inhibit_try_window_reusing
)
15327 if (/* This function doesn't handle terminal frames. */
15328 !FRAME_WINDOW_P (f
)
15329 /* Don't try to reuse the display if windows have been split
15331 || windows_or_buffers_changed
15332 || cursor_type_changed
)
15335 /* Can't do this if region may have changed. */
15336 if ((!NILP (Vtransient_mark_mode
)
15337 && !NILP (BVAR (current_buffer
, mark_active
)))
15338 || !NILP (w
->region_showing
)
15339 || !NILP (Vshow_trailing_whitespace
))
15342 /* If top-line visibility has changed, give up. */
15343 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15344 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
15347 /* Give up if old or new display is scrolled vertically. We could
15348 make this function handle this, but right now it doesn't. */
15349 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15350 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
15353 /* The variable new_start now holds the new window start. The old
15354 start `start' can be determined from the current matrix. */
15355 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
15356 start
= start_row
->minpos
;
15357 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
15359 /* Clear the desired matrix for the display below. */
15360 clear_glyph_matrix (w
->desired_matrix
);
15362 if (CHARPOS (new_start
) <= CHARPOS (start
))
15364 /* Don't use this method if the display starts with an ellipsis
15365 displayed for invisible text. It's not easy to handle that case
15366 below, and it's certainly not worth the effort since this is
15367 not a frequent case. */
15368 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
15371 IF_DEBUG (debug_method_add (w
, "twu1"));
15373 /* Display up to a row that can be reused. The variable
15374 last_text_row is set to the last row displayed that displays
15375 text. Note that it.vpos == 0 if or if not there is a
15376 header-line; it's not the same as the MATRIX_ROW_VPOS! */
15377 start_display (&it
, w
, new_start
);
15378 w
->cursor
.vpos
= -1;
15379 last_text_row
= last_reused_text_row
= NULL
;
15381 while (it
.current_y
< it
.last_visible_y
15382 && !fonts_changed_p
)
15384 /* If we have reached into the characters in the START row,
15385 that means the line boundaries have changed. So we
15386 can't start copying with the row START. Maybe it will
15387 work to start copying with the following row. */
15388 while (IT_CHARPOS (it
) > CHARPOS (start
))
15390 /* Advance to the next row as the "start". */
15392 start
= start_row
->minpos
;
15393 /* If there are no more rows to try, or just one, give up. */
15394 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
15395 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
15396 || CHARPOS (start
) == ZV
)
15398 clear_glyph_matrix (w
->desired_matrix
);
15402 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
15404 /* If we have reached alignment,
15405 we can copy the rest of the rows. */
15406 if (IT_CHARPOS (it
) == CHARPOS (start
))
15409 if (display_line (&it
))
15410 last_text_row
= it
.glyph_row
- 1;
15413 /* A value of current_y < last_visible_y means that we stopped
15414 at the previous window start, which in turn means that we
15415 have at least one reusable row. */
15416 if (it
.current_y
< it
.last_visible_y
)
15418 struct glyph_row
*row
;
15420 /* IT.vpos always starts from 0; it counts text lines. */
15421 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
15423 /* Find PT if not already found in the lines displayed. */
15424 if (w
->cursor
.vpos
< 0)
15426 int dy
= it
.current_y
- start_row
->y
;
15428 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15429 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
15431 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
15432 dy
, nrows_scrolled
);
15435 clear_glyph_matrix (w
->desired_matrix
);
15440 /* Scroll the display. Do it before the current matrix is
15441 changed. The problem here is that update has not yet
15442 run, i.e. part of the current matrix is not up to date.
15443 scroll_run_hook will clear the cursor, and use the
15444 current matrix to get the height of the row the cursor is
15446 run
.current_y
= start_row
->y
;
15447 run
.desired_y
= it
.current_y
;
15448 run
.height
= it
.last_visible_y
- it
.current_y
;
15450 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
15453 FRAME_RIF (f
)->update_window_begin_hook (w
);
15454 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15455 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15456 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15460 /* Shift current matrix down by nrows_scrolled lines. */
15461 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15462 rotate_matrix (w
->current_matrix
,
15464 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15467 /* Disable lines that must be updated. */
15468 for (i
= 0; i
< nrows_scrolled
; ++i
)
15469 (start_row
+ i
)->enabled_p
= 0;
15471 /* Re-compute Y positions. */
15472 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15473 max_y
= it
.last_visible_y
;
15474 for (row
= start_row
+ nrows_scrolled
;
15478 row
->y
= it
.current_y
;
15479 row
->visible_height
= row
->height
;
15481 if (row
->y
< min_y
)
15482 row
->visible_height
-= min_y
- row
->y
;
15483 if (row
->y
+ row
->height
> max_y
)
15484 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15485 row
->redraw_fringe_bitmaps_p
= 1;
15487 it
.current_y
+= row
->height
;
15489 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15490 last_reused_text_row
= row
;
15491 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
15495 /* Disable lines in the current matrix which are now
15496 below the window. */
15497 for (++row
; row
< bottom_row
; ++row
)
15498 row
->enabled_p
= row
->mode_line_p
= 0;
15501 /* Update window_end_pos etc.; last_reused_text_row is the last
15502 reused row from the current matrix containing text, if any.
15503 The value of last_text_row is the last displayed line
15504 containing text. */
15505 if (last_reused_text_row
)
15507 w
->window_end_bytepos
15508 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
15510 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
15512 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
15513 w
->current_matrix
));
15515 else if (last_text_row
)
15517 w
->window_end_bytepos
15518 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15520 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15522 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15526 /* This window must be completely empty. */
15527 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
15528 w
->window_end_pos
= make_number (Z
- ZV
);
15529 w
->window_end_vpos
= make_number (0);
15531 w
->window_end_valid
= Qnil
;
15533 /* Update hint: don't try scrolling again in update_window. */
15534 w
->desired_matrix
->no_scrolling_p
= 1;
15537 debug_method_add (w
, "try_window_reusing_current_matrix 1");
15541 else if (CHARPOS (new_start
) > CHARPOS (start
))
15543 struct glyph_row
*pt_row
, *row
;
15544 struct glyph_row
*first_reusable_row
;
15545 struct glyph_row
*first_row_to_display
;
15547 int yb
= window_text_bottom_y (w
);
15549 /* Find the row starting at new_start, if there is one. Don't
15550 reuse a partially visible line at the end. */
15551 first_reusable_row
= start_row
;
15552 while (first_reusable_row
->enabled_p
15553 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
15554 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15555 < CHARPOS (new_start
)))
15556 ++first_reusable_row
;
15558 /* Give up if there is no row to reuse. */
15559 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
15560 || !first_reusable_row
->enabled_p
15561 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15562 != CHARPOS (new_start
)))
15565 /* We can reuse fully visible rows beginning with
15566 first_reusable_row to the end of the window. Set
15567 first_row_to_display to the first row that cannot be reused.
15568 Set pt_row to the row containing point, if there is any. */
15570 for (first_row_to_display
= first_reusable_row
;
15571 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
15572 ++first_row_to_display
)
15574 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
15575 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
15576 pt_row
= first_row_to_display
;
15579 /* Start displaying at the start of first_row_to_display. */
15580 xassert (first_row_to_display
->y
< yb
);
15581 init_to_row_start (&it
, w
, first_row_to_display
);
15583 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
15585 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
15587 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
15588 + WINDOW_HEADER_LINE_HEIGHT (w
));
15590 /* Display lines beginning with first_row_to_display in the
15591 desired matrix. Set last_text_row to the last row displayed
15592 that displays text. */
15593 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
15594 if (pt_row
== NULL
)
15595 w
->cursor
.vpos
= -1;
15596 last_text_row
= NULL
;
15597 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
15598 if (display_line (&it
))
15599 last_text_row
= it
.glyph_row
- 1;
15601 /* If point is in a reused row, adjust y and vpos of the cursor
15605 w
->cursor
.vpos
-= nrows_scrolled
;
15606 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
15609 /* Give up if point isn't in a row displayed or reused. (This
15610 also handles the case where w->cursor.vpos < nrows_scrolled
15611 after the calls to display_line, which can happen with scroll
15612 margins. See bug#1295.) */
15613 if (w
->cursor
.vpos
< 0)
15615 clear_glyph_matrix (w
->desired_matrix
);
15619 /* Scroll the display. */
15620 run
.current_y
= first_reusable_row
->y
;
15621 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15622 run
.height
= it
.last_visible_y
- run
.current_y
;
15623 dy
= run
.current_y
- run
.desired_y
;
15628 FRAME_RIF (f
)->update_window_begin_hook (w
);
15629 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15630 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15631 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15635 /* Adjust Y positions of reused rows. */
15636 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15637 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15638 max_y
= it
.last_visible_y
;
15639 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15642 row
->visible_height
= row
->height
;
15643 if (row
->y
< min_y
)
15644 row
->visible_height
-= min_y
- row
->y
;
15645 if (row
->y
+ row
->height
> max_y
)
15646 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15647 row
->redraw_fringe_bitmaps_p
= 1;
15650 /* Scroll the current matrix. */
15651 xassert (nrows_scrolled
> 0);
15652 rotate_matrix (w
->current_matrix
,
15654 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15657 /* Disable rows not reused. */
15658 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15659 row
->enabled_p
= 0;
15661 /* Point may have moved to a different line, so we cannot assume that
15662 the previous cursor position is valid; locate the correct row. */
15665 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15666 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15670 w
->cursor
.y
= row
->y
;
15672 if (row
< bottom_row
)
15674 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15675 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15677 /* Can't use this optimization with bidi-reordered glyph
15678 rows, unless cursor is already at point. */
15679 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15681 if (!(w
->cursor
.hpos
>= 0
15682 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
15683 && BUFFERP (glyph
->object
)
15684 && glyph
->charpos
== PT
))
15689 && (!BUFFERP (glyph
->object
)
15690 || glyph
->charpos
< PT
);
15694 w
->cursor
.x
+= glyph
->pixel_width
;
15699 /* Adjust window end. A null value of last_text_row means that
15700 the window end is in reused rows which in turn means that
15701 only its vpos can have changed. */
15704 w
->window_end_bytepos
15705 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15707 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15709 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15714 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15717 w
->window_end_valid
= Qnil
;
15718 w
->desired_matrix
->no_scrolling_p
= 1;
15721 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15731 /************************************************************************
15732 Window redisplay reusing current matrix when buffer has changed
15733 ************************************************************************/
15735 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
15736 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
15737 EMACS_INT
*, EMACS_INT
*);
15738 static struct glyph_row
*
15739 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
15740 struct glyph_row
*);
15743 /* Return the last row in MATRIX displaying text. If row START is
15744 non-null, start searching with that row. IT gives the dimensions
15745 of the display. Value is null if matrix is empty; otherwise it is
15746 a pointer to the row found. */
15748 static struct glyph_row
*
15749 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
15750 struct glyph_row
*start
)
15752 struct glyph_row
*row
, *row_found
;
15754 /* Set row_found to the last row in IT->w's current matrix
15755 displaying text. The loop looks funny but think of partially
15758 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15759 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15761 xassert (row
->enabled_p
);
15763 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15772 /* Return the last row in the current matrix of W that is not affected
15773 by changes at the start of current_buffer that occurred since W's
15774 current matrix was built. Value is null if no such row exists.
15776 BEG_UNCHANGED us the number of characters unchanged at the start of
15777 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15778 first changed character in current_buffer. Characters at positions <
15779 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15780 when the current matrix was built. */
15782 static struct glyph_row
*
15783 find_last_unchanged_at_beg_row (struct window
*w
)
15785 EMACS_INT first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15786 struct glyph_row
*row
;
15787 struct glyph_row
*row_found
= NULL
;
15788 int yb
= window_text_bottom_y (w
);
15790 /* Find the last row displaying unchanged text. */
15791 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15792 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15793 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15796 if (/* If row ends before first_changed_pos, it is unchanged,
15797 except in some case. */
15798 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15799 /* When row ends in ZV and we write at ZV it is not
15801 && !row
->ends_at_zv_p
15802 /* When first_changed_pos is the end of a continued line,
15803 row is not unchanged because it may be no longer
15805 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15806 && (row
->continued_p
15807 || row
->exact_window_width_line_p
)))
15810 /* Stop if last visible row. */
15811 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15819 /* Find the first glyph row in the current matrix of W that is not
15820 affected by changes at the end of current_buffer since the
15821 time W's current matrix was built.
15823 Return in *DELTA the number of chars by which buffer positions in
15824 unchanged text at the end of current_buffer must be adjusted.
15826 Return in *DELTA_BYTES the corresponding number of bytes.
15828 Value is null if no such row exists, i.e. all rows are affected by
15831 static struct glyph_row
*
15832 find_first_unchanged_at_end_row (struct window
*w
,
15833 EMACS_INT
*delta
, EMACS_INT
*delta_bytes
)
15835 struct glyph_row
*row
;
15836 struct glyph_row
*row_found
= NULL
;
15838 *delta
= *delta_bytes
= 0;
15840 /* Display must not have been paused, otherwise the current matrix
15841 is not up to date. */
15842 eassert (!NILP (w
->window_end_valid
));
15844 /* A value of window_end_pos >= END_UNCHANGED means that the window
15845 end is in the range of changed text. If so, there is no
15846 unchanged row at the end of W's current matrix. */
15847 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15850 /* Set row to the last row in W's current matrix displaying text. */
15851 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15853 /* If matrix is entirely empty, no unchanged row exists. */
15854 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15856 /* The value of row is the last glyph row in the matrix having a
15857 meaningful buffer position in it. The end position of row
15858 corresponds to window_end_pos. This allows us to translate
15859 buffer positions in the current matrix to current buffer
15860 positions for characters not in changed text. */
15862 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15863 EMACS_INT Z_BYTE_old
=
15864 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15865 EMACS_INT last_unchanged_pos
, last_unchanged_pos_old
;
15866 struct glyph_row
*first_text_row
15867 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15869 *delta
= Z
- Z_old
;
15870 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15872 /* Set last_unchanged_pos to the buffer position of the last
15873 character in the buffer that has not been changed. Z is the
15874 index + 1 of the last character in current_buffer, i.e. by
15875 subtracting END_UNCHANGED we get the index of the last
15876 unchanged character, and we have to add BEG to get its buffer
15878 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15879 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15881 /* Search backward from ROW for a row displaying a line that
15882 starts at a minimum position >= last_unchanged_pos_old. */
15883 for (; row
> first_text_row
; --row
)
15885 /* This used to abort, but it can happen.
15886 It is ok to just stop the search instead here. KFS. */
15887 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15890 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15895 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15901 /* Make sure that glyph rows in the current matrix of window W
15902 reference the same glyph memory as corresponding rows in the
15903 frame's frame matrix. This function is called after scrolling W's
15904 current matrix on a terminal frame in try_window_id and
15905 try_window_reusing_current_matrix. */
15908 sync_frame_with_window_matrix_rows (struct window
*w
)
15910 struct frame
*f
= XFRAME (w
->frame
);
15911 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15913 /* Preconditions: W must be a leaf window and full-width. Its frame
15914 must have a frame matrix. */
15915 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15916 xassert (WINDOW_FULL_WIDTH_P (w
));
15917 xassert (!FRAME_WINDOW_P (f
));
15919 /* If W is a full-width window, glyph pointers in W's current matrix
15920 have, by definition, to be the same as glyph pointers in the
15921 corresponding frame matrix. Note that frame matrices have no
15922 marginal areas (see build_frame_matrix). */
15923 window_row
= w
->current_matrix
->rows
;
15924 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15925 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15926 while (window_row
< window_row_end
)
15928 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15929 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15931 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15932 frame_row
->glyphs
[TEXT_AREA
] = start
;
15933 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15934 frame_row
->glyphs
[LAST_AREA
] = end
;
15936 /* Disable frame rows whose corresponding window rows have
15937 been disabled in try_window_id. */
15938 if (!window_row
->enabled_p
)
15939 frame_row
->enabled_p
= 0;
15941 ++window_row
, ++frame_row
;
15946 /* Find the glyph row in window W containing CHARPOS. Consider all
15947 rows between START and END (not inclusive). END null means search
15948 all rows to the end of the display area of W. Value is the row
15949 containing CHARPOS or null. */
15952 row_containing_pos (struct window
*w
, EMACS_INT charpos
,
15953 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
15955 struct glyph_row
*row
= start
;
15956 struct glyph_row
*best_row
= NULL
;
15957 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15960 /* If we happen to start on a header-line, skip that. */
15961 if (row
->mode_line_p
)
15964 if ((end
&& row
>= end
) || !row
->enabled_p
)
15967 last_y
= window_text_bottom_y (w
) - dy
;
15971 /* Give up if we have gone too far. */
15972 if (end
&& row
>= end
)
15974 /* This formerly returned if they were equal.
15975 I think that both quantities are of a "last plus one" type;
15976 if so, when they are equal, the row is within the screen. -- rms. */
15977 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15980 /* If it is in this row, return this row. */
15981 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15982 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15983 /* The end position of a row equals the start
15984 position of the next row. If CHARPOS is there, we
15985 would rather display it in the next line, except
15986 when this line ends in ZV. */
15987 && !row
->ends_at_zv_p
15988 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15989 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15993 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
15994 || (!best_row
&& !row
->continued_p
))
15996 /* In bidi-reordered rows, there could be several rows
15997 occluding point, all of them belonging to the same
15998 continued line. We need to find the row which fits
15999 CHARPOS the best. */
16000 for (g
= row
->glyphs
[TEXT_AREA
];
16001 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16004 if (!STRINGP (g
->object
))
16006 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
16008 mindif
= eabs (g
->charpos
- charpos
);
16010 /* Exact match always wins. */
16017 else if (best_row
&& !row
->continued_p
)
16024 /* Try to redisplay window W by reusing its existing display. W's
16025 current matrix must be up to date when this function is called,
16026 i.e. window_end_valid must not be nil.
16030 1 if display has been updated
16031 0 if otherwise unsuccessful
16032 -1 if redisplay with same window start is known not to succeed
16034 The following steps are performed:
16036 1. Find the last row in the current matrix of W that is not
16037 affected by changes at the start of current_buffer. If no such row
16040 2. Find the first row in W's current matrix that is not affected by
16041 changes at the end of current_buffer. Maybe there is no such row.
16043 3. Display lines beginning with the row + 1 found in step 1 to the
16044 row found in step 2 or, if step 2 didn't find a row, to the end of
16047 4. If cursor is not known to appear on the window, give up.
16049 5. If display stopped at the row found in step 2, scroll the
16050 display and current matrix as needed.
16052 6. Maybe display some lines at the end of W, if we must. This can
16053 happen under various circumstances, like a partially visible line
16054 becoming fully visible, or because newly displayed lines are displayed
16055 in smaller font sizes.
16057 7. Update W's window end information. */
16060 try_window_id (struct window
*w
)
16062 struct frame
*f
= XFRAME (w
->frame
);
16063 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
16064 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
16065 struct glyph_row
*last_unchanged_at_beg_row
;
16066 struct glyph_row
*first_unchanged_at_end_row
;
16067 struct glyph_row
*row
;
16068 struct glyph_row
*bottom_row
;
16071 EMACS_INT delta
= 0, delta_bytes
= 0, stop_pos
;
16073 struct text_pos start_pos
;
16075 int first_unchanged_at_end_vpos
= 0;
16076 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
16077 struct text_pos start
;
16078 EMACS_INT first_changed_charpos
, last_changed_charpos
;
16081 if (inhibit_try_window_id
)
16085 /* This is handy for debugging. */
16087 #define GIVE_UP(X) \
16089 fprintf (stderr, "try_window_id give up %d\n", (X)); \
16093 #define GIVE_UP(X) return 0
16096 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
16098 /* Don't use this for mini-windows because these can show
16099 messages and mini-buffers, and we don't handle that here. */
16100 if (MINI_WINDOW_P (w
))
16103 /* This flag is used to prevent redisplay optimizations. */
16104 if (windows_or_buffers_changed
|| cursor_type_changed
)
16107 /* Verify that narrowing has not changed.
16108 Also verify that we were not told to prevent redisplay optimizations.
16109 It would be nice to further
16110 reduce the number of cases where this prevents try_window_id. */
16111 if (current_buffer
->clip_changed
16112 || current_buffer
->prevent_redisplay_optimizations_p
)
16115 /* Window must either use window-based redisplay or be full width. */
16116 if (!FRAME_WINDOW_P (f
)
16117 && (!FRAME_LINE_INS_DEL_OK (f
)
16118 || !WINDOW_FULL_WIDTH_P (w
)))
16121 /* Give up if point is known NOT to appear in W. */
16122 if (PT
< CHARPOS (start
))
16125 /* Another way to prevent redisplay optimizations. */
16126 if (XFASTINT (w
->last_modified
) == 0)
16129 /* Verify that window is not hscrolled. */
16130 if (XFASTINT (w
->hscroll
) != 0)
16133 /* Verify that display wasn't paused. */
16134 if (NILP (w
->window_end_valid
))
16137 /* Can't use this if highlighting a region because a cursor movement
16138 will do more than just set the cursor. */
16139 if (!NILP (Vtransient_mark_mode
)
16140 && !NILP (BVAR (current_buffer
, mark_active
)))
16143 /* Likewise if highlighting trailing whitespace. */
16144 if (!NILP (Vshow_trailing_whitespace
))
16147 /* Likewise if showing a region. */
16148 if (!NILP (w
->region_showing
))
16151 /* Can't use this if overlay arrow position and/or string have
16153 if (overlay_arrows_changed_p ())
16156 /* When word-wrap is on, adding a space to the first word of a
16157 wrapped line can change the wrap position, altering the line
16158 above it. It might be worthwhile to handle this more
16159 intelligently, but for now just redisplay from scratch. */
16160 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
16163 /* Under bidi reordering, adding or deleting a character in the
16164 beginning of a paragraph, before the first strong directional
16165 character, can change the base direction of the paragraph (unless
16166 the buffer specifies a fixed paragraph direction), which will
16167 require to redisplay the whole paragraph. It might be worthwhile
16168 to find the paragraph limits and widen the range of redisplayed
16169 lines to that, but for now just give up this optimization and
16170 redisplay from scratch. */
16171 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16172 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
16175 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
16176 only if buffer has really changed. The reason is that the gap is
16177 initially at Z for freshly visited files. The code below would
16178 set end_unchanged to 0 in that case. */
16179 if (MODIFF
> SAVE_MODIFF
16180 /* This seems to happen sometimes after saving a buffer. */
16181 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
16183 if (GPT
- BEG
< BEG_UNCHANGED
)
16184 BEG_UNCHANGED
= GPT
- BEG
;
16185 if (Z
- GPT
< END_UNCHANGED
)
16186 END_UNCHANGED
= Z
- GPT
;
16189 /* The position of the first and last character that has been changed. */
16190 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
16191 last_changed_charpos
= Z
- END_UNCHANGED
;
16193 /* If window starts after a line end, and the last change is in
16194 front of that newline, then changes don't affect the display.
16195 This case happens with stealth-fontification. Note that although
16196 the display is unchanged, glyph positions in the matrix have to
16197 be adjusted, of course. */
16198 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16199 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16200 && ((last_changed_charpos
< CHARPOS (start
)
16201 && CHARPOS (start
) == BEGV
)
16202 || (last_changed_charpos
< CHARPOS (start
) - 1
16203 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
16205 EMACS_INT Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
16206 struct glyph_row
*r0
;
16208 /* Compute how many chars/bytes have been added to or removed
16209 from the buffer. */
16210 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16211 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16212 Z_delta
= Z
- Z_old
;
16213 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16215 /* Give up if PT is not in the window. Note that it already has
16216 been checked at the start of try_window_id that PT is not in
16217 front of the window start. */
16218 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
16221 /* If window start is unchanged, we can reuse the whole matrix
16222 as is, after adjusting glyph positions. No need to compute
16223 the window end again, since its offset from Z hasn't changed. */
16224 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16225 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
16226 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
16227 /* PT must not be in a partially visible line. */
16228 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
16229 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
16231 /* Adjust positions in the glyph matrix. */
16232 if (Z_delta
|| Z_delta_bytes
)
16234 struct glyph_row
*r1
16235 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16236 increment_matrix_positions (w
->current_matrix
,
16237 MATRIX_ROW_VPOS (r0
, current_matrix
),
16238 MATRIX_ROW_VPOS (r1
, current_matrix
),
16239 Z_delta
, Z_delta_bytes
);
16242 /* Set the cursor. */
16243 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
16245 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
16252 /* Handle the case that changes are all below what is displayed in
16253 the window, and that PT is in the window. This shortcut cannot
16254 be taken if ZV is visible in the window, and text has been added
16255 there that is visible in the window. */
16256 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
16257 /* ZV is not visible in the window, or there are no
16258 changes at ZV, actually. */
16259 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
16260 || first_changed_charpos
== last_changed_charpos
))
16262 struct glyph_row
*r0
;
16264 /* Give up if PT is not in the window. Note that it already has
16265 been checked at the start of try_window_id that PT is not in
16266 front of the window start. */
16267 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
16270 /* If window start is unchanged, we can reuse the whole matrix
16271 as is, without changing glyph positions since no text has
16272 been added/removed in front of the window end. */
16273 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16274 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
16275 /* PT must not be in a partially visible line. */
16276 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
16277 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
16279 /* We have to compute the window end anew since text
16280 could have been added/removed after it. */
16282 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16283 w
->window_end_bytepos
16284 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16286 /* Set the cursor. */
16287 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
16289 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
16296 /* Give up if window start is in the changed area.
16298 The condition used to read
16300 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
16302 but why that was tested escapes me at the moment. */
16303 if (CHARPOS (start
) >= first_changed_charpos
16304 && CHARPOS (start
) <= last_changed_charpos
)
16307 /* Check that window start agrees with the start of the first glyph
16308 row in its current matrix. Check this after we know the window
16309 start is not in changed text, otherwise positions would not be
16311 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16312 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
16315 /* Give up if the window ends in strings. Overlay strings
16316 at the end are difficult to handle, so don't try. */
16317 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
16318 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
16321 /* Compute the position at which we have to start displaying new
16322 lines. Some of the lines at the top of the window might be
16323 reusable because they are not displaying changed text. Find the
16324 last row in W's current matrix not affected by changes at the
16325 start of current_buffer. Value is null if changes start in the
16326 first line of window. */
16327 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
16328 if (last_unchanged_at_beg_row
)
16330 /* Avoid starting to display in the moddle of a character, a TAB
16331 for instance. This is easier than to set up the iterator
16332 exactly, and it's not a frequent case, so the additional
16333 effort wouldn't really pay off. */
16334 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
16335 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
16336 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
16337 --last_unchanged_at_beg_row
;
16339 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
16342 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
16344 start_pos
= it
.current
.pos
;
16346 /* Start displaying new lines in the desired matrix at the same
16347 vpos we would use in the current matrix, i.e. below
16348 last_unchanged_at_beg_row. */
16349 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
16351 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16352 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
16354 xassert (it
.hpos
== 0 && it
.current_x
== 0);
16358 /* There are no reusable lines at the start of the window.
16359 Start displaying in the first text line. */
16360 start_display (&it
, w
, start
);
16361 it
.vpos
= it
.first_vpos
;
16362 start_pos
= it
.current
.pos
;
16365 /* Find the first row that is not affected by changes at the end of
16366 the buffer. Value will be null if there is no unchanged row, in
16367 which case we must redisplay to the end of the window. delta
16368 will be set to the value by which buffer positions beginning with
16369 first_unchanged_at_end_row have to be adjusted due to text
16371 first_unchanged_at_end_row
16372 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
16373 IF_DEBUG (debug_delta
= delta
);
16374 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
16376 /* Set stop_pos to the buffer position up to which we will have to
16377 display new lines. If first_unchanged_at_end_row != NULL, this
16378 is the buffer position of the start of the line displayed in that
16379 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
16380 that we don't stop at a buffer position. */
16382 if (first_unchanged_at_end_row
)
16384 xassert (last_unchanged_at_beg_row
== NULL
16385 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
16387 /* If this is a continuation line, move forward to the next one
16388 that isn't. Changes in lines above affect this line.
16389 Caution: this may move first_unchanged_at_end_row to a row
16390 not displaying text. */
16391 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
16392 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
16393 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
16394 < it
.last_visible_y
))
16395 ++first_unchanged_at_end_row
;
16397 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
16398 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
16399 >= it
.last_visible_y
))
16400 first_unchanged_at_end_row
= NULL
;
16403 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
16405 first_unchanged_at_end_vpos
16406 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
16407 xassert (stop_pos
>= Z
- END_UNCHANGED
);
16410 else if (last_unchanged_at_beg_row
== NULL
)
16416 /* Either there is no unchanged row at the end, or the one we have
16417 now displays text. This is a necessary condition for the window
16418 end pos calculation at the end of this function. */
16419 xassert (first_unchanged_at_end_row
== NULL
16420 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
16422 debug_last_unchanged_at_beg_vpos
16423 = (last_unchanged_at_beg_row
16424 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
16426 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
16428 #endif /* GLYPH_DEBUG != 0 */
16431 /* Display new lines. Set last_text_row to the last new line
16432 displayed which has text on it, i.e. might end up as being the
16433 line where the window_end_vpos is. */
16434 w
->cursor
.vpos
= -1;
16435 last_text_row
= NULL
;
16436 overlay_arrow_seen
= 0;
16437 while (it
.current_y
< it
.last_visible_y
16438 && !fonts_changed_p
16439 && (first_unchanged_at_end_row
== NULL
16440 || IT_CHARPOS (it
) < stop_pos
))
16442 if (display_line (&it
))
16443 last_text_row
= it
.glyph_row
- 1;
16446 if (fonts_changed_p
)
16450 /* Compute differences in buffer positions, y-positions etc. for
16451 lines reused at the bottom of the window. Compute what we can
16453 if (first_unchanged_at_end_row
16454 /* No lines reused because we displayed everything up to the
16455 bottom of the window. */
16456 && it
.current_y
< it
.last_visible_y
)
16459 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
16461 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
16462 run
.current_y
= first_unchanged_at_end_row
->y
;
16463 run
.desired_y
= run
.current_y
+ dy
;
16464 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
16468 delta
= delta_bytes
= dvpos
= dy
16469 = run
.current_y
= run
.desired_y
= run
.height
= 0;
16470 first_unchanged_at_end_row
= NULL
;
16472 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
16475 /* Find the cursor if not already found. We have to decide whether
16476 PT will appear on this window (it sometimes doesn't, but this is
16477 not a very frequent case.) This decision has to be made before
16478 the current matrix is altered. A value of cursor.vpos < 0 means
16479 that PT is either in one of the lines beginning at
16480 first_unchanged_at_end_row or below the window. Don't care for
16481 lines that might be displayed later at the window end; as
16482 mentioned, this is not a frequent case. */
16483 if (w
->cursor
.vpos
< 0)
16485 /* Cursor in unchanged rows at the top? */
16486 if (PT
< CHARPOS (start_pos
)
16487 && last_unchanged_at_beg_row
)
16489 row
= row_containing_pos (w
, PT
,
16490 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
16491 last_unchanged_at_beg_row
+ 1, 0);
16493 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16496 /* Start from first_unchanged_at_end_row looking for PT. */
16497 else if (first_unchanged_at_end_row
)
16499 row
= row_containing_pos (w
, PT
- delta
,
16500 first_unchanged_at_end_row
, NULL
, 0);
16502 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
16503 delta_bytes
, dy
, dvpos
);
16506 /* Give up if cursor was not found. */
16507 if (w
->cursor
.vpos
< 0)
16509 clear_glyph_matrix (w
->desired_matrix
);
16514 /* Don't let the cursor end in the scroll margins. */
16516 int this_scroll_margin
, cursor_height
;
16518 this_scroll_margin
= max (0, scroll_margin
);
16519 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16520 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
16521 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
16523 if ((w
->cursor
.y
< this_scroll_margin
16524 && CHARPOS (start
) > BEGV
)
16525 /* Old redisplay didn't take scroll margin into account at the bottom,
16526 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
16527 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
16528 ? cursor_height
+ this_scroll_margin
16529 : 1)) > it
.last_visible_y
)
16531 w
->cursor
.vpos
= -1;
16532 clear_glyph_matrix (w
->desired_matrix
);
16537 /* Scroll the display. Do it before changing the current matrix so
16538 that xterm.c doesn't get confused about where the cursor glyph is
16540 if (dy
&& run
.height
)
16544 if (FRAME_WINDOW_P (f
))
16546 FRAME_RIF (f
)->update_window_begin_hook (w
);
16547 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16548 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16549 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16553 /* Terminal frame. In this case, dvpos gives the number of
16554 lines to scroll by; dvpos < 0 means scroll up. */
16556 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
16557 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
16558 int end
= (WINDOW_TOP_EDGE_LINE (w
)
16559 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
16560 + window_internal_height (w
));
16562 #if defined (HAVE_GPM) || defined (MSDOS)
16563 x_clear_window_mouse_face (w
);
16565 /* Perform the operation on the screen. */
16568 /* Scroll last_unchanged_at_beg_row to the end of the
16569 window down dvpos lines. */
16570 set_terminal_window (f
, end
);
16572 /* On dumb terminals delete dvpos lines at the end
16573 before inserting dvpos empty lines. */
16574 if (!FRAME_SCROLL_REGION_OK (f
))
16575 ins_del_lines (f
, end
- dvpos
, -dvpos
);
16577 /* Insert dvpos empty lines in front of
16578 last_unchanged_at_beg_row. */
16579 ins_del_lines (f
, from
, dvpos
);
16581 else if (dvpos
< 0)
16583 /* Scroll up last_unchanged_at_beg_vpos to the end of
16584 the window to last_unchanged_at_beg_vpos - |dvpos|. */
16585 set_terminal_window (f
, end
);
16587 /* Delete dvpos lines in front of
16588 last_unchanged_at_beg_vpos. ins_del_lines will set
16589 the cursor to the given vpos and emit |dvpos| delete
16591 ins_del_lines (f
, from
+ dvpos
, dvpos
);
16593 /* On a dumb terminal insert dvpos empty lines at the
16595 if (!FRAME_SCROLL_REGION_OK (f
))
16596 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
16599 set_terminal_window (f
, 0);
16605 /* Shift reused rows of the current matrix to the right position.
16606 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
16608 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16609 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
16612 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
16613 bottom_vpos
, dvpos
);
16614 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
16617 else if (dvpos
> 0)
16619 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
16620 bottom_vpos
, dvpos
);
16621 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
16622 first_unchanged_at_end_vpos
+ dvpos
, 0);
16625 /* For frame-based redisplay, make sure that current frame and window
16626 matrix are in sync with respect to glyph memory. */
16627 if (!FRAME_WINDOW_P (f
))
16628 sync_frame_with_window_matrix_rows (w
);
16630 /* Adjust buffer positions in reused rows. */
16631 if (delta
|| delta_bytes
)
16632 increment_matrix_positions (current_matrix
,
16633 first_unchanged_at_end_vpos
+ dvpos
,
16634 bottom_vpos
, delta
, delta_bytes
);
16636 /* Adjust Y positions. */
16638 shift_glyph_matrix (w
, current_matrix
,
16639 first_unchanged_at_end_vpos
+ dvpos
,
16642 if (first_unchanged_at_end_row
)
16644 first_unchanged_at_end_row
+= dvpos
;
16645 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16646 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16647 first_unchanged_at_end_row
= NULL
;
16650 /* If scrolling up, there may be some lines to display at the end of
16652 last_text_row_at_end
= NULL
;
16655 /* Scrolling up can leave for example a partially visible line
16656 at the end of the window to be redisplayed. */
16657 /* Set last_row to the glyph row in the current matrix where the
16658 window end line is found. It has been moved up or down in
16659 the matrix by dvpos. */
16660 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16661 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16663 /* If last_row is the window end line, it should display text. */
16664 xassert (last_row
->displays_text_p
);
16666 /* If window end line was partially visible before, begin
16667 displaying at that line. Otherwise begin displaying with the
16668 line following it. */
16669 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16671 init_to_row_start (&it
, w
, last_row
);
16672 it
.vpos
= last_vpos
;
16673 it
.current_y
= last_row
->y
;
16677 init_to_row_end (&it
, w
, last_row
);
16678 it
.vpos
= 1 + last_vpos
;
16679 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16683 /* We may start in a continuation line. If so, we have to
16684 get the right continuation_lines_width and current_x. */
16685 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16686 it
.hpos
= it
.current_x
= 0;
16688 /* Display the rest of the lines at the window end. */
16689 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16690 while (it
.current_y
< it
.last_visible_y
16691 && !fonts_changed_p
)
16693 /* Is it always sure that the display agrees with lines in
16694 the current matrix? I don't think so, so we mark rows
16695 displayed invalid in the current matrix by setting their
16696 enabled_p flag to zero. */
16697 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16698 if (display_line (&it
))
16699 last_text_row_at_end
= it
.glyph_row
- 1;
16703 /* Update window_end_pos and window_end_vpos. */
16704 if (first_unchanged_at_end_row
16705 && !last_text_row_at_end
)
16707 /* Window end line if one of the preserved rows from the current
16708 matrix. Set row to the last row displaying text in current
16709 matrix starting at first_unchanged_at_end_row, after
16711 xassert (first_unchanged_at_end_row
->displays_text_p
);
16712 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16713 first_unchanged_at_end_row
);
16714 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16716 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16717 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16719 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16720 xassert (w
->window_end_bytepos
>= 0);
16721 IF_DEBUG (debug_method_add (w
, "A"));
16723 else if (last_text_row_at_end
)
16726 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16727 w
->window_end_bytepos
16728 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16730 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16731 xassert (w
->window_end_bytepos
>= 0);
16732 IF_DEBUG (debug_method_add (w
, "B"));
16734 else if (last_text_row
)
16736 /* We have displayed either to the end of the window or at the
16737 end of the window, i.e. the last row with text is to be found
16738 in the desired matrix. */
16740 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16741 w
->window_end_bytepos
16742 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16744 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16745 xassert (w
->window_end_bytepos
>= 0);
16747 else if (first_unchanged_at_end_row
== NULL
16748 && last_text_row
== NULL
16749 && last_text_row_at_end
== NULL
)
16751 /* Displayed to end of window, but no line containing text was
16752 displayed. Lines were deleted at the end of the window. */
16753 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16754 int vpos
= XFASTINT (w
->window_end_vpos
);
16755 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16756 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16759 row
== NULL
&& vpos
>= first_vpos
;
16760 --vpos
, --current_row
, --desired_row
)
16762 if (desired_row
->enabled_p
)
16764 if (desired_row
->displays_text_p
)
16767 else if (current_row
->displays_text_p
)
16771 xassert (row
!= NULL
);
16772 w
->window_end_vpos
= make_number (vpos
+ 1);
16773 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16774 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16775 xassert (w
->window_end_bytepos
>= 0);
16776 IF_DEBUG (debug_method_add (w
, "C"));
16781 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16782 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16784 /* Record that display has not been completed. */
16785 w
->window_end_valid
= Qnil
;
16786 w
->desired_matrix
->no_scrolling_p
= 1;
16794 /***********************************************************************
16795 More debugging support
16796 ***********************************************************************/
16800 void dump_glyph_row (struct glyph_row
*, int, int);
16801 void dump_glyph_matrix (struct glyph_matrix
*, int);
16802 void dump_glyph (struct glyph_row
*, struct glyph
*, int);
16805 /* Dump the contents of glyph matrix MATRIX on stderr.
16807 GLYPHS 0 means don't show glyph contents.
16808 GLYPHS 1 means show glyphs in short form
16809 GLYPHS > 1 means show glyphs in long form. */
16812 dump_glyph_matrix (matrix
, glyphs
)
16813 struct glyph_matrix
*matrix
;
16817 for (i
= 0; i
< matrix
->nrows
; ++i
)
16818 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16822 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16823 the glyph row and area where the glyph comes from. */
16826 dump_glyph (row
, glyph
, area
)
16827 struct glyph_row
*row
;
16828 struct glyph
*glyph
;
16831 if (glyph
->type
== CHAR_GLYPH
)
16834 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16835 glyph
- row
->glyphs
[TEXT_AREA
],
16838 (BUFFERP (glyph
->object
)
16840 : (STRINGP (glyph
->object
)
16843 glyph
->pixel_width
,
16845 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16849 glyph
->left_box_line_p
,
16850 glyph
->right_box_line_p
);
16852 else if (glyph
->type
== STRETCH_GLYPH
)
16855 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16856 glyph
- row
->glyphs
[TEXT_AREA
],
16859 (BUFFERP (glyph
->object
)
16861 : (STRINGP (glyph
->object
)
16864 glyph
->pixel_width
,
16868 glyph
->left_box_line_p
,
16869 glyph
->right_box_line_p
);
16871 else if (glyph
->type
== IMAGE_GLYPH
)
16874 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16875 glyph
- row
->glyphs
[TEXT_AREA
],
16878 (BUFFERP (glyph
->object
)
16880 : (STRINGP (glyph
->object
)
16883 glyph
->pixel_width
,
16887 glyph
->left_box_line_p
,
16888 glyph
->right_box_line_p
);
16890 else if (glyph
->type
== COMPOSITE_GLYPH
)
16893 " %5d %4c %6d %c %3d 0x%05x",
16894 glyph
- row
->glyphs
[TEXT_AREA
],
16897 (BUFFERP (glyph
->object
)
16899 : (STRINGP (glyph
->object
)
16902 glyph
->pixel_width
,
16904 if (glyph
->u
.cmp
.automatic
)
16907 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
16908 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16910 glyph
->left_box_line_p
,
16911 glyph
->right_box_line_p
);
16916 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16917 GLYPHS 0 means don't show glyph contents.
16918 GLYPHS 1 means show glyphs in short form
16919 GLYPHS > 1 means show glyphs in long form. */
16922 dump_glyph_row (row
, vpos
, glyphs
)
16923 struct glyph_row
*row
;
16928 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16929 fprintf (stderr
, "======================================================================\n");
16931 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16932 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16934 MATRIX_ROW_START_CHARPOS (row
),
16935 MATRIX_ROW_END_CHARPOS (row
),
16936 row
->used
[TEXT_AREA
],
16937 row
->contains_overlapping_glyphs_p
,
16939 row
->truncated_on_left_p
,
16940 row
->truncated_on_right_p
,
16942 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16943 row
->displays_text_p
,
16946 row
->ends_in_middle_of_char_p
,
16947 row
->starts_in_middle_of_char_p
,
16953 row
->visible_height
,
16956 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16957 row
->end
.overlay_string_index
,
16958 row
->continuation_lines_width
);
16959 fprintf (stderr
, "%9d %5d\n",
16960 CHARPOS (row
->start
.string_pos
),
16961 CHARPOS (row
->end
.string_pos
));
16962 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16963 row
->end
.dpvec_index
);
16970 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16972 struct glyph
*glyph
= row
->glyphs
[area
];
16973 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16975 /* Glyph for a line end in text. */
16976 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16979 if (glyph
< glyph_end
)
16980 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16982 for (; glyph
< glyph_end
; ++glyph
)
16983 dump_glyph (row
, glyph
, area
);
16986 else if (glyphs
== 1)
16990 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16992 char *s
= (char *) alloca (row
->used
[area
] + 1);
16995 for (i
= 0; i
< row
->used
[area
]; ++i
)
16997 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16998 if (glyph
->type
== CHAR_GLYPH
16999 && glyph
->u
.ch
< 0x80
17000 && glyph
->u
.ch
>= ' ')
17001 s
[i
] = glyph
->u
.ch
;
17007 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
17013 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
17014 Sdump_glyph_matrix
, 0, 1, "p",
17015 doc
: /* Dump the current matrix of the selected window to stderr.
17016 Shows contents of glyph row structures. With non-nil
17017 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
17018 glyphs in short form, otherwise show glyphs in long form. */)
17019 (Lisp_Object glyphs
)
17021 struct window
*w
= XWINDOW (selected_window
);
17022 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17024 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
17025 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
17026 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
17027 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
17028 fprintf (stderr
, "=============================================\n");
17029 dump_glyph_matrix (w
->current_matrix
,
17030 NILP (glyphs
) ? 0 : XINT (glyphs
));
17035 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
17036 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
17039 struct frame
*f
= XFRAME (selected_frame
);
17040 dump_glyph_matrix (f
->current_matrix
, 1);
17045 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
17046 doc
: /* Dump glyph row ROW to stderr.
17047 GLYPH 0 means don't dump glyphs.
17048 GLYPH 1 means dump glyphs in short form.
17049 GLYPH > 1 or omitted means dump glyphs in long form. */)
17050 (Lisp_Object row
, Lisp_Object glyphs
)
17052 struct glyph_matrix
*matrix
;
17055 CHECK_NUMBER (row
);
17056 matrix
= XWINDOW (selected_window
)->current_matrix
;
17058 if (vpos
>= 0 && vpos
< matrix
->nrows
)
17059 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
17061 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
17066 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
17067 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
17068 GLYPH 0 means don't dump glyphs.
17069 GLYPH 1 means dump glyphs in short form.
17070 GLYPH > 1 or omitted means dump glyphs in long form. */)
17071 (Lisp_Object row
, Lisp_Object glyphs
)
17073 struct frame
*sf
= SELECTED_FRAME ();
17074 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
17077 CHECK_NUMBER (row
);
17079 if (vpos
>= 0 && vpos
< m
->nrows
)
17080 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
17081 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
17086 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
17087 doc
: /* Toggle tracing of redisplay.
17088 With ARG, turn tracing on if and only if ARG is positive. */)
17092 trace_redisplay_p
= !trace_redisplay_p
;
17095 arg
= Fprefix_numeric_value (arg
);
17096 trace_redisplay_p
= XINT (arg
) > 0;
17103 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
17104 doc
: /* Like `format', but print result to stderr.
17105 usage: (trace-to-stderr STRING &rest OBJECTS) */)
17106 (size_t nargs
, Lisp_Object
*args
)
17108 Lisp_Object s
= Fformat (nargs
, args
);
17109 fprintf (stderr
, "%s", SDATA (s
));
17113 #endif /* GLYPH_DEBUG */
17117 /***********************************************************************
17118 Building Desired Matrix Rows
17119 ***********************************************************************/
17121 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
17122 Used for non-window-redisplay windows, and for windows w/o left fringe. */
17124 static struct glyph_row
*
17125 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
17127 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17128 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17129 struct buffer
*old
= current_buffer
;
17130 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
17131 int arrow_len
= SCHARS (overlay_arrow_string
);
17132 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
17133 const unsigned char *p
;
17136 int n_glyphs_before
;
17138 set_buffer_temp (buffer
);
17139 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
17140 it
.glyph_row
->used
[TEXT_AREA
] = 0;
17141 SET_TEXT_POS (it
.position
, 0, 0);
17143 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
17145 while (p
< arrow_end
)
17147 Lisp_Object face
, ilisp
;
17149 /* Get the next character. */
17151 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
17154 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
17155 if (! ASCII_CHAR_P (it
.c
))
17156 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
17160 /* Get its face. */
17161 ilisp
= make_number (p
- arrow_string
);
17162 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
17163 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
17165 /* Compute its width, get its glyphs. */
17166 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
17167 SET_TEXT_POS (it
.position
, -1, -1);
17168 PRODUCE_GLYPHS (&it
);
17170 /* If this character doesn't fit any more in the line, we have
17171 to remove some glyphs. */
17172 if (it
.current_x
> it
.last_visible_x
)
17174 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17179 set_buffer_temp (old
);
17180 return it
.glyph_row
;
17184 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
17185 glyphs are only inserted for terminal frames since we can't really
17186 win with truncation glyphs when partially visible glyphs are
17187 involved. Which glyphs to insert is determined by
17188 produce_special_glyphs. */
17191 insert_left_trunc_glyphs (struct it
*it
)
17193 struct it truncate_it
;
17194 struct glyph
*from
, *end
, *to
, *toend
;
17196 xassert (!FRAME_WINDOW_P (it
->f
));
17198 /* Get the truncation glyphs. */
17200 truncate_it
.current_x
= 0;
17201 truncate_it
.face_id
= DEFAULT_FACE_ID
;
17202 truncate_it
.glyph_row
= &scratch_glyph_row
;
17203 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
17204 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
17205 truncate_it
.object
= make_number (0);
17206 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
17208 /* Overwrite glyphs from IT with truncation glyphs. */
17209 if (!it
->glyph_row
->reversed_p
)
17211 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17212 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
17213 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17214 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
17219 /* There may be padding glyphs left over. Overwrite them too. */
17220 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
17222 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17228 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
17232 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
17233 that back to front. */
17234 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17235 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17236 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17237 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17239 while (from
>= end
&& to
>= toend
)
17241 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
17244 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
17245 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17246 while (from
>= end
&& to
>= toend
)
17251 /* Need to free some room before prepending additional
17253 int move_by
= from
- end
+ 1;
17254 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17255 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17257 for ( ; g
>= g0
; g
--)
17259 while (from
>= end
)
17261 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
17267 /* Compute the pixel height and width of IT->glyph_row.
17269 Most of the time, ascent and height of a display line will be equal
17270 to the max_ascent and max_height values of the display iterator
17271 structure. This is not the case if
17273 1. We hit ZV without displaying anything. In this case, max_ascent
17274 and max_height will be zero.
17276 2. We have some glyphs that don't contribute to the line height.
17277 (The glyph row flag contributes_to_line_height_p is for future
17278 pixmap extensions).
17280 The first case is easily covered by using default values because in
17281 these cases, the line height does not really matter, except that it
17282 must not be zero. */
17285 compute_line_metrics (struct it
*it
)
17287 struct glyph_row
*row
= it
->glyph_row
;
17289 if (FRAME_WINDOW_P (it
->f
))
17291 int i
, min_y
, max_y
;
17293 /* The line may consist of one space only, that was added to
17294 place the cursor on it. If so, the row's height hasn't been
17296 if (row
->height
== 0)
17298 if (it
->max_ascent
+ it
->max_descent
== 0)
17299 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
17300 row
->ascent
= it
->max_ascent
;
17301 row
->height
= it
->max_ascent
+ it
->max_descent
;
17302 row
->phys_ascent
= it
->max_phys_ascent
;
17303 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17304 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17307 /* Compute the width of this line. */
17308 row
->pixel_width
= row
->x
;
17309 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
17310 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
17312 xassert (row
->pixel_width
>= 0);
17313 xassert (row
->ascent
>= 0 && row
->height
> 0);
17315 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
17316 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
17318 /* If first line's physical ascent is larger than its logical
17319 ascent, use the physical ascent, and make the row taller.
17320 This makes accented characters fully visible. */
17321 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
17322 && row
->phys_ascent
> row
->ascent
)
17324 row
->height
+= row
->phys_ascent
- row
->ascent
;
17325 row
->ascent
= row
->phys_ascent
;
17328 /* Compute how much of the line is visible. */
17329 row
->visible_height
= row
->height
;
17331 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
17332 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
17334 if (row
->y
< min_y
)
17335 row
->visible_height
-= min_y
- row
->y
;
17336 if (row
->y
+ row
->height
> max_y
)
17337 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17341 row
->pixel_width
= row
->used
[TEXT_AREA
];
17342 if (row
->continued_p
)
17343 row
->pixel_width
-= it
->continuation_pixel_width
;
17344 else if (row
->truncated_on_right_p
)
17345 row
->pixel_width
-= it
->truncation_pixel_width
;
17346 row
->ascent
= row
->phys_ascent
= 0;
17347 row
->height
= row
->phys_height
= row
->visible_height
= 1;
17348 row
->extra_line_spacing
= 0;
17351 /* Compute a hash code for this row. */
17355 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17356 for (i
= 0; i
< row
->used
[area
]; ++i
)
17357 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
17358 + row
->glyphs
[area
][i
].u
.val
17359 + row
->glyphs
[area
][i
].face_id
17360 + row
->glyphs
[area
][i
].padding_p
17361 + (row
->glyphs
[area
][i
].type
<< 2));
17364 it
->max_ascent
= it
->max_descent
= 0;
17365 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
17369 /* Append one space to the glyph row of iterator IT if doing a
17370 window-based redisplay. The space has the same face as
17371 IT->face_id. Value is non-zero if a space was added.
17373 This function is called to make sure that there is always one glyph
17374 at the end of a glyph row that the cursor can be set on under
17375 window-systems. (If there weren't such a glyph we would not know
17376 how wide and tall a box cursor should be displayed).
17378 At the same time this space let's a nicely handle clearing to the
17379 end of the line if the row ends in italic text. */
17382 append_space_for_newline (struct it
*it
, int default_face_p
)
17384 if (FRAME_WINDOW_P (it
->f
))
17386 int n
= it
->glyph_row
->used
[TEXT_AREA
];
17388 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
17389 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
17391 /* Save some values that must not be changed.
17392 Must save IT->c and IT->len because otherwise
17393 ITERATOR_AT_END_P wouldn't work anymore after
17394 append_space_for_newline has been called. */
17395 enum display_element_type saved_what
= it
->what
;
17396 int saved_c
= it
->c
, saved_len
= it
->len
;
17397 int saved_char_to_display
= it
->char_to_display
;
17398 int saved_x
= it
->current_x
;
17399 int saved_face_id
= it
->face_id
;
17400 struct text_pos saved_pos
;
17401 Lisp_Object saved_object
;
17404 saved_object
= it
->object
;
17405 saved_pos
= it
->position
;
17407 it
->what
= IT_CHARACTER
;
17408 memset (&it
->position
, 0, sizeof it
->position
);
17409 it
->object
= make_number (0);
17410 it
->c
= it
->char_to_display
= ' ';
17413 if (default_face_p
)
17414 it
->face_id
= DEFAULT_FACE_ID
;
17415 else if (it
->face_before_selective_p
)
17416 it
->face_id
= it
->saved_face_id
;
17417 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17418 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
17420 PRODUCE_GLYPHS (it
);
17422 it
->override_ascent
= -1;
17423 it
->constrain_row_ascent_descent_p
= 0;
17424 it
->current_x
= saved_x
;
17425 it
->object
= saved_object
;
17426 it
->position
= saved_pos
;
17427 it
->what
= saved_what
;
17428 it
->face_id
= saved_face_id
;
17429 it
->len
= saved_len
;
17431 it
->char_to_display
= saved_char_to_display
;
17440 /* Extend the face of the last glyph in the text area of IT->glyph_row
17441 to the end of the display line. Called from display_line. If the
17442 glyph row is empty, add a space glyph to it so that we know the
17443 face to draw. Set the glyph row flag fill_line_p. If the glyph
17444 row is R2L, prepend a stretch glyph to cover the empty space to the
17445 left of the leftmost glyph. */
17448 extend_face_to_end_of_line (struct it
*it
)
17451 struct frame
*f
= it
->f
;
17453 /* If line is already filled, do nothing. Non window-system frames
17454 get a grace of one more ``pixel'' because their characters are
17455 1-``pixel'' wide, so they hit the equality too early. This grace
17456 is needed only for R2L rows that are not continued, to produce
17457 one extra blank where we could display the cursor. */
17458 if (it
->current_x
>= it
->last_visible_x
17459 + (!FRAME_WINDOW_P (f
)
17460 && it
->glyph_row
->reversed_p
17461 && !it
->glyph_row
->continued_p
))
17464 /* Face extension extends the background and box of IT->face_id
17465 to the end of the line. If the background equals the background
17466 of the frame, we don't have to do anything. */
17467 if (it
->face_before_selective_p
)
17468 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
17470 face
= FACE_FROM_ID (f
, it
->face_id
);
17472 if (FRAME_WINDOW_P (f
)
17473 && it
->glyph_row
->displays_text_p
17474 && face
->box
== FACE_NO_BOX
17475 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
17477 && !it
->glyph_row
->reversed_p
)
17480 /* Set the glyph row flag indicating that the face of the last glyph
17481 in the text area has to be drawn to the end of the text area. */
17482 it
->glyph_row
->fill_line_p
= 1;
17484 /* If current character of IT is not ASCII, make sure we have the
17485 ASCII face. This will be automatically undone the next time
17486 get_next_display_element returns a multibyte character. Note
17487 that the character will always be single byte in unibyte
17489 if (!ASCII_CHAR_P (it
->c
))
17491 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
17494 if (FRAME_WINDOW_P (f
))
17496 /* If the row is empty, add a space with the current face of IT,
17497 so that we know which face to draw. */
17498 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
17500 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
17501 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
17502 it
->glyph_row
->used
[TEXT_AREA
] = 1;
17504 #ifdef HAVE_WINDOW_SYSTEM
17505 if (it
->glyph_row
->reversed_p
)
17507 /* Prepend a stretch glyph to the row, such that the
17508 rightmost glyph will be drawn flushed all the way to the
17509 right margin of the window. The stretch glyph that will
17510 occupy the empty space, if any, to the left of the
17512 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
17513 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17514 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
17516 int row_width
, stretch_ascent
, stretch_width
;
17517 struct text_pos saved_pos
;
17518 int saved_face_id
, saved_avoid_cursor
;
17520 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
17521 row_width
+= g
->pixel_width
;
17522 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
17523 if (stretch_width
> 0)
17526 (((it
->ascent
+ it
->descent
)
17527 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
17528 saved_pos
= it
->position
;
17529 memset (&it
->position
, 0, sizeof it
->position
);
17530 saved_avoid_cursor
= it
->avoid_cursor_p
;
17531 it
->avoid_cursor_p
= 1;
17532 saved_face_id
= it
->face_id
;
17533 /* The last row's stretch glyph should get the default
17534 face, to avoid painting the rest of the window with
17535 the region face, if the region ends at ZV. */
17536 if (it
->glyph_row
->ends_at_zv_p
)
17537 it
->face_id
= DEFAULT_FACE_ID
;
17539 it
->face_id
= face
->id
;
17540 append_stretch_glyph (it
, make_number (0), stretch_width
,
17541 it
->ascent
+ it
->descent
, stretch_ascent
);
17542 it
->position
= saved_pos
;
17543 it
->avoid_cursor_p
= saved_avoid_cursor
;
17544 it
->face_id
= saved_face_id
;
17547 #endif /* HAVE_WINDOW_SYSTEM */
17551 /* Save some values that must not be changed. */
17552 int saved_x
= it
->current_x
;
17553 struct text_pos saved_pos
;
17554 Lisp_Object saved_object
;
17555 enum display_element_type saved_what
= it
->what
;
17556 int saved_face_id
= it
->face_id
;
17558 saved_object
= it
->object
;
17559 saved_pos
= it
->position
;
17561 it
->what
= IT_CHARACTER
;
17562 memset (&it
->position
, 0, sizeof it
->position
);
17563 it
->object
= make_number (0);
17564 it
->c
= it
->char_to_display
= ' ';
17566 /* The last row's blank glyphs should get the default face, to
17567 avoid painting the rest of the window with the region face,
17568 if the region ends at ZV. */
17569 if (it
->glyph_row
->ends_at_zv_p
)
17570 it
->face_id
= DEFAULT_FACE_ID
;
17572 it
->face_id
= face
->id
;
17574 PRODUCE_GLYPHS (it
);
17576 while (it
->current_x
<= it
->last_visible_x
)
17577 PRODUCE_GLYPHS (it
);
17579 /* Don't count these blanks really. It would let us insert a left
17580 truncation glyph below and make us set the cursor on them, maybe. */
17581 it
->current_x
= saved_x
;
17582 it
->object
= saved_object
;
17583 it
->position
= saved_pos
;
17584 it
->what
= saved_what
;
17585 it
->face_id
= saved_face_id
;
17590 /* Value is non-zero if text starting at CHARPOS in current_buffer is
17591 trailing whitespace. */
17594 trailing_whitespace_p (EMACS_INT charpos
)
17596 EMACS_INT bytepos
= CHAR_TO_BYTE (charpos
);
17599 while (bytepos
< ZV_BYTE
17600 && (c
= FETCH_CHAR (bytepos
),
17601 c
== ' ' || c
== '\t'))
17604 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
17606 if (bytepos
!= PT_BYTE
)
17613 /* Highlight trailing whitespace, if any, in ROW. */
17616 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
17618 int used
= row
->used
[TEXT_AREA
];
17622 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
17623 struct glyph
*glyph
= start
+ used
- 1;
17625 if (row
->reversed_p
)
17627 /* Right-to-left rows need to be processed in the opposite
17628 direction, so swap the edge pointers. */
17630 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
17633 /* Skip over glyphs inserted to display the cursor at the
17634 end of a line, for extending the face of the last glyph
17635 to the end of the line on terminals, and for truncation
17636 and continuation glyphs. */
17637 if (!row
->reversed_p
)
17639 while (glyph
>= start
17640 && glyph
->type
== CHAR_GLYPH
17641 && INTEGERP (glyph
->object
))
17646 while (glyph
<= start
17647 && glyph
->type
== CHAR_GLYPH
17648 && INTEGERP (glyph
->object
))
17652 /* If last glyph is a space or stretch, and it's trailing
17653 whitespace, set the face of all trailing whitespace glyphs in
17654 IT->glyph_row to `trailing-whitespace'. */
17655 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
17656 && BUFFERP (glyph
->object
)
17657 && (glyph
->type
== STRETCH_GLYPH
17658 || (glyph
->type
== CHAR_GLYPH
17659 && glyph
->u
.ch
== ' '))
17660 && trailing_whitespace_p (glyph
->charpos
))
17662 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
17666 if (!row
->reversed_p
)
17668 while (glyph
>= start
17669 && BUFFERP (glyph
->object
)
17670 && (glyph
->type
== STRETCH_GLYPH
17671 || (glyph
->type
== CHAR_GLYPH
17672 && glyph
->u
.ch
== ' ')))
17673 (glyph
--)->face_id
= face_id
;
17677 while (glyph
<= start
17678 && BUFFERP (glyph
->object
)
17679 && (glyph
->type
== STRETCH_GLYPH
17680 || (glyph
->type
== CHAR_GLYPH
17681 && glyph
->u
.ch
== ' ')))
17682 (glyph
++)->face_id
= face_id
;
17689 /* Value is non-zero if glyph row ROW should be
17690 used to hold the cursor. */
17693 cursor_row_p (struct glyph_row
*row
)
17697 if (PT
== CHARPOS (row
->end
.pos
))
17699 /* Suppose the row ends on a string.
17700 Unless the row is continued, that means it ends on a newline
17701 in the string. If it's anything other than a display string
17702 (e.g. a before-string from an overlay), we don't want the
17703 cursor there. (This heuristic seems to give the optimal
17704 behavior for the various types of multi-line strings.) */
17705 if (CHARPOS (row
->end
.string_pos
) >= 0)
17707 if (row
->continued_p
)
17711 /* Check for `display' property. */
17712 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17713 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17714 struct glyph
*glyph
;
17717 for (glyph
= end
; glyph
>= beg
; --glyph
)
17718 if (STRINGP (glyph
->object
))
17721 = Fget_char_property (make_number (PT
),
17725 && display_prop_string_p (prop
, glyph
->object
));
17730 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17732 /* If the row ends in middle of a real character,
17733 and the line is continued, we want the cursor here.
17734 That's because CHARPOS (ROW->end.pos) would equal
17735 PT if PT is before the character. */
17736 if (!row
->ends_in_ellipsis_p
)
17737 result
= row
->continued_p
;
17739 /* If the row ends in an ellipsis, then
17740 CHARPOS (ROW->end.pos) will equal point after the
17741 invisible text. We want that position to be displayed
17742 after the ellipsis. */
17745 /* If the row ends at ZV, display the cursor at the end of that
17746 row instead of at the start of the row below. */
17747 else if (row
->ends_at_zv_p
)
17758 /* Push the display property PROP so that it will be rendered at the
17759 current position in IT. Return 1 if PROP was successfully pushed,
17763 push_display_prop (struct it
*it
, Lisp_Object prop
)
17765 xassert (it
->method
== GET_FROM_BUFFER
);
17767 push_it (it
, NULL
);
17769 if (STRINGP (prop
))
17771 if (SCHARS (prop
) == 0)
17778 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17779 it
->current
.overlay_string_index
= -1;
17780 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17781 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17782 it
->method
= GET_FROM_STRING
;
17783 it
->stop_charpos
= 0;
17785 it
->base_level_stop
= 0;
17786 it
->string_from_display_prop_p
= 1;
17787 it
->from_disp_prop_p
= 1;
17789 /* Force paragraph direction to be that of the parent
17791 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
17792 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
17794 it
->paragraph_embedding
= L2R
;
17796 /* Set up the bidi iterator for this display string. */
17799 it
->bidi_it
.string
.lstring
= it
->string
;
17800 it
->bidi_it
.string
.s
= NULL
;
17801 it
->bidi_it
.string
.schars
= it
->end_charpos
;
17802 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
17803 it
->bidi_it
.string
.from_disp_str
= 1;
17804 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
17805 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
17808 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17810 it
->method
= GET_FROM_STRETCH
;
17813 #ifdef HAVE_WINDOW_SYSTEM
17814 else if (IMAGEP (prop
))
17816 it
->what
= IT_IMAGE
;
17817 it
->image_id
= lookup_image (it
->f
, prop
);
17818 it
->method
= GET_FROM_IMAGE
;
17820 #endif /* HAVE_WINDOW_SYSTEM */
17823 pop_it (it
); /* bogus display property, give up */
17830 /* Return the character-property PROP at the current position in IT. */
17833 get_it_property (struct it
*it
, Lisp_Object prop
)
17835 Lisp_Object position
;
17837 if (STRINGP (it
->object
))
17838 position
= make_number (IT_STRING_CHARPOS (*it
));
17839 else if (BUFFERP (it
->object
))
17840 position
= make_number (IT_CHARPOS (*it
));
17844 return Fget_char_property (position
, prop
, it
->object
);
17847 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17850 handle_line_prefix (struct it
*it
)
17852 Lisp_Object prefix
;
17854 if (it
->continuation_lines_width
> 0)
17856 prefix
= get_it_property (it
, Qwrap_prefix
);
17858 prefix
= Vwrap_prefix
;
17862 prefix
= get_it_property (it
, Qline_prefix
);
17864 prefix
= Vline_prefix
;
17866 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17868 /* If the prefix is wider than the window, and we try to wrap
17869 it, it would acquire its own wrap prefix, and so on till the
17870 iterator stack overflows. So, don't wrap the prefix. */
17871 it
->line_wrap
= TRUNCATE
;
17872 it
->avoid_cursor_p
= 1;
17878 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
17879 only for R2L lines from display_line and display_string, when they
17880 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
17881 the line/string needs to be continued on the next glyph row. */
17883 unproduce_glyphs (struct it
*it
, int n
)
17885 struct glyph
*glyph
, *end
;
17887 xassert (it
->glyph_row
);
17888 xassert (it
->glyph_row
->reversed_p
);
17889 xassert (it
->area
== TEXT_AREA
);
17890 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
17892 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
17893 n
= it
->glyph_row
->used
[TEXT_AREA
];
17894 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
17895 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
17896 for ( ; glyph
< end
; glyph
++)
17897 glyph
[-n
] = *glyph
;
17900 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
17901 and ROW->maxpos. */
17903 find_row_edges (struct it
*it
, struct glyph_row
*row
,
17904 EMACS_INT min_pos
, EMACS_INT min_bpos
,
17905 EMACS_INT max_pos
, EMACS_INT max_bpos
)
17907 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17908 lines' rows is implemented for bidi-reordered rows. */
17910 /* ROW->minpos is the value of min_pos, the minimal buffer position
17913 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
17915 /* We didn't find _any_ valid buffer positions in any of the
17916 glyphs, so we must trust the iterator's computed positions. */
17917 row
->minpos
= row
->start
.pos
;
17920 max_pos
= CHARPOS (it
->current
.pos
);
17921 max_bpos
= BYTEPOS (it
->current
.pos
);
17924 /* Here are the various use-cases for ending the row, and the
17925 corresponding values for ROW->maxpos:
17927 Line ends in a newline from buffer eol_pos + 1
17928 Line is continued from buffer max_pos + 1
17929 Line is truncated on right it->current.pos
17930 Line ends in a newline from string max_pos
17931 Line is continued from string max_pos
17932 Line is continued from display vector max_pos
17933 Line is entirely from a string min_pos == max_pos
17934 Line is entirely from a display vector min_pos == max_pos
17935 Line that ends at ZV ZV
17937 If you discover other use-cases, please add them here as
17939 if (row
->ends_at_zv_p
)
17940 row
->maxpos
= it
->current
.pos
;
17941 else if (row
->used
[TEXT_AREA
])
17943 if (row
->ends_in_newline_from_string_p
)
17944 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17945 else if (CHARPOS (it
->eol_pos
) > 0)
17946 SET_TEXT_POS (row
->maxpos
,
17947 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
17948 else if (row
->continued_p
)
17950 /* If max_pos is different from IT's current position, it
17951 means IT->method does not belong to the display element
17952 at max_pos. However, it also means that the display
17953 element at max_pos was displayed in its entirety on this
17954 line, which is equivalent to saying that the next line
17955 starts at the next buffer position. */
17956 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
17957 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17960 INC_BOTH (max_pos
, max_bpos
);
17961 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17964 else if (row
->truncated_on_right_p
)
17965 /* display_line already called reseat_at_next_visible_line_start,
17966 which puts the iterator at the beginning of the next line, in
17967 the logical order. */
17968 row
->maxpos
= it
->current
.pos
;
17969 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
17970 /* A line that is entirely from a string/image/stretch... */
17971 row
->maxpos
= row
->minpos
;
17976 row
->maxpos
= it
->current
.pos
;
17979 /* Construct the glyph row IT->glyph_row in the desired matrix of
17980 IT->w from text at the current position of IT. See dispextern.h
17981 for an overview of struct it. Value is non-zero if
17982 IT->glyph_row displays text, as opposed to a line displaying ZV
17986 display_line (struct it
*it
)
17988 struct glyph_row
*row
= it
->glyph_row
;
17989 Lisp_Object overlay_arrow_string
;
17991 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
17992 int wrap_row_used
= -1;
17993 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
17994 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
17995 int wrap_row_extra_line_spacing
IF_LINT (= 0);
17996 EMACS_INT wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
17997 EMACS_INT wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
17999 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
18000 EMACS_INT min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
18002 /* We always start displaying at hpos zero even if hscrolled. */
18003 xassert (it
->hpos
== 0 && it
->current_x
== 0);
18005 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
18006 >= it
->w
->desired_matrix
->nrows
)
18008 it
->w
->nrows_scale_factor
++;
18009 fonts_changed_p
= 1;
18013 /* Is IT->w showing the region? */
18014 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
18016 /* Clear the result glyph row and enable it. */
18017 prepare_desired_row (row
);
18019 row
->y
= it
->current_y
;
18020 row
->start
= it
->start
;
18021 row
->continuation_lines_width
= it
->continuation_lines_width
;
18022 row
->displays_text_p
= 1;
18023 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
18024 it
->starts_in_middle_of_char_p
= 0;
18026 /* Arrange the overlays nicely for our purposes. Usually, we call
18027 display_line on only one line at a time, in which case this
18028 can't really hurt too much, or we call it on lines which appear
18029 one after another in the buffer, in which case all calls to
18030 recenter_overlay_lists but the first will be pretty cheap. */
18031 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
18033 /* Move over display elements that are not visible because we are
18034 hscrolled. This may stop at an x-position < IT->first_visible_x
18035 if the first glyph is partially visible or if we hit a line end. */
18036 if (it
->current_x
< it
->first_visible_x
)
18038 this_line_min_pos
= row
->start
.pos
;
18039 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
18040 MOVE_TO_POS
| MOVE_TO_X
);
18041 /* Record the smallest positions seen while we moved over
18042 display elements that are not visible. This is needed by
18043 redisplay_internal for optimizing the case where the cursor
18044 stays inside the same line. The rest of this function only
18045 considers positions that are actually displayed, so
18046 RECORD_MAX_MIN_POS will not otherwise record positions that
18047 are hscrolled to the left of the left edge of the window. */
18048 min_pos
= CHARPOS (this_line_min_pos
);
18049 min_bpos
= BYTEPOS (this_line_min_pos
);
18053 /* We only do this when not calling `move_it_in_display_line_to'
18054 above, because move_it_in_display_line_to calls
18055 handle_line_prefix itself. */
18056 handle_line_prefix (it
);
18059 /* Get the initial row height. This is either the height of the
18060 text hscrolled, if there is any, or zero. */
18061 row
->ascent
= it
->max_ascent
;
18062 row
->height
= it
->max_ascent
+ it
->max_descent
;
18063 row
->phys_ascent
= it
->max_phys_ascent
;
18064 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18065 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18067 /* Utility macro to record max and min buffer positions seen until now. */
18068 #define RECORD_MAX_MIN_POS(IT) \
18071 if (IT_CHARPOS (*(IT)) < min_pos) \
18073 min_pos = IT_CHARPOS (*(IT)); \
18074 min_bpos = IT_BYTEPOS (*(IT)); \
18076 if (IT_CHARPOS (*(IT)) > max_pos) \
18078 max_pos = IT_CHARPOS (*(IT)); \
18079 max_bpos = IT_BYTEPOS (*(IT)); \
18084 /* Loop generating characters. The loop is left with IT on the next
18085 character to display. */
18088 int n_glyphs_before
, hpos_before
, x_before
;
18090 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
18092 /* Retrieve the next thing to display. Value is zero if end of
18094 if (!get_next_display_element (it
))
18096 /* Maybe add a space at the end of this line that is used to
18097 display the cursor there under X. Set the charpos of the
18098 first glyph of blank lines not corresponding to any text
18100 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18101 row
->exact_window_width_line_p
= 1;
18102 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
18103 || row
->used
[TEXT_AREA
] == 0)
18105 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
18106 row
->displays_text_p
= 0;
18108 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
18109 && (!MINI_WINDOW_P (it
->w
)
18110 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
18111 row
->indicate_empty_line_p
= 1;
18114 it
->continuation_lines_width
= 0;
18115 row
->ends_at_zv_p
= 1;
18116 /* A row that displays right-to-left text must always have
18117 its last face extended all the way to the end of line,
18118 even if this row ends in ZV, because we still write to
18119 the screen left to right. */
18120 if (row
->reversed_p
)
18121 extend_face_to_end_of_line (it
);
18125 /* Now, get the metrics of what we want to display. This also
18126 generates glyphs in `row' (which is IT->glyph_row). */
18127 n_glyphs_before
= row
->used
[TEXT_AREA
];
18130 /* Remember the line height so far in case the next element doesn't
18131 fit on the line. */
18132 if (it
->line_wrap
!= TRUNCATE
)
18134 ascent
= it
->max_ascent
;
18135 descent
= it
->max_descent
;
18136 phys_ascent
= it
->max_phys_ascent
;
18137 phys_descent
= it
->max_phys_descent
;
18139 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
18141 if (IT_DISPLAYING_WHITESPACE (it
))
18147 wrap_row_used
= row
->used
[TEXT_AREA
];
18148 wrap_row_ascent
= row
->ascent
;
18149 wrap_row_height
= row
->height
;
18150 wrap_row_phys_ascent
= row
->phys_ascent
;
18151 wrap_row_phys_height
= row
->phys_height
;
18152 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
18153 wrap_row_min_pos
= min_pos
;
18154 wrap_row_min_bpos
= min_bpos
;
18155 wrap_row_max_pos
= max_pos
;
18156 wrap_row_max_bpos
= max_bpos
;
18162 PRODUCE_GLYPHS (it
);
18164 /* If this display element was in marginal areas, continue with
18166 if (it
->area
!= TEXT_AREA
)
18168 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18169 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18170 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18171 row
->phys_height
= max (row
->phys_height
,
18172 it
->max_phys_ascent
+ it
->max_phys_descent
);
18173 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18174 it
->max_extra_line_spacing
);
18175 set_iterator_to_next (it
, 1);
18179 /* Does the display element fit on the line? If we truncate
18180 lines, we should draw past the right edge of the window. If
18181 we don't truncate, we want to stop so that we can display the
18182 continuation glyph before the right margin. If lines are
18183 continued, there are two possible strategies for characters
18184 resulting in more than 1 glyph (e.g. tabs): Display as many
18185 glyphs as possible in this line and leave the rest for the
18186 continuation line, or display the whole element in the next
18187 line. Original redisplay did the former, so we do it also. */
18188 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
18189 hpos_before
= it
->hpos
;
18192 if (/* Not a newline. */
18194 /* Glyphs produced fit entirely in the line. */
18195 && it
->current_x
< it
->last_visible_x
)
18197 it
->hpos
+= nglyphs
;
18198 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18199 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18200 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18201 row
->phys_height
= max (row
->phys_height
,
18202 it
->max_phys_ascent
+ it
->max_phys_descent
);
18203 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18204 it
->max_extra_line_spacing
);
18205 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
18206 row
->x
= x
- it
->first_visible_x
;
18207 /* Record the maximum and minimum buffer positions seen so
18208 far in glyphs that will be displayed by this row. */
18210 RECORD_MAX_MIN_POS (it
);
18215 struct glyph
*glyph
;
18217 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
18219 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18220 new_x
= x
+ glyph
->pixel_width
;
18222 if (/* Lines are continued. */
18223 it
->line_wrap
!= TRUNCATE
18224 && (/* Glyph doesn't fit on the line. */
18225 new_x
> it
->last_visible_x
18226 /* Or it fits exactly on a window system frame. */
18227 || (new_x
== it
->last_visible_x
18228 && FRAME_WINDOW_P (it
->f
))))
18230 /* End of a continued line. */
18233 || (new_x
== it
->last_visible_x
18234 && FRAME_WINDOW_P (it
->f
)))
18236 /* Current glyph is the only one on the line or
18237 fits exactly on the line. We must continue
18238 the line because we can't draw the cursor
18239 after the glyph. */
18240 row
->continued_p
= 1;
18241 it
->current_x
= new_x
;
18242 it
->continuation_lines_width
+= new_x
;
18244 /* Record the maximum and minimum buffer
18245 positions seen so far in glyphs that will be
18246 displayed by this row. */
18248 RECORD_MAX_MIN_POS (it
);
18249 if (i
== nglyphs
- 1)
18251 /* If line-wrap is on, check if a previous
18252 wrap point was found. */
18253 if (wrap_row_used
> 0
18254 /* Even if there is a previous wrap
18255 point, continue the line here as
18256 usual, if (i) the previous character
18257 was a space or tab AND (ii) the
18258 current character is not. */
18260 || IT_DISPLAYING_WHITESPACE (it
)))
18263 set_iterator_to_next (it
, 1);
18264 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18266 if (!get_next_display_element (it
))
18268 row
->exact_window_width_line_p
= 1;
18269 it
->continuation_lines_width
= 0;
18270 row
->continued_p
= 0;
18271 row
->ends_at_zv_p
= 1;
18273 else if (ITERATOR_AT_END_OF_LINE_P (it
))
18275 row
->continued_p
= 0;
18276 row
->exact_window_width_line_p
= 1;
18281 else if (CHAR_GLYPH_PADDING_P (*glyph
)
18282 && !FRAME_WINDOW_P (it
->f
))
18284 /* A padding glyph that doesn't fit on this line.
18285 This means the whole character doesn't fit
18287 if (row
->reversed_p
)
18288 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
18289 - n_glyphs_before
);
18290 row
->used
[TEXT_AREA
] = n_glyphs_before
;
18292 /* Fill the rest of the row with continuation
18293 glyphs like in 20.x. */
18294 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
18295 < row
->glyphs
[1 + TEXT_AREA
])
18296 produce_special_glyphs (it
, IT_CONTINUATION
);
18298 row
->continued_p
= 1;
18299 it
->current_x
= x_before
;
18300 it
->continuation_lines_width
+= x_before
;
18302 /* Restore the height to what it was before the
18303 element not fitting on the line. */
18304 it
->max_ascent
= ascent
;
18305 it
->max_descent
= descent
;
18306 it
->max_phys_ascent
= phys_ascent
;
18307 it
->max_phys_descent
= phys_descent
;
18309 else if (wrap_row_used
> 0)
18312 if (row
->reversed_p
)
18313 unproduce_glyphs (it
,
18314 row
->used
[TEXT_AREA
] - wrap_row_used
);
18316 it
->continuation_lines_width
+= wrap_x
;
18317 row
->used
[TEXT_AREA
] = wrap_row_used
;
18318 row
->ascent
= wrap_row_ascent
;
18319 row
->height
= wrap_row_height
;
18320 row
->phys_ascent
= wrap_row_phys_ascent
;
18321 row
->phys_height
= wrap_row_phys_height
;
18322 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
18323 min_pos
= wrap_row_min_pos
;
18324 min_bpos
= wrap_row_min_bpos
;
18325 max_pos
= wrap_row_max_pos
;
18326 max_bpos
= wrap_row_max_bpos
;
18327 row
->continued_p
= 1;
18328 row
->ends_at_zv_p
= 0;
18329 row
->exact_window_width_line_p
= 0;
18330 it
->continuation_lines_width
+= x
;
18332 /* Make sure that a non-default face is extended
18333 up to the right margin of the window. */
18334 extend_face_to_end_of_line (it
);
18336 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
18338 /* A TAB that extends past the right edge of the
18339 window. This produces a single glyph on
18340 window system frames. We leave the glyph in
18341 this row and let it fill the row, but don't
18342 consume the TAB. */
18343 it
->continuation_lines_width
+= it
->last_visible_x
;
18344 row
->ends_in_middle_of_char_p
= 1;
18345 row
->continued_p
= 1;
18346 glyph
->pixel_width
= it
->last_visible_x
- x
;
18347 it
->starts_in_middle_of_char_p
= 1;
18351 /* Something other than a TAB that draws past
18352 the right edge of the window. Restore
18353 positions to values before the element. */
18354 if (row
->reversed_p
)
18355 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
18356 - (n_glyphs_before
+ i
));
18357 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18359 /* Display continuation glyphs. */
18360 if (!FRAME_WINDOW_P (it
->f
))
18361 produce_special_glyphs (it
, IT_CONTINUATION
);
18362 row
->continued_p
= 1;
18364 it
->current_x
= x_before
;
18365 it
->continuation_lines_width
+= x
;
18366 extend_face_to_end_of_line (it
);
18368 if (nglyphs
> 1 && i
> 0)
18370 row
->ends_in_middle_of_char_p
= 1;
18371 it
->starts_in_middle_of_char_p
= 1;
18374 /* Restore the height to what it was before the
18375 element not fitting on the line. */
18376 it
->max_ascent
= ascent
;
18377 it
->max_descent
= descent
;
18378 it
->max_phys_ascent
= phys_ascent
;
18379 it
->max_phys_descent
= phys_descent
;
18384 else if (new_x
> it
->first_visible_x
)
18386 /* Increment number of glyphs actually displayed. */
18389 /* Record the maximum and minimum buffer positions
18390 seen so far in glyphs that will be displayed by
18393 RECORD_MAX_MIN_POS (it
);
18395 if (x
< it
->first_visible_x
)
18396 /* Glyph is partially visible, i.e. row starts at
18397 negative X position. */
18398 row
->x
= x
- it
->first_visible_x
;
18402 /* Glyph is completely off the left margin of the
18403 window. This should not happen because of the
18404 move_it_in_display_line at the start of this
18405 function, unless the text display area of the
18406 window is empty. */
18407 xassert (it
->first_visible_x
<= it
->last_visible_x
);
18411 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18412 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18413 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18414 row
->phys_height
= max (row
->phys_height
,
18415 it
->max_phys_ascent
+ it
->max_phys_descent
);
18416 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18417 it
->max_extra_line_spacing
);
18419 /* End of this display line if row is continued. */
18420 if (row
->continued_p
|| row
->ends_at_zv_p
)
18425 /* Is this a line end? If yes, we're also done, after making
18426 sure that a non-default face is extended up to the right
18427 margin of the window. */
18428 if (ITERATOR_AT_END_OF_LINE_P (it
))
18430 int used_before
= row
->used
[TEXT_AREA
];
18432 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
18434 /* Add a space at the end of the line that is used to
18435 display the cursor there. */
18436 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18437 append_space_for_newline (it
, 0);
18439 /* Extend the face to the end of the line. */
18440 extend_face_to_end_of_line (it
);
18442 /* Make sure we have the position. */
18443 if (used_before
== 0)
18444 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
18446 /* Record the position of the newline, for use in
18448 it
->eol_pos
= it
->current
.pos
;
18450 /* Consume the line end. This skips over invisible lines. */
18451 set_iterator_to_next (it
, 1);
18452 it
->continuation_lines_width
= 0;
18456 /* Proceed with next display element. Note that this skips
18457 over lines invisible because of selective display. */
18458 set_iterator_to_next (it
, 1);
18460 /* If we truncate lines, we are done when the last displayed
18461 glyphs reach past the right margin of the window. */
18462 if (it
->line_wrap
== TRUNCATE
18463 && (FRAME_WINDOW_P (it
->f
)
18464 ? (it
->current_x
>= it
->last_visible_x
)
18465 : (it
->current_x
> it
->last_visible_x
)))
18467 /* Maybe add truncation glyphs. */
18468 if (!FRAME_WINDOW_P (it
->f
))
18472 if (!row
->reversed_p
)
18474 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18475 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18480 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
18481 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18483 /* Remove any padding glyphs at the front of ROW, to
18484 make room for the truncation glyphs we will be
18485 adding below. The loop below always inserts at
18486 least one truncation glyph, so also remove the
18487 last glyph added to ROW. */
18488 unproduce_glyphs (it
, i
+ 1);
18489 /* Adjust i for the loop below. */
18490 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
18493 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18495 row
->used
[TEXT_AREA
] = i
;
18496 produce_special_glyphs (it
, IT_TRUNCATION
);
18499 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18501 /* Don't truncate if we can overflow newline into fringe. */
18502 if (!get_next_display_element (it
))
18504 it
->continuation_lines_width
= 0;
18505 row
->ends_at_zv_p
= 1;
18506 row
->exact_window_width_line_p
= 1;
18509 if (ITERATOR_AT_END_OF_LINE_P (it
))
18511 row
->exact_window_width_line_p
= 1;
18512 goto at_end_of_line
;
18516 row
->truncated_on_right_p
= 1;
18517 it
->continuation_lines_width
= 0;
18518 reseat_at_next_visible_line_start (it
, 0);
18519 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
18520 it
->hpos
= hpos_before
;
18521 it
->current_x
= x_before
;
18526 /* If line is not empty and hscrolled, maybe insert truncation glyphs
18527 at the left window margin. */
18528 if (it
->first_visible_x
18529 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
18531 if (!FRAME_WINDOW_P (it
->f
))
18532 insert_left_trunc_glyphs (it
);
18533 row
->truncated_on_left_p
= 1;
18536 /* Remember the position at which this line ends.
18538 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
18539 cannot be before the call to find_row_edges below, since that is
18540 where these positions are determined. */
18541 row
->end
= it
->current
;
18544 row
->minpos
= row
->start
.pos
;
18545 row
->maxpos
= row
->end
.pos
;
18549 /* ROW->minpos and ROW->maxpos must be the smallest and
18550 `1 + the largest' buffer positions in ROW. But if ROW was
18551 bidi-reordered, these two positions can be anywhere in the
18552 row, so we must determine them now. */
18553 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
18556 /* If the start of this line is the overlay arrow-position, then
18557 mark this glyph row as the one containing the overlay arrow.
18558 This is clearly a mess with variable size fonts. It would be
18559 better to let it be displayed like cursors under X. */
18560 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
18561 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
18562 !NILP (overlay_arrow_string
)))
18564 /* Overlay arrow in window redisplay is a fringe bitmap. */
18565 if (STRINGP (overlay_arrow_string
))
18567 struct glyph_row
*arrow_row
18568 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
18569 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
18570 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
18571 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
18572 struct glyph
*p2
, *end
;
18574 /* Copy the arrow glyphs. */
18575 while (glyph
< arrow_end
)
18578 /* Throw away padding glyphs. */
18580 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
18581 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
18587 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
18592 xassert (INTEGERP (overlay_arrow_string
));
18593 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
18595 overlay_arrow_seen
= 1;
18598 /* Compute pixel dimensions of this line. */
18599 compute_line_metrics (it
);
18601 /* Record whether this row ends inside an ellipsis. */
18602 row
->ends_in_ellipsis_p
18603 = (it
->method
== GET_FROM_DISPLAY_VECTOR
18604 && it
->ellipsis_p
);
18606 /* Save fringe bitmaps in this row. */
18607 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
18608 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
18609 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
18610 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
18612 it
->left_user_fringe_bitmap
= 0;
18613 it
->left_user_fringe_face_id
= 0;
18614 it
->right_user_fringe_bitmap
= 0;
18615 it
->right_user_fringe_face_id
= 0;
18617 /* Maybe set the cursor. */
18618 cvpos
= it
->w
->cursor
.vpos
;
18620 /* In bidi-reordered rows, keep checking for proper cursor
18621 position even if one has been found already, because buffer
18622 positions in such rows change non-linearly with ROW->VPOS,
18623 when a line is continued. One exception: when we are at ZV,
18624 display cursor on the first suitable glyph row, since all
18625 the empty rows after that also have their position set to ZV. */
18626 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18627 lines' rows is implemented for bidi-reordered rows. */
18629 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
18630 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
18631 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
18632 && cursor_row_p (row
))
18633 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
18635 /* Highlight trailing whitespace. */
18636 if (!NILP (Vshow_trailing_whitespace
))
18637 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
18639 /* Prepare for the next line. This line starts horizontally at (X
18640 HPOS) = (0 0). Vertical positions are incremented. As a
18641 convenience for the caller, IT->glyph_row is set to the next
18643 it
->current_x
= it
->hpos
= 0;
18644 it
->current_y
+= row
->height
;
18645 SET_TEXT_POS (it
->eol_pos
, 0, 0);
18648 /* The next row should by default use the same value of the
18649 reversed_p flag as this one. set_iterator_to_next decides when
18650 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
18651 the flag accordingly. */
18652 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
18653 it
->glyph_row
->reversed_p
= row
->reversed_p
;
18654 it
->start
= row
->end
;
18655 return row
->displays_text_p
;
18657 #undef RECORD_MAX_MIN_POS
18660 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
18661 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
18662 doc
: /* Return paragraph direction at point in BUFFER.
18663 Value is either `left-to-right' or `right-to-left'.
18664 If BUFFER is omitted or nil, it defaults to the current buffer.
18666 Paragraph direction determines how the text in the paragraph is displayed.
18667 In left-to-right paragraphs, text begins at the left margin of the window
18668 and the reading direction is generally left to right. In right-to-left
18669 paragraphs, text begins at the right margin and is read from right to left.
18671 See also `bidi-paragraph-direction'. */)
18672 (Lisp_Object buffer
)
18674 struct buffer
*buf
= current_buffer
;
18675 struct buffer
*old
= buf
;
18677 if (! NILP (buffer
))
18679 CHECK_BUFFER (buffer
);
18680 buf
= XBUFFER (buffer
);
18683 if (NILP (BVAR (buf
, bidi_display_reordering
)))
18684 return Qleft_to_right
;
18685 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
18686 return BVAR (buf
, bidi_paragraph_direction
);
18689 /* Determine the direction from buffer text. We could try to
18690 use current_matrix if it is up to date, but this seems fast
18691 enough as it is. */
18692 struct bidi_it itb
;
18693 EMACS_INT pos
= BUF_PT (buf
);
18694 EMACS_INT bytepos
= BUF_PT_BYTE (buf
);
18697 set_buffer_temp (buf
);
18698 /* bidi_paragraph_init finds the base direction of the paragraph
18699 by searching forward from paragraph start. We need the base
18700 direction of the current or _previous_ paragraph, so we need
18701 to make sure we are within that paragraph. To that end, find
18702 the previous non-empty line. */
18703 if (pos
>= ZV
&& pos
> BEGV
)
18706 bytepos
= CHAR_TO_BYTE (pos
);
18708 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
18709 || c
== ' ' || c
== '\t' || c
== '\f')
18711 if (bytepos
<= BEGV_BYTE
)
18716 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
18719 itb
.bytepos
= bytepos
;
18721 itb
.string
.s
= NULL
;
18722 itb
.string
.lstring
= Qnil
;
18723 itb
.frame_window_p
= FRAME_WINDOW_P (SELECTED_FRAME ()); /* guesswork */
18725 itb
.separator_limit
= -1;
18726 itb
.paragraph_dir
= NEUTRAL_DIR
;
18728 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
18729 set_buffer_temp (old
);
18730 switch (itb
.paragraph_dir
)
18733 return Qleft_to_right
;
18736 return Qright_to_left
;
18746 /***********************************************************************
18748 ***********************************************************************/
18750 /* Redisplay the menu bar in the frame for window W.
18752 The menu bar of X frames that don't have X toolkit support is
18753 displayed in a special window W->frame->menu_bar_window.
18755 The menu bar of terminal frames is treated specially as far as
18756 glyph matrices are concerned. Menu bar lines are not part of
18757 windows, so the update is done directly on the frame matrix rows
18758 for the menu bar. */
18761 display_menu_bar (struct window
*w
)
18763 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18768 /* Don't do all this for graphical frames. */
18770 if (FRAME_W32_P (f
))
18773 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
18779 if (FRAME_NS_P (f
))
18781 #endif /* HAVE_NS */
18783 #ifdef USE_X_TOOLKIT
18784 xassert (!FRAME_WINDOW_P (f
));
18785 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
18786 it
.first_visible_x
= 0;
18787 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18788 #else /* not USE_X_TOOLKIT */
18789 if (FRAME_WINDOW_P (f
))
18791 /* Menu bar lines are displayed in the desired matrix of the
18792 dummy window menu_bar_window. */
18793 struct window
*menu_w
;
18794 xassert (WINDOWP (f
->menu_bar_window
));
18795 menu_w
= XWINDOW (f
->menu_bar_window
);
18796 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
18798 it
.first_visible_x
= 0;
18799 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18803 /* This is a TTY frame, i.e. character hpos/vpos are used as
18805 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
18807 it
.first_visible_x
= 0;
18808 it
.last_visible_x
= FRAME_COLS (f
);
18810 #endif /* not USE_X_TOOLKIT */
18812 /* FIXME: This should be controlled by a user option. See the
18813 comments in redisplay_tool_bar and display_mode_line about
18815 it
.paragraph_embedding
= L2R
;
18817 if (! mode_line_inverse_video
)
18818 /* Force the menu-bar to be displayed in the default face. */
18819 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18821 /* Clear all rows of the menu bar. */
18822 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
18824 struct glyph_row
*row
= it
.glyph_row
+ i
;
18825 clear_glyph_row (row
);
18826 row
->enabled_p
= 1;
18827 row
->full_width_p
= 1;
18830 /* Display all items of the menu bar. */
18831 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
18832 for (i
= 0; i
< ASIZE (items
); i
+= 4)
18834 Lisp_Object string
;
18836 /* Stop at nil string. */
18837 string
= AREF (items
, i
+ 1);
18841 /* Remember where item was displayed. */
18842 ASET (items
, i
+ 3, make_number (it
.hpos
));
18844 /* Display the item, pad with one space. */
18845 if (it
.current_x
< it
.last_visible_x
)
18846 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
18847 SCHARS (string
) + 1, 0, 0, -1);
18850 /* Fill out the line with spaces. */
18851 if (it
.current_x
< it
.last_visible_x
)
18852 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
18854 /* Compute the total height of the lines. */
18855 compute_line_metrics (&it
);
18860 /***********************************************************************
18862 ***********************************************************************/
18864 /* Redisplay mode lines in the window tree whose root is WINDOW. If
18865 FORCE is non-zero, redisplay mode lines unconditionally.
18866 Otherwise, redisplay only mode lines that are garbaged. Value is
18867 the number of windows whose mode lines were redisplayed. */
18870 redisplay_mode_lines (Lisp_Object window
, int force
)
18874 while (!NILP (window
))
18876 struct window
*w
= XWINDOW (window
);
18878 if (WINDOWP (w
->hchild
))
18879 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
18880 else if (WINDOWP (w
->vchild
))
18881 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18883 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18884 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18886 struct text_pos lpoint
;
18887 struct buffer
*old
= current_buffer
;
18889 /* Set the window's buffer for the mode line display. */
18890 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18891 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18893 /* Point refers normally to the selected window. For any
18894 other window, set up appropriate value. */
18895 if (!EQ (window
, selected_window
))
18897 struct text_pos pt
;
18899 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18900 if (CHARPOS (pt
) < BEGV
)
18901 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18902 else if (CHARPOS (pt
) > (ZV
- 1))
18903 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18905 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18908 /* Display mode lines. */
18909 clear_glyph_matrix (w
->desired_matrix
);
18910 if (display_mode_lines (w
))
18913 w
->must_be_updated_p
= 1;
18916 /* Restore old settings. */
18917 set_buffer_internal_1 (old
);
18918 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18928 /* Display the mode and/or header line of window W. Value is the
18929 sum number of mode lines and header lines displayed. */
18932 display_mode_lines (struct window
*w
)
18934 Lisp_Object old_selected_window
, old_selected_frame
;
18937 old_selected_frame
= selected_frame
;
18938 selected_frame
= w
->frame
;
18939 old_selected_window
= selected_window
;
18940 XSETWINDOW (selected_window
, w
);
18942 /* These will be set while the mode line specs are processed. */
18943 line_number_displayed
= 0;
18944 w
->column_number_displayed
= Qnil
;
18946 if (WINDOW_WANTS_MODELINE_P (w
))
18948 struct window
*sel_w
= XWINDOW (old_selected_window
);
18950 /* Select mode line face based on the real selected window. */
18951 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18952 BVAR (current_buffer
, mode_line_format
));
18956 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18958 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18959 BVAR (current_buffer
, header_line_format
));
18963 selected_frame
= old_selected_frame
;
18964 selected_window
= old_selected_window
;
18969 /* Display mode or header line of window W. FACE_ID specifies which
18970 line to display; it is either MODE_LINE_FACE_ID or
18971 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18972 display. Value is the pixel height of the mode/header line
18976 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
18980 int count
= SPECPDL_INDEX ();
18982 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18983 /* Don't extend on a previously drawn mode-line.
18984 This may happen if called from pos_visible_p. */
18985 it
.glyph_row
->enabled_p
= 0;
18986 prepare_desired_row (it
.glyph_row
);
18988 it
.glyph_row
->mode_line_p
= 1;
18990 if (! mode_line_inverse_video
)
18991 /* Force the mode-line to be displayed in the default face. */
18992 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18994 /* FIXME: This should be controlled by a user option. But
18995 supporting such an option is not trivial, since the mode line is
18996 made up of many separate strings. */
18997 it
.paragraph_embedding
= L2R
;
18999 record_unwind_protect (unwind_format_mode_line
,
19000 format_mode_line_unwind_data (NULL
, Qnil
, 0));
19002 mode_line_target
= MODE_LINE_DISPLAY
;
19004 /* Temporarily make frame's keyboard the current kboard so that
19005 kboard-local variables in the mode_line_format will get the right
19007 push_kboard (FRAME_KBOARD (it
.f
));
19008 record_unwind_save_match_data ();
19009 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19012 unbind_to (count
, Qnil
);
19014 /* Fill up with spaces. */
19015 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
19017 compute_line_metrics (&it
);
19018 it
.glyph_row
->full_width_p
= 1;
19019 it
.glyph_row
->continued_p
= 0;
19020 it
.glyph_row
->truncated_on_left_p
= 0;
19021 it
.glyph_row
->truncated_on_right_p
= 0;
19023 /* Make a 3D mode-line have a shadow at its right end. */
19024 face
= FACE_FROM_ID (it
.f
, face_id
);
19025 extend_face_to_end_of_line (&it
);
19026 if (face
->box
!= FACE_NO_BOX
)
19028 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
19029 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
19030 last
->right_box_line_p
= 1;
19033 return it
.glyph_row
->height
;
19036 /* Move element ELT in LIST to the front of LIST.
19037 Return the updated list. */
19040 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
19042 register Lisp_Object tail
, prev
;
19043 register Lisp_Object tem
;
19047 while (CONSP (tail
))
19053 /* Splice out the link TAIL. */
19055 list
= XCDR (tail
);
19057 Fsetcdr (prev
, XCDR (tail
));
19059 /* Now make it the first. */
19060 Fsetcdr (tail
, list
);
19065 tail
= XCDR (tail
);
19069 /* Not found--return unchanged LIST. */
19073 /* Contribute ELT to the mode line for window IT->w. How it
19074 translates into text depends on its data type.
19076 IT describes the display environment in which we display, as usual.
19078 DEPTH is the depth in recursion. It is used to prevent
19079 infinite recursion here.
19081 FIELD_WIDTH is the number of characters the display of ELT should
19082 occupy in the mode line, and PRECISION is the maximum number of
19083 characters to display from ELT's representation. See
19084 display_string for details.
19086 Returns the hpos of the end of the text generated by ELT.
19088 PROPS is a property list to add to any string we encounter.
19090 If RISKY is nonzero, remove (disregard) any properties in any string
19091 we encounter, and ignore :eval and :propertize.
19093 The global variable `mode_line_target' determines whether the
19094 output is passed to `store_mode_line_noprop',
19095 `store_mode_line_string', or `display_string'. */
19098 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
19099 Lisp_Object elt
, Lisp_Object props
, int risky
)
19101 int n
= 0, field
, prec
;
19106 elt
= build_string ("*too-deep*");
19110 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
19114 /* A string: output it and check for %-constructs within it. */
19116 EMACS_INT offset
= 0;
19118 if (SCHARS (elt
) > 0
19119 && (!NILP (props
) || risky
))
19121 Lisp_Object oprops
, aelt
;
19122 oprops
= Ftext_properties_at (make_number (0), elt
);
19124 /* If the starting string's properties are not what
19125 we want, translate the string. Also, if the string
19126 is risky, do that anyway. */
19128 if (NILP (Fequal (props
, oprops
)) || risky
)
19130 /* If the starting string has properties,
19131 merge the specified ones onto the existing ones. */
19132 if (! NILP (oprops
) && !risky
)
19136 oprops
= Fcopy_sequence (oprops
);
19138 while (CONSP (tem
))
19140 oprops
= Fplist_put (oprops
, XCAR (tem
),
19141 XCAR (XCDR (tem
)));
19142 tem
= XCDR (XCDR (tem
));
19147 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
19148 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
19150 /* AELT is what we want. Move it to the front
19151 without consing. */
19153 mode_line_proptrans_alist
19154 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
19160 /* If AELT has the wrong props, it is useless.
19161 so get rid of it. */
19163 mode_line_proptrans_alist
19164 = Fdelq (aelt
, mode_line_proptrans_alist
);
19166 elt
= Fcopy_sequence (elt
);
19167 Fset_text_properties (make_number (0), Flength (elt
),
19169 /* Add this item to mode_line_proptrans_alist. */
19170 mode_line_proptrans_alist
19171 = Fcons (Fcons (elt
, props
),
19172 mode_line_proptrans_alist
);
19173 /* Truncate mode_line_proptrans_alist
19174 to at most 50 elements. */
19175 tem
= Fnthcdr (make_number (50),
19176 mode_line_proptrans_alist
);
19178 XSETCDR (tem
, Qnil
);
19187 prec
= precision
- n
;
19188 switch (mode_line_target
)
19190 case MODE_LINE_NOPROP
:
19191 case MODE_LINE_TITLE
:
19192 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
19194 case MODE_LINE_STRING
:
19195 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
19197 case MODE_LINE_DISPLAY
:
19198 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
19199 0, prec
, 0, STRING_MULTIBYTE (elt
));
19206 /* Handle the non-literal case. */
19208 while ((precision
<= 0 || n
< precision
)
19209 && SREF (elt
, offset
) != 0
19210 && (mode_line_target
!= MODE_LINE_DISPLAY
19211 || it
->current_x
< it
->last_visible_x
))
19213 EMACS_INT last_offset
= offset
;
19215 /* Advance to end of string or next format specifier. */
19216 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
19219 if (offset
- 1 != last_offset
)
19221 EMACS_INT nchars
, nbytes
;
19223 /* Output to end of string or up to '%'. Field width
19224 is length of string. Don't output more than
19225 PRECISION allows us. */
19228 prec
= c_string_width (SDATA (elt
) + last_offset
,
19229 offset
- last_offset
, precision
- n
,
19232 switch (mode_line_target
)
19234 case MODE_LINE_NOPROP
:
19235 case MODE_LINE_TITLE
:
19236 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
19238 case MODE_LINE_STRING
:
19240 EMACS_INT bytepos
= last_offset
;
19241 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
19242 EMACS_INT endpos
= (precision
<= 0
19243 ? string_byte_to_char (elt
, offset
)
19244 : charpos
+ nchars
);
19246 n
+= store_mode_line_string (NULL
,
19247 Fsubstring (elt
, make_number (charpos
),
19248 make_number (endpos
)),
19252 case MODE_LINE_DISPLAY
:
19254 EMACS_INT bytepos
= last_offset
;
19255 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
19257 if (precision
<= 0)
19258 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
19259 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
19261 STRING_MULTIBYTE (elt
));
19266 else /* c == '%' */
19268 EMACS_INT percent_position
= offset
;
19270 /* Get the specified minimum width. Zero means
19273 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
19274 field
= field
* 10 + c
- '0';
19276 /* Don't pad beyond the total padding allowed. */
19277 if (field_width
- n
> 0 && field
> field_width
- n
)
19278 field
= field_width
- n
;
19280 /* Note that either PRECISION <= 0 or N < PRECISION. */
19281 prec
= precision
- n
;
19284 n
+= display_mode_element (it
, depth
, field
, prec
,
19285 Vglobal_mode_string
, props
,
19290 EMACS_INT bytepos
, charpos
;
19292 Lisp_Object string
;
19294 bytepos
= percent_position
;
19295 charpos
= (STRING_MULTIBYTE (elt
)
19296 ? string_byte_to_char (elt
, bytepos
)
19298 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
19299 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
19301 switch (mode_line_target
)
19303 case MODE_LINE_NOPROP
:
19304 case MODE_LINE_TITLE
:
19305 n
+= store_mode_line_noprop (spec
, field
, prec
);
19307 case MODE_LINE_STRING
:
19309 int len
= strlen (spec
);
19310 Lisp_Object tem
= make_string (spec
, len
);
19311 props
= Ftext_properties_at (make_number (charpos
), elt
);
19312 /* Should only keep face property in props */
19313 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
19316 case MODE_LINE_DISPLAY
:
19318 int nglyphs_before
, nwritten
;
19320 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
19321 nwritten
= display_string (spec
, string
, elt
,
19326 /* Assign to the glyphs written above the
19327 string where the `%x' came from, position
19331 struct glyph
*glyph
19332 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
19336 for (i
= 0; i
< nwritten
; ++i
)
19338 glyph
[i
].object
= elt
;
19339 glyph
[i
].charpos
= charpos
;
19356 /* A symbol: process the value of the symbol recursively
19357 as if it appeared here directly. Avoid error if symbol void.
19358 Special case: if value of symbol is a string, output the string
19361 register Lisp_Object tem
;
19363 /* If the variable is not marked as risky to set
19364 then its contents are risky to use. */
19365 if (NILP (Fget (elt
, Qrisky_local_variable
)))
19368 tem
= Fboundp (elt
);
19371 tem
= Fsymbol_value (elt
);
19372 /* If value is a string, output that string literally:
19373 don't check for % within it. */
19377 if (!EQ (tem
, elt
))
19379 /* Give up right away for nil or t. */
19389 register Lisp_Object car
, tem
;
19391 /* A cons cell: five distinct cases.
19392 If first element is :eval or :propertize, do something special.
19393 If first element is a string or a cons, process all the elements
19394 and effectively concatenate them.
19395 If first element is a negative number, truncate displaying cdr to
19396 at most that many characters. If positive, pad (with spaces)
19397 to at least that many characters.
19398 If first element is a symbol, process the cadr or caddr recursively
19399 according to whether the symbol's value is non-nil or nil. */
19401 if (EQ (car
, QCeval
))
19403 /* An element of the form (:eval FORM) means evaluate FORM
19404 and use the result as mode line elements. */
19409 if (CONSP (XCDR (elt
)))
19412 spec
= safe_eval (XCAR (XCDR (elt
)));
19413 n
+= display_mode_element (it
, depth
, field_width
- n
,
19414 precision
- n
, spec
, props
,
19418 else if (EQ (car
, QCpropertize
))
19420 /* An element of the form (:propertize ELT PROPS...)
19421 means display ELT but applying properties PROPS. */
19426 if (CONSP (XCDR (elt
)))
19427 n
+= display_mode_element (it
, depth
, field_width
- n
,
19428 precision
- n
, XCAR (XCDR (elt
)),
19429 XCDR (XCDR (elt
)), risky
);
19431 else if (SYMBOLP (car
))
19433 tem
= Fboundp (car
);
19437 /* elt is now the cdr, and we know it is a cons cell.
19438 Use its car if CAR has a non-nil value. */
19441 tem
= Fsymbol_value (car
);
19448 /* Symbol's value is nil (or symbol is unbound)
19449 Get the cddr of the original list
19450 and if possible find the caddr and use that. */
19454 else if (!CONSP (elt
))
19459 else if (INTEGERP (car
))
19461 register int lim
= XINT (car
);
19465 /* Negative int means reduce maximum width. */
19466 if (precision
<= 0)
19469 precision
= min (precision
, -lim
);
19473 /* Padding specified. Don't let it be more than
19474 current maximum. */
19476 lim
= min (precision
, lim
);
19478 /* If that's more padding than already wanted, queue it.
19479 But don't reduce padding already specified even if
19480 that is beyond the current truncation point. */
19481 field_width
= max (lim
, field_width
);
19485 else if (STRINGP (car
) || CONSP (car
))
19487 Lisp_Object halftail
= elt
;
19491 && (precision
<= 0 || n
< precision
))
19493 n
+= display_mode_element (it
, depth
,
19494 /* Do padding only after the last
19495 element in the list. */
19496 (! CONSP (XCDR (elt
))
19499 precision
- n
, XCAR (elt
),
19503 if ((len
& 1) == 0)
19504 halftail
= XCDR (halftail
);
19505 /* Check for cycle. */
19506 if (EQ (halftail
, elt
))
19515 elt
= build_string ("*invalid*");
19519 /* Pad to FIELD_WIDTH. */
19520 if (field_width
> 0 && n
< field_width
)
19522 switch (mode_line_target
)
19524 case MODE_LINE_NOPROP
:
19525 case MODE_LINE_TITLE
:
19526 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
19528 case MODE_LINE_STRING
:
19529 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
19531 case MODE_LINE_DISPLAY
:
19532 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
19541 /* Store a mode-line string element in mode_line_string_list.
19543 If STRING is non-null, display that C string. Otherwise, the Lisp
19544 string LISP_STRING is displayed.
19546 FIELD_WIDTH is the minimum number of output glyphs to produce.
19547 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19548 with spaces. FIELD_WIDTH <= 0 means don't pad.
19550 PRECISION is the maximum number of characters to output from
19551 STRING. PRECISION <= 0 means don't truncate the string.
19553 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
19554 properties to the string.
19556 PROPS are the properties to add to the string.
19557 The mode_line_string_face face property is always added to the string.
19561 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
19562 int field_width
, int precision
, Lisp_Object props
)
19567 if (string
!= NULL
)
19569 len
= strlen (string
);
19570 if (precision
> 0 && len
> precision
)
19572 lisp_string
= make_string (string
, len
);
19574 props
= mode_line_string_face_prop
;
19575 else if (!NILP (mode_line_string_face
))
19577 Lisp_Object face
= Fplist_get (props
, Qface
);
19578 props
= Fcopy_sequence (props
);
19580 face
= mode_line_string_face
;
19582 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19583 props
= Fplist_put (props
, Qface
, face
);
19585 Fadd_text_properties (make_number (0), make_number (len
),
19586 props
, lisp_string
);
19590 len
= XFASTINT (Flength (lisp_string
));
19591 if (precision
> 0 && len
> precision
)
19594 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
19597 if (!NILP (mode_line_string_face
))
19601 props
= Ftext_properties_at (make_number (0), lisp_string
);
19602 face
= Fplist_get (props
, Qface
);
19604 face
= mode_line_string_face
;
19606 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19607 props
= Fcons (Qface
, Fcons (face
, Qnil
));
19609 lisp_string
= Fcopy_sequence (lisp_string
);
19612 Fadd_text_properties (make_number (0), make_number (len
),
19613 props
, lisp_string
);
19618 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19622 if (field_width
> len
)
19624 field_width
-= len
;
19625 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
19627 Fadd_text_properties (make_number (0), make_number (field_width
),
19628 props
, lisp_string
);
19629 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19637 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
19639 doc
: /* Format a string out of a mode line format specification.
19640 First arg FORMAT specifies the mode line format (see `mode-line-format'
19641 for details) to use.
19643 By default, the format is evaluated for the currently selected window.
19645 Optional second arg FACE specifies the face property to put on all
19646 characters for which no face is specified. The value nil means the
19647 default face. The value t means whatever face the window's mode line
19648 currently uses (either `mode-line' or `mode-line-inactive',
19649 depending on whether the window is the selected window or not).
19650 An integer value means the value string has no text
19653 Optional third and fourth args WINDOW and BUFFER specify the window
19654 and buffer to use as the context for the formatting (defaults
19655 are the selected window and the WINDOW's buffer). */)
19656 (Lisp_Object format
, Lisp_Object face
,
19657 Lisp_Object window
, Lisp_Object buffer
)
19662 struct buffer
*old_buffer
= NULL
;
19664 int no_props
= INTEGERP (face
);
19665 int count
= SPECPDL_INDEX ();
19667 int string_start
= 0;
19670 window
= selected_window
;
19671 CHECK_WINDOW (window
);
19672 w
= XWINDOW (window
);
19675 buffer
= w
->buffer
;
19676 CHECK_BUFFER (buffer
);
19678 /* Make formatting the modeline a non-op when noninteractive, otherwise
19679 there will be problems later caused by a partially initialized frame. */
19680 if (NILP (format
) || noninteractive
)
19681 return empty_unibyte_string
;
19686 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
19687 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
19688 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
19689 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
19690 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
19691 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
19692 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
19695 if (XBUFFER (buffer
) != current_buffer
)
19696 old_buffer
= current_buffer
;
19698 /* Save things including mode_line_proptrans_alist,
19699 and set that to nil so that we don't alter the outer value. */
19700 record_unwind_protect (unwind_format_mode_line
,
19701 format_mode_line_unwind_data
19702 (old_buffer
, selected_window
, 1));
19703 mode_line_proptrans_alist
= Qnil
;
19705 Fselect_window (window
, Qt
);
19707 set_buffer_internal_1 (XBUFFER (buffer
));
19709 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19713 mode_line_target
= MODE_LINE_NOPROP
;
19714 mode_line_string_face_prop
= Qnil
;
19715 mode_line_string_list
= Qnil
;
19716 string_start
= MODE_LINE_NOPROP_LEN (0);
19720 mode_line_target
= MODE_LINE_STRING
;
19721 mode_line_string_list
= Qnil
;
19722 mode_line_string_face
= face
;
19723 mode_line_string_face_prop
19724 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
19727 push_kboard (FRAME_KBOARD (it
.f
));
19728 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19733 len
= MODE_LINE_NOPROP_LEN (string_start
);
19734 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
19738 mode_line_string_list
= Fnreverse (mode_line_string_list
);
19739 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
19740 empty_unibyte_string
);
19743 unbind_to (count
, Qnil
);
19747 /* Write a null-terminated, right justified decimal representation of
19748 the positive integer D to BUF using a minimal field width WIDTH. */
19751 pint2str (register char *buf
, register int width
, register EMACS_INT d
)
19753 register char *p
= buf
;
19761 *p
++ = d
% 10 + '0';
19766 for (width
-= (int) (p
- buf
); width
> 0; --width
)
19777 /* Write a null-terminated, right justified decimal and "human
19778 readable" representation of the nonnegative integer D to BUF using
19779 a minimal field width WIDTH. D should be smaller than 999.5e24. */
19781 static const char power_letter
[] =
19795 pint2hrstr (char *buf
, int width
, EMACS_INT d
)
19797 /* We aim to represent the nonnegative integer D as
19798 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
19799 EMACS_INT quotient
= d
;
19801 /* -1 means: do not use TENTHS. */
19805 /* Length of QUOTIENT.TENTHS as a string. */
19811 if (1000 <= quotient
)
19813 /* Scale to the appropriate EXPONENT. */
19816 remainder
= quotient
% 1000;
19820 while (1000 <= quotient
);
19822 /* Round to nearest and decide whether to use TENTHS or not. */
19825 tenths
= remainder
/ 100;
19826 if (50 <= remainder
% 100)
19833 if (quotient
== 10)
19841 if (500 <= remainder
)
19843 if (quotient
< 999)
19854 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
19855 if (tenths
== -1 && quotient
<= 99)
19862 p
= psuffix
= buf
+ max (width
, length
);
19864 /* Print EXPONENT. */
19865 *psuffix
++ = power_letter
[exponent
];
19868 /* Print TENTHS. */
19871 *--p
= '0' + tenths
;
19875 /* Print QUOTIENT. */
19878 int digit
= quotient
% 10;
19879 *--p
= '0' + digit
;
19881 while ((quotient
/= 10) != 0);
19883 /* Print leading spaces. */
19888 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19889 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19890 type of CODING_SYSTEM. Return updated pointer into BUF. */
19892 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19895 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
19898 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
19899 const unsigned char *eol_str
;
19901 /* The EOL conversion we are using. */
19902 Lisp_Object eoltype
;
19904 val
= CODING_SYSTEM_SPEC (coding_system
);
19907 if (!VECTORP (val
)) /* Not yet decided. */
19912 eoltype
= eol_mnemonic_undecided
;
19913 /* Don't mention EOL conversion if it isn't decided. */
19918 Lisp_Object eolvalue
;
19920 attrs
= AREF (val
, 0);
19921 eolvalue
= AREF (val
, 2);
19924 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19928 /* The EOL conversion that is normal on this system. */
19930 if (NILP (eolvalue
)) /* Not yet decided. */
19931 eoltype
= eol_mnemonic_undecided
;
19932 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19933 eoltype
= eol_mnemonic_undecided
;
19934 else /* eolvalue is Qunix, Qdos, or Qmac. */
19935 eoltype
= (EQ (eolvalue
, Qunix
)
19936 ? eol_mnemonic_unix
19937 : (EQ (eolvalue
, Qdos
) == 1
19938 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19944 /* Mention the EOL conversion if it is not the usual one. */
19945 if (STRINGP (eoltype
))
19947 eol_str
= SDATA (eoltype
);
19948 eol_str_len
= SBYTES (eoltype
);
19950 else if (CHARACTERP (eoltype
))
19952 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19953 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19958 eol_str
= invalid_eol_type
;
19959 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19961 memcpy (buf
, eol_str
, eol_str_len
);
19962 buf
+= eol_str_len
;
19968 /* Return a string for the output of a mode line %-spec for window W,
19969 generated by character C. FIELD_WIDTH > 0 means pad the string
19970 returned with spaces to that value. Return a Lisp string in
19971 *STRING if the resulting string is taken from that Lisp string.
19973 Note we operate on the current buffer for most purposes,
19974 the exception being w->base_line_pos. */
19976 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19978 static const char *
19979 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
19980 Lisp_Object
*string
)
19983 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19984 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19985 struct buffer
*b
= current_buffer
;
19993 if (!NILP (BVAR (b
, read_only
)))
19995 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20000 /* This differs from %* only for a modified read-only buffer. */
20001 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20003 if (!NILP (BVAR (b
, read_only
)))
20008 /* This differs from %* in ignoring read-only-ness. */
20009 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20021 if (command_loop_level
> 5)
20023 p
= decode_mode_spec_buf
;
20024 for (i
= 0; i
< command_loop_level
; i
++)
20027 return decode_mode_spec_buf
;
20035 if (command_loop_level
> 5)
20037 p
= decode_mode_spec_buf
;
20038 for (i
= 0; i
< command_loop_level
; i
++)
20041 return decode_mode_spec_buf
;
20048 /* Let lots_of_dashes be a string of infinite length. */
20049 if (mode_line_target
== MODE_LINE_NOPROP
||
20050 mode_line_target
== MODE_LINE_STRING
)
20052 if (field_width
<= 0
20053 || field_width
> sizeof (lots_of_dashes
))
20055 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
20056 decode_mode_spec_buf
[i
] = '-';
20057 decode_mode_spec_buf
[i
] = '\0';
20058 return decode_mode_spec_buf
;
20061 return lots_of_dashes
;
20065 obj
= BVAR (b
, name
);
20069 /* %c and %l are ignored in `frame-title-format'.
20070 (In redisplay_internal, the frame title is drawn _before_ the
20071 windows are updated, so the stuff which depends on actual
20072 window contents (such as %l) may fail to render properly, or
20073 even crash emacs.) */
20074 if (mode_line_target
== MODE_LINE_TITLE
)
20078 EMACS_INT col
= current_column ();
20079 w
->column_number_displayed
= make_number (col
);
20080 pint2str (decode_mode_spec_buf
, field_width
, col
);
20081 return decode_mode_spec_buf
;
20085 #ifndef SYSTEM_MALLOC
20087 if (NILP (Vmemory_full
))
20090 return "!MEM FULL! ";
20097 /* %F displays the frame name. */
20098 if (!NILP (f
->title
))
20099 return SSDATA (f
->title
);
20100 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
20101 return SSDATA (f
->name
);
20105 obj
= BVAR (b
, filename
);
20110 EMACS_INT size
= ZV
- BEGV
;
20111 pint2str (decode_mode_spec_buf
, field_width
, size
);
20112 return decode_mode_spec_buf
;
20117 EMACS_INT size
= ZV
- BEGV
;
20118 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
20119 return decode_mode_spec_buf
;
20124 EMACS_INT startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
20125 EMACS_INT topline
, nlines
, height
;
20128 /* %c and %l are ignored in `frame-title-format'. */
20129 if (mode_line_target
== MODE_LINE_TITLE
)
20132 startpos
= XMARKER (w
->start
)->charpos
;
20133 startpos_byte
= marker_byte_position (w
->start
);
20134 height
= WINDOW_TOTAL_LINES (w
);
20136 /* If we decided that this buffer isn't suitable for line numbers,
20137 don't forget that too fast. */
20138 if (EQ (w
->base_line_pos
, w
->buffer
))
20140 /* But do forget it, if the window shows a different buffer now. */
20141 else if (BUFFERP (w
->base_line_pos
))
20142 w
->base_line_pos
= Qnil
;
20144 /* If the buffer is very big, don't waste time. */
20145 if (INTEGERP (Vline_number_display_limit
)
20146 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
20148 w
->base_line_pos
= Qnil
;
20149 w
->base_line_number
= Qnil
;
20153 if (INTEGERP (w
->base_line_number
)
20154 && INTEGERP (w
->base_line_pos
)
20155 && XFASTINT (w
->base_line_pos
) <= startpos
)
20157 line
= XFASTINT (w
->base_line_number
);
20158 linepos
= XFASTINT (w
->base_line_pos
);
20159 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
20164 linepos
= BUF_BEGV (b
);
20165 linepos_byte
= BUF_BEGV_BYTE (b
);
20168 /* Count lines from base line to window start position. */
20169 nlines
= display_count_lines (linepos_byte
,
20173 topline
= nlines
+ line
;
20175 /* Determine a new base line, if the old one is too close
20176 or too far away, or if we did not have one.
20177 "Too close" means it's plausible a scroll-down would
20178 go back past it. */
20179 if (startpos
== BUF_BEGV (b
))
20181 w
->base_line_number
= make_number (topline
);
20182 w
->base_line_pos
= make_number (BUF_BEGV (b
));
20184 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
20185 || linepos
== BUF_BEGV (b
))
20187 EMACS_INT limit
= BUF_BEGV (b
);
20188 EMACS_INT limit_byte
= BUF_BEGV_BYTE (b
);
20189 EMACS_INT position
;
20190 EMACS_INT distance
=
20191 (height
* 2 + 30) * line_number_display_limit_width
;
20193 if (startpos
- distance
> limit
)
20195 limit
= startpos
- distance
;
20196 limit_byte
= CHAR_TO_BYTE (limit
);
20199 nlines
= display_count_lines (startpos_byte
,
20201 - (height
* 2 + 30),
20203 /* If we couldn't find the lines we wanted within
20204 line_number_display_limit_width chars per line,
20205 give up on line numbers for this window. */
20206 if (position
== limit_byte
&& limit
== startpos
- distance
)
20208 w
->base_line_pos
= w
->buffer
;
20209 w
->base_line_number
= Qnil
;
20213 w
->base_line_number
= make_number (topline
- nlines
);
20214 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
20217 /* Now count lines from the start pos to point. */
20218 nlines
= display_count_lines (startpos_byte
,
20219 PT_BYTE
, PT
, &junk
);
20221 /* Record that we did display the line number. */
20222 line_number_displayed
= 1;
20224 /* Make the string to show. */
20225 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
20226 return decode_mode_spec_buf
;
20229 char* p
= decode_mode_spec_buf
;
20230 int pad
= field_width
- 2;
20236 return decode_mode_spec_buf
;
20242 obj
= BVAR (b
, mode_name
);
20246 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
20252 EMACS_INT pos
= marker_position (w
->start
);
20253 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
20255 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
20257 if (pos
<= BUF_BEGV (b
))
20262 else if (pos
<= BUF_BEGV (b
))
20266 if (total
> 1000000)
20267 /* Do it differently for a large value, to avoid overflow. */
20268 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
20270 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
20271 /* We can't normally display a 3-digit number,
20272 so get us a 2-digit number that is close. */
20275 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
20276 return decode_mode_spec_buf
;
20280 /* Display percentage of size above the bottom of the screen. */
20283 EMACS_INT toppos
= marker_position (w
->start
);
20284 EMACS_INT botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
20285 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
20287 if (botpos
>= BUF_ZV (b
))
20289 if (toppos
<= BUF_BEGV (b
))
20296 if (total
> 1000000)
20297 /* Do it differently for a large value, to avoid overflow. */
20298 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
20300 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
20301 /* We can't normally display a 3-digit number,
20302 so get us a 2-digit number that is close. */
20305 if (toppos
<= BUF_BEGV (b
))
20306 sprintf (decode_mode_spec_buf
, "Top%2"pI
"d%%", total
);
20308 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
20309 return decode_mode_spec_buf
;
20314 /* status of process */
20315 obj
= Fget_buffer_process (Fcurrent_buffer ());
20317 return "no process";
20319 obj
= Fsymbol_name (Fprocess_status (obj
));
20325 int count
= inhibit_garbage_collection ();
20326 Lisp_Object val
= call1 (intern ("file-remote-p"),
20327 BVAR (current_buffer
, directory
));
20328 unbind_to (count
, Qnil
);
20336 case 't': /* indicate TEXT or BINARY */
20340 /* coding-system (not including end-of-line format) */
20342 /* coding-system (including end-of-line type) */
20344 int eol_flag
= (c
== 'Z');
20345 char *p
= decode_mode_spec_buf
;
20347 if (! FRAME_WINDOW_P (f
))
20349 /* No need to mention EOL here--the terminal never needs
20350 to do EOL conversion. */
20351 p
= decode_mode_spec_coding (CODING_ID_NAME
20352 (FRAME_KEYBOARD_CODING (f
)->id
),
20354 p
= decode_mode_spec_coding (CODING_ID_NAME
20355 (FRAME_TERMINAL_CODING (f
)->id
),
20358 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
20361 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
20362 #ifdef subprocesses
20363 obj
= Fget_buffer_process (Fcurrent_buffer ());
20364 if (PROCESSP (obj
))
20366 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
20368 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
20371 #endif /* subprocesses */
20374 return decode_mode_spec_buf
;
20381 return SSDATA (obj
);
20388 /* Count up to COUNT lines starting from START_BYTE.
20389 But don't go beyond LIMIT_BYTE.
20390 Return the number of lines thus found (always nonnegative).
20392 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
20395 display_count_lines (EMACS_INT start_byte
,
20396 EMACS_INT limit_byte
, EMACS_INT count
,
20397 EMACS_INT
*byte_pos_ptr
)
20399 register unsigned char *cursor
;
20400 unsigned char *base
;
20402 register EMACS_INT ceiling
;
20403 register unsigned char *ceiling_addr
;
20404 EMACS_INT orig_count
= count
;
20406 /* If we are not in selective display mode,
20407 check only for newlines. */
20408 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
20409 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
20413 while (start_byte
< limit_byte
)
20415 ceiling
= BUFFER_CEILING_OF (start_byte
);
20416 ceiling
= min (limit_byte
- 1, ceiling
);
20417 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
20418 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
20421 if (selective_display
)
20422 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
20425 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
20428 if (cursor
!= ceiling_addr
)
20432 start_byte
+= cursor
- base
+ 1;
20433 *byte_pos_ptr
= start_byte
;
20437 if (++cursor
== ceiling_addr
)
20443 start_byte
+= cursor
- base
;
20448 while (start_byte
> limit_byte
)
20450 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
20451 ceiling
= max (limit_byte
, ceiling
);
20452 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
20453 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
20456 if (selective_display
)
20457 while (--cursor
!= ceiling_addr
20458 && *cursor
!= '\n' && *cursor
!= 015)
20461 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
20464 if (cursor
!= ceiling_addr
)
20468 start_byte
+= cursor
- base
+ 1;
20469 *byte_pos_ptr
= start_byte
;
20470 /* When scanning backwards, we should
20471 not count the newline posterior to which we stop. */
20472 return - orig_count
- 1;
20478 /* Here we add 1 to compensate for the last decrement
20479 of CURSOR, which took it past the valid range. */
20480 start_byte
+= cursor
- base
+ 1;
20484 *byte_pos_ptr
= limit_byte
;
20487 return - orig_count
+ count
;
20488 return orig_count
- count
;
20494 /***********************************************************************
20496 ***********************************************************************/
20498 /* Display a NUL-terminated string, starting with index START.
20500 If STRING is non-null, display that C string. Otherwise, the Lisp
20501 string LISP_STRING is displayed. There's a case that STRING is
20502 non-null and LISP_STRING is not nil. It means STRING is a string
20503 data of LISP_STRING. In that case, we display LISP_STRING while
20504 ignoring its text properties.
20506 If FACE_STRING is not nil, FACE_STRING_POS is a position in
20507 FACE_STRING. Display STRING or LISP_STRING with the face at
20508 FACE_STRING_POS in FACE_STRING:
20510 Display the string in the environment given by IT, but use the
20511 standard display table, temporarily.
20513 FIELD_WIDTH is the minimum number of output glyphs to produce.
20514 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20515 with spaces. If STRING has more characters, more than FIELD_WIDTH
20516 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
20518 PRECISION is the maximum number of characters to output from
20519 STRING. PRECISION < 0 means don't truncate the string.
20521 This is roughly equivalent to printf format specifiers:
20523 FIELD_WIDTH PRECISION PRINTF
20524 ----------------------------------------
20530 MULTIBYTE zero means do not display multibyte chars, > 0 means do
20531 display them, and < 0 means obey the current buffer's value of
20532 enable_multibyte_characters.
20534 Value is the number of columns displayed. */
20537 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
20538 EMACS_INT face_string_pos
, EMACS_INT start
, struct it
*it
,
20539 int field_width
, int precision
, int max_x
, int multibyte
)
20541 int hpos_at_start
= it
->hpos
;
20542 int saved_face_id
= it
->face_id
;
20543 struct glyph_row
*row
= it
->glyph_row
;
20544 EMACS_INT it_charpos
;
20546 /* Initialize the iterator IT for iteration over STRING beginning
20547 with index START. */
20548 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
20549 precision
, field_width
, multibyte
);
20550 if (string
&& STRINGP (lisp_string
))
20551 /* LISP_STRING is the one returned by decode_mode_spec. We should
20552 ignore its text properties. */
20553 it
->stop_charpos
= it
->end_charpos
;
20555 /* If displaying STRING, set up the face of the iterator from
20556 FACE_STRING, if that's given. */
20557 if (STRINGP (face_string
))
20563 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
20564 0, it
->region_beg_charpos
,
20565 it
->region_end_charpos
,
20566 &endptr
, it
->base_face_id
, 0);
20567 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20568 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
20571 /* Set max_x to the maximum allowed X position. Don't let it go
20572 beyond the right edge of the window. */
20574 max_x
= it
->last_visible_x
;
20576 max_x
= min (max_x
, it
->last_visible_x
);
20578 /* Skip over display elements that are not visible. because IT->w is
20580 if (it
->current_x
< it
->first_visible_x
)
20581 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
20582 MOVE_TO_POS
| MOVE_TO_X
);
20584 row
->ascent
= it
->max_ascent
;
20585 row
->height
= it
->max_ascent
+ it
->max_descent
;
20586 row
->phys_ascent
= it
->max_phys_ascent
;
20587 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20588 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20590 if (STRINGP (it
->string
))
20591 it_charpos
= IT_STRING_CHARPOS (*it
);
20593 it_charpos
= IT_CHARPOS (*it
);
20595 /* This condition is for the case that we are called with current_x
20596 past last_visible_x. */
20597 while (it
->current_x
< max_x
)
20599 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
20601 /* Get the next display element. */
20602 if (!get_next_display_element (it
))
20605 /* Produce glyphs. */
20606 x_before
= it
->current_x
;
20607 n_glyphs_before
= row
->used
[TEXT_AREA
];
20608 PRODUCE_GLYPHS (it
);
20610 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
20613 while (i
< nglyphs
)
20615 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20617 if (it
->line_wrap
!= TRUNCATE
20618 && x
+ glyph
->pixel_width
> max_x
)
20620 /* End of continued line or max_x reached. */
20621 if (CHAR_GLYPH_PADDING_P (*glyph
))
20623 /* A wide character is unbreakable. */
20624 if (row
->reversed_p
)
20625 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20626 - n_glyphs_before
);
20627 row
->used
[TEXT_AREA
] = n_glyphs_before
;
20628 it
->current_x
= x_before
;
20632 if (row
->reversed_p
)
20633 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20634 - (n_glyphs_before
+ i
));
20635 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20640 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
20642 /* Glyph is at least partially visible. */
20644 if (x
< it
->first_visible_x
)
20645 row
->x
= x
- it
->first_visible_x
;
20649 /* Glyph is off the left margin of the display area.
20650 Should not happen. */
20654 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20655 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20656 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20657 row
->phys_height
= max (row
->phys_height
,
20658 it
->max_phys_ascent
+ it
->max_phys_descent
);
20659 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20660 it
->max_extra_line_spacing
);
20661 x
+= glyph
->pixel_width
;
20665 /* Stop if max_x reached. */
20669 /* Stop at line ends. */
20670 if (ITERATOR_AT_END_OF_LINE_P (it
))
20672 it
->continuation_lines_width
= 0;
20676 set_iterator_to_next (it
, 1);
20677 if (STRINGP (it
->string
))
20678 it_charpos
= IT_STRING_CHARPOS (*it
);
20680 it_charpos
= IT_CHARPOS (*it
);
20682 /* Stop if truncating at the right edge. */
20683 if (it
->line_wrap
== TRUNCATE
20684 && it
->current_x
>= it
->last_visible_x
)
20686 /* Add truncation mark, but don't do it if the line is
20687 truncated at a padding space. */
20688 if (it_charpos
< it
->string_nchars
)
20690 if (!FRAME_WINDOW_P (it
->f
))
20694 if (it
->current_x
> it
->last_visible_x
)
20696 if (!row
->reversed_p
)
20698 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
20699 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20704 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
20705 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20707 unproduce_glyphs (it
, ii
+ 1);
20708 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
20710 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
20712 row
->used
[TEXT_AREA
] = ii
;
20713 produce_special_glyphs (it
, IT_TRUNCATION
);
20716 produce_special_glyphs (it
, IT_TRUNCATION
);
20718 row
->truncated_on_right_p
= 1;
20724 /* Maybe insert a truncation at the left. */
20725 if (it
->first_visible_x
20728 if (!FRAME_WINDOW_P (it
->f
))
20729 insert_left_trunc_glyphs (it
);
20730 row
->truncated_on_left_p
= 1;
20733 it
->face_id
= saved_face_id
;
20735 /* Value is number of columns displayed. */
20736 return it
->hpos
- hpos_at_start
;
20741 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
20742 appears as an element of LIST or as the car of an element of LIST.
20743 If PROPVAL is a list, compare each element against LIST in that
20744 way, and return 1/2 if any element of PROPVAL is found in LIST.
20745 Otherwise return 0. This function cannot quit.
20746 The return value is 2 if the text is invisible but with an ellipsis
20747 and 1 if it's invisible and without an ellipsis. */
20750 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
20752 register Lisp_Object tail
, proptail
;
20754 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20756 register Lisp_Object tem
;
20758 if (EQ (propval
, tem
))
20760 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
20761 return NILP (XCDR (tem
)) ? 1 : 2;
20764 if (CONSP (propval
))
20766 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
20768 Lisp_Object propelt
;
20769 propelt
= XCAR (proptail
);
20770 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20772 register Lisp_Object tem
;
20774 if (EQ (propelt
, tem
))
20776 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
20777 return NILP (XCDR (tem
)) ? 1 : 2;
20785 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
20786 doc
: /* Non-nil if the property makes the text invisible.
20787 POS-OR-PROP can be a marker or number, in which case it is taken to be
20788 a position in the current buffer and the value of the `invisible' property
20789 is checked; or it can be some other value, which is then presumed to be the
20790 value of the `invisible' property of the text of interest.
20791 The non-nil value returned can be t for truly invisible text or something
20792 else if the text is replaced by an ellipsis. */)
20793 (Lisp_Object pos_or_prop
)
20796 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
20797 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
20799 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
20800 return (invis
== 0 ? Qnil
20802 : make_number (invis
));
20805 /* Calculate a width or height in pixels from a specification using
20806 the following elements:
20809 NUM - a (fractional) multiple of the default font width/height
20810 (NUM) - specifies exactly NUM pixels
20811 UNIT - a fixed number of pixels, see below.
20812 ELEMENT - size of a display element in pixels, see below.
20813 (NUM . SPEC) - equals NUM * SPEC
20814 (+ SPEC SPEC ...) - add pixel values
20815 (- SPEC SPEC ...) - subtract pixel values
20816 (- SPEC) - negate pixel value
20819 INT or FLOAT - a number constant
20820 SYMBOL - use symbol's (buffer local) variable binding.
20823 in - pixels per inch *)
20824 mm - pixels per 1/1000 meter *)
20825 cm - pixels per 1/100 meter *)
20826 width - width of current font in pixels.
20827 height - height of current font in pixels.
20829 *) using the ratio(s) defined in display-pixels-per-inch.
20833 left-fringe - left fringe width in pixels
20834 right-fringe - right fringe width in pixels
20836 left-margin - left margin width in pixels
20837 right-margin - right margin width in pixels
20839 scroll-bar - scroll-bar area width in pixels
20843 Pixels corresponding to 5 inches:
20846 Total width of non-text areas on left side of window (if scroll-bar is on left):
20847 '(space :width (+ left-fringe left-margin scroll-bar))
20849 Align to first text column (in header line):
20850 '(space :align-to 0)
20852 Align to middle of text area minus half the width of variable `my-image'
20853 containing a loaded image:
20854 '(space :align-to (0.5 . (- text my-image)))
20856 Width of left margin minus width of 1 character in the default font:
20857 '(space :width (- left-margin 1))
20859 Width of left margin minus width of 2 characters in the current font:
20860 '(space :width (- left-margin (2 . width)))
20862 Center 1 character over left-margin (in header line):
20863 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
20865 Different ways to express width of left fringe plus left margin minus one pixel:
20866 '(space :width (- (+ left-fringe left-margin) (1)))
20867 '(space :width (+ left-fringe left-margin (- (1))))
20868 '(space :width (+ left-fringe left-margin (-1)))
20872 #define NUMVAL(X) \
20873 ((INTEGERP (X) || FLOATP (X)) \
20878 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
20879 struct font
*font
, int width_p
, int *align_to
)
20883 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20884 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20887 return OK_PIXELS (0);
20889 xassert (FRAME_LIVE_P (it
->f
));
20891 if (SYMBOLP (prop
))
20893 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20895 char *unit
= SSDATA (SYMBOL_NAME (prop
));
20897 if (unit
[0] == 'i' && unit
[1] == 'n')
20899 else if (unit
[0] == 'm' && unit
[1] == 'm')
20901 else if (unit
[0] == 'c' && unit
[1] == 'm')
20908 #ifdef HAVE_WINDOW_SYSTEM
20909 if (FRAME_WINDOW_P (it
->f
)
20911 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20912 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20914 return OK_PIXELS (ppi
/ pixels
);
20917 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20918 || (CONSP (Vdisplay_pixels_per_inch
)
20920 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20921 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20923 return OK_PIXELS (ppi
/ pixels
);
20929 #ifdef HAVE_WINDOW_SYSTEM
20930 if (EQ (prop
, Qheight
))
20931 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20932 if (EQ (prop
, Qwidth
))
20933 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20935 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20936 return OK_PIXELS (1);
20939 if (EQ (prop
, Qtext
))
20940 return OK_PIXELS (width_p
20941 ? window_box_width (it
->w
, TEXT_AREA
)
20942 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20944 if (align_to
&& *align_to
< 0)
20947 if (EQ (prop
, Qleft
))
20948 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20949 if (EQ (prop
, Qright
))
20950 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20951 if (EQ (prop
, Qcenter
))
20952 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20953 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20954 if (EQ (prop
, Qleft_fringe
))
20955 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20956 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20957 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20958 if (EQ (prop
, Qright_fringe
))
20959 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20960 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20961 : window_box_right_offset (it
->w
, TEXT_AREA
));
20962 if (EQ (prop
, Qleft_margin
))
20963 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20964 if (EQ (prop
, Qright_margin
))
20965 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20966 if (EQ (prop
, Qscroll_bar
))
20967 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20969 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20970 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20971 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20976 if (EQ (prop
, Qleft_fringe
))
20977 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20978 if (EQ (prop
, Qright_fringe
))
20979 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20980 if (EQ (prop
, Qleft_margin
))
20981 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20982 if (EQ (prop
, Qright_margin
))
20983 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20984 if (EQ (prop
, Qscroll_bar
))
20985 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20988 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20991 if (INTEGERP (prop
) || FLOATP (prop
))
20993 int base_unit
= (width_p
20994 ? FRAME_COLUMN_WIDTH (it
->f
)
20995 : FRAME_LINE_HEIGHT (it
->f
));
20996 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
21001 Lisp_Object car
= XCAR (prop
);
21002 Lisp_Object cdr
= XCDR (prop
);
21006 #ifdef HAVE_WINDOW_SYSTEM
21007 if (FRAME_WINDOW_P (it
->f
)
21008 && valid_image_p (prop
))
21010 int id
= lookup_image (it
->f
, prop
);
21011 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
21013 return OK_PIXELS (width_p
? img
->width
: img
->height
);
21016 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
21022 while (CONSP (cdr
))
21024 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
21025 font
, width_p
, align_to
))
21028 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
21033 if (EQ (car
, Qminus
))
21035 return OK_PIXELS (pixels
);
21038 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
21041 if (INTEGERP (car
) || FLOATP (car
))
21044 pixels
= XFLOATINT (car
);
21046 return OK_PIXELS (pixels
);
21047 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
21048 font
, width_p
, align_to
))
21049 return OK_PIXELS (pixels
* fact
);
21060 /***********************************************************************
21062 ***********************************************************************/
21064 #ifdef HAVE_WINDOW_SYSTEM
21069 dump_glyph_string (s
)
21070 struct glyph_string
*s
;
21072 fprintf (stderr
, "glyph string\n");
21073 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
21074 s
->x
, s
->y
, s
->width
, s
->height
);
21075 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
21076 fprintf (stderr
, " hl = %d\n", s
->hl
);
21077 fprintf (stderr
, " left overhang = %d, right = %d\n",
21078 s
->left_overhang
, s
->right_overhang
);
21079 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
21080 fprintf (stderr
, " extends to end of line = %d\n",
21081 s
->extends_to_end_of_line_p
);
21082 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
21083 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
21086 #endif /* GLYPH_DEBUG */
21088 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
21089 of XChar2b structures for S; it can't be allocated in
21090 init_glyph_string because it must be allocated via `alloca'. W
21091 is the window on which S is drawn. ROW and AREA are the glyph row
21092 and area within the row from which S is constructed. START is the
21093 index of the first glyph structure covered by S. HL is a
21094 face-override for drawing S. */
21097 #define OPTIONAL_HDC(hdc) HDC hdc,
21098 #define DECLARE_HDC(hdc) HDC hdc;
21099 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
21100 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
21103 #ifndef OPTIONAL_HDC
21104 #define OPTIONAL_HDC(hdc)
21105 #define DECLARE_HDC(hdc)
21106 #define ALLOCATE_HDC(hdc, f)
21107 #define RELEASE_HDC(hdc, f)
21111 init_glyph_string (struct glyph_string
*s
,
21113 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
21114 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
21116 memset (s
, 0, sizeof *s
);
21118 s
->f
= XFRAME (w
->frame
);
21122 s
->display
= FRAME_X_DISPLAY (s
->f
);
21123 s
->window
= FRAME_X_WINDOW (s
->f
);
21124 s
->char2b
= char2b
;
21128 s
->first_glyph
= row
->glyphs
[area
] + start
;
21129 s
->height
= row
->height
;
21130 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
21131 s
->ybase
= s
->y
+ row
->ascent
;
21135 /* Append the list of glyph strings with head H and tail T to the list
21136 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
21139 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
21140 struct glyph_string
*h
, struct glyph_string
*t
)
21154 /* Prepend the list of glyph strings with head H and tail T to the
21155 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
21159 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
21160 struct glyph_string
*h
, struct glyph_string
*t
)
21174 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
21175 Set *HEAD and *TAIL to the resulting list. */
21178 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
21179 struct glyph_string
*s
)
21181 s
->next
= s
->prev
= NULL
;
21182 append_glyph_string_lists (head
, tail
, s
, s
);
21186 /* Get face and two-byte form of character C in face FACE_ID on frame F.
21187 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
21188 make sure that X resources for the face returned are allocated.
21189 Value is a pointer to a realized face that is ready for display if
21190 DISPLAY_P is non-zero. */
21192 static INLINE
struct face
*
21193 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
21194 XChar2b
*char2b
, int display_p
)
21196 struct face
*face
= FACE_FROM_ID (f
, face_id
);
21200 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
21202 if (code
!= FONT_INVALID_CODE
)
21203 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21205 STORE_XCHAR2B (char2b
, 0, 0);
21208 /* Make sure X resources of the face are allocated. */
21209 #ifdef HAVE_X_WINDOWS
21213 xassert (face
!= NULL
);
21214 PREPARE_FACE_FOR_DISPLAY (f
, face
);
21221 /* Get face and two-byte form of character glyph GLYPH on frame F.
21222 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
21223 a pointer to a realized face that is ready for display. */
21225 static INLINE
struct face
*
21226 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
21227 XChar2b
*char2b
, int *two_byte_p
)
21231 xassert (glyph
->type
== CHAR_GLYPH
);
21232 face
= FACE_FROM_ID (f
, glyph
->face_id
);
21241 if (CHAR_BYTE8_P (glyph
->u
.ch
))
21242 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
21244 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
21246 if (code
!= FONT_INVALID_CODE
)
21247 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21249 STORE_XCHAR2B (char2b
, 0, 0);
21252 /* Make sure X resources of the face are allocated. */
21253 xassert (face
!= NULL
);
21254 PREPARE_FACE_FOR_DISPLAY (f
, face
);
21259 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
21260 Retunr 1 if FONT has a glyph for C, otherwise return 0. */
21263 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
21267 if (CHAR_BYTE8_P (c
))
21268 code
= CHAR_TO_BYTE8 (c
);
21270 code
= font
->driver
->encode_char (font
, c
);
21272 if (code
== FONT_INVALID_CODE
)
21274 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21279 /* Fill glyph string S with composition components specified by S->cmp.
21281 BASE_FACE is the base face of the composition.
21282 S->cmp_from is the index of the first component for S.
21284 OVERLAPS non-zero means S should draw the foreground only, and use
21285 its physical height for clipping. See also draw_glyphs.
21287 Value is the index of a component not in S. */
21290 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
21294 /* For all glyphs of this composition, starting at the offset
21295 S->cmp_from, until we reach the end of the definition or encounter a
21296 glyph that requires the different face, add it to S. */
21301 s
->for_overlaps
= overlaps
;
21304 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
21306 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
21310 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
21313 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
21320 s
->font
= s
->face
->font
;
21322 else if (s
->face
!= face
)
21330 /* All glyph strings for the same composition has the same width,
21331 i.e. the width set for the first component of the composition. */
21332 s
->width
= s
->first_glyph
->pixel_width
;
21334 /* If the specified font could not be loaded, use the frame's
21335 default font, but record the fact that we couldn't load it in
21336 the glyph string so that we can draw rectangles for the
21337 characters of the glyph string. */
21338 if (s
->font
== NULL
)
21340 s
->font_not_found_p
= 1;
21341 s
->font
= FRAME_FONT (s
->f
);
21344 /* Adjust base line for subscript/superscript text. */
21345 s
->ybase
+= s
->first_glyph
->voffset
;
21347 /* This glyph string must always be drawn with 16-bit functions. */
21354 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
21355 int start
, int end
, int overlaps
)
21357 struct glyph
*glyph
, *last
;
21358 Lisp_Object lgstring
;
21361 s
->for_overlaps
= overlaps
;
21362 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21363 last
= s
->row
->glyphs
[s
->area
] + end
;
21364 s
->cmp_id
= glyph
->u
.cmp
.id
;
21365 s
->cmp_from
= glyph
->slice
.cmp
.from
;
21366 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
21367 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21368 lgstring
= composition_gstring_from_id (s
->cmp_id
);
21369 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
21371 while (glyph
< last
21372 && glyph
->u
.cmp
.automatic
21373 && glyph
->u
.cmp
.id
== s
->cmp_id
21374 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
21375 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
21377 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
21379 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
21380 unsigned code
= LGLYPH_CODE (lglyph
);
21382 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
21384 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
21385 return glyph
- s
->row
->glyphs
[s
->area
];
21389 /* Fill glyph string S from a sequence glyphs for glyphless characters.
21390 See the comment of fill_glyph_string for arguments.
21391 Value is the index of the first glyph not in S. */
21395 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
21396 int start
, int end
, int overlaps
)
21398 struct glyph
*glyph
, *last
;
21401 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
21402 s
->for_overlaps
= overlaps
;
21403 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21404 last
= s
->row
->glyphs
[s
->area
] + end
;
21405 voffset
= glyph
->voffset
;
21406 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21407 s
->font
= s
->face
->font
;
21409 s
->width
= glyph
->pixel_width
;
21411 while (glyph
< last
21412 && glyph
->type
== GLYPHLESS_GLYPH
21413 && glyph
->voffset
== voffset
21414 && glyph
->face_id
== face_id
)
21417 s
->width
+= glyph
->pixel_width
;
21420 s
->ybase
+= voffset
;
21421 return glyph
- s
->row
->glyphs
[s
->area
];
21425 /* Fill glyph string S from a sequence of character glyphs.
21427 FACE_ID is the face id of the string. START is the index of the
21428 first glyph to consider, END is the index of the last + 1.
21429 OVERLAPS non-zero means S should draw the foreground only, and use
21430 its physical height for clipping. See also draw_glyphs.
21432 Value is the index of the first glyph not in S. */
21435 fill_glyph_string (struct glyph_string
*s
, int face_id
,
21436 int start
, int end
, int overlaps
)
21438 struct glyph
*glyph
, *last
;
21440 int glyph_not_available_p
;
21442 xassert (s
->f
== XFRAME (s
->w
->frame
));
21443 xassert (s
->nchars
== 0);
21444 xassert (start
>= 0 && end
> start
);
21446 s
->for_overlaps
= overlaps
;
21447 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21448 last
= s
->row
->glyphs
[s
->area
] + end
;
21449 voffset
= glyph
->voffset
;
21450 s
->padding_p
= glyph
->padding_p
;
21451 glyph_not_available_p
= glyph
->glyph_not_available_p
;
21453 while (glyph
< last
21454 && glyph
->type
== CHAR_GLYPH
21455 && glyph
->voffset
== voffset
21456 /* Same face id implies same font, nowadays. */
21457 && glyph
->face_id
== face_id
21458 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
21462 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
21463 s
->char2b
+ s
->nchars
,
21465 s
->two_byte_p
= two_byte_p
;
21467 xassert (s
->nchars
<= end
- start
);
21468 s
->width
+= glyph
->pixel_width
;
21469 if (glyph
++->padding_p
!= s
->padding_p
)
21473 s
->font
= s
->face
->font
;
21475 /* If the specified font could not be loaded, use the frame's font,
21476 but record the fact that we couldn't load it in
21477 S->font_not_found_p so that we can draw rectangles for the
21478 characters of the glyph string. */
21479 if (s
->font
== NULL
|| glyph_not_available_p
)
21481 s
->font_not_found_p
= 1;
21482 s
->font
= FRAME_FONT (s
->f
);
21485 /* Adjust base line for subscript/superscript text. */
21486 s
->ybase
+= voffset
;
21488 xassert (s
->face
&& s
->face
->gc
);
21489 return glyph
- s
->row
->glyphs
[s
->area
];
21493 /* Fill glyph string S from image glyph S->first_glyph. */
21496 fill_image_glyph_string (struct glyph_string
*s
)
21498 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
21499 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
21501 s
->slice
= s
->first_glyph
->slice
.img
;
21502 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
21503 s
->font
= s
->face
->font
;
21504 s
->width
= s
->first_glyph
->pixel_width
;
21506 /* Adjust base line for subscript/superscript text. */
21507 s
->ybase
+= s
->first_glyph
->voffset
;
21511 /* Fill glyph string S from a sequence of stretch glyphs.
21513 START is the index of the first glyph to consider,
21514 END is the index of the last + 1.
21516 Value is the index of the first glyph not in S. */
21519 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
21521 struct glyph
*glyph
, *last
;
21522 int voffset
, face_id
;
21524 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
21526 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21527 last
= s
->row
->glyphs
[s
->area
] + end
;
21528 face_id
= glyph
->face_id
;
21529 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21530 s
->font
= s
->face
->font
;
21531 s
->width
= glyph
->pixel_width
;
21533 voffset
= glyph
->voffset
;
21537 && glyph
->type
== STRETCH_GLYPH
21538 && glyph
->voffset
== voffset
21539 && glyph
->face_id
== face_id
);
21541 s
->width
+= glyph
->pixel_width
;
21543 /* Adjust base line for subscript/superscript text. */
21544 s
->ybase
+= voffset
;
21546 /* The case that face->gc == 0 is handled when drawing the glyph
21547 string by calling PREPARE_FACE_FOR_DISPLAY. */
21549 return glyph
- s
->row
->glyphs
[s
->area
];
21552 static struct font_metrics
*
21553 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
21555 static struct font_metrics metrics
;
21556 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
21558 if (! font
|| code
== FONT_INVALID_CODE
)
21560 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
21565 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
21566 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
21567 assumed to be zero. */
21570 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
21572 *left
= *right
= 0;
21574 if (glyph
->type
== CHAR_GLYPH
)
21578 struct font_metrics
*pcm
;
21580 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
21581 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
21583 if (pcm
->rbearing
> pcm
->width
)
21584 *right
= pcm
->rbearing
- pcm
->width
;
21585 if (pcm
->lbearing
< 0)
21586 *left
= -pcm
->lbearing
;
21589 else if (glyph
->type
== COMPOSITE_GLYPH
)
21591 if (! glyph
->u
.cmp
.automatic
)
21593 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
21595 if (cmp
->rbearing
> cmp
->pixel_width
)
21596 *right
= cmp
->rbearing
- cmp
->pixel_width
;
21597 if (cmp
->lbearing
< 0)
21598 *left
= - cmp
->lbearing
;
21602 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
21603 struct font_metrics metrics
;
21605 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
21606 glyph
->slice
.cmp
.to
+ 1, &metrics
);
21607 if (metrics
.rbearing
> metrics
.width
)
21608 *right
= metrics
.rbearing
- metrics
.width
;
21609 if (metrics
.lbearing
< 0)
21610 *left
= - metrics
.lbearing
;
21616 /* Return the index of the first glyph preceding glyph string S that
21617 is overwritten by S because of S's left overhang. Value is -1
21618 if no glyphs are overwritten. */
21621 left_overwritten (struct glyph_string
*s
)
21625 if (s
->left_overhang
)
21628 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21629 int first
= s
->first_glyph
- glyphs
;
21631 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
21632 x
-= glyphs
[i
].pixel_width
;
21643 /* Return the index of the first glyph preceding glyph string S that
21644 is overwriting S because of its right overhang. Value is -1 if no
21645 glyph in front of S overwrites S. */
21648 left_overwriting (struct glyph_string
*s
)
21651 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21652 int first
= s
->first_glyph
- glyphs
;
21656 for (i
= first
- 1; i
>= 0; --i
)
21659 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21662 x
-= glyphs
[i
].pixel_width
;
21669 /* Return the index of the last glyph following glyph string S that is
21670 overwritten by S because of S's right overhang. Value is -1 if
21671 no such glyph is found. */
21674 right_overwritten (struct glyph_string
*s
)
21678 if (s
->right_overhang
)
21681 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21682 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21683 int end
= s
->row
->used
[s
->area
];
21685 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
21686 x
+= glyphs
[i
].pixel_width
;
21695 /* Return the index of the last glyph following glyph string S that
21696 overwrites S because of its left overhang. Value is negative
21697 if no such glyph is found. */
21700 right_overwriting (struct glyph_string
*s
)
21703 int end
= s
->row
->used
[s
->area
];
21704 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21705 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21709 for (i
= first
; i
< end
; ++i
)
21712 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21715 x
+= glyphs
[i
].pixel_width
;
21722 /* Set background width of glyph string S. START is the index of the
21723 first glyph following S. LAST_X is the right-most x-position + 1
21724 in the drawing area. */
21727 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
21729 /* If the face of this glyph string has to be drawn to the end of
21730 the drawing area, set S->extends_to_end_of_line_p. */
21732 if (start
== s
->row
->used
[s
->area
]
21733 && s
->area
== TEXT_AREA
21734 && ((s
->row
->fill_line_p
21735 && (s
->hl
== DRAW_NORMAL_TEXT
21736 || s
->hl
== DRAW_IMAGE_RAISED
21737 || s
->hl
== DRAW_IMAGE_SUNKEN
))
21738 || s
->hl
== DRAW_MOUSE_FACE
))
21739 s
->extends_to_end_of_line_p
= 1;
21741 /* If S extends its face to the end of the line, set its
21742 background_width to the distance to the right edge of the drawing
21744 if (s
->extends_to_end_of_line_p
)
21745 s
->background_width
= last_x
- s
->x
+ 1;
21747 s
->background_width
= s
->width
;
21751 /* Compute overhangs and x-positions for glyph string S and its
21752 predecessors, or successors. X is the starting x-position for S.
21753 BACKWARD_P non-zero means process predecessors. */
21756 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
21762 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21763 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21773 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21774 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21784 /* The following macros are only called from draw_glyphs below.
21785 They reference the following parameters of that function directly:
21786 `w', `row', `area', and `overlap_p'
21787 as well as the following local variables:
21788 `s', `f', and `hdc' (in W32) */
21791 /* On W32, silently add local `hdc' variable to argument list of
21792 init_glyph_string. */
21793 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21794 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
21796 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21797 init_glyph_string (s, char2b, w, row, area, start, hl)
21800 /* Add a glyph string for a stretch glyph to the list of strings
21801 between HEAD and TAIL. START is the index of the stretch glyph in
21802 row area AREA of glyph row ROW. END is the index of the last glyph
21803 in that glyph row area. X is the current output position assigned
21804 to the new glyph string constructed. HL overrides that face of the
21805 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21806 is the right-most x-position of the drawing area. */
21808 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
21809 and below -- keep them on one line. */
21810 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21813 s = (struct glyph_string *) alloca (sizeof *s); \
21814 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21815 START = fill_stretch_glyph_string (s, START, END); \
21816 append_glyph_string (&HEAD, &TAIL, s); \
21822 /* Add a glyph string for an image glyph to the list of strings
21823 between HEAD and TAIL. START is the index of the image glyph in
21824 row area AREA of glyph row ROW. END is the index of the last glyph
21825 in that glyph row area. X is the current output position assigned
21826 to the new glyph string constructed. HL overrides that face of the
21827 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21828 is the right-most x-position of the drawing area. */
21830 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21833 s = (struct glyph_string *) alloca (sizeof *s); \
21834 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21835 fill_image_glyph_string (s); \
21836 append_glyph_string (&HEAD, &TAIL, s); \
21843 /* Add a glyph string for a sequence of character glyphs to the list
21844 of strings between HEAD and TAIL. START is the index of the first
21845 glyph in row area AREA of glyph row ROW that is part of the new
21846 glyph string. END is the index of the last glyph in that glyph row
21847 area. X is the current output position assigned to the new glyph
21848 string constructed. HL overrides that face of the glyph; e.g. it
21849 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
21850 right-most x-position of the drawing area. */
21852 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21858 face_id = (row)->glyphs[area][START].face_id; \
21860 s = (struct glyph_string *) alloca (sizeof *s); \
21861 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
21862 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21863 append_glyph_string (&HEAD, &TAIL, s); \
21865 START = fill_glyph_string (s, face_id, START, END, overlaps); \
21870 /* Add a glyph string for a composite sequence to the list of strings
21871 between HEAD and TAIL. START is the index of the first glyph in
21872 row area AREA of glyph row ROW that is part of the new glyph
21873 string. END is the index of the last glyph in that glyph row area.
21874 X is the current output position assigned to the new glyph string
21875 constructed. HL overrides that face of the glyph; e.g. it is
21876 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
21877 x-position of the drawing area. */
21879 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21881 int face_id = (row)->glyphs[area][START].face_id; \
21882 struct face *base_face = FACE_FROM_ID (f, face_id); \
21883 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
21884 struct composition *cmp = composition_table[cmp_id]; \
21886 struct glyph_string *first_s IF_LINT (= NULL); \
21889 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21891 /* Make glyph_strings for each glyph sequence that is drawable by \
21892 the same face, and append them to HEAD/TAIL. */ \
21893 for (n = 0; n < cmp->glyph_len;) \
21895 s = (struct glyph_string *) alloca (sizeof *s); \
21896 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21897 append_glyph_string (&(HEAD), &(TAIL), s); \
21903 n = fill_composite_glyph_string (s, base_face, overlaps); \
21911 /* Add a glyph string for a glyph-string sequence to the list of strings
21912 between HEAD and TAIL. */
21914 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21918 Lisp_Object gstring; \
21920 face_id = (row)->glyphs[area][START].face_id; \
21921 gstring = (composition_gstring_from_id \
21922 ((row)->glyphs[area][START].u.cmp.id)); \
21923 s = (struct glyph_string *) alloca (sizeof *s); \
21924 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21925 * LGSTRING_GLYPH_LEN (gstring)); \
21926 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21927 append_glyph_string (&(HEAD), &(TAIL), s); \
21929 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21933 /* Add a glyph string for a sequence of glyphless character's glyphs
21934 to the list of strings between HEAD and TAIL. The meanings of
21935 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
21937 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21942 face_id = (row)->glyphs[area][START].face_id; \
21944 s = (struct glyph_string *) alloca (sizeof *s); \
21945 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21946 append_glyph_string (&HEAD, &TAIL, s); \
21948 START = fill_glyphless_glyph_string (s, face_id, START, END, \
21954 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21955 of AREA of glyph row ROW on window W between indices START and END.
21956 HL overrides the face for drawing glyph strings, e.g. it is
21957 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21958 x-positions of the drawing area.
21960 This is an ugly monster macro construct because we must use alloca
21961 to allocate glyph strings (because draw_glyphs can be called
21962 asynchronously). */
21964 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21967 HEAD = TAIL = NULL; \
21968 while (START < END) \
21970 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21971 switch (first_glyph->type) \
21974 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21978 case COMPOSITE_GLYPH: \
21979 if (first_glyph->u.cmp.automatic) \
21980 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21983 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21987 case STRETCH_GLYPH: \
21988 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21992 case IMAGE_GLYPH: \
21993 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21997 case GLYPHLESS_GLYPH: \
21998 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
22008 set_glyph_string_background_width (s, START, LAST_X); \
22015 /* Draw glyphs between START and END in AREA of ROW on window W,
22016 starting at x-position X. X is relative to AREA in W. HL is a
22017 face-override with the following meaning:
22019 DRAW_NORMAL_TEXT draw normally
22020 DRAW_CURSOR draw in cursor face
22021 DRAW_MOUSE_FACE draw in mouse face.
22022 DRAW_INVERSE_VIDEO draw in mode line face
22023 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
22024 DRAW_IMAGE_RAISED draw an image with a raised relief around it
22026 If OVERLAPS is non-zero, draw only the foreground of characters and
22027 clip to the physical height of ROW. Non-zero value also defines
22028 the overlapping part to be drawn:
22030 OVERLAPS_PRED overlap with preceding rows
22031 OVERLAPS_SUCC overlap with succeeding rows
22032 OVERLAPS_BOTH overlap with both preceding/succeeding rows
22033 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
22035 Value is the x-position reached, relative to AREA of W. */
22038 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
22039 enum glyph_row_area area
, EMACS_INT start
, EMACS_INT end
,
22040 enum draw_glyphs_face hl
, int overlaps
)
22042 struct glyph_string
*head
, *tail
;
22043 struct glyph_string
*s
;
22044 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
22045 int i
, j
, x_reached
, last_x
, area_left
= 0;
22046 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22049 ALLOCATE_HDC (hdc
, f
);
22051 /* Let's rather be paranoid than getting a SEGV. */
22052 end
= min (end
, row
->used
[area
]);
22053 start
= max (0, start
);
22054 start
= min (end
, start
);
22056 /* Translate X to frame coordinates. Set last_x to the right
22057 end of the drawing area. */
22058 if (row
->full_width_p
)
22060 /* X is relative to the left edge of W, without scroll bars
22062 area_left
= WINDOW_LEFT_EDGE_X (w
);
22063 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
22067 area_left
= window_box_left (w
, area
);
22068 last_x
= area_left
+ window_box_width (w
, area
);
22072 /* Build a doubly-linked list of glyph_string structures between
22073 head and tail from what we have to draw. Note that the macro
22074 BUILD_GLYPH_STRINGS will modify its start parameter. That's
22075 the reason we use a separate variable `i'. */
22077 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
22079 x_reached
= tail
->x
+ tail
->background_width
;
22083 /* If there are any glyphs with lbearing < 0 or rbearing > width in
22084 the row, redraw some glyphs in front or following the glyph
22085 strings built above. */
22086 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
22088 struct glyph_string
*h
, *t
;
22089 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
22090 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
22091 int check_mouse_face
= 0;
22094 /* If mouse highlighting is on, we may need to draw adjacent
22095 glyphs using mouse-face highlighting. */
22096 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
22098 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
22100 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
22101 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
22103 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
22105 check_mouse_face
= 1;
22106 mouse_beg_col
= (row
== mouse_beg_row
)
22107 ? hlinfo
->mouse_face_beg_col
: 0;
22108 mouse_end_col
= (row
== mouse_end_row
)
22109 ? hlinfo
->mouse_face_end_col
22110 : row
->used
[TEXT_AREA
];
22114 /* Compute overhangs for all glyph strings. */
22115 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
22116 for (s
= head
; s
; s
= s
->next
)
22117 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
22119 /* Prepend glyph strings for glyphs in front of the first glyph
22120 string that are overwritten because of the first glyph
22121 string's left overhang. The background of all strings
22122 prepended must be drawn because the first glyph string
22124 i
= left_overwritten (head
);
22127 enum draw_glyphs_face overlap_hl
;
22129 /* If this row contains mouse highlighting, attempt to draw
22130 the overlapped glyphs with the correct highlight. This
22131 code fails if the overlap encompasses more than one glyph
22132 and mouse-highlight spans only some of these glyphs.
22133 However, making it work perfectly involves a lot more
22134 code, and I don't know if the pathological case occurs in
22135 practice, so we'll stick to this for now. --- cyd */
22136 if (check_mouse_face
22137 && mouse_beg_col
< start
&& mouse_end_col
> i
)
22138 overlap_hl
= DRAW_MOUSE_FACE
;
22140 overlap_hl
= DRAW_NORMAL_TEXT
;
22143 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
22144 overlap_hl
, dummy_x
, last_x
);
22146 compute_overhangs_and_x (t
, head
->x
, 1);
22147 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
22151 /* Prepend glyph strings for glyphs in front of the first glyph
22152 string that overwrite that glyph string because of their
22153 right overhang. For these strings, only the foreground must
22154 be drawn, because it draws over the glyph string at `head'.
22155 The background must not be drawn because this would overwrite
22156 right overhangs of preceding glyphs for which no glyph
22158 i
= left_overwriting (head
);
22161 enum draw_glyphs_face overlap_hl
;
22163 if (check_mouse_face
22164 && mouse_beg_col
< start
&& mouse_end_col
> i
)
22165 overlap_hl
= DRAW_MOUSE_FACE
;
22167 overlap_hl
= DRAW_NORMAL_TEXT
;
22170 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
22171 overlap_hl
, dummy_x
, last_x
);
22172 for (s
= h
; s
; s
= s
->next
)
22173 s
->background_filled_p
= 1;
22174 compute_overhangs_and_x (t
, head
->x
, 1);
22175 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
22178 /* Append glyphs strings for glyphs following the last glyph
22179 string tail that are overwritten by tail. The background of
22180 these strings has to be drawn because tail's foreground draws
22182 i
= right_overwritten (tail
);
22185 enum draw_glyphs_face overlap_hl
;
22187 if (check_mouse_face
22188 && mouse_beg_col
< i
&& mouse_end_col
> end
)
22189 overlap_hl
= DRAW_MOUSE_FACE
;
22191 overlap_hl
= DRAW_NORMAL_TEXT
;
22193 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
22194 overlap_hl
, x
, last_x
);
22195 /* Because BUILD_GLYPH_STRINGS updates the first argument,
22196 we don't have `end = i;' here. */
22197 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
22198 append_glyph_string_lists (&head
, &tail
, h
, t
);
22202 /* Append glyph strings for glyphs following the last glyph
22203 string tail that overwrite tail. The foreground of such
22204 glyphs has to be drawn because it writes into the background
22205 of tail. The background must not be drawn because it could
22206 paint over the foreground of following glyphs. */
22207 i
= right_overwriting (tail
);
22210 enum draw_glyphs_face overlap_hl
;
22211 if (check_mouse_face
22212 && mouse_beg_col
< i
&& mouse_end_col
> end
)
22213 overlap_hl
= DRAW_MOUSE_FACE
;
22215 overlap_hl
= DRAW_NORMAL_TEXT
;
22218 i
++; /* We must include the Ith glyph. */
22219 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
22220 overlap_hl
, x
, last_x
);
22221 for (s
= h
; s
; s
= s
->next
)
22222 s
->background_filled_p
= 1;
22223 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
22224 append_glyph_string_lists (&head
, &tail
, h
, t
);
22226 if (clip_head
|| clip_tail
)
22227 for (s
= head
; s
; s
= s
->next
)
22229 s
->clip_head
= clip_head
;
22230 s
->clip_tail
= clip_tail
;
22234 /* Draw all strings. */
22235 for (s
= head
; s
; s
= s
->next
)
22236 FRAME_RIF (f
)->draw_glyph_string (s
);
22239 /* When focus a sole frame and move horizontally, this sets on_p to 0
22240 causing a failure to erase prev cursor position. */
22241 if (area
== TEXT_AREA
22242 && !row
->full_width_p
22243 /* When drawing overlapping rows, only the glyph strings'
22244 foreground is drawn, which doesn't erase a cursor
22248 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
22249 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
22250 : (tail
? tail
->x
+ tail
->background_width
: x
));
22254 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
22255 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
22259 /* Value is the x-position up to which drawn, relative to AREA of W.
22260 This doesn't include parts drawn because of overhangs. */
22261 if (row
->full_width_p
)
22262 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
22264 x_reached
-= area_left
;
22266 RELEASE_HDC (hdc
, f
);
22271 /* Expand row matrix if too narrow. Don't expand if area
22274 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
22276 if (!fonts_changed_p \
22277 && (it->glyph_row->glyphs[area] \
22278 < it->glyph_row->glyphs[area + 1])) \
22280 it->w->ncols_scale_factor++; \
22281 fonts_changed_p = 1; \
22285 /* Store one glyph for IT->char_to_display in IT->glyph_row.
22286 Called from x_produce_glyphs when IT->glyph_row is non-null. */
22289 append_glyph (struct it
*it
)
22291 struct glyph
*glyph
;
22292 enum glyph_row_area area
= it
->area
;
22294 xassert (it
->glyph_row
);
22295 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
22297 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22298 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22300 /* If the glyph row is reversed, we need to prepend the glyph
22301 rather than append it. */
22302 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22306 /* Make room for the additional glyph. */
22307 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22309 glyph
= it
->glyph_row
->glyphs
[area
];
22311 glyph
->charpos
= CHARPOS (it
->position
);
22312 glyph
->object
= it
->object
;
22313 if (it
->pixel_width
> 0)
22315 glyph
->pixel_width
= it
->pixel_width
;
22316 glyph
->padding_p
= 0;
22320 /* Assure at least 1-pixel width. Otherwise, cursor can't
22321 be displayed correctly. */
22322 glyph
->pixel_width
= 1;
22323 glyph
->padding_p
= 1;
22325 glyph
->ascent
= it
->ascent
;
22326 glyph
->descent
= it
->descent
;
22327 glyph
->voffset
= it
->voffset
;
22328 glyph
->type
= CHAR_GLYPH
;
22329 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22330 glyph
->multibyte_p
= it
->multibyte_p
;
22331 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22332 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22333 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22334 || it
->phys_descent
> it
->descent
);
22335 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
22336 glyph
->face_id
= it
->face_id
;
22337 glyph
->u
.ch
= it
->char_to_display
;
22338 glyph
->slice
.img
= null_glyph_slice
;
22339 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22342 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22343 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22345 glyph
->bidi_type
= it
->bidi_it
.type
;
22349 glyph
->resolved_level
= 0;
22350 glyph
->bidi_type
= UNKNOWN_BT
;
22352 ++it
->glyph_row
->used
[area
];
22355 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22358 /* Store one glyph for the composition IT->cmp_it.id in
22359 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
22363 append_composite_glyph (struct it
*it
)
22365 struct glyph
*glyph
;
22366 enum glyph_row_area area
= it
->area
;
22368 xassert (it
->glyph_row
);
22370 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22371 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22373 /* If the glyph row is reversed, we need to prepend the glyph
22374 rather than append it. */
22375 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
22379 /* Make room for the new glyph. */
22380 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
22382 glyph
= it
->glyph_row
->glyphs
[it
->area
];
22384 glyph
->charpos
= it
->cmp_it
.charpos
;
22385 glyph
->object
= it
->object
;
22386 glyph
->pixel_width
= it
->pixel_width
;
22387 glyph
->ascent
= it
->ascent
;
22388 glyph
->descent
= it
->descent
;
22389 glyph
->voffset
= it
->voffset
;
22390 glyph
->type
= COMPOSITE_GLYPH
;
22391 if (it
->cmp_it
.ch
< 0)
22393 glyph
->u
.cmp
.automatic
= 0;
22394 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
22395 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
22399 glyph
->u
.cmp
.automatic
= 1;
22400 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
22401 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
22402 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
22404 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22405 glyph
->multibyte_p
= it
->multibyte_p
;
22406 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22407 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22408 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22409 || it
->phys_descent
> it
->descent
);
22410 glyph
->padding_p
= 0;
22411 glyph
->glyph_not_available_p
= 0;
22412 glyph
->face_id
= it
->face_id
;
22413 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22416 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22417 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22419 glyph
->bidi_type
= it
->bidi_it
.type
;
22421 ++it
->glyph_row
->used
[area
];
22424 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22428 /* Change IT->ascent and IT->height according to the setting of
22432 take_vertical_position_into_account (struct it
*it
)
22436 if (it
->voffset
< 0)
22437 /* Increase the ascent so that we can display the text higher
22439 it
->ascent
-= it
->voffset
;
22441 /* Increase the descent so that we can display the text lower
22443 it
->descent
+= it
->voffset
;
22448 /* Produce glyphs/get display metrics for the image IT is loaded with.
22449 See the description of struct display_iterator in dispextern.h for
22450 an overview of struct display_iterator. */
22453 produce_image_glyph (struct it
*it
)
22457 int glyph_ascent
, crop
;
22458 struct glyph_slice slice
;
22460 xassert (it
->what
== IT_IMAGE
);
22462 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22464 /* Make sure X resources of the face is loaded. */
22465 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22467 if (it
->image_id
< 0)
22469 /* Fringe bitmap. */
22470 it
->ascent
= it
->phys_ascent
= 0;
22471 it
->descent
= it
->phys_descent
= 0;
22472 it
->pixel_width
= 0;
22477 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
22479 /* Make sure X resources of the image is loaded. */
22480 prepare_image_for_display (it
->f
, img
);
22482 slice
.x
= slice
.y
= 0;
22483 slice
.width
= img
->width
;
22484 slice
.height
= img
->height
;
22486 if (INTEGERP (it
->slice
.x
))
22487 slice
.x
= XINT (it
->slice
.x
);
22488 else if (FLOATP (it
->slice
.x
))
22489 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
22491 if (INTEGERP (it
->slice
.y
))
22492 slice
.y
= XINT (it
->slice
.y
);
22493 else if (FLOATP (it
->slice
.y
))
22494 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
22496 if (INTEGERP (it
->slice
.width
))
22497 slice
.width
= XINT (it
->slice
.width
);
22498 else if (FLOATP (it
->slice
.width
))
22499 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
22501 if (INTEGERP (it
->slice
.height
))
22502 slice
.height
= XINT (it
->slice
.height
);
22503 else if (FLOATP (it
->slice
.height
))
22504 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
22506 if (slice
.x
>= img
->width
)
22507 slice
.x
= img
->width
;
22508 if (slice
.y
>= img
->height
)
22509 slice
.y
= img
->height
;
22510 if (slice
.x
+ slice
.width
>= img
->width
)
22511 slice
.width
= img
->width
- slice
.x
;
22512 if (slice
.y
+ slice
.height
> img
->height
)
22513 slice
.height
= img
->height
- slice
.y
;
22515 if (slice
.width
== 0 || slice
.height
== 0)
22518 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
22520 it
->descent
= slice
.height
- glyph_ascent
;
22522 it
->descent
+= img
->vmargin
;
22523 if (slice
.y
+ slice
.height
== img
->height
)
22524 it
->descent
+= img
->vmargin
;
22525 it
->phys_descent
= it
->descent
;
22527 it
->pixel_width
= slice
.width
;
22529 it
->pixel_width
+= img
->hmargin
;
22530 if (slice
.x
+ slice
.width
== img
->width
)
22531 it
->pixel_width
+= img
->hmargin
;
22533 /* It's quite possible for images to have an ascent greater than
22534 their height, so don't get confused in that case. */
22535 if (it
->descent
< 0)
22540 if (face
->box
!= FACE_NO_BOX
)
22542 if (face
->box_line_width
> 0)
22545 it
->ascent
+= face
->box_line_width
;
22546 if (slice
.y
+ slice
.height
== img
->height
)
22547 it
->descent
+= face
->box_line_width
;
22550 if (it
->start_of_box_run_p
&& slice
.x
== 0)
22551 it
->pixel_width
+= eabs (face
->box_line_width
);
22552 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
22553 it
->pixel_width
+= eabs (face
->box_line_width
);
22556 take_vertical_position_into_account (it
);
22558 /* Automatically crop wide image glyphs at right edge so we can
22559 draw the cursor on same display row. */
22560 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
22561 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
22563 it
->pixel_width
-= crop
;
22564 slice
.width
-= crop
;
22569 struct glyph
*glyph
;
22570 enum glyph_row_area area
= it
->area
;
22572 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22573 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22575 glyph
->charpos
= CHARPOS (it
->position
);
22576 glyph
->object
= it
->object
;
22577 glyph
->pixel_width
= it
->pixel_width
;
22578 glyph
->ascent
= glyph_ascent
;
22579 glyph
->descent
= it
->descent
;
22580 glyph
->voffset
= it
->voffset
;
22581 glyph
->type
= IMAGE_GLYPH
;
22582 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22583 glyph
->multibyte_p
= it
->multibyte_p
;
22584 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22585 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22586 glyph
->overlaps_vertically_p
= 0;
22587 glyph
->padding_p
= 0;
22588 glyph
->glyph_not_available_p
= 0;
22589 glyph
->face_id
= it
->face_id
;
22590 glyph
->u
.img_id
= img
->id
;
22591 glyph
->slice
.img
= slice
;
22592 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22595 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22596 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22598 glyph
->bidi_type
= it
->bidi_it
.type
;
22600 ++it
->glyph_row
->used
[area
];
22603 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22608 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
22609 of the glyph, WIDTH and HEIGHT are the width and height of the
22610 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
22613 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
22614 int width
, int height
, int ascent
)
22616 struct glyph
*glyph
;
22617 enum glyph_row_area area
= it
->area
;
22619 xassert (ascent
>= 0 && ascent
<= height
);
22621 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22622 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22624 /* If the glyph row is reversed, we need to prepend the glyph
22625 rather than append it. */
22626 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22630 /* Make room for the additional glyph. */
22631 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22633 glyph
= it
->glyph_row
->glyphs
[area
];
22635 glyph
->charpos
= CHARPOS (it
->position
);
22636 glyph
->object
= object
;
22637 glyph
->pixel_width
= width
;
22638 glyph
->ascent
= ascent
;
22639 glyph
->descent
= height
- ascent
;
22640 glyph
->voffset
= it
->voffset
;
22641 glyph
->type
= STRETCH_GLYPH
;
22642 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22643 glyph
->multibyte_p
= it
->multibyte_p
;
22644 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22645 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22646 glyph
->overlaps_vertically_p
= 0;
22647 glyph
->padding_p
= 0;
22648 glyph
->glyph_not_available_p
= 0;
22649 glyph
->face_id
= it
->face_id
;
22650 glyph
->u
.stretch
.ascent
= ascent
;
22651 glyph
->u
.stretch
.height
= height
;
22652 glyph
->slice
.img
= null_glyph_slice
;
22653 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22656 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22657 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22659 glyph
->bidi_type
= it
->bidi_it
.type
;
22663 glyph
->resolved_level
= 0;
22664 glyph
->bidi_type
= UNKNOWN_BT
;
22666 ++it
->glyph_row
->used
[area
];
22669 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22673 /* Produce a stretch glyph for iterator IT. IT->object is the value
22674 of the glyph property displayed. The value must be a list
22675 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
22678 1. `:width WIDTH' specifies that the space should be WIDTH *
22679 canonical char width wide. WIDTH may be an integer or floating
22682 2. `:relative-width FACTOR' specifies that the width of the stretch
22683 should be computed from the width of the first character having the
22684 `glyph' property, and should be FACTOR times that width.
22686 3. `:align-to HPOS' specifies that the space should be wide enough
22687 to reach HPOS, a value in canonical character units.
22689 Exactly one of the above pairs must be present.
22691 4. `:height HEIGHT' specifies that the height of the stretch produced
22692 should be HEIGHT, measured in canonical character units.
22694 5. `:relative-height FACTOR' specifies that the height of the
22695 stretch should be FACTOR times the height of the characters having
22696 the glyph property.
22698 Either none or exactly one of 4 or 5 must be present.
22700 6. `:ascent ASCENT' specifies that ASCENT percent of the height
22701 of the stretch should be used for the ascent of the stretch.
22702 ASCENT must be in the range 0 <= ASCENT <= 100. */
22705 produce_stretch_glyph (struct it
*it
)
22707 /* (space :width WIDTH :height HEIGHT ...) */
22708 Lisp_Object prop
, plist
;
22709 int width
= 0, height
= 0, align_to
= -1;
22710 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
22713 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22714 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22716 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22718 /* List should start with `space'. */
22719 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
22720 plist
= XCDR (it
->object
);
22722 /* Compute the width of the stretch. */
22723 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
22724 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
22726 /* Absolute width `:width WIDTH' specified and valid. */
22727 zero_width_ok_p
= 1;
22730 else if (prop
= Fplist_get (plist
, QCrelative_width
),
22733 /* Relative width `:relative-width FACTOR' specified and valid.
22734 Compute the width of the characters having the `glyph'
22737 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
22740 if (it
->multibyte_p
)
22741 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
22744 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
22745 if (! ASCII_CHAR_P (it2
.c
))
22746 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
22749 it2
.glyph_row
= NULL
;
22750 it2
.what
= IT_CHARACTER
;
22751 x_produce_glyphs (&it2
);
22752 width
= NUMVAL (prop
) * it2
.pixel_width
;
22754 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
22755 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
22757 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
22758 align_to
= (align_to
< 0
22760 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
22761 else if (align_to
< 0)
22762 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
22763 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
22764 zero_width_ok_p
= 1;
22767 /* Nothing specified -> width defaults to canonical char width. */
22768 width
= FRAME_COLUMN_WIDTH (it
->f
);
22770 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
22773 /* Compute height. */
22774 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
22775 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22778 zero_height_ok_p
= 1;
22780 else if (prop
= Fplist_get (plist
, QCrelative_height
),
22782 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
22784 height
= FONT_HEIGHT (font
);
22786 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
22789 /* Compute percentage of height used for ascent. If
22790 `:ascent ASCENT' is present and valid, use that. Otherwise,
22791 derive the ascent from the font in use. */
22792 if (prop
= Fplist_get (plist
, QCascent
),
22793 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
22794 ascent
= height
* NUMVAL (prop
) / 100.0;
22795 else if (!NILP (prop
)
22796 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22797 ascent
= min (max (0, (int)tem
), height
);
22799 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
22801 if (width
> 0 && it
->line_wrap
!= TRUNCATE
22802 && it
->current_x
+ width
> it
->last_visible_x
)
22803 width
= it
->last_visible_x
- it
->current_x
- 1;
22805 if (width
> 0 && height
> 0 && it
->glyph_row
)
22807 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
22808 if (!STRINGP (object
))
22809 object
= it
->w
->buffer
;
22810 append_stretch_glyph (it
, object
, width
, height
, ascent
);
22813 it
->pixel_width
= width
;
22814 it
->ascent
= it
->phys_ascent
= ascent
;
22815 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
22816 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
22818 take_vertical_position_into_account (it
);
22821 /* Calculate line-height and line-spacing properties.
22822 An integer value specifies explicit pixel value.
22823 A float value specifies relative value to current face height.
22824 A cons (float . face-name) specifies relative value to
22825 height of specified face font.
22827 Returns height in pixels, or nil. */
22831 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
22832 int boff
, int override
)
22834 Lisp_Object face_name
= Qnil
;
22835 int ascent
, descent
, height
;
22837 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
22842 face_name
= XCAR (val
);
22844 if (!NUMBERP (val
))
22845 val
= make_number (1);
22846 if (NILP (face_name
))
22848 height
= it
->ascent
+ it
->descent
;
22853 if (NILP (face_name
))
22855 font
= FRAME_FONT (it
->f
);
22856 boff
= FRAME_BASELINE_OFFSET (it
->f
);
22858 else if (EQ (face_name
, Qt
))
22867 face_id
= lookup_named_face (it
->f
, face_name
, 0);
22869 return make_number (-1);
22871 face
= FACE_FROM_ID (it
->f
, face_id
);
22874 return make_number (-1);
22875 boff
= font
->baseline_offset
;
22876 if (font
->vertical_centering
)
22877 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22880 ascent
= FONT_BASE (font
) + boff
;
22881 descent
= FONT_DESCENT (font
) - boff
;
22885 it
->override_ascent
= ascent
;
22886 it
->override_descent
= descent
;
22887 it
->override_boff
= boff
;
22890 height
= ascent
+ descent
;
22894 height
= (int)(XFLOAT_DATA (val
) * height
);
22895 else if (INTEGERP (val
))
22896 height
*= XINT (val
);
22898 return make_number (height
);
22902 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
22903 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
22904 and only if this is for a character for which no font was found.
22906 If the display method (it->glyphless_method) is
22907 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
22908 length of the acronym or the hexadecimal string, UPPER_XOFF and
22909 UPPER_YOFF are pixel offsets for the upper part of the string,
22910 LOWER_XOFF and LOWER_YOFF are for the lower part.
22912 For the other display methods, LEN through LOWER_YOFF are zero. */
22915 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
22916 short upper_xoff
, short upper_yoff
,
22917 short lower_xoff
, short lower_yoff
)
22919 struct glyph
*glyph
;
22920 enum glyph_row_area area
= it
->area
;
22922 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22923 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22925 /* If the glyph row is reversed, we need to prepend the glyph
22926 rather than append it. */
22927 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22931 /* Make room for the additional glyph. */
22932 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22934 glyph
= it
->glyph_row
->glyphs
[area
];
22936 glyph
->charpos
= CHARPOS (it
->position
);
22937 glyph
->object
= it
->object
;
22938 glyph
->pixel_width
= it
->pixel_width
;
22939 glyph
->ascent
= it
->ascent
;
22940 glyph
->descent
= it
->descent
;
22941 glyph
->voffset
= it
->voffset
;
22942 glyph
->type
= GLYPHLESS_GLYPH
;
22943 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
22944 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
22945 glyph
->u
.glyphless
.len
= len
;
22946 glyph
->u
.glyphless
.ch
= it
->c
;
22947 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
22948 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
22949 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
22950 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
22951 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22952 glyph
->multibyte_p
= it
->multibyte_p
;
22953 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22954 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22955 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22956 || it
->phys_descent
> it
->descent
);
22957 glyph
->padding_p
= 0;
22958 glyph
->glyph_not_available_p
= 0;
22959 glyph
->face_id
= face_id
;
22960 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22963 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22964 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22966 glyph
->bidi_type
= it
->bidi_it
.type
;
22968 ++it
->glyph_row
->used
[area
];
22971 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22975 /* Produce a glyph for a glyphless character for iterator IT.
22976 IT->glyphless_method specifies which method to use for displaying
22977 the character. See the description of enum
22978 glyphless_display_method in dispextern.h for the detail.
22980 FOR_NO_FONT is nonzero if and only if this is for a character for
22981 which no font was found. ACRONYM, if non-nil, is an acronym string
22982 for the character. */
22985 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
22990 int base_width
, base_height
, width
, height
;
22991 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
22994 /* Get the metrics of the base font. We always refer to the current
22996 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
22997 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22998 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
22999 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
23000 base_height
= it
->ascent
+ it
->descent
;
23001 base_width
= font
->average_width
;
23003 /* Get a face ID for the glyph by utilizing a cache (the same way as
23004 doen for `escape-glyph' in get_next_display_element). */
23005 if (it
->f
== last_glyphless_glyph_frame
23006 && it
->face_id
== last_glyphless_glyph_face_id
)
23008 face_id
= last_glyphless_glyph_merged_face_id
;
23012 /* Merge the `glyphless-char' face into the current face. */
23013 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
23014 last_glyphless_glyph_frame
= it
->f
;
23015 last_glyphless_glyph_face_id
= it
->face_id
;
23016 last_glyphless_glyph_merged_face_id
= face_id
;
23019 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
23021 it
->pixel_width
= THIN_SPACE_WIDTH
;
23023 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
23025 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
23027 width
= CHAR_WIDTH (it
->c
);
23030 else if (width
> 4)
23032 it
->pixel_width
= base_width
* width
;
23034 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
23040 unsigned int code
[6];
23042 int ascent
, descent
;
23043 struct font_metrics metrics_upper
, metrics_lower
;
23045 face
= FACE_FROM_ID (it
->f
, face_id
);
23046 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23047 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23049 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
23051 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
23052 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
23053 if (CONSP (acronym
))
23054 acronym
= XCAR (acronym
);
23055 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
23059 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
23060 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
23063 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
23064 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
23065 upper_len
= (len
+ 1) / 2;
23066 font
->driver
->text_extents (font
, code
, upper_len
,
23068 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
23073 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
23074 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
23075 upper_xoff
= upper_yoff
= 2; /* the typical case */
23076 if (base_width
>= width
)
23078 /* Align the upper to the left, the lower to the right. */
23079 it
->pixel_width
= base_width
;
23080 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
23084 /* Center the shorter one. */
23085 it
->pixel_width
= width
;
23086 if (metrics_upper
.width
>= metrics_lower
.width
)
23087 lower_xoff
= (width
- metrics_lower
.width
) / 2;
23090 /* FIXME: This code doesn't look right. It formerly was
23091 missing the "lower_xoff = 0;", which couldn't have
23092 been right since it left lower_xoff uninitialized. */
23094 upper_xoff
= (width
- metrics_upper
.width
) / 2;
23098 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
23099 top, bottom, and between upper and lower strings. */
23100 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
23101 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
23102 /* Center vertically.
23103 H:base_height, D:base_descent
23104 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
23106 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
23107 descent = D - H/2 + h/2;
23108 lower_yoff = descent - 2 - ld;
23109 upper_yoff = lower_yoff - la - 1 - ud; */
23110 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
23111 descent
= it
->descent
- (base_height
- height
) / 2;
23112 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
23113 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
23114 - metrics_upper
.descent
);
23115 /* Don't make the height shorter than the base height. */
23116 if (height
> base_height
)
23118 it
->ascent
= ascent
;
23119 it
->descent
= descent
;
23123 it
->phys_ascent
= it
->ascent
;
23124 it
->phys_descent
= it
->descent
;
23126 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
23127 upper_xoff
, upper_yoff
,
23128 lower_xoff
, lower_yoff
);
23130 take_vertical_position_into_account (it
);
23135 Produce glyphs/get display metrics for the display element IT is
23136 loaded with. See the description of struct it in dispextern.h
23137 for an overview of struct it. */
23140 x_produce_glyphs (struct it
*it
)
23142 int extra_line_spacing
= it
->extra_line_spacing
;
23144 it
->glyph_not_available_p
= 0;
23146 if (it
->what
== IT_CHARACTER
)
23149 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23150 struct font
*font
= face
->font
;
23151 struct font_metrics
*pcm
= NULL
;
23152 int boff
; /* baseline offset */
23156 /* When no suitable font is found, display this character by
23157 the method specified in the first extra slot of
23158 Vglyphless_char_display. */
23159 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
23161 xassert (it
->what
== IT_GLYPHLESS
);
23162 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
23166 boff
= font
->baseline_offset
;
23167 if (font
->vertical_centering
)
23168 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23170 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
23176 if (it
->override_ascent
>= 0)
23178 it
->ascent
= it
->override_ascent
;
23179 it
->descent
= it
->override_descent
;
23180 boff
= it
->override_boff
;
23184 it
->ascent
= FONT_BASE (font
) + boff
;
23185 it
->descent
= FONT_DESCENT (font
) - boff
;
23188 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
23190 pcm
= get_per_char_metric (font
, &char2b
);
23191 if (pcm
->width
== 0
23192 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
23198 it
->phys_ascent
= pcm
->ascent
+ boff
;
23199 it
->phys_descent
= pcm
->descent
- boff
;
23200 it
->pixel_width
= pcm
->width
;
23204 it
->glyph_not_available_p
= 1;
23205 it
->phys_ascent
= it
->ascent
;
23206 it
->phys_descent
= it
->descent
;
23207 it
->pixel_width
= font
->space_width
;
23210 if (it
->constrain_row_ascent_descent_p
)
23212 if (it
->descent
> it
->max_descent
)
23214 it
->ascent
+= it
->descent
- it
->max_descent
;
23215 it
->descent
= it
->max_descent
;
23217 if (it
->ascent
> it
->max_ascent
)
23219 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
23220 it
->ascent
= it
->max_ascent
;
23222 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
23223 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
23224 extra_line_spacing
= 0;
23227 /* If this is a space inside a region of text with
23228 `space-width' property, change its width. */
23229 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
23231 it
->pixel_width
*= XFLOATINT (it
->space_width
);
23233 /* If face has a box, add the box thickness to the character
23234 height. If character has a box line to the left and/or
23235 right, add the box line width to the character's width. */
23236 if (face
->box
!= FACE_NO_BOX
)
23238 int thick
= face
->box_line_width
;
23242 it
->ascent
+= thick
;
23243 it
->descent
+= thick
;
23248 if (it
->start_of_box_run_p
)
23249 it
->pixel_width
+= thick
;
23250 if (it
->end_of_box_run_p
)
23251 it
->pixel_width
+= thick
;
23254 /* If face has an overline, add the height of the overline
23255 (1 pixel) and a 1 pixel margin to the character height. */
23256 if (face
->overline_p
)
23257 it
->ascent
+= overline_margin
;
23259 if (it
->constrain_row_ascent_descent_p
)
23261 if (it
->ascent
> it
->max_ascent
)
23262 it
->ascent
= it
->max_ascent
;
23263 if (it
->descent
> it
->max_descent
)
23264 it
->descent
= it
->max_descent
;
23267 take_vertical_position_into_account (it
);
23269 /* If we have to actually produce glyphs, do it. */
23274 /* Translate a space with a `space-width' property
23275 into a stretch glyph. */
23276 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
23277 / FONT_HEIGHT (font
));
23278 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
23279 it
->ascent
+ it
->descent
, ascent
);
23284 /* If characters with lbearing or rbearing are displayed
23285 in this line, record that fact in a flag of the
23286 glyph row. This is used to optimize X output code. */
23287 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
23288 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23290 if (! stretched_p
&& it
->pixel_width
== 0)
23291 /* We assure that all visible glyphs have at least 1-pixel
23293 it
->pixel_width
= 1;
23295 else if (it
->char_to_display
== '\n')
23297 /* A newline has no width, but we need the height of the
23298 line. But if previous part of the line sets a height,
23299 don't increase that height */
23301 Lisp_Object height
;
23302 Lisp_Object total_height
= Qnil
;
23304 it
->override_ascent
= -1;
23305 it
->pixel_width
= 0;
23308 height
= get_it_property (it
, Qline_height
);
23309 /* Split (line-height total-height) list */
23311 && CONSP (XCDR (height
))
23312 && NILP (XCDR (XCDR (height
))))
23314 total_height
= XCAR (XCDR (height
));
23315 height
= XCAR (height
);
23317 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
23319 if (it
->override_ascent
>= 0)
23321 it
->ascent
= it
->override_ascent
;
23322 it
->descent
= it
->override_descent
;
23323 boff
= it
->override_boff
;
23327 it
->ascent
= FONT_BASE (font
) + boff
;
23328 it
->descent
= FONT_DESCENT (font
) - boff
;
23331 if (EQ (height
, Qt
))
23333 if (it
->descent
> it
->max_descent
)
23335 it
->ascent
+= it
->descent
- it
->max_descent
;
23336 it
->descent
= it
->max_descent
;
23338 if (it
->ascent
> it
->max_ascent
)
23340 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
23341 it
->ascent
= it
->max_ascent
;
23343 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
23344 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
23345 it
->constrain_row_ascent_descent_p
= 1;
23346 extra_line_spacing
= 0;
23350 Lisp_Object spacing
;
23352 it
->phys_ascent
= it
->ascent
;
23353 it
->phys_descent
= it
->descent
;
23355 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
23356 && face
->box
!= FACE_NO_BOX
23357 && face
->box_line_width
> 0)
23359 it
->ascent
+= face
->box_line_width
;
23360 it
->descent
+= face
->box_line_width
;
23363 && XINT (height
) > it
->ascent
+ it
->descent
)
23364 it
->ascent
= XINT (height
) - it
->descent
;
23366 if (!NILP (total_height
))
23367 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
23370 spacing
= get_it_property (it
, Qline_spacing
);
23371 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
23373 if (INTEGERP (spacing
))
23375 extra_line_spacing
= XINT (spacing
);
23376 if (!NILP (total_height
))
23377 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
23381 else /* i.e. (it->char_to_display == '\t') */
23383 if (font
->space_width
> 0)
23385 int tab_width
= it
->tab_width
* font
->space_width
;
23386 int x
= it
->current_x
+ it
->continuation_lines_width
;
23387 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
23389 /* If the distance from the current position to the next tab
23390 stop is less than a space character width, use the
23391 tab stop after that. */
23392 if (next_tab_x
- x
< font
->space_width
)
23393 next_tab_x
+= tab_width
;
23395 it
->pixel_width
= next_tab_x
- x
;
23397 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
23398 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
23402 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
23403 it
->ascent
+ it
->descent
, it
->ascent
);
23408 it
->pixel_width
= 0;
23413 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
23415 /* A static composition.
23417 Note: A composition is represented as one glyph in the
23418 glyph matrix. There are no padding glyphs.
23420 Important note: pixel_width, ascent, and descent are the
23421 values of what is drawn by draw_glyphs (i.e. the values of
23422 the overall glyphs composed). */
23423 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23424 int boff
; /* baseline offset */
23425 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
23426 int glyph_len
= cmp
->glyph_len
;
23427 struct font
*font
= face
->font
;
23431 /* If we have not yet calculated pixel size data of glyphs of
23432 the composition for the current face font, calculate them
23433 now. Theoretically, we have to check all fonts for the
23434 glyphs, but that requires much time and memory space. So,
23435 here we check only the font of the first glyph. This may
23436 lead to incorrect display, but it's very rare, and C-l
23437 (recenter-top-bottom) can correct the display anyway. */
23438 if (! cmp
->font
|| cmp
->font
!= font
)
23440 /* Ascent and descent of the font of the first character
23441 of this composition (adjusted by baseline offset).
23442 Ascent and descent of overall glyphs should not be less
23443 than these, respectively. */
23444 int font_ascent
, font_descent
, font_height
;
23445 /* Bounding box of the overall glyphs. */
23446 int leftmost
, rightmost
, lowest
, highest
;
23447 int lbearing
, rbearing
;
23448 int i
, width
, ascent
, descent
;
23449 int left_padded
= 0, right_padded
= 0;
23450 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
23452 struct font_metrics
*pcm
;
23453 int font_not_found_p
;
23456 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
23457 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
23459 if (glyph_len
< cmp
->glyph_len
)
23461 for (i
= 0; i
< glyph_len
; i
++)
23463 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
23465 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
23470 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
23471 : IT_CHARPOS (*it
));
23472 /* If no suitable font is found, use the default font. */
23473 font_not_found_p
= font
== NULL
;
23474 if (font_not_found_p
)
23476 face
= face
->ascii_face
;
23479 boff
= font
->baseline_offset
;
23480 if (font
->vertical_centering
)
23481 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23482 font_ascent
= FONT_BASE (font
) + boff
;
23483 font_descent
= FONT_DESCENT (font
) - boff
;
23484 font_height
= FONT_HEIGHT (font
);
23486 cmp
->font
= (void *) font
;
23489 if (! font_not_found_p
)
23491 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
23493 pcm
= get_per_char_metric (font
, &char2b
);
23496 /* Initialize the bounding box. */
23499 width
= pcm
->width
;
23500 ascent
= pcm
->ascent
;
23501 descent
= pcm
->descent
;
23502 lbearing
= pcm
->lbearing
;
23503 rbearing
= pcm
->rbearing
;
23507 width
= font
->space_width
;
23508 ascent
= FONT_BASE (font
);
23509 descent
= FONT_DESCENT (font
);
23516 lowest
= - descent
+ boff
;
23517 highest
= ascent
+ boff
;
23519 if (! font_not_found_p
23520 && font
->default_ascent
23521 && CHAR_TABLE_P (Vuse_default_ascent
)
23522 && !NILP (Faref (Vuse_default_ascent
,
23523 make_number (it
->char_to_display
))))
23524 highest
= font
->default_ascent
+ boff
;
23526 /* Draw the first glyph at the normal position. It may be
23527 shifted to right later if some other glyphs are drawn
23529 cmp
->offsets
[i
* 2] = 0;
23530 cmp
->offsets
[i
* 2 + 1] = boff
;
23531 cmp
->lbearing
= lbearing
;
23532 cmp
->rbearing
= rbearing
;
23534 /* Set cmp->offsets for the remaining glyphs. */
23535 for (i
++; i
< glyph_len
; i
++)
23537 int left
, right
, btm
, top
;
23538 int ch
= COMPOSITION_GLYPH (cmp
, i
);
23540 struct face
*this_face
;
23544 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
23545 this_face
= FACE_FROM_ID (it
->f
, face_id
);
23546 font
= this_face
->font
;
23552 get_char_face_and_encoding (it
->f
, ch
, face_id
,
23554 pcm
= get_per_char_metric (font
, &char2b
);
23557 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
23560 width
= pcm
->width
;
23561 ascent
= pcm
->ascent
;
23562 descent
= pcm
->descent
;
23563 lbearing
= pcm
->lbearing
;
23564 rbearing
= pcm
->rbearing
;
23565 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
23567 /* Relative composition with or without
23568 alternate chars. */
23569 left
= (leftmost
+ rightmost
- width
) / 2;
23570 btm
= - descent
+ boff
;
23571 if (font
->relative_compose
23572 && (! CHAR_TABLE_P (Vignore_relative_composition
)
23573 || NILP (Faref (Vignore_relative_composition
,
23574 make_number (ch
)))))
23577 if (- descent
>= font
->relative_compose
)
23578 /* One extra pixel between two glyphs. */
23580 else if (ascent
<= 0)
23581 /* One extra pixel between two glyphs. */
23582 btm
= lowest
- 1 - ascent
- descent
;
23587 /* A composition rule is specified by an integer
23588 value that encodes global and new reference
23589 points (GREF and NREF). GREF and NREF are
23590 specified by numbers as below:
23592 0---1---2 -- ascent
23596 9--10--11 -- center
23598 ---3---4---5--- baseline
23600 6---7---8 -- descent
23602 int rule
= COMPOSITION_RULE (cmp
, i
);
23603 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
23605 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
23606 grefx
= gref
% 3, nrefx
= nref
% 3;
23607 grefy
= gref
/ 3, nrefy
= nref
/ 3;
23609 xoff
= font_height
* (xoff
- 128) / 256;
23611 yoff
= font_height
* (yoff
- 128) / 256;
23614 + grefx
* (rightmost
- leftmost
) / 2
23615 - nrefx
* width
/ 2
23618 btm
= ((grefy
== 0 ? highest
23620 : grefy
== 2 ? lowest
23621 : (highest
+ lowest
) / 2)
23622 - (nrefy
== 0 ? ascent
+ descent
23623 : nrefy
== 1 ? descent
- boff
23625 : (ascent
+ descent
) / 2)
23629 cmp
->offsets
[i
* 2] = left
;
23630 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
23632 /* Update the bounding box of the overall glyphs. */
23635 right
= left
+ width
;
23636 if (left
< leftmost
)
23638 if (right
> rightmost
)
23641 top
= btm
+ descent
+ ascent
;
23647 if (cmp
->lbearing
> left
+ lbearing
)
23648 cmp
->lbearing
= left
+ lbearing
;
23649 if (cmp
->rbearing
< left
+ rbearing
)
23650 cmp
->rbearing
= left
+ rbearing
;
23654 /* If there are glyphs whose x-offsets are negative,
23655 shift all glyphs to the right and make all x-offsets
23659 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23660 cmp
->offsets
[i
* 2] -= leftmost
;
23661 rightmost
-= leftmost
;
23662 cmp
->lbearing
-= leftmost
;
23663 cmp
->rbearing
-= leftmost
;
23666 if (left_padded
&& cmp
->lbearing
< 0)
23668 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23669 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
23670 rightmost
-= cmp
->lbearing
;
23671 cmp
->rbearing
-= cmp
->lbearing
;
23674 if (right_padded
&& rightmost
< cmp
->rbearing
)
23676 rightmost
= cmp
->rbearing
;
23679 cmp
->pixel_width
= rightmost
;
23680 cmp
->ascent
= highest
;
23681 cmp
->descent
= - lowest
;
23682 if (cmp
->ascent
< font_ascent
)
23683 cmp
->ascent
= font_ascent
;
23684 if (cmp
->descent
< font_descent
)
23685 cmp
->descent
= font_descent
;
23689 && (cmp
->lbearing
< 0
23690 || cmp
->rbearing
> cmp
->pixel_width
))
23691 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23693 it
->pixel_width
= cmp
->pixel_width
;
23694 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
23695 it
->descent
= it
->phys_descent
= cmp
->descent
;
23696 if (face
->box
!= FACE_NO_BOX
)
23698 int thick
= face
->box_line_width
;
23702 it
->ascent
+= thick
;
23703 it
->descent
+= thick
;
23708 if (it
->start_of_box_run_p
)
23709 it
->pixel_width
+= thick
;
23710 if (it
->end_of_box_run_p
)
23711 it
->pixel_width
+= thick
;
23714 /* If face has an overline, add the height of the overline
23715 (1 pixel) and a 1 pixel margin to the character height. */
23716 if (face
->overline_p
)
23717 it
->ascent
+= overline_margin
;
23719 take_vertical_position_into_account (it
);
23720 if (it
->ascent
< 0)
23722 if (it
->descent
< 0)
23726 append_composite_glyph (it
);
23728 else if (it
->what
== IT_COMPOSITION
)
23730 /* A dynamic (automatic) composition. */
23731 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23732 Lisp_Object gstring
;
23733 struct font_metrics metrics
;
23735 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
23737 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
23740 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
23741 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23742 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
23743 it
->descent
= it
->phys_descent
= metrics
.descent
;
23744 if (face
->box
!= FACE_NO_BOX
)
23746 int thick
= face
->box_line_width
;
23750 it
->ascent
+= thick
;
23751 it
->descent
+= thick
;
23756 if (it
->start_of_box_run_p
)
23757 it
->pixel_width
+= thick
;
23758 if (it
->end_of_box_run_p
)
23759 it
->pixel_width
+= thick
;
23761 /* If face has an overline, add the height of the overline
23762 (1 pixel) and a 1 pixel margin to the character height. */
23763 if (face
->overline_p
)
23764 it
->ascent
+= overline_margin
;
23765 take_vertical_position_into_account (it
);
23766 if (it
->ascent
< 0)
23768 if (it
->descent
< 0)
23772 append_composite_glyph (it
);
23774 else if (it
->what
== IT_GLYPHLESS
)
23775 produce_glyphless_glyph (it
, 0, Qnil
);
23776 else if (it
->what
== IT_IMAGE
)
23777 produce_image_glyph (it
);
23778 else if (it
->what
== IT_STRETCH
)
23779 produce_stretch_glyph (it
);
23782 /* Accumulate dimensions. Note: can't assume that it->descent > 0
23783 because this isn't true for images with `:ascent 100'. */
23784 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
23785 if (it
->area
== TEXT_AREA
)
23786 it
->current_x
+= it
->pixel_width
;
23788 if (extra_line_spacing
> 0)
23790 it
->descent
+= extra_line_spacing
;
23791 if (extra_line_spacing
> it
->max_extra_line_spacing
)
23792 it
->max_extra_line_spacing
= extra_line_spacing
;
23795 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
23796 it
->max_descent
= max (it
->max_descent
, it
->descent
);
23797 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
23798 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
23802 Output LEN glyphs starting at START at the nominal cursor position.
23803 Advance the nominal cursor over the text. The global variable
23804 updated_window contains the window being updated, updated_row is
23805 the glyph row being updated, and updated_area is the area of that
23806 row being updated. */
23809 x_write_glyphs (struct glyph
*start
, int len
)
23813 xassert (updated_window
&& updated_row
);
23816 /* Write glyphs. */
23818 hpos
= start
- updated_row
->glyphs
[updated_area
];
23819 x
= draw_glyphs (updated_window
, output_cursor
.x
,
23820 updated_row
, updated_area
,
23822 DRAW_NORMAL_TEXT
, 0);
23824 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
23825 if (updated_area
== TEXT_AREA
23826 && updated_window
->phys_cursor_on_p
23827 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
23828 && updated_window
->phys_cursor
.hpos
>= hpos
23829 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
23830 updated_window
->phys_cursor_on_p
= 0;
23834 /* Advance the output cursor. */
23835 output_cursor
.hpos
+= len
;
23836 output_cursor
.x
= x
;
23841 Insert LEN glyphs from START at the nominal cursor position. */
23844 x_insert_glyphs (struct glyph
*start
, int len
)
23848 int line_height
, shift_by_width
, shifted_region_width
;
23849 struct glyph_row
*row
;
23850 struct glyph
*glyph
;
23851 int frame_x
, frame_y
;
23854 xassert (updated_window
&& updated_row
);
23856 w
= updated_window
;
23857 f
= XFRAME (WINDOW_FRAME (w
));
23859 /* Get the height of the line we are in. */
23861 line_height
= row
->height
;
23863 /* Get the width of the glyphs to insert. */
23864 shift_by_width
= 0;
23865 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
23866 shift_by_width
+= glyph
->pixel_width
;
23868 /* Get the width of the region to shift right. */
23869 shifted_region_width
= (window_box_width (w
, updated_area
)
23874 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
23875 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
23877 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
23878 line_height
, shift_by_width
);
23880 /* Write the glyphs. */
23881 hpos
= start
- row
->glyphs
[updated_area
];
23882 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
23884 DRAW_NORMAL_TEXT
, 0);
23886 /* Advance the output cursor. */
23887 output_cursor
.hpos
+= len
;
23888 output_cursor
.x
+= shift_by_width
;
23894 Erase the current text line from the nominal cursor position
23895 (inclusive) to pixel column TO_X (exclusive). The idea is that
23896 everything from TO_X onward is already erased.
23898 TO_X is a pixel position relative to updated_area of
23899 updated_window. TO_X == -1 means clear to the end of this area. */
23902 x_clear_end_of_line (int to_x
)
23905 struct window
*w
= updated_window
;
23906 int max_x
, min_y
, max_y
;
23907 int from_x
, from_y
, to_y
;
23909 xassert (updated_window
&& updated_row
);
23910 f
= XFRAME (w
->frame
);
23912 if (updated_row
->full_width_p
)
23913 max_x
= WINDOW_TOTAL_WIDTH (w
);
23915 max_x
= window_box_width (w
, updated_area
);
23916 max_y
= window_text_bottom_y (w
);
23918 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
23919 of window. For TO_X > 0, truncate to end of drawing area. */
23925 to_x
= min (to_x
, max_x
);
23927 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
23929 /* Notice if the cursor will be cleared by this operation. */
23930 if (!updated_row
->full_width_p
)
23931 notice_overwritten_cursor (w
, updated_area
,
23932 output_cursor
.x
, -1,
23934 MATRIX_ROW_BOTTOM_Y (updated_row
));
23936 from_x
= output_cursor
.x
;
23938 /* Translate to frame coordinates. */
23939 if (updated_row
->full_width_p
)
23941 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
23942 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
23946 int area_left
= window_box_left (w
, updated_area
);
23947 from_x
+= area_left
;
23951 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
23952 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
23953 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
23955 /* Prevent inadvertently clearing to end of the X window. */
23956 if (to_x
> from_x
&& to_y
> from_y
)
23959 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
23960 to_x
- from_x
, to_y
- from_y
);
23965 #endif /* HAVE_WINDOW_SYSTEM */
23969 /***********************************************************************
23971 ***********************************************************************/
23973 /* Value is the internal representation of the specified cursor type
23974 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
23975 of the bar cursor. */
23977 static enum text_cursor_kinds
23978 get_specified_cursor_type (Lisp_Object arg
, int *width
)
23980 enum text_cursor_kinds type
;
23985 if (EQ (arg
, Qbox
))
23986 return FILLED_BOX_CURSOR
;
23988 if (EQ (arg
, Qhollow
))
23989 return HOLLOW_BOX_CURSOR
;
23991 if (EQ (arg
, Qbar
))
23998 && EQ (XCAR (arg
), Qbar
)
23999 && INTEGERP (XCDR (arg
))
24000 && XINT (XCDR (arg
)) >= 0)
24002 *width
= XINT (XCDR (arg
));
24006 if (EQ (arg
, Qhbar
))
24009 return HBAR_CURSOR
;
24013 && EQ (XCAR (arg
), Qhbar
)
24014 && INTEGERP (XCDR (arg
))
24015 && XINT (XCDR (arg
)) >= 0)
24017 *width
= XINT (XCDR (arg
));
24018 return HBAR_CURSOR
;
24021 /* Treat anything unknown as "hollow box cursor".
24022 It was bad to signal an error; people have trouble fixing
24023 .Xdefaults with Emacs, when it has something bad in it. */
24024 type
= HOLLOW_BOX_CURSOR
;
24029 /* Set the default cursor types for specified frame. */
24031 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
24036 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
24037 FRAME_CURSOR_WIDTH (f
) = width
;
24039 /* By default, set up the blink-off state depending on the on-state. */
24041 tem
= Fassoc (arg
, Vblink_cursor_alist
);
24044 FRAME_BLINK_OFF_CURSOR (f
)
24045 = get_specified_cursor_type (XCDR (tem
), &width
);
24046 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
24049 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
24053 #ifdef HAVE_WINDOW_SYSTEM
24055 /* Return the cursor we want to be displayed in window W. Return
24056 width of bar/hbar cursor through WIDTH arg. Return with
24057 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
24058 (i.e. if the `system caret' should track this cursor).
24060 In a mini-buffer window, we want the cursor only to appear if we
24061 are reading input from this window. For the selected window, we
24062 want the cursor type given by the frame parameter or buffer local
24063 setting of cursor-type. If explicitly marked off, draw no cursor.
24064 In all other cases, we want a hollow box cursor. */
24066 static enum text_cursor_kinds
24067 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
24068 int *active_cursor
)
24070 struct frame
*f
= XFRAME (w
->frame
);
24071 struct buffer
*b
= XBUFFER (w
->buffer
);
24072 int cursor_type
= DEFAULT_CURSOR
;
24073 Lisp_Object alt_cursor
;
24074 int non_selected
= 0;
24076 *active_cursor
= 1;
24079 if (cursor_in_echo_area
24080 && FRAME_HAS_MINIBUF_P (f
)
24081 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
24083 if (w
== XWINDOW (echo_area_window
))
24085 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
24087 *width
= FRAME_CURSOR_WIDTH (f
);
24088 return FRAME_DESIRED_CURSOR (f
);
24091 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
24094 *active_cursor
= 0;
24098 /* Detect a nonselected window or nonselected frame. */
24099 else if (w
!= XWINDOW (f
->selected_window
)
24100 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
24102 *active_cursor
= 0;
24104 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
24110 /* Never display a cursor in a window in which cursor-type is nil. */
24111 if (NILP (BVAR (b
, cursor_type
)))
24114 /* Get the normal cursor type for this window. */
24115 if (EQ (BVAR (b
, cursor_type
), Qt
))
24117 cursor_type
= FRAME_DESIRED_CURSOR (f
);
24118 *width
= FRAME_CURSOR_WIDTH (f
);
24121 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
24123 /* Use cursor-in-non-selected-windows instead
24124 for non-selected window or frame. */
24127 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
24128 if (!EQ (Qt
, alt_cursor
))
24129 return get_specified_cursor_type (alt_cursor
, width
);
24130 /* t means modify the normal cursor type. */
24131 if (cursor_type
== FILLED_BOX_CURSOR
)
24132 cursor_type
= HOLLOW_BOX_CURSOR
;
24133 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
24135 return cursor_type
;
24138 /* Use normal cursor if not blinked off. */
24139 if (!w
->cursor_off_p
)
24141 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
24143 if (cursor_type
== FILLED_BOX_CURSOR
)
24145 /* Using a block cursor on large images can be very annoying.
24146 So use a hollow cursor for "large" images.
24147 If image is not transparent (no mask), also use hollow cursor. */
24148 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
24149 if (img
!= NULL
&& IMAGEP (img
->spec
))
24151 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
24152 where N = size of default frame font size.
24153 This should cover most of the "tiny" icons people may use. */
24155 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
24156 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
24157 cursor_type
= HOLLOW_BOX_CURSOR
;
24160 else if (cursor_type
!= NO_CURSOR
)
24162 /* Display current only supports BOX and HOLLOW cursors for images.
24163 So for now, unconditionally use a HOLLOW cursor when cursor is
24164 not a solid box cursor. */
24165 cursor_type
= HOLLOW_BOX_CURSOR
;
24168 return cursor_type
;
24171 /* Cursor is blinked off, so determine how to "toggle" it. */
24173 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
24174 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
24175 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
24177 /* Then see if frame has specified a specific blink off cursor type. */
24178 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
24180 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
24181 return FRAME_BLINK_OFF_CURSOR (f
);
24185 /* Some people liked having a permanently visible blinking cursor,
24186 while others had very strong opinions against it. So it was
24187 decided to remove it. KFS 2003-09-03 */
24189 /* Finally perform built-in cursor blinking:
24190 filled box <-> hollow box
24191 wide [h]bar <-> narrow [h]bar
24192 narrow [h]bar <-> no cursor
24193 other type <-> no cursor */
24195 if (cursor_type
== FILLED_BOX_CURSOR
)
24196 return HOLLOW_BOX_CURSOR
;
24198 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
24201 return cursor_type
;
24209 /* Notice when the text cursor of window W has been completely
24210 overwritten by a drawing operation that outputs glyphs in AREA
24211 starting at X0 and ending at X1 in the line starting at Y0 and
24212 ending at Y1. X coordinates are area-relative. X1 < 0 means all
24213 the rest of the line after X0 has been written. Y coordinates
24214 are window-relative. */
24217 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
24218 int x0
, int x1
, int y0
, int y1
)
24220 int cx0
, cx1
, cy0
, cy1
;
24221 struct glyph_row
*row
;
24223 if (!w
->phys_cursor_on_p
)
24225 if (area
!= TEXT_AREA
)
24228 if (w
->phys_cursor
.vpos
< 0
24229 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
24230 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
24231 !(row
->enabled_p
&& row
->displays_text_p
)))
24234 if (row
->cursor_in_fringe_p
)
24236 row
->cursor_in_fringe_p
= 0;
24237 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
24238 w
->phys_cursor_on_p
= 0;
24242 cx0
= w
->phys_cursor
.x
;
24243 cx1
= cx0
+ w
->phys_cursor_width
;
24244 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
24247 /* The cursor image will be completely removed from the
24248 screen if the output area intersects the cursor area in
24249 y-direction. When we draw in [y0 y1[, and some part of
24250 the cursor is at y < y0, that part must have been drawn
24251 before. When scrolling, the cursor is erased before
24252 actually scrolling, so we don't come here. When not
24253 scrolling, the rows above the old cursor row must have
24254 changed, and in this case these rows must have written
24255 over the cursor image.
24257 Likewise if part of the cursor is below y1, with the
24258 exception of the cursor being in the first blank row at
24259 the buffer and window end because update_text_area
24260 doesn't draw that row. (Except when it does, but
24261 that's handled in update_text_area.) */
24263 cy0
= w
->phys_cursor
.y
;
24264 cy1
= cy0
+ w
->phys_cursor_height
;
24265 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
24268 w
->phys_cursor_on_p
= 0;
24271 #endif /* HAVE_WINDOW_SYSTEM */
24274 /************************************************************************
24276 ************************************************************************/
24278 #ifdef HAVE_WINDOW_SYSTEM
24281 Fix the display of area AREA of overlapping row ROW in window W
24282 with respect to the overlapping part OVERLAPS. */
24285 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
24286 enum glyph_row_area area
, int overlaps
)
24293 for (i
= 0; i
< row
->used
[area
];)
24295 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
24297 int start
= i
, start_x
= x
;
24301 x
+= row
->glyphs
[area
][i
].pixel_width
;
24304 while (i
< row
->used
[area
]
24305 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
24307 draw_glyphs (w
, start_x
, row
, area
,
24309 DRAW_NORMAL_TEXT
, overlaps
);
24313 x
+= row
->glyphs
[area
][i
].pixel_width
;
24323 Draw the cursor glyph of window W in glyph row ROW. See the
24324 comment of draw_glyphs for the meaning of HL. */
24327 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
24328 enum draw_glyphs_face hl
)
24330 /* If cursor hpos is out of bounds, don't draw garbage. This can
24331 happen in mini-buffer windows when switching between echo area
24332 glyphs and mini-buffer. */
24333 if ((row
->reversed_p
24334 ? (w
->phys_cursor
.hpos
>= 0)
24335 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
24337 int on_p
= w
->phys_cursor_on_p
;
24339 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
24340 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
24342 w
->phys_cursor_on_p
= on_p
;
24344 if (hl
== DRAW_CURSOR
)
24345 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
24346 /* When we erase the cursor, and ROW is overlapped by other
24347 rows, make sure that these overlapping parts of other rows
24349 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
24351 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
24353 if (row
> w
->current_matrix
->rows
24354 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
24355 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
24356 OVERLAPS_ERASED_CURSOR
);
24358 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
24359 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
24360 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
24361 OVERLAPS_ERASED_CURSOR
);
24368 Erase the image of a cursor of window W from the screen. */
24371 erase_phys_cursor (struct window
*w
)
24373 struct frame
*f
= XFRAME (w
->frame
);
24374 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
24375 int hpos
= w
->phys_cursor
.hpos
;
24376 int vpos
= w
->phys_cursor
.vpos
;
24377 int mouse_face_here_p
= 0;
24378 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
24379 struct glyph_row
*cursor_row
;
24380 struct glyph
*cursor_glyph
;
24381 enum draw_glyphs_face hl
;
24383 /* No cursor displayed or row invalidated => nothing to do on the
24385 if (w
->phys_cursor_type
== NO_CURSOR
)
24386 goto mark_cursor_off
;
24388 /* VPOS >= active_glyphs->nrows means that window has been resized.
24389 Don't bother to erase the cursor. */
24390 if (vpos
>= active_glyphs
->nrows
)
24391 goto mark_cursor_off
;
24393 /* If row containing cursor is marked invalid, there is nothing we
24395 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
24396 if (!cursor_row
->enabled_p
)
24397 goto mark_cursor_off
;
24399 /* If line spacing is > 0, old cursor may only be partially visible in
24400 window after split-window. So adjust visible height. */
24401 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
24402 window_text_bottom_y (w
) - cursor_row
->y
);
24404 /* If row is completely invisible, don't attempt to delete a cursor which
24405 isn't there. This can happen if cursor is at top of a window, and
24406 we switch to a buffer with a header line in that window. */
24407 if (cursor_row
->visible_height
<= 0)
24408 goto mark_cursor_off
;
24410 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
24411 if (cursor_row
->cursor_in_fringe_p
)
24413 cursor_row
->cursor_in_fringe_p
= 0;
24414 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
24415 goto mark_cursor_off
;
24418 /* This can happen when the new row is shorter than the old one.
24419 In this case, either draw_glyphs or clear_end_of_line
24420 should have cleared the cursor. Note that we wouldn't be
24421 able to erase the cursor in this case because we don't have a
24422 cursor glyph at hand. */
24423 if ((cursor_row
->reversed_p
24424 ? (w
->phys_cursor
.hpos
< 0)
24425 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
24426 goto mark_cursor_off
;
24428 /* If the cursor is in the mouse face area, redisplay that when
24429 we clear the cursor. */
24430 if (! NILP (hlinfo
->mouse_face_window
)
24431 && coords_in_mouse_face_p (w
, hpos
, vpos
)
24432 /* Don't redraw the cursor's spot in mouse face if it is at the
24433 end of a line (on a newline). The cursor appears there, but
24434 mouse highlighting does not. */
24435 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
24436 mouse_face_here_p
= 1;
24438 /* Maybe clear the display under the cursor. */
24439 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
24442 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
24445 cursor_glyph
= get_phys_cursor_glyph (w
);
24446 if (cursor_glyph
== NULL
)
24447 goto mark_cursor_off
;
24449 width
= cursor_glyph
->pixel_width
;
24450 left_x
= window_box_left_offset (w
, TEXT_AREA
);
24451 x
= w
->phys_cursor
.x
;
24453 width
-= left_x
- x
;
24454 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
24455 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
24456 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
24459 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
24462 /* Erase the cursor by redrawing the character underneath it. */
24463 if (mouse_face_here_p
)
24464 hl
= DRAW_MOUSE_FACE
;
24466 hl
= DRAW_NORMAL_TEXT
;
24467 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
24470 w
->phys_cursor_on_p
= 0;
24471 w
->phys_cursor_type
= NO_CURSOR
;
24476 Display or clear cursor of window W. If ON is zero, clear the
24477 cursor. If it is non-zero, display the cursor. If ON is nonzero,
24478 where to put the cursor is specified by HPOS, VPOS, X and Y. */
24481 display_and_set_cursor (struct window
*w
, int on
,
24482 int hpos
, int vpos
, int x
, int y
)
24484 struct frame
*f
= XFRAME (w
->frame
);
24485 int new_cursor_type
;
24486 int new_cursor_width
;
24488 struct glyph_row
*glyph_row
;
24489 struct glyph
*glyph
;
24491 /* This is pointless on invisible frames, and dangerous on garbaged
24492 windows and frames; in the latter case, the frame or window may
24493 be in the midst of changing its size, and x and y may be off the
24495 if (! FRAME_VISIBLE_P (f
)
24496 || FRAME_GARBAGED_P (f
)
24497 || vpos
>= w
->current_matrix
->nrows
24498 || hpos
>= w
->current_matrix
->matrix_w
)
24501 /* If cursor is off and we want it off, return quickly. */
24502 if (!on
&& !w
->phys_cursor_on_p
)
24505 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
24506 /* If cursor row is not enabled, we don't really know where to
24507 display the cursor. */
24508 if (!glyph_row
->enabled_p
)
24510 w
->phys_cursor_on_p
= 0;
24515 if (!glyph_row
->exact_window_width_line_p
24516 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
24517 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
24519 xassert (interrupt_input_blocked
);
24521 /* Set new_cursor_type to the cursor we want to be displayed. */
24522 new_cursor_type
= get_window_cursor_type (w
, glyph
,
24523 &new_cursor_width
, &active_cursor
);
24525 /* If cursor is currently being shown and we don't want it to be or
24526 it is in the wrong place, or the cursor type is not what we want,
24528 if (w
->phys_cursor_on_p
24530 || w
->phys_cursor
.x
!= x
24531 || w
->phys_cursor
.y
!= y
24532 || new_cursor_type
!= w
->phys_cursor_type
24533 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
24534 && new_cursor_width
!= w
->phys_cursor_width
)))
24535 erase_phys_cursor (w
);
24537 /* Don't check phys_cursor_on_p here because that flag is only set
24538 to zero in some cases where we know that the cursor has been
24539 completely erased, to avoid the extra work of erasing the cursor
24540 twice. In other words, phys_cursor_on_p can be 1 and the cursor
24541 still not be visible, or it has only been partly erased. */
24544 w
->phys_cursor_ascent
= glyph_row
->ascent
;
24545 w
->phys_cursor_height
= glyph_row
->height
;
24547 /* Set phys_cursor_.* before x_draw_.* is called because some
24548 of them may need the information. */
24549 w
->phys_cursor
.x
= x
;
24550 w
->phys_cursor
.y
= glyph_row
->y
;
24551 w
->phys_cursor
.hpos
= hpos
;
24552 w
->phys_cursor
.vpos
= vpos
;
24555 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
24556 new_cursor_type
, new_cursor_width
,
24557 on
, active_cursor
);
24561 /* Switch the display of W's cursor on or off, according to the value
24565 update_window_cursor (struct window
*w
, int on
)
24567 /* Don't update cursor in windows whose frame is in the process
24568 of being deleted. */
24569 if (w
->current_matrix
)
24572 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24573 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24579 /* Call update_window_cursor with parameter ON_P on all leaf windows
24580 in the window tree rooted at W. */
24583 update_cursor_in_window_tree (struct window
*w
, int on_p
)
24587 if (!NILP (w
->hchild
))
24588 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
24589 else if (!NILP (w
->vchild
))
24590 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
24592 update_window_cursor (w
, on_p
);
24594 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
24600 Display the cursor on window W, or clear it, according to ON_P.
24601 Don't change the cursor's position. */
24604 x_update_cursor (struct frame
*f
, int on_p
)
24606 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
24611 Clear the cursor of window W to background color, and mark the
24612 cursor as not shown. This is used when the text where the cursor
24613 is about to be rewritten. */
24616 x_clear_cursor (struct window
*w
)
24618 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
24619 update_window_cursor (w
, 0);
24622 #endif /* HAVE_WINDOW_SYSTEM */
24624 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
24627 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
24628 int start_hpos
, int end_hpos
,
24629 enum draw_glyphs_face draw
)
24631 #ifdef HAVE_WINDOW_SYSTEM
24632 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
24634 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
24638 #if defined (HAVE_GPM) || defined (MSDOS)
24639 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
24643 /* Display the active region described by mouse_face_* according to DRAW. */
24646 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
24648 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
24649 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24651 if (/* If window is in the process of being destroyed, don't bother
24653 w
->current_matrix
!= NULL
24654 /* Don't update mouse highlight if hidden */
24655 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
24656 /* Recognize when we are called to operate on rows that don't exist
24657 anymore. This can happen when a window is split. */
24658 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
24660 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
24661 struct glyph_row
*row
, *first
, *last
;
24663 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
24664 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
24666 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
24668 int start_hpos
, end_hpos
, start_x
;
24670 /* For all but the first row, the highlight starts at column 0. */
24673 /* R2L rows have BEG and END in reversed order, but the
24674 screen drawing geometry is always left to right. So
24675 we need to mirror the beginning and end of the
24676 highlighted area in R2L rows. */
24677 if (!row
->reversed_p
)
24679 start_hpos
= hlinfo
->mouse_face_beg_col
;
24680 start_x
= hlinfo
->mouse_face_beg_x
;
24682 else if (row
== last
)
24684 start_hpos
= hlinfo
->mouse_face_end_col
;
24685 start_x
= hlinfo
->mouse_face_end_x
;
24693 else if (row
->reversed_p
&& row
== last
)
24695 start_hpos
= hlinfo
->mouse_face_end_col
;
24696 start_x
= hlinfo
->mouse_face_end_x
;
24706 if (!row
->reversed_p
)
24707 end_hpos
= hlinfo
->mouse_face_end_col
;
24708 else if (row
== first
)
24709 end_hpos
= hlinfo
->mouse_face_beg_col
;
24712 end_hpos
= row
->used
[TEXT_AREA
];
24713 if (draw
== DRAW_NORMAL_TEXT
)
24714 row
->fill_line_p
= 1; /* Clear to end of line */
24717 else if (row
->reversed_p
&& row
== first
)
24718 end_hpos
= hlinfo
->mouse_face_beg_col
;
24721 end_hpos
= row
->used
[TEXT_AREA
];
24722 if (draw
== DRAW_NORMAL_TEXT
)
24723 row
->fill_line_p
= 1; /* Clear to end of line */
24726 if (end_hpos
> start_hpos
)
24728 draw_row_with_mouse_face (w
, start_x
, row
,
24729 start_hpos
, end_hpos
, draw
);
24732 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
24736 #ifdef HAVE_WINDOW_SYSTEM
24737 /* When we've written over the cursor, arrange for it to
24738 be displayed again. */
24739 if (FRAME_WINDOW_P (f
)
24740 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
24743 display_and_set_cursor (w
, 1,
24744 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24745 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24748 #endif /* HAVE_WINDOW_SYSTEM */
24751 #ifdef HAVE_WINDOW_SYSTEM
24752 /* Change the mouse cursor. */
24753 if (FRAME_WINDOW_P (f
))
24755 if (draw
== DRAW_NORMAL_TEXT
24756 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
24757 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
24758 else if (draw
== DRAW_MOUSE_FACE
)
24759 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
24761 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
24763 #endif /* HAVE_WINDOW_SYSTEM */
24767 Clear out the mouse-highlighted active region.
24768 Redraw it un-highlighted first. Value is non-zero if mouse
24769 face was actually drawn unhighlighted. */
24772 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
24776 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
24778 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
24782 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
24783 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
24784 hlinfo
->mouse_face_window
= Qnil
;
24785 hlinfo
->mouse_face_overlay
= Qnil
;
24789 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
24790 within the mouse face on that window. */
24792 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
24794 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
24796 /* Quickly resolve the easy cases. */
24797 if (!(WINDOWP (hlinfo
->mouse_face_window
)
24798 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
24800 if (vpos
< hlinfo
->mouse_face_beg_row
24801 || vpos
> hlinfo
->mouse_face_end_row
)
24803 if (vpos
> hlinfo
->mouse_face_beg_row
24804 && vpos
< hlinfo
->mouse_face_end_row
)
24807 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
24809 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24811 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
24814 else if ((vpos
== hlinfo
->mouse_face_beg_row
24815 && hpos
>= hlinfo
->mouse_face_beg_col
)
24816 || (vpos
== hlinfo
->mouse_face_end_row
24817 && hpos
< hlinfo
->mouse_face_end_col
))
24822 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24824 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
24827 else if ((vpos
== hlinfo
->mouse_face_beg_row
24828 && hpos
<= hlinfo
->mouse_face_beg_col
)
24829 || (vpos
== hlinfo
->mouse_face_end_row
24830 && hpos
> hlinfo
->mouse_face_end_col
))
24838 Non-zero if physical cursor of window W is within mouse face. */
24841 cursor_in_mouse_face_p (struct window
*w
)
24843 return coords_in_mouse_face_p (w
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
);
24848 /* Find the glyph rows START_ROW and END_ROW of window W that display
24849 characters between buffer positions START_CHARPOS and END_CHARPOS
24850 (excluding END_CHARPOS). This is similar to row_containing_pos,
24851 but is more accurate when bidi reordering makes buffer positions
24852 change non-linearly with glyph rows. */
24854 rows_from_pos_range (struct window
*w
,
24855 EMACS_INT start_charpos
, EMACS_INT end_charpos
,
24856 struct glyph_row
**start
, struct glyph_row
**end
)
24858 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24859 int last_y
= window_text_bottom_y (w
);
24860 struct glyph_row
*row
;
24865 while (!first
->enabled_p
24866 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
24869 /* Find the START row. */
24871 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
24874 /* A row can potentially be the START row if the range of the
24875 characters it displays intersects the range
24876 [START_CHARPOS..END_CHARPOS). */
24877 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
24878 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
24879 /* See the commentary in row_containing_pos, for the
24880 explanation of the complicated way to check whether
24881 some position is beyond the end of the characters
24882 displayed by a row. */
24883 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24884 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24885 && !row
->ends_at_zv_p
24886 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
24887 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24888 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24889 && !row
->ends_at_zv_p
24890 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
24892 /* Found a candidate row. Now make sure at least one of the
24893 glyphs it displays has a charpos from the range
24894 [START_CHARPOS..END_CHARPOS).
24896 This is not obvious because bidi reordering could make
24897 buffer positions of a row be 1,2,3,102,101,100, and if we
24898 want to highlight characters in [50..60), we don't want
24899 this row, even though [50..60) does intersect [1..103),
24900 the range of character positions given by the row's start
24901 and end positions. */
24902 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
24903 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
24907 if (BUFFERP (g
->object
)
24908 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24917 /* Find the END row. */
24919 /* If the last row is partially visible, start looking for END
24920 from that row, instead of starting from FIRST. */
24921 && !(row
->enabled_p
24922 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
24924 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
24926 struct glyph_row
*next
= row
+ 1;
24928 if (!next
->enabled_p
24929 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
24930 /* The first row >= START whose range of displayed characters
24931 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
24932 is the row END + 1. */
24933 || (start_charpos
< MATRIX_ROW_START_CHARPOS (next
)
24934 && end_charpos
< MATRIX_ROW_START_CHARPOS (next
))
24935 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24936 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24937 && !next
->ends_at_zv_p
24938 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
24939 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24940 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24941 && !next
->ends_at_zv_p
24942 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
24949 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
24950 but none of the characters it displays are in the range, it is
24952 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
24953 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
24957 if (BUFFERP (g
->object
)
24958 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24971 /* This function sets the mouse_face_* elements of HLINFO, assuming
24972 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
24973 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
24974 for the overlay or run of text properties specifying the mouse
24975 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
24976 before-string and after-string that must also be highlighted.
24977 COVER_STRING, if non-nil, is a display string that may cover some
24978 or all of the highlighted text. */
24981 mouse_face_from_buffer_pos (Lisp_Object window
,
24982 Mouse_HLInfo
*hlinfo
,
24983 EMACS_INT mouse_charpos
,
24984 EMACS_INT start_charpos
,
24985 EMACS_INT end_charpos
,
24986 Lisp_Object before_string
,
24987 Lisp_Object after_string
,
24988 Lisp_Object cover_string
)
24990 struct window
*w
= XWINDOW (window
);
24991 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24992 struct glyph_row
*r1
, *r2
;
24993 struct glyph
*glyph
, *end
;
24994 EMACS_INT ignore
, pos
;
24997 xassert (NILP (cover_string
) || STRINGP (cover_string
));
24998 xassert (NILP (before_string
) || STRINGP (before_string
));
24999 xassert (NILP (after_string
) || STRINGP (after_string
));
25001 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
25002 rows_from_pos_range (w
, start_charpos
, end_charpos
, &r1
, &r2
);
25004 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
25005 /* If the before-string or display-string contains newlines,
25006 rows_from_pos_range skips to its last row. Move back. */
25007 if (!NILP (before_string
) || !NILP (cover_string
))
25009 struct glyph_row
*prev
;
25010 while ((prev
= r1
- 1, prev
>= first
)
25011 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
25012 && prev
->used
[TEXT_AREA
] > 0)
25014 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
25015 glyph
= beg
+ prev
->used
[TEXT_AREA
];
25016 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
25018 || !(EQ (glyph
->object
, before_string
)
25019 || EQ (glyph
->object
, cover_string
)))
25026 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
25027 hlinfo
->mouse_face_past_end
= 1;
25029 else if (!NILP (after_string
))
25031 /* If the after-string has newlines, advance to its last row. */
25032 struct glyph_row
*next
;
25033 struct glyph_row
*last
25034 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
25036 for (next
= r2
+ 1;
25038 && next
->used
[TEXT_AREA
] > 0
25039 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
25043 /* The rest of the display engine assumes that mouse_face_beg_row is
25044 either above below mouse_face_end_row or identical to it. But
25045 with bidi-reordered continued lines, the row for START_CHARPOS
25046 could be below the row for END_CHARPOS. If so, swap the rows and
25047 store them in correct order. */
25050 struct glyph_row
*tem
= r2
;
25056 hlinfo
->mouse_face_beg_y
= r1
->y
;
25057 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
25058 hlinfo
->mouse_face_end_y
= r2
->y
;
25059 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
25061 /* For a bidi-reordered row, the positions of BEFORE_STRING,
25062 AFTER_STRING, COVER_STRING, START_CHARPOS, and END_CHARPOS
25063 could be anywhere in the row and in any order. The strategy
25064 below is to find the leftmost and the rightmost glyph that
25065 belongs to either of these 3 strings, or whose position is
25066 between START_CHARPOS and END_CHARPOS, and highlight all the
25067 glyphs between those two. This may cover more than just the text
25068 between START_CHARPOS and END_CHARPOS if the range of characters
25069 strides the bidi level boundary, e.g. if the beginning is in R2L
25070 text while the end is in L2R text or vice versa. */
25071 if (!r1
->reversed_p
)
25073 /* This row is in a left to right paragraph. Scan it left to
25075 glyph
= r1
->glyphs
[TEXT_AREA
];
25076 end
= glyph
+ r1
->used
[TEXT_AREA
];
25079 /* Skip truncation glyphs at the start of the glyph row. */
25080 if (r1
->displays_text_p
)
25082 && INTEGERP (glyph
->object
)
25083 && glyph
->charpos
< 0;
25085 x
+= glyph
->pixel_width
;
25087 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
25088 or COVER_STRING, and the first glyph from buffer whose
25089 position is between START_CHARPOS and END_CHARPOS. */
25091 && !INTEGERP (glyph
->object
)
25092 && !EQ (glyph
->object
, cover_string
)
25093 && !(BUFFERP (glyph
->object
)
25094 && (glyph
->charpos
>= start_charpos
25095 && glyph
->charpos
< end_charpos
));
25098 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25099 are present at buffer positions between START_CHARPOS and
25100 END_CHARPOS, or if they come from an overlay. */
25101 if (EQ (glyph
->object
, before_string
))
25103 pos
= string_buffer_position (before_string
,
25105 /* If pos == 0, it means before_string came from an
25106 overlay, not from a buffer position. */
25107 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25110 else if (EQ (glyph
->object
, after_string
))
25112 pos
= string_buffer_position (after_string
, end_charpos
);
25113 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25116 x
+= glyph
->pixel_width
;
25118 hlinfo
->mouse_face_beg_x
= x
;
25119 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
25123 /* This row is in a right to left paragraph. Scan it right to
25127 end
= r1
->glyphs
[TEXT_AREA
] - 1;
25128 glyph
= end
+ r1
->used
[TEXT_AREA
];
25130 /* Skip truncation glyphs at the start of the glyph row. */
25131 if (r1
->displays_text_p
)
25133 && INTEGERP (glyph
->object
)
25134 && glyph
->charpos
< 0;
25138 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
25139 or COVER_STRING, and the first glyph from buffer whose
25140 position is between START_CHARPOS and END_CHARPOS. */
25142 && !INTEGERP (glyph
->object
)
25143 && !EQ (glyph
->object
, cover_string
)
25144 && !(BUFFERP (glyph
->object
)
25145 && (glyph
->charpos
>= start_charpos
25146 && glyph
->charpos
< end_charpos
));
25149 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25150 are present at buffer positions between START_CHARPOS and
25151 END_CHARPOS, or if they come from an overlay. */
25152 if (EQ (glyph
->object
, before_string
))
25154 pos
= string_buffer_position (before_string
, start_charpos
);
25155 /* If pos == 0, it means before_string came from an
25156 overlay, not from a buffer position. */
25157 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25160 else if (EQ (glyph
->object
, after_string
))
25162 pos
= string_buffer_position (after_string
, end_charpos
);
25163 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25168 glyph
++; /* first glyph to the right of the highlighted area */
25169 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
25170 x
+= g
->pixel_width
;
25171 hlinfo
->mouse_face_beg_x
= x
;
25172 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
25175 /* If the highlight ends in a different row, compute GLYPH and END
25176 for the end row. Otherwise, reuse the values computed above for
25177 the row where the highlight begins. */
25180 if (!r2
->reversed_p
)
25182 glyph
= r2
->glyphs
[TEXT_AREA
];
25183 end
= glyph
+ r2
->used
[TEXT_AREA
];
25188 end
= r2
->glyphs
[TEXT_AREA
] - 1;
25189 glyph
= end
+ r2
->used
[TEXT_AREA
];
25193 if (!r2
->reversed_p
)
25195 /* Skip truncation and continuation glyphs near the end of the
25196 row, and also blanks and stretch glyphs inserted by
25197 extend_face_to_end_of_line. */
25199 && INTEGERP ((end
- 1)->object
)
25200 && (end
- 1)->charpos
<= 0)
25202 /* Scan the rest of the glyph row from the end, looking for the
25203 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
25204 COVER_STRING, or whose position is between START_CHARPOS
25208 && !INTEGERP (end
->object
)
25209 && !EQ (end
->object
, cover_string
)
25210 && !(BUFFERP (end
->object
)
25211 && (end
->charpos
>= start_charpos
25212 && end
->charpos
< end_charpos
));
25215 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25216 are present at buffer positions between START_CHARPOS and
25217 END_CHARPOS, or if they come from an overlay. */
25218 if (EQ (end
->object
, before_string
))
25220 pos
= string_buffer_position (before_string
, start_charpos
);
25221 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25224 else if (EQ (end
->object
, after_string
))
25226 pos
= string_buffer_position (after_string
, end_charpos
);
25227 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25231 /* Find the X coordinate of the last glyph to be highlighted. */
25232 for (; glyph
<= end
; ++glyph
)
25233 x
+= glyph
->pixel_width
;
25235 hlinfo
->mouse_face_end_x
= x
;
25236 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
25240 /* Skip truncation and continuation glyphs near the end of the
25241 row, and also blanks and stretch glyphs inserted by
25242 extend_face_to_end_of_line. */
25246 && INTEGERP (end
->object
)
25247 && end
->charpos
<= 0)
25249 x
+= end
->pixel_width
;
25252 /* Scan the rest of the glyph row from the end, looking for the
25253 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
25254 COVER_STRING, or whose position is between START_CHARPOS
25258 && !INTEGERP (end
->object
)
25259 && !EQ (end
->object
, cover_string
)
25260 && !(BUFFERP (end
->object
)
25261 && (end
->charpos
>= start_charpos
25262 && end
->charpos
< end_charpos
));
25265 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25266 are present at buffer positions between START_CHARPOS and
25267 END_CHARPOS, or if they come from an overlay. */
25268 if (EQ (end
->object
, before_string
))
25270 pos
= string_buffer_position (before_string
, start_charpos
);
25271 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25274 else if (EQ (end
->object
, after_string
))
25276 pos
= string_buffer_position (after_string
, end_charpos
);
25277 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25280 x
+= end
->pixel_width
;
25282 hlinfo
->mouse_face_end_x
= x
;
25283 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
25286 hlinfo
->mouse_face_window
= window
;
25287 hlinfo
->mouse_face_face_id
25288 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
25290 !hlinfo
->mouse_face_hidden
, -1);
25291 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25294 /* The following function is not used anymore (replaced with
25295 mouse_face_from_string_pos), but I leave it here for the time
25296 being, in case someone would. */
25298 #if 0 /* not used */
25300 /* Find the position of the glyph for position POS in OBJECT in
25301 window W's current matrix, and return in *X, *Y the pixel
25302 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
25304 RIGHT_P non-zero means return the position of the right edge of the
25305 glyph, RIGHT_P zero means return the left edge position.
25307 If no glyph for POS exists in the matrix, return the position of
25308 the glyph with the next smaller position that is in the matrix, if
25309 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
25310 exists in the matrix, return the position of the glyph with the
25311 next larger position in OBJECT.
25313 Value is non-zero if a glyph was found. */
25316 fast_find_string_pos (struct window
*w
, EMACS_INT pos
, Lisp_Object object
,
25317 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
25319 int yb
= window_text_bottom_y (w
);
25320 struct glyph_row
*r
;
25321 struct glyph
*best_glyph
= NULL
;
25322 struct glyph_row
*best_row
= NULL
;
25325 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25326 r
->enabled_p
&& r
->y
< yb
;
25329 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
25330 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
25333 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
25334 if (EQ (g
->object
, object
))
25336 if (g
->charpos
== pos
)
25343 else if (best_glyph
== NULL
25344 || ((eabs (g
->charpos
- pos
)
25345 < eabs (best_glyph
->charpos
- pos
))
25348 : g
->charpos
> pos
)))
25362 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
25366 *x
+= best_glyph
->pixel_width
;
25371 *vpos
= best_row
- w
->current_matrix
->rows
;
25374 return best_glyph
!= NULL
;
25376 #endif /* not used */
25378 /* Find the positions of the first and the last glyphs in window W's
25379 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
25380 (assumed to be a string), and return in HLINFO's mouse_face_*
25381 members the pixel and column/row coordinates of those glyphs. */
25384 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
25385 Lisp_Object object
,
25386 EMACS_INT startpos
, EMACS_INT endpos
)
25388 int yb
= window_text_bottom_y (w
);
25389 struct glyph_row
*r
;
25390 struct glyph
*g
, *e
;
25394 /* Find the glyph row with at least one position in the range
25395 [STARTPOS..ENDPOS], and the first glyph in that row whose
25396 position belongs to that range. */
25397 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25398 r
->enabled_p
&& r
->y
< yb
;
25401 if (!r
->reversed_p
)
25403 g
= r
->glyphs
[TEXT_AREA
];
25404 e
= g
+ r
->used
[TEXT_AREA
];
25405 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
25406 if (EQ (g
->object
, object
)
25407 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
25409 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
25410 hlinfo
->mouse_face_beg_y
= r
->y
;
25411 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
25412 hlinfo
->mouse_face_beg_x
= gx
;
25421 e
= r
->glyphs
[TEXT_AREA
];
25422 g
= e
+ r
->used
[TEXT_AREA
];
25423 for ( ; g
> e
; --g
)
25424 if (EQ ((g
-1)->object
, object
)
25425 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
25427 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
25428 hlinfo
->mouse_face_beg_y
= r
->y
;
25429 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
25430 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
25431 gx
+= g1
->pixel_width
;
25432 hlinfo
->mouse_face_beg_x
= gx
;
25444 /* Starting with the next row, look for the first row which does NOT
25445 include any glyphs whose positions are in the range. */
25446 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
25448 g
= r
->glyphs
[TEXT_AREA
];
25449 e
= g
+ r
->used
[TEXT_AREA
];
25451 for ( ; g
< e
; ++g
)
25452 if (EQ (g
->object
, object
)
25453 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
25462 /* The highlighted region ends on the previous row. */
25465 /* Set the end row and its vertical pixel coordinate. */
25466 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
25467 hlinfo
->mouse_face_end_y
= r
->y
;
25469 /* Compute and set the end column and the end column's horizontal
25470 pixel coordinate. */
25471 if (!r
->reversed_p
)
25473 g
= r
->glyphs
[TEXT_AREA
];
25474 e
= g
+ r
->used
[TEXT_AREA
];
25475 for ( ; e
> g
; --e
)
25476 if (EQ ((e
-1)->object
, object
)
25477 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
25479 hlinfo
->mouse_face_end_col
= e
- g
;
25481 for (gx
= r
->x
; g
< e
; ++g
)
25482 gx
+= g
->pixel_width
;
25483 hlinfo
->mouse_face_end_x
= gx
;
25487 e
= r
->glyphs
[TEXT_AREA
];
25488 g
= e
+ r
->used
[TEXT_AREA
];
25489 for (gx
= r
->x
; e
< g
; ++e
)
25491 if (EQ (e
->object
, object
)
25492 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
25494 gx
+= e
->pixel_width
;
25496 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
25497 hlinfo
->mouse_face_end_x
= gx
;
25501 #ifdef HAVE_WINDOW_SYSTEM
25503 /* See if position X, Y is within a hot-spot of an image. */
25506 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
25508 if (!CONSP (hot_spot
))
25511 if (EQ (XCAR (hot_spot
), Qrect
))
25513 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
25514 Lisp_Object rect
= XCDR (hot_spot
);
25518 if (!CONSP (XCAR (rect
)))
25520 if (!CONSP (XCDR (rect
)))
25522 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
25524 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
25526 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
25528 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
25532 else if (EQ (XCAR (hot_spot
), Qcircle
))
25534 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
25535 Lisp_Object circ
= XCDR (hot_spot
);
25536 Lisp_Object lr
, lx0
, ly0
;
25538 && CONSP (XCAR (circ
))
25539 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
25540 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
25541 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
25543 double r
= XFLOATINT (lr
);
25544 double dx
= XINT (lx0
) - x
;
25545 double dy
= XINT (ly0
) - y
;
25546 return (dx
* dx
+ dy
* dy
<= r
* r
);
25549 else if (EQ (XCAR (hot_spot
), Qpoly
))
25551 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
25552 if (VECTORP (XCDR (hot_spot
)))
25554 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
25555 Lisp_Object
*poly
= v
->contents
;
25556 int n
= v
->header
.size
;
25559 Lisp_Object lx
, ly
;
25562 /* Need an even number of coordinates, and at least 3 edges. */
25563 if (n
< 6 || n
& 1)
25566 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
25567 If count is odd, we are inside polygon. Pixels on edges
25568 may or may not be included depending on actual geometry of the
25570 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
25571 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
25573 x0
= XINT (lx
), y0
= XINT (ly
);
25574 for (i
= 0; i
< n
; i
+= 2)
25576 int x1
= x0
, y1
= y0
;
25577 if ((lx
= poly
[i
], !INTEGERP (lx
))
25578 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
25580 x0
= XINT (lx
), y0
= XINT (ly
);
25582 /* Does this segment cross the X line? */
25590 if (y
> y0
&& y
> y1
)
25592 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
25602 find_hot_spot (Lisp_Object map
, int x
, int y
)
25604 while (CONSP (map
))
25606 if (CONSP (XCAR (map
))
25607 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
25615 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
25617 doc
: /* Lookup in image map MAP coordinates X and Y.
25618 An image map is an alist where each element has the format (AREA ID PLIST).
25619 An AREA is specified as either a rectangle, a circle, or a polygon:
25620 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
25621 pixel coordinates of the upper left and bottom right corners.
25622 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
25623 and the radius of the circle; r may be a float or integer.
25624 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
25625 vector describes one corner in the polygon.
25626 Returns the alist element for the first matching AREA in MAP. */)
25627 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
25635 return find_hot_spot (map
, XINT (x
), XINT (y
));
25639 /* Display frame CURSOR, optionally using shape defined by POINTER. */
25641 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
25643 /* Do not change cursor shape while dragging mouse. */
25644 if (!NILP (do_mouse_tracking
))
25647 if (!NILP (pointer
))
25649 if (EQ (pointer
, Qarrow
))
25650 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25651 else if (EQ (pointer
, Qhand
))
25652 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
25653 else if (EQ (pointer
, Qtext
))
25654 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25655 else if (EQ (pointer
, intern ("hdrag")))
25656 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25657 #ifdef HAVE_X_WINDOWS
25658 else if (EQ (pointer
, intern ("vdrag")))
25659 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
25661 else if (EQ (pointer
, intern ("hourglass")))
25662 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
25663 else if (EQ (pointer
, Qmodeline
))
25664 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
25666 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25669 if (cursor
!= No_Cursor
)
25670 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
25673 #endif /* HAVE_WINDOW_SYSTEM */
25675 /* Take proper action when mouse has moved to the mode or header line
25676 or marginal area AREA of window W, x-position X and y-position Y.
25677 X is relative to the start of the text display area of W, so the
25678 width of bitmap areas and scroll bars must be subtracted to get a
25679 position relative to the start of the mode line. */
25682 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
25683 enum window_part area
)
25685 struct window
*w
= XWINDOW (window
);
25686 struct frame
*f
= XFRAME (w
->frame
);
25687 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25688 #ifdef HAVE_WINDOW_SYSTEM
25689 Display_Info
*dpyinfo
;
25691 Cursor cursor
= No_Cursor
;
25692 Lisp_Object pointer
= Qnil
;
25693 int dx
, dy
, width
, height
;
25695 Lisp_Object string
, object
= Qnil
;
25696 Lisp_Object pos
, help
;
25698 Lisp_Object mouse_face
;
25699 int original_x_pixel
= x
;
25700 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
25701 struct glyph_row
*row
;
25703 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
25708 /* Kludge alert: mode_line_string takes X/Y in pixels, but
25709 returns them in row/column units! */
25710 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
25711 &object
, &dx
, &dy
, &width
, &height
);
25713 row
= (area
== ON_MODE_LINE
25714 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
25715 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
25717 /* Find the glyph under the mouse pointer. */
25718 if (row
->mode_line_p
&& row
->enabled_p
)
25720 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
25721 end
= glyph
+ row
->used
[TEXT_AREA
];
25723 for (x0
= original_x_pixel
;
25724 glyph
< end
&& x0
>= glyph
->pixel_width
;
25726 x0
-= glyph
->pixel_width
;
25734 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
25735 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
25736 returns them in row/column units! */
25737 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
25738 &object
, &dx
, &dy
, &width
, &height
);
25743 #ifdef HAVE_WINDOW_SYSTEM
25744 if (IMAGEP (object
))
25746 Lisp_Object image_map
, hotspot
;
25747 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
25749 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
25751 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25755 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
25756 If so, we could look for mouse-enter, mouse-leave
25757 properties in PLIST (and do something...). */
25758 hotspot
= XCDR (hotspot
);
25759 if (CONSP (hotspot
)
25760 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25762 pointer
= Fplist_get (plist
, Qpointer
);
25763 if (NILP (pointer
))
25765 help
= Fplist_get (plist
, Qhelp_echo
);
25768 help_echo_string
= help
;
25769 /* Is this correct? ++kfs */
25770 XSETWINDOW (help_echo_window
, w
);
25771 help_echo_object
= w
->buffer
;
25772 help_echo_pos
= charpos
;
25776 if (NILP (pointer
))
25777 pointer
= Fplist_get (XCDR (object
), QCpointer
);
25779 #endif /* HAVE_WINDOW_SYSTEM */
25781 if (STRINGP (string
))
25783 pos
= make_number (charpos
);
25784 /* If we're on a string with `help-echo' text property, arrange
25785 for the help to be displayed. This is done by setting the
25786 global variable help_echo_string to the help string. */
25789 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
25792 help_echo_string
= help
;
25793 XSETWINDOW (help_echo_window
, w
);
25794 help_echo_object
= string
;
25795 help_echo_pos
= charpos
;
25799 #ifdef HAVE_WINDOW_SYSTEM
25800 if (FRAME_WINDOW_P (f
))
25802 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25803 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25804 if (NILP (pointer
))
25805 pointer
= Fget_text_property (pos
, Qpointer
, string
);
25807 /* Change the mouse pointer according to what is under X/Y. */
25809 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
25812 map
= Fget_text_property (pos
, Qlocal_map
, string
);
25813 if (!KEYMAPP (map
))
25814 map
= Fget_text_property (pos
, Qkeymap
, string
);
25815 if (!KEYMAPP (map
))
25816 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
25821 /* Change the mouse face according to what is under X/Y. */
25822 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
25823 if (!NILP (mouse_face
)
25824 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25829 struct glyph
* tmp_glyph
;
25833 int total_pixel_width
;
25834 EMACS_INT begpos
, endpos
, ignore
;
25838 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
25839 Qmouse_face
, string
, Qnil
);
25845 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
25847 endpos
= SCHARS (string
);
25851 /* Calculate the glyph position GPOS of GLYPH in the
25852 displayed string, relative to the beginning of the
25853 highlighted part of the string.
25855 Note: GPOS is different from CHARPOS. CHARPOS is the
25856 position of GLYPH in the internal string object. A mode
25857 line string format has structures which are converted to
25858 a flattened string by the Emacs Lisp interpreter. The
25859 internal string is an element of those structures. The
25860 displayed string is the flattened string. */
25861 tmp_glyph
= row_start_glyph
;
25862 while (tmp_glyph
< glyph
25863 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25864 && begpos
<= tmp_glyph
->charpos
25865 && tmp_glyph
->charpos
< endpos
)))
25867 gpos
= glyph
- tmp_glyph
;
25869 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
25870 the highlighted part of the displayed string to which
25871 GLYPH belongs. Note: GSEQ_LENGTH is different from
25872 SCHARS (STRING), because the latter returns the length of
25873 the internal string. */
25874 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
25876 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25877 && begpos
<= tmp_glyph
->charpos
25878 && tmp_glyph
->charpos
< endpos
));
25881 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
25883 /* Calculate the total pixel width of all the glyphs between
25884 the beginning of the highlighted area and GLYPH. */
25885 total_pixel_width
= 0;
25886 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
25887 total_pixel_width
+= tmp_glyph
->pixel_width
;
25889 /* Pre calculation of re-rendering position. Note: X is in
25890 column units here, after the call to mode_line_string or
25891 marginal_area_string. */
25893 vpos
= (area
== ON_MODE_LINE
25894 ? (w
->current_matrix
)->nrows
- 1
25897 /* If GLYPH's position is included in the region that is
25898 already drawn in mouse face, we have nothing to do. */
25899 if ( EQ (window
, hlinfo
->mouse_face_window
)
25900 && (!row
->reversed_p
25901 ? (hlinfo
->mouse_face_beg_col
<= hpos
25902 && hpos
< hlinfo
->mouse_face_end_col
)
25903 /* In R2L rows we swap BEG and END, see below. */
25904 : (hlinfo
->mouse_face_end_col
<= hpos
25905 && hpos
< hlinfo
->mouse_face_beg_col
))
25906 && hlinfo
->mouse_face_beg_row
== vpos
)
25909 if (clear_mouse_face (hlinfo
))
25910 cursor
= No_Cursor
;
25912 if (!row
->reversed_p
)
25914 hlinfo
->mouse_face_beg_col
= hpos
;
25915 hlinfo
->mouse_face_beg_x
= original_x_pixel
25916 - (total_pixel_width
+ dx
);
25917 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
25918 hlinfo
->mouse_face_end_x
= 0;
25922 /* In R2L rows, show_mouse_face expects BEG and END
25923 coordinates to be swapped. */
25924 hlinfo
->mouse_face_end_col
= hpos
;
25925 hlinfo
->mouse_face_end_x
= original_x_pixel
25926 - (total_pixel_width
+ dx
);
25927 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
25928 hlinfo
->mouse_face_beg_x
= 0;
25931 hlinfo
->mouse_face_beg_row
= vpos
;
25932 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
25933 hlinfo
->mouse_face_beg_y
= 0;
25934 hlinfo
->mouse_face_end_y
= 0;
25935 hlinfo
->mouse_face_past_end
= 0;
25936 hlinfo
->mouse_face_window
= window
;
25938 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
25944 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25946 if (NILP (pointer
))
25949 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25950 clear_mouse_face (hlinfo
);
25952 #ifdef HAVE_WINDOW_SYSTEM
25953 if (FRAME_WINDOW_P (f
))
25954 define_frame_cursor1 (f
, cursor
, pointer
);
25960 Take proper action when the mouse has moved to position X, Y on
25961 frame F as regards highlighting characters that have mouse-face
25962 properties. Also de-highlighting chars where the mouse was before.
25963 X and Y can be negative or out of range. */
25966 note_mouse_highlight (struct frame
*f
, int x
, int y
)
25968 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25969 enum window_part part
;
25970 Lisp_Object window
;
25972 Cursor cursor
= No_Cursor
;
25973 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
25976 /* When a menu is active, don't highlight because this looks odd. */
25977 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
25978 if (popup_activated ())
25982 if (NILP (Vmouse_highlight
)
25983 || !f
->glyphs_initialized_p
25984 || f
->pointer_invisible
)
25987 hlinfo
->mouse_face_mouse_x
= x
;
25988 hlinfo
->mouse_face_mouse_y
= y
;
25989 hlinfo
->mouse_face_mouse_frame
= f
;
25991 if (hlinfo
->mouse_face_defer
)
25994 if (gc_in_progress
)
25996 hlinfo
->mouse_face_deferred_gc
= 1;
26000 /* Which window is that in? */
26001 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
26003 /* If we were displaying active text in another window, clear that.
26004 Also clear if we move out of text area in same window. */
26005 if (! EQ (window
, hlinfo
->mouse_face_window
)
26006 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
26007 && !NILP (hlinfo
->mouse_face_window
)))
26008 clear_mouse_face (hlinfo
);
26010 /* Not on a window -> return. */
26011 if (!WINDOWP (window
))
26014 /* Reset help_echo_string. It will get recomputed below. */
26015 help_echo_string
= Qnil
;
26017 /* Convert to window-relative pixel coordinates. */
26018 w
= XWINDOW (window
);
26019 frame_to_window_pixel_xy (w
, &x
, &y
);
26021 #ifdef HAVE_WINDOW_SYSTEM
26022 /* Handle tool-bar window differently since it doesn't display a
26024 if (EQ (window
, f
->tool_bar_window
))
26026 note_tool_bar_highlight (f
, x
, y
);
26031 /* Mouse is on the mode, header line or margin? */
26032 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
26033 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
26035 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
26039 #ifdef HAVE_WINDOW_SYSTEM
26040 if (part
== ON_VERTICAL_BORDER
)
26042 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
26043 help_echo_string
= build_string ("drag-mouse-1: resize");
26045 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
26046 || part
== ON_SCROLL_BAR
)
26047 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26049 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
26052 /* Are we in a window whose display is up to date?
26053 And verify the buffer's text has not changed. */
26054 b
= XBUFFER (w
->buffer
);
26055 if (part
== ON_TEXT
26056 && EQ (w
->window_end_valid
, w
->buffer
)
26057 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
26058 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
26060 int hpos
, vpos
, i
, dx
, dy
, area
;
26062 struct glyph
*glyph
;
26063 Lisp_Object object
;
26064 Lisp_Object mouse_face
= Qnil
, position
;
26065 Lisp_Object
*overlay_vec
= NULL
;
26067 struct buffer
*obuf
;
26068 EMACS_INT obegv
, ozv
;
26071 /* Find the glyph under X/Y. */
26072 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
26074 #ifdef HAVE_WINDOW_SYSTEM
26075 /* Look for :pointer property on image. */
26076 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26078 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26079 if (img
!= NULL
&& IMAGEP (img
->spec
))
26081 Lisp_Object image_map
, hotspot
;
26082 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
26084 && (hotspot
= find_hot_spot (image_map
,
26085 glyph
->slice
.img
.x
+ dx
,
26086 glyph
->slice
.img
.y
+ dy
),
26088 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
26092 /* Could check XCAR (hotspot) to see if we enter/leave
26094 If so, we could look for mouse-enter, mouse-leave
26095 properties in PLIST (and do something...). */
26096 hotspot
= XCDR (hotspot
);
26097 if (CONSP (hotspot
)
26098 && (plist
= XCAR (hotspot
), CONSP (plist
)))
26100 pointer
= Fplist_get (plist
, Qpointer
);
26101 if (NILP (pointer
))
26103 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
26104 if (!NILP (help_echo_string
))
26106 help_echo_window
= window
;
26107 help_echo_object
= glyph
->object
;
26108 help_echo_pos
= glyph
->charpos
;
26112 if (NILP (pointer
))
26113 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
26116 #endif /* HAVE_WINDOW_SYSTEM */
26118 /* Clear mouse face if X/Y not over text. */
26120 || area
!= TEXT_AREA
26121 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
26122 /* Glyph's OBJECT is an integer for glyphs inserted by the
26123 display engine for its internal purposes, like truncation
26124 and continuation glyphs and blanks beyond the end of
26125 line's text on text terminals. If we are over such a
26126 glyph, we are not over any text. */
26127 || INTEGERP (glyph
->object
)
26128 /* R2L rows have a stretch glyph at their front, which
26129 stands for no text, whereas L2R rows have no glyphs at
26130 all beyond the end of text. Treat such stretch glyphs
26131 like we do with NULL glyphs in L2R rows. */
26132 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
26133 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
26134 && glyph
->type
== STRETCH_GLYPH
26135 && glyph
->avoid_cursor_p
))
26137 if (clear_mouse_face (hlinfo
))
26138 cursor
= No_Cursor
;
26139 #ifdef HAVE_WINDOW_SYSTEM
26140 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
26142 if (area
!= TEXT_AREA
)
26143 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26145 pointer
= Vvoid_text_area_pointer
;
26151 pos
= glyph
->charpos
;
26152 object
= glyph
->object
;
26153 if (!STRINGP (object
) && !BUFFERP (object
))
26156 /* If we get an out-of-range value, return now; avoid an error. */
26157 if (BUFFERP (object
) && pos
> BUF_Z (b
))
26160 /* Make the window's buffer temporarily current for
26161 overlays_at and compute_char_face. */
26162 obuf
= current_buffer
;
26163 current_buffer
= b
;
26169 /* Is this char mouse-active or does it have help-echo? */
26170 position
= make_number (pos
);
26172 if (BUFFERP (object
))
26174 /* Put all the overlays we want in a vector in overlay_vec. */
26175 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
26176 /* Sort overlays into increasing priority order. */
26177 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
26182 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
26185 cursor
= No_Cursor
;
26187 /* Check mouse-face highlighting. */
26189 /* If there exists an overlay with mouse-face overlapping
26190 the one we are currently highlighting, we have to
26191 check if we enter the overlapping overlay, and then
26192 highlight only that. */
26193 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
26194 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
26196 /* Find the highest priority overlay with a mouse-face. */
26197 Lisp_Object overlay
= Qnil
;
26198 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
26200 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
26201 if (!NILP (mouse_face
))
26202 overlay
= overlay_vec
[i
];
26205 /* If we're highlighting the same overlay as before, there's
26206 no need to do that again. */
26207 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
26208 goto check_help_echo
;
26209 hlinfo
->mouse_face_overlay
= overlay
;
26211 /* Clear the display of the old active region, if any. */
26212 if (clear_mouse_face (hlinfo
))
26213 cursor
= No_Cursor
;
26215 /* If no overlay applies, get a text property. */
26216 if (NILP (overlay
))
26217 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
26219 /* Next, compute the bounds of the mouse highlighting and
26221 if (!NILP (mouse_face
) && STRINGP (object
))
26223 /* The mouse-highlighting comes from a display string
26224 with a mouse-face. */
26228 s
= Fprevious_single_property_change
26229 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
26230 e
= Fnext_single_property_change
26231 (position
, Qmouse_face
, object
, Qnil
);
26233 s
= make_number (0);
26235 e
= make_number (SCHARS (object
) - 1);
26236 mouse_face_from_string_pos (w
, hlinfo
, object
,
26237 XINT (s
), XINT (e
));
26238 hlinfo
->mouse_face_past_end
= 0;
26239 hlinfo
->mouse_face_window
= window
;
26240 hlinfo
->mouse_face_face_id
26241 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
26242 glyph
->face_id
, 1);
26243 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26244 cursor
= No_Cursor
;
26248 /* The mouse-highlighting, if any, comes from an overlay
26249 or text property in the buffer. */
26250 Lisp_Object buffer
IF_LINT (= Qnil
);
26251 Lisp_Object cover_string
IF_LINT (= Qnil
);
26253 if (STRINGP (object
))
26255 /* If we are on a display string with no mouse-face,
26256 check if the text under it has one. */
26257 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
26258 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26259 pos
= string_buffer_position (object
, start
);
26262 mouse_face
= get_char_property_and_overlay
26263 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
26264 buffer
= w
->buffer
;
26265 cover_string
= object
;
26271 cover_string
= Qnil
;
26274 if (!NILP (mouse_face
))
26276 Lisp_Object before
, after
;
26277 Lisp_Object before_string
, after_string
;
26278 /* To correctly find the limits of mouse highlight
26279 in a bidi-reordered buffer, we must not use the
26280 optimization of limiting the search in
26281 previous-single-property-change and
26282 next-single-property-change, because
26283 rows_from_pos_range needs the real start and end
26284 positions to DTRT in this case. That's because
26285 the first row visible in a window does not
26286 necessarily display the character whose position
26287 is the smallest. */
26289 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
26290 ? Fmarker_position (w
->start
)
26293 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
26294 ? make_number (BUF_Z (XBUFFER (buffer
))
26295 - XFASTINT (w
->window_end_pos
))
26298 if (NILP (overlay
))
26300 /* Handle the text property case. */
26301 before
= Fprevious_single_property_change
26302 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
26303 after
= Fnext_single_property_change
26304 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
26305 before_string
= after_string
= Qnil
;
26309 /* Handle the overlay case. */
26310 before
= Foverlay_start (overlay
);
26311 after
= Foverlay_end (overlay
);
26312 before_string
= Foverlay_get (overlay
, Qbefore_string
);
26313 after_string
= Foverlay_get (overlay
, Qafter_string
);
26315 if (!STRINGP (before_string
)) before_string
= Qnil
;
26316 if (!STRINGP (after_string
)) after_string
= Qnil
;
26319 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
26322 before_string
, after_string
,
26324 cursor
= No_Cursor
;
26331 /* Look for a `help-echo' property. */
26332 if (NILP (help_echo_string
)) {
26333 Lisp_Object help
, overlay
;
26335 /* Check overlays first. */
26336 help
= overlay
= Qnil
;
26337 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
26339 overlay
= overlay_vec
[i
];
26340 help
= Foverlay_get (overlay
, Qhelp_echo
);
26345 help_echo_string
= help
;
26346 help_echo_window
= window
;
26347 help_echo_object
= overlay
;
26348 help_echo_pos
= pos
;
26352 Lisp_Object obj
= glyph
->object
;
26353 EMACS_INT charpos
= glyph
->charpos
;
26355 /* Try text properties. */
26358 && charpos
< SCHARS (obj
))
26360 help
= Fget_text_property (make_number (charpos
),
26364 /* If the string itself doesn't specify a help-echo,
26365 see if the buffer text ``under'' it does. */
26366 struct glyph_row
*r
26367 = MATRIX_ROW (w
->current_matrix
, vpos
);
26368 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26369 EMACS_INT p
= string_buffer_position (obj
, start
);
26372 help
= Fget_char_property (make_number (p
),
26373 Qhelp_echo
, w
->buffer
);
26382 else if (BUFFERP (obj
)
26385 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
26390 help_echo_string
= help
;
26391 help_echo_window
= window
;
26392 help_echo_object
= obj
;
26393 help_echo_pos
= charpos
;
26398 #ifdef HAVE_WINDOW_SYSTEM
26399 /* Look for a `pointer' property. */
26400 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
26402 /* Check overlays first. */
26403 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
26404 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
26406 if (NILP (pointer
))
26408 Lisp_Object obj
= glyph
->object
;
26409 EMACS_INT charpos
= glyph
->charpos
;
26411 /* Try text properties. */
26414 && charpos
< SCHARS (obj
))
26416 pointer
= Fget_text_property (make_number (charpos
),
26418 if (NILP (pointer
))
26420 /* If the string itself doesn't specify a pointer,
26421 see if the buffer text ``under'' it does. */
26422 struct glyph_row
*r
26423 = MATRIX_ROW (w
->current_matrix
, vpos
);
26424 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26425 EMACS_INT p
= string_buffer_position (obj
, start
);
26427 pointer
= Fget_char_property (make_number (p
),
26428 Qpointer
, w
->buffer
);
26431 else if (BUFFERP (obj
)
26434 pointer
= Fget_text_property (make_number (charpos
),
26438 #endif /* HAVE_WINDOW_SYSTEM */
26442 current_buffer
= obuf
;
26447 #ifdef HAVE_WINDOW_SYSTEM
26448 if (FRAME_WINDOW_P (f
))
26449 define_frame_cursor1 (f
, cursor
, pointer
);
26451 /* This is here to prevent a compiler error, about "label at end of
26452 compound statement". */
26459 Clear any mouse-face on window W. This function is part of the
26460 redisplay interface, and is called from try_window_id and similar
26461 functions to ensure the mouse-highlight is off. */
26464 x_clear_window_mouse_face (struct window
*w
)
26466 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26467 Lisp_Object window
;
26470 XSETWINDOW (window
, w
);
26471 if (EQ (window
, hlinfo
->mouse_face_window
))
26472 clear_mouse_face (hlinfo
);
26478 Just discard the mouse face information for frame F, if any.
26479 This is used when the size of F is changed. */
26482 cancel_mouse_face (struct frame
*f
)
26484 Lisp_Object window
;
26485 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26487 window
= hlinfo
->mouse_face_window
;
26488 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
26490 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26491 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26492 hlinfo
->mouse_face_window
= Qnil
;
26498 /***********************************************************************
26500 ***********************************************************************/
26502 #ifdef HAVE_WINDOW_SYSTEM
26504 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
26505 which intersects rectangle R. R is in window-relative coordinates. */
26508 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
26509 enum glyph_row_area area
)
26511 struct glyph
*first
= row
->glyphs
[area
];
26512 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
26513 struct glyph
*last
;
26514 int first_x
, start_x
, x
;
26516 if (area
== TEXT_AREA
&& row
->fill_line_p
)
26517 /* If row extends face to end of line write the whole line. */
26518 draw_glyphs (w
, 0, row
, area
,
26519 0, row
->used
[area
],
26520 DRAW_NORMAL_TEXT
, 0);
26523 /* Set START_X to the window-relative start position for drawing glyphs of
26524 AREA. The first glyph of the text area can be partially visible.
26525 The first glyphs of other areas cannot. */
26526 start_x
= window_box_left_offset (w
, area
);
26528 if (area
== TEXT_AREA
)
26531 /* Find the first glyph that must be redrawn. */
26533 && x
+ first
->pixel_width
< r
->x
)
26535 x
+= first
->pixel_width
;
26539 /* Find the last one. */
26543 && x
< r
->x
+ r
->width
)
26545 x
+= last
->pixel_width
;
26551 draw_glyphs (w
, first_x
- start_x
, row
, area
,
26552 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
26553 DRAW_NORMAL_TEXT
, 0);
26558 /* Redraw the parts of the glyph row ROW on window W intersecting
26559 rectangle R. R is in window-relative coordinates. Value is
26560 non-zero if mouse-face was overwritten. */
26563 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
26565 xassert (row
->enabled_p
);
26567 if (row
->mode_line_p
|| w
->pseudo_window_p
)
26568 draw_glyphs (w
, 0, row
, TEXT_AREA
,
26569 0, row
->used
[TEXT_AREA
],
26570 DRAW_NORMAL_TEXT
, 0);
26573 if (row
->used
[LEFT_MARGIN_AREA
])
26574 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
26575 if (row
->used
[TEXT_AREA
])
26576 expose_area (w
, row
, r
, TEXT_AREA
);
26577 if (row
->used
[RIGHT_MARGIN_AREA
])
26578 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
26579 draw_row_fringe_bitmaps (w
, row
);
26582 return row
->mouse_face_p
;
26586 /* Redraw those parts of glyphs rows during expose event handling that
26587 overlap other rows. Redrawing of an exposed line writes over parts
26588 of lines overlapping that exposed line; this function fixes that.
26590 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
26591 row in W's current matrix that is exposed and overlaps other rows.
26592 LAST_OVERLAPPING_ROW is the last such row. */
26595 expose_overlaps (struct window
*w
,
26596 struct glyph_row
*first_overlapping_row
,
26597 struct glyph_row
*last_overlapping_row
,
26600 struct glyph_row
*row
;
26602 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
26603 if (row
->overlapping_p
)
26605 xassert (row
->enabled_p
&& !row
->mode_line_p
);
26608 if (row
->used
[LEFT_MARGIN_AREA
])
26609 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
26611 if (row
->used
[TEXT_AREA
])
26612 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
26614 if (row
->used
[RIGHT_MARGIN_AREA
])
26615 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
26621 /* Return non-zero if W's cursor intersects rectangle R. */
26624 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
26626 XRectangle cr
, result
;
26627 struct glyph
*cursor_glyph
;
26628 struct glyph_row
*row
;
26630 if (w
->phys_cursor
.vpos
>= 0
26631 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
26632 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
26634 && row
->cursor_in_fringe_p
)
26636 /* Cursor is in the fringe. */
26637 cr
.x
= window_box_right_offset (w
,
26638 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
26639 ? RIGHT_MARGIN_AREA
26642 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
26643 cr
.height
= row
->height
;
26644 return x_intersect_rectangles (&cr
, r
, &result
);
26647 cursor_glyph
= get_phys_cursor_glyph (w
);
26650 /* r is relative to W's box, but w->phys_cursor.x is relative
26651 to left edge of W's TEXT area. Adjust it. */
26652 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
26653 cr
.y
= w
->phys_cursor
.y
;
26654 cr
.width
= cursor_glyph
->pixel_width
;
26655 cr
.height
= w
->phys_cursor_height
;
26656 /* ++KFS: W32 version used W32-specific IntersectRect here, but
26657 I assume the effect is the same -- and this is portable. */
26658 return x_intersect_rectangles (&cr
, r
, &result
);
26660 /* If we don't understand the format, pretend we're not in the hot-spot. */
26666 Draw a vertical window border to the right of window W if W doesn't
26667 have vertical scroll bars. */
26670 x_draw_vertical_border (struct window
*w
)
26672 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26674 /* We could do better, if we knew what type of scroll-bar the adjacent
26675 windows (on either side) have... But we don't :-(
26676 However, I think this works ok. ++KFS 2003-04-25 */
26678 /* Redraw borders between horizontally adjacent windows. Don't
26679 do it for frames with vertical scroll bars because either the
26680 right scroll bar of a window, or the left scroll bar of its
26681 neighbor will suffice as a border. */
26682 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
26685 if (!WINDOW_RIGHTMOST_P (w
)
26686 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
26688 int x0
, x1
, y0
, y1
;
26690 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26693 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26696 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
26698 else if (!WINDOW_LEFTMOST_P (w
)
26699 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
26701 int x0
, x1
, y0
, y1
;
26703 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26706 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26709 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
26714 /* Redraw the part of window W intersection rectangle FR. Pixel
26715 coordinates in FR are frame-relative. Call this function with
26716 input blocked. Value is non-zero if the exposure overwrites
26720 expose_window (struct window
*w
, XRectangle
*fr
)
26722 struct frame
*f
= XFRAME (w
->frame
);
26724 int mouse_face_overwritten_p
= 0;
26726 /* If window is not yet fully initialized, do nothing. This can
26727 happen when toolkit scroll bars are used and a window is split.
26728 Reconfiguring the scroll bar will generate an expose for a newly
26730 if (w
->current_matrix
== NULL
)
26733 /* When we're currently updating the window, display and current
26734 matrix usually don't agree. Arrange for a thorough display
26736 if (w
== updated_window
)
26738 SET_FRAME_GARBAGED (f
);
26742 /* Frame-relative pixel rectangle of W. */
26743 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
26744 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
26745 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
26746 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
26748 if (x_intersect_rectangles (fr
, &wr
, &r
))
26750 int yb
= window_text_bottom_y (w
);
26751 struct glyph_row
*row
;
26752 int cursor_cleared_p
;
26753 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
26755 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
26756 r
.x
, r
.y
, r
.width
, r
.height
));
26758 /* Convert to window coordinates. */
26759 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
26760 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
26762 /* Turn off the cursor. */
26763 if (!w
->pseudo_window_p
26764 && phys_cursor_in_rect_p (w
, &r
))
26766 x_clear_cursor (w
);
26767 cursor_cleared_p
= 1;
26770 cursor_cleared_p
= 0;
26772 /* Update lines intersecting rectangle R. */
26773 first_overlapping_row
= last_overlapping_row
= NULL
;
26774 for (row
= w
->current_matrix
->rows
;
26779 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
26781 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
26782 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
26783 || (r
.y
>= y0
&& r
.y
< y1
)
26784 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
26786 /* A header line may be overlapping, but there is no need
26787 to fix overlapping areas for them. KFS 2005-02-12 */
26788 if (row
->overlapping_p
&& !row
->mode_line_p
)
26790 if (first_overlapping_row
== NULL
)
26791 first_overlapping_row
= row
;
26792 last_overlapping_row
= row
;
26796 if (expose_line (w
, row
, &r
))
26797 mouse_face_overwritten_p
= 1;
26800 else if (row
->overlapping_p
)
26802 /* We must redraw a row overlapping the exposed area. */
26804 ? y0
+ row
->phys_height
> r
.y
26805 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
26807 if (first_overlapping_row
== NULL
)
26808 first_overlapping_row
= row
;
26809 last_overlapping_row
= row
;
26817 /* Display the mode line if there is one. */
26818 if (WINDOW_WANTS_MODELINE_P (w
)
26819 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
26821 && row
->y
< r
.y
+ r
.height
)
26823 if (expose_line (w
, row
, &r
))
26824 mouse_face_overwritten_p
= 1;
26827 if (!w
->pseudo_window_p
)
26829 /* Fix the display of overlapping rows. */
26830 if (first_overlapping_row
)
26831 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
26834 /* Draw border between windows. */
26835 x_draw_vertical_border (w
);
26837 /* Turn the cursor on again. */
26838 if (cursor_cleared_p
)
26839 update_window_cursor (w
, 1);
26843 return mouse_face_overwritten_p
;
26848 /* Redraw (parts) of all windows in the window tree rooted at W that
26849 intersect R. R contains frame pixel coordinates. Value is
26850 non-zero if the exposure overwrites mouse-face. */
26853 expose_window_tree (struct window
*w
, XRectangle
*r
)
26855 struct frame
*f
= XFRAME (w
->frame
);
26856 int mouse_face_overwritten_p
= 0;
26858 while (w
&& !FRAME_GARBAGED_P (f
))
26860 if (!NILP (w
->hchild
))
26861 mouse_face_overwritten_p
26862 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
26863 else if (!NILP (w
->vchild
))
26864 mouse_face_overwritten_p
26865 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
26867 mouse_face_overwritten_p
|= expose_window (w
, r
);
26869 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
26872 return mouse_face_overwritten_p
;
26877 Redisplay an exposed area of frame F. X and Y are the upper-left
26878 corner of the exposed rectangle. W and H are width and height of
26879 the exposed area. All are pixel values. W or H zero means redraw
26880 the entire frame. */
26883 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
26886 int mouse_face_overwritten_p
= 0;
26888 TRACE ((stderr
, "expose_frame "));
26890 /* No need to redraw if frame will be redrawn soon. */
26891 if (FRAME_GARBAGED_P (f
))
26893 TRACE ((stderr
, " garbaged\n"));
26897 /* If basic faces haven't been realized yet, there is no point in
26898 trying to redraw anything. This can happen when we get an expose
26899 event while Emacs is starting, e.g. by moving another window. */
26900 if (FRAME_FACE_CACHE (f
) == NULL
26901 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
26903 TRACE ((stderr
, " no faces\n"));
26907 if (w
== 0 || h
== 0)
26910 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
26911 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
26921 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
26922 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
26924 if (WINDOWP (f
->tool_bar_window
))
26925 mouse_face_overwritten_p
26926 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
26928 #ifdef HAVE_X_WINDOWS
26930 #ifndef USE_X_TOOLKIT
26931 if (WINDOWP (f
->menu_bar_window
))
26932 mouse_face_overwritten_p
26933 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
26934 #endif /* not USE_X_TOOLKIT */
26938 /* Some window managers support a focus-follows-mouse style with
26939 delayed raising of frames. Imagine a partially obscured frame,
26940 and moving the mouse into partially obscured mouse-face on that
26941 frame. The visible part of the mouse-face will be highlighted,
26942 then the WM raises the obscured frame. With at least one WM, KDE
26943 2.1, Emacs is not getting any event for the raising of the frame
26944 (even tried with SubstructureRedirectMask), only Expose events.
26945 These expose events will draw text normally, i.e. not
26946 highlighted. Which means we must redo the highlight here.
26947 Subsume it under ``we love X''. --gerd 2001-08-15 */
26948 /* Included in Windows version because Windows most likely does not
26949 do the right thing if any third party tool offers
26950 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
26951 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
26953 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26954 if (f
== hlinfo
->mouse_face_mouse_frame
)
26956 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
26957 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
26958 clear_mouse_face (hlinfo
);
26959 note_mouse_highlight (f
, mouse_x
, mouse_y
);
26966 Determine the intersection of two rectangles R1 and R2. Return
26967 the intersection in *RESULT. Value is non-zero if RESULT is not
26971 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
26973 XRectangle
*left
, *right
;
26974 XRectangle
*upper
, *lower
;
26975 int intersection_p
= 0;
26977 /* Rearrange so that R1 is the left-most rectangle. */
26979 left
= r1
, right
= r2
;
26981 left
= r2
, right
= r1
;
26983 /* X0 of the intersection is right.x0, if this is inside R1,
26984 otherwise there is no intersection. */
26985 if (right
->x
<= left
->x
+ left
->width
)
26987 result
->x
= right
->x
;
26989 /* The right end of the intersection is the minimum of the
26990 the right ends of left and right. */
26991 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
26994 /* Same game for Y. */
26996 upper
= r1
, lower
= r2
;
26998 upper
= r2
, lower
= r1
;
27000 /* The upper end of the intersection is lower.y0, if this is inside
27001 of upper. Otherwise, there is no intersection. */
27002 if (lower
->y
<= upper
->y
+ upper
->height
)
27004 result
->y
= lower
->y
;
27006 /* The lower end of the intersection is the minimum of the lower
27007 ends of upper and lower. */
27008 result
->height
= (min (lower
->y
+ lower
->height
,
27009 upper
->y
+ upper
->height
)
27011 intersection_p
= 1;
27015 return intersection_p
;
27018 #endif /* HAVE_WINDOW_SYSTEM */
27021 /***********************************************************************
27023 ***********************************************************************/
27026 syms_of_xdisp (void)
27028 Vwith_echo_area_save_vector
= Qnil
;
27029 staticpro (&Vwith_echo_area_save_vector
);
27031 Vmessage_stack
= Qnil
;
27032 staticpro (&Vmessage_stack
);
27034 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
27035 staticpro (&Qinhibit_redisplay
);
27037 message_dolog_marker1
= Fmake_marker ();
27038 staticpro (&message_dolog_marker1
);
27039 message_dolog_marker2
= Fmake_marker ();
27040 staticpro (&message_dolog_marker2
);
27041 message_dolog_marker3
= Fmake_marker ();
27042 staticpro (&message_dolog_marker3
);
27045 defsubr (&Sdump_frame_glyph_matrix
);
27046 defsubr (&Sdump_glyph_matrix
);
27047 defsubr (&Sdump_glyph_row
);
27048 defsubr (&Sdump_tool_bar_row
);
27049 defsubr (&Strace_redisplay
);
27050 defsubr (&Strace_to_stderr
);
27052 #ifdef HAVE_WINDOW_SYSTEM
27053 defsubr (&Stool_bar_lines_needed
);
27054 defsubr (&Slookup_image_map
);
27056 defsubr (&Sformat_mode_line
);
27057 defsubr (&Sinvisible_p
);
27058 defsubr (&Scurrent_bidi_paragraph_direction
);
27060 staticpro (&Qmenu_bar_update_hook
);
27061 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
27063 staticpro (&Qoverriding_terminal_local_map
);
27064 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
27066 staticpro (&Qoverriding_local_map
);
27067 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
27069 staticpro (&Qwindow_scroll_functions
);
27070 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
27072 staticpro (&Qwindow_text_change_functions
);
27073 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
27075 staticpro (&Qredisplay_end_trigger_functions
);
27076 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
27078 staticpro (&Qinhibit_point_motion_hooks
);
27079 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
27081 Qeval
= intern_c_string ("eval");
27082 staticpro (&Qeval
);
27084 QCdata
= intern_c_string (":data");
27085 staticpro (&QCdata
);
27086 Qdisplay
= intern_c_string ("display");
27087 staticpro (&Qdisplay
);
27088 Qspace_width
= intern_c_string ("space-width");
27089 staticpro (&Qspace_width
);
27090 Qraise
= intern_c_string ("raise");
27091 staticpro (&Qraise
);
27092 Qslice
= intern_c_string ("slice");
27093 staticpro (&Qslice
);
27094 Qspace
= intern_c_string ("space");
27095 staticpro (&Qspace
);
27096 Qmargin
= intern_c_string ("margin");
27097 staticpro (&Qmargin
);
27098 Qpointer
= intern_c_string ("pointer");
27099 staticpro (&Qpointer
);
27100 Qleft_margin
= intern_c_string ("left-margin");
27101 staticpro (&Qleft_margin
);
27102 Qright_margin
= intern_c_string ("right-margin");
27103 staticpro (&Qright_margin
);
27104 Qcenter
= intern_c_string ("center");
27105 staticpro (&Qcenter
);
27106 Qline_height
= intern_c_string ("line-height");
27107 staticpro (&Qline_height
);
27108 QCalign_to
= intern_c_string (":align-to");
27109 staticpro (&QCalign_to
);
27110 QCrelative_width
= intern_c_string (":relative-width");
27111 staticpro (&QCrelative_width
);
27112 QCrelative_height
= intern_c_string (":relative-height");
27113 staticpro (&QCrelative_height
);
27114 QCeval
= intern_c_string (":eval");
27115 staticpro (&QCeval
);
27116 QCpropertize
= intern_c_string (":propertize");
27117 staticpro (&QCpropertize
);
27118 QCfile
= intern_c_string (":file");
27119 staticpro (&QCfile
);
27120 Qfontified
= intern_c_string ("fontified");
27121 staticpro (&Qfontified
);
27122 Qfontification_functions
= intern_c_string ("fontification-functions");
27123 staticpro (&Qfontification_functions
);
27124 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
27125 staticpro (&Qtrailing_whitespace
);
27126 Qescape_glyph
= intern_c_string ("escape-glyph");
27127 staticpro (&Qescape_glyph
);
27128 Qnobreak_space
= intern_c_string ("nobreak-space");
27129 staticpro (&Qnobreak_space
);
27130 Qimage
= intern_c_string ("image");
27131 staticpro (&Qimage
);
27132 Qtext
= intern_c_string ("text");
27133 staticpro (&Qtext
);
27134 Qboth
= intern_c_string ("both");
27135 staticpro (&Qboth
);
27136 Qboth_horiz
= intern_c_string ("both-horiz");
27137 staticpro (&Qboth_horiz
);
27138 Qtext_image_horiz
= intern_c_string ("text-image-horiz");
27139 staticpro (&Qtext_image_horiz
);
27140 QCmap
= intern_c_string (":map");
27141 staticpro (&QCmap
);
27142 QCpointer
= intern_c_string (":pointer");
27143 staticpro (&QCpointer
);
27144 Qrect
= intern_c_string ("rect");
27145 staticpro (&Qrect
);
27146 Qcircle
= intern_c_string ("circle");
27147 staticpro (&Qcircle
);
27148 Qpoly
= intern_c_string ("poly");
27149 staticpro (&Qpoly
);
27150 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
27151 staticpro (&Qmessage_truncate_lines
);
27152 Qgrow_only
= intern_c_string ("grow-only");
27153 staticpro (&Qgrow_only
);
27154 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
27155 staticpro (&Qinhibit_menubar_update
);
27156 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
27157 staticpro (&Qinhibit_eval_during_redisplay
);
27158 Qposition
= intern_c_string ("position");
27159 staticpro (&Qposition
);
27160 Qbuffer_position
= intern_c_string ("buffer-position");
27161 staticpro (&Qbuffer_position
);
27162 Qobject
= intern_c_string ("object");
27163 staticpro (&Qobject
);
27164 Qbar
= intern_c_string ("bar");
27166 Qhbar
= intern_c_string ("hbar");
27167 staticpro (&Qhbar
);
27168 Qbox
= intern_c_string ("box");
27170 Qhollow
= intern_c_string ("hollow");
27171 staticpro (&Qhollow
);
27172 Qhand
= intern_c_string ("hand");
27173 staticpro (&Qhand
);
27174 Qarrow
= intern_c_string ("arrow");
27175 staticpro (&Qarrow
);
27176 Qtext
= intern_c_string ("text");
27177 staticpro (&Qtext
);
27178 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
27179 staticpro (&Qinhibit_free_realized_faces
);
27181 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
27182 Fcons (intern_c_string ("void-variable"), Qnil
)),
27184 staticpro (&list_of_error
);
27186 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
27187 staticpro (&Qlast_arrow_position
);
27188 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
27189 staticpro (&Qlast_arrow_string
);
27191 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
27192 staticpro (&Qoverlay_arrow_string
);
27193 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
27194 staticpro (&Qoverlay_arrow_bitmap
);
27196 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
27197 staticpro (&echo_buffer
[0]);
27198 staticpro (&echo_buffer
[1]);
27200 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
27201 staticpro (&echo_area_buffer
[0]);
27202 staticpro (&echo_area_buffer
[1]);
27204 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
27205 staticpro (&Vmessages_buffer_name
);
27207 mode_line_proptrans_alist
= Qnil
;
27208 staticpro (&mode_line_proptrans_alist
);
27209 mode_line_string_list
= Qnil
;
27210 staticpro (&mode_line_string_list
);
27211 mode_line_string_face
= Qnil
;
27212 staticpro (&mode_line_string_face
);
27213 mode_line_string_face_prop
= Qnil
;
27214 staticpro (&mode_line_string_face_prop
);
27215 Vmode_line_unwind_vector
= Qnil
;
27216 staticpro (&Vmode_line_unwind_vector
);
27218 help_echo_string
= Qnil
;
27219 staticpro (&help_echo_string
);
27220 help_echo_object
= Qnil
;
27221 staticpro (&help_echo_object
);
27222 help_echo_window
= Qnil
;
27223 staticpro (&help_echo_window
);
27224 previous_help_echo_string
= Qnil
;
27225 staticpro (&previous_help_echo_string
);
27226 help_echo_pos
= -1;
27228 Qright_to_left
= intern_c_string ("right-to-left");
27229 staticpro (&Qright_to_left
);
27230 Qleft_to_right
= intern_c_string ("left-to-right");
27231 staticpro (&Qleft_to_right
);
27233 #ifdef HAVE_WINDOW_SYSTEM
27234 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
27235 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
27236 For example, if a block cursor is over a tab, it will be drawn as
27237 wide as that tab on the display. */);
27238 x_stretch_cursor_p
= 0;
27241 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
27242 doc
: /* *Non-nil means highlight trailing whitespace.
27243 The face used for trailing whitespace is `trailing-whitespace'. */);
27244 Vshow_trailing_whitespace
= Qnil
;
27246 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
27247 doc
: /* *Control highlighting of nobreak space and soft hyphen.
27248 A value of t means highlight the character itself (for nobreak space,
27249 use face `nobreak-space').
27250 A value of nil means no highlighting.
27251 Other values mean display the escape glyph followed by an ordinary
27252 space or ordinary hyphen. */);
27253 Vnobreak_char_display
= Qt
;
27255 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
27256 doc
: /* *The pointer shape to show in void text areas.
27257 A value of nil means to show the text pointer. Other options are `arrow',
27258 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
27259 Vvoid_text_area_pointer
= Qarrow
;
27261 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
27262 doc
: /* Non-nil means don't actually do any redisplay.
27263 This is used for internal purposes. */);
27264 Vinhibit_redisplay
= Qnil
;
27266 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
27267 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
27268 Vglobal_mode_string
= Qnil
;
27270 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
27271 doc
: /* Marker for where to display an arrow on top of the buffer text.
27272 This must be the beginning of a line in order to work.
27273 See also `overlay-arrow-string'. */);
27274 Voverlay_arrow_position
= Qnil
;
27276 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
27277 doc
: /* String to display as an arrow in non-window frames.
27278 See also `overlay-arrow-position'. */);
27279 Voverlay_arrow_string
= make_pure_c_string ("=>");
27281 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
27282 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
27283 The symbols on this list are examined during redisplay to determine
27284 where to display overlay arrows. */);
27285 Voverlay_arrow_variable_list
27286 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
27288 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
27289 doc
: /* *The number of lines to try scrolling a window by when point moves out.
27290 If that fails to bring point back on frame, point is centered instead.
27291 If this is zero, point is always centered after it moves off frame.
27292 If you want scrolling to always be a line at a time, you should set
27293 `scroll-conservatively' to a large value rather than set this to 1. */);
27295 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
27296 doc
: /* *Scroll up to this many lines, to bring point back on screen.
27297 If point moves off-screen, redisplay will scroll by up to
27298 `scroll-conservatively' lines in order to bring point just barely
27299 onto the screen again. If that cannot be done, then redisplay
27300 recenters point as usual.
27302 If the value is greater than 100, redisplay will never recenter point,
27303 but will always scroll just enough text to bring point into view, even
27304 if you move far away.
27306 A value of zero means always recenter point if it moves off screen. */);
27307 scroll_conservatively
= 0;
27309 DEFVAR_INT ("scroll-margin", scroll_margin
,
27310 doc
: /* *Number of lines of margin at the top and bottom of a window.
27311 Recenter the window whenever point gets within this many lines
27312 of the top or bottom of the window. */);
27315 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
27316 doc
: /* Pixels per inch value for non-window system displays.
27317 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
27318 Vdisplay_pixels_per_inch
= make_float (72.0);
27321 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
27324 DEFVAR_LISP ("truncate-partial-width-windows",
27325 Vtruncate_partial_width_windows
,
27326 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
27327 For an integer value, truncate lines in each window narrower than the
27328 full frame width, provided the window width is less than that integer;
27329 otherwise, respect the value of `truncate-lines'.
27331 For any other non-nil value, truncate lines in all windows that do
27332 not span the full frame width.
27334 A value of nil means to respect the value of `truncate-lines'.
27336 If `word-wrap' is enabled, you might want to reduce this. */);
27337 Vtruncate_partial_width_windows
= make_number (50);
27339 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
27340 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
27341 Any other value means to use the appropriate face, `mode-line',
27342 `header-line', or `menu' respectively. */);
27343 mode_line_inverse_video
= 1;
27345 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
27346 doc
: /* *Maximum buffer size for which line number should be displayed.
27347 If the buffer is bigger than this, the line number does not appear
27348 in the mode line. A value of nil means no limit. */);
27349 Vline_number_display_limit
= Qnil
;
27351 DEFVAR_INT ("line-number-display-limit-width",
27352 line_number_display_limit_width
,
27353 doc
: /* *Maximum line width (in characters) for line number display.
27354 If the average length of the lines near point is bigger than this, then the
27355 line number may be omitted from the mode line. */);
27356 line_number_display_limit_width
= 200;
27358 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
27359 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
27360 highlight_nonselected_windows
= 0;
27362 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
27363 doc
: /* Non-nil if more than one frame is visible on this display.
27364 Minibuffer-only frames don't count, but iconified frames do.
27365 This variable is not guaranteed to be accurate except while processing
27366 `frame-title-format' and `icon-title-format'. */);
27368 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
27369 doc
: /* Template for displaying the title bar of visible frames.
27370 \(Assuming the window manager supports this feature.)
27372 This variable has the same structure as `mode-line-format', except that
27373 the %c and %l constructs are ignored. It is used only on frames for
27374 which no explicit name has been set \(see `modify-frame-parameters'). */);
27376 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
27377 doc
: /* Template for displaying the title bar of an iconified frame.
27378 \(Assuming the window manager supports this feature.)
27379 This variable has the same structure as `mode-line-format' (which see),
27380 and is used only on frames for which no explicit name has been set
27381 \(see `modify-frame-parameters'). */);
27383 = Vframe_title_format
27384 = pure_cons (intern_c_string ("multiple-frames"),
27385 pure_cons (make_pure_c_string ("%b"),
27386 pure_cons (pure_cons (empty_unibyte_string
,
27387 pure_cons (intern_c_string ("invocation-name"),
27388 pure_cons (make_pure_c_string ("@"),
27389 pure_cons (intern_c_string ("system-name"),
27393 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
27394 doc
: /* Maximum number of lines to keep in the message log buffer.
27395 If nil, disable message logging. If t, log messages but don't truncate
27396 the buffer when it becomes large. */);
27397 Vmessage_log_max
= make_number (100);
27399 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
27400 doc
: /* Functions called before redisplay, if window sizes have changed.
27401 The value should be a list of functions that take one argument.
27402 Just before redisplay, for each frame, if any of its windows have changed
27403 size since the last redisplay, or have been split or deleted,
27404 all the functions in the list are called, with the frame as argument. */);
27405 Vwindow_size_change_functions
= Qnil
;
27407 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
27408 doc
: /* List of functions to call before redisplaying a window with scrolling.
27409 Each function is called with two arguments, the window and its new
27410 display-start position. Note that these functions are also called by
27411 `set-window-buffer'. Also note that the value of `window-end' is not
27412 valid when these functions are called. */);
27413 Vwindow_scroll_functions
= Qnil
;
27415 DEFVAR_LISP ("window-text-change-functions",
27416 Vwindow_text_change_functions
,
27417 doc
: /* Functions to call in redisplay when text in the window might change. */);
27418 Vwindow_text_change_functions
= Qnil
;
27420 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
27421 doc
: /* Functions called when redisplay of a window reaches the end trigger.
27422 Each function is called with two arguments, the window and the end trigger value.
27423 See `set-window-redisplay-end-trigger'. */);
27424 Vredisplay_end_trigger_functions
= Qnil
;
27426 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
27427 doc
: /* *Non-nil means autoselect window with mouse pointer.
27428 If nil, do not autoselect windows.
27429 A positive number means delay autoselection by that many seconds: a
27430 window is autoselected only after the mouse has remained in that
27431 window for the duration of the delay.
27432 A negative number has a similar effect, but causes windows to be
27433 autoselected only after the mouse has stopped moving. \(Because of
27434 the way Emacs compares mouse events, you will occasionally wait twice
27435 that time before the window gets selected.\)
27436 Any other value means to autoselect window instantaneously when the
27437 mouse pointer enters it.
27439 Autoselection selects the minibuffer only if it is active, and never
27440 unselects the minibuffer if it is active.
27442 When customizing this variable make sure that the actual value of
27443 `focus-follows-mouse' matches the behavior of your window manager. */);
27444 Vmouse_autoselect_window
= Qnil
;
27446 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
27447 doc
: /* *Non-nil means automatically resize tool-bars.
27448 This dynamically changes the tool-bar's height to the minimum height
27449 that is needed to make all tool-bar items visible.
27450 If value is `grow-only', the tool-bar's height is only increased
27451 automatically; to decrease the tool-bar height, use \\[recenter]. */);
27452 Vauto_resize_tool_bars
= Qt
;
27454 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
27455 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
27456 auto_raise_tool_bar_buttons_p
= 1;
27458 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
27459 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
27460 make_cursor_line_fully_visible_p
= 1;
27462 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
27463 doc
: /* *Border below tool-bar in pixels.
27464 If an integer, use it as the height of the border.
27465 If it is one of `internal-border-width' or `border-width', use the
27466 value of the corresponding frame parameter.
27467 Otherwise, no border is added below the tool-bar. */);
27468 Vtool_bar_border
= Qinternal_border_width
;
27470 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
27471 doc
: /* *Margin around tool-bar buttons in pixels.
27472 If an integer, use that for both horizontal and vertical margins.
27473 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
27474 HORZ specifying the horizontal margin, and VERT specifying the
27475 vertical margin. */);
27476 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
27478 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
27479 doc
: /* *Relief thickness of tool-bar buttons. */);
27480 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
27482 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
27483 doc
: /* Tool bar style to use.
27485 image - show images only
27486 text - show text only
27487 both - show both, text below image
27488 both-horiz - show text to the right of the image
27489 text-image-horiz - show text to the left of the image
27490 any other - use system default or image if no system default. */);
27491 Vtool_bar_style
= Qnil
;
27493 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
27494 doc
: /* *Maximum number of characters a label can have to be shown.
27495 The tool bar style must also show labels for this to have any effect, see
27496 `tool-bar-style'. */);
27497 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
27499 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
27500 doc
: /* List of functions to call to fontify regions of text.
27501 Each function is called with one argument POS. Functions must
27502 fontify a region starting at POS in the current buffer, and give
27503 fontified regions the property `fontified'. */);
27504 Vfontification_functions
= Qnil
;
27505 Fmake_variable_buffer_local (Qfontification_functions
);
27507 DEFVAR_BOOL ("unibyte-display-via-language-environment",
27508 unibyte_display_via_language_environment
,
27509 doc
: /* *Non-nil means display unibyte text according to language environment.
27510 Specifically, this means that raw bytes in the range 160-255 decimal
27511 are displayed by converting them to the equivalent multibyte characters
27512 according to the current language environment. As a result, they are
27513 displayed according to the current fontset.
27515 Note that this variable affects only how these bytes are displayed,
27516 but does not change the fact they are interpreted as raw bytes. */);
27517 unibyte_display_via_language_environment
= 0;
27519 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
27520 doc
: /* *Maximum height for resizing mini-windows.
27521 If a float, it specifies a fraction of the mini-window frame's height.
27522 If an integer, it specifies a number of lines. */);
27523 Vmax_mini_window_height
= make_float (0.25);
27525 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
27526 doc
: /* *How to resize mini-windows.
27527 A value of nil means don't automatically resize mini-windows.
27528 A value of t means resize them to fit the text displayed in them.
27529 A value of `grow-only', the default, means let mini-windows grow
27530 only, until their display becomes empty, at which point the windows
27531 go back to their normal size. */);
27532 Vresize_mini_windows
= Qgrow_only
;
27534 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
27535 doc
: /* Alist specifying how to blink the cursor off.
27536 Each element has the form (ON-STATE . OFF-STATE). Whenever the
27537 `cursor-type' frame-parameter or variable equals ON-STATE,
27538 comparing using `equal', Emacs uses OFF-STATE to specify
27539 how to blink it off. ON-STATE and OFF-STATE are values for
27540 the `cursor-type' frame parameter.
27542 If a frame's ON-STATE has no entry in this list,
27543 the frame's other specifications determine how to blink the cursor off. */);
27544 Vblink_cursor_alist
= Qnil
;
27546 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
27547 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
27548 If non-nil, windows are automatically scrolled horizontally to make
27549 point visible. */);
27550 automatic_hscrolling_p
= 1;
27551 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
27552 staticpro (&Qauto_hscroll_mode
);
27554 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
27555 doc
: /* *How many columns away from the window edge point is allowed to get
27556 before automatic hscrolling will horizontally scroll the window. */);
27557 hscroll_margin
= 5;
27559 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
27560 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
27561 When point is less than `hscroll-margin' columns from the window
27562 edge, automatic hscrolling will scroll the window by the amount of columns
27563 determined by this variable. If its value is a positive integer, scroll that
27564 many columns. If it's a positive floating-point number, it specifies the
27565 fraction of the window's width to scroll. If it's nil or zero, point will be
27566 centered horizontally after the scroll. Any other value, including negative
27567 numbers, are treated as if the value were zero.
27569 Automatic hscrolling always moves point outside the scroll margin, so if
27570 point was more than scroll step columns inside the margin, the window will
27571 scroll more than the value given by the scroll step.
27573 Note that the lower bound for automatic hscrolling specified by `scroll-left'
27574 and `scroll-right' overrides this variable's effect. */);
27575 Vhscroll_step
= make_number (0);
27577 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
27578 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
27579 Bind this around calls to `message' to let it take effect. */);
27580 message_truncate_lines
= 0;
27582 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
27583 doc
: /* Normal hook run to update the menu bar definitions.
27584 Redisplay runs this hook before it redisplays the menu bar.
27585 This is used to update submenus such as Buffers,
27586 whose contents depend on various data. */);
27587 Vmenu_bar_update_hook
= Qnil
;
27589 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
27590 doc
: /* Frame for which we are updating a menu.
27591 The enable predicate for a menu binding should check this variable. */);
27592 Vmenu_updating_frame
= Qnil
;
27594 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
27595 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
27596 inhibit_menubar_update
= 0;
27598 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
27599 doc
: /* Prefix prepended to all continuation lines at display time.
27600 The value may be a string, an image, or a stretch-glyph; it is
27601 interpreted in the same way as the value of a `display' text property.
27603 This variable is overridden by any `wrap-prefix' text or overlay
27606 To add a prefix to non-continuation lines, use `line-prefix'. */);
27607 Vwrap_prefix
= Qnil
;
27608 staticpro (&Qwrap_prefix
);
27609 Qwrap_prefix
= intern_c_string ("wrap-prefix");
27610 Fmake_variable_buffer_local (Qwrap_prefix
);
27612 DEFVAR_LISP ("line-prefix", Vline_prefix
,
27613 doc
: /* Prefix prepended to all non-continuation lines at display time.
27614 The value may be a string, an image, or a stretch-glyph; it is
27615 interpreted in the same way as the value of a `display' text property.
27617 This variable is overridden by any `line-prefix' text or overlay
27620 To add a prefix to continuation lines, use `wrap-prefix'. */);
27621 Vline_prefix
= Qnil
;
27622 staticpro (&Qline_prefix
);
27623 Qline_prefix
= intern_c_string ("line-prefix");
27624 Fmake_variable_buffer_local (Qline_prefix
);
27626 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
27627 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
27628 inhibit_eval_during_redisplay
= 0;
27630 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
27631 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
27632 inhibit_free_realized_faces
= 0;
27635 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
27636 doc
: /* Inhibit try_window_id display optimization. */);
27637 inhibit_try_window_id
= 0;
27639 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
27640 doc
: /* Inhibit try_window_reusing display optimization. */);
27641 inhibit_try_window_reusing
= 0;
27643 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
27644 doc
: /* Inhibit try_cursor_movement display optimization. */);
27645 inhibit_try_cursor_movement
= 0;
27646 #endif /* GLYPH_DEBUG */
27648 DEFVAR_INT ("overline-margin", overline_margin
,
27649 doc
: /* *Space between overline and text, in pixels.
27650 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
27651 margin to the caracter height. */);
27652 overline_margin
= 2;
27654 DEFVAR_INT ("underline-minimum-offset",
27655 underline_minimum_offset
,
27656 doc
: /* Minimum distance between baseline and underline.
27657 This can improve legibility of underlined text at small font sizes,
27658 particularly when using variable `x-use-underline-position-properties'
27659 with fonts that specify an UNDERLINE_POSITION relatively close to the
27660 baseline. The default value is 1. */);
27661 underline_minimum_offset
= 1;
27663 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
27664 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
27665 This feature only works when on a window system that can change
27666 cursor shapes. */);
27667 display_hourglass_p
= 1;
27669 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
27670 doc
: /* *Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
27671 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
27673 hourglass_atimer
= NULL
;
27674 hourglass_shown_p
= 0;
27676 DEFSYM (Qglyphless_char
, "glyphless-char");
27677 DEFSYM (Qhex_code
, "hex-code");
27678 DEFSYM (Qempty_box
, "empty-box");
27679 DEFSYM (Qthin_space
, "thin-space");
27680 DEFSYM (Qzero_width
, "zero-width");
27682 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
27683 /* Intern this now in case it isn't already done.
27684 Setting this variable twice is harmless.
27685 But don't staticpro it here--that is done in alloc.c. */
27686 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
27687 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
27689 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
27690 doc
: /* Char-table defining glyphless characters.
27691 Each element, if non-nil, should be one of the following:
27692 an ASCII acronym string: display this string in a box
27693 `hex-code': display the hexadecimal code of a character in a box
27694 `empty-box': display as an empty box
27695 `thin-space': display as 1-pixel width space
27696 `zero-width': don't display
27697 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
27698 display method for graphical terminals and text terminals respectively.
27699 GRAPHICAL and TEXT should each have one of the values listed above.
27701 The char-table has one extra slot to control the display of a character for
27702 which no font is found. This slot only takes effect on graphical terminals.
27703 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
27704 `thin-space'. The default is `empty-box'. */);
27705 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
27706 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
27711 /* Initialize this module when Emacs starts. */
27716 Lisp_Object root_window
;
27717 struct window
*mini_w
;
27719 current_header_line_height
= current_mode_line_height
= -1;
27721 CHARPOS (this_line_start_pos
) = 0;
27723 mini_w
= XWINDOW (minibuf_window
);
27724 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
27725 echo_area_window
= minibuf_window
;
27727 if (!noninteractive
)
27729 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
27732 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
27733 set_window_height (root_window
,
27734 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
27736 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
27737 set_window_height (minibuf_window
, 1, 0);
27739 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
27740 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
27742 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
27743 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
27744 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
27746 /* The default ellipsis glyphs `...'. */
27747 for (i
= 0; i
< 3; ++i
)
27748 default_invis_vector
[i
] = make_number ('.');
27752 /* Allocate the buffer for frame titles.
27753 Also used for `format-mode-line'. */
27755 mode_line_noprop_buf
= (char *) xmalloc (size
);
27756 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
27757 mode_line_noprop_ptr
= mode_line_noprop_buf
;
27758 mode_line_target
= MODE_LINE_DISPLAY
;
27761 help_echo_showing_p
= 0;
27764 /* Since w32 does not support atimers, it defines its own implementation of
27765 the following three functions in w32fns.c. */
27768 /* Platform-independent portion of hourglass implementation. */
27770 /* Return non-zero if houglass timer has been started or hourglass is shown. */
27772 hourglass_started (void)
27774 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
27777 /* Cancel a currently active hourglass timer, and start a new one. */
27779 start_hourglass (void)
27781 #if defined (HAVE_WINDOW_SYSTEM)
27783 int secs
, usecs
= 0;
27785 cancel_hourglass ();
27787 if (INTEGERP (Vhourglass_delay
)
27788 && XINT (Vhourglass_delay
) > 0)
27789 secs
= XFASTINT (Vhourglass_delay
);
27790 else if (FLOATP (Vhourglass_delay
)
27791 && XFLOAT_DATA (Vhourglass_delay
) > 0)
27794 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
27795 secs
= XFASTINT (tem
);
27796 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
27799 secs
= DEFAULT_HOURGLASS_DELAY
;
27801 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
27802 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
27803 show_hourglass
, NULL
);
27808 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
27811 cancel_hourglass (void)
27813 #if defined (HAVE_WINDOW_SYSTEM)
27814 if (hourglass_atimer
)
27816 cancel_atimer (hourglass_atimer
);
27817 hourglass_atimer
= NULL
;
27820 if (hourglass_shown_p
)
27824 #endif /* ! WINDOWSNT */