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
;
4399 /* Say that we haven't consumed the characters with
4400 `display' property yet. The call to pop_it in
4401 set_iterator_to_next will clean this up. */
4402 *position
= start_pos
;
4404 if (EQ (XCAR (spec
), Qleft_fringe
))
4406 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4407 it
->left_user_fringe_face_id
= face_id
;
4411 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4412 it
->right_user_fringe_face_id
= face_id
;
4415 #endif /* HAVE_WINDOW_SYSTEM */
4419 /* Prepare to handle `((margin left-margin) ...)',
4420 `((margin right-margin) ...)' and `((margin nil) ...)'
4421 prefixes for display specifications. */
4422 location
= Qunbound
;
4423 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4427 value
= XCDR (spec
);
4429 value
= XCAR (value
);
4432 if (EQ (XCAR (tem
), Qmargin
)
4433 && (tem
= XCDR (tem
),
4434 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4436 || EQ (tem
, Qleft_margin
)
4437 || EQ (tem
, Qright_margin
))))
4441 if (EQ (location
, Qunbound
))
4447 /* After this point, VALUE is the property after any
4448 margin prefix has been stripped. It must be a string,
4449 an image specification, or `(space ...)'.
4451 LOCATION specifies where to display: `left-margin',
4452 `right-margin' or nil. */
4454 valid_p
= (STRINGP (value
)
4455 #ifdef HAVE_WINDOW_SYSTEM
4456 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4457 && valid_image_p (value
))
4458 #endif /* not HAVE_WINDOW_SYSTEM */
4459 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4461 if (valid_p
&& !display_replaced_p
)
4466 /* Save current settings of IT so that we can restore them
4467 when we are finished with the glyph property value. */
4468 push_it (it
, position
);
4469 it
->from_overlay
= overlay
;
4471 if (NILP (location
))
4472 it
->area
= TEXT_AREA
;
4473 else if (EQ (location
, Qleft_margin
))
4474 it
->area
= LEFT_MARGIN_AREA
;
4476 it
->area
= RIGHT_MARGIN_AREA
;
4478 if (STRINGP (value
))
4481 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4482 it
->current
.overlay_string_index
= -1;
4483 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4484 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4485 it
->method
= GET_FROM_STRING
;
4486 it
->stop_charpos
= 0;
4488 it
->base_level_stop
= 0;
4489 it
->string_from_display_prop_p
= 1;
4490 /* Say that we haven't consumed the characters with
4491 `display' property yet. The call to pop_it in
4492 set_iterator_to_next will clean this up. */
4493 if (BUFFERP (object
))
4494 *position
= start_pos
;
4496 /* Force paragraph direction to be that of the parent
4498 it
->paragraph_embedding
=
4499 (it
->bidi_p
? it
->bidi_it
.paragraph_dir
: L2R
);
4501 /* Set up the bidi iterator for this display string. */
4504 it
->bidi_it
.string
.lstring
= it
->string
;
4505 it
->bidi_it
.string
.s
= NULL
;
4506 it
->bidi_it
.string
.schars
= it
->end_charpos
;
4507 it
->bidi_it
.string
.bufpos
= bufpos
;
4508 it
->bidi_it
.string
.from_disp_str
= 1;
4509 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
4510 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4513 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4515 it
->method
= GET_FROM_STRETCH
;
4517 *position
= it
->position
= start_pos
;
4519 #ifdef HAVE_WINDOW_SYSTEM
4522 it
->what
= IT_IMAGE
;
4523 it
->image_id
= lookup_image (it
->f
, value
);
4524 it
->position
= start_pos
;
4525 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4526 it
->method
= GET_FROM_IMAGE
;
4528 /* Say that we haven't consumed the characters with
4529 `display' property yet. The call to pop_it in
4530 set_iterator_to_next will clean this up. */
4531 *position
= start_pos
;
4533 #endif /* HAVE_WINDOW_SYSTEM */
4538 /* Invalid property or property not supported. Restore
4539 POSITION to what it was before. */
4540 *position
= start_pos
;
4544 /* Check if PROP is a display property value whose text should be
4545 treated as intangible. OVERLAY is the overlay from which PROP
4546 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4547 specify the buffer position covered by PROP. */
4550 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4551 EMACS_INT charpos
, EMACS_INT bytepos
)
4553 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4554 struct text_pos position
;
4556 SET_TEXT_POS (position
, charpos
, bytepos
);
4557 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4558 &position
, charpos
, frame_window_p
);
4562 /* Return 1 if PROP is a display sub-property value containing STRING.
4564 Implementation note: this and the following function are really
4565 special cases of handle_display_spec and
4566 handle_single_display_spec, and should ideally use the same code.
4567 Until they do, these two pairs must be consistent and must be
4568 modified in sync. */
4571 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4573 if (EQ (string
, prop
))
4576 /* Skip over `when FORM'. */
4577 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4582 /* Actually, the condition following `when' should be eval'ed,
4583 like handle_single_display_spec does, and we should return
4584 zero if it evaluates to nil. However, this function is
4585 called only when the buffer was already displayed and some
4586 glyph in the glyph matrix was found to come from a display
4587 string. Therefore, the condition was already evaluated, and
4588 the result was non-nil, otherwise the display string wouldn't
4589 have been displayed and we would have never been called for
4590 this property. Thus, we can skip the evaluation and assume
4591 its result is non-nil. */
4596 /* Skip over `margin LOCATION'. */
4597 if (EQ (XCAR (prop
), Qmargin
))
4608 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
4612 /* Return 1 if STRING appears in the `display' property PROP. */
4615 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4618 && !EQ (XCAR (prop
), Qwhen
)
4619 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
4621 /* A list of sub-properties. */
4622 while (CONSP (prop
))
4624 if (single_display_spec_string_p (XCAR (prop
), string
))
4629 else if (VECTORP (prop
))
4631 /* A vector of sub-properties. */
4633 for (i
= 0; i
< ASIZE (prop
); ++i
)
4634 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4638 return single_display_spec_string_p (prop
, string
);
4643 /* Look for STRING in overlays and text properties in the current
4644 buffer, between character positions FROM and TO (excluding TO).
4645 BACK_P non-zero means look back (in this case, TO is supposed to be
4647 Value is the first character position where STRING was found, or
4648 zero if it wasn't found before hitting TO.
4650 This function may only use code that doesn't eval because it is
4651 called asynchronously from note_mouse_highlight. */
4654 string_buffer_position_lim (Lisp_Object string
,
4655 EMACS_INT from
, EMACS_INT to
, int back_p
)
4657 Lisp_Object limit
, prop
, pos
;
4660 pos
= make_number (from
);
4662 if (!back_p
) /* looking forward */
4664 limit
= make_number (min (to
, ZV
));
4665 while (!found
&& !EQ (pos
, limit
))
4667 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4668 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4671 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4675 else /* looking back */
4677 limit
= make_number (max (to
, BEGV
));
4678 while (!found
&& !EQ (pos
, limit
))
4680 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4681 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4684 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4689 return found
? XINT (pos
) : 0;
4692 /* Determine which buffer position in current buffer STRING comes from.
4693 AROUND_CHARPOS is an approximate position where it could come from.
4694 Value is the buffer position or 0 if it couldn't be determined.
4696 This function is necessary because we don't record buffer positions
4697 in glyphs generated from strings (to keep struct glyph small).
4698 This function may only use code that doesn't eval because it is
4699 called asynchronously from note_mouse_highlight. */
4702 string_buffer_position (Lisp_Object string
, EMACS_INT around_charpos
)
4704 const int MAX_DISTANCE
= 1000;
4705 EMACS_INT found
= string_buffer_position_lim (string
, around_charpos
,
4706 around_charpos
+ MAX_DISTANCE
,
4710 found
= string_buffer_position_lim (string
, around_charpos
,
4711 around_charpos
- MAX_DISTANCE
, 1);
4717 /***********************************************************************
4718 `composition' property
4719 ***********************************************************************/
4721 /* Set up iterator IT from `composition' property at its current
4722 position. Called from handle_stop. */
4724 static enum prop_handled
4725 handle_composition_prop (struct it
*it
)
4727 Lisp_Object prop
, string
;
4728 EMACS_INT pos
, pos_byte
, start
, end
;
4730 if (STRINGP (it
->string
))
4734 pos
= IT_STRING_CHARPOS (*it
);
4735 pos_byte
= IT_STRING_BYTEPOS (*it
);
4736 string
= it
->string
;
4737 s
= SDATA (string
) + pos_byte
;
4738 it
->c
= STRING_CHAR (s
);
4742 pos
= IT_CHARPOS (*it
);
4743 pos_byte
= IT_BYTEPOS (*it
);
4745 it
->c
= FETCH_CHAR (pos_byte
);
4748 /* If there's a valid composition and point is not inside of the
4749 composition (in the case that the composition is from the current
4750 buffer), draw a glyph composed from the composition components. */
4751 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4752 && COMPOSITION_VALID_P (start
, end
, prop
)
4753 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4757 if (STRINGP (it
->string
))
4758 pos_byte
= string_char_to_byte (it
->string
, start
);
4760 pos_byte
= CHAR_TO_BYTE (start
);
4762 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4765 if (it
->cmp_it
.id
>= 0)
4768 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4769 it
->cmp_it
.nglyphs
= -1;
4773 return HANDLED_NORMALLY
;
4778 /***********************************************************************
4780 ***********************************************************************/
4782 /* The following structure is used to record overlay strings for
4783 later sorting in load_overlay_strings. */
4785 struct overlay_entry
4787 Lisp_Object overlay
;
4794 /* Set up iterator IT from overlay strings at its current position.
4795 Called from handle_stop. */
4797 static enum prop_handled
4798 handle_overlay_change (struct it
*it
)
4800 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4801 return HANDLED_RECOMPUTE_PROPS
;
4803 return HANDLED_NORMALLY
;
4807 /* Set up the next overlay string for delivery by IT, if there is an
4808 overlay string to deliver. Called by set_iterator_to_next when the
4809 end of the current overlay string is reached. If there are more
4810 overlay strings to display, IT->string and
4811 IT->current.overlay_string_index are set appropriately here.
4812 Otherwise IT->string is set to nil. */
4815 next_overlay_string (struct it
*it
)
4817 ++it
->current
.overlay_string_index
;
4818 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4820 /* No more overlay strings. Restore IT's settings to what
4821 they were before overlay strings were processed, and
4822 continue to deliver from current_buffer. */
4824 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4827 || (NILP (it
->string
)
4828 && it
->method
== GET_FROM_BUFFER
4829 && it
->stop_charpos
>= BEGV
4830 && it
->stop_charpos
<= it
->end_charpos
));
4831 it
->current
.overlay_string_index
= -1;
4832 it
->n_overlay_strings
= 0;
4833 it
->overlay_strings_charpos
= -1;
4835 /* If we're at the end of the buffer, record that we have
4836 processed the overlay strings there already, so that
4837 next_element_from_buffer doesn't try it again. */
4838 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4839 it
->overlay_strings_at_end_processed_p
= 1;
4843 /* There are more overlay strings to process. If
4844 IT->current.overlay_string_index has advanced to a position
4845 where we must load IT->overlay_strings with more strings, do
4846 it. We must load at the IT->overlay_strings_charpos where
4847 IT->n_overlay_strings was originally computed; when invisible
4848 text is present, this might not be IT_CHARPOS (Bug#7016). */
4849 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4851 if (it
->current
.overlay_string_index
&& i
== 0)
4852 load_overlay_strings (it
, it
->overlay_strings_charpos
);
4854 /* Initialize IT to deliver display elements from the overlay
4856 it
->string
= it
->overlay_strings
[i
];
4857 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4858 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4859 it
->method
= GET_FROM_STRING
;
4860 it
->stop_charpos
= 0;
4861 if (it
->cmp_it
.stop_pos
>= 0)
4862 it
->cmp_it
.stop_pos
= 0;
4864 it
->base_level_stop
= 0;
4866 /* Set up the bidi iterator for this overlay string. */
4869 it
->bidi_it
.string
.lstring
= it
->string
;
4870 it
->bidi_it
.string
.s
= NULL
;
4871 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
4872 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
4873 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
4874 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
4875 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4883 /* Compare two overlay_entry structures E1 and E2. Used as a
4884 comparison function for qsort in load_overlay_strings. Overlay
4885 strings for the same position are sorted so that
4887 1. All after-strings come in front of before-strings, except
4888 when they come from the same overlay.
4890 2. Within after-strings, strings are sorted so that overlay strings
4891 from overlays with higher priorities come first.
4893 2. Within before-strings, strings are sorted so that overlay
4894 strings from overlays with higher priorities come last.
4896 Value is analogous to strcmp. */
4900 compare_overlay_entries (const void *e1
, const void *e2
)
4902 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4903 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4906 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4908 /* Let after-strings appear in front of before-strings if
4909 they come from different overlays. */
4910 if (EQ (entry1
->overlay
, entry2
->overlay
))
4911 result
= entry1
->after_string_p
? 1 : -1;
4913 result
= entry1
->after_string_p
? -1 : 1;
4915 else if (entry1
->after_string_p
)
4916 /* After-strings sorted in order of decreasing priority. */
4917 result
= entry2
->priority
- entry1
->priority
;
4919 /* Before-strings sorted in order of increasing priority. */
4920 result
= entry1
->priority
- entry2
->priority
;
4926 /* Load the vector IT->overlay_strings with overlay strings from IT's
4927 current buffer position, or from CHARPOS if that is > 0. Set
4928 IT->n_overlays to the total number of overlay strings found.
4930 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4931 a time. On entry into load_overlay_strings,
4932 IT->current.overlay_string_index gives the number of overlay
4933 strings that have already been loaded by previous calls to this
4936 IT->add_overlay_start contains an additional overlay start
4937 position to consider for taking overlay strings from, if non-zero.
4938 This position comes into play when the overlay has an `invisible'
4939 property, and both before and after-strings. When we've skipped to
4940 the end of the overlay, because of its `invisible' property, we
4941 nevertheless want its before-string to appear.
4942 IT->add_overlay_start will contain the overlay start position
4945 Overlay strings are sorted so that after-string strings come in
4946 front of before-string strings. Within before and after-strings,
4947 strings are sorted by overlay priority. See also function
4948 compare_overlay_entries. */
4951 load_overlay_strings (struct it
*it
, EMACS_INT charpos
)
4953 Lisp_Object overlay
, window
, str
, invisible
;
4954 struct Lisp_Overlay
*ov
;
4955 EMACS_INT start
, end
;
4957 int n
= 0, i
, j
, invis_p
;
4958 struct overlay_entry
*entries
4959 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4962 charpos
= IT_CHARPOS (*it
);
4964 /* Append the overlay string STRING of overlay OVERLAY to vector
4965 `entries' which has size `size' and currently contains `n'
4966 elements. AFTER_P non-zero means STRING is an after-string of
4968 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4971 Lisp_Object priority; \
4975 int new_size = 2 * size; \
4976 struct overlay_entry *old = entries; \
4978 (struct overlay_entry *) alloca (new_size \
4979 * sizeof *entries); \
4980 memcpy (entries, old, size * sizeof *entries); \
4984 entries[n].string = (STRING); \
4985 entries[n].overlay = (OVERLAY); \
4986 priority = Foverlay_get ((OVERLAY), Qpriority); \
4987 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4988 entries[n].after_string_p = (AFTER_P); \
4993 /* Process overlay before the overlay center. */
4994 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4996 XSETMISC (overlay
, ov
);
4997 xassert (OVERLAYP (overlay
));
4998 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4999 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5004 /* Skip this overlay if it doesn't start or end at IT's current
5006 if (end
!= charpos
&& start
!= charpos
)
5009 /* Skip this overlay if it doesn't apply to IT->w. */
5010 window
= Foverlay_get (overlay
, Qwindow
);
5011 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5014 /* If the text ``under'' the overlay is invisible, both before-
5015 and after-strings from this overlay are visible; start and
5016 end position are indistinguishable. */
5017 invisible
= Foverlay_get (overlay
, Qinvisible
);
5018 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5020 /* If overlay has a non-empty before-string, record it. */
5021 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5022 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5024 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5026 /* If overlay has a non-empty after-string, record it. */
5027 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5028 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5030 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5033 /* Process overlays after the overlay center. */
5034 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5036 XSETMISC (overlay
, ov
);
5037 xassert (OVERLAYP (overlay
));
5038 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5039 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5041 if (start
> charpos
)
5044 /* Skip this overlay if it doesn't start or end at IT's current
5046 if (end
!= charpos
&& start
!= charpos
)
5049 /* Skip this overlay if it doesn't apply to IT->w. */
5050 window
= Foverlay_get (overlay
, Qwindow
);
5051 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5054 /* If the text ``under'' the overlay is invisible, it has a zero
5055 dimension, and both before- and after-strings apply. */
5056 invisible
= Foverlay_get (overlay
, Qinvisible
);
5057 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5059 /* If overlay has a non-empty before-string, record it. */
5060 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5061 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5063 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5065 /* If overlay has a non-empty after-string, record it. */
5066 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5067 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5069 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5072 #undef RECORD_OVERLAY_STRING
5076 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5078 /* Record number of overlay strings, and where we computed it. */
5079 it
->n_overlay_strings
= n
;
5080 it
->overlay_strings_charpos
= charpos
;
5082 /* IT->current.overlay_string_index is the number of overlay strings
5083 that have already been consumed by IT. Copy some of the
5084 remaining overlay strings to IT->overlay_strings. */
5086 j
= it
->current
.overlay_string_index
;
5087 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5089 it
->overlay_strings
[i
] = entries
[j
].string
;
5090 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5097 /* Get the first chunk of overlay strings at IT's current buffer
5098 position, or at CHARPOS if that is > 0. Value is non-zero if at
5099 least one overlay string was found. */
5102 get_overlay_strings_1 (struct it
*it
, EMACS_INT charpos
, int compute_stop_p
)
5104 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5105 process. This fills IT->overlay_strings with strings, and sets
5106 IT->n_overlay_strings to the total number of strings to process.
5107 IT->pos.overlay_string_index has to be set temporarily to zero
5108 because load_overlay_strings needs this; it must be set to -1
5109 when no overlay strings are found because a zero value would
5110 indicate a position in the first overlay string. */
5111 it
->current
.overlay_string_index
= 0;
5112 load_overlay_strings (it
, charpos
);
5114 /* If we found overlay strings, set up IT to deliver display
5115 elements from the first one. Otherwise set up IT to deliver
5116 from current_buffer. */
5117 if (it
->n_overlay_strings
)
5119 /* Make sure we know settings in current_buffer, so that we can
5120 restore meaningful values when we're done with the overlay
5123 compute_stop_pos (it
);
5124 xassert (it
->face_id
>= 0);
5126 /* Save IT's settings. They are restored after all overlay
5127 strings have been processed. */
5128 xassert (!compute_stop_p
|| it
->sp
== 0);
5130 /* When called from handle_stop, there might be an empty display
5131 string loaded. In that case, don't bother saving it. */
5132 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5135 /* Set up IT to deliver display elements from the first overlay
5137 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5138 it
->string
= it
->overlay_strings
[0];
5139 it
->from_overlay
= Qnil
;
5140 it
->stop_charpos
= 0;
5141 xassert (STRINGP (it
->string
));
5142 it
->end_charpos
= SCHARS (it
->string
);
5144 it
->base_level_stop
= 0;
5145 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5146 it
->method
= GET_FROM_STRING
;
5148 /* Force paragraph direction to be that of the parent
5150 it
->paragraph_embedding
= (it
->bidi_p
? it
->bidi_it
.paragraph_dir
: L2R
);
5152 /* Set up the bidi iterator for this overlay string. */
5155 EMACS_INT pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5157 it
->bidi_it
.string
.lstring
= it
->string
;
5158 it
->bidi_it
.string
.s
= NULL
;
5159 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5160 it
->bidi_it
.string
.bufpos
= pos
;
5161 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5162 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5163 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5168 it
->current
.overlay_string_index
= -1;
5173 get_overlay_strings (struct it
*it
, EMACS_INT charpos
)
5176 it
->method
= GET_FROM_BUFFER
;
5178 (void) get_overlay_strings_1 (it
, charpos
, 1);
5182 /* Value is non-zero if we found at least one overlay string. */
5183 return STRINGP (it
->string
);
5188 /***********************************************************************
5189 Saving and restoring state
5190 ***********************************************************************/
5192 /* Save current settings of IT on IT->stack. Called, for example,
5193 before setting up IT for an overlay string, to be able to restore
5194 IT's settings to what they were after the overlay string has been
5195 processed. If POSITION is non-NULL, it is the position to save on
5196 the stack instead of IT->position. */
5199 push_it (struct it
*it
, struct text_pos
*position
)
5201 struct iterator_stack_entry
*p
;
5203 xassert (it
->sp
< IT_STACK_SIZE
);
5204 p
= it
->stack
+ it
->sp
;
5206 p
->stop_charpos
= it
->stop_charpos
;
5207 p
->prev_stop
= it
->prev_stop
;
5208 p
->base_level_stop
= it
->base_level_stop
;
5209 p
->cmp_it
= it
->cmp_it
;
5210 xassert (it
->face_id
>= 0);
5211 p
->face_id
= it
->face_id
;
5212 p
->string
= it
->string
;
5213 p
->method
= it
->method
;
5214 p
->from_overlay
= it
->from_overlay
;
5217 case GET_FROM_IMAGE
:
5218 p
->u
.image
.object
= it
->object
;
5219 p
->u
.image
.image_id
= it
->image_id
;
5220 p
->u
.image
.slice
= it
->slice
;
5222 case GET_FROM_STRETCH
:
5223 p
->u
.stretch
.object
= it
->object
;
5226 p
->position
= position
? *position
: it
->position
;
5227 p
->current
= it
->current
;
5228 p
->end_charpos
= it
->end_charpos
;
5229 p
->string_nchars
= it
->string_nchars
;
5231 p
->multibyte_p
= it
->multibyte_p
;
5232 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5233 p
->space_width
= it
->space_width
;
5234 p
->font_height
= it
->font_height
;
5235 p
->voffset
= it
->voffset
;
5236 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5237 p
->display_ellipsis_p
= 0;
5238 p
->line_wrap
= it
->line_wrap
;
5239 p
->bidi_p
= it
->bidi_p
;
5240 p
->paragraph_embedding
= it
->paragraph_embedding
;
5243 /* Save the state of the bidi iterator as well. */
5245 bidi_push_it (&it
->bidi_it
);
5249 iterate_out_of_display_property (struct it
*it
)
5251 int buffer_p
= BUFFERP (it
->object
);
5252 EMACS_INT eob
= (buffer_p
? ZV
: it
->end_charpos
);
5253 EMACS_INT bob
= (buffer_p
? BEGV
: 0);
5255 /* Maybe initialize paragraph direction. If we are at the beginning
5256 of a new paragraph, next_element_from_buffer may not have a
5257 chance to do that. */
5258 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5259 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5260 /* prev_stop can be zero, so check against BEGV as well. */
5261 while (it
->bidi_it
.charpos
>= bob
5262 && it
->prev_stop
<= it
->bidi_it
.charpos
5263 && it
->bidi_it
.charpos
< CHARPOS (it
->position
))
5264 bidi_move_to_visually_next (&it
->bidi_it
);
5265 /* Record the stop_pos we just crossed, for when we cross it
5267 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5268 it
->prev_stop
= CHARPOS (it
->position
);
5269 /* If we ended up not where pop_it put us, resync IT's
5270 positional members with the bidi iterator. */
5271 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5273 SET_TEXT_POS (it
->position
,
5274 it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5276 it
->current
.pos
= it
->position
;
5278 it
->current
.string_pos
= it
->position
;
5282 /* Restore IT's settings from IT->stack. Called, for example, when no
5283 more overlay strings must be processed, and we return to delivering
5284 display elements from a buffer, or when the end of a string from a
5285 `display' property is reached and we return to delivering display
5286 elements from an overlay string, or from a buffer. */
5289 pop_it (struct it
*it
)
5291 struct iterator_stack_entry
*p
;
5293 xassert (it
->sp
> 0);
5295 p
= it
->stack
+ it
->sp
;
5296 it
->stop_charpos
= p
->stop_charpos
;
5297 it
->prev_stop
= p
->prev_stop
;
5298 it
->base_level_stop
= p
->base_level_stop
;
5299 it
->cmp_it
= p
->cmp_it
;
5300 it
->face_id
= p
->face_id
;
5301 it
->current
= p
->current
;
5302 it
->position
= p
->position
;
5303 it
->string
= p
->string
;
5304 it
->from_overlay
= p
->from_overlay
;
5305 if (NILP (it
->string
))
5306 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5307 it
->method
= p
->method
;
5310 case GET_FROM_IMAGE
:
5311 it
->image_id
= p
->u
.image
.image_id
;
5312 it
->object
= p
->u
.image
.object
;
5313 it
->slice
= p
->u
.image
.slice
;
5315 case GET_FROM_STRETCH
:
5316 it
->object
= p
->u
.comp
.object
;
5318 case GET_FROM_BUFFER
:
5319 it
->object
= it
->w
->buffer
;
5321 case GET_FROM_STRING
:
5322 it
->object
= it
->string
;
5324 case GET_FROM_DISPLAY_VECTOR
:
5326 it
->method
= GET_FROM_C_STRING
;
5327 else if (STRINGP (it
->string
))
5328 it
->method
= GET_FROM_STRING
;
5331 it
->method
= GET_FROM_BUFFER
;
5332 it
->object
= it
->w
->buffer
;
5335 it
->end_charpos
= p
->end_charpos
;
5336 it
->string_nchars
= p
->string_nchars
;
5338 it
->multibyte_p
= p
->multibyte_p
;
5339 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5340 it
->space_width
= p
->space_width
;
5341 it
->font_height
= p
->font_height
;
5342 it
->voffset
= p
->voffset
;
5343 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5344 it
->line_wrap
= p
->line_wrap
;
5345 it
->bidi_p
= p
->bidi_p
;
5346 it
->paragraph_embedding
= p
->paragraph_embedding
;
5349 bidi_pop_it (&it
->bidi_it
);
5350 /* Bidi-iterate until we get out of the portion of text, if any,
5351 covered by a `display' text property or by an overlay with
5352 `display' property. (We cannot just jump there, because the
5353 internal coherency of the bidi iterator state can not be
5354 preserved across such jumps.) We also must determine the
5355 paragraph base direction if the overlay we just processed is
5356 at the beginning of a new paragraph. */
5357 if (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
)
5358 iterate_out_of_display_property (it
);
5364 /***********************************************************************
5366 ***********************************************************************/
5368 /* Set IT's current position to the previous line start. */
5371 back_to_previous_line_start (struct it
*it
)
5373 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5374 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5378 /* Move IT to the next line start.
5380 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5381 we skipped over part of the text (as opposed to moving the iterator
5382 continuously over the text). Otherwise, don't change the value
5385 Newlines may come from buffer text, overlay strings, or strings
5386 displayed via the `display' property. That's the reason we can't
5387 simply use find_next_newline_no_quit.
5389 Note that this function may not skip over invisible text that is so
5390 because of text properties and immediately follows a newline. If
5391 it would, function reseat_at_next_visible_line_start, when called
5392 from set_iterator_to_next, would effectively make invisible
5393 characters following a newline part of the wrong glyph row, which
5394 leads to wrong cursor motion. */
5397 forward_to_next_line_start (struct it
*it
, int *skipped_p
)
5399 int old_selective
, newline_found_p
, n
;
5400 const int MAX_NEWLINE_DISTANCE
= 500;
5402 /* If already on a newline, just consume it to avoid unintended
5403 skipping over invisible text below. */
5404 if (it
->what
== IT_CHARACTER
5406 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5408 set_iterator_to_next (it
, 0);
5413 /* Don't handle selective display in the following. It's (a)
5414 unnecessary because it's done by the caller, and (b) leads to an
5415 infinite recursion because next_element_from_ellipsis indirectly
5416 calls this function. */
5417 old_selective
= it
->selective
;
5420 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5421 from buffer text. */
5422 for (n
= newline_found_p
= 0;
5423 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5424 n
+= STRINGP (it
->string
) ? 0 : 1)
5426 if (!get_next_display_element (it
))
5428 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5429 set_iterator_to_next (it
, 0);
5432 /* If we didn't find a newline near enough, see if we can use a
5434 if (!newline_found_p
)
5436 EMACS_INT start
= IT_CHARPOS (*it
);
5437 EMACS_INT limit
= find_next_newline_no_quit (start
, 1);
5440 xassert (!STRINGP (it
->string
));
5442 /* If we are not bidi-reordering, and there isn't any `display'
5443 property in sight, and no overlays, we can just use the
5444 position of the newline in buffer text. */
5446 && (it
->stop_charpos
>= limit
5447 || ((pos
= Fnext_single_property_change (make_number (start
),
5449 make_number (limit
)),
5451 && next_overlay_change (start
) == ZV
)))
5453 IT_CHARPOS (*it
) = limit
;
5454 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5455 *skipped_p
= newline_found_p
= 1;
5459 while (get_next_display_element (it
)
5460 && !newline_found_p
)
5462 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5463 set_iterator_to_next (it
, 0);
5468 it
->selective
= old_selective
;
5469 return newline_found_p
;
5473 /* Set IT's current position to the previous visible line start. Skip
5474 invisible text that is so either due to text properties or due to
5475 selective display. Caution: this does not change IT->current_x and
5479 back_to_previous_visible_line_start (struct it
*it
)
5481 while (IT_CHARPOS (*it
) > BEGV
)
5483 back_to_previous_line_start (it
);
5485 if (IT_CHARPOS (*it
) <= BEGV
)
5488 /* If selective > 0, then lines indented more than its value are
5490 if (it
->selective
> 0
5491 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5492 (double) it
->selective
)) /* iftc */
5495 /* Check the newline before point for invisibility. */
5498 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5499 Qinvisible
, it
->window
);
5500 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5504 if (IT_CHARPOS (*it
) <= BEGV
)
5511 Lisp_Object val
, overlay
;
5513 /* If newline is part of a composition, continue from start of composition */
5514 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5515 && beg
< IT_CHARPOS (*it
))
5518 /* If newline is replaced by a display property, find start of overlay
5519 or interval and continue search from that point. */
5521 pos
= --IT_CHARPOS (it2
);
5524 it2
.string_from_display_prop_p
= 0;
5525 if (handle_display_prop (&it2
) == HANDLED_RETURN
5526 && !NILP (val
= get_char_property_and_overlay
5527 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5528 && (OVERLAYP (overlay
)
5529 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5530 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5532 /* If the call to handle_display_prop above pushed the
5533 iterator state, that causes side effects for the bidi
5534 iterator by calling bidi_push_it. Undo those side
5538 /* push_it calls bidi_push_it only if the bidi_p flag
5539 is set in the iterator being pushed. */
5540 if (it2
.stack
[--it2
.sp
].bidi_p
)
5541 bidi_pop_it (&it2
.bidi_it
);
5546 /* Newline is not replaced by anything -- so we are done. */
5552 IT_CHARPOS (*it
) = beg
;
5553 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5557 it
->continuation_lines_width
= 0;
5559 xassert (IT_CHARPOS (*it
) >= BEGV
);
5560 xassert (IT_CHARPOS (*it
) == BEGV
5561 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5566 /* Reseat iterator IT at the previous visible line start. Skip
5567 invisible text that is so either due to text properties or due to
5568 selective display. At the end, update IT's overlay information,
5569 face information etc. */
5572 reseat_at_previous_visible_line_start (struct it
*it
)
5574 back_to_previous_visible_line_start (it
);
5575 reseat (it
, it
->current
.pos
, 1);
5580 /* Reseat iterator IT on the next visible line start in the current
5581 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5582 preceding the line start. Skip over invisible text that is so
5583 because of selective display. Compute faces, overlays etc at the
5584 new position. Note that this function does not skip over text that
5585 is invisible because of text properties. */
5588 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5590 int newline_found_p
, skipped_p
= 0;
5592 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5594 /* Skip over lines that are invisible because they are indented
5595 more than the value of IT->selective. */
5596 if (it
->selective
> 0)
5597 while (IT_CHARPOS (*it
) < ZV
5598 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5599 (double) it
->selective
)) /* iftc */
5601 xassert (IT_BYTEPOS (*it
) == BEGV
5602 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5603 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5606 /* Position on the newline if that's what's requested. */
5607 if (on_newline_p
&& newline_found_p
)
5609 if (STRINGP (it
->string
))
5611 if (IT_STRING_CHARPOS (*it
) > 0)
5615 --IT_STRING_CHARPOS (*it
);
5616 --IT_STRING_BYTEPOS (*it
);
5619 /* Setting this flag will cause
5620 bidi_move_to_visually_next not to advance, but
5621 instead deliver the current character (newline),
5622 which is what the ON_NEWLINE_P flag wants. */
5623 it
->bidi_it
.first_elt
= 1;
5626 else if (IT_CHARPOS (*it
) > BEGV
)
5633 /* With bidi iteration, the call to `reseat' will cause
5634 bidi_move_to_visually_next deliver the current character,
5635 the newline, instead of advancing. */
5636 reseat (it
, it
->current
.pos
, 0);
5640 reseat (it
, it
->current
.pos
, 0);
5647 /***********************************************************************
5648 Changing an iterator's position
5649 ***********************************************************************/
5651 /* Change IT's current position to POS in current_buffer. If FORCE_P
5652 is non-zero, always check for text properties at the new position.
5653 Otherwise, text properties are only looked up if POS >=
5654 IT->check_charpos of a property. */
5657 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
5659 EMACS_INT original_pos
= IT_CHARPOS (*it
);
5661 reseat_1 (it
, pos
, 0);
5663 /* Determine where to check text properties. Avoid doing it
5664 where possible because text property lookup is very expensive. */
5666 || CHARPOS (pos
) > it
->stop_charpos
5667 || CHARPOS (pos
) < original_pos
)
5671 /* For bidi iteration, we need to prime prev_stop and
5672 base_level_stop with our best estimations. */
5673 if (CHARPOS (pos
) < it
->prev_stop
)
5675 handle_stop_backwards (it
, BEGV
);
5676 if (CHARPOS (pos
) < it
->base_level_stop
)
5677 it
->base_level_stop
= 0;
5679 else if (CHARPOS (pos
) > it
->stop_charpos
5680 && it
->stop_charpos
>= BEGV
)
5681 handle_stop_backwards (it
, it
->stop_charpos
);
5688 it
->prev_stop
= it
->base_level_stop
= 0;
5697 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5698 IT->stop_pos to POS, also. */
5701 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
5703 /* Don't call this function when scanning a C string. */
5704 xassert (it
->s
== NULL
);
5706 /* POS must be a reasonable value. */
5707 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5709 it
->current
.pos
= it
->position
= pos
;
5710 it
->end_charpos
= ZV
;
5712 it
->current
.dpvec_index
= -1;
5713 it
->current
.overlay_string_index
= -1;
5714 IT_STRING_CHARPOS (*it
) = -1;
5715 IT_STRING_BYTEPOS (*it
) = -1;
5717 it
->method
= GET_FROM_BUFFER
;
5718 it
->object
= it
->w
->buffer
;
5719 it
->area
= TEXT_AREA
;
5720 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
5722 it
->string_from_display_prop_p
= 0;
5723 it
->face_before_selective_p
= 0;
5726 it
->bidi_it
.first_elt
= 1;
5727 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5728 it
->bidi_it
.disp_pos
= -1;
5729 it
->bidi_it
.string
.s
= NULL
;
5730 it
->bidi_it
.string
.lstring
= Qnil
;
5731 it
->bidi_it
.string
.bufpos
= 0;
5732 it
->bidi_it
.string
.unibyte
= 0;
5737 it
->stop_charpos
= CHARPOS (pos
);
5738 it
->base_level_stop
= CHARPOS (pos
);
5743 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5744 If S is non-null, it is a C string to iterate over. Otherwise,
5745 STRING gives a Lisp string to iterate over.
5747 If PRECISION > 0, don't return more then PRECISION number of
5748 characters from the string.
5750 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5751 characters have been returned. FIELD_WIDTH < 0 means an infinite
5754 MULTIBYTE = 0 means disable processing of multibyte characters,
5755 MULTIBYTE > 0 means enable it,
5756 MULTIBYTE < 0 means use IT->multibyte_p.
5758 IT must be initialized via a prior call to init_iterator before
5759 calling this function. */
5762 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
5763 EMACS_INT charpos
, EMACS_INT precision
, int field_width
,
5766 /* No region in strings. */
5767 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5769 /* No text property checks performed by default, but see below. */
5770 it
->stop_charpos
= -1;
5772 /* Set iterator position and end position. */
5773 memset (&it
->current
, 0, sizeof it
->current
);
5774 it
->current
.overlay_string_index
= -1;
5775 it
->current
.dpvec_index
= -1;
5776 xassert (charpos
>= 0);
5778 /* If STRING is specified, use its multibyteness, otherwise use the
5779 setting of MULTIBYTE, if specified. */
5781 it
->multibyte_p
= multibyte
> 0;
5783 /* Bidirectional reordering of strings is controlled by the default
5784 value of bidi-display-reordering. */
5785 it
->bidi_p
= !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
5789 xassert (STRINGP (string
));
5790 it
->string
= string
;
5792 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5793 it
->method
= GET_FROM_STRING
;
5794 it
->current
.string_pos
= string_pos (charpos
, string
);
5798 it
->bidi_it
.string
.lstring
= string
;
5799 it
->bidi_it
.string
.s
= NULL
;
5800 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5801 it
->bidi_it
.string
.bufpos
= 0;
5802 it
->bidi_it
.string
.from_disp_str
= 0;
5803 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5804 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
5805 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5810 it
->s
= (const unsigned char *) s
;
5813 /* Note that we use IT->current.pos, not it->current.string_pos,
5814 for displaying C strings. */
5815 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5816 if (it
->multibyte_p
)
5818 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5819 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5823 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5824 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5829 it
->bidi_it
.string
.lstring
= Qnil
;
5830 it
->bidi_it
.string
.s
= s
;
5831 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5832 it
->bidi_it
.string
.bufpos
= 0;
5833 it
->bidi_it
.string
.from_disp_str
= 0;
5834 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5835 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
5838 it
->method
= GET_FROM_C_STRING
;
5841 /* PRECISION > 0 means don't return more than PRECISION characters
5843 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5845 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5847 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5850 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5851 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5852 FIELD_WIDTH < 0 means infinite field width. This is useful for
5853 padding with `-' at the end of a mode line. */
5854 if (field_width
< 0)
5855 field_width
= INFINITY
;
5856 /* Implementation note: We deliberately don't enlarge
5857 it->bidi_it.string.schars here to fit it->end_charpos, because
5858 the bidi iterator cannot produce characters out of thin air. */
5859 if (field_width
> it
->end_charpos
- charpos
)
5860 it
->end_charpos
= charpos
+ field_width
;
5862 /* Use the standard display table for displaying strings. */
5863 if (DISP_TABLE_P (Vstandard_display_table
))
5864 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5866 it
->stop_charpos
= charpos
;
5867 it
->prev_stop
= charpos
;
5868 it
->base_level_stop
= 0;
5871 it
->bidi_it
.first_elt
= 1;
5872 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5873 it
->bidi_it
.disp_pos
= -1;
5875 if (s
== NULL
&& it
->multibyte_p
)
5877 EMACS_INT endpos
= SCHARS (it
->string
);
5878 if (endpos
> it
->end_charpos
)
5879 endpos
= it
->end_charpos
;
5880 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5888 /***********************************************************************
5890 ***********************************************************************/
5892 /* Map enum it_method value to corresponding next_element_from_* function. */
5894 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
5896 next_element_from_buffer
,
5897 next_element_from_display_vector
,
5898 next_element_from_string
,
5899 next_element_from_c_string
,
5900 next_element_from_image
,
5901 next_element_from_stretch
5904 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5907 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5908 (possibly with the following characters). */
5910 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5911 ((IT)->cmp_it.id >= 0 \
5912 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5913 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5914 END_CHARPOS, (IT)->w, \
5915 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5919 /* Lookup the char-table Vglyphless_char_display for character C (-1
5920 if we want information for no-font case), and return the display
5921 method symbol. By side-effect, update it->what and
5922 it->glyphless_method. This function is called from
5923 get_next_display_element for each character element, and from
5924 x_produce_glyphs when no suitable font was found. */
5927 lookup_glyphless_char_display (int c
, struct it
*it
)
5929 Lisp_Object glyphless_method
= Qnil
;
5931 if (CHAR_TABLE_P (Vglyphless_char_display
)
5932 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
5936 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
5937 if (CONSP (glyphless_method
))
5938 glyphless_method
= FRAME_WINDOW_P (it
->f
)
5939 ? XCAR (glyphless_method
)
5940 : XCDR (glyphless_method
);
5943 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
5947 if (NILP (glyphless_method
))
5950 /* The default is to display the character by a proper font. */
5952 /* The default for the no-font case is to display an empty box. */
5953 glyphless_method
= Qempty_box
;
5955 if (EQ (glyphless_method
, Qzero_width
))
5958 return glyphless_method
;
5959 /* This method can't be used for the no-font case. */
5960 glyphless_method
= Qempty_box
;
5962 if (EQ (glyphless_method
, Qthin_space
))
5963 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
5964 else if (EQ (glyphless_method
, Qempty_box
))
5965 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
5966 else if (EQ (glyphless_method
, Qhex_code
))
5967 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
5968 else if (STRINGP (glyphless_method
))
5969 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
5972 /* Invalid value. We use the default method. */
5973 glyphless_method
= Qnil
;
5976 it
->what
= IT_GLYPHLESS
;
5977 return glyphless_method
;
5980 /* Load IT's display element fields with information about the next
5981 display element from the current position of IT. Value is zero if
5982 end of buffer (or C string) is reached. */
5984 static struct frame
*last_escape_glyph_frame
= NULL
;
5985 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5986 static int last_escape_glyph_merged_face_id
= 0;
5988 struct frame
*last_glyphless_glyph_frame
= NULL
;
5989 unsigned last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
5990 int last_glyphless_glyph_merged_face_id
= 0;
5993 get_next_display_element (struct it
*it
)
5995 /* Non-zero means that we found a display element. Zero means that
5996 we hit the end of what we iterate over. Performance note: the
5997 function pointer `method' used here turns out to be faster than
5998 using a sequence of if-statements. */
6002 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6004 if (it
->what
== IT_CHARACTER
)
6006 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6007 and only if (a) the resolved directionality of that character
6009 /* FIXME: Do we need an exception for characters from display
6011 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6012 it
->c
= bidi_mirror_char (it
->c
);
6013 /* Map via display table or translate control characters.
6014 IT->c, IT->len etc. have been set to the next character by
6015 the function call above. If we have a display table, and it
6016 contains an entry for IT->c, translate it. Don't do this if
6017 IT->c itself comes from a display table, otherwise we could
6018 end up in an infinite recursion. (An alternative could be to
6019 count the recursion depth of this function and signal an
6020 error when a certain maximum depth is reached.) Is it worth
6022 if (success_p
&& it
->dpvec
== NULL
)
6025 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6026 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
6027 nbsp_or_shy
= char_is_other
;
6028 int c
= it
->c
; /* This is the character to display. */
6030 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6032 xassert (SINGLE_BYTE_CHAR_P (c
));
6033 if (unibyte_display_via_language_environment
)
6035 c
= DECODE_CHAR (unibyte
, c
);
6037 c
= BYTE8_TO_CHAR (it
->c
);
6040 c
= BYTE8_TO_CHAR (it
->c
);
6044 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6047 struct Lisp_Vector
*v
= XVECTOR (dv
);
6049 /* Return the first character from the display table
6050 entry, if not empty. If empty, don't display the
6051 current character. */
6054 it
->dpvec_char_len
= it
->len
;
6055 it
->dpvec
= v
->contents
;
6056 it
->dpend
= v
->contents
+ v
->header
.size
;
6057 it
->current
.dpvec_index
= 0;
6058 it
->dpvec_face_id
= -1;
6059 it
->saved_face_id
= it
->face_id
;
6060 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6065 set_iterator_to_next (it
, 0);
6070 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6072 if (it
->what
== IT_GLYPHLESS
)
6074 /* Don't display this character. */
6075 set_iterator_to_next (it
, 0);
6079 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6080 nbsp_or_shy
= (c
== 0xA0 ? char_is_nbsp
6081 : c
== 0xAD ? char_is_soft_hyphen
6084 /* Translate control characters into `\003' or `^C' form.
6085 Control characters coming from a display table entry are
6086 currently not translated because we use IT->dpvec to hold
6087 the translation. This could easily be changed but I
6088 don't believe that it is worth doing.
6090 NBSP and SOFT-HYPEN are property translated too.
6092 Non-printable characters and raw-byte characters are also
6093 translated to octal form. */
6094 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6095 ? (it
->area
!= TEXT_AREA
6096 /* In mode line, treat \n, \t like other crl chars. */
6099 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6100 || (c
!= '\n' && c
!= '\t'))
6103 || ! CHAR_PRINTABLE_P (c
))))
6105 /* C is a control character, NBSP, SOFT-HYPEN, raw-byte,
6106 or a non-printable character which must be displayed
6107 either as '\003' or as `^C' where the '\\' and '^'
6108 can be defined in the display table. Fill
6109 IT->ctl_chars with glyphs for what we have to
6110 display. Then, set IT->dpvec to these glyphs. */
6113 int face_id
, lface_id
= 0 ;
6116 /* Handle control characters with ^. */
6118 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6122 g
= '^'; /* default glyph for Control */
6123 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6125 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6126 && GLYPH_CODE_CHAR_VALID_P (gc
))
6128 g
= GLYPH_CODE_CHAR (gc
);
6129 lface_id
= GLYPH_CODE_FACE (gc
);
6133 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6135 else if (it
->f
== last_escape_glyph_frame
6136 && it
->face_id
== last_escape_glyph_face_id
)
6138 face_id
= last_escape_glyph_merged_face_id
;
6142 /* Merge the escape-glyph face into the current face. */
6143 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6145 last_escape_glyph_frame
= it
->f
;
6146 last_escape_glyph_face_id
= it
->face_id
;
6147 last_escape_glyph_merged_face_id
= face_id
;
6150 XSETINT (it
->ctl_chars
[0], g
);
6151 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6153 goto display_control
;
6156 /* Handle non-break space in the mode where it only gets
6159 if (EQ (Vnobreak_char_display
, Qt
)
6160 && nbsp_or_shy
== char_is_nbsp
)
6162 /* Merge the no-break-space face into the current face. */
6163 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6167 XSETINT (it
->ctl_chars
[0], ' ');
6169 goto display_control
;
6172 /* Handle sequences that start with the "escape glyph". */
6174 /* the default escape glyph is \. */
6175 escape_glyph
= '\\';
6178 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6179 && GLYPH_CODE_CHAR_VALID_P (gc
))
6181 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6182 lface_id
= GLYPH_CODE_FACE (gc
);
6186 /* The display table specified a face.
6187 Merge it into face_id and also into escape_glyph. */
6188 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6191 else if (it
->f
== last_escape_glyph_frame
6192 && it
->face_id
== last_escape_glyph_face_id
)
6194 face_id
= last_escape_glyph_merged_face_id
;
6198 /* Merge the escape-glyph face into the current face. */
6199 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6201 last_escape_glyph_frame
= it
->f
;
6202 last_escape_glyph_face_id
= it
->face_id
;
6203 last_escape_glyph_merged_face_id
= face_id
;
6206 /* Handle soft hyphens in the mode where they only get
6209 if (EQ (Vnobreak_char_display
, Qt
)
6210 && nbsp_or_shy
== char_is_soft_hyphen
)
6212 XSETINT (it
->ctl_chars
[0], '-');
6214 goto display_control
;
6217 /* Handle non-break space and soft hyphen
6218 with the escape glyph. */
6222 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6223 c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
6224 XSETINT (it
->ctl_chars
[1], c
);
6226 goto display_control
;
6233 if (CHAR_BYTE8_P (c
))
6234 /* Display \200 instead of \17777600. */
6235 c
= CHAR_TO_BYTE8 (c
);
6236 len
= sprintf (str
, "%03o", c
);
6238 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6239 for (i
= 0; i
< len
; i
++)
6240 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6245 /* Set up IT->dpvec and return first character from it. */
6246 it
->dpvec_char_len
= it
->len
;
6247 it
->dpvec
= it
->ctl_chars
;
6248 it
->dpend
= it
->dpvec
+ ctl_len
;
6249 it
->current
.dpvec_index
= 0;
6250 it
->dpvec_face_id
= face_id
;
6251 it
->saved_face_id
= it
->face_id
;
6252 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6256 it
->char_to_display
= c
;
6260 it
->char_to_display
= it
->c
;
6264 /* Adjust face id for a multibyte character. There are no multibyte
6265 character in unibyte text. */
6266 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6269 && FRAME_WINDOW_P (it
->f
))
6271 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6273 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6275 /* Automatic composition with glyph-string. */
6276 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6278 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6282 EMACS_INT pos
= (it
->s
? -1
6283 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6284 : IT_CHARPOS (*it
));
6286 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
, pos
,
6292 /* Is this character the last one of a run of characters with
6293 box? If yes, set IT->end_of_box_run_p to 1. */
6297 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6299 int face_id
= underlying_face_id (it
);
6300 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6304 if (face
->box
== FACE_NO_BOX
)
6306 /* If the box comes from face properties in a
6307 display string, check faces in that string. */
6308 int string_face_id
= face_after_it_pos (it
);
6309 it
->end_of_box_run_p
6310 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6313 /* Otherwise, the box comes from the underlying face.
6314 If this is the last string character displayed, check
6315 the next buffer location. */
6316 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6317 && (it
->current
.overlay_string_index
6318 == it
->n_overlay_strings
- 1))
6322 struct text_pos pos
= it
->current
.pos
;
6323 INC_TEXT_POS (pos
, it
->multibyte_p
);
6325 next_face_id
= face_at_buffer_position
6326 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6327 it
->region_end_charpos
, &ignore
,
6328 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6330 it
->end_of_box_run_p
6331 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6338 int face_id
= face_after_it_pos (it
);
6339 it
->end_of_box_run_p
6340 = (face_id
!= it
->face_id
6341 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6345 /* Value is 0 if end of buffer or string reached. */
6350 /* Move IT to the next display element.
6352 RESEAT_P non-zero means if called on a newline in buffer text,
6353 skip to the next visible line start.
6355 Functions get_next_display_element and set_iterator_to_next are
6356 separate because I find this arrangement easier to handle than a
6357 get_next_display_element function that also increments IT's
6358 position. The way it is we can first look at an iterator's current
6359 display element, decide whether it fits on a line, and if it does,
6360 increment the iterator position. The other way around we probably
6361 would either need a flag indicating whether the iterator has to be
6362 incremented the next time, or we would have to implement a
6363 decrement position function which would not be easy to write. */
6366 set_iterator_to_next (struct it
*it
, int reseat_p
)
6368 /* Reset flags indicating start and end of a sequence of characters
6369 with box. Reset them at the start of this function because
6370 moving the iterator to a new position might set them. */
6371 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6375 case GET_FROM_BUFFER
:
6376 /* The current display element of IT is a character from
6377 current_buffer. Advance in the buffer, and maybe skip over
6378 invisible lines that are so because of selective display. */
6379 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6380 reseat_at_next_visible_line_start (it
, 0);
6381 else if (it
->cmp_it
.id
>= 0)
6383 /* We are currently getting glyphs from a composition. */
6388 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6389 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6390 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6392 it
->cmp_it
.from
= it
->cmp_it
.to
;
6397 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6399 it
->end_charpos
, Qnil
);
6402 else if (! it
->cmp_it
.reversed_p
)
6404 /* Composition created while scanning forward. */
6405 /* Update IT's char/byte positions to point to the first
6406 character of the next grapheme cluster, or to the
6407 character visually after the current composition. */
6408 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6409 bidi_move_to_visually_next (&it
->bidi_it
);
6410 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6411 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6413 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6415 /* Proceed to the next grapheme cluster. */
6416 it
->cmp_it
.from
= it
->cmp_it
.to
;
6420 /* No more grapheme clusters in this composition.
6421 Find the next stop position. */
6422 EMACS_INT stop
= it
->end_charpos
;
6423 if (it
->bidi_it
.scan_dir
< 0)
6424 /* Now we are scanning backward and don't know
6427 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6428 IT_BYTEPOS (*it
), stop
, Qnil
);
6433 /* Composition created while scanning backward. */
6434 /* Update IT's char/byte positions to point to the last
6435 character of the previous grapheme cluster, or the
6436 character visually after the current composition. */
6437 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6438 bidi_move_to_visually_next (&it
->bidi_it
);
6439 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6440 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6441 if (it
->cmp_it
.from
> 0)
6443 /* Proceed to the previous grapheme cluster. */
6444 it
->cmp_it
.to
= it
->cmp_it
.from
;
6448 /* No more grapheme clusters in this composition.
6449 Find the next stop position. */
6450 EMACS_INT stop
= it
->end_charpos
;
6451 if (it
->bidi_it
.scan_dir
< 0)
6452 /* Now we are scanning backward and don't know
6455 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6456 IT_BYTEPOS (*it
), stop
, Qnil
);
6462 xassert (it
->len
!= 0);
6466 IT_BYTEPOS (*it
) += it
->len
;
6467 IT_CHARPOS (*it
) += 1;
6471 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6472 /* If this is a new paragraph, determine its base
6473 direction (a.k.a. its base embedding level). */
6474 if (it
->bidi_it
.new_paragraph
)
6475 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6476 bidi_move_to_visually_next (&it
->bidi_it
);
6477 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6478 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6479 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6481 /* As the scan direction was changed, we must
6482 re-compute the stop position for composition. */
6483 EMACS_INT stop
= it
->end_charpos
;
6484 if (it
->bidi_it
.scan_dir
< 0)
6486 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6487 IT_BYTEPOS (*it
), stop
, Qnil
);
6490 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6494 case GET_FROM_C_STRING
:
6495 /* Current display element of IT is from a C string. */
6497 /* If the string position is beyond string's end, it means
6498 next_element_from_c_string is padding the string with
6499 blanks, in which case we bypass the bidi iterator,
6500 because it cannot deal with such virtual characters. */
6501 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
6503 IT_BYTEPOS (*it
) += it
->len
;
6504 IT_CHARPOS (*it
) += 1;
6508 bidi_move_to_visually_next (&it
->bidi_it
);
6509 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6510 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6514 case GET_FROM_DISPLAY_VECTOR
:
6515 /* Current display element of IT is from a display table entry.
6516 Advance in the display table definition. Reset it to null if
6517 end reached, and continue with characters from buffers/
6519 ++it
->current
.dpvec_index
;
6521 /* Restore face of the iterator to what they were before the
6522 display vector entry (these entries may contain faces). */
6523 it
->face_id
= it
->saved_face_id
;
6525 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6527 int recheck_faces
= it
->ellipsis_p
;
6530 it
->method
= GET_FROM_C_STRING
;
6531 else if (STRINGP (it
->string
))
6532 it
->method
= GET_FROM_STRING
;
6535 it
->method
= GET_FROM_BUFFER
;
6536 it
->object
= it
->w
->buffer
;
6540 it
->current
.dpvec_index
= -1;
6542 /* Skip over characters which were displayed via IT->dpvec. */
6543 if (it
->dpvec_char_len
< 0)
6544 reseat_at_next_visible_line_start (it
, 1);
6545 else if (it
->dpvec_char_len
> 0)
6547 if (it
->method
== GET_FROM_STRING
6548 && it
->n_overlay_strings
> 0)
6549 it
->ignore_overlay_strings_at_pos_p
= 1;
6550 it
->len
= it
->dpvec_char_len
;
6551 set_iterator_to_next (it
, reseat_p
);
6554 /* Maybe recheck faces after display vector */
6556 it
->stop_charpos
= IT_CHARPOS (*it
);
6560 case GET_FROM_STRING
:
6561 /* Current display element is a character from a Lisp string. */
6562 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6563 if (it
->cmp_it
.id
>= 0)
6569 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6570 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6571 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6572 it
->cmp_it
.from
= it
->cmp_it
.to
;
6576 composition_compute_stop_pos (&it
->cmp_it
,
6577 IT_STRING_CHARPOS (*it
),
6578 IT_STRING_BYTEPOS (*it
),
6579 it
->end_charpos
, it
->string
);
6582 else if (! it
->cmp_it
.reversed_p
)
6584 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6585 bidi_move_to_visually_next (&it
->bidi_it
);
6586 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6587 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6589 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6590 it
->cmp_it
.from
= it
->cmp_it
.to
;
6593 EMACS_INT stop
= it
->end_charpos
;
6594 if (it
->bidi_it
.scan_dir
< 0)
6596 composition_compute_stop_pos (&it
->cmp_it
,
6597 IT_STRING_CHARPOS (*it
),
6598 IT_STRING_BYTEPOS (*it
), stop
,
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
;
6608 if (it
->cmp_it
.from
> 0)
6609 it
->cmp_it
.to
= it
->cmp_it
.from
;
6612 EMACS_INT stop
= it
->end_charpos
;
6613 if (it
->bidi_it
.scan_dir
< 0)
6615 composition_compute_stop_pos (&it
->cmp_it
,
6616 IT_STRING_CHARPOS (*it
),
6617 IT_STRING_BYTEPOS (*it
), stop
,
6625 /* If the string position is beyond string's end, it
6626 means next_element_from_string is padding the string
6627 with blanks, in which case we bypass the bidi
6628 iterator, because it cannot deal with such virtual
6630 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
6632 IT_STRING_BYTEPOS (*it
) += it
->len
;
6633 IT_STRING_CHARPOS (*it
) += 1;
6637 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6639 bidi_move_to_visually_next (&it
->bidi_it
);
6640 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6641 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6642 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6644 EMACS_INT stop
= it
->end_charpos
;
6646 if (it
->bidi_it
.scan_dir
< 0)
6648 composition_compute_stop_pos (&it
->cmp_it
,
6649 IT_STRING_CHARPOS (*it
),
6650 IT_STRING_BYTEPOS (*it
), stop
,
6656 consider_string_end
:
6658 if (it
->current
.overlay_string_index
>= 0)
6660 /* IT->string is an overlay string. Advance to the
6661 next, if there is one. */
6662 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6665 next_overlay_string (it
);
6667 setup_for_ellipsis (it
, 0);
6672 /* IT->string is not an overlay string. If we reached
6673 its end, and there is something on IT->stack, proceed
6674 with what is on the stack. This can be either another
6675 string, this time an overlay string, or a buffer. */
6676 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6680 if (it
->method
== GET_FROM_STRING
)
6681 goto consider_string_end
;
6686 case GET_FROM_IMAGE
:
6687 case GET_FROM_STRETCH
:
6688 /* The position etc with which we have to proceed are on
6689 the stack. The position may be at the end of a string,
6690 if the `display' property takes up the whole string. */
6691 xassert (it
->sp
> 0);
6693 if (it
->method
== GET_FROM_STRING
)
6694 goto consider_string_end
;
6698 /* There are no other methods defined, so this should be a bug. */
6702 xassert (it
->method
!= GET_FROM_STRING
6703 || (STRINGP (it
->string
)
6704 && IT_STRING_CHARPOS (*it
) >= 0));
6707 /* Load IT's display element fields with information about the next
6708 display element which comes from a display table entry or from the
6709 result of translating a control character to one of the forms `^C'
6712 IT->dpvec holds the glyphs to return as characters.
6713 IT->saved_face_id holds the face id before the display vector--it
6714 is restored into IT->face_id in set_iterator_to_next. */
6717 next_element_from_display_vector (struct it
*it
)
6722 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6724 it
->face_id
= it
->saved_face_id
;
6726 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6727 That seemed totally bogus - so I changed it... */
6728 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6730 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6732 it
->c
= GLYPH_CODE_CHAR (gc
);
6733 it
->len
= CHAR_BYTES (it
->c
);
6735 /* The entry may contain a face id to use. Such a face id is
6736 the id of a Lisp face, not a realized face. A face id of
6737 zero means no face is specified. */
6738 if (it
->dpvec_face_id
>= 0)
6739 it
->face_id
= it
->dpvec_face_id
;
6742 int lface_id
= GLYPH_CODE_FACE (gc
);
6744 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6749 /* Display table entry is invalid. Return a space. */
6750 it
->c
= ' ', it
->len
= 1;
6752 /* Don't change position and object of the iterator here. They are
6753 still the values of the character that had this display table
6754 entry or was translated, and that's what we want. */
6755 it
->what
= IT_CHARACTER
;
6759 /* Get the first element of string/buffer in the visual order, after
6760 being reseated to a new position in a string or a buffer. */
6762 get_visually_first_element (struct it
*it
)
6764 int string_p
= STRINGP (it
->string
) || it
->s
;
6765 EMACS_INT eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
6766 EMACS_INT bob
= (string_p
? 0 : BEGV
);
6768 if (STRINGP (it
->string
))
6770 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
6771 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
6775 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6776 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6779 if (it
->bidi_it
.charpos
== eob
)
6781 /* Nothing to do, but reset the FIRST_ELT flag, like
6782 bidi_paragraph_init does, because we are not going to
6784 it
->bidi_it
.first_elt
= 0;
6786 else if (it
->bidi_it
.charpos
== bob
6788 /* FIXME: Should support all Unicode line separators. */
6789 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6790 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
6792 /* If we are at the beginning of a line/string, we can produce
6793 the next element right away. */
6794 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6795 bidi_move_to_visually_next (&it
->bidi_it
);
6799 EMACS_INT orig_bytepos
= it
->bidi_it
.bytepos
;
6801 /* We need to prime the bidi iterator starting at the line's or
6802 string's beginning, before we will be able to produce the
6805 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
6808 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
6810 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
6812 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6815 /* Now return to buffer/string position where we were asked
6816 to get the next display element, and produce that. */
6817 bidi_move_to_visually_next (&it
->bidi_it
);
6819 while (it
->bidi_it
.bytepos
!= orig_bytepos
6820 && it
->bidi_it
.charpos
< eob
);
6823 /* Adjust IT's position information to where we ended up. */
6824 if (STRINGP (it
->string
))
6826 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6827 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6831 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6832 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6835 if (STRINGP (it
->string
) || !it
->s
)
6837 EMACS_INT stop
, charpos
, bytepos
;
6839 if (STRINGP (it
->string
))
6842 stop
= SCHARS (it
->string
);
6843 if (stop
> it
->end_charpos
)
6844 stop
= it
->end_charpos
;
6845 charpos
= IT_STRING_CHARPOS (*it
);
6846 bytepos
= IT_STRING_BYTEPOS (*it
);
6850 stop
= it
->end_charpos
;
6851 charpos
= IT_CHARPOS (*it
);
6852 bytepos
= IT_BYTEPOS (*it
);
6854 if (it
->bidi_it
.scan_dir
< 0)
6856 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
6861 /* Load IT with the next display element from Lisp string IT->string.
6862 IT->current.string_pos is the current position within the string.
6863 If IT->current.overlay_string_index >= 0, the Lisp string is an
6867 next_element_from_string (struct it
*it
)
6869 struct text_pos position
;
6871 xassert (STRINGP (it
->string
));
6872 xassert (!it
->bidi_p
|| it
->string
== it
->bidi_it
.string
.lstring
);
6873 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6874 position
= it
->current
.string_pos
;
6876 /* With bidi reordering, the character to display might not be the
6877 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
6878 that we were reseat()ed to a new string, whose paragraph
6879 direction is not known. */
6880 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6882 get_visually_first_element (it
);
6883 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
6886 /* Time to check for invisible text? */
6887 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
6889 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
6892 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6893 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
6895 /* With bidi non-linear iteration, we could find
6896 ourselves far beyond the last computed stop_charpos,
6897 with several other stop positions in between that we
6898 missed. Scan them all now, in buffer's logical
6899 order, until we find and handle the last stop_charpos
6900 that precedes our current position. */
6901 handle_stop_backwards (it
, it
->stop_charpos
);
6902 return GET_NEXT_DISPLAY_ELEMENT (it
);
6908 /* Take note of the stop position we just moved
6909 across, for when we will move back across it. */
6910 it
->prev_stop
= it
->stop_charpos
;
6911 /* If we are at base paragraph embedding level, take
6912 note of the last stop position seen at this
6914 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6915 it
->base_level_stop
= it
->stop_charpos
;
6919 /* Since a handler may have changed IT->method, we must
6921 return GET_NEXT_DISPLAY_ELEMENT (it
);
6925 /* If we are before prev_stop, we may have overstepped
6926 on our way backwards a stop_pos, and if so, we need
6927 to handle that stop_pos. */
6928 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
6929 /* We can sometimes back up for reasons that have nothing
6930 to do with bidi reordering. E.g., compositions. The
6931 code below is only needed when we are above the base
6932 embedding level, so test for that explicitly. */
6933 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6935 /* If we lost track of base_level_stop, we have no better place
6936 for handle_stop_backwards to start from than BEGV. This
6937 happens, e.g., when we were reseated to the previous
6938 screenful of text by vertical-motion. */
6939 if (it
->base_level_stop
<= 0
6940 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
6941 it
->base_level_stop
= 0;
6942 handle_stop_backwards (it
, it
->base_level_stop
);
6943 return GET_NEXT_DISPLAY_ELEMENT (it
);
6947 if (it
->current
.overlay_string_index
>= 0)
6949 /* Get the next character from an overlay string. In overlay
6950 strings, There is no field width or padding with spaces to
6952 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6957 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6958 IT_STRING_BYTEPOS (*it
),
6959 it
->bidi_it
.scan_dir
< 0
6961 : SCHARS (it
->string
))
6962 && next_element_from_composition (it
))
6966 else if (STRING_MULTIBYTE (it
->string
))
6968 const unsigned char *s
= (SDATA (it
->string
)
6969 + IT_STRING_BYTEPOS (*it
));
6970 it
->c
= string_char_and_length (s
, &it
->len
);
6974 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6980 /* Get the next character from a Lisp string that is not an
6981 overlay string. Such strings come from the mode line, for
6982 example. We may have to pad with spaces, or truncate the
6983 string. See also next_element_from_c_string. */
6984 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6989 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6991 /* Pad with spaces. */
6992 it
->c
= ' ', it
->len
= 1;
6993 CHARPOS (position
) = BYTEPOS (position
) = -1;
6995 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6996 IT_STRING_BYTEPOS (*it
),
6997 it
->bidi_it
.scan_dir
< 0
6999 : it
->string_nchars
)
7000 && next_element_from_composition (it
))
7004 else if (STRING_MULTIBYTE (it
->string
))
7006 const unsigned char *s
= (SDATA (it
->string
)
7007 + IT_STRING_BYTEPOS (*it
));
7008 it
->c
= string_char_and_length (s
, &it
->len
);
7012 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7017 /* Record what we have and where it came from. */
7018 it
->what
= IT_CHARACTER
;
7019 it
->object
= it
->string
;
7020 it
->position
= position
;
7025 /* Load IT with next display element from C string IT->s.
7026 IT->string_nchars is the maximum number of characters to return
7027 from the string. IT->end_charpos may be greater than
7028 IT->string_nchars when this function is called, in which case we
7029 may have to return padding spaces. Value is zero if end of string
7030 reached, including padding spaces. */
7033 next_element_from_c_string (struct it
*it
)
7038 xassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7039 it
->what
= IT_CHARACTER
;
7040 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7043 /* With bidi reordering, the character to display might not be the
7044 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7045 we were reseated to a new string, whose paragraph direction is
7047 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7048 get_visually_first_element (it
);
7050 /* IT's position can be greater than IT->string_nchars in case a
7051 field width or precision has been specified when the iterator was
7053 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7055 /* End of the game. */
7059 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7061 /* Pad with spaces. */
7062 it
->c
= ' ', it
->len
= 1;
7063 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7065 else if (it
->multibyte_p
)
7066 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7068 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7074 /* Set up IT to return characters from an ellipsis, if appropriate.
7075 The definition of the ellipsis glyphs may come from a display table
7076 entry. This function fills IT with the first glyph from the
7077 ellipsis if an ellipsis is to be displayed. */
7080 next_element_from_ellipsis (struct it
*it
)
7082 if (it
->selective_display_ellipsis_p
)
7083 setup_for_ellipsis (it
, it
->len
);
7086 /* The face at the current position may be different from the
7087 face we find after the invisible text. Remember what it
7088 was in IT->saved_face_id, and signal that it's there by
7089 setting face_before_selective_p. */
7090 it
->saved_face_id
= it
->face_id
;
7091 it
->method
= GET_FROM_BUFFER
;
7092 it
->object
= it
->w
->buffer
;
7093 reseat_at_next_visible_line_start (it
, 1);
7094 it
->face_before_selective_p
= 1;
7097 return GET_NEXT_DISPLAY_ELEMENT (it
);
7101 /* Deliver an image display element. The iterator IT is already
7102 filled with image information (done in handle_display_prop). Value
7107 next_element_from_image (struct it
*it
)
7109 it
->what
= IT_IMAGE
;
7110 it
->ignore_overlay_strings_at_pos_p
= 0;
7115 /* Fill iterator IT with next display element from a stretch glyph
7116 property. IT->object is the value of the text property. Value is
7120 next_element_from_stretch (struct it
*it
)
7122 it
->what
= IT_STRETCH
;
7126 /* Scan forward from CHARPOS in the current buffer/string, until we
7127 find a stop position > current IT's position. Then handle the stop
7128 position before that. This is called when we bump into a stop
7129 position while reordering bidirectional text. CHARPOS should be
7130 the last previously processed stop_pos (or BEGV/0, if none were
7131 processed yet) whose position is less that IT's current
7135 handle_stop_backwards (struct it
*it
, EMACS_INT charpos
)
7137 int bufp
= !STRINGP (it
->string
);
7138 EMACS_INT where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7139 struct display_pos save_current
= it
->current
;
7140 struct text_pos save_position
= it
->position
;
7141 struct text_pos pos1
;
7142 EMACS_INT next_stop
;
7144 /* Scan in strict logical order. */
7148 it
->prev_stop
= charpos
;
7151 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7152 reseat_1 (it
, pos1
, 0);
7155 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7156 compute_stop_pos (it
);
7157 /* We must advance forward, right? */
7158 if (it
->stop_charpos
<= it
->prev_stop
)
7160 charpos
= it
->stop_charpos
;
7162 while (charpos
<= where_we_are
);
7164 next_stop
= it
->stop_charpos
;
7165 it
->stop_charpos
= it
->prev_stop
;
7167 it
->current
= save_current
;
7168 it
->position
= save_position
;
7170 it
->stop_charpos
= next_stop
;
7173 /* Load IT with the next display element from current_buffer. Value
7174 is zero if end of buffer reached. IT->stop_charpos is the next
7175 position at which to stop and check for text properties or buffer
7179 next_element_from_buffer (struct it
*it
)
7183 xassert (IT_CHARPOS (*it
) >= BEGV
);
7184 xassert (NILP (it
->string
) && !it
->s
);
7185 xassert (!it
->bidi_p
7186 || (it
->bidi_it
.string
.lstring
== Qnil
7187 && it
->bidi_it
.string
.s
== NULL
));
7189 /* With bidi reordering, the character to display might not be the
7190 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7191 we were reseat()ed to a new buffer position, which is potentially
7192 a different paragraph. */
7193 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7195 get_visually_first_element (it
);
7196 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7199 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7201 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7203 int overlay_strings_follow_p
;
7205 /* End of the game, except when overlay strings follow that
7206 haven't been returned yet. */
7207 if (it
->overlay_strings_at_end_processed_p
)
7208 overlay_strings_follow_p
= 0;
7211 it
->overlay_strings_at_end_processed_p
= 1;
7212 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7215 if (overlay_strings_follow_p
)
7216 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7220 it
->position
= it
->current
.pos
;
7224 else if (!(!it
->bidi_p
7225 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7226 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7228 /* With bidi non-linear iteration, we could find ourselves
7229 far beyond the last computed stop_charpos, with several
7230 other stop positions in between that we missed. Scan
7231 them all now, in buffer's logical order, until we find
7232 and handle the last stop_charpos that precedes our
7233 current position. */
7234 handle_stop_backwards (it
, it
->stop_charpos
);
7235 return GET_NEXT_DISPLAY_ELEMENT (it
);
7241 /* Take note of the stop position we just moved across,
7242 for when we will move back across it. */
7243 it
->prev_stop
= it
->stop_charpos
;
7244 /* If we are at base paragraph embedding level, take
7245 note of the last stop position seen at this
7247 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7248 it
->base_level_stop
= it
->stop_charpos
;
7251 return GET_NEXT_DISPLAY_ELEMENT (it
);
7255 /* If we are before prev_stop, we may have overstepped on
7256 our way backwards a stop_pos, and if so, we need to
7257 handle that stop_pos. */
7258 && IT_CHARPOS (*it
) < it
->prev_stop
7259 /* We can sometimes back up for reasons that have nothing
7260 to do with bidi reordering. E.g., compositions. The
7261 code below is only needed when we are above the base
7262 embedding level, so test for that explicitly. */
7263 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7265 /* If we lost track of base_level_stop, we have no better place
7266 for handle_stop_backwards to start from than BEGV. This
7267 happens, e.g., when we were reseated to the previous
7268 screenful of text by vertical-motion. */
7269 if (it
->base_level_stop
<= 0
7270 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7271 it
->base_level_stop
= BEGV
;
7272 handle_stop_backwards (it
, it
->base_level_stop
);
7273 return GET_NEXT_DISPLAY_ELEMENT (it
);
7277 /* No face changes, overlays etc. in sight, so just return a
7278 character from current_buffer. */
7282 /* Maybe run the redisplay end trigger hook. Performance note:
7283 This doesn't seem to cost measurable time. */
7284 if (it
->redisplay_end_trigger_charpos
7286 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7287 run_redisplay_end_trigger_hook (it
);
7289 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7290 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7292 && next_element_from_composition (it
))
7297 /* Get the next character, maybe multibyte. */
7298 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7299 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7300 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7302 it
->c
= *p
, it
->len
= 1;
7304 /* Record what we have and where it came from. */
7305 it
->what
= IT_CHARACTER
;
7306 it
->object
= it
->w
->buffer
;
7307 it
->position
= it
->current
.pos
;
7309 /* Normally we return the character found above, except when we
7310 really want to return an ellipsis for selective display. */
7315 /* A value of selective > 0 means hide lines indented more
7316 than that number of columns. */
7317 if (it
->selective
> 0
7318 && IT_CHARPOS (*it
) + 1 < ZV
7319 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7320 IT_BYTEPOS (*it
) + 1,
7321 (double) it
->selective
)) /* iftc */
7323 success_p
= next_element_from_ellipsis (it
);
7324 it
->dpvec_char_len
= -1;
7327 else if (it
->c
== '\r' && it
->selective
== -1)
7329 /* A value of selective == -1 means that everything from the
7330 CR to the end of the line is invisible, with maybe an
7331 ellipsis displayed for it. */
7332 success_p
= next_element_from_ellipsis (it
);
7333 it
->dpvec_char_len
= -1;
7338 /* Value is zero if end of buffer reached. */
7339 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7344 /* Run the redisplay end trigger hook for IT. */
7347 run_redisplay_end_trigger_hook (struct it
*it
)
7349 Lisp_Object args
[3];
7351 /* IT->glyph_row should be non-null, i.e. we should be actually
7352 displaying something, or otherwise we should not run the hook. */
7353 xassert (it
->glyph_row
);
7355 /* Set up hook arguments. */
7356 args
[0] = Qredisplay_end_trigger_functions
;
7357 args
[1] = it
->window
;
7358 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7359 it
->redisplay_end_trigger_charpos
= 0;
7361 /* Since we are *trying* to run these functions, don't try to run
7362 them again, even if they get an error. */
7363 it
->w
->redisplay_end_trigger
= Qnil
;
7364 Frun_hook_with_args (3, args
);
7366 /* Notice if it changed the face of the character we are on. */
7367 handle_face_prop (it
);
7371 /* Deliver a composition display element. Unlike the other
7372 next_element_from_XXX, this function is not registered in the array
7373 get_next_element[]. It is called from next_element_from_buffer and
7374 next_element_from_string when necessary. */
7377 next_element_from_composition (struct it
*it
)
7379 it
->what
= IT_COMPOSITION
;
7380 it
->len
= it
->cmp_it
.nbytes
;
7381 if (STRINGP (it
->string
))
7385 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7386 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7389 it
->position
= it
->current
.string_pos
;
7390 it
->object
= it
->string
;
7391 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
7392 IT_STRING_BYTEPOS (*it
), it
->string
);
7398 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7399 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7402 if (it
->bidi_it
.new_paragraph
)
7403 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7404 /* Resync the bidi iterator with IT's new position.
7405 FIXME: this doesn't support bidirectional text. */
7406 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
7407 bidi_move_to_visually_next (&it
->bidi_it
);
7411 it
->position
= it
->current
.pos
;
7412 it
->object
= it
->w
->buffer
;
7413 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
7414 IT_BYTEPOS (*it
), Qnil
);
7421 /***********************************************************************
7422 Moving an iterator without producing glyphs
7423 ***********************************************************************/
7425 /* Check if iterator is at a position corresponding to a valid buffer
7426 position after some move_it_ call. */
7428 #define IT_POS_VALID_AFTER_MOVE_P(it) \
7429 ((it)->method == GET_FROM_STRING \
7430 ? IT_STRING_CHARPOS (*it) == 0 \
7434 /* Move iterator IT to a specified buffer or X position within one
7435 line on the display without producing glyphs.
7437 OP should be a bit mask including some or all of these bits:
7438 MOVE_TO_X: Stop upon reaching x-position TO_X.
7439 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
7440 Regardless of OP's value, stop upon reaching the end of the display line.
7442 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
7443 This means, in particular, that TO_X includes window's horizontal
7446 The return value has several possible values that
7447 say what condition caused the scan to stop:
7449 MOVE_POS_MATCH_OR_ZV
7450 - when TO_POS or ZV was reached.
7453 -when TO_X was reached before TO_POS or ZV were reached.
7456 - when we reached the end of the display area and the line must
7460 - when we reached the end of the display area and the line is
7464 - when we stopped at a line end, i.e. a newline or a CR and selective
7467 static enum move_it_result
7468 move_it_in_display_line_to (struct it
*it
,
7469 EMACS_INT to_charpos
, int to_x
,
7470 enum move_operation_enum op
)
7472 enum move_it_result result
= MOVE_UNDEFINED
;
7473 struct glyph_row
*saved_glyph_row
;
7474 struct it wrap_it
, atpos_it
, atx_it
;
7476 enum it_method prev_method
= it
->method
;
7477 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
7479 /* Don't produce glyphs in produce_glyphs. */
7480 saved_glyph_row
= it
->glyph_row
;
7481 it
->glyph_row
= NULL
;
7483 /* Use wrap_it to save a copy of IT wherever a word wrap could
7484 occur. Use atpos_it to save a copy of IT at the desired buffer
7485 position, if found, so that we can scan ahead and check if the
7486 word later overshoots the window edge. Use atx_it similarly, for
7492 #define BUFFER_POS_REACHED_P() \
7493 ((op & MOVE_TO_POS) != 0 \
7494 && BUFFERP (it->object) \
7495 && (IT_CHARPOS (*it) == to_charpos \
7496 || (!it->bidi_p && IT_CHARPOS (*it) > to_charpos)) \
7497 && (it->method == GET_FROM_BUFFER \
7498 || (it->method == GET_FROM_DISPLAY_VECTOR \
7499 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
7501 /* If there's a line-/wrap-prefix, handle it. */
7502 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
7503 && it
->current_y
< it
->last_visible_y
)
7504 handle_line_prefix (it
);
7506 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7507 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7511 int x
, i
, ascent
= 0, descent
= 0;
7513 /* Utility macro to reset an iterator with x, ascent, and descent. */
7514 #define IT_RESET_X_ASCENT_DESCENT(IT) \
7515 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
7516 (IT)->max_descent = descent)
7518 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
7520 if ((op
& MOVE_TO_POS
) != 0
7521 && BUFFERP (it
->object
)
7522 && it
->method
== GET_FROM_BUFFER
7523 && ((!it
->bidi_p
&& IT_CHARPOS (*it
) > to_charpos
)
7525 && (prev_method
== GET_FROM_IMAGE
7526 || prev_method
== GET_FROM_STRETCH
)
7527 /* Passed TO_CHARPOS from left to right. */
7528 && ((prev_pos
< to_charpos
7529 && IT_CHARPOS (*it
) > to_charpos
)
7530 /* Passed TO_CHARPOS from right to left. */
7531 || (prev_pos
> to_charpos
7532 && IT_CHARPOS (*it
) < to_charpos
)))))
7534 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7536 result
= MOVE_POS_MATCH_OR_ZV
;
7539 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7540 /* If wrap_it is valid, the current position might be in a
7541 word that is wrapped. So, save the iterator in
7542 atpos_it and continue to see if wrapping happens. */
7546 prev_method
= it
->method
;
7547 if (it
->method
== GET_FROM_BUFFER
)
7548 prev_pos
= IT_CHARPOS (*it
);
7549 /* Stop when ZV reached.
7550 We used to stop here when TO_CHARPOS reached as well, but that is
7551 too soon if this glyph does not fit on this line. So we handle it
7552 explicitly below. */
7553 if (!get_next_display_element (it
))
7555 result
= MOVE_POS_MATCH_OR_ZV
;
7559 if (it
->line_wrap
== TRUNCATE
)
7561 if (BUFFER_POS_REACHED_P ())
7563 result
= MOVE_POS_MATCH_OR_ZV
;
7569 if (it
->line_wrap
== WORD_WRAP
)
7571 if (IT_DISPLAYING_WHITESPACE (it
))
7575 /* We have reached a glyph that follows one or more
7576 whitespace characters. If the position is
7577 already found, we are done. */
7578 if (atpos_it
.sp
>= 0)
7581 result
= MOVE_POS_MATCH_OR_ZV
;
7587 result
= MOVE_X_REACHED
;
7590 /* Otherwise, we can wrap here. */
7597 /* Remember the line height for the current line, in case
7598 the next element doesn't fit on the line. */
7599 ascent
= it
->max_ascent
;
7600 descent
= it
->max_descent
;
7602 /* The call to produce_glyphs will get the metrics of the
7603 display element IT is loaded with. Record the x-position
7604 before this display element, in case it doesn't fit on the
7608 PRODUCE_GLYPHS (it
);
7610 if (it
->area
!= TEXT_AREA
)
7612 set_iterator_to_next (it
, 1);
7613 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7614 SET_TEXT_POS (this_line_min_pos
,
7615 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7619 /* The number of glyphs we get back in IT->nglyphs will normally
7620 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7621 character on a terminal frame, or (iii) a line end. For the
7622 second case, IT->nglyphs - 1 padding glyphs will be present.
7623 (On X frames, there is only one glyph produced for a
7624 composite character.)
7626 The behavior implemented below means, for continuation lines,
7627 that as many spaces of a TAB as fit on the current line are
7628 displayed there. For terminal frames, as many glyphs of a
7629 multi-glyph character are displayed in the current line, too.
7630 This is what the old redisplay code did, and we keep it that
7631 way. Under X, the whole shape of a complex character must
7632 fit on the line or it will be completely displayed in the
7635 Note that both for tabs and padding glyphs, all glyphs have
7639 /* More than one glyph or glyph doesn't fit on line. All
7640 glyphs have the same width. */
7641 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7643 int x_before_this_char
= x
;
7644 int hpos_before_this_char
= it
->hpos
;
7646 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7648 new_x
= x
+ single_glyph_width
;
7650 /* We want to leave anything reaching TO_X to the caller. */
7651 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7653 if (BUFFER_POS_REACHED_P ())
7655 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7656 goto buffer_pos_reached
;
7657 if (atpos_it
.sp
< 0)
7660 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7665 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7668 result
= MOVE_X_REACHED
;
7674 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7679 if (/* Lines are continued. */
7680 it
->line_wrap
!= TRUNCATE
7681 && (/* And glyph doesn't fit on the line. */
7682 new_x
> it
->last_visible_x
7683 /* Or it fits exactly and we're on a window
7685 || (new_x
== it
->last_visible_x
7686 && FRAME_WINDOW_P (it
->f
))))
7688 if (/* IT->hpos == 0 means the very first glyph
7689 doesn't fit on the line, e.g. a wide image. */
7691 || (new_x
== it
->last_visible_x
7692 && FRAME_WINDOW_P (it
->f
)))
7695 it
->current_x
= new_x
;
7697 /* The character's last glyph just barely fits
7699 if (i
== it
->nglyphs
- 1)
7701 /* If this is the destination position,
7702 return a position *before* it in this row,
7703 now that we know it fits in this row. */
7704 if (BUFFER_POS_REACHED_P ())
7706 if (it
->line_wrap
!= WORD_WRAP
7709 it
->hpos
= hpos_before_this_char
;
7710 it
->current_x
= x_before_this_char
;
7711 result
= MOVE_POS_MATCH_OR_ZV
;
7714 if (it
->line_wrap
== WORD_WRAP
7718 atpos_it
.current_x
= x_before_this_char
;
7719 atpos_it
.hpos
= hpos_before_this_char
;
7723 set_iterator_to_next (it
, 1);
7724 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7725 SET_TEXT_POS (this_line_min_pos
,
7726 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7727 /* On graphical terminals, newlines may
7728 "overflow" into the fringe if
7729 overflow-newline-into-fringe is non-nil.
7730 On text-only terminals, newlines may
7731 overflow into the last glyph on the
7733 if (!FRAME_WINDOW_P (it
->f
)
7734 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7736 if (!get_next_display_element (it
))
7738 result
= MOVE_POS_MATCH_OR_ZV
;
7741 if (BUFFER_POS_REACHED_P ())
7743 if (ITERATOR_AT_END_OF_LINE_P (it
))
7744 result
= MOVE_POS_MATCH_OR_ZV
;
7746 result
= MOVE_LINE_CONTINUED
;
7749 if (ITERATOR_AT_END_OF_LINE_P (it
))
7751 result
= MOVE_NEWLINE_OR_CR
;
7758 IT_RESET_X_ASCENT_DESCENT (it
);
7760 if (wrap_it
.sp
>= 0)
7767 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7769 result
= MOVE_LINE_CONTINUED
;
7773 if (BUFFER_POS_REACHED_P ())
7775 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7776 goto buffer_pos_reached
;
7777 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7780 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7784 if (new_x
> it
->first_visible_x
)
7786 /* Glyph is visible. Increment number of glyphs that
7787 would be displayed. */
7792 if (result
!= MOVE_UNDEFINED
)
7795 else if (BUFFER_POS_REACHED_P ())
7798 IT_RESET_X_ASCENT_DESCENT (it
);
7799 result
= MOVE_POS_MATCH_OR_ZV
;
7802 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7804 /* Stop when TO_X specified and reached. This check is
7805 necessary here because of lines consisting of a line end,
7806 only. The line end will not produce any glyphs and we
7807 would never get MOVE_X_REACHED. */
7808 xassert (it
->nglyphs
== 0);
7809 result
= MOVE_X_REACHED
;
7813 /* Is this a line end? If yes, we're done. */
7814 if (ITERATOR_AT_END_OF_LINE_P (it
))
7816 result
= MOVE_NEWLINE_OR_CR
;
7820 if (it
->method
== GET_FROM_BUFFER
)
7821 prev_pos
= IT_CHARPOS (*it
);
7822 /* The current display element has been consumed. Advance
7824 set_iterator_to_next (it
, 1);
7825 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7826 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7828 /* Stop if lines are truncated and IT's current x-position is
7829 past the right edge of the window now. */
7830 if (it
->line_wrap
== TRUNCATE
7831 && it
->current_x
>= it
->last_visible_x
)
7833 if (!FRAME_WINDOW_P (it
->f
)
7834 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7836 if (!get_next_display_element (it
)
7837 || BUFFER_POS_REACHED_P ())
7839 result
= MOVE_POS_MATCH_OR_ZV
;
7842 if (ITERATOR_AT_END_OF_LINE_P (it
))
7844 result
= MOVE_NEWLINE_OR_CR
;
7848 result
= MOVE_LINE_TRUNCATED
;
7851 #undef IT_RESET_X_ASCENT_DESCENT
7854 #undef BUFFER_POS_REACHED_P
7856 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7857 restore the saved iterator. */
7858 if (atpos_it
.sp
>= 0)
7860 else if (atx_it
.sp
>= 0)
7865 /* Restore the iterator settings altered at the beginning of this
7867 it
->glyph_row
= saved_glyph_row
;
7871 /* For external use. */
7873 move_it_in_display_line (struct it
*it
,
7874 EMACS_INT to_charpos
, int to_x
,
7875 enum move_operation_enum op
)
7877 if (it
->line_wrap
== WORD_WRAP
7878 && (op
& MOVE_TO_X
))
7880 struct it save_it
= *it
;
7881 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7882 /* When word-wrap is on, TO_X may lie past the end
7883 of a wrapped line. Then it->current is the
7884 character on the next line, so backtrack to the
7885 space before the wrap point. */
7886 if (skip
== MOVE_LINE_CONTINUED
)
7888 int prev_x
= max (it
->current_x
- 1, 0);
7890 move_it_in_display_line_to
7891 (it
, -1, prev_x
, MOVE_TO_X
);
7895 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7899 /* Move IT forward until it satisfies one or more of the criteria in
7900 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7902 OP is a bit-mask that specifies where to stop, and in particular,
7903 which of those four position arguments makes a difference. See the
7904 description of enum move_operation_enum.
7906 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7907 screen line, this function will set IT to the next position >
7911 move_it_to (struct it
*it
, EMACS_INT to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
7913 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7914 int line_height
, line_start_x
= 0, reached
= 0;
7918 if (op
& MOVE_TO_VPOS
)
7920 /* If no TO_CHARPOS and no TO_X specified, stop at the
7921 start of the line TO_VPOS. */
7922 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7924 if (it
->vpos
== to_vpos
)
7930 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7934 /* TO_VPOS >= 0 means stop at TO_X in the line at
7935 TO_VPOS, or at TO_POS, whichever comes first. */
7936 if (it
->vpos
== to_vpos
)
7942 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7944 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7949 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7951 /* We have reached TO_X but not in the line we want. */
7952 skip
= move_it_in_display_line_to (it
, to_charpos
,
7954 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7962 else if (op
& MOVE_TO_Y
)
7964 struct it it_backup
;
7966 if (it
->line_wrap
== WORD_WRAP
)
7969 /* TO_Y specified means stop at TO_X in the line containing
7970 TO_Y---or at TO_CHARPOS if this is reached first. The
7971 problem is that we can't really tell whether the line
7972 contains TO_Y before we have completely scanned it, and
7973 this may skip past TO_X. What we do is to first scan to
7976 If TO_X is not specified, use a TO_X of zero. The reason
7977 is to make the outcome of this function more predictable.
7978 If we didn't use TO_X == 0, we would stop at the end of
7979 the line which is probably not what a caller would expect
7981 skip
= move_it_in_display_line_to
7982 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7983 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7985 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7986 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7988 else if (skip
== MOVE_X_REACHED
)
7990 /* If TO_X was reached, we want to know whether TO_Y is
7991 in the line. We know this is the case if the already
7992 scanned glyphs make the line tall enough. Otherwise,
7993 we must check by scanning the rest of the line. */
7994 line_height
= it
->max_ascent
+ it
->max_descent
;
7995 if (to_y
>= it
->current_y
7996 && to_y
< it
->current_y
+ line_height
)
8002 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8003 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8005 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8006 line_height
= it
->max_ascent
+ it
->max_descent
;
8007 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8009 if (to_y
>= it
->current_y
8010 && to_y
< it
->current_y
+ line_height
)
8012 /* If TO_Y is in this line and TO_X was reached
8013 above, we scanned too far. We have to restore
8014 IT's settings to the ones before skipping. */
8021 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8027 /* Check whether TO_Y is in this line. */
8028 line_height
= it
->max_ascent
+ it
->max_descent
;
8029 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8031 if (to_y
>= it
->current_y
8032 && to_y
< it
->current_y
+ line_height
)
8034 /* When word-wrap is on, TO_X may lie past the end
8035 of a wrapped line. Then it->current is the
8036 character on the next line, so backtrack to the
8037 space before the wrap point. */
8038 if (skip
== MOVE_LINE_CONTINUED
8039 && it
->line_wrap
== WORD_WRAP
)
8041 int prev_x
= max (it
->current_x
- 1, 0);
8043 skip
= move_it_in_display_line_to
8044 (it
, -1, prev_x
, MOVE_TO_X
);
8053 else if (BUFFERP (it
->object
)
8054 && (it
->method
== GET_FROM_BUFFER
8055 || it
->method
== GET_FROM_STRETCH
)
8056 && IT_CHARPOS (*it
) >= to_charpos
)
8057 skip
= MOVE_POS_MATCH_OR_ZV
;
8059 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8063 case MOVE_POS_MATCH_OR_ZV
:
8067 case MOVE_NEWLINE_OR_CR
:
8068 set_iterator_to_next (it
, 1);
8069 it
->continuation_lines_width
= 0;
8072 case MOVE_LINE_TRUNCATED
:
8073 it
->continuation_lines_width
= 0;
8074 reseat_at_next_visible_line_start (it
, 0);
8075 if ((op
& MOVE_TO_POS
) != 0
8076 && IT_CHARPOS (*it
) > to_charpos
)
8083 case MOVE_LINE_CONTINUED
:
8084 /* For continued lines ending in a tab, some of the glyphs
8085 associated with the tab are displayed on the current
8086 line. Since it->current_x does not include these glyphs,
8087 we use it->last_visible_x instead. */
8090 it
->continuation_lines_width
+= it
->last_visible_x
;
8091 /* When moving by vpos, ensure that the iterator really
8092 advances to the next line (bug#847, bug#969). Fixme:
8093 do we need to do this in other circumstances? */
8094 if (it
->current_x
!= it
->last_visible_x
8095 && (op
& MOVE_TO_VPOS
)
8096 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8098 line_start_x
= it
->current_x
+ it
->pixel_width
8099 - it
->last_visible_x
;
8100 set_iterator_to_next (it
, 0);
8104 it
->continuation_lines_width
+= it
->current_x
;
8111 /* Reset/increment for the next run. */
8112 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8113 it
->current_x
= line_start_x
;
8116 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8118 last_height
= it
->max_ascent
+ it
->max_descent
;
8119 last_max_ascent
= it
->max_ascent
;
8120 it
->max_ascent
= it
->max_descent
= 0;
8125 /* On text terminals, we may stop at the end of a line in the middle
8126 of a multi-character glyph. If the glyph itself is continued,
8127 i.e. it is actually displayed on the next line, don't treat this
8128 stopping point as valid; move to the next line instead (unless
8129 that brings us offscreen). */
8130 if (!FRAME_WINDOW_P (it
->f
)
8132 && IT_CHARPOS (*it
) == to_charpos
8133 && it
->what
== IT_CHARACTER
8135 && it
->line_wrap
== WINDOW_WRAP
8136 && it
->current_x
== it
->last_visible_x
- 1
8139 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8141 it
->continuation_lines_width
+= it
->current_x
;
8142 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8143 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8145 last_height
= it
->max_ascent
+ it
->max_descent
;
8146 last_max_ascent
= it
->max_ascent
;
8149 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8153 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8155 If DY > 0, move IT backward at least that many pixels. DY = 0
8156 means move IT backward to the preceding line start or BEGV. This
8157 function may move over more than DY pixels if IT->current_y - DY
8158 ends up in the middle of a line; in this case IT->current_y will be
8159 set to the top of the line moved to. */
8162 move_it_vertically_backward (struct it
*it
, int dy
)
8166 EMACS_INT start_pos
;
8171 start_pos
= IT_CHARPOS (*it
);
8173 /* Estimate how many newlines we must move back. */
8174 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8176 /* Set the iterator's position that many lines back. */
8177 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8178 back_to_previous_visible_line_start (it
);
8180 /* Reseat the iterator here. When moving backward, we don't want
8181 reseat to skip forward over invisible text, set up the iterator
8182 to deliver from overlay strings at the new position etc. So,
8183 use reseat_1 here. */
8184 reseat_1 (it
, it
->current
.pos
, 1);
8186 /* We are now surely at a line start. */
8187 it
->current_x
= it
->hpos
= 0;
8188 it
->continuation_lines_width
= 0;
8190 /* Move forward and see what y-distance we moved. First move to the
8191 start of the next line so that we get its height. We need this
8192 height to be able to tell whether we reached the specified
8195 it2
.max_ascent
= it2
.max_descent
= 0;
8198 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8199 MOVE_TO_POS
| MOVE_TO_VPOS
);
8201 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
8202 xassert (IT_CHARPOS (*it
) >= BEGV
);
8205 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8206 xassert (IT_CHARPOS (*it
) >= BEGV
);
8207 /* H is the actual vertical distance from the position in *IT
8208 and the starting position. */
8209 h
= it2
.current_y
- it
->current_y
;
8210 /* NLINES is the distance in number of lines. */
8211 nlines
= it2
.vpos
- it
->vpos
;
8213 /* Correct IT's y and vpos position
8214 so that they are relative to the starting point. */
8220 /* DY == 0 means move to the start of the screen line. The
8221 value of nlines is > 0 if continuation lines were involved. */
8223 move_it_by_lines (it
, nlines
);
8227 /* The y-position we try to reach, relative to *IT.
8228 Note that H has been subtracted in front of the if-statement. */
8229 int target_y
= it
->current_y
+ h
- dy
;
8230 int y0
= it3
.current_y
;
8231 int y1
= line_bottom_y (&it3
);
8232 int line_height
= y1
- y0
;
8234 /* If we did not reach target_y, try to move further backward if
8235 we can. If we moved too far backward, try to move forward. */
8236 if (target_y
< it
->current_y
8237 /* This is heuristic. In a window that's 3 lines high, with
8238 a line height of 13 pixels each, recentering with point
8239 on the bottom line will try to move -39/2 = 19 pixels
8240 backward. Try to avoid moving into the first line. */
8241 && (it
->current_y
- target_y
8242 > min (window_box_height (it
->w
), line_height
* 2 / 3))
8243 && IT_CHARPOS (*it
) > BEGV
)
8245 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
8246 target_y
- it
->current_y
));
8247 dy
= it
->current_y
- target_y
;
8248 goto move_further_back
;
8250 else if (target_y
>= it
->current_y
+ line_height
8251 && IT_CHARPOS (*it
) < ZV
)
8253 /* Should move forward by at least one line, maybe more.
8255 Note: Calling move_it_by_lines can be expensive on
8256 terminal frames, where compute_motion is used (via
8257 vmotion) to do the job, when there are very long lines
8258 and truncate-lines is nil. That's the reason for
8259 treating terminal frames specially here. */
8261 if (!FRAME_WINDOW_P (it
->f
))
8262 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
8267 move_it_by_lines (it
, 1);
8269 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
8276 /* Move IT by a specified amount of pixel lines DY. DY negative means
8277 move backwards. DY = 0 means move to start of screen line. At the
8278 end, IT will be on the start of a screen line. */
8281 move_it_vertically (struct it
*it
, int dy
)
8284 move_it_vertically_backward (it
, -dy
);
8287 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
8288 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
8289 MOVE_TO_POS
| MOVE_TO_Y
);
8290 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
8292 /* If buffer ends in ZV without a newline, move to the start of
8293 the line to satisfy the post-condition. */
8294 if (IT_CHARPOS (*it
) == ZV
8296 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8297 move_it_by_lines (it
, 0);
8302 /* Move iterator IT past the end of the text line it is in. */
8305 move_it_past_eol (struct it
*it
)
8307 enum move_it_result rc
;
8309 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
8310 if (rc
== MOVE_NEWLINE_OR_CR
)
8311 set_iterator_to_next (it
, 0);
8315 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
8316 negative means move up. DVPOS == 0 means move to the start of the
8319 Optimization idea: If we would know that IT->f doesn't use
8320 a face with proportional font, we could be faster for
8321 truncate-lines nil. */
8324 move_it_by_lines (struct it
*it
, int dvpos
)
8327 /* The commented-out optimization uses vmotion on terminals. This
8328 gives bad results, because elements like it->what, on which
8329 callers such as pos_visible_p rely, aren't updated. */
8330 /* struct position pos;
8331 if (!FRAME_WINDOW_P (it->f))
8333 struct text_pos textpos;
8335 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
8336 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
8337 reseat (it, textpos, 1);
8338 it->vpos += pos.vpos;
8339 it->current_y += pos.vpos;
8345 /* DVPOS == 0 means move to the start of the screen line. */
8346 move_it_vertically_backward (it
, 0);
8347 xassert (it
->current_x
== 0 && it
->hpos
== 0);
8348 /* Let next call to line_bottom_y calculate real line height */
8353 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
8354 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
8355 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
8360 EMACS_INT start_charpos
, i
;
8362 /* Start at the beginning of the screen line containing IT's
8363 position. This may actually move vertically backwards,
8364 in case of overlays, so adjust dvpos accordingly. */
8366 move_it_vertically_backward (it
, 0);
8369 /* Go back -DVPOS visible lines and reseat the iterator there. */
8370 start_charpos
= IT_CHARPOS (*it
);
8371 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
8372 back_to_previous_visible_line_start (it
);
8373 reseat (it
, it
->current
.pos
, 1);
8375 /* Move further back if we end up in a string or an image. */
8376 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
8378 /* First try to move to start of display line. */
8380 move_it_vertically_backward (it
, 0);
8382 if (IT_POS_VALID_AFTER_MOVE_P (it
))
8384 /* If start of line is still in string or image,
8385 move further back. */
8386 back_to_previous_visible_line_start (it
);
8387 reseat (it
, it
->current
.pos
, 1);
8391 it
->current_x
= it
->hpos
= 0;
8393 /* Above call may have moved too far if continuation lines
8394 are involved. Scan forward and see if it did. */
8396 it2
.vpos
= it2
.current_y
= 0;
8397 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
8398 it
->vpos
-= it2
.vpos
;
8399 it
->current_y
-= it2
.current_y
;
8400 it
->current_x
= it
->hpos
= 0;
8402 /* If we moved too far back, move IT some lines forward. */
8403 if (it2
.vpos
> -dvpos
)
8405 int delta
= it2
.vpos
+ dvpos
;
8407 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
8408 /* Move back again if we got too far ahead. */
8409 if (IT_CHARPOS (*it
) >= start_charpos
)
8415 /* Return 1 if IT points into the middle of a display vector. */
8418 in_display_vector_p (struct it
*it
)
8420 return (it
->method
== GET_FROM_DISPLAY_VECTOR
8421 && it
->current
.dpvec_index
> 0
8422 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
8426 /***********************************************************************
8428 ***********************************************************************/
8431 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
8435 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
8437 Lisp_Object args
[3];
8438 Lisp_Object msg
, fmt
;
8441 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
8444 /* Do nothing if called asynchronously. Inserting text into
8445 a buffer may call after-change-functions and alike and
8446 that would means running Lisp asynchronously. */
8447 if (handling_signal
)
8451 GCPRO4 (fmt
, msg
, arg1
, arg2
);
8453 args
[0] = fmt
= build_string (format
);
8456 msg
= Fformat (3, args
);
8458 len
= SBYTES (msg
) + 1;
8459 SAFE_ALLOCA (buffer
, char *, len
);
8460 memcpy (buffer
, SDATA (msg
), len
);
8462 message_dolog (buffer
, len
- 1, 1, 0);
8469 /* Output a newline in the *Messages* buffer if "needs" one. */
8472 message_log_maybe_newline (void)
8474 if (message_log_need_newline
)
8475 message_dolog ("", 0, 1, 0);
8479 /* Add a string M of length NBYTES to the message log, optionally
8480 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
8481 nonzero, means interpret the contents of M as multibyte. This
8482 function calls low-level routines in order to bypass text property
8483 hooks, etc. which might not be safe to run.
8485 This may GC (insert may run before/after change hooks),
8486 so the buffer M must NOT point to a Lisp string. */
8489 message_dolog (const char *m
, EMACS_INT nbytes
, int nlflag
, int multibyte
)
8491 const unsigned char *msg
= (const unsigned char *) m
;
8493 if (!NILP (Vmemory_full
))
8496 if (!NILP (Vmessage_log_max
))
8498 struct buffer
*oldbuf
;
8499 Lisp_Object oldpoint
, oldbegv
, oldzv
;
8500 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
8501 EMACS_INT point_at_end
= 0;
8502 EMACS_INT zv_at_end
= 0;
8503 Lisp_Object old_deactivate_mark
, tem
;
8504 struct gcpro gcpro1
;
8506 old_deactivate_mark
= Vdeactivate_mark
;
8507 oldbuf
= current_buffer
;
8508 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
8509 BVAR (current_buffer
, undo_list
) = Qt
;
8511 oldpoint
= message_dolog_marker1
;
8512 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
8513 oldbegv
= message_dolog_marker2
;
8514 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
8515 oldzv
= message_dolog_marker3
;
8516 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
8517 GCPRO1 (old_deactivate_mark
);
8525 BEGV_BYTE
= BEG_BYTE
;
8528 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8530 /* Insert the string--maybe converting multibyte to single byte
8531 or vice versa, so that all the text fits the buffer. */
8533 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8539 /* Convert a multibyte string to single-byte
8540 for the *Message* buffer. */
8541 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
8543 c
= string_char_and_length (msg
+ i
, &char_bytes
);
8544 work
[0] = (ASCII_CHAR_P (c
)
8546 : multibyte_char_to_unibyte (c
));
8547 insert_1_both (work
, 1, 1, 1, 0, 0);
8550 else if (! multibyte
8551 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8555 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8556 /* Convert a single-byte string to multibyte
8557 for the *Message* buffer. */
8558 for (i
= 0; i
< nbytes
; i
++)
8561 MAKE_CHAR_MULTIBYTE (c
);
8562 char_bytes
= CHAR_STRING (c
, str
);
8563 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
8567 insert_1 (m
, nbytes
, 1, 0, 0);
8571 EMACS_INT this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
8572 unsigned long int dups
;
8573 insert_1 ("\n", 1, 1, 0, 0);
8575 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8577 this_bol_byte
= PT_BYTE
;
8579 /* See if this line duplicates the previous one.
8580 If so, combine duplicates. */
8583 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8585 prev_bol_byte
= PT_BYTE
;
8587 dups
= message_log_check_duplicate (prev_bol_byte
,
8591 del_range_both (prev_bol
, prev_bol_byte
,
8592 this_bol
, this_bol_byte
, 0);
8598 /* If you change this format, don't forget to also
8599 change message_log_check_duplicate. */
8600 sprintf (dupstr
, " [%lu times]", dups
);
8601 duplen
= strlen (dupstr
);
8602 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8603 insert_1 (dupstr
, duplen
, 1, 0, 1);
8608 /* If we have more than the desired maximum number of lines
8609 in the *Messages* buffer now, delete the oldest ones.
8610 This is safe because we don't have undo in this buffer. */
8612 if (NATNUMP (Vmessage_log_max
))
8614 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8615 -XFASTINT (Vmessage_log_max
) - 1, 0);
8616 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8619 BEGV
= XMARKER (oldbegv
)->charpos
;
8620 BEGV_BYTE
= marker_byte_position (oldbegv
);
8629 ZV
= XMARKER (oldzv
)->charpos
;
8630 ZV_BYTE
= marker_byte_position (oldzv
);
8634 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8636 /* We can't do Fgoto_char (oldpoint) because it will run some
8638 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8639 XMARKER (oldpoint
)->bytepos
);
8642 unchain_marker (XMARKER (oldpoint
));
8643 unchain_marker (XMARKER (oldbegv
));
8644 unchain_marker (XMARKER (oldzv
));
8646 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8647 set_buffer_internal (oldbuf
);
8649 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8650 message_log_need_newline
= !nlflag
;
8651 Vdeactivate_mark
= old_deactivate_mark
;
8656 /* We are at the end of the buffer after just having inserted a newline.
8657 (Note: We depend on the fact we won't be crossing the gap.)
8658 Check to see if the most recent message looks a lot like the previous one.
8659 Return 0 if different, 1 if the new one should just replace it, or a
8660 value N > 1 if we should also append " [N times]". */
8662 static unsigned long int
8663 message_log_check_duplicate (EMACS_INT prev_bol_byte
, EMACS_INT this_bol_byte
)
8666 EMACS_INT len
= Z_BYTE
- 1 - this_bol_byte
;
8668 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8669 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8671 for (i
= 0; i
< len
; i
++)
8673 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8681 if (*p1
++ == ' ' && *p1
++ == '[')
8684 unsigned long int n
= strtoul ((char *) p1
, &pend
, 10);
8685 if (strncmp (pend
, " times]\n", 8) == 0)
8692 /* Display an echo area message M with a specified length of NBYTES
8693 bytes. The string may include null characters. If M is 0, clear
8694 out any existing message, and let the mini-buffer text show
8697 This may GC, so the buffer M must NOT point to a Lisp string. */
8700 message2 (const char *m
, EMACS_INT nbytes
, int multibyte
)
8702 /* First flush out any partial line written with print. */
8703 message_log_maybe_newline ();
8705 message_dolog (m
, nbytes
, 1, multibyte
);
8706 message2_nolog (m
, nbytes
, multibyte
);
8710 /* The non-logging counterpart of message2. */
8713 message2_nolog (const char *m
, EMACS_INT nbytes
, int multibyte
)
8715 struct frame
*sf
= SELECTED_FRAME ();
8716 message_enable_multibyte
= multibyte
;
8718 if (FRAME_INITIAL_P (sf
))
8720 if (noninteractive_need_newline
)
8721 putc ('\n', stderr
);
8722 noninteractive_need_newline
= 0;
8724 fwrite (m
, nbytes
, 1, stderr
);
8725 if (cursor_in_echo_area
== 0)
8726 fprintf (stderr
, "\n");
8729 /* A null message buffer means that the frame hasn't really been
8730 initialized yet. Error messages get reported properly by
8731 cmd_error, so this must be just an informative message; toss it. */
8732 else if (INTERACTIVE
8733 && sf
->glyphs_initialized_p
8734 && FRAME_MESSAGE_BUF (sf
))
8736 Lisp_Object mini_window
;
8739 /* Get the frame containing the mini-buffer
8740 that the selected frame is using. */
8741 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8742 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8744 FRAME_SAMPLE_VISIBILITY (f
);
8745 if (FRAME_VISIBLE_P (sf
)
8746 && ! FRAME_VISIBLE_P (f
))
8747 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8751 set_message (m
, Qnil
, nbytes
, multibyte
);
8752 if (minibuffer_auto_raise
)
8753 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8756 clear_message (1, 1);
8758 do_pending_window_change (0);
8759 echo_area_display (1);
8760 do_pending_window_change (0);
8761 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8762 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8767 /* Display an echo area message M with a specified length of NBYTES
8768 bytes. The string may include null characters. If M is not a
8769 string, clear out any existing message, and let the mini-buffer
8772 This function cancels echoing. */
8775 message3 (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8777 struct gcpro gcpro1
;
8780 clear_message (1,1);
8783 /* First flush out any partial line written with print. */
8784 message_log_maybe_newline ();
8790 SAFE_ALLOCA (buffer
, char *, nbytes
);
8791 memcpy (buffer
, SDATA (m
), nbytes
);
8792 message_dolog (buffer
, nbytes
, 1, multibyte
);
8795 message3_nolog (m
, nbytes
, multibyte
);
8801 /* The non-logging version of message3.
8802 This does not cancel echoing, because it is used for echoing.
8803 Perhaps we need to make a separate function for echoing
8804 and make this cancel echoing. */
8807 message3_nolog (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8809 struct frame
*sf
= SELECTED_FRAME ();
8810 message_enable_multibyte
= multibyte
;
8812 if (FRAME_INITIAL_P (sf
))
8814 if (noninteractive_need_newline
)
8815 putc ('\n', stderr
);
8816 noninteractive_need_newline
= 0;
8818 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8819 if (cursor_in_echo_area
== 0)
8820 fprintf (stderr
, "\n");
8823 /* A null message buffer means that the frame hasn't really been
8824 initialized yet. Error messages get reported properly by
8825 cmd_error, so this must be just an informative message; toss it. */
8826 else if (INTERACTIVE
8827 && sf
->glyphs_initialized_p
8828 && FRAME_MESSAGE_BUF (sf
))
8830 Lisp_Object mini_window
;
8834 /* Get the frame containing the mini-buffer
8835 that the selected frame is using. */
8836 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8837 frame
= XWINDOW (mini_window
)->frame
;
8840 FRAME_SAMPLE_VISIBILITY (f
);
8841 if (FRAME_VISIBLE_P (sf
)
8842 && !FRAME_VISIBLE_P (f
))
8843 Fmake_frame_visible (frame
);
8845 if (STRINGP (m
) && SCHARS (m
) > 0)
8847 set_message (NULL
, m
, nbytes
, multibyte
);
8848 if (minibuffer_auto_raise
)
8849 Fraise_frame (frame
);
8850 /* Assume we are not echoing.
8851 (If we are, echo_now will override this.) */
8852 echo_message_buffer
= Qnil
;
8855 clear_message (1, 1);
8857 do_pending_window_change (0);
8858 echo_area_display (1);
8859 do_pending_window_change (0);
8860 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8861 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8866 /* Display a null-terminated echo area message M. If M is 0, clear
8867 out any existing message, and let the mini-buffer text show through.
8869 The buffer M must continue to exist until after the echo area gets
8870 cleared or some other message gets displayed there. Do not pass
8871 text that is stored in a Lisp string. Do not pass text in a buffer
8872 that was alloca'd. */
8875 message1 (const char *m
)
8877 message2 (m
, (m
? strlen (m
) : 0), 0);
8881 /* The non-logging counterpart of message1. */
8884 message1_nolog (const char *m
)
8886 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8889 /* Display a message M which contains a single %s
8890 which gets replaced with STRING. */
8893 message_with_string (const char *m
, Lisp_Object string
, int log
)
8895 CHECK_STRING (string
);
8901 if (noninteractive_need_newline
)
8902 putc ('\n', stderr
);
8903 noninteractive_need_newline
= 0;
8904 fprintf (stderr
, m
, SDATA (string
));
8905 if (!cursor_in_echo_area
)
8906 fprintf (stderr
, "\n");
8910 else if (INTERACTIVE
)
8912 /* The frame whose minibuffer we're going to display the message on.
8913 It may be larger than the selected frame, so we need
8914 to use its buffer, not the selected frame's buffer. */
8915 Lisp_Object mini_window
;
8916 struct frame
*f
, *sf
= SELECTED_FRAME ();
8918 /* Get the frame containing the minibuffer
8919 that the selected frame is using. */
8920 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8921 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8923 /* A null message buffer means that the frame hasn't really been
8924 initialized yet. Error messages get reported properly by
8925 cmd_error, so this must be just an informative message; toss it. */
8926 if (FRAME_MESSAGE_BUF (f
))
8928 Lisp_Object args
[2], msg
;
8929 struct gcpro gcpro1
, gcpro2
;
8931 args
[0] = build_string (m
);
8932 args
[1] = msg
= string
;
8933 GCPRO2 (args
[0], msg
);
8936 msg
= Fformat (2, args
);
8939 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8941 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8945 /* Print should start at the beginning of the message
8946 buffer next time. */
8947 message_buf_print
= 0;
8953 /* Dump an informative message to the minibuf. If M is 0, clear out
8954 any existing message, and let the mini-buffer text show through. */
8957 vmessage (const char *m
, va_list ap
)
8963 if (noninteractive_need_newline
)
8964 putc ('\n', stderr
);
8965 noninteractive_need_newline
= 0;
8966 vfprintf (stderr
, m
, ap
);
8967 if (cursor_in_echo_area
== 0)
8968 fprintf (stderr
, "\n");
8972 else if (INTERACTIVE
)
8974 /* The frame whose mini-buffer we're going to display the message
8975 on. It may be larger than the selected frame, so we need to
8976 use its buffer, not the selected frame's buffer. */
8977 Lisp_Object mini_window
;
8978 struct frame
*f
, *sf
= SELECTED_FRAME ();
8980 /* Get the frame containing the mini-buffer
8981 that the selected frame is using. */
8982 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8983 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8985 /* A null message buffer means that the frame hasn't really been
8986 initialized yet. Error messages get reported properly by
8987 cmd_error, so this must be just an informative message; toss
8989 if (FRAME_MESSAGE_BUF (f
))
8995 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8996 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
8998 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
9003 /* Print should start at the beginning of the message
9004 buffer next time. */
9005 message_buf_print
= 0;
9011 message (const char *m
, ...)
9021 /* The non-logging version of message. */
9024 message_nolog (const char *m
, ...)
9026 Lisp_Object old_log_max
;
9029 old_log_max
= Vmessage_log_max
;
9030 Vmessage_log_max
= Qnil
;
9032 Vmessage_log_max
= old_log_max
;
9038 /* Display the current message in the current mini-buffer. This is
9039 only called from error handlers in process.c, and is not time
9043 update_echo_area (void)
9045 if (!NILP (echo_area_buffer
[0]))
9048 string
= Fcurrent_message ();
9049 message3 (string
, SBYTES (string
),
9050 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9055 /* Make sure echo area buffers in `echo_buffers' are live.
9056 If they aren't, make new ones. */
9059 ensure_echo_area_buffers (void)
9063 for (i
= 0; i
< 2; ++i
)
9064 if (!BUFFERP (echo_buffer
[i
])
9065 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
9068 Lisp_Object old_buffer
;
9071 old_buffer
= echo_buffer
[i
];
9072 sprintf (name
, " *Echo Area %d*", i
);
9073 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
9074 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
9075 /* to force word wrap in echo area -
9076 it was decided to postpone this*/
9077 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9079 for (j
= 0; j
< 2; ++j
)
9080 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9081 echo_area_buffer
[j
] = echo_buffer
[i
];
9086 /* Call FN with args A1..A4 with either the current or last displayed
9087 echo_area_buffer as current buffer.
9089 WHICH zero means use the current message buffer
9090 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9091 from echo_buffer[] and clear it.
9093 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9094 suitable buffer from echo_buffer[] and clear it.
9096 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9097 that the current message becomes the last displayed one, make
9098 choose a suitable buffer for echo_area_buffer[0], and clear it.
9100 Value is what FN returns. */
9103 with_echo_area_buffer (struct window
*w
, int which
,
9104 int (*fn
) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
9105 EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9108 int this_one
, the_other
, clear_buffer_p
, rc
;
9109 int count
= SPECPDL_INDEX ();
9111 /* If buffers aren't live, make new ones. */
9112 ensure_echo_area_buffers ();
9117 this_one
= 0, the_other
= 1;
9119 this_one
= 1, the_other
= 0;
9122 this_one
= 0, the_other
= 1;
9125 /* We need a fresh one in case the current echo buffer equals
9126 the one containing the last displayed echo area message. */
9127 if (!NILP (echo_area_buffer
[this_one
])
9128 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9129 echo_area_buffer
[this_one
] = Qnil
;
9132 /* Choose a suitable buffer from echo_buffer[] is we don't
9134 if (NILP (echo_area_buffer
[this_one
]))
9136 echo_area_buffer
[this_one
]
9137 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9138 ? echo_buffer
[the_other
]
9139 : echo_buffer
[this_one
]);
9143 buffer
= echo_area_buffer
[this_one
];
9145 /* Don't get confused by reusing the buffer used for echoing
9146 for a different purpose. */
9147 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9150 record_unwind_protect (unwind_with_echo_area_buffer
,
9151 with_echo_area_buffer_unwind_data (w
));
9153 /* Make the echo area buffer current. Note that for display
9154 purposes, it is not necessary that the displayed window's buffer
9155 == current_buffer, except for text property lookup. So, let's
9156 only set that buffer temporarily here without doing a full
9157 Fset_window_buffer. We must also change w->pointm, though,
9158 because otherwise an assertions in unshow_buffer fails, and Emacs
9160 set_buffer_internal_1 (XBUFFER (buffer
));
9164 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9167 BVAR (current_buffer
, undo_list
) = Qt
;
9168 BVAR (current_buffer
, read_only
) = Qnil
;
9169 specbind (Qinhibit_read_only
, Qt
);
9170 specbind (Qinhibit_modification_hooks
, Qt
);
9172 if (clear_buffer_p
&& Z
> BEG
)
9175 xassert (BEGV
>= BEG
);
9176 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9178 rc
= fn (a1
, a2
, a3
, a4
);
9180 xassert (BEGV
>= BEG
);
9181 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9183 unbind_to (count
, Qnil
);
9188 /* Save state that should be preserved around the call to the function
9189 FN called in with_echo_area_buffer. */
9192 with_echo_area_buffer_unwind_data (struct window
*w
)
9195 Lisp_Object vector
, tmp
;
9197 /* Reduce consing by keeping one vector in
9198 Vwith_echo_area_save_vector. */
9199 vector
= Vwith_echo_area_save_vector
;
9200 Vwith_echo_area_save_vector
= Qnil
;
9203 vector
= Fmake_vector (make_number (7), Qnil
);
9205 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9206 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9207 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
9211 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
9212 ASET (vector
, i
, w
->buffer
); ++i
;
9213 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
9214 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
9219 for (; i
< end
; ++i
)
9220 ASET (vector
, i
, Qnil
);
9223 xassert (i
== ASIZE (vector
));
9228 /* Restore global state from VECTOR which was created by
9229 with_echo_area_buffer_unwind_data. */
9232 unwind_with_echo_area_buffer (Lisp_Object vector
)
9234 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
9235 Vdeactivate_mark
= AREF (vector
, 1);
9236 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
9238 if (WINDOWP (AREF (vector
, 3)))
9241 Lisp_Object buffer
, charpos
, bytepos
;
9243 w
= XWINDOW (AREF (vector
, 3));
9244 buffer
= AREF (vector
, 4);
9245 charpos
= AREF (vector
, 5);
9246 bytepos
= AREF (vector
, 6);
9249 set_marker_both (w
->pointm
, buffer
,
9250 XFASTINT (charpos
), XFASTINT (bytepos
));
9253 Vwith_echo_area_save_vector
= vector
;
9258 /* Set up the echo area for use by print functions. MULTIBYTE_P
9259 non-zero means we will print multibyte. */
9262 setup_echo_area_for_printing (int multibyte_p
)
9264 /* If we can't find an echo area any more, exit. */
9265 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9268 ensure_echo_area_buffers ();
9270 if (!message_buf_print
)
9272 /* A message has been output since the last time we printed.
9273 Choose a fresh echo area buffer. */
9274 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9275 echo_area_buffer
[0] = echo_buffer
[1];
9277 echo_area_buffer
[0] = echo_buffer
[0];
9279 /* Switch to that buffer and clear it. */
9280 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9281 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9285 int count
= SPECPDL_INDEX ();
9286 specbind (Qinhibit_read_only
, Qt
);
9287 /* Note that undo recording is always disabled. */
9289 unbind_to (count
, Qnil
);
9291 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9293 /* Set up the buffer for the multibyteness we need. */
9295 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9296 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
9298 /* Raise the frame containing the echo area. */
9299 if (minibuffer_auto_raise
)
9301 struct frame
*sf
= SELECTED_FRAME ();
9302 Lisp_Object mini_window
;
9303 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9304 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9307 message_log_maybe_newline ();
9308 message_buf_print
= 1;
9312 if (NILP (echo_area_buffer
[0]))
9314 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9315 echo_area_buffer
[0] = echo_buffer
[1];
9317 echo_area_buffer
[0] = echo_buffer
[0];
9320 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
9322 /* Someone switched buffers between print requests. */
9323 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9324 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9330 /* Display an echo area message in window W. Value is non-zero if W's
9331 height is changed. If display_last_displayed_message_p is
9332 non-zero, display the message that was last displayed, otherwise
9333 display the current message. */
9336 display_echo_area (struct window
*w
)
9338 int i
, no_message_p
, window_height_changed_p
, count
;
9340 /* Temporarily disable garbage collections while displaying the echo
9341 area. This is done because a GC can print a message itself.
9342 That message would modify the echo area buffer's contents while a
9343 redisplay of the buffer is going on, and seriously confuse
9345 count
= inhibit_garbage_collection ();
9347 /* If there is no message, we must call display_echo_area_1
9348 nevertheless because it resizes the window. But we will have to
9349 reset the echo_area_buffer in question to nil at the end because
9350 with_echo_area_buffer will sets it to an empty buffer. */
9351 i
= display_last_displayed_message_p
? 1 : 0;
9352 no_message_p
= NILP (echo_area_buffer
[i
]);
9354 window_height_changed_p
9355 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
9356 display_echo_area_1
,
9357 (intptr_t) w
, Qnil
, 0, 0);
9360 echo_area_buffer
[i
] = Qnil
;
9362 unbind_to (count
, Qnil
);
9363 return window_height_changed_p
;
9367 /* Helper for display_echo_area. Display the current buffer which
9368 contains the current echo area message in window W, a mini-window,
9369 a pointer to which is passed in A1. A2..A4 are currently not used.
9370 Change the height of W so that all of the message is displayed.
9371 Value is non-zero if height of W was changed. */
9374 display_echo_area_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9377 struct window
*w
= (struct window
*) i1
;
9379 struct text_pos start
;
9380 int window_height_changed_p
= 0;
9382 /* Do this before displaying, so that we have a large enough glyph
9383 matrix for the display. If we can't get enough space for the
9384 whole text, display the last N lines. That works by setting w->start. */
9385 window_height_changed_p
= resize_mini_window (w
, 0);
9387 /* Use the starting position chosen by resize_mini_window. */
9388 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
9391 clear_glyph_matrix (w
->desired_matrix
);
9392 XSETWINDOW (window
, w
);
9393 try_window (window
, start
, 0);
9395 return window_height_changed_p
;
9399 /* Resize the echo area window to exactly the size needed for the
9400 currently displayed message, if there is one. If a mini-buffer
9401 is active, don't shrink it. */
9404 resize_echo_area_exactly (void)
9406 if (BUFFERP (echo_area_buffer
[0])
9407 && WINDOWP (echo_area_window
))
9409 struct window
*w
= XWINDOW (echo_area_window
);
9411 Lisp_Object resize_exactly
;
9413 if (minibuf_level
== 0)
9414 resize_exactly
= Qt
;
9416 resize_exactly
= Qnil
;
9418 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
9419 (intptr_t) w
, resize_exactly
,
9423 ++windows_or_buffers_changed
;
9424 ++update_mode_lines
;
9425 redisplay_internal ();
9431 /* Callback function for with_echo_area_buffer, when used from
9432 resize_echo_area_exactly. A1 contains a pointer to the window to
9433 resize, EXACTLY non-nil means resize the mini-window exactly to the
9434 size of the text displayed. A3 and A4 are not used. Value is what
9435 resize_mini_window returns. */
9438 resize_mini_window_1 (EMACS_INT a1
, Lisp_Object exactly
, EMACS_INT a3
, EMACS_INT a4
)
9441 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
9445 /* Resize mini-window W to fit the size of its contents. EXACT_P
9446 means size the window exactly to the size needed. Otherwise, it's
9447 only enlarged until W's buffer is empty.
9449 Set W->start to the right place to begin display. If the whole
9450 contents fit, start at the beginning. Otherwise, start so as
9451 to make the end of the contents appear. This is particularly
9452 important for y-or-n-p, but seems desirable generally.
9454 Value is non-zero if the window height has been changed. */
9457 resize_mini_window (struct window
*w
, int exact_p
)
9459 struct frame
*f
= XFRAME (w
->frame
);
9460 int window_height_changed_p
= 0;
9462 xassert (MINI_WINDOW_P (w
));
9464 /* By default, start display at the beginning. */
9465 set_marker_both (w
->start
, w
->buffer
,
9466 BUF_BEGV (XBUFFER (w
->buffer
)),
9467 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
9469 /* Don't resize windows while redisplaying a window; it would
9470 confuse redisplay functions when the size of the window they are
9471 displaying changes from under them. Such a resizing can happen,
9472 for instance, when which-func prints a long message while
9473 we are running fontification-functions. We're running these
9474 functions with safe_call which binds inhibit-redisplay to t. */
9475 if (!NILP (Vinhibit_redisplay
))
9478 /* Nil means don't try to resize. */
9479 if (NILP (Vresize_mini_windows
)
9480 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
9483 if (!FRAME_MINIBUF_ONLY_P (f
))
9486 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
9487 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
9488 int height
, max_height
;
9489 int unit
= FRAME_LINE_HEIGHT (f
);
9490 struct text_pos start
;
9491 struct buffer
*old_current_buffer
= NULL
;
9493 if (current_buffer
!= XBUFFER (w
->buffer
))
9495 old_current_buffer
= current_buffer
;
9496 set_buffer_internal (XBUFFER (w
->buffer
));
9499 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9501 /* Compute the max. number of lines specified by the user. */
9502 if (FLOATP (Vmax_mini_window_height
))
9503 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
9504 else if (INTEGERP (Vmax_mini_window_height
))
9505 max_height
= XINT (Vmax_mini_window_height
);
9507 max_height
= total_height
/ 4;
9509 /* Correct that max. height if it's bogus. */
9510 max_height
= max (1, max_height
);
9511 max_height
= min (total_height
, max_height
);
9513 /* Find out the height of the text in the window. */
9514 if (it
.line_wrap
== TRUNCATE
)
9519 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
9520 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
9521 height
= it
.current_y
+ last_height
;
9523 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9524 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9525 height
= (height
+ unit
- 1) / unit
;
9528 /* Compute a suitable window start. */
9529 if (height
> max_height
)
9531 height
= max_height
;
9532 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9533 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9534 start
= it
.current
.pos
;
9537 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9538 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9540 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9542 /* Let it grow only, until we display an empty message, in which
9543 case the window shrinks again. */
9544 if (height
> WINDOW_TOTAL_LINES (w
))
9546 int old_height
= WINDOW_TOTAL_LINES (w
);
9547 freeze_window_starts (f
, 1);
9548 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9549 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9551 else if (height
< WINDOW_TOTAL_LINES (w
)
9552 && (exact_p
|| BEGV
== ZV
))
9554 int old_height
= WINDOW_TOTAL_LINES (w
);
9555 freeze_window_starts (f
, 0);
9556 shrink_mini_window (w
);
9557 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9562 /* Always resize to exact size needed. */
9563 if (height
> WINDOW_TOTAL_LINES (w
))
9565 int old_height
= WINDOW_TOTAL_LINES (w
);
9566 freeze_window_starts (f
, 1);
9567 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9568 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9570 else if (height
< WINDOW_TOTAL_LINES (w
))
9572 int old_height
= WINDOW_TOTAL_LINES (w
);
9573 freeze_window_starts (f
, 0);
9574 shrink_mini_window (w
);
9578 freeze_window_starts (f
, 1);
9579 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9582 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9586 if (old_current_buffer
)
9587 set_buffer_internal (old_current_buffer
);
9590 return window_height_changed_p
;
9594 /* Value is the current message, a string, or nil if there is no
9598 current_message (void)
9602 if (!BUFFERP (echo_area_buffer
[0]))
9606 with_echo_area_buffer (0, 0, current_message_1
,
9607 (intptr_t) &msg
, Qnil
, 0, 0);
9609 echo_area_buffer
[0] = Qnil
;
9617 current_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9620 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
9623 *msg
= make_buffer_string (BEG
, Z
, 1);
9630 /* Push the current message on Vmessage_stack for later restauration
9631 by restore_message. Value is non-zero if the current message isn't
9632 empty. This is a relatively infrequent operation, so it's not
9633 worth optimizing. */
9639 msg
= current_message ();
9640 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9641 return STRINGP (msg
);
9645 /* Restore message display from the top of Vmessage_stack. */
9648 restore_message (void)
9652 xassert (CONSP (Vmessage_stack
));
9653 msg
= XCAR (Vmessage_stack
);
9655 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9657 message3_nolog (msg
, 0, 0);
9661 /* Handler for record_unwind_protect calling pop_message. */
9664 pop_message_unwind (Lisp_Object dummy
)
9670 /* Pop the top-most entry off Vmessage_stack. */
9675 xassert (CONSP (Vmessage_stack
));
9676 Vmessage_stack
= XCDR (Vmessage_stack
);
9680 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9681 exits. If the stack is not empty, we have a missing pop_message
9685 check_message_stack (void)
9687 if (!NILP (Vmessage_stack
))
9692 /* Truncate to NCHARS what will be displayed in the echo area the next
9693 time we display it---but don't redisplay it now. */
9696 truncate_echo_area (EMACS_INT nchars
)
9699 echo_area_buffer
[0] = Qnil
;
9700 /* A null message buffer means that the frame hasn't really been
9701 initialized yet. Error messages get reported properly by
9702 cmd_error, so this must be just an informative message; toss it. */
9703 else if (!noninteractive
9705 && !NILP (echo_area_buffer
[0]))
9707 struct frame
*sf
= SELECTED_FRAME ();
9708 if (FRAME_MESSAGE_BUF (sf
))
9709 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9714 /* Helper function for truncate_echo_area. Truncate the current
9715 message to at most NCHARS characters. */
9718 truncate_message_1 (EMACS_INT nchars
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9720 if (BEG
+ nchars
< Z
)
9721 del_range (BEG
+ nchars
, Z
);
9723 echo_area_buffer
[0] = Qnil
;
9728 /* Set the current message to a substring of S or STRING.
9730 If STRING is a Lisp string, set the message to the first NBYTES
9731 bytes from STRING. NBYTES zero means use the whole string. If
9732 STRING is multibyte, the message will be displayed multibyte.
9734 If S is not null, set the message to the first LEN bytes of S. LEN
9735 zero means use the whole string. MULTIBYTE_P non-zero means S is
9736 multibyte. Display the message multibyte in that case.
9738 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9739 to t before calling set_message_1 (which calls insert).
9743 set_message (const char *s
, Lisp_Object string
,
9744 EMACS_INT nbytes
, int multibyte_p
)
9746 message_enable_multibyte
9747 = ((s
&& multibyte_p
)
9748 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9750 with_echo_area_buffer (0, -1, set_message_1
,
9751 (intptr_t) s
, string
, nbytes
, multibyte_p
);
9752 message_buf_print
= 0;
9753 help_echo_showing_p
= 0;
9757 /* Helper function for set_message. Arguments have the same meaning
9758 as there, with A1 corresponding to S and A2 corresponding to STRING
9759 This function is called with the echo area buffer being
9763 set_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT nbytes
, EMACS_INT multibyte_p
)
9766 const char *s
= (const char *) i1
;
9767 const unsigned char *msg
= (const unsigned char *) s
;
9768 Lisp_Object string
= a2
;
9770 /* Change multibyteness of the echo buffer appropriately. */
9771 if (message_enable_multibyte
9772 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9773 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9775 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
9776 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
9777 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
9779 /* Insert new message at BEG. */
9780 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9782 if (STRINGP (string
))
9787 nbytes
= SBYTES (string
);
9788 nchars
= string_byte_to_char (string
, nbytes
);
9790 /* This function takes care of single/multibyte conversion. We
9791 just have to ensure that the echo area buffer has the right
9792 setting of enable_multibyte_characters. */
9793 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9798 nbytes
= strlen (s
);
9800 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9802 /* Convert from multi-byte to single-byte. */
9807 /* Convert a multibyte string to single-byte. */
9808 for (i
= 0; i
< nbytes
; i
+= n
)
9810 c
= string_char_and_length (msg
+ i
, &n
);
9811 work
[0] = (ASCII_CHAR_P (c
)
9813 : multibyte_char_to_unibyte (c
));
9814 insert_1_both (work
, 1, 1, 1, 0, 0);
9817 else if (!multibyte_p
9818 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9820 /* Convert from single-byte to multi-byte. */
9823 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9825 /* Convert a single-byte string to multibyte. */
9826 for (i
= 0; i
< nbytes
; i
++)
9829 MAKE_CHAR_MULTIBYTE (c
);
9830 n
= CHAR_STRING (c
, str
);
9831 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
9835 insert_1 (s
, nbytes
, 1, 0, 0);
9842 /* Clear messages. CURRENT_P non-zero means clear the current
9843 message. LAST_DISPLAYED_P non-zero means clear the message
9847 clear_message (int current_p
, int last_displayed_p
)
9851 echo_area_buffer
[0] = Qnil
;
9852 message_cleared_p
= 1;
9855 if (last_displayed_p
)
9856 echo_area_buffer
[1] = Qnil
;
9858 message_buf_print
= 0;
9861 /* Clear garbaged frames.
9863 This function is used where the old redisplay called
9864 redraw_garbaged_frames which in turn called redraw_frame which in
9865 turn called clear_frame. The call to clear_frame was a source of
9866 flickering. I believe a clear_frame is not necessary. It should
9867 suffice in the new redisplay to invalidate all current matrices,
9868 and ensure a complete redisplay of all windows. */
9871 clear_garbaged_frames (void)
9875 Lisp_Object tail
, frame
;
9876 int changed_count
= 0;
9878 FOR_EACH_FRAME (tail
, frame
)
9880 struct frame
*f
= XFRAME (frame
);
9882 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9886 Fredraw_frame (frame
);
9887 f
->force_flush_display_p
= 1;
9889 clear_current_matrices (f
);
9898 ++windows_or_buffers_changed
;
9903 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9904 is non-zero update selected_frame. Value is non-zero if the
9905 mini-windows height has been changed. */
9908 echo_area_display (int update_frame_p
)
9910 Lisp_Object mini_window
;
9913 int window_height_changed_p
= 0;
9914 struct frame
*sf
= SELECTED_FRAME ();
9916 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9917 w
= XWINDOW (mini_window
);
9918 f
= XFRAME (WINDOW_FRAME (w
));
9920 /* Don't display if frame is invisible or not yet initialized. */
9921 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9924 #ifdef HAVE_WINDOW_SYSTEM
9925 /* When Emacs starts, selected_frame may be the initial terminal
9926 frame. If we let this through, a message would be displayed on
9928 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9930 #endif /* HAVE_WINDOW_SYSTEM */
9932 /* Redraw garbaged frames. */
9934 clear_garbaged_frames ();
9936 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9938 echo_area_window
= mini_window
;
9939 window_height_changed_p
= display_echo_area (w
);
9940 w
->must_be_updated_p
= 1;
9942 /* Update the display, unless called from redisplay_internal.
9943 Also don't update the screen during redisplay itself. The
9944 update will happen at the end of redisplay, and an update
9945 here could cause confusion. */
9946 if (update_frame_p
&& !redisplaying_p
)
9950 /* If the display update has been interrupted by pending
9951 input, update mode lines in the frame. Due to the
9952 pending input, it might have been that redisplay hasn't
9953 been called, so that mode lines above the echo area are
9954 garbaged. This looks odd, so we prevent it here. */
9955 if (!display_completed
)
9956 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9958 if (window_height_changed_p
9959 /* Don't do this if Emacs is shutting down. Redisplay
9960 needs to run hooks. */
9961 && !NILP (Vrun_hooks
))
9963 /* Must update other windows. Likewise as in other
9964 cases, don't let this update be interrupted by
9966 int count
= SPECPDL_INDEX ();
9967 specbind (Qredisplay_dont_pause
, Qt
);
9968 windows_or_buffers_changed
= 1;
9969 redisplay_internal ();
9970 unbind_to (count
, Qnil
);
9972 else if (FRAME_WINDOW_P (f
) && n
== 0)
9974 /* Window configuration is the same as before.
9975 Can do with a display update of the echo area,
9976 unless we displayed some mode lines. */
9977 update_single_window (w
, 1);
9978 FRAME_RIF (f
)->flush_display (f
);
9981 update_frame (f
, 1, 1);
9983 /* If cursor is in the echo area, make sure that the next
9984 redisplay displays the minibuffer, so that the cursor will
9985 be replaced with what the minibuffer wants. */
9986 if (cursor_in_echo_area
)
9987 ++windows_or_buffers_changed
;
9990 else if (!EQ (mini_window
, selected_window
))
9991 windows_or_buffers_changed
++;
9993 /* Last displayed message is now the current message. */
9994 echo_area_buffer
[1] = echo_area_buffer
[0];
9995 /* Inform read_char that we're not echoing. */
9996 echo_message_buffer
= Qnil
;
9998 /* Prevent redisplay optimization in redisplay_internal by resetting
9999 this_line_start_pos. This is done because the mini-buffer now
10000 displays the message instead of its buffer text. */
10001 if (EQ (mini_window
, selected_window
))
10002 CHARPOS (this_line_start_pos
) = 0;
10004 return window_height_changed_p
;
10009 /***********************************************************************
10010 Mode Lines and Frame Titles
10011 ***********************************************************************/
10013 /* A buffer for constructing non-propertized mode-line strings and
10014 frame titles in it; allocated from the heap in init_xdisp and
10015 resized as needed in store_mode_line_noprop_char. */
10017 static char *mode_line_noprop_buf
;
10019 /* The buffer's end, and a current output position in it. */
10021 static char *mode_line_noprop_buf_end
;
10022 static char *mode_line_noprop_ptr
;
10024 #define MODE_LINE_NOPROP_LEN(start) \
10025 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10028 MODE_LINE_DISPLAY
= 0,
10032 } mode_line_target
;
10034 /* Alist that caches the results of :propertize.
10035 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10036 static Lisp_Object mode_line_proptrans_alist
;
10038 /* List of strings making up the mode-line. */
10039 static Lisp_Object mode_line_string_list
;
10041 /* Base face property when building propertized mode line string. */
10042 static Lisp_Object mode_line_string_face
;
10043 static Lisp_Object mode_line_string_face_prop
;
10046 /* Unwind data for mode line strings */
10048 static Lisp_Object Vmode_line_unwind_vector
;
10051 format_mode_line_unwind_data (struct buffer
*obuf
,
10053 int save_proptrans
)
10055 Lisp_Object vector
, tmp
;
10057 /* Reduce consing by keeping one vector in
10058 Vwith_echo_area_save_vector. */
10059 vector
= Vmode_line_unwind_vector
;
10060 Vmode_line_unwind_vector
= Qnil
;
10063 vector
= Fmake_vector (make_number (8), Qnil
);
10065 ASET (vector
, 0, make_number (mode_line_target
));
10066 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10067 ASET (vector
, 2, mode_line_string_list
);
10068 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10069 ASET (vector
, 4, mode_line_string_face
);
10070 ASET (vector
, 5, mode_line_string_face_prop
);
10073 XSETBUFFER (tmp
, obuf
);
10076 ASET (vector
, 6, tmp
);
10077 ASET (vector
, 7, owin
);
10083 unwind_format_mode_line (Lisp_Object vector
)
10085 mode_line_target
= XINT (AREF (vector
, 0));
10086 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10087 mode_line_string_list
= AREF (vector
, 2);
10088 if (! EQ (AREF (vector
, 3), Qt
))
10089 mode_line_proptrans_alist
= AREF (vector
, 3);
10090 mode_line_string_face
= AREF (vector
, 4);
10091 mode_line_string_face_prop
= AREF (vector
, 5);
10093 if (!NILP (AREF (vector
, 7)))
10094 /* Select window before buffer, since it may change the buffer. */
10095 Fselect_window (AREF (vector
, 7), Qt
);
10097 if (!NILP (AREF (vector
, 6)))
10099 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10100 ASET (vector
, 6, Qnil
);
10103 Vmode_line_unwind_vector
= vector
;
10108 /* Store a single character C for the frame title in mode_line_noprop_buf.
10109 Re-allocate mode_line_noprop_buf if necessary. */
10112 store_mode_line_noprop_char (char c
)
10114 /* If output position has reached the end of the allocated buffer,
10115 double the buffer's size. */
10116 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10118 int len
= MODE_LINE_NOPROP_LEN (0);
10119 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
10120 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
10121 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
10122 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10125 *mode_line_noprop_ptr
++ = c
;
10129 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10130 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10131 characters that yield more columns than PRECISION; PRECISION <= 0
10132 means copy the whole string. Pad with spaces until FIELD_WIDTH
10133 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10134 pad. Called from display_mode_element when it is used to build a
10138 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10140 const unsigned char *str
= (const unsigned char *) string
;
10142 EMACS_INT dummy
, nbytes
;
10144 /* Copy at most PRECISION chars from STR. */
10145 nbytes
= strlen (string
);
10146 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10148 store_mode_line_noprop_char (*str
++);
10150 /* Fill up with spaces until FIELD_WIDTH reached. */
10151 while (field_width
> 0
10152 && n
< field_width
)
10154 store_mode_line_noprop_char (' ');
10161 /***********************************************************************
10163 ***********************************************************************/
10165 #ifdef HAVE_WINDOW_SYSTEM
10167 /* Set the title of FRAME, if it has changed. The title format is
10168 Vicon_title_format if FRAME is iconified, otherwise it is
10169 frame_title_format. */
10172 x_consider_frame_title (Lisp_Object frame
)
10174 struct frame
*f
= XFRAME (frame
);
10176 if (FRAME_WINDOW_P (f
)
10177 || FRAME_MINIBUF_ONLY_P (f
)
10178 || f
->explicit_name
)
10180 /* Do we have more than one visible frame on this X display? */
10187 int count
= SPECPDL_INDEX ();
10189 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
10191 Lisp_Object other_frame
= XCAR (tail
);
10192 struct frame
*tf
= XFRAME (other_frame
);
10195 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
10196 && !FRAME_MINIBUF_ONLY_P (tf
)
10197 && !EQ (other_frame
, tip_frame
)
10198 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
10202 /* Set global variable indicating that multiple frames exist. */
10203 multiple_frames
= CONSP (tail
);
10205 /* Switch to the buffer of selected window of the frame. Set up
10206 mode_line_target so that display_mode_element will output into
10207 mode_line_noprop_buf; then display the title. */
10208 record_unwind_protect (unwind_format_mode_line
,
10209 format_mode_line_unwind_data
10210 (current_buffer
, selected_window
, 0));
10212 Fselect_window (f
->selected_window
, Qt
);
10213 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
10214 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
10216 mode_line_target
= MODE_LINE_TITLE
;
10217 title_start
= MODE_LINE_NOPROP_LEN (0);
10218 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
10219 NULL
, DEFAULT_FACE_ID
);
10220 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
10221 len
= MODE_LINE_NOPROP_LEN (title_start
);
10222 title
= mode_line_noprop_buf
+ title_start
;
10223 unbind_to (count
, Qnil
);
10225 /* Set the title only if it's changed. This avoids consing in
10226 the common case where it hasn't. (If it turns out that we've
10227 already wasted too much time by walking through the list with
10228 display_mode_element, then we might need to optimize at a
10229 higher level than this.) */
10230 if (! STRINGP (f
->name
)
10231 || SBYTES (f
->name
) != len
10232 || memcmp (title
, SDATA (f
->name
), len
) != 0)
10233 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
10237 #endif /* not HAVE_WINDOW_SYSTEM */
10242 /***********************************************************************
10244 ***********************************************************************/
10247 /* Prepare for redisplay by updating menu-bar item lists when
10248 appropriate. This can call eval. */
10251 prepare_menu_bars (void)
10254 struct gcpro gcpro1
, gcpro2
;
10256 Lisp_Object tooltip_frame
;
10258 #ifdef HAVE_WINDOW_SYSTEM
10259 tooltip_frame
= tip_frame
;
10261 tooltip_frame
= Qnil
;
10264 /* Update all frame titles based on their buffer names, etc. We do
10265 this before the menu bars so that the buffer-menu will show the
10266 up-to-date frame titles. */
10267 #ifdef HAVE_WINDOW_SYSTEM
10268 if (windows_or_buffers_changed
|| update_mode_lines
)
10270 Lisp_Object tail
, frame
;
10272 FOR_EACH_FRAME (tail
, frame
)
10274 f
= XFRAME (frame
);
10275 if (!EQ (frame
, tooltip_frame
)
10276 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
10277 x_consider_frame_title (frame
);
10280 #endif /* HAVE_WINDOW_SYSTEM */
10282 /* Update the menu bar item lists, if appropriate. This has to be
10283 done before any actual redisplay or generation of display lines. */
10284 all_windows
= (update_mode_lines
10285 || buffer_shared
> 1
10286 || windows_or_buffers_changed
);
10289 Lisp_Object tail
, frame
;
10290 int count
= SPECPDL_INDEX ();
10291 /* 1 means that update_menu_bar has run its hooks
10292 so any further calls to update_menu_bar shouldn't do so again. */
10293 int menu_bar_hooks_run
= 0;
10295 record_unwind_save_match_data ();
10297 FOR_EACH_FRAME (tail
, frame
)
10299 f
= XFRAME (frame
);
10301 /* Ignore tooltip frame. */
10302 if (EQ (frame
, tooltip_frame
))
10305 /* If a window on this frame changed size, report that to
10306 the user and clear the size-change flag. */
10307 if (FRAME_WINDOW_SIZES_CHANGED (f
))
10309 Lisp_Object functions
;
10311 /* Clear flag first in case we get an error below. */
10312 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
10313 functions
= Vwindow_size_change_functions
;
10314 GCPRO2 (tail
, functions
);
10316 while (CONSP (functions
))
10318 if (!EQ (XCAR (functions
), Qt
))
10319 call1 (XCAR (functions
), frame
);
10320 functions
= XCDR (functions
);
10326 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
10327 #ifdef HAVE_WINDOW_SYSTEM
10328 update_tool_bar (f
, 0);
10331 if (windows_or_buffers_changed
10333 ns_set_doc_edited (f
, Fbuffer_modified_p
10334 (XWINDOW (f
->selected_window
)->buffer
));
10339 unbind_to (count
, Qnil
);
10343 struct frame
*sf
= SELECTED_FRAME ();
10344 update_menu_bar (sf
, 1, 0);
10345 #ifdef HAVE_WINDOW_SYSTEM
10346 update_tool_bar (sf
, 1);
10352 /* Update the menu bar item list for frame F. This has to be done
10353 before we start to fill in any display lines, because it can call
10356 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
10358 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
10359 already ran the menu bar hooks for this redisplay, so there
10360 is no need to run them again. The return value is the
10361 updated value of this flag, to pass to the next call. */
10364 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
10366 Lisp_Object window
;
10367 register struct window
*w
;
10369 /* If called recursively during a menu update, do nothing. This can
10370 happen when, for instance, an activate-menubar-hook causes a
10372 if (inhibit_menubar_update
)
10375 window
= FRAME_SELECTED_WINDOW (f
);
10376 w
= XWINDOW (window
);
10378 if (FRAME_WINDOW_P (f
)
10380 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10381 || defined (HAVE_NS) || defined (USE_GTK)
10382 FRAME_EXTERNAL_MENU_BAR (f
)
10384 FRAME_MENU_BAR_LINES (f
) > 0
10386 : FRAME_MENU_BAR_LINES (f
) > 0)
10388 /* If the user has switched buffers or windows, we need to
10389 recompute to reflect the new bindings. But we'll
10390 recompute when update_mode_lines is set too; that means
10391 that people can use force-mode-line-update to request
10392 that the menu bar be recomputed. The adverse effect on
10393 the rest of the redisplay algorithm is about the same as
10394 windows_or_buffers_changed anyway. */
10395 if (windows_or_buffers_changed
10396 /* This used to test w->update_mode_line, but we believe
10397 there is no need to recompute the menu in that case. */
10398 || update_mode_lines
10399 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10400 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10401 != !NILP (w
->last_had_star
))
10402 || ((!NILP (Vtransient_mark_mode
)
10403 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10404 != !NILP (w
->region_showing
)))
10406 struct buffer
*prev
= current_buffer
;
10407 int count
= SPECPDL_INDEX ();
10409 specbind (Qinhibit_menubar_update
, Qt
);
10411 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10412 if (save_match_data
)
10413 record_unwind_save_match_data ();
10414 if (NILP (Voverriding_local_map_menu_flag
))
10416 specbind (Qoverriding_terminal_local_map
, Qnil
);
10417 specbind (Qoverriding_local_map
, Qnil
);
10422 /* Run the Lucid hook. */
10423 safe_run_hooks (Qactivate_menubar_hook
);
10425 /* If it has changed current-menubar from previous value,
10426 really recompute the menu-bar from the value. */
10427 if (! NILP (Vlucid_menu_bar_dirty_flag
))
10428 call0 (Qrecompute_lucid_menubar
);
10430 safe_run_hooks (Qmenu_bar_update_hook
);
10435 XSETFRAME (Vmenu_updating_frame
, f
);
10436 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
10438 /* Redisplay the menu bar in case we changed it. */
10439 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10440 || defined (HAVE_NS) || defined (USE_GTK)
10441 if (FRAME_WINDOW_P (f
))
10443 #if defined (HAVE_NS)
10444 /* All frames on Mac OS share the same menubar. So only
10445 the selected frame should be allowed to set it. */
10446 if (f
== SELECTED_FRAME ())
10448 set_frame_menubar (f
, 0, 0);
10451 /* On a terminal screen, the menu bar is an ordinary screen
10452 line, and this makes it get updated. */
10453 w
->update_mode_line
= Qt
;
10454 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10455 /* In the non-toolkit version, the menu bar is an ordinary screen
10456 line, and this makes it get updated. */
10457 w
->update_mode_line
= Qt
;
10458 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10460 unbind_to (count
, Qnil
);
10461 set_buffer_internal_1 (prev
);
10470 /***********************************************************************
10472 ***********************************************************************/
10474 #ifdef HAVE_WINDOW_SYSTEM
10477 Nominal cursor position -- where to draw output.
10478 HPOS and VPOS are window relative glyph matrix coordinates.
10479 X and Y are window relative pixel coordinates. */
10481 struct cursor_pos output_cursor
;
10485 Set the global variable output_cursor to CURSOR. All cursor
10486 positions are relative to updated_window. */
10489 set_output_cursor (struct cursor_pos
*cursor
)
10491 output_cursor
.hpos
= cursor
->hpos
;
10492 output_cursor
.vpos
= cursor
->vpos
;
10493 output_cursor
.x
= cursor
->x
;
10494 output_cursor
.y
= cursor
->y
;
10499 Set a nominal cursor position.
10501 HPOS and VPOS are column/row positions in a window glyph matrix. X
10502 and Y are window text area relative pixel positions.
10504 If this is done during an update, updated_window will contain the
10505 window that is being updated and the position is the future output
10506 cursor position for that window. If updated_window is null, use
10507 selected_window and display the cursor at the given position. */
10510 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
10514 /* If updated_window is not set, work on selected_window. */
10515 if (updated_window
)
10516 w
= updated_window
;
10518 w
= XWINDOW (selected_window
);
10520 /* Set the output cursor. */
10521 output_cursor
.hpos
= hpos
;
10522 output_cursor
.vpos
= vpos
;
10523 output_cursor
.x
= x
;
10524 output_cursor
.y
= y
;
10526 /* If not called as part of an update, really display the cursor.
10527 This will also set the cursor position of W. */
10528 if (updated_window
== NULL
)
10531 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10532 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10533 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10538 #endif /* HAVE_WINDOW_SYSTEM */
10541 /***********************************************************************
10543 ***********************************************************************/
10545 #ifdef HAVE_WINDOW_SYSTEM
10547 /* Where the mouse was last time we reported a mouse event. */
10549 FRAME_PTR last_mouse_frame
;
10551 /* Tool-bar item index of the item on which a mouse button was pressed
10554 int last_tool_bar_item
;
10558 update_tool_bar_unwind (Lisp_Object frame
)
10560 selected_frame
= frame
;
10564 /* Update the tool-bar item list for frame F. This has to be done
10565 before we start to fill in any display lines. Called from
10566 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10567 and restore it here. */
10570 update_tool_bar (struct frame
*f
, int save_match_data
)
10572 #if defined (USE_GTK) || defined (HAVE_NS)
10573 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10575 int do_update
= WINDOWP (f
->tool_bar_window
)
10576 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10581 Lisp_Object window
;
10584 window
= FRAME_SELECTED_WINDOW (f
);
10585 w
= XWINDOW (window
);
10587 /* If the user has switched buffers or windows, we need to
10588 recompute to reflect the new bindings. But we'll
10589 recompute when update_mode_lines is set too; that means
10590 that people can use force-mode-line-update to request
10591 that the menu bar be recomputed. The adverse effect on
10592 the rest of the redisplay algorithm is about the same as
10593 windows_or_buffers_changed anyway. */
10594 if (windows_or_buffers_changed
10595 || !NILP (w
->update_mode_line
)
10596 || update_mode_lines
10597 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10598 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10599 != !NILP (w
->last_had_star
))
10600 || ((!NILP (Vtransient_mark_mode
)
10601 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10602 != !NILP (w
->region_showing
)))
10604 struct buffer
*prev
= current_buffer
;
10605 int count
= SPECPDL_INDEX ();
10606 Lisp_Object frame
, new_tool_bar
;
10607 int new_n_tool_bar
;
10608 struct gcpro gcpro1
;
10610 /* Set current_buffer to the buffer of the selected
10611 window of the frame, so that we get the right local
10613 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10615 /* Save match data, if we must. */
10616 if (save_match_data
)
10617 record_unwind_save_match_data ();
10619 /* Make sure that we don't accidentally use bogus keymaps. */
10620 if (NILP (Voverriding_local_map_menu_flag
))
10622 specbind (Qoverriding_terminal_local_map
, Qnil
);
10623 specbind (Qoverriding_local_map
, Qnil
);
10626 GCPRO1 (new_tool_bar
);
10628 /* We must temporarily set the selected frame to this frame
10629 before calling tool_bar_items, because the calculation of
10630 the tool-bar keymap uses the selected frame (see
10631 `tool-bar-make-keymap' in tool-bar.el). */
10632 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10633 XSETFRAME (frame
, f
);
10634 selected_frame
= frame
;
10636 /* Build desired tool-bar items from keymaps. */
10637 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10640 /* Redisplay the tool-bar if we changed it. */
10641 if (new_n_tool_bar
!= f
->n_tool_bar_items
10642 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10644 /* Redisplay that happens asynchronously due to an expose event
10645 may access f->tool_bar_items. Make sure we update both
10646 variables within BLOCK_INPUT so no such event interrupts. */
10648 f
->tool_bar_items
= new_tool_bar
;
10649 f
->n_tool_bar_items
= new_n_tool_bar
;
10650 w
->update_mode_line
= Qt
;
10656 unbind_to (count
, Qnil
);
10657 set_buffer_internal_1 (prev
);
10663 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10664 F's desired tool-bar contents. F->tool_bar_items must have
10665 been set up previously by calling prepare_menu_bars. */
10668 build_desired_tool_bar_string (struct frame
*f
)
10670 int i
, size
, size_needed
;
10671 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10672 Lisp_Object image
, plist
, props
;
10674 image
= plist
= props
= Qnil
;
10675 GCPRO3 (image
, plist
, props
);
10677 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10678 Otherwise, make a new string. */
10680 /* The size of the string we might be able to reuse. */
10681 size
= (STRINGP (f
->desired_tool_bar_string
)
10682 ? SCHARS (f
->desired_tool_bar_string
)
10685 /* We need one space in the string for each image. */
10686 size_needed
= f
->n_tool_bar_items
;
10688 /* Reuse f->desired_tool_bar_string, if possible. */
10689 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10690 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10691 make_number (' '));
10694 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10695 Fremove_text_properties (make_number (0), make_number (size
),
10696 props
, f
->desired_tool_bar_string
);
10699 /* Put a `display' property on the string for the images to display,
10700 put a `menu_item' property on tool-bar items with a value that
10701 is the index of the item in F's tool-bar item vector. */
10702 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10704 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10706 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10707 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10708 int hmargin
, vmargin
, relief
, idx
, end
;
10710 /* If image is a vector, choose the image according to the
10712 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10713 if (VECTORP (image
))
10717 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10718 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10721 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10722 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10724 xassert (ASIZE (image
) >= idx
);
10725 image
= AREF (image
, idx
);
10730 /* Ignore invalid image specifications. */
10731 if (!valid_image_p (image
))
10734 /* Display the tool-bar button pressed, or depressed. */
10735 plist
= Fcopy_sequence (XCDR (image
));
10737 /* Compute margin and relief to draw. */
10738 relief
= (tool_bar_button_relief
>= 0
10739 ? tool_bar_button_relief
10740 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10741 hmargin
= vmargin
= relief
;
10743 if (INTEGERP (Vtool_bar_button_margin
)
10744 && XINT (Vtool_bar_button_margin
) > 0)
10746 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10747 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10749 else if (CONSP (Vtool_bar_button_margin
))
10751 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10752 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10753 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10755 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10756 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10757 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10760 if (auto_raise_tool_bar_buttons_p
)
10762 /* Add a `:relief' property to the image spec if the item is
10766 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10773 /* If image is selected, display it pressed, i.e. with a
10774 negative relief. If it's not selected, display it with a
10776 plist
= Fplist_put (plist
, QCrelief
,
10778 ? make_number (-relief
)
10779 : make_number (relief
)));
10784 /* Put a margin around the image. */
10785 if (hmargin
|| vmargin
)
10787 if (hmargin
== vmargin
)
10788 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10790 plist
= Fplist_put (plist
, QCmargin
,
10791 Fcons (make_number (hmargin
),
10792 make_number (vmargin
)));
10795 /* If button is not enabled, and we don't have special images
10796 for the disabled state, make the image appear disabled by
10797 applying an appropriate algorithm to it. */
10798 if (!enabled_p
&& idx
< 0)
10799 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10801 /* Put a `display' text property on the string for the image to
10802 display. Put a `menu-item' property on the string that gives
10803 the start of this item's properties in the tool-bar items
10805 image
= Fcons (Qimage
, plist
);
10806 props
= list4 (Qdisplay
, image
,
10807 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10809 /* Let the last image hide all remaining spaces in the tool bar
10810 string. The string can be longer than needed when we reuse a
10811 previous string. */
10812 if (i
+ 1 == f
->n_tool_bar_items
)
10813 end
= SCHARS (f
->desired_tool_bar_string
);
10816 Fadd_text_properties (make_number (i
), make_number (end
),
10817 props
, f
->desired_tool_bar_string
);
10825 /* Display one line of the tool-bar of frame IT->f.
10827 HEIGHT specifies the desired height of the tool-bar line.
10828 If the actual height of the glyph row is less than HEIGHT, the
10829 row's height is increased to HEIGHT, and the icons are centered
10830 vertically in the new height.
10832 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10833 count a final empty row in case the tool-bar width exactly matches
10838 display_tool_bar_line (struct it
*it
, int height
)
10840 struct glyph_row
*row
= it
->glyph_row
;
10841 int max_x
= it
->last_visible_x
;
10842 struct glyph
*last
;
10844 prepare_desired_row (row
);
10845 row
->y
= it
->current_y
;
10847 /* Note that this isn't made use of if the face hasn't a box,
10848 so there's no need to check the face here. */
10849 it
->start_of_box_run_p
= 1;
10851 while (it
->current_x
< max_x
)
10853 int x
, n_glyphs_before
, i
, nglyphs
;
10854 struct it it_before
;
10856 /* Get the next display element. */
10857 if (!get_next_display_element (it
))
10859 /* Don't count empty row if we are counting needed tool-bar lines. */
10860 if (height
< 0 && !it
->hpos
)
10865 /* Produce glyphs. */
10866 n_glyphs_before
= row
->used
[TEXT_AREA
];
10869 PRODUCE_GLYPHS (it
);
10871 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10873 x
= it_before
.current_x
;
10874 while (i
< nglyphs
)
10876 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10878 if (x
+ glyph
->pixel_width
> max_x
)
10880 /* Glyph doesn't fit on line. Backtrack. */
10881 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10883 /* If this is the only glyph on this line, it will never fit on the
10884 tool-bar, so skip it. But ensure there is at least one glyph,
10885 so we don't accidentally disable the tool-bar. */
10886 if (n_glyphs_before
== 0
10887 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10893 x
+= glyph
->pixel_width
;
10897 /* Stop at line end. */
10898 if (ITERATOR_AT_END_OF_LINE_P (it
))
10901 set_iterator_to_next (it
, 1);
10906 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10908 /* Use default face for the border below the tool bar.
10910 FIXME: When auto-resize-tool-bars is grow-only, there is
10911 no additional border below the possibly empty tool-bar lines.
10912 So to make the extra empty lines look "normal", we have to
10913 use the tool-bar face for the border too. */
10914 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10915 it
->face_id
= DEFAULT_FACE_ID
;
10917 extend_face_to_end_of_line (it
);
10918 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10919 last
->right_box_line_p
= 1;
10920 if (last
== row
->glyphs
[TEXT_AREA
])
10921 last
->left_box_line_p
= 1;
10923 /* Make line the desired height and center it vertically. */
10924 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10926 /* Don't add more than one line height. */
10927 height
%= FRAME_LINE_HEIGHT (it
->f
);
10928 it
->max_ascent
+= height
/ 2;
10929 it
->max_descent
+= (height
+ 1) / 2;
10932 compute_line_metrics (it
);
10934 /* If line is empty, make it occupy the rest of the tool-bar. */
10935 if (!row
->displays_text_p
)
10937 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10938 row
->visible_height
= row
->height
;
10939 row
->ascent
= row
->phys_ascent
= 0;
10940 row
->extra_line_spacing
= 0;
10943 row
->full_width_p
= 1;
10944 row
->continued_p
= 0;
10945 row
->truncated_on_left_p
= 0;
10946 row
->truncated_on_right_p
= 0;
10948 it
->current_x
= it
->hpos
= 0;
10949 it
->current_y
+= row
->height
;
10955 /* Max tool-bar height. */
10957 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10958 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10960 /* Value is the number of screen lines needed to make all tool-bar
10961 items of frame F visible. The number of actual rows needed is
10962 returned in *N_ROWS if non-NULL. */
10965 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
10967 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10969 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10970 the desired matrix, so use (unused) mode-line row as temporary row to
10971 avoid destroying the first tool-bar row. */
10972 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10974 /* Initialize an iterator for iteration over
10975 F->desired_tool_bar_string in the tool-bar window of frame F. */
10976 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10977 it
.first_visible_x
= 0;
10978 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10979 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10980 it
.paragraph_embedding
= L2R
;
10982 while (!ITERATOR_AT_END_P (&it
))
10984 clear_glyph_row (temp_row
);
10985 it
.glyph_row
= temp_row
;
10986 display_tool_bar_line (&it
, -1);
10988 clear_glyph_row (temp_row
);
10990 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10992 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10994 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10998 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11000 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11001 (Lisp_Object frame
)
11008 frame
= selected_frame
;
11010 CHECK_FRAME (frame
);
11011 f
= XFRAME (frame
);
11013 if (WINDOWP (f
->tool_bar_window
)
11014 || (w
= XWINDOW (f
->tool_bar_window
),
11015 WINDOW_TOTAL_LINES (w
) > 0))
11017 update_tool_bar (f
, 1);
11018 if (f
->n_tool_bar_items
)
11020 build_desired_tool_bar_string (f
);
11021 nlines
= tool_bar_lines_needed (f
, NULL
);
11025 return make_number (nlines
);
11029 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11030 height should be changed. */
11033 redisplay_tool_bar (struct frame
*f
)
11037 struct glyph_row
*row
;
11039 #if defined (USE_GTK) || defined (HAVE_NS)
11040 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11041 update_frame_tool_bar (f
);
11045 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11046 do anything. This means you must start with tool-bar-lines
11047 non-zero to get the auto-sizing effect. Or in other words, you
11048 can turn off tool-bars by specifying tool-bar-lines zero. */
11049 if (!WINDOWP (f
->tool_bar_window
)
11050 || (w
= XWINDOW (f
->tool_bar_window
),
11051 WINDOW_TOTAL_LINES (w
) == 0))
11054 /* Set up an iterator for the tool-bar window. */
11055 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11056 it
.first_visible_x
= 0;
11057 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11058 row
= it
.glyph_row
;
11060 /* Build a string that represents the contents of the tool-bar. */
11061 build_desired_tool_bar_string (f
);
11062 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11063 /* FIXME: This should be controlled by a user option. But it
11064 doesn't make sense to have an R2L tool bar if the menu bar cannot
11065 be drawn also R2L, and making the menu bar R2L is tricky due to
11066 unibyte strings it uses and toolkit-specific code that implements
11067 it. If an R2L tool bar is ever supported, display_tool_bar_line
11068 should also be augmented to call unproduce_glyphs like
11069 display_line and display_string do. */
11070 it
.paragraph_embedding
= L2R
;
11072 if (f
->n_tool_bar_rows
== 0)
11076 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11077 nlines
!= WINDOW_TOTAL_LINES (w
)))
11080 int old_height
= WINDOW_TOTAL_LINES (w
);
11082 XSETFRAME (frame
, f
);
11083 Fmodify_frame_parameters (frame
,
11084 Fcons (Fcons (Qtool_bar_lines
,
11085 make_number (nlines
)),
11087 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11089 clear_glyph_matrix (w
->desired_matrix
);
11090 fonts_changed_p
= 1;
11096 /* Display as many lines as needed to display all tool-bar items. */
11098 if (f
->n_tool_bar_rows
> 0)
11100 int border
, rows
, height
, extra
;
11102 if (INTEGERP (Vtool_bar_border
))
11103 border
= XINT (Vtool_bar_border
);
11104 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11105 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11106 else if (EQ (Vtool_bar_border
, Qborder_width
))
11107 border
= f
->border_width
;
11113 rows
= f
->n_tool_bar_rows
;
11114 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11115 extra
= it
.last_visible_y
- border
- height
* rows
;
11117 while (it
.current_y
< it
.last_visible_y
)
11120 if (extra
> 0 && rows
-- > 0)
11122 h
= (extra
+ rows
- 1) / rows
;
11125 display_tool_bar_line (&it
, height
+ h
);
11130 while (it
.current_y
< it
.last_visible_y
)
11131 display_tool_bar_line (&it
, 0);
11134 /* It doesn't make much sense to try scrolling in the tool-bar
11135 window, so don't do it. */
11136 w
->desired_matrix
->no_scrolling_p
= 1;
11137 w
->must_be_updated_p
= 1;
11139 if (!NILP (Vauto_resize_tool_bars
))
11141 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11142 int change_height_p
= 0;
11144 /* If we couldn't display everything, change the tool-bar's
11145 height if there is room for more. */
11146 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11147 && it
.current_y
< max_tool_bar_height
)
11148 change_height_p
= 1;
11150 row
= it
.glyph_row
- 1;
11152 /* If there are blank lines at the end, except for a partially
11153 visible blank line at the end that is smaller than
11154 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11155 if (!row
->displays_text_p
11156 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11157 change_height_p
= 1;
11159 /* If row displays tool-bar items, but is partially visible,
11160 change the tool-bar's height. */
11161 if (row
->displays_text_p
11162 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11163 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11164 change_height_p
= 1;
11166 /* Resize windows as needed by changing the `tool-bar-lines'
11167 frame parameter. */
11168 if (change_height_p
)
11171 int old_height
= WINDOW_TOTAL_LINES (w
);
11173 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11175 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11176 && !f
->minimize_tool_bar_window_p
)
11177 ? (nlines
> old_height
)
11178 : (nlines
!= old_height
));
11179 f
->minimize_tool_bar_window_p
= 0;
11181 if (change_height_p
)
11183 XSETFRAME (frame
, f
);
11184 Fmodify_frame_parameters (frame
,
11185 Fcons (Fcons (Qtool_bar_lines
,
11186 make_number (nlines
)),
11188 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11190 clear_glyph_matrix (w
->desired_matrix
);
11191 f
->n_tool_bar_rows
= nrows
;
11192 fonts_changed_p
= 1;
11199 f
->minimize_tool_bar_window_p
= 0;
11204 /* Get information about the tool-bar item which is displayed in GLYPH
11205 on frame F. Return in *PROP_IDX the index where tool-bar item
11206 properties start in F->tool_bar_items. Value is zero if
11207 GLYPH doesn't display a tool-bar item. */
11210 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
11216 /* This function can be called asynchronously, which means we must
11217 exclude any possibility that Fget_text_property signals an
11219 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
11220 charpos
= max (0, charpos
);
11222 /* Get the text property `menu-item' at pos. The value of that
11223 property is the start index of this item's properties in
11224 F->tool_bar_items. */
11225 prop
= Fget_text_property (make_number (charpos
),
11226 Qmenu_item
, f
->current_tool_bar_string
);
11227 if (INTEGERP (prop
))
11229 *prop_idx
= XINT (prop
);
11239 /* Get information about the tool-bar item at position X/Y on frame F.
11240 Return in *GLYPH a pointer to the glyph of the tool-bar item in
11241 the current matrix of the tool-bar window of F, or NULL if not
11242 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
11243 item in F->tool_bar_items. Value is
11245 -1 if X/Y is not on a tool-bar item
11246 0 if X/Y is on the same item that was highlighted before.
11250 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
11251 int *hpos
, int *vpos
, int *prop_idx
)
11253 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11254 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11257 /* Find the glyph under X/Y. */
11258 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
11259 if (*glyph
== NULL
)
11262 /* Get the start of this tool-bar item's properties in
11263 f->tool_bar_items. */
11264 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
11267 /* Is mouse on the highlighted item? */
11268 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
11269 && *vpos
>= hlinfo
->mouse_face_beg_row
11270 && *vpos
<= hlinfo
->mouse_face_end_row
11271 && (*vpos
> hlinfo
->mouse_face_beg_row
11272 || *hpos
>= hlinfo
->mouse_face_beg_col
)
11273 && (*vpos
< hlinfo
->mouse_face_end_row
11274 || *hpos
< hlinfo
->mouse_face_end_col
11275 || hlinfo
->mouse_face_past_end
))
11283 Handle mouse button event on the tool-bar of frame F, at
11284 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
11285 0 for button release. MODIFIERS is event modifiers for button
11289 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
11290 unsigned int modifiers
)
11292 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11293 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11294 int hpos
, vpos
, prop_idx
;
11295 struct glyph
*glyph
;
11296 Lisp_Object enabled_p
;
11298 /* If not on the highlighted tool-bar item, return. */
11299 frame_to_window_pixel_xy (w
, &x
, &y
);
11300 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
11303 /* If item is disabled, do nothing. */
11304 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11305 if (NILP (enabled_p
))
11310 /* Show item in pressed state. */
11311 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
11312 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
11313 last_tool_bar_item
= prop_idx
;
11317 Lisp_Object key
, frame
;
11318 struct input_event event
;
11319 EVENT_INIT (event
);
11321 /* Show item in released state. */
11322 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
11323 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
11325 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
11327 XSETFRAME (frame
, f
);
11328 event
.kind
= TOOL_BAR_EVENT
;
11329 event
.frame_or_window
= frame
;
11331 kbd_buffer_store_event (&event
);
11333 event
.kind
= TOOL_BAR_EVENT
;
11334 event
.frame_or_window
= frame
;
11336 event
.modifiers
= modifiers
;
11337 kbd_buffer_store_event (&event
);
11338 last_tool_bar_item
= -1;
11343 /* Possibly highlight a tool-bar item on frame F when mouse moves to
11344 tool-bar window-relative coordinates X/Y. Called from
11345 note_mouse_highlight. */
11348 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
11350 Lisp_Object window
= f
->tool_bar_window
;
11351 struct window
*w
= XWINDOW (window
);
11352 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11353 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11355 struct glyph
*glyph
;
11356 struct glyph_row
*row
;
11358 Lisp_Object enabled_p
;
11360 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
11361 int mouse_down_p
, rc
;
11363 /* Function note_mouse_highlight is called with negative X/Y
11364 values when mouse moves outside of the frame. */
11365 if (x
<= 0 || y
<= 0)
11367 clear_mouse_face (hlinfo
);
11371 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
11374 /* Not on tool-bar item. */
11375 clear_mouse_face (hlinfo
);
11379 /* On same tool-bar item as before. */
11380 goto set_help_echo
;
11382 clear_mouse_face (hlinfo
);
11384 /* Mouse is down, but on different tool-bar item? */
11385 mouse_down_p
= (dpyinfo
->grabbed
11386 && f
== last_mouse_frame
11387 && FRAME_LIVE_P (f
));
11389 && last_tool_bar_item
!= prop_idx
)
11392 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
11393 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
11395 /* If tool-bar item is not enabled, don't highlight it. */
11396 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11397 if (!NILP (enabled_p
))
11399 /* Compute the x-position of the glyph. In front and past the
11400 image is a space. We include this in the highlighted area. */
11401 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
11402 for (i
= x
= 0; i
< hpos
; ++i
)
11403 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11405 /* Record this as the current active region. */
11406 hlinfo
->mouse_face_beg_col
= hpos
;
11407 hlinfo
->mouse_face_beg_row
= vpos
;
11408 hlinfo
->mouse_face_beg_x
= x
;
11409 hlinfo
->mouse_face_beg_y
= row
->y
;
11410 hlinfo
->mouse_face_past_end
= 0;
11412 hlinfo
->mouse_face_end_col
= hpos
+ 1;
11413 hlinfo
->mouse_face_end_row
= vpos
;
11414 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
11415 hlinfo
->mouse_face_end_y
= row
->y
;
11416 hlinfo
->mouse_face_window
= window
;
11417 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
11419 /* Display it as active. */
11420 show_mouse_face (hlinfo
, draw
);
11421 hlinfo
->mouse_face_image_state
= draw
;
11426 /* Set help_echo_string to a help string to display for this tool-bar item.
11427 XTread_socket does the rest. */
11428 help_echo_object
= help_echo_window
= Qnil
;
11429 help_echo_pos
= -1;
11430 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
11431 if (NILP (help_echo_string
))
11432 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
11435 #endif /* HAVE_WINDOW_SYSTEM */
11439 /************************************************************************
11440 Horizontal scrolling
11441 ************************************************************************/
11443 static int hscroll_window_tree (Lisp_Object
);
11444 static int hscroll_windows (Lisp_Object
);
11446 /* For all leaf windows in the window tree rooted at WINDOW, set their
11447 hscroll value so that PT is (i) visible in the window, and (ii) so
11448 that it is not within a certain margin at the window's left and
11449 right border. Value is non-zero if any window's hscroll has been
11453 hscroll_window_tree (Lisp_Object window
)
11455 int hscrolled_p
= 0;
11456 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
11457 int hscroll_step_abs
= 0;
11458 double hscroll_step_rel
= 0;
11460 if (hscroll_relative_p
)
11462 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
11463 if (hscroll_step_rel
< 0)
11465 hscroll_relative_p
= 0;
11466 hscroll_step_abs
= 0;
11469 else if (INTEGERP (Vhscroll_step
))
11471 hscroll_step_abs
= XINT (Vhscroll_step
);
11472 if (hscroll_step_abs
< 0)
11473 hscroll_step_abs
= 0;
11476 hscroll_step_abs
= 0;
11478 while (WINDOWP (window
))
11480 struct window
*w
= XWINDOW (window
);
11482 if (WINDOWP (w
->hchild
))
11483 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11484 else if (WINDOWP (w
->vchild
))
11485 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11486 else if (w
->cursor
.vpos
>= 0)
11489 int text_area_width
;
11490 struct glyph_row
*current_cursor_row
11491 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11492 struct glyph_row
*desired_cursor_row
11493 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11494 struct glyph_row
*cursor_row
11495 = (desired_cursor_row
->enabled_p
11496 ? desired_cursor_row
11497 : current_cursor_row
);
11499 text_area_width
= window_box_width (w
, TEXT_AREA
);
11501 /* Scroll when cursor is inside this scroll margin. */
11502 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11504 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11505 && ((XFASTINT (w
->hscroll
)
11506 && w
->cursor
.x
<= h_margin
)
11507 || (cursor_row
->enabled_p
11508 && cursor_row
->truncated_on_right_p
11509 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11513 struct buffer
*saved_current_buffer
;
11517 /* Find point in a display of infinite width. */
11518 saved_current_buffer
= current_buffer
;
11519 current_buffer
= XBUFFER (w
->buffer
);
11521 if (w
== XWINDOW (selected_window
))
11525 pt
= marker_position (w
->pointm
);
11526 pt
= max (BEGV
, pt
);
11530 /* Move iterator to pt starting at cursor_row->start in
11531 a line with infinite width. */
11532 init_to_row_start (&it
, w
, cursor_row
);
11533 it
.last_visible_x
= INFINITY
;
11534 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11535 current_buffer
= saved_current_buffer
;
11537 /* Position cursor in window. */
11538 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11539 hscroll
= max (0, (it
.current_x
11540 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11541 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11542 : (text_area_width
/ 2))))
11543 / FRAME_COLUMN_WIDTH (it
.f
);
11544 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11546 if (hscroll_relative_p
)
11547 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11550 wanted_x
= text_area_width
11551 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11554 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11558 if (hscroll_relative_p
)
11559 wanted_x
= text_area_width
* hscroll_step_rel
11562 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11565 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11567 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11569 /* Don't call Fset_window_hscroll if value hasn't
11570 changed because it will prevent redisplay
11572 if (XFASTINT (w
->hscroll
) != hscroll
)
11574 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11575 w
->hscroll
= make_number (hscroll
);
11584 /* Value is non-zero if hscroll of any leaf window has been changed. */
11585 return hscrolled_p
;
11589 /* Set hscroll so that cursor is visible and not inside horizontal
11590 scroll margins for all windows in the tree rooted at WINDOW. See
11591 also hscroll_window_tree above. Value is non-zero if any window's
11592 hscroll has been changed. If it has, desired matrices on the frame
11593 of WINDOW are cleared. */
11596 hscroll_windows (Lisp_Object window
)
11598 int hscrolled_p
= hscroll_window_tree (window
);
11600 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11601 return hscrolled_p
;
11606 /************************************************************************
11608 ************************************************************************/
11610 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11611 to a non-zero value. This is sometimes handy to have in a debugger
11616 /* First and last unchanged row for try_window_id. */
11618 int debug_first_unchanged_at_end_vpos
;
11619 int debug_last_unchanged_at_beg_vpos
;
11621 /* Delta vpos and y. */
11623 int debug_dvpos
, debug_dy
;
11625 /* Delta in characters and bytes for try_window_id. */
11627 EMACS_INT debug_delta
, debug_delta_bytes
;
11629 /* Values of window_end_pos and window_end_vpos at the end of
11632 EMACS_INT debug_end_vpos
;
11634 /* Append a string to W->desired_matrix->method. FMT is a printf
11635 format string. A1...A9 are a supplement for a variable-length
11636 argument list. If trace_redisplay_p is non-zero also printf the
11637 resulting string to stderr. */
11640 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11643 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11646 char *method
= w
->desired_matrix
->method
;
11647 int len
= strlen (method
);
11648 int size
= sizeof w
->desired_matrix
->method
;
11649 int remaining
= size
- len
- 1;
11651 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11652 if (len
&& remaining
)
11655 --remaining
, ++len
;
11658 strncpy (method
+ len
, buffer
, remaining
);
11660 if (trace_redisplay_p
)
11661 fprintf (stderr
, "%p (%s): %s\n",
11663 ((BUFFERP (w
->buffer
)
11664 && STRINGP (XBUFFER (w
->buffer
)->name
))
11665 ? SSDATA (XBUFFER (w
->buffer
)->name
)
11670 #endif /* GLYPH_DEBUG */
11673 /* Value is non-zero if all changes in window W, which displays
11674 current_buffer, are in the text between START and END. START is a
11675 buffer position, END is given as a distance from Z. Used in
11676 redisplay_internal for display optimization. */
11679 text_outside_line_unchanged_p (struct window
*w
,
11680 EMACS_INT start
, EMACS_INT end
)
11682 int unchanged_p
= 1;
11684 /* If text or overlays have changed, see where. */
11685 if (XFASTINT (w
->last_modified
) < MODIFF
11686 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11688 /* Gap in the line? */
11689 if (GPT
< start
|| Z
- GPT
< end
)
11692 /* Changes start in front of the line, or end after it? */
11694 && (BEG_UNCHANGED
< start
- 1
11695 || END_UNCHANGED
< end
))
11698 /* If selective display, can't optimize if changes start at the
11699 beginning of the line. */
11701 && INTEGERP (BVAR (current_buffer
, selective_display
))
11702 && XINT (BVAR (current_buffer
, selective_display
)) > 0
11703 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11706 /* If there are overlays at the start or end of the line, these
11707 may have overlay strings with newlines in them. A change at
11708 START, for instance, may actually concern the display of such
11709 overlay strings as well, and they are displayed on different
11710 lines. So, quickly rule out this case. (For the future, it
11711 might be desirable to implement something more telling than
11712 just BEG/END_UNCHANGED.) */
11715 if (BEG
+ BEG_UNCHANGED
== start
11716 && overlay_touches_p (start
))
11718 if (END_UNCHANGED
== end
11719 && overlay_touches_p (Z
- end
))
11723 /* Under bidi reordering, adding or deleting a character in the
11724 beginning of a paragraph, before the first strong directional
11725 character, can change the base direction of the paragraph (unless
11726 the buffer specifies a fixed paragraph direction), which will
11727 require to redisplay the whole paragraph. It might be worthwhile
11728 to find the paragraph limits and widen the range of redisplayed
11729 lines to that, but for now just give up this optimization. */
11730 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
11731 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
11735 return unchanged_p
;
11739 /* Do a frame update, taking possible shortcuts into account. This is
11740 the main external entry point for redisplay.
11742 If the last redisplay displayed an echo area message and that message
11743 is no longer requested, we clear the echo area or bring back the
11744 mini-buffer if that is in use. */
11749 redisplay_internal ();
11754 overlay_arrow_string_or_property (Lisp_Object var
)
11758 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11761 return Voverlay_arrow_string
;
11764 /* Return 1 if there are any overlay-arrows in current_buffer. */
11766 overlay_arrow_in_current_buffer_p (void)
11770 for (vlist
= Voverlay_arrow_variable_list
;
11772 vlist
= XCDR (vlist
))
11774 Lisp_Object var
= XCAR (vlist
);
11777 if (!SYMBOLP (var
))
11779 val
= find_symbol_value (var
);
11781 && current_buffer
== XMARKER (val
)->buffer
)
11788 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11792 overlay_arrows_changed_p (void)
11796 for (vlist
= Voverlay_arrow_variable_list
;
11798 vlist
= XCDR (vlist
))
11800 Lisp_Object var
= XCAR (vlist
);
11801 Lisp_Object val
, pstr
;
11803 if (!SYMBOLP (var
))
11805 val
= find_symbol_value (var
);
11806 if (!MARKERP (val
))
11808 if (! EQ (COERCE_MARKER (val
),
11809 Fget (var
, Qlast_arrow_position
))
11810 || ! (pstr
= overlay_arrow_string_or_property (var
),
11811 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11817 /* Mark overlay arrows to be updated on next redisplay. */
11820 update_overlay_arrows (int up_to_date
)
11824 for (vlist
= Voverlay_arrow_variable_list
;
11826 vlist
= XCDR (vlist
))
11828 Lisp_Object var
= XCAR (vlist
);
11830 if (!SYMBOLP (var
))
11833 if (up_to_date
> 0)
11835 Lisp_Object val
= find_symbol_value (var
);
11836 Fput (var
, Qlast_arrow_position
,
11837 COERCE_MARKER (val
));
11838 Fput (var
, Qlast_arrow_string
,
11839 overlay_arrow_string_or_property (var
));
11841 else if (up_to_date
< 0
11842 || !NILP (Fget (var
, Qlast_arrow_position
)))
11844 Fput (var
, Qlast_arrow_position
, Qt
);
11845 Fput (var
, Qlast_arrow_string
, Qt
);
11851 /* Return overlay arrow string to display at row.
11852 Return integer (bitmap number) for arrow bitmap in left fringe.
11853 Return nil if no overlay arrow. */
11856 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
11860 for (vlist
= Voverlay_arrow_variable_list
;
11862 vlist
= XCDR (vlist
))
11864 Lisp_Object var
= XCAR (vlist
);
11867 if (!SYMBOLP (var
))
11870 val
= find_symbol_value (var
);
11873 && current_buffer
== XMARKER (val
)->buffer
11874 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11876 if (FRAME_WINDOW_P (it
->f
)
11877 /* FIXME: if ROW->reversed_p is set, this should test
11878 the right fringe, not the left one. */
11879 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11881 #ifdef HAVE_WINDOW_SYSTEM
11882 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11885 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11886 return make_number (fringe_bitmap
);
11889 return make_number (-1); /* Use default arrow bitmap */
11891 return overlay_arrow_string_or_property (var
);
11898 /* Return 1 if point moved out of or into a composition. Otherwise
11899 return 0. PREV_BUF and PREV_PT are the last point buffer and
11900 position. BUF and PT are the current point buffer and position. */
11903 check_point_in_composition (struct buffer
*prev_buf
, EMACS_INT prev_pt
,
11904 struct buffer
*buf
, EMACS_INT pt
)
11906 EMACS_INT start
, end
;
11908 Lisp_Object buffer
;
11910 XSETBUFFER (buffer
, buf
);
11911 /* Check a composition at the last point if point moved within the
11913 if (prev_buf
== buf
)
11916 /* Point didn't move. */
11919 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11920 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11921 && COMPOSITION_VALID_P (start
, end
, prop
)
11922 && start
< prev_pt
&& end
> prev_pt
)
11923 /* The last point was within the composition. Return 1 iff
11924 point moved out of the composition. */
11925 return (pt
<= start
|| pt
>= end
);
11928 /* Check a composition at the current point. */
11929 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11930 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11931 && COMPOSITION_VALID_P (start
, end
, prop
)
11932 && start
< pt
&& end
> pt
);
11936 /* Reconsider the setting of B->clip_changed which is displayed
11940 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
11942 if (b
->clip_changed
11943 && !NILP (w
->window_end_valid
)
11944 && w
->current_matrix
->buffer
== b
11945 && w
->current_matrix
->zv
== BUF_ZV (b
)
11946 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11947 b
->clip_changed
= 0;
11949 /* If display wasn't paused, and W is not a tool bar window, see if
11950 point has been moved into or out of a composition. In that case,
11951 we set b->clip_changed to 1 to force updating the screen. If
11952 b->clip_changed has already been set to 1, we can skip this
11954 if (!b
->clip_changed
11955 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11959 if (w
== XWINDOW (selected_window
))
11962 pt
= marker_position (w
->pointm
);
11964 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11965 || pt
!= XINT (w
->last_point
))
11966 && check_point_in_composition (w
->current_matrix
->buffer
,
11967 XINT (w
->last_point
),
11968 XBUFFER (w
->buffer
), pt
))
11969 b
->clip_changed
= 1;
11974 /* Select FRAME to forward the values of frame-local variables into C
11975 variables so that the redisplay routines can access those values
11979 select_frame_for_redisplay (Lisp_Object frame
)
11981 Lisp_Object tail
, tem
;
11982 Lisp_Object old
= selected_frame
;
11983 struct Lisp_Symbol
*sym
;
11985 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11987 selected_frame
= frame
;
11990 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11991 if (CONSP (XCAR (tail
))
11992 && (tem
= XCAR (XCAR (tail
)),
11994 && (sym
= indirect_variable (XSYMBOL (tem
)),
11995 sym
->redirect
== SYMBOL_LOCALIZED
)
11996 && sym
->val
.blv
->frame_local
)
11997 /* Use find_symbol_value rather than Fsymbol_value
11998 to avoid an error if it is void. */
11999 find_symbol_value (tem
);
12000 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12004 #define STOP_POLLING \
12005 do { if (! polling_stopped_here) stop_polling (); \
12006 polling_stopped_here = 1; } while (0)
12008 #define RESUME_POLLING \
12009 do { if (polling_stopped_here) start_polling (); \
12010 polling_stopped_here = 0; } while (0)
12013 /* Perhaps in the future avoid recentering windows if it
12014 is not necessary; currently that causes some problems. */
12017 redisplay_internal (void)
12019 struct window
*w
= XWINDOW (selected_window
);
12023 int must_finish
= 0;
12024 struct text_pos tlbufpos
, tlendpos
;
12025 int number_of_visible_frames
;
12028 int polling_stopped_here
= 0;
12029 Lisp_Object old_frame
= selected_frame
;
12031 /* Non-zero means redisplay has to consider all windows on all
12032 frames. Zero means, only selected_window is considered. */
12033 int consider_all_windows_p
;
12035 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12037 /* No redisplay if running in batch mode or frame is not yet fully
12038 initialized, or redisplay is explicitly turned off by setting
12039 Vinhibit_redisplay. */
12040 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12041 || !NILP (Vinhibit_redisplay
))
12044 /* Don't examine these until after testing Vinhibit_redisplay.
12045 When Emacs is shutting down, perhaps because its connection to
12046 X has dropped, we should not look at them at all. */
12047 fr
= XFRAME (w
->frame
);
12048 sf
= SELECTED_FRAME ();
12050 if (!fr
->glyphs_initialized_p
)
12053 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12054 if (popup_activated ())
12058 /* I don't think this happens but let's be paranoid. */
12059 if (redisplaying_p
)
12062 /* Record a function that resets redisplaying_p to its old value
12063 when we leave this function. */
12064 count
= SPECPDL_INDEX ();
12065 record_unwind_protect (unwind_redisplay
,
12066 Fcons (make_number (redisplaying_p
), selected_frame
));
12068 specbind (Qinhibit_free_realized_faces
, Qnil
);
12071 Lisp_Object tail
, frame
;
12073 FOR_EACH_FRAME (tail
, frame
)
12075 struct frame
*f
= XFRAME (frame
);
12076 f
->already_hscrolled_p
= 0;
12081 /* Remember the currently selected window. */
12084 if (!EQ (old_frame
, selected_frame
)
12085 && FRAME_LIVE_P (XFRAME (old_frame
)))
12086 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12087 selected_frame and selected_window to be temporarily out-of-sync so
12088 when we come back here via `goto retry', we need to resync because we
12089 may need to run Elisp code (via prepare_menu_bars). */
12090 select_frame_for_redisplay (old_frame
);
12093 reconsider_clip_changes (w
, current_buffer
);
12094 last_escape_glyph_frame
= NULL
;
12095 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12096 last_glyphless_glyph_frame
= NULL
;
12097 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12099 /* If new fonts have been loaded that make a glyph matrix adjustment
12100 necessary, do it. */
12101 if (fonts_changed_p
)
12103 adjust_glyphs (NULL
);
12104 ++windows_or_buffers_changed
;
12105 fonts_changed_p
= 0;
12108 /* If face_change_count is non-zero, init_iterator will free all
12109 realized faces, which includes the faces referenced from current
12110 matrices. So, we can't reuse current matrices in this case. */
12111 if (face_change_count
)
12112 ++windows_or_buffers_changed
;
12114 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12115 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12117 /* Since frames on a single ASCII terminal share the same
12118 display area, displaying a different frame means redisplay
12119 the whole thing. */
12120 windows_or_buffers_changed
++;
12121 SET_FRAME_GARBAGED (sf
);
12123 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12125 FRAME_TTY (sf
)->previous_frame
= sf
;
12128 /* Set the visible flags for all frames. Do this before checking
12129 for resized or garbaged frames; they want to know if their frames
12130 are visible. See the comment in frame.h for
12131 FRAME_SAMPLE_VISIBILITY. */
12133 Lisp_Object tail
, frame
;
12135 number_of_visible_frames
= 0;
12137 FOR_EACH_FRAME (tail
, frame
)
12139 struct frame
*f
= XFRAME (frame
);
12141 FRAME_SAMPLE_VISIBILITY (f
);
12142 if (FRAME_VISIBLE_P (f
))
12143 ++number_of_visible_frames
;
12144 clear_desired_matrices (f
);
12148 /* Notice any pending interrupt request to change frame size. */
12149 do_pending_window_change (1);
12151 /* do_pending_window_change could change the selected_window due to
12152 frame resizing which makes the selected window too small. */
12153 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12156 reconsider_clip_changes (w
, current_buffer
);
12159 /* Clear frames marked as garbaged. */
12160 if (frame_garbaged
)
12161 clear_garbaged_frames ();
12163 /* Build menubar and tool-bar items. */
12164 if (NILP (Vmemory_full
))
12165 prepare_menu_bars ();
12167 if (windows_or_buffers_changed
)
12168 update_mode_lines
++;
12170 /* Detect case that we need to write or remove a star in the mode line. */
12171 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
12173 w
->update_mode_line
= Qt
;
12174 if (buffer_shared
> 1)
12175 update_mode_lines
++;
12178 /* Avoid invocation of point motion hooks by `current_column' below. */
12179 count1
= SPECPDL_INDEX ();
12180 specbind (Qinhibit_point_motion_hooks
, Qt
);
12182 /* If %c is in the mode line, update it if needed. */
12183 if (!NILP (w
->column_number_displayed
)
12184 /* This alternative quickly identifies a common case
12185 where no change is needed. */
12186 && !(PT
== XFASTINT (w
->last_point
)
12187 && XFASTINT (w
->last_modified
) >= MODIFF
12188 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12189 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
12190 w
->update_mode_line
= Qt
;
12192 unbind_to (count1
, Qnil
);
12194 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
12196 /* The variable buffer_shared is set in redisplay_window and
12197 indicates that we redisplay a buffer in different windows. See
12199 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
12200 || cursor_type_changed
);
12202 /* If specs for an arrow have changed, do thorough redisplay
12203 to ensure we remove any arrow that should no longer exist. */
12204 if (overlay_arrows_changed_p ())
12205 consider_all_windows_p
= windows_or_buffers_changed
= 1;
12207 /* Normally the message* functions will have already displayed and
12208 updated the echo area, but the frame may have been trashed, or
12209 the update may have been preempted, so display the echo area
12210 again here. Checking message_cleared_p captures the case that
12211 the echo area should be cleared. */
12212 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
12213 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
12214 || (message_cleared_p
12215 && minibuf_level
== 0
12216 /* If the mini-window is currently selected, this means the
12217 echo-area doesn't show through. */
12218 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
12220 int window_height_changed_p
= echo_area_display (0);
12223 /* If we don't display the current message, don't clear the
12224 message_cleared_p flag, because, if we did, we wouldn't clear
12225 the echo area in the next redisplay which doesn't preserve
12227 if (!display_last_displayed_message_p
)
12228 message_cleared_p
= 0;
12230 if (fonts_changed_p
)
12232 else if (window_height_changed_p
)
12234 consider_all_windows_p
= 1;
12235 ++update_mode_lines
;
12236 ++windows_or_buffers_changed
;
12238 /* If window configuration was changed, frames may have been
12239 marked garbaged. Clear them or we will experience
12240 surprises wrt scrolling. */
12241 if (frame_garbaged
)
12242 clear_garbaged_frames ();
12245 else if (EQ (selected_window
, minibuf_window
)
12246 && (current_buffer
->clip_changed
12247 || XFASTINT (w
->last_modified
) < MODIFF
12248 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12249 && resize_mini_window (w
, 0))
12251 /* Resized active mini-window to fit the size of what it is
12252 showing if its contents might have changed. */
12254 /* FIXME: this causes all frames to be updated, which seems unnecessary
12255 since only the current frame needs to be considered. This function needs
12256 to be rewritten with two variables, consider_all_windows and
12257 consider_all_frames. */
12258 consider_all_windows_p
= 1;
12259 ++windows_or_buffers_changed
;
12260 ++update_mode_lines
;
12262 /* If window configuration was changed, frames may have been
12263 marked garbaged. Clear them or we will experience
12264 surprises wrt scrolling. */
12265 if (frame_garbaged
)
12266 clear_garbaged_frames ();
12270 /* If showing the region, and mark has changed, we must redisplay
12271 the whole window. The assignment to this_line_start_pos prevents
12272 the optimization directly below this if-statement. */
12273 if (((!NILP (Vtransient_mark_mode
)
12274 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
12275 != !NILP (w
->region_showing
))
12276 || (!NILP (w
->region_showing
)
12277 && !EQ (w
->region_showing
,
12278 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
12279 CHARPOS (this_line_start_pos
) = 0;
12281 /* Optimize the case that only the line containing the cursor in the
12282 selected window has changed. Variables starting with this_ are
12283 set in display_line and record information about the line
12284 containing the cursor. */
12285 tlbufpos
= this_line_start_pos
;
12286 tlendpos
= this_line_end_pos
;
12287 if (!consider_all_windows_p
12288 && CHARPOS (tlbufpos
) > 0
12289 && NILP (w
->update_mode_line
)
12290 && !current_buffer
->clip_changed
12291 && !current_buffer
->prevent_redisplay_optimizations_p
12292 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
12293 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
12294 /* Make sure recorded data applies to current buffer, etc. */
12295 && this_line_buffer
== current_buffer
12296 && current_buffer
== XBUFFER (w
->buffer
)
12297 && NILP (w
->force_start
)
12298 && NILP (w
->optional_new_start
)
12299 /* Point must be on the line that we have info recorded about. */
12300 && PT
>= CHARPOS (tlbufpos
)
12301 && PT
<= Z
- CHARPOS (tlendpos
)
12302 /* All text outside that line, including its final newline,
12303 must be unchanged. */
12304 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
12305 CHARPOS (tlendpos
)))
12307 if (CHARPOS (tlbufpos
) > BEGV
12308 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
12309 && (CHARPOS (tlbufpos
) == ZV
12310 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
12311 /* Former continuation line has disappeared by becoming empty. */
12313 else if (XFASTINT (w
->last_modified
) < MODIFF
12314 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
12315 || MINI_WINDOW_P (w
))
12317 /* We have to handle the case of continuation around a
12318 wide-column character (see the comment in indent.c around
12321 For instance, in the following case:
12323 -------- Insert --------
12324 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
12325 J_I_ ==> J_I_ `^^' are cursors.
12329 As we have to redraw the line above, we cannot use this
12333 int line_height_before
= this_line_pixel_height
;
12335 /* Note that start_display will handle the case that the
12336 line starting at tlbufpos is a continuation line. */
12337 start_display (&it
, w
, tlbufpos
);
12339 /* Implementation note: It this still necessary? */
12340 if (it
.current_x
!= this_line_start_x
)
12343 TRACE ((stderr
, "trying display optimization 1\n"));
12344 w
->cursor
.vpos
= -1;
12345 overlay_arrow_seen
= 0;
12346 it
.vpos
= this_line_vpos
;
12347 it
.current_y
= this_line_y
;
12348 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
12349 display_line (&it
);
12351 /* If line contains point, is not continued,
12352 and ends at same distance from eob as before, we win. */
12353 if (w
->cursor
.vpos
>= 0
12354 /* Line is not continued, otherwise this_line_start_pos
12355 would have been set to 0 in display_line. */
12356 && CHARPOS (this_line_start_pos
)
12357 /* Line ends as before. */
12358 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
12359 /* Line has same height as before. Otherwise other lines
12360 would have to be shifted up or down. */
12361 && this_line_pixel_height
== line_height_before
)
12363 /* If this is not the window's last line, we must adjust
12364 the charstarts of the lines below. */
12365 if (it
.current_y
< it
.last_visible_y
)
12367 struct glyph_row
*row
12368 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
12369 EMACS_INT delta
, delta_bytes
;
12371 /* We used to distinguish between two cases here,
12372 conditioned by Z - CHARPOS (tlendpos) == ZV, for
12373 when the line ends in a newline or the end of the
12374 buffer's accessible portion. But both cases did
12375 the same, so they were collapsed. */
12377 - CHARPOS (tlendpos
)
12378 - MATRIX_ROW_START_CHARPOS (row
));
12379 delta_bytes
= (Z_BYTE
12380 - BYTEPOS (tlendpos
)
12381 - MATRIX_ROW_START_BYTEPOS (row
));
12383 increment_matrix_positions (w
->current_matrix
,
12384 this_line_vpos
+ 1,
12385 w
->current_matrix
->nrows
,
12386 delta
, delta_bytes
);
12389 /* If this row displays text now but previously didn't,
12390 or vice versa, w->window_end_vpos may have to be
12392 if ((it
.glyph_row
- 1)->displays_text_p
)
12394 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
12395 XSETINT (w
->window_end_vpos
, this_line_vpos
);
12397 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
12398 && this_line_vpos
> 0)
12399 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
12400 w
->window_end_valid
= Qnil
;
12402 /* Update hint: No need to try to scroll in update_window. */
12403 w
->desired_matrix
->no_scrolling_p
= 1;
12406 *w
->desired_matrix
->method
= 0;
12407 debug_method_add (w
, "optimization 1");
12409 #ifdef HAVE_WINDOW_SYSTEM
12410 update_window_fringes (w
, 0);
12417 else if (/* Cursor position hasn't changed. */
12418 PT
== XFASTINT (w
->last_point
)
12419 /* Make sure the cursor was last displayed
12420 in this window. Otherwise we have to reposition it. */
12421 && 0 <= w
->cursor
.vpos
12422 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
12426 do_pending_window_change (1);
12427 /* If selected_window changed, redisplay again. */
12428 if (WINDOWP (selected_window
)
12429 && (w
= XWINDOW (selected_window
)) != sw
)
12432 /* We used to always goto end_of_redisplay here, but this
12433 isn't enough if we have a blinking cursor. */
12434 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
12435 goto end_of_redisplay
;
12439 /* If highlighting the region, or if the cursor is in the echo area,
12440 then we can't just move the cursor. */
12441 else if (! (!NILP (Vtransient_mark_mode
)
12442 && !NILP (BVAR (current_buffer
, mark_active
)))
12443 && (EQ (selected_window
, BVAR (current_buffer
, last_selected_window
))
12444 || highlight_nonselected_windows
)
12445 && NILP (w
->region_showing
)
12446 && NILP (Vshow_trailing_whitespace
)
12447 && !cursor_in_echo_area
)
12450 struct glyph_row
*row
;
12452 /* Skip from tlbufpos to PT and see where it is. Note that
12453 PT may be in invisible text. If so, we will end at the
12454 next visible position. */
12455 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
12456 NULL
, DEFAULT_FACE_ID
);
12457 it
.current_x
= this_line_start_x
;
12458 it
.current_y
= this_line_y
;
12459 it
.vpos
= this_line_vpos
;
12461 /* The call to move_it_to stops in front of PT, but
12462 moves over before-strings. */
12463 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
12465 if (it
.vpos
== this_line_vpos
12466 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12469 xassert (this_line_vpos
== it
.vpos
);
12470 xassert (this_line_y
== it
.current_y
);
12471 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12473 *w
->desired_matrix
->method
= 0;
12474 debug_method_add (w
, "optimization 3");
12483 /* Text changed drastically or point moved off of line. */
12484 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12487 CHARPOS (this_line_start_pos
) = 0;
12488 consider_all_windows_p
|= buffer_shared
> 1;
12489 ++clear_face_cache_count
;
12490 #ifdef HAVE_WINDOW_SYSTEM
12491 ++clear_image_cache_count
;
12494 /* Build desired matrices, and update the display. If
12495 consider_all_windows_p is non-zero, do it for all windows on all
12496 frames. Otherwise do it for selected_window, only. */
12498 if (consider_all_windows_p
)
12500 Lisp_Object tail
, frame
;
12502 FOR_EACH_FRAME (tail
, frame
)
12503 XFRAME (frame
)->updated_p
= 0;
12505 /* Recompute # windows showing selected buffer. This will be
12506 incremented each time such a window is displayed. */
12509 FOR_EACH_FRAME (tail
, frame
)
12511 struct frame
*f
= XFRAME (frame
);
12513 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12515 if (! EQ (frame
, selected_frame
))
12516 /* Select the frame, for the sake of frame-local
12518 select_frame_for_redisplay (frame
);
12520 /* Mark all the scroll bars to be removed; we'll redeem
12521 the ones we want when we redisplay their windows. */
12522 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12523 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12525 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12526 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12528 /* The X error handler may have deleted that frame. */
12529 if (!FRAME_LIVE_P (f
))
12532 /* Any scroll bars which redisplay_windows should have
12533 nuked should now go away. */
12534 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12535 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12537 /* If fonts changed, display again. */
12538 /* ??? rms: I suspect it is a mistake to jump all the way
12539 back to retry here. It should just retry this frame. */
12540 if (fonts_changed_p
)
12543 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12545 /* See if we have to hscroll. */
12546 if (!f
->already_hscrolled_p
)
12548 f
->already_hscrolled_p
= 1;
12549 if (hscroll_windows (f
->root_window
))
12553 /* Prevent various kinds of signals during display
12554 update. stdio is not robust about handling
12555 signals, which can cause an apparent I/O
12557 if (interrupt_input
)
12558 unrequest_sigio ();
12561 /* Update the display. */
12562 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12563 pending
|= update_frame (f
, 0, 0);
12569 if (!EQ (old_frame
, selected_frame
)
12570 && FRAME_LIVE_P (XFRAME (old_frame
)))
12571 /* We played a bit fast-and-loose above and allowed selected_frame
12572 and selected_window to be temporarily out-of-sync but let's make
12573 sure this stays contained. */
12574 select_frame_for_redisplay (old_frame
);
12575 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12579 /* Do the mark_window_display_accurate after all windows have
12580 been redisplayed because this call resets flags in buffers
12581 which are needed for proper redisplay. */
12582 FOR_EACH_FRAME (tail
, frame
)
12584 struct frame
*f
= XFRAME (frame
);
12587 mark_window_display_accurate (f
->root_window
, 1);
12588 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12589 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12594 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12596 Lisp_Object mini_window
;
12597 struct frame
*mini_frame
;
12599 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12600 /* Use list_of_error, not Qerror, so that
12601 we catch only errors and don't run the debugger. */
12602 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12604 redisplay_window_error
);
12606 /* Compare desired and current matrices, perform output. */
12609 /* If fonts changed, display again. */
12610 if (fonts_changed_p
)
12613 /* Prevent various kinds of signals during display update.
12614 stdio is not robust about handling signals,
12615 which can cause an apparent I/O error. */
12616 if (interrupt_input
)
12617 unrequest_sigio ();
12620 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12622 if (hscroll_windows (selected_window
))
12625 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12626 pending
= update_frame (sf
, 0, 0);
12629 /* We may have called echo_area_display at the top of this
12630 function. If the echo area is on another frame, that may
12631 have put text on a frame other than the selected one, so the
12632 above call to update_frame would not have caught it. Catch
12634 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12635 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12637 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12639 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12640 pending
|= update_frame (mini_frame
, 0, 0);
12641 if (!pending
&& hscroll_windows (mini_window
))
12646 /* If display was paused because of pending input, make sure we do a
12647 thorough update the next time. */
12650 /* Prevent the optimization at the beginning of
12651 redisplay_internal that tries a single-line update of the
12652 line containing the cursor in the selected window. */
12653 CHARPOS (this_line_start_pos
) = 0;
12655 /* Let the overlay arrow be updated the next time. */
12656 update_overlay_arrows (0);
12658 /* If we pause after scrolling, some rows in the current
12659 matrices of some windows are not valid. */
12660 if (!WINDOW_FULL_WIDTH_P (w
)
12661 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12662 update_mode_lines
= 1;
12666 if (!consider_all_windows_p
)
12668 /* This has already been done above if
12669 consider_all_windows_p is set. */
12670 mark_window_display_accurate_1 (w
, 1);
12672 /* Say overlay arrows are up to date. */
12673 update_overlay_arrows (1);
12675 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12676 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12679 update_mode_lines
= 0;
12680 windows_or_buffers_changed
= 0;
12681 cursor_type_changed
= 0;
12684 /* Start SIGIO interrupts coming again. Having them off during the
12685 code above makes it less likely one will discard output, but not
12686 impossible, since there might be stuff in the system buffer here.
12687 But it is much hairier to try to do anything about that. */
12688 if (interrupt_input
)
12692 /* If a frame has become visible which was not before, redisplay
12693 again, so that we display it. Expose events for such a frame
12694 (which it gets when becoming visible) don't call the parts of
12695 redisplay constructing glyphs, so simply exposing a frame won't
12696 display anything in this case. So, we have to display these
12697 frames here explicitly. */
12700 Lisp_Object tail
, frame
;
12703 FOR_EACH_FRAME (tail
, frame
)
12705 int this_is_visible
= 0;
12707 if (XFRAME (frame
)->visible
)
12708 this_is_visible
= 1;
12709 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12710 if (XFRAME (frame
)->visible
)
12711 this_is_visible
= 1;
12713 if (this_is_visible
)
12717 if (new_count
!= number_of_visible_frames
)
12718 windows_or_buffers_changed
++;
12721 /* Change frame size now if a change is pending. */
12722 do_pending_window_change (1);
12724 /* If we just did a pending size change, or have additional
12725 visible frames, or selected_window changed, redisplay again. */
12726 if ((windows_or_buffers_changed
&& !pending
)
12727 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
12730 /* Clear the face and image caches.
12732 We used to do this only if consider_all_windows_p. But the cache
12733 needs to be cleared if a timer creates images in the current
12734 buffer (e.g. the test case in Bug#6230). */
12736 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12738 clear_face_cache (0);
12739 clear_face_cache_count
= 0;
12742 #ifdef HAVE_WINDOW_SYSTEM
12743 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12745 clear_image_caches (Qnil
);
12746 clear_image_cache_count
= 0;
12748 #endif /* HAVE_WINDOW_SYSTEM */
12751 unbind_to (count
, Qnil
);
12756 /* Redisplay, but leave alone any recent echo area message unless
12757 another message has been requested in its place.
12759 This is useful in situations where you need to redisplay but no
12760 user action has occurred, making it inappropriate for the message
12761 area to be cleared. See tracking_off and
12762 wait_reading_process_output for examples of these situations.
12764 FROM_WHERE is an integer saying from where this function was
12765 called. This is useful for debugging. */
12768 redisplay_preserve_echo_area (int from_where
)
12770 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12772 if (!NILP (echo_area_buffer
[1]))
12774 /* We have a previously displayed message, but no current
12775 message. Redisplay the previous message. */
12776 display_last_displayed_message_p
= 1;
12777 redisplay_internal ();
12778 display_last_displayed_message_p
= 0;
12781 redisplay_internal ();
12783 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12784 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12785 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12789 /* Function registered with record_unwind_protect in
12790 redisplay_internal. Reset redisplaying_p to the value it had
12791 before redisplay_internal was called, and clear
12792 prevent_freeing_realized_faces_p. It also selects the previously
12793 selected frame, unless it has been deleted (by an X connection
12794 failure during redisplay, for example). */
12797 unwind_redisplay (Lisp_Object val
)
12799 Lisp_Object old_redisplaying_p
, old_frame
;
12801 old_redisplaying_p
= XCAR (val
);
12802 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12803 old_frame
= XCDR (val
);
12804 if (! EQ (old_frame
, selected_frame
)
12805 && FRAME_LIVE_P (XFRAME (old_frame
)))
12806 select_frame_for_redisplay (old_frame
);
12811 /* Mark the display of window W as accurate or inaccurate. If
12812 ACCURATE_P is non-zero mark display of W as accurate. If
12813 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12814 redisplay_internal is called. */
12817 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
12819 if (BUFFERP (w
->buffer
))
12821 struct buffer
*b
= XBUFFER (w
->buffer
);
12824 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12825 w
->last_overlay_modified
12826 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12828 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12832 b
->clip_changed
= 0;
12833 b
->prevent_redisplay_optimizations_p
= 0;
12835 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12836 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12837 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12838 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12840 w
->current_matrix
->buffer
= b
;
12841 w
->current_matrix
->begv
= BUF_BEGV (b
);
12842 w
->current_matrix
->zv
= BUF_ZV (b
);
12844 w
->last_cursor
= w
->cursor
;
12845 w
->last_cursor_off_p
= w
->cursor_off_p
;
12847 if (w
== XWINDOW (selected_window
))
12848 w
->last_point
= make_number (BUF_PT (b
));
12850 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12856 w
->window_end_valid
= w
->buffer
;
12857 w
->update_mode_line
= Qnil
;
12862 /* Mark the display of windows in the window tree rooted at WINDOW as
12863 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12864 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12865 be redisplayed the next time redisplay_internal is called. */
12868 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
12872 for (; !NILP (window
); window
= w
->next
)
12874 w
= XWINDOW (window
);
12875 mark_window_display_accurate_1 (w
, accurate_p
);
12877 if (!NILP (w
->vchild
))
12878 mark_window_display_accurate (w
->vchild
, accurate_p
);
12879 if (!NILP (w
->hchild
))
12880 mark_window_display_accurate (w
->hchild
, accurate_p
);
12885 update_overlay_arrows (1);
12889 /* Force a thorough redisplay the next time by setting
12890 last_arrow_position and last_arrow_string to t, which is
12891 unequal to any useful value of Voverlay_arrow_... */
12892 update_overlay_arrows (-1);
12897 /* Return value in display table DP (Lisp_Char_Table *) for character
12898 C. Since a display table doesn't have any parent, we don't have to
12899 follow parent. Do not call this function directly but use the
12900 macro DISP_CHAR_VECTOR. */
12903 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
12907 if (ASCII_CHAR_P (c
))
12910 if (SUB_CHAR_TABLE_P (val
))
12911 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12917 XSETCHAR_TABLE (table
, dp
);
12918 val
= char_table_ref (table
, c
);
12927 /***********************************************************************
12929 ***********************************************************************/
12931 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12934 redisplay_windows (Lisp_Object window
)
12936 while (!NILP (window
))
12938 struct window
*w
= XWINDOW (window
);
12940 if (!NILP (w
->hchild
))
12941 redisplay_windows (w
->hchild
);
12942 else if (!NILP (w
->vchild
))
12943 redisplay_windows (w
->vchild
);
12944 else if (!NILP (w
->buffer
))
12946 displayed_buffer
= XBUFFER (w
->buffer
);
12947 /* Use list_of_error, not Qerror, so that
12948 we catch only errors and don't run the debugger. */
12949 internal_condition_case_1 (redisplay_window_0
, window
,
12951 redisplay_window_error
);
12959 redisplay_window_error (Lisp_Object ignore
)
12961 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12966 redisplay_window_0 (Lisp_Object window
)
12968 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12969 redisplay_window (window
, 0);
12974 redisplay_window_1 (Lisp_Object window
)
12976 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12977 redisplay_window (window
, 1);
12982 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12983 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12984 which positions recorded in ROW differ from current buffer
12987 Return 0 if cursor is not on this row, 1 otherwise. */
12990 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
12991 struct glyph_matrix
*matrix
,
12992 EMACS_INT delta
, EMACS_INT delta_bytes
,
12995 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12996 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12997 struct glyph
*cursor
= NULL
;
12998 /* The last known character position in row. */
12999 EMACS_INT last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13001 EMACS_INT pt_old
= PT
- delta
;
13002 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13003 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13004 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13005 /* A glyph beyond the edge of TEXT_AREA which we should never
13007 struct glyph
*glyphs_end
= end
;
13008 /* Non-zero means we've found a match for cursor position, but that
13009 glyph has the avoid_cursor_p flag set. */
13010 int match_with_avoid_cursor
= 0;
13011 /* Non-zero means we've seen at least one glyph that came from a
13013 int string_seen
= 0;
13014 /* Largest and smalles buffer positions seen so far during scan of
13016 EMACS_INT bpos_max
= pos_before
;
13017 EMACS_INT bpos_min
= pos_after
;
13018 /* Last buffer position covered by an overlay string with an integer
13019 `cursor' property. */
13020 EMACS_INT bpos_covered
= 0;
13022 /* Skip over glyphs not having an object at the start and the end of
13023 the row. These are special glyphs like truncation marks on
13024 terminal frames. */
13025 if (row
->displays_text_p
)
13027 if (!row
->reversed_p
)
13030 && INTEGERP (glyph
->object
)
13031 && glyph
->charpos
< 0)
13033 x
+= glyph
->pixel_width
;
13037 && INTEGERP ((end
- 1)->object
)
13038 /* CHARPOS is zero for blanks and stretch glyphs
13039 inserted by extend_face_to_end_of_line. */
13040 && (end
- 1)->charpos
<= 0)
13042 glyph_before
= glyph
- 1;
13049 /* If the glyph row is reversed, we need to process it from back
13050 to front, so swap the edge pointers. */
13051 glyphs_end
= end
= glyph
- 1;
13052 glyph
+= row
->used
[TEXT_AREA
] - 1;
13054 while (glyph
> end
+ 1
13055 && INTEGERP (glyph
->object
)
13056 && glyph
->charpos
< 0)
13059 x
-= glyph
->pixel_width
;
13061 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13063 /* By default, in reversed rows we put the cursor on the
13064 rightmost (first in the reading order) glyph. */
13065 for (g
= end
+ 1; g
< glyph
; g
++)
13066 x
+= g
->pixel_width
;
13068 && INTEGERP ((end
+ 1)->object
)
13069 && (end
+ 1)->charpos
<= 0)
13071 glyph_before
= glyph
+ 1;
13075 else if (row
->reversed_p
)
13077 /* In R2L rows that don't display text, put the cursor on the
13078 rightmost glyph. Case in point: an empty last line that is
13079 part of an R2L paragraph. */
13081 /* Avoid placing the cursor on the last glyph of the row, where
13082 on terminal frames we hold the vertical border between
13083 adjacent windows. */
13084 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13085 && !WINDOW_RIGHTMOST_P (w
)
13086 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13088 x
= -1; /* will be computed below, at label compute_x */
13091 /* Step 1: Try to find the glyph whose character position
13092 corresponds to point. If that's not possible, find 2 glyphs
13093 whose character positions are the closest to point, one before
13094 point, the other after it. */
13095 if (!row
->reversed_p
)
13096 while (/* not marched to end of glyph row */
13098 /* glyph was not inserted by redisplay for internal purposes */
13099 && !INTEGERP (glyph
->object
))
13101 if (BUFFERP (glyph
->object
))
13103 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
13105 if (glyph
->charpos
> bpos_max
)
13106 bpos_max
= glyph
->charpos
;
13107 if (glyph
->charpos
< bpos_min
)
13108 bpos_min
= glyph
->charpos
;
13109 if (!glyph
->avoid_cursor_p
)
13111 /* If we hit point, we've found the glyph on which to
13112 display the cursor. */
13115 match_with_avoid_cursor
= 0;
13118 /* See if we've found a better approximation to
13119 POS_BEFORE or to POS_AFTER. Note that we want the
13120 first (leftmost) glyph of all those that are the
13121 closest from below, and the last (rightmost) of all
13122 those from above. */
13123 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13125 pos_before
= glyph
->charpos
;
13126 glyph_before
= glyph
;
13128 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13130 pos_after
= glyph
->charpos
;
13131 glyph_after
= glyph
;
13134 else if (dpos
== 0)
13135 match_with_avoid_cursor
= 1;
13137 else if (STRINGP (glyph
->object
))
13139 Lisp_Object chprop
;
13140 EMACS_INT glyph_pos
= glyph
->charpos
;
13142 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13144 if (INTEGERP (chprop
))
13146 bpos_covered
= bpos_max
+ XINT (chprop
);
13147 /* If the `cursor' property covers buffer positions up
13148 to and including point, we should display cursor on
13149 this glyph. Note that overlays and text properties
13150 with string values stop bidi reordering, so every
13151 buffer position to the left of the string is always
13152 smaller than any position to the right of the
13153 string. Therefore, if a `cursor' property on one
13154 of the string's characters has an integer value, we
13155 will break out of the loop below _before_ we get to
13156 the position match above. IOW, integer values of
13157 the `cursor' property override the "exact match for
13158 point" strategy of positioning the cursor. */
13159 /* Implementation note: bpos_max == pt_old when, e.g.,
13160 we are in an empty line, where bpos_max is set to
13161 MATRIX_ROW_START_CHARPOS, see above. */
13162 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13171 x
+= glyph
->pixel_width
;
13174 else if (glyph
> end
) /* row is reversed */
13175 while (!INTEGERP (glyph
->object
))
13177 if (BUFFERP (glyph
->object
))
13179 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
13181 if (glyph
->charpos
> bpos_max
)
13182 bpos_max
= glyph
->charpos
;
13183 if (glyph
->charpos
< bpos_min
)
13184 bpos_min
= glyph
->charpos
;
13185 if (!glyph
->avoid_cursor_p
)
13189 match_with_avoid_cursor
= 0;
13192 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13194 pos_before
= glyph
->charpos
;
13195 glyph_before
= glyph
;
13197 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13199 pos_after
= glyph
->charpos
;
13200 glyph_after
= glyph
;
13203 else if (dpos
== 0)
13204 match_with_avoid_cursor
= 1;
13206 else if (STRINGP (glyph
->object
))
13208 Lisp_Object chprop
;
13209 EMACS_INT glyph_pos
= glyph
->charpos
;
13211 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13213 if (INTEGERP (chprop
))
13215 bpos_covered
= bpos_max
+ XINT (chprop
);
13216 /* If the `cursor' property covers buffer positions up
13217 to and including point, we should display cursor on
13219 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13228 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
13230 x
--; /* can't use any pixel_width */
13233 x
-= glyph
->pixel_width
;
13236 /* Step 2: If we didn't find an exact match for point, we need to
13237 look for a proper place to put the cursor among glyphs between
13238 GLYPH_BEFORE and GLYPH_AFTER. */
13239 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13240 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13241 && bpos_covered
< pt_old
)
13243 /* An empty line has a single glyph whose OBJECT is zero and
13244 whose CHARPOS is the position of a newline on that line.
13245 Note that on a TTY, there are more glyphs after that, which
13246 were produced by extend_face_to_end_of_line, but their
13247 CHARPOS is zero or negative. */
13249 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13250 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
13252 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
13254 EMACS_INT ellipsis_pos
;
13256 /* Scan back over the ellipsis glyphs. */
13257 if (!row
->reversed_p
)
13259 ellipsis_pos
= (glyph
- 1)->charpos
;
13260 while (glyph
> row
->glyphs
[TEXT_AREA
]
13261 && (glyph
- 1)->charpos
== ellipsis_pos
)
13262 glyph
--, x
-= glyph
->pixel_width
;
13263 /* That loop always goes one position too far, including
13264 the glyph before the ellipsis. So scan forward over
13266 x
+= glyph
->pixel_width
;
13269 else /* row is reversed */
13271 ellipsis_pos
= (glyph
+ 1)->charpos
;
13272 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
13273 && (glyph
+ 1)->charpos
== ellipsis_pos
)
13274 glyph
++, x
+= glyph
->pixel_width
;
13275 x
-= glyph
->pixel_width
;
13279 else if (match_with_avoid_cursor
13280 /* A truncated row may not include PT among its
13281 character positions. Setting the cursor inside the
13282 scroll margin will trigger recalculation of hscroll
13283 in hscroll_window_tree. */
13284 || (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
13285 || (row
->truncated_on_right_p
&& pt_old
> bpos_max
)
13286 /* Zero-width characters produce no glyphs. */
13289 && (row
->reversed_p
13290 ? glyph_after
> glyphs_end
13291 : glyph_after
< glyphs_end
)))
13293 cursor
= glyph_after
;
13296 else if (string_seen
)
13298 int incr
= row
->reversed_p
? -1 : +1;
13300 /* Need to find the glyph that came out of a string which is
13301 present at point. That glyph is somewhere between
13302 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
13303 positioned between POS_BEFORE and POS_AFTER in the
13305 struct glyph
*start
, *stop
;
13306 EMACS_INT pos
= pos_before
;
13310 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
13311 correspond to POS_BEFORE and POS_AFTER, respectively. We
13312 need START and STOP in the order that corresponds to the
13313 row's direction as given by its reversed_p flag. If the
13314 directionality of characters between POS_BEFORE and
13315 POS_AFTER is the opposite of the row's base direction,
13316 these characters will have been reordered for display,
13317 and we need to reverse START and STOP. */
13318 if (!row
->reversed_p
)
13320 start
= min (glyph_before
, glyph_after
);
13321 stop
= max (glyph_before
, glyph_after
);
13325 start
= max (glyph_before
, glyph_after
);
13326 stop
= min (glyph_before
, glyph_after
);
13328 for (glyph
= start
+ incr
;
13329 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
13332 /* Any glyphs that come from the buffer are here because
13333 of bidi reordering. Skip them, and only pay
13334 attention to glyphs that came from some string. */
13335 if (STRINGP (glyph
->object
))
13340 str
= glyph
->object
;
13341 tem
= string_buffer_position_lim (str
, pos
, pos_after
, 0);
13342 if (tem
== 0 /* from overlay */
13345 /* If the string from which this glyph came is
13346 found in the buffer at point, then we've
13347 found the glyph we've been looking for. If
13348 it comes from an overlay (tem == 0), and it
13349 has the `cursor' property on one of its
13350 glyphs, record that glyph as a candidate for
13351 displaying the cursor. (As in the
13352 unidirectional version, we will display the
13353 cursor on the last candidate we find.) */
13354 if (tem
== 0 || tem
== pt_old
)
13356 /* The glyphs from this string could have
13357 been reordered. Find the one with the
13358 smallest string position. Or there could
13359 be a character in the string with the
13360 `cursor' property, which means display
13361 cursor on that character's glyph. */
13362 EMACS_INT strpos
= glyph
->charpos
;
13367 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
13368 && EQ (glyph
->object
, str
);
13372 EMACS_INT gpos
= glyph
->charpos
;
13374 cprop
= Fget_char_property (make_number (gpos
),
13382 if (tem
&& glyph
->charpos
< strpos
)
13384 strpos
= glyph
->charpos
;
13393 pos
= tem
+ 1; /* don't find previous instances */
13395 /* This string is not what we want; skip all of the
13396 glyphs that came from it. */
13397 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
13398 && EQ (glyph
->object
, str
))
13405 /* If we reached the end of the line, and END was from a string,
13406 the cursor is not on this line. */
13408 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
13409 && STRINGP (end
->object
)
13410 && row
->continued_p
)
13416 if (cursor
!= NULL
)
13422 /* Need to compute x that corresponds to GLYPH. */
13423 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
13425 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
13427 x
+= g
->pixel_width
;
13431 /* ROW could be part of a continued line, which, under bidi
13432 reordering, might have other rows whose start and end charpos
13433 occlude point. Only set w->cursor if we found a better
13434 approximation to the cursor position than we have from previously
13435 examined candidate rows belonging to the same continued line. */
13436 if (/* we already have a candidate row */
13437 w
->cursor
.vpos
>= 0
13438 /* that candidate is not the row we are processing */
13439 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
13440 /* the row we are processing is part of a continued line */
13441 && (row
->continued_p
|| MATRIX_ROW_CONTINUATION_LINE_P (row
))
13442 /* Make sure cursor.vpos specifies a row whose start and end
13443 charpos occlude point. This is because some callers of this
13444 function leave cursor.vpos at the row where the cursor was
13445 displayed during the last redisplay cycle. */
13446 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
13447 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
13450 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
13452 /* Don't consider glyphs that are outside TEXT_AREA. */
13453 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
13455 /* Keep the candidate whose buffer position is the closest to
13457 if (/* previous candidate is a glyph in TEXT_AREA of that row */
13458 w
->cursor
.hpos
>= 0
13459 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
13460 && BUFFERP (g1
->object
)
13461 && (g1
->charpos
== pt_old
/* an exact match always wins */
13462 || (BUFFERP (glyph
->object
)
13463 && eabs (g1
->charpos
- pt_old
)
13464 < eabs (glyph
->charpos
- pt_old
))))
13466 /* If this candidate gives an exact match, use that. */
13467 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13468 /* Otherwise, keep the candidate that comes from a row
13469 spanning less buffer positions. This may win when one or
13470 both candidate positions are on glyphs that came from
13471 display strings, for which we cannot compare buffer
13473 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13474 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13475 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
13478 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
13480 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
13481 w
->cursor
.y
= row
->y
+ dy
;
13483 if (w
== XWINDOW (selected_window
))
13485 if (!row
->continued_p
13486 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
13489 this_line_buffer
= XBUFFER (w
->buffer
);
13491 CHARPOS (this_line_start_pos
)
13492 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
13493 BYTEPOS (this_line_start_pos
)
13494 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
13496 CHARPOS (this_line_end_pos
)
13497 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
13498 BYTEPOS (this_line_end_pos
)
13499 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
13501 this_line_y
= w
->cursor
.y
;
13502 this_line_pixel_height
= row
->height
;
13503 this_line_vpos
= w
->cursor
.vpos
;
13504 this_line_start_x
= row
->x
;
13507 CHARPOS (this_line_start_pos
) = 0;
13514 /* Run window scroll functions, if any, for WINDOW with new window
13515 start STARTP. Sets the window start of WINDOW to that position.
13517 We assume that the window's buffer is really current. */
13519 static INLINE
struct text_pos
13520 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
13522 struct window
*w
= XWINDOW (window
);
13523 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13525 if (current_buffer
!= XBUFFER (w
->buffer
))
13528 if (!NILP (Vwindow_scroll_functions
))
13530 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13531 make_number (CHARPOS (startp
)));
13532 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13533 /* In case the hook functions switch buffers. */
13534 if (current_buffer
!= XBUFFER (w
->buffer
))
13535 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13542 /* Make sure the line containing the cursor is fully visible.
13543 A value of 1 means there is nothing to be done.
13544 (Either the line is fully visible, or it cannot be made so,
13545 or we cannot tell.)
13547 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13548 is higher than window.
13550 A value of 0 means the caller should do scrolling
13551 as if point had gone off the screen. */
13554 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
13556 struct glyph_matrix
*matrix
;
13557 struct glyph_row
*row
;
13560 if (!make_cursor_line_fully_visible_p
)
13563 /* It's not always possible to find the cursor, e.g, when a window
13564 is full of overlay strings. Don't do anything in that case. */
13565 if (w
->cursor
.vpos
< 0)
13568 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13569 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13571 /* If the cursor row is not partially visible, there's nothing to do. */
13572 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13575 /* If the row the cursor is in is taller than the window's height,
13576 it's not clear what to do, so do nothing. */
13577 window_height
= window_box_height (w
);
13578 if (row
->height
>= window_height
)
13580 if (!force_p
|| MINI_WINDOW_P (w
)
13581 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13588 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13589 non-zero means only WINDOW is redisplayed in redisplay_internal.
13590 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
13591 in redisplay_window to bring a partially visible line into view in
13592 the case that only the cursor has moved.
13594 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13595 last screen line's vertical height extends past the end of the screen.
13599 1 if scrolling succeeded
13601 0 if scrolling didn't find point.
13603 -1 if new fonts have been loaded so that we must interrupt
13604 redisplay, adjust glyph matrices, and try again. */
13610 SCROLLING_NEED_LARGER_MATRICES
13613 /* If scroll-conservatively is more than this, never recenter.
13615 If you change this, don't forget to update the doc string of
13616 `scroll-conservatively' and the Emacs manual. */
13617 #define SCROLL_LIMIT 100
13620 try_scrolling (Lisp_Object window
, int just_this_one_p
,
13621 EMACS_INT arg_scroll_conservatively
, EMACS_INT scroll_step
,
13622 int temp_scroll_step
, int last_line_misfit
)
13624 struct window
*w
= XWINDOW (window
);
13625 struct frame
*f
= XFRAME (w
->frame
);
13626 struct text_pos pos
, startp
;
13628 int this_scroll_margin
, scroll_max
, rc
, height
;
13629 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13630 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13631 Lisp_Object aggressive
;
13632 /* We will never try scrolling more than this number of lines. */
13633 int scroll_limit
= SCROLL_LIMIT
;
13636 debug_method_add (w
, "try_scrolling");
13639 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13641 /* Compute scroll margin height in pixels. We scroll when point is
13642 within this distance from the top or bottom of the window. */
13643 if (scroll_margin
> 0)
13644 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13645 * FRAME_LINE_HEIGHT (f
);
13647 this_scroll_margin
= 0;
13649 /* Force arg_scroll_conservatively to have a reasonable value, to
13650 avoid scrolling too far away with slow move_it_* functions. Note
13651 that the user can supply scroll-conservatively equal to
13652 `most-positive-fixnum', which can be larger than INT_MAX. */
13653 if (arg_scroll_conservatively
> scroll_limit
)
13655 arg_scroll_conservatively
= scroll_limit
+ 1;
13656 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
13658 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
13659 /* Compute how much we should try to scroll maximally to bring
13660 point into view. */
13661 scroll_max
= (max (scroll_step
,
13662 max (arg_scroll_conservatively
, temp_scroll_step
))
13663 * FRAME_LINE_HEIGHT (f
));
13664 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
13665 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
13666 /* We're trying to scroll because of aggressive scrolling but no
13667 scroll_step is set. Choose an arbitrary one. */
13668 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13674 /* Decide whether to scroll down. */
13675 if (PT
> CHARPOS (startp
))
13677 int scroll_margin_y
;
13679 /* Compute the pixel ypos of the scroll margin, then move it to
13680 either that ypos or PT, whichever comes first. */
13681 start_display (&it
, w
, startp
);
13682 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13683 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13684 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13685 (MOVE_TO_POS
| MOVE_TO_Y
));
13687 if (PT
> CHARPOS (it
.current
.pos
))
13689 int y0
= line_bottom_y (&it
);
13690 /* Compute how many pixels below window bottom to stop searching
13691 for PT. This avoids costly search for PT that is far away if
13692 the user limited scrolling by a small number of lines, but
13693 always finds PT if scroll_conservatively is set to a large
13694 number, such as most-positive-fixnum. */
13695 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
13696 int y_to_move
= it
.last_visible_y
+ slack
;
13698 /* Compute the distance from the scroll margin to PT or to
13699 the scroll limit, whichever comes first. This should
13700 include the height of the cursor line, to make that line
13702 move_it_to (&it
, PT
, -1, y_to_move
,
13703 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13704 dy
= line_bottom_y (&it
) - y0
;
13706 if (dy
> scroll_max
)
13707 return SCROLLING_FAILED
;
13715 /* Point is in or below the bottom scroll margin, so move the
13716 window start down. If scrolling conservatively, move it just
13717 enough down to make point visible. If scroll_step is set,
13718 move it down by scroll_step. */
13719 if (arg_scroll_conservatively
)
13721 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13722 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
13723 else if (scroll_step
|| temp_scroll_step
)
13724 amount_to_scroll
= scroll_max
;
13727 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
13728 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13729 if (NUMBERP (aggressive
))
13731 double float_amount
= XFLOATINT (aggressive
) * height
;
13732 amount_to_scroll
= float_amount
;
13733 if (amount_to_scroll
== 0 && float_amount
> 0)
13734 amount_to_scroll
= 1;
13735 /* Don't let point enter the scroll margin near top of
13737 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13738 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13742 if (amount_to_scroll
<= 0)
13743 return SCROLLING_FAILED
;
13745 start_display (&it
, w
, startp
);
13746 if (arg_scroll_conservatively
<= scroll_limit
)
13747 move_it_vertically (&it
, amount_to_scroll
);
13750 /* Extra precision for users who set scroll-conservatively
13751 to a large number: make sure the amount we scroll
13752 the window start is never less than amount_to_scroll,
13753 which was computed as distance from window bottom to
13754 point. This matters when lines at window top and lines
13755 below window bottom have different height. */
13756 struct it it1
= it
;
13757 /* We use a temporary it1 because line_bottom_y can modify
13758 its argument, if it moves one line down; see there. */
13759 int start_y
= line_bottom_y (&it1
);
13762 move_it_by_lines (&it
, 1);
13764 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
13767 /* If STARTP is unchanged, move it down another screen line. */
13768 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13769 move_it_by_lines (&it
, 1);
13770 startp
= it
.current
.pos
;
13774 struct text_pos scroll_margin_pos
= startp
;
13776 /* See if point is inside the scroll margin at the top of the
13778 if (this_scroll_margin
)
13780 start_display (&it
, w
, startp
);
13781 move_it_vertically (&it
, this_scroll_margin
);
13782 scroll_margin_pos
= it
.current
.pos
;
13785 if (PT
< CHARPOS (scroll_margin_pos
))
13787 /* Point is in the scroll margin at the top of the window or
13788 above what is displayed in the window. */
13791 /* Compute the vertical distance from PT to the scroll
13792 margin position. Move as far as scroll_max allows, or
13793 one screenful, or 10 screen lines, whichever is largest.
13794 Give up if distance is greater than scroll_max. */
13795 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13796 start_display (&it
, w
, pos
);
13798 y_to_move
= max (it
.last_visible_y
,
13799 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
13800 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13802 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13803 dy
= it
.current_y
- y0
;
13804 if (dy
> scroll_max
)
13805 return SCROLLING_FAILED
;
13807 /* Compute new window start. */
13808 start_display (&it
, w
, startp
);
13810 if (arg_scroll_conservatively
)
13811 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
13812 max (scroll_step
, temp_scroll_step
));
13813 else if (scroll_step
|| temp_scroll_step
)
13814 amount_to_scroll
= scroll_max
;
13817 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
13818 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13819 if (NUMBERP (aggressive
))
13821 double float_amount
= XFLOATINT (aggressive
) * height
;
13822 amount_to_scroll
= float_amount
;
13823 if (amount_to_scroll
== 0 && float_amount
> 0)
13824 amount_to_scroll
= 1;
13825 amount_to_scroll
-=
13826 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
13827 /* Don't let point enter the scroll margin near
13828 bottom of the window. */
13829 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13830 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13834 if (amount_to_scroll
<= 0)
13835 return SCROLLING_FAILED
;
13837 move_it_vertically_backward (&it
, amount_to_scroll
);
13838 startp
= it
.current
.pos
;
13842 /* Run window scroll functions. */
13843 startp
= run_window_scroll_functions (window
, startp
);
13845 /* Display the window. Give up if new fonts are loaded, or if point
13847 if (!try_window (window
, startp
, 0))
13848 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13849 else if (w
->cursor
.vpos
< 0)
13851 clear_glyph_matrix (w
->desired_matrix
);
13852 rc
= SCROLLING_FAILED
;
13856 /* Maybe forget recorded base line for line number display. */
13857 if (!just_this_one_p
13858 || current_buffer
->clip_changed
13859 || BEG_UNCHANGED
< CHARPOS (startp
))
13860 w
->base_line_number
= Qnil
;
13862 /* If cursor ends up on a partially visible line,
13863 treat that as being off the bottom of the screen. */
13864 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
13865 /* It's possible that the cursor is on the first line of the
13866 buffer, which is partially obscured due to a vscroll
13867 (Bug#7537). In that case, avoid looping forever . */
13868 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
13870 clear_glyph_matrix (w
->desired_matrix
);
13871 ++extra_scroll_margin_lines
;
13874 rc
= SCROLLING_SUCCESS
;
13881 /* Compute a suitable window start for window W if display of W starts
13882 on a continuation line. Value is non-zero if a new window start
13885 The new window start will be computed, based on W's width, starting
13886 from the start of the continued line. It is the start of the
13887 screen line with the minimum distance from the old start W->start. */
13890 compute_window_start_on_continuation_line (struct window
*w
)
13892 struct text_pos pos
, start_pos
;
13893 int window_start_changed_p
= 0;
13895 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13897 /* If window start is on a continuation line... Window start may be
13898 < BEGV in case there's invisible text at the start of the
13899 buffer (M-x rmail, for example). */
13900 if (CHARPOS (start_pos
) > BEGV
13901 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13904 struct glyph_row
*row
;
13906 /* Handle the case that the window start is out of range. */
13907 if (CHARPOS (start_pos
) < BEGV
)
13908 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13909 else if (CHARPOS (start_pos
) > ZV
)
13910 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13912 /* Find the start of the continued line. This should be fast
13913 because scan_buffer is fast (newline cache). */
13914 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13915 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13916 row
, DEFAULT_FACE_ID
);
13917 reseat_at_previous_visible_line_start (&it
);
13919 /* If the line start is "too far" away from the window start,
13920 say it takes too much time to compute a new window start. */
13921 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13922 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13924 int min_distance
, distance
;
13926 /* Move forward by display lines to find the new window
13927 start. If window width was enlarged, the new start can
13928 be expected to be > the old start. If window width was
13929 decreased, the new window start will be < the old start.
13930 So, we're looking for the display line start with the
13931 minimum distance from the old window start. */
13932 pos
= it
.current
.pos
;
13933 min_distance
= INFINITY
;
13934 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13935 distance
< min_distance
)
13937 min_distance
= distance
;
13938 pos
= it
.current
.pos
;
13939 move_it_by_lines (&it
, 1);
13942 /* Set the window start there. */
13943 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13944 window_start_changed_p
= 1;
13948 return window_start_changed_p
;
13952 /* Try cursor movement in case text has not changed in window WINDOW,
13953 with window start STARTP. Value is
13955 CURSOR_MOVEMENT_SUCCESS if successful
13957 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13959 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13960 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13961 we want to scroll as if scroll-step were set to 1. See the code.
13963 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13964 which case we have to abort this redisplay, and adjust matrices
13969 CURSOR_MOVEMENT_SUCCESS
,
13970 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13971 CURSOR_MOVEMENT_MUST_SCROLL
,
13972 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13976 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
13978 struct window
*w
= XWINDOW (window
);
13979 struct frame
*f
= XFRAME (w
->frame
);
13980 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13983 if (inhibit_try_cursor_movement
)
13987 /* Handle case where text has not changed, only point, and it has
13988 not moved off the frame. */
13989 if (/* Point may be in this window. */
13990 PT
>= CHARPOS (startp
)
13991 /* Selective display hasn't changed. */
13992 && !current_buffer
->clip_changed
13993 /* Function force-mode-line-update is used to force a thorough
13994 redisplay. It sets either windows_or_buffers_changed or
13995 update_mode_lines. So don't take a shortcut here for these
13997 && !update_mode_lines
13998 && !windows_or_buffers_changed
13999 && !cursor_type_changed
14000 /* Can't use this case if highlighting a region. When a
14001 region exists, cursor movement has to do more than just
14003 && !(!NILP (Vtransient_mark_mode
)
14004 && !NILP (BVAR (current_buffer
, mark_active
)))
14005 && NILP (w
->region_showing
)
14006 && NILP (Vshow_trailing_whitespace
)
14007 /* Right after splitting windows, last_point may be nil. */
14008 && INTEGERP (w
->last_point
)
14009 /* This code is not used for mini-buffer for the sake of the case
14010 of redisplaying to replace an echo area message; since in
14011 that case the mini-buffer contents per se are usually
14012 unchanged. This code is of no real use in the mini-buffer
14013 since the handling of this_line_start_pos, etc., in redisplay
14014 handles the same cases. */
14015 && !EQ (window
, minibuf_window
)
14016 /* When splitting windows or for new windows, it happens that
14017 redisplay is called with a nil window_end_vpos or one being
14018 larger than the window. This should really be fixed in
14019 window.c. I don't have this on my list, now, so we do
14020 approximately the same as the old redisplay code. --gerd. */
14021 && INTEGERP (w
->window_end_vpos
)
14022 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14023 && (FRAME_WINDOW_P (f
)
14024 || !overlay_arrow_in_current_buffer_p ()))
14026 int this_scroll_margin
, top_scroll_margin
;
14027 struct glyph_row
*row
= NULL
;
14030 debug_method_add (w
, "cursor movement");
14033 /* Scroll if point within this distance from the top or bottom
14034 of the window. This is a pixel value. */
14035 if (scroll_margin
> 0)
14037 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14038 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14041 this_scroll_margin
= 0;
14043 top_scroll_margin
= this_scroll_margin
;
14044 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14045 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14047 /* Start with the row the cursor was displayed during the last
14048 not paused redisplay. Give up if that row is not valid. */
14049 if (w
->last_cursor
.vpos
< 0
14050 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
14051 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14054 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
14055 if (row
->mode_line_p
)
14057 if (!row
->enabled_p
)
14058 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14061 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14063 int scroll_p
= 0, must_scroll
= 0;
14064 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14066 if (PT
> XFASTINT (w
->last_point
))
14068 /* Point has moved forward. */
14069 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14070 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14072 xassert (row
->enabled_p
);
14076 /* If the end position of a row equals the start
14077 position of the next row, and PT is at that position,
14078 we would rather display cursor in the next line. */
14079 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14080 && MATRIX_ROW_END_CHARPOS (row
) == PT
14081 && row
< w
->current_matrix
->rows
14082 + w
->current_matrix
->nrows
- 1
14083 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14084 && !cursor_row_p (row
))
14087 /* If within the scroll margin, scroll. Note that
14088 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
14089 the next line would be drawn, and that
14090 this_scroll_margin can be zero. */
14091 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
14092 || PT
> MATRIX_ROW_END_CHARPOS (row
)
14093 /* Line is completely visible last line in window
14094 and PT is to be set in the next line. */
14095 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
14096 && PT
== MATRIX_ROW_END_CHARPOS (row
)
14097 && !row
->ends_at_zv_p
14098 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14101 else if (PT
< XFASTINT (w
->last_point
))
14103 /* Cursor has to be moved backward. Note that PT >=
14104 CHARPOS (startp) because of the outer if-statement. */
14105 while (!row
->mode_line_p
14106 && (MATRIX_ROW_START_CHARPOS (row
) > PT
14107 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14108 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
14109 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
14110 row
> w
->current_matrix
->rows
14111 && (row
-1)->ends_in_newline_from_string_p
))))
14112 && (row
->y
> top_scroll_margin
14113 || CHARPOS (startp
) == BEGV
))
14115 xassert (row
->enabled_p
);
14119 /* Consider the following case: Window starts at BEGV,
14120 there is invisible, intangible text at BEGV, so that
14121 display starts at some point START > BEGV. It can
14122 happen that we are called with PT somewhere between
14123 BEGV and START. Try to handle that case. */
14124 if (row
< w
->current_matrix
->rows
14125 || row
->mode_line_p
)
14127 row
= w
->current_matrix
->rows
;
14128 if (row
->mode_line_p
)
14132 /* Due to newlines in overlay strings, we may have to
14133 skip forward over overlay strings. */
14134 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14135 && MATRIX_ROW_END_CHARPOS (row
) == PT
14136 && !cursor_row_p (row
))
14139 /* If within the scroll margin, scroll. */
14140 if (row
->y
< top_scroll_margin
14141 && CHARPOS (startp
) != BEGV
)
14146 /* Cursor did not move. So don't scroll even if cursor line
14147 is partially visible, as it was so before. */
14148 rc
= CURSOR_MOVEMENT_SUCCESS
;
14151 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
14152 || PT
> MATRIX_ROW_END_CHARPOS (row
))
14154 /* if PT is not in the glyph row, give up. */
14155 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14158 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14159 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14161 /* If rows are bidi-reordered and point moved, back up
14162 until we find a row that does not belong to a
14163 continuation line. This is because we must consider
14164 all rows of a continued line as candidates for the
14165 new cursor positioning, since row start and end
14166 positions change non-linearly with vertical position
14168 /* FIXME: Revisit this when glyph ``spilling'' in
14169 continuation lines' rows is implemented for
14170 bidi-reordered rows. */
14171 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
14173 xassert (row
->enabled_p
);
14175 /* If we hit the beginning of the displayed portion
14176 without finding the first row of a continued
14178 if (row
<= w
->current_matrix
->rows
)
14180 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14188 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14189 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
14190 && make_cursor_line_fully_visible_p
)
14192 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
14193 && !row
->ends_at_zv_p
14194 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14195 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14196 else if (row
->height
> window_box_height (w
))
14198 /* If we end up in a partially visible line, let's
14199 make it fully visible, except when it's taller
14200 than the window, in which case we can't do much
14203 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14207 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14208 if (!cursor_row_fully_visible_p (w
, 0, 1))
14209 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14211 rc
= CURSOR_MOVEMENT_SUCCESS
;
14215 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14216 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14217 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14219 /* With bidi-reordered rows, there could be more than
14220 one candidate row whose start and end positions
14221 occlude point. We need to let set_cursor_from_row
14222 find the best candidate. */
14223 /* FIXME: Revisit this when glyph ``spilling'' in
14224 continuation lines' rows is implemented for
14225 bidi-reordered rows. */
14230 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
14231 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14232 && cursor_row_p (row
))
14233 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
14235 /* As soon as we've found the first suitable row
14236 whose ends_at_zv_p flag is set, we are done. */
14238 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
14240 rc
= CURSOR_MOVEMENT_SUCCESS
;
14245 while ((MATRIX_ROW_CONTINUATION_LINE_P (row
)
14246 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
14247 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14248 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
14249 /* If we didn't find any candidate rows, or exited the
14250 loop before all the candidates were examined, signal
14251 to the caller that this method failed. */
14252 if (rc
!= CURSOR_MOVEMENT_SUCCESS
14253 && (!rv
|| MATRIX_ROW_CONTINUATION_LINE_P (row
)))
14254 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14256 rc
= CURSOR_MOVEMENT_SUCCESS
;
14262 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
14264 rc
= CURSOR_MOVEMENT_SUCCESS
;
14269 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14270 && MATRIX_ROW_START_CHARPOS (row
) == PT
14271 && cursor_row_p (row
));
14279 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
14283 set_vertical_scroll_bar (struct window
*w
)
14285 EMACS_INT start
, end
, whole
;
14287 /* Calculate the start and end positions for the current window.
14288 At some point, it would be nice to choose between scrollbars
14289 which reflect the whole buffer size, with special markers
14290 indicating narrowing, and scrollbars which reflect only the
14293 Note that mini-buffers sometimes aren't displaying any text. */
14294 if (!MINI_WINDOW_P (w
)
14295 || (w
== XWINDOW (minibuf_window
)
14296 && NILP (echo_area_buffer
[0])))
14298 struct buffer
*buf
= XBUFFER (w
->buffer
);
14299 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
14300 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
14301 /* I don't think this is guaranteed to be right. For the
14302 moment, we'll pretend it is. */
14303 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
14307 if (whole
< (end
- start
))
14308 whole
= end
- start
;
14311 start
= end
= whole
= 0;
14313 /* Indicate what this scroll bar ought to be displaying now. */
14314 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
14315 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
14316 (w
, end
- start
, whole
, start
);
14320 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
14321 selected_window is redisplayed.
14323 We can return without actually redisplaying the window if
14324 fonts_changed_p is nonzero. In that case, redisplay_internal will
14328 redisplay_window (Lisp_Object window
, int just_this_one_p
)
14330 struct window
*w
= XWINDOW (window
);
14331 struct frame
*f
= XFRAME (w
->frame
);
14332 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14333 struct buffer
*old
= current_buffer
;
14334 struct text_pos lpoint
, opoint
, startp
;
14335 int update_mode_line
;
14338 /* Record it now because it's overwritten. */
14339 int current_matrix_up_to_date_p
= 0;
14340 int used_current_matrix_p
= 0;
14341 /* This is less strict than current_matrix_up_to_date_p.
14342 It indictes that the buffer contents and narrowing are unchanged. */
14343 int buffer_unchanged_p
= 0;
14344 int temp_scroll_step
= 0;
14345 int count
= SPECPDL_INDEX ();
14347 int centering_position
= -1;
14348 int last_line_misfit
= 0;
14349 EMACS_INT beg_unchanged
, end_unchanged
;
14351 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14354 /* W must be a leaf window here. */
14355 xassert (!NILP (w
->buffer
));
14357 *w
->desired_matrix
->method
= 0;
14361 reconsider_clip_changes (w
, buffer
);
14363 /* Has the mode line to be updated? */
14364 update_mode_line
= (!NILP (w
->update_mode_line
)
14365 || update_mode_lines
14366 || buffer
->clip_changed
14367 || buffer
->prevent_redisplay_optimizations_p
);
14369 if (MINI_WINDOW_P (w
))
14371 if (w
== XWINDOW (echo_area_window
)
14372 && !NILP (echo_area_buffer
[0]))
14374 if (update_mode_line
)
14375 /* We may have to update a tty frame's menu bar or a
14376 tool-bar. Example `M-x C-h C-h C-g'. */
14377 goto finish_menu_bars
;
14379 /* We've already displayed the echo area glyphs in this window. */
14380 goto finish_scroll_bars
;
14382 else if ((w
!= XWINDOW (minibuf_window
)
14383 || minibuf_level
== 0)
14384 /* When buffer is nonempty, redisplay window normally. */
14385 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
14386 /* Quail displays non-mini buffers in minibuffer window.
14387 In that case, redisplay the window normally. */
14388 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
14390 /* W is a mini-buffer window, but it's not active, so clear
14392 int yb
= window_text_bottom_y (w
);
14393 struct glyph_row
*row
;
14396 for (y
= 0, row
= w
->desired_matrix
->rows
;
14398 y
+= row
->height
, ++row
)
14399 blank_row (w
, row
, y
);
14400 goto finish_scroll_bars
;
14403 clear_glyph_matrix (w
->desired_matrix
);
14406 /* Otherwise set up data on this window; select its buffer and point
14408 /* Really select the buffer, for the sake of buffer-local
14410 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14412 current_matrix_up_to_date_p
14413 = (!NILP (w
->window_end_valid
)
14414 && !current_buffer
->clip_changed
14415 && !current_buffer
->prevent_redisplay_optimizations_p
14416 && XFASTINT (w
->last_modified
) >= MODIFF
14417 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
14419 /* Run the window-bottom-change-functions
14420 if it is possible that the text on the screen has changed
14421 (either due to modification of the text, or any other reason). */
14422 if (!current_matrix_up_to_date_p
14423 && !NILP (Vwindow_text_change_functions
))
14425 safe_run_hooks (Qwindow_text_change_functions
);
14429 beg_unchanged
= BEG_UNCHANGED
;
14430 end_unchanged
= END_UNCHANGED
;
14432 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
14434 specbind (Qinhibit_point_motion_hooks
, Qt
);
14437 = (!NILP (w
->window_end_valid
)
14438 && !current_buffer
->clip_changed
14439 && XFASTINT (w
->last_modified
) >= MODIFF
14440 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
14442 /* When windows_or_buffers_changed is non-zero, we can't rely on
14443 the window end being valid, so set it to nil there. */
14444 if (windows_or_buffers_changed
)
14446 /* If window starts on a continuation line, maybe adjust the
14447 window start in case the window's width changed. */
14448 if (XMARKER (w
->start
)->buffer
== current_buffer
)
14449 compute_window_start_on_continuation_line (w
);
14451 w
->window_end_valid
= Qnil
;
14454 /* Some sanity checks. */
14455 CHECK_WINDOW_END (w
);
14456 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
14458 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
14461 /* If %c is in mode line, update it if needed. */
14462 if (!NILP (w
->column_number_displayed
)
14463 /* This alternative quickly identifies a common case
14464 where no change is needed. */
14465 && !(PT
== XFASTINT (w
->last_point
)
14466 && XFASTINT (w
->last_modified
) >= MODIFF
14467 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
14468 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
14469 update_mode_line
= 1;
14471 /* Count number of windows showing the selected buffer. An indirect
14472 buffer counts as its base buffer. */
14473 if (!just_this_one_p
)
14475 struct buffer
*current_base
, *window_base
;
14476 current_base
= current_buffer
;
14477 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
14478 if (current_base
->base_buffer
)
14479 current_base
= current_base
->base_buffer
;
14480 if (window_base
->base_buffer
)
14481 window_base
= window_base
->base_buffer
;
14482 if (current_base
== window_base
)
14486 /* Point refers normally to the selected window. For any other
14487 window, set up appropriate value. */
14488 if (!EQ (window
, selected_window
))
14490 EMACS_INT new_pt
= XMARKER (w
->pointm
)->charpos
;
14491 EMACS_INT new_pt_byte
= marker_byte_position (w
->pointm
);
14495 new_pt_byte
= BEGV_BYTE
;
14496 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
14498 else if (new_pt
> (ZV
- 1))
14501 new_pt_byte
= ZV_BYTE
;
14502 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
14505 /* We don't use SET_PT so that the point-motion hooks don't run. */
14506 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
14509 /* If any of the character widths specified in the display table
14510 have changed, invalidate the width run cache. It's true that
14511 this may be a bit late to catch such changes, but the rest of
14512 redisplay goes (non-fatally) haywire when the display table is
14513 changed, so why should we worry about doing any better? */
14514 if (current_buffer
->width_run_cache
)
14516 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
14518 if (! disptab_matches_widthtab (disptab
,
14519 XVECTOR (BVAR (current_buffer
, width_table
))))
14521 invalidate_region_cache (current_buffer
,
14522 current_buffer
->width_run_cache
,
14524 recompute_width_table (current_buffer
, disptab
);
14528 /* If window-start is screwed up, choose a new one. */
14529 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
14532 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14534 /* If someone specified a new starting point but did not insist,
14535 check whether it can be used. */
14536 if (!NILP (w
->optional_new_start
)
14537 && CHARPOS (startp
) >= BEGV
14538 && CHARPOS (startp
) <= ZV
)
14540 w
->optional_new_start
= Qnil
;
14541 start_display (&it
, w
, startp
);
14542 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
14543 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14544 if (IT_CHARPOS (it
) == PT
)
14545 w
->force_start
= Qt
;
14546 /* IT may overshoot PT if text at PT is invisible. */
14547 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
14548 w
->force_start
= Qt
;
14553 /* Handle case where place to start displaying has been specified,
14554 unless the specified location is outside the accessible range. */
14555 if (!NILP (w
->force_start
)
14556 || w
->frozen_window_start_p
)
14558 /* We set this later on if we have to adjust point. */
14561 w
->force_start
= Qnil
;
14563 w
->window_end_valid
= Qnil
;
14565 /* Forget any recorded base line for line number display. */
14566 if (!buffer_unchanged_p
)
14567 w
->base_line_number
= Qnil
;
14569 /* Redisplay the mode line. Select the buffer properly for that.
14570 Also, run the hook window-scroll-functions
14571 because we have scrolled. */
14572 /* Note, we do this after clearing force_start because
14573 if there's an error, it is better to forget about force_start
14574 than to get into an infinite loop calling the hook functions
14575 and having them get more errors. */
14576 if (!update_mode_line
14577 || ! NILP (Vwindow_scroll_functions
))
14579 update_mode_line
= 1;
14580 w
->update_mode_line
= Qt
;
14581 startp
= run_window_scroll_functions (window
, startp
);
14584 w
->last_modified
= make_number (0);
14585 w
->last_overlay_modified
= make_number (0);
14586 if (CHARPOS (startp
) < BEGV
)
14587 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14588 else if (CHARPOS (startp
) > ZV
)
14589 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14591 /* Redisplay, then check if cursor has been set during the
14592 redisplay. Give up if new fonts were loaded. */
14593 /* We used to issue a CHECK_MARGINS argument to try_window here,
14594 but this causes scrolling to fail when point begins inside
14595 the scroll margin (bug#148) -- cyd */
14596 if (!try_window (window
, startp
, 0))
14598 w
->force_start
= Qt
;
14599 clear_glyph_matrix (w
->desired_matrix
);
14600 goto need_larger_matrices
;
14603 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14605 /* If point does not appear, try to move point so it does
14606 appear. The desired matrix has been built above, so we
14607 can use it here. */
14608 new_vpos
= window_box_height (w
) / 2;
14611 if (!cursor_row_fully_visible_p (w
, 0, 0))
14613 /* Point does appear, but on a line partly visible at end of window.
14614 Move it back to a fully-visible line. */
14615 new_vpos
= window_box_height (w
);
14618 /* If we need to move point for either of the above reasons,
14619 now actually do it. */
14622 struct glyph_row
*row
;
14624 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14625 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14628 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14629 MATRIX_ROW_START_BYTEPOS (row
));
14631 if (w
!= XWINDOW (selected_window
))
14632 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14633 else if (current_buffer
== old
)
14634 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14636 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14638 /* If we are highlighting the region, then we just changed
14639 the region, so redisplay to show it. */
14640 if (!NILP (Vtransient_mark_mode
)
14641 && !NILP (BVAR (current_buffer
, mark_active
)))
14643 clear_glyph_matrix (w
->desired_matrix
);
14644 if (!try_window (window
, startp
, 0))
14645 goto need_larger_matrices
;
14650 debug_method_add (w
, "forced window start");
14655 /* Handle case where text has not changed, only point, and it has
14656 not moved off the frame, and we are not retrying after hscroll.
14657 (current_matrix_up_to_date_p is nonzero when retrying.) */
14658 if (current_matrix_up_to_date_p
14659 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14660 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14664 case CURSOR_MOVEMENT_SUCCESS
:
14665 used_current_matrix_p
= 1;
14668 case CURSOR_MOVEMENT_MUST_SCROLL
:
14669 goto try_to_scroll
;
14675 /* If current starting point was originally the beginning of a line
14676 but no longer is, find a new starting point. */
14677 else if (!NILP (w
->start_at_line_beg
)
14678 && !(CHARPOS (startp
) <= BEGV
14679 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14682 debug_method_add (w
, "recenter 1");
14687 /* Try scrolling with try_window_id. Value is > 0 if update has
14688 been done, it is -1 if we know that the same window start will
14689 not work. It is 0 if unsuccessful for some other reason. */
14690 else if ((tem
= try_window_id (w
)) != 0)
14693 debug_method_add (w
, "try_window_id %d", tem
);
14696 if (fonts_changed_p
)
14697 goto need_larger_matrices
;
14701 /* Otherwise try_window_id has returned -1 which means that we
14702 don't want the alternative below this comment to execute. */
14704 else if (CHARPOS (startp
) >= BEGV
14705 && CHARPOS (startp
) <= ZV
14706 && PT
>= CHARPOS (startp
)
14707 && (CHARPOS (startp
) < ZV
14708 /* Avoid starting at end of buffer. */
14709 || CHARPOS (startp
) == BEGV
14710 || (XFASTINT (w
->last_modified
) >= MODIFF
14711 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14714 /* If first window line is a continuation line, and window start
14715 is inside the modified region, but the first change is before
14716 current window start, we must select a new window start.
14718 However, if this is the result of a down-mouse event (e.g. by
14719 extending the mouse-drag-overlay), we don't want to select a
14720 new window start, since that would change the position under
14721 the mouse, resulting in an unwanted mouse-movement rather
14722 than a simple mouse-click. */
14723 if (NILP (w
->start_at_line_beg
)
14724 && NILP (do_mouse_tracking
)
14725 && CHARPOS (startp
) > BEGV
14726 && CHARPOS (startp
) > BEG
+ beg_unchanged
14727 && CHARPOS (startp
) <= Z
- end_unchanged
14728 /* Even if w->start_at_line_beg is nil, a new window may
14729 start at a line_beg, since that's how set_buffer_window
14730 sets it. So, we need to check the return value of
14731 compute_window_start_on_continuation_line. (See also
14733 && XMARKER (w
->start
)->buffer
== current_buffer
14734 && compute_window_start_on_continuation_line (w
))
14736 w
->force_start
= Qt
;
14737 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14742 debug_method_add (w
, "same window start");
14745 /* Try to redisplay starting at same place as before.
14746 If point has not moved off frame, accept the results. */
14747 if (!current_matrix_up_to_date_p
14748 /* Don't use try_window_reusing_current_matrix in this case
14749 because a window scroll function can have changed the
14751 || !NILP (Vwindow_scroll_functions
)
14752 || MINI_WINDOW_P (w
)
14753 || !(used_current_matrix_p
14754 = try_window_reusing_current_matrix (w
)))
14756 IF_DEBUG (debug_method_add (w
, "1"));
14757 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
14758 /* -1 means we need to scroll.
14759 0 means we need new matrices, but fonts_changed_p
14760 is set in that case, so we will detect it below. */
14761 goto try_to_scroll
;
14764 if (fonts_changed_p
)
14765 goto need_larger_matrices
;
14767 if (w
->cursor
.vpos
>= 0)
14769 if (!just_this_one_p
14770 || current_buffer
->clip_changed
14771 || BEG_UNCHANGED
< CHARPOS (startp
))
14772 /* Forget any recorded base line for line number display. */
14773 w
->base_line_number
= Qnil
;
14775 if (!cursor_row_fully_visible_p (w
, 1, 0))
14777 clear_glyph_matrix (w
->desired_matrix
);
14778 last_line_misfit
= 1;
14780 /* Drop through and scroll. */
14785 clear_glyph_matrix (w
->desired_matrix
);
14790 w
->last_modified
= make_number (0);
14791 w
->last_overlay_modified
= make_number (0);
14793 /* Redisplay the mode line. Select the buffer properly for that. */
14794 if (!update_mode_line
)
14796 update_mode_line
= 1;
14797 w
->update_mode_line
= Qt
;
14800 /* Try to scroll by specified few lines. */
14801 if ((scroll_conservatively
14802 || emacs_scroll_step
14803 || temp_scroll_step
14804 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
14805 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
14806 && CHARPOS (startp
) >= BEGV
14807 && CHARPOS (startp
) <= ZV
)
14809 /* The function returns -1 if new fonts were loaded, 1 if
14810 successful, 0 if not successful. */
14811 int ss
= try_scrolling (window
, just_this_one_p
,
14812 scroll_conservatively
,
14814 temp_scroll_step
, last_line_misfit
);
14817 case SCROLLING_SUCCESS
:
14820 case SCROLLING_NEED_LARGER_MATRICES
:
14821 goto need_larger_matrices
;
14823 case SCROLLING_FAILED
:
14831 /* Finally, just choose a place to start which positions point
14832 according to user preferences. */
14837 debug_method_add (w
, "recenter");
14840 /* w->vscroll = 0; */
14842 /* Forget any previously recorded base line for line number display. */
14843 if (!buffer_unchanged_p
)
14844 w
->base_line_number
= Qnil
;
14846 /* Determine the window start relative to point. */
14847 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14848 it
.current_y
= it
.last_visible_y
;
14849 if (centering_position
< 0)
14853 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14855 EMACS_INT margin_pos
= CHARPOS (startp
);
14857 Lisp_Object aggressive
;
14859 /* If there is a scroll margin at the top of the window, find
14860 its character position. */
14862 /* Cannot call start_display if startp is not in the
14863 accessible region of the buffer. This can happen when we
14864 have just switched to a different buffer and/or changed
14865 its restriction. In that case, startp is initialized to
14866 the character position 1 (BEG) because we did not yet
14867 have chance to display the buffer even once. */
14868 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
14872 start_display (&it1
, w
, startp
);
14873 move_it_vertically (&it1
, margin
);
14874 margin_pos
= IT_CHARPOS (it1
);
14876 scrolling_up
= PT
> margin_pos
;
14879 ? BVAR (current_buffer
, scroll_up_aggressively
)
14880 : BVAR (current_buffer
, scroll_down_aggressively
);
14882 if (!MINI_WINDOW_P (w
)
14883 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
14887 /* Setting scroll-conservatively overrides
14888 scroll-*-aggressively. */
14889 if (!scroll_conservatively
&& NUMBERP (aggressive
))
14891 double float_amount
= XFLOATINT (aggressive
);
14893 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
14894 if (pt_offset
== 0 && float_amount
> 0)
14899 /* Compute how much to move the window start backward from
14900 point so that point will be displayed where the user
14904 centering_position
= it
.last_visible_y
;
14906 centering_position
-= pt_offset
;
14907 centering_position
-=
14908 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0));
14909 /* Don't let point enter the scroll margin near top of
14911 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
14912 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
14915 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
14918 /* Set the window start half the height of the window backward
14920 centering_position
= window_box_height (w
) / 2;
14922 move_it_vertically_backward (&it
, centering_position
);
14924 xassert (IT_CHARPOS (it
) >= BEGV
);
14926 /* The function move_it_vertically_backward may move over more
14927 than the specified y-distance. If it->w is small, e.g. a
14928 mini-buffer window, we may end up in front of the window's
14929 display area. Start displaying at the start of the line
14930 containing PT in this case. */
14931 if (it
.current_y
<= 0)
14933 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14934 move_it_vertically_backward (&it
, 0);
14938 it
.current_x
= it
.hpos
= 0;
14940 /* Set the window start position here explicitly, to avoid an
14941 infinite loop in case the functions in window-scroll-functions
14943 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14945 /* Run scroll hooks. */
14946 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14948 /* Redisplay the window. */
14949 if (!current_matrix_up_to_date_p
14950 || windows_or_buffers_changed
14951 || cursor_type_changed
14952 /* Don't use try_window_reusing_current_matrix in this case
14953 because it can have changed the buffer. */
14954 || !NILP (Vwindow_scroll_functions
)
14955 || !just_this_one_p
14956 || MINI_WINDOW_P (w
)
14957 || !(used_current_matrix_p
14958 = try_window_reusing_current_matrix (w
)))
14959 try_window (window
, startp
, 0);
14961 /* If new fonts have been loaded (due to fontsets), give up. We
14962 have to start a new redisplay since we need to re-adjust glyph
14964 if (fonts_changed_p
)
14965 goto need_larger_matrices
;
14967 /* If cursor did not appear assume that the middle of the window is
14968 in the first line of the window. Do it again with the next line.
14969 (Imagine a window of height 100, displaying two lines of height
14970 60. Moving back 50 from it->last_visible_y will end in the first
14972 if (w
->cursor
.vpos
< 0)
14974 if (!NILP (w
->window_end_valid
)
14975 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14977 clear_glyph_matrix (w
->desired_matrix
);
14978 move_it_by_lines (&it
, 1);
14979 try_window (window
, it
.current
.pos
, 0);
14981 else if (PT
< IT_CHARPOS (it
))
14983 clear_glyph_matrix (w
->desired_matrix
);
14984 move_it_by_lines (&it
, -1);
14985 try_window (window
, it
.current
.pos
, 0);
14989 /* Not much we can do about it. */
14993 /* Consider the following case: Window starts at BEGV, there is
14994 invisible, intangible text at BEGV, so that display starts at
14995 some point START > BEGV. It can happen that we are called with
14996 PT somewhere between BEGV and START. Try to handle that case. */
14997 if (w
->cursor
.vpos
< 0)
14999 struct glyph_row
*row
= w
->current_matrix
->rows
;
15000 if (row
->mode_line_p
)
15002 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15005 if (!cursor_row_fully_visible_p (w
, 0, 0))
15007 /* If vscroll is enabled, disable it and try again. */
15011 clear_glyph_matrix (w
->desired_matrix
);
15015 /* If centering point failed to make the whole line visible,
15016 put point at the top instead. That has to make the whole line
15017 visible, if it can be done. */
15018 if (centering_position
== 0)
15021 clear_glyph_matrix (w
->desired_matrix
);
15022 centering_position
= 0;
15028 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15029 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
15030 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
15033 /* Display the mode line, if we must. */
15034 if ((update_mode_line
15035 /* If window not full width, must redo its mode line
15036 if (a) the window to its side is being redone and
15037 (b) we do a frame-based redisplay. This is a consequence
15038 of how inverted lines are drawn in frame-based redisplay. */
15039 || (!just_this_one_p
15040 && !FRAME_WINDOW_P (f
)
15041 && !WINDOW_FULL_WIDTH_P (w
))
15042 /* Line number to display. */
15043 || INTEGERP (w
->base_line_pos
)
15044 /* Column number is displayed and different from the one displayed. */
15045 || (!NILP (w
->column_number_displayed
)
15046 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
15047 /* This means that the window has a mode line. */
15048 && (WINDOW_WANTS_MODELINE_P (w
)
15049 || WINDOW_WANTS_HEADER_LINE_P (w
)))
15051 display_mode_lines (w
);
15053 /* If mode line height has changed, arrange for a thorough
15054 immediate redisplay using the correct mode line height. */
15055 if (WINDOW_WANTS_MODELINE_P (w
)
15056 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
15058 fonts_changed_p
= 1;
15059 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
15060 = DESIRED_MODE_LINE_HEIGHT (w
);
15063 /* If header line height has changed, arrange for a thorough
15064 immediate redisplay using the correct header line height. */
15065 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15066 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
15068 fonts_changed_p
= 1;
15069 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
15070 = DESIRED_HEADER_LINE_HEIGHT (w
);
15073 if (fonts_changed_p
)
15074 goto need_larger_matrices
;
15077 if (!line_number_displayed
15078 && !BUFFERP (w
->base_line_pos
))
15080 w
->base_line_pos
= Qnil
;
15081 w
->base_line_number
= Qnil
;
15086 /* When we reach a frame's selected window, redo the frame's menu bar. */
15087 if (update_mode_line
15088 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
15090 int redisplay_menu_p
= 0;
15092 if (FRAME_WINDOW_P (f
))
15094 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
15095 || defined (HAVE_NS) || defined (USE_GTK)
15096 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
15098 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15102 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15104 if (redisplay_menu_p
)
15105 display_menu_bar (w
);
15107 #ifdef HAVE_WINDOW_SYSTEM
15108 if (FRAME_WINDOW_P (f
))
15110 #if defined (USE_GTK) || defined (HAVE_NS)
15111 if (FRAME_EXTERNAL_TOOL_BAR (f
))
15112 redisplay_tool_bar (f
);
15114 if (WINDOWP (f
->tool_bar_window
)
15115 && (FRAME_TOOL_BAR_LINES (f
) > 0
15116 || !NILP (Vauto_resize_tool_bars
))
15117 && redisplay_tool_bar (f
))
15118 ignore_mouse_drag_p
= 1;
15124 #ifdef HAVE_WINDOW_SYSTEM
15125 if (FRAME_WINDOW_P (f
)
15126 && update_window_fringes (w
, (just_this_one_p
15127 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
15128 || w
->pseudo_window_p
)))
15132 if (draw_window_fringes (w
, 1))
15133 x_draw_vertical_border (w
);
15137 #endif /* HAVE_WINDOW_SYSTEM */
15139 /* We go to this label, with fonts_changed_p nonzero,
15140 if it is necessary to try again using larger glyph matrices.
15141 We have to redeem the scroll bar even in this case,
15142 because the loop in redisplay_internal expects that. */
15143 need_larger_matrices
:
15145 finish_scroll_bars
:
15147 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
15149 /* Set the thumb's position and size. */
15150 set_vertical_scroll_bar (w
);
15152 /* Note that we actually used the scroll bar attached to this
15153 window, so it shouldn't be deleted at the end of redisplay. */
15154 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
15155 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
15158 /* Restore current_buffer and value of point in it. The window
15159 update may have changed the buffer, so first make sure `opoint'
15160 is still valid (Bug#6177). */
15161 if (CHARPOS (opoint
) < BEGV
)
15162 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15163 else if (CHARPOS (opoint
) > ZV
)
15164 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
15166 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
15168 set_buffer_internal_1 (old
);
15169 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
15170 shorter. This can be caused by log truncation in *Messages*. */
15171 if (CHARPOS (lpoint
) <= ZV
)
15172 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15174 unbind_to (count
, Qnil
);
15178 /* Build the complete desired matrix of WINDOW with a window start
15179 buffer position POS.
15181 Value is 1 if successful. It is zero if fonts were loaded during
15182 redisplay which makes re-adjusting glyph matrices necessary, and -1
15183 if point would appear in the scroll margins.
15184 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
15185 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
15189 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
15191 struct window
*w
= XWINDOW (window
);
15193 struct glyph_row
*last_text_row
= NULL
;
15194 struct frame
*f
= XFRAME (w
->frame
);
15196 /* Make POS the new window start. */
15197 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
15199 /* Mark cursor position as unknown. No overlay arrow seen. */
15200 w
->cursor
.vpos
= -1;
15201 overlay_arrow_seen
= 0;
15203 /* Initialize iterator and info to start at POS. */
15204 start_display (&it
, w
, pos
);
15206 /* Display all lines of W. */
15207 while (it
.current_y
< it
.last_visible_y
)
15209 if (display_line (&it
))
15210 last_text_row
= it
.glyph_row
- 1;
15211 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
15215 /* Don't let the cursor end in the scroll margins. */
15216 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
15217 && !MINI_WINDOW_P (w
))
15219 int this_scroll_margin
;
15221 if (scroll_margin
> 0)
15223 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15224 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15227 this_scroll_margin
= 0;
15229 if ((w
->cursor
.y
>= 0 /* not vscrolled */
15230 && w
->cursor
.y
< this_scroll_margin
15231 && CHARPOS (pos
) > BEGV
15232 && IT_CHARPOS (it
) < ZV
)
15233 /* rms: considering make_cursor_line_fully_visible_p here
15234 seems to give wrong results. We don't want to recenter
15235 when the last line is partly visible, we want to allow
15236 that case to be handled in the usual way. */
15237 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
15239 w
->cursor
.vpos
= -1;
15240 clear_glyph_matrix (w
->desired_matrix
);
15245 /* If bottom moved off end of frame, change mode line percentage. */
15246 if (XFASTINT (w
->window_end_pos
) <= 0
15247 && Z
!= IT_CHARPOS (it
))
15248 w
->update_mode_line
= Qt
;
15250 /* Set window_end_pos to the offset of the last character displayed
15251 on the window from the end of current_buffer. Set
15252 window_end_vpos to its row number. */
15255 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
15256 w
->window_end_bytepos
15257 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15259 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15261 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15262 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
15263 ->displays_text_p
);
15267 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
15268 w
->window_end_pos
= make_number (Z
- ZV
);
15269 w
->window_end_vpos
= make_number (0);
15272 /* But that is not valid info until redisplay finishes. */
15273 w
->window_end_valid
= Qnil
;
15279 /************************************************************************
15280 Window redisplay reusing current matrix when buffer has not changed
15281 ************************************************************************/
15283 /* Try redisplay of window W showing an unchanged buffer with a
15284 different window start than the last time it was displayed by
15285 reusing its current matrix. Value is non-zero if successful.
15286 W->start is the new window start. */
15289 try_window_reusing_current_matrix (struct window
*w
)
15291 struct frame
*f
= XFRAME (w
->frame
);
15292 struct glyph_row
*bottom_row
;
15295 struct text_pos start
, new_start
;
15296 int nrows_scrolled
, i
;
15297 struct glyph_row
*last_text_row
;
15298 struct glyph_row
*last_reused_text_row
;
15299 struct glyph_row
*start_row
;
15300 int start_vpos
, min_y
, max_y
;
15303 if (inhibit_try_window_reusing
)
15307 if (/* This function doesn't handle terminal frames. */
15308 !FRAME_WINDOW_P (f
)
15309 /* Don't try to reuse the display if windows have been split
15311 || windows_or_buffers_changed
15312 || cursor_type_changed
)
15315 /* Can't do this if region may have changed. */
15316 if ((!NILP (Vtransient_mark_mode
)
15317 && !NILP (BVAR (current_buffer
, mark_active
)))
15318 || !NILP (w
->region_showing
)
15319 || !NILP (Vshow_trailing_whitespace
))
15322 /* If top-line visibility has changed, give up. */
15323 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15324 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
15327 /* Give up if old or new display is scrolled vertically. We could
15328 make this function handle this, but right now it doesn't. */
15329 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15330 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
15333 /* The variable new_start now holds the new window start. The old
15334 start `start' can be determined from the current matrix. */
15335 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
15336 start
= start_row
->minpos
;
15337 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
15339 /* Clear the desired matrix for the display below. */
15340 clear_glyph_matrix (w
->desired_matrix
);
15342 if (CHARPOS (new_start
) <= CHARPOS (start
))
15344 /* Don't use this method if the display starts with an ellipsis
15345 displayed for invisible text. It's not easy to handle that case
15346 below, and it's certainly not worth the effort since this is
15347 not a frequent case. */
15348 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
15351 IF_DEBUG (debug_method_add (w
, "twu1"));
15353 /* Display up to a row that can be reused. The variable
15354 last_text_row is set to the last row displayed that displays
15355 text. Note that it.vpos == 0 if or if not there is a
15356 header-line; it's not the same as the MATRIX_ROW_VPOS! */
15357 start_display (&it
, w
, new_start
);
15358 w
->cursor
.vpos
= -1;
15359 last_text_row
= last_reused_text_row
= NULL
;
15361 while (it
.current_y
< it
.last_visible_y
15362 && !fonts_changed_p
)
15364 /* If we have reached into the characters in the START row,
15365 that means the line boundaries have changed. So we
15366 can't start copying with the row START. Maybe it will
15367 work to start copying with the following row. */
15368 while (IT_CHARPOS (it
) > CHARPOS (start
))
15370 /* Advance to the next row as the "start". */
15372 start
= start_row
->minpos
;
15373 /* If there are no more rows to try, or just one, give up. */
15374 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
15375 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
15376 || CHARPOS (start
) == ZV
)
15378 clear_glyph_matrix (w
->desired_matrix
);
15382 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
15384 /* If we have reached alignment,
15385 we can copy the rest of the rows. */
15386 if (IT_CHARPOS (it
) == CHARPOS (start
))
15389 if (display_line (&it
))
15390 last_text_row
= it
.glyph_row
- 1;
15393 /* A value of current_y < last_visible_y means that we stopped
15394 at the previous window start, which in turn means that we
15395 have at least one reusable row. */
15396 if (it
.current_y
< it
.last_visible_y
)
15398 struct glyph_row
*row
;
15400 /* IT.vpos always starts from 0; it counts text lines. */
15401 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
15403 /* Find PT if not already found in the lines displayed. */
15404 if (w
->cursor
.vpos
< 0)
15406 int dy
= it
.current_y
- start_row
->y
;
15408 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15409 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
15411 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
15412 dy
, nrows_scrolled
);
15415 clear_glyph_matrix (w
->desired_matrix
);
15420 /* Scroll the display. Do it before the current matrix is
15421 changed. The problem here is that update has not yet
15422 run, i.e. part of the current matrix is not up to date.
15423 scroll_run_hook will clear the cursor, and use the
15424 current matrix to get the height of the row the cursor is
15426 run
.current_y
= start_row
->y
;
15427 run
.desired_y
= it
.current_y
;
15428 run
.height
= it
.last_visible_y
- it
.current_y
;
15430 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
15433 FRAME_RIF (f
)->update_window_begin_hook (w
);
15434 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15435 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15436 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15440 /* Shift current matrix down by nrows_scrolled lines. */
15441 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15442 rotate_matrix (w
->current_matrix
,
15444 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15447 /* Disable lines that must be updated. */
15448 for (i
= 0; i
< nrows_scrolled
; ++i
)
15449 (start_row
+ i
)->enabled_p
= 0;
15451 /* Re-compute Y positions. */
15452 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15453 max_y
= it
.last_visible_y
;
15454 for (row
= start_row
+ nrows_scrolled
;
15458 row
->y
= it
.current_y
;
15459 row
->visible_height
= row
->height
;
15461 if (row
->y
< min_y
)
15462 row
->visible_height
-= min_y
- row
->y
;
15463 if (row
->y
+ row
->height
> max_y
)
15464 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15465 row
->redraw_fringe_bitmaps_p
= 1;
15467 it
.current_y
+= row
->height
;
15469 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15470 last_reused_text_row
= row
;
15471 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
15475 /* Disable lines in the current matrix which are now
15476 below the window. */
15477 for (++row
; row
< bottom_row
; ++row
)
15478 row
->enabled_p
= row
->mode_line_p
= 0;
15481 /* Update window_end_pos etc.; last_reused_text_row is the last
15482 reused row from the current matrix containing text, if any.
15483 The value of last_text_row is the last displayed line
15484 containing text. */
15485 if (last_reused_text_row
)
15487 w
->window_end_bytepos
15488 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
15490 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
15492 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
15493 w
->current_matrix
));
15495 else if (last_text_row
)
15497 w
->window_end_bytepos
15498 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15500 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15502 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15506 /* This window must be completely empty. */
15507 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
15508 w
->window_end_pos
= make_number (Z
- ZV
);
15509 w
->window_end_vpos
= make_number (0);
15511 w
->window_end_valid
= Qnil
;
15513 /* Update hint: don't try scrolling again in update_window. */
15514 w
->desired_matrix
->no_scrolling_p
= 1;
15517 debug_method_add (w
, "try_window_reusing_current_matrix 1");
15521 else if (CHARPOS (new_start
) > CHARPOS (start
))
15523 struct glyph_row
*pt_row
, *row
;
15524 struct glyph_row
*first_reusable_row
;
15525 struct glyph_row
*first_row_to_display
;
15527 int yb
= window_text_bottom_y (w
);
15529 /* Find the row starting at new_start, if there is one. Don't
15530 reuse a partially visible line at the end. */
15531 first_reusable_row
= start_row
;
15532 while (first_reusable_row
->enabled_p
15533 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
15534 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15535 < CHARPOS (new_start
)))
15536 ++first_reusable_row
;
15538 /* Give up if there is no row to reuse. */
15539 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
15540 || !first_reusable_row
->enabled_p
15541 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15542 != CHARPOS (new_start
)))
15545 /* We can reuse fully visible rows beginning with
15546 first_reusable_row to the end of the window. Set
15547 first_row_to_display to the first row that cannot be reused.
15548 Set pt_row to the row containing point, if there is any. */
15550 for (first_row_to_display
= first_reusable_row
;
15551 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
15552 ++first_row_to_display
)
15554 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
15555 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
15556 pt_row
= first_row_to_display
;
15559 /* Start displaying at the start of first_row_to_display. */
15560 xassert (first_row_to_display
->y
< yb
);
15561 init_to_row_start (&it
, w
, first_row_to_display
);
15563 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
15565 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
15567 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
15568 + WINDOW_HEADER_LINE_HEIGHT (w
));
15570 /* Display lines beginning with first_row_to_display in the
15571 desired matrix. Set last_text_row to the last row displayed
15572 that displays text. */
15573 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
15574 if (pt_row
== NULL
)
15575 w
->cursor
.vpos
= -1;
15576 last_text_row
= NULL
;
15577 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
15578 if (display_line (&it
))
15579 last_text_row
= it
.glyph_row
- 1;
15581 /* If point is in a reused row, adjust y and vpos of the cursor
15585 w
->cursor
.vpos
-= nrows_scrolled
;
15586 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
15589 /* Give up if point isn't in a row displayed or reused. (This
15590 also handles the case where w->cursor.vpos < nrows_scrolled
15591 after the calls to display_line, which can happen with scroll
15592 margins. See bug#1295.) */
15593 if (w
->cursor
.vpos
< 0)
15595 clear_glyph_matrix (w
->desired_matrix
);
15599 /* Scroll the display. */
15600 run
.current_y
= first_reusable_row
->y
;
15601 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15602 run
.height
= it
.last_visible_y
- run
.current_y
;
15603 dy
= run
.current_y
- run
.desired_y
;
15608 FRAME_RIF (f
)->update_window_begin_hook (w
);
15609 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15610 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15611 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15615 /* Adjust Y positions of reused rows. */
15616 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15617 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15618 max_y
= it
.last_visible_y
;
15619 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15622 row
->visible_height
= row
->height
;
15623 if (row
->y
< min_y
)
15624 row
->visible_height
-= min_y
- row
->y
;
15625 if (row
->y
+ row
->height
> max_y
)
15626 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15627 row
->redraw_fringe_bitmaps_p
= 1;
15630 /* Scroll the current matrix. */
15631 xassert (nrows_scrolled
> 0);
15632 rotate_matrix (w
->current_matrix
,
15634 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15637 /* Disable rows not reused. */
15638 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15639 row
->enabled_p
= 0;
15641 /* Point may have moved to a different line, so we cannot assume that
15642 the previous cursor position is valid; locate the correct row. */
15645 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15646 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15650 w
->cursor
.y
= row
->y
;
15652 if (row
< bottom_row
)
15654 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15655 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15657 /* Can't use this optimization with bidi-reordered glyph
15658 rows, unless cursor is already at point. */
15659 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15661 if (!(w
->cursor
.hpos
>= 0
15662 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
15663 && BUFFERP (glyph
->object
)
15664 && glyph
->charpos
== PT
))
15669 && (!BUFFERP (glyph
->object
)
15670 || glyph
->charpos
< PT
);
15674 w
->cursor
.x
+= glyph
->pixel_width
;
15679 /* Adjust window end. A null value of last_text_row means that
15680 the window end is in reused rows which in turn means that
15681 only its vpos can have changed. */
15684 w
->window_end_bytepos
15685 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15687 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15689 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15694 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15697 w
->window_end_valid
= Qnil
;
15698 w
->desired_matrix
->no_scrolling_p
= 1;
15701 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15711 /************************************************************************
15712 Window redisplay reusing current matrix when buffer has changed
15713 ************************************************************************/
15715 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
15716 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
15717 EMACS_INT
*, EMACS_INT
*);
15718 static struct glyph_row
*
15719 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
15720 struct glyph_row
*);
15723 /* Return the last row in MATRIX displaying text. If row START is
15724 non-null, start searching with that row. IT gives the dimensions
15725 of the display. Value is null if matrix is empty; otherwise it is
15726 a pointer to the row found. */
15728 static struct glyph_row
*
15729 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
15730 struct glyph_row
*start
)
15732 struct glyph_row
*row
, *row_found
;
15734 /* Set row_found to the last row in IT->w's current matrix
15735 displaying text. The loop looks funny but think of partially
15738 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15739 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15741 xassert (row
->enabled_p
);
15743 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15752 /* Return the last row in the current matrix of W that is not affected
15753 by changes at the start of current_buffer that occurred since W's
15754 current matrix was built. Value is null if no such row exists.
15756 BEG_UNCHANGED us the number of characters unchanged at the start of
15757 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15758 first changed character in current_buffer. Characters at positions <
15759 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15760 when the current matrix was built. */
15762 static struct glyph_row
*
15763 find_last_unchanged_at_beg_row (struct window
*w
)
15765 EMACS_INT first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15766 struct glyph_row
*row
;
15767 struct glyph_row
*row_found
= NULL
;
15768 int yb
= window_text_bottom_y (w
);
15770 /* Find the last row displaying unchanged text. */
15771 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15772 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15773 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15776 if (/* If row ends before first_changed_pos, it is unchanged,
15777 except in some case. */
15778 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15779 /* When row ends in ZV and we write at ZV it is not
15781 && !row
->ends_at_zv_p
15782 /* When first_changed_pos is the end of a continued line,
15783 row is not unchanged because it may be no longer
15785 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15786 && (row
->continued_p
15787 || row
->exact_window_width_line_p
)))
15790 /* Stop if last visible row. */
15791 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15799 /* Find the first glyph row in the current matrix of W that is not
15800 affected by changes at the end of current_buffer since the
15801 time W's current matrix was built.
15803 Return in *DELTA the number of chars by which buffer positions in
15804 unchanged text at the end of current_buffer must be adjusted.
15806 Return in *DELTA_BYTES the corresponding number of bytes.
15808 Value is null if no such row exists, i.e. all rows are affected by
15811 static struct glyph_row
*
15812 find_first_unchanged_at_end_row (struct window
*w
,
15813 EMACS_INT
*delta
, EMACS_INT
*delta_bytes
)
15815 struct glyph_row
*row
;
15816 struct glyph_row
*row_found
= NULL
;
15818 *delta
= *delta_bytes
= 0;
15820 /* Display must not have been paused, otherwise the current matrix
15821 is not up to date. */
15822 eassert (!NILP (w
->window_end_valid
));
15824 /* A value of window_end_pos >= END_UNCHANGED means that the window
15825 end is in the range of changed text. If so, there is no
15826 unchanged row at the end of W's current matrix. */
15827 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15830 /* Set row to the last row in W's current matrix displaying text. */
15831 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15833 /* If matrix is entirely empty, no unchanged row exists. */
15834 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15836 /* The value of row is the last glyph row in the matrix having a
15837 meaningful buffer position in it. The end position of row
15838 corresponds to window_end_pos. This allows us to translate
15839 buffer positions in the current matrix to current buffer
15840 positions for characters not in changed text. */
15842 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15843 EMACS_INT Z_BYTE_old
=
15844 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15845 EMACS_INT last_unchanged_pos
, last_unchanged_pos_old
;
15846 struct glyph_row
*first_text_row
15847 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15849 *delta
= Z
- Z_old
;
15850 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15852 /* Set last_unchanged_pos to the buffer position of the last
15853 character in the buffer that has not been changed. Z is the
15854 index + 1 of the last character in current_buffer, i.e. by
15855 subtracting END_UNCHANGED we get the index of the last
15856 unchanged character, and we have to add BEG to get its buffer
15858 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15859 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15861 /* Search backward from ROW for a row displaying a line that
15862 starts at a minimum position >= last_unchanged_pos_old. */
15863 for (; row
> first_text_row
; --row
)
15865 /* This used to abort, but it can happen.
15866 It is ok to just stop the search instead here. KFS. */
15867 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15870 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15875 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15881 /* Make sure that glyph rows in the current matrix of window W
15882 reference the same glyph memory as corresponding rows in the
15883 frame's frame matrix. This function is called after scrolling W's
15884 current matrix on a terminal frame in try_window_id and
15885 try_window_reusing_current_matrix. */
15888 sync_frame_with_window_matrix_rows (struct window
*w
)
15890 struct frame
*f
= XFRAME (w
->frame
);
15891 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15893 /* Preconditions: W must be a leaf window and full-width. Its frame
15894 must have a frame matrix. */
15895 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15896 xassert (WINDOW_FULL_WIDTH_P (w
));
15897 xassert (!FRAME_WINDOW_P (f
));
15899 /* If W is a full-width window, glyph pointers in W's current matrix
15900 have, by definition, to be the same as glyph pointers in the
15901 corresponding frame matrix. Note that frame matrices have no
15902 marginal areas (see build_frame_matrix). */
15903 window_row
= w
->current_matrix
->rows
;
15904 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15905 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15906 while (window_row
< window_row_end
)
15908 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15909 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15911 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15912 frame_row
->glyphs
[TEXT_AREA
] = start
;
15913 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15914 frame_row
->glyphs
[LAST_AREA
] = end
;
15916 /* Disable frame rows whose corresponding window rows have
15917 been disabled in try_window_id. */
15918 if (!window_row
->enabled_p
)
15919 frame_row
->enabled_p
= 0;
15921 ++window_row
, ++frame_row
;
15926 /* Find the glyph row in window W containing CHARPOS. Consider all
15927 rows between START and END (not inclusive). END null means search
15928 all rows to the end of the display area of W. Value is the row
15929 containing CHARPOS or null. */
15932 row_containing_pos (struct window
*w
, EMACS_INT charpos
,
15933 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
15935 struct glyph_row
*row
= start
;
15936 struct glyph_row
*best_row
= NULL
;
15937 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15940 /* If we happen to start on a header-line, skip that. */
15941 if (row
->mode_line_p
)
15944 if ((end
&& row
>= end
) || !row
->enabled_p
)
15947 last_y
= window_text_bottom_y (w
) - dy
;
15951 /* Give up if we have gone too far. */
15952 if (end
&& row
>= end
)
15954 /* This formerly returned if they were equal.
15955 I think that both quantities are of a "last plus one" type;
15956 if so, when they are equal, the row is within the screen. -- rms. */
15957 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15960 /* If it is in this row, return this row. */
15961 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15962 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15963 /* The end position of a row equals the start
15964 position of the next row. If CHARPOS is there, we
15965 would rather display it in the next line, except
15966 when this line ends in ZV. */
15967 && !row
->ends_at_zv_p
15968 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15969 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15973 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
15974 || (!best_row
&& !row
->continued_p
))
15976 /* In bidi-reordered rows, there could be several rows
15977 occluding point, all of them belonging to the same
15978 continued line. We need to find the row which fits
15979 CHARPOS the best. */
15980 for (g
= row
->glyphs
[TEXT_AREA
];
15981 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15984 if (!STRINGP (g
->object
))
15986 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
15988 mindif
= eabs (g
->charpos
- charpos
);
15990 /* Exact match always wins. */
15997 else if (best_row
&& !row
->continued_p
)
16004 /* Try to redisplay window W by reusing its existing display. W's
16005 current matrix must be up to date when this function is called,
16006 i.e. window_end_valid must not be nil.
16010 1 if display has been updated
16011 0 if otherwise unsuccessful
16012 -1 if redisplay with same window start is known not to succeed
16014 The following steps are performed:
16016 1. Find the last row in the current matrix of W that is not
16017 affected by changes at the start of current_buffer. If no such row
16020 2. Find the first row in W's current matrix that is not affected by
16021 changes at the end of current_buffer. Maybe there is no such row.
16023 3. Display lines beginning with the row + 1 found in step 1 to the
16024 row found in step 2 or, if step 2 didn't find a row, to the end of
16027 4. If cursor is not known to appear on the window, give up.
16029 5. If display stopped at the row found in step 2, scroll the
16030 display and current matrix as needed.
16032 6. Maybe display some lines at the end of W, if we must. This can
16033 happen under various circumstances, like a partially visible line
16034 becoming fully visible, or because newly displayed lines are displayed
16035 in smaller font sizes.
16037 7. Update W's window end information. */
16040 try_window_id (struct window
*w
)
16042 struct frame
*f
= XFRAME (w
->frame
);
16043 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
16044 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
16045 struct glyph_row
*last_unchanged_at_beg_row
;
16046 struct glyph_row
*first_unchanged_at_end_row
;
16047 struct glyph_row
*row
;
16048 struct glyph_row
*bottom_row
;
16051 EMACS_INT delta
= 0, delta_bytes
= 0, stop_pos
;
16053 struct text_pos start_pos
;
16055 int first_unchanged_at_end_vpos
= 0;
16056 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
16057 struct text_pos start
;
16058 EMACS_INT first_changed_charpos
, last_changed_charpos
;
16061 if (inhibit_try_window_id
)
16065 /* This is handy for debugging. */
16067 #define GIVE_UP(X) \
16069 fprintf (stderr, "try_window_id give up %d\n", (X)); \
16073 #define GIVE_UP(X) return 0
16076 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
16078 /* Don't use this for mini-windows because these can show
16079 messages and mini-buffers, and we don't handle that here. */
16080 if (MINI_WINDOW_P (w
))
16083 /* This flag is used to prevent redisplay optimizations. */
16084 if (windows_or_buffers_changed
|| cursor_type_changed
)
16087 /* Verify that narrowing has not changed.
16088 Also verify that we were not told to prevent redisplay optimizations.
16089 It would be nice to further
16090 reduce the number of cases where this prevents try_window_id. */
16091 if (current_buffer
->clip_changed
16092 || current_buffer
->prevent_redisplay_optimizations_p
)
16095 /* Window must either use window-based redisplay or be full width. */
16096 if (!FRAME_WINDOW_P (f
)
16097 && (!FRAME_LINE_INS_DEL_OK (f
)
16098 || !WINDOW_FULL_WIDTH_P (w
)))
16101 /* Give up if point is known NOT to appear in W. */
16102 if (PT
< CHARPOS (start
))
16105 /* Another way to prevent redisplay optimizations. */
16106 if (XFASTINT (w
->last_modified
) == 0)
16109 /* Verify that window is not hscrolled. */
16110 if (XFASTINT (w
->hscroll
) != 0)
16113 /* Verify that display wasn't paused. */
16114 if (NILP (w
->window_end_valid
))
16117 /* Can't use this if highlighting a region because a cursor movement
16118 will do more than just set the cursor. */
16119 if (!NILP (Vtransient_mark_mode
)
16120 && !NILP (BVAR (current_buffer
, mark_active
)))
16123 /* Likewise if highlighting trailing whitespace. */
16124 if (!NILP (Vshow_trailing_whitespace
))
16127 /* Likewise if showing a region. */
16128 if (!NILP (w
->region_showing
))
16131 /* Can't use this if overlay arrow position and/or string have
16133 if (overlay_arrows_changed_p ())
16136 /* When word-wrap is on, adding a space to the first word of a
16137 wrapped line can change the wrap position, altering the line
16138 above it. It might be worthwhile to handle this more
16139 intelligently, but for now just redisplay from scratch. */
16140 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
16143 /* Under bidi reordering, adding or deleting a character in the
16144 beginning of a paragraph, before the first strong directional
16145 character, can change the base direction of the paragraph (unless
16146 the buffer specifies a fixed paragraph direction), which will
16147 require to redisplay the whole paragraph. It might be worthwhile
16148 to find the paragraph limits and widen the range of redisplayed
16149 lines to that, but for now just give up this optimization and
16150 redisplay from scratch. */
16151 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16152 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
16155 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
16156 only if buffer has really changed. The reason is that the gap is
16157 initially at Z for freshly visited files. The code below would
16158 set end_unchanged to 0 in that case. */
16159 if (MODIFF
> SAVE_MODIFF
16160 /* This seems to happen sometimes after saving a buffer. */
16161 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
16163 if (GPT
- BEG
< BEG_UNCHANGED
)
16164 BEG_UNCHANGED
= GPT
- BEG
;
16165 if (Z
- GPT
< END_UNCHANGED
)
16166 END_UNCHANGED
= Z
- GPT
;
16169 /* The position of the first and last character that has been changed. */
16170 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
16171 last_changed_charpos
= Z
- END_UNCHANGED
;
16173 /* If window starts after a line end, and the last change is in
16174 front of that newline, then changes don't affect the display.
16175 This case happens with stealth-fontification. Note that although
16176 the display is unchanged, glyph positions in the matrix have to
16177 be adjusted, of course. */
16178 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16179 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16180 && ((last_changed_charpos
< CHARPOS (start
)
16181 && CHARPOS (start
) == BEGV
)
16182 || (last_changed_charpos
< CHARPOS (start
) - 1
16183 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
16185 EMACS_INT Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
16186 struct glyph_row
*r0
;
16188 /* Compute how many chars/bytes have been added to or removed
16189 from the buffer. */
16190 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16191 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16192 Z_delta
= Z
- Z_old
;
16193 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16195 /* Give up if PT is not in the window. Note that it already has
16196 been checked at the start of try_window_id that PT is not in
16197 front of the window start. */
16198 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
16201 /* If window start is unchanged, we can reuse the whole matrix
16202 as is, after adjusting glyph positions. No need to compute
16203 the window end again, since its offset from Z hasn't changed. */
16204 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16205 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
16206 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
16207 /* PT must not be in a partially visible line. */
16208 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
16209 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
16211 /* Adjust positions in the glyph matrix. */
16212 if (Z_delta
|| Z_delta_bytes
)
16214 struct glyph_row
*r1
16215 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16216 increment_matrix_positions (w
->current_matrix
,
16217 MATRIX_ROW_VPOS (r0
, current_matrix
),
16218 MATRIX_ROW_VPOS (r1
, current_matrix
),
16219 Z_delta
, Z_delta_bytes
);
16222 /* Set the cursor. */
16223 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
16225 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
16232 /* Handle the case that changes are all below what is displayed in
16233 the window, and that PT is in the window. This shortcut cannot
16234 be taken if ZV is visible in the window, and text has been added
16235 there that is visible in the window. */
16236 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
16237 /* ZV is not visible in the window, or there are no
16238 changes at ZV, actually. */
16239 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
16240 || first_changed_charpos
== last_changed_charpos
))
16242 struct glyph_row
*r0
;
16244 /* Give up if PT is not in the window. Note that it already has
16245 been checked at the start of try_window_id that PT is not in
16246 front of the window start. */
16247 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
16250 /* If window start is unchanged, we can reuse the whole matrix
16251 as is, without changing glyph positions since no text has
16252 been added/removed in front of the window end. */
16253 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16254 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
16255 /* PT must not be in a partially visible line. */
16256 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
16257 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
16259 /* We have to compute the window end anew since text
16260 could have been added/removed after it. */
16262 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16263 w
->window_end_bytepos
16264 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16266 /* Set the cursor. */
16267 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
16269 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
16276 /* Give up if window start is in the changed area.
16278 The condition used to read
16280 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
16282 but why that was tested escapes me at the moment. */
16283 if (CHARPOS (start
) >= first_changed_charpos
16284 && CHARPOS (start
) <= last_changed_charpos
)
16287 /* Check that window start agrees with the start of the first glyph
16288 row in its current matrix. Check this after we know the window
16289 start is not in changed text, otherwise positions would not be
16291 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16292 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
16295 /* Give up if the window ends in strings. Overlay strings
16296 at the end are difficult to handle, so don't try. */
16297 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
16298 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
16301 /* Compute the position at which we have to start displaying new
16302 lines. Some of the lines at the top of the window might be
16303 reusable because they are not displaying changed text. Find the
16304 last row in W's current matrix not affected by changes at the
16305 start of current_buffer. Value is null if changes start in the
16306 first line of window. */
16307 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
16308 if (last_unchanged_at_beg_row
)
16310 /* Avoid starting to display in the moddle of a character, a TAB
16311 for instance. This is easier than to set up the iterator
16312 exactly, and it's not a frequent case, so the additional
16313 effort wouldn't really pay off. */
16314 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
16315 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
16316 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
16317 --last_unchanged_at_beg_row
;
16319 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
16322 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
16324 start_pos
= it
.current
.pos
;
16326 /* Start displaying new lines in the desired matrix at the same
16327 vpos we would use in the current matrix, i.e. below
16328 last_unchanged_at_beg_row. */
16329 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
16331 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16332 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
16334 xassert (it
.hpos
== 0 && it
.current_x
== 0);
16338 /* There are no reusable lines at the start of the window.
16339 Start displaying in the first text line. */
16340 start_display (&it
, w
, start
);
16341 it
.vpos
= it
.first_vpos
;
16342 start_pos
= it
.current
.pos
;
16345 /* Find the first row that is not affected by changes at the end of
16346 the buffer. Value will be null if there is no unchanged row, in
16347 which case we must redisplay to the end of the window. delta
16348 will be set to the value by which buffer positions beginning with
16349 first_unchanged_at_end_row have to be adjusted due to text
16351 first_unchanged_at_end_row
16352 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
16353 IF_DEBUG (debug_delta
= delta
);
16354 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
16356 /* Set stop_pos to the buffer position up to which we will have to
16357 display new lines. If first_unchanged_at_end_row != NULL, this
16358 is the buffer position of the start of the line displayed in that
16359 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
16360 that we don't stop at a buffer position. */
16362 if (first_unchanged_at_end_row
)
16364 xassert (last_unchanged_at_beg_row
== NULL
16365 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
16367 /* If this is a continuation line, move forward to the next one
16368 that isn't. Changes in lines above affect this line.
16369 Caution: this may move first_unchanged_at_end_row to a row
16370 not displaying text. */
16371 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
16372 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
16373 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
16374 < it
.last_visible_y
))
16375 ++first_unchanged_at_end_row
;
16377 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
16378 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
16379 >= it
.last_visible_y
))
16380 first_unchanged_at_end_row
= NULL
;
16383 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
16385 first_unchanged_at_end_vpos
16386 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
16387 xassert (stop_pos
>= Z
- END_UNCHANGED
);
16390 else if (last_unchanged_at_beg_row
== NULL
)
16396 /* Either there is no unchanged row at the end, or the one we have
16397 now displays text. This is a necessary condition for the window
16398 end pos calculation at the end of this function. */
16399 xassert (first_unchanged_at_end_row
== NULL
16400 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
16402 debug_last_unchanged_at_beg_vpos
16403 = (last_unchanged_at_beg_row
16404 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
16406 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
16408 #endif /* GLYPH_DEBUG != 0 */
16411 /* Display new lines. Set last_text_row to the last new line
16412 displayed which has text on it, i.e. might end up as being the
16413 line where the window_end_vpos is. */
16414 w
->cursor
.vpos
= -1;
16415 last_text_row
= NULL
;
16416 overlay_arrow_seen
= 0;
16417 while (it
.current_y
< it
.last_visible_y
16418 && !fonts_changed_p
16419 && (first_unchanged_at_end_row
== NULL
16420 || IT_CHARPOS (it
) < stop_pos
))
16422 if (display_line (&it
))
16423 last_text_row
= it
.glyph_row
- 1;
16426 if (fonts_changed_p
)
16430 /* Compute differences in buffer positions, y-positions etc. for
16431 lines reused at the bottom of the window. Compute what we can
16433 if (first_unchanged_at_end_row
16434 /* No lines reused because we displayed everything up to the
16435 bottom of the window. */
16436 && it
.current_y
< it
.last_visible_y
)
16439 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
16441 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
16442 run
.current_y
= first_unchanged_at_end_row
->y
;
16443 run
.desired_y
= run
.current_y
+ dy
;
16444 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
16448 delta
= delta_bytes
= dvpos
= dy
16449 = run
.current_y
= run
.desired_y
= run
.height
= 0;
16450 first_unchanged_at_end_row
= NULL
;
16452 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
16455 /* Find the cursor if not already found. We have to decide whether
16456 PT will appear on this window (it sometimes doesn't, but this is
16457 not a very frequent case.) This decision has to be made before
16458 the current matrix is altered. A value of cursor.vpos < 0 means
16459 that PT is either in one of the lines beginning at
16460 first_unchanged_at_end_row or below the window. Don't care for
16461 lines that might be displayed later at the window end; as
16462 mentioned, this is not a frequent case. */
16463 if (w
->cursor
.vpos
< 0)
16465 /* Cursor in unchanged rows at the top? */
16466 if (PT
< CHARPOS (start_pos
)
16467 && last_unchanged_at_beg_row
)
16469 row
= row_containing_pos (w
, PT
,
16470 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
16471 last_unchanged_at_beg_row
+ 1, 0);
16473 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16476 /* Start from first_unchanged_at_end_row looking for PT. */
16477 else if (first_unchanged_at_end_row
)
16479 row
= row_containing_pos (w
, PT
- delta
,
16480 first_unchanged_at_end_row
, NULL
, 0);
16482 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
16483 delta_bytes
, dy
, dvpos
);
16486 /* Give up if cursor was not found. */
16487 if (w
->cursor
.vpos
< 0)
16489 clear_glyph_matrix (w
->desired_matrix
);
16494 /* Don't let the cursor end in the scroll margins. */
16496 int this_scroll_margin
, cursor_height
;
16498 this_scroll_margin
= max (0, scroll_margin
);
16499 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16500 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
16501 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
16503 if ((w
->cursor
.y
< this_scroll_margin
16504 && CHARPOS (start
) > BEGV
)
16505 /* Old redisplay didn't take scroll margin into account at the bottom,
16506 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
16507 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
16508 ? cursor_height
+ this_scroll_margin
16509 : 1)) > it
.last_visible_y
)
16511 w
->cursor
.vpos
= -1;
16512 clear_glyph_matrix (w
->desired_matrix
);
16517 /* Scroll the display. Do it before changing the current matrix so
16518 that xterm.c doesn't get confused about where the cursor glyph is
16520 if (dy
&& run
.height
)
16524 if (FRAME_WINDOW_P (f
))
16526 FRAME_RIF (f
)->update_window_begin_hook (w
);
16527 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16528 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16529 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16533 /* Terminal frame. In this case, dvpos gives the number of
16534 lines to scroll by; dvpos < 0 means scroll up. */
16536 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
16537 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
16538 int end
= (WINDOW_TOP_EDGE_LINE (w
)
16539 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
16540 + window_internal_height (w
));
16542 #if defined (HAVE_GPM) || defined (MSDOS)
16543 x_clear_window_mouse_face (w
);
16545 /* Perform the operation on the screen. */
16548 /* Scroll last_unchanged_at_beg_row to the end of the
16549 window down dvpos lines. */
16550 set_terminal_window (f
, end
);
16552 /* On dumb terminals delete dvpos lines at the end
16553 before inserting dvpos empty lines. */
16554 if (!FRAME_SCROLL_REGION_OK (f
))
16555 ins_del_lines (f
, end
- dvpos
, -dvpos
);
16557 /* Insert dvpos empty lines in front of
16558 last_unchanged_at_beg_row. */
16559 ins_del_lines (f
, from
, dvpos
);
16561 else if (dvpos
< 0)
16563 /* Scroll up last_unchanged_at_beg_vpos to the end of
16564 the window to last_unchanged_at_beg_vpos - |dvpos|. */
16565 set_terminal_window (f
, end
);
16567 /* Delete dvpos lines in front of
16568 last_unchanged_at_beg_vpos. ins_del_lines will set
16569 the cursor to the given vpos and emit |dvpos| delete
16571 ins_del_lines (f
, from
+ dvpos
, dvpos
);
16573 /* On a dumb terminal insert dvpos empty lines at the
16575 if (!FRAME_SCROLL_REGION_OK (f
))
16576 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
16579 set_terminal_window (f
, 0);
16585 /* Shift reused rows of the current matrix to the right position.
16586 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
16588 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16589 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
16592 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
16593 bottom_vpos
, dvpos
);
16594 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
16597 else if (dvpos
> 0)
16599 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
16600 bottom_vpos
, dvpos
);
16601 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
16602 first_unchanged_at_end_vpos
+ dvpos
, 0);
16605 /* For frame-based redisplay, make sure that current frame and window
16606 matrix are in sync with respect to glyph memory. */
16607 if (!FRAME_WINDOW_P (f
))
16608 sync_frame_with_window_matrix_rows (w
);
16610 /* Adjust buffer positions in reused rows. */
16611 if (delta
|| delta_bytes
)
16612 increment_matrix_positions (current_matrix
,
16613 first_unchanged_at_end_vpos
+ dvpos
,
16614 bottom_vpos
, delta
, delta_bytes
);
16616 /* Adjust Y positions. */
16618 shift_glyph_matrix (w
, current_matrix
,
16619 first_unchanged_at_end_vpos
+ dvpos
,
16622 if (first_unchanged_at_end_row
)
16624 first_unchanged_at_end_row
+= dvpos
;
16625 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16626 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16627 first_unchanged_at_end_row
= NULL
;
16630 /* If scrolling up, there may be some lines to display at the end of
16632 last_text_row_at_end
= NULL
;
16635 /* Scrolling up can leave for example a partially visible line
16636 at the end of the window to be redisplayed. */
16637 /* Set last_row to the glyph row in the current matrix where the
16638 window end line is found. It has been moved up or down in
16639 the matrix by dvpos. */
16640 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16641 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16643 /* If last_row is the window end line, it should display text. */
16644 xassert (last_row
->displays_text_p
);
16646 /* If window end line was partially visible before, begin
16647 displaying at that line. Otherwise begin displaying with the
16648 line following it. */
16649 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16651 init_to_row_start (&it
, w
, last_row
);
16652 it
.vpos
= last_vpos
;
16653 it
.current_y
= last_row
->y
;
16657 init_to_row_end (&it
, w
, last_row
);
16658 it
.vpos
= 1 + last_vpos
;
16659 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16663 /* We may start in a continuation line. If so, we have to
16664 get the right continuation_lines_width and current_x. */
16665 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16666 it
.hpos
= it
.current_x
= 0;
16668 /* Display the rest of the lines at the window end. */
16669 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16670 while (it
.current_y
< it
.last_visible_y
16671 && !fonts_changed_p
)
16673 /* Is it always sure that the display agrees with lines in
16674 the current matrix? I don't think so, so we mark rows
16675 displayed invalid in the current matrix by setting their
16676 enabled_p flag to zero. */
16677 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16678 if (display_line (&it
))
16679 last_text_row_at_end
= it
.glyph_row
- 1;
16683 /* Update window_end_pos and window_end_vpos. */
16684 if (first_unchanged_at_end_row
16685 && !last_text_row_at_end
)
16687 /* Window end line if one of the preserved rows from the current
16688 matrix. Set row to the last row displaying text in current
16689 matrix starting at first_unchanged_at_end_row, after
16691 xassert (first_unchanged_at_end_row
->displays_text_p
);
16692 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16693 first_unchanged_at_end_row
);
16694 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16696 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16697 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16699 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16700 xassert (w
->window_end_bytepos
>= 0);
16701 IF_DEBUG (debug_method_add (w
, "A"));
16703 else if (last_text_row_at_end
)
16706 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16707 w
->window_end_bytepos
16708 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16710 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16711 xassert (w
->window_end_bytepos
>= 0);
16712 IF_DEBUG (debug_method_add (w
, "B"));
16714 else if (last_text_row
)
16716 /* We have displayed either to the end of the window or at the
16717 end of the window, i.e. the last row with text is to be found
16718 in the desired matrix. */
16720 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16721 w
->window_end_bytepos
16722 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16724 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16725 xassert (w
->window_end_bytepos
>= 0);
16727 else if (first_unchanged_at_end_row
== NULL
16728 && last_text_row
== NULL
16729 && last_text_row_at_end
== NULL
)
16731 /* Displayed to end of window, but no line containing text was
16732 displayed. Lines were deleted at the end of the window. */
16733 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16734 int vpos
= XFASTINT (w
->window_end_vpos
);
16735 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16736 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16739 row
== NULL
&& vpos
>= first_vpos
;
16740 --vpos
, --current_row
, --desired_row
)
16742 if (desired_row
->enabled_p
)
16744 if (desired_row
->displays_text_p
)
16747 else if (current_row
->displays_text_p
)
16751 xassert (row
!= NULL
);
16752 w
->window_end_vpos
= make_number (vpos
+ 1);
16753 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16754 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16755 xassert (w
->window_end_bytepos
>= 0);
16756 IF_DEBUG (debug_method_add (w
, "C"));
16761 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16762 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16764 /* Record that display has not been completed. */
16765 w
->window_end_valid
= Qnil
;
16766 w
->desired_matrix
->no_scrolling_p
= 1;
16774 /***********************************************************************
16775 More debugging support
16776 ***********************************************************************/
16780 void dump_glyph_row (struct glyph_row
*, int, int);
16781 void dump_glyph_matrix (struct glyph_matrix
*, int);
16782 void dump_glyph (struct glyph_row
*, struct glyph
*, int);
16785 /* Dump the contents of glyph matrix MATRIX on stderr.
16787 GLYPHS 0 means don't show glyph contents.
16788 GLYPHS 1 means show glyphs in short form
16789 GLYPHS > 1 means show glyphs in long form. */
16792 dump_glyph_matrix (matrix
, glyphs
)
16793 struct glyph_matrix
*matrix
;
16797 for (i
= 0; i
< matrix
->nrows
; ++i
)
16798 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16802 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16803 the glyph row and area where the glyph comes from. */
16806 dump_glyph (row
, glyph
, area
)
16807 struct glyph_row
*row
;
16808 struct glyph
*glyph
;
16811 if (glyph
->type
== CHAR_GLYPH
)
16814 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16815 glyph
- row
->glyphs
[TEXT_AREA
],
16818 (BUFFERP (glyph
->object
)
16820 : (STRINGP (glyph
->object
)
16823 glyph
->pixel_width
,
16825 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16829 glyph
->left_box_line_p
,
16830 glyph
->right_box_line_p
);
16832 else if (glyph
->type
== STRETCH_GLYPH
)
16835 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16836 glyph
- row
->glyphs
[TEXT_AREA
],
16839 (BUFFERP (glyph
->object
)
16841 : (STRINGP (glyph
->object
)
16844 glyph
->pixel_width
,
16848 glyph
->left_box_line_p
,
16849 glyph
->right_box_line_p
);
16851 else if (glyph
->type
== IMAGE_GLYPH
)
16854 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16855 glyph
- row
->glyphs
[TEXT_AREA
],
16858 (BUFFERP (glyph
->object
)
16860 : (STRINGP (glyph
->object
)
16863 glyph
->pixel_width
,
16867 glyph
->left_box_line_p
,
16868 glyph
->right_box_line_p
);
16870 else if (glyph
->type
== COMPOSITE_GLYPH
)
16873 " %5d %4c %6d %c %3d 0x%05x",
16874 glyph
- row
->glyphs
[TEXT_AREA
],
16877 (BUFFERP (glyph
->object
)
16879 : (STRINGP (glyph
->object
)
16882 glyph
->pixel_width
,
16884 if (glyph
->u
.cmp
.automatic
)
16887 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
16888 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16890 glyph
->left_box_line_p
,
16891 glyph
->right_box_line_p
);
16896 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16897 GLYPHS 0 means don't show glyph contents.
16898 GLYPHS 1 means show glyphs in short form
16899 GLYPHS > 1 means show glyphs in long form. */
16902 dump_glyph_row (row
, vpos
, glyphs
)
16903 struct glyph_row
*row
;
16908 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16909 fprintf (stderr
, "======================================================================\n");
16911 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16912 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16914 MATRIX_ROW_START_CHARPOS (row
),
16915 MATRIX_ROW_END_CHARPOS (row
),
16916 row
->used
[TEXT_AREA
],
16917 row
->contains_overlapping_glyphs_p
,
16919 row
->truncated_on_left_p
,
16920 row
->truncated_on_right_p
,
16922 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16923 row
->displays_text_p
,
16926 row
->ends_in_middle_of_char_p
,
16927 row
->starts_in_middle_of_char_p
,
16933 row
->visible_height
,
16936 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16937 row
->end
.overlay_string_index
,
16938 row
->continuation_lines_width
);
16939 fprintf (stderr
, "%9d %5d\n",
16940 CHARPOS (row
->start
.string_pos
),
16941 CHARPOS (row
->end
.string_pos
));
16942 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16943 row
->end
.dpvec_index
);
16950 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16952 struct glyph
*glyph
= row
->glyphs
[area
];
16953 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16955 /* Glyph for a line end in text. */
16956 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16959 if (glyph
< glyph_end
)
16960 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16962 for (; glyph
< glyph_end
; ++glyph
)
16963 dump_glyph (row
, glyph
, area
);
16966 else if (glyphs
== 1)
16970 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16972 char *s
= (char *) alloca (row
->used
[area
] + 1);
16975 for (i
= 0; i
< row
->used
[area
]; ++i
)
16977 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16978 if (glyph
->type
== CHAR_GLYPH
16979 && glyph
->u
.ch
< 0x80
16980 && glyph
->u
.ch
>= ' ')
16981 s
[i
] = glyph
->u
.ch
;
16987 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16993 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16994 Sdump_glyph_matrix
, 0, 1, "p",
16995 doc
: /* Dump the current matrix of the selected window to stderr.
16996 Shows contents of glyph row structures. With non-nil
16997 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16998 glyphs in short form, otherwise show glyphs in long form. */)
16999 (Lisp_Object glyphs
)
17001 struct window
*w
= XWINDOW (selected_window
);
17002 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17004 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
17005 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
17006 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
17007 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
17008 fprintf (stderr
, "=============================================\n");
17009 dump_glyph_matrix (w
->current_matrix
,
17010 NILP (glyphs
) ? 0 : XINT (glyphs
));
17015 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
17016 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
17019 struct frame
*f
= XFRAME (selected_frame
);
17020 dump_glyph_matrix (f
->current_matrix
, 1);
17025 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
17026 doc
: /* Dump glyph row ROW to stderr.
17027 GLYPH 0 means don't dump glyphs.
17028 GLYPH 1 means dump glyphs in short form.
17029 GLYPH > 1 or omitted means dump glyphs in long form. */)
17030 (Lisp_Object row
, Lisp_Object glyphs
)
17032 struct glyph_matrix
*matrix
;
17035 CHECK_NUMBER (row
);
17036 matrix
= XWINDOW (selected_window
)->current_matrix
;
17038 if (vpos
>= 0 && vpos
< matrix
->nrows
)
17039 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
17041 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
17046 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
17047 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
17048 GLYPH 0 means don't dump glyphs.
17049 GLYPH 1 means dump glyphs in short form.
17050 GLYPH > 1 or omitted means dump glyphs in long form. */)
17051 (Lisp_Object row
, Lisp_Object glyphs
)
17053 struct frame
*sf
= SELECTED_FRAME ();
17054 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
17057 CHECK_NUMBER (row
);
17059 if (vpos
>= 0 && vpos
< m
->nrows
)
17060 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
17061 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
17066 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
17067 doc
: /* Toggle tracing of redisplay.
17068 With ARG, turn tracing on if and only if ARG is positive. */)
17072 trace_redisplay_p
= !trace_redisplay_p
;
17075 arg
= Fprefix_numeric_value (arg
);
17076 trace_redisplay_p
= XINT (arg
) > 0;
17083 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
17084 doc
: /* Like `format', but print result to stderr.
17085 usage: (trace-to-stderr STRING &rest OBJECTS) */)
17086 (size_t nargs
, Lisp_Object
*args
)
17088 Lisp_Object s
= Fformat (nargs
, args
);
17089 fprintf (stderr
, "%s", SDATA (s
));
17093 #endif /* GLYPH_DEBUG */
17097 /***********************************************************************
17098 Building Desired Matrix Rows
17099 ***********************************************************************/
17101 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
17102 Used for non-window-redisplay windows, and for windows w/o left fringe. */
17104 static struct glyph_row
*
17105 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
17107 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17108 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17109 struct buffer
*old
= current_buffer
;
17110 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
17111 int arrow_len
= SCHARS (overlay_arrow_string
);
17112 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
17113 const unsigned char *p
;
17116 int n_glyphs_before
;
17118 set_buffer_temp (buffer
);
17119 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
17120 it
.glyph_row
->used
[TEXT_AREA
] = 0;
17121 SET_TEXT_POS (it
.position
, 0, 0);
17123 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
17125 while (p
< arrow_end
)
17127 Lisp_Object face
, ilisp
;
17129 /* Get the next character. */
17131 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
17134 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
17135 if (! ASCII_CHAR_P (it
.c
))
17136 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
17140 /* Get its face. */
17141 ilisp
= make_number (p
- arrow_string
);
17142 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
17143 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
17145 /* Compute its width, get its glyphs. */
17146 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
17147 SET_TEXT_POS (it
.position
, -1, -1);
17148 PRODUCE_GLYPHS (&it
);
17150 /* If this character doesn't fit any more in the line, we have
17151 to remove some glyphs. */
17152 if (it
.current_x
> it
.last_visible_x
)
17154 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17159 set_buffer_temp (old
);
17160 return it
.glyph_row
;
17164 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
17165 glyphs are only inserted for terminal frames since we can't really
17166 win with truncation glyphs when partially visible glyphs are
17167 involved. Which glyphs to insert is determined by
17168 produce_special_glyphs. */
17171 insert_left_trunc_glyphs (struct it
*it
)
17173 struct it truncate_it
;
17174 struct glyph
*from
, *end
, *to
, *toend
;
17176 xassert (!FRAME_WINDOW_P (it
->f
));
17178 /* Get the truncation glyphs. */
17180 truncate_it
.current_x
= 0;
17181 truncate_it
.face_id
= DEFAULT_FACE_ID
;
17182 truncate_it
.glyph_row
= &scratch_glyph_row
;
17183 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
17184 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
17185 truncate_it
.object
= make_number (0);
17186 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
17188 /* Overwrite glyphs from IT with truncation glyphs. */
17189 if (!it
->glyph_row
->reversed_p
)
17191 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17192 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
17193 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17194 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
17199 /* There may be padding glyphs left over. Overwrite them too. */
17200 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
17202 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17208 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
17212 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
17213 that back to front. */
17214 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17215 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17216 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17217 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17219 while (from
>= end
&& to
>= toend
)
17221 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
17224 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
17225 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17226 while (from
>= end
&& to
>= toend
)
17231 /* Need to free some room before prepending additional
17233 int move_by
= from
- end
+ 1;
17234 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17235 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17237 for ( ; g
>= g0
; g
--)
17239 while (from
>= end
)
17241 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
17247 /* Compute the pixel height and width of IT->glyph_row.
17249 Most of the time, ascent and height of a display line will be equal
17250 to the max_ascent and max_height values of the display iterator
17251 structure. This is not the case if
17253 1. We hit ZV without displaying anything. In this case, max_ascent
17254 and max_height will be zero.
17256 2. We have some glyphs that don't contribute to the line height.
17257 (The glyph row flag contributes_to_line_height_p is for future
17258 pixmap extensions).
17260 The first case is easily covered by using default values because in
17261 these cases, the line height does not really matter, except that it
17262 must not be zero. */
17265 compute_line_metrics (struct it
*it
)
17267 struct glyph_row
*row
= it
->glyph_row
;
17269 if (FRAME_WINDOW_P (it
->f
))
17271 int i
, min_y
, max_y
;
17273 /* The line may consist of one space only, that was added to
17274 place the cursor on it. If so, the row's height hasn't been
17276 if (row
->height
== 0)
17278 if (it
->max_ascent
+ it
->max_descent
== 0)
17279 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
17280 row
->ascent
= it
->max_ascent
;
17281 row
->height
= it
->max_ascent
+ it
->max_descent
;
17282 row
->phys_ascent
= it
->max_phys_ascent
;
17283 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17284 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17287 /* Compute the width of this line. */
17288 row
->pixel_width
= row
->x
;
17289 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
17290 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
17292 xassert (row
->pixel_width
>= 0);
17293 xassert (row
->ascent
>= 0 && row
->height
> 0);
17295 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
17296 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
17298 /* If first line's physical ascent is larger than its logical
17299 ascent, use the physical ascent, and make the row taller.
17300 This makes accented characters fully visible. */
17301 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
17302 && row
->phys_ascent
> row
->ascent
)
17304 row
->height
+= row
->phys_ascent
- row
->ascent
;
17305 row
->ascent
= row
->phys_ascent
;
17308 /* Compute how much of the line is visible. */
17309 row
->visible_height
= row
->height
;
17311 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
17312 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
17314 if (row
->y
< min_y
)
17315 row
->visible_height
-= min_y
- row
->y
;
17316 if (row
->y
+ row
->height
> max_y
)
17317 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17321 row
->pixel_width
= row
->used
[TEXT_AREA
];
17322 if (row
->continued_p
)
17323 row
->pixel_width
-= it
->continuation_pixel_width
;
17324 else if (row
->truncated_on_right_p
)
17325 row
->pixel_width
-= it
->truncation_pixel_width
;
17326 row
->ascent
= row
->phys_ascent
= 0;
17327 row
->height
= row
->phys_height
= row
->visible_height
= 1;
17328 row
->extra_line_spacing
= 0;
17331 /* Compute a hash code for this row. */
17335 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17336 for (i
= 0; i
< row
->used
[area
]; ++i
)
17337 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
17338 + row
->glyphs
[area
][i
].u
.val
17339 + row
->glyphs
[area
][i
].face_id
17340 + row
->glyphs
[area
][i
].padding_p
17341 + (row
->glyphs
[area
][i
].type
<< 2));
17344 it
->max_ascent
= it
->max_descent
= 0;
17345 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
17349 /* Append one space to the glyph row of iterator IT if doing a
17350 window-based redisplay. The space has the same face as
17351 IT->face_id. Value is non-zero if a space was added.
17353 This function is called to make sure that there is always one glyph
17354 at the end of a glyph row that the cursor can be set on under
17355 window-systems. (If there weren't such a glyph we would not know
17356 how wide and tall a box cursor should be displayed).
17358 At the same time this space let's a nicely handle clearing to the
17359 end of the line if the row ends in italic text. */
17362 append_space_for_newline (struct it
*it
, int default_face_p
)
17364 if (FRAME_WINDOW_P (it
->f
))
17366 int n
= it
->glyph_row
->used
[TEXT_AREA
];
17368 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
17369 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
17371 /* Save some values that must not be changed.
17372 Must save IT->c and IT->len because otherwise
17373 ITERATOR_AT_END_P wouldn't work anymore after
17374 append_space_for_newline has been called. */
17375 enum display_element_type saved_what
= it
->what
;
17376 int saved_c
= it
->c
, saved_len
= it
->len
;
17377 int saved_char_to_display
= it
->char_to_display
;
17378 int saved_x
= it
->current_x
;
17379 int saved_face_id
= it
->face_id
;
17380 struct text_pos saved_pos
;
17381 Lisp_Object saved_object
;
17384 saved_object
= it
->object
;
17385 saved_pos
= it
->position
;
17387 it
->what
= IT_CHARACTER
;
17388 memset (&it
->position
, 0, sizeof it
->position
);
17389 it
->object
= make_number (0);
17390 it
->c
= it
->char_to_display
= ' ';
17393 if (default_face_p
)
17394 it
->face_id
= DEFAULT_FACE_ID
;
17395 else if (it
->face_before_selective_p
)
17396 it
->face_id
= it
->saved_face_id
;
17397 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17398 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
17400 PRODUCE_GLYPHS (it
);
17402 it
->override_ascent
= -1;
17403 it
->constrain_row_ascent_descent_p
= 0;
17404 it
->current_x
= saved_x
;
17405 it
->object
= saved_object
;
17406 it
->position
= saved_pos
;
17407 it
->what
= saved_what
;
17408 it
->face_id
= saved_face_id
;
17409 it
->len
= saved_len
;
17411 it
->char_to_display
= saved_char_to_display
;
17420 /* Extend the face of the last glyph in the text area of IT->glyph_row
17421 to the end of the display line. Called from display_line. If the
17422 glyph row is empty, add a space glyph to it so that we know the
17423 face to draw. Set the glyph row flag fill_line_p. If the glyph
17424 row is R2L, prepend a stretch glyph to cover the empty space to the
17425 left of the leftmost glyph. */
17428 extend_face_to_end_of_line (struct it
*it
)
17431 struct frame
*f
= it
->f
;
17433 /* If line is already filled, do nothing. Non window-system frames
17434 get a grace of one more ``pixel'' because their characters are
17435 1-``pixel'' wide, so they hit the equality too early. This grace
17436 is needed only for R2L rows that are not continued, to produce
17437 one extra blank where we could display the cursor. */
17438 if (it
->current_x
>= it
->last_visible_x
17439 + (!FRAME_WINDOW_P (f
)
17440 && it
->glyph_row
->reversed_p
17441 && !it
->glyph_row
->continued_p
))
17444 /* Face extension extends the background and box of IT->face_id
17445 to the end of the line. If the background equals the background
17446 of the frame, we don't have to do anything. */
17447 if (it
->face_before_selective_p
)
17448 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
17450 face
= FACE_FROM_ID (f
, it
->face_id
);
17452 if (FRAME_WINDOW_P (f
)
17453 && it
->glyph_row
->displays_text_p
17454 && face
->box
== FACE_NO_BOX
17455 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
17457 && !it
->glyph_row
->reversed_p
)
17460 /* Set the glyph row flag indicating that the face of the last glyph
17461 in the text area has to be drawn to the end of the text area. */
17462 it
->glyph_row
->fill_line_p
= 1;
17464 /* If current character of IT is not ASCII, make sure we have the
17465 ASCII face. This will be automatically undone the next time
17466 get_next_display_element returns a multibyte character. Note
17467 that the character will always be single byte in unibyte
17469 if (!ASCII_CHAR_P (it
->c
))
17471 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
17474 if (FRAME_WINDOW_P (f
))
17476 /* If the row is empty, add a space with the current face of IT,
17477 so that we know which face to draw. */
17478 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
17480 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
17481 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
17482 it
->glyph_row
->used
[TEXT_AREA
] = 1;
17484 #ifdef HAVE_WINDOW_SYSTEM
17485 if (it
->glyph_row
->reversed_p
)
17487 /* Prepend a stretch glyph to the row, such that the
17488 rightmost glyph will be drawn flushed all the way to the
17489 right margin of the window. The stretch glyph that will
17490 occupy the empty space, if any, to the left of the
17492 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
17493 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17494 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
17496 int row_width
, stretch_ascent
, stretch_width
;
17497 struct text_pos saved_pos
;
17498 int saved_face_id
, saved_avoid_cursor
;
17500 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
17501 row_width
+= g
->pixel_width
;
17502 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
17503 if (stretch_width
> 0)
17506 (((it
->ascent
+ it
->descent
)
17507 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
17508 saved_pos
= it
->position
;
17509 memset (&it
->position
, 0, sizeof it
->position
);
17510 saved_avoid_cursor
= it
->avoid_cursor_p
;
17511 it
->avoid_cursor_p
= 1;
17512 saved_face_id
= it
->face_id
;
17513 /* The last row's stretch glyph should get the default
17514 face, to avoid painting the rest of the window with
17515 the region face, if the region ends at ZV. */
17516 if (it
->glyph_row
->ends_at_zv_p
)
17517 it
->face_id
= DEFAULT_FACE_ID
;
17519 it
->face_id
= face
->id
;
17520 append_stretch_glyph (it
, make_number (0), stretch_width
,
17521 it
->ascent
+ it
->descent
, stretch_ascent
);
17522 it
->position
= saved_pos
;
17523 it
->avoid_cursor_p
= saved_avoid_cursor
;
17524 it
->face_id
= saved_face_id
;
17527 #endif /* HAVE_WINDOW_SYSTEM */
17531 /* Save some values that must not be changed. */
17532 int saved_x
= it
->current_x
;
17533 struct text_pos saved_pos
;
17534 Lisp_Object saved_object
;
17535 enum display_element_type saved_what
= it
->what
;
17536 int saved_face_id
= it
->face_id
;
17538 saved_object
= it
->object
;
17539 saved_pos
= it
->position
;
17541 it
->what
= IT_CHARACTER
;
17542 memset (&it
->position
, 0, sizeof it
->position
);
17543 it
->object
= make_number (0);
17544 it
->c
= it
->char_to_display
= ' ';
17546 /* The last row's blank glyphs should get the default face, to
17547 avoid painting the rest of the window with the region face,
17548 if the region ends at ZV. */
17549 if (it
->glyph_row
->ends_at_zv_p
)
17550 it
->face_id
= DEFAULT_FACE_ID
;
17552 it
->face_id
= face
->id
;
17554 PRODUCE_GLYPHS (it
);
17556 while (it
->current_x
<= it
->last_visible_x
)
17557 PRODUCE_GLYPHS (it
);
17559 /* Don't count these blanks really. It would let us insert a left
17560 truncation glyph below and make us set the cursor on them, maybe. */
17561 it
->current_x
= saved_x
;
17562 it
->object
= saved_object
;
17563 it
->position
= saved_pos
;
17564 it
->what
= saved_what
;
17565 it
->face_id
= saved_face_id
;
17570 /* Value is non-zero if text starting at CHARPOS in current_buffer is
17571 trailing whitespace. */
17574 trailing_whitespace_p (EMACS_INT charpos
)
17576 EMACS_INT bytepos
= CHAR_TO_BYTE (charpos
);
17579 while (bytepos
< ZV_BYTE
17580 && (c
= FETCH_CHAR (bytepos
),
17581 c
== ' ' || c
== '\t'))
17584 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
17586 if (bytepos
!= PT_BYTE
)
17593 /* Highlight trailing whitespace, if any, in ROW. */
17596 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
17598 int used
= row
->used
[TEXT_AREA
];
17602 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
17603 struct glyph
*glyph
= start
+ used
- 1;
17605 if (row
->reversed_p
)
17607 /* Right-to-left rows need to be processed in the opposite
17608 direction, so swap the edge pointers. */
17610 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
17613 /* Skip over glyphs inserted to display the cursor at the
17614 end of a line, for extending the face of the last glyph
17615 to the end of the line on terminals, and for truncation
17616 and continuation glyphs. */
17617 if (!row
->reversed_p
)
17619 while (glyph
>= start
17620 && glyph
->type
== CHAR_GLYPH
17621 && INTEGERP (glyph
->object
))
17626 while (glyph
<= start
17627 && glyph
->type
== CHAR_GLYPH
17628 && INTEGERP (glyph
->object
))
17632 /* If last glyph is a space or stretch, and it's trailing
17633 whitespace, set the face of all trailing whitespace glyphs in
17634 IT->glyph_row to `trailing-whitespace'. */
17635 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
17636 && BUFFERP (glyph
->object
)
17637 && (glyph
->type
== STRETCH_GLYPH
17638 || (glyph
->type
== CHAR_GLYPH
17639 && glyph
->u
.ch
== ' '))
17640 && trailing_whitespace_p (glyph
->charpos
))
17642 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
17646 if (!row
->reversed_p
)
17648 while (glyph
>= start
17649 && BUFFERP (glyph
->object
)
17650 && (glyph
->type
== STRETCH_GLYPH
17651 || (glyph
->type
== CHAR_GLYPH
17652 && glyph
->u
.ch
== ' ')))
17653 (glyph
--)->face_id
= face_id
;
17657 while (glyph
<= start
17658 && BUFFERP (glyph
->object
)
17659 && (glyph
->type
== STRETCH_GLYPH
17660 || (glyph
->type
== CHAR_GLYPH
17661 && glyph
->u
.ch
== ' ')))
17662 (glyph
++)->face_id
= face_id
;
17669 /* Value is non-zero if glyph row ROW should be
17670 used to hold the cursor. */
17673 cursor_row_p (struct glyph_row
*row
)
17677 if (PT
== CHARPOS (row
->end
.pos
))
17679 /* Suppose the row ends on a string.
17680 Unless the row is continued, that means it ends on a newline
17681 in the string. If it's anything other than a display string
17682 (e.g. a before-string from an overlay), we don't want the
17683 cursor there. (This heuristic seems to give the optimal
17684 behavior for the various types of multi-line strings.) */
17685 if (CHARPOS (row
->end
.string_pos
) >= 0)
17687 if (row
->continued_p
)
17691 /* Check for `display' property. */
17692 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17693 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17694 struct glyph
*glyph
;
17697 for (glyph
= end
; glyph
>= beg
; --glyph
)
17698 if (STRINGP (glyph
->object
))
17701 = Fget_char_property (make_number (PT
),
17705 && display_prop_string_p (prop
, glyph
->object
));
17710 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17712 /* If the row ends in middle of a real character,
17713 and the line is continued, we want the cursor here.
17714 That's because CHARPOS (ROW->end.pos) would equal
17715 PT if PT is before the character. */
17716 if (!row
->ends_in_ellipsis_p
)
17717 result
= row
->continued_p
;
17719 /* If the row ends in an ellipsis, then
17720 CHARPOS (ROW->end.pos) will equal point after the
17721 invisible text. We want that position to be displayed
17722 after the ellipsis. */
17725 /* If the row ends at ZV, display the cursor at the end of that
17726 row instead of at the start of the row below. */
17727 else if (row
->ends_at_zv_p
)
17738 /* Push the display property PROP so that it will be rendered at the
17739 current position in IT. Return 1 if PROP was successfully pushed,
17743 push_display_prop (struct it
*it
, Lisp_Object prop
)
17745 xassert (it
->method
== GET_FROM_BUFFER
);
17747 push_it (it
, NULL
);
17749 if (STRINGP (prop
))
17751 if (SCHARS (prop
) == 0)
17758 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17759 it
->current
.overlay_string_index
= -1;
17760 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17761 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17762 it
->method
= GET_FROM_STRING
;
17763 it
->stop_charpos
= 0;
17765 it
->base_level_stop
= 0;
17766 it
->string_from_display_prop_p
= 1;
17768 /* Force paragraph direction to be that of the parent
17770 it
->paragraph_embedding
= (it
->bidi_p
? it
->bidi_it
.paragraph_dir
: L2R
);
17772 /* Set up the bidi iterator for this display string. */
17775 it
->bidi_it
.string
.lstring
= it
->string
;
17776 it
->bidi_it
.string
.s
= NULL
;
17777 it
->bidi_it
.string
.schars
= it
->end_charpos
;
17778 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
17779 it
->bidi_it
.string
.from_disp_str
= 1;
17780 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
17781 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
17784 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17786 it
->method
= GET_FROM_STRETCH
;
17789 #ifdef HAVE_WINDOW_SYSTEM
17790 else if (IMAGEP (prop
))
17792 it
->what
= IT_IMAGE
;
17793 it
->image_id
= lookup_image (it
->f
, prop
);
17794 it
->method
= GET_FROM_IMAGE
;
17796 #endif /* HAVE_WINDOW_SYSTEM */
17799 pop_it (it
); /* bogus display property, give up */
17806 /* Return the character-property PROP at the current position in IT. */
17809 get_it_property (struct it
*it
, Lisp_Object prop
)
17811 Lisp_Object position
;
17813 if (STRINGP (it
->object
))
17814 position
= make_number (IT_STRING_CHARPOS (*it
));
17815 else if (BUFFERP (it
->object
))
17816 position
= make_number (IT_CHARPOS (*it
));
17820 return Fget_char_property (position
, prop
, it
->object
);
17823 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17826 handle_line_prefix (struct it
*it
)
17828 Lisp_Object prefix
;
17830 if (it
->continuation_lines_width
> 0)
17832 prefix
= get_it_property (it
, Qwrap_prefix
);
17834 prefix
= Vwrap_prefix
;
17838 prefix
= get_it_property (it
, Qline_prefix
);
17840 prefix
= Vline_prefix
;
17842 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17844 /* If the prefix is wider than the window, and we try to wrap
17845 it, it would acquire its own wrap prefix, and so on till the
17846 iterator stack overflows. So, don't wrap the prefix. */
17847 it
->line_wrap
= TRUNCATE
;
17848 it
->avoid_cursor_p
= 1;
17854 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
17855 only for R2L lines from display_line and display_string, when they
17856 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
17857 the line/string needs to be continued on the next glyph row. */
17859 unproduce_glyphs (struct it
*it
, int n
)
17861 struct glyph
*glyph
, *end
;
17863 xassert (it
->glyph_row
);
17864 xassert (it
->glyph_row
->reversed_p
);
17865 xassert (it
->area
== TEXT_AREA
);
17866 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
17868 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
17869 n
= it
->glyph_row
->used
[TEXT_AREA
];
17870 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
17871 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
17872 for ( ; glyph
< end
; glyph
++)
17873 glyph
[-n
] = *glyph
;
17876 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
17877 and ROW->maxpos. */
17879 find_row_edges (struct it
*it
, struct glyph_row
*row
,
17880 EMACS_INT min_pos
, EMACS_INT min_bpos
,
17881 EMACS_INT max_pos
, EMACS_INT max_bpos
)
17883 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17884 lines' rows is implemented for bidi-reordered rows. */
17886 /* ROW->minpos is the value of min_pos, the minimal buffer position
17889 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
17891 /* We didn't find _any_ valid buffer positions in any of the
17892 glyphs, so we must trust the iterator's computed positions. */
17893 row
->minpos
= row
->start
.pos
;
17896 max_pos
= CHARPOS (it
->current
.pos
);
17897 max_bpos
= BYTEPOS (it
->current
.pos
);
17900 /* Here are the various use-cases for ending the row, and the
17901 corresponding values for ROW->maxpos:
17903 Line ends in a newline from buffer eol_pos + 1
17904 Line is continued from buffer max_pos + 1
17905 Line is truncated on right it->current.pos
17906 Line ends in a newline from string max_pos
17907 Line is continued from string max_pos
17908 Line is continued from display vector max_pos
17909 Line is entirely from a string min_pos == max_pos
17910 Line is entirely from a display vector min_pos == max_pos
17911 Line that ends at ZV ZV
17913 If you discover other use-cases, please add them here as
17915 if (row
->ends_at_zv_p
)
17916 row
->maxpos
= it
->current
.pos
;
17917 else if (row
->used
[TEXT_AREA
])
17919 if (row
->ends_in_newline_from_string_p
)
17920 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17921 else if (CHARPOS (it
->eol_pos
) > 0)
17922 SET_TEXT_POS (row
->maxpos
,
17923 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
17924 else if (row
->continued_p
)
17926 /* If max_pos is different from IT's current position, it
17927 means IT->method does not belong to the display element
17928 at max_pos. However, it also means that the display
17929 element at max_pos was displayed in its entirety on this
17930 line, which is equivalent to saying that the next line
17931 starts at the next buffer position. */
17932 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
17933 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17936 INC_BOTH (max_pos
, max_bpos
);
17937 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17940 else if (row
->truncated_on_right_p
)
17941 /* display_line already called reseat_at_next_visible_line_start,
17942 which puts the iterator at the beginning of the next line, in
17943 the logical order. */
17944 row
->maxpos
= it
->current
.pos
;
17945 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
17946 /* A line that is entirely from a string/image/stretch... */
17947 row
->maxpos
= row
->minpos
;
17952 row
->maxpos
= it
->current
.pos
;
17955 /* Construct the glyph row IT->glyph_row in the desired matrix of
17956 IT->w from text at the current position of IT. See dispextern.h
17957 for an overview of struct it. Value is non-zero if
17958 IT->glyph_row displays text, as opposed to a line displaying ZV
17962 display_line (struct it
*it
)
17964 struct glyph_row
*row
= it
->glyph_row
;
17965 Lisp_Object overlay_arrow_string
;
17967 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
17968 int wrap_row_used
= -1;
17969 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
17970 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
17971 int wrap_row_extra_line_spacing
IF_LINT (= 0);
17972 EMACS_INT wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
17973 EMACS_INT wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
17975 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
17976 EMACS_INT min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
17978 /* We always start displaying at hpos zero even if hscrolled. */
17979 xassert (it
->hpos
== 0 && it
->current_x
== 0);
17981 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
17982 >= it
->w
->desired_matrix
->nrows
)
17984 it
->w
->nrows_scale_factor
++;
17985 fonts_changed_p
= 1;
17989 /* Is IT->w showing the region? */
17990 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
17992 /* Clear the result glyph row and enable it. */
17993 prepare_desired_row (row
);
17995 row
->y
= it
->current_y
;
17996 row
->start
= it
->start
;
17997 row
->continuation_lines_width
= it
->continuation_lines_width
;
17998 row
->displays_text_p
= 1;
17999 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
18000 it
->starts_in_middle_of_char_p
= 0;
18002 /* Arrange the overlays nicely for our purposes. Usually, we call
18003 display_line on only one line at a time, in which case this
18004 can't really hurt too much, or we call it on lines which appear
18005 one after another in the buffer, in which case all calls to
18006 recenter_overlay_lists but the first will be pretty cheap. */
18007 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
18009 /* Move over display elements that are not visible because we are
18010 hscrolled. This may stop at an x-position < IT->first_visible_x
18011 if the first glyph is partially visible or if we hit a line end. */
18012 if (it
->current_x
< it
->first_visible_x
)
18014 this_line_min_pos
= row
->start
.pos
;
18015 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
18016 MOVE_TO_POS
| MOVE_TO_X
);
18017 /* Record the smallest positions seen while we moved over
18018 display elements that are not visible. This is needed by
18019 redisplay_internal for optimizing the case where the cursor
18020 stays inside the same line. The rest of this function only
18021 considers positions that are actually displayed, so
18022 RECORD_MAX_MIN_POS will not otherwise record positions that
18023 are hscrolled to the left of the left edge of the window. */
18024 min_pos
= CHARPOS (this_line_min_pos
);
18025 min_bpos
= BYTEPOS (this_line_min_pos
);
18029 /* We only do this when not calling `move_it_in_display_line_to'
18030 above, because move_it_in_display_line_to calls
18031 handle_line_prefix itself. */
18032 handle_line_prefix (it
);
18035 /* Get the initial row height. This is either the height of the
18036 text hscrolled, if there is any, or zero. */
18037 row
->ascent
= it
->max_ascent
;
18038 row
->height
= it
->max_ascent
+ it
->max_descent
;
18039 row
->phys_ascent
= it
->max_phys_ascent
;
18040 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18041 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18043 /* Utility macro to record max and min buffer positions seen until now. */
18044 #define RECORD_MAX_MIN_POS(IT) \
18047 if (IT_CHARPOS (*(IT)) < min_pos) \
18049 min_pos = IT_CHARPOS (*(IT)); \
18050 min_bpos = IT_BYTEPOS (*(IT)); \
18052 if (IT_CHARPOS (*(IT)) > max_pos) \
18054 max_pos = IT_CHARPOS (*(IT)); \
18055 max_bpos = IT_BYTEPOS (*(IT)); \
18060 /* Loop generating characters. The loop is left with IT on the next
18061 character to display. */
18064 int n_glyphs_before
, hpos_before
, x_before
;
18066 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
18068 /* Retrieve the next thing to display. Value is zero if end of
18070 if (!get_next_display_element (it
))
18072 /* Maybe add a space at the end of this line that is used to
18073 display the cursor there under X. Set the charpos of the
18074 first glyph of blank lines not corresponding to any text
18076 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18077 row
->exact_window_width_line_p
= 1;
18078 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
18079 || row
->used
[TEXT_AREA
] == 0)
18081 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
18082 row
->displays_text_p
= 0;
18084 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
18085 && (!MINI_WINDOW_P (it
->w
)
18086 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
18087 row
->indicate_empty_line_p
= 1;
18090 it
->continuation_lines_width
= 0;
18091 row
->ends_at_zv_p
= 1;
18092 /* A row that displays right-to-left text must always have
18093 its last face extended all the way to the end of line,
18094 even if this row ends in ZV, because we still write to
18095 the screen left to right. */
18096 if (row
->reversed_p
)
18097 extend_face_to_end_of_line (it
);
18101 /* Now, get the metrics of what we want to display. This also
18102 generates glyphs in `row' (which is IT->glyph_row). */
18103 n_glyphs_before
= row
->used
[TEXT_AREA
];
18106 /* Remember the line height so far in case the next element doesn't
18107 fit on the line. */
18108 if (it
->line_wrap
!= TRUNCATE
)
18110 ascent
= it
->max_ascent
;
18111 descent
= it
->max_descent
;
18112 phys_ascent
= it
->max_phys_ascent
;
18113 phys_descent
= it
->max_phys_descent
;
18115 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
18117 if (IT_DISPLAYING_WHITESPACE (it
))
18123 wrap_row_used
= row
->used
[TEXT_AREA
];
18124 wrap_row_ascent
= row
->ascent
;
18125 wrap_row_height
= row
->height
;
18126 wrap_row_phys_ascent
= row
->phys_ascent
;
18127 wrap_row_phys_height
= row
->phys_height
;
18128 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
18129 wrap_row_min_pos
= min_pos
;
18130 wrap_row_min_bpos
= min_bpos
;
18131 wrap_row_max_pos
= max_pos
;
18132 wrap_row_max_bpos
= max_bpos
;
18138 PRODUCE_GLYPHS (it
);
18140 /* If this display element was in marginal areas, continue with
18142 if (it
->area
!= TEXT_AREA
)
18144 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18145 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18146 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18147 row
->phys_height
= max (row
->phys_height
,
18148 it
->max_phys_ascent
+ it
->max_phys_descent
);
18149 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18150 it
->max_extra_line_spacing
);
18151 set_iterator_to_next (it
, 1);
18155 /* Does the display element fit on the line? If we truncate
18156 lines, we should draw past the right edge of the window. If
18157 we don't truncate, we want to stop so that we can display the
18158 continuation glyph before the right margin. If lines are
18159 continued, there are two possible strategies for characters
18160 resulting in more than 1 glyph (e.g. tabs): Display as many
18161 glyphs as possible in this line and leave the rest for the
18162 continuation line, or display the whole element in the next
18163 line. Original redisplay did the former, so we do it also. */
18164 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
18165 hpos_before
= it
->hpos
;
18168 if (/* Not a newline. */
18170 /* Glyphs produced fit entirely in the line. */
18171 && it
->current_x
< it
->last_visible_x
)
18173 it
->hpos
+= nglyphs
;
18174 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18175 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18176 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18177 row
->phys_height
= max (row
->phys_height
,
18178 it
->max_phys_ascent
+ it
->max_phys_descent
);
18179 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18180 it
->max_extra_line_spacing
);
18181 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
18182 row
->x
= x
- it
->first_visible_x
;
18183 /* Record the maximum and minimum buffer positions seen so
18184 far in glyphs that will be displayed by this row. */
18186 RECORD_MAX_MIN_POS (it
);
18191 struct glyph
*glyph
;
18193 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
18195 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18196 new_x
= x
+ glyph
->pixel_width
;
18198 if (/* Lines are continued. */
18199 it
->line_wrap
!= TRUNCATE
18200 && (/* Glyph doesn't fit on the line. */
18201 new_x
> it
->last_visible_x
18202 /* Or it fits exactly on a window system frame. */
18203 || (new_x
== it
->last_visible_x
18204 && FRAME_WINDOW_P (it
->f
))))
18206 /* End of a continued line. */
18209 || (new_x
== it
->last_visible_x
18210 && FRAME_WINDOW_P (it
->f
)))
18212 /* Current glyph is the only one on the line or
18213 fits exactly on the line. We must continue
18214 the line because we can't draw the cursor
18215 after the glyph. */
18216 row
->continued_p
= 1;
18217 it
->current_x
= new_x
;
18218 it
->continuation_lines_width
+= new_x
;
18220 /* Record the maximum and minimum buffer
18221 positions seen so far in glyphs that will be
18222 displayed by this row. */
18224 RECORD_MAX_MIN_POS (it
);
18225 if (i
== nglyphs
- 1)
18227 /* If line-wrap is on, check if a previous
18228 wrap point was found. */
18229 if (wrap_row_used
> 0
18230 /* Even if there is a previous wrap
18231 point, continue the line here as
18232 usual, if (i) the previous character
18233 was a space or tab AND (ii) the
18234 current character is not. */
18236 || IT_DISPLAYING_WHITESPACE (it
)))
18239 set_iterator_to_next (it
, 1);
18240 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18242 if (!get_next_display_element (it
))
18244 row
->exact_window_width_line_p
= 1;
18245 it
->continuation_lines_width
= 0;
18246 row
->continued_p
= 0;
18247 row
->ends_at_zv_p
= 1;
18249 else if (ITERATOR_AT_END_OF_LINE_P (it
))
18251 row
->continued_p
= 0;
18252 row
->exact_window_width_line_p
= 1;
18257 else if (CHAR_GLYPH_PADDING_P (*glyph
)
18258 && !FRAME_WINDOW_P (it
->f
))
18260 /* A padding glyph that doesn't fit on this line.
18261 This means the whole character doesn't fit
18263 if (row
->reversed_p
)
18264 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
18265 - n_glyphs_before
);
18266 row
->used
[TEXT_AREA
] = n_glyphs_before
;
18268 /* Fill the rest of the row with continuation
18269 glyphs like in 20.x. */
18270 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
18271 < row
->glyphs
[1 + TEXT_AREA
])
18272 produce_special_glyphs (it
, IT_CONTINUATION
);
18274 row
->continued_p
= 1;
18275 it
->current_x
= x_before
;
18276 it
->continuation_lines_width
+= x_before
;
18278 /* Restore the height to what it was before the
18279 element not fitting on the line. */
18280 it
->max_ascent
= ascent
;
18281 it
->max_descent
= descent
;
18282 it
->max_phys_ascent
= phys_ascent
;
18283 it
->max_phys_descent
= phys_descent
;
18285 else if (wrap_row_used
> 0)
18288 if (row
->reversed_p
)
18289 unproduce_glyphs (it
,
18290 row
->used
[TEXT_AREA
] - wrap_row_used
);
18292 it
->continuation_lines_width
+= wrap_x
;
18293 row
->used
[TEXT_AREA
] = wrap_row_used
;
18294 row
->ascent
= wrap_row_ascent
;
18295 row
->height
= wrap_row_height
;
18296 row
->phys_ascent
= wrap_row_phys_ascent
;
18297 row
->phys_height
= wrap_row_phys_height
;
18298 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
18299 min_pos
= wrap_row_min_pos
;
18300 min_bpos
= wrap_row_min_bpos
;
18301 max_pos
= wrap_row_max_pos
;
18302 max_bpos
= wrap_row_max_bpos
;
18303 row
->continued_p
= 1;
18304 row
->ends_at_zv_p
= 0;
18305 row
->exact_window_width_line_p
= 0;
18306 it
->continuation_lines_width
+= x
;
18308 /* Make sure that a non-default face is extended
18309 up to the right margin of the window. */
18310 extend_face_to_end_of_line (it
);
18312 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
18314 /* A TAB that extends past the right edge of the
18315 window. This produces a single glyph on
18316 window system frames. We leave the glyph in
18317 this row and let it fill the row, but don't
18318 consume the TAB. */
18319 it
->continuation_lines_width
+= it
->last_visible_x
;
18320 row
->ends_in_middle_of_char_p
= 1;
18321 row
->continued_p
= 1;
18322 glyph
->pixel_width
= it
->last_visible_x
- x
;
18323 it
->starts_in_middle_of_char_p
= 1;
18327 /* Something other than a TAB that draws past
18328 the right edge of the window. Restore
18329 positions to values before the element. */
18330 if (row
->reversed_p
)
18331 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
18332 - (n_glyphs_before
+ i
));
18333 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18335 /* Display continuation glyphs. */
18336 if (!FRAME_WINDOW_P (it
->f
))
18337 produce_special_glyphs (it
, IT_CONTINUATION
);
18338 row
->continued_p
= 1;
18340 it
->current_x
= x_before
;
18341 it
->continuation_lines_width
+= x
;
18342 extend_face_to_end_of_line (it
);
18344 if (nglyphs
> 1 && i
> 0)
18346 row
->ends_in_middle_of_char_p
= 1;
18347 it
->starts_in_middle_of_char_p
= 1;
18350 /* Restore the height to what it was before the
18351 element not fitting on the line. */
18352 it
->max_ascent
= ascent
;
18353 it
->max_descent
= descent
;
18354 it
->max_phys_ascent
= phys_ascent
;
18355 it
->max_phys_descent
= phys_descent
;
18360 else if (new_x
> it
->first_visible_x
)
18362 /* Increment number of glyphs actually displayed. */
18365 /* Record the maximum and minimum buffer positions
18366 seen so far in glyphs that will be displayed by
18369 RECORD_MAX_MIN_POS (it
);
18371 if (x
< it
->first_visible_x
)
18372 /* Glyph is partially visible, i.e. row starts at
18373 negative X position. */
18374 row
->x
= x
- it
->first_visible_x
;
18378 /* Glyph is completely off the left margin of the
18379 window. This should not happen because of the
18380 move_it_in_display_line at the start of this
18381 function, unless the text display area of the
18382 window is empty. */
18383 xassert (it
->first_visible_x
<= it
->last_visible_x
);
18387 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18388 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18389 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18390 row
->phys_height
= max (row
->phys_height
,
18391 it
->max_phys_ascent
+ it
->max_phys_descent
);
18392 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18393 it
->max_extra_line_spacing
);
18395 /* End of this display line if row is continued. */
18396 if (row
->continued_p
|| row
->ends_at_zv_p
)
18401 /* Is this a line end? If yes, we're also done, after making
18402 sure that a non-default face is extended up to the right
18403 margin of the window. */
18404 if (ITERATOR_AT_END_OF_LINE_P (it
))
18406 int used_before
= row
->used
[TEXT_AREA
];
18408 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
18410 /* Add a space at the end of the line that is used to
18411 display the cursor there. */
18412 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18413 append_space_for_newline (it
, 0);
18415 /* Extend the face to the end of the line. */
18416 extend_face_to_end_of_line (it
);
18418 /* Make sure we have the position. */
18419 if (used_before
== 0)
18420 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
18422 /* Record the position of the newline, for use in
18424 it
->eol_pos
= it
->current
.pos
;
18426 /* Consume the line end. This skips over invisible lines. */
18427 set_iterator_to_next (it
, 1);
18428 it
->continuation_lines_width
= 0;
18432 /* Proceed with next display element. Note that this skips
18433 over lines invisible because of selective display. */
18434 set_iterator_to_next (it
, 1);
18436 /* If we truncate lines, we are done when the last displayed
18437 glyphs reach past the right margin of the window. */
18438 if (it
->line_wrap
== TRUNCATE
18439 && (FRAME_WINDOW_P (it
->f
)
18440 ? (it
->current_x
>= it
->last_visible_x
)
18441 : (it
->current_x
> it
->last_visible_x
)))
18443 /* Maybe add truncation glyphs. */
18444 if (!FRAME_WINDOW_P (it
->f
))
18448 if (!row
->reversed_p
)
18450 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18451 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18456 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
18457 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18459 /* Remove any padding glyphs at the front of ROW, to
18460 make room for the truncation glyphs we will be
18461 adding below. The loop below always inserts at
18462 least one truncation glyph, so also remove the
18463 last glyph added to ROW. */
18464 unproduce_glyphs (it
, i
+ 1);
18465 /* Adjust i for the loop below. */
18466 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
18469 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18471 row
->used
[TEXT_AREA
] = i
;
18472 produce_special_glyphs (it
, IT_TRUNCATION
);
18475 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18477 /* Don't truncate if we can overflow newline into fringe. */
18478 if (!get_next_display_element (it
))
18480 it
->continuation_lines_width
= 0;
18481 row
->ends_at_zv_p
= 1;
18482 row
->exact_window_width_line_p
= 1;
18485 if (ITERATOR_AT_END_OF_LINE_P (it
))
18487 row
->exact_window_width_line_p
= 1;
18488 goto at_end_of_line
;
18492 row
->truncated_on_right_p
= 1;
18493 it
->continuation_lines_width
= 0;
18494 reseat_at_next_visible_line_start (it
, 0);
18495 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
18496 it
->hpos
= hpos_before
;
18497 it
->current_x
= x_before
;
18502 /* If line is not empty and hscrolled, maybe insert truncation glyphs
18503 at the left window margin. */
18504 if (it
->first_visible_x
18505 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
18507 if (!FRAME_WINDOW_P (it
->f
))
18508 insert_left_trunc_glyphs (it
);
18509 row
->truncated_on_left_p
= 1;
18512 /* Remember the position at which this line ends.
18514 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
18515 cannot be before the call to find_row_edges below, since that is
18516 where these positions are determined. */
18517 row
->end
= it
->current
;
18520 row
->minpos
= row
->start
.pos
;
18521 row
->maxpos
= row
->end
.pos
;
18525 /* ROW->minpos and ROW->maxpos must be the smallest and
18526 `1 + the largest' buffer positions in ROW. But if ROW was
18527 bidi-reordered, these two positions can be anywhere in the
18528 row, so we must determine them now. */
18529 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
18532 /* If the start of this line is the overlay arrow-position, then
18533 mark this glyph row as the one containing the overlay arrow.
18534 This is clearly a mess with variable size fonts. It would be
18535 better to let it be displayed like cursors under X. */
18536 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
18537 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
18538 !NILP (overlay_arrow_string
)))
18540 /* Overlay arrow in window redisplay is a fringe bitmap. */
18541 if (STRINGP (overlay_arrow_string
))
18543 struct glyph_row
*arrow_row
18544 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
18545 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
18546 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
18547 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
18548 struct glyph
*p2
, *end
;
18550 /* Copy the arrow glyphs. */
18551 while (glyph
< arrow_end
)
18554 /* Throw away padding glyphs. */
18556 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
18557 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
18563 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
18568 xassert (INTEGERP (overlay_arrow_string
));
18569 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
18571 overlay_arrow_seen
= 1;
18574 /* Compute pixel dimensions of this line. */
18575 compute_line_metrics (it
);
18577 /* Record whether this row ends inside an ellipsis. */
18578 row
->ends_in_ellipsis_p
18579 = (it
->method
== GET_FROM_DISPLAY_VECTOR
18580 && it
->ellipsis_p
);
18582 /* Save fringe bitmaps in this row. */
18583 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
18584 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
18585 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
18586 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
18588 it
->left_user_fringe_bitmap
= 0;
18589 it
->left_user_fringe_face_id
= 0;
18590 it
->right_user_fringe_bitmap
= 0;
18591 it
->right_user_fringe_face_id
= 0;
18593 /* Maybe set the cursor. */
18594 cvpos
= it
->w
->cursor
.vpos
;
18596 /* In bidi-reordered rows, keep checking for proper cursor
18597 position even if one has been found already, because buffer
18598 positions in such rows change non-linearly with ROW->VPOS,
18599 when a line is continued. One exception: when we are at ZV,
18600 display cursor on the first suitable glyph row, since all
18601 the empty rows after that also have their position set to ZV. */
18602 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18603 lines' rows is implemented for bidi-reordered rows. */
18605 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
18606 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
18607 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
18608 && cursor_row_p (row
))
18609 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
18611 /* Highlight trailing whitespace. */
18612 if (!NILP (Vshow_trailing_whitespace
))
18613 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
18615 /* Prepare for the next line. This line starts horizontally at (X
18616 HPOS) = (0 0). Vertical positions are incremented. As a
18617 convenience for the caller, IT->glyph_row is set to the next
18619 it
->current_x
= it
->hpos
= 0;
18620 it
->current_y
+= row
->height
;
18621 SET_TEXT_POS (it
->eol_pos
, 0, 0);
18624 /* The next row should by default use the same value of the
18625 reversed_p flag as this one. set_iterator_to_next decides when
18626 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
18627 the flag accordingly. */
18628 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
18629 it
->glyph_row
->reversed_p
= row
->reversed_p
;
18630 it
->start
= row
->end
;
18631 return row
->displays_text_p
;
18633 #undef RECORD_MAX_MIN_POS
18636 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
18637 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
18638 doc
: /* Return paragraph direction at point in BUFFER.
18639 Value is either `left-to-right' or `right-to-left'.
18640 If BUFFER is omitted or nil, it defaults to the current buffer.
18642 Paragraph direction determines how the text in the paragraph is displayed.
18643 In left-to-right paragraphs, text begins at the left margin of the window
18644 and the reading direction is generally left to right. In right-to-left
18645 paragraphs, text begins at the right margin and is read from right to left.
18647 See also `bidi-paragraph-direction'. */)
18648 (Lisp_Object buffer
)
18650 struct buffer
*buf
= current_buffer
;
18651 struct buffer
*old
= buf
;
18653 if (! NILP (buffer
))
18655 CHECK_BUFFER (buffer
);
18656 buf
= XBUFFER (buffer
);
18659 if (NILP (BVAR (buf
, bidi_display_reordering
)))
18660 return Qleft_to_right
;
18661 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
18662 return BVAR (buf
, bidi_paragraph_direction
);
18665 /* Determine the direction from buffer text. We could try to
18666 use current_matrix if it is up to date, but this seems fast
18667 enough as it is. */
18668 struct bidi_it itb
;
18669 EMACS_INT pos
= BUF_PT (buf
);
18670 EMACS_INT bytepos
= BUF_PT_BYTE (buf
);
18673 set_buffer_temp (buf
);
18674 /* bidi_paragraph_init finds the base direction of the paragraph
18675 by searching forward from paragraph start. We need the base
18676 direction of the current or _previous_ paragraph, so we need
18677 to make sure we are within that paragraph. To that end, find
18678 the previous non-empty line. */
18679 if (pos
>= ZV
&& pos
> BEGV
)
18682 bytepos
= CHAR_TO_BYTE (pos
);
18684 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
18685 || c
== ' ' || c
== '\t' || c
== '\f')
18687 if (bytepos
<= BEGV_BYTE
)
18692 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
18695 itb
.bytepos
= bytepos
;
18697 itb
.string
.s
= NULL
;
18698 itb
.string
.lstring
= Qnil
;
18699 itb
.frame_window_p
= FRAME_WINDOW_P (SELECTED_FRAME ()); /* guesswork */
18701 itb
.separator_limit
= -1;
18702 itb
.paragraph_dir
= NEUTRAL_DIR
;
18704 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
18705 set_buffer_temp (old
);
18706 switch (itb
.paragraph_dir
)
18709 return Qleft_to_right
;
18712 return Qright_to_left
;
18722 /***********************************************************************
18724 ***********************************************************************/
18726 /* Redisplay the menu bar in the frame for window W.
18728 The menu bar of X frames that don't have X toolkit support is
18729 displayed in a special window W->frame->menu_bar_window.
18731 The menu bar of terminal frames is treated specially as far as
18732 glyph matrices are concerned. Menu bar lines are not part of
18733 windows, so the update is done directly on the frame matrix rows
18734 for the menu bar. */
18737 display_menu_bar (struct window
*w
)
18739 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18744 /* Don't do all this for graphical frames. */
18746 if (FRAME_W32_P (f
))
18749 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
18755 if (FRAME_NS_P (f
))
18757 #endif /* HAVE_NS */
18759 #ifdef USE_X_TOOLKIT
18760 xassert (!FRAME_WINDOW_P (f
));
18761 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
18762 it
.first_visible_x
= 0;
18763 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18764 #else /* not USE_X_TOOLKIT */
18765 if (FRAME_WINDOW_P (f
))
18767 /* Menu bar lines are displayed in the desired matrix of the
18768 dummy window menu_bar_window. */
18769 struct window
*menu_w
;
18770 xassert (WINDOWP (f
->menu_bar_window
));
18771 menu_w
= XWINDOW (f
->menu_bar_window
);
18772 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
18774 it
.first_visible_x
= 0;
18775 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18779 /* This is a TTY frame, i.e. character hpos/vpos are used as
18781 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
18783 it
.first_visible_x
= 0;
18784 it
.last_visible_x
= FRAME_COLS (f
);
18786 #endif /* not USE_X_TOOLKIT */
18788 /* FIXME: This should be controlled by a user option. See the
18789 comments in redisplay_tool_bar and display_mode_line about
18791 it
.paragraph_embedding
= L2R
;
18793 if (! mode_line_inverse_video
)
18794 /* Force the menu-bar to be displayed in the default face. */
18795 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18797 /* Clear all rows of the menu bar. */
18798 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
18800 struct glyph_row
*row
= it
.glyph_row
+ i
;
18801 clear_glyph_row (row
);
18802 row
->enabled_p
= 1;
18803 row
->full_width_p
= 1;
18806 /* Display all items of the menu bar. */
18807 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
18808 for (i
= 0; i
< ASIZE (items
); i
+= 4)
18810 Lisp_Object string
;
18812 /* Stop at nil string. */
18813 string
= AREF (items
, i
+ 1);
18817 /* Remember where item was displayed. */
18818 ASET (items
, i
+ 3, make_number (it
.hpos
));
18820 /* Display the item, pad with one space. */
18821 if (it
.current_x
< it
.last_visible_x
)
18822 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
18823 SCHARS (string
) + 1, 0, 0, -1);
18826 /* Fill out the line with spaces. */
18827 if (it
.current_x
< it
.last_visible_x
)
18828 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
18830 /* Compute the total height of the lines. */
18831 compute_line_metrics (&it
);
18836 /***********************************************************************
18838 ***********************************************************************/
18840 /* Redisplay mode lines in the window tree whose root is WINDOW. If
18841 FORCE is non-zero, redisplay mode lines unconditionally.
18842 Otherwise, redisplay only mode lines that are garbaged. Value is
18843 the number of windows whose mode lines were redisplayed. */
18846 redisplay_mode_lines (Lisp_Object window
, int force
)
18850 while (!NILP (window
))
18852 struct window
*w
= XWINDOW (window
);
18854 if (WINDOWP (w
->hchild
))
18855 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
18856 else if (WINDOWP (w
->vchild
))
18857 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18859 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18860 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18862 struct text_pos lpoint
;
18863 struct buffer
*old
= current_buffer
;
18865 /* Set the window's buffer for the mode line display. */
18866 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18867 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18869 /* Point refers normally to the selected window. For any
18870 other window, set up appropriate value. */
18871 if (!EQ (window
, selected_window
))
18873 struct text_pos pt
;
18875 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18876 if (CHARPOS (pt
) < BEGV
)
18877 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18878 else if (CHARPOS (pt
) > (ZV
- 1))
18879 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18881 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18884 /* Display mode lines. */
18885 clear_glyph_matrix (w
->desired_matrix
);
18886 if (display_mode_lines (w
))
18889 w
->must_be_updated_p
= 1;
18892 /* Restore old settings. */
18893 set_buffer_internal_1 (old
);
18894 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18904 /* Display the mode and/or header line of window W. Value is the
18905 sum number of mode lines and header lines displayed. */
18908 display_mode_lines (struct window
*w
)
18910 Lisp_Object old_selected_window
, old_selected_frame
;
18913 old_selected_frame
= selected_frame
;
18914 selected_frame
= w
->frame
;
18915 old_selected_window
= selected_window
;
18916 XSETWINDOW (selected_window
, w
);
18918 /* These will be set while the mode line specs are processed. */
18919 line_number_displayed
= 0;
18920 w
->column_number_displayed
= Qnil
;
18922 if (WINDOW_WANTS_MODELINE_P (w
))
18924 struct window
*sel_w
= XWINDOW (old_selected_window
);
18926 /* Select mode line face based on the real selected window. */
18927 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18928 BVAR (current_buffer
, mode_line_format
));
18932 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18934 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18935 BVAR (current_buffer
, header_line_format
));
18939 selected_frame
= old_selected_frame
;
18940 selected_window
= old_selected_window
;
18945 /* Display mode or header line of window W. FACE_ID specifies which
18946 line to display; it is either MODE_LINE_FACE_ID or
18947 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18948 display. Value is the pixel height of the mode/header line
18952 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
18956 int count
= SPECPDL_INDEX ();
18958 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18959 /* Don't extend on a previously drawn mode-line.
18960 This may happen if called from pos_visible_p. */
18961 it
.glyph_row
->enabled_p
= 0;
18962 prepare_desired_row (it
.glyph_row
);
18964 it
.glyph_row
->mode_line_p
= 1;
18966 if (! mode_line_inverse_video
)
18967 /* Force the mode-line to be displayed in the default face. */
18968 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18970 /* FIXME: This should be controlled by a user option. But
18971 supporting such an option is not trivial, since the mode line is
18972 made up of many separate strings, most of which are normally
18973 unibyte, and unibyte strings currently don't get reordered for
18975 it
.paragraph_embedding
= L2R
;
18977 record_unwind_protect (unwind_format_mode_line
,
18978 format_mode_line_unwind_data (NULL
, Qnil
, 0));
18980 mode_line_target
= MODE_LINE_DISPLAY
;
18982 /* Temporarily make frame's keyboard the current kboard so that
18983 kboard-local variables in the mode_line_format will get the right
18985 push_kboard (FRAME_KBOARD (it
.f
));
18986 record_unwind_save_match_data ();
18987 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18990 unbind_to (count
, Qnil
);
18992 /* Fill up with spaces. */
18993 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
18995 compute_line_metrics (&it
);
18996 it
.glyph_row
->full_width_p
= 1;
18997 it
.glyph_row
->continued_p
= 0;
18998 it
.glyph_row
->truncated_on_left_p
= 0;
18999 it
.glyph_row
->truncated_on_right_p
= 0;
19001 /* Make a 3D mode-line have a shadow at its right end. */
19002 face
= FACE_FROM_ID (it
.f
, face_id
);
19003 extend_face_to_end_of_line (&it
);
19004 if (face
->box
!= FACE_NO_BOX
)
19006 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
19007 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
19008 last
->right_box_line_p
= 1;
19011 return it
.glyph_row
->height
;
19014 /* Move element ELT in LIST to the front of LIST.
19015 Return the updated list. */
19018 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
19020 register Lisp_Object tail
, prev
;
19021 register Lisp_Object tem
;
19025 while (CONSP (tail
))
19031 /* Splice out the link TAIL. */
19033 list
= XCDR (tail
);
19035 Fsetcdr (prev
, XCDR (tail
));
19037 /* Now make it the first. */
19038 Fsetcdr (tail
, list
);
19043 tail
= XCDR (tail
);
19047 /* Not found--return unchanged LIST. */
19051 /* Contribute ELT to the mode line for window IT->w. How it
19052 translates into text depends on its data type.
19054 IT describes the display environment in which we display, as usual.
19056 DEPTH is the depth in recursion. It is used to prevent
19057 infinite recursion here.
19059 FIELD_WIDTH is the number of characters the display of ELT should
19060 occupy in the mode line, and PRECISION is the maximum number of
19061 characters to display from ELT's representation. See
19062 display_string for details.
19064 Returns the hpos of the end of the text generated by ELT.
19066 PROPS is a property list to add to any string we encounter.
19068 If RISKY is nonzero, remove (disregard) any properties in any string
19069 we encounter, and ignore :eval and :propertize.
19071 The global variable `mode_line_target' determines whether the
19072 output is passed to `store_mode_line_noprop',
19073 `store_mode_line_string', or `display_string'. */
19076 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
19077 Lisp_Object elt
, Lisp_Object props
, int risky
)
19079 int n
= 0, field
, prec
;
19084 elt
= build_string ("*too-deep*");
19088 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
19092 /* A string: output it and check for %-constructs within it. */
19094 EMACS_INT offset
= 0;
19096 if (SCHARS (elt
) > 0
19097 && (!NILP (props
) || risky
))
19099 Lisp_Object oprops
, aelt
;
19100 oprops
= Ftext_properties_at (make_number (0), elt
);
19102 /* If the starting string's properties are not what
19103 we want, translate the string. Also, if the string
19104 is risky, do that anyway. */
19106 if (NILP (Fequal (props
, oprops
)) || risky
)
19108 /* If the starting string has properties,
19109 merge the specified ones onto the existing ones. */
19110 if (! NILP (oprops
) && !risky
)
19114 oprops
= Fcopy_sequence (oprops
);
19116 while (CONSP (tem
))
19118 oprops
= Fplist_put (oprops
, XCAR (tem
),
19119 XCAR (XCDR (tem
)));
19120 tem
= XCDR (XCDR (tem
));
19125 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
19126 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
19128 /* AELT is what we want. Move it to the front
19129 without consing. */
19131 mode_line_proptrans_alist
19132 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
19138 /* If AELT has the wrong props, it is useless.
19139 so get rid of it. */
19141 mode_line_proptrans_alist
19142 = Fdelq (aelt
, mode_line_proptrans_alist
);
19144 elt
= Fcopy_sequence (elt
);
19145 Fset_text_properties (make_number (0), Flength (elt
),
19147 /* Add this item to mode_line_proptrans_alist. */
19148 mode_line_proptrans_alist
19149 = Fcons (Fcons (elt
, props
),
19150 mode_line_proptrans_alist
);
19151 /* Truncate mode_line_proptrans_alist
19152 to at most 50 elements. */
19153 tem
= Fnthcdr (make_number (50),
19154 mode_line_proptrans_alist
);
19156 XSETCDR (tem
, Qnil
);
19165 prec
= precision
- n
;
19166 switch (mode_line_target
)
19168 case MODE_LINE_NOPROP
:
19169 case MODE_LINE_TITLE
:
19170 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
19172 case MODE_LINE_STRING
:
19173 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
19175 case MODE_LINE_DISPLAY
:
19176 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
19177 0, prec
, 0, STRING_MULTIBYTE (elt
));
19184 /* Handle the non-literal case. */
19186 while ((precision
<= 0 || n
< precision
)
19187 && SREF (elt
, offset
) != 0
19188 && (mode_line_target
!= MODE_LINE_DISPLAY
19189 || it
->current_x
< it
->last_visible_x
))
19191 EMACS_INT last_offset
= offset
;
19193 /* Advance to end of string or next format specifier. */
19194 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
19197 if (offset
- 1 != last_offset
)
19199 EMACS_INT nchars
, nbytes
;
19201 /* Output to end of string or up to '%'. Field width
19202 is length of string. Don't output more than
19203 PRECISION allows us. */
19206 prec
= c_string_width (SDATA (elt
) + last_offset
,
19207 offset
- last_offset
, precision
- n
,
19210 switch (mode_line_target
)
19212 case MODE_LINE_NOPROP
:
19213 case MODE_LINE_TITLE
:
19214 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
19216 case MODE_LINE_STRING
:
19218 EMACS_INT bytepos
= last_offset
;
19219 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
19220 EMACS_INT endpos
= (precision
<= 0
19221 ? string_byte_to_char (elt
, offset
)
19222 : charpos
+ nchars
);
19224 n
+= store_mode_line_string (NULL
,
19225 Fsubstring (elt
, make_number (charpos
),
19226 make_number (endpos
)),
19230 case MODE_LINE_DISPLAY
:
19232 EMACS_INT bytepos
= last_offset
;
19233 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
19235 if (precision
<= 0)
19236 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
19237 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
19239 STRING_MULTIBYTE (elt
));
19244 else /* c == '%' */
19246 EMACS_INT percent_position
= offset
;
19248 /* Get the specified minimum width. Zero means
19251 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
19252 field
= field
* 10 + c
- '0';
19254 /* Don't pad beyond the total padding allowed. */
19255 if (field_width
- n
> 0 && field
> field_width
- n
)
19256 field
= field_width
- n
;
19258 /* Note that either PRECISION <= 0 or N < PRECISION. */
19259 prec
= precision
- n
;
19262 n
+= display_mode_element (it
, depth
, field
, prec
,
19263 Vglobal_mode_string
, props
,
19268 EMACS_INT bytepos
, charpos
;
19270 Lisp_Object string
;
19272 bytepos
= percent_position
;
19273 charpos
= (STRING_MULTIBYTE (elt
)
19274 ? string_byte_to_char (elt
, bytepos
)
19276 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
19277 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
19279 switch (mode_line_target
)
19281 case MODE_LINE_NOPROP
:
19282 case MODE_LINE_TITLE
:
19283 n
+= store_mode_line_noprop (spec
, field
, prec
);
19285 case MODE_LINE_STRING
:
19287 int len
= strlen (spec
);
19288 Lisp_Object tem
= make_string (spec
, len
);
19289 props
= Ftext_properties_at (make_number (charpos
), elt
);
19290 /* Should only keep face property in props */
19291 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
19294 case MODE_LINE_DISPLAY
:
19296 int nglyphs_before
, nwritten
;
19298 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
19299 nwritten
= display_string (spec
, string
, elt
,
19304 /* Assign to the glyphs written above the
19305 string where the `%x' came from, position
19309 struct glyph
*glyph
19310 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
19314 for (i
= 0; i
< nwritten
; ++i
)
19316 glyph
[i
].object
= elt
;
19317 glyph
[i
].charpos
= charpos
;
19334 /* A symbol: process the value of the symbol recursively
19335 as if it appeared here directly. Avoid error if symbol void.
19336 Special case: if value of symbol is a string, output the string
19339 register Lisp_Object tem
;
19341 /* If the variable is not marked as risky to set
19342 then its contents are risky to use. */
19343 if (NILP (Fget (elt
, Qrisky_local_variable
)))
19346 tem
= Fboundp (elt
);
19349 tem
= Fsymbol_value (elt
);
19350 /* If value is a string, output that string literally:
19351 don't check for % within it. */
19355 if (!EQ (tem
, elt
))
19357 /* Give up right away for nil or t. */
19367 register Lisp_Object car
, tem
;
19369 /* A cons cell: five distinct cases.
19370 If first element is :eval or :propertize, do something special.
19371 If first element is a string or a cons, process all the elements
19372 and effectively concatenate them.
19373 If first element is a negative number, truncate displaying cdr to
19374 at most that many characters. If positive, pad (with spaces)
19375 to at least that many characters.
19376 If first element is a symbol, process the cadr or caddr recursively
19377 according to whether the symbol's value is non-nil or nil. */
19379 if (EQ (car
, QCeval
))
19381 /* An element of the form (:eval FORM) means evaluate FORM
19382 and use the result as mode line elements. */
19387 if (CONSP (XCDR (elt
)))
19390 spec
= safe_eval (XCAR (XCDR (elt
)));
19391 n
+= display_mode_element (it
, depth
, field_width
- n
,
19392 precision
- n
, spec
, props
,
19396 else if (EQ (car
, QCpropertize
))
19398 /* An element of the form (:propertize ELT PROPS...)
19399 means display ELT but applying properties PROPS. */
19404 if (CONSP (XCDR (elt
)))
19405 n
+= display_mode_element (it
, depth
, field_width
- n
,
19406 precision
- n
, XCAR (XCDR (elt
)),
19407 XCDR (XCDR (elt
)), risky
);
19409 else if (SYMBOLP (car
))
19411 tem
= Fboundp (car
);
19415 /* elt is now the cdr, and we know it is a cons cell.
19416 Use its car if CAR has a non-nil value. */
19419 tem
= Fsymbol_value (car
);
19426 /* Symbol's value is nil (or symbol is unbound)
19427 Get the cddr of the original list
19428 and if possible find the caddr and use that. */
19432 else if (!CONSP (elt
))
19437 else if (INTEGERP (car
))
19439 register int lim
= XINT (car
);
19443 /* Negative int means reduce maximum width. */
19444 if (precision
<= 0)
19447 precision
= min (precision
, -lim
);
19451 /* Padding specified. Don't let it be more than
19452 current maximum. */
19454 lim
= min (precision
, lim
);
19456 /* If that's more padding than already wanted, queue it.
19457 But don't reduce padding already specified even if
19458 that is beyond the current truncation point. */
19459 field_width
= max (lim
, field_width
);
19463 else if (STRINGP (car
) || CONSP (car
))
19465 Lisp_Object halftail
= elt
;
19469 && (precision
<= 0 || n
< precision
))
19471 n
+= display_mode_element (it
, depth
,
19472 /* Do padding only after the last
19473 element in the list. */
19474 (! CONSP (XCDR (elt
))
19477 precision
- n
, XCAR (elt
),
19481 if ((len
& 1) == 0)
19482 halftail
= XCDR (halftail
);
19483 /* Check for cycle. */
19484 if (EQ (halftail
, elt
))
19493 elt
= build_string ("*invalid*");
19497 /* Pad to FIELD_WIDTH. */
19498 if (field_width
> 0 && n
< field_width
)
19500 switch (mode_line_target
)
19502 case MODE_LINE_NOPROP
:
19503 case MODE_LINE_TITLE
:
19504 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
19506 case MODE_LINE_STRING
:
19507 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
19509 case MODE_LINE_DISPLAY
:
19510 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
19519 /* Store a mode-line string element in mode_line_string_list.
19521 If STRING is non-null, display that C string. Otherwise, the Lisp
19522 string LISP_STRING is displayed.
19524 FIELD_WIDTH is the minimum number of output glyphs to produce.
19525 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19526 with spaces. FIELD_WIDTH <= 0 means don't pad.
19528 PRECISION is the maximum number of characters to output from
19529 STRING. PRECISION <= 0 means don't truncate the string.
19531 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
19532 properties to the string.
19534 PROPS are the properties to add to the string.
19535 The mode_line_string_face face property is always added to the string.
19539 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
19540 int field_width
, int precision
, Lisp_Object props
)
19545 if (string
!= NULL
)
19547 len
= strlen (string
);
19548 if (precision
> 0 && len
> precision
)
19550 lisp_string
= make_string (string
, len
);
19552 props
= mode_line_string_face_prop
;
19553 else if (!NILP (mode_line_string_face
))
19555 Lisp_Object face
= Fplist_get (props
, Qface
);
19556 props
= Fcopy_sequence (props
);
19558 face
= mode_line_string_face
;
19560 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19561 props
= Fplist_put (props
, Qface
, face
);
19563 Fadd_text_properties (make_number (0), make_number (len
),
19564 props
, lisp_string
);
19568 len
= XFASTINT (Flength (lisp_string
));
19569 if (precision
> 0 && len
> precision
)
19572 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
19575 if (!NILP (mode_line_string_face
))
19579 props
= Ftext_properties_at (make_number (0), lisp_string
);
19580 face
= Fplist_get (props
, Qface
);
19582 face
= mode_line_string_face
;
19584 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19585 props
= Fcons (Qface
, Fcons (face
, Qnil
));
19587 lisp_string
= Fcopy_sequence (lisp_string
);
19590 Fadd_text_properties (make_number (0), make_number (len
),
19591 props
, lisp_string
);
19596 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19600 if (field_width
> len
)
19602 field_width
-= len
;
19603 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
19605 Fadd_text_properties (make_number (0), make_number (field_width
),
19606 props
, lisp_string
);
19607 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19615 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
19617 doc
: /* Format a string out of a mode line format specification.
19618 First arg FORMAT specifies the mode line format (see `mode-line-format'
19619 for details) to use.
19621 By default, the format is evaluated for the currently selected window.
19623 Optional second arg FACE specifies the face property to put on all
19624 characters for which no face is specified. The value nil means the
19625 default face. The value t means whatever face the window's mode line
19626 currently uses (either `mode-line' or `mode-line-inactive',
19627 depending on whether the window is the selected window or not).
19628 An integer value means the value string has no text
19631 Optional third and fourth args WINDOW and BUFFER specify the window
19632 and buffer to use as the context for the formatting (defaults
19633 are the selected window and the WINDOW's buffer). */)
19634 (Lisp_Object format
, Lisp_Object face
,
19635 Lisp_Object window
, Lisp_Object buffer
)
19640 struct buffer
*old_buffer
= NULL
;
19642 int no_props
= INTEGERP (face
);
19643 int count
= SPECPDL_INDEX ();
19645 int string_start
= 0;
19648 window
= selected_window
;
19649 CHECK_WINDOW (window
);
19650 w
= XWINDOW (window
);
19653 buffer
= w
->buffer
;
19654 CHECK_BUFFER (buffer
);
19656 /* Make formatting the modeline a non-op when noninteractive, otherwise
19657 there will be problems later caused by a partially initialized frame. */
19658 if (NILP (format
) || noninteractive
)
19659 return empty_unibyte_string
;
19664 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
19665 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
19666 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
19667 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
19668 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
19669 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
19670 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
19673 if (XBUFFER (buffer
) != current_buffer
)
19674 old_buffer
= current_buffer
;
19676 /* Save things including mode_line_proptrans_alist,
19677 and set that to nil so that we don't alter the outer value. */
19678 record_unwind_protect (unwind_format_mode_line
,
19679 format_mode_line_unwind_data
19680 (old_buffer
, selected_window
, 1));
19681 mode_line_proptrans_alist
= Qnil
;
19683 Fselect_window (window
, Qt
);
19685 set_buffer_internal_1 (XBUFFER (buffer
));
19687 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19691 mode_line_target
= MODE_LINE_NOPROP
;
19692 mode_line_string_face_prop
= Qnil
;
19693 mode_line_string_list
= Qnil
;
19694 string_start
= MODE_LINE_NOPROP_LEN (0);
19698 mode_line_target
= MODE_LINE_STRING
;
19699 mode_line_string_list
= Qnil
;
19700 mode_line_string_face
= face
;
19701 mode_line_string_face_prop
19702 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
19705 push_kboard (FRAME_KBOARD (it
.f
));
19706 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19711 len
= MODE_LINE_NOPROP_LEN (string_start
);
19712 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
19716 mode_line_string_list
= Fnreverse (mode_line_string_list
);
19717 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
19718 empty_unibyte_string
);
19721 unbind_to (count
, Qnil
);
19725 /* Write a null-terminated, right justified decimal representation of
19726 the positive integer D to BUF using a minimal field width WIDTH. */
19729 pint2str (register char *buf
, register int width
, register EMACS_INT d
)
19731 register char *p
= buf
;
19739 *p
++ = d
% 10 + '0';
19744 for (width
-= (int) (p
- buf
); width
> 0; --width
)
19755 /* Write a null-terminated, right justified decimal and "human
19756 readable" representation of the nonnegative integer D to BUF using
19757 a minimal field width WIDTH. D should be smaller than 999.5e24. */
19759 static const char power_letter
[] =
19773 pint2hrstr (char *buf
, int width
, EMACS_INT d
)
19775 /* We aim to represent the nonnegative integer D as
19776 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
19777 EMACS_INT quotient
= d
;
19779 /* -1 means: do not use TENTHS. */
19783 /* Length of QUOTIENT.TENTHS as a string. */
19789 if (1000 <= quotient
)
19791 /* Scale to the appropriate EXPONENT. */
19794 remainder
= quotient
% 1000;
19798 while (1000 <= quotient
);
19800 /* Round to nearest and decide whether to use TENTHS or not. */
19803 tenths
= remainder
/ 100;
19804 if (50 <= remainder
% 100)
19811 if (quotient
== 10)
19819 if (500 <= remainder
)
19821 if (quotient
< 999)
19832 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
19833 if (tenths
== -1 && quotient
<= 99)
19840 p
= psuffix
= buf
+ max (width
, length
);
19842 /* Print EXPONENT. */
19843 *psuffix
++ = power_letter
[exponent
];
19846 /* Print TENTHS. */
19849 *--p
= '0' + tenths
;
19853 /* Print QUOTIENT. */
19856 int digit
= quotient
% 10;
19857 *--p
= '0' + digit
;
19859 while ((quotient
/= 10) != 0);
19861 /* Print leading spaces. */
19866 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19867 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19868 type of CODING_SYSTEM. Return updated pointer into BUF. */
19870 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19873 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
19876 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
19877 const unsigned char *eol_str
;
19879 /* The EOL conversion we are using. */
19880 Lisp_Object eoltype
;
19882 val
= CODING_SYSTEM_SPEC (coding_system
);
19885 if (!VECTORP (val
)) /* Not yet decided. */
19890 eoltype
= eol_mnemonic_undecided
;
19891 /* Don't mention EOL conversion if it isn't decided. */
19896 Lisp_Object eolvalue
;
19898 attrs
= AREF (val
, 0);
19899 eolvalue
= AREF (val
, 2);
19902 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19906 /* The EOL conversion that is normal on this system. */
19908 if (NILP (eolvalue
)) /* Not yet decided. */
19909 eoltype
= eol_mnemonic_undecided
;
19910 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19911 eoltype
= eol_mnemonic_undecided
;
19912 else /* eolvalue is Qunix, Qdos, or Qmac. */
19913 eoltype
= (EQ (eolvalue
, Qunix
)
19914 ? eol_mnemonic_unix
19915 : (EQ (eolvalue
, Qdos
) == 1
19916 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19922 /* Mention the EOL conversion if it is not the usual one. */
19923 if (STRINGP (eoltype
))
19925 eol_str
= SDATA (eoltype
);
19926 eol_str_len
= SBYTES (eoltype
);
19928 else if (CHARACTERP (eoltype
))
19930 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19931 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19936 eol_str
= invalid_eol_type
;
19937 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19939 memcpy (buf
, eol_str
, eol_str_len
);
19940 buf
+= eol_str_len
;
19946 /* Return a string for the output of a mode line %-spec for window W,
19947 generated by character C. FIELD_WIDTH > 0 means pad the string
19948 returned with spaces to that value. Return a Lisp string in
19949 *STRING if the resulting string is taken from that Lisp string.
19951 Note we operate on the current buffer for most purposes,
19952 the exception being w->base_line_pos. */
19954 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19956 static const char *
19957 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
19958 Lisp_Object
*string
)
19961 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19962 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19963 struct buffer
*b
= current_buffer
;
19971 if (!NILP (BVAR (b
, read_only
)))
19973 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19978 /* This differs from %* only for a modified read-only buffer. */
19979 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19981 if (!NILP (BVAR (b
, read_only
)))
19986 /* This differs from %* in ignoring read-only-ness. */
19987 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19999 if (command_loop_level
> 5)
20001 p
= decode_mode_spec_buf
;
20002 for (i
= 0; i
< command_loop_level
; i
++)
20005 return decode_mode_spec_buf
;
20013 if (command_loop_level
> 5)
20015 p
= decode_mode_spec_buf
;
20016 for (i
= 0; i
< command_loop_level
; i
++)
20019 return decode_mode_spec_buf
;
20026 /* Let lots_of_dashes be a string of infinite length. */
20027 if (mode_line_target
== MODE_LINE_NOPROP
||
20028 mode_line_target
== MODE_LINE_STRING
)
20030 if (field_width
<= 0
20031 || field_width
> sizeof (lots_of_dashes
))
20033 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
20034 decode_mode_spec_buf
[i
] = '-';
20035 decode_mode_spec_buf
[i
] = '\0';
20036 return decode_mode_spec_buf
;
20039 return lots_of_dashes
;
20043 obj
= BVAR (b
, name
);
20047 /* %c and %l are ignored in `frame-title-format'.
20048 (In redisplay_internal, the frame title is drawn _before_ the
20049 windows are updated, so the stuff which depends on actual
20050 window contents (such as %l) may fail to render properly, or
20051 even crash emacs.) */
20052 if (mode_line_target
== MODE_LINE_TITLE
)
20056 EMACS_INT col
= current_column ();
20057 w
->column_number_displayed
= make_number (col
);
20058 pint2str (decode_mode_spec_buf
, field_width
, col
);
20059 return decode_mode_spec_buf
;
20063 #ifndef SYSTEM_MALLOC
20065 if (NILP (Vmemory_full
))
20068 return "!MEM FULL! ";
20075 /* %F displays the frame name. */
20076 if (!NILP (f
->title
))
20077 return SSDATA (f
->title
);
20078 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
20079 return SSDATA (f
->name
);
20083 obj
= BVAR (b
, filename
);
20088 EMACS_INT size
= ZV
- BEGV
;
20089 pint2str (decode_mode_spec_buf
, field_width
, size
);
20090 return decode_mode_spec_buf
;
20095 EMACS_INT size
= ZV
- BEGV
;
20096 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
20097 return decode_mode_spec_buf
;
20102 EMACS_INT startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
20103 EMACS_INT topline
, nlines
, height
;
20106 /* %c and %l are ignored in `frame-title-format'. */
20107 if (mode_line_target
== MODE_LINE_TITLE
)
20110 startpos
= XMARKER (w
->start
)->charpos
;
20111 startpos_byte
= marker_byte_position (w
->start
);
20112 height
= WINDOW_TOTAL_LINES (w
);
20114 /* If we decided that this buffer isn't suitable for line numbers,
20115 don't forget that too fast. */
20116 if (EQ (w
->base_line_pos
, w
->buffer
))
20118 /* But do forget it, if the window shows a different buffer now. */
20119 else if (BUFFERP (w
->base_line_pos
))
20120 w
->base_line_pos
= Qnil
;
20122 /* If the buffer is very big, don't waste time. */
20123 if (INTEGERP (Vline_number_display_limit
)
20124 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
20126 w
->base_line_pos
= Qnil
;
20127 w
->base_line_number
= Qnil
;
20131 if (INTEGERP (w
->base_line_number
)
20132 && INTEGERP (w
->base_line_pos
)
20133 && XFASTINT (w
->base_line_pos
) <= startpos
)
20135 line
= XFASTINT (w
->base_line_number
);
20136 linepos
= XFASTINT (w
->base_line_pos
);
20137 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
20142 linepos
= BUF_BEGV (b
);
20143 linepos_byte
= BUF_BEGV_BYTE (b
);
20146 /* Count lines from base line to window start position. */
20147 nlines
= display_count_lines (linepos_byte
,
20151 topline
= nlines
+ line
;
20153 /* Determine a new base line, if the old one is too close
20154 or too far away, or if we did not have one.
20155 "Too close" means it's plausible a scroll-down would
20156 go back past it. */
20157 if (startpos
== BUF_BEGV (b
))
20159 w
->base_line_number
= make_number (topline
);
20160 w
->base_line_pos
= make_number (BUF_BEGV (b
));
20162 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
20163 || linepos
== BUF_BEGV (b
))
20165 EMACS_INT limit
= BUF_BEGV (b
);
20166 EMACS_INT limit_byte
= BUF_BEGV_BYTE (b
);
20167 EMACS_INT position
;
20168 EMACS_INT distance
=
20169 (height
* 2 + 30) * line_number_display_limit_width
;
20171 if (startpos
- distance
> limit
)
20173 limit
= startpos
- distance
;
20174 limit_byte
= CHAR_TO_BYTE (limit
);
20177 nlines
= display_count_lines (startpos_byte
,
20179 - (height
* 2 + 30),
20181 /* If we couldn't find the lines we wanted within
20182 line_number_display_limit_width chars per line,
20183 give up on line numbers for this window. */
20184 if (position
== limit_byte
&& limit
== startpos
- distance
)
20186 w
->base_line_pos
= w
->buffer
;
20187 w
->base_line_number
= Qnil
;
20191 w
->base_line_number
= make_number (topline
- nlines
);
20192 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
20195 /* Now count lines from the start pos to point. */
20196 nlines
= display_count_lines (startpos_byte
,
20197 PT_BYTE
, PT
, &junk
);
20199 /* Record that we did display the line number. */
20200 line_number_displayed
= 1;
20202 /* Make the string to show. */
20203 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
20204 return decode_mode_spec_buf
;
20207 char* p
= decode_mode_spec_buf
;
20208 int pad
= field_width
- 2;
20214 return decode_mode_spec_buf
;
20220 obj
= BVAR (b
, mode_name
);
20224 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
20230 EMACS_INT pos
= marker_position (w
->start
);
20231 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
20233 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
20235 if (pos
<= BUF_BEGV (b
))
20240 else if (pos
<= BUF_BEGV (b
))
20244 if (total
> 1000000)
20245 /* Do it differently for a large value, to avoid overflow. */
20246 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
20248 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
20249 /* We can't normally display a 3-digit number,
20250 so get us a 2-digit number that is close. */
20253 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
20254 return decode_mode_spec_buf
;
20258 /* Display percentage of size above the bottom of the screen. */
20261 EMACS_INT toppos
= marker_position (w
->start
);
20262 EMACS_INT botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
20263 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
20265 if (botpos
>= BUF_ZV (b
))
20267 if (toppos
<= BUF_BEGV (b
))
20274 if (total
> 1000000)
20275 /* Do it differently for a large value, to avoid overflow. */
20276 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
20278 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
20279 /* We can't normally display a 3-digit number,
20280 so get us a 2-digit number that is close. */
20283 if (toppos
<= BUF_BEGV (b
))
20284 sprintf (decode_mode_spec_buf
, "Top%2"pI
"d%%", total
);
20286 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
20287 return decode_mode_spec_buf
;
20292 /* status of process */
20293 obj
= Fget_buffer_process (Fcurrent_buffer ());
20295 return "no process";
20297 obj
= Fsymbol_name (Fprocess_status (obj
));
20303 int count
= inhibit_garbage_collection ();
20304 Lisp_Object val
= call1 (intern ("file-remote-p"),
20305 BVAR (current_buffer
, directory
));
20306 unbind_to (count
, Qnil
);
20314 case 't': /* indicate TEXT or BINARY */
20318 /* coding-system (not including end-of-line format) */
20320 /* coding-system (including end-of-line type) */
20322 int eol_flag
= (c
== 'Z');
20323 char *p
= decode_mode_spec_buf
;
20325 if (! FRAME_WINDOW_P (f
))
20327 /* No need to mention EOL here--the terminal never needs
20328 to do EOL conversion. */
20329 p
= decode_mode_spec_coding (CODING_ID_NAME
20330 (FRAME_KEYBOARD_CODING (f
)->id
),
20332 p
= decode_mode_spec_coding (CODING_ID_NAME
20333 (FRAME_TERMINAL_CODING (f
)->id
),
20336 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
20339 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
20340 #ifdef subprocesses
20341 obj
= Fget_buffer_process (Fcurrent_buffer ());
20342 if (PROCESSP (obj
))
20344 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
20346 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
20349 #endif /* subprocesses */
20352 return decode_mode_spec_buf
;
20359 return SSDATA (obj
);
20366 /* Count up to COUNT lines starting from START_BYTE.
20367 But don't go beyond LIMIT_BYTE.
20368 Return the number of lines thus found (always nonnegative).
20370 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
20373 display_count_lines (EMACS_INT start_byte
,
20374 EMACS_INT limit_byte
, EMACS_INT count
,
20375 EMACS_INT
*byte_pos_ptr
)
20377 register unsigned char *cursor
;
20378 unsigned char *base
;
20380 register EMACS_INT ceiling
;
20381 register unsigned char *ceiling_addr
;
20382 EMACS_INT orig_count
= count
;
20384 /* If we are not in selective display mode,
20385 check only for newlines. */
20386 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
20387 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
20391 while (start_byte
< limit_byte
)
20393 ceiling
= BUFFER_CEILING_OF (start_byte
);
20394 ceiling
= min (limit_byte
- 1, ceiling
);
20395 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
20396 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
20399 if (selective_display
)
20400 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
20403 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
20406 if (cursor
!= ceiling_addr
)
20410 start_byte
+= cursor
- base
+ 1;
20411 *byte_pos_ptr
= start_byte
;
20415 if (++cursor
== ceiling_addr
)
20421 start_byte
+= cursor
- base
;
20426 while (start_byte
> limit_byte
)
20428 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
20429 ceiling
= max (limit_byte
, ceiling
);
20430 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
20431 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
20434 if (selective_display
)
20435 while (--cursor
!= ceiling_addr
20436 && *cursor
!= '\n' && *cursor
!= 015)
20439 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
20442 if (cursor
!= ceiling_addr
)
20446 start_byte
+= cursor
- base
+ 1;
20447 *byte_pos_ptr
= start_byte
;
20448 /* When scanning backwards, we should
20449 not count the newline posterior to which we stop. */
20450 return - orig_count
- 1;
20456 /* Here we add 1 to compensate for the last decrement
20457 of CURSOR, which took it past the valid range. */
20458 start_byte
+= cursor
- base
+ 1;
20462 *byte_pos_ptr
= limit_byte
;
20465 return - orig_count
+ count
;
20466 return orig_count
- count
;
20472 /***********************************************************************
20474 ***********************************************************************/
20476 /* Display a NUL-terminated string, starting with index START.
20478 If STRING is non-null, display that C string. Otherwise, the Lisp
20479 string LISP_STRING is displayed. There's a case that STRING is
20480 non-null and LISP_STRING is not nil. It means STRING is a string
20481 data of LISP_STRING. In that case, we display LISP_STRING while
20482 ignoring its text properties.
20484 If FACE_STRING is not nil, FACE_STRING_POS is a position in
20485 FACE_STRING. Display STRING or LISP_STRING with the face at
20486 FACE_STRING_POS in FACE_STRING:
20488 Display the string in the environment given by IT, but use the
20489 standard display table, temporarily.
20491 FIELD_WIDTH is the minimum number of output glyphs to produce.
20492 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20493 with spaces. If STRING has more characters, more than FIELD_WIDTH
20494 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
20496 PRECISION is the maximum number of characters to output from
20497 STRING. PRECISION < 0 means don't truncate the string.
20499 This is roughly equivalent to printf format specifiers:
20501 FIELD_WIDTH PRECISION PRINTF
20502 ----------------------------------------
20508 MULTIBYTE zero means do not display multibyte chars, > 0 means do
20509 display them, and < 0 means obey the current buffer's value of
20510 enable_multibyte_characters.
20512 Value is the number of columns displayed. */
20515 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
20516 EMACS_INT face_string_pos
, EMACS_INT start
, struct it
*it
,
20517 int field_width
, int precision
, int max_x
, int multibyte
)
20519 int hpos_at_start
= it
->hpos
;
20520 int saved_face_id
= it
->face_id
;
20521 struct glyph_row
*row
= it
->glyph_row
;
20522 EMACS_INT it_charpos
;
20524 /* Initialize the iterator IT for iteration over STRING beginning
20525 with index START. */
20526 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
20527 precision
, field_width
, multibyte
);
20528 if (string
&& STRINGP (lisp_string
))
20529 /* LISP_STRING is the one returned by decode_mode_spec. We should
20530 ignore its text properties. */
20531 it
->stop_charpos
= it
->end_charpos
;
20533 /* If displaying STRING, set up the face of the iterator from
20534 FACE_STRING, if that's given. */
20535 if (STRINGP (face_string
))
20541 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
20542 0, it
->region_beg_charpos
,
20543 it
->region_end_charpos
,
20544 &endptr
, it
->base_face_id
, 0);
20545 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20546 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
20549 /* Set max_x to the maximum allowed X position. Don't let it go
20550 beyond the right edge of the window. */
20552 max_x
= it
->last_visible_x
;
20554 max_x
= min (max_x
, it
->last_visible_x
);
20556 /* Skip over display elements that are not visible. because IT->w is
20558 if (it
->current_x
< it
->first_visible_x
)
20559 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
20560 MOVE_TO_POS
| MOVE_TO_X
);
20562 row
->ascent
= it
->max_ascent
;
20563 row
->height
= it
->max_ascent
+ it
->max_descent
;
20564 row
->phys_ascent
= it
->max_phys_ascent
;
20565 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20566 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20568 if (STRINGP (it
->string
))
20569 it_charpos
= IT_STRING_CHARPOS (*it
);
20571 it_charpos
= IT_CHARPOS (*it
);
20573 /* This condition is for the case that we are called with current_x
20574 past last_visible_x. */
20575 while (it
->current_x
< max_x
)
20577 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
20579 /* Get the next display element. */
20580 if (!get_next_display_element (it
))
20583 /* Produce glyphs. */
20584 x_before
= it
->current_x
;
20585 n_glyphs_before
= row
->used
[TEXT_AREA
];
20586 PRODUCE_GLYPHS (it
);
20588 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
20591 while (i
< nglyphs
)
20593 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20595 if (it
->line_wrap
!= TRUNCATE
20596 && x
+ glyph
->pixel_width
> max_x
)
20598 /* End of continued line or max_x reached. */
20599 if (CHAR_GLYPH_PADDING_P (*glyph
))
20601 /* A wide character is unbreakable. */
20602 if (row
->reversed_p
)
20603 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20604 - n_glyphs_before
);
20605 row
->used
[TEXT_AREA
] = n_glyphs_before
;
20606 it
->current_x
= x_before
;
20610 if (row
->reversed_p
)
20611 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20612 - (n_glyphs_before
+ i
));
20613 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20618 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
20620 /* Glyph is at least partially visible. */
20622 if (x
< it
->first_visible_x
)
20623 row
->x
= x
- it
->first_visible_x
;
20627 /* Glyph is off the left margin of the display area.
20628 Should not happen. */
20632 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20633 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20634 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20635 row
->phys_height
= max (row
->phys_height
,
20636 it
->max_phys_ascent
+ it
->max_phys_descent
);
20637 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20638 it
->max_extra_line_spacing
);
20639 x
+= glyph
->pixel_width
;
20643 /* Stop if max_x reached. */
20647 /* Stop at line ends. */
20648 if (ITERATOR_AT_END_OF_LINE_P (it
))
20650 it
->continuation_lines_width
= 0;
20654 set_iterator_to_next (it
, 1);
20655 if (STRINGP (it
->string
))
20656 it_charpos
= IT_STRING_CHARPOS (*it
);
20658 it_charpos
= IT_CHARPOS (*it
);
20660 /* Stop if truncating at the right edge. */
20661 if (it
->line_wrap
== TRUNCATE
20662 && it
->current_x
>= it
->last_visible_x
)
20664 /* Add truncation mark, but don't do it if the line is
20665 truncated at a padding space. */
20666 if (it_charpos
< it
->string_nchars
)
20668 if (!FRAME_WINDOW_P (it
->f
))
20672 if (it
->current_x
> it
->last_visible_x
)
20674 if (!row
->reversed_p
)
20676 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
20677 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20682 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
20683 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20685 unproduce_glyphs (it
, ii
+ 1);
20686 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
20688 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
20690 row
->used
[TEXT_AREA
] = ii
;
20691 produce_special_glyphs (it
, IT_TRUNCATION
);
20694 produce_special_glyphs (it
, IT_TRUNCATION
);
20696 row
->truncated_on_right_p
= 1;
20702 /* Maybe insert a truncation at the left. */
20703 if (it
->first_visible_x
20706 if (!FRAME_WINDOW_P (it
->f
))
20707 insert_left_trunc_glyphs (it
);
20708 row
->truncated_on_left_p
= 1;
20711 it
->face_id
= saved_face_id
;
20713 /* Value is number of columns displayed. */
20714 return it
->hpos
- hpos_at_start
;
20719 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
20720 appears as an element of LIST or as the car of an element of LIST.
20721 If PROPVAL is a list, compare each element against LIST in that
20722 way, and return 1/2 if any element of PROPVAL is found in LIST.
20723 Otherwise return 0. This function cannot quit.
20724 The return value is 2 if the text is invisible but with an ellipsis
20725 and 1 if it's invisible and without an ellipsis. */
20728 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
20730 register Lisp_Object tail
, proptail
;
20732 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20734 register Lisp_Object tem
;
20736 if (EQ (propval
, tem
))
20738 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
20739 return NILP (XCDR (tem
)) ? 1 : 2;
20742 if (CONSP (propval
))
20744 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
20746 Lisp_Object propelt
;
20747 propelt
= XCAR (proptail
);
20748 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20750 register Lisp_Object tem
;
20752 if (EQ (propelt
, tem
))
20754 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
20755 return NILP (XCDR (tem
)) ? 1 : 2;
20763 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
20764 doc
: /* Non-nil if the property makes the text invisible.
20765 POS-OR-PROP can be a marker or number, in which case it is taken to be
20766 a position in the current buffer and the value of the `invisible' property
20767 is checked; or it can be some other value, which is then presumed to be the
20768 value of the `invisible' property of the text of interest.
20769 The non-nil value returned can be t for truly invisible text or something
20770 else if the text is replaced by an ellipsis. */)
20771 (Lisp_Object pos_or_prop
)
20774 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
20775 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
20777 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
20778 return (invis
== 0 ? Qnil
20780 : make_number (invis
));
20783 /* Calculate a width or height in pixels from a specification using
20784 the following elements:
20787 NUM - a (fractional) multiple of the default font width/height
20788 (NUM) - specifies exactly NUM pixels
20789 UNIT - a fixed number of pixels, see below.
20790 ELEMENT - size of a display element in pixels, see below.
20791 (NUM . SPEC) - equals NUM * SPEC
20792 (+ SPEC SPEC ...) - add pixel values
20793 (- SPEC SPEC ...) - subtract pixel values
20794 (- SPEC) - negate pixel value
20797 INT or FLOAT - a number constant
20798 SYMBOL - use symbol's (buffer local) variable binding.
20801 in - pixels per inch *)
20802 mm - pixels per 1/1000 meter *)
20803 cm - pixels per 1/100 meter *)
20804 width - width of current font in pixels.
20805 height - height of current font in pixels.
20807 *) using the ratio(s) defined in display-pixels-per-inch.
20811 left-fringe - left fringe width in pixels
20812 right-fringe - right fringe width in pixels
20814 left-margin - left margin width in pixels
20815 right-margin - right margin width in pixels
20817 scroll-bar - scroll-bar area width in pixels
20821 Pixels corresponding to 5 inches:
20824 Total width of non-text areas on left side of window (if scroll-bar is on left):
20825 '(space :width (+ left-fringe left-margin scroll-bar))
20827 Align to first text column (in header line):
20828 '(space :align-to 0)
20830 Align to middle of text area minus half the width of variable `my-image'
20831 containing a loaded image:
20832 '(space :align-to (0.5 . (- text my-image)))
20834 Width of left margin minus width of 1 character in the default font:
20835 '(space :width (- left-margin 1))
20837 Width of left margin minus width of 2 characters in the current font:
20838 '(space :width (- left-margin (2 . width)))
20840 Center 1 character over left-margin (in header line):
20841 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
20843 Different ways to express width of left fringe plus left margin minus one pixel:
20844 '(space :width (- (+ left-fringe left-margin) (1)))
20845 '(space :width (+ left-fringe left-margin (- (1))))
20846 '(space :width (+ left-fringe left-margin (-1)))
20850 #define NUMVAL(X) \
20851 ((INTEGERP (X) || FLOATP (X)) \
20856 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
20857 struct font
*font
, int width_p
, int *align_to
)
20861 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20862 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20865 return OK_PIXELS (0);
20867 xassert (FRAME_LIVE_P (it
->f
));
20869 if (SYMBOLP (prop
))
20871 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20873 char *unit
= SSDATA (SYMBOL_NAME (prop
));
20875 if (unit
[0] == 'i' && unit
[1] == 'n')
20877 else if (unit
[0] == 'm' && unit
[1] == 'm')
20879 else if (unit
[0] == 'c' && unit
[1] == 'm')
20886 #ifdef HAVE_WINDOW_SYSTEM
20887 if (FRAME_WINDOW_P (it
->f
)
20889 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20890 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20892 return OK_PIXELS (ppi
/ pixels
);
20895 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20896 || (CONSP (Vdisplay_pixels_per_inch
)
20898 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20899 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20901 return OK_PIXELS (ppi
/ pixels
);
20907 #ifdef HAVE_WINDOW_SYSTEM
20908 if (EQ (prop
, Qheight
))
20909 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20910 if (EQ (prop
, Qwidth
))
20911 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20913 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20914 return OK_PIXELS (1);
20917 if (EQ (prop
, Qtext
))
20918 return OK_PIXELS (width_p
20919 ? window_box_width (it
->w
, TEXT_AREA
)
20920 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20922 if (align_to
&& *align_to
< 0)
20925 if (EQ (prop
, Qleft
))
20926 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20927 if (EQ (prop
, Qright
))
20928 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20929 if (EQ (prop
, Qcenter
))
20930 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20931 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20932 if (EQ (prop
, Qleft_fringe
))
20933 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20934 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20935 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20936 if (EQ (prop
, Qright_fringe
))
20937 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20938 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20939 : window_box_right_offset (it
->w
, TEXT_AREA
));
20940 if (EQ (prop
, Qleft_margin
))
20941 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20942 if (EQ (prop
, Qright_margin
))
20943 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20944 if (EQ (prop
, Qscroll_bar
))
20945 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20947 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20948 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20949 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20954 if (EQ (prop
, Qleft_fringe
))
20955 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20956 if (EQ (prop
, Qright_fringe
))
20957 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20958 if (EQ (prop
, Qleft_margin
))
20959 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20960 if (EQ (prop
, Qright_margin
))
20961 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20962 if (EQ (prop
, Qscroll_bar
))
20963 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20966 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20969 if (INTEGERP (prop
) || FLOATP (prop
))
20971 int base_unit
= (width_p
20972 ? FRAME_COLUMN_WIDTH (it
->f
)
20973 : FRAME_LINE_HEIGHT (it
->f
));
20974 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
20979 Lisp_Object car
= XCAR (prop
);
20980 Lisp_Object cdr
= XCDR (prop
);
20984 #ifdef HAVE_WINDOW_SYSTEM
20985 if (FRAME_WINDOW_P (it
->f
)
20986 && valid_image_p (prop
))
20988 int id
= lookup_image (it
->f
, prop
);
20989 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
20991 return OK_PIXELS (width_p
? img
->width
: img
->height
);
20994 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
21000 while (CONSP (cdr
))
21002 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
21003 font
, width_p
, align_to
))
21006 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
21011 if (EQ (car
, Qminus
))
21013 return OK_PIXELS (pixels
);
21016 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
21019 if (INTEGERP (car
) || FLOATP (car
))
21022 pixels
= XFLOATINT (car
);
21024 return OK_PIXELS (pixels
);
21025 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
21026 font
, width_p
, align_to
))
21027 return OK_PIXELS (pixels
* fact
);
21038 /***********************************************************************
21040 ***********************************************************************/
21042 #ifdef HAVE_WINDOW_SYSTEM
21047 dump_glyph_string (s
)
21048 struct glyph_string
*s
;
21050 fprintf (stderr
, "glyph string\n");
21051 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
21052 s
->x
, s
->y
, s
->width
, s
->height
);
21053 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
21054 fprintf (stderr
, " hl = %d\n", s
->hl
);
21055 fprintf (stderr
, " left overhang = %d, right = %d\n",
21056 s
->left_overhang
, s
->right_overhang
);
21057 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
21058 fprintf (stderr
, " extends to end of line = %d\n",
21059 s
->extends_to_end_of_line_p
);
21060 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
21061 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
21064 #endif /* GLYPH_DEBUG */
21066 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
21067 of XChar2b structures for S; it can't be allocated in
21068 init_glyph_string because it must be allocated via `alloca'. W
21069 is the window on which S is drawn. ROW and AREA are the glyph row
21070 and area within the row from which S is constructed. START is the
21071 index of the first glyph structure covered by S. HL is a
21072 face-override for drawing S. */
21075 #define OPTIONAL_HDC(hdc) HDC hdc,
21076 #define DECLARE_HDC(hdc) HDC hdc;
21077 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
21078 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
21081 #ifndef OPTIONAL_HDC
21082 #define OPTIONAL_HDC(hdc)
21083 #define DECLARE_HDC(hdc)
21084 #define ALLOCATE_HDC(hdc, f)
21085 #define RELEASE_HDC(hdc, f)
21089 init_glyph_string (struct glyph_string
*s
,
21091 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
21092 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
21094 memset (s
, 0, sizeof *s
);
21096 s
->f
= XFRAME (w
->frame
);
21100 s
->display
= FRAME_X_DISPLAY (s
->f
);
21101 s
->window
= FRAME_X_WINDOW (s
->f
);
21102 s
->char2b
= char2b
;
21106 s
->first_glyph
= row
->glyphs
[area
] + start
;
21107 s
->height
= row
->height
;
21108 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
21109 s
->ybase
= s
->y
+ row
->ascent
;
21113 /* Append the list of glyph strings with head H and tail T to the list
21114 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
21117 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
21118 struct glyph_string
*h
, struct glyph_string
*t
)
21132 /* Prepend the list of glyph strings with head H and tail T to the
21133 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
21137 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
21138 struct glyph_string
*h
, struct glyph_string
*t
)
21152 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
21153 Set *HEAD and *TAIL to the resulting list. */
21156 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
21157 struct glyph_string
*s
)
21159 s
->next
= s
->prev
= NULL
;
21160 append_glyph_string_lists (head
, tail
, s
, s
);
21164 /* Get face and two-byte form of character C in face FACE_ID on frame F.
21165 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
21166 make sure that X resources for the face returned are allocated.
21167 Value is a pointer to a realized face that is ready for display if
21168 DISPLAY_P is non-zero. */
21170 static INLINE
struct face
*
21171 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
21172 XChar2b
*char2b
, int display_p
)
21174 struct face
*face
= FACE_FROM_ID (f
, face_id
);
21178 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
21180 if (code
!= FONT_INVALID_CODE
)
21181 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21183 STORE_XCHAR2B (char2b
, 0, 0);
21186 /* Make sure X resources of the face are allocated. */
21187 #ifdef HAVE_X_WINDOWS
21191 xassert (face
!= NULL
);
21192 PREPARE_FACE_FOR_DISPLAY (f
, face
);
21199 /* Get face and two-byte form of character glyph GLYPH on frame F.
21200 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
21201 a pointer to a realized face that is ready for display. */
21203 static INLINE
struct face
*
21204 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
21205 XChar2b
*char2b
, int *two_byte_p
)
21209 xassert (glyph
->type
== CHAR_GLYPH
);
21210 face
= FACE_FROM_ID (f
, glyph
->face_id
);
21219 if (CHAR_BYTE8_P (glyph
->u
.ch
))
21220 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
21222 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
21224 if (code
!= FONT_INVALID_CODE
)
21225 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21227 STORE_XCHAR2B (char2b
, 0, 0);
21230 /* Make sure X resources of the face are allocated. */
21231 xassert (face
!= NULL
);
21232 PREPARE_FACE_FOR_DISPLAY (f
, face
);
21237 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
21238 Retunr 1 if FONT has a glyph for C, otherwise return 0. */
21241 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
21245 if (CHAR_BYTE8_P (c
))
21246 code
= CHAR_TO_BYTE8 (c
);
21248 code
= font
->driver
->encode_char (font
, c
);
21250 if (code
== FONT_INVALID_CODE
)
21252 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21257 /* Fill glyph string S with composition components specified by S->cmp.
21259 BASE_FACE is the base face of the composition.
21260 S->cmp_from is the index of the first component for S.
21262 OVERLAPS non-zero means S should draw the foreground only, and use
21263 its physical height for clipping. See also draw_glyphs.
21265 Value is the index of a component not in S. */
21268 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
21272 /* For all glyphs of this composition, starting at the offset
21273 S->cmp_from, until we reach the end of the definition or encounter a
21274 glyph that requires the different face, add it to S. */
21279 s
->for_overlaps
= overlaps
;
21282 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
21284 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
21288 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
21291 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
21298 s
->font
= s
->face
->font
;
21300 else if (s
->face
!= face
)
21308 /* All glyph strings for the same composition has the same width,
21309 i.e. the width set for the first component of the composition. */
21310 s
->width
= s
->first_glyph
->pixel_width
;
21312 /* If the specified font could not be loaded, use the frame's
21313 default font, but record the fact that we couldn't load it in
21314 the glyph string so that we can draw rectangles for the
21315 characters of the glyph string. */
21316 if (s
->font
== NULL
)
21318 s
->font_not_found_p
= 1;
21319 s
->font
= FRAME_FONT (s
->f
);
21322 /* Adjust base line for subscript/superscript text. */
21323 s
->ybase
+= s
->first_glyph
->voffset
;
21325 /* This glyph string must always be drawn with 16-bit functions. */
21332 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
21333 int start
, int end
, int overlaps
)
21335 struct glyph
*glyph
, *last
;
21336 Lisp_Object lgstring
;
21339 s
->for_overlaps
= overlaps
;
21340 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21341 last
= s
->row
->glyphs
[s
->area
] + end
;
21342 s
->cmp_id
= glyph
->u
.cmp
.id
;
21343 s
->cmp_from
= glyph
->slice
.cmp
.from
;
21344 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
21345 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21346 lgstring
= composition_gstring_from_id (s
->cmp_id
);
21347 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
21349 while (glyph
< last
21350 && glyph
->u
.cmp
.automatic
21351 && glyph
->u
.cmp
.id
== s
->cmp_id
21352 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
21353 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
21355 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
21357 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
21358 unsigned code
= LGLYPH_CODE (lglyph
);
21360 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
21362 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
21363 return glyph
- s
->row
->glyphs
[s
->area
];
21367 /* Fill glyph string S from a sequence glyphs for glyphless characters.
21368 See the comment of fill_glyph_string for arguments.
21369 Value is the index of the first glyph not in S. */
21373 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
21374 int start
, int end
, int overlaps
)
21376 struct glyph
*glyph
, *last
;
21379 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
21380 s
->for_overlaps
= overlaps
;
21381 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21382 last
= s
->row
->glyphs
[s
->area
] + end
;
21383 voffset
= glyph
->voffset
;
21384 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21385 s
->font
= s
->face
->font
;
21387 s
->width
= glyph
->pixel_width
;
21389 while (glyph
< last
21390 && glyph
->type
== GLYPHLESS_GLYPH
21391 && glyph
->voffset
== voffset
21392 && glyph
->face_id
== face_id
)
21395 s
->width
+= glyph
->pixel_width
;
21398 s
->ybase
+= voffset
;
21399 return glyph
- s
->row
->glyphs
[s
->area
];
21403 /* Fill glyph string S from a sequence of character glyphs.
21405 FACE_ID is the face id of the string. START is the index of the
21406 first glyph to consider, END is the index of the last + 1.
21407 OVERLAPS non-zero means S should draw the foreground only, and use
21408 its physical height for clipping. See also draw_glyphs.
21410 Value is the index of the first glyph not in S. */
21413 fill_glyph_string (struct glyph_string
*s
, int face_id
,
21414 int start
, int end
, int overlaps
)
21416 struct glyph
*glyph
, *last
;
21418 int glyph_not_available_p
;
21420 xassert (s
->f
== XFRAME (s
->w
->frame
));
21421 xassert (s
->nchars
== 0);
21422 xassert (start
>= 0 && end
> start
);
21424 s
->for_overlaps
= overlaps
;
21425 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21426 last
= s
->row
->glyphs
[s
->area
] + end
;
21427 voffset
= glyph
->voffset
;
21428 s
->padding_p
= glyph
->padding_p
;
21429 glyph_not_available_p
= glyph
->glyph_not_available_p
;
21431 while (glyph
< last
21432 && glyph
->type
== CHAR_GLYPH
21433 && glyph
->voffset
== voffset
21434 /* Same face id implies same font, nowadays. */
21435 && glyph
->face_id
== face_id
21436 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
21440 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
21441 s
->char2b
+ s
->nchars
,
21443 s
->two_byte_p
= two_byte_p
;
21445 xassert (s
->nchars
<= end
- start
);
21446 s
->width
+= glyph
->pixel_width
;
21447 if (glyph
++->padding_p
!= s
->padding_p
)
21451 s
->font
= s
->face
->font
;
21453 /* If the specified font could not be loaded, use the frame's font,
21454 but record the fact that we couldn't load it in
21455 S->font_not_found_p so that we can draw rectangles for the
21456 characters of the glyph string. */
21457 if (s
->font
== NULL
|| glyph_not_available_p
)
21459 s
->font_not_found_p
= 1;
21460 s
->font
= FRAME_FONT (s
->f
);
21463 /* Adjust base line for subscript/superscript text. */
21464 s
->ybase
+= voffset
;
21466 xassert (s
->face
&& s
->face
->gc
);
21467 return glyph
- s
->row
->glyphs
[s
->area
];
21471 /* Fill glyph string S from image glyph S->first_glyph. */
21474 fill_image_glyph_string (struct glyph_string
*s
)
21476 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
21477 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
21479 s
->slice
= s
->first_glyph
->slice
.img
;
21480 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
21481 s
->font
= s
->face
->font
;
21482 s
->width
= s
->first_glyph
->pixel_width
;
21484 /* Adjust base line for subscript/superscript text. */
21485 s
->ybase
+= s
->first_glyph
->voffset
;
21489 /* Fill glyph string S from a sequence of stretch glyphs.
21491 START is the index of the first glyph to consider,
21492 END is the index of the last + 1.
21494 Value is the index of the first glyph not in S. */
21497 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
21499 struct glyph
*glyph
, *last
;
21500 int voffset
, face_id
;
21502 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
21504 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21505 last
= s
->row
->glyphs
[s
->area
] + end
;
21506 face_id
= glyph
->face_id
;
21507 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21508 s
->font
= s
->face
->font
;
21509 s
->width
= glyph
->pixel_width
;
21511 voffset
= glyph
->voffset
;
21515 && glyph
->type
== STRETCH_GLYPH
21516 && glyph
->voffset
== voffset
21517 && glyph
->face_id
== face_id
);
21519 s
->width
+= glyph
->pixel_width
;
21521 /* Adjust base line for subscript/superscript text. */
21522 s
->ybase
+= voffset
;
21524 /* The case that face->gc == 0 is handled when drawing the glyph
21525 string by calling PREPARE_FACE_FOR_DISPLAY. */
21527 return glyph
- s
->row
->glyphs
[s
->area
];
21530 static struct font_metrics
*
21531 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
21533 static struct font_metrics metrics
;
21534 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
21536 if (! font
|| code
== FONT_INVALID_CODE
)
21538 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
21543 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
21544 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
21545 assumed to be zero. */
21548 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
21550 *left
= *right
= 0;
21552 if (glyph
->type
== CHAR_GLYPH
)
21556 struct font_metrics
*pcm
;
21558 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
21559 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
21561 if (pcm
->rbearing
> pcm
->width
)
21562 *right
= pcm
->rbearing
- pcm
->width
;
21563 if (pcm
->lbearing
< 0)
21564 *left
= -pcm
->lbearing
;
21567 else if (glyph
->type
== COMPOSITE_GLYPH
)
21569 if (! glyph
->u
.cmp
.automatic
)
21571 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
21573 if (cmp
->rbearing
> cmp
->pixel_width
)
21574 *right
= cmp
->rbearing
- cmp
->pixel_width
;
21575 if (cmp
->lbearing
< 0)
21576 *left
= - cmp
->lbearing
;
21580 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
21581 struct font_metrics metrics
;
21583 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
21584 glyph
->slice
.cmp
.to
+ 1, &metrics
);
21585 if (metrics
.rbearing
> metrics
.width
)
21586 *right
= metrics
.rbearing
- metrics
.width
;
21587 if (metrics
.lbearing
< 0)
21588 *left
= - metrics
.lbearing
;
21594 /* Return the index of the first glyph preceding glyph string S that
21595 is overwritten by S because of S's left overhang. Value is -1
21596 if no glyphs are overwritten. */
21599 left_overwritten (struct glyph_string
*s
)
21603 if (s
->left_overhang
)
21606 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21607 int first
= s
->first_glyph
- glyphs
;
21609 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
21610 x
-= glyphs
[i
].pixel_width
;
21621 /* Return the index of the first glyph preceding glyph string S that
21622 is overwriting S because of its right overhang. Value is -1 if no
21623 glyph in front of S overwrites S. */
21626 left_overwriting (struct glyph_string
*s
)
21629 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21630 int first
= s
->first_glyph
- glyphs
;
21634 for (i
= first
- 1; i
>= 0; --i
)
21637 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21640 x
-= glyphs
[i
].pixel_width
;
21647 /* Return the index of the last glyph following glyph string S that is
21648 overwritten by S because of S's right overhang. Value is -1 if
21649 no such glyph is found. */
21652 right_overwritten (struct glyph_string
*s
)
21656 if (s
->right_overhang
)
21659 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21660 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21661 int end
= s
->row
->used
[s
->area
];
21663 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
21664 x
+= glyphs
[i
].pixel_width
;
21673 /* Return the index of the last glyph following glyph string S that
21674 overwrites S because of its left overhang. Value is negative
21675 if no such glyph is found. */
21678 right_overwriting (struct glyph_string
*s
)
21681 int end
= s
->row
->used
[s
->area
];
21682 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21683 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21687 for (i
= first
; i
< end
; ++i
)
21690 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21693 x
+= glyphs
[i
].pixel_width
;
21700 /* Set background width of glyph string S. START is the index of the
21701 first glyph following S. LAST_X is the right-most x-position + 1
21702 in the drawing area. */
21705 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
21707 /* If the face of this glyph string has to be drawn to the end of
21708 the drawing area, set S->extends_to_end_of_line_p. */
21710 if (start
== s
->row
->used
[s
->area
]
21711 && s
->area
== TEXT_AREA
21712 && ((s
->row
->fill_line_p
21713 && (s
->hl
== DRAW_NORMAL_TEXT
21714 || s
->hl
== DRAW_IMAGE_RAISED
21715 || s
->hl
== DRAW_IMAGE_SUNKEN
))
21716 || s
->hl
== DRAW_MOUSE_FACE
))
21717 s
->extends_to_end_of_line_p
= 1;
21719 /* If S extends its face to the end of the line, set its
21720 background_width to the distance to the right edge of the drawing
21722 if (s
->extends_to_end_of_line_p
)
21723 s
->background_width
= last_x
- s
->x
+ 1;
21725 s
->background_width
= s
->width
;
21729 /* Compute overhangs and x-positions for glyph string S and its
21730 predecessors, or successors. X is the starting x-position for S.
21731 BACKWARD_P non-zero means process predecessors. */
21734 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
21740 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21741 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21751 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21752 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21762 /* The following macros are only called from draw_glyphs below.
21763 They reference the following parameters of that function directly:
21764 `w', `row', `area', and `overlap_p'
21765 as well as the following local variables:
21766 `s', `f', and `hdc' (in W32) */
21769 /* On W32, silently add local `hdc' variable to argument list of
21770 init_glyph_string. */
21771 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21772 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
21774 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21775 init_glyph_string (s, char2b, w, row, area, start, hl)
21778 /* Add a glyph string for a stretch glyph to the list of strings
21779 between HEAD and TAIL. START is the index of the stretch glyph in
21780 row area AREA of glyph row ROW. END is the index of the last glyph
21781 in that glyph row area. X is the current output position assigned
21782 to the new glyph string constructed. HL overrides that face of the
21783 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21784 is the right-most x-position of the drawing area. */
21786 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
21787 and below -- keep them on one line. */
21788 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21791 s = (struct glyph_string *) alloca (sizeof *s); \
21792 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21793 START = fill_stretch_glyph_string (s, START, END); \
21794 append_glyph_string (&HEAD, &TAIL, s); \
21800 /* Add a glyph string for an image glyph to the list of strings
21801 between HEAD and TAIL. START is the index of the image 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 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21811 s = (struct glyph_string *) alloca (sizeof *s); \
21812 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21813 fill_image_glyph_string (s); \
21814 append_glyph_string (&HEAD, &TAIL, s); \
21821 /* Add a glyph string for a sequence of character glyphs to the list
21822 of strings between HEAD and TAIL. START is the index of the first
21823 glyph in row area AREA of glyph row ROW that is part of the new
21824 glyph string. END is the index of the last glyph in that glyph row
21825 area. X is the current output position assigned to the new glyph
21826 string constructed. HL overrides that face of the glyph; e.g. it
21827 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
21828 right-most x-position of the drawing area. */
21830 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21836 face_id = (row)->glyphs[area][START].face_id; \
21838 s = (struct glyph_string *) alloca (sizeof *s); \
21839 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
21840 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21841 append_glyph_string (&HEAD, &TAIL, s); \
21843 START = fill_glyph_string (s, face_id, START, END, overlaps); \
21848 /* Add a glyph string for a composite sequence to the list of strings
21849 between HEAD and TAIL. START is the index of the first glyph in
21850 row area AREA of glyph row ROW that is part of the new glyph
21851 string. END is the index of the last glyph in that glyph row area.
21852 X is the current output position assigned to the new glyph string
21853 constructed. HL overrides that face of the glyph; e.g. it is
21854 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
21855 x-position of the drawing area. */
21857 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21859 int face_id = (row)->glyphs[area][START].face_id; \
21860 struct face *base_face = FACE_FROM_ID (f, face_id); \
21861 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
21862 struct composition *cmp = composition_table[cmp_id]; \
21864 struct glyph_string *first_s IF_LINT (= NULL); \
21867 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21869 /* Make glyph_strings for each glyph sequence that is drawable by \
21870 the same face, and append them to HEAD/TAIL. */ \
21871 for (n = 0; n < cmp->glyph_len;) \
21873 s = (struct glyph_string *) alloca (sizeof *s); \
21874 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21875 append_glyph_string (&(HEAD), &(TAIL), s); \
21881 n = fill_composite_glyph_string (s, base_face, overlaps); \
21889 /* Add a glyph string for a glyph-string sequence to the list of strings
21890 between HEAD and TAIL. */
21892 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21896 Lisp_Object gstring; \
21898 face_id = (row)->glyphs[area][START].face_id; \
21899 gstring = (composition_gstring_from_id \
21900 ((row)->glyphs[area][START].u.cmp.id)); \
21901 s = (struct glyph_string *) alloca (sizeof *s); \
21902 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21903 * LGSTRING_GLYPH_LEN (gstring)); \
21904 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21905 append_glyph_string (&(HEAD), &(TAIL), s); \
21907 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21911 /* Add a glyph string for a sequence of glyphless character's glyphs
21912 to the list of strings between HEAD and TAIL. The meanings of
21913 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
21915 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21920 face_id = (row)->glyphs[area][START].face_id; \
21922 s = (struct glyph_string *) alloca (sizeof *s); \
21923 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21924 append_glyph_string (&HEAD, &TAIL, s); \
21926 START = fill_glyphless_glyph_string (s, face_id, START, END, \
21932 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21933 of AREA of glyph row ROW on window W between indices START and END.
21934 HL overrides the face for drawing glyph strings, e.g. it is
21935 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21936 x-positions of the drawing area.
21938 This is an ugly monster macro construct because we must use alloca
21939 to allocate glyph strings (because draw_glyphs can be called
21940 asynchronously). */
21942 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21945 HEAD = TAIL = NULL; \
21946 while (START < END) \
21948 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21949 switch (first_glyph->type) \
21952 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21956 case COMPOSITE_GLYPH: \
21957 if (first_glyph->u.cmp.automatic) \
21958 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21961 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21965 case STRETCH_GLYPH: \
21966 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21970 case IMAGE_GLYPH: \
21971 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21975 case GLYPHLESS_GLYPH: \
21976 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
21986 set_glyph_string_background_width (s, START, LAST_X); \
21993 /* Draw glyphs between START and END in AREA of ROW on window W,
21994 starting at x-position X. X is relative to AREA in W. HL is a
21995 face-override with the following meaning:
21997 DRAW_NORMAL_TEXT draw normally
21998 DRAW_CURSOR draw in cursor face
21999 DRAW_MOUSE_FACE draw in mouse face.
22000 DRAW_INVERSE_VIDEO draw in mode line face
22001 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
22002 DRAW_IMAGE_RAISED draw an image with a raised relief around it
22004 If OVERLAPS is non-zero, draw only the foreground of characters and
22005 clip to the physical height of ROW. Non-zero value also defines
22006 the overlapping part to be drawn:
22008 OVERLAPS_PRED overlap with preceding rows
22009 OVERLAPS_SUCC overlap with succeeding rows
22010 OVERLAPS_BOTH overlap with both preceding/succeeding rows
22011 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
22013 Value is the x-position reached, relative to AREA of W. */
22016 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
22017 enum glyph_row_area area
, EMACS_INT start
, EMACS_INT end
,
22018 enum draw_glyphs_face hl
, int overlaps
)
22020 struct glyph_string
*head
, *tail
;
22021 struct glyph_string
*s
;
22022 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
22023 int i
, j
, x_reached
, last_x
, area_left
= 0;
22024 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22027 ALLOCATE_HDC (hdc
, f
);
22029 /* Let's rather be paranoid than getting a SEGV. */
22030 end
= min (end
, row
->used
[area
]);
22031 start
= max (0, start
);
22032 start
= min (end
, start
);
22034 /* Translate X to frame coordinates. Set last_x to the right
22035 end of the drawing area. */
22036 if (row
->full_width_p
)
22038 /* X is relative to the left edge of W, without scroll bars
22040 area_left
= WINDOW_LEFT_EDGE_X (w
);
22041 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
22045 area_left
= window_box_left (w
, area
);
22046 last_x
= area_left
+ window_box_width (w
, area
);
22050 /* Build a doubly-linked list of glyph_string structures between
22051 head and tail from what we have to draw. Note that the macro
22052 BUILD_GLYPH_STRINGS will modify its start parameter. That's
22053 the reason we use a separate variable `i'. */
22055 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
22057 x_reached
= tail
->x
+ tail
->background_width
;
22061 /* If there are any glyphs with lbearing < 0 or rbearing > width in
22062 the row, redraw some glyphs in front or following the glyph
22063 strings built above. */
22064 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
22066 struct glyph_string
*h
, *t
;
22067 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
22068 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
22069 int check_mouse_face
= 0;
22072 /* If mouse highlighting is on, we may need to draw adjacent
22073 glyphs using mouse-face highlighting. */
22074 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
22076 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
22078 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
22079 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
22081 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
22083 check_mouse_face
= 1;
22084 mouse_beg_col
= (row
== mouse_beg_row
)
22085 ? hlinfo
->mouse_face_beg_col
: 0;
22086 mouse_end_col
= (row
== mouse_end_row
)
22087 ? hlinfo
->mouse_face_end_col
22088 : row
->used
[TEXT_AREA
];
22092 /* Compute overhangs for all glyph strings. */
22093 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
22094 for (s
= head
; s
; s
= s
->next
)
22095 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
22097 /* Prepend glyph strings for glyphs in front of the first glyph
22098 string that are overwritten because of the first glyph
22099 string's left overhang. The background of all strings
22100 prepended must be drawn because the first glyph string
22102 i
= left_overwritten (head
);
22105 enum draw_glyphs_face overlap_hl
;
22107 /* If this row contains mouse highlighting, attempt to draw
22108 the overlapped glyphs with the correct highlight. This
22109 code fails if the overlap encompasses more than one glyph
22110 and mouse-highlight spans only some of these glyphs.
22111 However, making it work perfectly involves a lot more
22112 code, and I don't know if the pathological case occurs in
22113 practice, so we'll stick to this for now. --- cyd */
22114 if (check_mouse_face
22115 && mouse_beg_col
< start
&& mouse_end_col
> i
)
22116 overlap_hl
= DRAW_MOUSE_FACE
;
22118 overlap_hl
= DRAW_NORMAL_TEXT
;
22121 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
22122 overlap_hl
, dummy_x
, last_x
);
22124 compute_overhangs_and_x (t
, head
->x
, 1);
22125 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
22129 /* Prepend glyph strings for glyphs in front of the first glyph
22130 string that overwrite that glyph string because of their
22131 right overhang. For these strings, only the foreground must
22132 be drawn, because it draws over the glyph string at `head'.
22133 The background must not be drawn because this would overwrite
22134 right overhangs of preceding glyphs for which no glyph
22136 i
= left_overwriting (head
);
22139 enum draw_glyphs_face overlap_hl
;
22141 if (check_mouse_face
22142 && mouse_beg_col
< start
&& mouse_end_col
> i
)
22143 overlap_hl
= DRAW_MOUSE_FACE
;
22145 overlap_hl
= DRAW_NORMAL_TEXT
;
22148 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
22149 overlap_hl
, dummy_x
, last_x
);
22150 for (s
= h
; s
; s
= s
->next
)
22151 s
->background_filled_p
= 1;
22152 compute_overhangs_and_x (t
, head
->x
, 1);
22153 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
22156 /* Append glyphs strings for glyphs following the last glyph
22157 string tail that are overwritten by tail. The background of
22158 these strings has to be drawn because tail's foreground draws
22160 i
= right_overwritten (tail
);
22163 enum draw_glyphs_face overlap_hl
;
22165 if (check_mouse_face
22166 && mouse_beg_col
< i
&& mouse_end_col
> end
)
22167 overlap_hl
= DRAW_MOUSE_FACE
;
22169 overlap_hl
= DRAW_NORMAL_TEXT
;
22171 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
22172 overlap_hl
, x
, last_x
);
22173 /* Because BUILD_GLYPH_STRINGS updates the first argument,
22174 we don't have `end = i;' here. */
22175 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
22176 append_glyph_string_lists (&head
, &tail
, h
, t
);
22180 /* Append glyph strings for glyphs following the last glyph
22181 string tail that overwrite tail. The foreground of such
22182 glyphs has to be drawn because it writes into the background
22183 of tail. The background must not be drawn because it could
22184 paint over the foreground of following glyphs. */
22185 i
= right_overwriting (tail
);
22188 enum draw_glyphs_face overlap_hl
;
22189 if (check_mouse_face
22190 && mouse_beg_col
< i
&& mouse_end_col
> end
)
22191 overlap_hl
= DRAW_MOUSE_FACE
;
22193 overlap_hl
= DRAW_NORMAL_TEXT
;
22196 i
++; /* We must include the Ith glyph. */
22197 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
22198 overlap_hl
, x
, last_x
);
22199 for (s
= h
; s
; s
= s
->next
)
22200 s
->background_filled_p
= 1;
22201 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
22202 append_glyph_string_lists (&head
, &tail
, h
, t
);
22204 if (clip_head
|| clip_tail
)
22205 for (s
= head
; s
; s
= s
->next
)
22207 s
->clip_head
= clip_head
;
22208 s
->clip_tail
= clip_tail
;
22212 /* Draw all strings. */
22213 for (s
= head
; s
; s
= s
->next
)
22214 FRAME_RIF (f
)->draw_glyph_string (s
);
22217 /* When focus a sole frame and move horizontally, this sets on_p to 0
22218 causing a failure to erase prev cursor position. */
22219 if (area
== TEXT_AREA
22220 && !row
->full_width_p
22221 /* When drawing overlapping rows, only the glyph strings'
22222 foreground is drawn, which doesn't erase a cursor
22226 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
22227 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
22228 : (tail
? tail
->x
+ tail
->background_width
: x
));
22232 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
22233 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
22237 /* Value is the x-position up to which drawn, relative to AREA of W.
22238 This doesn't include parts drawn because of overhangs. */
22239 if (row
->full_width_p
)
22240 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
22242 x_reached
-= area_left
;
22244 RELEASE_HDC (hdc
, f
);
22249 /* Expand row matrix if too narrow. Don't expand if area
22252 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
22254 if (!fonts_changed_p \
22255 && (it->glyph_row->glyphs[area] \
22256 < it->glyph_row->glyphs[area + 1])) \
22258 it->w->ncols_scale_factor++; \
22259 fonts_changed_p = 1; \
22263 /* Store one glyph for IT->char_to_display in IT->glyph_row.
22264 Called from x_produce_glyphs when IT->glyph_row is non-null. */
22267 append_glyph (struct it
*it
)
22269 struct glyph
*glyph
;
22270 enum glyph_row_area area
= it
->area
;
22272 xassert (it
->glyph_row
);
22273 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
22275 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22276 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22278 /* If the glyph row is reversed, we need to prepend the glyph
22279 rather than append it. */
22280 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22284 /* Make room for the additional glyph. */
22285 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22287 glyph
= it
->glyph_row
->glyphs
[area
];
22289 glyph
->charpos
= CHARPOS (it
->position
);
22290 glyph
->object
= it
->object
;
22291 if (it
->pixel_width
> 0)
22293 glyph
->pixel_width
= it
->pixel_width
;
22294 glyph
->padding_p
= 0;
22298 /* Assure at least 1-pixel width. Otherwise, cursor can't
22299 be displayed correctly. */
22300 glyph
->pixel_width
= 1;
22301 glyph
->padding_p
= 1;
22303 glyph
->ascent
= it
->ascent
;
22304 glyph
->descent
= it
->descent
;
22305 glyph
->voffset
= it
->voffset
;
22306 glyph
->type
= CHAR_GLYPH
;
22307 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22308 glyph
->multibyte_p
= it
->multibyte_p
;
22309 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22310 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22311 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22312 || it
->phys_descent
> it
->descent
);
22313 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
22314 glyph
->face_id
= it
->face_id
;
22315 glyph
->u
.ch
= it
->char_to_display
;
22316 glyph
->slice
.img
= null_glyph_slice
;
22317 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22320 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22321 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22323 glyph
->bidi_type
= it
->bidi_it
.type
;
22327 glyph
->resolved_level
= 0;
22328 glyph
->bidi_type
= UNKNOWN_BT
;
22330 ++it
->glyph_row
->used
[area
];
22333 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22336 /* Store one glyph for the composition IT->cmp_it.id in
22337 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
22341 append_composite_glyph (struct it
*it
)
22343 struct glyph
*glyph
;
22344 enum glyph_row_area area
= it
->area
;
22346 xassert (it
->glyph_row
);
22348 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22349 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22351 /* If the glyph row is reversed, we need to prepend the glyph
22352 rather than append it. */
22353 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
22357 /* Make room for the new glyph. */
22358 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
22360 glyph
= it
->glyph_row
->glyphs
[it
->area
];
22362 glyph
->charpos
= it
->cmp_it
.charpos
;
22363 glyph
->object
= it
->object
;
22364 glyph
->pixel_width
= it
->pixel_width
;
22365 glyph
->ascent
= it
->ascent
;
22366 glyph
->descent
= it
->descent
;
22367 glyph
->voffset
= it
->voffset
;
22368 glyph
->type
= COMPOSITE_GLYPH
;
22369 if (it
->cmp_it
.ch
< 0)
22371 glyph
->u
.cmp
.automatic
= 0;
22372 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
22373 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
22377 glyph
->u
.cmp
.automatic
= 1;
22378 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
22379 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
22380 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
22382 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22383 glyph
->multibyte_p
= it
->multibyte_p
;
22384 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22385 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22386 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22387 || it
->phys_descent
> it
->descent
);
22388 glyph
->padding_p
= 0;
22389 glyph
->glyph_not_available_p
= 0;
22390 glyph
->face_id
= it
->face_id
;
22391 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22394 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22395 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22397 glyph
->bidi_type
= it
->bidi_it
.type
;
22399 ++it
->glyph_row
->used
[area
];
22402 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22406 /* Change IT->ascent and IT->height according to the setting of
22410 take_vertical_position_into_account (struct it
*it
)
22414 if (it
->voffset
< 0)
22415 /* Increase the ascent so that we can display the text higher
22417 it
->ascent
-= it
->voffset
;
22419 /* Increase the descent so that we can display the text lower
22421 it
->descent
+= it
->voffset
;
22426 /* Produce glyphs/get display metrics for the image IT is loaded with.
22427 See the description of struct display_iterator in dispextern.h for
22428 an overview of struct display_iterator. */
22431 produce_image_glyph (struct it
*it
)
22435 int glyph_ascent
, crop
;
22436 struct glyph_slice slice
;
22438 xassert (it
->what
== IT_IMAGE
);
22440 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22442 /* Make sure X resources of the face is loaded. */
22443 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22445 if (it
->image_id
< 0)
22447 /* Fringe bitmap. */
22448 it
->ascent
= it
->phys_ascent
= 0;
22449 it
->descent
= it
->phys_descent
= 0;
22450 it
->pixel_width
= 0;
22455 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
22457 /* Make sure X resources of the image is loaded. */
22458 prepare_image_for_display (it
->f
, img
);
22460 slice
.x
= slice
.y
= 0;
22461 slice
.width
= img
->width
;
22462 slice
.height
= img
->height
;
22464 if (INTEGERP (it
->slice
.x
))
22465 slice
.x
= XINT (it
->slice
.x
);
22466 else if (FLOATP (it
->slice
.x
))
22467 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
22469 if (INTEGERP (it
->slice
.y
))
22470 slice
.y
= XINT (it
->slice
.y
);
22471 else if (FLOATP (it
->slice
.y
))
22472 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
22474 if (INTEGERP (it
->slice
.width
))
22475 slice
.width
= XINT (it
->slice
.width
);
22476 else if (FLOATP (it
->slice
.width
))
22477 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
22479 if (INTEGERP (it
->slice
.height
))
22480 slice
.height
= XINT (it
->slice
.height
);
22481 else if (FLOATP (it
->slice
.height
))
22482 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
22484 if (slice
.x
>= img
->width
)
22485 slice
.x
= img
->width
;
22486 if (slice
.y
>= img
->height
)
22487 slice
.y
= img
->height
;
22488 if (slice
.x
+ slice
.width
>= img
->width
)
22489 slice
.width
= img
->width
- slice
.x
;
22490 if (slice
.y
+ slice
.height
> img
->height
)
22491 slice
.height
= img
->height
- slice
.y
;
22493 if (slice
.width
== 0 || slice
.height
== 0)
22496 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
22498 it
->descent
= slice
.height
- glyph_ascent
;
22500 it
->descent
+= img
->vmargin
;
22501 if (slice
.y
+ slice
.height
== img
->height
)
22502 it
->descent
+= img
->vmargin
;
22503 it
->phys_descent
= it
->descent
;
22505 it
->pixel_width
= slice
.width
;
22507 it
->pixel_width
+= img
->hmargin
;
22508 if (slice
.x
+ slice
.width
== img
->width
)
22509 it
->pixel_width
+= img
->hmargin
;
22511 /* It's quite possible for images to have an ascent greater than
22512 their height, so don't get confused in that case. */
22513 if (it
->descent
< 0)
22518 if (face
->box
!= FACE_NO_BOX
)
22520 if (face
->box_line_width
> 0)
22523 it
->ascent
+= face
->box_line_width
;
22524 if (slice
.y
+ slice
.height
== img
->height
)
22525 it
->descent
+= face
->box_line_width
;
22528 if (it
->start_of_box_run_p
&& slice
.x
== 0)
22529 it
->pixel_width
+= eabs (face
->box_line_width
);
22530 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
22531 it
->pixel_width
+= eabs (face
->box_line_width
);
22534 take_vertical_position_into_account (it
);
22536 /* Automatically crop wide image glyphs at right edge so we can
22537 draw the cursor on same display row. */
22538 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
22539 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
22541 it
->pixel_width
-= crop
;
22542 slice
.width
-= crop
;
22547 struct glyph
*glyph
;
22548 enum glyph_row_area area
= it
->area
;
22550 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22551 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22553 glyph
->charpos
= CHARPOS (it
->position
);
22554 glyph
->object
= it
->object
;
22555 glyph
->pixel_width
= it
->pixel_width
;
22556 glyph
->ascent
= glyph_ascent
;
22557 glyph
->descent
= it
->descent
;
22558 glyph
->voffset
= it
->voffset
;
22559 glyph
->type
= IMAGE_GLYPH
;
22560 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22561 glyph
->multibyte_p
= it
->multibyte_p
;
22562 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22563 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22564 glyph
->overlaps_vertically_p
= 0;
22565 glyph
->padding_p
= 0;
22566 glyph
->glyph_not_available_p
= 0;
22567 glyph
->face_id
= it
->face_id
;
22568 glyph
->u
.img_id
= img
->id
;
22569 glyph
->slice
.img
= slice
;
22570 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22573 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22574 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22576 glyph
->bidi_type
= it
->bidi_it
.type
;
22578 ++it
->glyph_row
->used
[area
];
22581 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22586 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
22587 of the glyph, WIDTH and HEIGHT are the width and height of the
22588 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
22591 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
22592 int width
, int height
, int ascent
)
22594 struct glyph
*glyph
;
22595 enum glyph_row_area area
= it
->area
;
22597 xassert (ascent
>= 0 && ascent
<= height
);
22599 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22600 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22602 /* If the glyph row is reversed, we need to prepend the glyph
22603 rather than append it. */
22604 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22608 /* Make room for the additional glyph. */
22609 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22611 glyph
= it
->glyph_row
->glyphs
[area
];
22613 glyph
->charpos
= CHARPOS (it
->position
);
22614 glyph
->object
= object
;
22615 glyph
->pixel_width
= width
;
22616 glyph
->ascent
= ascent
;
22617 glyph
->descent
= height
- ascent
;
22618 glyph
->voffset
= it
->voffset
;
22619 glyph
->type
= STRETCH_GLYPH
;
22620 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22621 glyph
->multibyte_p
= it
->multibyte_p
;
22622 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22623 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22624 glyph
->overlaps_vertically_p
= 0;
22625 glyph
->padding_p
= 0;
22626 glyph
->glyph_not_available_p
= 0;
22627 glyph
->face_id
= it
->face_id
;
22628 glyph
->u
.stretch
.ascent
= ascent
;
22629 glyph
->u
.stretch
.height
= height
;
22630 glyph
->slice
.img
= null_glyph_slice
;
22631 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22634 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22635 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22637 glyph
->bidi_type
= it
->bidi_it
.type
;
22641 glyph
->resolved_level
= 0;
22642 glyph
->bidi_type
= UNKNOWN_BT
;
22644 ++it
->glyph_row
->used
[area
];
22647 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22651 /* Produce a stretch glyph for iterator IT. IT->object is the value
22652 of the glyph property displayed. The value must be a list
22653 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
22656 1. `:width WIDTH' specifies that the space should be WIDTH *
22657 canonical char width wide. WIDTH may be an integer or floating
22660 2. `:relative-width FACTOR' specifies that the width of the stretch
22661 should be computed from the width of the first character having the
22662 `glyph' property, and should be FACTOR times that width.
22664 3. `:align-to HPOS' specifies that the space should be wide enough
22665 to reach HPOS, a value in canonical character units.
22667 Exactly one of the above pairs must be present.
22669 4. `:height HEIGHT' specifies that the height of the stretch produced
22670 should be HEIGHT, measured in canonical character units.
22672 5. `:relative-height FACTOR' specifies that the height of the
22673 stretch should be FACTOR times the height of the characters having
22674 the glyph property.
22676 Either none or exactly one of 4 or 5 must be present.
22678 6. `:ascent ASCENT' specifies that ASCENT percent of the height
22679 of the stretch should be used for the ascent of the stretch.
22680 ASCENT must be in the range 0 <= ASCENT <= 100. */
22683 produce_stretch_glyph (struct it
*it
)
22685 /* (space :width WIDTH :height HEIGHT ...) */
22686 Lisp_Object prop
, plist
;
22687 int width
= 0, height
= 0, align_to
= -1;
22688 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
22691 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22692 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22694 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22696 /* List should start with `space'. */
22697 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
22698 plist
= XCDR (it
->object
);
22700 /* Compute the width of the stretch. */
22701 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
22702 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
22704 /* Absolute width `:width WIDTH' specified and valid. */
22705 zero_width_ok_p
= 1;
22708 else if (prop
= Fplist_get (plist
, QCrelative_width
),
22711 /* Relative width `:relative-width FACTOR' specified and valid.
22712 Compute the width of the characters having the `glyph'
22715 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
22718 if (it
->multibyte_p
)
22719 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
22722 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
22723 if (! ASCII_CHAR_P (it2
.c
))
22724 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
22727 it2
.glyph_row
= NULL
;
22728 it2
.what
= IT_CHARACTER
;
22729 x_produce_glyphs (&it2
);
22730 width
= NUMVAL (prop
) * it2
.pixel_width
;
22732 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
22733 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
22735 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
22736 align_to
= (align_to
< 0
22738 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
22739 else if (align_to
< 0)
22740 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
22741 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
22742 zero_width_ok_p
= 1;
22745 /* Nothing specified -> width defaults to canonical char width. */
22746 width
= FRAME_COLUMN_WIDTH (it
->f
);
22748 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
22751 /* Compute height. */
22752 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
22753 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22756 zero_height_ok_p
= 1;
22758 else if (prop
= Fplist_get (plist
, QCrelative_height
),
22760 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
22762 height
= FONT_HEIGHT (font
);
22764 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
22767 /* Compute percentage of height used for ascent. If
22768 `:ascent ASCENT' is present and valid, use that. Otherwise,
22769 derive the ascent from the font in use. */
22770 if (prop
= Fplist_get (plist
, QCascent
),
22771 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
22772 ascent
= height
* NUMVAL (prop
) / 100.0;
22773 else if (!NILP (prop
)
22774 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22775 ascent
= min (max (0, (int)tem
), height
);
22777 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
22779 if (width
> 0 && it
->line_wrap
!= TRUNCATE
22780 && it
->current_x
+ width
> it
->last_visible_x
)
22781 width
= it
->last_visible_x
- it
->current_x
- 1;
22783 if (width
> 0 && height
> 0 && it
->glyph_row
)
22785 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
22786 if (!STRINGP (object
))
22787 object
= it
->w
->buffer
;
22788 append_stretch_glyph (it
, object
, width
, height
, ascent
);
22791 it
->pixel_width
= width
;
22792 it
->ascent
= it
->phys_ascent
= ascent
;
22793 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
22794 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
22796 take_vertical_position_into_account (it
);
22799 /* Calculate line-height and line-spacing properties.
22800 An integer value specifies explicit pixel value.
22801 A float value specifies relative value to current face height.
22802 A cons (float . face-name) specifies relative value to
22803 height of specified face font.
22805 Returns height in pixels, or nil. */
22809 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
22810 int boff
, int override
)
22812 Lisp_Object face_name
= Qnil
;
22813 int ascent
, descent
, height
;
22815 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
22820 face_name
= XCAR (val
);
22822 if (!NUMBERP (val
))
22823 val
= make_number (1);
22824 if (NILP (face_name
))
22826 height
= it
->ascent
+ it
->descent
;
22831 if (NILP (face_name
))
22833 font
= FRAME_FONT (it
->f
);
22834 boff
= FRAME_BASELINE_OFFSET (it
->f
);
22836 else if (EQ (face_name
, Qt
))
22845 face_id
= lookup_named_face (it
->f
, face_name
, 0);
22847 return make_number (-1);
22849 face
= FACE_FROM_ID (it
->f
, face_id
);
22852 return make_number (-1);
22853 boff
= font
->baseline_offset
;
22854 if (font
->vertical_centering
)
22855 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22858 ascent
= FONT_BASE (font
) + boff
;
22859 descent
= FONT_DESCENT (font
) - boff
;
22863 it
->override_ascent
= ascent
;
22864 it
->override_descent
= descent
;
22865 it
->override_boff
= boff
;
22868 height
= ascent
+ descent
;
22872 height
= (int)(XFLOAT_DATA (val
) * height
);
22873 else if (INTEGERP (val
))
22874 height
*= XINT (val
);
22876 return make_number (height
);
22880 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
22881 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
22882 and only if this is for a character for which no font was found.
22884 If the display method (it->glyphless_method) is
22885 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
22886 length of the acronym or the hexadecimal string, UPPER_XOFF and
22887 UPPER_YOFF are pixel offsets for the upper part of the string,
22888 LOWER_XOFF and LOWER_YOFF are for the lower part.
22890 For the other display methods, LEN through LOWER_YOFF are zero. */
22893 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
22894 short upper_xoff
, short upper_yoff
,
22895 short lower_xoff
, short lower_yoff
)
22897 struct glyph
*glyph
;
22898 enum glyph_row_area area
= it
->area
;
22900 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22901 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22903 /* If the glyph row is reversed, we need to prepend the glyph
22904 rather than append it. */
22905 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22909 /* Make room for the additional glyph. */
22910 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22912 glyph
= it
->glyph_row
->glyphs
[area
];
22914 glyph
->charpos
= CHARPOS (it
->position
);
22915 glyph
->object
= it
->object
;
22916 glyph
->pixel_width
= it
->pixel_width
;
22917 glyph
->ascent
= it
->ascent
;
22918 glyph
->descent
= it
->descent
;
22919 glyph
->voffset
= it
->voffset
;
22920 glyph
->type
= GLYPHLESS_GLYPH
;
22921 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
22922 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
22923 glyph
->u
.glyphless
.len
= len
;
22924 glyph
->u
.glyphless
.ch
= it
->c
;
22925 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
22926 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
22927 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
22928 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
22929 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22930 glyph
->multibyte_p
= it
->multibyte_p
;
22931 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22932 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22933 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22934 || it
->phys_descent
> it
->descent
);
22935 glyph
->padding_p
= 0;
22936 glyph
->glyph_not_available_p
= 0;
22937 glyph
->face_id
= face_id
;
22938 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22941 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22942 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22944 glyph
->bidi_type
= it
->bidi_it
.type
;
22946 ++it
->glyph_row
->used
[area
];
22949 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22953 /* Produce a glyph for a glyphless character for iterator IT.
22954 IT->glyphless_method specifies which method to use for displaying
22955 the character. See the description of enum
22956 glyphless_display_method in dispextern.h for the detail.
22958 FOR_NO_FONT is nonzero if and only if this is for a character for
22959 which no font was found. ACRONYM, if non-nil, is an acronym string
22960 for the character. */
22963 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
22968 int base_width
, base_height
, width
, height
;
22969 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
22972 /* Get the metrics of the base font. We always refer to the current
22974 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
22975 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22976 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
22977 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
22978 base_height
= it
->ascent
+ it
->descent
;
22979 base_width
= font
->average_width
;
22981 /* Get a face ID for the glyph by utilizing a cache (the same way as
22982 doen for `escape-glyph' in get_next_display_element). */
22983 if (it
->f
== last_glyphless_glyph_frame
22984 && it
->face_id
== last_glyphless_glyph_face_id
)
22986 face_id
= last_glyphless_glyph_merged_face_id
;
22990 /* Merge the `glyphless-char' face into the current face. */
22991 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
22992 last_glyphless_glyph_frame
= it
->f
;
22993 last_glyphless_glyph_face_id
= it
->face_id
;
22994 last_glyphless_glyph_merged_face_id
= face_id
;
22997 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
22999 it
->pixel_width
= THIN_SPACE_WIDTH
;
23001 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
23003 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
23005 width
= CHAR_WIDTH (it
->c
);
23008 else if (width
> 4)
23010 it
->pixel_width
= base_width
* width
;
23012 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
23018 unsigned int code
[6];
23020 int ascent
, descent
;
23021 struct font_metrics metrics_upper
, metrics_lower
;
23023 face
= FACE_FROM_ID (it
->f
, face_id
);
23024 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23025 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23027 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
23029 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
23030 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
23031 if (CONSP (acronym
))
23032 acronym
= XCAR (acronym
);
23033 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
23037 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
23038 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
23041 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
23042 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
23043 upper_len
= (len
+ 1) / 2;
23044 font
->driver
->text_extents (font
, code
, upper_len
,
23046 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
23051 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
23052 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
23053 upper_xoff
= upper_yoff
= 2; /* the typical case */
23054 if (base_width
>= width
)
23056 /* Align the upper to the left, the lower to the right. */
23057 it
->pixel_width
= base_width
;
23058 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
23062 /* Center the shorter one. */
23063 it
->pixel_width
= width
;
23064 if (metrics_upper
.width
>= metrics_lower
.width
)
23065 lower_xoff
= (width
- metrics_lower
.width
) / 2;
23068 /* FIXME: This code doesn't look right. It formerly was
23069 missing the "lower_xoff = 0;", which couldn't have
23070 been right since it left lower_xoff uninitialized. */
23072 upper_xoff
= (width
- metrics_upper
.width
) / 2;
23076 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
23077 top, bottom, and between upper and lower strings. */
23078 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
23079 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
23080 /* Center vertically.
23081 H:base_height, D:base_descent
23082 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
23084 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
23085 descent = D - H/2 + h/2;
23086 lower_yoff = descent - 2 - ld;
23087 upper_yoff = lower_yoff - la - 1 - ud; */
23088 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
23089 descent
= it
->descent
- (base_height
- height
) / 2;
23090 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
23091 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
23092 - metrics_upper
.descent
);
23093 /* Don't make the height shorter than the base height. */
23094 if (height
> base_height
)
23096 it
->ascent
= ascent
;
23097 it
->descent
= descent
;
23101 it
->phys_ascent
= it
->ascent
;
23102 it
->phys_descent
= it
->descent
;
23104 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
23105 upper_xoff
, upper_yoff
,
23106 lower_xoff
, lower_yoff
);
23108 take_vertical_position_into_account (it
);
23113 Produce glyphs/get display metrics for the display element IT is
23114 loaded with. See the description of struct it in dispextern.h
23115 for an overview of struct it. */
23118 x_produce_glyphs (struct it
*it
)
23120 int extra_line_spacing
= it
->extra_line_spacing
;
23122 it
->glyph_not_available_p
= 0;
23124 if (it
->what
== IT_CHARACTER
)
23127 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23128 struct font
*font
= face
->font
;
23129 struct font_metrics
*pcm
= NULL
;
23130 int boff
; /* baseline offset */
23134 /* When no suitable font is found, display this character by
23135 the method specified in the first extra slot of
23136 Vglyphless_char_display. */
23137 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
23139 xassert (it
->what
== IT_GLYPHLESS
);
23140 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
23144 boff
= font
->baseline_offset
;
23145 if (font
->vertical_centering
)
23146 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23148 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
23154 if (it
->override_ascent
>= 0)
23156 it
->ascent
= it
->override_ascent
;
23157 it
->descent
= it
->override_descent
;
23158 boff
= it
->override_boff
;
23162 it
->ascent
= FONT_BASE (font
) + boff
;
23163 it
->descent
= FONT_DESCENT (font
) - boff
;
23166 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
23168 pcm
= get_per_char_metric (font
, &char2b
);
23169 if (pcm
->width
== 0
23170 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
23176 it
->phys_ascent
= pcm
->ascent
+ boff
;
23177 it
->phys_descent
= pcm
->descent
- boff
;
23178 it
->pixel_width
= pcm
->width
;
23182 it
->glyph_not_available_p
= 1;
23183 it
->phys_ascent
= it
->ascent
;
23184 it
->phys_descent
= it
->descent
;
23185 it
->pixel_width
= font
->space_width
;
23188 if (it
->constrain_row_ascent_descent_p
)
23190 if (it
->descent
> it
->max_descent
)
23192 it
->ascent
+= it
->descent
- it
->max_descent
;
23193 it
->descent
= it
->max_descent
;
23195 if (it
->ascent
> it
->max_ascent
)
23197 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
23198 it
->ascent
= it
->max_ascent
;
23200 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
23201 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
23202 extra_line_spacing
= 0;
23205 /* If this is a space inside a region of text with
23206 `space-width' property, change its width. */
23207 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
23209 it
->pixel_width
*= XFLOATINT (it
->space_width
);
23211 /* If face has a box, add the box thickness to the character
23212 height. If character has a box line to the left and/or
23213 right, add the box line width to the character's width. */
23214 if (face
->box
!= FACE_NO_BOX
)
23216 int thick
= face
->box_line_width
;
23220 it
->ascent
+= thick
;
23221 it
->descent
+= thick
;
23226 if (it
->start_of_box_run_p
)
23227 it
->pixel_width
+= thick
;
23228 if (it
->end_of_box_run_p
)
23229 it
->pixel_width
+= thick
;
23232 /* If face has an overline, add the height of the overline
23233 (1 pixel) and a 1 pixel margin to the character height. */
23234 if (face
->overline_p
)
23235 it
->ascent
+= overline_margin
;
23237 if (it
->constrain_row_ascent_descent_p
)
23239 if (it
->ascent
> it
->max_ascent
)
23240 it
->ascent
= it
->max_ascent
;
23241 if (it
->descent
> it
->max_descent
)
23242 it
->descent
= it
->max_descent
;
23245 take_vertical_position_into_account (it
);
23247 /* If we have to actually produce glyphs, do it. */
23252 /* Translate a space with a `space-width' property
23253 into a stretch glyph. */
23254 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
23255 / FONT_HEIGHT (font
));
23256 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
23257 it
->ascent
+ it
->descent
, ascent
);
23262 /* If characters with lbearing or rbearing are displayed
23263 in this line, record that fact in a flag of the
23264 glyph row. This is used to optimize X output code. */
23265 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
23266 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23268 if (! stretched_p
&& it
->pixel_width
== 0)
23269 /* We assure that all visible glyphs have at least 1-pixel
23271 it
->pixel_width
= 1;
23273 else if (it
->char_to_display
== '\n')
23275 /* A newline has no width, but we need the height of the
23276 line. But if previous part of the line sets a height,
23277 don't increase that height */
23279 Lisp_Object height
;
23280 Lisp_Object total_height
= Qnil
;
23282 it
->override_ascent
= -1;
23283 it
->pixel_width
= 0;
23286 height
= get_it_property (it
, Qline_height
);
23287 /* Split (line-height total-height) list */
23289 && CONSP (XCDR (height
))
23290 && NILP (XCDR (XCDR (height
))))
23292 total_height
= XCAR (XCDR (height
));
23293 height
= XCAR (height
);
23295 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
23297 if (it
->override_ascent
>= 0)
23299 it
->ascent
= it
->override_ascent
;
23300 it
->descent
= it
->override_descent
;
23301 boff
= it
->override_boff
;
23305 it
->ascent
= FONT_BASE (font
) + boff
;
23306 it
->descent
= FONT_DESCENT (font
) - boff
;
23309 if (EQ (height
, Qt
))
23311 if (it
->descent
> it
->max_descent
)
23313 it
->ascent
+= it
->descent
- it
->max_descent
;
23314 it
->descent
= it
->max_descent
;
23316 if (it
->ascent
> it
->max_ascent
)
23318 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
23319 it
->ascent
= it
->max_ascent
;
23321 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
23322 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
23323 it
->constrain_row_ascent_descent_p
= 1;
23324 extra_line_spacing
= 0;
23328 Lisp_Object spacing
;
23330 it
->phys_ascent
= it
->ascent
;
23331 it
->phys_descent
= it
->descent
;
23333 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
23334 && face
->box
!= FACE_NO_BOX
23335 && face
->box_line_width
> 0)
23337 it
->ascent
+= face
->box_line_width
;
23338 it
->descent
+= face
->box_line_width
;
23341 && XINT (height
) > it
->ascent
+ it
->descent
)
23342 it
->ascent
= XINT (height
) - it
->descent
;
23344 if (!NILP (total_height
))
23345 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
23348 spacing
= get_it_property (it
, Qline_spacing
);
23349 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
23351 if (INTEGERP (spacing
))
23353 extra_line_spacing
= XINT (spacing
);
23354 if (!NILP (total_height
))
23355 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
23359 else /* i.e. (it->char_to_display == '\t') */
23361 if (font
->space_width
> 0)
23363 int tab_width
= it
->tab_width
* font
->space_width
;
23364 int x
= it
->current_x
+ it
->continuation_lines_width
;
23365 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
23367 /* If the distance from the current position to the next tab
23368 stop is less than a space character width, use the
23369 tab stop after that. */
23370 if (next_tab_x
- x
< font
->space_width
)
23371 next_tab_x
+= tab_width
;
23373 it
->pixel_width
= next_tab_x
- x
;
23375 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
23376 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
23380 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
23381 it
->ascent
+ it
->descent
, it
->ascent
);
23386 it
->pixel_width
= 0;
23391 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
23393 /* A static composition.
23395 Note: A composition is represented as one glyph in the
23396 glyph matrix. There are no padding glyphs.
23398 Important note: pixel_width, ascent, and descent are the
23399 values of what is drawn by draw_glyphs (i.e. the values of
23400 the overall glyphs composed). */
23401 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23402 int boff
; /* baseline offset */
23403 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
23404 int glyph_len
= cmp
->glyph_len
;
23405 struct font
*font
= face
->font
;
23409 /* If we have not yet calculated pixel size data of glyphs of
23410 the composition for the current face font, calculate them
23411 now. Theoretically, we have to check all fonts for the
23412 glyphs, but that requires much time and memory space. So,
23413 here we check only the font of the first glyph. This may
23414 lead to incorrect display, but it's very rare, and C-l
23415 (recenter-top-bottom) can correct the display anyway. */
23416 if (! cmp
->font
|| cmp
->font
!= font
)
23418 /* Ascent and descent of the font of the first character
23419 of this composition (adjusted by baseline offset).
23420 Ascent and descent of overall glyphs should not be less
23421 than these, respectively. */
23422 int font_ascent
, font_descent
, font_height
;
23423 /* Bounding box of the overall glyphs. */
23424 int leftmost
, rightmost
, lowest
, highest
;
23425 int lbearing
, rbearing
;
23426 int i
, width
, ascent
, descent
;
23427 int left_padded
= 0, right_padded
= 0;
23428 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
23430 struct font_metrics
*pcm
;
23431 int font_not_found_p
;
23434 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
23435 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
23437 if (glyph_len
< cmp
->glyph_len
)
23439 for (i
= 0; i
< glyph_len
; i
++)
23441 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
23443 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
23448 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
23449 : IT_CHARPOS (*it
));
23450 /* If no suitable font is found, use the default font. */
23451 font_not_found_p
= font
== NULL
;
23452 if (font_not_found_p
)
23454 face
= face
->ascii_face
;
23457 boff
= font
->baseline_offset
;
23458 if (font
->vertical_centering
)
23459 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23460 font_ascent
= FONT_BASE (font
) + boff
;
23461 font_descent
= FONT_DESCENT (font
) - boff
;
23462 font_height
= FONT_HEIGHT (font
);
23464 cmp
->font
= (void *) font
;
23467 if (! font_not_found_p
)
23469 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
23471 pcm
= get_per_char_metric (font
, &char2b
);
23474 /* Initialize the bounding box. */
23477 width
= pcm
->width
;
23478 ascent
= pcm
->ascent
;
23479 descent
= pcm
->descent
;
23480 lbearing
= pcm
->lbearing
;
23481 rbearing
= pcm
->rbearing
;
23485 width
= font
->space_width
;
23486 ascent
= FONT_BASE (font
);
23487 descent
= FONT_DESCENT (font
);
23494 lowest
= - descent
+ boff
;
23495 highest
= ascent
+ boff
;
23497 if (! font_not_found_p
23498 && font
->default_ascent
23499 && CHAR_TABLE_P (Vuse_default_ascent
)
23500 && !NILP (Faref (Vuse_default_ascent
,
23501 make_number (it
->char_to_display
))))
23502 highest
= font
->default_ascent
+ boff
;
23504 /* Draw the first glyph at the normal position. It may be
23505 shifted to right later if some other glyphs are drawn
23507 cmp
->offsets
[i
* 2] = 0;
23508 cmp
->offsets
[i
* 2 + 1] = boff
;
23509 cmp
->lbearing
= lbearing
;
23510 cmp
->rbearing
= rbearing
;
23512 /* Set cmp->offsets for the remaining glyphs. */
23513 for (i
++; i
< glyph_len
; i
++)
23515 int left
, right
, btm
, top
;
23516 int ch
= COMPOSITION_GLYPH (cmp
, i
);
23518 struct face
*this_face
;
23522 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
23523 this_face
= FACE_FROM_ID (it
->f
, face_id
);
23524 font
= this_face
->font
;
23530 get_char_face_and_encoding (it
->f
, ch
, face_id
,
23532 pcm
= get_per_char_metric (font
, &char2b
);
23535 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
23538 width
= pcm
->width
;
23539 ascent
= pcm
->ascent
;
23540 descent
= pcm
->descent
;
23541 lbearing
= pcm
->lbearing
;
23542 rbearing
= pcm
->rbearing
;
23543 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
23545 /* Relative composition with or without
23546 alternate chars. */
23547 left
= (leftmost
+ rightmost
- width
) / 2;
23548 btm
= - descent
+ boff
;
23549 if (font
->relative_compose
23550 && (! CHAR_TABLE_P (Vignore_relative_composition
)
23551 || NILP (Faref (Vignore_relative_composition
,
23552 make_number (ch
)))))
23555 if (- descent
>= font
->relative_compose
)
23556 /* One extra pixel between two glyphs. */
23558 else if (ascent
<= 0)
23559 /* One extra pixel between two glyphs. */
23560 btm
= lowest
- 1 - ascent
- descent
;
23565 /* A composition rule is specified by an integer
23566 value that encodes global and new reference
23567 points (GREF and NREF). GREF and NREF are
23568 specified by numbers as below:
23570 0---1---2 -- ascent
23574 9--10--11 -- center
23576 ---3---4---5--- baseline
23578 6---7---8 -- descent
23580 int rule
= COMPOSITION_RULE (cmp
, i
);
23581 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
23583 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
23584 grefx
= gref
% 3, nrefx
= nref
% 3;
23585 grefy
= gref
/ 3, nrefy
= nref
/ 3;
23587 xoff
= font_height
* (xoff
- 128) / 256;
23589 yoff
= font_height
* (yoff
- 128) / 256;
23592 + grefx
* (rightmost
- leftmost
) / 2
23593 - nrefx
* width
/ 2
23596 btm
= ((grefy
== 0 ? highest
23598 : grefy
== 2 ? lowest
23599 : (highest
+ lowest
) / 2)
23600 - (nrefy
== 0 ? ascent
+ descent
23601 : nrefy
== 1 ? descent
- boff
23603 : (ascent
+ descent
) / 2)
23607 cmp
->offsets
[i
* 2] = left
;
23608 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
23610 /* Update the bounding box of the overall glyphs. */
23613 right
= left
+ width
;
23614 if (left
< leftmost
)
23616 if (right
> rightmost
)
23619 top
= btm
+ descent
+ ascent
;
23625 if (cmp
->lbearing
> left
+ lbearing
)
23626 cmp
->lbearing
= left
+ lbearing
;
23627 if (cmp
->rbearing
< left
+ rbearing
)
23628 cmp
->rbearing
= left
+ rbearing
;
23632 /* If there are glyphs whose x-offsets are negative,
23633 shift all glyphs to the right and make all x-offsets
23637 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23638 cmp
->offsets
[i
* 2] -= leftmost
;
23639 rightmost
-= leftmost
;
23640 cmp
->lbearing
-= leftmost
;
23641 cmp
->rbearing
-= leftmost
;
23644 if (left_padded
&& cmp
->lbearing
< 0)
23646 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23647 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
23648 rightmost
-= cmp
->lbearing
;
23649 cmp
->rbearing
-= cmp
->lbearing
;
23652 if (right_padded
&& rightmost
< cmp
->rbearing
)
23654 rightmost
= cmp
->rbearing
;
23657 cmp
->pixel_width
= rightmost
;
23658 cmp
->ascent
= highest
;
23659 cmp
->descent
= - lowest
;
23660 if (cmp
->ascent
< font_ascent
)
23661 cmp
->ascent
= font_ascent
;
23662 if (cmp
->descent
< font_descent
)
23663 cmp
->descent
= font_descent
;
23667 && (cmp
->lbearing
< 0
23668 || cmp
->rbearing
> cmp
->pixel_width
))
23669 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23671 it
->pixel_width
= cmp
->pixel_width
;
23672 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
23673 it
->descent
= it
->phys_descent
= cmp
->descent
;
23674 if (face
->box
!= FACE_NO_BOX
)
23676 int thick
= face
->box_line_width
;
23680 it
->ascent
+= thick
;
23681 it
->descent
+= thick
;
23686 if (it
->start_of_box_run_p
)
23687 it
->pixel_width
+= thick
;
23688 if (it
->end_of_box_run_p
)
23689 it
->pixel_width
+= thick
;
23692 /* If face has an overline, add the height of the overline
23693 (1 pixel) and a 1 pixel margin to the character height. */
23694 if (face
->overline_p
)
23695 it
->ascent
+= overline_margin
;
23697 take_vertical_position_into_account (it
);
23698 if (it
->ascent
< 0)
23700 if (it
->descent
< 0)
23704 append_composite_glyph (it
);
23706 else if (it
->what
== IT_COMPOSITION
)
23708 /* A dynamic (automatic) composition. */
23709 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23710 Lisp_Object gstring
;
23711 struct font_metrics metrics
;
23713 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
23715 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
23718 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
23719 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23720 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
23721 it
->descent
= it
->phys_descent
= metrics
.descent
;
23722 if (face
->box
!= FACE_NO_BOX
)
23724 int thick
= face
->box_line_width
;
23728 it
->ascent
+= thick
;
23729 it
->descent
+= thick
;
23734 if (it
->start_of_box_run_p
)
23735 it
->pixel_width
+= thick
;
23736 if (it
->end_of_box_run_p
)
23737 it
->pixel_width
+= thick
;
23739 /* If face has an overline, add the height of the overline
23740 (1 pixel) and a 1 pixel margin to the character height. */
23741 if (face
->overline_p
)
23742 it
->ascent
+= overline_margin
;
23743 take_vertical_position_into_account (it
);
23744 if (it
->ascent
< 0)
23746 if (it
->descent
< 0)
23750 append_composite_glyph (it
);
23752 else if (it
->what
== IT_GLYPHLESS
)
23753 produce_glyphless_glyph (it
, 0, Qnil
);
23754 else if (it
->what
== IT_IMAGE
)
23755 produce_image_glyph (it
);
23756 else if (it
->what
== IT_STRETCH
)
23757 produce_stretch_glyph (it
);
23760 /* Accumulate dimensions. Note: can't assume that it->descent > 0
23761 because this isn't true for images with `:ascent 100'. */
23762 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
23763 if (it
->area
== TEXT_AREA
)
23764 it
->current_x
+= it
->pixel_width
;
23766 if (extra_line_spacing
> 0)
23768 it
->descent
+= extra_line_spacing
;
23769 if (extra_line_spacing
> it
->max_extra_line_spacing
)
23770 it
->max_extra_line_spacing
= extra_line_spacing
;
23773 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
23774 it
->max_descent
= max (it
->max_descent
, it
->descent
);
23775 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
23776 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
23780 Output LEN glyphs starting at START at the nominal cursor position.
23781 Advance the nominal cursor over the text. The global variable
23782 updated_window contains the window being updated, updated_row is
23783 the glyph row being updated, and updated_area is the area of that
23784 row being updated. */
23787 x_write_glyphs (struct glyph
*start
, int len
)
23791 xassert (updated_window
&& updated_row
);
23794 /* Write glyphs. */
23796 hpos
= start
- updated_row
->glyphs
[updated_area
];
23797 x
= draw_glyphs (updated_window
, output_cursor
.x
,
23798 updated_row
, updated_area
,
23800 DRAW_NORMAL_TEXT
, 0);
23802 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
23803 if (updated_area
== TEXT_AREA
23804 && updated_window
->phys_cursor_on_p
23805 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
23806 && updated_window
->phys_cursor
.hpos
>= hpos
23807 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
23808 updated_window
->phys_cursor_on_p
= 0;
23812 /* Advance the output cursor. */
23813 output_cursor
.hpos
+= len
;
23814 output_cursor
.x
= x
;
23819 Insert LEN glyphs from START at the nominal cursor position. */
23822 x_insert_glyphs (struct glyph
*start
, int len
)
23826 int line_height
, shift_by_width
, shifted_region_width
;
23827 struct glyph_row
*row
;
23828 struct glyph
*glyph
;
23829 int frame_x
, frame_y
;
23832 xassert (updated_window
&& updated_row
);
23834 w
= updated_window
;
23835 f
= XFRAME (WINDOW_FRAME (w
));
23837 /* Get the height of the line we are in. */
23839 line_height
= row
->height
;
23841 /* Get the width of the glyphs to insert. */
23842 shift_by_width
= 0;
23843 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
23844 shift_by_width
+= glyph
->pixel_width
;
23846 /* Get the width of the region to shift right. */
23847 shifted_region_width
= (window_box_width (w
, updated_area
)
23852 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
23853 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
23855 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
23856 line_height
, shift_by_width
);
23858 /* Write the glyphs. */
23859 hpos
= start
- row
->glyphs
[updated_area
];
23860 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
23862 DRAW_NORMAL_TEXT
, 0);
23864 /* Advance the output cursor. */
23865 output_cursor
.hpos
+= len
;
23866 output_cursor
.x
+= shift_by_width
;
23872 Erase the current text line from the nominal cursor position
23873 (inclusive) to pixel column TO_X (exclusive). The idea is that
23874 everything from TO_X onward is already erased.
23876 TO_X is a pixel position relative to updated_area of
23877 updated_window. TO_X == -1 means clear to the end of this area. */
23880 x_clear_end_of_line (int to_x
)
23883 struct window
*w
= updated_window
;
23884 int max_x
, min_y
, max_y
;
23885 int from_x
, from_y
, to_y
;
23887 xassert (updated_window
&& updated_row
);
23888 f
= XFRAME (w
->frame
);
23890 if (updated_row
->full_width_p
)
23891 max_x
= WINDOW_TOTAL_WIDTH (w
);
23893 max_x
= window_box_width (w
, updated_area
);
23894 max_y
= window_text_bottom_y (w
);
23896 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
23897 of window. For TO_X > 0, truncate to end of drawing area. */
23903 to_x
= min (to_x
, max_x
);
23905 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
23907 /* Notice if the cursor will be cleared by this operation. */
23908 if (!updated_row
->full_width_p
)
23909 notice_overwritten_cursor (w
, updated_area
,
23910 output_cursor
.x
, -1,
23912 MATRIX_ROW_BOTTOM_Y (updated_row
));
23914 from_x
= output_cursor
.x
;
23916 /* Translate to frame coordinates. */
23917 if (updated_row
->full_width_p
)
23919 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
23920 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
23924 int area_left
= window_box_left (w
, updated_area
);
23925 from_x
+= area_left
;
23929 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
23930 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
23931 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
23933 /* Prevent inadvertently clearing to end of the X window. */
23934 if (to_x
> from_x
&& to_y
> from_y
)
23937 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
23938 to_x
- from_x
, to_y
- from_y
);
23943 #endif /* HAVE_WINDOW_SYSTEM */
23947 /***********************************************************************
23949 ***********************************************************************/
23951 /* Value is the internal representation of the specified cursor type
23952 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
23953 of the bar cursor. */
23955 static enum text_cursor_kinds
23956 get_specified_cursor_type (Lisp_Object arg
, int *width
)
23958 enum text_cursor_kinds type
;
23963 if (EQ (arg
, Qbox
))
23964 return FILLED_BOX_CURSOR
;
23966 if (EQ (arg
, Qhollow
))
23967 return HOLLOW_BOX_CURSOR
;
23969 if (EQ (arg
, Qbar
))
23976 && EQ (XCAR (arg
), Qbar
)
23977 && INTEGERP (XCDR (arg
))
23978 && XINT (XCDR (arg
)) >= 0)
23980 *width
= XINT (XCDR (arg
));
23984 if (EQ (arg
, Qhbar
))
23987 return HBAR_CURSOR
;
23991 && EQ (XCAR (arg
), Qhbar
)
23992 && INTEGERP (XCDR (arg
))
23993 && XINT (XCDR (arg
)) >= 0)
23995 *width
= XINT (XCDR (arg
));
23996 return HBAR_CURSOR
;
23999 /* Treat anything unknown as "hollow box cursor".
24000 It was bad to signal an error; people have trouble fixing
24001 .Xdefaults with Emacs, when it has something bad in it. */
24002 type
= HOLLOW_BOX_CURSOR
;
24007 /* Set the default cursor types for specified frame. */
24009 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
24014 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
24015 FRAME_CURSOR_WIDTH (f
) = width
;
24017 /* By default, set up the blink-off state depending on the on-state. */
24019 tem
= Fassoc (arg
, Vblink_cursor_alist
);
24022 FRAME_BLINK_OFF_CURSOR (f
)
24023 = get_specified_cursor_type (XCDR (tem
), &width
);
24024 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
24027 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
24031 #ifdef HAVE_WINDOW_SYSTEM
24033 /* Return the cursor we want to be displayed in window W. Return
24034 width of bar/hbar cursor through WIDTH arg. Return with
24035 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
24036 (i.e. if the `system caret' should track this cursor).
24038 In a mini-buffer window, we want the cursor only to appear if we
24039 are reading input from this window. For the selected window, we
24040 want the cursor type given by the frame parameter or buffer local
24041 setting of cursor-type. If explicitly marked off, draw no cursor.
24042 In all other cases, we want a hollow box cursor. */
24044 static enum text_cursor_kinds
24045 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
24046 int *active_cursor
)
24048 struct frame
*f
= XFRAME (w
->frame
);
24049 struct buffer
*b
= XBUFFER (w
->buffer
);
24050 int cursor_type
= DEFAULT_CURSOR
;
24051 Lisp_Object alt_cursor
;
24052 int non_selected
= 0;
24054 *active_cursor
= 1;
24057 if (cursor_in_echo_area
24058 && FRAME_HAS_MINIBUF_P (f
)
24059 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
24061 if (w
== XWINDOW (echo_area_window
))
24063 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
24065 *width
= FRAME_CURSOR_WIDTH (f
);
24066 return FRAME_DESIRED_CURSOR (f
);
24069 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
24072 *active_cursor
= 0;
24076 /* Detect a nonselected window or nonselected frame. */
24077 else if (w
!= XWINDOW (f
->selected_window
)
24078 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
24080 *active_cursor
= 0;
24082 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
24088 /* Never display a cursor in a window in which cursor-type is nil. */
24089 if (NILP (BVAR (b
, cursor_type
)))
24092 /* Get the normal cursor type for this window. */
24093 if (EQ (BVAR (b
, cursor_type
), Qt
))
24095 cursor_type
= FRAME_DESIRED_CURSOR (f
);
24096 *width
= FRAME_CURSOR_WIDTH (f
);
24099 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
24101 /* Use cursor-in-non-selected-windows instead
24102 for non-selected window or frame. */
24105 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
24106 if (!EQ (Qt
, alt_cursor
))
24107 return get_specified_cursor_type (alt_cursor
, width
);
24108 /* t means modify the normal cursor type. */
24109 if (cursor_type
== FILLED_BOX_CURSOR
)
24110 cursor_type
= HOLLOW_BOX_CURSOR
;
24111 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
24113 return cursor_type
;
24116 /* Use normal cursor if not blinked off. */
24117 if (!w
->cursor_off_p
)
24119 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
24121 if (cursor_type
== FILLED_BOX_CURSOR
)
24123 /* Using a block cursor on large images can be very annoying.
24124 So use a hollow cursor for "large" images.
24125 If image is not transparent (no mask), also use hollow cursor. */
24126 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
24127 if (img
!= NULL
&& IMAGEP (img
->spec
))
24129 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
24130 where N = size of default frame font size.
24131 This should cover most of the "tiny" icons people may use. */
24133 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
24134 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
24135 cursor_type
= HOLLOW_BOX_CURSOR
;
24138 else if (cursor_type
!= NO_CURSOR
)
24140 /* Display current only supports BOX and HOLLOW cursors for images.
24141 So for now, unconditionally use a HOLLOW cursor when cursor is
24142 not a solid box cursor. */
24143 cursor_type
= HOLLOW_BOX_CURSOR
;
24146 return cursor_type
;
24149 /* Cursor is blinked off, so determine how to "toggle" it. */
24151 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
24152 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
24153 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
24155 /* Then see if frame has specified a specific blink off cursor type. */
24156 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
24158 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
24159 return FRAME_BLINK_OFF_CURSOR (f
);
24163 /* Some people liked having a permanently visible blinking cursor,
24164 while others had very strong opinions against it. So it was
24165 decided to remove it. KFS 2003-09-03 */
24167 /* Finally perform built-in cursor blinking:
24168 filled box <-> hollow box
24169 wide [h]bar <-> narrow [h]bar
24170 narrow [h]bar <-> no cursor
24171 other type <-> no cursor */
24173 if (cursor_type
== FILLED_BOX_CURSOR
)
24174 return HOLLOW_BOX_CURSOR
;
24176 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
24179 return cursor_type
;
24187 /* Notice when the text cursor of window W has been completely
24188 overwritten by a drawing operation that outputs glyphs in AREA
24189 starting at X0 and ending at X1 in the line starting at Y0 and
24190 ending at Y1. X coordinates are area-relative. X1 < 0 means all
24191 the rest of the line after X0 has been written. Y coordinates
24192 are window-relative. */
24195 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
24196 int x0
, int x1
, int y0
, int y1
)
24198 int cx0
, cx1
, cy0
, cy1
;
24199 struct glyph_row
*row
;
24201 if (!w
->phys_cursor_on_p
)
24203 if (area
!= TEXT_AREA
)
24206 if (w
->phys_cursor
.vpos
< 0
24207 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
24208 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
24209 !(row
->enabled_p
&& row
->displays_text_p
)))
24212 if (row
->cursor_in_fringe_p
)
24214 row
->cursor_in_fringe_p
= 0;
24215 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
24216 w
->phys_cursor_on_p
= 0;
24220 cx0
= w
->phys_cursor
.x
;
24221 cx1
= cx0
+ w
->phys_cursor_width
;
24222 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
24225 /* The cursor image will be completely removed from the
24226 screen if the output area intersects the cursor area in
24227 y-direction. When we draw in [y0 y1[, and some part of
24228 the cursor is at y < y0, that part must have been drawn
24229 before. When scrolling, the cursor is erased before
24230 actually scrolling, so we don't come here. When not
24231 scrolling, the rows above the old cursor row must have
24232 changed, and in this case these rows must have written
24233 over the cursor image.
24235 Likewise if part of the cursor is below y1, with the
24236 exception of the cursor being in the first blank row at
24237 the buffer and window end because update_text_area
24238 doesn't draw that row. (Except when it does, but
24239 that's handled in update_text_area.) */
24241 cy0
= w
->phys_cursor
.y
;
24242 cy1
= cy0
+ w
->phys_cursor_height
;
24243 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
24246 w
->phys_cursor_on_p
= 0;
24249 #endif /* HAVE_WINDOW_SYSTEM */
24252 /************************************************************************
24254 ************************************************************************/
24256 #ifdef HAVE_WINDOW_SYSTEM
24259 Fix the display of area AREA of overlapping row ROW in window W
24260 with respect to the overlapping part OVERLAPS. */
24263 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
24264 enum glyph_row_area area
, int overlaps
)
24271 for (i
= 0; i
< row
->used
[area
];)
24273 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
24275 int start
= i
, start_x
= x
;
24279 x
+= row
->glyphs
[area
][i
].pixel_width
;
24282 while (i
< row
->used
[area
]
24283 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
24285 draw_glyphs (w
, start_x
, row
, area
,
24287 DRAW_NORMAL_TEXT
, overlaps
);
24291 x
+= row
->glyphs
[area
][i
].pixel_width
;
24301 Draw the cursor glyph of window W in glyph row ROW. See the
24302 comment of draw_glyphs for the meaning of HL. */
24305 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
24306 enum draw_glyphs_face hl
)
24308 /* If cursor hpos is out of bounds, don't draw garbage. This can
24309 happen in mini-buffer windows when switching between echo area
24310 glyphs and mini-buffer. */
24311 if ((row
->reversed_p
24312 ? (w
->phys_cursor
.hpos
>= 0)
24313 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
24315 int on_p
= w
->phys_cursor_on_p
;
24317 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
24318 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
24320 w
->phys_cursor_on_p
= on_p
;
24322 if (hl
== DRAW_CURSOR
)
24323 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
24324 /* When we erase the cursor, and ROW is overlapped by other
24325 rows, make sure that these overlapping parts of other rows
24327 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
24329 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
24331 if (row
> w
->current_matrix
->rows
24332 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
24333 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
24334 OVERLAPS_ERASED_CURSOR
);
24336 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
24337 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
24338 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
24339 OVERLAPS_ERASED_CURSOR
);
24346 Erase the image of a cursor of window W from the screen. */
24349 erase_phys_cursor (struct window
*w
)
24351 struct frame
*f
= XFRAME (w
->frame
);
24352 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
24353 int hpos
= w
->phys_cursor
.hpos
;
24354 int vpos
= w
->phys_cursor
.vpos
;
24355 int mouse_face_here_p
= 0;
24356 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
24357 struct glyph_row
*cursor_row
;
24358 struct glyph
*cursor_glyph
;
24359 enum draw_glyphs_face hl
;
24361 /* No cursor displayed or row invalidated => nothing to do on the
24363 if (w
->phys_cursor_type
== NO_CURSOR
)
24364 goto mark_cursor_off
;
24366 /* VPOS >= active_glyphs->nrows means that window has been resized.
24367 Don't bother to erase the cursor. */
24368 if (vpos
>= active_glyphs
->nrows
)
24369 goto mark_cursor_off
;
24371 /* If row containing cursor is marked invalid, there is nothing we
24373 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
24374 if (!cursor_row
->enabled_p
)
24375 goto mark_cursor_off
;
24377 /* If line spacing is > 0, old cursor may only be partially visible in
24378 window after split-window. So adjust visible height. */
24379 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
24380 window_text_bottom_y (w
) - cursor_row
->y
);
24382 /* If row is completely invisible, don't attempt to delete a cursor which
24383 isn't there. This can happen if cursor is at top of a window, and
24384 we switch to a buffer with a header line in that window. */
24385 if (cursor_row
->visible_height
<= 0)
24386 goto mark_cursor_off
;
24388 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
24389 if (cursor_row
->cursor_in_fringe_p
)
24391 cursor_row
->cursor_in_fringe_p
= 0;
24392 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
24393 goto mark_cursor_off
;
24396 /* This can happen when the new row is shorter than the old one.
24397 In this case, either draw_glyphs or clear_end_of_line
24398 should have cleared the cursor. Note that we wouldn't be
24399 able to erase the cursor in this case because we don't have a
24400 cursor glyph at hand. */
24401 if ((cursor_row
->reversed_p
24402 ? (w
->phys_cursor
.hpos
< 0)
24403 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
24404 goto mark_cursor_off
;
24406 /* If the cursor is in the mouse face area, redisplay that when
24407 we clear the cursor. */
24408 if (! NILP (hlinfo
->mouse_face_window
)
24409 && coords_in_mouse_face_p (w
, hpos
, vpos
)
24410 /* Don't redraw the cursor's spot in mouse face if it is at the
24411 end of a line (on a newline). The cursor appears there, but
24412 mouse highlighting does not. */
24413 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
24414 mouse_face_here_p
= 1;
24416 /* Maybe clear the display under the cursor. */
24417 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
24420 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
24423 cursor_glyph
= get_phys_cursor_glyph (w
);
24424 if (cursor_glyph
== NULL
)
24425 goto mark_cursor_off
;
24427 width
= cursor_glyph
->pixel_width
;
24428 left_x
= window_box_left_offset (w
, TEXT_AREA
);
24429 x
= w
->phys_cursor
.x
;
24431 width
-= left_x
- x
;
24432 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
24433 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
24434 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
24437 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
24440 /* Erase the cursor by redrawing the character underneath it. */
24441 if (mouse_face_here_p
)
24442 hl
= DRAW_MOUSE_FACE
;
24444 hl
= DRAW_NORMAL_TEXT
;
24445 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
24448 w
->phys_cursor_on_p
= 0;
24449 w
->phys_cursor_type
= NO_CURSOR
;
24454 Display or clear cursor of window W. If ON is zero, clear the
24455 cursor. If it is non-zero, display the cursor. If ON is nonzero,
24456 where to put the cursor is specified by HPOS, VPOS, X and Y. */
24459 display_and_set_cursor (struct window
*w
, int on
,
24460 int hpos
, int vpos
, int x
, int y
)
24462 struct frame
*f
= XFRAME (w
->frame
);
24463 int new_cursor_type
;
24464 int new_cursor_width
;
24466 struct glyph_row
*glyph_row
;
24467 struct glyph
*glyph
;
24469 /* This is pointless on invisible frames, and dangerous on garbaged
24470 windows and frames; in the latter case, the frame or window may
24471 be in the midst of changing its size, and x and y may be off the
24473 if (! FRAME_VISIBLE_P (f
)
24474 || FRAME_GARBAGED_P (f
)
24475 || vpos
>= w
->current_matrix
->nrows
24476 || hpos
>= w
->current_matrix
->matrix_w
)
24479 /* If cursor is off and we want it off, return quickly. */
24480 if (!on
&& !w
->phys_cursor_on_p
)
24483 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
24484 /* If cursor row is not enabled, we don't really know where to
24485 display the cursor. */
24486 if (!glyph_row
->enabled_p
)
24488 w
->phys_cursor_on_p
= 0;
24493 if (!glyph_row
->exact_window_width_line_p
24494 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
24495 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
24497 xassert (interrupt_input_blocked
);
24499 /* Set new_cursor_type to the cursor we want to be displayed. */
24500 new_cursor_type
= get_window_cursor_type (w
, glyph
,
24501 &new_cursor_width
, &active_cursor
);
24503 /* If cursor is currently being shown and we don't want it to be or
24504 it is in the wrong place, or the cursor type is not what we want,
24506 if (w
->phys_cursor_on_p
24508 || w
->phys_cursor
.x
!= x
24509 || w
->phys_cursor
.y
!= y
24510 || new_cursor_type
!= w
->phys_cursor_type
24511 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
24512 && new_cursor_width
!= w
->phys_cursor_width
)))
24513 erase_phys_cursor (w
);
24515 /* Don't check phys_cursor_on_p here because that flag is only set
24516 to zero in some cases where we know that the cursor has been
24517 completely erased, to avoid the extra work of erasing the cursor
24518 twice. In other words, phys_cursor_on_p can be 1 and the cursor
24519 still not be visible, or it has only been partly erased. */
24522 w
->phys_cursor_ascent
= glyph_row
->ascent
;
24523 w
->phys_cursor_height
= glyph_row
->height
;
24525 /* Set phys_cursor_.* before x_draw_.* is called because some
24526 of them may need the information. */
24527 w
->phys_cursor
.x
= x
;
24528 w
->phys_cursor
.y
= glyph_row
->y
;
24529 w
->phys_cursor
.hpos
= hpos
;
24530 w
->phys_cursor
.vpos
= vpos
;
24533 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
24534 new_cursor_type
, new_cursor_width
,
24535 on
, active_cursor
);
24539 /* Switch the display of W's cursor on or off, according to the value
24543 update_window_cursor (struct window
*w
, int on
)
24545 /* Don't update cursor in windows whose frame is in the process
24546 of being deleted. */
24547 if (w
->current_matrix
)
24550 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24551 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24557 /* Call update_window_cursor with parameter ON_P on all leaf windows
24558 in the window tree rooted at W. */
24561 update_cursor_in_window_tree (struct window
*w
, int on_p
)
24565 if (!NILP (w
->hchild
))
24566 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
24567 else if (!NILP (w
->vchild
))
24568 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
24570 update_window_cursor (w
, on_p
);
24572 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
24578 Display the cursor on window W, or clear it, according to ON_P.
24579 Don't change the cursor's position. */
24582 x_update_cursor (struct frame
*f
, int on_p
)
24584 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
24589 Clear the cursor of window W to background color, and mark the
24590 cursor as not shown. This is used when the text where the cursor
24591 is about to be rewritten. */
24594 x_clear_cursor (struct window
*w
)
24596 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
24597 update_window_cursor (w
, 0);
24600 #endif /* HAVE_WINDOW_SYSTEM */
24602 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
24605 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
24606 int start_hpos
, int end_hpos
,
24607 enum draw_glyphs_face draw
)
24609 #ifdef HAVE_WINDOW_SYSTEM
24610 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
24612 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
24616 #if defined (HAVE_GPM) || defined (MSDOS)
24617 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
24621 /* Display the active region described by mouse_face_* according to DRAW. */
24624 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
24626 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
24627 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24629 if (/* If window is in the process of being destroyed, don't bother
24631 w
->current_matrix
!= NULL
24632 /* Don't update mouse highlight if hidden */
24633 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
24634 /* Recognize when we are called to operate on rows that don't exist
24635 anymore. This can happen when a window is split. */
24636 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
24638 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
24639 struct glyph_row
*row
, *first
, *last
;
24641 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
24642 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
24644 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
24646 int start_hpos
, end_hpos
, start_x
;
24648 /* For all but the first row, the highlight starts at column 0. */
24651 /* R2L rows have BEG and END in reversed order, but the
24652 screen drawing geometry is always left to right. So
24653 we need to mirror the beginning and end of the
24654 highlighted area in R2L rows. */
24655 if (!row
->reversed_p
)
24657 start_hpos
= hlinfo
->mouse_face_beg_col
;
24658 start_x
= hlinfo
->mouse_face_beg_x
;
24660 else if (row
== last
)
24662 start_hpos
= hlinfo
->mouse_face_end_col
;
24663 start_x
= hlinfo
->mouse_face_end_x
;
24671 else if (row
->reversed_p
&& row
== last
)
24673 start_hpos
= hlinfo
->mouse_face_end_col
;
24674 start_x
= hlinfo
->mouse_face_end_x
;
24684 if (!row
->reversed_p
)
24685 end_hpos
= hlinfo
->mouse_face_end_col
;
24686 else if (row
== first
)
24687 end_hpos
= hlinfo
->mouse_face_beg_col
;
24690 end_hpos
= row
->used
[TEXT_AREA
];
24691 if (draw
== DRAW_NORMAL_TEXT
)
24692 row
->fill_line_p
= 1; /* Clear to end of line */
24695 else if (row
->reversed_p
&& row
== first
)
24696 end_hpos
= hlinfo
->mouse_face_beg_col
;
24699 end_hpos
= row
->used
[TEXT_AREA
];
24700 if (draw
== DRAW_NORMAL_TEXT
)
24701 row
->fill_line_p
= 1; /* Clear to end of line */
24704 if (end_hpos
> start_hpos
)
24706 draw_row_with_mouse_face (w
, start_x
, row
,
24707 start_hpos
, end_hpos
, draw
);
24710 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
24714 #ifdef HAVE_WINDOW_SYSTEM
24715 /* When we've written over the cursor, arrange for it to
24716 be displayed again. */
24717 if (FRAME_WINDOW_P (f
)
24718 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
24721 display_and_set_cursor (w
, 1,
24722 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24723 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24726 #endif /* HAVE_WINDOW_SYSTEM */
24729 #ifdef HAVE_WINDOW_SYSTEM
24730 /* Change the mouse cursor. */
24731 if (FRAME_WINDOW_P (f
))
24733 if (draw
== DRAW_NORMAL_TEXT
24734 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
24735 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
24736 else if (draw
== DRAW_MOUSE_FACE
)
24737 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
24739 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
24741 #endif /* HAVE_WINDOW_SYSTEM */
24745 Clear out the mouse-highlighted active region.
24746 Redraw it un-highlighted first. Value is non-zero if mouse
24747 face was actually drawn unhighlighted. */
24750 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
24754 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
24756 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
24760 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
24761 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
24762 hlinfo
->mouse_face_window
= Qnil
;
24763 hlinfo
->mouse_face_overlay
= Qnil
;
24767 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
24768 within the mouse face on that window. */
24770 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
24772 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
24774 /* Quickly resolve the easy cases. */
24775 if (!(WINDOWP (hlinfo
->mouse_face_window
)
24776 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
24778 if (vpos
< hlinfo
->mouse_face_beg_row
24779 || vpos
> hlinfo
->mouse_face_end_row
)
24781 if (vpos
> hlinfo
->mouse_face_beg_row
24782 && vpos
< hlinfo
->mouse_face_end_row
)
24785 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
24787 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24789 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
24792 else if ((vpos
== hlinfo
->mouse_face_beg_row
24793 && hpos
>= hlinfo
->mouse_face_beg_col
)
24794 || (vpos
== hlinfo
->mouse_face_end_row
24795 && hpos
< hlinfo
->mouse_face_end_col
))
24800 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24802 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
24805 else if ((vpos
== hlinfo
->mouse_face_beg_row
24806 && hpos
<= hlinfo
->mouse_face_beg_col
)
24807 || (vpos
== hlinfo
->mouse_face_end_row
24808 && hpos
> hlinfo
->mouse_face_end_col
))
24816 Non-zero if physical cursor of window W is within mouse face. */
24819 cursor_in_mouse_face_p (struct window
*w
)
24821 return coords_in_mouse_face_p (w
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
);
24826 /* Find the glyph rows START_ROW and END_ROW of window W that display
24827 characters between buffer positions START_CHARPOS and END_CHARPOS
24828 (excluding END_CHARPOS). This is similar to row_containing_pos,
24829 but is more accurate when bidi reordering makes buffer positions
24830 change non-linearly with glyph rows. */
24832 rows_from_pos_range (struct window
*w
,
24833 EMACS_INT start_charpos
, EMACS_INT end_charpos
,
24834 struct glyph_row
**start
, struct glyph_row
**end
)
24836 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24837 int last_y
= window_text_bottom_y (w
);
24838 struct glyph_row
*row
;
24843 while (!first
->enabled_p
24844 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
24847 /* Find the START row. */
24849 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
24852 /* A row can potentially be the START row if the range of the
24853 characters it displays intersects the range
24854 [START_CHARPOS..END_CHARPOS). */
24855 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
24856 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
24857 /* See the commentary in row_containing_pos, for the
24858 explanation of the complicated way to check whether
24859 some position is beyond the end of the characters
24860 displayed by a row. */
24861 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24862 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24863 && !row
->ends_at_zv_p
24864 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
24865 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24866 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24867 && !row
->ends_at_zv_p
24868 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
24870 /* Found a candidate row. Now make sure at least one of the
24871 glyphs it displays has a charpos from the range
24872 [START_CHARPOS..END_CHARPOS).
24874 This is not obvious because bidi reordering could make
24875 buffer positions of a row be 1,2,3,102,101,100, and if we
24876 want to highlight characters in [50..60), we don't want
24877 this row, even though [50..60) does intersect [1..103),
24878 the range of character positions given by the row's start
24879 and end positions. */
24880 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
24881 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
24885 if (BUFFERP (g
->object
)
24886 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24895 /* Find the END row. */
24897 /* If the last row is partially visible, start looking for END
24898 from that row, instead of starting from FIRST. */
24899 && !(row
->enabled_p
24900 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
24902 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
24904 struct glyph_row
*next
= row
+ 1;
24906 if (!next
->enabled_p
24907 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
24908 /* The first row >= START whose range of displayed characters
24909 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
24910 is the row END + 1. */
24911 || (start_charpos
< MATRIX_ROW_START_CHARPOS (next
)
24912 && end_charpos
< MATRIX_ROW_START_CHARPOS (next
))
24913 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24914 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24915 && !next
->ends_at_zv_p
24916 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
24917 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24918 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24919 && !next
->ends_at_zv_p
24920 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
24927 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
24928 but none of the characters it displays are in the range, it is
24930 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
24931 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
24935 if (BUFFERP (g
->object
)
24936 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24949 /* This function sets the mouse_face_* elements of HLINFO, assuming
24950 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
24951 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
24952 for the overlay or run of text properties specifying the mouse
24953 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
24954 before-string and after-string that must also be highlighted.
24955 COVER_STRING, if non-nil, is a display string that may cover some
24956 or all of the highlighted text. */
24959 mouse_face_from_buffer_pos (Lisp_Object window
,
24960 Mouse_HLInfo
*hlinfo
,
24961 EMACS_INT mouse_charpos
,
24962 EMACS_INT start_charpos
,
24963 EMACS_INT end_charpos
,
24964 Lisp_Object before_string
,
24965 Lisp_Object after_string
,
24966 Lisp_Object cover_string
)
24968 struct window
*w
= XWINDOW (window
);
24969 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24970 struct glyph_row
*r1
, *r2
;
24971 struct glyph
*glyph
, *end
;
24972 EMACS_INT ignore
, pos
;
24975 xassert (NILP (cover_string
) || STRINGP (cover_string
));
24976 xassert (NILP (before_string
) || STRINGP (before_string
));
24977 xassert (NILP (after_string
) || STRINGP (after_string
));
24979 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
24980 rows_from_pos_range (w
, start_charpos
, end_charpos
, &r1
, &r2
);
24982 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24983 /* If the before-string or display-string contains newlines,
24984 rows_from_pos_range skips to its last row. Move back. */
24985 if (!NILP (before_string
) || !NILP (cover_string
))
24987 struct glyph_row
*prev
;
24988 while ((prev
= r1
- 1, prev
>= first
)
24989 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
24990 && prev
->used
[TEXT_AREA
] > 0)
24992 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
24993 glyph
= beg
+ prev
->used
[TEXT_AREA
];
24994 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
24996 || !(EQ (glyph
->object
, before_string
)
24997 || EQ (glyph
->object
, cover_string
)))
25004 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
25005 hlinfo
->mouse_face_past_end
= 1;
25007 else if (!NILP (after_string
))
25009 /* If the after-string has newlines, advance to its last row. */
25010 struct glyph_row
*next
;
25011 struct glyph_row
*last
25012 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
25014 for (next
= r2
+ 1;
25016 && next
->used
[TEXT_AREA
] > 0
25017 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
25021 /* The rest of the display engine assumes that mouse_face_beg_row is
25022 either above below mouse_face_end_row or identical to it. But
25023 with bidi-reordered continued lines, the row for START_CHARPOS
25024 could be below the row for END_CHARPOS. If so, swap the rows and
25025 store them in correct order. */
25028 struct glyph_row
*tem
= r2
;
25034 hlinfo
->mouse_face_beg_y
= r1
->y
;
25035 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
25036 hlinfo
->mouse_face_end_y
= r2
->y
;
25037 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
25039 /* For a bidi-reordered row, the positions of BEFORE_STRING,
25040 AFTER_STRING, COVER_STRING, START_CHARPOS, and END_CHARPOS
25041 could be anywhere in the row and in any order. The strategy
25042 below is to find the leftmost and the rightmost glyph that
25043 belongs to either of these 3 strings, or whose position is
25044 between START_CHARPOS and END_CHARPOS, and highlight all the
25045 glyphs between those two. This may cover more than just the text
25046 between START_CHARPOS and END_CHARPOS if the range of characters
25047 strides the bidi level boundary, e.g. if the beginning is in R2L
25048 text while the end is in L2R text or vice versa. */
25049 if (!r1
->reversed_p
)
25051 /* This row is in a left to right paragraph. Scan it left to
25053 glyph
= r1
->glyphs
[TEXT_AREA
];
25054 end
= glyph
+ r1
->used
[TEXT_AREA
];
25057 /* Skip truncation glyphs at the start of the glyph row. */
25058 if (r1
->displays_text_p
)
25060 && INTEGERP (glyph
->object
)
25061 && glyph
->charpos
< 0;
25063 x
+= glyph
->pixel_width
;
25065 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
25066 or COVER_STRING, and the first glyph from buffer whose
25067 position is between START_CHARPOS and END_CHARPOS. */
25069 && !INTEGERP (glyph
->object
)
25070 && !EQ (glyph
->object
, cover_string
)
25071 && !(BUFFERP (glyph
->object
)
25072 && (glyph
->charpos
>= start_charpos
25073 && glyph
->charpos
< end_charpos
));
25076 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25077 are present at buffer positions between START_CHARPOS and
25078 END_CHARPOS, or if they come from an overlay. */
25079 if (EQ (glyph
->object
, before_string
))
25081 pos
= string_buffer_position (before_string
,
25083 /* If pos == 0, it means before_string came from an
25084 overlay, not from a buffer position. */
25085 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25088 else if (EQ (glyph
->object
, after_string
))
25090 pos
= string_buffer_position (after_string
, end_charpos
);
25091 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25094 x
+= glyph
->pixel_width
;
25096 hlinfo
->mouse_face_beg_x
= x
;
25097 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
25101 /* This row is in a right to left paragraph. Scan it right to
25105 end
= r1
->glyphs
[TEXT_AREA
] - 1;
25106 glyph
= end
+ r1
->used
[TEXT_AREA
];
25108 /* Skip truncation glyphs at the start of the glyph row. */
25109 if (r1
->displays_text_p
)
25111 && INTEGERP (glyph
->object
)
25112 && glyph
->charpos
< 0;
25116 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
25117 or COVER_STRING, and the first glyph from buffer whose
25118 position is between START_CHARPOS and END_CHARPOS. */
25120 && !INTEGERP (glyph
->object
)
25121 && !EQ (glyph
->object
, cover_string
)
25122 && !(BUFFERP (glyph
->object
)
25123 && (glyph
->charpos
>= start_charpos
25124 && glyph
->charpos
< end_charpos
));
25127 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25128 are present at buffer positions between START_CHARPOS and
25129 END_CHARPOS, or if they come from an overlay. */
25130 if (EQ (glyph
->object
, before_string
))
25132 pos
= string_buffer_position (before_string
, start_charpos
);
25133 /* If pos == 0, it means before_string came from an
25134 overlay, not from a buffer position. */
25135 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25138 else if (EQ (glyph
->object
, after_string
))
25140 pos
= string_buffer_position (after_string
, end_charpos
);
25141 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25146 glyph
++; /* first glyph to the right of the highlighted area */
25147 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
25148 x
+= g
->pixel_width
;
25149 hlinfo
->mouse_face_beg_x
= x
;
25150 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
25153 /* If the highlight ends in a different row, compute GLYPH and END
25154 for the end row. Otherwise, reuse the values computed above for
25155 the row where the highlight begins. */
25158 if (!r2
->reversed_p
)
25160 glyph
= r2
->glyphs
[TEXT_AREA
];
25161 end
= glyph
+ r2
->used
[TEXT_AREA
];
25166 end
= r2
->glyphs
[TEXT_AREA
] - 1;
25167 glyph
= end
+ r2
->used
[TEXT_AREA
];
25171 if (!r2
->reversed_p
)
25173 /* Skip truncation and continuation glyphs near the end of the
25174 row, and also blanks and stretch glyphs inserted by
25175 extend_face_to_end_of_line. */
25177 && INTEGERP ((end
- 1)->object
)
25178 && (end
- 1)->charpos
<= 0)
25180 /* Scan the rest of the glyph row from the end, looking for the
25181 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
25182 COVER_STRING, or whose position is between START_CHARPOS
25186 && !INTEGERP (end
->object
)
25187 && !EQ (end
->object
, cover_string
)
25188 && !(BUFFERP (end
->object
)
25189 && (end
->charpos
>= start_charpos
25190 && end
->charpos
< end_charpos
));
25193 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25194 are present at buffer positions between START_CHARPOS and
25195 END_CHARPOS, or if they come from an overlay. */
25196 if (EQ (end
->object
, before_string
))
25198 pos
= string_buffer_position (before_string
, start_charpos
);
25199 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25202 else if (EQ (end
->object
, after_string
))
25204 pos
= string_buffer_position (after_string
, end_charpos
);
25205 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25209 /* Find the X coordinate of the last glyph to be highlighted. */
25210 for (; glyph
<= end
; ++glyph
)
25211 x
+= glyph
->pixel_width
;
25213 hlinfo
->mouse_face_end_x
= x
;
25214 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
25218 /* Skip truncation and continuation glyphs near the end of the
25219 row, and also blanks and stretch glyphs inserted by
25220 extend_face_to_end_of_line. */
25224 && INTEGERP (end
->object
)
25225 && end
->charpos
<= 0)
25227 x
+= end
->pixel_width
;
25230 /* Scan the rest of the glyph row from the end, looking for the
25231 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
25232 COVER_STRING, or whose position is between START_CHARPOS
25236 && !INTEGERP (end
->object
)
25237 && !EQ (end
->object
, cover_string
)
25238 && !(BUFFERP (end
->object
)
25239 && (end
->charpos
>= start_charpos
25240 && end
->charpos
< end_charpos
));
25243 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25244 are present at buffer positions between START_CHARPOS and
25245 END_CHARPOS, or if they come from an overlay. */
25246 if (EQ (end
->object
, before_string
))
25248 pos
= string_buffer_position (before_string
, start_charpos
);
25249 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25252 else if (EQ (end
->object
, after_string
))
25254 pos
= string_buffer_position (after_string
, end_charpos
);
25255 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25258 x
+= end
->pixel_width
;
25260 hlinfo
->mouse_face_end_x
= x
;
25261 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
25264 hlinfo
->mouse_face_window
= window
;
25265 hlinfo
->mouse_face_face_id
25266 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
25268 !hlinfo
->mouse_face_hidden
, -1);
25269 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25272 /* The following function is not used anymore (replaced with
25273 mouse_face_from_string_pos), but I leave it here for the time
25274 being, in case someone would. */
25276 #if 0 /* not used */
25278 /* Find the position of the glyph for position POS in OBJECT in
25279 window W's current matrix, and return in *X, *Y the pixel
25280 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
25282 RIGHT_P non-zero means return the position of the right edge of the
25283 glyph, RIGHT_P zero means return the left edge position.
25285 If no glyph for POS exists in the matrix, return the position of
25286 the glyph with the next smaller position that is in the matrix, if
25287 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
25288 exists in the matrix, return the position of the glyph with the
25289 next larger position in OBJECT.
25291 Value is non-zero if a glyph was found. */
25294 fast_find_string_pos (struct window
*w
, EMACS_INT pos
, Lisp_Object object
,
25295 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
25297 int yb
= window_text_bottom_y (w
);
25298 struct glyph_row
*r
;
25299 struct glyph
*best_glyph
= NULL
;
25300 struct glyph_row
*best_row
= NULL
;
25303 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25304 r
->enabled_p
&& r
->y
< yb
;
25307 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
25308 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
25311 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
25312 if (EQ (g
->object
, object
))
25314 if (g
->charpos
== pos
)
25321 else if (best_glyph
== NULL
25322 || ((eabs (g
->charpos
- pos
)
25323 < eabs (best_glyph
->charpos
- pos
))
25326 : g
->charpos
> pos
)))
25340 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
25344 *x
+= best_glyph
->pixel_width
;
25349 *vpos
= best_row
- w
->current_matrix
->rows
;
25352 return best_glyph
!= NULL
;
25354 #endif /* not used */
25356 /* Find the positions of the first and the last glyphs in window W's
25357 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
25358 (assumed to be a string), and return in HLINFO's mouse_face_*
25359 members the pixel and column/row coordinates of those glyphs. */
25362 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
25363 Lisp_Object object
,
25364 EMACS_INT startpos
, EMACS_INT endpos
)
25366 int yb
= window_text_bottom_y (w
);
25367 struct glyph_row
*r
;
25368 struct glyph
*g
, *e
;
25372 /* Find the glyph row with at least one position in the range
25373 [STARTPOS..ENDPOS], and the first glyph in that row whose
25374 position belongs to that range. */
25375 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25376 r
->enabled_p
&& r
->y
< yb
;
25379 if (!r
->reversed_p
)
25381 g
= r
->glyphs
[TEXT_AREA
];
25382 e
= g
+ r
->used
[TEXT_AREA
];
25383 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
25384 if (EQ (g
->object
, object
)
25385 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
25387 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
25388 hlinfo
->mouse_face_beg_y
= r
->y
;
25389 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
25390 hlinfo
->mouse_face_beg_x
= gx
;
25399 e
= r
->glyphs
[TEXT_AREA
];
25400 g
= e
+ r
->used
[TEXT_AREA
];
25401 for ( ; g
> e
; --g
)
25402 if (EQ ((g
-1)->object
, object
)
25403 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
25405 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
25406 hlinfo
->mouse_face_beg_y
= r
->y
;
25407 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
25408 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
25409 gx
+= g1
->pixel_width
;
25410 hlinfo
->mouse_face_beg_x
= gx
;
25422 /* Starting with the next row, look for the first row which does NOT
25423 include any glyphs whose positions are in the range. */
25424 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
25426 g
= r
->glyphs
[TEXT_AREA
];
25427 e
= g
+ r
->used
[TEXT_AREA
];
25429 for ( ; g
< e
; ++g
)
25430 if (EQ (g
->object
, object
)
25431 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
25440 /* The highlighted region ends on the previous row. */
25443 /* Set the end row and its vertical pixel coordinate. */
25444 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
25445 hlinfo
->mouse_face_end_y
= r
->y
;
25447 /* Compute and set the end column and the end column's horizontal
25448 pixel coordinate. */
25449 if (!r
->reversed_p
)
25451 g
= r
->glyphs
[TEXT_AREA
];
25452 e
= g
+ r
->used
[TEXT_AREA
];
25453 for ( ; e
> g
; --e
)
25454 if (EQ ((e
-1)->object
, object
)
25455 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
25457 hlinfo
->mouse_face_end_col
= e
- g
;
25459 for (gx
= r
->x
; g
< e
; ++g
)
25460 gx
+= g
->pixel_width
;
25461 hlinfo
->mouse_face_end_x
= gx
;
25465 e
= r
->glyphs
[TEXT_AREA
];
25466 g
= e
+ r
->used
[TEXT_AREA
];
25467 for (gx
= r
->x
; e
< g
; ++e
)
25469 if (EQ (e
->object
, object
)
25470 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
25472 gx
+= e
->pixel_width
;
25474 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
25475 hlinfo
->mouse_face_end_x
= gx
;
25479 #ifdef HAVE_WINDOW_SYSTEM
25481 /* See if position X, Y is within a hot-spot of an image. */
25484 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
25486 if (!CONSP (hot_spot
))
25489 if (EQ (XCAR (hot_spot
), Qrect
))
25491 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
25492 Lisp_Object rect
= XCDR (hot_spot
);
25496 if (!CONSP (XCAR (rect
)))
25498 if (!CONSP (XCDR (rect
)))
25500 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
25502 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
25504 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
25506 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
25510 else if (EQ (XCAR (hot_spot
), Qcircle
))
25512 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
25513 Lisp_Object circ
= XCDR (hot_spot
);
25514 Lisp_Object lr
, lx0
, ly0
;
25516 && CONSP (XCAR (circ
))
25517 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
25518 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
25519 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
25521 double r
= XFLOATINT (lr
);
25522 double dx
= XINT (lx0
) - x
;
25523 double dy
= XINT (ly0
) - y
;
25524 return (dx
* dx
+ dy
* dy
<= r
* r
);
25527 else if (EQ (XCAR (hot_spot
), Qpoly
))
25529 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
25530 if (VECTORP (XCDR (hot_spot
)))
25532 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
25533 Lisp_Object
*poly
= v
->contents
;
25534 int n
= v
->header
.size
;
25537 Lisp_Object lx
, ly
;
25540 /* Need an even number of coordinates, and at least 3 edges. */
25541 if (n
< 6 || n
& 1)
25544 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
25545 If count is odd, we are inside polygon. Pixels on edges
25546 may or may not be included depending on actual geometry of the
25548 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
25549 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
25551 x0
= XINT (lx
), y0
= XINT (ly
);
25552 for (i
= 0; i
< n
; i
+= 2)
25554 int x1
= x0
, y1
= y0
;
25555 if ((lx
= poly
[i
], !INTEGERP (lx
))
25556 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
25558 x0
= XINT (lx
), y0
= XINT (ly
);
25560 /* Does this segment cross the X line? */
25568 if (y
> y0
&& y
> y1
)
25570 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
25580 find_hot_spot (Lisp_Object map
, int x
, int y
)
25582 while (CONSP (map
))
25584 if (CONSP (XCAR (map
))
25585 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
25593 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
25595 doc
: /* Lookup in image map MAP coordinates X and Y.
25596 An image map is an alist where each element has the format (AREA ID PLIST).
25597 An AREA is specified as either a rectangle, a circle, or a polygon:
25598 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
25599 pixel coordinates of the upper left and bottom right corners.
25600 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
25601 and the radius of the circle; r may be a float or integer.
25602 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
25603 vector describes one corner in the polygon.
25604 Returns the alist element for the first matching AREA in MAP. */)
25605 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
25613 return find_hot_spot (map
, XINT (x
), XINT (y
));
25617 /* Display frame CURSOR, optionally using shape defined by POINTER. */
25619 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
25621 /* Do not change cursor shape while dragging mouse. */
25622 if (!NILP (do_mouse_tracking
))
25625 if (!NILP (pointer
))
25627 if (EQ (pointer
, Qarrow
))
25628 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25629 else if (EQ (pointer
, Qhand
))
25630 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
25631 else if (EQ (pointer
, Qtext
))
25632 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25633 else if (EQ (pointer
, intern ("hdrag")))
25634 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25635 #ifdef HAVE_X_WINDOWS
25636 else if (EQ (pointer
, intern ("vdrag")))
25637 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
25639 else if (EQ (pointer
, intern ("hourglass")))
25640 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
25641 else if (EQ (pointer
, Qmodeline
))
25642 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
25644 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25647 if (cursor
!= No_Cursor
)
25648 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
25651 #endif /* HAVE_WINDOW_SYSTEM */
25653 /* Take proper action when mouse has moved to the mode or header line
25654 or marginal area AREA of window W, x-position X and y-position Y.
25655 X is relative to the start of the text display area of W, so the
25656 width of bitmap areas and scroll bars must be subtracted to get a
25657 position relative to the start of the mode line. */
25660 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
25661 enum window_part area
)
25663 struct window
*w
= XWINDOW (window
);
25664 struct frame
*f
= XFRAME (w
->frame
);
25665 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25666 #ifdef HAVE_WINDOW_SYSTEM
25667 Display_Info
*dpyinfo
;
25669 Cursor cursor
= No_Cursor
;
25670 Lisp_Object pointer
= Qnil
;
25671 int dx
, dy
, width
, height
;
25673 Lisp_Object string
, object
= Qnil
;
25674 Lisp_Object pos
, help
;
25676 Lisp_Object mouse_face
;
25677 int original_x_pixel
= x
;
25678 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
25679 struct glyph_row
*row
;
25681 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
25686 /* Kludge alert: mode_line_string takes X/Y in pixels, but
25687 returns them in row/column units! */
25688 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
25689 &object
, &dx
, &dy
, &width
, &height
);
25691 row
= (area
== ON_MODE_LINE
25692 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
25693 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
25695 /* Find the glyph under the mouse pointer. */
25696 if (row
->mode_line_p
&& row
->enabled_p
)
25698 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
25699 end
= glyph
+ row
->used
[TEXT_AREA
];
25701 for (x0
= original_x_pixel
;
25702 glyph
< end
&& x0
>= glyph
->pixel_width
;
25704 x0
-= glyph
->pixel_width
;
25712 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
25713 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
25714 returns them in row/column units! */
25715 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
25716 &object
, &dx
, &dy
, &width
, &height
);
25721 #ifdef HAVE_WINDOW_SYSTEM
25722 if (IMAGEP (object
))
25724 Lisp_Object image_map
, hotspot
;
25725 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
25727 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
25729 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25733 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
25734 If so, we could look for mouse-enter, mouse-leave
25735 properties in PLIST (and do something...). */
25736 hotspot
= XCDR (hotspot
);
25737 if (CONSP (hotspot
)
25738 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25740 pointer
= Fplist_get (plist
, Qpointer
);
25741 if (NILP (pointer
))
25743 help
= Fplist_get (plist
, Qhelp_echo
);
25746 help_echo_string
= help
;
25747 /* Is this correct? ++kfs */
25748 XSETWINDOW (help_echo_window
, w
);
25749 help_echo_object
= w
->buffer
;
25750 help_echo_pos
= charpos
;
25754 if (NILP (pointer
))
25755 pointer
= Fplist_get (XCDR (object
), QCpointer
);
25757 #endif /* HAVE_WINDOW_SYSTEM */
25759 if (STRINGP (string
))
25761 pos
= make_number (charpos
);
25762 /* If we're on a string with `help-echo' text property, arrange
25763 for the help to be displayed. This is done by setting the
25764 global variable help_echo_string to the help string. */
25767 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
25770 help_echo_string
= help
;
25771 XSETWINDOW (help_echo_window
, w
);
25772 help_echo_object
= string
;
25773 help_echo_pos
= charpos
;
25777 #ifdef HAVE_WINDOW_SYSTEM
25778 if (FRAME_WINDOW_P (f
))
25780 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25781 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25782 if (NILP (pointer
))
25783 pointer
= Fget_text_property (pos
, Qpointer
, string
);
25785 /* Change the mouse pointer according to what is under X/Y. */
25787 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
25790 map
= Fget_text_property (pos
, Qlocal_map
, string
);
25791 if (!KEYMAPP (map
))
25792 map
= Fget_text_property (pos
, Qkeymap
, string
);
25793 if (!KEYMAPP (map
))
25794 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
25799 /* Change the mouse face according to what is under X/Y. */
25800 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
25801 if (!NILP (mouse_face
)
25802 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25807 struct glyph
* tmp_glyph
;
25811 int total_pixel_width
;
25812 EMACS_INT begpos
, endpos
, ignore
;
25816 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
25817 Qmouse_face
, string
, Qnil
);
25823 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
25825 endpos
= SCHARS (string
);
25829 /* Calculate the glyph position GPOS of GLYPH in the
25830 displayed string, relative to the beginning of the
25831 highlighted part of the string.
25833 Note: GPOS is different from CHARPOS. CHARPOS is the
25834 position of GLYPH in the internal string object. A mode
25835 line string format has structures which are converted to
25836 a flattened string by the Emacs Lisp interpreter. The
25837 internal string is an element of those structures. The
25838 displayed string is the flattened string. */
25839 tmp_glyph
= row_start_glyph
;
25840 while (tmp_glyph
< glyph
25841 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25842 && begpos
<= tmp_glyph
->charpos
25843 && tmp_glyph
->charpos
< endpos
)))
25845 gpos
= glyph
- tmp_glyph
;
25847 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
25848 the highlighted part of the displayed string to which
25849 GLYPH belongs. Note: GSEQ_LENGTH is different from
25850 SCHARS (STRING), because the latter returns the length of
25851 the internal string. */
25852 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
25854 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25855 && begpos
<= tmp_glyph
->charpos
25856 && tmp_glyph
->charpos
< endpos
));
25859 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
25861 /* Calculate the total pixel width of all the glyphs between
25862 the beginning of the highlighted area and GLYPH. */
25863 total_pixel_width
= 0;
25864 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
25865 total_pixel_width
+= tmp_glyph
->pixel_width
;
25867 /* Pre calculation of re-rendering position. Note: X is in
25868 column units here, after the call to mode_line_string or
25869 marginal_area_string. */
25871 vpos
= (area
== ON_MODE_LINE
25872 ? (w
->current_matrix
)->nrows
- 1
25875 /* If GLYPH's position is included in the region that is
25876 already drawn in mouse face, we have nothing to do. */
25877 if ( EQ (window
, hlinfo
->mouse_face_window
)
25878 && (!row
->reversed_p
25879 ? (hlinfo
->mouse_face_beg_col
<= hpos
25880 && hpos
< hlinfo
->mouse_face_end_col
)
25881 /* In R2L rows we swap BEG and END, see below. */
25882 : (hlinfo
->mouse_face_end_col
<= hpos
25883 && hpos
< hlinfo
->mouse_face_beg_col
))
25884 && hlinfo
->mouse_face_beg_row
== vpos
)
25887 if (clear_mouse_face (hlinfo
))
25888 cursor
= No_Cursor
;
25890 if (!row
->reversed_p
)
25892 hlinfo
->mouse_face_beg_col
= hpos
;
25893 hlinfo
->mouse_face_beg_x
= original_x_pixel
25894 - (total_pixel_width
+ dx
);
25895 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
25896 hlinfo
->mouse_face_end_x
= 0;
25900 /* In R2L rows, show_mouse_face expects BEG and END
25901 coordinates to be swapped. */
25902 hlinfo
->mouse_face_end_col
= hpos
;
25903 hlinfo
->mouse_face_end_x
= original_x_pixel
25904 - (total_pixel_width
+ dx
);
25905 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
25906 hlinfo
->mouse_face_beg_x
= 0;
25909 hlinfo
->mouse_face_beg_row
= vpos
;
25910 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
25911 hlinfo
->mouse_face_beg_y
= 0;
25912 hlinfo
->mouse_face_end_y
= 0;
25913 hlinfo
->mouse_face_past_end
= 0;
25914 hlinfo
->mouse_face_window
= window
;
25916 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
25922 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25924 if (NILP (pointer
))
25927 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25928 clear_mouse_face (hlinfo
);
25930 #ifdef HAVE_WINDOW_SYSTEM
25931 if (FRAME_WINDOW_P (f
))
25932 define_frame_cursor1 (f
, cursor
, pointer
);
25938 Take proper action when the mouse has moved to position X, Y on
25939 frame F as regards highlighting characters that have mouse-face
25940 properties. Also de-highlighting chars where the mouse was before.
25941 X and Y can be negative or out of range. */
25944 note_mouse_highlight (struct frame
*f
, int x
, int y
)
25946 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25947 enum window_part part
;
25948 Lisp_Object window
;
25950 Cursor cursor
= No_Cursor
;
25951 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
25954 /* When a menu is active, don't highlight because this looks odd. */
25955 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
25956 if (popup_activated ())
25960 if (NILP (Vmouse_highlight
)
25961 || !f
->glyphs_initialized_p
25962 || f
->pointer_invisible
)
25965 hlinfo
->mouse_face_mouse_x
= x
;
25966 hlinfo
->mouse_face_mouse_y
= y
;
25967 hlinfo
->mouse_face_mouse_frame
= f
;
25969 if (hlinfo
->mouse_face_defer
)
25972 if (gc_in_progress
)
25974 hlinfo
->mouse_face_deferred_gc
= 1;
25978 /* Which window is that in? */
25979 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
25981 /* If we were displaying active text in another window, clear that.
25982 Also clear if we move out of text area in same window. */
25983 if (! EQ (window
, hlinfo
->mouse_face_window
)
25984 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
25985 && !NILP (hlinfo
->mouse_face_window
)))
25986 clear_mouse_face (hlinfo
);
25988 /* Not on a window -> return. */
25989 if (!WINDOWP (window
))
25992 /* Reset help_echo_string. It will get recomputed below. */
25993 help_echo_string
= Qnil
;
25995 /* Convert to window-relative pixel coordinates. */
25996 w
= XWINDOW (window
);
25997 frame_to_window_pixel_xy (w
, &x
, &y
);
25999 #ifdef HAVE_WINDOW_SYSTEM
26000 /* Handle tool-bar window differently since it doesn't display a
26002 if (EQ (window
, f
->tool_bar_window
))
26004 note_tool_bar_highlight (f
, x
, y
);
26009 /* Mouse is on the mode, header line or margin? */
26010 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
26011 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
26013 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
26017 #ifdef HAVE_WINDOW_SYSTEM
26018 if (part
== ON_VERTICAL_BORDER
)
26020 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
26021 help_echo_string
= build_string ("drag-mouse-1: resize");
26023 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
26024 || part
== ON_SCROLL_BAR
)
26025 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26027 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
26030 /* Are we in a window whose display is up to date?
26031 And verify the buffer's text has not changed. */
26032 b
= XBUFFER (w
->buffer
);
26033 if (part
== ON_TEXT
26034 && EQ (w
->window_end_valid
, w
->buffer
)
26035 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
26036 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
26038 int hpos
, vpos
, i
, dx
, dy
, area
;
26040 struct glyph
*glyph
;
26041 Lisp_Object object
;
26042 Lisp_Object mouse_face
= Qnil
, position
;
26043 Lisp_Object
*overlay_vec
= NULL
;
26045 struct buffer
*obuf
;
26046 EMACS_INT obegv
, ozv
;
26049 /* Find the glyph under X/Y. */
26050 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
26052 #ifdef HAVE_WINDOW_SYSTEM
26053 /* Look for :pointer property on image. */
26054 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26056 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26057 if (img
!= NULL
&& IMAGEP (img
->spec
))
26059 Lisp_Object image_map
, hotspot
;
26060 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
26062 && (hotspot
= find_hot_spot (image_map
,
26063 glyph
->slice
.img
.x
+ dx
,
26064 glyph
->slice
.img
.y
+ dy
),
26066 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
26070 /* Could check XCAR (hotspot) to see if we enter/leave
26072 If so, we could look for mouse-enter, mouse-leave
26073 properties in PLIST (and do something...). */
26074 hotspot
= XCDR (hotspot
);
26075 if (CONSP (hotspot
)
26076 && (plist
= XCAR (hotspot
), CONSP (plist
)))
26078 pointer
= Fplist_get (plist
, Qpointer
);
26079 if (NILP (pointer
))
26081 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
26082 if (!NILP (help_echo_string
))
26084 help_echo_window
= window
;
26085 help_echo_object
= glyph
->object
;
26086 help_echo_pos
= glyph
->charpos
;
26090 if (NILP (pointer
))
26091 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
26094 #endif /* HAVE_WINDOW_SYSTEM */
26096 /* Clear mouse face if X/Y not over text. */
26098 || area
!= TEXT_AREA
26099 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
26100 /* Glyph's OBJECT is an integer for glyphs inserted by the
26101 display engine for its internal purposes, like truncation
26102 and continuation glyphs and blanks beyond the end of
26103 line's text on text terminals. If we are over such a
26104 glyph, we are not over any text. */
26105 || INTEGERP (glyph
->object
)
26106 /* R2L rows have a stretch glyph at their front, which
26107 stands for no text, whereas L2R rows have no glyphs at
26108 all beyond the end of text. Treat such stretch glyphs
26109 like we do with NULL glyphs in L2R rows. */
26110 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
26111 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
26112 && glyph
->type
== STRETCH_GLYPH
26113 && glyph
->avoid_cursor_p
))
26115 if (clear_mouse_face (hlinfo
))
26116 cursor
= No_Cursor
;
26117 #ifdef HAVE_WINDOW_SYSTEM
26118 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
26120 if (area
!= TEXT_AREA
)
26121 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26123 pointer
= Vvoid_text_area_pointer
;
26129 pos
= glyph
->charpos
;
26130 object
= glyph
->object
;
26131 if (!STRINGP (object
) && !BUFFERP (object
))
26134 /* If we get an out-of-range value, return now; avoid an error. */
26135 if (BUFFERP (object
) && pos
> BUF_Z (b
))
26138 /* Make the window's buffer temporarily current for
26139 overlays_at and compute_char_face. */
26140 obuf
= current_buffer
;
26141 current_buffer
= b
;
26147 /* Is this char mouse-active or does it have help-echo? */
26148 position
= make_number (pos
);
26150 if (BUFFERP (object
))
26152 /* Put all the overlays we want in a vector in overlay_vec. */
26153 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
26154 /* Sort overlays into increasing priority order. */
26155 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
26160 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
26163 cursor
= No_Cursor
;
26165 /* Check mouse-face highlighting. */
26167 /* If there exists an overlay with mouse-face overlapping
26168 the one we are currently highlighting, we have to
26169 check if we enter the overlapping overlay, and then
26170 highlight only that. */
26171 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
26172 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
26174 /* Find the highest priority overlay with a mouse-face. */
26175 Lisp_Object overlay
= Qnil
;
26176 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
26178 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
26179 if (!NILP (mouse_face
))
26180 overlay
= overlay_vec
[i
];
26183 /* If we're highlighting the same overlay as before, there's
26184 no need to do that again. */
26185 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
26186 goto check_help_echo
;
26187 hlinfo
->mouse_face_overlay
= overlay
;
26189 /* Clear the display of the old active region, if any. */
26190 if (clear_mouse_face (hlinfo
))
26191 cursor
= No_Cursor
;
26193 /* If no overlay applies, get a text property. */
26194 if (NILP (overlay
))
26195 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
26197 /* Next, compute the bounds of the mouse highlighting and
26199 if (!NILP (mouse_face
) && STRINGP (object
))
26201 /* The mouse-highlighting comes from a display string
26202 with a mouse-face. */
26206 s
= Fprevious_single_property_change
26207 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
26208 e
= Fnext_single_property_change
26209 (position
, Qmouse_face
, object
, Qnil
);
26211 s
= make_number (0);
26213 e
= make_number (SCHARS (object
) - 1);
26214 mouse_face_from_string_pos (w
, hlinfo
, object
,
26215 XINT (s
), XINT (e
));
26216 hlinfo
->mouse_face_past_end
= 0;
26217 hlinfo
->mouse_face_window
= window
;
26218 hlinfo
->mouse_face_face_id
26219 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
26220 glyph
->face_id
, 1);
26221 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26222 cursor
= No_Cursor
;
26226 /* The mouse-highlighting, if any, comes from an overlay
26227 or text property in the buffer. */
26228 Lisp_Object buffer
IF_LINT (= Qnil
);
26229 Lisp_Object cover_string
IF_LINT (= Qnil
);
26231 if (STRINGP (object
))
26233 /* If we are on a display string with no mouse-face,
26234 check if the text under it has one. */
26235 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
26236 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26237 pos
= string_buffer_position (object
, start
);
26240 mouse_face
= get_char_property_and_overlay
26241 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
26242 buffer
= w
->buffer
;
26243 cover_string
= object
;
26249 cover_string
= Qnil
;
26252 if (!NILP (mouse_face
))
26254 Lisp_Object before
, after
;
26255 Lisp_Object before_string
, after_string
;
26256 /* To correctly find the limits of mouse highlight
26257 in a bidi-reordered buffer, we must not use the
26258 optimization of limiting the search in
26259 previous-single-property-change and
26260 next-single-property-change, because
26261 rows_from_pos_range needs the real start and end
26262 positions to DTRT in this case. That's because
26263 the first row visible in a window does not
26264 necessarily display the character whose position
26265 is the smallest. */
26267 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
26268 ? Fmarker_position (w
->start
)
26271 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
26272 ? make_number (BUF_Z (XBUFFER (buffer
))
26273 - XFASTINT (w
->window_end_pos
))
26276 if (NILP (overlay
))
26278 /* Handle the text property case. */
26279 before
= Fprevious_single_property_change
26280 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
26281 after
= Fnext_single_property_change
26282 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
26283 before_string
= after_string
= Qnil
;
26287 /* Handle the overlay case. */
26288 before
= Foverlay_start (overlay
);
26289 after
= Foverlay_end (overlay
);
26290 before_string
= Foverlay_get (overlay
, Qbefore_string
);
26291 after_string
= Foverlay_get (overlay
, Qafter_string
);
26293 if (!STRINGP (before_string
)) before_string
= Qnil
;
26294 if (!STRINGP (after_string
)) after_string
= Qnil
;
26297 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
26300 before_string
, after_string
,
26302 cursor
= No_Cursor
;
26309 /* Look for a `help-echo' property. */
26310 if (NILP (help_echo_string
)) {
26311 Lisp_Object help
, overlay
;
26313 /* Check overlays first. */
26314 help
= overlay
= Qnil
;
26315 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
26317 overlay
= overlay_vec
[i
];
26318 help
= Foverlay_get (overlay
, Qhelp_echo
);
26323 help_echo_string
= help
;
26324 help_echo_window
= window
;
26325 help_echo_object
= overlay
;
26326 help_echo_pos
= pos
;
26330 Lisp_Object obj
= glyph
->object
;
26331 EMACS_INT charpos
= glyph
->charpos
;
26333 /* Try text properties. */
26336 && charpos
< SCHARS (obj
))
26338 help
= Fget_text_property (make_number (charpos
),
26342 /* If the string itself doesn't specify a help-echo,
26343 see if the buffer text ``under'' it does. */
26344 struct glyph_row
*r
26345 = MATRIX_ROW (w
->current_matrix
, vpos
);
26346 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26347 EMACS_INT p
= string_buffer_position (obj
, start
);
26350 help
= Fget_char_property (make_number (p
),
26351 Qhelp_echo
, w
->buffer
);
26360 else if (BUFFERP (obj
)
26363 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
26368 help_echo_string
= help
;
26369 help_echo_window
= window
;
26370 help_echo_object
= obj
;
26371 help_echo_pos
= charpos
;
26376 #ifdef HAVE_WINDOW_SYSTEM
26377 /* Look for a `pointer' property. */
26378 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
26380 /* Check overlays first. */
26381 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
26382 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
26384 if (NILP (pointer
))
26386 Lisp_Object obj
= glyph
->object
;
26387 EMACS_INT charpos
= glyph
->charpos
;
26389 /* Try text properties. */
26392 && charpos
< SCHARS (obj
))
26394 pointer
= Fget_text_property (make_number (charpos
),
26396 if (NILP (pointer
))
26398 /* If the string itself doesn't specify a pointer,
26399 see if the buffer text ``under'' it does. */
26400 struct glyph_row
*r
26401 = MATRIX_ROW (w
->current_matrix
, vpos
);
26402 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26403 EMACS_INT p
= string_buffer_position (obj
, start
);
26405 pointer
= Fget_char_property (make_number (p
),
26406 Qpointer
, w
->buffer
);
26409 else if (BUFFERP (obj
)
26412 pointer
= Fget_text_property (make_number (charpos
),
26416 #endif /* HAVE_WINDOW_SYSTEM */
26420 current_buffer
= obuf
;
26425 #ifdef HAVE_WINDOW_SYSTEM
26426 if (FRAME_WINDOW_P (f
))
26427 define_frame_cursor1 (f
, cursor
, pointer
);
26429 /* This is here to prevent a compiler error, about "label at end of
26430 compound statement". */
26437 Clear any mouse-face on window W. This function is part of the
26438 redisplay interface, and is called from try_window_id and similar
26439 functions to ensure the mouse-highlight is off. */
26442 x_clear_window_mouse_face (struct window
*w
)
26444 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26445 Lisp_Object window
;
26448 XSETWINDOW (window
, w
);
26449 if (EQ (window
, hlinfo
->mouse_face_window
))
26450 clear_mouse_face (hlinfo
);
26456 Just discard the mouse face information for frame F, if any.
26457 This is used when the size of F is changed. */
26460 cancel_mouse_face (struct frame
*f
)
26462 Lisp_Object window
;
26463 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26465 window
= hlinfo
->mouse_face_window
;
26466 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
26468 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26469 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26470 hlinfo
->mouse_face_window
= Qnil
;
26476 /***********************************************************************
26478 ***********************************************************************/
26480 #ifdef HAVE_WINDOW_SYSTEM
26482 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
26483 which intersects rectangle R. R is in window-relative coordinates. */
26486 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
26487 enum glyph_row_area area
)
26489 struct glyph
*first
= row
->glyphs
[area
];
26490 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
26491 struct glyph
*last
;
26492 int first_x
, start_x
, x
;
26494 if (area
== TEXT_AREA
&& row
->fill_line_p
)
26495 /* If row extends face to end of line write the whole line. */
26496 draw_glyphs (w
, 0, row
, area
,
26497 0, row
->used
[area
],
26498 DRAW_NORMAL_TEXT
, 0);
26501 /* Set START_X to the window-relative start position for drawing glyphs of
26502 AREA. The first glyph of the text area can be partially visible.
26503 The first glyphs of other areas cannot. */
26504 start_x
= window_box_left_offset (w
, area
);
26506 if (area
== TEXT_AREA
)
26509 /* Find the first glyph that must be redrawn. */
26511 && x
+ first
->pixel_width
< r
->x
)
26513 x
+= first
->pixel_width
;
26517 /* Find the last one. */
26521 && x
< r
->x
+ r
->width
)
26523 x
+= last
->pixel_width
;
26529 draw_glyphs (w
, first_x
- start_x
, row
, area
,
26530 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
26531 DRAW_NORMAL_TEXT
, 0);
26536 /* Redraw the parts of the glyph row ROW on window W intersecting
26537 rectangle R. R is in window-relative coordinates. Value is
26538 non-zero if mouse-face was overwritten. */
26541 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
26543 xassert (row
->enabled_p
);
26545 if (row
->mode_line_p
|| w
->pseudo_window_p
)
26546 draw_glyphs (w
, 0, row
, TEXT_AREA
,
26547 0, row
->used
[TEXT_AREA
],
26548 DRAW_NORMAL_TEXT
, 0);
26551 if (row
->used
[LEFT_MARGIN_AREA
])
26552 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
26553 if (row
->used
[TEXT_AREA
])
26554 expose_area (w
, row
, r
, TEXT_AREA
);
26555 if (row
->used
[RIGHT_MARGIN_AREA
])
26556 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
26557 draw_row_fringe_bitmaps (w
, row
);
26560 return row
->mouse_face_p
;
26564 /* Redraw those parts of glyphs rows during expose event handling that
26565 overlap other rows. Redrawing of an exposed line writes over parts
26566 of lines overlapping that exposed line; this function fixes that.
26568 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
26569 row in W's current matrix that is exposed and overlaps other rows.
26570 LAST_OVERLAPPING_ROW is the last such row. */
26573 expose_overlaps (struct window
*w
,
26574 struct glyph_row
*first_overlapping_row
,
26575 struct glyph_row
*last_overlapping_row
,
26578 struct glyph_row
*row
;
26580 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
26581 if (row
->overlapping_p
)
26583 xassert (row
->enabled_p
&& !row
->mode_line_p
);
26586 if (row
->used
[LEFT_MARGIN_AREA
])
26587 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
26589 if (row
->used
[TEXT_AREA
])
26590 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
26592 if (row
->used
[RIGHT_MARGIN_AREA
])
26593 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
26599 /* Return non-zero if W's cursor intersects rectangle R. */
26602 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
26604 XRectangle cr
, result
;
26605 struct glyph
*cursor_glyph
;
26606 struct glyph_row
*row
;
26608 if (w
->phys_cursor
.vpos
>= 0
26609 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
26610 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
26612 && row
->cursor_in_fringe_p
)
26614 /* Cursor is in the fringe. */
26615 cr
.x
= window_box_right_offset (w
,
26616 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
26617 ? RIGHT_MARGIN_AREA
26620 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
26621 cr
.height
= row
->height
;
26622 return x_intersect_rectangles (&cr
, r
, &result
);
26625 cursor_glyph
= get_phys_cursor_glyph (w
);
26628 /* r is relative to W's box, but w->phys_cursor.x is relative
26629 to left edge of W's TEXT area. Adjust it. */
26630 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
26631 cr
.y
= w
->phys_cursor
.y
;
26632 cr
.width
= cursor_glyph
->pixel_width
;
26633 cr
.height
= w
->phys_cursor_height
;
26634 /* ++KFS: W32 version used W32-specific IntersectRect here, but
26635 I assume the effect is the same -- and this is portable. */
26636 return x_intersect_rectangles (&cr
, r
, &result
);
26638 /* If we don't understand the format, pretend we're not in the hot-spot. */
26644 Draw a vertical window border to the right of window W if W doesn't
26645 have vertical scroll bars. */
26648 x_draw_vertical_border (struct window
*w
)
26650 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26652 /* We could do better, if we knew what type of scroll-bar the adjacent
26653 windows (on either side) have... But we don't :-(
26654 However, I think this works ok. ++KFS 2003-04-25 */
26656 /* Redraw borders between horizontally adjacent windows. Don't
26657 do it for frames with vertical scroll bars because either the
26658 right scroll bar of a window, or the left scroll bar of its
26659 neighbor will suffice as a border. */
26660 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
26663 if (!WINDOW_RIGHTMOST_P (w
)
26664 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
26666 int x0
, x1
, y0
, y1
;
26668 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26671 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26674 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
26676 else if (!WINDOW_LEFTMOST_P (w
)
26677 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
26679 int x0
, x1
, y0
, y1
;
26681 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26684 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26687 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
26692 /* Redraw the part of window W intersection rectangle FR. Pixel
26693 coordinates in FR are frame-relative. Call this function with
26694 input blocked. Value is non-zero if the exposure overwrites
26698 expose_window (struct window
*w
, XRectangle
*fr
)
26700 struct frame
*f
= XFRAME (w
->frame
);
26702 int mouse_face_overwritten_p
= 0;
26704 /* If window is not yet fully initialized, do nothing. This can
26705 happen when toolkit scroll bars are used and a window is split.
26706 Reconfiguring the scroll bar will generate an expose for a newly
26708 if (w
->current_matrix
== NULL
)
26711 /* When we're currently updating the window, display and current
26712 matrix usually don't agree. Arrange for a thorough display
26714 if (w
== updated_window
)
26716 SET_FRAME_GARBAGED (f
);
26720 /* Frame-relative pixel rectangle of W. */
26721 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
26722 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
26723 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
26724 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
26726 if (x_intersect_rectangles (fr
, &wr
, &r
))
26728 int yb
= window_text_bottom_y (w
);
26729 struct glyph_row
*row
;
26730 int cursor_cleared_p
;
26731 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
26733 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
26734 r
.x
, r
.y
, r
.width
, r
.height
));
26736 /* Convert to window coordinates. */
26737 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
26738 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
26740 /* Turn off the cursor. */
26741 if (!w
->pseudo_window_p
26742 && phys_cursor_in_rect_p (w
, &r
))
26744 x_clear_cursor (w
);
26745 cursor_cleared_p
= 1;
26748 cursor_cleared_p
= 0;
26750 /* Update lines intersecting rectangle R. */
26751 first_overlapping_row
= last_overlapping_row
= NULL
;
26752 for (row
= w
->current_matrix
->rows
;
26757 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
26759 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
26760 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
26761 || (r
.y
>= y0
&& r
.y
< y1
)
26762 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
26764 /* A header line may be overlapping, but there is no need
26765 to fix overlapping areas for them. KFS 2005-02-12 */
26766 if (row
->overlapping_p
&& !row
->mode_line_p
)
26768 if (first_overlapping_row
== NULL
)
26769 first_overlapping_row
= row
;
26770 last_overlapping_row
= row
;
26774 if (expose_line (w
, row
, &r
))
26775 mouse_face_overwritten_p
= 1;
26778 else if (row
->overlapping_p
)
26780 /* We must redraw a row overlapping the exposed area. */
26782 ? y0
+ row
->phys_height
> r
.y
26783 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
26785 if (first_overlapping_row
== NULL
)
26786 first_overlapping_row
= row
;
26787 last_overlapping_row
= row
;
26795 /* Display the mode line if there is one. */
26796 if (WINDOW_WANTS_MODELINE_P (w
)
26797 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
26799 && row
->y
< r
.y
+ r
.height
)
26801 if (expose_line (w
, row
, &r
))
26802 mouse_face_overwritten_p
= 1;
26805 if (!w
->pseudo_window_p
)
26807 /* Fix the display of overlapping rows. */
26808 if (first_overlapping_row
)
26809 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
26812 /* Draw border between windows. */
26813 x_draw_vertical_border (w
);
26815 /* Turn the cursor on again. */
26816 if (cursor_cleared_p
)
26817 update_window_cursor (w
, 1);
26821 return mouse_face_overwritten_p
;
26826 /* Redraw (parts) of all windows in the window tree rooted at W that
26827 intersect R. R contains frame pixel coordinates. Value is
26828 non-zero if the exposure overwrites mouse-face. */
26831 expose_window_tree (struct window
*w
, XRectangle
*r
)
26833 struct frame
*f
= XFRAME (w
->frame
);
26834 int mouse_face_overwritten_p
= 0;
26836 while (w
&& !FRAME_GARBAGED_P (f
))
26838 if (!NILP (w
->hchild
))
26839 mouse_face_overwritten_p
26840 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
26841 else if (!NILP (w
->vchild
))
26842 mouse_face_overwritten_p
26843 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
26845 mouse_face_overwritten_p
|= expose_window (w
, r
);
26847 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
26850 return mouse_face_overwritten_p
;
26855 Redisplay an exposed area of frame F. X and Y are the upper-left
26856 corner of the exposed rectangle. W and H are width and height of
26857 the exposed area. All are pixel values. W or H zero means redraw
26858 the entire frame. */
26861 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
26864 int mouse_face_overwritten_p
= 0;
26866 TRACE ((stderr
, "expose_frame "));
26868 /* No need to redraw if frame will be redrawn soon. */
26869 if (FRAME_GARBAGED_P (f
))
26871 TRACE ((stderr
, " garbaged\n"));
26875 /* If basic faces haven't been realized yet, there is no point in
26876 trying to redraw anything. This can happen when we get an expose
26877 event while Emacs is starting, e.g. by moving another window. */
26878 if (FRAME_FACE_CACHE (f
) == NULL
26879 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
26881 TRACE ((stderr
, " no faces\n"));
26885 if (w
== 0 || h
== 0)
26888 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
26889 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
26899 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
26900 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
26902 if (WINDOWP (f
->tool_bar_window
))
26903 mouse_face_overwritten_p
26904 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
26906 #ifdef HAVE_X_WINDOWS
26908 #ifndef USE_X_TOOLKIT
26909 if (WINDOWP (f
->menu_bar_window
))
26910 mouse_face_overwritten_p
26911 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
26912 #endif /* not USE_X_TOOLKIT */
26916 /* Some window managers support a focus-follows-mouse style with
26917 delayed raising of frames. Imagine a partially obscured frame,
26918 and moving the mouse into partially obscured mouse-face on that
26919 frame. The visible part of the mouse-face will be highlighted,
26920 then the WM raises the obscured frame. With at least one WM, KDE
26921 2.1, Emacs is not getting any event for the raising of the frame
26922 (even tried with SubstructureRedirectMask), only Expose events.
26923 These expose events will draw text normally, i.e. not
26924 highlighted. Which means we must redo the highlight here.
26925 Subsume it under ``we love X''. --gerd 2001-08-15 */
26926 /* Included in Windows version because Windows most likely does not
26927 do the right thing if any third party tool offers
26928 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
26929 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
26931 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26932 if (f
== hlinfo
->mouse_face_mouse_frame
)
26934 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
26935 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
26936 clear_mouse_face (hlinfo
);
26937 note_mouse_highlight (f
, mouse_x
, mouse_y
);
26944 Determine the intersection of two rectangles R1 and R2. Return
26945 the intersection in *RESULT. Value is non-zero if RESULT is not
26949 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
26951 XRectangle
*left
, *right
;
26952 XRectangle
*upper
, *lower
;
26953 int intersection_p
= 0;
26955 /* Rearrange so that R1 is the left-most rectangle. */
26957 left
= r1
, right
= r2
;
26959 left
= r2
, right
= r1
;
26961 /* X0 of the intersection is right.x0, if this is inside R1,
26962 otherwise there is no intersection. */
26963 if (right
->x
<= left
->x
+ left
->width
)
26965 result
->x
= right
->x
;
26967 /* The right end of the intersection is the minimum of the
26968 the right ends of left and right. */
26969 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
26972 /* Same game for Y. */
26974 upper
= r1
, lower
= r2
;
26976 upper
= r2
, lower
= r1
;
26978 /* The upper end of the intersection is lower.y0, if this is inside
26979 of upper. Otherwise, there is no intersection. */
26980 if (lower
->y
<= upper
->y
+ upper
->height
)
26982 result
->y
= lower
->y
;
26984 /* The lower end of the intersection is the minimum of the lower
26985 ends of upper and lower. */
26986 result
->height
= (min (lower
->y
+ lower
->height
,
26987 upper
->y
+ upper
->height
)
26989 intersection_p
= 1;
26993 return intersection_p
;
26996 #endif /* HAVE_WINDOW_SYSTEM */
26999 /***********************************************************************
27001 ***********************************************************************/
27004 syms_of_xdisp (void)
27006 Vwith_echo_area_save_vector
= Qnil
;
27007 staticpro (&Vwith_echo_area_save_vector
);
27009 Vmessage_stack
= Qnil
;
27010 staticpro (&Vmessage_stack
);
27012 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
27013 staticpro (&Qinhibit_redisplay
);
27015 message_dolog_marker1
= Fmake_marker ();
27016 staticpro (&message_dolog_marker1
);
27017 message_dolog_marker2
= Fmake_marker ();
27018 staticpro (&message_dolog_marker2
);
27019 message_dolog_marker3
= Fmake_marker ();
27020 staticpro (&message_dolog_marker3
);
27023 defsubr (&Sdump_frame_glyph_matrix
);
27024 defsubr (&Sdump_glyph_matrix
);
27025 defsubr (&Sdump_glyph_row
);
27026 defsubr (&Sdump_tool_bar_row
);
27027 defsubr (&Strace_redisplay
);
27028 defsubr (&Strace_to_stderr
);
27030 #ifdef HAVE_WINDOW_SYSTEM
27031 defsubr (&Stool_bar_lines_needed
);
27032 defsubr (&Slookup_image_map
);
27034 defsubr (&Sformat_mode_line
);
27035 defsubr (&Sinvisible_p
);
27036 defsubr (&Scurrent_bidi_paragraph_direction
);
27038 staticpro (&Qmenu_bar_update_hook
);
27039 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
27041 staticpro (&Qoverriding_terminal_local_map
);
27042 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
27044 staticpro (&Qoverriding_local_map
);
27045 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
27047 staticpro (&Qwindow_scroll_functions
);
27048 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
27050 staticpro (&Qwindow_text_change_functions
);
27051 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
27053 staticpro (&Qredisplay_end_trigger_functions
);
27054 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
27056 staticpro (&Qinhibit_point_motion_hooks
);
27057 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
27059 Qeval
= intern_c_string ("eval");
27060 staticpro (&Qeval
);
27062 QCdata
= intern_c_string (":data");
27063 staticpro (&QCdata
);
27064 Qdisplay
= intern_c_string ("display");
27065 staticpro (&Qdisplay
);
27066 Qspace_width
= intern_c_string ("space-width");
27067 staticpro (&Qspace_width
);
27068 Qraise
= intern_c_string ("raise");
27069 staticpro (&Qraise
);
27070 Qslice
= intern_c_string ("slice");
27071 staticpro (&Qslice
);
27072 Qspace
= intern_c_string ("space");
27073 staticpro (&Qspace
);
27074 Qmargin
= intern_c_string ("margin");
27075 staticpro (&Qmargin
);
27076 Qpointer
= intern_c_string ("pointer");
27077 staticpro (&Qpointer
);
27078 Qleft_margin
= intern_c_string ("left-margin");
27079 staticpro (&Qleft_margin
);
27080 Qright_margin
= intern_c_string ("right-margin");
27081 staticpro (&Qright_margin
);
27082 Qcenter
= intern_c_string ("center");
27083 staticpro (&Qcenter
);
27084 Qline_height
= intern_c_string ("line-height");
27085 staticpro (&Qline_height
);
27086 QCalign_to
= intern_c_string (":align-to");
27087 staticpro (&QCalign_to
);
27088 QCrelative_width
= intern_c_string (":relative-width");
27089 staticpro (&QCrelative_width
);
27090 QCrelative_height
= intern_c_string (":relative-height");
27091 staticpro (&QCrelative_height
);
27092 QCeval
= intern_c_string (":eval");
27093 staticpro (&QCeval
);
27094 QCpropertize
= intern_c_string (":propertize");
27095 staticpro (&QCpropertize
);
27096 QCfile
= intern_c_string (":file");
27097 staticpro (&QCfile
);
27098 Qfontified
= intern_c_string ("fontified");
27099 staticpro (&Qfontified
);
27100 Qfontification_functions
= intern_c_string ("fontification-functions");
27101 staticpro (&Qfontification_functions
);
27102 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
27103 staticpro (&Qtrailing_whitespace
);
27104 Qescape_glyph
= intern_c_string ("escape-glyph");
27105 staticpro (&Qescape_glyph
);
27106 Qnobreak_space
= intern_c_string ("nobreak-space");
27107 staticpro (&Qnobreak_space
);
27108 Qimage
= intern_c_string ("image");
27109 staticpro (&Qimage
);
27110 Qtext
= intern_c_string ("text");
27111 staticpro (&Qtext
);
27112 Qboth
= intern_c_string ("both");
27113 staticpro (&Qboth
);
27114 Qboth_horiz
= intern_c_string ("both-horiz");
27115 staticpro (&Qboth_horiz
);
27116 Qtext_image_horiz
= intern_c_string ("text-image-horiz");
27117 staticpro (&Qtext_image_horiz
);
27118 QCmap
= intern_c_string (":map");
27119 staticpro (&QCmap
);
27120 QCpointer
= intern_c_string (":pointer");
27121 staticpro (&QCpointer
);
27122 Qrect
= intern_c_string ("rect");
27123 staticpro (&Qrect
);
27124 Qcircle
= intern_c_string ("circle");
27125 staticpro (&Qcircle
);
27126 Qpoly
= intern_c_string ("poly");
27127 staticpro (&Qpoly
);
27128 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
27129 staticpro (&Qmessage_truncate_lines
);
27130 Qgrow_only
= intern_c_string ("grow-only");
27131 staticpro (&Qgrow_only
);
27132 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
27133 staticpro (&Qinhibit_menubar_update
);
27134 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
27135 staticpro (&Qinhibit_eval_during_redisplay
);
27136 Qposition
= intern_c_string ("position");
27137 staticpro (&Qposition
);
27138 Qbuffer_position
= intern_c_string ("buffer-position");
27139 staticpro (&Qbuffer_position
);
27140 Qobject
= intern_c_string ("object");
27141 staticpro (&Qobject
);
27142 Qbar
= intern_c_string ("bar");
27144 Qhbar
= intern_c_string ("hbar");
27145 staticpro (&Qhbar
);
27146 Qbox
= intern_c_string ("box");
27148 Qhollow
= intern_c_string ("hollow");
27149 staticpro (&Qhollow
);
27150 Qhand
= intern_c_string ("hand");
27151 staticpro (&Qhand
);
27152 Qarrow
= intern_c_string ("arrow");
27153 staticpro (&Qarrow
);
27154 Qtext
= intern_c_string ("text");
27155 staticpro (&Qtext
);
27156 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
27157 staticpro (&Qinhibit_free_realized_faces
);
27159 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
27160 Fcons (intern_c_string ("void-variable"), Qnil
)),
27162 staticpro (&list_of_error
);
27164 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
27165 staticpro (&Qlast_arrow_position
);
27166 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
27167 staticpro (&Qlast_arrow_string
);
27169 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
27170 staticpro (&Qoverlay_arrow_string
);
27171 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
27172 staticpro (&Qoverlay_arrow_bitmap
);
27174 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
27175 staticpro (&echo_buffer
[0]);
27176 staticpro (&echo_buffer
[1]);
27178 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
27179 staticpro (&echo_area_buffer
[0]);
27180 staticpro (&echo_area_buffer
[1]);
27182 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
27183 staticpro (&Vmessages_buffer_name
);
27185 mode_line_proptrans_alist
= Qnil
;
27186 staticpro (&mode_line_proptrans_alist
);
27187 mode_line_string_list
= Qnil
;
27188 staticpro (&mode_line_string_list
);
27189 mode_line_string_face
= Qnil
;
27190 staticpro (&mode_line_string_face
);
27191 mode_line_string_face_prop
= Qnil
;
27192 staticpro (&mode_line_string_face_prop
);
27193 Vmode_line_unwind_vector
= Qnil
;
27194 staticpro (&Vmode_line_unwind_vector
);
27196 help_echo_string
= Qnil
;
27197 staticpro (&help_echo_string
);
27198 help_echo_object
= Qnil
;
27199 staticpro (&help_echo_object
);
27200 help_echo_window
= Qnil
;
27201 staticpro (&help_echo_window
);
27202 previous_help_echo_string
= Qnil
;
27203 staticpro (&previous_help_echo_string
);
27204 help_echo_pos
= -1;
27206 Qright_to_left
= intern_c_string ("right-to-left");
27207 staticpro (&Qright_to_left
);
27208 Qleft_to_right
= intern_c_string ("left-to-right");
27209 staticpro (&Qleft_to_right
);
27211 #ifdef HAVE_WINDOW_SYSTEM
27212 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
27213 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
27214 For example, if a block cursor is over a tab, it will be drawn as
27215 wide as that tab on the display. */);
27216 x_stretch_cursor_p
= 0;
27219 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
27220 doc
: /* *Non-nil means highlight trailing whitespace.
27221 The face used for trailing whitespace is `trailing-whitespace'. */);
27222 Vshow_trailing_whitespace
= Qnil
;
27224 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
27225 doc
: /* *Control highlighting of nobreak space and soft hyphen.
27226 A value of t means highlight the character itself (for nobreak space,
27227 use face `nobreak-space').
27228 A value of nil means no highlighting.
27229 Other values mean display the escape glyph followed by an ordinary
27230 space or ordinary hyphen. */);
27231 Vnobreak_char_display
= Qt
;
27233 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
27234 doc
: /* *The pointer shape to show in void text areas.
27235 A value of nil means to show the text pointer. Other options are `arrow',
27236 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
27237 Vvoid_text_area_pointer
= Qarrow
;
27239 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
27240 doc
: /* Non-nil means don't actually do any redisplay.
27241 This is used for internal purposes. */);
27242 Vinhibit_redisplay
= Qnil
;
27244 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
27245 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
27246 Vglobal_mode_string
= Qnil
;
27248 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
27249 doc
: /* Marker for where to display an arrow on top of the buffer text.
27250 This must be the beginning of a line in order to work.
27251 See also `overlay-arrow-string'. */);
27252 Voverlay_arrow_position
= Qnil
;
27254 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
27255 doc
: /* String to display as an arrow in non-window frames.
27256 See also `overlay-arrow-position'. */);
27257 Voverlay_arrow_string
= make_pure_c_string ("=>");
27259 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
27260 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
27261 The symbols on this list are examined during redisplay to determine
27262 where to display overlay arrows. */);
27263 Voverlay_arrow_variable_list
27264 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
27266 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
27267 doc
: /* *The number of lines to try scrolling a window by when point moves out.
27268 If that fails to bring point back on frame, point is centered instead.
27269 If this is zero, point is always centered after it moves off frame.
27270 If you want scrolling to always be a line at a time, you should set
27271 `scroll-conservatively' to a large value rather than set this to 1. */);
27273 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
27274 doc
: /* *Scroll up to this many lines, to bring point back on screen.
27275 If point moves off-screen, redisplay will scroll by up to
27276 `scroll-conservatively' lines in order to bring point just barely
27277 onto the screen again. If that cannot be done, then redisplay
27278 recenters point as usual.
27280 If the value is greater than 100, redisplay will never recenter point,
27281 but will always scroll just enough text to bring point into view, even
27282 if you move far away.
27284 A value of zero means always recenter point if it moves off screen. */);
27285 scroll_conservatively
= 0;
27287 DEFVAR_INT ("scroll-margin", scroll_margin
,
27288 doc
: /* *Number of lines of margin at the top and bottom of a window.
27289 Recenter the window whenever point gets within this many lines
27290 of the top or bottom of the window. */);
27293 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
27294 doc
: /* Pixels per inch value for non-window system displays.
27295 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
27296 Vdisplay_pixels_per_inch
= make_float (72.0);
27299 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
27302 DEFVAR_LISP ("truncate-partial-width-windows",
27303 Vtruncate_partial_width_windows
,
27304 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
27305 For an integer value, truncate lines in each window narrower than the
27306 full frame width, provided the window width is less than that integer;
27307 otherwise, respect the value of `truncate-lines'.
27309 For any other non-nil value, truncate lines in all windows that do
27310 not span the full frame width.
27312 A value of nil means to respect the value of `truncate-lines'.
27314 If `word-wrap' is enabled, you might want to reduce this. */);
27315 Vtruncate_partial_width_windows
= make_number (50);
27317 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
27318 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
27319 Any other value means to use the appropriate face, `mode-line',
27320 `header-line', or `menu' respectively. */);
27321 mode_line_inverse_video
= 1;
27323 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
27324 doc
: /* *Maximum buffer size for which line number should be displayed.
27325 If the buffer is bigger than this, the line number does not appear
27326 in the mode line. A value of nil means no limit. */);
27327 Vline_number_display_limit
= Qnil
;
27329 DEFVAR_INT ("line-number-display-limit-width",
27330 line_number_display_limit_width
,
27331 doc
: /* *Maximum line width (in characters) for line number display.
27332 If the average length of the lines near point is bigger than this, then the
27333 line number may be omitted from the mode line. */);
27334 line_number_display_limit_width
= 200;
27336 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
27337 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
27338 highlight_nonselected_windows
= 0;
27340 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
27341 doc
: /* Non-nil if more than one frame is visible on this display.
27342 Minibuffer-only frames don't count, but iconified frames do.
27343 This variable is not guaranteed to be accurate except while processing
27344 `frame-title-format' and `icon-title-format'. */);
27346 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
27347 doc
: /* Template for displaying the title bar of visible frames.
27348 \(Assuming the window manager supports this feature.)
27350 This variable has the same structure as `mode-line-format', except that
27351 the %c and %l constructs are ignored. It is used only on frames for
27352 which no explicit name has been set \(see `modify-frame-parameters'). */);
27354 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
27355 doc
: /* Template for displaying the title bar of an iconified frame.
27356 \(Assuming the window manager supports this feature.)
27357 This variable has the same structure as `mode-line-format' (which see),
27358 and is used only on frames for which no explicit name has been set
27359 \(see `modify-frame-parameters'). */);
27361 = Vframe_title_format
27362 = pure_cons (intern_c_string ("multiple-frames"),
27363 pure_cons (make_pure_c_string ("%b"),
27364 pure_cons (pure_cons (empty_unibyte_string
,
27365 pure_cons (intern_c_string ("invocation-name"),
27366 pure_cons (make_pure_c_string ("@"),
27367 pure_cons (intern_c_string ("system-name"),
27371 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
27372 doc
: /* Maximum number of lines to keep in the message log buffer.
27373 If nil, disable message logging. If t, log messages but don't truncate
27374 the buffer when it becomes large. */);
27375 Vmessage_log_max
= make_number (100);
27377 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
27378 doc
: /* Functions called before redisplay, if window sizes have changed.
27379 The value should be a list of functions that take one argument.
27380 Just before redisplay, for each frame, if any of its windows have changed
27381 size since the last redisplay, or have been split or deleted,
27382 all the functions in the list are called, with the frame as argument. */);
27383 Vwindow_size_change_functions
= Qnil
;
27385 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
27386 doc
: /* List of functions to call before redisplaying a window with scrolling.
27387 Each function is called with two arguments, the window and its new
27388 display-start position. Note that these functions are also called by
27389 `set-window-buffer'. Also note that the value of `window-end' is not
27390 valid when these functions are called. */);
27391 Vwindow_scroll_functions
= Qnil
;
27393 DEFVAR_LISP ("window-text-change-functions",
27394 Vwindow_text_change_functions
,
27395 doc
: /* Functions to call in redisplay when text in the window might change. */);
27396 Vwindow_text_change_functions
= Qnil
;
27398 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
27399 doc
: /* Functions called when redisplay of a window reaches the end trigger.
27400 Each function is called with two arguments, the window and the end trigger value.
27401 See `set-window-redisplay-end-trigger'. */);
27402 Vredisplay_end_trigger_functions
= Qnil
;
27404 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
27405 doc
: /* *Non-nil means autoselect window with mouse pointer.
27406 If nil, do not autoselect windows.
27407 A positive number means delay autoselection by that many seconds: a
27408 window is autoselected only after the mouse has remained in that
27409 window for the duration of the delay.
27410 A negative number has a similar effect, but causes windows to be
27411 autoselected only after the mouse has stopped moving. \(Because of
27412 the way Emacs compares mouse events, you will occasionally wait twice
27413 that time before the window gets selected.\)
27414 Any other value means to autoselect window instantaneously when the
27415 mouse pointer enters it.
27417 Autoselection selects the minibuffer only if it is active, and never
27418 unselects the minibuffer if it is active.
27420 When customizing this variable make sure that the actual value of
27421 `focus-follows-mouse' matches the behavior of your window manager. */);
27422 Vmouse_autoselect_window
= Qnil
;
27424 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
27425 doc
: /* *Non-nil means automatically resize tool-bars.
27426 This dynamically changes the tool-bar's height to the minimum height
27427 that is needed to make all tool-bar items visible.
27428 If value is `grow-only', the tool-bar's height is only increased
27429 automatically; to decrease the tool-bar height, use \\[recenter]. */);
27430 Vauto_resize_tool_bars
= Qt
;
27432 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
27433 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
27434 auto_raise_tool_bar_buttons_p
= 1;
27436 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
27437 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
27438 make_cursor_line_fully_visible_p
= 1;
27440 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
27441 doc
: /* *Border below tool-bar in pixels.
27442 If an integer, use it as the height of the border.
27443 If it is one of `internal-border-width' or `border-width', use the
27444 value of the corresponding frame parameter.
27445 Otherwise, no border is added below the tool-bar. */);
27446 Vtool_bar_border
= Qinternal_border_width
;
27448 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
27449 doc
: /* *Margin around tool-bar buttons in pixels.
27450 If an integer, use that for both horizontal and vertical margins.
27451 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
27452 HORZ specifying the horizontal margin, and VERT specifying the
27453 vertical margin. */);
27454 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
27456 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
27457 doc
: /* *Relief thickness of tool-bar buttons. */);
27458 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
27460 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
27461 doc
: /* Tool bar style to use.
27463 image - show images only
27464 text - show text only
27465 both - show both, text below image
27466 both-horiz - show text to the right of the image
27467 text-image-horiz - show text to the left of the image
27468 any other - use system default or image if no system default. */);
27469 Vtool_bar_style
= Qnil
;
27471 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
27472 doc
: /* *Maximum number of characters a label can have to be shown.
27473 The tool bar style must also show labels for this to have any effect, see
27474 `tool-bar-style'. */);
27475 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
27477 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
27478 doc
: /* List of functions to call to fontify regions of text.
27479 Each function is called with one argument POS. Functions must
27480 fontify a region starting at POS in the current buffer, and give
27481 fontified regions the property `fontified'. */);
27482 Vfontification_functions
= Qnil
;
27483 Fmake_variable_buffer_local (Qfontification_functions
);
27485 DEFVAR_BOOL ("unibyte-display-via-language-environment",
27486 unibyte_display_via_language_environment
,
27487 doc
: /* *Non-nil means display unibyte text according to language environment.
27488 Specifically, this means that raw bytes in the range 160-255 decimal
27489 are displayed by converting them to the equivalent multibyte characters
27490 according to the current language environment. As a result, they are
27491 displayed according to the current fontset.
27493 Note that this variable affects only how these bytes are displayed,
27494 but does not change the fact they are interpreted as raw bytes. */);
27495 unibyte_display_via_language_environment
= 0;
27497 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
27498 doc
: /* *Maximum height for resizing mini-windows.
27499 If a float, it specifies a fraction of the mini-window frame's height.
27500 If an integer, it specifies a number of lines. */);
27501 Vmax_mini_window_height
= make_float (0.25);
27503 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
27504 doc
: /* *How to resize mini-windows.
27505 A value of nil means don't automatically resize mini-windows.
27506 A value of t means resize them to fit the text displayed in them.
27507 A value of `grow-only', the default, means let mini-windows grow
27508 only, until their display becomes empty, at which point the windows
27509 go back to their normal size. */);
27510 Vresize_mini_windows
= Qgrow_only
;
27512 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
27513 doc
: /* Alist specifying how to blink the cursor off.
27514 Each element has the form (ON-STATE . OFF-STATE). Whenever the
27515 `cursor-type' frame-parameter or variable equals ON-STATE,
27516 comparing using `equal', Emacs uses OFF-STATE to specify
27517 how to blink it off. ON-STATE and OFF-STATE are values for
27518 the `cursor-type' frame parameter.
27520 If a frame's ON-STATE has no entry in this list,
27521 the frame's other specifications determine how to blink the cursor off. */);
27522 Vblink_cursor_alist
= Qnil
;
27524 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
27525 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
27526 If non-nil, windows are automatically scrolled horizontally to make
27527 point visible. */);
27528 automatic_hscrolling_p
= 1;
27529 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
27530 staticpro (&Qauto_hscroll_mode
);
27532 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
27533 doc
: /* *How many columns away from the window edge point is allowed to get
27534 before automatic hscrolling will horizontally scroll the window. */);
27535 hscroll_margin
= 5;
27537 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
27538 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
27539 When point is less than `hscroll-margin' columns from the window
27540 edge, automatic hscrolling will scroll the window by the amount of columns
27541 determined by this variable. If its value is a positive integer, scroll that
27542 many columns. If it's a positive floating-point number, it specifies the
27543 fraction of the window's width to scroll. If it's nil or zero, point will be
27544 centered horizontally after the scroll. Any other value, including negative
27545 numbers, are treated as if the value were zero.
27547 Automatic hscrolling always moves point outside the scroll margin, so if
27548 point was more than scroll step columns inside the margin, the window will
27549 scroll more than the value given by the scroll step.
27551 Note that the lower bound for automatic hscrolling specified by `scroll-left'
27552 and `scroll-right' overrides this variable's effect. */);
27553 Vhscroll_step
= make_number (0);
27555 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
27556 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
27557 Bind this around calls to `message' to let it take effect. */);
27558 message_truncate_lines
= 0;
27560 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
27561 doc
: /* Normal hook run to update the menu bar definitions.
27562 Redisplay runs this hook before it redisplays the menu bar.
27563 This is used to update submenus such as Buffers,
27564 whose contents depend on various data. */);
27565 Vmenu_bar_update_hook
= Qnil
;
27567 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
27568 doc
: /* Frame for which we are updating a menu.
27569 The enable predicate for a menu binding should check this variable. */);
27570 Vmenu_updating_frame
= Qnil
;
27572 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
27573 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
27574 inhibit_menubar_update
= 0;
27576 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
27577 doc
: /* Prefix prepended to all continuation lines at display time.
27578 The value may be a string, an image, or a stretch-glyph; it is
27579 interpreted in the same way as the value of a `display' text property.
27581 This variable is overridden by any `wrap-prefix' text or overlay
27584 To add a prefix to non-continuation lines, use `line-prefix'. */);
27585 Vwrap_prefix
= Qnil
;
27586 staticpro (&Qwrap_prefix
);
27587 Qwrap_prefix
= intern_c_string ("wrap-prefix");
27588 Fmake_variable_buffer_local (Qwrap_prefix
);
27590 DEFVAR_LISP ("line-prefix", Vline_prefix
,
27591 doc
: /* Prefix prepended to all non-continuation lines at display time.
27592 The value may be a string, an image, or a stretch-glyph; it is
27593 interpreted in the same way as the value of a `display' text property.
27595 This variable is overridden by any `line-prefix' text or overlay
27598 To add a prefix to continuation lines, use `wrap-prefix'. */);
27599 Vline_prefix
= Qnil
;
27600 staticpro (&Qline_prefix
);
27601 Qline_prefix
= intern_c_string ("line-prefix");
27602 Fmake_variable_buffer_local (Qline_prefix
);
27604 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
27605 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
27606 inhibit_eval_during_redisplay
= 0;
27608 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
27609 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
27610 inhibit_free_realized_faces
= 0;
27613 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
27614 doc
: /* Inhibit try_window_id display optimization. */);
27615 inhibit_try_window_id
= 0;
27617 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
27618 doc
: /* Inhibit try_window_reusing display optimization. */);
27619 inhibit_try_window_reusing
= 0;
27621 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
27622 doc
: /* Inhibit try_cursor_movement display optimization. */);
27623 inhibit_try_cursor_movement
= 0;
27624 #endif /* GLYPH_DEBUG */
27626 DEFVAR_INT ("overline-margin", overline_margin
,
27627 doc
: /* *Space between overline and text, in pixels.
27628 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
27629 margin to the caracter height. */);
27630 overline_margin
= 2;
27632 DEFVAR_INT ("underline-minimum-offset",
27633 underline_minimum_offset
,
27634 doc
: /* Minimum distance between baseline and underline.
27635 This can improve legibility of underlined text at small font sizes,
27636 particularly when using variable `x-use-underline-position-properties'
27637 with fonts that specify an UNDERLINE_POSITION relatively close to the
27638 baseline. The default value is 1. */);
27639 underline_minimum_offset
= 1;
27641 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
27642 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
27643 This feature only works when on a window system that can change
27644 cursor shapes. */);
27645 display_hourglass_p
= 1;
27647 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
27648 doc
: /* *Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
27649 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
27651 hourglass_atimer
= NULL
;
27652 hourglass_shown_p
= 0;
27654 DEFSYM (Qglyphless_char
, "glyphless-char");
27655 DEFSYM (Qhex_code
, "hex-code");
27656 DEFSYM (Qempty_box
, "empty-box");
27657 DEFSYM (Qthin_space
, "thin-space");
27658 DEFSYM (Qzero_width
, "zero-width");
27660 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
27661 /* Intern this now in case it isn't already done.
27662 Setting this variable twice is harmless.
27663 But don't staticpro it here--that is done in alloc.c. */
27664 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
27665 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
27667 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
27668 doc
: /* Char-table defining glyphless characters.
27669 Each element, if non-nil, should be one of the following:
27670 an ASCII acronym string: display this string in a box
27671 `hex-code': display the hexadecimal code of a character in a box
27672 `empty-box': display as an empty box
27673 `thin-space': display as 1-pixel width space
27674 `zero-width': don't display
27675 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
27676 display method for graphical terminals and text terminals respectively.
27677 GRAPHICAL and TEXT should each have one of the values listed above.
27679 The char-table has one extra slot to control the display of a character for
27680 which no font is found. This slot only takes effect on graphical terminals.
27681 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
27682 `thin-space'. The default is `empty-box'. */);
27683 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
27684 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
27689 /* Initialize this module when Emacs starts. */
27694 Lisp_Object root_window
;
27695 struct window
*mini_w
;
27697 current_header_line_height
= current_mode_line_height
= -1;
27699 CHARPOS (this_line_start_pos
) = 0;
27701 mini_w
= XWINDOW (minibuf_window
);
27702 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
27703 echo_area_window
= minibuf_window
;
27705 if (!noninteractive
)
27707 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
27710 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
27711 set_window_height (root_window
,
27712 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
27714 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
27715 set_window_height (minibuf_window
, 1, 0);
27717 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
27718 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
27720 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
27721 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
27722 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
27724 /* The default ellipsis glyphs `...'. */
27725 for (i
= 0; i
< 3; ++i
)
27726 default_invis_vector
[i
] = make_number ('.');
27730 /* Allocate the buffer for frame titles.
27731 Also used for `format-mode-line'. */
27733 mode_line_noprop_buf
= (char *) xmalloc (size
);
27734 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
27735 mode_line_noprop_ptr
= mode_line_noprop_buf
;
27736 mode_line_target
= MODE_LINE_DISPLAY
;
27739 help_echo_showing_p
= 0;
27742 /* Since w32 does not support atimers, it defines its own implementation of
27743 the following three functions in w32fns.c. */
27746 /* Platform-independent portion of hourglass implementation. */
27748 /* Return non-zero if houglass timer has been started or hourglass is shown. */
27750 hourglass_started (void)
27752 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
27755 /* Cancel a currently active hourglass timer, and start a new one. */
27757 start_hourglass (void)
27759 #if defined (HAVE_WINDOW_SYSTEM)
27761 int secs
, usecs
= 0;
27763 cancel_hourglass ();
27765 if (INTEGERP (Vhourglass_delay
)
27766 && XINT (Vhourglass_delay
) > 0)
27767 secs
= XFASTINT (Vhourglass_delay
);
27768 else if (FLOATP (Vhourglass_delay
)
27769 && XFLOAT_DATA (Vhourglass_delay
) > 0)
27772 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
27773 secs
= XFASTINT (tem
);
27774 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
27777 secs
= DEFAULT_HOURGLASS_DELAY
;
27779 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
27780 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
27781 show_hourglass
, NULL
);
27786 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
27789 cancel_hourglass (void)
27791 #if defined (HAVE_WINDOW_SYSTEM)
27792 if (hourglass_atimer
)
27794 cancel_atimer (hourglass_atimer
);
27795 hourglass_atimer
= NULL
;
27798 if (hourglass_shown_p
)
27802 #endif /* ! WINDOWSNT */