1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2011 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
24 Emacs separates the task of updating the display from code
25 modifying global state, e.g. buffer text. This way functions
26 operating on buffers don't also have to be concerned with updating
29 Updating the display is triggered by the Lisp interpreter when it
30 decides it's time to do it. This is done either automatically for
31 you as part of the interpreter's command loop or as the result of
32 calling Lisp functions like `sit-for'. The C function `redisplay'
33 in xdisp.c is the only entry into the inner redisplay code.
35 The following diagram shows how redisplay code is invoked. As you
36 can see, Lisp calls redisplay and vice versa. Under window systems
37 like X, some portions of the redisplay code are also called
38 asynchronously during mouse movement or expose events. It is very
39 important that these code parts do NOT use the C library (malloc,
40 free) because many C libraries under Unix are not reentrant. They
41 may also NOT call functions of the Lisp interpreter which could
42 change the interpreter's state. If you don't follow these rules,
43 you will encounter bugs which are very hard to explain.
45 +--------------+ redisplay +----------------+
46 | Lisp machine |---------------->| Redisplay code |<--+
47 +--------------+ (xdisp.c) +----------------+ |
49 +----------------------------------+ |
50 Don't use this path when called |
53 expose_window (asynchronous) |
55 X expose events -----+
57 What does redisplay do? Obviously, it has to figure out somehow what
58 has been changed since the last time the display has been updated,
59 and to make these changes visible. Preferably it would do that in
60 a moderately intelligent way, i.e. fast.
62 Changes in buffer text can be deduced from window and buffer
63 structures, and from some global variables like `beg_unchanged' and
64 `end_unchanged'. The contents of the display are additionally
65 recorded in a `glyph matrix', a two-dimensional matrix of glyph
66 structures. Each row in such a matrix corresponds to a line on the
67 display, and each glyph in a row corresponds to a column displaying
68 a character, an image, or what else. This matrix is called the
69 `current glyph matrix' or `current matrix' in redisplay
72 For buffer parts that have been changed since the last update, a
73 second glyph matrix is constructed, the so called `desired glyph
74 matrix' or short `desired matrix'. Current and desired matrix are
75 then compared to find a cheap way to update the display, e.g. by
76 reusing part of the display by scrolling lines.
78 You will find a lot of redisplay optimizations when you start
79 looking at the innards of redisplay. The overall goal of all these
80 optimizations is to make redisplay fast because it is done
81 frequently. Some of these optimizations are implemented by the
86 This function tries to update the display if the text in the
87 window did not change and did not scroll, only point moved, and
88 it did not move off the displayed portion of the text.
90 . try_window_reusing_current_matrix
92 This function reuses the current matrix of a window when text
93 has not changed, but the window start changed (e.g., due to
98 This function attempts to redisplay a window by reusing parts of
99 its existing display. It finds and reuses the part that was not
100 changed, and redraws the rest.
104 This function performs the full redisplay of a single window
105 assuming that its fonts were not changed and that the cursor
106 will not end up in the scroll margins. (Loading fonts requires
107 re-adjustment of dimensions of glyph matrices, which makes this
108 method impossible to use.)
110 These optimizations are tried in sequence (some can be skipped if
111 it is known that they are not applicable). If none of the
112 optimizations were successful, redisplay calls redisplay_windows,
113 which performs a full redisplay of all windows.
117 Desired matrices are always built per Emacs window. The function
118 `display_line' is the central function to look at if you are
119 interested. It constructs one row in a desired matrix given an
120 iterator structure containing both a buffer position and a
121 description of the environment in which the text is to be
122 displayed. But this is too early, read on.
124 Characters and pixmaps displayed for a range of buffer text depend
125 on various settings of buffers and windows, on overlays and text
126 properties, on display tables, on selective display. The good news
127 is that all this hairy stuff is hidden behind a small set of
128 interface functions taking an iterator structure (struct it)
131 Iteration over things to be displayed is then simple. It is
132 started by initializing an iterator with a call to init_iterator,
133 passing it the buffer position where to start iteration. For
134 iteration over strings, pass -1 as the position to init_iterator,
135 and call reseat_to_string when the string is ready, to initialize
136 the iterator for that string. Thereafter, calls to
137 get_next_display_element fill the iterator structure with relevant
138 information about the next thing to display. Calls to
139 set_iterator_to_next move the iterator to the next thing.
141 Besides this, an iterator also contains information about the
142 display environment in which glyphs for display elements are to be
143 produced. It has fields for the width and height of the display,
144 the information whether long lines are truncated or continued, a
145 current X and Y position, and lots of other stuff you can better
148 Glyphs in a desired matrix are normally constructed in a loop
149 calling get_next_display_element and then PRODUCE_GLYPHS. The call
150 to PRODUCE_GLYPHS will fill the iterator structure with pixel
151 information about the element being displayed and at the same time
152 produce glyphs for it. If the display element fits on the line
153 being displayed, set_iterator_to_next is called next, otherwise the
154 glyphs produced are discarded. The function display_line is the
155 workhorse of filling glyph rows in the desired matrix with glyphs.
156 In addition to producing glyphs, it also handles line truncation
157 and continuation, word wrap, and cursor positioning (for the
158 latter, see also set_cursor_from_row).
162 That just couldn't be all, could it? What about terminal types not
163 supporting operations on sub-windows of the screen? To update the
164 display on such a terminal, window-based glyph matrices are not
165 well suited. To be able to reuse part of the display (scrolling
166 lines up and down), we must instead have a view of the whole
167 screen. This is what `frame matrices' are for. They are a trick.
169 Frames on terminals like above have a glyph pool. Windows on such
170 a frame sub-allocate their glyph memory from their frame's glyph
171 pool. The frame itself is given its own glyph matrices. By
172 coincidence---or maybe something else---rows in window glyph
173 matrices are slices of corresponding rows in frame matrices. Thus
174 writing to window matrices implicitly updates a frame matrix which
175 provides us with the view of the whole screen that we originally
176 wanted to have without having to move many bytes around. To be
177 honest, there is a little bit more done, but not much more. If you
178 plan to extend that code, take a look at dispnew.c. The function
179 build_frame_matrix is a good starting point.
181 Bidirectional display.
183 Bidirectional display adds quite some hair to this already complex
184 design. The good news are that a large portion of that hairy stuff
185 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
186 reordering engine which is called by set_iterator_to_next and
187 returns the next character to display in the visual order. See
188 commentary on bidi.c for more details. As far as redisplay is
189 concerned, the effect of calling bidi_move_to_visually_next, the
190 main interface of the reordering engine, is that the iterator gets
191 magically placed on the buffer or string position that is to be
192 displayed next. In other words, a linear iteration through the
193 buffer/string is replaced with a non-linear one. All the rest of
194 the redisplay is oblivious to the bidi reordering.
196 Well, almost oblivious---there are still complications, most of
197 them due to the fact that buffer and string positions no longer
198 change monotonously with glyph indices in a glyph row. Moreover,
199 for continued lines, the buffer positions may not even be
200 monotonously changing with vertical positions. Also, accounting
201 for face changes, overlays, etc. becomes more complex because
202 non-linear iteration could potentially skip many positions with
203 changes, and then cross them again on the way back...
205 One other prominent effect of bidirectional display is that some
206 paragraphs of text need to be displayed starting at the right
207 margin of the window---the so-called right-to-left, or R2L
208 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
209 which have their reversed_p flag set. The bidi reordering engine
210 produces characters in such rows starting from the character which
211 should be the rightmost on display. PRODUCE_GLYPHS then reverses
212 the order, when it fills up the glyph row whose reversed_p flag is
213 set, by prepending each new glyph to what is already there, instead
214 of appending it. When the glyph row is complete, the function
215 extend_face_to_end_of_line fills the empty space to the left of the
216 leftmost character with special glyphs, which will display as,
217 well, empty. On text terminals, these special glyphs are simply
218 blank characters. On graphics terminals, there's a single stretch
219 glyph of a suitably computed width. Both the blanks and the
220 stretch glyph are given the face of the background of the line.
221 This way, the terminal-specific back-end can still draw the glyphs
222 left to right, even for R2L lines.
224 Bidirectional display and character compositions
226 Some scripts cannot be displayed by drawing each character
227 individually, because adjacent characters change each other's shape
228 on display. For example, Arabic and Indic scripts belong to this
231 Emacs display supports this by providing "character compositions",
232 most of which is implemented in composite.c. During the buffer
233 scan that delivers characters to PRODUCE_GLYPHS, if the next
234 character to be delivered is a composed character, the iteration
235 calls composition_reseat_it and next_element_from_composition. If
236 they succeed to compose the character with one or more of the
237 following characters, the whole sequence of characters that where
238 composed is recorded in the `struct composition_it' object that is
239 part of the buffer iterator. The composed sequence could produce
240 one or more font glyphs (called "grapheme clusters") on the screen.
241 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
242 in the direction corresponding to the current bidi scan direction
243 (recorded in the scan_dir member of the `struct bidi_it' object
244 that is part of the buffer iterator). In particular, if the bidi
245 iterator currently scans the buffer backwards, the grapheme
246 clusters are delivered back to front. This reorders the grapheme
247 clusters as appropriate for the current bidi context. Note that
248 this means that the grapheme clusters are always stored in the
249 LGSTRING object (see composite.c) in the logical order.
251 Moving an iterator in bidirectional text
252 without producing glyphs
254 Note one important detail mentioned above: that the bidi reordering
255 engine, driven by the iterator, produces characters in R2L rows
256 starting at the character that will be the rightmost on display.
257 As far as the iterator is concerned, the geometry of such rows is
258 still left to right, i.e. the iterator "thinks" the first character
259 is at the leftmost pixel position. The iterator does not know that
260 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
261 delivers. This is important when functions from the the move_it_*
262 family are used to get to certain screen position or to match
263 screen coordinates with buffer coordinates: these functions use the
264 iterator geometry, which is left to right even in R2L paragraphs.
265 This works well with most callers of move_it_*, because they need
266 to get to a specific column, and columns are still numbered in the
267 reading order, i.e. the rightmost character in a R2L paragraph is
268 still column zero. But some callers do not get well with this; a
269 notable example is mouse clicks that need to find the character
270 that corresponds to certain pixel coordinates. See
271 buffer_posn_from_coords in dispnew.c for how this is handled. */
279 #include "keyboard.h"
282 #include "termchar.h"
283 #include "dispextern.h"
285 #include "character.h"
288 #include "commands.h"
292 #include "termhooks.h"
293 #include "termopts.h"
294 #include "intervals.h"
297 #include "region-cache.h"
300 #include "blockinput.h"
302 #ifdef HAVE_X_WINDOWS
317 #ifndef FRAME_X_OUTPUT
318 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
321 #define INFINITY 10000000
323 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
324 Lisp_Object Qwindow_scroll_functions
;
325 static Lisp_Object Qwindow_text_change_functions
;
326 static Lisp_Object Qredisplay_end_trigger_functions
;
327 Lisp_Object Qinhibit_point_motion_hooks
;
328 static Lisp_Object QCeval
, QCpropertize
;
329 Lisp_Object QCfile
, QCdata
;
330 static Lisp_Object Qfontified
;
331 static Lisp_Object Qgrow_only
;
332 static Lisp_Object Qinhibit_eval_during_redisplay
;
333 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
334 static Lisp_Object Qright_to_left
, Qleft_to_right
;
337 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
340 static Lisp_Object Qarrow
, Qhand
;
343 /* Holds the list (error). */
344 static Lisp_Object list_of_error
;
346 static Lisp_Object Qfontification_functions
;
348 static Lisp_Object Qwrap_prefix
;
349 static Lisp_Object Qline_prefix
;
351 /* Non-nil means don't actually do any redisplay. */
353 Lisp_Object Qinhibit_redisplay
;
355 /* Names of text properties relevant for redisplay. */
357 Lisp_Object Qdisplay
;
359 Lisp_Object Qspace
, QCalign_to
;
360 static Lisp_Object QCrelative_width
, QCrelative_height
;
361 Lisp_Object Qleft_margin
, Qright_margin
;
362 static Lisp_Object Qspace_width
, Qraise
;
363 static Lisp_Object Qslice
;
365 static Lisp_Object Qmargin
, Qpointer
;
366 static Lisp_Object Qline_height
;
368 #ifdef HAVE_WINDOW_SYSTEM
370 /* Test if overflow newline into fringe. Called with iterator IT
371 at or past right window margin, and with IT->current_x set. */
373 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
374 (!NILP (Voverflow_newline_into_fringe) \
375 && FRAME_WINDOW_P ((IT)->f) \
376 && ((IT)->bidi_it.paragraph_dir == R2L \
377 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
378 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
379 && (IT)->current_x == (IT)->last_visible_x \
380 && (IT)->line_wrap != WORD_WRAP)
382 #else /* !HAVE_WINDOW_SYSTEM */
383 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
384 #endif /* HAVE_WINDOW_SYSTEM */
386 /* Test if the display element loaded in IT is a space or tab
387 character. This is used to determine word wrapping. */
389 #define IT_DISPLAYING_WHITESPACE(it) \
390 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
392 /* Name of the face used to highlight trailing whitespace. */
394 static Lisp_Object Qtrailing_whitespace
;
396 /* Name and number of the face used to highlight escape glyphs. */
398 static Lisp_Object Qescape_glyph
;
400 /* Name and number of the face used to highlight non-breaking spaces. */
402 static Lisp_Object Qnobreak_space
;
404 /* The symbol `image' which is the car of the lists used to represent
405 images in Lisp. Also a tool bar style. */
409 /* The image map types. */
411 static Lisp_Object QCpointer
;
412 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
414 /* Tool bar styles */
415 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
417 /* Non-zero means print newline to stdout before next mini-buffer
420 int noninteractive_need_newline
;
422 /* Non-zero means print newline to message log before next message. */
424 static int message_log_need_newline
;
426 /* Three markers that message_dolog uses.
427 It could allocate them itself, but that causes trouble
428 in handling memory-full errors. */
429 static Lisp_Object message_dolog_marker1
;
430 static Lisp_Object message_dolog_marker2
;
431 static Lisp_Object message_dolog_marker3
;
433 /* The buffer position of the first character appearing entirely or
434 partially on the line of the selected window which contains the
435 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
436 redisplay optimization in redisplay_internal. */
438 static struct text_pos this_line_start_pos
;
440 /* Number of characters past the end of the line above, including the
441 terminating newline. */
443 static struct text_pos this_line_end_pos
;
445 /* The vertical positions and the height of this line. */
447 static int this_line_vpos
;
448 static int this_line_y
;
449 static int this_line_pixel_height
;
451 /* X position at which this display line starts. Usually zero;
452 negative if first character is partially visible. */
454 static int this_line_start_x
;
456 /* The smallest character position seen by move_it_* functions as they
457 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
458 hscrolled lines, see display_line. */
460 static struct text_pos this_line_min_pos
;
462 /* Buffer that this_line_.* variables are referring to. */
464 static struct buffer
*this_line_buffer
;
467 /* Values of those variables at last redisplay are stored as
468 properties on `overlay-arrow-position' symbol. However, if
469 Voverlay_arrow_position is a marker, last-arrow-position is its
470 numerical position. */
472 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
474 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
475 properties on a symbol in overlay-arrow-variable-list. */
477 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
479 Lisp_Object Qmenu_bar_update_hook
;
481 /* Nonzero if an overlay arrow has been displayed in this window. */
483 static int overlay_arrow_seen
;
485 /* Number of windows showing the buffer of the selected window (or
486 another buffer with the same base buffer). keyboard.c refers to
491 /* Vector containing glyphs for an ellipsis `...'. */
493 static Lisp_Object default_invis_vector
[3];
495 /* This is the window where the echo area message was displayed. It
496 is always a mini-buffer window, but it may not be the same window
497 currently active as a mini-buffer. */
499 Lisp_Object echo_area_window
;
501 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
502 pushes the current message and the value of
503 message_enable_multibyte on the stack, the function restore_message
504 pops the stack and displays MESSAGE again. */
506 static Lisp_Object Vmessage_stack
;
508 /* Nonzero means multibyte characters were enabled when the echo area
509 message was specified. */
511 static int message_enable_multibyte
;
513 /* Nonzero if we should redraw the mode lines on the next redisplay. */
515 int update_mode_lines
;
517 /* Nonzero if window sizes or contents have changed since last
518 redisplay that finished. */
520 int windows_or_buffers_changed
;
522 /* Nonzero means a frame's cursor type has been changed. */
524 int cursor_type_changed
;
526 /* Nonzero after display_mode_line if %l was used and it displayed a
529 static int line_number_displayed
;
531 /* The name of the *Messages* buffer, a string. */
533 static Lisp_Object Vmessages_buffer_name
;
535 /* Current, index 0, and last displayed echo area message. Either
536 buffers from echo_buffers, or nil to indicate no message. */
538 Lisp_Object echo_area_buffer
[2];
540 /* The buffers referenced from echo_area_buffer. */
542 static Lisp_Object echo_buffer
[2];
544 /* A vector saved used in with_area_buffer to reduce consing. */
546 static Lisp_Object Vwith_echo_area_save_vector
;
548 /* Non-zero means display_echo_area should display the last echo area
549 message again. Set by redisplay_preserve_echo_area. */
551 static int display_last_displayed_message_p
;
553 /* Nonzero if echo area is being used by print; zero if being used by
556 static int message_buf_print
;
558 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
560 static Lisp_Object Qinhibit_menubar_update
;
561 static Lisp_Object Qmessage_truncate_lines
;
563 /* Set to 1 in clear_message to make redisplay_internal aware
564 of an emptied echo area. */
566 static int message_cleared_p
;
568 /* A scratch glyph row with contents used for generating truncation
569 glyphs. Also used in direct_output_for_insert. */
571 #define MAX_SCRATCH_GLYPHS 100
572 static struct glyph_row scratch_glyph_row
;
573 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
575 /* Ascent and height of the last line processed by move_it_to. */
577 static int last_max_ascent
, last_height
;
579 /* Non-zero if there's a help-echo in the echo area. */
581 int help_echo_showing_p
;
583 /* If >= 0, computed, exact values of mode-line and header-line height
584 to use in the macros CURRENT_MODE_LINE_HEIGHT and
585 CURRENT_HEADER_LINE_HEIGHT. */
587 int current_mode_line_height
, current_header_line_height
;
589 /* The maximum distance to look ahead for text properties. Values
590 that are too small let us call compute_char_face and similar
591 functions too often which is expensive. Values that are too large
592 let us call compute_char_face and alike too often because we
593 might not be interested in text properties that far away. */
595 #define TEXT_PROP_DISTANCE_LIMIT 100
599 /* Non-zero means print traces of redisplay if compiled with
602 int trace_redisplay_p
;
604 #endif /* GLYPH_DEBUG */
606 #ifdef DEBUG_TRACE_MOVE
607 /* Non-zero means trace with TRACE_MOVE to stderr. */
610 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
612 #define TRACE_MOVE(x) (void) 0
615 static Lisp_Object Qauto_hscroll_mode
;
617 /* Buffer being redisplayed -- for redisplay_window_error. */
619 static struct buffer
*displayed_buffer
;
621 /* Value returned from text property handlers (see below). */
626 HANDLED_RECOMPUTE_PROPS
,
627 HANDLED_OVERLAY_STRING_CONSUMED
,
631 /* A description of text properties that redisplay is interested
636 /* The name of the property. */
639 /* A unique index for the property. */
642 /* A handler function called to set up iterator IT from the property
643 at IT's current position. Value is used to steer handle_stop. */
644 enum prop_handled (*handler
) (struct it
*it
);
647 static enum prop_handled
handle_face_prop (struct it
*);
648 static enum prop_handled
handle_invisible_prop (struct it
*);
649 static enum prop_handled
handle_display_prop (struct it
*);
650 static enum prop_handled
handle_composition_prop (struct it
*);
651 static enum prop_handled
handle_overlay_change (struct it
*);
652 static enum prop_handled
handle_fontified_prop (struct it
*);
654 /* Properties handled by iterators. */
656 static struct props it_props
[] =
658 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
659 /* Handle `face' before `display' because some sub-properties of
660 `display' need to know the face. */
661 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
662 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
663 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
664 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
668 /* Value is the position described by X. If X is a marker, value is
669 the marker_position of X. Otherwise, value is X. */
671 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
673 /* Enumeration returned by some move_it_.* functions internally. */
677 /* Not used. Undefined value. */
680 /* Move ended at the requested buffer position or ZV. */
681 MOVE_POS_MATCH_OR_ZV
,
683 /* Move ended at the requested X pixel position. */
686 /* Move within a line ended at the end of a line that must be
690 /* Move within a line ended at the end of a line that would
691 be displayed truncated. */
694 /* Move within a line ended at a line end. */
698 /* This counter is used to clear the face cache every once in a while
699 in redisplay_internal. It is incremented for each redisplay.
700 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
703 #define CLEAR_FACE_CACHE_COUNT 500
704 static int clear_face_cache_count
;
706 /* Similarly for the image cache. */
708 #ifdef HAVE_WINDOW_SYSTEM
709 #define CLEAR_IMAGE_CACHE_COUNT 101
710 static int clear_image_cache_count
;
712 /* Null glyph slice */
713 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
716 /* Non-zero while redisplay_internal is in progress. */
720 static Lisp_Object Qinhibit_free_realized_faces
;
722 /* If a string, XTread_socket generates an event to display that string.
723 (The display is done in read_char.) */
725 Lisp_Object help_echo_string
;
726 Lisp_Object help_echo_window
;
727 Lisp_Object help_echo_object
;
728 EMACS_INT help_echo_pos
;
730 /* Temporary variable for XTread_socket. */
732 Lisp_Object previous_help_echo_string
;
734 /* Platform-independent portion of hourglass implementation. */
736 /* Non-zero means an hourglass cursor is currently shown. */
737 int hourglass_shown_p
;
739 /* If non-null, an asynchronous timer that, when it expires, displays
740 an hourglass cursor on all frames. */
741 struct atimer
*hourglass_atimer
;
743 /* Name of the face used to display glyphless characters. */
744 Lisp_Object Qglyphless_char
;
746 /* Symbol for the purpose of Vglyphless_char_display. */
747 static Lisp_Object Qglyphless_char_display
;
749 /* Method symbols for Vglyphless_char_display. */
750 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
752 /* Default pixel width of `thin-space' display method. */
753 #define THIN_SPACE_WIDTH 1
755 /* Default number of seconds to wait before displaying an hourglass
757 #define DEFAULT_HOURGLASS_DELAY 1
760 /* Function prototypes. */
762 static void setup_for_ellipsis (struct it
*, int);
763 static void set_iterator_to_next (struct it
*, int);
764 static void mark_window_display_accurate_1 (struct window
*, int);
765 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
766 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
767 static int cursor_row_p (struct glyph_row
*);
768 static int redisplay_mode_lines (Lisp_Object
, int);
769 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
771 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
773 static void handle_line_prefix (struct it
*);
775 static void pint2str (char *, int, EMACS_INT
);
776 static void pint2hrstr (char *, int, EMACS_INT
);
777 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
779 static void reconsider_clip_changes (struct window
*, struct buffer
*);
780 static int text_outside_line_unchanged_p (struct window
*,
781 EMACS_INT
, EMACS_INT
);
782 static void store_mode_line_noprop_char (char);
783 static int store_mode_line_noprop (const char *, int, int);
784 static void handle_stop (struct it
*);
785 static void handle_stop_backwards (struct it
*, EMACS_INT
);
786 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
787 static void ensure_echo_area_buffers (void);
788 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
789 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
790 static int with_echo_area_buffer (struct window
*, int,
791 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
792 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
793 static void clear_garbaged_frames (void);
794 static int current_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
795 static void pop_message (void);
796 static int truncate_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
797 static void set_message (const char *, Lisp_Object
, EMACS_INT
, int);
798 static int set_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
799 static int display_echo_area (struct window
*);
800 static int display_echo_area_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
801 static int resize_mini_window_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
802 static Lisp_Object
unwind_redisplay (Lisp_Object
);
803 static int string_char_and_length (const unsigned char *, int *);
804 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
806 static int compute_window_start_on_continuation_line (struct window
*);
807 static Lisp_Object
safe_eval_handler (Lisp_Object
);
808 static void insert_left_trunc_glyphs (struct it
*);
809 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
811 static void extend_face_to_end_of_line (struct it
*);
812 static int append_space_for_newline (struct it
*, int);
813 static int cursor_row_fully_visible_p (struct window
*, int, int);
814 static int try_scrolling (Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int);
815 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
816 static int trailing_whitespace_p (EMACS_INT
);
817 static unsigned long int message_log_check_duplicate (EMACS_INT
, EMACS_INT
);
818 static void push_it (struct it
*, struct text_pos
*);
819 static void pop_it (struct it
*);
820 static void sync_frame_with_window_matrix_rows (struct window
*);
821 static void select_frame_for_redisplay (Lisp_Object
);
822 static void redisplay_internal (void);
823 static int echo_area_display (int);
824 static void redisplay_windows (Lisp_Object
);
825 static void redisplay_window (Lisp_Object
, int);
826 static Lisp_Object
redisplay_window_error (Lisp_Object
);
827 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
828 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
829 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
830 struct glyph_matrix
*, EMACS_INT
, EMACS_INT
,
832 static int update_menu_bar (struct frame
*, int, int);
833 static int try_window_reusing_current_matrix (struct window
*);
834 static int try_window_id (struct window
*);
835 static int display_line (struct it
*);
836 static int display_mode_lines (struct window
*);
837 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
838 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
839 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
840 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
841 static void display_menu_bar (struct window
*);
842 static EMACS_INT
display_count_lines (EMACS_INT
, EMACS_INT
, EMACS_INT
,
844 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
845 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int);
846 static void compute_line_metrics (struct it
*);
847 static void run_redisplay_end_trigger_hook (struct it
*);
848 static int get_overlay_strings (struct it
*, EMACS_INT
);
849 static int get_overlay_strings_1 (struct it
*, EMACS_INT
, int);
850 static void next_overlay_string (struct it
*);
851 static void reseat (struct it
*, struct text_pos
, int);
852 static void reseat_1 (struct it
*, struct text_pos
, int);
853 static void back_to_previous_visible_line_start (struct it
*);
854 void reseat_at_previous_visible_line_start (struct it
*);
855 static void reseat_at_next_visible_line_start (struct it
*, int);
856 static int next_element_from_ellipsis (struct it
*);
857 static int next_element_from_display_vector (struct it
*);
858 static int next_element_from_string (struct it
*);
859 static int next_element_from_c_string (struct it
*);
860 static int next_element_from_buffer (struct it
*);
861 static int next_element_from_composition (struct it
*);
862 static int next_element_from_image (struct it
*);
863 static int next_element_from_stretch (struct it
*);
864 static void load_overlay_strings (struct it
*, EMACS_INT
);
865 static int init_from_display_pos (struct it
*, struct window
*,
866 struct display_pos
*);
867 static void reseat_to_string (struct it
*, const char *,
868 Lisp_Object
, EMACS_INT
, EMACS_INT
, int, int);
869 static int get_next_display_element (struct it
*);
870 static enum move_it_result
871 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
872 enum move_operation_enum
);
873 void move_it_vertically_backward (struct it
*, int);
874 static void init_to_row_start (struct it
*, struct window
*,
876 static int init_to_row_end (struct it
*, struct window
*,
878 static void back_to_previous_line_start (struct it
*);
879 static int forward_to_next_line_start (struct it
*, int *);
880 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
881 Lisp_Object
, EMACS_INT
);
882 static struct text_pos
string_pos (EMACS_INT
, Lisp_Object
);
883 static struct text_pos
c_string_pos (EMACS_INT
, const char *, int);
884 static EMACS_INT
number_of_chars (const char *, int);
885 static void compute_stop_pos (struct it
*);
886 static void compute_string_pos (struct text_pos
*, struct text_pos
,
888 static int face_before_or_after_it_pos (struct it
*, int);
889 static EMACS_INT
next_overlay_change (EMACS_INT
);
890 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
891 Lisp_Object
, struct text_pos
*, EMACS_INT
, int);
892 static int handle_single_display_spec (struct it
*, Lisp_Object
,
893 Lisp_Object
, Lisp_Object
,
894 struct text_pos
*, EMACS_INT
, int, int);
895 static int underlying_face_id (struct it
*);
896 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
899 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
900 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
902 #ifdef HAVE_WINDOW_SYSTEM
904 static void x_consider_frame_title (Lisp_Object
);
905 static int tool_bar_lines_needed (struct frame
*, int *);
906 static void update_tool_bar (struct frame
*, int);
907 static void build_desired_tool_bar_string (struct frame
*f
);
908 static int redisplay_tool_bar (struct frame
*);
909 static void display_tool_bar_line (struct it
*, int);
910 static void notice_overwritten_cursor (struct window
*,
913 static void append_stretch_glyph (struct it
*, Lisp_Object
,
917 #endif /* HAVE_WINDOW_SYSTEM */
919 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
920 static int coords_in_mouse_face_p (struct window
*, int, int);
924 /***********************************************************************
925 Window display dimensions
926 ***********************************************************************/
928 /* Return the bottom boundary y-position for text lines in window W.
929 This is the first y position at which a line cannot start.
930 It is relative to the top of the window.
932 This is the height of W minus the height of a mode line, if any. */
935 window_text_bottom_y (struct window
*w
)
937 int height
= WINDOW_TOTAL_HEIGHT (w
);
939 if (WINDOW_WANTS_MODELINE_P (w
))
940 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
944 /* Return the pixel width of display area AREA of window W. AREA < 0
945 means return the total width of W, not including fringes to
946 the left and right of the window. */
949 window_box_width (struct window
*w
, int area
)
951 int cols
= XFASTINT (w
->total_cols
);
954 if (!w
->pseudo_window_p
)
956 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
958 if (area
== TEXT_AREA
)
960 if (INTEGERP (w
->left_margin_cols
))
961 cols
-= XFASTINT (w
->left_margin_cols
);
962 if (INTEGERP (w
->right_margin_cols
))
963 cols
-= XFASTINT (w
->right_margin_cols
);
964 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
966 else if (area
== LEFT_MARGIN_AREA
)
968 cols
= (INTEGERP (w
->left_margin_cols
)
969 ? XFASTINT (w
->left_margin_cols
) : 0);
972 else if (area
== RIGHT_MARGIN_AREA
)
974 cols
= (INTEGERP (w
->right_margin_cols
)
975 ? XFASTINT (w
->right_margin_cols
) : 0);
980 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
984 /* Return the pixel height of the display area of window W, not
985 including mode lines of W, if any. */
988 window_box_height (struct window
*w
)
990 struct frame
*f
= XFRAME (w
->frame
);
991 int height
= WINDOW_TOTAL_HEIGHT (w
);
993 xassert (height
>= 0);
995 /* Note: the code below that determines the mode-line/header-line
996 height is essentially the same as that contained in the macro
997 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
998 the appropriate glyph row has its `mode_line_p' flag set,
999 and if it doesn't, uses estimate_mode_line_height instead. */
1001 if (WINDOW_WANTS_MODELINE_P (w
))
1003 struct glyph_row
*ml_row
1004 = (w
->current_matrix
&& w
->current_matrix
->rows
1005 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1007 if (ml_row
&& ml_row
->mode_line_p
)
1008 height
-= ml_row
->height
;
1010 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1013 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1015 struct glyph_row
*hl_row
1016 = (w
->current_matrix
&& w
->current_matrix
->rows
1017 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1019 if (hl_row
&& hl_row
->mode_line_p
)
1020 height
-= hl_row
->height
;
1022 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1025 /* With a very small font and a mode-line that's taller than
1026 default, we might end up with a negative height. */
1027 return max (0, height
);
1030 /* Return the window-relative coordinate of the left edge of display
1031 area AREA of window W. AREA < 0 means return the left edge of the
1032 whole window, to the right of the left fringe of W. */
1035 window_box_left_offset (struct window
*w
, int area
)
1039 if (w
->pseudo_window_p
)
1042 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1044 if (area
== TEXT_AREA
)
1045 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1046 + window_box_width (w
, LEFT_MARGIN_AREA
));
1047 else if (area
== RIGHT_MARGIN_AREA
)
1048 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1049 + window_box_width (w
, LEFT_MARGIN_AREA
)
1050 + window_box_width (w
, TEXT_AREA
)
1051 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1053 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1054 else if (area
== LEFT_MARGIN_AREA
1055 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1056 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1062 /* Return the window-relative coordinate of the right edge of display
1063 area AREA of window W. AREA < 0 means return the right edge of the
1064 whole window, to the left of the right fringe of W. */
1067 window_box_right_offset (struct window
*w
, int area
)
1069 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1072 /* Return the frame-relative coordinate of the left edge of display
1073 area AREA of window W. AREA < 0 means return the left edge of the
1074 whole window, to the right of the left fringe of W. */
1077 window_box_left (struct window
*w
, int area
)
1079 struct frame
*f
= XFRAME (w
->frame
);
1082 if (w
->pseudo_window_p
)
1083 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1085 x
= (WINDOW_LEFT_EDGE_X (w
)
1086 + window_box_left_offset (w
, area
));
1092 /* Return the frame-relative coordinate of the right edge of display
1093 area AREA of window W. AREA < 0 means return the right edge of the
1094 whole window, to the left of the right fringe of W. */
1097 window_box_right (struct window
*w
, int area
)
1099 return window_box_left (w
, area
) + window_box_width (w
, area
);
1102 /* Get the bounding box of the display area AREA of window W, without
1103 mode lines, in frame-relative coordinates. AREA < 0 means the
1104 whole window, not including the left and right fringes of
1105 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1106 coordinates of the upper-left corner of the box. Return in
1107 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1110 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1111 int *box_width
, int *box_height
)
1114 *box_width
= window_box_width (w
, area
);
1116 *box_height
= window_box_height (w
);
1118 *box_x
= window_box_left (w
, area
);
1121 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1122 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1123 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1128 /* Get the bounding box of the display area AREA of window W, without
1129 mode lines. AREA < 0 means the whole window, not including the
1130 left and right fringe of the window. Return in *TOP_LEFT_X
1131 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1132 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1133 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1137 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1138 int *bottom_right_x
, int *bottom_right_y
)
1140 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1142 *bottom_right_x
+= *top_left_x
;
1143 *bottom_right_y
+= *top_left_y
;
1148 /***********************************************************************
1150 ***********************************************************************/
1152 /* Return the bottom y-position of the line the iterator IT is in.
1153 This can modify IT's settings. */
1156 line_bottom_y (struct it
*it
)
1158 int line_height
= it
->max_ascent
+ it
->max_descent
;
1159 int line_top_y
= it
->current_y
;
1161 if (line_height
== 0)
1164 line_height
= last_height
;
1165 else if (IT_CHARPOS (*it
) < ZV
)
1167 move_it_by_lines (it
, 1);
1168 line_height
= (it
->max_ascent
|| it
->max_descent
1169 ? it
->max_ascent
+ it
->max_descent
1174 struct glyph_row
*row
= it
->glyph_row
;
1176 /* Use the default character height. */
1177 it
->glyph_row
= NULL
;
1178 it
->what
= IT_CHARACTER
;
1181 PRODUCE_GLYPHS (it
);
1182 line_height
= it
->ascent
+ it
->descent
;
1183 it
->glyph_row
= row
;
1187 return line_top_y
+ line_height
;
1191 /* Return 1 if position CHARPOS is visible in window W.
1192 CHARPOS < 0 means return info about WINDOW_END position.
1193 If visible, set *X and *Y to pixel coordinates of top left corner.
1194 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1195 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1198 pos_visible_p (struct window
*w
, EMACS_INT charpos
, int *x
, int *y
,
1199 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1202 struct text_pos top
;
1204 struct buffer
*old_buffer
= NULL
;
1206 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1209 if (XBUFFER (w
->buffer
) != current_buffer
)
1211 old_buffer
= current_buffer
;
1212 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1215 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1217 /* Compute exact mode line heights. */
1218 if (WINDOW_WANTS_MODELINE_P (w
))
1219 current_mode_line_height
1220 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1221 BVAR (current_buffer
, mode_line_format
));
1223 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1224 current_header_line_height
1225 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1226 BVAR (current_buffer
, header_line_format
));
1228 start_display (&it
, w
, top
);
1229 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1230 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1232 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1234 /* We have reached CHARPOS, or passed it. How the call to
1235 move_it_to can overshoot: (i) If CHARPOS is on invisible
1236 text, move_it_to stops at the end of the invisible text,
1237 after CHARPOS. (ii) If CHARPOS is in a display vector,
1238 move_it_to stops on its last glyph. */
1239 int top_x
= it
.current_x
;
1240 int top_y
= it
.current_y
;
1241 enum it_method it_method
= it
.method
;
1242 /* Calling line_bottom_y may change it.method, it.position, etc. */
1243 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1244 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1246 if (top_y
< window_top_y
)
1247 visible_p
= bottom_y
> window_top_y
;
1248 else if (top_y
< it
.last_visible_y
)
1252 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1254 /* We stopped on the last glyph of a display vector.
1255 Try and recompute. Hack alert! */
1256 if (charpos
< 2 || top
.charpos
>= charpos
)
1257 top_x
= it
.glyph_row
->x
;
1261 start_display (&it2
, w
, top
);
1262 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1263 get_next_display_element (&it2
);
1264 PRODUCE_GLYPHS (&it2
);
1265 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1266 || it2
.current_x
> it2
.last_visible_x
)
1267 top_x
= it
.glyph_row
->x
;
1270 top_x
= it2
.current_x
;
1271 top_y
= it2
.current_y
;
1277 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1278 *rtop
= max (0, window_top_y
- top_y
);
1279 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1280 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1281 - max (top_y
, window_top_y
)));
1290 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1291 move_it_by_lines (&it
, 1);
1292 if (charpos
< IT_CHARPOS (it
)
1293 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1296 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1298 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1299 *rtop
= max (0, -it2
.current_y
);
1300 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1301 - it
.last_visible_y
));
1302 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1304 - max (it2
.current_y
,
1305 WINDOW_HEADER_LINE_HEIGHT (w
))));
1311 set_buffer_internal_1 (old_buffer
);
1313 current_header_line_height
= current_mode_line_height
= -1;
1315 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1316 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1319 /* Debugging code. */
1321 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1322 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1324 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1331 /* Return the next character from STR. Return in *LEN the length of
1332 the character. This is like STRING_CHAR_AND_LENGTH but never
1333 returns an invalid character. If we find one, we return a `?', but
1334 with the length of the invalid character. */
1337 string_char_and_length (const unsigned char *str
, int *len
)
1341 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1342 if (!CHAR_VALID_P (c
, 1))
1343 /* We may not change the length here because other places in Emacs
1344 don't use this function, i.e. they silently accept invalid
1353 /* Given a position POS containing a valid character and byte position
1354 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1356 static struct text_pos
1357 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, EMACS_INT nchars
)
1359 xassert (STRINGP (string
) && nchars
>= 0);
1361 if (STRING_MULTIBYTE (string
))
1363 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1368 string_char_and_length (p
, &len
);
1371 BYTEPOS (pos
) += len
;
1375 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1381 /* Value is the text position, i.e. character and byte position,
1382 for character position CHARPOS in STRING. */
1384 static INLINE
struct text_pos
1385 string_pos (EMACS_INT charpos
, Lisp_Object string
)
1387 struct text_pos pos
;
1388 xassert (STRINGP (string
));
1389 xassert (charpos
>= 0);
1390 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1395 /* Value is a text position, i.e. character and byte position, for
1396 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1397 means recognize multibyte characters. */
1399 static struct text_pos
1400 c_string_pos (EMACS_INT charpos
, const char *s
, int multibyte_p
)
1402 struct text_pos pos
;
1404 xassert (s
!= NULL
);
1405 xassert (charpos
>= 0);
1411 SET_TEXT_POS (pos
, 0, 0);
1414 string_char_and_length ((const unsigned char *) s
, &len
);
1417 BYTEPOS (pos
) += len
;
1421 SET_TEXT_POS (pos
, charpos
, charpos
);
1427 /* Value is the number of characters in C string S. MULTIBYTE_P
1428 non-zero means recognize multibyte characters. */
1431 number_of_chars (const char *s
, int multibyte_p
)
1437 EMACS_INT rest
= strlen (s
);
1439 const unsigned char *p
= (const unsigned char *) s
;
1441 for (nchars
= 0; rest
> 0; ++nchars
)
1443 string_char_and_length (p
, &len
);
1444 rest
-= len
, p
+= len
;
1448 nchars
= strlen (s
);
1454 /* Compute byte position NEWPOS->bytepos corresponding to
1455 NEWPOS->charpos. POS is a known position in string STRING.
1456 NEWPOS->charpos must be >= POS.charpos. */
1459 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1461 xassert (STRINGP (string
));
1462 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1464 if (STRING_MULTIBYTE (string
))
1465 *newpos
= string_pos_nchars_ahead (pos
, string
,
1466 CHARPOS (*newpos
) - CHARPOS (pos
));
1468 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1472 Return an estimation of the pixel height of mode or header lines on
1473 frame F. FACE_ID specifies what line's height to estimate. */
1476 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1478 #ifdef HAVE_WINDOW_SYSTEM
1479 if (FRAME_WINDOW_P (f
))
1481 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1483 /* This function is called so early when Emacs starts that the face
1484 cache and mode line face are not yet initialized. */
1485 if (FRAME_FACE_CACHE (f
))
1487 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1491 height
= FONT_HEIGHT (face
->font
);
1492 if (face
->box_line_width
> 0)
1493 height
+= 2 * face
->box_line_width
;
1504 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1505 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1506 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1507 not force the value into range. */
1510 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1511 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1514 #ifdef HAVE_WINDOW_SYSTEM
1515 if (FRAME_WINDOW_P (f
))
1517 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1518 even for negative values. */
1520 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1522 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1524 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1525 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1528 STORE_NATIVE_RECT (*bounds
,
1529 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1530 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1531 FRAME_COLUMN_WIDTH (f
) - 1,
1532 FRAME_LINE_HEIGHT (f
) - 1);
1538 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1539 pix_x
= FRAME_TOTAL_COLS (f
);
1543 else if (pix_y
> FRAME_LINES (f
))
1544 pix_y
= FRAME_LINES (f
);
1554 /* Find the glyph under window-relative coordinates X/Y in window W.
1555 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1556 strings. Return in *HPOS and *VPOS the row and column number of
1557 the glyph found. Return in *AREA the glyph area containing X.
1558 Value is a pointer to the glyph found or null if X/Y is not on
1559 text, or we can't tell because W's current matrix is not up to
1564 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1565 int *dx
, int *dy
, int *area
)
1567 struct glyph
*glyph
, *end
;
1568 struct glyph_row
*row
= NULL
;
1571 /* Find row containing Y. Give up if some row is not enabled. */
1572 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1574 row
= MATRIX_ROW (w
->current_matrix
, i
);
1575 if (!row
->enabled_p
)
1577 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1584 /* Give up if Y is not in the window. */
1585 if (i
== w
->current_matrix
->nrows
)
1588 /* Get the glyph area containing X. */
1589 if (w
->pseudo_window_p
)
1596 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1598 *area
= LEFT_MARGIN_AREA
;
1599 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1601 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1604 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1608 *area
= RIGHT_MARGIN_AREA
;
1609 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1613 /* Find glyph containing X. */
1614 glyph
= row
->glyphs
[*area
];
1615 end
= glyph
+ row
->used
[*area
];
1617 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1619 x
-= glyph
->pixel_width
;
1629 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1632 *hpos
= glyph
- row
->glyphs
[*area
];
1636 /* Convert frame-relative x/y to coordinates relative to window W.
1637 Takes pseudo-windows into account. */
1640 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1642 if (w
->pseudo_window_p
)
1644 /* A pseudo-window is always full-width, and starts at the
1645 left edge of the frame, plus a frame border. */
1646 struct frame
*f
= XFRAME (w
->frame
);
1647 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1648 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1652 *x
-= WINDOW_LEFT_EDGE_X (w
);
1653 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1657 #ifdef HAVE_WINDOW_SYSTEM
1660 Return in RECTS[] at most N clipping rectangles for glyph string S.
1661 Return the number of stored rectangles. */
1664 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1671 if (s
->row
->full_width_p
)
1673 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1674 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1675 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1677 /* Unless displaying a mode or menu bar line, which are always
1678 fully visible, clip to the visible part of the row. */
1679 if (s
->w
->pseudo_window_p
)
1680 r
.height
= s
->row
->visible_height
;
1682 r
.height
= s
->height
;
1686 /* This is a text line that may be partially visible. */
1687 r
.x
= window_box_left (s
->w
, s
->area
);
1688 r
.width
= window_box_width (s
->w
, s
->area
);
1689 r
.height
= s
->row
->visible_height
;
1693 if (r
.x
< s
->clip_head
->x
)
1695 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1696 r
.width
-= s
->clip_head
->x
- r
.x
;
1699 r
.x
= s
->clip_head
->x
;
1702 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1704 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1705 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1710 /* If S draws overlapping rows, it's sufficient to use the top and
1711 bottom of the window for clipping because this glyph string
1712 intentionally draws over other lines. */
1713 if (s
->for_overlaps
)
1715 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1716 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1718 /* Alas, the above simple strategy does not work for the
1719 environments with anti-aliased text: if the same text is
1720 drawn onto the same place multiple times, it gets thicker.
1721 If the overlap we are processing is for the erased cursor, we
1722 take the intersection with the rectagle of the cursor. */
1723 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1725 XRectangle rc
, r_save
= r
;
1727 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1728 rc
.y
= s
->w
->phys_cursor
.y
;
1729 rc
.width
= s
->w
->phys_cursor_width
;
1730 rc
.height
= s
->w
->phys_cursor_height
;
1732 x_intersect_rectangles (&r_save
, &rc
, &r
);
1737 /* Don't use S->y for clipping because it doesn't take partially
1738 visible lines into account. For example, it can be negative for
1739 partially visible lines at the top of a window. */
1740 if (!s
->row
->full_width_p
1741 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1742 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1744 r
.y
= max (0, s
->row
->y
);
1747 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1749 /* If drawing the cursor, don't let glyph draw outside its
1750 advertised boundaries. Cleartype does this under some circumstances. */
1751 if (s
->hl
== DRAW_CURSOR
)
1753 struct glyph
*glyph
= s
->first_glyph
;
1758 r
.width
-= s
->x
- r
.x
;
1761 r
.width
= min (r
.width
, glyph
->pixel_width
);
1763 /* If r.y is below window bottom, ensure that we still see a cursor. */
1764 height
= min (glyph
->ascent
+ glyph
->descent
,
1765 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1766 max_y
= window_text_bottom_y (s
->w
) - height
;
1767 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1768 if (s
->ybase
- glyph
->ascent
> max_y
)
1775 /* Don't draw cursor glyph taller than our actual glyph. */
1776 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1777 if (height
< r
.height
)
1779 max_y
= r
.y
+ r
.height
;
1780 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1781 r
.height
= min (max_y
- r
.y
, height
);
1788 XRectangle r_save
= r
;
1790 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
1794 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1795 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1797 #ifdef CONVERT_FROM_XRECT
1798 CONVERT_FROM_XRECT (r
, *rects
);
1806 /* If we are processing overlapping and allowed to return
1807 multiple clipping rectangles, we exclude the row of the glyph
1808 string from the clipping rectangle. This is to avoid drawing
1809 the same text on the environment with anti-aliasing. */
1810 #ifdef CONVERT_FROM_XRECT
1813 XRectangle
*rs
= rects
;
1815 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1817 if (s
->for_overlaps
& OVERLAPS_PRED
)
1820 if (r
.y
+ r
.height
> row_y
)
1823 rs
[i
].height
= row_y
- r
.y
;
1829 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1832 if (r
.y
< row_y
+ s
->row
->visible_height
)
1834 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1836 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1837 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1846 #ifdef CONVERT_FROM_XRECT
1847 for (i
= 0; i
< n
; i
++)
1848 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1855 Return in *NR the clipping rectangle for glyph string S. */
1858 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
1860 get_glyph_string_clip_rects (s
, nr
, 1);
1865 Return the position and height of the phys cursor in window W.
1866 Set w->phys_cursor_width to width of phys cursor.
1870 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
1871 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
1873 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1874 int x
, y
, wd
, h
, h0
, y0
;
1876 /* Compute the width of the rectangle to draw. If on a stretch
1877 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1878 rectangle as wide as the glyph, but use a canonical character
1880 wd
= glyph
->pixel_width
- 1;
1881 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
1885 x
= w
->phys_cursor
.x
;
1892 if (glyph
->type
== STRETCH_GLYPH
1893 && !x_stretch_cursor_p
)
1894 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
1895 w
->phys_cursor_width
= wd
;
1897 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
1899 /* If y is below window bottom, ensure that we still see a cursor. */
1900 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
1902 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
1903 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
1905 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
1908 h
= max (h
- (y0
- y
) + 1, h0
);
1913 y0
= window_text_bottom_y (w
) - h0
;
1921 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
1922 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
1927 * Remember which glyph the mouse is over.
1931 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
1935 struct glyph_row
*r
, *gr
, *end_row
;
1936 enum window_part part
;
1937 enum glyph_row_area area
;
1938 int x
, y
, width
, height
;
1940 /* Try to determine frame pixel position and size of the glyph under
1941 frame pixel coordinates X/Y on frame F. */
1943 if (!f
->glyphs_initialized_p
1944 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
1947 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
1948 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
1952 w
= XWINDOW (window
);
1953 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
1954 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
1956 x
= window_relative_x_coord (w
, part
, gx
);
1957 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
1959 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1960 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1962 if (w
->pseudo_window_p
)
1965 part
= ON_MODE_LINE
; /* Don't adjust margin. */
1971 case ON_LEFT_MARGIN
:
1972 area
= LEFT_MARGIN_AREA
;
1975 case ON_RIGHT_MARGIN
:
1976 area
= RIGHT_MARGIN_AREA
;
1979 case ON_HEADER_LINE
:
1981 gr
= (part
== ON_HEADER_LINE
1982 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1983 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
1986 goto text_glyph_row_found
;
1993 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
1994 if (r
->y
+ r
->height
> y
)
2000 text_glyph_row_found
:
2003 struct glyph
*g
= gr
->glyphs
[area
];
2004 struct glyph
*end
= g
+ gr
->used
[area
];
2006 height
= gr
->height
;
2007 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2008 if (gx
+ g
->pixel_width
> x
)
2013 if (g
->type
== IMAGE_GLYPH
)
2015 /* Don't remember when mouse is over image, as
2016 image may have hot-spots. */
2017 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2020 width
= g
->pixel_width
;
2024 /* Use nominal char spacing at end of line. */
2026 gx
+= (x
/ width
) * width
;
2029 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2030 gx
+= window_box_left_offset (w
, area
);
2034 /* Use nominal line height at end of window. */
2035 gx
= (x
/ width
) * width
;
2037 gy
+= (y
/ height
) * height
;
2041 case ON_LEFT_FRINGE
:
2042 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2043 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2044 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2045 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2048 case ON_RIGHT_FRINGE
:
2049 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2050 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2051 : window_box_right_offset (w
, TEXT_AREA
));
2052 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2056 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2058 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2059 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2060 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2062 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2066 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2067 if (r
->y
+ r
->height
> y
)
2074 height
= gr
->height
;
2077 /* Use nominal line height at end of window. */
2079 gy
+= (y
/ height
) * height
;
2086 /* If there is no glyph under the mouse, then we divide the screen
2087 into a grid of the smallest glyph in the frame, and use that
2090 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2091 round down even for negative values. */
2097 gx
= (gx
/ width
) * width
;
2098 gy
= (gy
/ height
) * height
;
2103 gx
+= WINDOW_LEFT_EDGE_X (w
);
2104 gy
+= WINDOW_TOP_EDGE_Y (w
);
2107 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2109 /* Visible feedback for debugging. */
2112 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2113 f
->output_data
.x
->normal_gc
,
2114 gx
, gy
, width
, height
);
2120 #endif /* HAVE_WINDOW_SYSTEM */
2123 /***********************************************************************
2124 Lisp form evaluation
2125 ***********************************************************************/
2127 /* Error handler for safe_eval and safe_call. */
2130 safe_eval_handler (Lisp_Object arg
)
2132 add_to_log ("Error during redisplay: %S", arg
, Qnil
);
2137 /* Evaluate SEXPR and return the result, or nil if something went
2138 wrong. Prevent redisplay during the evaluation. */
2140 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2141 Return the result, or nil if something went wrong. Prevent
2142 redisplay during the evaluation. */
2145 safe_call (size_t nargs
, Lisp_Object
*args
)
2149 if (inhibit_eval_during_redisplay
)
2153 int count
= SPECPDL_INDEX ();
2154 struct gcpro gcpro1
;
2157 gcpro1
.nvars
= nargs
;
2158 specbind (Qinhibit_redisplay
, Qt
);
2159 /* Use Qt to ensure debugger does not run,
2160 so there is no possibility of wanting to redisplay. */
2161 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2164 val
= unbind_to (count
, val
);
2171 /* Call function FN with one argument ARG.
2172 Return the result, or nil if something went wrong. */
2175 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2177 Lisp_Object args
[2];
2180 return safe_call (2, args
);
2183 static Lisp_Object Qeval
;
2186 safe_eval (Lisp_Object sexpr
)
2188 return safe_call1 (Qeval
, sexpr
);
2191 /* Call function FN with one argument ARG.
2192 Return the result, or nil if something went wrong. */
2195 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2197 Lisp_Object args
[3];
2201 return safe_call (3, args
);
2206 /***********************************************************************
2208 ***********************************************************************/
2212 /* Define CHECK_IT to perform sanity checks on iterators.
2213 This is for debugging. It is too slow to do unconditionally. */
2219 if (it
->method
== GET_FROM_STRING
)
2221 xassert (STRINGP (it
->string
));
2222 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2226 xassert (IT_STRING_CHARPOS (*it
) < 0);
2227 if (it
->method
== GET_FROM_BUFFER
)
2229 /* Check that character and byte positions agree. */
2230 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2235 xassert (it
->current
.dpvec_index
>= 0);
2237 xassert (it
->current
.dpvec_index
< 0);
2240 #define CHECK_IT(IT) check_it ((IT))
2244 #define CHECK_IT(IT) (void) 0
2251 /* Check that the window end of window W is what we expect it
2252 to be---the last row in the current matrix displaying text. */
2255 check_window_end (w
)
2258 if (!MINI_WINDOW_P (w
)
2259 && !NILP (w
->window_end_valid
))
2261 struct glyph_row
*row
;
2262 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2263 XFASTINT (w
->window_end_vpos
)),
2265 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2266 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2270 #define CHECK_WINDOW_END(W) check_window_end ((W))
2272 #else /* not GLYPH_DEBUG */
2274 #define CHECK_WINDOW_END(W) (void) 0
2276 #endif /* not GLYPH_DEBUG */
2280 /***********************************************************************
2281 Iterator initialization
2282 ***********************************************************************/
2284 /* Initialize IT for displaying current_buffer in window W, starting
2285 at character position CHARPOS. CHARPOS < 0 means that no buffer
2286 position is specified which is useful when the iterator is assigned
2287 a position later. BYTEPOS is the byte position corresponding to
2288 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2290 If ROW is not null, calls to produce_glyphs with IT as parameter
2291 will produce glyphs in that row.
2293 BASE_FACE_ID is the id of a base face to use. It must be one of
2294 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2295 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2296 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2298 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2299 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2300 will be initialized to use the corresponding mode line glyph row of
2301 the desired matrix of W. */
2304 init_iterator (struct it
*it
, struct window
*w
,
2305 EMACS_INT charpos
, EMACS_INT bytepos
,
2306 struct glyph_row
*row
, enum face_id base_face_id
)
2308 int highlight_region_p
;
2309 enum face_id remapped_base_face_id
= base_face_id
;
2311 /* Some precondition checks. */
2312 xassert (w
!= NULL
&& it
!= NULL
);
2313 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2316 /* If face attributes have been changed since the last redisplay,
2317 free realized faces now because they depend on face definitions
2318 that might have changed. Don't free faces while there might be
2319 desired matrices pending which reference these faces. */
2320 if (face_change_count
&& !inhibit_free_realized_faces
)
2322 face_change_count
= 0;
2323 free_all_realized_faces (Qnil
);
2326 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2327 if (! NILP (Vface_remapping_alist
))
2328 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2330 /* Use one of the mode line rows of W's desired matrix if
2334 if (base_face_id
== MODE_LINE_FACE_ID
2335 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2336 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2337 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2338 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2342 memset (it
, 0, sizeof *it
);
2343 it
->current
.overlay_string_index
= -1;
2344 it
->current
.dpvec_index
= -1;
2345 it
->base_face_id
= remapped_base_face_id
;
2347 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2348 it
->paragraph_embedding
= L2R
;
2349 it
->bidi_it
.string
.lstring
= Qnil
;
2350 it
->bidi_it
.string
.s
= NULL
;
2351 it
->bidi_it
.string
.bufpos
= 0;
2353 /* The window in which we iterate over current_buffer: */
2354 XSETWINDOW (it
->window
, w
);
2356 it
->f
= XFRAME (w
->frame
);
2360 /* Extra space between lines (on window systems only). */
2361 if (base_face_id
== DEFAULT_FACE_ID
2362 && FRAME_WINDOW_P (it
->f
))
2364 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2365 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2366 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2367 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2368 * FRAME_LINE_HEIGHT (it
->f
));
2369 else if (it
->f
->extra_line_spacing
> 0)
2370 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2371 it
->max_extra_line_spacing
= 0;
2374 /* If realized faces have been removed, e.g. because of face
2375 attribute changes of named faces, recompute them. When running
2376 in batch mode, the face cache of the initial frame is null. If
2377 we happen to get called, make a dummy face cache. */
2378 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2379 init_frame_faces (it
->f
);
2380 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2381 recompute_basic_faces (it
->f
);
2383 /* Current value of the `slice', `space-width', and 'height' properties. */
2384 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2385 it
->space_width
= Qnil
;
2386 it
->font_height
= Qnil
;
2387 it
->override_ascent
= -1;
2389 /* Are control characters displayed as `^C'? */
2390 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2392 /* -1 means everything between a CR and the following line end
2393 is invisible. >0 means lines indented more than this value are
2395 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2396 ? XFASTINT (BVAR (current_buffer
, selective_display
))
2397 : (!NILP (BVAR (current_buffer
, selective_display
))
2399 it
->selective_display_ellipsis_p
2400 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2402 /* Display table to use. */
2403 it
->dp
= window_display_table (w
);
2405 /* Are multibyte characters enabled in current_buffer? */
2406 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2408 /* Non-zero if we should highlight the region. */
2410 = (!NILP (Vtransient_mark_mode
)
2411 && !NILP (BVAR (current_buffer
, mark_active
))
2412 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= 0);
2414 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2415 start and end of a visible region in window IT->w. Set both to
2416 -1 to indicate no region. */
2417 if (highlight_region_p
2418 /* Maybe highlight only in selected window. */
2419 && (/* Either show region everywhere. */
2420 highlight_nonselected_windows
2421 /* Or show region in the selected window. */
2422 || w
== XWINDOW (selected_window
)
2423 /* Or show the region if we are in the mini-buffer and W is
2424 the window the mini-buffer refers to. */
2425 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2426 && WINDOWP (minibuf_selected_window
)
2427 && w
== XWINDOW (minibuf_selected_window
))))
2429 EMACS_INT markpos
= marker_position (BVAR (current_buffer
, mark
));
2430 it
->region_beg_charpos
= min (PT
, markpos
);
2431 it
->region_end_charpos
= max (PT
, markpos
);
2434 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2436 /* Get the position at which the redisplay_end_trigger hook should
2437 be run, if it is to be run at all. */
2438 if (MARKERP (w
->redisplay_end_trigger
)
2439 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2440 it
->redisplay_end_trigger_charpos
2441 = marker_position (w
->redisplay_end_trigger
);
2442 else if (INTEGERP (w
->redisplay_end_trigger
))
2443 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2445 /* Correct bogus values of tab_width. */
2446 it
->tab_width
= XINT (BVAR (current_buffer
, tab_width
));
2447 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2450 /* Are lines in the display truncated? */
2451 if (base_face_id
!= DEFAULT_FACE_ID
2452 || XINT (it
->w
->hscroll
)
2453 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2454 && ((!NILP (Vtruncate_partial_width_windows
)
2455 && !INTEGERP (Vtruncate_partial_width_windows
))
2456 || (INTEGERP (Vtruncate_partial_width_windows
)
2457 && (WINDOW_TOTAL_COLS (it
->w
)
2458 < XINT (Vtruncate_partial_width_windows
))))))
2459 it
->line_wrap
= TRUNCATE
;
2460 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2461 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2462 ? WINDOW_WRAP
: WORD_WRAP
;
2464 it
->line_wrap
= TRUNCATE
;
2466 /* Get dimensions of truncation and continuation glyphs. These are
2467 displayed as fringe bitmaps under X, so we don't need them for such
2469 if (!FRAME_WINDOW_P (it
->f
))
2471 if (it
->line_wrap
== TRUNCATE
)
2473 /* We will need the truncation glyph. */
2474 xassert (it
->glyph_row
== NULL
);
2475 produce_special_glyphs (it
, IT_TRUNCATION
);
2476 it
->truncation_pixel_width
= it
->pixel_width
;
2480 /* We will need the continuation glyph. */
2481 xassert (it
->glyph_row
== NULL
);
2482 produce_special_glyphs (it
, IT_CONTINUATION
);
2483 it
->continuation_pixel_width
= it
->pixel_width
;
2486 /* Reset these values to zero because the produce_special_glyphs
2487 above has changed them. */
2488 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2489 it
->phys_ascent
= it
->phys_descent
= 0;
2492 /* Set this after getting the dimensions of truncation and
2493 continuation glyphs, so that we don't produce glyphs when calling
2494 produce_special_glyphs, above. */
2495 it
->glyph_row
= row
;
2496 it
->area
= TEXT_AREA
;
2498 /* Forget any previous info about this row being reversed. */
2500 it
->glyph_row
->reversed_p
= 0;
2502 /* Get the dimensions of the display area. The display area
2503 consists of the visible window area plus a horizontally scrolled
2504 part to the left of the window. All x-values are relative to the
2505 start of this total display area. */
2506 if (base_face_id
!= DEFAULT_FACE_ID
)
2508 /* Mode lines, menu bar in terminal frames. */
2509 it
->first_visible_x
= 0;
2510 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2515 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2516 it
->last_visible_x
= (it
->first_visible_x
2517 + window_box_width (w
, TEXT_AREA
));
2519 /* If we truncate lines, leave room for the truncator glyph(s) at
2520 the right margin. Otherwise, leave room for the continuation
2521 glyph(s). Truncation and continuation glyphs are not inserted
2522 for window-based redisplay. */
2523 if (!FRAME_WINDOW_P (it
->f
))
2525 if (it
->line_wrap
== TRUNCATE
)
2526 it
->last_visible_x
-= it
->truncation_pixel_width
;
2528 it
->last_visible_x
-= it
->continuation_pixel_width
;
2531 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2532 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2535 /* Leave room for a border glyph. */
2536 if (!FRAME_WINDOW_P (it
->f
)
2537 && !WINDOW_RIGHTMOST_P (it
->w
))
2538 it
->last_visible_x
-= 1;
2540 it
->last_visible_y
= window_text_bottom_y (w
);
2542 /* For mode lines and alike, arrange for the first glyph having a
2543 left box line if the face specifies a box. */
2544 if (base_face_id
!= DEFAULT_FACE_ID
)
2548 it
->face_id
= remapped_base_face_id
;
2550 /* If we have a boxed mode line, make the first character appear
2551 with a left box line. */
2552 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2553 if (face
->box
!= FACE_NO_BOX
)
2554 it
->start_of_box_run_p
= 1;
2557 /* If a buffer position was specified, set the iterator there,
2558 getting overlays and face properties from that position. */
2559 if (charpos
>= BUF_BEG (current_buffer
))
2561 it
->end_charpos
= ZV
;
2563 IT_CHARPOS (*it
) = charpos
;
2565 /* Compute byte position if not specified. */
2566 if (bytepos
< charpos
)
2567 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2569 IT_BYTEPOS (*it
) = bytepos
;
2571 it
->start
= it
->current
;
2572 /* Do we need to reorder bidirectional text? Not if this is a
2573 unibyte buffer: by definition, none of the single-byte
2574 characters are strong R2L, so no reordering is needed. And
2575 bidi.c doesn't support unibyte buffers anyway. */
2577 !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2580 /* If we are to reorder bidirectional text, init the bidi
2584 /* Note the paragraph direction that this buffer wants to
2586 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2588 it
->paragraph_embedding
= L2R
;
2589 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2591 it
->paragraph_embedding
= R2L
;
2593 it
->paragraph_embedding
= NEUTRAL_DIR
;
2594 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2598 /* Compute faces etc. */
2599 reseat (it
, it
->current
.pos
, 1);
2606 /* Initialize IT for the display of window W with window start POS. */
2609 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2611 struct glyph_row
*row
;
2612 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2614 row
= w
->desired_matrix
->rows
+ first_vpos
;
2615 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2616 it
->first_vpos
= first_vpos
;
2618 /* Don't reseat to previous visible line start if current start
2619 position is in a string or image. */
2620 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2622 int start_at_line_beg_p
;
2623 int first_y
= it
->current_y
;
2625 /* If window start is not at a line start, skip forward to POS to
2626 get the correct continuation lines width. */
2627 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2628 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2629 if (!start_at_line_beg_p
)
2633 reseat_at_previous_visible_line_start (it
);
2634 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2636 new_x
= it
->current_x
+ it
->pixel_width
;
2638 /* If lines are continued, this line may end in the middle
2639 of a multi-glyph character (e.g. a control character
2640 displayed as \003, or in the middle of an overlay
2641 string). In this case move_it_to above will not have
2642 taken us to the start of the continuation line but to the
2643 end of the continued line. */
2644 if (it
->current_x
> 0
2645 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2646 && (/* And glyph doesn't fit on the line. */
2647 new_x
> it
->last_visible_x
2648 /* Or it fits exactly and we're on a window
2650 || (new_x
== it
->last_visible_x
2651 && FRAME_WINDOW_P (it
->f
))))
2653 if (it
->current
.dpvec_index
>= 0
2654 || it
->current
.overlay_string_index
>= 0)
2656 set_iterator_to_next (it
, 1);
2657 move_it_in_display_line_to (it
, -1, -1, 0);
2660 it
->continuation_lines_width
+= it
->current_x
;
2663 /* We're starting a new display line, not affected by the
2664 height of the continued line, so clear the appropriate
2665 fields in the iterator structure. */
2666 it
->max_ascent
= it
->max_descent
= 0;
2667 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2669 it
->current_y
= first_y
;
2671 it
->current_x
= it
->hpos
= 0;
2677 /* Return 1 if POS is a position in ellipses displayed for invisible
2678 text. W is the window we display, for text property lookup. */
2681 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2683 Lisp_Object prop
, window
;
2685 EMACS_INT charpos
= CHARPOS (pos
->pos
);
2687 /* If POS specifies a position in a display vector, this might
2688 be for an ellipsis displayed for invisible text. We won't
2689 get the iterator set up for delivering that ellipsis unless
2690 we make sure that it gets aware of the invisible text. */
2691 if (pos
->dpvec_index
>= 0
2692 && pos
->overlay_string_index
< 0
2693 && CHARPOS (pos
->string_pos
) < 0
2695 && (XSETWINDOW (window
, w
),
2696 prop
= Fget_char_property (make_number (charpos
),
2697 Qinvisible
, window
),
2698 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2700 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2702 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2709 /* Initialize IT for stepping through current_buffer in window W,
2710 starting at position POS that includes overlay string and display
2711 vector/ control character translation position information. Value
2712 is zero if there are overlay strings with newlines at POS. */
2715 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
2717 EMACS_INT charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2718 int i
, overlay_strings_with_newlines
= 0;
2720 /* If POS specifies a position in a display vector, this might
2721 be for an ellipsis displayed for invisible text. We won't
2722 get the iterator set up for delivering that ellipsis unless
2723 we make sure that it gets aware of the invisible text. */
2724 if (in_ellipses_for_invisible_text_p (pos
, w
))
2730 /* Keep in mind: the call to reseat in init_iterator skips invisible
2731 text, so we might end up at a position different from POS. This
2732 is only a problem when POS is a row start after a newline and an
2733 overlay starts there with an after-string, and the overlay has an
2734 invisible property. Since we don't skip invisible text in
2735 display_line and elsewhere immediately after consuming the
2736 newline before the row start, such a POS will not be in a string,
2737 but the call to init_iterator below will move us to the
2739 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2741 /* This only scans the current chunk -- it should scan all chunks.
2742 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2743 to 16 in 22.1 to make this a lesser problem. */
2744 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2746 const char *s
= SSDATA (it
->overlay_strings
[i
]);
2747 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2749 while (s
< e
&& *s
!= '\n')
2754 overlay_strings_with_newlines
= 1;
2759 /* If position is within an overlay string, set up IT to the right
2761 if (pos
->overlay_string_index
>= 0)
2765 /* If the first overlay string happens to have a `display'
2766 property for an image, the iterator will be set up for that
2767 image, and we have to undo that setup first before we can
2768 correct the overlay string index. */
2769 if (it
->method
== GET_FROM_IMAGE
)
2772 /* We already have the first chunk of overlay strings in
2773 IT->overlay_strings. Load more until the one for
2774 pos->overlay_string_index is in IT->overlay_strings. */
2775 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2777 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2778 it
->current
.overlay_string_index
= 0;
2781 load_overlay_strings (it
, 0);
2782 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2786 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2787 relative_index
= (it
->current
.overlay_string_index
2788 % OVERLAY_STRING_CHUNK_SIZE
);
2789 it
->string
= it
->overlay_strings
[relative_index
];
2790 xassert (STRINGP (it
->string
));
2791 it
->current
.string_pos
= pos
->string_pos
;
2792 it
->method
= GET_FROM_STRING
;
2795 if (CHARPOS (pos
->string_pos
) >= 0)
2797 /* Recorded position is not in an overlay string, but in another
2798 string. This can only be a string from a `display' property.
2799 IT should already be filled with that string. */
2800 it
->current
.string_pos
= pos
->string_pos
;
2801 xassert (STRINGP (it
->string
));
2804 /* Restore position in display vector translations, control
2805 character translations or ellipses. */
2806 if (pos
->dpvec_index
>= 0)
2808 if (it
->dpvec
== NULL
)
2809 get_next_display_element (it
);
2810 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2811 it
->current
.dpvec_index
= pos
->dpvec_index
;
2815 return !overlay_strings_with_newlines
;
2819 /* Initialize IT for stepping through current_buffer in window W
2820 starting at ROW->start. */
2823 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
2825 init_from_display_pos (it
, w
, &row
->start
);
2826 it
->start
= row
->start
;
2827 it
->continuation_lines_width
= row
->continuation_lines_width
;
2832 /* Initialize IT for stepping through current_buffer in window W
2833 starting in the line following ROW, i.e. starting at ROW->end.
2834 Value is zero if there are overlay strings with newlines at ROW's
2838 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
2842 if (init_from_display_pos (it
, w
, &row
->end
))
2844 if (row
->continued_p
)
2845 it
->continuation_lines_width
2846 = row
->continuation_lines_width
+ row
->pixel_width
;
2857 /***********************************************************************
2859 ***********************************************************************/
2861 /* Called when IT reaches IT->stop_charpos. Handle text property and
2862 overlay changes. Set IT->stop_charpos to the next position where
2866 handle_stop (struct it
*it
)
2868 enum prop_handled handled
;
2869 int handle_overlay_change_p
;
2873 it
->current
.dpvec_index
= -1;
2874 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
2875 it
->ignore_overlay_strings_at_pos_p
= 0;
2878 /* Use face of preceding text for ellipsis (if invisible) */
2879 if (it
->selective_display_ellipsis_p
)
2880 it
->saved_face_id
= it
->face_id
;
2884 handled
= HANDLED_NORMALLY
;
2886 /* Call text property handlers. */
2887 for (p
= it_props
; p
->handler
; ++p
)
2889 handled
= p
->handler (it
);
2891 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2893 else if (handled
== HANDLED_RETURN
)
2895 /* We still want to show before and after strings from
2896 overlays even if the actual buffer text is replaced. */
2897 if (!handle_overlay_change_p
2899 || !get_overlay_strings_1 (it
, 0, 0))
2902 setup_for_ellipsis (it
, 0);
2903 /* When handling a display spec, we might load an
2904 empty string. In that case, discard it here. We
2905 used to discard it in handle_single_display_spec,
2906 but that causes get_overlay_strings_1, above, to
2907 ignore overlay strings that we must check. */
2908 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
2912 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
2916 it
->ignore_overlay_strings_at_pos_p
= 1;
2917 it
->string_from_display_prop_p
= 0;
2918 handle_overlay_change_p
= 0;
2920 handled
= HANDLED_RECOMPUTE_PROPS
;
2923 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2924 handle_overlay_change_p
= 0;
2927 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2929 /* Don't check for overlay strings below when set to deliver
2930 characters from a display vector. */
2931 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
2932 handle_overlay_change_p
= 0;
2934 /* Handle overlay changes.
2935 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
2936 if it finds overlays. */
2937 if (handle_overlay_change_p
)
2938 handled
= handle_overlay_change (it
);
2943 setup_for_ellipsis (it
, 0);
2947 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2949 /* Determine where to stop next. */
2950 if (handled
== HANDLED_NORMALLY
)
2951 compute_stop_pos (it
);
2955 /* Compute IT->stop_charpos from text property and overlay change
2956 information for IT's current position. */
2959 compute_stop_pos (struct it
*it
)
2961 register INTERVAL iv
, next_iv
;
2962 Lisp_Object object
, limit
, position
;
2963 EMACS_INT charpos
, bytepos
;
2965 /* If nowhere else, stop at the end. */
2966 it
->stop_charpos
= it
->end_charpos
;
2968 if (STRINGP (it
->string
))
2970 /* Strings are usually short, so don't limit the search for
2972 object
= it
->string
;
2974 charpos
= IT_STRING_CHARPOS (*it
);
2975 bytepos
= IT_STRING_BYTEPOS (*it
);
2981 /* If next overlay change is in front of the current stop pos
2982 (which is IT->end_charpos), stop there. Note: value of
2983 next_overlay_change is point-max if no overlay change
2985 charpos
= IT_CHARPOS (*it
);
2986 bytepos
= IT_BYTEPOS (*it
);
2987 pos
= next_overlay_change (charpos
);
2988 if (pos
< it
->stop_charpos
)
2989 it
->stop_charpos
= pos
;
2991 /* If showing the region, we have to stop at the region
2992 start or end because the face might change there. */
2993 if (it
->region_beg_charpos
> 0)
2995 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2996 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2997 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2998 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3001 /* Set up variables for computing the stop position from text
3002 property changes. */
3003 XSETBUFFER (object
, current_buffer
);
3004 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3007 /* Get the interval containing IT's position. Value is a null
3008 interval if there isn't such an interval. */
3009 position
= make_number (charpos
);
3010 iv
= validate_interval_range (object
, &position
, &position
, 0);
3011 if (!NULL_INTERVAL_P (iv
))
3013 Lisp_Object values_here
[LAST_PROP_IDX
];
3016 /* Get properties here. */
3017 for (p
= it_props
; p
->handler
; ++p
)
3018 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3020 /* Look for an interval following iv that has different
3022 for (next_iv
= next_interval (iv
);
3023 (!NULL_INTERVAL_P (next_iv
)
3025 || XFASTINT (limit
) > next_iv
->position
));
3026 next_iv
= next_interval (next_iv
))
3028 for (p
= it_props
; p
->handler
; ++p
)
3030 Lisp_Object new_value
;
3032 new_value
= textget (next_iv
->plist
, *p
->name
);
3033 if (!EQ (values_here
[p
->idx
], new_value
))
3041 if (!NULL_INTERVAL_P (next_iv
))
3043 if (INTEGERP (limit
)
3044 && next_iv
->position
>= XFASTINT (limit
))
3045 /* No text property change up to limit. */
3046 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3048 /* Text properties change in next_iv. */
3049 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3053 if (it
->cmp_it
.id
< 0)
3055 EMACS_INT stoppos
= it
->end_charpos
;
3057 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3059 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3060 stoppos
, it
->string
);
3063 xassert (STRINGP (it
->string
)
3064 || (it
->stop_charpos
>= BEGV
3065 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3069 /* Return the position of the next overlay change after POS in
3070 current_buffer. Value is point-max if no overlay change
3071 follows. This is like `next-overlay-change' but doesn't use
3075 next_overlay_change (EMACS_INT pos
)
3079 Lisp_Object
*overlays
;
3082 /* Get all overlays at the given position. */
3083 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3085 /* If any of these overlays ends before endpos,
3086 use its ending point instead. */
3087 for (i
= 0; i
< noverlays
; ++i
)
3092 oend
= OVERLAY_END (overlays
[i
]);
3093 oendpos
= OVERLAY_POSITION (oend
);
3094 endpos
= min (endpos
, oendpos
);
3100 /* Return the character position of a display string at or after
3101 position specified by POSITION. If no display string exists at or
3102 after POSITION, return ZV. A display string is either an overlay
3103 with `display' property whose value is a string, or a `display'
3104 text property whose value is a string. STRING is data about the
3105 string to iterate; if STRING->lstring is nil, we are iterating a
3106 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3109 compute_display_string_pos (struct text_pos
*position
,
3110 struct bidi_string_data
*string
, int frame_window_p
)
3112 /* OBJECT = nil means current buffer. */
3113 Lisp_Object object
=
3114 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3115 Lisp_Object pos
, spec
;
3116 EMACS_INT eob
= STRINGP (object
) ? string
->schars
: ZV
;
3117 EMACS_INT begb
= STRINGP (object
) ? 0 : BEGV
;
3118 EMACS_INT bufpos
, charpos
= CHARPOS (*position
);
3119 struct text_pos tpos
;
3122 /* We don't support display properties whose values are strings
3123 that have display string properties. */
3124 || string
->from_disp_str
3125 /* C strings cannot have display properties. */
3126 || (string
->s
&& !STRINGP (object
)))
3129 /* If the character at CHARPOS is where the display string begins,
3131 pos
= make_number (charpos
);
3132 if (STRINGP (object
))
3133 bufpos
= string
->bufpos
;
3137 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3139 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3142 && handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3146 /* Look forward for the first character with a `display' property
3147 that will replace the underlying text when displayed. */
3149 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3150 CHARPOS (tpos
) = XFASTINT (pos
);
3151 if (STRINGP (object
))
3152 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3154 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3155 if (CHARPOS (tpos
) >= eob
)
3157 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3158 if (!STRINGP (object
))
3159 bufpos
= CHARPOS (tpos
);
3160 } while (NILP (spec
)
3161 || !handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3164 return CHARPOS (tpos
);
3167 /* Return the character position of the end of the display string that
3168 started at CHARPOS. A display string is either an overlay with
3169 `display' property whose value is a string or a `display' text
3170 property whose value is a string. */
3172 compute_display_string_end (EMACS_INT charpos
, struct bidi_string_data
*string
)
3174 /* OBJECT = nil means current buffer. */
3175 Lisp_Object object
=
3176 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3177 Lisp_Object pos
= make_number (charpos
);
3178 EMACS_INT eob
= STRINGP (object
) ? string
->schars
: ZV
;
3180 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3183 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3186 /* Look forward for the first character where the `display' property
3188 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3190 return XFASTINT (pos
);
3195 /***********************************************************************
3197 ***********************************************************************/
3199 /* Handle changes in the `fontified' property of the current buffer by
3200 calling hook functions from Qfontification_functions to fontify
3203 static enum prop_handled
3204 handle_fontified_prop (struct it
*it
)
3206 Lisp_Object prop
, pos
;
3207 enum prop_handled handled
= HANDLED_NORMALLY
;
3209 if (!NILP (Vmemory_full
))
3212 /* Get the value of the `fontified' property at IT's current buffer
3213 position. (The `fontified' property doesn't have a special
3214 meaning in strings.) If the value is nil, call functions from
3215 Qfontification_functions. */
3216 if (!STRINGP (it
->string
)
3218 && !NILP (Vfontification_functions
)
3219 && !NILP (Vrun_hooks
)
3220 && (pos
= make_number (IT_CHARPOS (*it
)),
3221 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3222 /* Ignore the special cased nil value always present at EOB since
3223 no amount of fontifying will be able to change it. */
3224 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3226 int count
= SPECPDL_INDEX ();
3228 struct buffer
*obuf
= current_buffer
;
3229 int begv
= BEGV
, zv
= ZV
;
3230 int old_clip_changed
= current_buffer
->clip_changed
;
3232 val
= Vfontification_functions
;
3233 specbind (Qfontification_functions
, Qnil
);
3235 xassert (it
->end_charpos
== ZV
);
3237 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3238 safe_call1 (val
, pos
);
3241 Lisp_Object fns
, fn
;
3242 struct gcpro gcpro1
, gcpro2
;
3247 for (; CONSP (val
); val
= XCDR (val
))
3253 /* A value of t indicates this hook has a local
3254 binding; it means to run the global binding too.
3255 In a global value, t should not occur. If it
3256 does, we must ignore it to avoid an endless
3258 for (fns
= Fdefault_value (Qfontification_functions
);
3264 safe_call1 (fn
, pos
);
3268 safe_call1 (fn
, pos
);
3274 unbind_to (count
, Qnil
);
3276 /* Fontification functions routinely call `save-restriction'.
3277 Normally, this tags clip_changed, which can confuse redisplay
3278 (see discussion in Bug#6671). Since we don't perform any
3279 special handling of fontification changes in the case where
3280 `save-restriction' isn't called, there's no point doing so in
3281 this case either. So, if the buffer's restrictions are
3282 actually left unchanged, reset clip_changed. */
3283 if (obuf
== current_buffer
)
3285 if (begv
== BEGV
&& zv
== ZV
)
3286 current_buffer
->clip_changed
= old_clip_changed
;
3288 /* There isn't much we can reasonably do to protect against
3289 misbehaving fontification, but here's a fig leaf. */
3290 else if (!NILP (BVAR (obuf
, name
)))
3291 set_buffer_internal_1 (obuf
);
3293 /* The fontification code may have added/removed text.
3294 It could do even a lot worse, but let's at least protect against
3295 the most obvious case where only the text past `pos' gets changed',
3296 as is/was done in grep.el where some escapes sequences are turned
3297 into face properties (bug#7876). */
3298 it
->end_charpos
= ZV
;
3300 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3301 something. This avoids an endless loop if they failed to
3302 fontify the text for which reason ever. */
3303 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3304 handled
= HANDLED_RECOMPUTE_PROPS
;
3312 /***********************************************************************
3314 ***********************************************************************/
3316 /* Set up iterator IT from face properties at its current position.
3317 Called from handle_stop. */
3319 static enum prop_handled
3320 handle_face_prop (struct it
*it
)
3323 EMACS_INT next_stop
;
3325 if (!STRINGP (it
->string
))
3328 = face_at_buffer_position (it
->w
,
3330 it
->region_beg_charpos
,
3331 it
->region_end_charpos
,
3334 + TEXT_PROP_DISTANCE_LIMIT
),
3335 0, it
->base_face_id
);
3337 /* Is this a start of a run of characters with box face?
3338 Caveat: this can be called for a freshly initialized
3339 iterator; face_id is -1 in this case. We know that the new
3340 face will not change until limit, i.e. if the new face has a
3341 box, all characters up to limit will have one. But, as
3342 usual, we don't know whether limit is really the end. */
3343 if (new_face_id
!= it
->face_id
)
3345 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3347 /* If new face has a box but old face has not, this is
3348 the start of a run of characters with box, i.e. it has
3349 a shadow on the left side. The value of face_id of the
3350 iterator will be -1 if this is the initial call that gets
3351 the face. In this case, we have to look in front of IT's
3352 position and see whether there is a face != new_face_id. */
3353 it
->start_of_box_run_p
3354 = (new_face
->box
!= FACE_NO_BOX
3355 && (it
->face_id
>= 0
3356 || IT_CHARPOS (*it
) == BEG
3357 || new_face_id
!= face_before_it_pos (it
)));
3358 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3366 Lisp_Object from_overlay
3367 = (it
->current
.overlay_string_index
>= 0
3368 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3371 /* See if we got to this string directly or indirectly from
3372 an overlay property. That includes the before-string or
3373 after-string of an overlay, strings in display properties
3374 provided by an overlay, their text properties, etc.
3376 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3377 if (! NILP (from_overlay
))
3378 for (i
= it
->sp
- 1; i
>= 0; i
--)
3380 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3382 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3383 else if (! NILP (it
->stack
[i
].from_overlay
))
3384 from_overlay
= it
->stack
[i
].from_overlay
;
3386 if (!NILP (from_overlay
))
3390 if (! NILP (from_overlay
))
3392 bufpos
= IT_CHARPOS (*it
);
3393 /* For a string from an overlay, the base face depends
3394 only on text properties and ignores overlays. */
3396 = face_for_overlay_string (it
->w
,
3398 it
->region_beg_charpos
,
3399 it
->region_end_charpos
,
3402 + TEXT_PROP_DISTANCE_LIMIT
),
3410 /* For strings from a `display' property, use the face at
3411 IT's current buffer position as the base face to merge
3412 with, so that overlay strings appear in the same face as
3413 surrounding text, unless they specify their own
3415 base_face_id
= underlying_face_id (it
);
3418 new_face_id
= face_at_string_position (it
->w
,
3420 IT_STRING_CHARPOS (*it
),
3422 it
->region_beg_charpos
,
3423 it
->region_end_charpos
,
3427 /* Is this a start of a run of characters with box? Caveat:
3428 this can be called for a freshly allocated iterator; face_id
3429 is -1 is this case. We know that the new face will not
3430 change until the next check pos, i.e. if the new face has a
3431 box, all characters up to that position will have a
3432 box. But, as usual, we don't know whether that position
3433 is really the end. */
3434 if (new_face_id
!= it
->face_id
)
3436 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3437 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3439 /* If new face has a box but old face hasn't, this is the
3440 start of a run of characters with box, i.e. it has a
3441 shadow on the left side. */
3442 it
->start_of_box_run_p
3443 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3444 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3448 it
->face_id
= new_face_id
;
3449 return HANDLED_NORMALLY
;
3453 /* Return the ID of the face ``underlying'' IT's current position,
3454 which is in a string. If the iterator is associated with a
3455 buffer, return the face at IT's current buffer position.
3456 Otherwise, use the iterator's base_face_id. */
3459 underlying_face_id (struct it
*it
)
3461 int face_id
= it
->base_face_id
, i
;
3463 xassert (STRINGP (it
->string
));
3465 for (i
= it
->sp
- 1; i
>= 0; --i
)
3466 if (NILP (it
->stack
[i
].string
))
3467 face_id
= it
->stack
[i
].face_id
;
3473 /* Compute the face one character before or after the current position
3474 of IT, in the visual order. BEFORE_P non-zero means get the face
3475 in front (to the left in L2R paragraphs, to the right in R2L
3476 paragraphs) of IT's screen position. Value is the ID of the face. */
3479 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3482 EMACS_INT next_check_charpos
;
3485 xassert (it
->s
== NULL
);
3487 if (STRINGP (it
->string
))
3489 EMACS_INT bufpos
, charpos
;
3492 /* No face change past the end of the string (for the case
3493 we are padding with spaces). No face change before the
3495 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3496 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3501 /* Set charpos to the position before or after IT's current
3502 position, in the logical order, which in the non-bidi
3503 case is the same as the visual order. */
3505 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3506 else if (it
->what
== IT_COMPOSITION
)
3507 /* For composition, we must check the character after the
3509 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3511 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3517 /* With bidi iteration, the character before the current
3518 in the visual order cannot be found by simple
3519 iteration, because "reverse" reordering is not
3520 supported. Instead, we need to use the move_it_*
3521 family of functions. */
3522 /* Ignore face changes before the first visible
3523 character on this display line. */
3524 if (it
->current_x
<= it
->first_visible_x
)
3527 /* Implementation note: Since move_it_in_display_line
3528 works in the iterator geometry, and thinks the first
3529 character is always the leftmost, even in R2L lines,
3530 we don't need to distinguish between the R2L and L2R
3532 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3533 it_copy
.current_x
- 1, MOVE_TO_X
);
3534 charpos
= IT_STRING_CHARPOS (it_copy
);
3538 /* Set charpos to the string position of the character
3539 that comes after IT's current position in the visual
3541 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3545 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3547 charpos
= it_copy
.bidi_it
.charpos
;
3550 xassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3552 if (it
->current
.overlay_string_index
>= 0)
3553 bufpos
= IT_CHARPOS (*it
);
3557 base_face_id
= underlying_face_id (it
);
3559 /* Get the face for ASCII, or unibyte. */
3560 face_id
= face_at_string_position (it
->w
,
3564 it
->region_beg_charpos
,
3565 it
->region_end_charpos
,
3566 &next_check_charpos
,
3569 /* Correct the face for charsets different from ASCII. Do it
3570 for the multibyte case only. The face returned above is
3571 suitable for unibyte text if IT->string is unibyte. */
3572 if (STRING_MULTIBYTE (it
->string
))
3574 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3575 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3577 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3579 c
= string_char_and_length (p
, &len
);
3580 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3585 struct text_pos pos
;
3587 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3588 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3591 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3592 pos
= it
->current
.pos
;
3597 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3600 if (it
->what
== IT_COMPOSITION
)
3602 /* For composition, we must check the position after
3604 pos
.charpos
+= it
->cmp_it
.nchars
;
3605 pos
.bytepos
+= it
->len
;
3608 INC_TEXT_POS (pos
, it
->multibyte_p
);
3615 /* With bidi iteration, the character before the current
3616 in the visual order cannot be found by simple
3617 iteration, because "reverse" reordering is not
3618 supported. Instead, we need to use the move_it_*
3619 family of functions. */
3620 /* Ignore face changes before the first visible
3621 character on this display line. */
3622 if (it
->current_x
<= it
->first_visible_x
)
3625 /* Implementation note: Since move_it_in_display_line
3626 works in the iterator geometry, and thinks the first
3627 character is always the leftmost, even in R2L lines,
3628 we don't need to distinguish between the R2L and L2R
3630 move_it_in_display_line (&it_copy
, ZV
,
3631 it_copy
.current_x
- 1, MOVE_TO_X
);
3632 pos
= it_copy
.current
.pos
;
3636 /* Set charpos to the buffer position of the character
3637 that comes after IT's current position in the visual
3639 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3643 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3646 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
3649 xassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
3651 /* Determine face for CHARSET_ASCII, or unibyte. */
3652 face_id
= face_at_buffer_position (it
->w
,
3654 it
->region_beg_charpos
,
3655 it
->region_end_charpos
,
3656 &next_check_charpos
,
3659 /* Correct the face for charsets different from ASCII. Do it
3660 for the multibyte case only. The face returned above is
3661 suitable for unibyte text if current_buffer is unibyte. */
3662 if (it
->multibyte_p
)
3664 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3665 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3666 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3675 /***********************************************************************
3677 ***********************************************************************/
3679 /* Set up iterator IT from invisible properties at its current
3680 position. Called from handle_stop. */
3682 static enum prop_handled
3683 handle_invisible_prop (struct it
*it
)
3685 enum prop_handled handled
= HANDLED_NORMALLY
;
3687 if (STRINGP (it
->string
))
3689 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3691 /* Get the value of the invisible text property at the
3692 current position. Value will be nil if there is no such
3694 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3695 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3698 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3702 handled
= HANDLED_RECOMPUTE_PROPS
;
3704 /* Get the position at which the next change of the
3705 invisible text property can be found in IT->string.
3706 Value will be nil if the property value is the same for
3707 all the rest of IT->string. */
3708 XSETINT (limit
, SCHARS (it
->string
));
3709 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3712 /* Text at current position is invisible. The next
3713 change in the property is at position end_charpos.
3714 Move IT's current position to that position. */
3715 if (INTEGERP (end_charpos
)
3716 && (endpos
= XFASTINT (end_charpos
)) < XFASTINT (limit
))
3718 struct text_pos old
;
3721 old
= it
->current
.string_pos
;
3722 oldpos
= CHARPOS (old
);
3725 if (it
->bidi_it
.first_elt
3726 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
3727 bidi_paragraph_init (it
->paragraph_embedding
,
3729 /* Bidi-iterate out of the invisible text. */
3732 bidi_move_to_visually_next (&it
->bidi_it
);
3734 while (oldpos
<= it
->bidi_it
.charpos
3735 && it
->bidi_it
.charpos
< endpos
);
3737 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3738 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3739 if (IT_CHARPOS (*it
) >= endpos
)
3740 it
->prev_stop
= endpos
;
3744 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3745 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3750 /* The rest of the string is invisible. If this is an
3751 overlay string, proceed with the next overlay string
3752 or whatever comes and return a character from there. */
3753 if (it
->current
.overlay_string_index
>= 0)
3755 next_overlay_string (it
);
3756 /* Don't check for overlay strings when we just
3757 finished processing them. */
3758 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3762 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3763 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3771 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
3772 Lisp_Object pos
, prop
, overlay
;
3774 /* First of all, is there invisible text at this position? */
3775 tem
= start_charpos
= IT_CHARPOS (*it
);
3776 pos
= make_number (tem
);
3777 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3779 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3781 /* If we are on invisible text, skip over it. */
3782 if (invis_p
&& start_charpos
< it
->end_charpos
)
3784 /* Record whether we have to display an ellipsis for the
3786 int display_ellipsis_p
= invis_p
== 2;
3788 handled
= HANDLED_RECOMPUTE_PROPS
;
3790 /* Loop skipping over invisible text. The loop is left at
3791 ZV or with IT on the first char being visible again. */
3794 /* Try to skip some invisible text. Return value is the
3795 position reached which can be equal to where we start
3796 if there is nothing invisible there. This skips both
3797 over invisible text properties and overlays with
3798 invisible property. */
3799 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
3801 /* If we skipped nothing at all we weren't at invisible
3802 text in the first place. If everything to the end of
3803 the buffer was skipped, end the loop. */
3804 if (newpos
== tem
|| newpos
>= ZV
)
3808 /* We skipped some characters but not necessarily
3809 all there are. Check if we ended up on visible
3810 text. Fget_char_property returns the property of
3811 the char before the given position, i.e. if we
3812 get invis_p = 0, this means that the char at
3813 newpos is visible. */
3814 pos
= make_number (newpos
);
3815 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3816 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3819 /* If we ended up on invisible text, proceed to
3820 skip starting with next_stop. */
3824 /* If there are adjacent invisible texts, don't lose the
3825 second one's ellipsis. */
3827 display_ellipsis_p
= 1;
3831 /* The position newpos is now either ZV or on visible text. */
3832 if (it
->bidi_p
&& newpos
< ZV
)
3834 /* With bidi iteration, the region of invisible text
3835 could start and/or end in the middle of a non-base
3836 embedding level. Therefore, we need to skip
3837 invisible text using the bidi iterator, starting at
3838 IT's current position, until we find ourselves
3839 outside the invisible text. Skipping invisible text
3840 _after_ bidi iteration avoids affecting the visual
3841 order of the displayed text when invisible properties
3842 are added or removed. */
3843 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
3845 /* If we were `reseat'ed to a new paragraph,
3846 determine the paragraph base direction. We need
3847 to do it now because next_element_from_buffer may
3848 not have a chance to do it, if we are going to
3849 skip any text at the beginning, which resets the
3851 bidi_paragraph_init (it
->paragraph_embedding
,
3856 bidi_move_to_visually_next (&it
->bidi_it
);
3858 while (it
->stop_charpos
<= it
->bidi_it
.charpos
3859 && it
->bidi_it
.charpos
< newpos
);
3860 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3861 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3862 /* If we overstepped NEWPOS, record its position in the
3863 iterator, so that we skip invisible text if later the
3864 bidi iteration lands us in the invisible region
3866 if (IT_CHARPOS (*it
) >= newpos
)
3867 it
->prev_stop
= newpos
;
3871 IT_CHARPOS (*it
) = newpos
;
3872 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3875 /* If there are before-strings at the start of invisible
3876 text, and the text is invisible because of a text
3877 property, arrange to show before-strings because 20.x did
3878 it that way. (If the text is invisible because of an
3879 overlay property instead of a text property, this is
3880 already handled in the overlay code.) */
3882 && get_overlay_strings (it
, it
->stop_charpos
))
3884 handled
= HANDLED_RECOMPUTE_PROPS
;
3885 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3887 else if (display_ellipsis_p
)
3889 /* Make sure that the glyphs of the ellipsis will get
3890 correct `charpos' values. If we would not update
3891 it->position here, the glyphs would belong to the
3892 last visible character _before_ the invisible
3893 text, which confuses `set_cursor_from_row'.
3895 We use the last invisible position instead of the
3896 first because this way the cursor is always drawn on
3897 the first "." of the ellipsis, whenever PT is inside
3898 the invisible text. Otherwise the cursor would be
3899 placed _after_ the ellipsis when the point is after the
3900 first invisible character. */
3901 if (!STRINGP (it
->object
))
3903 it
->position
.charpos
= newpos
- 1;
3904 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3907 /* Let the ellipsis display before
3908 considering any properties of the following char.
3909 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3910 handled
= HANDLED_RETURN
;
3919 /* Make iterator IT return `...' next.
3920 Replaces LEN characters from buffer. */
3923 setup_for_ellipsis (struct it
*it
, int len
)
3925 /* Use the display table definition for `...'. Invalid glyphs
3926 will be handled by the method returning elements from dpvec. */
3927 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3929 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3930 it
->dpvec
= v
->contents
;
3931 it
->dpend
= v
->contents
+ v
->header
.size
;
3935 /* Default `...'. */
3936 it
->dpvec
= default_invis_vector
;
3937 it
->dpend
= default_invis_vector
+ 3;
3940 it
->dpvec_char_len
= len
;
3941 it
->current
.dpvec_index
= 0;
3942 it
->dpvec_face_id
= -1;
3944 /* Remember the current face id in case glyphs specify faces.
3945 IT's face is restored in set_iterator_to_next.
3946 saved_face_id was set to preceding char's face in handle_stop. */
3947 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3948 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3950 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3956 /***********************************************************************
3958 ***********************************************************************/
3960 /* Set up iterator IT from `display' property at its current position.
3961 Called from handle_stop.
3962 We return HANDLED_RETURN if some part of the display property
3963 overrides the display of the buffer text itself.
3964 Otherwise we return HANDLED_NORMALLY. */
3966 static enum prop_handled
3967 handle_display_prop (struct it
*it
)
3969 Lisp_Object propval
, object
, overlay
;
3970 struct text_pos
*position
;
3972 /* Nonzero if some property replaces the display of the text itself. */
3973 int display_replaced_p
= 0;
3975 if (STRINGP (it
->string
))
3977 object
= it
->string
;
3978 position
= &it
->current
.string_pos
;
3979 bufpos
= CHARPOS (it
->current
.pos
);
3983 XSETWINDOW (object
, it
->w
);
3984 position
= &it
->current
.pos
;
3985 bufpos
= CHARPOS (*position
);
3988 /* Reset those iterator values set from display property values. */
3989 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3990 it
->space_width
= Qnil
;
3991 it
->font_height
= Qnil
;
3994 /* We don't support recursive `display' properties, i.e. string
3995 values that have a string `display' property, that have a string
3996 `display' property etc. */
3997 if (!it
->string_from_display_prop_p
)
3998 it
->area
= TEXT_AREA
;
4000 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4001 Qdisplay
, object
, &overlay
);
4003 return HANDLED_NORMALLY
;
4004 /* Now OVERLAY is the overlay that gave us this property, or nil
4005 if it was a text property. */
4007 if (!STRINGP (it
->string
))
4008 object
= it
->w
->buffer
;
4010 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4012 FRAME_WINDOW_P (it
->f
));
4014 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4017 /* Subroutine of handle_display_prop. Returns non-zero if the display
4018 specification in SPEC is a replacing specification, i.e. it would
4019 replace the text covered by `display' property with something else,
4020 such as an image or a display string.
4022 See handle_single_display_spec for documentation of arguments.
4023 frame_window_p is non-zero if the window being redisplayed is on a
4024 GUI frame; this argument is used only if IT is NULL, see below.
4026 IT can be NULL, if this is called by the bidi reordering code
4027 through compute_display_string_pos, which see. In that case, this
4028 function only examines SPEC, but does not otherwise "handle" it, in
4029 the sense that it doesn't set up members of IT from the display
4032 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4033 Lisp_Object overlay
, struct text_pos
*position
,
4034 EMACS_INT bufpos
, int frame_window_p
)
4036 int replacing_p
= 0;
4039 /* Simple specerties. */
4040 && !EQ (XCAR (spec
), Qimage
)
4041 && !EQ (XCAR (spec
), Qspace
)
4042 && !EQ (XCAR (spec
), Qwhen
)
4043 && !EQ (XCAR (spec
), Qslice
)
4044 && !EQ (XCAR (spec
), Qspace_width
)
4045 && !EQ (XCAR (spec
), Qheight
)
4046 && !EQ (XCAR (spec
), Qraise
)
4047 /* Marginal area specifications. */
4048 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4049 && !EQ (XCAR (spec
), Qleft_fringe
)
4050 && !EQ (XCAR (spec
), Qright_fringe
)
4051 && !NILP (XCAR (spec
)))
4053 for (; CONSP (spec
); spec
= XCDR (spec
))
4055 if (handle_single_display_spec (it
, XCAR (spec
), object
, overlay
,
4056 position
, bufpos
, replacing_p
,
4060 /* If some text in a string is replaced, `position' no
4061 longer points to the position of `object'. */
4062 if (!it
|| STRINGP (object
))
4067 else if (VECTORP (spec
))
4070 for (i
= 0; i
< ASIZE (spec
); ++i
)
4071 if (handle_single_display_spec (it
, AREF (spec
, i
), object
, overlay
,
4072 position
, bufpos
, replacing_p
,
4076 /* If some text in a string is replaced, `position' no
4077 longer points to the position of `object'. */
4078 if (!it
|| STRINGP (object
))
4084 if (handle_single_display_spec (it
, spec
, object
, overlay
,
4085 position
, bufpos
, 0, frame_window_p
))
4092 /* Value is the position of the end of the `display' property starting
4093 at START_POS in OBJECT. */
4095 static struct text_pos
4096 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4099 struct text_pos end_pos
;
4101 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4102 Qdisplay
, object
, Qnil
);
4103 CHARPOS (end_pos
) = XFASTINT (end
);
4104 if (STRINGP (object
))
4105 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4107 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4113 /* Set up IT from a single `display' property specification SPEC. OBJECT
4114 is the object in which the `display' property was found. *POSITION
4115 is the position in OBJECT at which the `display' property was found.
4116 BUFPOS is the buffer position of OBJECT (different from POSITION if
4117 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4118 previously saw a display specification which already replaced text
4119 display with something else, for example an image; we ignore such
4120 properties after the first one has been processed.
4122 OVERLAY is the overlay this `display' property came from,
4123 or nil if it was a text property.
4125 If SPEC is a `space' or `image' specification, and in some other
4126 cases too, set *POSITION to the position where the `display'
4129 If IT is NULL, only examine the property specification in SPEC, but
4130 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4131 is intended to be displayed in a window on a GUI frame.
4133 Value is non-zero if something was found which replaces the display
4134 of buffer or string text. */
4137 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4138 Lisp_Object overlay
, struct text_pos
*position
,
4139 EMACS_INT bufpos
, int display_replaced_p
,
4143 Lisp_Object location
, value
;
4144 struct text_pos start_pos
= *position
;
4147 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4148 If the result is non-nil, use VALUE instead of SPEC. */
4150 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4159 if (!NILP (form
) && !EQ (form
, Qt
))
4161 int count
= SPECPDL_INDEX ();
4162 struct gcpro gcpro1
;
4164 /* Bind `object' to the object having the `display' property, a
4165 buffer or string. Bind `position' to the position in the
4166 object where the property was found, and `buffer-position'
4167 to the current position in the buffer. */
4170 XSETBUFFER (object
, current_buffer
);
4171 specbind (Qobject
, object
);
4172 specbind (Qposition
, make_number (CHARPOS (*position
)));
4173 specbind (Qbuffer_position
, make_number (bufpos
));
4175 form
= safe_eval (form
);
4177 unbind_to (count
, Qnil
);
4183 /* Handle `(height HEIGHT)' specifications. */
4185 && EQ (XCAR (spec
), Qheight
)
4186 && CONSP (XCDR (spec
)))
4190 if (!FRAME_WINDOW_P (it
->f
))
4193 it
->font_height
= XCAR (XCDR (spec
));
4194 if (!NILP (it
->font_height
))
4196 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4197 int new_height
= -1;
4199 if (CONSP (it
->font_height
)
4200 && (EQ (XCAR (it
->font_height
), Qplus
)
4201 || EQ (XCAR (it
->font_height
), Qminus
))
4202 && CONSP (XCDR (it
->font_height
))
4203 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4205 /* `(+ N)' or `(- N)' where N is an integer. */
4206 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4207 if (EQ (XCAR (it
->font_height
), Qplus
))
4209 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4211 else if (FUNCTIONP (it
->font_height
))
4213 /* Call function with current height as argument.
4214 Value is the new height. */
4216 height
= safe_call1 (it
->font_height
,
4217 face
->lface
[LFACE_HEIGHT_INDEX
]);
4218 if (NUMBERP (height
))
4219 new_height
= XFLOATINT (height
);
4221 else if (NUMBERP (it
->font_height
))
4223 /* Value is a multiple of the canonical char height. */
4226 f
= FACE_FROM_ID (it
->f
,
4227 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4228 new_height
= (XFLOATINT (it
->font_height
)
4229 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4233 /* Evaluate IT->font_height with `height' bound to the
4234 current specified height to get the new height. */
4235 int count
= SPECPDL_INDEX ();
4237 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4238 value
= safe_eval (it
->font_height
);
4239 unbind_to (count
, Qnil
);
4241 if (NUMBERP (value
))
4242 new_height
= XFLOATINT (value
);
4246 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4253 /* Handle `(space-width WIDTH)'. */
4255 && EQ (XCAR (spec
), Qspace_width
)
4256 && CONSP (XCDR (spec
)))
4260 if (!FRAME_WINDOW_P (it
->f
))
4263 value
= XCAR (XCDR (spec
));
4264 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4265 it
->space_width
= value
;
4271 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4273 && EQ (XCAR (spec
), Qslice
))
4279 if (!FRAME_WINDOW_P (it
->f
))
4282 if (tem
= XCDR (spec
), CONSP (tem
))
4284 it
->slice
.x
= XCAR (tem
);
4285 if (tem
= XCDR (tem
), CONSP (tem
))
4287 it
->slice
.y
= XCAR (tem
);
4288 if (tem
= XCDR (tem
), CONSP (tem
))
4290 it
->slice
.width
= XCAR (tem
);
4291 if (tem
= XCDR (tem
), CONSP (tem
))
4292 it
->slice
.height
= XCAR (tem
);
4301 /* Handle `(raise FACTOR)'. */
4303 && EQ (XCAR (spec
), Qraise
)
4304 && CONSP (XCDR (spec
)))
4308 if (!FRAME_WINDOW_P (it
->f
))
4311 #ifdef HAVE_WINDOW_SYSTEM
4312 value
= XCAR (XCDR (spec
));
4313 if (NUMBERP (value
))
4315 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4316 it
->voffset
= - (XFLOATINT (value
)
4317 * (FONT_HEIGHT (face
->font
)));
4319 #endif /* HAVE_WINDOW_SYSTEM */
4325 /* Don't handle the other kinds of display specifications
4326 inside a string that we got from a `display' property. */
4327 if (it
&& it
->string_from_display_prop_p
)
4330 /* Characters having this form of property are not displayed, so
4331 we have to find the end of the property. */
4334 start_pos
= *position
;
4335 *position
= display_prop_end (it
, object
, start_pos
);
4339 /* Stop the scan at that end position--we assume that all
4340 text properties change there. */
4342 it
->stop_charpos
= position
->charpos
;
4344 /* Handle `(left-fringe BITMAP [FACE])'
4345 and `(right-fringe BITMAP [FACE])'. */
4347 && (EQ (XCAR (spec
), Qleft_fringe
)
4348 || EQ (XCAR (spec
), Qright_fringe
))
4349 && CONSP (XCDR (spec
)))
4355 if (!FRAME_WINDOW_P (it
->f
))
4356 /* If we return here, POSITION has been advanced
4357 across the text with this property. */
4360 else if (!frame_window_p
)
4363 #ifdef HAVE_WINDOW_SYSTEM
4364 value
= XCAR (XCDR (spec
));
4365 if (!SYMBOLP (value
)
4366 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4367 /* If we return here, POSITION has been advanced
4368 across the text with this property. */
4373 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4375 if (CONSP (XCDR (XCDR (spec
))))
4377 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4378 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4384 /* Save current settings of IT so that we can restore them
4385 when we are finished with the glyph property value. */
4386 push_it (it
, position
);
4388 it
->area
= TEXT_AREA
;
4389 it
->what
= IT_IMAGE
;
4390 it
->image_id
= -1; /* no image */
4391 it
->position
= start_pos
;
4392 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4393 it
->method
= GET_FROM_IMAGE
;
4394 it
->from_overlay
= Qnil
;
4395 it
->face_id
= face_id
;
4397 /* Say that we haven't consumed the characters with
4398 `display' property yet. The call to pop_it in
4399 set_iterator_to_next will clean this up. */
4400 *position
= start_pos
;
4402 if (EQ (XCAR (spec
), Qleft_fringe
))
4404 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4405 it
->left_user_fringe_face_id
= face_id
;
4409 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4410 it
->right_user_fringe_face_id
= face_id
;
4413 #endif /* HAVE_WINDOW_SYSTEM */
4417 /* Prepare to handle `((margin left-margin) ...)',
4418 `((margin right-margin) ...)' and `((margin nil) ...)'
4419 prefixes for display specifications. */
4420 location
= Qunbound
;
4421 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4425 value
= XCDR (spec
);
4427 value
= XCAR (value
);
4430 if (EQ (XCAR (tem
), Qmargin
)
4431 && (tem
= XCDR (tem
),
4432 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4434 || EQ (tem
, Qleft_margin
)
4435 || EQ (tem
, Qright_margin
))))
4439 if (EQ (location
, Qunbound
))
4445 /* After this point, VALUE is the property after any
4446 margin prefix has been stripped. It must be a string,
4447 an image specification, or `(space ...)'.
4449 LOCATION specifies where to display: `left-margin',
4450 `right-margin' or nil. */
4452 valid_p
= (STRINGP (value
)
4453 #ifdef HAVE_WINDOW_SYSTEM
4454 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4455 && valid_image_p (value
))
4456 #endif /* not HAVE_WINDOW_SYSTEM */
4457 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4459 if (valid_p
&& !display_replaced_p
)
4464 /* Save current settings of IT so that we can restore them
4465 when we are finished with the glyph property value. */
4466 push_it (it
, position
);
4467 it
->from_overlay
= overlay
;
4469 if (NILP (location
))
4470 it
->area
= TEXT_AREA
;
4471 else if (EQ (location
, Qleft_margin
))
4472 it
->area
= LEFT_MARGIN_AREA
;
4474 it
->area
= RIGHT_MARGIN_AREA
;
4476 if (STRINGP (value
))
4479 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4480 it
->current
.overlay_string_index
= -1;
4481 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4482 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4483 it
->method
= GET_FROM_STRING
;
4484 it
->stop_charpos
= 0;
4486 it
->base_level_stop
= 0;
4487 it
->string_from_display_prop_p
= 1;
4488 /* Say that we haven't consumed the characters with
4489 `display' property yet. The call to pop_it in
4490 set_iterator_to_next will clean this up. */
4491 if (BUFFERP (object
))
4492 *position
= start_pos
;
4494 /* Force paragraph direction to be that of the parent
4496 it
->paragraph_embedding
=
4497 (it
->bidi_p
? it
->bidi_it
.paragraph_dir
: L2R
);
4499 /* Do we need to reorder this display string? */
4500 if (it
->multibyte_p
)
4502 if (BUFFERP (object
))
4504 !NILP (BVAR (XBUFFER (object
), bidi_display_reordering
));
4507 !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
4512 /* Set up the bidi iterator for this display string. */
4515 it
->bidi_it
.string
.lstring
= it
->string
;
4516 it
->bidi_it
.string
.s
= NULL
;
4517 it
->bidi_it
.string
.schars
= it
->end_charpos
;
4518 it
->bidi_it
.string
.bufpos
= bufpos
;
4519 it
->bidi_it
.string
.from_disp_str
= 1;
4520 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4523 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4525 it
->method
= GET_FROM_STRETCH
;
4527 *position
= it
->position
= start_pos
;
4529 #ifdef HAVE_WINDOW_SYSTEM
4532 it
->what
= IT_IMAGE
;
4533 it
->image_id
= lookup_image (it
->f
, value
);
4534 it
->position
= start_pos
;
4535 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4536 it
->method
= GET_FROM_IMAGE
;
4538 /* Say that we haven't consumed the characters with
4539 `display' property yet. The call to pop_it in
4540 set_iterator_to_next will clean this up. */
4541 *position
= start_pos
;
4543 #endif /* HAVE_WINDOW_SYSTEM */
4548 /* Invalid property or property not supported. Restore
4549 POSITION to what it was before. */
4550 *position
= start_pos
;
4554 /* Check if PROP is a display property value whose text should be
4555 treated as intangible. OVERLAY is the overlay from which PROP
4556 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4557 specify the buffer position covered by PROP. */
4560 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4561 EMACS_INT charpos
, EMACS_INT bytepos
)
4563 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4564 struct text_pos position
;
4566 SET_TEXT_POS (position
, charpos
, bytepos
);
4567 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4568 &position
, charpos
, frame_window_p
);
4572 /* Return 1 if PROP is a display sub-property value containing STRING.
4574 Implementation note: this and the following function are really
4575 special cases of handle_display_spec and
4576 handle_single_display_spec, and should ideally use the same code.
4577 Until they do, these two pairs must be consistent and must be
4578 modified in sync. */
4581 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4583 if (EQ (string
, prop
))
4586 /* Skip over `when FORM'. */
4587 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4592 /* Actually, the condition following `when' should be eval'ed,
4593 like handle_single_display_spec does, and we should return
4594 zero if it evaluates to nil. However, this function is
4595 called only when the buffer was already displayed and some
4596 glyph in the glyph matrix was found to come from a display
4597 string. Therefore, the condition was already evaluated, and
4598 the result was non-nil, otherwise the display string wouldn't
4599 have been displayed and we would have never been called for
4600 this property. Thus, we can skip the evaluation and assume
4601 its result is non-nil. */
4606 /* Skip over `margin LOCATION'. */
4607 if (EQ (XCAR (prop
), Qmargin
))
4618 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
4622 /* Return 1 if STRING appears in the `display' property PROP. */
4625 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4628 && !EQ (XCAR (prop
), Qwhen
)
4629 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
4631 /* A list of sub-properties. */
4632 while (CONSP (prop
))
4634 if (single_display_spec_string_p (XCAR (prop
), string
))
4639 else if (VECTORP (prop
))
4641 /* A vector of sub-properties. */
4643 for (i
= 0; i
< ASIZE (prop
); ++i
)
4644 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4648 return single_display_spec_string_p (prop
, string
);
4653 /* Look for STRING in overlays and text properties in the current
4654 buffer, between character positions FROM and TO (excluding TO).
4655 BACK_P non-zero means look back (in this case, TO is supposed to be
4657 Value is the first character position where STRING was found, or
4658 zero if it wasn't found before hitting TO.
4660 This function may only use code that doesn't eval because it is
4661 called asynchronously from note_mouse_highlight. */
4664 string_buffer_position_lim (Lisp_Object string
,
4665 EMACS_INT from
, EMACS_INT to
, int back_p
)
4667 Lisp_Object limit
, prop
, pos
;
4670 pos
= make_number (from
);
4672 if (!back_p
) /* looking forward */
4674 limit
= make_number (min (to
, ZV
));
4675 while (!found
&& !EQ (pos
, limit
))
4677 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4678 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4681 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4685 else /* looking back */
4687 limit
= make_number (max (to
, BEGV
));
4688 while (!found
&& !EQ (pos
, limit
))
4690 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4691 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4694 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4699 return found
? XINT (pos
) : 0;
4702 /* Determine which buffer position in current buffer STRING comes from.
4703 AROUND_CHARPOS is an approximate position where it could come from.
4704 Value is the buffer position or 0 if it couldn't be determined.
4706 This function is necessary because we don't record buffer positions
4707 in glyphs generated from strings (to keep struct glyph small).
4708 This function may only use code that doesn't eval because it is
4709 called asynchronously from note_mouse_highlight. */
4712 string_buffer_position (Lisp_Object string
, EMACS_INT around_charpos
)
4714 const int MAX_DISTANCE
= 1000;
4715 EMACS_INT found
= string_buffer_position_lim (string
, around_charpos
,
4716 around_charpos
+ MAX_DISTANCE
,
4720 found
= string_buffer_position_lim (string
, around_charpos
,
4721 around_charpos
- MAX_DISTANCE
, 1);
4727 /***********************************************************************
4728 `composition' property
4729 ***********************************************************************/
4731 /* Set up iterator IT from `composition' property at its current
4732 position. Called from handle_stop. */
4734 static enum prop_handled
4735 handle_composition_prop (struct it
*it
)
4737 Lisp_Object prop
, string
;
4738 EMACS_INT pos
, pos_byte
, start
, end
;
4740 if (STRINGP (it
->string
))
4744 pos
= IT_STRING_CHARPOS (*it
);
4745 pos_byte
= IT_STRING_BYTEPOS (*it
);
4746 string
= it
->string
;
4747 s
= SDATA (string
) + pos_byte
;
4748 it
->c
= STRING_CHAR (s
);
4752 pos
= IT_CHARPOS (*it
);
4753 pos_byte
= IT_BYTEPOS (*it
);
4755 it
->c
= FETCH_CHAR (pos_byte
);
4758 /* If there's a valid composition and point is not inside of the
4759 composition (in the case that the composition is from the current
4760 buffer), draw a glyph composed from the composition components. */
4761 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4762 && COMPOSITION_VALID_P (start
, end
, prop
)
4763 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4767 if (STRINGP (it
->string
))
4768 pos_byte
= string_char_to_byte (it
->string
, start
);
4770 pos_byte
= CHAR_TO_BYTE (start
);
4772 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4775 if (it
->cmp_it
.id
>= 0)
4778 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4779 it
->cmp_it
.nglyphs
= -1;
4783 return HANDLED_NORMALLY
;
4788 /***********************************************************************
4790 ***********************************************************************/
4792 /* The following structure is used to record overlay strings for
4793 later sorting in load_overlay_strings. */
4795 struct overlay_entry
4797 Lisp_Object overlay
;
4804 /* Set up iterator IT from overlay strings at its current position.
4805 Called from handle_stop. */
4807 static enum prop_handled
4808 handle_overlay_change (struct it
*it
)
4810 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4811 return HANDLED_RECOMPUTE_PROPS
;
4813 return HANDLED_NORMALLY
;
4817 /* Set up the next overlay string for delivery by IT, if there is an
4818 overlay string to deliver. Called by set_iterator_to_next when the
4819 end of the current overlay string is reached. If there are more
4820 overlay strings to display, IT->string and
4821 IT->current.overlay_string_index are set appropriately here.
4822 Otherwise IT->string is set to nil. */
4825 next_overlay_string (struct it
*it
)
4827 ++it
->current
.overlay_string_index
;
4828 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4830 /* No more overlay strings. Restore IT's settings to what
4831 they were before overlay strings were processed, and
4832 continue to deliver from current_buffer. */
4834 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4837 || (NILP (it
->string
)
4838 && it
->method
== GET_FROM_BUFFER
4839 && it
->stop_charpos
>= BEGV
4840 && it
->stop_charpos
<= it
->end_charpos
));
4841 it
->current
.overlay_string_index
= -1;
4842 it
->n_overlay_strings
= 0;
4843 it
->overlay_strings_charpos
= -1;
4845 /* If we're at the end of the buffer, record that we have
4846 processed the overlay strings there already, so that
4847 next_element_from_buffer doesn't try it again. */
4848 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4849 it
->overlay_strings_at_end_processed_p
= 1;
4853 /* There are more overlay strings to process. If
4854 IT->current.overlay_string_index has advanced to a position
4855 where we must load IT->overlay_strings with more strings, do
4856 it. We must load at the IT->overlay_strings_charpos where
4857 IT->n_overlay_strings was originally computed; when invisible
4858 text is present, this might not be IT_CHARPOS (Bug#7016). */
4859 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4861 if (it
->current
.overlay_string_index
&& i
== 0)
4862 load_overlay_strings (it
, it
->overlay_strings_charpos
);
4864 /* Initialize IT to deliver display elements from the overlay
4866 it
->string
= it
->overlay_strings
[i
];
4867 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4868 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4869 it
->method
= GET_FROM_STRING
;
4870 it
->stop_charpos
= 0;
4871 if (it
->cmp_it
.stop_pos
>= 0)
4872 it
->cmp_it
.stop_pos
= 0;
4874 it
->base_level_stop
= 0;
4876 /* Do we need to reorder this overlay string? */
4879 && !NILP (BVAR (current_buffer
, bidi_display_reordering
));
4881 /* Set up the bidi iterator for this overlay string. */
4884 it
->bidi_it
.string
.lstring
= it
->string
;
4885 it
->bidi_it
.string
.s
= NULL
;
4886 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
4887 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
4888 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
4889 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4897 /* Compare two overlay_entry structures E1 and E2. Used as a
4898 comparison function for qsort in load_overlay_strings. Overlay
4899 strings for the same position are sorted so that
4901 1. All after-strings come in front of before-strings, except
4902 when they come from the same overlay.
4904 2. Within after-strings, strings are sorted so that overlay strings
4905 from overlays with higher priorities come first.
4907 2. Within before-strings, strings are sorted so that overlay
4908 strings from overlays with higher priorities come last.
4910 Value is analogous to strcmp. */
4914 compare_overlay_entries (const void *e1
, const void *e2
)
4916 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4917 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4920 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4922 /* Let after-strings appear in front of before-strings if
4923 they come from different overlays. */
4924 if (EQ (entry1
->overlay
, entry2
->overlay
))
4925 result
= entry1
->after_string_p
? 1 : -1;
4927 result
= entry1
->after_string_p
? -1 : 1;
4929 else if (entry1
->after_string_p
)
4930 /* After-strings sorted in order of decreasing priority. */
4931 result
= entry2
->priority
- entry1
->priority
;
4933 /* Before-strings sorted in order of increasing priority. */
4934 result
= entry1
->priority
- entry2
->priority
;
4940 /* Load the vector IT->overlay_strings with overlay strings from IT's
4941 current buffer position, or from CHARPOS if that is > 0. Set
4942 IT->n_overlays to the total number of overlay strings found.
4944 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4945 a time. On entry into load_overlay_strings,
4946 IT->current.overlay_string_index gives the number of overlay
4947 strings that have already been loaded by previous calls to this
4950 IT->add_overlay_start contains an additional overlay start
4951 position to consider for taking overlay strings from, if non-zero.
4952 This position comes into play when the overlay has an `invisible'
4953 property, and both before and after-strings. When we've skipped to
4954 the end of the overlay, because of its `invisible' property, we
4955 nevertheless want its before-string to appear.
4956 IT->add_overlay_start will contain the overlay start position
4959 Overlay strings are sorted so that after-string strings come in
4960 front of before-string strings. Within before and after-strings,
4961 strings are sorted by overlay priority. See also function
4962 compare_overlay_entries. */
4965 load_overlay_strings (struct it
*it
, EMACS_INT charpos
)
4967 Lisp_Object overlay
, window
, str
, invisible
;
4968 struct Lisp_Overlay
*ov
;
4969 EMACS_INT start
, end
;
4971 int n
= 0, i
, j
, invis_p
;
4972 struct overlay_entry
*entries
4973 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4976 charpos
= IT_CHARPOS (*it
);
4978 /* Append the overlay string STRING of overlay OVERLAY to vector
4979 `entries' which has size `size' and currently contains `n'
4980 elements. AFTER_P non-zero means STRING is an after-string of
4982 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4985 Lisp_Object priority; \
4989 int new_size = 2 * size; \
4990 struct overlay_entry *old = entries; \
4992 (struct overlay_entry *) alloca (new_size \
4993 * sizeof *entries); \
4994 memcpy (entries, old, size * sizeof *entries); \
4998 entries[n].string = (STRING); \
4999 entries[n].overlay = (OVERLAY); \
5000 priority = Foverlay_get ((OVERLAY), Qpriority); \
5001 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5002 entries[n].after_string_p = (AFTER_P); \
5007 /* Process overlay before the overlay center. */
5008 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5010 XSETMISC (overlay
, ov
);
5011 xassert (OVERLAYP (overlay
));
5012 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5013 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5018 /* Skip this overlay if it doesn't start or end at IT's current
5020 if (end
!= charpos
&& start
!= charpos
)
5023 /* Skip this overlay if it doesn't apply to IT->w. */
5024 window
= Foverlay_get (overlay
, Qwindow
);
5025 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5028 /* If the text ``under'' the overlay is invisible, both before-
5029 and after-strings from this overlay are visible; start and
5030 end position are indistinguishable. */
5031 invisible
= Foverlay_get (overlay
, Qinvisible
);
5032 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5034 /* If overlay has a non-empty before-string, record it. */
5035 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5036 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5038 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5040 /* If overlay has a non-empty after-string, record it. */
5041 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5042 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5044 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5047 /* Process overlays after the overlay center. */
5048 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5050 XSETMISC (overlay
, ov
);
5051 xassert (OVERLAYP (overlay
));
5052 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5053 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5055 if (start
> charpos
)
5058 /* Skip this overlay if it doesn't start or end at IT's current
5060 if (end
!= charpos
&& start
!= charpos
)
5063 /* Skip this overlay if it doesn't apply to IT->w. */
5064 window
= Foverlay_get (overlay
, Qwindow
);
5065 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5068 /* If the text ``under'' the overlay is invisible, it has a zero
5069 dimension, and both before- and after-strings apply. */
5070 invisible
= Foverlay_get (overlay
, Qinvisible
);
5071 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5073 /* If overlay has a non-empty before-string, record it. */
5074 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5075 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5077 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5079 /* If overlay has a non-empty after-string, record it. */
5080 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5081 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5083 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5086 #undef RECORD_OVERLAY_STRING
5090 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5092 /* Record number of overlay strings, and where we computed it. */
5093 it
->n_overlay_strings
= n
;
5094 it
->overlay_strings_charpos
= charpos
;
5096 /* IT->current.overlay_string_index is the number of overlay strings
5097 that have already been consumed by IT. Copy some of the
5098 remaining overlay strings to IT->overlay_strings. */
5100 j
= it
->current
.overlay_string_index
;
5101 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5103 it
->overlay_strings
[i
] = entries
[j
].string
;
5104 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5111 /* Get the first chunk of overlay strings at IT's current buffer
5112 position, or at CHARPOS if that is > 0. Value is non-zero if at
5113 least one overlay string was found. */
5116 get_overlay_strings_1 (struct it
*it
, EMACS_INT charpos
, int compute_stop_p
)
5118 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5119 process. This fills IT->overlay_strings with strings, and sets
5120 IT->n_overlay_strings to the total number of strings to process.
5121 IT->pos.overlay_string_index has to be set temporarily to zero
5122 because load_overlay_strings needs this; it must be set to -1
5123 when no overlay strings are found because a zero value would
5124 indicate a position in the first overlay string. */
5125 it
->current
.overlay_string_index
= 0;
5126 load_overlay_strings (it
, charpos
);
5128 /* If we found overlay strings, set up IT to deliver display
5129 elements from the first one. Otherwise set up IT to deliver
5130 from current_buffer. */
5131 if (it
->n_overlay_strings
)
5133 /* Make sure we know settings in current_buffer, so that we can
5134 restore meaningful values when we're done with the overlay
5137 compute_stop_pos (it
);
5138 xassert (it
->face_id
>= 0);
5140 /* Save IT's settings. They are restored after all overlay
5141 strings have been processed. */
5142 xassert (!compute_stop_p
|| it
->sp
== 0);
5144 /* When called from handle_stop, there might be an empty display
5145 string loaded. In that case, don't bother saving it. */
5146 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5149 /* Set up IT to deliver display elements from the first overlay
5151 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5152 it
->string
= it
->overlay_strings
[0];
5153 it
->from_overlay
= Qnil
;
5154 it
->stop_charpos
= 0;
5155 xassert (STRINGP (it
->string
));
5156 it
->end_charpos
= SCHARS (it
->string
);
5158 it
->base_level_stop
= 0;
5159 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5160 it
->method
= GET_FROM_STRING
;
5162 /* Do we need to reorder this overlay string? */
5165 && !NILP (BVAR (current_buffer
, bidi_display_reordering
));
5167 /* Force paragraph direction to be that of the parent
5169 it
->paragraph_embedding
= (it
->bidi_p
? it
->bidi_it
.paragraph_dir
: L2R
);
5171 /* Set up the bidi iterator for this overlay string. */
5174 EMACS_INT pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5176 it
->bidi_it
.string
.lstring
= it
->string
;
5177 it
->bidi_it
.string
.s
= NULL
;
5178 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5179 it
->bidi_it
.string
.bufpos
= pos
;
5180 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5181 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5186 it
->current
.overlay_string_index
= -1;
5191 get_overlay_strings (struct it
*it
, EMACS_INT charpos
)
5194 it
->method
= GET_FROM_BUFFER
;
5196 (void) get_overlay_strings_1 (it
, charpos
, 1);
5200 /* Value is non-zero if we found at least one overlay string. */
5201 return STRINGP (it
->string
);
5206 /***********************************************************************
5207 Saving and restoring state
5208 ***********************************************************************/
5210 /* Save current settings of IT on IT->stack. Called, for example,
5211 before setting up IT for an overlay string, to be able to restore
5212 IT's settings to what they were after the overlay string has been
5213 processed. If POSITION is non-NULL, it is the position to save on
5214 the stack instead of IT->position. */
5217 push_it (struct it
*it
, struct text_pos
*position
)
5219 struct iterator_stack_entry
*p
;
5221 xassert (it
->sp
< IT_STACK_SIZE
);
5222 p
= it
->stack
+ it
->sp
;
5224 p
->stop_charpos
= it
->stop_charpos
;
5225 p
->prev_stop
= it
->prev_stop
;
5226 p
->base_level_stop
= it
->base_level_stop
;
5227 p
->cmp_it
= it
->cmp_it
;
5228 xassert (it
->face_id
>= 0);
5229 p
->face_id
= it
->face_id
;
5230 p
->string
= it
->string
;
5231 p
->method
= it
->method
;
5232 p
->from_overlay
= it
->from_overlay
;
5235 case GET_FROM_IMAGE
:
5236 p
->u
.image
.object
= it
->object
;
5237 p
->u
.image
.image_id
= it
->image_id
;
5238 p
->u
.image
.slice
= it
->slice
;
5240 case GET_FROM_STRETCH
:
5241 p
->u
.stretch
.object
= it
->object
;
5244 p
->position
= position
? *position
: it
->position
;
5245 p
->current
= it
->current
;
5246 p
->end_charpos
= it
->end_charpos
;
5247 p
->string_nchars
= it
->string_nchars
;
5249 p
->multibyte_p
= it
->multibyte_p
;
5250 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5251 p
->space_width
= it
->space_width
;
5252 p
->font_height
= it
->font_height
;
5253 p
->voffset
= it
->voffset
;
5254 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5255 p
->display_ellipsis_p
= 0;
5256 p
->line_wrap
= it
->line_wrap
;
5257 p
->bidi_p
= it
->bidi_p
;
5260 /* Save the state of the bidi iterator as well. */
5262 bidi_push_it (&it
->bidi_it
);
5266 iterate_out_of_display_property (struct it
*it
)
5268 int buffer_p
= BUFFERP (it
->object
);
5269 EMACS_INT eob
= (buffer_p
? ZV
: it
->end_charpos
);
5270 EMACS_INT bob
= (buffer_p
? BEGV
: 0);
5272 /* Maybe initialize paragraph direction. If we are at the beginning
5273 of a new paragraph, next_element_from_buffer may not have a
5274 chance to do that. */
5275 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5276 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5277 /* prev_stop can be zero, so check against BEGV as well. */
5278 while (it
->bidi_it
.charpos
>= bob
5279 && it
->prev_stop
<= it
->bidi_it
.charpos
5280 && it
->bidi_it
.charpos
< CHARPOS (it
->position
))
5281 bidi_move_to_visually_next (&it
->bidi_it
);
5282 /* Record the stop_pos we just crossed, for when we cross it
5284 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5285 it
->prev_stop
= CHARPOS (it
->position
);
5286 /* If we ended up not where pop_it put us, resync IT's
5287 positional members with the bidi iterator. */
5288 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5290 SET_TEXT_POS (it
->position
,
5291 it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5293 it
->current
.pos
= it
->position
;
5295 it
->current
.string_pos
= it
->position
;
5299 /* Restore IT's settings from IT->stack. Called, for example, when no
5300 more overlay strings must be processed, and we return to delivering
5301 display elements from a buffer, or when the end of a string from a
5302 `display' property is reached and we return to delivering display
5303 elements from an overlay string, or from a buffer. */
5306 pop_it (struct it
*it
)
5308 struct iterator_stack_entry
*p
;
5310 xassert (it
->sp
> 0);
5312 p
= it
->stack
+ it
->sp
;
5313 it
->stop_charpos
= p
->stop_charpos
;
5314 it
->prev_stop
= p
->prev_stop
;
5315 it
->base_level_stop
= p
->base_level_stop
;
5316 it
->cmp_it
= p
->cmp_it
;
5317 it
->face_id
= p
->face_id
;
5318 it
->current
= p
->current
;
5319 it
->position
= p
->position
;
5320 it
->string
= p
->string
;
5321 it
->from_overlay
= p
->from_overlay
;
5322 if (NILP (it
->string
))
5323 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5324 it
->method
= p
->method
;
5327 case GET_FROM_IMAGE
:
5328 it
->image_id
= p
->u
.image
.image_id
;
5329 it
->object
= p
->u
.image
.object
;
5330 it
->slice
= p
->u
.image
.slice
;
5332 case GET_FROM_STRETCH
:
5333 it
->object
= p
->u
.comp
.object
;
5335 case GET_FROM_BUFFER
:
5336 it
->object
= it
->w
->buffer
;
5338 case GET_FROM_STRING
:
5339 it
->object
= it
->string
;
5341 case GET_FROM_DISPLAY_VECTOR
:
5343 it
->method
= GET_FROM_C_STRING
;
5344 else if (STRINGP (it
->string
))
5345 it
->method
= GET_FROM_STRING
;
5348 it
->method
= GET_FROM_BUFFER
;
5349 it
->object
= it
->w
->buffer
;
5352 it
->end_charpos
= p
->end_charpos
;
5353 it
->string_nchars
= p
->string_nchars
;
5355 it
->multibyte_p
= p
->multibyte_p
;
5356 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5357 it
->space_width
= p
->space_width
;
5358 it
->font_height
= p
->font_height
;
5359 it
->voffset
= p
->voffset
;
5360 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5361 it
->line_wrap
= p
->line_wrap
;
5362 it
->bidi_p
= p
->bidi_p
;
5365 bidi_pop_it (&it
->bidi_it
);
5366 /* Bidi-iterate until we get out of the portion of text, if any,
5367 covered by a `display' text property or by an overlay with
5368 `display' property. (We cannot just jump there, because the
5369 internal coherency of the bidi iterator state can not be
5370 preserved across such jumps.) We also must determine the
5371 paragraph base direction if the overlay we just processed is
5372 at the beginning of a new paragraph. */
5373 if (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
)
5374 iterate_out_of_display_property (it
);
5380 /***********************************************************************
5382 ***********************************************************************/
5384 /* Set IT's current position to the previous line start. */
5387 back_to_previous_line_start (struct it
*it
)
5389 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5390 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5394 /* Move IT to the next line start.
5396 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5397 we skipped over part of the text (as opposed to moving the iterator
5398 continuously over the text). Otherwise, don't change the value
5401 Newlines may come from buffer text, overlay strings, or strings
5402 displayed via the `display' property. That's the reason we can't
5403 simply use find_next_newline_no_quit.
5405 Note that this function may not skip over invisible text that is so
5406 because of text properties and immediately follows a newline. If
5407 it would, function reseat_at_next_visible_line_start, when called
5408 from set_iterator_to_next, would effectively make invisible
5409 characters following a newline part of the wrong glyph row, which
5410 leads to wrong cursor motion. */
5413 forward_to_next_line_start (struct it
*it
, int *skipped_p
)
5415 int old_selective
, newline_found_p
, n
;
5416 const int MAX_NEWLINE_DISTANCE
= 500;
5418 /* If already on a newline, just consume it to avoid unintended
5419 skipping over invisible text below. */
5420 if (it
->what
== IT_CHARACTER
5422 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5424 set_iterator_to_next (it
, 0);
5429 /* Don't handle selective display in the following. It's (a)
5430 unnecessary because it's done by the caller, and (b) leads to an
5431 infinite recursion because next_element_from_ellipsis indirectly
5432 calls this function. */
5433 old_selective
= it
->selective
;
5436 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5437 from buffer text. */
5438 for (n
= newline_found_p
= 0;
5439 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5440 n
+= STRINGP (it
->string
) ? 0 : 1)
5442 if (!get_next_display_element (it
))
5444 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5445 set_iterator_to_next (it
, 0);
5448 /* If we didn't find a newline near enough, see if we can use a
5450 if (!newline_found_p
)
5452 EMACS_INT start
= IT_CHARPOS (*it
);
5453 EMACS_INT limit
= find_next_newline_no_quit (start
, 1);
5456 xassert (!STRINGP (it
->string
));
5458 /* If we are not bidi-reordering, and there isn't any `display'
5459 property in sight, and no overlays, we can just use the
5460 position of the newline in buffer text. */
5462 && (it
->stop_charpos
>= limit
5463 || ((pos
= Fnext_single_property_change (make_number (start
),
5465 make_number (limit
)),
5467 && next_overlay_change (start
) == ZV
)))
5469 IT_CHARPOS (*it
) = limit
;
5470 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5471 *skipped_p
= newline_found_p
= 1;
5475 while (get_next_display_element (it
)
5476 && !newline_found_p
)
5478 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5479 set_iterator_to_next (it
, 0);
5484 it
->selective
= old_selective
;
5485 return newline_found_p
;
5489 /* Set IT's current position to the previous visible line start. Skip
5490 invisible text that is so either due to text properties or due to
5491 selective display. Caution: this does not change IT->current_x and
5495 back_to_previous_visible_line_start (struct it
*it
)
5497 while (IT_CHARPOS (*it
) > BEGV
)
5499 back_to_previous_line_start (it
);
5501 if (IT_CHARPOS (*it
) <= BEGV
)
5504 /* If selective > 0, then lines indented more than its value are
5506 if (it
->selective
> 0
5507 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5508 (double) it
->selective
)) /* iftc */
5511 /* Check the newline before point for invisibility. */
5514 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5515 Qinvisible
, it
->window
);
5516 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5520 if (IT_CHARPOS (*it
) <= BEGV
)
5527 Lisp_Object val
, overlay
;
5529 /* If newline is part of a composition, continue from start of composition */
5530 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5531 && beg
< IT_CHARPOS (*it
))
5534 /* If newline is replaced by a display property, find start of overlay
5535 or interval and continue search from that point. */
5537 pos
= --IT_CHARPOS (it2
);
5540 it2
.string_from_display_prop_p
= 0;
5541 if (handle_display_prop (&it2
) == HANDLED_RETURN
5542 && !NILP (val
= get_char_property_and_overlay
5543 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5544 && (OVERLAYP (overlay
)
5545 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5546 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5548 /* If the call to handle_display_prop above pushed the
5549 iterator state, that causes side effects for the bidi
5550 iterator by calling bidi_push_it. Undo those side
5554 /* push_it calls bidi_push_it only if the bidi_p flag
5555 is set in the iterator being pushed. */
5556 if (it2
.stack
[--it2
.sp
].bidi_p
)
5557 bidi_pop_it (&it2
.bidi_it
);
5562 /* Newline is not replaced by anything -- so we are done. */
5568 IT_CHARPOS (*it
) = beg
;
5569 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5573 it
->continuation_lines_width
= 0;
5575 xassert (IT_CHARPOS (*it
) >= BEGV
);
5576 xassert (IT_CHARPOS (*it
) == BEGV
5577 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5582 /* Reseat iterator IT at the previous visible line start. Skip
5583 invisible text that is so either due to text properties or due to
5584 selective display. At the end, update IT's overlay information,
5585 face information etc. */
5588 reseat_at_previous_visible_line_start (struct it
*it
)
5590 back_to_previous_visible_line_start (it
);
5591 reseat (it
, it
->current
.pos
, 1);
5596 /* Reseat iterator IT on the next visible line start in the current
5597 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5598 preceding the line start. Skip over invisible text that is so
5599 because of selective display. Compute faces, overlays etc at the
5600 new position. Note that this function does not skip over text that
5601 is invisible because of text properties. */
5604 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5606 int newline_found_p
, skipped_p
= 0;
5608 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5610 /* Skip over lines that are invisible because they are indented
5611 more than the value of IT->selective. */
5612 if (it
->selective
> 0)
5613 while (IT_CHARPOS (*it
) < ZV
5614 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5615 (double) it
->selective
)) /* iftc */
5617 xassert (IT_BYTEPOS (*it
) == BEGV
5618 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5619 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5622 /* Position on the newline if that's what's requested. */
5623 if (on_newline_p
&& newline_found_p
)
5625 if (STRINGP (it
->string
))
5627 if (IT_STRING_CHARPOS (*it
) > 0)
5631 --IT_STRING_CHARPOS (*it
);
5632 --IT_STRING_BYTEPOS (*it
);
5635 /* Setting this flag will cause
5636 bidi_move_to_visually_next not to advance, but
5637 instead deliver the current character (newline),
5638 which is what the ON_NEWLINE_P flag wants. */
5639 it
->bidi_it
.first_elt
= 1;
5642 else if (IT_CHARPOS (*it
) > BEGV
)
5649 /* With bidi iteration, the call to `reseat' will cause
5650 bidi_move_to_visually_next deliver the current character,
5651 the newline, instead of advancing. */
5652 reseat (it
, it
->current
.pos
, 0);
5656 reseat (it
, it
->current
.pos
, 0);
5663 /***********************************************************************
5664 Changing an iterator's position
5665 ***********************************************************************/
5667 /* Change IT's current position to POS in current_buffer. If FORCE_P
5668 is non-zero, always check for text properties at the new position.
5669 Otherwise, text properties are only looked up if POS >=
5670 IT->check_charpos of a property. */
5673 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
5675 EMACS_INT original_pos
= IT_CHARPOS (*it
);
5677 reseat_1 (it
, pos
, 0);
5679 /* Determine where to check text properties. Avoid doing it
5680 where possible because text property lookup is very expensive. */
5682 || CHARPOS (pos
) > it
->stop_charpos
5683 || CHARPOS (pos
) < original_pos
)
5687 /* For bidi iteration, we need to prime prev_stop and
5688 base_level_stop with our best estimations. */
5689 if (CHARPOS (pos
) < it
->prev_stop
)
5691 handle_stop_backwards (it
, BEGV
);
5692 if (CHARPOS (pos
) < it
->base_level_stop
)
5693 it
->base_level_stop
= 0;
5695 else if (CHARPOS (pos
) > it
->stop_charpos
5696 && it
->stop_charpos
>= BEGV
)
5697 handle_stop_backwards (it
, it
->stop_charpos
);
5704 it
->prev_stop
= it
->base_level_stop
= 0;
5713 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5714 IT->stop_pos to POS, also. */
5717 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
5719 /* Don't call this function when scanning a C string. */
5720 xassert (it
->s
== NULL
);
5722 /* POS must be a reasonable value. */
5723 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5725 it
->current
.pos
= it
->position
= pos
;
5726 it
->end_charpos
= ZV
;
5728 it
->current
.dpvec_index
= -1;
5729 it
->current
.overlay_string_index
= -1;
5730 IT_STRING_CHARPOS (*it
) = -1;
5731 IT_STRING_BYTEPOS (*it
) = -1;
5733 it
->method
= GET_FROM_BUFFER
;
5734 it
->object
= it
->w
->buffer
;
5735 it
->area
= TEXT_AREA
;
5736 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
5738 it
->string_from_display_prop_p
= 0;
5739 it
->face_before_selective_p
= 0;
5742 it
->bidi_it
.first_elt
= 1;
5743 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5744 it
->bidi_it
.disp_pos
= -1;
5745 it
->bidi_it
.string
.s
= NULL
;
5746 it
->bidi_it
.string
.lstring
= Qnil
;
5747 it
->bidi_it
.string
.bufpos
= 0;
5752 it
->stop_charpos
= CHARPOS (pos
);
5753 it
->base_level_stop
= CHARPOS (pos
);
5758 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5759 If S is non-null, it is a C string to iterate over. Otherwise,
5760 STRING gives a Lisp string to iterate over.
5762 If PRECISION > 0, don't return more then PRECISION number of
5763 characters from the string.
5765 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5766 characters have been returned. FIELD_WIDTH < 0 means an infinite
5769 MULTIBYTE = 0 means disable processing of multibyte characters,
5770 MULTIBYTE > 0 means enable it,
5771 MULTIBYTE < 0 means use IT->multibyte_p.
5773 IT must be initialized via a prior call to init_iterator before
5774 calling this function. */
5777 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
5778 EMACS_INT charpos
, EMACS_INT precision
, int field_width
,
5781 /* No region in strings. */
5782 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5784 /* No text property checks performed by default, but see below. */
5785 it
->stop_charpos
= -1;
5787 /* Set iterator position and end position. */
5788 memset (&it
->current
, 0, sizeof it
->current
);
5789 it
->current
.overlay_string_index
= -1;
5790 it
->current
.dpvec_index
= -1;
5791 xassert (charpos
>= 0);
5793 /* If STRING is specified, use its multibyteness, otherwise use the
5794 setting of MULTIBYTE, if specified. */
5796 it
->multibyte_p
= multibyte
> 0;
5798 /* Bidirectional reordering of strings is controlled by the default
5799 value of bidi-display-reordering. */
5801 !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
))
5806 xassert (STRINGP (string
));
5807 it
->string
= string
;
5809 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5810 it
->method
= GET_FROM_STRING
;
5811 it
->current
.string_pos
= string_pos (charpos
, string
);
5815 it
->bidi_it
.string
.lstring
= string
;
5816 it
->bidi_it
.string
.s
= NULL
;
5817 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5818 it
->bidi_it
.string
.bufpos
= 0;
5819 it
->bidi_it
.string
.from_disp_str
= 0;
5820 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
5821 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5826 it
->s
= (const unsigned char *) s
;
5829 /* Note that we use IT->current.pos, not it->current.string_pos,
5830 for displaying C strings. */
5831 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5832 if (it
->multibyte_p
)
5834 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5835 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5839 it
->bidi_it
.string
.lstring
= Qnil
;
5840 it
->bidi_it
.string
.s
= s
;
5841 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5842 it
->bidi_it
.string
.bufpos
= 0;
5843 it
->bidi_it
.string
.from_disp_str
= 0;
5844 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
5850 /* Unibyte (a.k.a. ASCII) C strings are never bidi-reordered. */
5851 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5852 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5855 it
->method
= GET_FROM_C_STRING
;
5858 /* PRECISION > 0 means don't return more than PRECISION characters
5860 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5862 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5864 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5867 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5868 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5869 FIELD_WIDTH < 0 means infinite field width. This is useful for
5870 padding with `-' at the end of a mode line. */
5871 if (field_width
< 0)
5872 field_width
= INFINITY
;
5873 /* Implementation note: We deliberately don't enlarge
5874 it->bidi_it.string.schars here to fit it->end_charpos, because
5875 the bidi iterator cannot produce characters out of thin air. */
5876 if (field_width
> it
->end_charpos
- charpos
)
5877 it
->end_charpos
= charpos
+ field_width
;
5879 /* Use the standard display table for displaying strings. */
5880 if (DISP_TABLE_P (Vstandard_display_table
))
5881 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5883 it
->stop_charpos
= charpos
;
5884 it
->prev_stop
= charpos
;
5885 it
->base_level_stop
= 0;
5888 it
->bidi_it
.first_elt
= 1;
5889 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5890 it
->bidi_it
.disp_pos
= -1;
5892 if (s
== NULL
&& it
->multibyte_p
)
5894 EMACS_INT endpos
= SCHARS (it
->string
);
5895 if (endpos
> it
->end_charpos
)
5896 endpos
= it
->end_charpos
;
5897 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5905 /***********************************************************************
5907 ***********************************************************************/
5909 /* Map enum it_method value to corresponding next_element_from_* function. */
5911 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
5913 next_element_from_buffer
,
5914 next_element_from_display_vector
,
5915 next_element_from_string
,
5916 next_element_from_c_string
,
5917 next_element_from_image
,
5918 next_element_from_stretch
5921 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5924 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5925 (possibly with the following characters). */
5927 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5928 ((IT)->cmp_it.id >= 0 \
5929 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5930 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5931 END_CHARPOS, (IT)->w, \
5932 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5936 /* Lookup the char-table Vglyphless_char_display for character C (-1
5937 if we want information for no-font case), and return the display
5938 method symbol. By side-effect, update it->what and
5939 it->glyphless_method. This function is called from
5940 get_next_display_element for each character element, and from
5941 x_produce_glyphs when no suitable font was found. */
5944 lookup_glyphless_char_display (int c
, struct it
*it
)
5946 Lisp_Object glyphless_method
= Qnil
;
5948 if (CHAR_TABLE_P (Vglyphless_char_display
)
5949 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
5953 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
5954 if (CONSP (glyphless_method
))
5955 glyphless_method
= FRAME_WINDOW_P (it
->f
)
5956 ? XCAR (glyphless_method
)
5957 : XCDR (glyphless_method
);
5960 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
5964 if (NILP (glyphless_method
))
5967 /* The default is to display the character by a proper font. */
5969 /* The default for the no-font case is to display an empty box. */
5970 glyphless_method
= Qempty_box
;
5972 if (EQ (glyphless_method
, Qzero_width
))
5975 return glyphless_method
;
5976 /* This method can't be used for the no-font case. */
5977 glyphless_method
= Qempty_box
;
5979 if (EQ (glyphless_method
, Qthin_space
))
5980 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
5981 else if (EQ (glyphless_method
, Qempty_box
))
5982 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
5983 else if (EQ (glyphless_method
, Qhex_code
))
5984 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
5985 else if (STRINGP (glyphless_method
))
5986 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
5989 /* Invalid value. We use the default method. */
5990 glyphless_method
= Qnil
;
5993 it
->what
= IT_GLYPHLESS
;
5994 return glyphless_method
;
5997 /* Load IT's display element fields with information about the next
5998 display element from the current position of IT. Value is zero if
5999 end of buffer (or C string) is reached. */
6001 static struct frame
*last_escape_glyph_frame
= NULL
;
6002 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6003 static int last_escape_glyph_merged_face_id
= 0;
6005 struct frame
*last_glyphless_glyph_frame
= NULL
;
6006 unsigned last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6007 int last_glyphless_glyph_merged_face_id
= 0;
6010 get_next_display_element (struct it
*it
)
6012 /* Non-zero means that we found a display element. Zero means that
6013 we hit the end of what we iterate over. Performance note: the
6014 function pointer `method' used here turns out to be faster than
6015 using a sequence of if-statements. */
6019 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6021 if (it
->what
== IT_CHARACTER
)
6023 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6024 and only if (a) the resolved directionality of that character
6026 /* FIXME: Do we need an exception for characters from display
6028 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6029 it
->c
= bidi_mirror_char (it
->c
);
6030 /* Map via display table or translate control characters.
6031 IT->c, IT->len etc. have been set to the next character by
6032 the function call above. If we have a display table, and it
6033 contains an entry for IT->c, translate it. Don't do this if
6034 IT->c itself comes from a display table, otherwise we could
6035 end up in an infinite recursion. (An alternative could be to
6036 count the recursion depth of this function and signal an
6037 error when a certain maximum depth is reached.) Is it worth
6039 if (success_p
&& it
->dpvec
== NULL
)
6042 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6043 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
6044 nbsp_or_shy
= char_is_other
;
6045 int c
= it
->c
; /* This is the character to display. */
6047 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6049 xassert (SINGLE_BYTE_CHAR_P (c
));
6050 if (unibyte_display_via_language_environment
)
6052 c
= DECODE_CHAR (unibyte
, c
);
6054 c
= BYTE8_TO_CHAR (it
->c
);
6057 c
= BYTE8_TO_CHAR (it
->c
);
6061 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6064 struct Lisp_Vector
*v
= XVECTOR (dv
);
6066 /* Return the first character from the display table
6067 entry, if not empty. If empty, don't display the
6068 current character. */
6071 it
->dpvec_char_len
= it
->len
;
6072 it
->dpvec
= v
->contents
;
6073 it
->dpend
= v
->contents
+ v
->header
.size
;
6074 it
->current
.dpvec_index
= 0;
6075 it
->dpvec_face_id
= -1;
6076 it
->saved_face_id
= it
->face_id
;
6077 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6082 set_iterator_to_next (it
, 0);
6087 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6089 if (it
->what
== IT_GLYPHLESS
)
6091 /* Don't display this character. */
6092 set_iterator_to_next (it
, 0);
6096 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6097 nbsp_or_shy
= (c
== 0xA0 ? char_is_nbsp
6098 : c
== 0xAD ? char_is_soft_hyphen
6101 /* Translate control characters into `\003' or `^C' form.
6102 Control characters coming from a display table entry are
6103 currently not translated because we use IT->dpvec to hold
6104 the translation. This could easily be changed but I
6105 don't believe that it is worth doing.
6107 NBSP and SOFT-HYPEN are property translated too.
6109 Non-printable characters and raw-byte characters are also
6110 translated to octal form. */
6111 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6112 ? (it
->area
!= TEXT_AREA
6113 /* In mode line, treat \n, \t like other crl chars. */
6116 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6117 || (c
!= '\n' && c
!= '\t'))
6120 || ! CHAR_PRINTABLE_P (c
))))
6122 /* C is a control character, NBSP, SOFT-HYPEN, raw-byte,
6123 or a non-printable character which must be displayed
6124 either as '\003' or as `^C' where the '\\' and '^'
6125 can be defined in the display table. Fill
6126 IT->ctl_chars with glyphs for what we have to
6127 display. Then, set IT->dpvec to these glyphs. */
6130 int face_id
, lface_id
= 0 ;
6133 /* Handle control characters with ^. */
6135 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6139 g
= '^'; /* default glyph for Control */
6140 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6142 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6143 && GLYPH_CODE_CHAR_VALID_P (gc
))
6145 g
= GLYPH_CODE_CHAR (gc
);
6146 lface_id
= GLYPH_CODE_FACE (gc
);
6150 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6152 else if (it
->f
== last_escape_glyph_frame
6153 && it
->face_id
== last_escape_glyph_face_id
)
6155 face_id
= last_escape_glyph_merged_face_id
;
6159 /* Merge the escape-glyph face into the current face. */
6160 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6162 last_escape_glyph_frame
= it
->f
;
6163 last_escape_glyph_face_id
= it
->face_id
;
6164 last_escape_glyph_merged_face_id
= face_id
;
6167 XSETINT (it
->ctl_chars
[0], g
);
6168 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6170 goto display_control
;
6173 /* Handle non-break space in the mode where it only gets
6176 if (EQ (Vnobreak_char_display
, Qt
)
6177 && nbsp_or_shy
== char_is_nbsp
)
6179 /* Merge the no-break-space face into the current face. */
6180 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6184 XSETINT (it
->ctl_chars
[0], ' ');
6186 goto display_control
;
6189 /* Handle sequences that start with the "escape glyph". */
6191 /* the default escape glyph is \. */
6192 escape_glyph
= '\\';
6195 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
6196 && GLYPH_CODE_CHAR_VALID_P (gc
))
6198 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6199 lface_id
= GLYPH_CODE_FACE (gc
);
6203 /* The display table specified a face.
6204 Merge it into face_id and also into escape_glyph. */
6205 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6208 else if (it
->f
== last_escape_glyph_frame
6209 && it
->face_id
== last_escape_glyph_face_id
)
6211 face_id
= last_escape_glyph_merged_face_id
;
6215 /* Merge the escape-glyph face into the current face. */
6216 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6218 last_escape_glyph_frame
= it
->f
;
6219 last_escape_glyph_face_id
= it
->face_id
;
6220 last_escape_glyph_merged_face_id
= face_id
;
6223 /* Handle soft hyphens in the mode where they only get
6226 if (EQ (Vnobreak_char_display
, Qt
)
6227 && nbsp_or_shy
== char_is_soft_hyphen
)
6229 XSETINT (it
->ctl_chars
[0], '-');
6231 goto display_control
;
6234 /* Handle non-break space and soft hyphen
6235 with the escape glyph. */
6239 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6240 c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
6241 XSETINT (it
->ctl_chars
[1], c
);
6243 goto display_control
;
6250 if (CHAR_BYTE8_P (c
))
6251 /* Display \200 instead of \17777600. */
6252 c
= CHAR_TO_BYTE8 (c
);
6253 len
= sprintf (str
, "%03o", c
);
6255 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6256 for (i
= 0; i
< len
; i
++)
6257 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6262 /* Set up IT->dpvec and return first character from it. */
6263 it
->dpvec_char_len
= it
->len
;
6264 it
->dpvec
= it
->ctl_chars
;
6265 it
->dpend
= it
->dpvec
+ ctl_len
;
6266 it
->current
.dpvec_index
= 0;
6267 it
->dpvec_face_id
= face_id
;
6268 it
->saved_face_id
= it
->face_id
;
6269 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6273 it
->char_to_display
= c
;
6277 it
->char_to_display
= it
->c
;
6281 /* Adjust face id for a multibyte character. There are no multibyte
6282 character in unibyte text. */
6283 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6286 && FRAME_WINDOW_P (it
->f
))
6288 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6290 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6292 /* Automatic composition with glyph-string. */
6293 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6295 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6299 EMACS_INT pos
= (it
->s
? -1
6300 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6301 : IT_CHARPOS (*it
));
6303 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
, pos
,
6309 /* Is this character the last one of a run of characters with
6310 box? If yes, set IT->end_of_box_run_p to 1. */
6314 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6316 int face_id
= underlying_face_id (it
);
6317 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6321 if (face
->box
== FACE_NO_BOX
)
6323 /* If the box comes from face properties in a
6324 display string, check faces in that string. */
6325 int string_face_id
= face_after_it_pos (it
);
6326 it
->end_of_box_run_p
6327 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6330 /* Otherwise, the box comes from the underlying face.
6331 If this is the last string character displayed, check
6332 the next buffer location. */
6333 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6334 && (it
->current
.overlay_string_index
6335 == it
->n_overlay_strings
- 1))
6339 struct text_pos pos
= it
->current
.pos
;
6340 INC_TEXT_POS (pos
, it
->multibyte_p
);
6342 next_face_id
= face_at_buffer_position
6343 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6344 it
->region_end_charpos
, &ignore
,
6345 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6347 it
->end_of_box_run_p
6348 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6355 int face_id
= face_after_it_pos (it
);
6356 it
->end_of_box_run_p
6357 = (face_id
!= it
->face_id
6358 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6362 /* Value is 0 if end of buffer or string reached. */
6367 /* Move IT to the next display element.
6369 RESEAT_P non-zero means if called on a newline in buffer text,
6370 skip to the next visible line start.
6372 Functions get_next_display_element and set_iterator_to_next are
6373 separate because I find this arrangement easier to handle than a
6374 get_next_display_element function that also increments IT's
6375 position. The way it is we can first look at an iterator's current
6376 display element, decide whether it fits on a line, and if it does,
6377 increment the iterator position. The other way around we probably
6378 would either need a flag indicating whether the iterator has to be
6379 incremented the next time, or we would have to implement a
6380 decrement position function which would not be easy to write. */
6383 set_iterator_to_next (struct it
*it
, int reseat_p
)
6385 /* Reset flags indicating start and end of a sequence of characters
6386 with box. Reset them at the start of this function because
6387 moving the iterator to a new position might set them. */
6388 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6392 case GET_FROM_BUFFER
:
6393 /* The current display element of IT is a character from
6394 current_buffer. Advance in the buffer, and maybe skip over
6395 invisible lines that are so because of selective display. */
6396 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6397 reseat_at_next_visible_line_start (it
, 0);
6398 else if (it
->cmp_it
.id
>= 0)
6400 /* We are currently getting glyphs from a composition. */
6405 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6406 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6407 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6409 it
->cmp_it
.from
= it
->cmp_it
.to
;
6414 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6416 it
->end_charpos
, Qnil
);
6419 else if (! it
->cmp_it
.reversed_p
)
6421 /* Composition created while scanning forward. */
6422 /* Update IT's char/byte positions to point to the first
6423 character of the next grapheme cluster, or to the
6424 character visually after the current composition. */
6425 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6426 bidi_move_to_visually_next (&it
->bidi_it
);
6427 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6428 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6430 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6432 /* Proceed to the next grapheme cluster. */
6433 it
->cmp_it
.from
= it
->cmp_it
.to
;
6437 /* No more grapheme clusters in this composition.
6438 Find the next stop position. */
6439 EMACS_INT stop
= it
->end_charpos
;
6440 if (it
->bidi_it
.scan_dir
< 0)
6441 /* Now we are scanning backward and don't know
6444 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6445 IT_BYTEPOS (*it
), stop
, Qnil
);
6450 /* Composition created while scanning backward. */
6451 /* Update IT's char/byte positions to point to the last
6452 character of the previous grapheme cluster, or the
6453 character visually after the current composition. */
6454 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6455 bidi_move_to_visually_next (&it
->bidi_it
);
6456 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6457 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6458 if (it
->cmp_it
.from
> 0)
6460 /* Proceed to the previous grapheme cluster. */
6461 it
->cmp_it
.to
= it
->cmp_it
.from
;
6465 /* No more grapheme clusters in this composition.
6466 Find the next stop position. */
6467 EMACS_INT stop
= it
->end_charpos
;
6468 if (it
->bidi_it
.scan_dir
< 0)
6469 /* Now we are scanning backward and don't know
6472 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6473 IT_BYTEPOS (*it
), stop
, Qnil
);
6479 xassert (it
->len
!= 0);
6483 IT_BYTEPOS (*it
) += it
->len
;
6484 IT_CHARPOS (*it
) += 1;
6488 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6489 /* If this is a new paragraph, determine its base
6490 direction (a.k.a. its base embedding level). */
6491 if (it
->bidi_it
.new_paragraph
)
6492 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6493 bidi_move_to_visually_next (&it
->bidi_it
);
6494 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6495 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6496 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6498 /* As the scan direction was changed, we must
6499 re-compute the stop position for composition. */
6500 EMACS_INT stop
= it
->end_charpos
;
6501 if (it
->bidi_it
.scan_dir
< 0)
6503 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6504 IT_BYTEPOS (*it
), stop
, Qnil
);
6507 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6511 case GET_FROM_C_STRING
:
6512 /* Current display element of IT is from a C string. */
6514 /* If the string position is beyond string_nchars, it means
6515 next_element_from_c_string is padding the string with
6516 blanks, in which case we bypass the bidi iterator,
6517 because it cannot deal with such virtual characters. */
6518 || IT_CHARPOS (*it
) >= it
->string_nchars
)
6520 IT_BYTEPOS (*it
) += it
->len
;
6521 IT_CHARPOS (*it
) += 1;
6525 bidi_move_to_visually_next (&it
->bidi_it
);
6526 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6527 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6531 case GET_FROM_DISPLAY_VECTOR
:
6532 /* Current display element of IT is from a display table entry.
6533 Advance in the display table definition. Reset it to null if
6534 end reached, and continue with characters from buffers/
6536 ++it
->current
.dpvec_index
;
6538 /* Restore face of the iterator to what they were before the
6539 display vector entry (these entries may contain faces). */
6540 it
->face_id
= it
->saved_face_id
;
6542 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6544 int recheck_faces
= it
->ellipsis_p
;
6547 it
->method
= GET_FROM_C_STRING
;
6548 else if (STRINGP (it
->string
))
6549 it
->method
= GET_FROM_STRING
;
6552 it
->method
= GET_FROM_BUFFER
;
6553 it
->object
= it
->w
->buffer
;
6557 it
->current
.dpvec_index
= -1;
6559 /* Skip over characters which were displayed via IT->dpvec. */
6560 if (it
->dpvec_char_len
< 0)
6561 reseat_at_next_visible_line_start (it
, 1);
6562 else if (it
->dpvec_char_len
> 0)
6564 if (it
->method
== GET_FROM_STRING
6565 && it
->n_overlay_strings
> 0)
6566 it
->ignore_overlay_strings_at_pos_p
= 1;
6567 it
->len
= it
->dpvec_char_len
;
6568 set_iterator_to_next (it
, reseat_p
);
6571 /* Maybe recheck faces after display vector */
6573 it
->stop_charpos
= IT_CHARPOS (*it
);
6577 case GET_FROM_STRING
:
6578 /* Current display element is a character from a Lisp string. */
6579 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6580 if (it
->cmp_it
.id
>= 0)
6586 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6587 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6588 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6589 it
->cmp_it
.from
= it
->cmp_it
.to
;
6593 composition_compute_stop_pos (&it
->cmp_it
,
6594 IT_STRING_CHARPOS (*it
),
6595 IT_STRING_BYTEPOS (*it
),
6596 it
->end_charpos
, it
->string
);
6599 else if (! it
->cmp_it
.reversed_p
)
6601 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6602 bidi_move_to_visually_next (&it
->bidi_it
);
6603 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6604 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6606 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6607 it
->cmp_it
.from
= it
->cmp_it
.to
;
6610 EMACS_INT stop
= it
->end_charpos
;
6611 if (it
->bidi_it
.scan_dir
< 0)
6613 composition_compute_stop_pos (&it
->cmp_it
,
6614 IT_STRING_CHARPOS (*it
),
6615 IT_STRING_BYTEPOS (*it
), stop
,
6621 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6622 bidi_move_to_visually_next (&it
->bidi_it
);
6623 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6624 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6625 if (it
->cmp_it
.from
> 0)
6626 it
->cmp_it
.to
= it
->cmp_it
.from
;
6629 EMACS_INT stop
= it
->end_charpos
;
6630 if (it
->bidi_it
.scan_dir
< 0)
6632 composition_compute_stop_pos (&it
->cmp_it
,
6633 IT_STRING_CHARPOS (*it
),
6634 IT_STRING_BYTEPOS (*it
), stop
,
6642 /* If the string position is beyond string_nchars, it
6643 means next_element_from_string is padding the string
6644 with blanks, in which case we bypass the bidi
6645 iterator, because it cannot deal with such virtual
6647 || IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6649 IT_STRING_BYTEPOS (*it
) += it
->len
;
6650 IT_STRING_CHARPOS (*it
) += 1;
6654 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6656 bidi_move_to_visually_next (&it
->bidi_it
);
6657 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6658 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6659 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6661 EMACS_INT stop
= it
->end_charpos
;
6663 if (it
->bidi_it
.scan_dir
< 0)
6665 composition_compute_stop_pos (&it
->cmp_it
,
6666 IT_STRING_CHARPOS (*it
),
6667 IT_STRING_BYTEPOS (*it
), stop
,
6673 consider_string_end
:
6675 if (it
->current
.overlay_string_index
>= 0)
6677 /* IT->string is an overlay string. Advance to the
6678 next, if there is one. */
6679 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6682 next_overlay_string (it
);
6684 setup_for_ellipsis (it
, 0);
6689 /* IT->string is not an overlay string. If we reached
6690 its end, and there is something on IT->stack, proceed
6691 with what is on the stack. This can be either another
6692 string, this time an overlay string, or a buffer. */
6693 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6697 if (it
->method
== GET_FROM_STRING
)
6698 goto consider_string_end
;
6703 case GET_FROM_IMAGE
:
6704 case GET_FROM_STRETCH
:
6705 /* The position etc with which we have to proceed are on
6706 the stack. The position may be at the end of a string,
6707 if the `display' property takes up the whole string. */
6708 xassert (it
->sp
> 0);
6710 if (it
->method
== GET_FROM_STRING
)
6711 goto consider_string_end
;
6715 /* There are no other methods defined, so this should be a bug. */
6719 xassert (it
->method
!= GET_FROM_STRING
6720 || (STRINGP (it
->string
)
6721 && IT_STRING_CHARPOS (*it
) >= 0));
6724 /* Load IT's display element fields with information about the next
6725 display element which comes from a display table entry or from the
6726 result of translating a control character to one of the forms `^C'
6729 IT->dpvec holds the glyphs to return as characters.
6730 IT->saved_face_id holds the face id before the display vector--it
6731 is restored into IT->face_id in set_iterator_to_next. */
6734 next_element_from_display_vector (struct it
*it
)
6739 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6741 it
->face_id
= it
->saved_face_id
;
6743 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6744 That seemed totally bogus - so I changed it... */
6745 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6747 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6749 it
->c
= GLYPH_CODE_CHAR (gc
);
6750 it
->len
= CHAR_BYTES (it
->c
);
6752 /* The entry may contain a face id to use. Such a face id is
6753 the id of a Lisp face, not a realized face. A face id of
6754 zero means no face is specified. */
6755 if (it
->dpvec_face_id
>= 0)
6756 it
->face_id
= it
->dpvec_face_id
;
6759 int lface_id
= GLYPH_CODE_FACE (gc
);
6761 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6766 /* Display table entry is invalid. Return a space. */
6767 it
->c
= ' ', it
->len
= 1;
6769 /* Don't change position and object of the iterator here. They are
6770 still the values of the character that had this display table
6771 entry or was translated, and that's what we want. */
6772 it
->what
= IT_CHARACTER
;
6776 /* Get the first element of string/buffer in the visual order, after
6777 being reseated to a new position in a string or a buffer. */
6779 get_visually_first_element (struct it
*it
)
6781 int string_p
= STRINGP (it
->string
) || it
->s
;
6782 EMACS_INT eob
= (string_p
? it
->string_nchars
: ZV
);
6783 EMACS_INT bob
= (string_p
? 0 : BEGV
);
6785 if (STRINGP (it
->string
))
6787 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
6788 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
6792 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6793 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6796 if (it
->bidi_it
.charpos
== eob
)
6798 /* Nothing to do, but reset the FIRST_ELT flag, like
6799 bidi_paragraph_init does, because we are not going to
6801 it
->bidi_it
.first_elt
= 0;
6803 else if (it
->bidi_it
.charpos
== bob
6805 /* FIXME: Should support all Unicode line separators. */
6806 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6807 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
6809 /* If we are at the beginning of a line/string, we can produce
6810 the next element right away. */
6811 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6812 bidi_move_to_visually_next (&it
->bidi_it
);
6816 EMACS_INT orig_bytepos
= it
->bidi_it
.bytepos
;
6818 /* We need to prime the bidi iterator starting at the line's or
6819 string's beginning, before we will be able to produce the
6822 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
6825 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
6827 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
6829 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6832 /* Now return to buffer/string position where we were asked
6833 to get the next display element, and produce that. */
6834 bidi_move_to_visually_next (&it
->bidi_it
);
6836 while (it
->bidi_it
.bytepos
!= orig_bytepos
6837 && it
->bidi_it
.charpos
< eob
);
6840 /* Adjust IT's position information to where we ended up. */
6841 if (STRINGP (it
->string
))
6843 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6844 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6848 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6849 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6852 if (STRINGP (it
->string
) || !it
->s
)
6854 EMACS_INT stop
, charpos
, bytepos
;
6856 if (STRINGP (it
->string
))
6859 stop
= SCHARS (it
->string
);
6860 if (stop
> it
->end_charpos
)
6861 stop
= it
->end_charpos
;
6862 charpos
= IT_STRING_CHARPOS (*it
);
6863 bytepos
= IT_STRING_BYTEPOS (*it
);
6867 stop
= it
->end_charpos
;
6868 charpos
= IT_CHARPOS (*it
);
6869 bytepos
= IT_BYTEPOS (*it
);
6871 if (it
->bidi_it
.scan_dir
< 0)
6873 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
6878 /* Load IT with the next display element from Lisp string IT->string.
6879 IT->current.string_pos is the current position within the string.
6880 If IT->current.overlay_string_index >= 0, the Lisp string is an
6884 next_element_from_string (struct it
*it
)
6886 struct text_pos position
;
6888 xassert (STRINGP (it
->string
));
6889 xassert (!it
->bidi_p
|| it
->string
== it
->bidi_it
.string
.lstring
);
6890 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6891 position
= it
->current
.string_pos
;
6893 /* With bidi reordering, the character to display might not be the
6894 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
6895 that we were reseat()ed to a new string, whose paragraph
6896 direction is not known. */
6897 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6899 get_visually_first_element (it
);
6900 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
6903 /* Time to check for invisible text? */
6904 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
6906 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
6909 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6910 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
6912 /* With bidi non-linear iteration, we could find
6913 ourselves far beyond the last computed stop_charpos,
6914 with several other stop positions in between that we
6915 missed. Scan them all now, in buffer's logical
6916 order, until we find and handle the last stop_charpos
6917 that precedes our current position. */
6918 handle_stop_backwards (it
, it
->stop_charpos
);
6919 return GET_NEXT_DISPLAY_ELEMENT (it
);
6925 /* Take note of the stop position we just moved
6926 across, for when we will move back across it. */
6927 it
->prev_stop
= it
->stop_charpos
;
6928 /* If we are at base paragraph embedding level, take
6929 note of the last stop position seen at this
6931 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6932 it
->base_level_stop
= it
->stop_charpos
;
6936 /* Since a handler may have changed IT->method, we must
6938 return GET_NEXT_DISPLAY_ELEMENT (it
);
6942 /* If we are before prev_stop, we may have overstepped
6943 on our way backwards a stop_pos, and if so, we need
6944 to handle that stop_pos. */
6945 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
6946 /* We can sometimes back up for reasons that have nothing
6947 to do with bidi reordering. E.g., compositions. The
6948 code below is only needed when we are above the base
6949 embedding level, so test for that explicitly. */
6950 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6952 /* If we lost track of base_level_stop, we have no better place
6953 for handle_stop_backwards to start from than BEGV. This
6954 happens, e.g., when we were reseated to the previous
6955 screenful of text by vertical-motion. */
6956 if (it
->base_level_stop
<= 0
6957 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
6958 it
->base_level_stop
= 0;
6959 handle_stop_backwards (it
, it
->base_level_stop
);
6960 return GET_NEXT_DISPLAY_ELEMENT (it
);
6964 if (it
->current
.overlay_string_index
>= 0)
6966 /* Get the next character from an overlay string. In overlay
6967 strings, There is no field width or padding with spaces to
6969 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6974 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6975 IT_STRING_BYTEPOS (*it
),
6976 it
->bidi_it
.scan_dir
< 0
6978 : SCHARS (it
->string
))
6979 && next_element_from_composition (it
))
6983 else if (STRING_MULTIBYTE (it
->string
))
6985 const unsigned char *s
= (SDATA (it
->string
)
6986 + IT_STRING_BYTEPOS (*it
));
6987 it
->c
= string_char_and_length (s
, &it
->len
);
6991 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6997 /* Get the next character from a Lisp string that is not an
6998 overlay string. Such strings come from the mode line, for
6999 example. We may have to pad with spaces, or truncate the
7000 string. See also next_element_from_c_string. */
7001 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7006 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7008 /* Pad with spaces. */
7009 it
->c
= ' ', it
->len
= 1;
7010 CHARPOS (position
) = BYTEPOS (position
) = -1;
7012 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7013 IT_STRING_BYTEPOS (*it
),
7014 it
->bidi_it
.scan_dir
< 0
7016 : it
->string_nchars
)
7017 && next_element_from_composition (it
))
7021 else if (STRING_MULTIBYTE (it
->string
))
7023 const unsigned char *s
= (SDATA (it
->string
)
7024 + IT_STRING_BYTEPOS (*it
));
7025 it
->c
= string_char_and_length (s
, &it
->len
);
7029 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7034 /* Record what we have and where it came from. */
7035 it
->what
= IT_CHARACTER
;
7036 it
->object
= it
->string
;
7037 it
->position
= position
;
7042 /* Load IT with next display element from C string IT->s.
7043 IT->string_nchars is the maximum number of characters to return
7044 from the string. IT->end_charpos may be greater than
7045 IT->string_nchars when this function is called, in which case we
7046 may have to return padding spaces. Value is zero if end of string
7047 reached, including padding spaces. */
7050 next_element_from_c_string (struct it
*it
)
7055 xassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7056 it
->what
= IT_CHARACTER
;
7057 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7060 /* With bidi reordering, the character to display might not be the
7061 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7062 we were reseated to a new string, whose paragraph direction is
7064 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7065 get_visually_first_element (it
);
7067 /* IT's position can be greater than IT->string_nchars in case a
7068 field width or precision has been specified when the iterator was
7070 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7072 /* End of the game. */
7076 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7078 /* Pad with spaces. */
7079 it
->c
= ' ', it
->len
= 1;
7080 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7082 else if (it
->multibyte_p
)
7083 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7085 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7091 /* Set up IT to return characters from an ellipsis, if appropriate.
7092 The definition of the ellipsis glyphs may come from a display table
7093 entry. This function fills IT with the first glyph from the
7094 ellipsis if an ellipsis is to be displayed. */
7097 next_element_from_ellipsis (struct it
*it
)
7099 if (it
->selective_display_ellipsis_p
)
7100 setup_for_ellipsis (it
, it
->len
);
7103 /* The face at the current position may be different from the
7104 face we find after the invisible text. Remember what it
7105 was in IT->saved_face_id, and signal that it's there by
7106 setting face_before_selective_p. */
7107 it
->saved_face_id
= it
->face_id
;
7108 it
->method
= GET_FROM_BUFFER
;
7109 it
->object
= it
->w
->buffer
;
7110 reseat_at_next_visible_line_start (it
, 1);
7111 it
->face_before_selective_p
= 1;
7114 return GET_NEXT_DISPLAY_ELEMENT (it
);
7118 /* Deliver an image display element. The iterator IT is already
7119 filled with image information (done in handle_display_prop). Value
7124 next_element_from_image (struct it
*it
)
7126 it
->what
= IT_IMAGE
;
7127 it
->ignore_overlay_strings_at_pos_p
= 0;
7132 /* Fill iterator IT with next display element from a stretch glyph
7133 property. IT->object is the value of the text property. Value is
7137 next_element_from_stretch (struct it
*it
)
7139 it
->what
= IT_STRETCH
;
7143 /* Scan forward from CHARPOS in the current buffer/string, until we
7144 find a stop position > current IT's position. Then handle the stop
7145 position before that. This is called when we bump into a stop
7146 position while reordering bidirectional text. CHARPOS should be
7147 the last previously processed stop_pos (or BEGV/0, if none were
7148 processed yet) whose position is less that IT's current
7152 handle_stop_backwards (struct it
*it
, EMACS_INT charpos
)
7154 int bufp
= !STRINGP (it
->string
);
7155 EMACS_INT where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7156 struct display_pos save_current
= it
->current
;
7157 struct text_pos save_position
= it
->position
;
7158 struct text_pos pos1
;
7159 EMACS_INT next_stop
;
7161 /* Scan in strict logical order. */
7165 it
->prev_stop
= charpos
;
7168 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7169 reseat_1 (it
, pos1
, 0);
7172 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7173 compute_stop_pos (it
);
7174 /* We must advance forward, right? */
7175 if (it
->stop_charpos
<= it
->prev_stop
)
7177 charpos
= it
->stop_charpos
;
7179 while (charpos
<= where_we_are
);
7181 next_stop
= it
->stop_charpos
;
7182 it
->stop_charpos
= it
->prev_stop
;
7184 it
->current
= save_current
;
7185 it
->position
= save_position
;
7187 it
->stop_charpos
= next_stop
;
7190 /* Load IT with the next display element from current_buffer. Value
7191 is zero if end of buffer reached. IT->stop_charpos is the next
7192 position at which to stop and check for text properties or buffer
7196 next_element_from_buffer (struct it
*it
)
7200 xassert (IT_CHARPOS (*it
) >= BEGV
);
7201 xassert (NILP (it
->string
) && !it
->s
);
7202 xassert (!it
->bidi_p
7203 || (it
->bidi_it
.string
.lstring
== Qnil
7204 && it
->bidi_it
.string
.s
== NULL
));
7206 /* With bidi reordering, the character to display might not be the
7207 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7208 we were reseat()ed to a new buffer position, which is potentially
7209 a different paragraph. */
7210 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7212 get_visually_first_element (it
);
7213 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7216 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7218 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7220 int overlay_strings_follow_p
;
7222 /* End of the game, except when overlay strings follow that
7223 haven't been returned yet. */
7224 if (it
->overlay_strings_at_end_processed_p
)
7225 overlay_strings_follow_p
= 0;
7228 it
->overlay_strings_at_end_processed_p
= 1;
7229 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7232 if (overlay_strings_follow_p
)
7233 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7237 it
->position
= it
->current
.pos
;
7241 else if (!(!it
->bidi_p
7242 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7243 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7245 /* With bidi non-linear iteration, we could find ourselves
7246 far beyond the last computed stop_charpos, with several
7247 other stop positions in between that we missed. Scan
7248 them all now, in buffer's logical order, until we find
7249 and handle the last stop_charpos that precedes our
7250 current position. */
7251 handle_stop_backwards (it
, it
->stop_charpos
);
7252 return GET_NEXT_DISPLAY_ELEMENT (it
);
7258 /* Take note of the stop position we just moved across,
7259 for when we will move back across it. */
7260 it
->prev_stop
= it
->stop_charpos
;
7261 /* If we are at base paragraph embedding level, take
7262 note of the last stop position seen at this
7264 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7265 it
->base_level_stop
= it
->stop_charpos
;
7268 return GET_NEXT_DISPLAY_ELEMENT (it
);
7272 /* If we are before prev_stop, we may have overstepped on
7273 our way backwards a stop_pos, and if so, we need to
7274 handle that stop_pos. */
7275 && IT_CHARPOS (*it
) < it
->prev_stop
7276 /* We can sometimes back up for reasons that have nothing
7277 to do with bidi reordering. E.g., compositions. The
7278 code below is only needed when we are above the base
7279 embedding level, so test for that explicitly. */
7280 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7282 /* If we lost track of base_level_stop, we have no better place
7283 for handle_stop_backwards to start from than BEGV. This
7284 happens, e.g., when we were reseated to the previous
7285 screenful of text by vertical-motion. */
7286 if (it
->base_level_stop
<= 0
7287 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7288 it
->base_level_stop
= BEGV
;
7289 handle_stop_backwards (it
, it
->base_level_stop
);
7290 return GET_NEXT_DISPLAY_ELEMENT (it
);
7294 /* No face changes, overlays etc. in sight, so just return a
7295 character from current_buffer. */
7299 /* Maybe run the redisplay end trigger hook. Performance note:
7300 This doesn't seem to cost measurable time. */
7301 if (it
->redisplay_end_trigger_charpos
7303 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7304 run_redisplay_end_trigger_hook (it
);
7306 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7307 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7309 && next_element_from_composition (it
))
7314 /* Get the next character, maybe multibyte. */
7315 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7316 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7317 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7319 it
->c
= *p
, it
->len
= 1;
7321 /* Record what we have and where it came from. */
7322 it
->what
= IT_CHARACTER
;
7323 it
->object
= it
->w
->buffer
;
7324 it
->position
= it
->current
.pos
;
7326 /* Normally we return the character found above, except when we
7327 really want to return an ellipsis for selective display. */
7332 /* A value of selective > 0 means hide lines indented more
7333 than that number of columns. */
7334 if (it
->selective
> 0
7335 && IT_CHARPOS (*it
) + 1 < ZV
7336 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7337 IT_BYTEPOS (*it
) + 1,
7338 (double) it
->selective
)) /* iftc */
7340 success_p
= next_element_from_ellipsis (it
);
7341 it
->dpvec_char_len
= -1;
7344 else if (it
->c
== '\r' && it
->selective
== -1)
7346 /* A value of selective == -1 means that everything from the
7347 CR to the end of the line is invisible, with maybe an
7348 ellipsis displayed for it. */
7349 success_p
= next_element_from_ellipsis (it
);
7350 it
->dpvec_char_len
= -1;
7355 /* Value is zero if end of buffer reached. */
7356 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
7361 /* Run the redisplay end trigger hook for IT. */
7364 run_redisplay_end_trigger_hook (struct it
*it
)
7366 Lisp_Object args
[3];
7368 /* IT->glyph_row should be non-null, i.e. we should be actually
7369 displaying something, or otherwise we should not run the hook. */
7370 xassert (it
->glyph_row
);
7372 /* Set up hook arguments. */
7373 args
[0] = Qredisplay_end_trigger_functions
;
7374 args
[1] = it
->window
;
7375 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
7376 it
->redisplay_end_trigger_charpos
= 0;
7378 /* Since we are *trying* to run these functions, don't try to run
7379 them again, even if they get an error. */
7380 it
->w
->redisplay_end_trigger
= Qnil
;
7381 Frun_hook_with_args (3, args
);
7383 /* Notice if it changed the face of the character we are on. */
7384 handle_face_prop (it
);
7388 /* Deliver a composition display element. Unlike the other
7389 next_element_from_XXX, this function is not registered in the array
7390 get_next_element[]. It is called from next_element_from_buffer and
7391 next_element_from_string when necessary. */
7394 next_element_from_composition (struct it
*it
)
7396 it
->what
= IT_COMPOSITION
;
7397 it
->len
= it
->cmp_it
.nbytes
;
7398 if (STRINGP (it
->string
))
7402 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7403 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7406 it
->position
= it
->current
.string_pos
;
7407 it
->object
= it
->string
;
7408 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
7409 IT_STRING_BYTEPOS (*it
), it
->string
);
7415 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7416 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7419 if (it
->bidi_it
.new_paragraph
)
7420 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7421 /* Resync the bidi iterator with IT's new position.
7422 FIXME: this doesn't support bidirectional text. */
7423 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
7424 bidi_move_to_visually_next (&it
->bidi_it
);
7428 it
->position
= it
->current
.pos
;
7429 it
->object
= it
->w
->buffer
;
7430 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
7431 IT_BYTEPOS (*it
), Qnil
);
7438 /***********************************************************************
7439 Moving an iterator without producing glyphs
7440 ***********************************************************************/
7442 /* Check if iterator is at a position corresponding to a valid buffer
7443 position after some move_it_ call. */
7445 #define IT_POS_VALID_AFTER_MOVE_P(it) \
7446 ((it)->method == GET_FROM_STRING \
7447 ? IT_STRING_CHARPOS (*it) == 0 \
7451 /* Move iterator IT to a specified buffer or X position within one
7452 line on the display without producing glyphs.
7454 OP should be a bit mask including some or all of these bits:
7455 MOVE_TO_X: Stop upon reaching x-position TO_X.
7456 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
7457 Regardless of OP's value, stop upon reaching the end of the display line.
7459 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
7460 This means, in particular, that TO_X includes window's horizontal
7463 The return value has several possible values that
7464 say what condition caused the scan to stop:
7466 MOVE_POS_MATCH_OR_ZV
7467 - when TO_POS or ZV was reached.
7470 -when TO_X was reached before TO_POS or ZV were reached.
7473 - when we reached the end of the display area and the line must
7477 - when we reached the end of the display area and the line is
7481 - when we stopped at a line end, i.e. a newline or a CR and selective
7484 static enum move_it_result
7485 move_it_in_display_line_to (struct it
*it
,
7486 EMACS_INT to_charpos
, int to_x
,
7487 enum move_operation_enum op
)
7489 enum move_it_result result
= MOVE_UNDEFINED
;
7490 struct glyph_row
*saved_glyph_row
;
7491 struct it wrap_it
, atpos_it
, atx_it
;
7493 enum it_method prev_method
= it
->method
;
7494 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
7496 /* Don't produce glyphs in produce_glyphs. */
7497 saved_glyph_row
= it
->glyph_row
;
7498 it
->glyph_row
= NULL
;
7500 /* Use wrap_it to save a copy of IT wherever a word wrap could
7501 occur. Use atpos_it to save a copy of IT at the desired buffer
7502 position, if found, so that we can scan ahead and check if the
7503 word later overshoots the window edge. Use atx_it similarly, for
7509 #define BUFFER_POS_REACHED_P() \
7510 ((op & MOVE_TO_POS) != 0 \
7511 && BUFFERP (it->object) \
7512 && (IT_CHARPOS (*it) == to_charpos \
7513 || (!it->bidi_p && IT_CHARPOS (*it) > to_charpos)) \
7514 && (it->method == GET_FROM_BUFFER \
7515 || (it->method == GET_FROM_DISPLAY_VECTOR \
7516 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
7518 /* If there's a line-/wrap-prefix, handle it. */
7519 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
7520 && it
->current_y
< it
->last_visible_y
)
7521 handle_line_prefix (it
);
7523 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7524 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7528 int x
, i
, ascent
= 0, descent
= 0;
7530 /* Utility macro to reset an iterator with x, ascent, and descent. */
7531 #define IT_RESET_X_ASCENT_DESCENT(IT) \
7532 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
7533 (IT)->max_descent = descent)
7535 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
7537 if ((op
& MOVE_TO_POS
) != 0
7538 && BUFFERP (it
->object
)
7539 && it
->method
== GET_FROM_BUFFER
7540 && ((!it
->bidi_p
&& IT_CHARPOS (*it
) > to_charpos
)
7542 && (prev_method
== GET_FROM_IMAGE
7543 || prev_method
== GET_FROM_STRETCH
)
7544 /* Passed TO_CHARPOS from left to right. */
7545 && ((prev_pos
< to_charpos
7546 && IT_CHARPOS (*it
) > to_charpos
)
7547 /* Passed TO_CHARPOS from right to left. */
7548 || (prev_pos
> to_charpos
7549 && IT_CHARPOS (*it
) < to_charpos
)))))
7551 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7553 result
= MOVE_POS_MATCH_OR_ZV
;
7556 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7557 /* If wrap_it is valid, the current position might be in a
7558 word that is wrapped. So, save the iterator in
7559 atpos_it and continue to see if wrapping happens. */
7563 prev_method
= it
->method
;
7564 if (it
->method
== GET_FROM_BUFFER
)
7565 prev_pos
= IT_CHARPOS (*it
);
7566 /* Stop when ZV reached.
7567 We used to stop here when TO_CHARPOS reached as well, but that is
7568 too soon if this glyph does not fit on this line. So we handle it
7569 explicitly below. */
7570 if (!get_next_display_element (it
))
7572 result
= MOVE_POS_MATCH_OR_ZV
;
7576 if (it
->line_wrap
== TRUNCATE
)
7578 if (BUFFER_POS_REACHED_P ())
7580 result
= MOVE_POS_MATCH_OR_ZV
;
7586 if (it
->line_wrap
== WORD_WRAP
)
7588 if (IT_DISPLAYING_WHITESPACE (it
))
7592 /* We have reached a glyph that follows one or more
7593 whitespace characters. If the position is
7594 already found, we are done. */
7595 if (atpos_it
.sp
>= 0)
7598 result
= MOVE_POS_MATCH_OR_ZV
;
7604 result
= MOVE_X_REACHED
;
7607 /* Otherwise, we can wrap here. */
7614 /* Remember the line height for the current line, in case
7615 the next element doesn't fit on the line. */
7616 ascent
= it
->max_ascent
;
7617 descent
= it
->max_descent
;
7619 /* The call to produce_glyphs will get the metrics of the
7620 display element IT is loaded with. Record the x-position
7621 before this display element, in case it doesn't fit on the
7625 PRODUCE_GLYPHS (it
);
7627 if (it
->area
!= TEXT_AREA
)
7629 set_iterator_to_next (it
, 1);
7630 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7631 SET_TEXT_POS (this_line_min_pos
,
7632 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7636 /* The number of glyphs we get back in IT->nglyphs will normally
7637 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7638 character on a terminal frame, or (iii) a line end. For the
7639 second case, IT->nglyphs - 1 padding glyphs will be present.
7640 (On X frames, there is only one glyph produced for a
7641 composite character.)
7643 The behavior implemented below means, for continuation lines,
7644 that as many spaces of a TAB as fit on the current line are
7645 displayed there. For terminal frames, as many glyphs of a
7646 multi-glyph character are displayed in the current line, too.
7647 This is what the old redisplay code did, and we keep it that
7648 way. Under X, the whole shape of a complex character must
7649 fit on the line or it will be completely displayed in the
7652 Note that both for tabs and padding glyphs, all glyphs have
7656 /* More than one glyph or glyph doesn't fit on line. All
7657 glyphs have the same width. */
7658 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7660 int x_before_this_char
= x
;
7661 int hpos_before_this_char
= it
->hpos
;
7663 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7665 new_x
= x
+ single_glyph_width
;
7667 /* We want to leave anything reaching TO_X to the caller. */
7668 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7670 if (BUFFER_POS_REACHED_P ())
7672 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7673 goto buffer_pos_reached
;
7674 if (atpos_it
.sp
< 0)
7677 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7682 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7685 result
= MOVE_X_REACHED
;
7691 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7696 if (/* Lines are continued. */
7697 it
->line_wrap
!= TRUNCATE
7698 && (/* And glyph doesn't fit on the line. */
7699 new_x
> it
->last_visible_x
7700 /* Or it fits exactly and we're on a window
7702 || (new_x
== it
->last_visible_x
7703 && FRAME_WINDOW_P (it
->f
))))
7705 if (/* IT->hpos == 0 means the very first glyph
7706 doesn't fit on the line, e.g. a wide image. */
7708 || (new_x
== it
->last_visible_x
7709 && FRAME_WINDOW_P (it
->f
)))
7712 it
->current_x
= new_x
;
7714 /* The character's last glyph just barely fits
7716 if (i
== it
->nglyphs
- 1)
7718 /* If this is the destination position,
7719 return a position *before* it in this row,
7720 now that we know it fits in this row. */
7721 if (BUFFER_POS_REACHED_P ())
7723 if (it
->line_wrap
!= WORD_WRAP
7726 it
->hpos
= hpos_before_this_char
;
7727 it
->current_x
= x_before_this_char
;
7728 result
= MOVE_POS_MATCH_OR_ZV
;
7731 if (it
->line_wrap
== WORD_WRAP
7735 atpos_it
.current_x
= x_before_this_char
;
7736 atpos_it
.hpos
= hpos_before_this_char
;
7740 set_iterator_to_next (it
, 1);
7741 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7742 SET_TEXT_POS (this_line_min_pos
,
7743 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7744 /* On graphical terminals, newlines may
7745 "overflow" into the fringe if
7746 overflow-newline-into-fringe is non-nil.
7747 On text-only terminals, newlines may
7748 overflow into the last glyph on the
7750 if (!FRAME_WINDOW_P (it
->f
)
7751 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7753 if (!get_next_display_element (it
))
7755 result
= MOVE_POS_MATCH_OR_ZV
;
7758 if (BUFFER_POS_REACHED_P ())
7760 if (ITERATOR_AT_END_OF_LINE_P (it
))
7761 result
= MOVE_POS_MATCH_OR_ZV
;
7763 result
= MOVE_LINE_CONTINUED
;
7766 if (ITERATOR_AT_END_OF_LINE_P (it
))
7768 result
= MOVE_NEWLINE_OR_CR
;
7775 IT_RESET_X_ASCENT_DESCENT (it
);
7777 if (wrap_it
.sp
>= 0)
7784 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7786 result
= MOVE_LINE_CONTINUED
;
7790 if (BUFFER_POS_REACHED_P ())
7792 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7793 goto buffer_pos_reached
;
7794 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7797 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7801 if (new_x
> it
->first_visible_x
)
7803 /* Glyph is visible. Increment number of glyphs that
7804 would be displayed. */
7809 if (result
!= MOVE_UNDEFINED
)
7812 else if (BUFFER_POS_REACHED_P ())
7815 IT_RESET_X_ASCENT_DESCENT (it
);
7816 result
= MOVE_POS_MATCH_OR_ZV
;
7819 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7821 /* Stop when TO_X specified and reached. This check is
7822 necessary here because of lines consisting of a line end,
7823 only. The line end will not produce any glyphs and we
7824 would never get MOVE_X_REACHED. */
7825 xassert (it
->nglyphs
== 0);
7826 result
= MOVE_X_REACHED
;
7830 /* Is this a line end? If yes, we're done. */
7831 if (ITERATOR_AT_END_OF_LINE_P (it
))
7833 result
= MOVE_NEWLINE_OR_CR
;
7837 if (it
->method
== GET_FROM_BUFFER
)
7838 prev_pos
= IT_CHARPOS (*it
);
7839 /* The current display element has been consumed. Advance
7841 set_iterator_to_next (it
, 1);
7842 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7843 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7845 /* Stop if lines are truncated and IT's current x-position is
7846 past the right edge of the window now. */
7847 if (it
->line_wrap
== TRUNCATE
7848 && it
->current_x
>= it
->last_visible_x
)
7850 if (!FRAME_WINDOW_P (it
->f
)
7851 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7853 if (!get_next_display_element (it
)
7854 || BUFFER_POS_REACHED_P ())
7856 result
= MOVE_POS_MATCH_OR_ZV
;
7859 if (ITERATOR_AT_END_OF_LINE_P (it
))
7861 result
= MOVE_NEWLINE_OR_CR
;
7865 result
= MOVE_LINE_TRUNCATED
;
7868 #undef IT_RESET_X_ASCENT_DESCENT
7871 #undef BUFFER_POS_REACHED_P
7873 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7874 restore the saved iterator. */
7875 if (atpos_it
.sp
>= 0)
7877 else if (atx_it
.sp
>= 0)
7882 /* Restore the iterator settings altered at the beginning of this
7884 it
->glyph_row
= saved_glyph_row
;
7888 /* For external use. */
7890 move_it_in_display_line (struct it
*it
,
7891 EMACS_INT to_charpos
, int to_x
,
7892 enum move_operation_enum op
)
7894 if (it
->line_wrap
== WORD_WRAP
7895 && (op
& MOVE_TO_X
))
7897 struct it save_it
= *it
;
7898 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7899 /* When word-wrap is on, TO_X may lie past the end
7900 of a wrapped line. Then it->current is the
7901 character on the next line, so backtrack to the
7902 space before the wrap point. */
7903 if (skip
== MOVE_LINE_CONTINUED
)
7905 int prev_x
= max (it
->current_x
- 1, 0);
7907 move_it_in_display_line_to
7908 (it
, -1, prev_x
, MOVE_TO_X
);
7912 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7916 /* Move IT forward until it satisfies one or more of the criteria in
7917 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7919 OP is a bit-mask that specifies where to stop, and in particular,
7920 which of those four position arguments makes a difference. See the
7921 description of enum move_operation_enum.
7923 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7924 screen line, this function will set IT to the next position >
7928 move_it_to (struct it
*it
, EMACS_INT to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
7930 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7931 int line_height
, line_start_x
= 0, reached
= 0;
7935 if (op
& MOVE_TO_VPOS
)
7937 /* If no TO_CHARPOS and no TO_X specified, stop at the
7938 start of the line TO_VPOS. */
7939 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7941 if (it
->vpos
== to_vpos
)
7947 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7951 /* TO_VPOS >= 0 means stop at TO_X in the line at
7952 TO_VPOS, or at TO_POS, whichever comes first. */
7953 if (it
->vpos
== to_vpos
)
7959 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7961 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7966 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7968 /* We have reached TO_X but not in the line we want. */
7969 skip
= move_it_in_display_line_to (it
, to_charpos
,
7971 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7979 else if (op
& MOVE_TO_Y
)
7981 struct it it_backup
;
7983 if (it
->line_wrap
== WORD_WRAP
)
7986 /* TO_Y specified means stop at TO_X in the line containing
7987 TO_Y---or at TO_CHARPOS if this is reached first. The
7988 problem is that we can't really tell whether the line
7989 contains TO_Y before we have completely scanned it, and
7990 this may skip past TO_X. What we do is to first scan to
7993 If TO_X is not specified, use a TO_X of zero. The reason
7994 is to make the outcome of this function more predictable.
7995 If we didn't use TO_X == 0, we would stop at the end of
7996 the line which is probably not what a caller would expect
7998 skip
= move_it_in_display_line_to
7999 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8000 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8002 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8003 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8005 else if (skip
== MOVE_X_REACHED
)
8007 /* If TO_X was reached, we want to know whether TO_Y is
8008 in the line. We know this is the case if the already
8009 scanned glyphs make the line tall enough. Otherwise,
8010 we must check by scanning the rest of the line. */
8011 line_height
= it
->max_ascent
+ it
->max_descent
;
8012 if (to_y
>= it
->current_y
8013 && to_y
< it
->current_y
+ line_height
)
8019 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8020 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8022 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8023 line_height
= it
->max_ascent
+ it
->max_descent
;
8024 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8026 if (to_y
>= it
->current_y
8027 && to_y
< it
->current_y
+ line_height
)
8029 /* If TO_Y is in this line and TO_X was reached
8030 above, we scanned too far. We have to restore
8031 IT's settings to the ones before skipping. */
8038 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8044 /* Check whether TO_Y is in this line. */
8045 line_height
= it
->max_ascent
+ it
->max_descent
;
8046 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8048 if (to_y
>= it
->current_y
8049 && to_y
< it
->current_y
+ line_height
)
8051 /* When word-wrap is on, TO_X may lie past the end
8052 of a wrapped line. Then it->current is the
8053 character on the next line, so backtrack to the
8054 space before the wrap point. */
8055 if (skip
== MOVE_LINE_CONTINUED
8056 && it
->line_wrap
== WORD_WRAP
)
8058 int prev_x
= max (it
->current_x
- 1, 0);
8060 skip
= move_it_in_display_line_to
8061 (it
, -1, prev_x
, MOVE_TO_X
);
8070 else if (BUFFERP (it
->object
)
8071 && (it
->method
== GET_FROM_BUFFER
8072 || it
->method
== GET_FROM_STRETCH
)
8073 && IT_CHARPOS (*it
) >= to_charpos
)
8074 skip
= MOVE_POS_MATCH_OR_ZV
;
8076 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8080 case MOVE_POS_MATCH_OR_ZV
:
8084 case MOVE_NEWLINE_OR_CR
:
8085 set_iterator_to_next (it
, 1);
8086 it
->continuation_lines_width
= 0;
8089 case MOVE_LINE_TRUNCATED
:
8090 it
->continuation_lines_width
= 0;
8091 reseat_at_next_visible_line_start (it
, 0);
8092 if ((op
& MOVE_TO_POS
) != 0
8093 && IT_CHARPOS (*it
) > to_charpos
)
8100 case MOVE_LINE_CONTINUED
:
8101 /* For continued lines ending in a tab, some of the glyphs
8102 associated with the tab are displayed on the current
8103 line. Since it->current_x does not include these glyphs,
8104 we use it->last_visible_x instead. */
8107 it
->continuation_lines_width
+= it
->last_visible_x
;
8108 /* When moving by vpos, ensure that the iterator really
8109 advances to the next line (bug#847, bug#969). Fixme:
8110 do we need to do this in other circumstances? */
8111 if (it
->current_x
!= it
->last_visible_x
8112 && (op
& MOVE_TO_VPOS
)
8113 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8115 line_start_x
= it
->current_x
+ it
->pixel_width
8116 - it
->last_visible_x
;
8117 set_iterator_to_next (it
, 0);
8121 it
->continuation_lines_width
+= it
->current_x
;
8128 /* Reset/increment for the next run. */
8129 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8130 it
->current_x
= line_start_x
;
8133 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8135 last_height
= it
->max_ascent
+ it
->max_descent
;
8136 last_max_ascent
= it
->max_ascent
;
8137 it
->max_ascent
= it
->max_descent
= 0;
8142 /* On text terminals, we may stop at the end of a line in the middle
8143 of a multi-character glyph. If the glyph itself is continued,
8144 i.e. it is actually displayed on the next line, don't treat this
8145 stopping point as valid; move to the next line instead (unless
8146 that brings us offscreen). */
8147 if (!FRAME_WINDOW_P (it
->f
)
8149 && IT_CHARPOS (*it
) == to_charpos
8150 && it
->what
== IT_CHARACTER
8152 && it
->line_wrap
== WINDOW_WRAP
8153 && it
->current_x
== it
->last_visible_x
- 1
8156 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8158 it
->continuation_lines_width
+= it
->current_x
;
8159 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8160 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8162 last_height
= it
->max_ascent
+ it
->max_descent
;
8163 last_max_ascent
= it
->max_ascent
;
8166 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8170 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8172 If DY > 0, move IT backward at least that many pixels. DY = 0
8173 means move IT backward to the preceding line start or BEGV. This
8174 function may move over more than DY pixels if IT->current_y - DY
8175 ends up in the middle of a line; in this case IT->current_y will be
8176 set to the top of the line moved to. */
8179 move_it_vertically_backward (struct it
*it
, int dy
)
8183 EMACS_INT start_pos
;
8188 start_pos
= IT_CHARPOS (*it
);
8190 /* Estimate how many newlines we must move back. */
8191 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8193 /* Set the iterator's position that many lines back. */
8194 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8195 back_to_previous_visible_line_start (it
);
8197 /* Reseat the iterator here. When moving backward, we don't want
8198 reseat to skip forward over invisible text, set up the iterator
8199 to deliver from overlay strings at the new position etc. So,
8200 use reseat_1 here. */
8201 reseat_1 (it
, it
->current
.pos
, 1);
8203 /* We are now surely at a line start. */
8204 it
->current_x
= it
->hpos
= 0;
8205 it
->continuation_lines_width
= 0;
8207 /* Move forward and see what y-distance we moved. First move to the
8208 start of the next line so that we get its height. We need this
8209 height to be able to tell whether we reached the specified
8212 it2
.max_ascent
= it2
.max_descent
= 0;
8215 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8216 MOVE_TO_POS
| MOVE_TO_VPOS
);
8218 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
8219 xassert (IT_CHARPOS (*it
) >= BEGV
);
8222 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
8223 xassert (IT_CHARPOS (*it
) >= BEGV
);
8224 /* H is the actual vertical distance from the position in *IT
8225 and the starting position. */
8226 h
= it2
.current_y
- it
->current_y
;
8227 /* NLINES is the distance in number of lines. */
8228 nlines
= it2
.vpos
- it
->vpos
;
8230 /* Correct IT's y and vpos position
8231 so that they are relative to the starting point. */
8237 /* DY == 0 means move to the start of the screen line. The
8238 value of nlines is > 0 if continuation lines were involved. */
8240 move_it_by_lines (it
, nlines
);
8244 /* The y-position we try to reach, relative to *IT.
8245 Note that H has been subtracted in front of the if-statement. */
8246 int target_y
= it
->current_y
+ h
- dy
;
8247 int y0
= it3
.current_y
;
8248 int y1
= line_bottom_y (&it3
);
8249 int line_height
= y1
- y0
;
8251 /* If we did not reach target_y, try to move further backward if
8252 we can. If we moved too far backward, try to move forward. */
8253 if (target_y
< it
->current_y
8254 /* This is heuristic. In a window that's 3 lines high, with
8255 a line height of 13 pixels each, recentering with point
8256 on the bottom line will try to move -39/2 = 19 pixels
8257 backward. Try to avoid moving into the first line. */
8258 && (it
->current_y
- target_y
8259 > min (window_box_height (it
->w
), line_height
* 2 / 3))
8260 && IT_CHARPOS (*it
) > BEGV
)
8262 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
8263 target_y
- it
->current_y
));
8264 dy
= it
->current_y
- target_y
;
8265 goto move_further_back
;
8267 else if (target_y
>= it
->current_y
+ line_height
8268 && IT_CHARPOS (*it
) < ZV
)
8270 /* Should move forward by at least one line, maybe more.
8272 Note: Calling move_it_by_lines can be expensive on
8273 terminal frames, where compute_motion is used (via
8274 vmotion) to do the job, when there are very long lines
8275 and truncate-lines is nil. That's the reason for
8276 treating terminal frames specially here. */
8278 if (!FRAME_WINDOW_P (it
->f
))
8279 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
8284 move_it_by_lines (it
, 1);
8286 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
8293 /* Move IT by a specified amount of pixel lines DY. DY negative means
8294 move backwards. DY = 0 means move to start of screen line. At the
8295 end, IT will be on the start of a screen line. */
8298 move_it_vertically (struct it
*it
, int dy
)
8301 move_it_vertically_backward (it
, -dy
);
8304 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
8305 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
8306 MOVE_TO_POS
| MOVE_TO_Y
);
8307 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
8309 /* If buffer ends in ZV without a newline, move to the start of
8310 the line to satisfy the post-condition. */
8311 if (IT_CHARPOS (*it
) == ZV
8313 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
8314 move_it_by_lines (it
, 0);
8319 /* Move iterator IT past the end of the text line it is in. */
8322 move_it_past_eol (struct it
*it
)
8324 enum move_it_result rc
;
8326 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
8327 if (rc
== MOVE_NEWLINE_OR_CR
)
8328 set_iterator_to_next (it
, 0);
8332 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
8333 negative means move up. DVPOS == 0 means move to the start of the
8336 Optimization idea: If we would know that IT->f doesn't use
8337 a face with proportional font, we could be faster for
8338 truncate-lines nil. */
8341 move_it_by_lines (struct it
*it
, int dvpos
)
8344 /* The commented-out optimization uses vmotion on terminals. This
8345 gives bad results, because elements like it->what, on which
8346 callers such as pos_visible_p rely, aren't updated. */
8347 /* struct position pos;
8348 if (!FRAME_WINDOW_P (it->f))
8350 struct text_pos textpos;
8352 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
8353 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
8354 reseat (it, textpos, 1);
8355 it->vpos += pos.vpos;
8356 it->current_y += pos.vpos;
8362 /* DVPOS == 0 means move to the start of the screen line. */
8363 move_it_vertically_backward (it
, 0);
8364 xassert (it
->current_x
== 0 && it
->hpos
== 0);
8365 /* Let next call to line_bottom_y calculate real line height */
8370 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
8371 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
8372 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
8377 EMACS_INT start_charpos
, i
;
8379 /* Start at the beginning of the screen line containing IT's
8380 position. This may actually move vertically backwards,
8381 in case of overlays, so adjust dvpos accordingly. */
8383 move_it_vertically_backward (it
, 0);
8386 /* Go back -DVPOS visible lines and reseat the iterator there. */
8387 start_charpos
= IT_CHARPOS (*it
);
8388 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
8389 back_to_previous_visible_line_start (it
);
8390 reseat (it
, it
->current
.pos
, 1);
8392 /* Move further back if we end up in a string or an image. */
8393 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
8395 /* First try to move to start of display line. */
8397 move_it_vertically_backward (it
, 0);
8399 if (IT_POS_VALID_AFTER_MOVE_P (it
))
8401 /* If start of line is still in string or image,
8402 move further back. */
8403 back_to_previous_visible_line_start (it
);
8404 reseat (it
, it
->current
.pos
, 1);
8408 it
->current_x
= it
->hpos
= 0;
8410 /* Above call may have moved too far if continuation lines
8411 are involved. Scan forward and see if it did. */
8413 it2
.vpos
= it2
.current_y
= 0;
8414 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
8415 it
->vpos
-= it2
.vpos
;
8416 it
->current_y
-= it2
.current_y
;
8417 it
->current_x
= it
->hpos
= 0;
8419 /* If we moved too far back, move IT some lines forward. */
8420 if (it2
.vpos
> -dvpos
)
8422 int delta
= it2
.vpos
+ dvpos
;
8424 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
8425 /* Move back again if we got too far ahead. */
8426 if (IT_CHARPOS (*it
) >= start_charpos
)
8432 /* Return 1 if IT points into the middle of a display vector. */
8435 in_display_vector_p (struct it
*it
)
8437 return (it
->method
== GET_FROM_DISPLAY_VECTOR
8438 && it
->current
.dpvec_index
> 0
8439 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
8443 /***********************************************************************
8445 ***********************************************************************/
8448 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
8452 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
8454 Lisp_Object args
[3];
8455 Lisp_Object msg
, fmt
;
8458 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
8461 /* Do nothing if called asynchronously. Inserting text into
8462 a buffer may call after-change-functions and alike and
8463 that would means running Lisp asynchronously. */
8464 if (handling_signal
)
8468 GCPRO4 (fmt
, msg
, arg1
, arg2
);
8470 args
[0] = fmt
= build_string (format
);
8473 msg
= Fformat (3, args
);
8475 len
= SBYTES (msg
) + 1;
8476 SAFE_ALLOCA (buffer
, char *, len
);
8477 memcpy (buffer
, SDATA (msg
), len
);
8479 message_dolog (buffer
, len
- 1, 1, 0);
8486 /* Output a newline in the *Messages* buffer if "needs" one. */
8489 message_log_maybe_newline (void)
8491 if (message_log_need_newline
)
8492 message_dolog ("", 0, 1, 0);
8496 /* Add a string M of length NBYTES to the message log, optionally
8497 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
8498 nonzero, means interpret the contents of M as multibyte. This
8499 function calls low-level routines in order to bypass text property
8500 hooks, etc. which might not be safe to run.
8502 This may GC (insert may run before/after change hooks),
8503 so the buffer M must NOT point to a Lisp string. */
8506 message_dolog (const char *m
, EMACS_INT nbytes
, int nlflag
, int multibyte
)
8508 const unsigned char *msg
= (const unsigned char *) m
;
8510 if (!NILP (Vmemory_full
))
8513 if (!NILP (Vmessage_log_max
))
8515 struct buffer
*oldbuf
;
8516 Lisp_Object oldpoint
, oldbegv
, oldzv
;
8517 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
8518 EMACS_INT point_at_end
= 0;
8519 EMACS_INT zv_at_end
= 0;
8520 Lisp_Object old_deactivate_mark
, tem
;
8521 struct gcpro gcpro1
;
8523 old_deactivate_mark
= Vdeactivate_mark
;
8524 oldbuf
= current_buffer
;
8525 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
8526 BVAR (current_buffer
, undo_list
) = Qt
;
8528 oldpoint
= message_dolog_marker1
;
8529 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
8530 oldbegv
= message_dolog_marker2
;
8531 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
8532 oldzv
= message_dolog_marker3
;
8533 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
8534 GCPRO1 (old_deactivate_mark
);
8542 BEGV_BYTE
= BEG_BYTE
;
8545 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8547 /* Insert the string--maybe converting multibyte to single byte
8548 or vice versa, so that all the text fits the buffer. */
8550 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8556 /* Convert a multibyte string to single-byte
8557 for the *Message* buffer. */
8558 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
8560 c
= string_char_and_length (msg
+ i
, &char_bytes
);
8561 work
[0] = (ASCII_CHAR_P (c
)
8563 : multibyte_char_to_unibyte (c
));
8564 insert_1_both (work
, 1, 1, 1, 0, 0);
8567 else if (! multibyte
8568 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8572 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8573 /* Convert a single-byte string to multibyte
8574 for the *Message* buffer. */
8575 for (i
= 0; i
< nbytes
; i
++)
8578 MAKE_CHAR_MULTIBYTE (c
);
8579 char_bytes
= CHAR_STRING (c
, str
);
8580 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
8584 insert_1 (m
, nbytes
, 1, 0, 0);
8588 EMACS_INT this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
8589 unsigned long int dups
;
8590 insert_1 ("\n", 1, 1, 0, 0);
8592 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8594 this_bol_byte
= PT_BYTE
;
8596 /* See if this line duplicates the previous one.
8597 If so, combine duplicates. */
8600 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8602 prev_bol_byte
= PT_BYTE
;
8604 dups
= message_log_check_duplicate (prev_bol_byte
,
8608 del_range_both (prev_bol
, prev_bol_byte
,
8609 this_bol
, this_bol_byte
, 0);
8615 /* If you change this format, don't forget to also
8616 change message_log_check_duplicate. */
8617 sprintf (dupstr
, " [%lu times]", dups
);
8618 duplen
= strlen (dupstr
);
8619 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8620 insert_1 (dupstr
, duplen
, 1, 0, 1);
8625 /* If we have more than the desired maximum number of lines
8626 in the *Messages* buffer now, delete the oldest ones.
8627 This is safe because we don't have undo in this buffer. */
8629 if (NATNUMP (Vmessage_log_max
))
8631 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8632 -XFASTINT (Vmessage_log_max
) - 1, 0);
8633 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8636 BEGV
= XMARKER (oldbegv
)->charpos
;
8637 BEGV_BYTE
= marker_byte_position (oldbegv
);
8646 ZV
= XMARKER (oldzv
)->charpos
;
8647 ZV_BYTE
= marker_byte_position (oldzv
);
8651 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8653 /* We can't do Fgoto_char (oldpoint) because it will run some
8655 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8656 XMARKER (oldpoint
)->bytepos
);
8659 unchain_marker (XMARKER (oldpoint
));
8660 unchain_marker (XMARKER (oldbegv
));
8661 unchain_marker (XMARKER (oldzv
));
8663 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8664 set_buffer_internal (oldbuf
);
8666 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8667 message_log_need_newline
= !nlflag
;
8668 Vdeactivate_mark
= old_deactivate_mark
;
8673 /* We are at the end of the buffer after just having inserted a newline.
8674 (Note: We depend on the fact we won't be crossing the gap.)
8675 Check to see if the most recent message looks a lot like the previous one.
8676 Return 0 if different, 1 if the new one should just replace it, or a
8677 value N > 1 if we should also append " [N times]". */
8679 static unsigned long int
8680 message_log_check_duplicate (EMACS_INT prev_bol_byte
, EMACS_INT this_bol_byte
)
8683 EMACS_INT len
= Z_BYTE
- 1 - this_bol_byte
;
8685 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8686 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8688 for (i
= 0; i
< len
; i
++)
8690 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8698 if (*p1
++ == ' ' && *p1
++ == '[')
8701 unsigned long int n
= strtoul ((char *) p1
, &pend
, 10);
8702 if (strncmp (pend
, " times]\n", 8) == 0)
8709 /* Display an echo area message M with a specified length of NBYTES
8710 bytes. The string may include null characters. If M is 0, clear
8711 out any existing message, and let the mini-buffer text show
8714 This may GC, so the buffer M must NOT point to a Lisp string. */
8717 message2 (const char *m
, EMACS_INT nbytes
, int multibyte
)
8719 /* First flush out any partial line written with print. */
8720 message_log_maybe_newline ();
8722 message_dolog (m
, nbytes
, 1, multibyte
);
8723 message2_nolog (m
, nbytes
, multibyte
);
8727 /* The non-logging counterpart of message2. */
8730 message2_nolog (const char *m
, EMACS_INT nbytes
, int multibyte
)
8732 struct frame
*sf
= SELECTED_FRAME ();
8733 message_enable_multibyte
= multibyte
;
8735 if (FRAME_INITIAL_P (sf
))
8737 if (noninteractive_need_newline
)
8738 putc ('\n', stderr
);
8739 noninteractive_need_newline
= 0;
8741 fwrite (m
, nbytes
, 1, stderr
);
8742 if (cursor_in_echo_area
== 0)
8743 fprintf (stderr
, "\n");
8746 /* A null message buffer means that the frame hasn't really been
8747 initialized yet. Error messages get reported properly by
8748 cmd_error, so this must be just an informative message; toss it. */
8749 else if (INTERACTIVE
8750 && sf
->glyphs_initialized_p
8751 && FRAME_MESSAGE_BUF (sf
))
8753 Lisp_Object mini_window
;
8756 /* Get the frame containing the mini-buffer
8757 that the selected frame is using. */
8758 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8759 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8761 FRAME_SAMPLE_VISIBILITY (f
);
8762 if (FRAME_VISIBLE_P (sf
)
8763 && ! FRAME_VISIBLE_P (f
))
8764 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8768 set_message (m
, Qnil
, nbytes
, multibyte
);
8769 if (minibuffer_auto_raise
)
8770 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8773 clear_message (1, 1);
8775 do_pending_window_change (0);
8776 echo_area_display (1);
8777 do_pending_window_change (0);
8778 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8779 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8784 /* Display an echo area message M with a specified length of NBYTES
8785 bytes. The string may include null characters. If M is not a
8786 string, clear out any existing message, and let the mini-buffer
8789 This function cancels echoing. */
8792 message3 (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8794 struct gcpro gcpro1
;
8797 clear_message (1,1);
8800 /* First flush out any partial line written with print. */
8801 message_log_maybe_newline ();
8807 SAFE_ALLOCA (buffer
, char *, nbytes
);
8808 memcpy (buffer
, SDATA (m
), nbytes
);
8809 message_dolog (buffer
, nbytes
, 1, multibyte
);
8812 message3_nolog (m
, nbytes
, multibyte
);
8818 /* The non-logging version of message3.
8819 This does not cancel echoing, because it is used for echoing.
8820 Perhaps we need to make a separate function for echoing
8821 and make this cancel echoing. */
8824 message3_nolog (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8826 struct frame
*sf
= SELECTED_FRAME ();
8827 message_enable_multibyte
= multibyte
;
8829 if (FRAME_INITIAL_P (sf
))
8831 if (noninteractive_need_newline
)
8832 putc ('\n', stderr
);
8833 noninteractive_need_newline
= 0;
8835 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8836 if (cursor_in_echo_area
== 0)
8837 fprintf (stderr
, "\n");
8840 /* A null message buffer means that the frame hasn't really been
8841 initialized yet. Error messages get reported properly by
8842 cmd_error, so this must be just an informative message; toss it. */
8843 else if (INTERACTIVE
8844 && sf
->glyphs_initialized_p
8845 && FRAME_MESSAGE_BUF (sf
))
8847 Lisp_Object mini_window
;
8851 /* Get the frame containing the mini-buffer
8852 that the selected frame is using. */
8853 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8854 frame
= XWINDOW (mini_window
)->frame
;
8857 FRAME_SAMPLE_VISIBILITY (f
);
8858 if (FRAME_VISIBLE_P (sf
)
8859 && !FRAME_VISIBLE_P (f
))
8860 Fmake_frame_visible (frame
);
8862 if (STRINGP (m
) && SCHARS (m
) > 0)
8864 set_message (NULL
, m
, nbytes
, multibyte
);
8865 if (minibuffer_auto_raise
)
8866 Fraise_frame (frame
);
8867 /* Assume we are not echoing.
8868 (If we are, echo_now will override this.) */
8869 echo_message_buffer
= Qnil
;
8872 clear_message (1, 1);
8874 do_pending_window_change (0);
8875 echo_area_display (1);
8876 do_pending_window_change (0);
8877 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8878 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8883 /* Display a null-terminated echo area message M. If M is 0, clear
8884 out any existing message, and let the mini-buffer text show through.
8886 The buffer M must continue to exist until after the echo area gets
8887 cleared or some other message gets displayed there. Do not pass
8888 text that is stored in a Lisp string. Do not pass text in a buffer
8889 that was alloca'd. */
8892 message1 (const char *m
)
8894 message2 (m
, (m
? strlen (m
) : 0), 0);
8898 /* The non-logging counterpart of message1. */
8901 message1_nolog (const char *m
)
8903 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8906 /* Display a message M which contains a single %s
8907 which gets replaced with STRING. */
8910 message_with_string (const char *m
, Lisp_Object string
, int log
)
8912 CHECK_STRING (string
);
8918 if (noninteractive_need_newline
)
8919 putc ('\n', stderr
);
8920 noninteractive_need_newline
= 0;
8921 fprintf (stderr
, m
, SDATA (string
));
8922 if (!cursor_in_echo_area
)
8923 fprintf (stderr
, "\n");
8927 else if (INTERACTIVE
)
8929 /* The frame whose minibuffer we're going to display the message on.
8930 It may be larger than the selected frame, so we need
8931 to use its buffer, not the selected frame's buffer. */
8932 Lisp_Object mini_window
;
8933 struct frame
*f
, *sf
= SELECTED_FRAME ();
8935 /* Get the frame containing the minibuffer
8936 that the selected frame is using. */
8937 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8938 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8940 /* A null message buffer means that the frame hasn't really been
8941 initialized yet. Error messages get reported properly by
8942 cmd_error, so this must be just an informative message; toss it. */
8943 if (FRAME_MESSAGE_BUF (f
))
8945 Lisp_Object args
[2], msg
;
8946 struct gcpro gcpro1
, gcpro2
;
8948 args
[0] = build_string (m
);
8949 args
[1] = msg
= string
;
8950 GCPRO2 (args
[0], msg
);
8953 msg
= Fformat (2, args
);
8956 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8958 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8962 /* Print should start at the beginning of the message
8963 buffer next time. */
8964 message_buf_print
= 0;
8970 /* Dump an informative message to the minibuf. If M is 0, clear out
8971 any existing message, and let the mini-buffer text show through. */
8974 vmessage (const char *m
, va_list ap
)
8980 if (noninteractive_need_newline
)
8981 putc ('\n', stderr
);
8982 noninteractive_need_newline
= 0;
8983 vfprintf (stderr
, m
, ap
);
8984 if (cursor_in_echo_area
== 0)
8985 fprintf (stderr
, "\n");
8989 else if (INTERACTIVE
)
8991 /* The frame whose mini-buffer we're going to display the message
8992 on. It may be larger than the selected frame, so we need to
8993 use its buffer, not the selected frame's buffer. */
8994 Lisp_Object mini_window
;
8995 struct frame
*f
, *sf
= SELECTED_FRAME ();
8997 /* Get the frame containing the mini-buffer
8998 that the selected frame is using. */
8999 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9000 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9002 /* A null message buffer means that the frame hasn't really been
9003 initialized yet. Error messages get reported properly by
9004 cmd_error, so this must be just an informative message; toss
9006 if (FRAME_MESSAGE_BUF (f
))
9012 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9013 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9015 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
9020 /* Print should start at the beginning of the message
9021 buffer next time. */
9022 message_buf_print
= 0;
9028 message (const char *m
, ...)
9038 /* The non-logging version of message. */
9041 message_nolog (const char *m
, ...)
9043 Lisp_Object old_log_max
;
9046 old_log_max
= Vmessage_log_max
;
9047 Vmessage_log_max
= Qnil
;
9049 Vmessage_log_max
= old_log_max
;
9055 /* Display the current message in the current mini-buffer. This is
9056 only called from error handlers in process.c, and is not time
9060 update_echo_area (void)
9062 if (!NILP (echo_area_buffer
[0]))
9065 string
= Fcurrent_message ();
9066 message3 (string
, SBYTES (string
),
9067 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9072 /* Make sure echo area buffers in `echo_buffers' are live.
9073 If they aren't, make new ones. */
9076 ensure_echo_area_buffers (void)
9080 for (i
= 0; i
< 2; ++i
)
9081 if (!BUFFERP (echo_buffer
[i
])
9082 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
9085 Lisp_Object old_buffer
;
9088 old_buffer
= echo_buffer
[i
];
9089 sprintf (name
, " *Echo Area %d*", i
);
9090 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
9091 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
9092 /* to force word wrap in echo area -
9093 it was decided to postpone this*/
9094 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9096 for (j
= 0; j
< 2; ++j
)
9097 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9098 echo_area_buffer
[j
] = echo_buffer
[i
];
9103 /* Call FN with args A1..A4 with either the current or last displayed
9104 echo_area_buffer as current buffer.
9106 WHICH zero means use the current message buffer
9107 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9108 from echo_buffer[] and clear it.
9110 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9111 suitable buffer from echo_buffer[] and clear it.
9113 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9114 that the current message becomes the last displayed one, make
9115 choose a suitable buffer for echo_area_buffer[0], and clear it.
9117 Value is what FN returns. */
9120 with_echo_area_buffer (struct window
*w
, int which
,
9121 int (*fn
) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
9122 EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9125 int this_one
, the_other
, clear_buffer_p
, rc
;
9126 int count
= SPECPDL_INDEX ();
9128 /* If buffers aren't live, make new ones. */
9129 ensure_echo_area_buffers ();
9134 this_one
= 0, the_other
= 1;
9136 this_one
= 1, the_other
= 0;
9139 this_one
= 0, the_other
= 1;
9142 /* We need a fresh one in case the current echo buffer equals
9143 the one containing the last displayed echo area message. */
9144 if (!NILP (echo_area_buffer
[this_one
])
9145 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9146 echo_area_buffer
[this_one
] = Qnil
;
9149 /* Choose a suitable buffer from echo_buffer[] is we don't
9151 if (NILP (echo_area_buffer
[this_one
]))
9153 echo_area_buffer
[this_one
]
9154 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9155 ? echo_buffer
[the_other
]
9156 : echo_buffer
[this_one
]);
9160 buffer
= echo_area_buffer
[this_one
];
9162 /* Don't get confused by reusing the buffer used for echoing
9163 for a different purpose. */
9164 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9167 record_unwind_protect (unwind_with_echo_area_buffer
,
9168 with_echo_area_buffer_unwind_data (w
));
9170 /* Make the echo area buffer current. Note that for display
9171 purposes, it is not necessary that the displayed window's buffer
9172 == current_buffer, except for text property lookup. So, let's
9173 only set that buffer temporarily here without doing a full
9174 Fset_window_buffer. We must also change w->pointm, though,
9175 because otherwise an assertions in unshow_buffer fails, and Emacs
9177 set_buffer_internal_1 (XBUFFER (buffer
));
9181 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9184 BVAR (current_buffer
, undo_list
) = Qt
;
9185 BVAR (current_buffer
, read_only
) = Qnil
;
9186 specbind (Qinhibit_read_only
, Qt
);
9187 specbind (Qinhibit_modification_hooks
, Qt
);
9189 if (clear_buffer_p
&& Z
> BEG
)
9192 xassert (BEGV
>= BEG
);
9193 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9195 rc
= fn (a1
, a2
, a3
, a4
);
9197 xassert (BEGV
>= BEG
);
9198 xassert (ZV
<= Z
&& ZV
>= BEGV
);
9200 unbind_to (count
, Qnil
);
9205 /* Save state that should be preserved around the call to the function
9206 FN called in with_echo_area_buffer. */
9209 with_echo_area_buffer_unwind_data (struct window
*w
)
9212 Lisp_Object vector
, tmp
;
9214 /* Reduce consing by keeping one vector in
9215 Vwith_echo_area_save_vector. */
9216 vector
= Vwith_echo_area_save_vector
;
9217 Vwith_echo_area_save_vector
= Qnil
;
9220 vector
= Fmake_vector (make_number (7), Qnil
);
9222 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9223 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9224 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
9228 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
9229 ASET (vector
, i
, w
->buffer
); ++i
;
9230 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
9231 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
9236 for (; i
< end
; ++i
)
9237 ASET (vector
, i
, Qnil
);
9240 xassert (i
== ASIZE (vector
));
9245 /* Restore global state from VECTOR which was created by
9246 with_echo_area_buffer_unwind_data. */
9249 unwind_with_echo_area_buffer (Lisp_Object vector
)
9251 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
9252 Vdeactivate_mark
= AREF (vector
, 1);
9253 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
9255 if (WINDOWP (AREF (vector
, 3)))
9258 Lisp_Object buffer
, charpos
, bytepos
;
9260 w
= XWINDOW (AREF (vector
, 3));
9261 buffer
= AREF (vector
, 4);
9262 charpos
= AREF (vector
, 5);
9263 bytepos
= AREF (vector
, 6);
9266 set_marker_both (w
->pointm
, buffer
,
9267 XFASTINT (charpos
), XFASTINT (bytepos
));
9270 Vwith_echo_area_save_vector
= vector
;
9275 /* Set up the echo area for use by print functions. MULTIBYTE_P
9276 non-zero means we will print multibyte. */
9279 setup_echo_area_for_printing (int multibyte_p
)
9281 /* If we can't find an echo area any more, exit. */
9282 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9285 ensure_echo_area_buffers ();
9287 if (!message_buf_print
)
9289 /* A message has been output since the last time we printed.
9290 Choose a fresh echo area buffer. */
9291 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9292 echo_area_buffer
[0] = echo_buffer
[1];
9294 echo_area_buffer
[0] = echo_buffer
[0];
9296 /* Switch to that buffer and clear it. */
9297 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9298 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9302 int count
= SPECPDL_INDEX ();
9303 specbind (Qinhibit_read_only
, Qt
);
9304 /* Note that undo recording is always disabled. */
9306 unbind_to (count
, Qnil
);
9308 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9310 /* Set up the buffer for the multibyteness we need. */
9312 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9313 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
9315 /* Raise the frame containing the echo area. */
9316 if (minibuffer_auto_raise
)
9318 struct frame
*sf
= SELECTED_FRAME ();
9319 Lisp_Object mini_window
;
9320 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9321 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9324 message_log_maybe_newline ();
9325 message_buf_print
= 1;
9329 if (NILP (echo_area_buffer
[0]))
9331 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
9332 echo_area_buffer
[0] = echo_buffer
[1];
9334 echo_area_buffer
[0] = echo_buffer
[0];
9337 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
9339 /* Someone switched buffers between print requests. */
9340 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
9341 BVAR (current_buffer
, truncate_lines
) = Qnil
;
9347 /* Display an echo area message in window W. Value is non-zero if W's
9348 height is changed. If display_last_displayed_message_p is
9349 non-zero, display the message that was last displayed, otherwise
9350 display the current message. */
9353 display_echo_area (struct window
*w
)
9355 int i
, no_message_p
, window_height_changed_p
, count
;
9357 /* Temporarily disable garbage collections while displaying the echo
9358 area. This is done because a GC can print a message itself.
9359 That message would modify the echo area buffer's contents while a
9360 redisplay of the buffer is going on, and seriously confuse
9362 count
= inhibit_garbage_collection ();
9364 /* If there is no message, we must call display_echo_area_1
9365 nevertheless because it resizes the window. But we will have to
9366 reset the echo_area_buffer in question to nil at the end because
9367 with_echo_area_buffer will sets it to an empty buffer. */
9368 i
= display_last_displayed_message_p
? 1 : 0;
9369 no_message_p
= NILP (echo_area_buffer
[i
]);
9371 window_height_changed_p
9372 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
9373 display_echo_area_1
,
9374 (intptr_t) w
, Qnil
, 0, 0);
9377 echo_area_buffer
[i
] = Qnil
;
9379 unbind_to (count
, Qnil
);
9380 return window_height_changed_p
;
9384 /* Helper for display_echo_area. Display the current buffer which
9385 contains the current echo area message in window W, a mini-window,
9386 a pointer to which is passed in A1. A2..A4 are currently not used.
9387 Change the height of W so that all of the message is displayed.
9388 Value is non-zero if height of W was changed. */
9391 display_echo_area_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9394 struct window
*w
= (struct window
*) i1
;
9396 struct text_pos start
;
9397 int window_height_changed_p
= 0;
9399 /* Do this before displaying, so that we have a large enough glyph
9400 matrix for the display. If we can't get enough space for the
9401 whole text, display the last N lines. That works by setting w->start. */
9402 window_height_changed_p
= resize_mini_window (w
, 0);
9404 /* Use the starting position chosen by resize_mini_window. */
9405 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
9408 clear_glyph_matrix (w
->desired_matrix
);
9409 XSETWINDOW (window
, w
);
9410 try_window (window
, start
, 0);
9412 return window_height_changed_p
;
9416 /* Resize the echo area window to exactly the size needed for the
9417 currently displayed message, if there is one. If a mini-buffer
9418 is active, don't shrink it. */
9421 resize_echo_area_exactly (void)
9423 if (BUFFERP (echo_area_buffer
[0])
9424 && WINDOWP (echo_area_window
))
9426 struct window
*w
= XWINDOW (echo_area_window
);
9428 Lisp_Object resize_exactly
;
9430 if (minibuf_level
== 0)
9431 resize_exactly
= Qt
;
9433 resize_exactly
= Qnil
;
9435 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
9436 (intptr_t) w
, resize_exactly
,
9440 ++windows_or_buffers_changed
;
9441 ++update_mode_lines
;
9442 redisplay_internal ();
9448 /* Callback function for with_echo_area_buffer, when used from
9449 resize_echo_area_exactly. A1 contains a pointer to the window to
9450 resize, EXACTLY non-nil means resize the mini-window exactly to the
9451 size of the text displayed. A3 and A4 are not used. Value is what
9452 resize_mini_window returns. */
9455 resize_mini_window_1 (EMACS_INT a1
, Lisp_Object exactly
, EMACS_INT a3
, EMACS_INT a4
)
9458 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
9462 /* Resize mini-window W to fit the size of its contents. EXACT_P
9463 means size the window exactly to the size needed. Otherwise, it's
9464 only enlarged until W's buffer is empty.
9466 Set W->start to the right place to begin display. If the whole
9467 contents fit, start at the beginning. Otherwise, start so as
9468 to make the end of the contents appear. This is particularly
9469 important for y-or-n-p, but seems desirable generally.
9471 Value is non-zero if the window height has been changed. */
9474 resize_mini_window (struct window
*w
, int exact_p
)
9476 struct frame
*f
= XFRAME (w
->frame
);
9477 int window_height_changed_p
= 0;
9479 xassert (MINI_WINDOW_P (w
));
9481 /* By default, start display at the beginning. */
9482 set_marker_both (w
->start
, w
->buffer
,
9483 BUF_BEGV (XBUFFER (w
->buffer
)),
9484 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
9486 /* Don't resize windows while redisplaying a window; it would
9487 confuse redisplay functions when the size of the window they are
9488 displaying changes from under them. Such a resizing can happen,
9489 for instance, when which-func prints a long message while
9490 we are running fontification-functions. We're running these
9491 functions with safe_call which binds inhibit-redisplay to t. */
9492 if (!NILP (Vinhibit_redisplay
))
9495 /* Nil means don't try to resize. */
9496 if (NILP (Vresize_mini_windows
)
9497 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
9500 if (!FRAME_MINIBUF_ONLY_P (f
))
9503 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
9504 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
9505 int height
, max_height
;
9506 int unit
= FRAME_LINE_HEIGHT (f
);
9507 struct text_pos start
;
9508 struct buffer
*old_current_buffer
= NULL
;
9510 if (current_buffer
!= XBUFFER (w
->buffer
))
9512 old_current_buffer
= current_buffer
;
9513 set_buffer_internal (XBUFFER (w
->buffer
));
9516 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9518 /* Compute the max. number of lines specified by the user. */
9519 if (FLOATP (Vmax_mini_window_height
))
9520 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
9521 else if (INTEGERP (Vmax_mini_window_height
))
9522 max_height
= XINT (Vmax_mini_window_height
);
9524 max_height
= total_height
/ 4;
9526 /* Correct that max. height if it's bogus. */
9527 max_height
= max (1, max_height
);
9528 max_height
= min (total_height
, max_height
);
9530 /* Find out the height of the text in the window. */
9531 if (it
.line_wrap
== TRUNCATE
)
9536 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
9537 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
9538 height
= it
.current_y
+ last_height
;
9540 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9541 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9542 height
= (height
+ unit
- 1) / unit
;
9545 /* Compute a suitable window start. */
9546 if (height
> max_height
)
9548 height
= max_height
;
9549 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9550 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9551 start
= it
.current
.pos
;
9554 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9555 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9557 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9559 /* Let it grow only, until we display an empty message, in which
9560 case the window shrinks again. */
9561 if (height
> WINDOW_TOTAL_LINES (w
))
9563 int old_height
= WINDOW_TOTAL_LINES (w
);
9564 freeze_window_starts (f
, 1);
9565 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9566 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9568 else if (height
< WINDOW_TOTAL_LINES (w
)
9569 && (exact_p
|| BEGV
== ZV
))
9571 int old_height
= WINDOW_TOTAL_LINES (w
);
9572 freeze_window_starts (f
, 0);
9573 shrink_mini_window (w
);
9574 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9579 /* Always resize to exact size needed. */
9580 if (height
> WINDOW_TOTAL_LINES (w
))
9582 int old_height
= WINDOW_TOTAL_LINES (w
);
9583 freeze_window_starts (f
, 1);
9584 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9585 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9587 else if (height
< WINDOW_TOTAL_LINES (w
))
9589 int old_height
= WINDOW_TOTAL_LINES (w
);
9590 freeze_window_starts (f
, 0);
9591 shrink_mini_window (w
);
9595 freeze_window_starts (f
, 1);
9596 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9599 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9603 if (old_current_buffer
)
9604 set_buffer_internal (old_current_buffer
);
9607 return window_height_changed_p
;
9611 /* Value is the current message, a string, or nil if there is no
9615 current_message (void)
9619 if (!BUFFERP (echo_area_buffer
[0]))
9623 with_echo_area_buffer (0, 0, current_message_1
,
9624 (intptr_t) &msg
, Qnil
, 0, 0);
9626 echo_area_buffer
[0] = Qnil
;
9634 current_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9637 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
9640 *msg
= make_buffer_string (BEG
, Z
, 1);
9647 /* Push the current message on Vmessage_stack for later restauration
9648 by restore_message. Value is non-zero if the current message isn't
9649 empty. This is a relatively infrequent operation, so it's not
9650 worth optimizing. */
9656 msg
= current_message ();
9657 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9658 return STRINGP (msg
);
9662 /* Restore message display from the top of Vmessage_stack. */
9665 restore_message (void)
9669 xassert (CONSP (Vmessage_stack
));
9670 msg
= XCAR (Vmessage_stack
);
9672 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9674 message3_nolog (msg
, 0, 0);
9678 /* Handler for record_unwind_protect calling pop_message. */
9681 pop_message_unwind (Lisp_Object dummy
)
9687 /* Pop the top-most entry off Vmessage_stack. */
9692 xassert (CONSP (Vmessage_stack
));
9693 Vmessage_stack
= XCDR (Vmessage_stack
);
9697 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9698 exits. If the stack is not empty, we have a missing pop_message
9702 check_message_stack (void)
9704 if (!NILP (Vmessage_stack
))
9709 /* Truncate to NCHARS what will be displayed in the echo area the next
9710 time we display it---but don't redisplay it now. */
9713 truncate_echo_area (EMACS_INT nchars
)
9716 echo_area_buffer
[0] = Qnil
;
9717 /* A null message buffer means that the frame hasn't really been
9718 initialized yet. Error messages get reported properly by
9719 cmd_error, so this must be just an informative message; toss it. */
9720 else if (!noninteractive
9722 && !NILP (echo_area_buffer
[0]))
9724 struct frame
*sf
= SELECTED_FRAME ();
9725 if (FRAME_MESSAGE_BUF (sf
))
9726 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9731 /* Helper function for truncate_echo_area. Truncate the current
9732 message to at most NCHARS characters. */
9735 truncate_message_1 (EMACS_INT nchars
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9737 if (BEG
+ nchars
< Z
)
9738 del_range (BEG
+ nchars
, Z
);
9740 echo_area_buffer
[0] = Qnil
;
9745 /* Set the current message to a substring of S or STRING.
9747 If STRING is a Lisp string, set the message to the first NBYTES
9748 bytes from STRING. NBYTES zero means use the whole string. If
9749 STRING is multibyte, the message will be displayed multibyte.
9751 If S is not null, set the message to the first LEN bytes of S. LEN
9752 zero means use the whole string. MULTIBYTE_P non-zero means S is
9753 multibyte. Display the message multibyte in that case.
9755 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9756 to t before calling set_message_1 (which calls insert).
9760 set_message (const char *s
, Lisp_Object string
,
9761 EMACS_INT nbytes
, int multibyte_p
)
9763 message_enable_multibyte
9764 = ((s
&& multibyte_p
)
9765 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9767 with_echo_area_buffer (0, -1, set_message_1
,
9768 (intptr_t) s
, string
, nbytes
, multibyte_p
);
9769 message_buf_print
= 0;
9770 help_echo_showing_p
= 0;
9774 /* Helper function for set_message. Arguments have the same meaning
9775 as there, with A1 corresponding to S and A2 corresponding to STRING
9776 This function is called with the echo area buffer being
9780 set_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT nbytes
, EMACS_INT multibyte_p
)
9783 const char *s
= (const char *) i1
;
9784 const unsigned char *msg
= (const unsigned char *) s
;
9785 Lisp_Object string
= a2
;
9787 /* Change multibyteness of the echo buffer appropriately. */
9788 if (message_enable_multibyte
9789 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9790 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9792 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
9793 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
9794 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
9796 /* Insert new message at BEG. */
9797 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9799 if (STRINGP (string
))
9804 nbytes
= SBYTES (string
);
9805 nchars
= string_byte_to_char (string
, nbytes
);
9807 /* This function takes care of single/multibyte conversion. We
9808 just have to ensure that the echo area buffer has the right
9809 setting of enable_multibyte_characters. */
9810 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9815 nbytes
= strlen (s
);
9817 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9819 /* Convert from multi-byte to single-byte. */
9824 /* Convert a multibyte string to single-byte. */
9825 for (i
= 0; i
< nbytes
; i
+= n
)
9827 c
= string_char_and_length (msg
+ i
, &n
);
9828 work
[0] = (ASCII_CHAR_P (c
)
9830 : multibyte_char_to_unibyte (c
));
9831 insert_1_both (work
, 1, 1, 1, 0, 0);
9834 else if (!multibyte_p
9835 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9837 /* Convert from single-byte to multi-byte. */
9840 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9842 /* Convert a single-byte string to multibyte. */
9843 for (i
= 0; i
< nbytes
; i
++)
9846 MAKE_CHAR_MULTIBYTE (c
);
9847 n
= CHAR_STRING (c
, str
);
9848 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
9852 insert_1 (s
, nbytes
, 1, 0, 0);
9859 /* Clear messages. CURRENT_P non-zero means clear the current
9860 message. LAST_DISPLAYED_P non-zero means clear the message
9864 clear_message (int current_p
, int last_displayed_p
)
9868 echo_area_buffer
[0] = Qnil
;
9869 message_cleared_p
= 1;
9872 if (last_displayed_p
)
9873 echo_area_buffer
[1] = Qnil
;
9875 message_buf_print
= 0;
9878 /* Clear garbaged frames.
9880 This function is used where the old redisplay called
9881 redraw_garbaged_frames which in turn called redraw_frame which in
9882 turn called clear_frame. The call to clear_frame was a source of
9883 flickering. I believe a clear_frame is not necessary. It should
9884 suffice in the new redisplay to invalidate all current matrices,
9885 and ensure a complete redisplay of all windows. */
9888 clear_garbaged_frames (void)
9892 Lisp_Object tail
, frame
;
9893 int changed_count
= 0;
9895 FOR_EACH_FRAME (tail
, frame
)
9897 struct frame
*f
= XFRAME (frame
);
9899 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9903 Fredraw_frame (frame
);
9904 f
->force_flush_display_p
= 1;
9906 clear_current_matrices (f
);
9915 ++windows_or_buffers_changed
;
9920 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9921 is non-zero update selected_frame. Value is non-zero if the
9922 mini-windows height has been changed. */
9925 echo_area_display (int update_frame_p
)
9927 Lisp_Object mini_window
;
9930 int window_height_changed_p
= 0;
9931 struct frame
*sf
= SELECTED_FRAME ();
9933 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9934 w
= XWINDOW (mini_window
);
9935 f
= XFRAME (WINDOW_FRAME (w
));
9937 /* Don't display if frame is invisible or not yet initialized. */
9938 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9941 #ifdef HAVE_WINDOW_SYSTEM
9942 /* When Emacs starts, selected_frame may be the initial terminal
9943 frame. If we let this through, a message would be displayed on
9945 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9947 #endif /* HAVE_WINDOW_SYSTEM */
9949 /* Redraw garbaged frames. */
9951 clear_garbaged_frames ();
9953 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9955 echo_area_window
= mini_window
;
9956 window_height_changed_p
= display_echo_area (w
);
9957 w
->must_be_updated_p
= 1;
9959 /* Update the display, unless called from redisplay_internal.
9960 Also don't update the screen during redisplay itself. The
9961 update will happen at the end of redisplay, and an update
9962 here could cause confusion. */
9963 if (update_frame_p
&& !redisplaying_p
)
9967 /* If the display update has been interrupted by pending
9968 input, update mode lines in the frame. Due to the
9969 pending input, it might have been that redisplay hasn't
9970 been called, so that mode lines above the echo area are
9971 garbaged. This looks odd, so we prevent it here. */
9972 if (!display_completed
)
9973 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9975 if (window_height_changed_p
9976 /* Don't do this if Emacs is shutting down. Redisplay
9977 needs to run hooks. */
9978 && !NILP (Vrun_hooks
))
9980 /* Must update other windows. Likewise as in other
9981 cases, don't let this update be interrupted by
9983 int count
= SPECPDL_INDEX ();
9984 specbind (Qredisplay_dont_pause
, Qt
);
9985 windows_or_buffers_changed
= 1;
9986 redisplay_internal ();
9987 unbind_to (count
, Qnil
);
9989 else if (FRAME_WINDOW_P (f
) && n
== 0)
9991 /* Window configuration is the same as before.
9992 Can do with a display update of the echo area,
9993 unless we displayed some mode lines. */
9994 update_single_window (w
, 1);
9995 FRAME_RIF (f
)->flush_display (f
);
9998 update_frame (f
, 1, 1);
10000 /* If cursor is in the echo area, make sure that the next
10001 redisplay displays the minibuffer, so that the cursor will
10002 be replaced with what the minibuffer wants. */
10003 if (cursor_in_echo_area
)
10004 ++windows_or_buffers_changed
;
10007 else if (!EQ (mini_window
, selected_window
))
10008 windows_or_buffers_changed
++;
10010 /* Last displayed message is now the current message. */
10011 echo_area_buffer
[1] = echo_area_buffer
[0];
10012 /* Inform read_char that we're not echoing. */
10013 echo_message_buffer
= Qnil
;
10015 /* Prevent redisplay optimization in redisplay_internal by resetting
10016 this_line_start_pos. This is done because the mini-buffer now
10017 displays the message instead of its buffer text. */
10018 if (EQ (mini_window
, selected_window
))
10019 CHARPOS (this_line_start_pos
) = 0;
10021 return window_height_changed_p
;
10026 /***********************************************************************
10027 Mode Lines and Frame Titles
10028 ***********************************************************************/
10030 /* A buffer for constructing non-propertized mode-line strings and
10031 frame titles in it; allocated from the heap in init_xdisp and
10032 resized as needed in store_mode_line_noprop_char. */
10034 static char *mode_line_noprop_buf
;
10036 /* The buffer's end, and a current output position in it. */
10038 static char *mode_line_noprop_buf_end
;
10039 static char *mode_line_noprop_ptr
;
10041 #define MODE_LINE_NOPROP_LEN(start) \
10042 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10045 MODE_LINE_DISPLAY
= 0,
10049 } mode_line_target
;
10051 /* Alist that caches the results of :propertize.
10052 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10053 static Lisp_Object mode_line_proptrans_alist
;
10055 /* List of strings making up the mode-line. */
10056 static Lisp_Object mode_line_string_list
;
10058 /* Base face property when building propertized mode line string. */
10059 static Lisp_Object mode_line_string_face
;
10060 static Lisp_Object mode_line_string_face_prop
;
10063 /* Unwind data for mode line strings */
10065 static Lisp_Object Vmode_line_unwind_vector
;
10068 format_mode_line_unwind_data (struct buffer
*obuf
,
10070 int save_proptrans
)
10072 Lisp_Object vector
, tmp
;
10074 /* Reduce consing by keeping one vector in
10075 Vwith_echo_area_save_vector. */
10076 vector
= Vmode_line_unwind_vector
;
10077 Vmode_line_unwind_vector
= Qnil
;
10080 vector
= Fmake_vector (make_number (8), Qnil
);
10082 ASET (vector
, 0, make_number (mode_line_target
));
10083 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10084 ASET (vector
, 2, mode_line_string_list
);
10085 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10086 ASET (vector
, 4, mode_line_string_face
);
10087 ASET (vector
, 5, mode_line_string_face_prop
);
10090 XSETBUFFER (tmp
, obuf
);
10093 ASET (vector
, 6, tmp
);
10094 ASET (vector
, 7, owin
);
10100 unwind_format_mode_line (Lisp_Object vector
)
10102 mode_line_target
= XINT (AREF (vector
, 0));
10103 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10104 mode_line_string_list
= AREF (vector
, 2);
10105 if (! EQ (AREF (vector
, 3), Qt
))
10106 mode_line_proptrans_alist
= AREF (vector
, 3);
10107 mode_line_string_face
= AREF (vector
, 4);
10108 mode_line_string_face_prop
= AREF (vector
, 5);
10110 if (!NILP (AREF (vector
, 7)))
10111 /* Select window before buffer, since it may change the buffer. */
10112 Fselect_window (AREF (vector
, 7), Qt
);
10114 if (!NILP (AREF (vector
, 6)))
10116 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10117 ASET (vector
, 6, Qnil
);
10120 Vmode_line_unwind_vector
= vector
;
10125 /* Store a single character C for the frame title in mode_line_noprop_buf.
10126 Re-allocate mode_line_noprop_buf if necessary. */
10129 store_mode_line_noprop_char (char c
)
10131 /* If output position has reached the end of the allocated buffer,
10132 double the buffer's size. */
10133 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10135 int len
= MODE_LINE_NOPROP_LEN (0);
10136 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
10137 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
10138 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
10139 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10142 *mode_line_noprop_ptr
++ = c
;
10146 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10147 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10148 characters that yield more columns than PRECISION; PRECISION <= 0
10149 means copy the whole string. Pad with spaces until FIELD_WIDTH
10150 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10151 pad. Called from display_mode_element when it is used to build a
10155 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10157 const unsigned char *str
= (const unsigned char *) string
;
10159 EMACS_INT dummy
, nbytes
;
10161 /* Copy at most PRECISION chars from STR. */
10162 nbytes
= strlen (string
);
10163 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10165 store_mode_line_noprop_char (*str
++);
10167 /* Fill up with spaces until FIELD_WIDTH reached. */
10168 while (field_width
> 0
10169 && n
< field_width
)
10171 store_mode_line_noprop_char (' ');
10178 /***********************************************************************
10180 ***********************************************************************/
10182 #ifdef HAVE_WINDOW_SYSTEM
10184 /* Set the title of FRAME, if it has changed. The title format is
10185 Vicon_title_format if FRAME is iconified, otherwise it is
10186 frame_title_format. */
10189 x_consider_frame_title (Lisp_Object frame
)
10191 struct frame
*f
= XFRAME (frame
);
10193 if (FRAME_WINDOW_P (f
)
10194 || FRAME_MINIBUF_ONLY_P (f
)
10195 || f
->explicit_name
)
10197 /* Do we have more than one visible frame on this X display? */
10204 int count
= SPECPDL_INDEX ();
10206 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
10208 Lisp_Object other_frame
= XCAR (tail
);
10209 struct frame
*tf
= XFRAME (other_frame
);
10212 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
10213 && !FRAME_MINIBUF_ONLY_P (tf
)
10214 && !EQ (other_frame
, tip_frame
)
10215 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
10219 /* Set global variable indicating that multiple frames exist. */
10220 multiple_frames
= CONSP (tail
);
10222 /* Switch to the buffer of selected window of the frame. Set up
10223 mode_line_target so that display_mode_element will output into
10224 mode_line_noprop_buf; then display the title. */
10225 record_unwind_protect (unwind_format_mode_line
,
10226 format_mode_line_unwind_data
10227 (current_buffer
, selected_window
, 0));
10229 Fselect_window (f
->selected_window
, Qt
);
10230 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
10231 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
10233 mode_line_target
= MODE_LINE_TITLE
;
10234 title_start
= MODE_LINE_NOPROP_LEN (0);
10235 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
10236 NULL
, DEFAULT_FACE_ID
);
10237 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
10238 len
= MODE_LINE_NOPROP_LEN (title_start
);
10239 title
= mode_line_noprop_buf
+ title_start
;
10240 unbind_to (count
, Qnil
);
10242 /* Set the title only if it's changed. This avoids consing in
10243 the common case where it hasn't. (If it turns out that we've
10244 already wasted too much time by walking through the list with
10245 display_mode_element, then we might need to optimize at a
10246 higher level than this.) */
10247 if (! STRINGP (f
->name
)
10248 || SBYTES (f
->name
) != len
10249 || memcmp (title
, SDATA (f
->name
), len
) != 0)
10250 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
10254 #endif /* not HAVE_WINDOW_SYSTEM */
10259 /***********************************************************************
10261 ***********************************************************************/
10264 /* Prepare for redisplay by updating menu-bar item lists when
10265 appropriate. This can call eval. */
10268 prepare_menu_bars (void)
10271 struct gcpro gcpro1
, gcpro2
;
10273 Lisp_Object tooltip_frame
;
10275 #ifdef HAVE_WINDOW_SYSTEM
10276 tooltip_frame
= tip_frame
;
10278 tooltip_frame
= Qnil
;
10281 /* Update all frame titles based on their buffer names, etc. We do
10282 this before the menu bars so that the buffer-menu will show the
10283 up-to-date frame titles. */
10284 #ifdef HAVE_WINDOW_SYSTEM
10285 if (windows_or_buffers_changed
|| update_mode_lines
)
10287 Lisp_Object tail
, frame
;
10289 FOR_EACH_FRAME (tail
, frame
)
10291 f
= XFRAME (frame
);
10292 if (!EQ (frame
, tooltip_frame
)
10293 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
10294 x_consider_frame_title (frame
);
10297 #endif /* HAVE_WINDOW_SYSTEM */
10299 /* Update the menu bar item lists, if appropriate. This has to be
10300 done before any actual redisplay or generation of display lines. */
10301 all_windows
= (update_mode_lines
10302 || buffer_shared
> 1
10303 || windows_or_buffers_changed
);
10306 Lisp_Object tail
, frame
;
10307 int count
= SPECPDL_INDEX ();
10308 /* 1 means that update_menu_bar has run its hooks
10309 so any further calls to update_menu_bar shouldn't do so again. */
10310 int menu_bar_hooks_run
= 0;
10312 record_unwind_save_match_data ();
10314 FOR_EACH_FRAME (tail
, frame
)
10316 f
= XFRAME (frame
);
10318 /* Ignore tooltip frame. */
10319 if (EQ (frame
, tooltip_frame
))
10322 /* If a window on this frame changed size, report that to
10323 the user and clear the size-change flag. */
10324 if (FRAME_WINDOW_SIZES_CHANGED (f
))
10326 Lisp_Object functions
;
10328 /* Clear flag first in case we get an error below. */
10329 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
10330 functions
= Vwindow_size_change_functions
;
10331 GCPRO2 (tail
, functions
);
10333 while (CONSP (functions
))
10335 if (!EQ (XCAR (functions
), Qt
))
10336 call1 (XCAR (functions
), frame
);
10337 functions
= XCDR (functions
);
10343 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
10344 #ifdef HAVE_WINDOW_SYSTEM
10345 update_tool_bar (f
, 0);
10348 if (windows_or_buffers_changed
10350 ns_set_doc_edited (f
, Fbuffer_modified_p
10351 (XWINDOW (f
->selected_window
)->buffer
));
10356 unbind_to (count
, Qnil
);
10360 struct frame
*sf
= SELECTED_FRAME ();
10361 update_menu_bar (sf
, 1, 0);
10362 #ifdef HAVE_WINDOW_SYSTEM
10363 update_tool_bar (sf
, 1);
10369 /* Update the menu bar item list for frame F. This has to be done
10370 before we start to fill in any display lines, because it can call
10373 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
10375 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
10376 already ran the menu bar hooks for this redisplay, so there
10377 is no need to run them again. The return value is the
10378 updated value of this flag, to pass to the next call. */
10381 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
10383 Lisp_Object window
;
10384 register struct window
*w
;
10386 /* If called recursively during a menu update, do nothing. This can
10387 happen when, for instance, an activate-menubar-hook causes a
10389 if (inhibit_menubar_update
)
10392 window
= FRAME_SELECTED_WINDOW (f
);
10393 w
= XWINDOW (window
);
10395 if (FRAME_WINDOW_P (f
)
10397 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10398 || defined (HAVE_NS) || defined (USE_GTK)
10399 FRAME_EXTERNAL_MENU_BAR (f
)
10401 FRAME_MENU_BAR_LINES (f
) > 0
10403 : FRAME_MENU_BAR_LINES (f
) > 0)
10405 /* If the user has switched buffers or windows, we need to
10406 recompute to reflect the new bindings. But we'll
10407 recompute when update_mode_lines is set too; that means
10408 that people can use force-mode-line-update to request
10409 that the menu bar be recomputed. The adverse effect on
10410 the rest of the redisplay algorithm is about the same as
10411 windows_or_buffers_changed anyway. */
10412 if (windows_or_buffers_changed
10413 /* This used to test w->update_mode_line, but we believe
10414 there is no need to recompute the menu in that case. */
10415 || update_mode_lines
10416 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10417 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10418 != !NILP (w
->last_had_star
))
10419 || ((!NILP (Vtransient_mark_mode
)
10420 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10421 != !NILP (w
->region_showing
)))
10423 struct buffer
*prev
= current_buffer
;
10424 int count
= SPECPDL_INDEX ();
10426 specbind (Qinhibit_menubar_update
, Qt
);
10428 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10429 if (save_match_data
)
10430 record_unwind_save_match_data ();
10431 if (NILP (Voverriding_local_map_menu_flag
))
10433 specbind (Qoverriding_terminal_local_map
, Qnil
);
10434 specbind (Qoverriding_local_map
, Qnil
);
10439 /* Run the Lucid hook. */
10440 safe_run_hooks (Qactivate_menubar_hook
);
10442 /* If it has changed current-menubar from previous value,
10443 really recompute the menu-bar from the value. */
10444 if (! NILP (Vlucid_menu_bar_dirty_flag
))
10445 call0 (Qrecompute_lucid_menubar
);
10447 safe_run_hooks (Qmenu_bar_update_hook
);
10452 XSETFRAME (Vmenu_updating_frame
, f
);
10453 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
10455 /* Redisplay the menu bar in case we changed it. */
10456 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10457 || defined (HAVE_NS) || defined (USE_GTK)
10458 if (FRAME_WINDOW_P (f
))
10460 #if defined (HAVE_NS)
10461 /* All frames on Mac OS share the same menubar. So only
10462 the selected frame should be allowed to set it. */
10463 if (f
== SELECTED_FRAME ())
10465 set_frame_menubar (f
, 0, 0);
10468 /* On a terminal screen, the menu bar is an ordinary screen
10469 line, and this makes it get updated. */
10470 w
->update_mode_line
= Qt
;
10471 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10472 /* In the non-toolkit version, the menu bar is an ordinary screen
10473 line, and this makes it get updated. */
10474 w
->update_mode_line
= Qt
;
10475 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10477 unbind_to (count
, Qnil
);
10478 set_buffer_internal_1 (prev
);
10487 /***********************************************************************
10489 ***********************************************************************/
10491 #ifdef HAVE_WINDOW_SYSTEM
10494 Nominal cursor position -- where to draw output.
10495 HPOS and VPOS are window relative glyph matrix coordinates.
10496 X and Y are window relative pixel coordinates. */
10498 struct cursor_pos output_cursor
;
10502 Set the global variable output_cursor to CURSOR. All cursor
10503 positions are relative to updated_window. */
10506 set_output_cursor (struct cursor_pos
*cursor
)
10508 output_cursor
.hpos
= cursor
->hpos
;
10509 output_cursor
.vpos
= cursor
->vpos
;
10510 output_cursor
.x
= cursor
->x
;
10511 output_cursor
.y
= cursor
->y
;
10516 Set a nominal cursor position.
10518 HPOS and VPOS are column/row positions in a window glyph matrix. X
10519 and Y are window text area relative pixel positions.
10521 If this is done during an update, updated_window will contain the
10522 window that is being updated and the position is the future output
10523 cursor position for that window. If updated_window is null, use
10524 selected_window and display the cursor at the given position. */
10527 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
10531 /* If updated_window is not set, work on selected_window. */
10532 if (updated_window
)
10533 w
= updated_window
;
10535 w
= XWINDOW (selected_window
);
10537 /* Set the output cursor. */
10538 output_cursor
.hpos
= hpos
;
10539 output_cursor
.vpos
= vpos
;
10540 output_cursor
.x
= x
;
10541 output_cursor
.y
= y
;
10543 /* If not called as part of an update, really display the cursor.
10544 This will also set the cursor position of W. */
10545 if (updated_window
== NULL
)
10548 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10549 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10550 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10555 #endif /* HAVE_WINDOW_SYSTEM */
10558 /***********************************************************************
10560 ***********************************************************************/
10562 #ifdef HAVE_WINDOW_SYSTEM
10564 /* Where the mouse was last time we reported a mouse event. */
10566 FRAME_PTR last_mouse_frame
;
10568 /* Tool-bar item index of the item on which a mouse button was pressed
10571 int last_tool_bar_item
;
10575 update_tool_bar_unwind (Lisp_Object frame
)
10577 selected_frame
= frame
;
10581 /* Update the tool-bar item list for frame F. This has to be done
10582 before we start to fill in any display lines. Called from
10583 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10584 and restore it here. */
10587 update_tool_bar (struct frame
*f
, int save_match_data
)
10589 #if defined (USE_GTK) || defined (HAVE_NS)
10590 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10592 int do_update
= WINDOWP (f
->tool_bar_window
)
10593 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10598 Lisp_Object window
;
10601 window
= FRAME_SELECTED_WINDOW (f
);
10602 w
= XWINDOW (window
);
10604 /* If the user has switched buffers or windows, we need to
10605 recompute to reflect the new bindings. But we'll
10606 recompute when update_mode_lines is set too; that means
10607 that people can use force-mode-line-update to request
10608 that the menu bar be recomputed. The adverse effect on
10609 the rest of the redisplay algorithm is about the same as
10610 windows_or_buffers_changed anyway. */
10611 if (windows_or_buffers_changed
10612 || !NILP (w
->update_mode_line
)
10613 || update_mode_lines
10614 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10615 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10616 != !NILP (w
->last_had_star
))
10617 || ((!NILP (Vtransient_mark_mode
)
10618 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10619 != !NILP (w
->region_showing
)))
10621 struct buffer
*prev
= current_buffer
;
10622 int count
= SPECPDL_INDEX ();
10623 Lisp_Object frame
, new_tool_bar
;
10624 int new_n_tool_bar
;
10625 struct gcpro gcpro1
;
10627 /* Set current_buffer to the buffer of the selected
10628 window of the frame, so that we get the right local
10630 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10632 /* Save match data, if we must. */
10633 if (save_match_data
)
10634 record_unwind_save_match_data ();
10636 /* Make sure that we don't accidentally use bogus keymaps. */
10637 if (NILP (Voverriding_local_map_menu_flag
))
10639 specbind (Qoverriding_terminal_local_map
, Qnil
);
10640 specbind (Qoverriding_local_map
, Qnil
);
10643 GCPRO1 (new_tool_bar
);
10645 /* We must temporarily set the selected frame to this frame
10646 before calling tool_bar_items, because the calculation of
10647 the tool-bar keymap uses the selected frame (see
10648 `tool-bar-make-keymap' in tool-bar.el). */
10649 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10650 XSETFRAME (frame
, f
);
10651 selected_frame
= frame
;
10653 /* Build desired tool-bar items from keymaps. */
10654 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10657 /* Redisplay the tool-bar if we changed it. */
10658 if (new_n_tool_bar
!= f
->n_tool_bar_items
10659 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10661 /* Redisplay that happens asynchronously due to an expose event
10662 may access f->tool_bar_items. Make sure we update both
10663 variables within BLOCK_INPUT so no such event interrupts. */
10665 f
->tool_bar_items
= new_tool_bar
;
10666 f
->n_tool_bar_items
= new_n_tool_bar
;
10667 w
->update_mode_line
= Qt
;
10673 unbind_to (count
, Qnil
);
10674 set_buffer_internal_1 (prev
);
10680 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10681 F's desired tool-bar contents. F->tool_bar_items must have
10682 been set up previously by calling prepare_menu_bars. */
10685 build_desired_tool_bar_string (struct frame
*f
)
10687 int i
, size
, size_needed
;
10688 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10689 Lisp_Object image
, plist
, props
;
10691 image
= plist
= props
= Qnil
;
10692 GCPRO3 (image
, plist
, props
);
10694 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10695 Otherwise, make a new string. */
10697 /* The size of the string we might be able to reuse. */
10698 size
= (STRINGP (f
->desired_tool_bar_string
)
10699 ? SCHARS (f
->desired_tool_bar_string
)
10702 /* We need one space in the string for each image. */
10703 size_needed
= f
->n_tool_bar_items
;
10705 /* Reuse f->desired_tool_bar_string, if possible. */
10706 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10707 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10708 make_number (' '));
10711 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10712 Fremove_text_properties (make_number (0), make_number (size
),
10713 props
, f
->desired_tool_bar_string
);
10716 /* Put a `display' property on the string for the images to display,
10717 put a `menu_item' property on tool-bar items with a value that
10718 is the index of the item in F's tool-bar item vector. */
10719 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10721 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10723 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10724 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10725 int hmargin
, vmargin
, relief
, idx
, end
;
10727 /* If image is a vector, choose the image according to the
10729 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10730 if (VECTORP (image
))
10734 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10735 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10738 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10739 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10741 xassert (ASIZE (image
) >= idx
);
10742 image
= AREF (image
, idx
);
10747 /* Ignore invalid image specifications. */
10748 if (!valid_image_p (image
))
10751 /* Display the tool-bar button pressed, or depressed. */
10752 plist
= Fcopy_sequence (XCDR (image
));
10754 /* Compute margin and relief to draw. */
10755 relief
= (tool_bar_button_relief
>= 0
10756 ? tool_bar_button_relief
10757 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10758 hmargin
= vmargin
= relief
;
10760 if (INTEGERP (Vtool_bar_button_margin
)
10761 && XINT (Vtool_bar_button_margin
) > 0)
10763 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10764 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10766 else if (CONSP (Vtool_bar_button_margin
))
10768 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10769 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10770 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10772 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10773 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10774 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10777 if (auto_raise_tool_bar_buttons_p
)
10779 /* Add a `:relief' property to the image spec if the item is
10783 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10790 /* If image is selected, display it pressed, i.e. with a
10791 negative relief. If it's not selected, display it with a
10793 plist
= Fplist_put (plist
, QCrelief
,
10795 ? make_number (-relief
)
10796 : make_number (relief
)));
10801 /* Put a margin around the image. */
10802 if (hmargin
|| vmargin
)
10804 if (hmargin
== vmargin
)
10805 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10807 plist
= Fplist_put (plist
, QCmargin
,
10808 Fcons (make_number (hmargin
),
10809 make_number (vmargin
)));
10812 /* If button is not enabled, and we don't have special images
10813 for the disabled state, make the image appear disabled by
10814 applying an appropriate algorithm to it. */
10815 if (!enabled_p
&& idx
< 0)
10816 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10818 /* Put a `display' text property on the string for the image to
10819 display. Put a `menu-item' property on the string that gives
10820 the start of this item's properties in the tool-bar items
10822 image
= Fcons (Qimage
, plist
);
10823 props
= list4 (Qdisplay
, image
,
10824 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10826 /* Let the last image hide all remaining spaces in the tool bar
10827 string. The string can be longer than needed when we reuse a
10828 previous string. */
10829 if (i
+ 1 == f
->n_tool_bar_items
)
10830 end
= SCHARS (f
->desired_tool_bar_string
);
10833 Fadd_text_properties (make_number (i
), make_number (end
),
10834 props
, f
->desired_tool_bar_string
);
10842 /* Display one line of the tool-bar of frame IT->f.
10844 HEIGHT specifies the desired height of the tool-bar line.
10845 If the actual height of the glyph row is less than HEIGHT, the
10846 row's height is increased to HEIGHT, and the icons are centered
10847 vertically in the new height.
10849 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10850 count a final empty row in case the tool-bar width exactly matches
10855 display_tool_bar_line (struct it
*it
, int height
)
10857 struct glyph_row
*row
= it
->glyph_row
;
10858 int max_x
= it
->last_visible_x
;
10859 struct glyph
*last
;
10861 prepare_desired_row (row
);
10862 row
->y
= it
->current_y
;
10864 /* Note that this isn't made use of if the face hasn't a box,
10865 so there's no need to check the face here. */
10866 it
->start_of_box_run_p
= 1;
10868 while (it
->current_x
< max_x
)
10870 int x
, n_glyphs_before
, i
, nglyphs
;
10871 struct it it_before
;
10873 /* Get the next display element. */
10874 if (!get_next_display_element (it
))
10876 /* Don't count empty row if we are counting needed tool-bar lines. */
10877 if (height
< 0 && !it
->hpos
)
10882 /* Produce glyphs. */
10883 n_glyphs_before
= row
->used
[TEXT_AREA
];
10886 PRODUCE_GLYPHS (it
);
10888 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10890 x
= it_before
.current_x
;
10891 while (i
< nglyphs
)
10893 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10895 if (x
+ glyph
->pixel_width
> max_x
)
10897 /* Glyph doesn't fit on line. Backtrack. */
10898 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10900 /* If this is the only glyph on this line, it will never fit on the
10901 tool-bar, so skip it. But ensure there is at least one glyph,
10902 so we don't accidentally disable the tool-bar. */
10903 if (n_glyphs_before
== 0
10904 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10910 x
+= glyph
->pixel_width
;
10914 /* Stop at line end. */
10915 if (ITERATOR_AT_END_OF_LINE_P (it
))
10918 set_iterator_to_next (it
, 1);
10923 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10925 /* Use default face for the border below the tool bar.
10927 FIXME: When auto-resize-tool-bars is grow-only, there is
10928 no additional border below the possibly empty tool-bar lines.
10929 So to make the extra empty lines look "normal", we have to
10930 use the tool-bar face for the border too. */
10931 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10932 it
->face_id
= DEFAULT_FACE_ID
;
10934 extend_face_to_end_of_line (it
);
10935 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10936 last
->right_box_line_p
= 1;
10937 if (last
== row
->glyphs
[TEXT_AREA
])
10938 last
->left_box_line_p
= 1;
10940 /* Make line the desired height and center it vertically. */
10941 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10943 /* Don't add more than one line height. */
10944 height
%= FRAME_LINE_HEIGHT (it
->f
);
10945 it
->max_ascent
+= height
/ 2;
10946 it
->max_descent
+= (height
+ 1) / 2;
10949 compute_line_metrics (it
);
10951 /* If line is empty, make it occupy the rest of the tool-bar. */
10952 if (!row
->displays_text_p
)
10954 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10955 row
->visible_height
= row
->height
;
10956 row
->ascent
= row
->phys_ascent
= 0;
10957 row
->extra_line_spacing
= 0;
10960 row
->full_width_p
= 1;
10961 row
->continued_p
= 0;
10962 row
->truncated_on_left_p
= 0;
10963 row
->truncated_on_right_p
= 0;
10965 it
->current_x
= it
->hpos
= 0;
10966 it
->current_y
+= row
->height
;
10972 /* Max tool-bar height. */
10974 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10975 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10977 /* Value is the number of screen lines needed to make all tool-bar
10978 items of frame F visible. The number of actual rows needed is
10979 returned in *N_ROWS if non-NULL. */
10982 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
10984 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10986 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10987 the desired matrix, so use (unused) mode-line row as temporary row to
10988 avoid destroying the first tool-bar row. */
10989 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10991 /* Initialize an iterator for iteration over
10992 F->desired_tool_bar_string in the tool-bar window of frame F. */
10993 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10994 it
.first_visible_x
= 0;
10995 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10996 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10997 it
.paragraph_embedding
= L2R
;
10999 while (!ITERATOR_AT_END_P (&it
))
11001 clear_glyph_row (temp_row
);
11002 it
.glyph_row
= temp_row
;
11003 display_tool_bar_line (&it
, -1);
11005 clear_glyph_row (temp_row
);
11007 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11009 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11011 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11015 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11017 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11018 (Lisp_Object frame
)
11025 frame
= selected_frame
;
11027 CHECK_FRAME (frame
);
11028 f
= XFRAME (frame
);
11030 if (WINDOWP (f
->tool_bar_window
)
11031 || (w
= XWINDOW (f
->tool_bar_window
),
11032 WINDOW_TOTAL_LINES (w
) > 0))
11034 update_tool_bar (f
, 1);
11035 if (f
->n_tool_bar_items
)
11037 build_desired_tool_bar_string (f
);
11038 nlines
= tool_bar_lines_needed (f
, NULL
);
11042 return make_number (nlines
);
11046 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11047 height should be changed. */
11050 redisplay_tool_bar (struct frame
*f
)
11054 struct glyph_row
*row
;
11056 #if defined (USE_GTK) || defined (HAVE_NS)
11057 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11058 update_frame_tool_bar (f
);
11062 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11063 do anything. This means you must start with tool-bar-lines
11064 non-zero to get the auto-sizing effect. Or in other words, you
11065 can turn off tool-bars by specifying tool-bar-lines zero. */
11066 if (!WINDOWP (f
->tool_bar_window
)
11067 || (w
= XWINDOW (f
->tool_bar_window
),
11068 WINDOW_TOTAL_LINES (w
) == 0))
11071 /* Set up an iterator for the tool-bar window. */
11072 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11073 it
.first_visible_x
= 0;
11074 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11075 row
= it
.glyph_row
;
11077 /* Build a string that represents the contents of the tool-bar. */
11078 build_desired_tool_bar_string (f
);
11079 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11080 /* FIXME: This should be controlled by a user option. But it
11081 doesn't make sense to have an R2L tool bar if the menu bar cannot
11082 be drawn also R2L, and making the menu bar R2L is tricky due to
11083 unibyte strings it uses and toolkit-specific code that implements
11084 it. If an R2L tool bar is ever supported, display_tool_bar_line
11085 should also be augmented to call unproduce_glyphs like
11086 display_line and display_string do. */
11087 it
.paragraph_embedding
= L2R
;
11089 if (f
->n_tool_bar_rows
== 0)
11093 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11094 nlines
!= WINDOW_TOTAL_LINES (w
)))
11097 int old_height
= WINDOW_TOTAL_LINES (w
);
11099 XSETFRAME (frame
, f
);
11100 Fmodify_frame_parameters (frame
,
11101 Fcons (Fcons (Qtool_bar_lines
,
11102 make_number (nlines
)),
11104 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11106 clear_glyph_matrix (w
->desired_matrix
);
11107 fonts_changed_p
= 1;
11113 /* Display as many lines as needed to display all tool-bar items. */
11115 if (f
->n_tool_bar_rows
> 0)
11117 int border
, rows
, height
, extra
;
11119 if (INTEGERP (Vtool_bar_border
))
11120 border
= XINT (Vtool_bar_border
);
11121 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11122 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11123 else if (EQ (Vtool_bar_border
, Qborder_width
))
11124 border
= f
->border_width
;
11130 rows
= f
->n_tool_bar_rows
;
11131 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11132 extra
= it
.last_visible_y
- border
- height
* rows
;
11134 while (it
.current_y
< it
.last_visible_y
)
11137 if (extra
> 0 && rows
-- > 0)
11139 h
= (extra
+ rows
- 1) / rows
;
11142 display_tool_bar_line (&it
, height
+ h
);
11147 while (it
.current_y
< it
.last_visible_y
)
11148 display_tool_bar_line (&it
, 0);
11151 /* It doesn't make much sense to try scrolling in the tool-bar
11152 window, so don't do it. */
11153 w
->desired_matrix
->no_scrolling_p
= 1;
11154 w
->must_be_updated_p
= 1;
11156 if (!NILP (Vauto_resize_tool_bars
))
11158 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11159 int change_height_p
= 0;
11161 /* If we couldn't display everything, change the tool-bar's
11162 height if there is room for more. */
11163 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11164 && it
.current_y
< max_tool_bar_height
)
11165 change_height_p
= 1;
11167 row
= it
.glyph_row
- 1;
11169 /* If there are blank lines at the end, except for a partially
11170 visible blank line at the end that is smaller than
11171 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11172 if (!row
->displays_text_p
11173 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11174 change_height_p
= 1;
11176 /* If row displays tool-bar items, but is partially visible,
11177 change the tool-bar's height. */
11178 if (row
->displays_text_p
11179 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11180 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11181 change_height_p
= 1;
11183 /* Resize windows as needed by changing the `tool-bar-lines'
11184 frame parameter. */
11185 if (change_height_p
)
11188 int old_height
= WINDOW_TOTAL_LINES (w
);
11190 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11192 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11193 && !f
->minimize_tool_bar_window_p
)
11194 ? (nlines
> old_height
)
11195 : (nlines
!= old_height
));
11196 f
->minimize_tool_bar_window_p
= 0;
11198 if (change_height_p
)
11200 XSETFRAME (frame
, f
);
11201 Fmodify_frame_parameters (frame
,
11202 Fcons (Fcons (Qtool_bar_lines
,
11203 make_number (nlines
)),
11205 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11207 clear_glyph_matrix (w
->desired_matrix
);
11208 f
->n_tool_bar_rows
= nrows
;
11209 fonts_changed_p
= 1;
11216 f
->minimize_tool_bar_window_p
= 0;
11221 /* Get information about the tool-bar item which is displayed in GLYPH
11222 on frame F. Return in *PROP_IDX the index where tool-bar item
11223 properties start in F->tool_bar_items. Value is zero if
11224 GLYPH doesn't display a tool-bar item. */
11227 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
11233 /* This function can be called asynchronously, which means we must
11234 exclude any possibility that Fget_text_property signals an
11236 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
11237 charpos
= max (0, charpos
);
11239 /* Get the text property `menu-item' at pos. The value of that
11240 property is the start index of this item's properties in
11241 F->tool_bar_items. */
11242 prop
= Fget_text_property (make_number (charpos
),
11243 Qmenu_item
, f
->current_tool_bar_string
);
11244 if (INTEGERP (prop
))
11246 *prop_idx
= XINT (prop
);
11256 /* Get information about the tool-bar item at position X/Y on frame F.
11257 Return in *GLYPH a pointer to the glyph of the tool-bar item in
11258 the current matrix of the tool-bar window of F, or NULL if not
11259 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
11260 item in F->tool_bar_items. Value is
11262 -1 if X/Y is not on a tool-bar item
11263 0 if X/Y is on the same item that was highlighted before.
11267 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
11268 int *hpos
, int *vpos
, int *prop_idx
)
11270 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11271 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11274 /* Find the glyph under X/Y. */
11275 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
11276 if (*glyph
== NULL
)
11279 /* Get the start of this tool-bar item's properties in
11280 f->tool_bar_items. */
11281 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
11284 /* Is mouse on the highlighted item? */
11285 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
11286 && *vpos
>= hlinfo
->mouse_face_beg_row
11287 && *vpos
<= hlinfo
->mouse_face_end_row
11288 && (*vpos
> hlinfo
->mouse_face_beg_row
11289 || *hpos
>= hlinfo
->mouse_face_beg_col
)
11290 && (*vpos
< hlinfo
->mouse_face_end_row
11291 || *hpos
< hlinfo
->mouse_face_end_col
11292 || hlinfo
->mouse_face_past_end
))
11300 Handle mouse button event on the tool-bar of frame F, at
11301 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
11302 0 for button release. MODIFIERS is event modifiers for button
11306 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
11307 unsigned int modifiers
)
11309 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11310 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11311 int hpos
, vpos
, prop_idx
;
11312 struct glyph
*glyph
;
11313 Lisp_Object enabled_p
;
11315 /* If not on the highlighted tool-bar item, return. */
11316 frame_to_window_pixel_xy (w
, &x
, &y
);
11317 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
11320 /* If item is disabled, do nothing. */
11321 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11322 if (NILP (enabled_p
))
11327 /* Show item in pressed state. */
11328 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
11329 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
11330 last_tool_bar_item
= prop_idx
;
11334 Lisp_Object key
, frame
;
11335 struct input_event event
;
11336 EVENT_INIT (event
);
11338 /* Show item in released state. */
11339 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
11340 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
11342 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
11344 XSETFRAME (frame
, f
);
11345 event
.kind
= TOOL_BAR_EVENT
;
11346 event
.frame_or_window
= frame
;
11348 kbd_buffer_store_event (&event
);
11350 event
.kind
= TOOL_BAR_EVENT
;
11351 event
.frame_or_window
= frame
;
11353 event
.modifiers
= modifiers
;
11354 kbd_buffer_store_event (&event
);
11355 last_tool_bar_item
= -1;
11360 /* Possibly highlight a tool-bar item on frame F when mouse moves to
11361 tool-bar window-relative coordinates X/Y. Called from
11362 note_mouse_highlight. */
11365 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
11367 Lisp_Object window
= f
->tool_bar_window
;
11368 struct window
*w
= XWINDOW (window
);
11369 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11370 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
11372 struct glyph
*glyph
;
11373 struct glyph_row
*row
;
11375 Lisp_Object enabled_p
;
11377 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
11378 int mouse_down_p
, rc
;
11380 /* Function note_mouse_highlight is called with negative X/Y
11381 values when mouse moves outside of the frame. */
11382 if (x
<= 0 || y
<= 0)
11384 clear_mouse_face (hlinfo
);
11388 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
11391 /* Not on tool-bar item. */
11392 clear_mouse_face (hlinfo
);
11396 /* On same tool-bar item as before. */
11397 goto set_help_echo
;
11399 clear_mouse_face (hlinfo
);
11401 /* Mouse is down, but on different tool-bar item? */
11402 mouse_down_p
= (dpyinfo
->grabbed
11403 && f
== last_mouse_frame
11404 && FRAME_LIVE_P (f
));
11406 && last_tool_bar_item
!= prop_idx
)
11409 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
11410 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
11412 /* If tool-bar item is not enabled, don't highlight it. */
11413 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11414 if (!NILP (enabled_p
))
11416 /* Compute the x-position of the glyph. In front and past the
11417 image is a space. We include this in the highlighted area. */
11418 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
11419 for (i
= x
= 0; i
< hpos
; ++i
)
11420 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11422 /* Record this as the current active region. */
11423 hlinfo
->mouse_face_beg_col
= hpos
;
11424 hlinfo
->mouse_face_beg_row
= vpos
;
11425 hlinfo
->mouse_face_beg_x
= x
;
11426 hlinfo
->mouse_face_beg_y
= row
->y
;
11427 hlinfo
->mouse_face_past_end
= 0;
11429 hlinfo
->mouse_face_end_col
= hpos
+ 1;
11430 hlinfo
->mouse_face_end_row
= vpos
;
11431 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
11432 hlinfo
->mouse_face_end_y
= row
->y
;
11433 hlinfo
->mouse_face_window
= window
;
11434 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
11436 /* Display it as active. */
11437 show_mouse_face (hlinfo
, draw
);
11438 hlinfo
->mouse_face_image_state
= draw
;
11443 /* Set help_echo_string to a help string to display for this tool-bar item.
11444 XTread_socket does the rest. */
11445 help_echo_object
= help_echo_window
= Qnil
;
11446 help_echo_pos
= -1;
11447 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
11448 if (NILP (help_echo_string
))
11449 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
11452 #endif /* HAVE_WINDOW_SYSTEM */
11456 /************************************************************************
11457 Horizontal scrolling
11458 ************************************************************************/
11460 static int hscroll_window_tree (Lisp_Object
);
11461 static int hscroll_windows (Lisp_Object
);
11463 /* For all leaf windows in the window tree rooted at WINDOW, set their
11464 hscroll value so that PT is (i) visible in the window, and (ii) so
11465 that it is not within a certain margin at the window's left and
11466 right border. Value is non-zero if any window's hscroll has been
11470 hscroll_window_tree (Lisp_Object window
)
11472 int hscrolled_p
= 0;
11473 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
11474 int hscroll_step_abs
= 0;
11475 double hscroll_step_rel
= 0;
11477 if (hscroll_relative_p
)
11479 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
11480 if (hscroll_step_rel
< 0)
11482 hscroll_relative_p
= 0;
11483 hscroll_step_abs
= 0;
11486 else if (INTEGERP (Vhscroll_step
))
11488 hscroll_step_abs
= XINT (Vhscroll_step
);
11489 if (hscroll_step_abs
< 0)
11490 hscroll_step_abs
= 0;
11493 hscroll_step_abs
= 0;
11495 while (WINDOWP (window
))
11497 struct window
*w
= XWINDOW (window
);
11499 if (WINDOWP (w
->hchild
))
11500 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11501 else if (WINDOWP (w
->vchild
))
11502 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11503 else if (w
->cursor
.vpos
>= 0)
11506 int text_area_width
;
11507 struct glyph_row
*current_cursor_row
11508 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11509 struct glyph_row
*desired_cursor_row
11510 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11511 struct glyph_row
*cursor_row
11512 = (desired_cursor_row
->enabled_p
11513 ? desired_cursor_row
11514 : current_cursor_row
);
11516 text_area_width
= window_box_width (w
, TEXT_AREA
);
11518 /* Scroll when cursor is inside this scroll margin. */
11519 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11521 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11522 && ((XFASTINT (w
->hscroll
)
11523 && w
->cursor
.x
<= h_margin
)
11524 || (cursor_row
->enabled_p
11525 && cursor_row
->truncated_on_right_p
11526 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11530 struct buffer
*saved_current_buffer
;
11534 /* Find point in a display of infinite width. */
11535 saved_current_buffer
= current_buffer
;
11536 current_buffer
= XBUFFER (w
->buffer
);
11538 if (w
== XWINDOW (selected_window
))
11542 pt
= marker_position (w
->pointm
);
11543 pt
= max (BEGV
, pt
);
11547 /* Move iterator to pt starting at cursor_row->start in
11548 a line with infinite width. */
11549 init_to_row_start (&it
, w
, cursor_row
);
11550 it
.last_visible_x
= INFINITY
;
11551 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11552 current_buffer
= saved_current_buffer
;
11554 /* Position cursor in window. */
11555 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11556 hscroll
= max (0, (it
.current_x
11557 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11558 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11559 : (text_area_width
/ 2))))
11560 / FRAME_COLUMN_WIDTH (it
.f
);
11561 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11563 if (hscroll_relative_p
)
11564 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11567 wanted_x
= text_area_width
11568 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11571 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11575 if (hscroll_relative_p
)
11576 wanted_x
= text_area_width
* hscroll_step_rel
11579 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11582 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11584 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11586 /* Don't call Fset_window_hscroll if value hasn't
11587 changed because it will prevent redisplay
11589 if (XFASTINT (w
->hscroll
) != hscroll
)
11591 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11592 w
->hscroll
= make_number (hscroll
);
11601 /* Value is non-zero if hscroll of any leaf window has been changed. */
11602 return hscrolled_p
;
11606 /* Set hscroll so that cursor is visible and not inside horizontal
11607 scroll margins for all windows in the tree rooted at WINDOW. See
11608 also hscroll_window_tree above. Value is non-zero if any window's
11609 hscroll has been changed. If it has, desired matrices on the frame
11610 of WINDOW are cleared. */
11613 hscroll_windows (Lisp_Object window
)
11615 int hscrolled_p
= hscroll_window_tree (window
);
11617 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11618 return hscrolled_p
;
11623 /************************************************************************
11625 ************************************************************************/
11627 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11628 to a non-zero value. This is sometimes handy to have in a debugger
11633 /* First and last unchanged row for try_window_id. */
11635 int debug_first_unchanged_at_end_vpos
;
11636 int debug_last_unchanged_at_beg_vpos
;
11638 /* Delta vpos and y. */
11640 int debug_dvpos
, debug_dy
;
11642 /* Delta in characters and bytes for try_window_id. */
11644 EMACS_INT debug_delta
, debug_delta_bytes
;
11646 /* Values of window_end_pos and window_end_vpos at the end of
11649 EMACS_INT debug_end_vpos
;
11651 /* Append a string to W->desired_matrix->method. FMT is a printf
11652 format string. A1...A9 are a supplement for a variable-length
11653 argument list. If trace_redisplay_p is non-zero also printf the
11654 resulting string to stderr. */
11657 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11660 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11663 char *method
= w
->desired_matrix
->method
;
11664 int len
= strlen (method
);
11665 int size
= sizeof w
->desired_matrix
->method
;
11666 int remaining
= size
- len
- 1;
11668 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11669 if (len
&& remaining
)
11672 --remaining
, ++len
;
11675 strncpy (method
+ len
, buffer
, remaining
);
11677 if (trace_redisplay_p
)
11678 fprintf (stderr
, "%p (%s): %s\n",
11680 ((BUFFERP (w
->buffer
)
11681 && STRINGP (XBUFFER (w
->buffer
)->name
))
11682 ? SSDATA (XBUFFER (w
->buffer
)->name
)
11687 #endif /* GLYPH_DEBUG */
11690 /* Value is non-zero if all changes in window W, which displays
11691 current_buffer, are in the text between START and END. START is a
11692 buffer position, END is given as a distance from Z. Used in
11693 redisplay_internal for display optimization. */
11696 text_outside_line_unchanged_p (struct window
*w
,
11697 EMACS_INT start
, EMACS_INT end
)
11699 int unchanged_p
= 1;
11701 /* If text or overlays have changed, see where. */
11702 if (XFASTINT (w
->last_modified
) < MODIFF
11703 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11705 /* Gap in the line? */
11706 if (GPT
< start
|| Z
- GPT
< end
)
11709 /* Changes start in front of the line, or end after it? */
11711 && (BEG_UNCHANGED
< start
- 1
11712 || END_UNCHANGED
< end
))
11715 /* If selective display, can't optimize if changes start at the
11716 beginning of the line. */
11718 && INTEGERP (BVAR (current_buffer
, selective_display
))
11719 && XINT (BVAR (current_buffer
, selective_display
)) > 0
11720 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11723 /* If there are overlays at the start or end of the line, these
11724 may have overlay strings with newlines in them. A change at
11725 START, for instance, may actually concern the display of such
11726 overlay strings as well, and they are displayed on different
11727 lines. So, quickly rule out this case. (For the future, it
11728 might be desirable to implement something more telling than
11729 just BEG/END_UNCHANGED.) */
11732 if (BEG
+ BEG_UNCHANGED
== start
11733 && overlay_touches_p (start
))
11735 if (END_UNCHANGED
== end
11736 && overlay_touches_p (Z
- end
))
11740 /* Under bidi reordering, adding or deleting a character in the
11741 beginning of a paragraph, before the first strong directional
11742 character, can change the base direction of the paragraph (unless
11743 the buffer specifies a fixed paragraph direction), which will
11744 require to redisplay the whole paragraph. It might be worthwhile
11745 to find the paragraph limits and widen the range of redisplayed
11746 lines to that, but for now just give up this optimization. */
11747 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
11748 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
11752 return unchanged_p
;
11756 /* Do a frame update, taking possible shortcuts into account. This is
11757 the main external entry point for redisplay.
11759 If the last redisplay displayed an echo area message and that message
11760 is no longer requested, we clear the echo area or bring back the
11761 mini-buffer if that is in use. */
11766 redisplay_internal ();
11771 overlay_arrow_string_or_property (Lisp_Object var
)
11775 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11778 return Voverlay_arrow_string
;
11781 /* Return 1 if there are any overlay-arrows in current_buffer. */
11783 overlay_arrow_in_current_buffer_p (void)
11787 for (vlist
= Voverlay_arrow_variable_list
;
11789 vlist
= XCDR (vlist
))
11791 Lisp_Object var
= XCAR (vlist
);
11794 if (!SYMBOLP (var
))
11796 val
= find_symbol_value (var
);
11798 && current_buffer
== XMARKER (val
)->buffer
)
11805 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11809 overlay_arrows_changed_p (void)
11813 for (vlist
= Voverlay_arrow_variable_list
;
11815 vlist
= XCDR (vlist
))
11817 Lisp_Object var
= XCAR (vlist
);
11818 Lisp_Object val
, pstr
;
11820 if (!SYMBOLP (var
))
11822 val
= find_symbol_value (var
);
11823 if (!MARKERP (val
))
11825 if (! EQ (COERCE_MARKER (val
),
11826 Fget (var
, Qlast_arrow_position
))
11827 || ! (pstr
= overlay_arrow_string_or_property (var
),
11828 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11834 /* Mark overlay arrows to be updated on next redisplay. */
11837 update_overlay_arrows (int up_to_date
)
11841 for (vlist
= Voverlay_arrow_variable_list
;
11843 vlist
= XCDR (vlist
))
11845 Lisp_Object var
= XCAR (vlist
);
11847 if (!SYMBOLP (var
))
11850 if (up_to_date
> 0)
11852 Lisp_Object val
= find_symbol_value (var
);
11853 Fput (var
, Qlast_arrow_position
,
11854 COERCE_MARKER (val
));
11855 Fput (var
, Qlast_arrow_string
,
11856 overlay_arrow_string_or_property (var
));
11858 else if (up_to_date
< 0
11859 || !NILP (Fget (var
, Qlast_arrow_position
)))
11861 Fput (var
, Qlast_arrow_position
, Qt
);
11862 Fput (var
, Qlast_arrow_string
, Qt
);
11868 /* Return overlay arrow string to display at row.
11869 Return integer (bitmap number) for arrow bitmap in left fringe.
11870 Return nil if no overlay arrow. */
11873 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
11877 for (vlist
= Voverlay_arrow_variable_list
;
11879 vlist
= XCDR (vlist
))
11881 Lisp_Object var
= XCAR (vlist
);
11884 if (!SYMBOLP (var
))
11887 val
= find_symbol_value (var
);
11890 && current_buffer
== XMARKER (val
)->buffer
11891 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11893 if (FRAME_WINDOW_P (it
->f
)
11894 /* FIXME: if ROW->reversed_p is set, this should test
11895 the right fringe, not the left one. */
11896 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11898 #ifdef HAVE_WINDOW_SYSTEM
11899 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11902 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11903 return make_number (fringe_bitmap
);
11906 return make_number (-1); /* Use default arrow bitmap */
11908 return overlay_arrow_string_or_property (var
);
11915 /* Return 1 if point moved out of or into a composition. Otherwise
11916 return 0. PREV_BUF and PREV_PT are the last point buffer and
11917 position. BUF and PT are the current point buffer and position. */
11920 check_point_in_composition (struct buffer
*prev_buf
, EMACS_INT prev_pt
,
11921 struct buffer
*buf
, EMACS_INT pt
)
11923 EMACS_INT start
, end
;
11925 Lisp_Object buffer
;
11927 XSETBUFFER (buffer
, buf
);
11928 /* Check a composition at the last point if point moved within the
11930 if (prev_buf
== buf
)
11933 /* Point didn't move. */
11936 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11937 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11938 && COMPOSITION_VALID_P (start
, end
, prop
)
11939 && start
< prev_pt
&& end
> prev_pt
)
11940 /* The last point was within the composition. Return 1 iff
11941 point moved out of the composition. */
11942 return (pt
<= start
|| pt
>= end
);
11945 /* Check a composition at the current point. */
11946 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11947 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11948 && COMPOSITION_VALID_P (start
, end
, prop
)
11949 && start
< pt
&& end
> pt
);
11953 /* Reconsider the setting of B->clip_changed which is displayed
11957 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
11959 if (b
->clip_changed
11960 && !NILP (w
->window_end_valid
)
11961 && w
->current_matrix
->buffer
== b
11962 && w
->current_matrix
->zv
== BUF_ZV (b
)
11963 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11964 b
->clip_changed
= 0;
11966 /* If display wasn't paused, and W is not a tool bar window, see if
11967 point has been moved into or out of a composition. In that case,
11968 we set b->clip_changed to 1 to force updating the screen. If
11969 b->clip_changed has already been set to 1, we can skip this
11971 if (!b
->clip_changed
11972 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11976 if (w
== XWINDOW (selected_window
))
11979 pt
= marker_position (w
->pointm
);
11981 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11982 || pt
!= XINT (w
->last_point
))
11983 && check_point_in_composition (w
->current_matrix
->buffer
,
11984 XINT (w
->last_point
),
11985 XBUFFER (w
->buffer
), pt
))
11986 b
->clip_changed
= 1;
11991 /* Select FRAME to forward the values of frame-local variables into C
11992 variables so that the redisplay routines can access those values
11996 select_frame_for_redisplay (Lisp_Object frame
)
11998 Lisp_Object tail
, tem
;
11999 Lisp_Object old
= selected_frame
;
12000 struct Lisp_Symbol
*sym
;
12002 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12004 selected_frame
= frame
;
12007 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
12008 if (CONSP (XCAR (tail
))
12009 && (tem
= XCAR (XCAR (tail
)),
12011 && (sym
= indirect_variable (XSYMBOL (tem
)),
12012 sym
->redirect
== SYMBOL_LOCALIZED
)
12013 && sym
->val
.blv
->frame_local
)
12014 /* Use find_symbol_value rather than Fsymbol_value
12015 to avoid an error if it is void. */
12016 find_symbol_value (tem
);
12017 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12021 #define STOP_POLLING \
12022 do { if (! polling_stopped_here) stop_polling (); \
12023 polling_stopped_here = 1; } while (0)
12025 #define RESUME_POLLING \
12026 do { if (polling_stopped_here) start_polling (); \
12027 polling_stopped_here = 0; } while (0)
12030 /* Perhaps in the future avoid recentering windows if it
12031 is not necessary; currently that causes some problems. */
12034 redisplay_internal (void)
12036 struct window
*w
= XWINDOW (selected_window
);
12040 int must_finish
= 0;
12041 struct text_pos tlbufpos
, tlendpos
;
12042 int number_of_visible_frames
;
12045 int polling_stopped_here
= 0;
12046 Lisp_Object old_frame
= selected_frame
;
12048 /* Non-zero means redisplay has to consider all windows on all
12049 frames. Zero means, only selected_window is considered. */
12050 int consider_all_windows_p
;
12052 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12054 /* No redisplay if running in batch mode or frame is not yet fully
12055 initialized, or redisplay is explicitly turned off by setting
12056 Vinhibit_redisplay. */
12057 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12058 || !NILP (Vinhibit_redisplay
))
12061 /* Don't examine these until after testing Vinhibit_redisplay.
12062 When Emacs is shutting down, perhaps because its connection to
12063 X has dropped, we should not look at them at all. */
12064 fr
= XFRAME (w
->frame
);
12065 sf
= SELECTED_FRAME ();
12067 if (!fr
->glyphs_initialized_p
)
12070 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12071 if (popup_activated ())
12075 /* I don't think this happens but let's be paranoid. */
12076 if (redisplaying_p
)
12079 /* Record a function that resets redisplaying_p to its old value
12080 when we leave this function. */
12081 count
= SPECPDL_INDEX ();
12082 record_unwind_protect (unwind_redisplay
,
12083 Fcons (make_number (redisplaying_p
), selected_frame
));
12085 specbind (Qinhibit_free_realized_faces
, Qnil
);
12088 Lisp_Object tail
, frame
;
12090 FOR_EACH_FRAME (tail
, frame
)
12092 struct frame
*f
= XFRAME (frame
);
12093 f
->already_hscrolled_p
= 0;
12098 /* Remember the currently selected window. */
12101 if (!EQ (old_frame
, selected_frame
)
12102 && FRAME_LIVE_P (XFRAME (old_frame
)))
12103 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12104 selected_frame and selected_window to be temporarily out-of-sync so
12105 when we come back here via `goto retry', we need to resync because we
12106 may need to run Elisp code (via prepare_menu_bars). */
12107 select_frame_for_redisplay (old_frame
);
12110 reconsider_clip_changes (w
, current_buffer
);
12111 last_escape_glyph_frame
= NULL
;
12112 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12113 last_glyphless_glyph_frame
= NULL
;
12114 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12116 /* If new fonts have been loaded that make a glyph matrix adjustment
12117 necessary, do it. */
12118 if (fonts_changed_p
)
12120 adjust_glyphs (NULL
);
12121 ++windows_or_buffers_changed
;
12122 fonts_changed_p
= 0;
12125 /* If face_change_count is non-zero, init_iterator will free all
12126 realized faces, which includes the faces referenced from current
12127 matrices. So, we can't reuse current matrices in this case. */
12128 if (face_change_count
)
12129 ++windows_or_buffers_changed
;
12131 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12132 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12134 /* Since frames on a single ASCII terminal share the same
12135 display area, displaying a different frame means redisplay
12136 the whole thing. */
12137 windows_or_buffers_changed
++;
12138 SET_FRAME_GARBAGED (sf
);
12140 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12142 FRAME_TTY (sf
)->previous_frame
= sf
;
12145 /* Set the visible flags for all frames. Do this before checking
12146 for resized or garbaged frames; they want to know if their frames
12147 are visible. See the comment in frame.h for
12148 FRAME_SAMPLE_VISIBILITY. */
12150 Lisp_Object tail
, frame
;
12152 number_of_visible_frames
= 0;
12154 FOR_EACH_FRAME (tail
, frame
)
12156 struct frame
*f
= XFRAME (frame
);
12158 FRAME_SAMPLE_VISIBILITY (f
);
12159 if (FRAME_VISIBLE_P (f
))
12160 ++number_of_visible_frames
;
12161 clear_desired_matrices (f
);
12165 /* Notice any pending interrupt request to change frame size. */
12166 do_pending_window_change (1);
12168 /* do_pending_window_change could change the selected_window due to
12169 frame resizing which makes the selected window too small. */
12170 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12173 reconsider_clip_changes (w
, current_buffer
);
12176 /* Clear frames marked as garbaged. */
12177 if (frame_garbaged
)
12178 clear_garbaged_frames ();
12180 /* Build menubar and tool-bar items. */
12181 if (NILP (Vmemory_full
))
12182 prepare_menu_bars ();
12184 if (windows_or_buffers_changed
)
12185 update_mode_lines
++;
12187 /* Detect case that we need to write or remove a star in the mode line. */
12188 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
12190 w
->update_mode_line
= Qt
;
12191 if (buffer_shared
> 1)
12192 update_mode_lines
++;
12195 /* Avoid invocation of point motion hooks by `current_column' below. */
12196 count1
= SPECPDL_INDEX ();
12197 specbind (Qinhibit_point_motion_hooks
, Qt
);
12199 /* If %c is in the mode line, update it if needed. */
12200 if (!NILP (w
->column_number_displayed
)
12201 /* This alternative quickly identifies a common case
12202 where no change is needed. */
12203 && !(PT
== XFASTINT (w
->last_point
)
12204 && XFASTINT (w
->last_modified
) >= MODIFF
12205 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12206 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
12207 w
->update_mode_line
= Qt
;
12209 unbind_to (count1
, Qnil
);
12211 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
12213 /* The variable buffer_shared is set in redisplay_window and
12214 indicates that we redisplay a buffer in different windows. See
12216 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
12217 || cursor_type_changed
);
12219 /* If specs for an arrow have changed, do thorough redisplay
12220 to ensure we remove any arrow that should no longer exist. */
12221 if (overlay_arrows_changed_p ())
12222 consider_all_windows_p
= windows_or_buffers_changed
= 1;
12224 /* Normally the message* functions will have already displayed and
12225 updated the echo area, but the frame may have been trashed, or
12226 the update may have been preempted, so display the echo area
12227 again here. Checking message_cleared_p captures the case that
12228 the echo area should be cleared. */
12229 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
12230 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
12231 || (message_cleared_p
12232 && minibuf_level
== 0
12233 /* If the mini-window is currently selected, this means the
12234 echo-area doesn't show through. */
12235 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
12237 int window_height_changed_p
= echo_area_display (0);
12240 /* If we don't display the current message, don't clear the
12241 message_cleared_p flag, because, if we did, we wouldn't clear
12242 the echo area in the next redisplay which doesn't preserve
12244 if (!display_last_displayed_message_p
)
12245 message_cleared_p
= 0;
12247 if (fonts_changed_p
)
12249 else if (window_height_changed_p
)
12251 consider_all_windows_p
= 1;
12252 ++update_mode_lines
;
12253 ++windows_or_buffers_changed
;
12255 /* If window configuration was changed, frames may have been
12256 marked garbaged. Clear them or we will experience
12257 surprises wrt scrolling. */
12258 if (frame_garbaged
)
12259 clear_garbaged_frames ();
12262 else if (EQ (selected_window
, minibuf_window
)
12263 && (current_buffer
->clip_changed
12264 || XFASTINT (w
->last_modified
) < MODIFF
12265 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
12266 && resize_mini_window (w
, 0))
12268 /* Resized active mini-window to fit the size of what it is
12269 showing if its contents might have changed. */
12271 /* FIXME: this causes all frames to be updated, which seems unnecessary
12272 since only the current frame needs to be considered. This function needs
12273 to be rewritten with two variables, consider_all_windows and
12274 consider_all_frames. */
12275 consider_all_windows_p
= 1;
12276 ++windows_or_buffers_changed
;
12277 ++update_mode_lines
;
12279 /* If window configuration was changed, frames may have been
12280 marked garbaged. Clear them or we will experience
12281 surprises wrt scrolling. */
12282 if (frame_garbaged
)
12283 clear_garbaged_frames ();
12287 /* If showing the region, and mark has changed, we must redisplay
12288 the whole window. The assignment to this_line_start_pos prevents
12289 the optimization directly below this if-statement. */
12290 if (((!NILP (Vtransient_mark_mode
)
12291 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
12292 != !NILP (w
->region_showing
))
12293 || (!NILP (w
->region_showing
)
12294 && !EQ (w
->region_showing
,
12295 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
12296 CHARPOS (this_line_start_pos
) = 0;
12298 /* Optimize the case that only the line containing the cursor in the
12299 selected window has changed. Variables starting with this_ are
12300 set in display_line and record information about the line
12301 containing the cursor. */
12302 tlbufpos
= this_line_start_pos
;
12303 tlendpos
= this_line_end_pos
;
12304 if (!consider_all_windows_p
12305 && CHARPOS (tlbufpos
) > 0
12306 && NILP (w
->update_mode_line
)
12307 && !current_buffer
->clip_changed
12308 && !current_buffer
->prevent_redisplay_optimizations_p
12309 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
12310 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
12311 /* Make sure recorded data applies to current buffer, etc. */
12312 && this_line_buffer
== current_buffer
12313 && current_buffer
== XBUFFER (w
->buffer
)
12314 && NILP (w
->force_start
)
12315 && NILP (w
->optional_new_start
)
12316 /* Point must be on the line that we have info recorded about. */
12317 && PT
>= CHARPOS (tlbufpos
)
12318 && PT
<= Z
- CHARPOS (tlendpos
)
12319 /* All text outside that line, including its final newline,
12320 must be unchanged. */
12321 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
12322 CHARPOS (tlendpos
)))
12324 if (CHARPOS (tlbufpos
) > BEGV
12325 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
12326 && (CHARPOS (tlbufpos
) == ZV
12327 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
12328 /* Former continuation line has disappeared by becoming empty. */
12330 else if (XFASTINT (w
->last_modified
) < MODIFF
12331 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
12332 || MINI_WINDOW_P (w
))
12334 /* We have to handle the case of continuation around a
12335 wide-column character (see the comment in indent.c around
12338 For instance, in the following case:
12340 -------- Insert --------
12341 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
12342 J_I_ ==> J_I_ `^^' are cursors.
12346 As we have to redraw the line above, we cannot use this
12350 int line_height_before
= this_line_pixel_height
;
12352 /* Note that start_display will handle the case that the
12353 line starting at tlbufpos is a continuation line. */
12354 start_display (&it
, w
, tlbufpos
);
12356 /* Implementation note: It this still necessary? */
12357 if (it
.current_x
!= this_line_start_x
)
12360 TRACE ((stderr
, "trying display optimization 1\n"));
12361 w
->cursor
.vpos
= -1;
12362 overlay_arrow_seen
= 0;
12363 it
.vpos
= this_line_vpos
;
12364 it
.current_y
= this_line_y
;
12365 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
12366 display_line (&it
);
12368 /* If line contains point, is not continued,
12369 and ends at same distance from eob as before, we win. */
12370 if (w
->cursor
.vpos
>= 0
12371 /* Line is not continued, otherwise this_line_start_pos
12372 would have been set to 0 in display_line. */
12373 && CHARPOS (this_line_start_pos
)
12374 /* Line ends as before. */
12375 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
12376 /* Line has same height as before. Otherwise other lines
12377 would have to be shifted up or down. */
12378 && this_line_pixel_height
== line_height_before
)
12380 /* If this is not the window's last line, we must adjust
12381 the charstarts of the lines below. */
12382 if (it
.current_y
< it
.last_visible_y
)
12384 struct glyph_row
*row
12385 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
12386 EMACS_INT delta
, delta_bytes
;
12388 /* We used to distinguish between two cases here,
12389 conditioned by Z - CHARPOS (tlendpos) == ZV, for
12390 when the line ends in a newline or the end of the
12391 buffer's accessible portion. But both cases did
12392 the same, so they were collapsed. */
12394 - CHARPOS (tlendpos
)
12395 - MATRIX_ROW_START_CHARPOS (row
));
12396 delta_bytes
= (Z_BYTE
12397 - BYTEPOS (tlendpos
)
12398 - MATRIX_ROW_START_BYTEPOS (row
));
12400 increment_matrix_positions (w
->current_matrix
,
12401 this_line_vpos
+ 1,
12402 w
->current_matrix
->nrows
,
12403 delta
, delta_bytes
);
12406 /* If this row displays text now but previously didn't,
12407 or vice versa, w->window_end_vpos may have to be
12409 if ((it
.glyph_row
- 1)->displays_text_p
)
12411 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
12412 XSETINT (w
->window_end_vpos
, this_line_vpos
);
12414 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
12415 && this_line_vpos
> 0)
12416 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
12417 w
->window_end_valid
= Qnil
;
12419 /* Update hint: No need to try to scroll in update_window. */
12420 w
->desired_matrix
->no_scrolling_p
= 1;
12423 *w
->desired_matrix
->method
= 0;
12424 debug_method_add (w
, "optimization 1");
12426 #ifdef HAVE_WINDOW_SYSTEM
12427 update_window_fringes (w
, 0);
12434 else if (/* Cursor position hasn't changed. */
12435 PT
== XFASTINT (w
->last_point
)
12436 /* Make sure the cursor was last displayed
12437 in this window. Otherwise we have to reposition it. */
12438 && 0 <= w
->cursor
.vpos
12439 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
12443 do_pending_window_change (1);
12444 /* If selected_window changed, redisplay again. */
12445 if (WINDOWP (selected_window
)
12446 && (w
= XWINDOW (selected_window
)) != sw
)
12449 /* We used to always goto end_of_redisplay here, but this
12450 isn't enough if we have a blinking cursor. */
12451 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
12452 goto end_of_redisplay
;
12456 /* If highlighting the region, or if the cursor is in the echo area,
12457 then we can't just move the cursor. */
12458 else if (! (!NILP (Vtransient_mark_mode
)
12459 && !NILP (BVAR (current_buffer
, mark_active
)))
12460 && (EQ (selected_window
, BVAR (current_buffer
, last_selected_window
))
12461 || highlight_nonselected_windows
)
12462 && NILP (w
->region_showing
)
12463 && NILP (Vshow_trailing_whitespace
)
12464 && !cursor_in_echo_area
)
12467 struct glyph_row
*row
;
12469 /* Skip from tlbufpos to PT and see where it is. Note that
12470 PT may be in invisible text. If so, we will end at the
12471 next visible position. */
12472 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
12473 NULL
, DEFAULT_FACE_ID
);
12474 it
.current_x
= this_line_start_x
;
12475 it
.current_y
= this_line_y
;
12476 it
.vpos
= this_line_vpos
;
12478 /* The call to move_it_to stops in front of PT, but
12479 moves over before-strings. */
12480 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
12482 if (it
.vpos
== this_line_vpos
12483 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12486 xassert (this_line_vpos
== it
.vpos
);
12487 xassert (this_line_y
== it
.current_y
);
12488 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12490 *w
->desired_matrix
->method
= 0;
12491 debug_method_add (w
, "optimization 3");
12500 /* Text changed drastically or point moved off of line. */
12501 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12504 CHARPOS (this_line_start_pos
) = 0;
12505 consider_all_windows_p
|= buffer_shared
> 1;
12506 ++clear_face_cache_count
;
12507 #ifdef HAVE_WINDOW_SYSTEM
12508 ++clear_image_cache_count
;
12511 /* Build desired matrices, and update the display. If
12512 consider_all_windows_p is non-zero, do it for all windows on all
12513 frames. Otherwise do it for selected_window, only. */
12515 if (consider_all_windows_p
)
12517 Lisp_Object tail
, frame
;
12519 FOR_EACH_FRAME (tail
, frame
)
12520 XFRAME (frame
)->updated_p
= 0;
12522 /* Recompute # windows showing selected buffer. This will be
12523 incremented each time such a window is displayed. */
12526 FOR_EACH_FRAME (tail
, frame
)
12528 struct frame
*f
= XFRAME (frame
);
12530 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12532 if (! EQ (frame
, selected_frame
))
12533 /* Select the frame, for the sake of frame-local
12535 select_frame_for_redisplay (frame
);
12537 /* Mark all the scroll bars to be removed; we'll redeem
12538 the ones we want when we redisplay their windows. */
12539 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12540 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12542 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12543 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12545 /* The X error handler may have deleted that frame. */
12546 if (!FRAME_LIVE_P (f
))
12549 /* Any scroll bars which redisplay_windows should have
12550 nuked should now go away. */
12551 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12552 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12554 /* If fonts changed, display again. */
12555 /* ??? rms: I suspect it is a mistake to jump all the way
12556 back to retry here. It should just retry this frame. */
12557 if (fonts_changed_p
)
12560 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12562 /* See if we have to hscroll. */
12563 if (!f
->already_hscrolled_p
)
12565 f
->already_hscrolled_p
= 1;
12566 if (hscroll_windows (f
->root_window
))
12570 /* Prevent various kinds of signals during display
12571 update. stdio is not robust about handling
12572 signals, which can cause an apparent I/O
12574 if (interrupt_input
)
12575 unrequest_sigio ();
12578 /* Update the display. */
12579 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12580 pending
|= update_frame (f
, 0, 0);
12586 if (!EQ (old_frame
, selected_frame
)
12587 && FRAME_LIVE_P (XFRAME (old_frame
)))
12588 /* We played a bit fast-and-loose above and allowed selected_frame
12589 and selected_window to be temporarily out-of-sync but let's make
12590 sure this stays contained. */
12591 select_frame_for_redisplay (old_frame
);
12592 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12596 /* Do the mark_window_display_accurate after all windows have
12597 been redisplayed because this call resets flags in buffers
12598 which are needed for proper redisplay. */
12599 FOR_EACH_FRAME (tail
, frame
)
12601 struct frame
*f
= XFRAME (frame
);
12604 mark_window_display_accurate (f
->root_window
, 1);
12605 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12606 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12611 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12613 Lisp_Object mini_window
;
12614 struct frame
*mini_frame
;
12616 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12617 /* Use list_of_error, not Qerror, so that
12618 we catch only errors and don't run the debugger. */
12619 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12621 redisplay_window_error
);
12623 /* Compare desired and current matrices, perform output. */
12626 /* If fonts changed, display again. */
12627 if (fonts_changed_p
)
12630 /* Prevent various kinds of signals during display update.
12631 stdio is not robust about handling signals,
12632 which can cause an apparent I/O error. */
12633 if (interrupt_input
)
12634 unrequest_sigio ();
12637 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12639 if (hscroll_windows (selected_window
))
12642 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12643 pending
= update_frame (sf
, 0, 0);
12646 /* We may have called echo_area_display at the top of this
12647 function. If the echo area is on another frame, that may
12648 have put text on a frame other than the selected one, so the
12649 above call to update_frame would not have caught it. Catch
12651 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12652 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12654 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12656 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12657 pending
|= update_frame (mini_frame
, 0, 0);
12658 if (!pending
&& hscroll_windows (mini_window
))
12663 /* If display was paused because of pending input, make sure we do a
12664 thorough update the next time. */
12667 /* Prevent the optimization at the beginning of
12668 redisplay_internal that tries a single-line update of the
12669 line containing the cursor in the selected window. */
12670 CHARPOS (this_line_start_pos
) = 0;
12672 /* Let the overlay arrow be updated the next time. */
12673 update_overlay_arrows (0);
12675 /* If we pause after scrolling, some rows in the current
12676 matrices of some windows are not valid. */
12677 if (!WINDOW_FULL_WIDTH_P (w
)
12678 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12679 update_mode_lines
= 1;
12683 if (!consider_all_windows_p
)
12685 /* This has already been done above if
12686 consider_all_windows_p is set. */
12687 mark_window_display_accurate_1 (w
, 1);
12689 /* Say overlay arrows are up to date. */
12690 update_overlay_arrows (1);
12692 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12693 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12696 update_mode_lines
= 0;
12697 windows_or_buffers_changed
= 0;
12698 cursor_type_changed
= 0;
12701 /* Start SIGIO interrupts coming again. Having them off during the
12702 code above makes it less likely one will discard output, but not
12703 impossible, since there might be stuff in the system buffer here.
12704 But it is much hairier to try to do anything about that. */
12705 if (interrupt_input
)
12709 /* If a frame has become visible which was not before, redisplay
12710 again, so that we display it. Expose events for such a frame
12711 (which it gets when becoming visible) don't call the parts of
12712 redisplay constructing glyphs, so simply exposing a frame won't
12713 display anything in this case. So, we have to display these
12714 frames here explicitly. */
12717 Lisp_Object tail
, frame
;
12720 FOR_EACH_FRAME (tail
, frame
)
12722 int this_is_visible
= 0;
12724 if (XFRAME (frame
)->visible
)
12725 this_is_visible
= 1;
12726 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12727 if (XFRAME (frame
)->visible
)
12728 this_is_visible
= 1;
12730 if (this_is_visible
)
12734 if (new_count
!= number_of_visible_frames
)
12735 windows_or_buffers_changed
++;
12738 /* Change frame size now if a change is pending. */
12739 do_pending_window_change (1);
12741 /* If we just did a pending size change, or have additional
12742 visible frames, or selected_window changed, redisplay again. */
12743 if ((windows_or_buffers_changed
&& !pending
)
12744 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
12747 /* Clear the face and image caches.
12749 We used to do this only if consider_all_windows_p. But the cache
12750 needs to be cleared if a timer creates images in the current
12751 buffer (e.g. the test case in Bug#6230). */
12753 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12755 clear_face_cache (0);
12756 clear_face_cache_count
= 0;
12759 #ifdef HAVE_WINDOW_SYSTEM
12760 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12762 clear_image_caches (Qnil
);
12763 clear_image_cache_count
= 0;
12765 #endif /* HAVE_WINDOW_SYSTEM */
12768 unbind_to (count
, Qnil
);
12773 /* Redisplay, but leave alone any recent echo area message unless
12774 another message has been requested in its place.
12776 This is useful in situations where you need to redisplay but no
12777 user action has occurred, making it inappropriate for the message
12778 area to be cleared. See tracking_off and
12779 wait_reading_process_output for examples of these situations.
12781 FROM_WHERE is an integer saying from where this function was
12782 called. This is useful for debugging. */
12785 redisplay_preserve_echo_area (int from_where
)
12787 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12789 if (!NILP (echo_area_buffer
[1]))
12791 /* We have a previously displayed message, but no current
12792 message. Redisplay the previous message. */
12793 display_last_displayed_message_p
= 1;
12794 redisplay_internal ();
12795 display_last_displayed_message_p
= 0;
12798 redisplay_internal ();
12800 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12801 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12802 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12806 /* Function registered with record_unwind_protect in
12807 redisplay_internal. Reset redisplaying_p to the value it had
12808 before redisplay_internal was called, and clear
12809 prevent_freeing_realized_faces_p. It also selects the previously
12810 selected frame, unless it has been deleted (by an X connection
12811 failure during redisplay, for example). */
12814 unwind_redisplay (Lisp_Object val
)
12816 Lisp_Object old_redisplaying_p
, old_frame
;
12818 old_redisplaying_p
= XCAR (val
);
12819 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12820 old_frame
= XCDR (val
);
12821 if (! EQ (old_frame
, selected_frame
)
12822 && FRAME_LIVE_P (XFRAME (old_frame
)))
12823 select_frame_for_redisplay (old_frame
);
12828 /* Mark the display of window W as accurate or inaccurate. If
12829 ACCURATE_P is non-zero mark display of W as accurate. If
12830 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12831 redisplay_internal is called. */
12834 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
12836 if (BUFFERP (w
->buffer
))
12838 struct buffer
*b
= XBUFFER (w
->buffer
);
12841 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12842 w
->last_overlay_modified
12843 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12845 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12849 b
->clip_changed
= 0;
12850 b
->prevent_redisplay_optimizations_p
= 0;
12852 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12853 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12854 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12855 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12857 w
->current_matrix
->buffer
= b
;
12858 w
->current_matrix
->begv
= BUF_BEGV (b
);
12859 w
->current_matrix
->zv
= BUF_ZV (b
);
12861 w
->last_cursor
= w
->cursor
;
12862 w
->last_cursor_off_p
= w
->cursor_off_p
;
12864 if (w
== XWINDOW (selected_window
))
12865 w
->last_point
= make_number (BUF_PT (b
));
12867 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12873 w
->window_end_valid
= w
->buffer
;
12874 w
->update_mode_line
= Qnil
;
12879 /* Mark the display of windows in the window tree rooted at WINDOW as
12880 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12881 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12882 be redisplayed the next time redisplay_internal is called. */
12885 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
12889 for (; !NILP (window
); window
= w
->next
)
12891 w
= XWINDOW (window
);
12892 mark_window_display_accurate_1 (w
, accurate_p
);
12894 if (!NILP (w
->vchild
))
12895 mark_window_display_accurate (w
->vchild
, accurate_p
);
12896 if (!NILP (w
->hchild
))
12897 mark_window_display_accurate (w
->hchild
, accurate_p
);
12902 update_overlay_arrows (1);
12906 /* Force a thorough redisplay the next time by setting
12907 last_arrow_position and last_arrow_string to t, which is
12908 unequal to any useful value of Voverlay_arrow_... */
12909 update_overlay_arrows (-1);
12914 /* Return value in display table DP (Lisp_Char_Table *) for character
12915 C. Since a display table doesn't have any parent, we don't have to
12916 follow parent. Do not call this function directly but use the
12917 macro DISP_CHAR_VECTOR. */
12920 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
12924 if (ASCII_CHAR_P (c
))
12927 if (SUB_CHAR_TABLE_P (val
))
12928 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12934 XSETCHAR_TABLE (table
, dp
);
12935 val
= char_table_ref (table
, c
);
12944 /***********************************************************************
12946 ***********************************************************************/
12948 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12951 redisplay_windows (Lisp_Object window
)
12953 while (!NILP (window
))
12955 struct window
*w
= XWINDOW (window
);
12957 if (!NILP (w
->hchild
))
12958 redisplay_windows (w
->hchild
);
12959 else if (!NILP (w
->vchild
))
12960 redisplay_windows (w
->vchild
);
12961 else if (!NILP (w
->buffer
))
12963 displayed_buffer
= XBUFFER (w
->buffer
);
12964 /* Use list_of_error, not Qerror, so that
12965 we catch only errors and don't run the debugger. */
12966 internal_condition_case_1 (redisplay_window_0
, window
,
12968 redisplay_window_error
);
12976 redisplay_window_error (Lisp_Object ignore
)
12978 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12983 redisplay_window_0 (Lisp_Object window
)
12985 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12986 redisplay_window (window
, 0);
12991 redisplay_window_1 (Lisp_Object window
)
12993 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12994 redisplay_window (window
, 1);
12999 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13000 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13001 which positions recorded in ROW differ from current buffer
13004 Return 0 if cursor is not on this row, 1 otherwise. */
13007 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13008 struct glyph_matrix
*matrix
,
13009 EMACS_INT delta
, EMACS_INT delta_bytes
,
13012 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13013 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13014 struct glyph
*cursor
= NULL
;
13015 /* The last known character position in row. */
13016 EMACS_INT last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13018 EMACS_INT pt_old
= PT
- delta
;
13019 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13020 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13021 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13022 /* A glyph beyond the edge of TEXT_AREA which we should never
13024 struct glyph
*glyphs_end
= end
;
13025 /* Non-zero means we've found a match for cursor position, but that
13026 glyph has the avoid_cursor_p flag set. */
13027 int match_with_avoid_cursor
= 0;
13028 /* Non-zero means we've seen at least one glyph that came from a
13030 int string_seen
= 0;
13031 /* Largest and smalles buffer positions seen so far during scan of
13033 EMACS_INT bpos_max
= pos_before
;
13034 EMACS_INT bpos_min
= pos_after
;
13035 /* Last buffer position covered by an overlay string with an integer
13036 `cursor' property. */
13037 EMACS_INT bpos_covered
= 0;
13039 /* Skip over glyphs not having an object at the start and the end of
13040 the row. These are special glyphs like truncation marks on
13041 terminal frames. */
13042 if (row
->displays_text_p
)
13044 if (!row
->reversed_p
)
13047 && INTEGERP (glyph
->object
)
13048 && glyph
->charpos
< 0)
13050 x
+= glyph
->pixel_width
;
13054 && INTEGERP ((end
- 1)->object
)
13055 /* CHARPOS is zero for blanks and stretch glyphs
13056 inserted by extend_face_to_end_of_line. */
13057 && (end
- 1)->charpos
<= 0)
13059 glyph_before
= glyph
- 1;
13066 /* If the glyph row is reversed, we need to process it from back
13067 to front, so swap the edge pointers. */
13068 glyphs_end
= end
= glyph
- 1;
13069 glyph
+= row
->used
[TEXT_AREA
] - 1;
13071 while (glyph
> end
+ 1
13072 && INTEGERP (glyph
->object
)
13073 && glyph
->charpos
< 0)
13076 x
-= glyph
->pixel_width
;
13078 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13080 /* By default, in reversed rows we put the cursor on the
13081 rightmost (first in the reading order) glyph. */
13082 for (g
= end
+ 1; g
< glyph
; g
++)
13083 x
+= g
->pixel_width
;
13085 && INTEGERP ((end
+ 1)->object
)
13086 && (end
+ 1)->charpos
<= 0)
13088 glyph_before
= glyph
+ 1;
13092 else if (row
->reversed_p
)
13094 /* In R2L rows that don't display text, put the cursor on the
13095 rightmost glyph. Case in point: an empty last line that is
13096 part of an R2L paragraph. */
13098 /* Avoid placing the cursor on the last glyph of the row, where
13099 on terminal frames we hold the vertical border between
13100 adjacent windows. */
13101 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13102 && !WINDOW_RIGHTMOST_P (w
)
13103 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13105 x
= -1; /* will be computed below, at label compute_x */
13108 /* Step 1: Try to find the glyph whose character position
13109 corresponds to point. If that's not possible, find 2 glyphs
13110 whose character positions are the closest to point, one before
13111 point, the other after it. */
13112 if (!row
->reversed_p
)
13113 while (/* not marched to end of glyph row */
13115 /* glyph was not inserted by redisplay for internal purposes */
13116 && !INTEGERP (glyph
->object
))
13118 if (BUFFERP (glyph
->object
))
13120 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
13122 if (glyph
->charpos
> bpos_max
)
13123 bpos_max
= glyph
->charpos
;
13124 if (glyph
->charpos
< bpos_min
)
13125 bpos_min
= glyph
->charpos
;
13126 if (!glyph
->avoid_cursor_p
)
13128 /* If we hit point, we've found the glyph on which to
13129 display the cursor. */
13132 match_with_avoid_cursor
= 0;
13135 /* See if we've found a better approximation to
13136 POS_BEFORE or to POS_AFTER. Note that we want the
13137 first (leftmost) glyph of all those that are the
13138 closest from below, and the last (rightmost) of all
13139 those from above. */
13140 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13142 pos_before
= glyph
->charpos
;
13143 glyph_before
= glyph
;
13145 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13147 pos_after
= glyph
->charpos
;
13148 glyph_after
= glyph
;
13151 else if (dpos
== 0)
13152 match_with_avoid_cursor
= 1;
13154 else if (STRINGP (glyph
->object
))
13156 Lisp_Object chprop
;
13157 EMACS_INT glyph_pos
= glyph
->charpos
;
13159 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13161 if (INTEGERP (chprop
))
13163 bpos_covered
= bpos_max
+ XINT (chprop
);
13164 /* If the `cursor' property covers buffer positions up
13165 to and including point, we should display cursor on
13166 this glyph. Note that overlays and text properties
13167 with string values stop bidi reordering, so every
13168 buffer position to the left of the string is always
13169 smaller than any position to the right of the
13170 string. Therefore, if a `cursor' property on one
13171 of the string's characters has an integer value, we
13172 will break out of the loop below _before_ we get to
13173 the position match above. IOW, integer values of
13174 the `cursor' property override the "exact match for
13175 point" strategy of positioning the cursor. */
13176 /* Implementation note: bpos_max == pt_old when, e.g.,
13177 we are in an empty line, where bpos_max is set to
13178 MATRIX_ROW_START_CHARPOS, see above. */
13179 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13188 x
+= glyph
->pixel_width
;
13191 else if (glyph
> end
) /* row is reversed */
13192 while (!INTEGERP (glyph
->object
))
13194 if (BUFFERP (glyph
->object
))
13196 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
13198 if (glyph
->charpos
> bpos_max
)
13199 bpos_max
= glyph
->charpos
;
13200 if (glyph
->charpos
< bpos_min
)
13201 bpos_min
= glyph
->charpos
;
13202 if (!glyph
->avoid_cursor_p
)
13206 match_with_avoid_cursor
= 0;
13209 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13211 pos_before
= glyph
->charpos
;
13212 glyph_before
= glyph
;
13214 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
13216 pos_after
= glyph
->charpos
;
13217 glyph_after
= glyph
;
13220 else if (dpos
== 0)
13221 match_with_avoid_cursor
= 1;
13223 else if (STRINGP (glyph
->object
))
13225 Lisp_Object chprop
;
13226 EMACS_INT glyph_pos
= glyph
->charpos
;
13228 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13230 if (INTEGERP (chprop
))
13232 bpos_covered
= bpos_max
+ XINT (chprop
);
13233 /* If the `cursor' property covers buffer positions up
13234 to and including point, we should display cursor on
13236 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13245 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
13247 x
--; /* can't use any pixel_width */
13250 x
-= glyph
->pixel_width
;
13253 /* Step 2: If we didn't find an exact match for point, we need to
13254 look for a proper place to put the cursor among glyphs between
13255 GLYPH_BEFORE and GLYPH_AFTER. */
13256 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13257 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13258 && bpos_covered
< pt_old
)
13260 /* An empty line has a single glyph whose OBJECT is zero and
13261 whose CHARPOS is the position of a newline on that line.
13262 Note that on a TTY, there are more glyphs after that, which
13263 were produced by extend_face_to_end_of_line, but their
13264 CHARPOS is zero or negative. */
13266 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13267 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
13269 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
13271 EMACS_INT ellipsis_pos
;
13273 /* Scan back over the ellipsis glyphs. */
13274 if (!row
->reversed_p
)
13276 ellipsis_pos
= (glyph
- 1)->charpos
;
13277 while (glyph
> row
->glyphs
[TEXT_AREA
]
13278 && (glyph
- 1)->charpos
== ellipsis_pos
)
13279 glyph
--, x
-= glyph
->pixel_width
;
13280 /* That loop always goes one position too far, including
13281 the glyph before the ellipsis. So scan forward over
13283 x
+= glyph
->pixel_width
;
13286 else /* row is reversed */
13288 ellipsis_pos
= (glyph
+ 1)->charpos
;
13289 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
13290 && (glyph
+ 1)->charpos
== ellipsis_pos
)
13291 glyph
++, x
+= glyph
->pixel_width
;
13292 x
-= glyph
->pixel_width
;
13296 else if (match_with_avoid_cursor
13297 /* A truncated row may not include PT among its
13298 character positions. Setting the cursor inside the
13299 scroll margin will trigger recalculation of hscroll
13300 in hscroll_window_tree. */
13301 || (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
13302 || (row
->truncated_on_right_p
&& pt_old
> bpos_max
)
13303 /* Zero-width characters produce no glyphs. */
13306 && (row
->reversed_p
13307 ? glyph_after
> glyphs_end
13308 : glyph_after
< glyphs_end
)))
13310 cursor
= glyph_after
;
13313 else if (string_seen
)
13315 int incr
= row
->reversed_p
? -1 : +1;
13317 /* Need to find the glyph that came out of a string which is
13318 present at point. That glyph is somewhere between
13319 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
13320 positioned between POS_BEFORE and POS_AFTER in the
13322 struct glyph
*start
, *stop
;
13323 EMACS_INT pos
= pos_before
;
13327 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
13328 correspond to POS_BEFORE and POS_AFTER, respectively. We
13329 need START and STOP in the order that corresponds to the
13330 row's direction as given by its reversed_p flag. If the
13331 directionality of characters between POS_BEFORE and
13332 POS_AFTER is the opposite of the row's base direction,
13333 these characters will have been reordered for display,
13334 and we need to reverse START and STOP. */
13335 if (!row
->reversed_p
)
13337 start
= min (glyph_before
, glyph_after
);
13338 stop
= max (glyph_before
, glyph_after
);
13342 start
= max (glyph_before
, glyph_after
);
13343 stop
= min (glyph_before
, glyph_after
);
13345 for (glyph
= start
+ incr
;
13346 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
13349 /* Any glyphs that come from the buffer are here because
13350 of bidi reordering. Skip them, and only pay
13351 attention to glyphs that came from some string. */
13352 if (STRINGP (glyph
->object
))
13357 str
= glyph
->object
;
13358 tem
= string_buffer_position_lim (str
, pos
, pos_after
, 0);
13359 if (tem
== 0 /* from overlay */
13362 /* If the string from which this glyph came is
13363 found in the buffer at point, then we've
13364 found the glyph we've been looking for. If
13365 it comes from an overlay (tem == 0), and it
13366 has the `cursor' property on one of its
13367 glyphs, record that glyph as a candidate for
13368 displaying the cursor. (As in the
13369 unidirectional version, we will display the
13370 cursor on the last candidate we find.) */
13371 if (tem
== 0 || tem
== pt_old
)
13373 /* The glyphs from this string could have
13374 been reordered. Find the one with the
13375 smallest string position. Or there could
13376 be a character in the string with the
13377 `cursor' property, which means display
13378 cursor on that character's glyph. */
13379 EMACS_INT strpos
= glyph
->charpos
;
13384 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
13385 && EQ (glyph
->object
, str
);
13389 EMACS_INT gpos
= glyph
->charpos
;
13391 cprop
= Fget_char_property (make_number (gpos
),
13399 if (tem
&& glyph
->charpos
< strpos
)
13401 strpos
= glyph
->charpos
;
13410 pos
= tem
+ 1; /* don't find previous instances */
13412 /* This string is not what we want; skip all of the
13413 glyphs that came from it. */
13414 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
13415 && EQ (glyph
->object
, str
))
13422 /* If we reached the end of the line, and END was from a string,
13423 the cursor is not on this line. */
13425 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
13426 && STRINGP (end
->object
)
13427 && row
->continued_p
)
13433 if (cursor
!= NULL
)
13439 /* Need to compute x that corresponds to GLYPH. */
13440 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
13442 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
13444 x
+= g
->pixel_width
;
13448 /* ROW could be part of a continued line, which, under bidi
13449 reordering, might have other rows whose start and end charpos
13450 occlude point. Only set w->cursor if we found a better
13451 approximation to the cursor position than we have from previously
13452 examined candidate rows belonging to the same continued line. */
13453 if (/* we already have a candidate row */
13454 w
->cursor
.vpos
>= 0
13455 /* that candidate is not the row we are processing */
13456 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
13457 /* the row we are processing is part of a continued line */
13458 && (row
->continued_p
|| MATRIX_ROW_CONTINUATION_LINE_P (row
))
13459 /* Make sure cursor.vpos specifies a row whose start and end
13460 charpos occlude point. This is because some callers of this
13461 function leave cursor.vpos at the row where the cursor was
13462 displayed during the last redisplay cycle. */
13463 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
13464 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
13467 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
13469 /* Don't consider glyphs that are outside TEXT_AREA. */
13470 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
13472 /* Keep the candidate whose buffer position is the closest to
13474 if (/* previous candidate is a glyph in TEXT_AREA of that row */
13475 w
->cursor
.hpos
>= 0
13476 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
13477 && BUFFERP (g1
->object
)
13478 && (g1
->charpos
== pt_old
/* an exact match always wins */
13479 || (BUFFERP (glyph
->object
)
13480 && eabs (g1
->charpos
- pt_old
)
13481 < eabs (glyph
->charpos
- pt_old
))))
13483 /* If this candidate gives an exact match, use that. */
13484 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13485 /* Otherwise, keep the candidate that comes from a row
13486 spanning less buffer positions. This may win when one or
13487 both candidate positions are on glyphs that came from
13488 display strings, for which we cannot compare buffer
13490 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13491 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13492 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
13495 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
13497 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
13498 w
->cursor
.y
= row
->y
+ dy
;
13500 if (w
== XWINDOW (selected_window
))
13502 if (!row
->continued_p
13503 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
13506 this_line_buffer
= XBUFFER (w
->buffer
);
13508 CHARPOS (this_line_start_pos
)
13509 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
13510 BYTEPOS (this_line_start_pos
)
13511 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
13513 CHARPOS (this_line_end_pos
)
13514 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
13515 BYTEPOS (this_line_end_pos
)
13516 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
13518 this_line_y
= w
->cursor
.y
;
13519 this_line_pixel_height
= row
->height
;
13520 this_line_vpos
= w
->cursor
.vpos
;
13521 this_line_start_x
= row
->x
;
13524 CHARPOS (this_line_start_pos
) = 0;
13531 /* Run window scroll functions, if any, for WINDOW with new window
13532 start STARTP. Sets the window start of WINDOW to that position.
13534 We assume that the window's buffer is really current. */
13536 static INLINE
struct text_pos
13537 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
13539 struct window
*w
= XWINDOW (window
);
13540 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13542 if (current_buffer
!= XBUFFER (w
->buffer
))
13545 if (!NILP (Vwindow_scroll_functions
))
13547 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13548 make_number (CHARPOS (startp
)));
13549 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13550 /* In case the hook functions switch buffers. */
13551 if (current_buffer
!= XBUFFER (w
->buffer
))
13552 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13559 /* Make sure the line containing the cursor is fully visible.
13560 A value of 1 means there is nothing to be done.
13561 (Either the line is fully visible, or it cannot be made so,
13562 or we cannot tell.)
13564 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13565 is higher than window.
13567 A value of 0 means the caller should do scrolling
13568 as if point had gone off the screen. */
13571 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
13573 struct glyph_matrix
*matrix
;
13574 struct glyph_row
*row
;
13577 if (!make_cursor_line_fully_visible_p
)
13580 /* It's not always possible to find the cursor, e.g, when a window
13581 is full of overlay strings. Don't do anything in that case. */
13582 if (w
->cursor
.vpos
< 0)
13585 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13586 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13588 /* If the cursor row is not partially visible, there's nothing to do. */
13589 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13592 /* If the row the cursor is in is taller than the window's height,
13593 it's not clear what to do, so do nothing. */
13594 window_height
= window_box_height (w
);
13595 if (row
->height
>= window_height
)
13597 if (!force_p
|| MINI_WINDOW_P (w
)
13598 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13605 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13606 non-zero means only WINDOW is redisplayed in redisplay_internal.
13607 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
13608 in redisplay_window to bring a partially visible line into view in
13609 the case that only the cursor has moved.
13611 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13612 last screen line's vertical height extends past the end of the screen.
13616 1 if scrolling succeeded
13618 0 if scrolling didn't find point.
13620 -1 if new fonts have been loaded so that we must interrupt
13621 redisplay, adjust glyph matrices, and try again. */
13627 SCROLLING_NEED_LARGER_MATRICES
13630 /* If scroll-conservatively is more than this, never recenter.
13632 If you change this, don't forget to update the doc string of
13633 `scroll-conservatively' and the Emacs manual. */
13634 #define SCROLL_LIMIT 100
13637 try_scrolling (Lisp_Object window
, int just_this_one_p
,
13638 EMACS_INT arg_scroll_conservatively
, EMACS_INT scroll_step
,
13639 int temp_scroll_step
, int last_line_misfit
)
13641 struct window
*w
= XWINDOW (window
);
13642 struct frame
*f
= XFRAME (w
->frame
);
13643 struct text_pos pos
, startp
;
13645 int this_scroll_margin
, scroll_max
, rc
, height
;
13646 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13647 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13648 Lisp_Object aggressive
;
13649 /* We will never try scrolling more than this number of lines. */
13650 int scroll_limit
= SCROLL_LIMIT
;
13653 debug_method_add (w
, "try_scrolling");
13656 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13658 /* Compute scroll margin height in pixels. We scroll when point is
13659 within this distance from the top or bottom of the window. */
13660 if (scroll_margin
> 0)
13661 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13662 * FRAME_LINE_HEIGHT (f
);
13664 this_scroll_margin
= 0;
13666 /* Force arg_scroll_conservatively to have a reasonable value, to
13667 avoid scrolling too far away with slow move_it_* functions. Note
13668 that the user can supply scroll-conservatively equal to
13669 `most-positive-fixnum', which can be larger than INT_MAX. */
13670 if (arg_scroll_conservatively
> scroll_limit
)
13672 arg_scroll_conservatively
= scroll_limit
+ 1;
13673 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
13675 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
13676 /* Compute how much we should try to scroll maximally to bring
13677 point into view. */
13678 scroll_max
= (max (scroll_step
,
13679 max (arg_scroll_conservatively
, temp_scroll_step
))
13680 * FRAME_LINE_HEIGHT (f
));
13681 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
13682 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
13683 /* We're trying to scroll because of aggressive scrolling but no
13684 scroll_step is set. Choose an arbitrary one. */
13685 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13691 /* Decide whether to scroll down. */
13692 if (PT
> CHARPOS (startp
))
13694 int scroll_margin_y
;
13696 /* Compute the pixel ypos of the scroll margin, then move it to
13697 either that ypos or PT, whichever comes first. */
13698 start_display (&it
, w
, startp
);
13699 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13700 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13701 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13702 (MOVE_TO_POS
| MOVE_TO_Y
));
13704 if (PT
> CHARPOS (it
.current
.pos
))
13706 int y0
= line_bottom_y (&it
);
13707 /* Compute how many pixels below window bottom to stop searching
13708 for PT. This avoids costly search for PT that is far away if
13709 the user limited scrolling by a small number of lines, but
13710 always finds PT if scroll_conservatively is set to a large
13711 number, such as most-positive-fixnum. */
13712 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
13713 int y_to_move
= it
.last_visible_y
+ slack
;
13715 /* Compute the distance from the scroll margin to PT or to
13716 the scroll limit, whichever comes first. This should
13717 include the height of the cursor line, to make that line
13719 move_it_to (&it
, PT
, -1, y_to_move
,
13720 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13721 dy
= line_bottom_y (&it
) - y0
;
13723 if (dy
> scroll_max
)
13724 return SCROLLING_FAILED
;
13732 /* Point is in or below the bottom scroll margin, so move the
13733 window start down. If scrolling conservatively, move it just
13734 enough down to make point visible. If scroll_step is set,
13735 move it down by scroll_step. */
13736 if (arg_scroll_conservatively
)
13738 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13739 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
13740 else if (scroll_step
|| temp_scroll_step
)
13741 amount_to_scroll
= scroll_max
;
13744 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
13745 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13746 if (NUMBERP (aggressive
))
13748 double float_amount
= XFLOATINT (aggressive
) * height
;
13749 amount_to_scroll
= float_amount
;
13750 if (amount_to_scroll
== 0 && float_amount
> 0)
13751 amount_to_scroll
= 1;
13752 /* Don't let point enter the scroll margin near top of
13754 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13755 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13759 if (amount_to_scroll
<= 0)
13760 return SCROLLING_FAILED
;
13762 start_display (&it
, w
, startp
);
13763 if (arg_scroll_conservatively
<= scroll_limit
)
13764 move_it_vertically (&it
, amount_to_scroll
);
13767 /* Extra precision for users who set scroll-conservatively
13768 to a large number: make sure the amount we scroll
13769 the window start is never less than amount_to_scroll,
13770 which was computed as distance from window bottom to
13771 point. This matters when lines at window top and lines
13772 below window bottom have different height. */
13773 struct it it1
= it
;
13774 /* We use a temporary it1 because line_bottom_y can modify
13775 its argument, if it moves one line down; see there. */
13776 int start_y
= line_bottom_y (&it1
);
13779 move_it_by_lines (&it
, 1);
13781 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
13784 /* If STARTP is unchanged, move it down another screen line. */
13785 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13786 move_it_by_lines (&it
, 1);
13787 startp
= it
.current
.pos
;
13791 struct text_pos scroll_margin_pos
= startp
;
13793 /* See if point is inside the scroll margin at the top of the
13795 if (this_scroll_margin
)
13797 start_display (&it
, w
, startp
);
13798 move_it_vertically (&it
, this_scroll_margin
);
13799 scroll_margin_pos
= it
.current
.pos
;
13802 if (PT
< CHARPOS (scroll_margin_pos
))
13804 /* Point is in the scroll margin at the top of the window or
13805 above what is displayed in the window. */
13808 /* Compute the vertical distance from PT to the scroll
13809 margin position. Move as far as scroll_max allows, or
13810 one screenful, or 10 screen lines, whichever is largest.
13811 Give up if distance is greater than scroll_max. */
13812 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13813 start_display (&it
, w
, pos
);
13815 y_to_move
= max (it
.last_visible_y
,
13816 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
13817 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13819 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13820 dy
= it
.current_y
- y0
;
13821 if (dy
> scroll_max
)
13822 return SCROLLING_FAILED
;
13824 /* Compute new window start. */
13825 start_display (&it
, w
, startp
);
13827 if (arg_scroll_conservatively
)
13828 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
13829 max (scroll_step
, temp_scroll_step
));
13830 else if (scroll_step
|| temp_scroll_step
)
13831 amount_to_scroll
= scroll_max
;
13834 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
13835 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13836 if (NUMBERP (aggressive
))
13838 double float_amount
= XFLOATINT (aggressive
) * height
;
13839 amount_to_scroll
= float_amount
;
13840 if (amount_to_scroll
== 0 && float_amount
> 0)
13841 amount_to_scroll
= 1;
13842 amount_to_scroll
-=
13843 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
13844 /* Don't let point enter the scroll margin near
13845 bottom of the window. */
13846 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13847 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13851 if (amount_to_scroll
<= 0)
13852 return SCROLLING_FAILED
;
13854 move_it_vertically_backward (&it
, amount_to_scroll
);
13855 startp
= it
.current
.pos
;
13859 /* Run window scroll functions. */
13860 startp
= run_window_scroll_functions (window
, startp
);
13862 /* Display the window. Give up if new fonts are loaded, or if point
13864 if (!try_window (window
, startp
, 0))
13865 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13866 else if (w
->cursor
.vpos
< 0)
13868 clear_glyph_matrix (w
->desired_matrix
);
13869 rc
= SCROLLING_FAILED
;
13873 /* Maybe forget recorded base line for line number display. */
13874 if (!just_this_one_p
13875 || current_buffer
->clip_changed
13876 || BEG_UNCHANGED
< CHARPOS (startp
))
13877 w
->base_line_number
= Qnil
;
13879 /* If cursor ends up on a partially visible line,
13880 treat that as being off the bottom of the screen. */
13881 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
13882 /* It's possible that the cursor is on the first line of the
13883 buffer, which is partially obscured due to a vscroll
13884 (Bug#7537). In that case, avoid looping forever . */
13885 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
13887 clear_glyph_matrix (w
->desired_matrix
);
13888 ++extra_scroll_margin_lines
;
13891 rc
= SCROLLING_SUCCESS
;
13898 /* Compute a suitable window start for window W if display of W starts
13899 on a continuation line. Value is non-zero if a new window start
13902 The new window start will be computed, based on W's width, starting
13903 from the start of the continued line. It is the start of the
13904 screen line with the minimum distance from the old start W->start. */
13907 compute_window_start_on_continuation_line (struct window
*w
)
13909 struct text_pos pos
, start_pos
;
13910 int window_start_changed_p
= 0;
13912 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13914 /* If window start is on a continuation line... Window start may be
13915 < BEGV in case there's invisible text at the start of the
13916 buffer (M-x rmail, for example). */
13917 if (CHARPOS (start_pos
) > BEGV
13918 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13921 struct glyph_row
*row
;
13923 /* Handle the case that the window start is out of range. */
13924 if (CHARPOS (start_pos
) < BEGV
)
13925 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13926 else if (CHARPOS (start_pos
) > ZV
)
13927 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13929 /* Find the start of the continued line. This should be fast
13930 because scan_buffer is fast (newline cache). */
13931 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13932 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13933 row
, DEFAULT_FACE_ID
);
13934 reseat_at_previous_visible_line_start (&it
);
13936 /* If the line start is "too far" away from the window start,
13937 say it takes too much time to compute a new window start. */
13938 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13939 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13941 int min_distance
, distance
;
13943 /* Move forward by display lines to find the new window
13944 start. If window width was enlarged, the new start can
13945 be expected to be > the old start. If window width was
13946 decreased, the new window start will be < the old start.
13947 So, we're looking for the display line start with the
13948 minimum distance from the old window start. */
13949 pos
= it
.current
.pos
;
13950 min_distance
= INFINITY
;
13951 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13952 distance
< min_distance
)
13954 min_distance
= distance
;
13955 pos
= it
.current
.pos
;
13956 move_it_by_lines (&it
, 1);
13959 /* Set the window start there. */
13960 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13961 window_start_changed_p
= 1;
13965 return window_start_changed_p
;
13969 /* Try cursor movement in case text has not changed in window WINDOW,
13970 with window start STARTP. Value is
13972 CURSOR_MOVEMENT_SUCCESS if successful
13974 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13976 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13977 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13978 we want to scroll as if scroll-step were set to 1. See the code.
13980 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13981 which case we have to abort this redisplay, and adjust matrices
13986 CURSOR_MOVEMENT_SUCCESS
,
13987 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13988 CURSOR_MOVEMENT_MUST_SCROLL
,
13989 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13993 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
13995 struct window
*w
= XWINDOW (window
);
13996 struct frame
*f
= XFRAME (w
->frame
);
13997 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14000 if (inhibit_try_cursor_movement
)
14004 /* Handle case where text has not changed, only point, and it has
14005 not moved off the frame. */
14006 if (/* Point may be in this window. */
14007 PT
>= CHARPOS (startp
)
14008 /* Selective display hasn't changed. */
14009 && !current_buffer
->clip_changed
14010 /* Function force-mode-line-update is used to force a thorough
14011 redisplay. It sets either windows_or_buffers_changed or
14012 update_mode_lines. So don't take a shortcut here for these
14014 && !update_mode_lines
14015 && !windows_or_buffers_changed
14016 && !cursor_type_changed
14017 /* Can't use this case if highlighting a region. When a
14018 region exists, cursor movement has to do more than just
14020 && !(!NILP (Vtransient_mark_mode
)
14021 && !NILP (BVAR (current_buffer
, mark_active
)))
14022 && NILP (w
->region_showing
)
14023 && NILP (Vshow_trailing_whitespace
)
14024 /* Right after splitting windows, last_point may be nil. */
14025 && INTEGERP (w
->last_point
)
14026 /* This code is not used for mini-buffer for the sake of the case
14027 of redisplaying to replace an echo area message; since in
14028 that case the mini-buffer contents per se are usually
14029 unchanged. This code is of no real use in the mini-buffer
14030 since the handling of this_line_start_pos, etc., in redisplay
14031 handles the same cases. */
14032 && !EQ (window
, minibuf_window
)
14033 /* When splitting windows or for new windows, it happens that
14034 redisplay is called with a nil window_end_vpos or one being
14035 larger than the window. This should really be fixed in
14036 window.c. I don't have this on my list, now, so we do
14037 approximately the same as the old redisplay code. --gerd. */
14038 && INTEGERP (w
->window_end_vpos
)
14039 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14040 && (FRAME_WINDOW_P (f
)
14041 || !overlay_arrow_in_current_buffer_p ()))
14043 int this_scroll_margin
, top_scroll_margin
;
14044 struct glyph_row
*row
= NULL
;
14047 debug_method_add (w
, "cursor movement");
14050 /* Scroll if point within this distance from the top or bottom
14051 of the window. This is a pixel value. */
14052 if (scroll_margin
> 0)
14054 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14055 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14058 this_scroll_margin
= 0;
14060 top_scroll_margin
= this_scroll_margin
;
14061 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14062 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14064 /* Start with the row the cursor was displayed during the last
14065 not paused redisplay. Give up if that row is not valid. */
14066 if (w
->last_cursor
.vpos
< 0
14067 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
14068 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14071 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
14072 if (row
->mode_line_p
)
14074 if (!row
->enabled_p
)
14075 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14078 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14080 int scroll_p
= 0, must_scroll
= 0;
14081 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14083 if (PT
> XFASTINT (w
->last_point
))
14085 /* Point has moved forward. */
14086 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14087 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14089 xassert (row
->enabled_p
);
14093 /* If the end position of a row equals the start
14094 position of the next row, and PT is at that position,
14095 we would rather display cursor in the next line. */
14096 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14097 && MATRIX_ROW_END_CHARPOS (row
) == PT
14098 && row
< w
->current_matrix
->rows
14099 + w
->current_matrix
->nrows
- 1
14100 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14101 && !cursor_row_p (row
))
14104 /* If within the scroll margin, scroll. Note that
14105 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
14106 the next line would be drawn, and that
14107 this_scroll_margin can be zero. */
14108 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
14109 || PT
> MATRIX_ROW_END_CHARPOS (row
)
14110 /* Line is completely visible last line in window
14111 and PT is to be set in the next line. */
14112 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
14113 && PT
== MATRIX_ROW_END_CHARPOS (row
)
14114 && !row
->ends_at_zv_p
14115 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14118 else if (PT
< XFASTINT (w
->last_point
))
14120 /* Cursor has to be moved backward. Note that PT >=
14121 CHARPOS (startp) because of the outer if-statement. */
14122 while (!row
->mode_line_p
14123 && (MATRIX_ROW_START_CHARPOS (row
) > PT
14124 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14125 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
14126 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
14127 row
> w
->current_matrix
->rows
14128 && (row
-1)->ends_in_newline_from_string_p
))))
14129 && (row
->y
> top_scroll_margin
14130 || CHARPOS (startp
) == BEGV
))
14132 xassert (row
->enabled_p
);
14136 /* Consider the following case: Window starts at BEGV,
14137 there is invisible, intangible text at BEGV, so that
14138 display starts at some point START > BEGV. It can
14139 happen that we are called with PT somewhere between
14140 BEGV and START. Try to handle that case. */
14141 if (row
< w
->current_matrix
->rows
14142 || row
->mode_line_p
)
14144 row
= w
->current_matrix
->rows
;
14145 if (row
->mode_line_p
)
14149 /* Due to newlines in overlay strings, we may have to
14150 skip forward over overlay strings. */
14151 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14152 && MATRIX_ROW_END_CHARPOS (row
) == PT
14153 && !cursor_row_p (row
))
14156 /* If within the scroll margin, scroll. */
14157 if (row
->y
< top_scroll_margin
14158 && CHARPOS (startp
) != BEGV
)
14163 /* Cursor did not move. So don't scroll even if cursor line
14164 is partially visible, as it was so before. */
14165 rc
= CURSOR_MOVEMENT_SUCCESS
;
14168 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
14169 || PT
> MATRIX_ROW_END_CHARPOS (row
))
14171 /* if PT is not in the glyph row, give up. */
14172 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14175 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14176 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14178 /* If rows are bidi-reordered and point moved, back up
14179 until we find a row that does not belong to a
14180 continuation line. This is because we must consider
14181 all rows of a continued line as candidates for the
14182 new cursor positioning, since row start and end
14183 positions change non-linearly with vertical position
14185 /* FIXME: Revisit this when glyph ``spilling'' in
14186 continuation lines' rows is implemented for
14187 bidi-reordered rows. */
14188 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
14190 xassert (row
->enabled_p
);
14192 /* If we hit the beginning of the displayed portion
14193 without finding the first row of a continued
14195 if (row
<= w
->current_matrix
->rows
)
14197 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14205 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14206 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
14207 && make_cursor_line_fully_visible_p
)
14209 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
14210 && !row
->ends_at_zv_p
14211 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14212 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14213 else if (row
->height
> window_box_height (w
))
14215 /* If we end up in a partially visible line, let's
14216 make it fully visible, except when it's taller
14217 than the window, in which case we can't do much
14220 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14224 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14225 if (!cursor_row_fully_visible_p (w
, 0, 1))
14226 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14228 rc
= CURSOR_MOVEMENT_SUCCESS
;
14232 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14233 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14234 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14236 /* With bidi-reordered rows, there could be more than
14237 one candidate row whose start and end positions
14238 occlude point. We need to let set_cursor_from_row
14239 find the best candidate. */
14240 /* FIXME: Revisit this when glyph ``spilling'' in
14241 continuation lines' rows is implemented for
14242 bidi-reordered rows. */
14247 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
14248 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14249 && cursor_row_p (row
))
14250 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
14252 /* As soon as we've found the first suitable row
14253 whose ends_at_zv_p flag is set, we are done. */
14255 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
14257 rc
= CURSOR_MOVEMENT_SUCCESS
;
14262 while ((MATRIX_ROW_CONTINUATION_LINE_P (row
)
14263 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
14264 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14265 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
14266 /* If we didn't find any candidate rows, or exited the
14267 loop before all the candidates were examined, signal
14268 to the caller that this method failed. */
14269 if (rc
!= CURSOR_MOVEMENT_SUCCESS
14270 && (!rv
|| MATRIX_ROW_CONTINUATION_LINE_P (row
)))
14271 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14273 rc
= CURSOR_MOVEMENT_SUCCESS
;
14279 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
14281 rc
= CURSOR_MOVEMENT_SUCCESS
;
14286 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14287 && MATRIX_ROW_START_CHARPOS (row
) == PT
14288 && cursor_row_p (row
));
14296 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
14300 set_vertical_scroll_bar (struct window
*w
)
14302 EMACS_INT start
, end
, whole
;
14304 /* Calculate the start and end positions for the current window.
14305 At some point, it would be nice to choose between scrollbars
14306 which reflect the whole buffer size, with special markers
14307 indicating narrowing, and scrollbars which reflect only the
14310 Note that mini-buffers sometimes aren't displaying any text. */
14311 if (!MINI_WINDOW_P (w
)
14312 || (w
== XWINDOW (minibuf_window
)
14313 && NILP (echo_area_buffer
[0])))
14315 struct buffer
*buf
= XBUFFER (w
->buffer
);
14316 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
14317 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
14318 /* I don't think this is guaranteed to be right. For the
14319 moment, we'll pretend it is. */
14320 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
14324 if (whole
< (end
- start
))
14325 whole
= end
- start
;
14328 start
= end
= whole
= 0;
14330 /* Indicate what this scroll bar ought to be displaying now. */
14331 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
14332 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
14333 (w
, end
- start
, whole
, start
);
14337 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
14338 selected_window is redisplayed.
14340 We can return without actually redisplaying the window if
14341 fonts_changed_p is nonzero. In that case, redisplay_internal will
14345 redisplay_window (Lisp_Object window
, int just_this_one_p
)
14347 struct window
*w
= XWINDOW (window
);
14348 struct frame
*f
= XFRAME (w
->frame
);
14349 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14350 struct buffer
*old
= current_buffer
;
14351 struct text_pos lpoint
, opoint
, startp
;
14352 int update_mode_line
;
14355 /* Record it now because it's overwritten. */
14356 int current_matrix_up_to_date_p
= 0;
14357 int used_current_matrix_p
= 0;
14358 /* This is less strict than current_matrix_up_to_date_p.
14359 It indictes that the buffer contents and narrowing are unchanged. */
14360 int buffer_unchanged_p
= 0;
14361 int temp_scroll_step
= 0;
14362 int count
= SPECPDL_INDEX ();
14364 int centering_position
= -1;
14365 int last_line_misfit
= 0;
14366 EMACS_INT beg_unchanged
, end_unchanged
;
14368 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14371 /* W must be a leaf window here. */
14372 xassert (!NILP (w
->buffer
));
14374 *w
->desired_matrix
->method
= 0;
14378 reconsider_clip_changes (w
, buffer
);
14380 /* Has the mode line to be updated? */
14381 update_mode_line
= (!NILP (w
->update_mode_line
)
14382 || update_mode_lines
14383 || buffer
->clip_changed
14384 || buffer
->prevent_redisplay_optimizations_p
);
14386 if (MINI_WINDOW_P (w
))
14388 if (w
== XWINDOW (echo_area_window
)
14389 && !NILP (echo_area_buffer
[0]))
14391 if (update_mode_line
)
14392 /* We may have to update a tty frame's menu bar or a
14393 tool-bar. Example `M-x C-h C-h C-g'. */
14394 goto finish_menu_bars
;
14396 /* We've already displayed the echo area glyphs in this window. */
14397 goto finish_scroll_bars
;
14399 else if ((w
!= XWINDOW (minibuf_window
)
14400 || minibuf_level
== 0)
14401 /* When buffer is nonempty, redisplay window normally. */
14402 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
14403 /* Quail displays non-mini buffers in minibuffer window.
14404 In that case, redisplay the window normally. */
14405 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
14407 /* W is a mini-buffer window, but it's not active, so clear
14409 int yb
= window_text_bottom_y (w
);
14410 struct glyph_row
*row
;
14413 for (y
= 0, row
= w
->desired_matrix
->rows
;
14415 y
+= row
->height
, ++row
)
14416 blank_row (w
, row
, y
);
14417 goto finish_scroll_bars
;
14420 clear_glyph_matrix (w
->desired_matrix
);
14423 /* Otherwise set up data on this window; select its buffer and point
14425 /* Really select the buffer, for the sake of buffer-local
14427 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14429 current_matrix_up_to_date_p
14430 = (!NILP (w
->window_end_valid
)
14431 && !current_buffer
->clip_changed
14432 && !current_buffer
->prevent_redisplay_optimizations_p
14433 && XFASTINT (w
->last_modified
) >= MODIFF
14434 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
14436 /* Run the window-bottom-change-functions
14437 if it is possible that the text on the screen has changed
14438 (either due to modification of the text, or any other reason). */
14439 if (!current_matrix_up_to_date_p
14440 && !NILP (Vwindow_text_change_functions
))
14442 safe_run_hooks (Qwindow_text_change_functions
);
14446 beg_unchanged
= BEG_UNCHANGED
;
14447 end_unchanged
= END_UNCHANGED
;
14449 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
14451 specbind (Qinhibit_point_motion_hooks
, Qt
);
14454 = (!NILP (w
->window_end_valid
)
14455 && !current_buffer
->clip_changed
14456 && XFASTINT (w
->last_modified
) >= MODIFF
14457 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
14459 /* When windows_or_buffers_changed is non-zero, we can't rely on
14460 the window end being valid, so set it to nil there. */
14461 if (windows_or_buffers_changed
)
14463 /* If window starts on a continuation line, maybe adjust the
14464 window start in case the window's width changed. */
14465 if (XMARKER (w
->start
)->buffer
== current_buffer
)
14466 compute_window_start_on_continuation_line (w
);
14468 w
->window_end_valid
= Qnil
;
14471 /* Some sanity checks. */
14472 CHECK_WINDOW_END (w
);
14473 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
14475 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
14478 /* If %c is in mode line, update it if needed. */
14479 if (!NILP (w
->column_number_displayed
)
14480 /* This alternative quickly identifies a common case
14481 where no change is needed. */
14482 && !(PT
== XFASTINT (w
->last_point
)
14483 && XFASTINT (w
->last_modified
) >= MODIFF
14484 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
14485 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
14486 update_mode_line
= 1;
14488 /* Count number of windows showing the selected buffer. An indirect
14489 buffer counts as its base buffer. */
14490 if (!just_this_one_p
)
14492 struct buffer
*current_base
, *window_base
;
14493 current_base
= current_buffer
;
14494 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
14495 if (current_base
->base_buffer
)
14496 current_base
= current_base
->base_buffer
;
14497 if (window_base
->base_buffer
)
14498 window_base
= window_base
->base_buffer
;
14499 if (current_base
== window_base
)
14503 /* Point refers normally to the selected window. For any other
14504 window, set up appropriate value. */
14505 if (!EQ (window
, selected_window
))
14507 EMACS_INT new_pt
= XMARKER (w
->pointm
)->charpos
;
14508 EMACS_INT new_pt_byte
= marker_byte_position (w
->pointm
);
14512 new_pt_byte
= BEGV_BYTE
;
14513 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
14515 else if (new_pt
> (ZV
- 1))
14518 new_pt_byte
= ZV_BYTE
;
14519 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
14522 /* We don't use SET_PT so that the point-motion hooks don't run. */
14523 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
14526 /* If any of the character widths specified in the display table
14527 have changed, invalidate the width run cache. It's true that
14528 this may be a bit late to catch such changes, but the rest of
14529 redisplay goes (non-fatally) haywire when the display table is
14530 changed, so why should we worry about doing any better? */
14531 if (current_buffer
->width_run_cache
)
14533 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
14535 if (! disptab_matches_widthtab (disptab
,
14536 XVECTOR (BVAR (current_buffer
, width_table
))))
14538 invalidate_region_cache (current_buffer
,
14539 current_buffer
->width_run_cache
,
14541 recompute_width_table (current_buffer
, disptab
);
14545 /* If window-start is screwed up, choose a new one. */
14546 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
14549 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14551 /* If someone specified a new starting point but did not insist,
14552 check whether it can be used. */
14553 if (!NILP (w
->optional_new_start
)
14554 && CHARPOS (startp
) >= BEGV
14555 && CHARPOS (startp
) <= ZV
)
14557 w
->optional_new_start
= Qnil
;
14558 start_display (&it
, w
, startp
);
14559 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
14560 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14561 if (IT_CHARPOS (it
) == PT
)
14562 w
->force_start
= Qt
;
14563 /* IT may overshoot PT if text at PT is invisible. */
14564 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
14565 w
->force_start
= Qt
;
14570 /* Handle case where place to start displaying has been specified,
14571 unless the specified location is outside the accessible range. */
14572 if (!NILP (w
->force_start
)
14573 || w
->frozen_window_start_p
)
14575 /* We set this later on if we have to adjust point. */
14578 w
->force_start
= Qnil
;
14580 w
->window_end_valid
= Qnil
;
14582 /* Forget any recorded base line for line number display. */
14583 if (!buffer_unchanged_p
)
14584 w
->base_line_number
= Qnil
;
14586 /* Redisplay the mode line. Select the buffer properly for that.
14587 Also, run the hook window-scroll-functions
14588 because we have scrolled. */
14589 /* Note, we do this after clearing force_start because
14590 if there's an error, it is better to forget about force_start
14591 than to get into an infinite loop calling the hook functions
14592 and having them get more errors. */
14593 if (!update_mode_line
14594 || ! NILP (Vwindow_scroll_functions
))
14596 update_mode_line
= 1;
14597 w
->update_mode_line
= Qt
;
14598 startp
= run_window_scroll_functions (window
, startp
);
14601 w
->last_modified
= make_number (0);
14602 w
->last_overlay_modified
= make_number (0);
14603 if (CHARPOS (startp
) < BEGV
)
14604 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14605 else if (CHARPOS (startp
) > ZV
)
14606 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14608 /* Redisplay, then check if cursor has been set during the
14609 redisplay. Give up if new fonts were loaded. */
14610 /* We used to issue a CHECK_MARGINS argument to try_window here,
14611 but this causes scrolling to fail when point begins inside
14612 the scroll margin (bug#148) -- cyd */
14613 if (!try_window (window
, startp
, 0))
14615 w
->force_start
= Qt
;
14616 clear_glyph_matrix (w
->desired_matrix
);
14617 goto need_larger_matrices
;
14620 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14622 /* If point does not appear, try to move point so it does
14623 appear. The desired matrix has been built above, so we
14624 can use it here. */
14625 new_vpos
= window_box_height (w
) / 2;
14628 if (!cursor_row_fully_visible_p (w
, 0, 0))
14630 /* Point does appear, but on a line partly visible at end of window.
14631 Move it back to a fully-visible line. */
14632 new_vpos
= window_box_height (w
);
14635 /* If we need to move point for either of the above reasons,
14636 now actually do it. */
14639 struct glyph_row
*row
;
14641 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14642 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14645 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14646 MATRIX_ROW_START_BYTEPOS (row
));
14648 if (w
!= XWINDOW (selected_window
))
14649 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14650 else if (current_buffer
== old
)
14651 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14653 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14655 /* If we are highlighting the region, then we just changed
14656 the region, so redisplay to show it. */
14657 if (!NILP (Vtransient_mark_mode
)
14658 && !NILP (BVAR (current_buffer
, mark_active
)))
14660 clear_glyph_matrix (w
->desired_matrix
);
14661 if (!try_window (window
, startp
, 0))
14662 goto need_larger_matrices
;
14667 debug_method_add (w
, "forced window start");
14672 /* Handle case where text has not changed, only point, and it has
14673 not moved off the frame, and we are not retrying after hscroll.
14674 (current_matrix_up_to_date_p is nonzero when retrying.) */
14675 if (current_matrix_up_to_date_p
14676 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14677 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14681 case CURSOR_MOVEMENT_SUCCESS
:
14682 used_current_matrix_p
= 1;
14685 case CURSOR_MOVEMENT_MUST_SCROLL
:
14686 goto try_to_scroll
;
14692 /* If current starting point was originally the beginning of a line
14693 but no longer is, find a new starting point. */
14694 else if (!NILP (w
->start_at_line_beg
)
14695 && !(CHARPOS (startp
) <= BEGV
14696 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14699 debug_method_add (w
, "recenter 1");
14704 /* Try scrolling with try_window_id. Value is > 0 if update has
14705 been done, it is -1 if we know that the same window start will
14706 not work. It is 0 if unsuccessful for some other reason. */
14707 else if ((tem
= try_window_id (w
)) != 0)
14710 debug_method_add (w
, "try_window_id %d", tem
);
14713 if (fonts_changed_p
)
14714 goto need_larger_matrices
;
14718 /* Otherwise try_window_id has returned -1 which means that we
14719 don't want the alternative below this comment to execute. */
14721 else if (CHARPOS (startp
) >= BEGV
14722 && CHARPOS (startp
) <= ZV
14723 && PT
>= CHARPOS (startp
)
14724 && (CHARPOS (startp
) < ZV
14725 /* Avoid starting at end of buffer. */
14726 || CHARPOS (startp
) == BEGV
14727 || (XFASTINT (w
->last_modified
) >= MODIFF
14728 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14731 /* If first window line is a continuation line, and window start
14732 is inside the modified region, but the first change is before
14733 current window start, we must select a new window start.
14735 However, if this is the result of a down-mouse event (e.g. by
14736 extending the mouse-drag-overlay), we don't want to select a
14737 new window start, since that would change the position under
14738 the mouse, resulting in an unwanted mouse-movement rather
14739 than a simple mouse-click. */
14740 if (NILP (w
->start_at_line_beg
)
14741 && NILP (do_mouse_tracking
)
14742 && CHARPOS (startp
) > BEGV
14743 && CHARPOS (startp
) > BEG
+ beg_unchanged
14744 && CHARPOS (startp
) <= Z
- end_unchanged
14745 /* Even if w->start_at_line_beg is nil, a new window may
14746 start at a line_beg, since that's how set_buffer_window
14747 sets it. So, we need to check the return value of
14748 compute_window_start_on_continuation_line. (See also
14750 && XMARKER (w
->start
)->buffer
== current_buffer
14751 && compute_window_start_on_continuation_line (w
))
14753 w
->force_start
= Qt
;
14754 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14759 debug_method_add (w
, "same window start");
14762 /* Try to redisplay starting at same place as before.
14763 If point has not moved off frame, accept the results. */
14764 if (!current_matrix_up_to_date_p
14765 /* Don't use try_window_reusing_current_matrix in this case
14766 because a window scroll function can have changed the
14768 || !NILP (Vwindow_scroll_functions
)
14769 || MINI_WINDOW_P (w
)
14770 || !(used_current_matrix_p
14771 = try_window_reusing_current_matrix (w
)))
14773 IF_DEBUG (debug_method_add (w
, "1"));
14774 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
14775 /* -1 means we need to scroll.
14776 0 means we need new matrices, but fonts_changed_p
14777 is set in that case, so we will detect it below. */
14778 goto try_to_scroll
;
14781 if (fonts_changed_p
)
14782 goto need_larger_matrices
;
14784 if (w
->cursor
.vpos
>= 0)
14786 if (!just_this_one_p
14787 || current_buffer
->clip_changed
14788 || BEG_UNCHANGED
< CHARPOS (startp
))
14789 /* Forget any recorded base line for line number display. */
14790 w
->base_line_number
= Qnil
;
14792 if (!cursor_row_fully_visible_p (w
, 1, 0))
14794 clear_glyph_matrix (w
->desired_matrix
);
14795 last_line_misfit
= 1;
14797 /* Drop through and scroll. */
14802 clear_glyph_matrix (w
->desired_matrix
);
14807 w
->last_modified
= make_number (0);
14808 w
->last_overlay_modified
= make_number (0);
14810 /* Redisplay the mode line. Select the buffer properly for that. */
14811 if (!update_mode_line
)
14813 update_mode_line
= 1;
14814 w
->update_mode_line
= Qt
;
14817 /* Try to scroll by specified few lines. */
14818 if ((scroll_conservatively
14819 || emacs_scroll_step
14820 || temp_scroll_step
14821 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
14822 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
14823 && CHARPOS (startp
) >= BEGV
14824 && CHARPOS (startp
) <= ZV
)
14826 /* The function returns -1 if new fonts were loaded, 1 if
14827 successful, 0 if not successful. */
14828 int ss
= try_scrolling (window
, just_this_one_p
,
14829 scroll_conservatively
,
14831 temp_scroll_step
, last_line_misfit
);
14834 case SCROLLING_SUCCESS
:
14837 case SCROLLING_NEED_LARGER_MATRICES
:
14838 goto need_larger_matrices
;
14840 case SCROLLING_FAILED
:
14848 /* Finally, just choose a place to start which positions point
14849 according to user preferences. */
14854 debug_method_add (w
, "recenter");
14857 /* w->vscroll = 0; */
14859 /* Forget any previously recorded base line for line number display. */
14860 if (!buffer_unchanged_p
)
14861 w
->base_line_number
= Qnil
;
14863 /* Determine the window start relative to point. */
14864 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14865 it
.current_y
= it
.last_visible_y
;
14866 if (centering_position
< 0)
14870 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14872 EMACS_INT margin_pos
= CHARPOS (startp
);
14874 Lisp_Object aggressive
;
14876 /* If there is a scroll margin at the top of the window, find
14877 its character position. */
14879 /* Cannot call start_display if startp is not in the
14880 accessible region of the buffer. This can happen when we
14881 have just switched to a different buffer and/or changed
14882 its restriction. In that case, startp is initialized to
14883 the character position 1 (BEG) because we did not yet
14884 have chance to display the buffer even once. */
14885 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
14889 start_display (&it1
, w
, startp
);
14890 move_it_vertically (&it1
, margin
);
14891 margin_pos
= IT_CHARPOS (it1
);
14893 scrolling_up
= PT
> margin_pos
;
14896 ? BVAR (current_buffer
, scroll_up_aggressively
)
14897 : BVAR (current_buffer
, scroll_down_aggressively
);
14899 if (!MINI_WINDOW_P (w
)
14900 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
14904 /* Setting scroll-conservatively overrides
14905 scroll-*-aggressively. */
14906 if (!scroll_conservatively
&& NUMBERP (aggressive
))
14908 double float_amount
= XFLOATINT (aggressive
);
14910 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
14911 if (pt_offset
== 0 && float_amount
> 0)
14916 /* Compute how much to move the window start backward from
14917 point so that point will be displayed where the user
14921 centering_position
= it
.last_visible_y
;
14923 centering_position
-= pt_offset
;
14924 centering_position
-=
14925 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0));
14926 /* Don't let point enter the scroll margin near top of
14928 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
14929 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
14932 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
14935 /* Set the window start half the height of the window backward
14937 centering_position
= window_box_height (w
) / 2;
14939 move_it_vertically_backward (&it
, centering_position
);
14941 xassert (IT_CHARPOS (it
) >= BEGV
);
14943 /* The function move_it_vertically_backward may move over more
14944 than the specified y-distance. If it->w is small, e.g. a
14945 mini-buffer window, we may end up in front of the window's
14946 display area. Start displaying at the start of the line
14947 containing PT in this case. */
14948 if (it
.current_y
<= 0)
14950 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14951 move_it_vertically_backward (&it
, 0);
14955 it
.current_x
= it
.hpos
= 0;
14957 /* Set the window start position here explicitly, to avoid an
14958 infinite loop in case the functions in window-scroll-functions
14960 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14962 /* Run scroll hooks. */
14963 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14965 /* Redisplay the window. */
14966 if (!current_matrix_up_to_date_p
14967 || windows_or_buffers_changed
14968 || cursor_type_changed
14969 /* Don't use try_window_reusing_current_matrix in this case
14970 because it can have changed the buffer. */
14971 || !NILP (Vwindow_scroll_functions
)
14972 || !just_this_one_p
14973 || MINI_WINDOW_P (w
)
14974 || !(used_current_matrix_p
14975 = try_window_reusing_current_matrix (w
)))
14976 try_window (window
, startp
, 0);
14978 /* If new fonts have been loaded (due to fontsets), give up. We
14979 have to start a new redisplay since we need to re-adjust glyph
14981 if (fonts_changed_p
)
14982 goto need_larger_matrices
;
14984 /* If cursor did not appear assume that the middle of the window is
14985 in the first line of the window. Do it again with the next line.
14986 (Imagine a window of height 100, displaying two lines of height
14987 60. Moving back 50 from it->last_visible_y will end in the first
14989 if (w
->cursor
.vpos
< 0)
14991 if (!NILP (w
->window_end_valid
)
14992 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14994 clear_glyph_matrix (w
->desired_matrix
);
14995 move_it_by_lines (&it
, 1);
14996 try_window (window
, it
.current
.pos
, 0);
14998 else if (PT
< IT_CHARPOS (it
))
15000 clear_glyph_matrix (w
->desired_matrix
);
15001 move_it_by_lines (&it
, -1);
15002 try_window (window
, it
.current
.pos
, 0);
15006 /* Not much we can do about it. */
15010 /* Consider the following case: Window starts at BEGV, there is
15011 invisible, intangible text at BEGV, so that display starts at
15012 some point START > BEGV. It can happen that we are called with
15013 PT somewhere between BEGV and START. Try to handle that case. */
15014 if (w
->cursor
.vpos
< 0)
15016 struct glyph_row
*row
= w
->current_matrix
->rows
;
15017 if (row
->mode_line_p
)
15019 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15022 if (!cursor_row_fully_visible_p (w
, 0, 0))
15024 /* If vscroll is enabled, disable it and try again. */
15028 clear_glyph_matrix (w
->desired_matrix
);
15032 /* If centering point failed to make the whole line visible,
15033 put point at the top instead. That has to make the whole line
15034 visible, if it can be done. */
15035 if (centering_position
== 0)
15038 clear_glyph_matrix (w
->desired_matrix
);
15039 centering_position
= 0;
15045 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15046 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
15047 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
15050 /* Display the mode line, if we must. */
15051 if ((update_mode_line
15052 /* If window not full width, must redo its mode line
15053 if (a) the window to its side is being redone and
15054 (b) we do a frame-based redisplay. This is a consequence
15055 of how inverted lines are drawn in frame-based redisplay. */
15056 || (!just_this_one_p
15057 && !FRAME_WINDOW_P (f
)
15058 && !WINDOW_FULL_WIDTH_P (w
))
15059 /* Line number to display. */
15060 || INTEGERP (w
->base_line_pos
)
15061 /* Column number is displayed and different from the one displayed. */
15062 || (!NILP (w
->column_number_displayed
)
15063 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
15064 /* This means that the window has a mode line. */
15065 && (WINDOW_WANTS_MODELINE_P (w
)
15066 || WINDOW_WANTS_HEADER_LINE_P (w
)))
15068 display_mode_lines (w
);
15070 /* If mode line height has changed, arrange for a thorough
15071 immediate redisplay using the correct mode line height. */
15072 if (WINDOW_WANTS_MODELINE_P (w
)
15073 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
15075 fonts_changed_p
= 1;
15076 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
15077 = DESIRED_MODE_LINE_HEIGHT (w
);
15080 /* If header line height has changed, arrange for a thorough
15081 immediate redisplay using the correct header line height. */
15082 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15083 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
15085 fonts_changed_p
= 1;
15086 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
15087 = DESIRED_HEADER_LINE_HEIGHT (w
);
15090 if (fonts_changed_p
)
15091 goto need_larger_matrices
;
15094 if (!line_number_displayed
15095 && !BUFFERP (w
->base_line_pos
))
15097 w
->base_line_pos
= Qnil
;
15098 w
->base_line_number
= Qnil
;
15103 /* When we reach a frame's selected window, redo the frame's menu bar. */
15104 if (update_mode_line
15105 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
15107 int redisplay_menu_p
= 0;
15109 if (FRAME_WINDOW_P (f
))
15111 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
15112 || defined (HAVE_NS) || defined (USE_GTK)
15113 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
15115 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15119 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15121 if (redisplay_menu_p
)
15122 display_menu_bar (w
);
15124 #ifdef HAVE_WINDOW_SYSTEM
15125 if (FRAME_WINDOW_P (f
))
15127 #if defined (USE_GTK) || defined (HAVE_NS)
15128 if (FRAME_EXTERNAL_TOOL_BAR (f
))
15129 redisplay_tool_bar (f
);
15131 if (WINDOWP (f
->tool_bar_window
)
15132 && (FRAME_TOOL_BAR_LINES (f
) > 0
15133 || !NILP (Vauto_resize_tool_bars
))
15134 && redisplay_tool_bar (f
))
15135 ignore_mouse_drag_p
= 1;
15141 #ifdef HAVE_WINDOW_SYSTEM
15142 if (FRAME_WINDOW_P (f
)
15143 && update_window_fringes (w
, (just_this_one_p
15144 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
15145 || w
->pseudo_window_p
)))
15149 if (draw_window_fringes (w
, 1))
15150 x_draw_vertical_border (w
);
15154 #endif /* HAVE_WINDOW_SYSTEM */
15156 /* We go to this label, with fonts_changed_p nonzero,
15157 if it is necessary to try again using larger glyph matrices.
15158 We have to redeem the scroll bar even in this case,
15159 because the loop in redisplay_internal expects that. */
15160 need_larger_matrices
:
15162 finish_scroll_bars
:
15164 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
15166 /* Set the thumb's position and size. */
15167 set_vertical_scroll_bar (w
);
15169 /* Note that we actually used the scroll bar attached to this
15170 window, so it shouldn't be deleted at the end of redisplay. */
15171 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
15172 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
15175 /* Restore current_buffer and value of point in it. The window
15176 update may have changed the buffer, so first make sure `opoint'
15177 is still valid (Bug#6177). */
15178 if (CHARPOS (opoint
) < BEGV
)
15179 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15180 else if (CHARPOS (opoint
) > ZV
)
15181 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
15183 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
15185 set_buffer_internal_1 (old
);
15186 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
15187 shorter. This can be caused by log truncation in *Messages*. */
15188 if (CHARPOS (lpoint
) <= ZV
)
15189 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15191 unbind_to (count
, Qnil
);
15195 /* Build the complete desired matrix of WINDOW with a window start
15196 buffer position POS.
15198 Value is 1 if successful. It is zero if fonts were loaded during
15199 redisplay which makes re-adjusting glyph matrices necessary, and -1
15200 if point would appear in the scroll margins.
15201 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
15202 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
15206 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
15208 struct window
*w
= XWINDOW (window
);
15210 struct glyph_row
*last_text_row
= NULL
;
15211 struct frame
*f
= XFRAME (w
->frame
);
15213 /* Make POS the new window start. */
15214 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
15216 /* Mark cursor position as unknown. No overlay arrow seen. */
15217 w
->cursor
.vpos
= -1;
15218 overlay_arrow_seen
= 0;
15220 /* Initialize iterator and info to start at POS. */
15221 start_display (&it
, w
, pos
);
15223 /* Display all lines of W. */
15224 while (it
.current_y
< it
.last_visible_y
)
15226 if (display_line (&it
))
15227 last_text_row
= it
.glyph_row
- 1;
15228 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
15232 /* Don't let the cursor end in the scroll margins. */
15233 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
15234 && !MINI_WINDOW_P (w
))
15236 int this_scroll_margin
;
15238 if (scroll_margin
> 0)
15240 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15241 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15244 this_scroll_margin
= 0;
15246 if ((w
->cursor
.y
>= 0 /* not vscrolled */
15247 && w
->cursor
.y
< this_scroll_margin
15248 && CHARPOS (pos
) > BEGV
15249 && IT_CHARPOS (it
) < ZV
)
15250 /* rms: considering make_cursor_line_fully_visible_p here
15251 seems to give wrong results. We don't want to recenter
15252 when the last line is partly visible, we want to allow
15253 that case to be handled in the usual way. */
15254 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
15256 w
->cursor
.vpos
= -1;
15257 clear_glyph_matrix (w
->desired_matrix
);
15262 /* If bottom moved off end of frame, change mode line percentage. */
15263 if (XFASTINT (w
->window_end_pos
) <= 0
15264 && Z
!= IT_CHARPOS (it
))
15265 w
->update_mode_line
= Qt
;
15267 /* Set window_end_pos to the offset of the last character displayed
15268 on the window from the end of current_buffer. Set
15269 window_end_vpos to its row number. */
15272 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
15273 w
->window_end_bytepos
15274 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15276 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15278 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15279 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
15280 ->displays_text_p
);
15284 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
15285 w
->window_end_pos
= make_number (Z
- ZV
);
15286 w
->window_end_vpos
= make_number (0);
15289 /* But that is not valid info until redisplay finishes. */
15290 w
->window_end_valid
= Qnil
;
15296 /************************************************************************
15297 Window redisplay reusing current matrix when buffer has not changed
15298 ************************************************************************/
15300 /* Try redisplay of window W showing an unchanged buffer with a
15301 different window start than the last time it was displayed by
15302 reusing its current matrix. Value is non-zero if successful.
15303 W->start is the new window start. */
15306 try_window_reusing_current_matrix (struct window
*w
)
15308 struct frame
*f
= XFRAME (w
->frame
);
15309 struct glyph_row
*bottom_row
;
15312 struct text_pos start
, new_start
;
15313 int nrows_scrolled
, i
;
15314 struct glyph_row
*last_text_row
;
15315 struct glyph_row
*last_reused_text_row
;
15316 struct glyph_row
*start_row
;
15317 int start_vpos
, min_y
, max_y
;
15320 if (inhibit_try_window_reusing
)
15324 if (/* This function doesn't handle terminal frames. */
15325 !FRAME_WINDOW_P (f
)
15326 /* Don't try to reuse the display if windows have been split
15328 || windows_or_buffers_changed
15329 || cursor_type_changed
)
15332 /* Can't do this if region may have changed. */
15333 if ((!NILP (Vtransient_mark_mode
)
15334 && !NILP (BVAR (current_buffer
, mark_active
)))
15335 || !NILP (w
->region_showing
)
15336 || !NILP (Vshow_trailing_whitespace
))
15339 /* If top-line visibility has changed, give up. */
15340 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15341 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
15344 /* Give up if old or new display is scrolled vertically. We could
15345 make this function handle this, but right now it doesn't. */
15346 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15347 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
15350 /* The variable new_start now holds the new window start. The old
15351 start `start' can be determined from the current matrix. */
15352 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
15353 start
= start_row
->minpos
;
15354 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
15356 /* Clear the desired matrix for the display below. */
15357 clear_glyph_matrix (w
->desired_matrix
);
15359 if (CHARPOS (new_start
) <= CHARPOS (start
))
15361 /* Don't use this method if the display starts with an ellipsis
15362 displayed for invisible text. It's not easy to handle that case
15363 below, and it's certainly not worth the effort since this is
15364 not a frequent case. */
15365 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
15368 IF_DEBUG (debug_method_add (w
, "twu1"));
15370 /* Display up to a row that can be reused. The variable
15371 last_text_row is set to the last row displayed that displays
15372 text. Note that it.vpos == 0 if or if not there is a
15373 header-line; it's not the same as the MATRIX_ROW_VPOS! */
15374 start_display (&it
, w
, new_start
);
15375 w
->cursor
.vpos
= -1;
15376 last_text_row
= last_reused_text_row
= NULL
;
15378 while (it
.current_y
< it
.last_visible_y
15379 && !fonts_changed_p
)
15381 /* If we have reached into the characters in the START row,
15382 that means the line boundaries have changed. So we
15383 can't start copying with the row START. Maybe it will
15384 work to start copying with the following row. */
15385 while (IT_CHARPOS (it
) > CHARPOS (start
))
15387 /* Advance to the next row as the "start". */
15389 start
= start_row
->minpos
;
15390 /* If there are no more rows to try, or just one, give up. */
15391 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
15392 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
15393 || CHARPOS (start
) == ZV
)
15395 clear_glyph_matrix (w
->desired_matrix
);
15399 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
15401 /* If we have reached alignment,
15402 we can copy the rest of the rows. */
15403 if (IT_CHARPOS (it
) == CHARPOS (start
))
15406 if (display_line (&it
))
15407 last_text_row
= it
.glyph_row
- 1;
15410 /* A value of current_y < last_visible_y means that we stopped
15411 at the previous window start, which in turn means that we
15412 have at least one reusable row. */
15413 if (it
.current_y
< it
.last_visible_y
)
15415 struct glyph_row
*row
;
15417 /* IT.vpos always starts from 0; it counts text lines. */
15418 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
15420 /* Find PT if not already found in the lines displayed. */
15421 if (w
->cursor
.vpos
< 0)
15423 int dy
= it
.current_y
- start_row
->y
;
15425 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15426 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
15428 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
15429 dy
, nrows_scrolled
);
15432 clear_glyph_matrix (w
->desired_matrix
);
15437 /* Scroll the display. Do it before the current matrix is
15438 changed. The problem here is that update has not yet
15439 run, i.e. part of the current matrix is not up to date.
15440 scroll_run_hook will clear the cursor, and use the
15441 current matrix to get the height of the row the cursor is
15443 run
.current_y
= start_row
->y
;
15444 run
.desired_y
= it
.current_y
;
15445 run
.height
= it
.last_visible_y
- it
.current_y
;
15447 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
15450 FRAME_RIF (f
)->update_window_begin_hook (w
);
15451 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15452 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15453 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15457 /* Shift current matrix down by nrows_scrolled lines. */
15458 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15459 rotate_matrix (w
->current_matrix
,
15461 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15464 /* Disable lines that must be updated. */
15465 for (i
= 0; i
< nrows_scrolled
; ++i
)
15466 (start_row
+ i
)->enabled_p
= 0;
15468 /* Re-compute Y positions. */
15469 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15470 max_y
= it
.last_visible_y
;
15471 for (row
= start_row
+ nrows_scrolled
;
15475 row
->y
= it
.current_y
;
15476 row
->visible_height
= row
->height
;
15478 if (row
->y
< min_y
)
15479 row
->visible_height
-= min_y
- row
->y
;
15480 if (row
->y
+ row
->height
> max_y
)
15481 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15482 row
->redraw_fringe_bitmaps_p
= 1;
15484 it
.current_y
+= row
->height
;
15486 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15487 last_reused_text_row
= row
;
15488 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
15492 /* Disable lines in the current matrix which are now
15493 below the window. */
15494 for (++row
; row
< bottom_row
; ++row
)
15495 row
->enabled_p
= row
->mode_line_p
= 0;
15498 /* Update window_end_pos etc.; last_reused_text_row is the last
15499 reused row from the current matrix containing text, if any.
15500 The value of last_text_row is the last displayed line
15501 containing text. */
15502 if (last_reused_text_row
)
15504 w
->window_end_bytepos
15505 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
15507 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
15509 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
15510 w
->current_matrix
));
15512 else if (last_text_row
)
15514 w
->window_end_bytepos
15515 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15517 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15519 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15523 /* This window must be completely empty. */
15524 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
15525 w
->window_end_pos
= make_number (Z
- ZV
);
15526 w
->window_end_vpos
= make_number (0);
15528 w
->window_end_valid
= Qnil
;
15530 /* Update hint: don't try scrolling again in update_window. */
15531 w
->desired_matrix
->no_scrolling_p
= 1;
15534 debug_method_add (w
, "try_window_reusing_current_matrix 1");
15538 else if (CHARPOS (new_start
) > CHARPOS (start
))
15540 struct glyph_row
*pt_row
, *row
;
15541 struct glyph_row
*first_reusable_row
;
15542 struct glyph_row
*first_row_to_display
;
15544 int yb
= window_text_bottom_y (w
);
15546 /* Find the row starting at new_start, if there is one. Don't
15547 reuse a partially visible line at the end. */
15548 first_reusable_row
= start_row
;
15549 while (first_reusable_row
->enabled_p
15550 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
15551 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15552 < CHARPOS (new_start
)))
15553 ++first_reusable_row
;
15555 /* Give up if there is no row to reuse. */
15556 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
15557 || !first_reusable_row
->enabled_p
15558 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15559 != CHARPOS (new_start
)))
15562 /* We can reuse fully visible rows beginning with
15563 first_reusable_row to the end of the window. Set
15564 first_row_to_display to the first row that cannot be reused.
15565 Set pt_row to the row containing point, if there is any. */
15567 for (first_row_to_display
= first_reusable_row
;
15568 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
15569 ++first_row_to_display
)
15571 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
15572 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
15573 pt_row
= first_row_to_display
;
15576 /* Start displaying at the start of first_row_to_display. */
15577 xassert (first_row_to_display
->y
< yb
);
15578 init_to_row_start (&it
, w
, first_row_to_display
);
15580 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
15582 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
15584 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
15585 + WINDOW_HEADER_LINE_HEIGHT (w
));
15587 /* Display lines beginning with first_row_to_display in the
15588 desired matrix. Set last_text_row to the last row displayed
15589 that displays text. */
15590 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
15591 if (pt_row
== NULL
)
15592 w
->cursor
.vpos
= -1;
15593 last_text_row
= NULL
;
15594 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
15595 if (display_line (&it
))
15596 last_text_row
= it
.glyph_row
- 1;
15598 /* If point is in a reused row, adjust y and vpos of the cursor
15602 w
->cursor
.vpos
-= nrows_scrolled
;
15603 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
15606 /* Give up if point isn't in a row displayed or reused. (This
15607 also handles the case where w->cursor.vpos < nrows_scrolled
15608 after the calls to display_line, which can happen with scroll
15609 margins. See bug#1295.) */
15610 if (w
->cursor
.vpos
< 0)
15612 clear_glyph_matrix (w
->desired_matrix
);
15616 /* Scroll the display. */
15617 run
.current_y
= first_reusable_row
->y
;
15618 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15619 run
.height
= it
.last_visible_y
- run
.current_y
;
15620 dy
= run
.current_y
- run
.desired_y
;
15625 FRAME_RIF (f
)->update_window_begin_hook (w
);
15626 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15627 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15628 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15632 /* Adjust Y positions of reused rows. */
15633 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15634 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15635 max_y
= it
.last_visible_y
;
15636 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15639 row
->visible_height
= row
->height
;
15640 if (row
->y
< min_y
)
15641 row
->visible_height
-= min_y
- row
->y
;
15642 if (row
->y
+ row
->height
> max_y
)
15643 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15644 row
->redraw_fringe_bitmaps_p
= 1;
15647 /* Scroll the current matrix. */
15648 xassert (nrows_scrolled
> 0);
15649 rotate_matrix (w
->current_matrix
,
15651 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15654 /* Disable rows not reused. */
15655 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15656 row
->enabled_p
= 0;
15658 /* Point may have moved to a different line, so we cannot assume that
15659 the previous cursor position is valid; locate the correct row. */
15662 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15663 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15667 w
->cursor
.y
= row
->y
;
15669 if (row
< bottom_row
)
15671 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15672 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15674 /* Can't use this optimization with bidi-reordered glyph
15675 rows, unless cursor is already at point. */
15676 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15678 if (!(w
->cursor
.hpos
>= 0
15679 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
15680 && BUFFERP (glyph
->object
)
15681 && glyph
->charpos
== PT
))
15686 && (!BUFFERP (glyph
->object
)
15687 || glyph
->charpos
< PT
);
15691 w
->cursor
.x
+= glyph
->pixel_width
;
15696 /* Adjust window end. A null value of last_text_row means that
15697 the window end is in reused rows which in turn means that
15698 only its vpos can have changed. */
15701 w
->window_end_bytepos
15702 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15704 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15706 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15711 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15714 w
->window_end_valid
= Qnil
;
15715 w
->desired_matrix
->no_scrolling_p
= 1;
15718 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15728 /************************************************************************
15729 Window redisplay reusing current matrix when buffer has changed
15730 ************************************************************************/
15732 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
15733 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
15734 EMACS_INT
*, EMACS_INT
*);
15735 static struct glyph_row
*
15736 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
15737 struct glyph_row
*);
15740 /* Return the last row in MATRIX displaying text. If row START is
15741 non-null, start searching with that row. IT gives the dimensions
15742 of the display. Value is null if matrix is empty; otherwise it is
15743 a pointer to the row found. */
15745 static struct glyph_row
*
15746 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
15747 struct glyph_row
*start
)
15749 struct glyph_row
*row
, *row_found
;
15751 /* Set row_found to the last row in IT->w's current matrix
15752 displaying text. The loop looks funny but think of partially
15755 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15756 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15758 xassert (row
->enabled_p
);
15760 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15769 /* Return the last row in the current matrix of W that is not affected
15770 by changes at the start of current_buffer that occurred since W's
15771 current matrix was built. Value is null if no such row exists.
15773 BEG_UNCHANGED us the number of characters unchanged at the start of
15774 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15775 first changed character in current_buffer. Characters at positions <
15776 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15777 when the current matrix was built. */
15779 static struct glyph_row
*
15780 find_last_unchanged_at_beg_row (struct window
*w
)
15782 EMACS_INT first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15783 struct glyph_row
*row
;
15784 struct glyph_row
*row_found
= NULL
;
15785 int yb
= window_text_bottom_y (w
);
15787 /* Find the last row displaying unchanged text. */
15788 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15789 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15790 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15793 if (/* If row ends before first_changed_pos, it is unchanged,
15794 except in some case. */
15795 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15796 /* When row ends in ZV and we write at ZV it is not
15798 && !row
->ends_at_zv_p
15799 /* When first_changed_pos is the end of a continued line,
15800 row is not unchanged because it may be no longer
15802 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15803 && (row
->continued_p
15804 || row
->exact_window_width_line_p
)))
15807 /* Stop if last visible row. */
15808 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15816 /* Find the first glyph row in the current matrix of W that is not
15817 affected by changes at the end of current_buffer since the
15818 time W's current matrix was built.
15820 Return in *DELTA the number of chars by which buffer positions in
15821 unchanged text at the end of current_buffer must be adjusted.
15823 Return in *DELTA_BYTES the corresponding number of bytes.
15825 Value is null if no such row exists, i.e. all rows are affected by
15828 static struct glyph_row
*
15829 find_first_unchanged_at_end_row (struct window
*w
,
15830 EMACS_INT
*delta
, EMACS_INT
*delta_bytes
)
15832 struct glyph_row
*row
;
15833 struct glyph_row
*row_found
= NULL
;
15835 *delta
= *delta_bytes
= 0;
15837 /* Display must not have been paused, otherwise the current matrix
15838 is not up to date. */
15839 eassert (!NILP (w
->window_end_valid
));
15841 /* A value of window_end_pos >= END_UNCHANGED means that the window
15842 end is in the range of changed text. If so, there is no
15843 unchanged row at the end of W's current matrix. */
15844 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15847 /* Set row to the last row in W's current matrix displaying text. */
15848 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15850 /* If matrix is entirely empty, no unchanged row exists. */
15851 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15853 /* The value of row is the last glyph row in the matrix having a
15854 meaningful buffer position in it. The end position of row
15855 corresponds to window_end_pos. This allows us to translate
15856 buffer positions in the current matrix to current buffer
15857 positions for characters not in changed text. */
15859 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15860 EMACS_INT Z_BYTE_old
=
15861 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15862 EMACS_INT last_unchanged_pos
, last_unchanged_pos_old
;
15863 struct glyph_row
*first_text_row
15864 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15866 *delta
= Z
- Z_old
;
15867 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15869 /* Set last_unchanged_pos to the buffer position of the last
15870 character in the buffer that has not been changed. Z is the
15871 index + 1 of the last character in current_buffer, i.e. by
15872 subtracting END_UNCHANGED we get the index of the last
15873 unchanged character, and we have to add BEG to get its buffer
15875 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15876 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15878 /* Search backward from ROW for a row displaying a line that
15879 starts at a minimum position >= last_unchanged_pos_old. */
15880 for (; row
> first_text_row
; --row
)
15882 /* This used to abort, but it can happen.
15883 It is ok to just stop the search instead here. KFS. */
15884 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15887 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15892 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15898 /* Make sure that glyph rows in the current matrix of window W
15899 reference the same glyph memory as corresponding rows in the
15900 frame's frame matrix. This function is called after scrolling W's
15901 current matrix on a terminal frame in try_window_id and
15902 try_window_reusing_current_matrix. */
15905 sync_frame_with_window_matrix_rows (struct window
*w
)
15907 struct frame
*f
= XFRAME (w
->frame
);
15908 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15910 /* Preconditions: W must be a leaf window and full-width. Its frame
15911 must have a frame matrix. */
15912 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15913 xassert (WINDOW_FULL_WIDTH_P (w
));
15914 xassert (!FRAME_WINDOW_P (f
));
15916 /* If W is a full-width window, glyph pointers in W's current matrix
15917 have, by definition, to be the same as glyph pointers in the
15918 corresponding frame matrix. Note that frame matrices have no
15919 marginal areas (see build_frame_matrix). */
15920 window_row
= w
->current_matrix
->rows
;
15921 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15922 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15923 while (window_row
< window_row_end
)
15925 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15926 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15928 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15929 frame_row
->glyphs
[TEXT_AREA
] = start
;
15930 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15931 frame_row
->glyphs
[LAST_AREA
] = end
;
15933 /* Disable frame rows whose corresponding window rows have
15934 been disabled in try_window_id. */
15935 if (!window_row
->enabled_p
)
15936 frame_row
->enabled_p
= 0;
15938 ++window_row
, ++frame_row
;
15943 /* Find the glyph row in window W containing CHARPOS. Consider all
15944 rows between START and END (not inclusive). END null means search
15945 all rows to the end of the display area of W. Value is the row
15946 containing CHARPOS or null. */
15949 row_containing_pos (struct window
*w
, EMACS_INT charpos
,
15950 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
15952 struct glyph_row
*row
= start
;
15953 struct glyph_row
*best_row
= NULL
;
15954 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15957 /* If we happen to start on a header-line, skip that. */
15958 if (row
->mode_line_p
)
15961 if ((end
&& row
>= end
) || !row
->enabled_p
)
15964 last_y
= window_text_bottom_y (w
) - dy
;
15968 /* Give up if we have gone too far. */
15969 if (end
&& row
>= end
)
15971 /* This formerly returned if they were equal.
15972 I think that both quantities are of a "last plus one" type;
15973 if so, when they are equal, the row is within the screen. -- rms. */
15974 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15977 /* If it is in this row, return this row. */
15978 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15979 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15980 /* The end position of a row equals the start
15981 position of the next row. If CHARPOS is there, we
15982 would rather display it in the next line, except
15983 when this line ends in ZV. */
15984 && !row
->ends_at_zv_p
15985 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15986 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15990 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
15991 || (!best_row
&& !row
->continued_p
))
15993 /* In bidi-reordered rows, there could be several rows
15994 occluding point, all of them belonging to the same
15995 continued line. We need to find the row which fits
15996 CHARPOS the best. */
15997 for (g
= row
->glyphs
[TEXT_AREA
];
15998 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16001 if (!STRINGP (g
->object
))
16003 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
16005 mindif
= eabs (g
->charpos
- charpos
);
16007 /* Exact match always wins. */
16014 else if (best_row
&& !row
->continued_p
)
16021 /* Try to redisplay window W by reusing its existing display. W's
16022 current matrix must be up to date when this function is called,
16023 i.e. window_end_valid must not be nil.
16027 1 if display has been updated
16028 0 if otherwise unsuccessful
16029 -1 if redisplay with same window start is known not to succeed
16031 The following steps are performed:
16033 1. Find the last row in the current matrix of W that is not
16034 affected by changes at the start of current_buffer. If no such row
16037 2. Find the first row in W's current matrix that is not affected by
16038 changes at the end of current_buffer. Maybe there is no such row.
16040 3. Display lines beginning with the row + 1 found in step 1 to the
16041 row found in step 2 or, if step 2 didn't find a row, to the end of
16044 4. If cursor is not known to appear on the window, give up.
16046 5. If display stopped at the row found in step 2, scroll the
16047 display and current matrix as needed.
16049 6. Maybe display some lines at the end of W, if we must. This can
16050 happen under various circumstances, like a partially visible line
16051 becoming fully visible, or because newly displayed lines are displayed
16052 in smaller font sizes.
16054 7. Update W's window end information. */
16057 try_window_id (struct window
*w
)
16059 struct frame
*f
= XFRAME (w
->frame
);
16060 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
16061 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
16062 struct glyph_row
*last_unchanged_at_beg_row
;
16063 struct glyph_row
*first_unchanged_at_end_row
;
16064 struct glyph_row
*row
;
16065 struct glyph_row
*bottom_row
;
16068 EMACS_INT delta
= 0, delta_bytes
= 0, stop_pos
;
16070 struct text_pos start_pos
;
16072 int first_unchanged_at_end_vpos
= 0;
16073 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
16074 struct text_pos start
;
16075 EMACS_INT first_changed_charpos
, last_changed_charpos
;
16078 if (inhibit_try_window_id
)
16082 /* This is handy for debugging. */
16084 #define GIVE_UP(X) \
16086 fprintf (stderr, "try_window_id give up %d\n", (X)); \
16090 #define GIVE_UP(X) return 0
16093 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
16095 /* Don't use this for mini-windows because these can show
16096 messages and mini-buffers, and we don't handle that here. */
16097 if (MINI_WINDOW_P (w
))
16100 /* This flag is used to prevent redisplay optimizations. */
16101 if (windows_or_buffers_changed
|| cursor_type_changed
)
16104 /* Verify that narrowing has not changed.
16105 Also verify that we were not told to prevent redisplay optimizations.
16106 It would be nice to further
16107 reduce the number of cases where this prevents try_window_id. */
16108 if (current_buffer
->clip_changed
16109 || current_buffer
->prevent_redisplay_optimizations_p
)
16112 /* Window must either use window-based redisplay or be full width. */
16113 if (!FRAME_WINDOW_P (f
)
16114 && (!FRAME_LINE_INS_DEL_OK (f
)
16115 || !WINDOW_FULL_WIDTH_P (w
)))
16118 /* Give up if point is known NOT to appear in W. */
16119 if (PT
< CHARPOS (start
))
16122 /* Another way to prevent redisplay optimizations. */
16123 if (XFASTINT (w
->last_modified
) == 0)
16126 /* Verify that window is not hscrolled. */
16127 if (XFASTINT (w
->hscroll
) != 0)
16130 /* Verify that display wasn't paused. */
16131 if (NILP (w
->window_end_valid
))
16134 /* Can't use this if highlighting a region because a cursor movement
16135 will do more than just set the cursor. */
16136 if (!NILP (Vtransient_mark_mode
)
16137 && !NILP (BVAR (current_buffer
, mark_active
)))
16140 /* Likewise if highlighting trailing whitespace. */
16141 if (!NILP (Vshow_trailing_whitespace
))
16144 /* Likewise if showing a region. */
16145 if (!NILP (w
->region_showing
))
16148 /* Can't use this if overlay arrow position and/or string have
16150 if (overlay_arrows_changed_p ())
16153 /* When word-wrap is on, adding a space to the first word of a
16154 wrapped line can change the wrap position, altering the line
16155 above it. It might be worthwhile to handle this more
16156 intelligently, but for now just redisplay from scratch. */
16157 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
16160 /* Under bidi reordering, adding or deleting a character in the
16161 beginning of a paragraph, before the first strong directional
16162 character, can change the base direction of the paragraph (unless
16163 the buffer specifies a fixed paragraph direction), which will
16164 require to redisplay the whole paragraph. It might be worthwhile
16165 to find the paragraph limits and widen the range of redisplayed
16166 lines to that, but for now just give up this optimization and
16167 redisplay from scratch. */
16168 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16169 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
16172 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
16173 only if buffer has really changed. The reason is that the gap is
16174 initially at Z for freshly visited files. The code below would
16175 set end_unchanged to 0 in that case. */
16176 if (MODIFF
> SAVE_MODIFF
16177 /* This seems to happen sometimes after saving a buffer. */
16178 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
16180 if (GPT
- BEG
< BEG_UNCHANGED
)
16181 BEG_UNCHANGED
= GPT
- BEG
;
16182 if (Z
- GPT
< END_UNCHANGED
)
16183 END_UNCHANGED
= Z
- GPT
;
16186 /* The position of the first and last character that has been changed. */
16187 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
16188 last_changed_charpos
= Z
- END_UNCHANGED
;
16190 /* If window starts after a line end, and the last change is in
16191 front of that newline, then changes don't affect the display.
16192 This case happens with stealth-fontification. Note that although
16193 the display is unchanged, glyph positions in the matrix have to
16194 be adjusted, of course. */
16195 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16196 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16197 && ((last_changed_charpos
< CHARPOS (start
)
16198 && CHARPOS (start
) == BEGV
)
16199 || (last_changed_charpos
< CHARPOS (start
) - 1
16200 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
16202 EMACS_INT Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
16203 struct glyph_row
*r0
;
16205 /* Compute how many chars/bytes have been added to or removed
16206 from the buffer. */
16207 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16208 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16209 Z_delta
= Z
- Z_old
;
16210 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16212 /* Give up if PT is not in the window. Note that it already has
16213 been checked at the start of try_window_id that PT is not in
16214 front of the window start. */
16215 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
16218 /* If window start is unchanged, we can reuse the whole matrix
16219 as is, after adjusting glyph positions. No need to compute
16220 the window end again, since its offset from Z hasn't changed. */
16221 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16222 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
16223 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
16224 /* PT must not be in a partially visible line. */
16225 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
16226 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
16228 /* Adjust positions in the glyph matrix. */
16229 if (Z_delta
|| Z_delta_bytes
)
16231 struct glyph_row
*r1
16232 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16233 increment_matrix_positions (w
->current_matrix
,
16234 MATRIX_ROW_VPOS (r0
, current_matrix
),
16235 MATRIX_ROW_VPOS (r1
, current_matrix
),
16236 Z_delta
, Z_delta_bytes
);
16239 /* Set the cursor. */
16240 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
16242 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
16249 /* Handle the case that changes are all below what is displayed in
16250 the window, and that PT is in the window. This shortcut cannot
16251 be taken if ZV is visible in the window, and text has been added
16252 there that is visible in the window. */
16253 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
16254 /* ZV is not visible in the window, or there are no
16255 changes at ZV, actually. */
16256 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
16257 || first_changed_charpos
== last_changed_charpos
))
16259 struct glyph_row
*r0
;
16261 /* Give up if PT is not in the window. Note that it already has
16262 been checked at the start of try_window_id that PT is not in
16263 front of the window start. */
16264 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
16267 /* If window start is unchanged, we can reuse the whole matrix
16268 as is, without changing glyph positions since no text has
16269 been added/removed in front of the window end. */
16270 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16271 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
16272 /* PT must not be in a partially visible line. */
16273 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
16274 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
16276 /* We have to compute the window end anew since text
16277 could have been added/removed after it. */
16279 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16280 w
->window_end_bytepos
16281 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16283 /* Set the cursor. */
16284 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
16286 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
16293 /* Give up if window start is in the changed area.
16295 The condition used to read
16297 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
16299 but why that was tested escapes me at the moment. */
16300 if (CHARPOS (start
) >= first_changed_charpos
16301 && CHARPOS (start
) <= last_changed_charpos
)
16304 /* Check that window start agrees with the start of the first glyph
16305 row in its current matrix. Check this after we know the window
16306 start is not in changed text, otherwise positions would not be
16308 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
16309 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
16312 /* Give up if the window ends in strings. Overlay strings
16313 at the end are difficult to handle, so don't try. */
16314 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
16315 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
16318 /* Compute the position at which we have to start displaying new
16319 lines. Some of the lines at the top of the window might be
16320 reusable because they are not displaying changed text. Find the
16321 last row in W's current matrix not affected by changes at the
16322 start of current_buffer. Value is null if changes start in the
16323 first line of window. */
16324 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
16325 if (last_unchanged_at_beg_row
)
16327 /* Avoid starting to display in the moddle of a character, a TAB
16328 for instance. This is easier than to set up the iterator
16329 exactly, and it's not a frequent case, so the additional
16330 effort wouldn't really pay off. */
16331 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
16332 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
16333 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
16334 --last_unchanged_at_beg_row
;
16336 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
16339 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
16341 start_pos
= it
.current
.pos
;
16343 /* Start displaying new lines in the desired matrix at the same
16344 vpos we would use in the current matrix, i.e. below
16345 last_unchanged_at_beg_row. */
16346 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
16348 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16349 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
16351 xassert (it
.hpos
== 0 && it
.current_x
== 0);
16355 /* There are no reusable lines at the start of the window.
16356 Start displaying in the first text line. */
16357 start_display (&it
, w
, start
);
16358 it
.vpos
= it
.first_vpos
;
16359 start_pos
= it
.current
.pos
;
16362 /* Find the first row that is not affected by changes at the end of
16363 the buffer. Value will be null if there is no unchanged row, in
16364 which case we must redisplay to the end of the window. delta
16365 will be set to the value by which buffer positions beginning with
16366 first_unchanged_at_end_row have to be adjusted due to text
16368 first_unchanged_at_end_row
16369 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
16370 IF_DEBUG (debug_delta
= delta
);
16371 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
16373 /* Set stop_pos to the buffer position up to which we will have to
16374 display new lines. If first_unchanged_at_end_row != NULL, this
16375 is the buffer position of the start of the line displayed in that
16376 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
16377 that we don't stop at a buffer position. */
16379 if (first_unchanged_at_end_row
)
16381 xassert (last_unchanged_at_beg_row
== NULL
16382 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
16384 /* If this is a continuation line, move forward to the next one
16385 that isn't. Changes in lines above affect this line.
16386 Caution: this may move first_unchanged_at_end_row to a row
16387 not displaying text. */
16388 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
16389 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
16390 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
16391 < it
.last_visible_y
))
16392 ++first_unchanged_at_end_row
;
16394 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
16395 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
16396 >= it
.last_visible_y
))
16397 first_unchanged_at_end_row
= NULL
;
16400 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
16402 first_unchanged_at_end_vpos
16403 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
16404 xassert (stop_pos
>= Z
- END_UNCHANGED
);
16407 else if (last_unchanged_at_beg_row
== NULL
)
16413 /* Either there is no unchanged row at the end, or the one we have
16414 now displays text. This is a necessary condition for the window
16415 end pos calculation at the end of this function. */
16416 xassert (first_unchanged_at_end_row
== NULL
16417 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
16419 debug_last_unchanged_at_beg_vpos
16420 = (last_unchanged_at_beg_row
16421 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
16423 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
16425 #endif /* GLYPH_DEBUG != 0 */
16428 /* Display new lines. Set last_text_row to the last new line
16429 displayed which has text on it, i.e. might end up as being the
16430 line where the window_end_vpos is. */
16431 w
->cursor
.vpos
= -1;
16432 last_text_row
= NULL
;
16433 overlay_arrow_seen
= 0;
16434 while (it
.current_y
< it
.last_visible_y
16435 && !fonts_changed_p
16436 && (first_unchanged_at_end_row
== NULL
16437 || IT_CHARPOS (it
) < stop_pos
))
16439 if (display_line (&it
))
16440 last_text_row
= it
.glyph_row
- 1;
16443 if (fonts_changed_p
)
16447 /* Compute differences in buffer positions, y-positions etc. for
16448 lines reused at the bottom of the window. Compute what we can
16450 if (first_unchanged_at_end_row
16451 /* No lines reused because we displayed everything up to the
16452 bottom of the window. */
16453 && it
.current_y
< it
.last_visible_y
)
16456 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
16458 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
16459 run
.current_y
= first_unchanged_at_end_row
->y
;
16460 run
.desired_y
= run
.current_y
+ dy
;
16461 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
16465 delta
= delta_bytes
= dvpos
= dy
16466 = run
.current_y
= run
.desired_y
= run
.height
= 0;
16467 first_unchanged_at_end_row
= NULL
;
16469 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
16472 /* Find the cursor if not already found. We have to decide whether
16473 PT will appear on this window (it sometimes doesn't, but this is
16474 not a very frequent case.) This decision has to be made before
16475 the current matrix is altered. A value of cursor.vpos < 0 means
16476 that PT is either in one of the lines beginning at
16477 first_unchanged_at_end_row or below the window. Don't care for
16478 lines that might be displayed later at the window end; as
16479 mentioned, this is not a frequent case. */
16480 if (w
->cursor
.vpos
< 0)
16482 /* Cursor in unchanged rows at the top? */
16483 if (PT
< CHARPOS (start_pos
)
16484 && last_unchanged_at_beg_row
)
16486 row
= row_containing_pos (w
, PT
,
16487 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
16488 last_unchanged_at_beg_row
+ 1, 0);
16490 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16493 /* Start from first_unchanged_at_end_row looking for PT. */
16494 else if (first_unchanged_at_end_row
)
16496 row
= row_containing_pos (w
, PT
- delta
,
16497 first_unchanged_at_end_row
, NULL
, 0);
16499 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
16500 delta_bytes
, dy
, dvpos
);
16503 /* Give up if cursor was not found. */
16504 if (w
->cursor
.vpos
< 0)
16506 clear_glyph_matrix (w
->desired_matrix
);
16511 /* Don't let the cursor end in the scroll margins. */
16513 int this_scroll_margin
, cursor_height
;
16515 this_scroll_margin
= max (0, scroll_margin
);
16516 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16517 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
16518 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
16520 if ((w
->cursor
.y
< this_scroll_margin
16521 && CHARPOS (start
) > BEGV
)
16522 /* Old redisplay didn't take scroll margin into account at the bottom,
16523 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
16524 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
16525 ? cursor_height
+ this_scroll_margin
16526 : 1)) > it
.last_visible_y
)
16528 w
->cursor
.vpos
= -1;
16529 clear_glyph_matrix (w
->desired_matrix
);
16534 /* Scroll the display. Do it before changing the current matrix so
16535 that xterm.c doesn't get confused about where the cursor glyph is
16537 if (dy
&& run
.height
)
16541 if (FRAME_WINDOW_P (f
))
16543 FRAME_RIF (f
)->update_window_begin_hook (w
);
16544 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16545 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16546 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16550 /* Terminal frame. In this case, dvpos gives the number of
16551 lines to scroll by; dvpos < 0 means scroll up. */
16553 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
16554 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
16555 int end
= (WINDOW_TOP_EDGE_LINE (w
)
16556 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
16557 + window_internal_height (w
));
16559 #if defined (HAVE_GPM) || defined (MSDOS)
16560 x_clear_window_mouse_face (w
);
16562 /* Perform the operation on the screen. */
16565 /* Scroll last_unchanged_at_beg_row to the end of the
16566 window down dvpos lines. */
16567 set_terminal_window (f
, end
);
16569 /* On dumb terminals delete dvpos lines at the end
16570 before inserting dvpos empty lines. */
16571 if (!FRAME_SCROLL_REGION_OK (f
))
16572 ins_del_lines (f
, end
- dvpos
, -dvpos
);
16574 /* Insert dvpos empty lines in front of
16575 last_unchanged_at_beg_row. */
16576 ins_del_lines (f
, from
, dvpos
);
16578 else if (dvpos
< 0)
16580 /* Scroll up last_unchanged_at_beg_vpos to the end of
16581 the window to last_unchanged_at_beg_vpos - |dvpos|. */
16582 set_terminal_window (f
, end
);
16584 /* Delete dvpos lines in front of
16585 last_unchanged_at_beg_vpos. ins_del_lines will set
16586 the cursor to the given vpos and emit |dvpos| delete
16588 ins_del_lines (f
, from
+ dvpos
, dvpos
);
16590 /* On a dumb terminal insert dvpos empty lines at the
16592 if (!FRAME_SCROLL_REGION_OK (f
))
16593 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
16596 set_terminal_window (f
, 0);
16602 /* Shift reused rows of the current matrix to the right position.
16603 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
16605 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16606 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
16609 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
16610 bottom_vpos
, dvpos
);
16611 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
16614 else if (dvpos
> 0)
16616 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
16617 bottom_vpos
, dvpos
);
16618 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
16619 first_unchanged_at_end_vpos
+ dvpos
, 0);
16622 /* For frame-based redisplay, make sure that current frame and window
16623 matrix are in sync with respect to glyph memory. */
16624 if (!FRAME_WINDOW_P (f
))
16625 sync_frame_with_window_matrix_rows (w
);
16627 /* Adjust buffer positions in reused rows. */
16628 if (delta
|| delta_bytes
)
16629 increment_matrix_positions (current_matrix
,
16630 first_unchanged_at_end_vpos
+ dvpos
,
16631 bottom_vpos
, delta
, delta_bytes
);
16633 /* Adjust Y positions. */
16635 shift_glyph_matrix (w
, current_matrix
,
16636 first_unchanged_at_end_vpos
+ dvpos
,
16639 if (first_unchanged_at_end_row
)
16641 first_unchanged_at_end_row
+= dvpos
;
16642 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16643 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16644 first_unchanged_at_end_row
= NULL
;
16647 /* If scrolling up, there may be some lines to display at the end of
16649 last_text_row_at_end
= NULL
;
16652 /* Scrolling up can leave for example a partially visible line
16653 at the end of the window to be redisplayed. */
16654 /* Set last_row to the glyph row in the current matrix where the
16655 window end line is found. It has been moved up or down in
16656 the matrix by dvpos. */
16657 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16658 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16660 /* If last_row is the window end line, it should display text. */
16661 xassert (last_row
->displays_text_p
);
16663 /* If window end line was partially visible before, begin
16664 displaying at that line. Otherwise begin displaying with the
16665 line following it. */
16666 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16668 init_to_row_start (&it
, w
, last_row
);
16669 it
.vpos
= last_vpos
;
16670 it
.current_y
= last_row
->y
;
16674 init_to_row_end (&it
, w
, last_row
);
16675 it
.vpos
= 1 + last_vpos
;
16676 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16680 /* We may start in a continuation line. If so, we have to
16681 get the right continuation_lines_width and current_x. */
16682 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16683 it
.hpos
= it
.current_x
= 0;
16685 /* Display the rest of the lines at the window end. */
16686 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16687 while (it
.current_y
< it
.last_visible_y
16688 && !fonts_changed_p
)
16690 /* Is it always sure that the display agrees with lines in
16691 the current matrix? I don't think so, so we mark rows
16692 displayed invalid in the current matrix by setting their
16693 enabled_p flag to zero. */
16694 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16695 if (display_line (&it
))
16696 last_text_row_at_end
= it
.glyph_row
- 1;
16700 /* Update window_end_pos and window_end_vpos. */
16701 if (first_unchanged_at_end_row
16702 && !last_text_row_at_end
)
16704 /* Window end line if one of the preserved rows from the current
16705 matrix. Set row to the last row displaying text in current
16706 matrix starting at first_unchanged_at_end_row, after
16708 xassert (first_unchanged_at_end_row
->displays_text_p
);
16709 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16710 first_unchanged_at_end_row
);
16711 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16713 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16714 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16716 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16717 xassert (w
->window_end_bytepos
>= 0);
16718 IF_DEBUG (debug_method_add (w
, "A"));
16720 else if (last_text_row_at_end
)
16723 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16724 w
->window_end_bytepos
16725 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16727 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16728 xassert (w
->window_end_bytepos
>= 0);
16729 IF_DEBUG (debug_method_add (w
, "B"));
16731 else if (last_text_row
)
16733 /* We have displayed either to the end of the window or at the
16734 end of the window, i.e. the last row with text is to be found
16735 in the desired matrix. */
16737 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16738 w
->window_end_bytepos
16739 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16741 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16742 xassert (w
->window_end_bytepos
>= 0);
16744 else if (first_unchanged_at_end_row
== NULL
16745 && last_text_row
== NULL
16746 && last_text_row_at_end
== NULL
)
16748 /* Displayed to end of window, but no line containing text was
16749 displayed. Lines were deleted at the end of the window. */
16750 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16751 int vpos
= XFASTINT (w
->window_end_vpos
);
16752 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16753 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16756 row
== NULL
&& vpos
>= first_vpos
;
16757 --vpos
, --current_row
, --desired_row
)
16759 if (desired_row
->enabled_p
)
16761 if (desired_row
->displays_text_p
)
16764 else if (current_row
->displays_text_p
)
16768 xassert (row
!= NULL
);
16769 w
->window_end_vpos
= make_number (vpos
+ 1);
16770 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16771 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16772 xassert (w
->window_end_bytepos
>= 0);
16773 IF_DEBUG (debug_method_add (w
, "C"));
16778 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16779 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16781 /* Record that display has not been completed. */
16782 w
->window_end_valid
= Qnil
;
16783 w
->desired_matrix
->no_scrolling_p
= 1;
16791 /***********************************************************************
16792 More debugging support
16793 ***********************************************************************/
16797 void dump_glyph_row (struct glyph_row
*, int, int);
16798 void dump_glyph_matrix (struct glyph_matrix
*, int);
16799 void dump_glyph (struct glyph_row
*, struct glyph
*, int);
16802 /* Dump the contents of glyph matrix MATRIX on stderr.
16804 GLYPHS 0 means don't show glyph contents.
16805 GLYPHS 1 means show glyphs in short form
16806 GLYPHS > 1 means show glyphs in long form. */
16809 dump_glyph_matrix (matrix
, glyphs
)
16810 struct glyph_matrix
*matrix
;
16814 for (i
= 0; i
< matrix
->nrows
; ++i
)
16815 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16819 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16820 the glyph row and area where the glyph comes from. */
16823 dump_glyph (row
, glyph
, area
)
16824 struct glyph_row
*row
;
16825 struct glyph
*glyph
;
16828 if (glyph
->type
== CHAR_GLYPH
)
16831 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16832 glyph
- row
->glyphs
[TEXT_AREA
],
16835 (BUFFERP (glyph
->object
)
16837 : (STRINGP (glyph
->object
)
16840 glyph
->pixel_width
,
16842 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16846 glyph
->left_box_line_p
,
16847 glyph
->right_box_line_p
);
16849 else if (glyph
->type
== STRETCH_GLYPH
)
16852 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16853 glyph
- row
->glyphs
[TEXT_AREA
],
16856 (BUFFERP (glyph
->object
)
16858 : (STRINGP (glyph
->object
)
16861 glyph
->pixel_width
,
16865 glyph
->left_box_line_p
,
16866 glyph
->right_box_line_p
);
16868 else if (glyph
->type
== IMAGE_GLYPH
)
16871 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16872 glyph
- row
->glyphs
[TEXT_AREA
],
16875 (BUFFERP (glyph
->object
)
16877 : (STRINGP (glyph
->object
)
16880 glyph
->pixel_width
,
16884 glyph
->left_box_line_p
,
16885 glyph
->right_box_line_p
);
16887 else if (glyph
->type
== COMPOSITE_GLYPH
)
16890 " %5d %4c %6d %c %3d 0x%05x",
16891 glyph
- row
->glyphs
[TEXT_AREA
],
16894 (BUFFERP (glyph
->object
)
16896 : (STRINGP (glyph
->object
)
16899 glyph
->pixel_width
,
16901 if (glyph
->u
.cmp
.automatic
)
16904 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
16905 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16907 glyph
->left_box_line_p
,
16908 glyph
->right_box_line_p
);
16913 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16914 GLYPHS 0 means don't show glyph contents.
16915 GLYPHS 1 means show glyphs in short form
16916 GLYPHS > 1 means show glyphs in long form. */
16919 dump_glyph_row (row
, vpos
, glyphs
)
16920 struct glyph_row
*row
;
16925 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16926 fprintf (stderr
, "======================================================================\n");
16928 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16929 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16931 MATRIX_ROW_START_CHARPOS (row
),
16932 MATRIX_ROW_END_CHARPOS (row
),
16933 row
->used
[TEXT_AREA
],
16934 row
->contains_overlapping_glyphs_p
,
16936 row
->truncated_on_left_p
,
16937 row
->truncated_on_right_p
,
16939 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16940 row
->displays_text_p
,
16943 row
->ends_in_middle_of_char_p
,
16944 row
->starts_in_middle_of_char_p
,
16950 row
->visible_height
,
16953 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16954 row
->end
.overlay_string_index
,
16955 row
->continuation_lines_width
);
16956 fprintf (stderr
, "%9d %5d\n",
16957 CHARPOS (row
->start
.string_pos
),
16958 CHARPOS (row
->end
.string_pos
));
16959 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16960 row
->end
.dpvec_index
);
16967 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16969 struct glyph
*glyph
= row
->glyphs
[area
];
16970 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16972 /* Glyph for a line end in text. */
16973 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16976 if (glyph
< glyph_end
)
16977 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16979 for (; glyph
< glyph_end
; ++glyph
)
16980 dump_glyph (row
, glyph
, area
);
16983 else if (glyphs
== 1)
16987 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16989 char *s
= (char *) alloca (row
->used
[area
] + 1);
16992 for (i
= 0; i
< row
->used
[area
]; ++i
)
16994 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16995 if (glyph
->type
== CHAR_GLYPH
16996 && glyph
->u
.ch
< 0x80
16997 && glyph
->u
.ch
>= ' ')
16998 s
[i
] = glyph
->u
.ch
;
17004 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
17010 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
17011 Sdump_glyph_matrix
, 0, 1, "p",
17012 doc
: /* Dump the current matrix of the selected window to stderr.
17013 Shows contents of glyph row structures. With non-nil
17014 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
17015 glyphs in short form, otherwise show glyphs in long form. */)
17016 (Lisp_Object glyphs
)
17018 struct window
*w
= XWINDOW (selected_window
);
17019 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17021 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
17022 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
17023 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
17024 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
17025 fprintf (stderr
, "=============================================\n");
17026 dump_glyph_matrix (w
->current_matrix
,
17027 NILP (glyphs
) ? 0 : XINT (glyphs
));
17032 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
17033 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
17036 struct frame
*f
= XFRAME (selected_frame
);
17037 dump_glyph_matrix (f
->current_matrix
, 1);
17042 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
17043 doc
: /* Dump glyph row ROW to stderr.
17044 GLYPH 0 means don't dump glyphs.
17045 GLYPH 1 means dump glyphs in short form.
17046 GLYPH > 1 or omitted means dump glyphs in long form. */)
17047 (Lisp_Object row
, Lisp_Object glyphs
)
17049 struct glyph_matrix
*matrix
;
17052 CHECK_NUMBER (row
);
17053 matrix
= XWINDOW (selected_window
)->current_matrix
;
17055 if (vpos
>= 0 && vpos
< matrix
->nrows
)
17056 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
17058 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
17063 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
17064 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
17065 GLYPH 0 means don't dump glyphs.
17066 GLYPH 1 means dump glyphs in short form.
17067 GLYPH > 1 or omitted means dump glyphs in long form. */)
17068 (Lisp_Object row
, Lisp_Object glyphs
)
17070 struct frame
*sf
= SELECTED_FRAME ();
17071 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
17074 CHECK_NUMBER (row
);
17076 if (vpos
>= 0 && vpos
< m
->nrows
)
17077 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
17078 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
17083 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
17084 doc
: /* Toggle tracing of redisplay.
17085 With ARG, turn tracing on if and only if ARG is positive. */)
17089 trace_redisplay_p
= !trace_redisplay_p
;
17092 arg
= Fprefix_numeric_value (arg
);
17093 trace_redisplay_p
= XINT (arg
) > 0;
17100 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
17101 doc
: /* Like `format', but print result to stderr.
17102 usage: (trace-to-stderr STRING &rest OBJECTS) */)
17103 (size_t nargs
, Lisp_Object
*args
)
17105 Lisp_Object s
= Fformat (nargs
, args
);
17106 fprintf (stderr
, "%s", SDATA (s
));
17110 #endif /* GLYPH_DEBUG */
17114 /***********************************************************************
17115 Building Desired Matrix Rows
17116 ***********************************************************************/
17118 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
17119 Used for non-window-redisplay windows, and for windows w/o left fringe. */
17121 static struct glyph_row
*
17122 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
17124 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17125 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17126 struct buffer
*old
= current_buffer
;
17127 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
17128 int arrow_len
= SCHARS (overlay_arrow_string
);
17129 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
17130 const unsigned char *p
;
17133 int n_glyphs_before
;
17135 set_buffer_temp (buffer
);
17136 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
17137 it
.glyph_row
->used
[TEXT_AREA
] = 0;
17138 SET_TEXT_POS (it
.position
, 0, 0);
17140 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
17142 while (p
< arrow_end
)
17144 Lisp_Object face
, ilisp
;
17146 /* Get the next character. */
17148 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
17151 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
17152 if (! ASCII_CHAR_P (it
.c
))
17153 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
17157 /* Get its face. */
17158 ilisp
= make_number (p
- arrow_string
);
17159 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
17160 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
17162 /* Compute its width, get its glyphs. */
17163 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
17164 SET_TEXT_POS (it
.position
, -1, -1);
17165 PRODUCE_GLYPHS (&it
);
17167 /* If this character doesn't fit any more in the line, we have
17168 to remove some glyphs. */
17169 if (it
.current_x
> it
.last_visible_x
)
17171 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17176 set_buffer_temp (old
);
17177 return it
.glyph_row
;
17181 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
17182 glyphs are only inserted for terminal frames since we can't really
17183 win with truncation glyphs when partially visible glyphs are
17184 involved. Which glyphs to insert is determined by
17185 produce_special_glyphs. */
17188 insert_left_trunc_glyphs (struct it
*it
)
17190 struct it truncate_it
;
17191 struct glyph
*from
, *end
, *to
, *toend
;
17193 xassert (!FRAME_WINDOW_P (it
->f
));
17195 /* Get the truncation glyphs. */
17197 truncate_it
.current_x
= 0;
17198 truncate_it
.face_id
= DEFAULT_FACE_ID
;
17199 truncate_it
.glyph_row
= &scratch_glyph_row
;
17200 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
17201 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
17202 truncate_it
.object
= make_number (0);
17203 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
17205 /* Overwrite glyphs from IT with truncation glyphs. */
17206 if (!it
->glyph_row
->reversed_p
)
17208 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17209 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
17210 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17211 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
17216 /* There may be padding glyphs left over. Overwrite them too. */
17217 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
17219 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17225 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
17229 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
17230 that back to front. */
17231 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
17232 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17233 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17234 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17236 while (from
>= end
&& to
>= toend
)
17238 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
17241 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
17242 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
17243 while (from
>= end
&& to
>= toend
)
17248 /* Need to free some room before prepending additional
17250 int move_by
= from
- end
+ 1;
17251 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17252 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
17254 for ( ; g
>= g0
; g
--)
17256 while (from
>= end
)
17258 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
17264 /* Compute the pixel height and width of IT->glyph_row.
17266 Most of the time, ascent and height of a display line will be equal
17267 to the max_ascent and max_height values of the display iterator
17268 structure. This is not the case if
17270 1. We hit ZV without displaying anything. In this case, max_ascent
17271 and max_height will be zero.
17273 2. We have some glyphs that don't contribute to the line height.
17274 (The glyph row flag contributes_to_line_height_p is for future
17275 pixmap extensions).
17277 The first case is easily covered by using default values because in
17278 these cases, the line height does not really matter, except that it
17279 must not be zero. */
17282 compute_line_metrics (struct it
*it
)
17284 struct glyph_row
*row
= it
->glyph_row
;
17286 if (FRAME_WINDOW_P (it
->f
))
17288 int i
, min_y
, max_y
;
17290 /* The line may consist of one space only, that was added to
17291 place the cursor on it. If so, the row's height hasn't been
17293 if (row
->height
== 0)
17295 if (it
->max_ascent
+ it
->max_descent
== 0)
17296 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
17297 row
->ascent
= it
->max_ascent
;
17298 row
->height
= it
->max_ascent
+ it
->max_descent
;
17299 row
->phys_ascent
= it
->max_phys_ascent
;
17300 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17301 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17304 /* Compute the width of this line. */
17305 row
->pixel_width
= row
->x
;
17306 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
17307 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
17309 xassert (row
->pixel_width
>= 0);
17310 xassert (row
->ascent
>= 0 && row
->height
> 0);
17312 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
17313 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
17315 /* If first line's physical ascent is larger than its logical
17316 ascent, use the physical ascent, and make the row taller.
17317 This makes accented characters fully visible. */
17318 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
17319 && row
->phys_ascent
> row
->ascent
)
17321 row
->height
+= row
->phys_ascent
- row
->ascent
;
17322 row
->ascent
= row
->phys_ascent
;
17325 /* Compute how much of the line is visible. */
17326 row
->visible_height
= row
->height
;
17328 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
17329 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
17331 if (row
->y
< min_y
)
17332 row
->visible_height
-= min_y
- row
->y
;
17333 if (row
->y
+ row
->height
> max_y
)
17334 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17338 row
->pixel_width
= row
->used
[TEXT_AREA
];
17339 if (row
->continued_p
)
17340 row
->pixel_width
-= it
->continuation_pixel_width
;
17341 else if (row
->truncated_on_right_p
)
17342 row
->pixel_width
-= it
->truncation_pixel_width
;
17343 row
->ascent
= row
->phys_ascent
= 0;
17344 row
->height
= row
->phys_height
= row
->visible_height
= 1;
17345 row
->extra_line_spacing
= 0;
17348 /* Compute a hash code for this row. */
17352 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17353 for (i
= 0; i
< row
->used
[area
]; ++i
)
17354 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
17355 + row
->glyphs
[area
][i
].u
.val
17356 + row
->glyphs
[area
][i
].face_id
17357 + row
->glyphs
[area
][i
].padding_p
17358 + (row
->glyphs
[area
][i
].type
<< 2));
17361 it
->max_ascent
= it
->max_descent
= 0;
17362 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
17366 /* Append one space to the glyph row of iterator IT if doing a
17367 window-based redisplay. The space has the same face as
17368 IT->face_id. Value is non-zero if a space was added.
17370 This function is called to make sure that there is always one glyph
17371 at the end of a glyph row that the cursor can be set on under
17372 window-systems. (If there weren't such a glyph we would not know
17373 how wide and tall a box cursor should be displayed).
17375 At the same time this space let's a nicely handle clearing to the
17376 end of the line if the row ends in italic text. */
17379 append_space_for_newline (struct it
*it
, int default_face_p
)
17381 if (FRAME_WINDOW_P (it
->f
))
17383 int n
= it
->glyph_row
->used
[TEXT_AREA
];
17385 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
17386 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
17388 /* Save some values that must not be changed.
17389 Must save IT->c and IT->len because otherwise
17390 ITERATOR_AT_END_P wouldn't work anymore after
17391 append_space_for_newline has been called. */
17392 enum display_element_type saved_what
= it
->what
;
17393 int saved_c
= it
->c
, saved_len
= it
->len
;
17394 int saved_char_to_display
= it
->char_to_display
;
17395 int saved_x
= it
->current_x
;
17396 int saved_face_id
= it
->face_id
;
17397 struct text_pos saved_pos
;
17398 Lisp_Object saved_object
;
17401 saved_object
= it
->object
;
17402 saved_pos
= it
->position
;
17404 it
->what
= IT_CHARACTER
;
17405 memset (&it
->position
, 0, sizeof it
->position
);
17406 it
->object
= make_number (0);
17407 it
->c
= it
->char_to_display
= ' ';
17410 if (default_face_p
)
17411 it
->face_id
= DEFAULT_FACE_ID
;
17412 else if (it
->face_before_selective_p
)
17413 it
->face_id
= it
->saved_face_id
;
17414 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17415 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
17417 PRODUCE_GLYPHS (it
);
17419 it
->override_ascent
= -1;
17420 it
->constrain_row_ascent_descent_p
= 0;
17421 it
->current_x
= saved_x
;
17422 it
->object
= saved_object
;
17423 it
->position
= saved_pos
;
17424 it
->what
= saved_what
;
17425 it
->face_id
= saved_face_id
;
17426 it
->len
= saved_len
;
17428 it
->char_to_display
= saved_char_to_display
;
17437 /* Extend the face of the last glyph in the text area of IT->glyph_row
17438 to the end of the display line. Called from display_line. If the
17439 glyph row is empty, add a space glyph to it so that we know the
17440 face to draw. Set the glyph row flag fill_line_p. If the glyph
17441 row is R2L, prepend a stretch glyph to cover the empty space to the
17442 left of the leftmost glyph. */
17445 extend_face_to_end_of_line (struct it
*it
)
17448 struct frame
*f
= it
->f
;
17450 /* If line is already filled, do nothing. Non window-system frames
17451 get a grace of one more ``pixel'' because their characters are
17452 1-``pixel'' wide, so they hit the equality too early. This grace
17453 is needed only for R2L rows that are not continued, to produce
17454 one extra blank where we could display the cursor. */
17455 if (it
->current_x
>= it
->last_visible_x
17456 + (!FRAME_WINDOW_P (f
)
17457 && it
->glyph_row
->reversed_p
17458 && !it
->glyph_row
->continued_p
))
17461 /* Face extension extends the background and box of IT->face_id
17462 to the end of the line. If the background equals the background
17463 of the frame, we don't have to do anything. */
17464 if (it
->face_before_selective_p
)
17465 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
17467 face
= FACE_FROM_ID (f
, it
->face_id
);
17469 if (FRAME_WINDOW_P (f
)
17470 && it
->glyph_row
->displays_text_p
17471 && face
->box
== FACE_NO_BOX
17472 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
17474 && !it
->glyph_row
->reversed_p
)
17477 /* Set the glyph row flag indicating that the face of the last glyph
17478 in the text area has to be drawn to the end of the text area. */
17479 it
->glyph_row
->fill_line_p
= 1;
17481 /* If current character of IT is not ASCII, make sure we have the
17482 ASCII face. This will be automatically undone the next time
17483 get_next_display_element returns a multibyte character. Note
17484 that the character will always be single byte in unibyte
17486 if (!ASCII_CHAR_P (it
->c
))
17488 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
17491 if (FRAME_WINDOW_P (f
))
17493 /* If the row is empty, add a space with the current face of IT,
17494 so that we know which face to draw. */
17495 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
17497 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
17498 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
17499 it
->glyph_row
->used
[TEXT_AREA
] = 1;
17501 #ifdef HAVE_WINDOW_SYSTEM
17502 if (it
->glyph_row
->reversed_p
)
17504 /* Prepend a stretch glyph to the row, such that the
17505 rightmost glyph will be drawn flushed all the way to the
17506 right margin of the window. The stretch glyph that will
17507 occupy the empty space, if any, to the left of the
17509 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
17510 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17511 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
17513 int row_width
, stretch_ascent
, stretch_width
;
17514 struct text_pos saved_pos
;
17515 int saved_face_id
, saved_avoid_cursor
;
17517 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
17518 row_width
+= g
->pixel_width
;
17519 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
17520 if (stretch_width
> 0)
17523 (((it
->ascent
+ it
->descent
)
17524 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
17525 saved_pos
= it
->position
;
17526 memset (&it
->position
, 0, sizeof it
->position
);
17527 saved_avoid_cursor
= it
->avoid_cursor_p
;
17528 it
->avoid_cursor_p
= 1;
17529 saved_face_id
= it
->face_id
;
17530 /* The last row's stretch glyph should get the default
17531 face, to avoid painting the rest of the window with
17532 the region face, if the region ends at ZV. */
17533 if (it
->glyph_row
->ends_at_zv_p
)
17534 it
->face_id
= DEFAULT_FACE_ID
;
17536 it
->face_id
= face
->id
;
17537 append_stretch_glyph (it
, make_number (0), stretch_width
,
17538 it
->ascent
+ it
->descent
, stretch_ascent
);
17539 it
->position
= saved_pos
;
17540 it
->avoid_cursor_p
= saved_avoid_cursor
;
17541 it
->face_id
= saved_face_id
;
17544 #endif /* HAVE_WINDOW_SYSTEM */
17548 /* Save some values that must not be changed. */
17549 int saved_x
= it
->current_x
;
17550 struct text_pos saved_pos
;
17551 Lisp_Object saved_object
;
17552 enum display_element_type saved_what
= it
->what
;
17553 int saved_face_id
= it
->face_id
;
17555 saved_object
= it
->object
;
17556 saved_pos
= it
->position
;
17558 it
->what
= IT_CHARACTER
;
17559 memset (&it
->position
, 0, sizeof it
->position
);
17560 it
->object
= make_number (0);
17561 it
->c
= it
->char_to_display
= ' ';
17563 /* The last row's blank glyphs should get the default face, to
17564 avoid painting the rest of the window with the region face,
17565 if the region ends at ZV. */
17566 if (it
->glyph_row
->ends_at_zv_p
)
17567 it
->face_id
= DEFAULT_FACE_ID
;
17569 it
->face_id
= face
->id
;
17571 PRODUCE_GLYPHS (it
);
17573 while (it
->current_x
<= it
->last_visible_x
)
17574 PRODUCE_GLYPHS (it
);
17576 /* Don't count these blanks really. It would let us insert a left
17577 truncation glyph below and make us set the cursor on them, maybe. */
17578 it
->current_x
= saved_x
;
17579 it
->object
= saved_object
;
17580 it
->position
= saved_pos
;
17581 it
->what
= saved_what
;
17582 it
->face_id
= saved_face_id
;
17587 /* Value is non-zero if text starting at CHARPOS in current_buffer is
17588 trailing whitespace. */
17591 trailing_whitespace_p (EMACS_INT charpos
)
17593 EMACS_INT bytepos
= CHAR_TO_BYTE (charpos
);
17596 while (bytepos
< ZV_BYTE
17597 && (c
= FETCH_CHAR (bytepos
),
17598 c
== ' ' || c
== '\t'))
17601 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
17603 if (bytepos
!= PT_BYTE
)
17610 /* Highlight trailing whitespace, if any, in ROW. */
17613 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
17615 int used
= row
->used
[TEXT_AREA
];
17619 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
17620 struct glyph
*glyph
= start
+ used
- 1;
17622 if (row
->reversed_p
)
17624 /* Right-to-left rows need to be processed in the opposite
17625 direction, so swap the edge pointers. */
17627 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
17630 /* Skip over glyphs inserted to display the cursor at the
17631 end of a line, for extending the face of the last glyph
17632 to the end of the line on terminals, and for truncation
17633 and continuation glyphs. */
17634 if (!row
->reversed_p
)
17636 while (glyph
>= start
17637 && glyph
->type
== CHAR_GLYPH
17638 && INTEGERP (glyph
->object
))
17643 while (glyph
<= start
17644 && glyph
->type
== CHAR_GLYPH
17645 && INTEGERP (glyph
->object
))
17649 /* If last glyph is a space or stretch, and it's trailing
17650 whitespace, set the face of all trailing whitespace glyphs in
17651 IT->glyph_row to `trailing-whitespace'. */
17652 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
17653 && BUFFERP (glyph
->object
)
17654 && (glyph
->type
== STRETCH_GLYPH
17655 || (glyph
->type
== CHAR_GLYPH
17656 && glyph
->u
.ch
== ' '))
17657 && trailing_whitespace_p (glyph
->charpos
))
17659 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
17663 if (!row
->reversed_p
)
17665 while (glyph
>= start
17666 && BUFFERP (glyph
->object
)
17667 && (glyph
->type
== STRETCH_GLYPH
17668 || (glyph
->type
== CHAR_GLYPH
17669 && glyph
->u
.ch
== ' ')))
17670 (glyph
--)->face_id
= face_id
;
17674 while (glyph
<= start
17675 && BUFFERP (glyph
->object
)
17676 && (glyph
->type
== STRETCH_GLYPH
17677 || (glyph
->type
== CHAR_GLYPH
17678 && glyph
->u
.ch
== ' ')))
17679 (glyph
++)->face_id
= face_id
;
17686 /* Value is non-zero if glyph row ROW should be
17687 used to hold the cursor. */
17690 cursor_row_p (struct glyph_row
*row
)
17694 if (PT
== CHARPOS (row
->end
.pos
))
17696 /* Suppose the row ends on a string.
17697 Unless the row is continued, that means it ends on a newline
17698 in the string. If it's anything other than a display string
17699 (e.g. a before-string from an overlay), we don't want the
17700 cursor there. (This heuristic seems to give the optimal
17701 behavior for the various types of multi-line strings.) */
17702 if (CHARPOS (row
->end
.string_pos
) >= 0)
17704 if (row
->continued_p
)
17708 /* Check for `display' property. */
17709 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17710 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17711 struct glyph
*glyph
;
17714 for (glyph
= end
; glyph
>= beg
; --glyph
)
17715 if (STRINGP (glyph
->object
))
17718 = Fget_char_property (make_number (PT
),
17722 && display_prop_string_p (prop
, glyph
->object
));
17727 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17729 /* If the row ends in middle of a real character,
17730 and the line is continued, we want the cursor here.
17731 That's because CHARPOS (ROW->end.pos) would equal
17732 PT if PT is before the character. */
17733 if (!row
->ends_in_ellipsis_p
)
17734 result
= row
->continued_p
;
17736 /* If the row ends in an ellipsis, then
17737 CHARPOS (ROW->end.pos) will equal point after the
17738 invisible text. We want that position to be displayed
17739 after the ellipsis. */
17742 /* If the row ends at ZV, display the cursor at the end of that
17743 row instead of at the start of the row below. */
17744 else if (row
->ends_at_zv_p
)
17755 /* Push the display property PROP so that it will be rendered at the
17756 current position in IT. Return 1 if PROP was successfully pushed,
17760 push_display_prop (struct it
*it
, Lisp_Object prop
)
17762 xassert (it
->method
== GET_FROM_BUFFER
);
17764 push_it (it
, NULL
);
17766 if (STRINGP (prop
))
17768 if (SCHARS (prop
) == 0)
17775 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17776 it
->current
.overlay_string_index
= -1;
17777 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17778 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17779 it
->method
= GET_FROM_STRING
;
17780 it
->stop_charpos
= 0;
17782 it
->base_level_stop
= 0;
17783 it
->string_from_display_prop_p
= 1;
17785 /* Force paragraph direction to be that of the parent
17787 it
->paragraph_embedding
= (it
->bidi_p
? it
->bidi_it
.paragraph_dir
: L2R
);
17789 /* Do we need to reorder this string? */
17790 if (it
->multibyte_p
)
17791 it
->bidi_p
= !NILP (BVAR (current_buffer
, bidi_display_reordering
));
17795 /* Set up the bidi iterator for this display string. */
17798 it
->bidi_it
.string
.lstring
= it
->string
;
17799 it
->bidi_it
.string
.s
= NULL
;
17800 it
->bidi_it
.string
.schars
= it
->end_charpos
;
17801 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
17802 it
->bidi_it
.string
.from_disp_str
= 1;
17803 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
17806 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17808 it
->method
= GET_FROM_STRETCH
;
17811 #ifdef HAVE_WINDOW_SYSTEM
17812 else if (IMAGEP (prop
))
17814 it
->what
= IT_IMAGE
;
17815 it
->image_id
= lookup_image (it
->f
, prop
);
17816 it
->method
= GET_FROM_IMAGE
;
17818 #endif /* HAVE_WINDOW_SYSTEM */
17821 pop_it (it
); /* bogus display property, give up */
17828 /* Return the character-property PROP at the current position in IT. */
17831 get_it_property (struct it
*it
, Lisp_Object prop
)
17833 Lisp_Object position
;
17835 if (STRINGP (it
->object
))
17836 position
= make_number (IT_STRING_CHARPOS (*it
));
17837 else if (BUFFERP (it
->object
))
17838 position
= make_number (IT_CHARPOS (*it
));
17842 return Fget_char_property (position
, prop
, it
->object
);
17845 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17848 handle_line_prefix (struct it
*it
)
17850 Lisp_Object prefix
;
17852 if (it
->continuation_lines_width
> 0)
17854 prefix
= get_it_property (it
, Qwrap_prefix
);
17856 prefix
= Vwrap_prefix
;
17860 prefix
= get_it_property (it
, Qline_prefix
);
17862 prefix
= Vline_prefix
;
17864 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17866 /* If the prefix is wider than the window, and we try to wrap
17867 it, it would acquire its own wrap prefix, and so on till the
17868 iterator stack overflows. So, don't wrap the prefix. */
17869 it
->line_wrap
= TRUNCATE
;
17870 it
->avoid_cursor_p
= 1;
17876 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
17877 only for R2L lines from display_line and display_string, when they
17878 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
17879 the line/string needs to be continued on the next glyph row. */
17881 unproduce_glyphs (struct it
*it
, int n
)
17883 struct glyph
*glyph
, *end
;
17885 xassert (it
->glyph_row
);
17886 xassert (it
->glyph_row
->reversed_p
);
17887 xassert (it
->area
== TEXT_AREA
);
17888 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
17890 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
17891 n
= it
->glyph_row
->used
[TEXT_AREA
];
17892 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
17893 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
17894 for ( ; glyph
< end
; glyph
++)
17895 glyph
[-n
] = *glyph
;
17898 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
17899 and ROW->maxpos. */
17901 find_row_edges (struct it
*it
, struct glyph_row
*row
,
17902 EMACS_INT min_pos
, EMACS_INT min_bpos
,
17903 EMACS_INT max_pos
, EMACS_INT max_bpos
)
17905 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17906 lines' rows is implemented for bidi-reordered rows. */
17908 /* ROW->minpos is the value of min_pos, the minimal buffer position
17911 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
17913 /* We didn't find _any_ valid buffer positions in any of the
17914 glyphs, so we must trust the iterator's computed positions. */
17915 row
->minpos
= row
->start
.pos
;
17918 max_pos
= CHARPOS (it
->current
.pos
);
17919 max_bpos
= BYTEPOS (it
->current
.pos
);
17922 /* Here are the various use-cases for ending the row, and the
17923 corresponding values for ROW->maxpos:
17925 Line ends in a newline from buffer eol_pos + 1
17926 Line is continued from buffer max_pos + 1
17927 Line is truncated on right it->current.pos
17928 Line ends in a newline from string max_pos
17929 Line is continued from string max_pos
17930 Line is continued from display vector max_pos
17931 Line is entirely from a string min_pos == max_pos
17932 Line is entirely from a display vector min_pos == max_pos
17933 Line that ends at ZV ZV
17935 If you discover other use-cases, please add them here as
17937 if (row
->ends_at_zv_p
)
17938 row
->maxpos
= it
->current
.pos
;
17939 else if (row
->used
[TEXT_AREA
])
17941 if (row
->ends_in_newline_from_string_p
)
17942 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17943 else if (CHARPOS (it
->eol_pos
) > 0)
17944 SET_TEXT_POS (row
->maxpos
,
17945 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
17946 else if (row
->continued_p
)
17948 /* If max_pos is different from IT's current position, it
17949 means IT->method does not belong to the display element
17950 at max_pos. However, it also means that the display
17951 element at max_pos was displayed in its entirety on this
17952 line, which is equivalent to saying that the next line
17953 starts at the next buffer position. */
17954 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
17955 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17958 INC_BOTH (max_pos
, max_bpos
);
17959 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17962 else if (row
->truncated_on_right_p
)
17963 /* display_line already called reseat_at_next_visible_line_start,
17964 which puts the iterator at the beginning of the next line, in
17965 the logical order. */
17966 row
->maxpos
= it
->current
.pos
;
17967 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
17968 /* A line that is entirely from a string/image/stretch... */
17969 row
->maxpos
= row
->minpos
;
17974 row
->maxpos
= it
->current
.pos
;
17977 /* Construct the glyph row IT->glyph_row in the desired matrix of
17978 IT->w from text at the current position of IT. See dispextern.h
17979 for an overview of struct it. Value is non-zero if
17980 IT->glyph_row displays text, as opposed to a line displaying ZV
17984 display_line (struct it
*it
)
17986 struct glyph_row
*row
= it
->glyph_row
;
17987 Lisp_Object overlay_arrow_string
;
17989 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
17990 int wrap_row_used
= -1;
17991 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
17992 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
17993 int wrap_row_extra_line_spacing
IF_LINT (= 0);
17994 EMACS_INT wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
17995 EMACS_INT wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
17997 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
17998 EMACS_INT min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
18000 /* We always start displaying at hpos zero even if hscrolled. */
18001 xassert (it
->hpos
== 0 && it
->current_x
== 0);
18003 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
18004 >= it
->w
->desired_matrix
->nrows
)
18006 it
->w
->nrows_scale_factor
++;
18007 fonts_changed_p
= 1;
18011 /* Is IT->w showing the region? */
18012 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
18014 /* Clear the result glyph row and enable it. */
18015 prepare_desired_row (row
);
18017 row
->y
= it
->current_y
;
18018 row
->start
= it
->start
;
18019 row
->continuation_lines_width
= it
->continuation_lines_width
;
18020 row
->displays_text_p
= 1;
18021 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
18022 it
->starts_in_middle_of_char_p
= 0;
18024 /* Arrange the overlays nicely for our purposes. Usually, we call
18025 display_line on only one line at a time, in which case this
18026 can't really hurt too much, or we call it on lines which appear
18027 one after another in the buffer, in which case all calls to
18028 recenter_overlay_lists but the first will be pretty cheap. */
18029 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
18031 /* Move over display elements that are not visible because we are
18032 hscrolled. This may stop at an x-position < IT->first_visible_x
18033 if the first glyph is partially visible or if we hit a line end. */
18034 if (it
->current_x
< it
->first_visible_x
)
18036 this_line_min_pos
= row
->start
.pos
;
18037 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
18038 MOVE_TO_POS
| MOVE_TO_X
);
18039 /* Record the smallest positions seen while we moved over
18040 display elements that are not visible. This is needed by
18041 redisplay_internal for optimizing the case where the cursor
18042 stays inside the same line. The rest of this function only
18043 considers positions that are actually displayed, so
18044 RECORD_MAX_MIN_POS will not otherwise record positions that
18045 are hscrolled to the left of the left edge of the window. */
18046 min_pos
= CHARPOS (this_line_min_pos
);
18047 min_bpos
= BYTEPOS (this_line_min_pos
);
18051 /* We only do this when not calling `move_it_in_display_line_to'
18052 above, because move_it_in_display_line_to calls
18053 handle_line_prefix itself. */
18054 handle_line_prefix (it
);
18057 /* Get the initial row height. This is either the height of the
18058 text hscrolled, if there is any, or zero. */
18059 row
->ascent
= it
->max_ascent
;
18060 row
->height
= it
->max_ascent
+ it
->max_descent
;
18061 row
->phys_ascent
= it
->max_phys_ascent
;
18062 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18063 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18065 /* Utility macro to record max and min buffer positions seen until now. */
18066 #define RECORD_MAX_MIN_POS(IT) \
18069 if (IT_CHARPOS (*(IT)) < min_pos) \
18071 min_pos = IT_CHARPOS (*(IT)); \
18072 min_bpos = IT_BYTEPOS (*(IT)); \
18074 if (IT_CHARPOS (*(IT)) > max_pos) \
18076 max_pos = IT_CHARPOS (*(IT)); \
18077 max_bpos = IT_BYTEPOS (*(IT)); \
18082 /* Loop generating characters. The loop is left with IT on the next
18083 character to display. */
18086 int n_glyphs_before
, hpos_before
, x_before
;
18088 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
18090 /* Retrieve the next thing to display. Value is zero if end of
18092 if (!get_next_display_element (it
))
18094 /* Maybe add a space at the end of this line that is used to
18095 display the cursor there under X. Set the charpos of the
18096 first glyph of blank lines not corresponding to any text
18098 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18099 row
->exact_window_width_line_p
= 1;
18100 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
18101 || row
->used
[TEXT_AREA
] == 0)
18103 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
18104 row
->displays_text_p
= 0;
18106 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
18107 && (!MINI_WINDOW_P (it
->w
)
18108 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
18109 row
->indicate_empty_line_p
= 1;
18112 it
->continuation_lines_width
= 0;
18113 row
->ends_at_zv_p
= 1;
18114 /* A row that displays right-to-left text must always have
18115 its last face extended all the way to the end of line,
18116 even if this row ends in ZV, because we still write to
18117 the screen left to right. */
18118 if (row
->reversed_p
)
18119 extend_face_to_end_of_line (it
);
18123 /* Now, get the metrics of what we want to display. This also
18124 generates glyphs in `row' (which is IT->glyph_row). */
18125 n_glyphs_before
= row
->used
[TEXT_AREA
];
18128 /* Remember the line height so far in case the next element doesn't
18129 fit on the line. */
18130 if (it
->line_wrap
!= TRUNCATE
)
18132 ascent
= it
->max_ascent
;
18133 descent
= it
->max_descent
;
18134 phys_ascent
= it
->max_phys_ascent
;
18135 phys_descent
= it
->max_phys_descent
;
18137 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
18139 if (IT_DISPLAYING_WHITESPACE (it
))
18145 wrap_row_used
= row
->used
[TEXT_AREA
];
18146 wrap_row_ascent
= row
->ascent
;
18147 wrap_row_height
= row
->height
;
18148 wrap_row_phys_ascent
= row
->phys_ascent
;
18149 wrap_row_phys_height
= row
->phys_height
;
18150 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
18151 wrap_row_min_pos
= min_pos
;
18152 wrap_row_min_bpos
= min_bpos
;
18153 wrap_row_max_pos
= max_pos
;
18154 wrap_row_max_bpos
= max_bpos
;
18160 PRODUCE_GLYPHS (it
);
18162 /* If this display element was in marginal areas, continue with
18164 if (it
->area
!= TEXT_AREA
)
18166 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18167 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18168 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18169 row
->phys_height
= max (row
->phys_height
,
18170 it
->max_phys_ascent
+ it
->max_phys_descent
);
18171 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18172 it
->max_extra_line_spacing
);
18173 set_iterator_to_next (it
, 1);
18177 /* Does the display element fit on the line? If we truncate
18178 lines, we should draw past the right edge of the window. If
18179 we don't truncate, we want to stop so that we can display the
18180 continuation glyph before the right margin. If lines are
18181 continued, there are two possible strategies for characters
18182 resulting in more than 1 glyph (e.g. tabs): Display as many
18183 glyphs as possible in this line and leave the rest for the
18184 continuation line, or display the whole element in the next
18185 line. Original redisplay did the former, so we do it also. */
18186 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
18187 hpos_before
= it
->hpos
;
18190 if (/* Not a newline. */
18192 /* Glyphs produced fit entirely in the line. */
18193 && it
->current_x
< it
->last_visible_x
)
18195 it
->hpos
+= nglyphs
;
18196 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18197 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18198 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18199 row
->phys_height
= max (row
->phys_height
,
18200 it
->max_phys_ascent
+ it
->max_phys_descent
);
18201 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18202 it
->max_extra_line_spacing
);
18203 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
18204 row
->x
= x
- it
->first_visible_x
;
18205 /* Record the maximum and minimum buffer positions seen so
18206 far in glyphs that will be displayed by this row. */
18208 RECORD_MAX_MIN_POS (it
);
18213 struct glyph
*glyph
;
18215 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
18217 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18218 new_x
= x
+ glyph
->pixel_width
;
18220 if (/* Lines are continued. */
18221 it
->line_wrap
!= TRUNCATE
18222 && (/* Glyph doesn't fit on the line. */
18223 new_x
> it
->last_visible_x
18224 /* Or it fits exactly on a window system frame. */
18225 || (new_x
== it
->last_visible_x
18226 && FRAME_WINDOW_P (it
->f
))))
18228 /* End of a continued line. */
18231 || (new_x
== it
->last_visible_x
18232 && FRAME_WINDOW_P (it
->f
)))
18234 /* Current glyph is the only one on the line or
18235 fits exactly on the line. We must continue
18236 the line because we can't draw the cursor
18237 after the glyph. */
18238 row
->continued_p
= 1;
18239 it
->current_x
= new_x
;
18240 it
->continuation_lines_width
+= new_x
;
18242 /* Record the maximum and minimum buffer
18243 positions seen so far in glyphs that will be
18244 displayed by this row. */
18246 RECORD_MAX_MIN_POS (it
);
18247 if (i
== nglyphs
- 1)
18249 /* If line-wrap is on, check if a previous
18250 wrap point was found. */
18251 if (wrap_row_used
> 0
18252 /* Even if there is a previous wrap
18253 point, continue the line here as
18254 usual, if (i) the previous character
18255 was a space or tab AND (ii) the
18256 current character is not. */
18258 || IT_DISPLAYING_WHITESPACE (it
)))
18261 set_iterator_to_next (it
, 1);
18262 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18264 if (!get_next_display_element (it
))
18266 row
->exact_window_width_line_p
= 1;
18267 it
->continuation_lines_width
= 0;
18268 row
->continued_p
= 0;
18269 row
->ends_at_zv_p
= 1;
18271 else if (ITERATOR_AT_END_OF_LINE_P (it
))
18273 row
->continued_p
= 0;
18274 row
->exact_window_width_line_p
= 1;
18279 else if (CHAR_GLYPH_PADDING_P (*glyph
)
18280 && !FRAME_WINDOW_P (it
->f
))
18282 /* A padding glyph that doesn't fit on this line.
18283 This means the whole character doesn't fit
18285 if (row
->reversed_p
)
18286 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
18287 - n_glyphs_before
);
18288 row
->used
[TEXT_AREA
] = n_glyphs_before
;
18290 /* Fill the rest of the row with continuation
18291 glyphs like in 20.x. */
18292 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
18293 < row
->glyphs
[1 + TEXT_AREA
])
18294 produce_special_glyphs (it
, IT_CONTINUATION
);
18296 row
->continued_p
= 1;
18297 it
->current_x
= x_before
;
18298 it
->continuation_lines_width
+= x_before
;
18300 /* Restore the height to what it was before the
18301 element not fitting on the line. */
18302 it
->max_ascent
= ascent
;
18303 it
->max_descent
= descent
;
18304 it
->max_phys_ascent
= phys_ascent
;
18305 it
->max_phys_descent
= phys_descent
;
18307 else if (wrap_row_used
> 0)
18310 if (row
->reversed_p
)
18311 unproduce_glyphs (it
,
18312 row
->used
[TEXT_AREA
] - wrap_row_used
);
18314 it
->continuation_lines_width
+= wrap_x
;
18315 row
->used
[TEXT_AREA
] = wrap_row_used
;
18316 row
->ascent
= wrap_row_ascent
;
18317 row
->height
= wrap_row_height
;
18318 row
->phys_ascent
= wrap_row_phys_ascent
;
18319 row
->phys_height
= wrap_row_phys_height
;
18320 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
18321 min_pos
= wrap_row_min_pos
;
18322 min_bpos
= wrap_row_min_bpos
;
18323 max_pos
= wrap_row_max_pos
;
18324 max_bpos
= wrap_row_max_bpos
;
18325 row
->continued_p
= 1;
18326 row
->ends_at_zv_p
= 0;
18327 row
->exact_window_width_line_p
= 0;
18328 it
->continuation_lines_width
+= x
;
18330 /* Make sure that a non-default face is extended
18331 up to the right margin of the window. */
18332 extend_face_to_end_of_line (it
);
18334 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
18336 /* A TAB that extends past the right edge of the
18337 window. This produces a single glyph on
18338 window system frames. We leave the glyph in
18339 this row and let it fill the row, but don't
18340 consume the TAB. */
18341 it
->continuation_lines_width
+= it
->last_visible_x
;
18342 row
->ends_in_middle_of_char_p
= 1;
18343 row
->continued_p
= 1;
18344 glyph
->pixel_width
= it
->last_visible_x
- x
;
18345 it
->starts_in_middle_of_char_p
= 1;
18349 /* Something other than a TAB that draws past
18350 the right edge of the window. Restore
18351 positions to values before the element. */
18352 if (row
->reversed_p
)
18353 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
18354 - (n_glyphs_before
+ i
));
18355 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18357 /* Display continuation glyphs. */
18358 if (!FRAME_WINDOW_P (it
->f
))
18359 produce_special_glyphs (it
, IT_CONTINUATION
);
18360 row
->continued_p
= 1;
18362 it
->current_x
= x_before
;
18363 it
->continuation_lines_width
+= x
;
18364 extend_face_to_end_of_line (it
);
18366 if (nglyphs
> 1 && i
> 0)
18368 row
->ends_in_middle_of_char_p
= 1;
18369 it
->starts_in_middle_of_char_p
= 1;
18372 /* Restore the height to what it was before the
18373 element not fitting on the line. */
18374 it
->max_ascent
= ascent
;
18375 it
->max_descent
= descent
;
18376 it
->max_phys_ascent
= phys_ascent
;
18377 it
->max_phys_descent
= phys_descent
;
18382 else if (new_x
> it
->first_visible_x
)
18384 /* Increment number of glyphs actually displayed. */
18387 /* Record the maximum and minimum buffer positions
18388 seen so far in glyphs that will be displayed by
18391 RECORD_MAX_MIN_POS (it
);
18393 if (x
< it
->first_visible_x
)
18394 /* Glyph is partially visible, i.e. row starts at
18395 negative X position. */
18396 row
->x
= x
- it
->first_visible_x
;
18400 /* Glyph is completely off the left margin of the
18401 window. This should not happen because of the
18402 move_it_in_display_line at the start of this
18403 function, unless the text display area of the
18404 window is empty. */
18405 xassert (it
->first_visible_x
<= it
->last_visible_x
);
18409 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18410 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18411 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18412 row
->phys_height
= max (row
->phys_height
,
18413 it
->max_phys_ascent
+ it
->max_phys_descent
);
18414 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18415 it
->max_extra_line_spacing
);
18417 /* End of this display line if row is continued. */
18418 if (row
->continued_p
|| row
->ends_at_zv_p
)
18423 /* Is this a line end? If yes, we're also done, after making
18424 sure that a non-default face is extended up to the right
18425 margin of the window. */
18426 if (ITERATOR_AT_END_OF_LINE_P (it
))
18428 int used_before
= row
->used
[TEXT_AREA
];
18430 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
18432 /* Add a space at the end of the line that is used to
18433 display the cursor there. */
18434 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18435 append_space_for_newline (it
, 0);
18437 /* Extend the face to the end of the line. */
18438 extend_face_to_end_of_line (it
);
18440 /* Make sure we have the position. */
18441 if (used_before
== 0)
18442 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
18444 /* Record the position of the newline, for use in
18446 it
->eol_pos
= it
->current
.pos
;
18448 /* Consume the line end. This skips over invisible lines. */
18449 set_iterator_to_next (it
, 1);
18450 it
->continuation_lines_width
= 0;
18454 /* Proceed with next display element. Note that this skips
18455 over lines invisible because of selective display. */
18456 set_iterator_to_next (it
, 1);
18458 /* If we truncate lines, we are done when the last displayed
18459 glyphs reach past the right margin of the window. */
18460 if (it
->line_wrap
== TRUNCATE
18461 && (FRAME_WINDOW_P (it
->f
)
18462 ? (it
->current_x
>= it
->last_visible_x
)
18463 : (it
->current_x
> it
->last_visible_x
)))
18465 /* Maybe add truncation glyphs. */
18466 if (!FRAME_WINDOW_P (it
->f
))
18470 if (!row
->reversed_p
)
18472 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18473 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18478 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
18479 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18481 /* Remove any padding glyphs at the front of ROW, to
18482 make room for the truncation glyphs we will be
18483 adding below. The loop below always inserts at
18484 least one truncation glyph, so also remove the
18485 last glyph added to ROW. */
18486 unproduce_glyphs (it
, i
+ 1);
18487 /* Adjust i for the loop below. */
18488 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
18491 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18493 row
->used
[TEXT_AREA
] = i
;
18494 produce_special_glyphs (it
, IT_TRUNCATION
);
18497 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18499 /* Don't truncate if we can overflow newline into fringe. */
18500 if (!get_next_display_element (it
))
18502 it
->continuation_lines_width
= 0;
18503 row
->ends_at_zv_p
= 1;
18504 row
->exact_window_width_line_p
= 1;
18507 if (ITERATOR_AT_END_OF_LINE_P (it
))
18509 row
->exact_window_width_line_p
= 1;
18510 goto at_end_of_line
;
18514 row
->truncated_on_right_p
= 1;
18515 it
->continuation_lines_width
= 0;
18516 reseat_at_next_visible_line_start (it
, 0);
18517 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
18518 it
->hpos
= hpos_before
;
18519 it
->current_x
= x_before
;
18524 /* If line is not empty and hscrolled, maybe insert truncation glyphs
18525 at the left window margin. */
18526 if (it
->first_visible_x
18527 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
18529 if (!FRAME_WINDOW_P (it
->f
))
18530 insert_left_trunc_glyphs (it
);
18531 row
->truncated_on_left_p
= 1;
18534 /* Remember the position at which this line ends.
18536 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
18537 cannot be before the call to find_row_edges below, since that is
18538 where these positions are determined. */
18539 row
->end
= it
->current
;
18542 row
->minpos
= row
->start
.pos
;
18543 row
->maxpos
= row
->end
.pos
;
18547 /* ROW->minpos and ROW->maxpos must be the smallest and
18548 `1 + the largest' buffer positions in ROW. But if ROW was
18549 bidi-reordered, these two positions can be anywhere in the
18550 row, so we must determine them now. */
18551 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
18554 /* If the start of this line is the overlay arrow-position, then
18555 mark this glyph row as the one containing the overlay arrow.
18556 This is clearly a mess with variable size fonts. It would be
18557 better to let it be displayed like cursors under X. */
18558 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
18559 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
18560 !NILP (overlay_arrow_string
)))
18562 /* Overlay arrow in window redisplay is a fringe bitmap. */
18563 if (STRINGP (overlay_arrow_string
))
18565 struct glyph_row
*arrow_row
18566 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
18567 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
18568 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
18569 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
18570 struct glyph
*p2
, *end
;
18572 /* Copy the arrow glyphs. */
18573 while (glyph
< arrow_end
)
18576 /* Throw away padding glyphs. */
18578 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
18579 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
18585 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
18590 xassert (INTEGERP (overlay_arrow_string
));
18591 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
18593 overlay_arrow_seen
= 1;
18596 /* Compute pixel dimensions of this line. */
18597 compute_line_metrics (it
);
18599 /* Record whether this row ends inside an ellipsis. */
18600 row
->ends_in_ellipsis_p
18601 = (it
->method
== GET_FROM_DISPLAY_VECTOR
18602 && it
->ellipsis_p
);
18604 /* Save fringe bitmaps in this row. */
18605 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
18606 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
18607 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
18608 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
18610 it
->left_user_fringe_bitmap
= 0;
18611 it
->left_user_fringe_face_id
= 0;
18612 it
->right_user_fringe_bitmap
= 0;
18613 it
->right_user_fringe_face_id
= 0;
18615 /* Maybe set the cursor. */
18616 cvpos
= it
->w
->cursor
.vpos
;
18618 /* In bidi-reordered rows, keep checking for proper cursor
18619 position even if one has been found already, because buffer
18620 positions in such rows change non-linearly with ROW->VPOS,
18621 when a line is continued. One exception: when we are at ZV,
18622 display cursor on the first suitable glyph row, since all
18623 the empty rows after that also have their position set to ZV. */
18624 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18625 lines' rows is implemented for bidi-reordered rows. */
18627 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
18628 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
18629 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
18630 && cursor_row_p (row
))
18631 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
18633 /* Highlight trailing whitespace. */
18634 if (!NILP (Vshow_trailing_whitespace
))
18635 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
18637 /* Prepare for the next line. This line starts horizontally at (X
18638 HPOS) = (0 0). Vertical positions are incremented. As a
18639 convenience for the caller, IT->glyph_row is set to the next
18641 it
->current_x
= it
->hpos
= 0;
18642 it
->current_y
+= row
->height
;
18643 SET_TEXT_POS (it
->eol_pos
, 0, 0);
18646 /* The next row should by default use the same value of the
18647 reversed_p flag as this one. set_iterator_to_next decides when
18648 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
18649 the flag accordingly. */
18650 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
18651 it
->glyph_row
->reversed_p
= row
->reversed_p
;
18652 it
->start
= row
->end
;
18653 return row
->displays_text_p
;
18655 #undef RECORD_MAX_MIN_POS
18658 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
18659 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
18660 doc
: /* Return paragraph direction at point in BUFFER.
18661 Value is either `left-to-right' or `right-to-left'.
18662 If BUFFER is omitted or nil, it defaults to the current buffer.
18664 Paragraph direction determines how the text in the paragraph is displayed.
18665 In left-to-right paragraphs, text begins at the left margin of the window
18666 and the reading direction is generally left to right. In right-to-left
18667 paragraphs, text begins at the right margin and is read from right to left.
18669 See also `bidi-paragraph-direction'. */)
18670 (Lisp_Object buffer
)
18672 struct buffer
*buf
= current_buffer
;
18673 struct buffer
*old
= buf
;
18675 if (! NILP (buffer
))
18677 CHECK_BUFFER (buffer
);
18678 buf
= XBUFFER (buffer
);
18681 if (NILP (BVAR (buf
, bidi_display_reordering
)))
18682 return Qleft_to_right
;
18683 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
18684 return BVAR (buf
, bidi_paragraph_direction
);
18687 /* Determine the direction from buffer text. We could try to
18688 use current_matrix if it is up to date, but this seems fast
18689 enough as it is. */
18690 struct bidi_it itb
;
18691 EMACS_INT pos
= BUF_PT (buf
);
18692 EMACS_INT bytepos
= BUF_PT_BYTE (buf
);
18695 set_buffer_temp (buf
);
18696 /* bidi_paragraph_init finds the base direction of the paragraph
18697 by searching forward from paragraph start. We need the base
18698 direction of the current or _previous_ paragraph, so we need
18699 to make sure we are within that paragraph. To that end, find
18700 the previous non-empty line. */
18701 if (pos
>= ZV
&& pos
> BEGV
)
18704 bytepos
= CHAR_TO_BYTE (pos
);
18706 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
18707 || c
== ' ' || c
== '\t' || c
== '\f')
18709 if (bytepos
<= BEGV_BYTE
)
18714 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
18717 itb
.bytepos
= bytepos
;
18719 itb
.string
.s
= NULL
;
18720 itb
.string
.lstring
= Qnil
;
18721 itb
.frame_window_p
= FRAME_WINDOW_P (SELECTED_FRAME ()); /* guesswork */
18723 itb
.separator_limit
= -1;
18724 itb
.paragraph_dir
= NEUTRAL_DIR
;
18726 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
18727 set_buffer_temp (old
);
18728 switch (itb
.paragraph_dir
)
18731 return Qleft_to_right
;
18734 return Qright_to_left
;
18744 /***********************************************************************
18746 ***********************************************************************/
18748 /* Redisplay the menu bar in the frame for window W.
18750 The menu bar of X frames that don't have X toolkit support is
18751 displayed in a special window W->frame->menu_bar_window.
18753 The menu bar of terminal frames is treated specially as far as
18754 glyph matrices are concerned. Menu bar lines are not part of
18755 windows, so the update is done directly on the frame matrix rows
18756 for the menu bar. */
18759 display_menu_bar (struct window
*w
)
18761 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18766 /* Don't do all this for graphical frames. */
18768 if (FRAME_W32_P (f
))
18771 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
18777 if (FRAME_NS_P (f
))
18779 #endif /* HAVE_NS */
18781 #ifdef USE_X_TOOLKIT
18782 xassert (!FRAME_WINDOW_P (f
));
18783 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
18784 it
.first_visible_x
= 0;
18785 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18786 #else /* not USE_X_TOOLKIT */
18787 if (FRAME_WINDOW_P (f
))
18789 /* Menu bar lines are displayed in the desired matrix of the
18790 dummy window menu_bar_window. */
18791 struct window
*menu_w
;
18792 xassert (WINDOWP (f
->menu_bar_window
));
18793 menu_w
= XWINDOW (f
->menu_bar_window
);
18794 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
18796 it
.first_visible_x
= 0;
18797 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18801 /* This is a TTY frame, i.e. character hpos/vpos are used as
18803 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
18805 it
.first_visible_x
= 0;
18806 it
.last_visible_x
= FRAME_COLS (f
);
18808 #endif /* not USE_X_TOOLKIT */
18810 /* FIXME: This should be controlled by a user option. See the
18811 comments in redisplay_tool_bar and display_mode_line about
18813 it
.paragraph_embedding
= L2R
;
18815 if (! mode_line_inverse_video
)
18816 /* Force the menu-bar to be displayed in the default face. */
18817 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18819 /* Clear all rows of the menu bar. */
18820 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
18822 struct glyph_row
*row
= it
.glyph_row
+ i
;
18823 clear_glyph_row (row
);
18824 row
->enabled_p
= 1;
18825 row
->full_width_p
= 1;
18828 /* Display all items of the menu bar. */
18829 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
18830 for (i
= 0; i
< ASIZE (items
); i
+= 4)
18832 Lisp_Object string
;
18834 /* Stop at nil string. */
18835 string
= AREF (items
, i
+ 1);
18839 /* Remember where item was displayed. */
18840 ASET (items
, i
+ 3, make_number (it
.hpos
));
18842 /* Display the item, pad with one space. */
18843 if (it
.current_x
< it
.last_visible_x
)
18844 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
18845 SCHARS (string
) + 1, 0, 0, -1);
18848 /* Fill out the line with spaces. */
18849 if (it
.current_x
< it
.last_visible_x
)
18850 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
18852 /* Compute the total height of the lines. */
18853 compute_line_metrics (&it
);
18858 /***********************************************************************
18860 ***********************************************************************/
18862 /* Redisplay mode lines in the window tree whose root is WINDOW. If
18863 FORCE is non-zero, redisplay mode lines unconditionally.
18864 Otherwise, redisplay only mode lines that are garbaged. Value is
18865 the number of windows whose mode lines were redisplayed. */
18868 redisplay_mode_lines (Lisp_Object window
, int force
)
18872 while (!NILP (window
))
18874 struct window
*w
= XWINDOW (window
);
18876 if (WINDOWP (w
->hchild
))
18877 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
18878 else if (WINDOWP (w
->vchild
))
18879 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18881 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18882 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18884 struct text_pos lpoint
;
18885 struct buffer
*old
= current_buffer
;
18887 /* Set the window's buffer for the mode line display. */
18888 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18889 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18891 /* Point refers normally to the selected window. For any
18892 other window, set up appropriate value. */
18893 if (!EQ (window
, selected_window
))
18895 struct text_pos pt
;
18897 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18898 if (CHARPOS (pt
) < BEGV
)
18899 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18900 else if (CHARPOS (pt
) > (ZV
- 1))
18901 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18903 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18906 /* Display mode lines. */
18907 clear_glyph_matrix (w
->desired_matrix
);
18908 if (display_mode_lines (w
))
18911 w
->must_be_updated_p
= 1;
18914 /* Restore old settings. */
18915 set_buffer_internal_1 (old
);
18916 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18926 /* Display the mode and/or header line of window W. Value is the
18927 sum number of mode lines and header lines displayed. */
18930 display_mode_lines (struct window
*w
)
18932 Lisp_Object old_selected_window
, old_selected_frame
;
18935 old_selected_frame
= selected_frame
;
18936 selected_frame
= w
->frame
;
18937 old_selected_window
= selected_window
;
18938 XSETWINDOW (selected_window
, w
);
18940 /* These will be set while the mode line specs are processed. */
18941 line_number_displayed
= 0;
18942 w
->column_number_displayed
= Qnil
;
18944 if (WINDOW_WANTS_MODELINE_P (w
))
18946 struct window
*sel_w
= XWINDOW (old_selected_window
);
18948 /* Select mode line face based on the real selected window. */
18949 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18950 BVAR (current_buffer
, mode_line_format
));
18954 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18956 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18957 BVAR (current_buffer
, header_line_format
));
18961 selected_frame
= old_selected_frame
;
18962 selected_window
= old_selected_window
;
18967 /* Display mode or header line of window W. FACE_ID specifies which
18968 line to display; it is either MODE_LINE_FACE_ID or
18969 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18970 display. Value is the pixel height of the mode/header line
18974 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
18978 int count
= SPECPDL_INDEX ();
18980 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18981 /* Don't extend on a previously drawn mode-line.
18982 This may happen if called from pos_visible_p. */
18983 it
.glyph_row
->enabled_p
= 0;
18984 prepare_desired_row (it
.glyph_row
);
18986 it
.glyph_row
->mode_line_p
= 1;
18988 if (! mode_line_inverse_video
)
18989 /* Force the mode-line to be displayed in the default face. */
18990 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18992 /* FIXME: This should be controlled by a user option. But
18993 supporting such an option is not trivial, since the mode line is
18994 made up of many separate strings, most of which are normally
18995 unibyte, and unibyte strings currently don't get reordered for
18997 it
.paragraph_embedding
= L2R
;
18999 record_unwind_protect (unwind_format_mode_line
,
19000 format_mode_line_unwind_data (NULL
, Qnil
, 0));
19002 mode_line_target
= MODE_LINE_DISPLAY
;
19004 /* Temporarily make frame's keyboard the current kboard so that
19005 kboard-local variables in the mode_line_format will get the right
19007 push_kboard (FRAME_KBOARD (it
.f
));
19008 record_unwind_save_match_data ();
19009 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19012 unbind_to (count
, Qnil
);
19014 /* Fill up with spaces. */
19015 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
19017 compute_line_metrics (&it
);
19018 it
.glyph_row
->full_width_p
= 1;
19019 it
.glyph_row
->continued_p
= 0;
19020 it
.glyph_row
->truncated_on_left_p
= 0;
19021 it
.glyph_row
->truncated_on_right_p
= 0;
19023 /* Make a 3D mode-line have a shadow at its right end. */
19024 face
= FACE_FROM_ID (it
.f
, face_id
);
19025 extend_face_to_end_of_line (&it
);
19026 if (face
->box
!= FACE_NO_BOX
)
19028 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
19029 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
19030 last
->right_box_line_p
= 1;
19033 return it
.glyph_row
->height
;
19036 /* Move element ELT in LIST to the front of LIST.
19037 Return the updated list. */
19040 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
19042 register Lisp_Object tail
, prev
;
19043 register Lisp_Object tem
;
19047 while (CONSP (tail
))
19053 /* Splice out the link TAIL. */
19055 list
= XCDR (tail
);
19057 Fsetcdr (prev
, XCDR (tail
));
19059 /* Now make it the first. */
19060 Fsetcdr (tail
, list
);
19065 tail
= XCDR (tail
);
19069 /* Not found--return unchanged LIST. */
19073 /* Contribute ELT to the mode line for window IT->w. How it
19074 translates into text depends on its data type.
19076 IT describes the display environment in which we display, as usual.
19078 DEPTH is the depth in recursion. It is used to prevent
19079 infinite recursion here.
19081 FIELD_WIDTH is the number of characters the display of ELT should
19082 occupy in the mode line, and PRECISION is the maximum number of
19083 characters to display from ELT's representation. See
19084 display_string for details.
19086 Returns the hpos of the end of the text generated by ELT.
19088 PROPS is a property list to add to any string we encounter.
19090 If RISKY is nonzero, remove (disregard) any properties in any string
19091 we encounter, and ignore :eval and :propertize.
19093 The global variable `mode_line_target' determines whether the
19094 output is passed to `store_mode_line_noprop',
19095 `store_mode_line_string', or `display_string'. */
19098 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
19099 Lisp_Object elt
, Lisp_Object props
, int risky
)
19101 int n
= 0, field
, prec
;
19106 elt
= build_string ("*too-deep*");
19110 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
19114 /* A string: output it and check for %-constructs within it. */
19116 EMACS_INT offset
= 0;
19118 if (SCHARS (elt
) > 0
19119 && (!NILP (props
) || risky
))
19121 Lisp_Object oprops
, aelt
;
19122 oprops
= Ftext_properties_at (make_number (0), elt
);
19124 /* If the starting string's properties are not what
19125 we want, translate the string. Also, if the string
19126 is risky, do that anyway. */
19128 if (NILP (Fequal (props
, oprops
)) || risky
)
19130 /* If the starting string has properties,
19131 merge the specified ones onto the existing ones. */
19132 if (! NILP (oprops
) && !risky
)
19136 oprops
= Fcopy_sequence (oprops
);
19138 while (CONSP (tem
))
19140 oprops
= Fplist_put (oprops
, XCAR (tem
),
19141 XCAR (XCDR (tem
)));
19142 tem
= XCDR (XCDR (tem
));
19147 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
19148 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
19150 /* AELT is what we want. Move it to the front
19151 without consing. */
19153 mode_line_proptrans_alist
19154 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
19160 /* If AELT has the wrong props, it is useless.
19161 so get rid of it. */
19163 mode_line_proptrans_alist
19164 = Fdelq (aelt
, mode_line_proptrans_alist
);
19166 elt
= Fcopy_sequence (elt
);
19167 Fset_text_properties (make_number (0), Flength (elt
),
19169 /* Add this item to mode_line_proptrans_alist. */
19170 mode_line_proptrans_alist
19171 = Fcons (Fcons (elt
, props
),
19172 mode_line_proptrans_alist
);
19173 /* Truncate mode_line_proptrans_alist
19174 to at most 50 elements. */
19175 tem
= Fnthcdr (make_number (50),
19176 mode_line_proptrans_alist
);
19178 XSETCDR (tem
, Qnil
);
19187 prec
= precision
- n
;
19188 switch (mode_line_target
)
19190 case MODE_LINE_NOPROP
:
19191 case MODE_LINE_TITLE
:
19192 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
19194 case MODE_LINE_STRING
:
19195 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
19197 case MODE_LINE_DISPLAY
:
19198 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
19199 0, prec
, 0, STRING_MULTIBYTE (elt
));
19206 /* Handle the non-literal case. */
19208 while ((precision
<= 0 || n
< precision
)
19209 && SREF (elt
, offset
) != 0
19210 && (mode_line_target
!= MODE_LINE_DISPLAY
19211 || it
->current_x
< it
->last_visible_x
))
19213 EMACS_INT last_offset
= offset
;
19215 /* Advance to end of string or next format specifier. */
19216 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
19219 if (offset
- 1 != last_offset
)
19221 EMACS_INT nchars
, nbytes
;
19223 /* Output to end of string or up to '%'. Field width
19224 is length of string. Don't output more than
19225 PRECISION allows us. */
19228 prec
= c_string_width (SDATA (elt
) + last_offset
,
19229 offset
- last_offset
, precision
- n
,
19232 switch (mode_line_target
)
19234 case MODE_LINE_NOPROP
:
19235 case MODE_LINE_TITLE
:
19236 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
19238 case MODE_LINE_STRING
:
19240 EMACS_INT bytepos
= last_offset
;
19241 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
19242 EMACS_INT endpos
= (precision
<= 0
19243 ? string_byte_to_char (elt
, offset
)
19244 : charpos
+ nchars
);
19246 n
+= store_mode_line_string (NULL
,
19247 Fsubstring (elt
, make_number (charpos
),
19248 make_number (endpos
)),
19252 case MODE_LINE_DISPLAY
:
19254 EMACS_INT bytepos
= last_offset
;
19255 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
19257 if (precision
<= 0)
19258 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
19259 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
19261 STRING_MULTIBYTE (elt
));
19266 else /* c == '%' */
19268 EMACS_INT percent_position
= offset
;
19270 /* Get the specified minimum width. Zero means
19273 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
19274 field
= field
* 10 + c
- '0';
19276 /* Don't pad beyond the total padding allowed. */
19277 if (field_width
- n
> 0 && field
> field_width
- n
)
19278 field
= field_width
- n
;
19280 /* Note that either PRECISION <= 0 or N < PRECISION. */
19281 prec
= precision
- n
;
19284 n
+= display_mode_element (it
, depth
, field
, prec
,
19285 Vglobal_mode_string
, props
,
19290 EMACS_INT bytepos
, charpos
;
19292 Lisp_Object string
;
19294 bytepos
= percent_position
;
19295 charpos
= (STRING_MULTIBYTE (elt
)
19296 ? string_byte_to_char (elt
, bytepos
)
19298 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
19299 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
19301 switch (mode_line_target
)
19303 case MODE_LINE_NOPROP
:
19304 case MODE_LINE_TITLE
:
19305 n
+= store_mode_line_noprop (spec
, field
, prec
);
19307 case MODE_LINE_STRING
:
19309 int len
= strlen (spec
);
19310 Lisp_Object tem
= make_string (spec
, len
);
19311 props
= Ftext_properties_at (make_number (charpos
), elt
);
19312 /* Should only keep face property in props */
19313 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
19316 case MODE_LINE_DISPLAY
:
19318 int nglyphs_before
, nwritten
;
19320 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
19321 nwritten
= display_string (spec
, string
, elt
,
19326 /* Assign to the glyphs written above the
19327 string where the `%x' came from, position
19331 struct glyph
*glyph
19332 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
19336 for (i
= 0; i
< nwritten
; ++i
)
19338 glyph
[i
].object
= elt
;
19339 glyph
[i
].charpos
= charpos
;
19356 /* A symbol: process the value of the symbol recursively
19357 as if it appeared here directly. Avoid error if symbol void.
19358 Special case: if value of symbol is a string, output the string
19361 register Lisp_Object tem
;
19363 /* If the variable is not marked as risky to set
19364 then its contents are risky to use. */
19365 if (NILP (Fget (elt
, Qrisky_local_variable
)))
19368 tem
= Fboundp (elt
);
19371 tem
= Fsymbol_value (elt
);
19372 /* If value is a string, output that string literally:
19373 don't check for % within it. */
19377 if (!EQ (tem
, elt
))
19379 /* Give up right away for nil or t. */
19389 register Lisp_Object car
, tem
;
19391 /* A cons cell: five distinct cases.
19392 If first element is :eval or :propertize, do something special.
19393 If first element is a string or a cons, process all the elements
19394 and effectively concatenate them.
19395 If first element is a negative number, truncate displaying cdr to
19396 at most that many characters. If positive, pad (with spaces)
19397 to at least that many characters.
19398 If first element is a symbol, process the cadr or caddr recursively
19399 according to whether the symbol's value is non-nil or nil. */
19401 if (EQ (car
, QCeval
))
19403 /* An element of the form (:eval FORM) means evaluate FORM
19404 and use the result as mode line elements. */
19409 if (CONSP (XCDR (elt
)))
19412 spec
= safe_eval (XCAR (XCDR (elt
)));
19413 n
+= display_mode_element (it
, depth
, field_width
- n
,
19414 precision
- n
, spec
, props
,
19418 else if (EQ (car
, QCpropertize
))
19420 /* An element of the form (:propertize ELT PROPS...)
19421 means display ELT but applying properties PROPS. */
19426 if (CONSP (XCDR (elt
)))
19427 n
+= display_mode_element (it
, depth
, field_width
- n
,
19428 precision
- n
, XCAR (XCDR (elt
)),
19429 XCDR (XCDR (elt
)), risky
);
19431 else if (SYMBOLP (car
))
19433 tem
= Fboundp (car
);
19437 /* elt is now the cdr, and we know it is a cons cell.
19438 Use its car if CAR has a non-nil value. */
19441 tem
= Fsymbol_value (car
);
19448 /* Symbol's value is nil (or symbol is unbound)
19449 Get the cddr of the original list
19450 and if possible find the caddr and use that. */
19454 else if (!CONSP (elt
))
19459 else if (INTEGERP (car
))
19461 register int lim
= XINT (car
);
19465 /* Negative int means reduce maximum width. */
19466 if (precision
<= 0)
19469 precision
= min (precision
, -lim
);
19473 /* Padding specified. Don't let it be more than
19474 current maximum. */
19476 lim
= min (precision
, lim
);
19478 /* If that's more padding than already wanted, queue it.
19479 But don't reduce padding already specified even if
19480 that is beyond the current truncation point. */
19481 field_width
= max (lim
, field_width
);
19485 else if (STRINGP (car
) || CONSP (car
))
19487 Lisp_Object halftail
= elt
;
19491 && (precision
<= 0 || n
< precision
))
19493 n
+= display_mode_element (it
, depth
,
19494 /* Do padding only after the last
19495 element in the list. */
19496 (! CONSP (XCDR (elt
))
19499 precision
- n
, XCAR (elt
),
19503 if ((len
& 1) == 0)
19504 halftail
= XCDR (halftail
);
19505 /* Check for cycle. */
19506 if (EQ (halftail
, elt
))
19515 elt
= build_string ("*invalid*");
19519 /* Pad to FIELD_WIDTH. */
19520 if (field_width
> 0 && n
< field_width
)
19522 switch (mode_line_target
)
19524 case MODE_LINE_NOPROP
:
19525 case MODE_LINE_TITLE
:
19526 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
19528 case MODE_LINE_STRING
:
19529 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
19531 case MODE_LINE_DISPLAY
:
19532 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
19541 /* Store a mode-line string element in mode_line_string_list.
19543 If STRING is non-null, display that C string. Otherwise, the Lisp
19544 string LISP_STRING is displayed.
19546 FIELD_WIDTH is the minimum number of output glyphs to produce.
19547 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19548 with spaces. FIELD_WIDTH <= 0 means don't pad.
19550 PRECISION is the maximum number of characters to output from
19551 STRING. PRECISION <= 0 means don't truncate the string.
19553 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
19554 properties to the string.
19556 PROPS are the properties to add to the string.
19557 The mode_line_string_face face property is always added to the string.
19561 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
19562 int field_width
, int precision
, Lisp_Object props
)
19567 if (string
!= NULL
)
19569 len
= strlen (string
);
19570 if (precision
> 0 && len
> precision
)
19572 lisp_string
= make_string (string
, len
);
19574 props
= mode_line_string_face_prop
;
19575 else if (!NILP (mode_line_string_face
))
19577 Lisp_Object face
= Fplist_get (props
, Qface
);
19578 props
= Fcopy_sequence (props
);
19580 face
= mode_line_string_face
;
19582 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19583 props
= Fplist_put (props
, Qface
, face
);
19585 Fadd_text_properties (make_number (0), make_number (len
),
19586 props
, lisp_string
);
19590 len
= XFASTINT (Flength (lisp_string
));
19591 if (precision
> 0 && len
> precision
)
19594 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
19597 if (!NILP (mode_line_string_face
))
19601 props
= Ftext_properties_at (make_number (0), lisp_string
);
19602 face
= Fplist_get (props
, Qface
);
19604 face
= mode_line_string_face
;
19606 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19607 props
= Fcons (Qface
, Fcons (face
, Qnil
));
19609 lisp_string
= Fcopy_sequence (lisp_string
);
19612 Fadd_text_properties (make_number (0), make_number (len
),
19613 props
, lisp_string
);
19618 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19622 if (field_width
> len
)
19624 field_width
-= len
;
19625 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
19627 Fadd_text_properties (make_number (0), make_number (field_width
),
19628 props
, lisp_string
);
19629 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19637 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
19639 doc
: /* Format a string out of a mode line format specification.
19640 First arg FORMAT specifies the mode line format (see `mode-line-format'
19641 for details) to use.
19643 By default, the format is evaluated for the currently selected window.
19645 Optional second arg FACE specifies the face property to put on all
19646 characters for which no face is specified. The value nil means the
19647 default face. The value t means whatever face the window's mode line
19648 currently uses (either `mode-line' or `mode-line-inactive',
19649 depending on whether the window is the selected window or not).
19650 An integer value means the value string has no text
19653 Optional third and fourth args WINDOW and BUFFER specify the window
19654 and buffer to use as the context for the formatting (defaults
19655 are the selected window and the WINDOW's buffer). */)
19656 (Lisp_Object format
, Lisp_Object face
,
19657 Lisp_Object window
, Lisp_Object buffer
)
19662 struct buffer
*old_buffer
= NULL
;
19664 int no_props
= INTEGERP (face
);
19665 int count
= SPECPDL_INDEX ();
19667 int string_start
= 0;
19670 window
= selected_window
;
19671 CHECK_WINDOW (window
);
19672 w
= XWINDOW (window
);
19675 buffer
= w
->buffer
;
19676 CHECK_BUFFER (buffer
);
19678 /* Make formatting the modeline a non-op when noninteractive, otherwise
19679 there will be problems later caused by a partially initialized frame. */
19680 if (NILP (format
) || noninteractive
)
19681 return empty_unibyte_string
;
19686 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
19687 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
19688 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
19689 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
19690 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
19691 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
19692 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
19695 if (XBUFFER (buffer
) != current_buffer
)
19696 old_buffer
= current_buffer
;
19698 /* Save things including mode_line_proptrans_alist,
19699 and set that to nil so that we don't alter the outer value. */
19700 record_unwind_protect (unwind_format_mode_line
,
19701 format_mode_line_unwind_data
19702 (old_buffer
, selected_window
, 1));
19703 mode_line_proptrans_alist
= Qnil
;
19705 Fselect_window (window
, Qt
);
19707 set_buffer_internal_1 (XBUFFER (buffer
));
19709 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19713 mode_line_target
= MODE_LINE_NOPROP
;
19714 mode_line_string_face_prop
= Qnil
;
19715 mode_line_string_list
= Qnil
;
19716 string_start
= MODE_LINE_NOPROP_LEN (0);
19720 mode_line_target
= MODE_LINE_STRING
;
19721 mode_line_string_list
= Qnil
;
19722 mode_line_string_face
= face
;
19723 mode_line_string_face_prop
19724 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
19727 push_kboard (FRAME_KBOARD (it
.f
));
19728 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19733 len
= MODE_LINE_NOPROP_LEN (string_start
);
19734 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
19738 mode_line_string_list
= Fnreverse (mode_line_string_list
);
19739 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
19740 empty_unibyte_string
);
19743 unbind_to (count
, Qnil
);
19747 /* Write a null-terminated, right justified decimal representation of
19748 the positive integer D to BUF using a minimal field width WIDTH. */
19751 pint2str (register char *buf
, register int width
, register EMACS_INT d
)
19753 register char *p
= buf
;
19761 *p
++ = d
% 10 + '0';
19766 for (width
-= (int) (p
- buf
); width
> 0; --width
)
19777 /* Write a null-terminated, right justified decimal and "human
19778 readable" representation of the nonnegative integer D to BUF using
19779 a minimal field width WIDTH. D should be smaller than 999.5e24. */
19781 static const char power_letter
[] =
19795 pint2hrstr (char *buf
, int width
, EMACS_INT d
)
19797 /* We aim to represent the nonnegative integer D as
19798 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
19799 EMACS_INT quotient
= d
;
19801 /* -1 means: do not use TENTHS. */
19805 /* Length of QUOTIENT.TENTHS as a string. */
19811 if (1000 <= quotient
)
19813 /* Scale to the appropriate EXPONENT. */
19816 remainder
= quotient
% 1000;
19820 while (1000 <= quotient
);
19822 /* Round to nearest and decide whether to use TENTHS or not. */
19825 tenths
= remainder
/ 100;
19826 if (50 <= remainder
% 100)
19833 if (quotient
== 10)
19841 if (500 <= remainder
)
19843 if (quotient
< 999)
19854 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
19855 if (tenths
== -1 && quotient
<= 99)
19862 p
= psuffix
= buf
+ max (width
, length
);
19864 /* Print EXPONENT. */
19865 *psuffix
++ = power_letter
[exponent
];
19868 /* Print TENTHS. */
19871 *--p
= '0' + tenths
;
19875 /* Print QUOTIENT. */
19878 int digit
= quotient
% 10;
19879 *--p
= '0' + digit
;
19881 while ((quotient
/= 10) != 0);
19883 /* Print leading spaces. */
19888 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19889 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19890 type of CODING_SYSTEM. Return updated pointer into BUF. */
19892 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19895 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
19898 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
19899 const unsigned char *eol_str
;
19901 /* The EOL conversion we are using. */
19902 Lisp_Object eoltype
;
19904 val
= CODING_SYSTEM_SPEC (coding_system
);
19907 if (!VECTORP (val
)) /* Not yet decided. */
19912 eoltype
= eol_mnemonic_undecided
;
19913 /* Don't mention EOL conversion if it isn't decided. */
19918 Lisp_Object eolvalue
;
19920 attrs
= AREF (val
, 0);
19921 eolvalue
= AREF (val
, 2);
19924 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19928 /* The EOL conversion that is normal on this system. */
19930 if (NILP (eolvalue
)) /* Not yet decided. */
19931 eoltype
= eol_mnemonic_undecided
;
19932 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19933 eoltype
= eol_mnemonic_undecided
;
19934 else /* eolvalue is Qunix, Qdos, or Qmac. */
19935 eoltype
= (EQ (eolvalue
, Qunix
)
19936 ? eol_mnemonic_unix
19937 : (EQ (eolvalue
, Qdos
) == 1
19938 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19944 /* Mention the EOL conversion if it is not the usual one. */
19945 if (STRINGP (eoltype
))
19947 eol_str
= SDATA (eoltype
);
19948 eol_str_len
= SBYTES (eoltype
);
19950 else if (CHARACTERP (eoltype
))
19952 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19953 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19958 eol_str
= invalid_eol_type
;
19959 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19961 memcpy (buf
, eol_str
, eol_str_len
);
19962 buf
+= eol_str_len
;
19968 /* Return a string for the output of a mode line %-spec for window W,
19969 generated by character C. FIELD_WIDTH > 0 means pad the string
19970 returned with spaces to that value. Return a Lisp string in
19971 *STRING if the resulting string is taken from that Lisp string.
19973 Note we operate on the current buffer for most purposes,
19974 the exception being w->base_line_pos. */
19976 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19978 static const char *
19979 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
19980 Lisp_Object
*string
)
19983 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19984 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19985 struct buffer
*b
= current_buffer
;
19993 if (!NILP (BVAR (b
, read_only
)))
19995 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20000 /* This differs from %* only for a modified read-only buffer. */
20001 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20003 if (!NILP (BVAR (b
, read_only
)))
20008 /* This differs from %* in ignoring read-only-ness. */
20009 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
20021 if (command_loop_level
> 5)
20023 p
= decode_mode_spec_buf
;
20024 for (i
= 0; i
< command_loop_level
; i
++)
20027 return decode_mode_spec_buf
;
20035 if (command_loop_level
> 5)
20037 p
= decode_mode_spec_buf
;
20038 for (i
= 0; i
< command_loop_level
; i
++)
20041 return decode_mode_spec_buf
;
20048 /* Let lots_of_dashes be a string of infinite length. */
20049 if (mode_line_target
== MODE_LINE_NOPROP
||
20050 mode_line_target
== MODE_LINE_STRING
)
20052 if (field_width
<= 0
20053 || field_width
> sizeof (lots_of_dashes
))
20055 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
20056 decode_mode_spec_buf
[i
] = '-';
20057 decode_mode_spec_buf
[i
] = '\0';
20058 return decode_mode_spec_buf
;
20061 return lots_of_dashes
;
20065 obj
= BVAR (b
, name
);
20069 /* %c and %l are ignored in `frame-title-format'.
20070 (In redisplay_internal, the frame title is drawn _before_ the
20071 windows are updated, so the stuff which depends on actual
20072 window contents (such as %l) may fail to render properly, or
20073 even crash emacs.) */
20074 if (mode_line_target
== MODE_LINE_TITLE
)
20078 EMACS_INT col
= current_column ();
20079 w
->column_number_displayed
= make_number (col
);
20080 pint2str (decode_mode_spec_buf
, field_width
, col
);
20081 return decode_mode_spec_buf
;
20085 #ifndef SYSTEM_MALLOC
20087 if (NILP (Vmemory_full
))
20090 return "!MEM FULL! ";
20097 /* %F displays the frame name. */
20098 if (!NILP (f
->title
))
20099 return SSDATA (f
->title
);
20100 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
20101 return SSDATA (f
->name
);
20105 obj
= BVAR (b
, filename
);
20110 EMACS_INT size
= ZV
- BEGV
;
20111 pint2str (decode_mode_spec_buf
, field_width
, size
);
20112 return decode_mode_spec_buf
;
20117 EMACS_INT size
= ZV
- BEGV
;
20118 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
20119 return decode_mode_spec_buf
;
20124 EMACS_INT startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
20125 EMACS_INT topline
, nlines
, height
;
20128 /* %c and %l are ignored in `frame-title-format'. */
20129 if (mode_line_target
== MODE_LINE_TITLE
)
20132 startpos
= XMARKER (w
->start
)->charpos
;
20133 startpos_byte
= marker_byte_position (w
->start
);
20134 height
= WINDOW_TOTAL_LINES (w
);
20136 /* If we decided that this buffer isn't suitable for line numbers,
20137 don't forget that too fast. */
20138 if (EQ (w
->base_line_pos
, w
->buffer
))
20140 /* But do forget it, if the window shows a different buffer now. */
20141 else if (BUFFERP (w
->base_line_pos
))
20142 w
->base_line_pos
= Qnil
;
20144 /* If the buffer is very big, don't waste time. */
20145 if (INTEGERP (Vline_number_display_limit
)
20146 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
20148 w
->base_line_pos
= Qnil
;
20149 w
->base_line_number
= Qnil
;
20153 if (INTEGERP (w
->base_line_number
)
20154 && INTEGERP (w
->base_line_pos
)
20155 && XFASTINT (w
->base_line_pos
) <= startpos
)
20157 line
= XFASTINT (w
->base_line_number
);
20158 linepos
= XFASTINT (w
->base_line_pos
);
20159 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
20164 linepos
= BUF_BEGV (b
);
20165 linepos_byte
= BUF_BEGV_BYTE (b
);
20168 /* Count lines from base line to window start position. */
20169 nlines
= display_count_lines (linepos_byte
,
20173 topline
= nlines
+ line
;
20175 /* Determine a new base line, if the old one is too close
20176 or too far away, or if we did not have one.
20177 "Too close" means it's plausible a scroll-down would
20178 go back past it. */
20179 if (startpos
== BUF_BEGV (b
))
20181 w
->base_line_number
= make_number (topline
);
20182 w
->base_line_pos
= make_number (BUF_BEGV (b
));
20184 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
20185 || linepos
== BUF_BEGV (b
))
20187 EMACS_INT limit
= BUF_BEGV (b
);
20188 EMACS_INT limit_byte
= BUF_BEGV_BYTE (b
);
20189 EMACS_INT position
;
20190 EMACS_INT distance
=
20191 (height
* 2 + 30) * line_number_display_limit_width
;
20193 if (startpos
- distance
> limit
)
20195 limit
= startpos
- distance
;
20196 limit_byte
= CHAR_TO_BYTE (limit
);
20199 nlines
= display_count_lines (startpos_byte
,
20201 - (height
* 2 + 30),
20203 /* If we couldn't find the lines we wanted within
20204 line_number_display_limit_width chars per line,
20205 give up on line numbers for this window. */
20206 if (position
== limit_byte
&& limit
== startpos
- distance
)
20208 w
->base_line_pos
= w
->buffer
;
20209 w
->base_line_number
= Qnil
;
20213 w
->base_line_number
= make_number (topline
- nlines
);
20214 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
20217 /* Now count lines from the start pos to point. */
20218 nlines
= display_count_lines (startpos_byte
,
20219 PT_BYTE
, PT
, &junk
);
20221 /* Record that we did display the line number. */
20222 line_number_displayed
= 1;
20224 /* Make the string to show. */
20225 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
20226 return decode_mode_spec_buf
;
20229 char* p
= decode_mode_spec_buf
;
20230 int pad
= field_width
- 2;
20236 return decode_mode_spec_buf
;
20242 obj
= BVAR (b
, mode_name
);
20246 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
20252 EMACS_INT pos
= marker_position (w
->start
);
20253 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
20255 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
20257 if (pos
<= BUF_BEGV (b
))
20262 else if (pos
<= BUF_BEGV (b
))
20266 if (total
> 1000000)
20267 /* Do it differently for a large value, to avoid overflow. */
20268 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
20270 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
20271 /* We can't normally display a 3-digit number,
20272 so get us a 2-digit number that is close. */
20275 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
20276 return decode_mode_spec_buf
;
20280 /* Display percentage of size above the bottom of the screen. */
20283 EMACS_INT toppos
= marker_position (w
->start
);
20284 EMACS_INT botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
20285 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
20287 if (botpos
>= BUF_ZV (b
))
20289 if (toppos
<= BUF_BEGV (b
))
20296 if (total
> 1000000)
20297 /* Do it differently for a large value, to avoid overflow. */
20298 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
20300 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
20301 /* We can't normally display a 3-digit number,
20302 so get us a 2-digit number that is close. */
20305 if (toppos
<= BUF_BEGV (b
))
20306 sprintf (decode_mode_spec_buf
, "Top%2"pI
"d%%", total
);
20308 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
20309 return decode_mode_spec_buf
;
20314 /* status of process */
20315 obj
= Fget_buffer_process (Fcurrent_buffer ());
20317 return "no process";
20319 obj
= Fsymbol_name (Fprocess_status (obj
));
20325 int count
= inhibit_garbage_collection ();
20326 Lisp_Object val
= call1 (intern ("file-remote-p"),
20327 BVAR (current_buffer
, directory
));
20328 unbind_to (count
, Qnil
);
20336 case 't': /* indicate TEXT or BINARY */
20340 /* coding-system (not including end-of-line format) */
20342 /* coding-system (including end-of-line type) */
20344 int eol_flag
= (c
== 'Z');
20345 char *p
= decode_mode_spec_buf
;
20347 if (! FRAME_WINDOW_P (f
))
20349 /* No need to mention EOL here--the terminal never needs
20350 to do EOL conversion. */
20351 p
= decode_mode_spec_coding (CODING_ID_NAME
20352 (FRAME_KEYBOARD_CODING (f
)->id
),
20354 p
= decode_mode_spec_coding (CODING_ID_NAME
20355 (FRAME_TERMINAL_CODING (f
)->id
),
20358 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
20361 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
20362 #ifdef subprocesses
20363 obj
= Fget_buffer_process (Fcurrent_buffer ());
20364 if (PROCESSP (obj
))
20366 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
20368 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
20371 #endif /* subprocesses */
20374 return decode_mode_spec_buf
;
20381 return SSDATA (obj
);
20388 /* Count up to COUNT lines starting from START_BYTE.
20389 But don't go beyond LIMIT_BYTE.
20390 Return the number of lines thus found (always nonnegative).
20392 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
20395 display_count_lines (EMACS_INT start_byte
,
20396 EMACS_INT limit_byte
, EMACS_INT count
,
20397 EMACS_INT
*byte_pos_ptr
)
20399 register unsigned char *cursor
;
20400 unsigned char *base
;
20402 register EMACS_INT ceiling
;
20403 register unsigned char *ceiling_addr
;
20404 EMACS_INT orig_count
= count
;
20406 /* If we are not in selective display mode,
20407 check only for newlines. */
20408 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
20409 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
20413 while (start_byte
< limit_byte
)
20415 ceiling
= BUFFER_CEILING_OF (start_byte
);
20416 ceiling
= min (limit_byte
- 1, ceiling
);
20417 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
20418 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
20421 if (selective_display
)
20422 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
20425 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
20428 if (cursor
!= ceiling_addr
)
20432 start_byte
+= cursor
- base
+ 1;
20433 *byte_pos_ptr
= start_byte
;
20437 if (++cursor
== ceiling_addr
)
20443 start_byte
+= cursor
- base
;
20448 while (start_byte
> limit_byte
)
20450 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
20451 ceiling
= max (limit_byte
, ceiling
);
20452 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
20453 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
20456 if (selective_display
)
20457 while (--cursor
!= ceiling_addr
20458 && *cursor
!= '\n' && *cursor
!= 015)
20461 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
20464 if (cursor
!= ceiling_addr
)
20468 start_byte
+= cursor
- base
+ 1;
20469 *byte_pos_ptr
= start_byte
;
20470 /* When scanning backwards, we should
20471 not count the newline posterior to which we stop. */
20472 return - orig_count
- 1;
20478 /* Here we add 1 to compensate for the last decrement
20479 of CURSOR, which took it past the valid range. */
20480 start_byte
+= cursor
- base
+ 1;
20484 *byte_pos_ptr
= limit_byte
;
20487 return - orig_count
+ count
;
20488 return orig_count
- count
;
20494 /***********************************************************************
20496 ***********************************************************************/
20498 /* Display a NUL-terminated string, starting with index START.
20500 If STRING is non-null, display that C string. Otherwise, the Lisp
20501 string LISP_STRING is displayed. There's a case that STRING is
20502 non-null and LISP_STRING is not nil. It means STRING is a string
20503 data of LISP_STRING. In that case, we display LISP_STRING while
20504 ignoring its text properties.
20506 If FACE_STRING is not nil, FACE_STRING_POS is a position in
20507 FACE_STRING. Display STRING or LISP_STRING with the face at
20508 FACE_STRING_POS in FACE_STRING:
20510 Display the string in the environment given by IT, but use the
20511 standard display table, temporarily.
20513 FIELD_WIDTH is the minimum number of output glyphs to produce.
20514 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20515 with spaces. If STRING has more characters, more than FIELD_WIDTH
20516 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
20518 PRECISION is the maximum number of characters to output from
20519 STRING. PRECISION < 0 means don't truncate the string.
20521 This is roughly equivalent to printf format specifiers:
20523 FIELD_WIDTH PRECISION PRINTF
20524 ----------------------------------------
20530 MULTIBYTE zero means do not display multibyte chars, > 0 means do
20531 display them, and < 0 means obey the current buffer's value of
20532 enable_multibyte_characters.
20534 Value is the number of columns displayed. */
20537 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
20538 EMACS_INT face_string_pos
, EMACS_INT start
, struct it
*it
,
20539 int field_width
, int precision
, int max_x
, int multibyte
)
20541 int hpos_at_start
= it
->hpos
;
20542 int saved_face_id
= it
->face_id
;
20543 struct glyph_row
*row
= it
->glyph_row
;
20544 EMACS_INT it_charpos
;
20546 /* Initialize the iterator IT for iteration over STRING beginning
20547 with index START. */
20548 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
20549 precision
, field_width
, multibyte
);
20550 if (string
&& STRINGP (lisp_string
))
20551 /* LISP_STRING is the one returned by decode_mode_spec. We should
20552 ignore its text properties. */
20553 it
->stop_charpos
= it
->end_charpos
;
20555 /* If displaying STRING, set up the face of the iterator from
20556 FACE_STRING, if that's given. */
20557 if (STRINGP (face_string
))
20563 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
20564 0, it
->region_beg_charpos
,
20565 it
->region_end_charpos
,
20566 &endptr
, it
->base_face_id
, 0);
20567 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20568 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
20571 /* Set max_x to the maximum allowed X position. Don't let it go
20572 beyond the right edge of the window. */
20574 max_x
= it
->last_visible_x
;
20576 max_x
= min (max_x
, it
->last_visible_x
);
20578 /* Skip over display elements that are not visible. because IT->w is
20580 if (it
->current_x
< it
->first_visible_x
)
20581 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
20582 MOVE_TO_POS
| MOVE_TO_X
);
20584 row
->ascent
= it
->max_ascent
;
20585 row
->height
= it
->max_ascent
+ it
->max_descent
;
20586 row
->phys_ascent
= it
->max_phys_ascent
;
20587 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20588 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20590 if (STRINGP (it
->string
))
20591 it_charpos
= IT_STRING_CHARPOS (*it
);
20593 it_charpos
= IT_CHARPOS (*it
);
20595 /* This condition is for the case that we are called with current_x
20596 past last_visible_x. */
20597 while (it
->current_x
< max_x
)
20599 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
20601 /* Get the next display element. */
20602 if (!get_next_display_element (it
))
20605 /* Produce glyphs. */
20606 x_before
= it
->current_x
;
20607 n_glyphs_before
= row
->used
[TEXT_AREA
];
20608 PRODUCE_GLYPHS (it
);
20610 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
20613 while (i
< nglyphs
)
20615 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20617 if (it
->line_wrap
!= TRUNCATE
20618 && x
+ glyph
->pixel_width
> max_x
)
20620 /* End of continued line or max_x reached. */
20621 if (CHAR_GLYPH_PADDING_P (*glyph
))
20623 /* A wide character is unbreakable. */
20624 if (row
->reversed_p
)
20625 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20626 - n_glyphs_before
);
20627 row
->used
[TEXT_AREA
] = n_glyphs_before
;
20628 it
->current_x
= x_before
;
20632 if (row
->reversed_p
)
20633 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20634 - (n_glyphs_before
+ i
));
20635 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20640 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
20642 /* Glyph is at least partially visible. */
20644 if (x
< it
->first_visible_x
)
20645 row
->x
= x
- it
->first_visible_x
;
20649 /* Glyph is off the left margin of the display area.
20650 Should not happen. */
20654 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20655 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20656 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20657 row
->phys_height
= max (row
->phys_height
,
20658 it
->max_phys_ascent
+ it
->max_phys_descent
);
20659 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20660 it
->max_extra_line_spacing
);
20661 x
+= glyph
->pixel_width
;
20665 /* Stop if max_x reached. */
20669 /* Stop at line ends. */
20670 if (ITERATOR_AT_END_OF_LINE_P (it
))
20672 it
->continuation_lines_width
= 0;
20676 set_iterator_to_next (it
, 1);
20677 if (STRINGP (it
->string
))
20678 it_charpos
= IT_STRING_CHARPOS (*it
);
20680 it_charpos
= IT_CHARPOS (*it
);
20682 /* Stop if truncating at the right edge. */
20683 if (it
->line_wrap
== TRUNCATE
20684 && it
->current_x
>= it
->last_visible_x
)
20686 /* Add truncation mark, but don't do it if the line is
20687 truncated at a padding space. */
20688 if (it_charpos
< it
->string_nchars
)
20690 if (!FRAME_WINDOW_P (it
->f
))
20694 if (it
->current_x
> it
->last_visible_x
)
20696 if (!row
->reversed_p
)
20698 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
20699 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20704 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
20705 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20707 unproduce_glyphs (it
, ii
+ 1);
20708 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
20710 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
20712 row
->used
[TEXT_AREA
] = ii
;
20713 produce_special_glyphs (it
, IT_TRUNCATION
);
20716 produce_special_glyphs (it
, IT_TRUNCATION
);
20718 row
->truncated_on_right_p
= 1;
20724 /* Maybe insert a truncation at the left. */
20725 if (it
->first_visible_x
20728 if (!FRAME_WINDOW_P (it
->f
))
20729 insert_left_trunc_glyphs (it
);
20730 row
->truncated_on_left_p
= 1;
20733 it
->face_id
= saved_face_id
;
20735 /* Value is number of columns displayed. */
20736 return it
->hpos
- hpos_at_start
;
20741 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
20742 appears as an element of LIST or as the car of an element of LIST.
20743 If PROPVAL is a list, compare each element against LIST in that
20744 way, and return 1/2 if any element of PROPVAL is found in LIST.
20745 Otherwise return 0. This function cannot quit.
20746 The return value is 2 if the text is invisible but with an ellipsis
20747 and 1 if it's invisible and without an ellipsis. */
20750 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
20752 register Lisp_Object tail
, proptail
;
20754 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20756 register Lisp_Object tem
;
20758 if (EQ (propval
, tem
))
20760 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
20761 return NILP (XCDR (tem
)) ? 1 : 2;
20764 if (CONSP (propval
))
20766 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
20768 Lisp_Object propelt
;
20769 propelt
= XCAR (proptail
);
20770 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20772 register Lisp_Object tem
;
20774 if (EQ (propelt
, tem
))
20776 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
20777 return NILP (XCDR (tem
)) ? 1 : 2;
20785 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
20786 doc
: /* Non-nil if the property makes the text invisible.
20787 POS-OR-PROP can be a marker or number, in which case it is taken to be
20788 a position in the current buffer and the value of the `invisible' property
20789 is checked; or it can be some other value, which is then presumed to be the
20790 value of the `invisible' property of the text of interest.
20791 The non-nil value returned can be t for truly invisible text or something
20792 else if the text is replaced by an ellipsis. */)
20793 (Lisp_Object pos_or_prop
)
20796 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
20797 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
20799 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
20800 return (invis
== 0 ? Qnil
20802 : make_number (invis
));
20805 /* Calculate a width or height in pixels from a specification using
20806 the following elements:
20809 NUM - a (fractional) multiple of the default font width/height
20810 (NUM) - specifies exactly NUM pixels
20811 UNIT - a fixed number of pixels, see below.
20812 ELEMENT - size of a display element in pixels, see below.
20813 (NUM . SPEC) - equals NUM * SPEC
20814 (+ SPEC SPEC ...) - add pixel values
20815 (- SPEC SPEC ...) - subtract pixel values
20816 (- SPEC) - negate pixel value
20819 INT or FLOAT - a number constant
20820 SYMBOL - use symbol's (buffer local) variable binding.
20823 in - pixels per inch *)
20824 mm - pixels per 1/1000 meter *)
20825 cm - pixels per 1/100 meter *)
20826 width - width of current font in pixels.
20827 height - height of current font in pixels.
20829 *) using the ratio(s) defined in display-pixels-per-inch.
20833 left-fringe - left fringe width in pixels
20834 right-fringe - right fringe width in pixels
20836 left-margin - left margin width in pixels
20837 right-margin - right margin width in pixels
20839 scroll-bar - scroll-bar area width in pixels
20843 Pixels corresponding to 5 inches:
20846 Total width of non-text areas on left side of window (if scroll-bar is on left):
20847 '(space :width (+ left-fringe left-margin scroll-bar))
20849 Align to first text column (in header line):
20850 '(space :align-to 0)
20852 Align to middle of text area minus half the width of variable `my-image'
20853 containing a loaded image:
20854 '(space :align-to (0.5 . (- text my-image)))
20856 Width of left margin minus width of 1 character in the default font:
20857 '(space :width (- left-margin 1))
20859 Width of left margin minus width of 2 characters in the current font:
20860 '(space :width (- left-margin (2 . width)))
20862 Center 1 character over left-margin (in header line):
20863 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
20865 Different ways to express width of left fringe plus left margin minus one pixel:
20866 '(space :width (- (+ left-fringe left-margin) (1)))
20867 '(space :width (+ left-fringe left-margin (- (1))))
20868 '(space :width (+ left-fringe left-margin (-1)))
20872 #define NUMVAL(X) \
20873 ((INTEGERP (X) || FLOATP (X)) \
20878 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
20879 struct font
*font
, int width_p
, int *align_to
)
20883 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20884 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20887 return OK_PIXELS (0);
20889 xassert (FRAME_LIVE_P (it
->f
));
20891 if (SYMBOLP (prop
))
20893 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20895 char *unit
= SSDATA (SYMBOL_NAME (prop
));
20897 if (unit
[0] == 'i' && unit
[1] == 'n')
20899 else if (unit
[0] == 'm' && unit
[1] == 'm')
20901 else if (unit
[0] == 'c' && unit
[1] == 'm')
20908 #ifdef HAVE_WINDOW_SYSTEM
20909 if (FRAME_WINDOW_P (it
->f
)
20911 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20912 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20914 return OK_PIXELS (ppi
/ pixels
);
20917 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20918 || (CONSP (Vdisplay_pixels_per_inch
)
20920 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20921 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20923 return OK_PIXELS (ppi
/ pixels
);
20929 #ifdef HAVE_WINDOW_SYSTEM
20930 if (EQ (prop
, Qheight
))
20931 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20932 if (EQ (prop
, Qwidth
))
20933 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20935 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20936 return OK_PIXELS (1);
20939 if (EQ (prop
, Qtext
))
20940 return OK_PIXELS (width_p
20941 ? window_box_width (it
->w
, TEXT_AREA
)
20942 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20944 if (align_to
&& *align_to
< 0)
20947 if (EQ (prop
, Qleft
))
20948 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20949 if (EQ (prop
, Qright
))
20950 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20951 if (EQ (prop
, Qcenter
))
20952 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20953 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20954 if (EQ (prop
, Qleft_fringe
))
20955 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20956 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20957 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20958 if (EQ (prop
, Qright_fringe
))
20959 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20960 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20961 : window_box_right_offset (it
->w
, TEXT_AREA
));
20962 if (EQ (prop
, Qleft_margin
))
20963 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20964 if (EQ (prop
, Qright_margin
))
20965 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20966 if (EQ (prop
, Qscroll_bar
))
20967 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20969 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20970 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20971 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20976 if (EQ (prop
, Qleft_fringe
))
20977 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20978 if (EQ (prop
, Qright_fringe
))
20979 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20980 if (EQ (prop
, Qleft_margin
))
20981 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20982 if (EQ (prop
, Qright_margin
))
20983 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20984 if (EQ (prop
, Qscroll_bar
))
20985 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20988 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20991 if (INTEGERP (prop
) || FLOATP (prop
))
20993 int base_unit
= (width_p
20994 ? FRAME_COLUMN_WIDTH (it
->f
)
20995 : FRAME_LINE_HEIGHT (it
->f
));
20996 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
21001 Lisp_Object car
= XCAR (prop
);
21002 Lisp_Object cdr
= XCDR (prop
);
21006 #ifdef HAVE_WINDOW_SYSTEM
21007 if (FRAME_WINDOW_P (it
->f
)
21008 && valid_image_p (prop
))
21010 int id
= lookup_image (it
->f
, prop
);
21011 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
21013 return OK_PIXELS (width_p
? img
->width
: img
->height
);
21016 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
21022 while (CONSP (cdr
))
21024 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
21025 font
, width_p
, align_to
))
21028 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
21033 if (EQ (car
, Qminus
))
21035 return OK_PIXELS (pixels
);
21038 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
21041 if (INTEGERP (car
) || FLOATP (car
))
21044 pixels
= XFLOATINT (car
);
21046 return OK_PIXELS (pixels
);
21047 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
21048 font
, width_p
, align_to
))
21049 return OK_PIXELS (pixels
* fact
);
21060 /***********************************************************************
21062 ***********************************************************************/
21064 #ifdef HAVE_WINDOW_SYSTEM
21069 dump_glyph_string (s
)
21070 struct glyph_string
*s
;
21072 fprintf (stderr
, "glyph string\n");
21073 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
21074 s
->x
, s
->y
, s
->width
, s
->height
);
21075 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
21076 fprintf (stderr
, " hl = %d\n", s
->hl
);
21077 fprintf (stderr
, " left overhang = %d, right = %d\n",
21078 s
->left_overhang
, s
->right_overhang
);
21079 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
21080 fprintf (stderr
, " extends to end of line = %d\n",
21081 s
->extends_to_end_of_line_p
);
21082 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
21083 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
21086 #endif /* GLYPH_DEBUG */
21088 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
21089 of XChar2b structures for S; it can't be allocated in
21090 init_glyph_string because it must be allocated via `alloca'. W
21091 is the window on which S is drawn. ROW and AREA are the glyph row
21092 and area within the row from which S is constructed. START is the
21093 index of the first glyph structure covered by S. HL is a
21094 face-override for drawing S. */
21097 #define OPTIONAL_HDC(hdc) HDC hdc,
21098 #define DECLARE_HDC(hdc) HDC hdc;
21099 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
21100 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
21103 #ifndef OPTIONAL_HDC
21104 #define OPTIONAL_HDC(hdc)
21105 #define DECLARE_HDC(hdc)
21106 #define ALLOCATE_HDC(hdc, f)
21107 #define RELEASE_HDC(hdc, f)
21111 init_glyph_string (struct glyph_string
*s
,
21113 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
21114 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
21116 memset (s
, 0, sizeof *s
);
21118 s
->f
= XFRAME (w
->frame
);
21122 s
->display
= FRAME_X_DISPLAY (s
->f
);
21123 s
->window
= FRAME_X_WINDOW (s
->f
);
21124 s
->char2b
= char2b
;
21128 s
->first_glyph
= row
->glyphs
[area
] + start
;
21129 s
->height
= row
->height
;
21130 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
21131 s
->ybase
= s
->y
+ row
->ascent
;
21135 /* Append the list of glyph strings with head H and tail T to the list
21136 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
21139 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
21140 struct glyph_string
*h
, struct glyph_string
*t
)
21154 /* Prepend the list of glyph strings with head H and tail T to the
21155 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
21159 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
21160 struct glyph_string
*h
, struct glyph_string
*t
)
21174 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
21175 Set *HEAD and *TAIL to the resulting list. */
21178 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
21179 struct glyph_string
*s
)
21181 s
->next
= s
->prev
= NULL
;
21182 append_glyph_string_lists (head
, tail
, s
, s
);
21186 /* Get face and two-byte form of character C in face FACE_ID on frame F.
21187 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
21188 make sure that X resources for the face returned are allocated.
21189 Value is a pointer to a realized face that is ready for display if
21190 DISPLAY_P is non-zero. */
21192 static INLINE
struct face
*
21193 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
21194 XChar2b
*char2b
, int display_p
)
21196 struct face
*face
= FACE_FROM_ID (f
, face_id
);
21200 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
21202 if (code
!= FONT_INVALID_CODE
)
21203 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21205 STORE_XCHAR2B (char2b
, 0, 0);
21208 /* Make sure X resources of the face are allocated. */
21209 #ifdef HAVE_X_WINDOWS
21213 xassert (face
!= NULL
);
21214 PREPARE_FACE_FOR_DISPLAY (f
, face
);
21221 /* Get face and two-byte form of character glyph GLYPH on frame F.
21222 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
21223 a pointer to a realized face that is ready for display. */
21225 static INLINE
struct face
*
21226 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
21227 XChar2b
*char2b
, int *two_byte_p
)
21231 xassert (glyph
->type
== CHAR_GLYPH
);
21232 face
= FACE_FROM_ID (f
, glyph
->face_id
);
21241 if (CHAR_BYTE8_P (glyph
->u
.ch
))
21242 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
21244 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
21246 if (code
!= FONT_INVALID_CODE
)
21247 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21249 STORE_XCHAR2B (char2b
, 0, 0);
21252 /* Make sure X resources of the face are allocated. */
21253 xassert (face
!= NULL
);
21254 PREPARE_FACE_FOR_DISPLAY (f
, face
);
21259 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
21260 Retunr 1 if FONT has a glyph for C, otherwise return 0. */
21263 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
21267 if (CHAR_BYTE8_P (c
))
21268 code
= CHAR_TO_BYTE8 (c
);
21270 code
= font
->driver
->encode_char (font
, c
);
21272 if (code
== FONT_INVALID_CODE
)
21274 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
21279 /* Fill glyph string S with composition components specified by S->cmp.
21281 BASE_FACE is the base face of the composition.
21282 S->cmp_from is the index of the first component for S.
21284 OVERLAPS non-zero means S should draw the foreground only, and use
21285 its physical height for clipping. See also draw_glyphs.
21287 Value is the index of a component not in S. */
21290 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
21294 /* For all glyphs of this composition, starting at the offset
21295 S->cmp_from, until we reach the end of the definition or encounter a
21296 glyph that requires the different face, add it to S. */
21301 s
->for_overlaps
= overlaps
;
21304 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
21306 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
21310 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
21313 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
21320 s
->font
= s
->face
->font
;
21322 else if (s
->face
!= face
)
21330 /* All glyph strings for the same composition has the same width,
21331 i.e. the width set for the first component of the composition. */
21332 s
->width
= s
->first_glyph
->pixel_width
;
21334 /* If the specified font could not be loaded, use the frame's
21335 default font, but record the fact that we couldn't load it in
21336 the glyph string so that we can draw rectangles for the
21337 characters of the glyph string. */
21338 if (s
->font
== NULL
)
21340 s
->font_not_found_p
= 1;
21341 s
->font
= FRAME_FONT (s
->f
);
21344 /* Adjust base line for subscript/superscript text. */
21345 s
->ybase
+= s
->first_glyph
->voffset
;
21347 /* This glyph string must always be drawn with 16-bit functions. */
21354 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
21355 int start
, int end
, int overlaps
)
21357 struct glyph
*glyph
, *last
;
21358 Lisp_Object lgstring
;
21361 s
->for_overlaps
= overlaps
;
21362 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21363 last
= s
->row
->glyphs
[s
->area
] + end
;
21364 s
->cmp_id
= glyph
->u
.cmp
.id
;
21365 s
->cmp_from
= glyph
->slice
.cmp
.from
;
21366 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
21367 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21368 lgstring
= composition_gstring_from_id (s
->cmp_id
);
21369 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
21371 while (glyph
< last
21372 && glyph
->u
.cmp
.automatic
21373 && glyph
->u
.cmp
.id
== s
->cmp_id
21374 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
21375 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
21377 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
21379 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
21380 unsigned code
= LGLYPH_CODE (lglyph
);
21382 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
21384 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
21385 return glyph
- s
->row
->glyphs
[s
->area
];
21389 /* Fill glyph string S from a sequence glyphs for glyphless characters.
21390 See the comment of fill_glyph_string for arguments.
21391 Value is the index of the first glyph not in S. */
21395 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
21396 int start
, int end
, int overlaps
)
21398 struct glyph
*glyph
, *last
;
21401 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
21402 s
->for_overlaps
= overlaps
;
21403 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21404 last
= s
->row
->glyphs
[s
->area
] + end
;
21405 voffset
= glyph
->voffset
;
21406 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21407 s
->font
= s
->face
->font
;
21409 s
->width
= glyph
->pixel_width
;
21411 while (glyph
< last
21412 && glyph
->type
== GLYPHLESS_GLYPH
21413 && glyph
->voffset
== voffset
21414 && glyph
->face_id
== face_id
)
21417 s
->width
+= glyph
->pixel_width
;
21420 s
->ybase
+= voffset
;
21421 return glyph
- s
->row
->glyphs
[s
->area
];
21425 /* Fill glyph string S from a sequence of character glyphs.
21427 FACE_ID is the face id of the string. START is the index of the
21428 first glyph to consider, END is the index of the last + 1.
21429 OVERLAPS non-zero means S should draw the foreground only, and use
21430 its physical height for clipping. See also draw_glyphs.
21432 Value is the index of the first glyph not in S. */
21435 fill_glyph_string (struct glyph_string
*s
, int face_id
,
21436 int start
, int end
, int overlaps
)
21438 struct glyph
*glyph
, *last
;
21440 int glyph_not_available_p
;
21442 xassert (s
->f
== XFRAME (s
->w
->frame
));
21443 xassert (s
->nchars
== 0);
21444 xassert (start
>= 0 && end
> start
);
21446 s
->for_overlaps
= overlaps
;
21447 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21448 last
= s
->row
->glyphs
[s
->area
] + end
;
21449 voffset
= glyph
->voffset
;
21450 s
->padding_p
= glyph
->padding_p
;
21451 glyph_not_available_p
= glyph
->glyph_not_available_p
;
21453 while (glyph
< last
21454 && glyph
->type
== CHAR_GLYPH
21455 && glyph
->voffset
== voffset
21456 /* Same face id implies same font, nowadays. */
21457 && glyph
->face_id
== face_id
21458 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
21462 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
21463 s
->char2b
+ s
->nchars
,
21465 s
->two_byte_p
= two_byte_p
;
21467 xassert (s
->nchars
<= end
- start
);
21468 s
->width
+= glyph
->pixel_width
;
21469 if (glyph
++->padding_p
!= s
->padding_p
)
21473 s
->font
= s
->face
->font
;
21475 /* If the specified font could not be loaded, use the frame's font,
21476 but record the fact that we couldn't load it in
21477 S->font_not_found_p so that we can draw rectangles for the
21478 characters of the glyph string. */
21479 if (s
->font
== NULL
|| glyph_not_available_p
)
21481 s
->font_not_found_p
= 1;
21482 s
->font
= FRAME_FONT (s
->f
);
21485 /* Adjust base line for subscript/superscript text. */
21486 s
->ybase
+= voffset
;
21488 xassert (s
->face
&& s
->face
->gc
);
21489 return glyph
- s
->row
->glyphs
[s
->area
];
21493 /* Fill glyph string S from image glyph S->first_glyph. */
21496 fill_image_glyph_string (struct glyph_string
*s
)
21498 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
21499 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
21501 s
->slice
= s
->first_glyph
->slice
.img
;
21502 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
21503 s
->font
= s
->face
->font
;
21504 s
->width
= s
->first_glyph
->pixel_width
;
21506 /* Adjust base line for subscript/superscript text. */
21507 s
->ybase
+= s
->first_glyph
->voffset
;
21511 /* Fill glyph string S from a sequence of stretch glyphs.
21513 START is the index of the first glyph to consider,
21514 END is the index of the last + 1.
21516 Value is the index of the first glyph not in S. */
21519 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
21521 struct glyph
*glyph
, *last
;
21522 int voffset
, face_id
;
21524 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
21526 glyph
= s
->row
->glyphs
[s
->area
] + start
;
21527 last
= s
->row
->glyphs
[s
->area
] + end
;
21528 face_id
= glyph
->face_id
;
21529 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21530 s
->font
= s
->face
->font
;
21531 s
->width
= glyph
->pixel_width
;
21533 voffset
= glyph
->voffset
;
21537 && glyph
->type
== STRETCH_GLYPH
21538 && glyph
->voffset
== voffset
21539 && glyph
->face_id
== face_id
);
21541 s
->width
+= glyph
->pixel_width
;
21543 /* Adjust base line for subscript/superscript text. */
21544 s
->ybase
+= voffset
;
21546 /* The case that face->gc == 0 is handled when drawing the glyph
21547 string by calling PREPARE_FACE_FOR_DISPLAY. */
21549 return glyph
- s
->row
->glyphs
[s
->area
];
21552 static struct font_metrics
*
21553 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
21555 static struct font_metrics metrics
;
21556 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
21558 if (! font
|| code
== FONT_INVALID_CODE
)
21560 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
21565 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
21566 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
21567 assumed to be zero. */
21570 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
21572 *left
= *right
= 0;
21574 if (glyph
->type
== CHAR_GLYPH
)
21578 struct font_metrics
*pcm
;
21580 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
21581 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
21583 if (pcm
->rbearing
> pcm
->width
)
21584 *right
= pcm
->rbearing
- pcm
->width
;
21585 if (pcm
->lbearing
< 0)
21586 *left
= -pcm
->lbearing
;
21589 else if (glyph
->type
== COMPOSITE_GLYPH
)
21591 if (! glyph
->u
.cmp
.automatic
)
21593 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
21595 if (cmp
->rbearing
> cmp
->pixel_width
)
21596 *right
= cmp
->rbearing
- cmp
->pixel_width
;
21597 if (cmp
->lbearing
< 0)
21598 *left
= - cmp
->lbearing
;
21602 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
21603 struct font_metrics metrics
;
21605 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
21606 glyph
->slice
.cmp
.to
+ 1, &metrics
);
21607 if (metrics
.rbearing
> metrics
.width
)
21608 *right
= metrics
.rbearing
- metrics
.width
;
21609 if (metrics
.lbearing
< 0)
21610 *left
= - metrics
.lbearing
;
21616 /* Return the index of the first glyph preceding glyph string S that
21617 is overwritten by S because of S's left overhang. Value is -1
21618 if no glyphs are overwritten. */
21621 left_overwritten (struct glyph_string
*s
)
21625 if (s
->left_overhang
)
21628 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21629 int first
= s
->first_glyph
- glyphs
;
21631 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
21632 x
-= glyphs
[i
].pixel_width
;
21643 /* Return the index of the first glyph preceding glyph string S that
21644 is overwriting S because of its right overhang. Value is -1 if no
21645 glyph in front of S overwrites S. */
21648 left_overwriting (struct glyph_string
*s
)
21651 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21652 int first
= s
->first_glyph
- glyphs
;
21656 for (i
= first
- 1; i
>= 0; --i
)
21659 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21662 x
-= glyphs
[i
].pixel_width
;
21669 /* Return the index of the last glyph following glyph string S that is
21670 overwritten by S because of S's right overhang. Value is -1 if
21671 no such glyph is found. */
21674 right_overwritten (struct glyph_string
*s
)
21678 if (s
->right_overhang
)
21681 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21682 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21683 int end
= s
->row
->used
[s
->area
];
21685 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
21686 x
+= glyphs
[i
].pixel_width
;
21695 /* Return the index of the last glyph following glyph string S that
21696 overwrites S because of its left overhang. Value is negative
21697 if no such glyph is found. */
21700 right_overwriting (struct glyph_string
*s
)
21703 int end
= s
->row
->used
[s
->area
];
21704 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21705 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21709 for (i
= first
; i
< end
; ++i
)
21712 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21715 x
+= glyphs
[i
].pixel_width
;
21722 /* Set background width of glyph string S. START is the index of the
21723 first glyph following S. LAST_X is the right-most x-position + 1
21724 in the drawing area. */
21727 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
21729 /* If the face of this glyph string has to be drawn to the end of
21730 the drawing area, set S->extends_to_end_of_line_p. */
21732 if (start
== s
->row
->used
[s
->area
]
21733 && s
->area
== TEXT_AREA
21734 && ((s
->row
->fill_line_p
21735 && (s
->hl
== DRAW_NORMAL_TEXT
21736 || s
->hl
== DRAW_IMAGE_RAISED
21737 || s
->hl
== DRAW_IMAGE_SUNKEN
))
21738 || s
->hl
== DRAW_MOUSE_FACE
))
21739 s
->extends_to_end_of_line_p
= 1;
21741 /* If S extends its face to the end of the line, set its
21742 background_width to the distance to the right edge of the drawing
21744 if (s
->extends_to_end_of_line_p
)
21745 s
->background_width
= last_x
- s
->x
+ 1;
21747 s
->background_width
= s
->width
;
21751 /* Compute overhangs and x-positions for glyph string S and its
21752 predecessors, or successors. X is the starting x-position for S.
21753 BACKWARD_P non-zero means process predecessors. */
21756 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
21762 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21763 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21773 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21774 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21784 /* The following macros are only called from draw_glyphs below.
21785 They reference the following parameters of that function directly:
21786 `w', `row', `area', and `overlap_p'
21787 as well as the following local variables:
21788 `s', `f', and `hdc' (in W32) */
21791 /* On W32, silently add local `hdc' variable to argument list of
21792 init_glyph_string. */
21793 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21794 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
21796 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21797 init_glyph_string (s, char2b, w, row, area, start, hl)
21800 /* Add a glyph string for a stretch glyph to the list of strings
21801 between HEAD and TAIL. START is the index of the stretch glyph in
21802 row area AREA of glyph row ROW. END is the index of the last glyph
21803 in that glyph row area. X is the current output position assigned
21804 to the new glyph string constructed. HL overrides that face of the
21805 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21806 is the right-most x-position of the drawing area. */
21808 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
21809 and below -- keep them on one line. */
21810 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21813 s = (struct glyph_string *) alloca (sizeof *s); \
21814 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21815 START = fill_stretch_glyph_string (s, START, END); \
21816 append_glyph_string (&HEAD, &TAIL, s); \
21822 /* Add a glyph string for an image glyph to the list of strings
21823 between HEAD and TAIL. START is the index of the image glyph in
21824 row area AREA of glyph row ROW. END is the index of the last glyph
21825 in that glyph row area. X is the current output position assigned
21826 to the new glyph string constructed. HL overrides that face of the
21827 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21828 is the right-most x-position of the drawing area. */
21830 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21833 s = (struct glyph_string *) alloca (sizeof *s); \
21834 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21835 fill_image_glyph_string (s); \
21836 append_glyph_string (&HEAD, &TAIL, s); \
21843 /* Add a glyph string for a sequence of character glyphs to the list
21844 of strings between HEAD and TAIL. START is the index of the first
21845 glyph in row area AREA of glyph row ROW that is part of the new
21846 glyph string. END is the index of the last glyph in that glyph row
21847 area. X is the current output position assigned to the new glyph
21848 string constructed. HL overrides that face of the glyph; e.g. it
21849 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
21850 right-most x-position of the drawing area. */
21852 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21858 face_id = (row)->glyphs[area][START].face_id; \
21860 s = (struct glyph_string *) alloca (sizeof *s); \
21861 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
21862 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21863 append_glyph_string (&HEAD, &TAIL, s); \
21865 START = fill_glyph_string (s, face_id, START, END, overlaps); \
21870 /* Add a glyph string for a composite sequence to the list of strings
21871 between HEAD and TAIL. START is the index of the first glyph in
21872 row area AREA of glyph row ROW that is part of the new glyph
21873 string. END is the index of the last glyph in that glyph row area.
21874 X is the current output position assigned to the new glyph string
21875 constructed. HL overrides that face of the glyph; e.g. it is
21876 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
21877 x-position of the drawing area. */
21879 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21881 int face_id = (row)->glyphs[area][START].face_id; \
21882 struct face *base_face = FACE_FROM_ID (f, face_id); \
21883 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
21884 struct composition *cmp = composition_table[cmp_id]; \
21886 struct glyph_string *first_s IF_LINT (= NULL); \
21889 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21891 /* Make glyph_strings for each glyph sequence that is drawable by \
21892 the same face, and append them to HEAD/TAIL. */ \
21893 for (n = 0; n < cmp->glyph_len;) \
21895 s = (struct glyph_string *) alloca (sizeof *s); \
21896 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21897 append_glyph_string (&(HEAD), &(TAIL), s); \
21903 n = fill_composite_glyph_string (s, base_face, overlaps); \
21911 /* Add a glyph string for a glyph-string sequence to the list of strings
21912 between HEAD and TAIL. */
21914 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21918 Lisp_Object gstring; \
21920 face_id = (row)->glyphs[area][START].face_id; \
21921 gstring = (composition_gstring_from_id \
21922 ((row)->glyphs[area][START].u.cmp.id)); \
21923 s = (struct glyph_string *) alloca (sizeof *s); \
21924 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21925 * LGSTRING_GLYPH_LEN (gstring)); \
21926 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21927 append_glyph_string (&(HEAD), &(TAIL), s); \
21929 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21933 /* Add a glyph string for a sequence of glyphless character's glyphs
21934 to the list of strings between HEAD and TAIL. The meanings of
21935 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
21937 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21942 face_id = (row)->glyphs[area][START].face_id; \
21944 s = (struct glyph_string *) alloca (sizeof *s); \
21945 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21946 append_glyph_string (&HEAD, &TAIL, s); \
21948 START = fill_glyphless_glyph_string (s, face_id, START, END, \
21954 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21955 of AREA of glyph row ROW on window W between indices START and END.
21956 HL overrides the face for drawing glyph strings, e.g. it is
21957 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21958 x-positions of the drawing area.
21960 This is an ugly monster macro construct because we must use alloca
21961 to allocate glyph strings (because draw_glyphs can be called
21962 asynchronously). */
21964 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21967 HEAD = TAIL = NULL; \
21968 while (START < END) \
21970 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21971 switch (first_glyph->type) \
21974 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21978 case COMPOSITE_GLYPH: \
21979 if (first_glyph->u.cmp.automatic) \
21980 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21983 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21987 case STRETCH_GLYPH: \
21988 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21992 case IMAGE_GLYPH: \
21993 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21997 case GLYPHLESS_GLYPH: \
21998 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
22008 set_glyph_string_background_width (s, START, LAST_X); \
22015 /* Draw glyphs between START and END in AREA of ROW on window W,
22016 starting at x-position X. X is relative to AREA in W. HL is a
22017 face-override with the following meaning:
22019 DRAW_NORMAL_TEXT draw normally
22020 DRAW_CURSOR draw in cursor face
22021 DRAW_MOUSE_FACE draw in mouse face.
22022 DRAW_INVERSE_VIDEO draw in mode line face
22023 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
22024 DRAW_IMAGE_RAISED draw an image with a raised relief around it
22026 If OVERLAPS is non-zero, draw only the foreground of characters and
22027 clip to the physical height of ROW. Non-zero value also defines
22028 the overlapping part to be drawn:
22030 OVERLAPS_PRED overlap with preceding rows
22031 OVERLAPS_SUCC overlap with succeeding rows
22032 OVERLAPS_BOTH overlap with both preceding/succeeding rows
22033 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
22035 Value is the x-position reached, relative to AREA of W. */
22038 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
22039 enum glyph_row_area area
, EMACS_INT start
, EMACS_INT end
,
22040 enum draw_glyphs_face hl
, int overlaps
)
22042 struct glyph_string
*head
, *tail
;
22043 struct glyph_string
*s
;
22044 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
22045 int i
, j
, x_reached
, last_x
, area_left
= 0;
22046 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22049 ALLOCATE_HDC (hdc
, f
);
22051 /* Let's rather be paranoid than getting a SEGV. */
22052 end
= min (end
, row
->used
[area
]);
22053 start
= max (0, start
);
22054 start
= min (end
, start
);
22056 /* Translate X to frame coordinates. Set last_x to the right
22057 end of the drawing area. */
22058 if (row
->full_width_p
)
22060 /* X is relative to the left edge of W, without scroll bars
22062 area_left
= WINDOW_LEFT_EDGE_X (w
);
22063 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
22067 area_left
= window_box_left (w
, area
);
22068 last_x
= area_left
+ window_box_width (w
, area
);
22072 /* Build a doubly-linked list of glyph_string structures between
22073 head and tail from what we have to draw. Note that the macro
22074 BUILD_GLYPH_STRINGS will modify its start parameter. That's
22075 the reason we use a separate variable `i'. */
22077 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
22079 x_reached
= tail
->x
+ tail
->background_width
;
22083 /* If there are any glyphs with lbearing < 0 or rbearing > width in
22084 the row, redraw some glyphs in front or following the glyph
22085 strings built above. */
22086 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
22088 struct glyph_string
*h
, *t
;
22089 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
22090 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
22091 int check_mouse_face
= 0;
22094 /* If mouse highlighting is on, we may need to draw adjacent
22095 glyphs using mouse-face highlighting. */
22096 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
22098 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
22100 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
22101 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
22103 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
22105 check_mouse_face
= 1;
22106 mouse_beg_col
= (row
== mouse_beg_row
)
22107 ? hlinfo
->mouse_face_beg_col
: 0;
22108 mouse_end_col
= (row
== mouse_end_row
)
22109 ? hlinfo
->mouse_face_end_col
22110 : row
->used
[TEXT_AREA
];
22114 /* Compute overhangs for all glyph strings. */
22115 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
22116 for (s
= head
; s
; s
= s
->next
)
22117 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
22119 /* Prepend glyph strings for glyphs in front of the first glyph
22120 string that are overwritten because of the first glyph
22121 string's left overhang. The background of all strings
22122 prepended must be drawn because the first glyph string
22124 i
= left_overwritten (head
);
22127 enum draw_glyphs_face overlap_hl
;
22129 /* If this row contains mouse highlighting, attempt to draw
22130 the overlapped glyphs with the correct highlight. This
22131 code fails if the overlap encompasses more than one glyph
22132 and mouse-highlight spans only some of these glyphs.
22133 However, making it work perfectly involves a lot more
22134 code, and I don't know if the pathological case occurs in
22135 practice, so we'll stick to this for now. --- cyd */
22136 if (check_mouse_face
22137 && mouse_beg_col
< start
&& mouse_end_col
> i
)
22138 overlap_hl
= DRAW_MOUSE_FACE
;
22140 overlap_hl
= DRAW_NORMAL_TEXT
;
22143 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
22144 overlap_hl
, dummy_x
, last_x
);
22146 compute_overhangs_and_x (t
, head
->x
, 1);
22147 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
22151 /* Prepend glyph strings for glyphs in front of the first glyph
22152 string that overwrite that glyph string because of their
22153 right overhang. For these strings, only the foreground must
22154 be drawn, because it draws over the glyph string at `head'.
22155 The background must not be drawn because this would overwrite
22156 right overhangs of preceding glyphs for which no glyph
22158 i
= left_overwriting (head
);
22161 enum draw_glyphs_face overlap_hl
;
22163 if (check_mouse_face
22164 && mouse_beg_col
< start
&& mouse_end_col
> i
)
22165 overlap_hl
= DRAW_MOUSE_FACE
;
22167 overlap_hl
= DRAW_NORMAL_TEXT
;
22170 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
22171 overlap_hl
, dummy_x
, last_x
);
22172 for (s
= h
; s
; s
= s
->next
)
22173 s
->background_filled_p
= 1;
22174 compute_overhangs_and_x (t
, head
->x
, 1);
22175 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
22178 /* Append glyphs strings for glyphs following the last glyph
22179 string tail that are overwritten by tail. The background of
22180 these strings has to be drawn because tail's foreground draws
22182 i
= right_overwritten (tail
);
22185 enum draw_glyphs_face overlap_hl
;
22187 if (check_mouse_face
22188 && mouse_beg_col
< i
&& mouse_end_col
> end
)
22189 overlap_hl
= DRAW_MOUSE_FACE
;
22191 overlap_hl
= DRAW_NORMAL_TEXT
;
22193 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
22194 overlap_hl
, x
, last_x
);
22195 /* Because BUILD_GLYPH_STRINGS updates the first argument,
22196 we don't have `end = i;' here. */
22197 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
22198 append_glyph_string_lists (&head
, &tail
, h
, t
);
22202 /* Append glyph strings for glyphs following the last glyph
22203 string tail that overwrite tail. The foreground of such
22204 glyphs has to be drawn because it writes into the background
22205 of tail. The background must not be drawn because it could
22206 paint over the foreground of following glyphs. */
22207 i
= right_overwriting (tail
);
22210 enum draw_glyphs_face overlap_hl
;
22211 if (check_mouse_face
22212 && mouse_beg_col
< i
&& mouse_end_col
> end
)
22213 overlap_hl
= DRAW_MOUSE_FACE
;
22215 overlap_hl
= DRAW_NORMAL_TEXT
;
22218 i
++; /* We must include the Ith glyph. */
22219 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
22220 overlap_hl
, x
, last_x
);
22221 for (s
= h
; s
; s
= s
->next
)
22222 s
->background_filled_p
= 1;
22223 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
22224 append_glyph_string_lists (&head
, &tail
, h
, t
);
22226 if (clip_head
|| clip_tail
)
22227 for (s
= head
; s
; s
= s
->next
)
22229 s
->clip_head
= clip_head
;
22230 s
->clip_tail
= clip_tail
;
22234 /* Draw all strings. */
22235 for (s
= head
; s
; s
= s
->next
)
22236 FRAME_RIF (f
)->draw_glyph_string (s
);
22239 /* When focus a sole frame and move horizontally, this sets on_p to 0
22240 causing a failure to erase prev cursor position. */
22241 if (area
== TEXT_AREA
22242 && !row
->full_width_p
22243 /* When drawing overlapping rows, only the glyph strings'
22244 foreground is drawn, which doesn't erase a cursor
22248 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
22249 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
22250 : (tail
? tail
->x
+ tail
->background_width
: x
));
22254 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
22255 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
22259 /* Value is the x-position up to which drawn, relative to AREA of W.
22260 This doesn't include parts drawn because of overhangs. */
22261 if (row
->full_width_p
)
22262 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
22264 x_reached
-= area_left
;
22266 RELEASE_HDC (hdc
, f
);
22271 /* Expand row matrix if too narrow. Don't expand if area
22274 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
22276 if (!fonts_changed_p \
22277 && (it->glyph_row->glyphs[area] \
22278 < it->glyph_row->glyphs[area + 1])) \
22280 it->w->ncols_scale_factor++; \
22281 fonts_changed_p = 1; \
22285 /* Store one glyph for IT->char_to_display in IT->glyph_row.
22286 Called from x_produce_glyphs when IT->glyph_row is non-null. */
22289 append_glyph (struct it
*it
)
22291 struct glyph
*glyph
;
22292 enum glyph_row_area area
= it
->area
;
22294 xassert (it
->glyph_row
);
22295 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
22297 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22298 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22300 /* If the glyph row is reversed, we need to prepend the glyph
22301 rather than append it. */
22302 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22306 /* Make room for the additional glyph. */
22307 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22309 glyph
= it
->glyph_row
->glyphs
[area
];
22311 glyph
->charpos
= CHARPOS (it
->position
);
22312 glyph
->object
= it
->object
;
22313 if (it
->pixel_width
> 0)
22315 glyph
->pixel_width
= it
->pixel_width
;
22316 glyph
->padding_p
= 0;
22320 /* Assure at least 1-pixel width. Otherwise, cursor can't
22321 be displayed correctly. */
22322 glyph
->pixel_width
= 1;
22323 glyph
->padding_p
= 1;
22325 glyph
->ascent
= it
->ascent
;
22326 glyph
->descent
= it
->descent
;
22327 glyph
->voffset
= it
->voffset
;
22328 glyph
->type
= CHAR_GLYPH
;
22329 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22330 glyph
->multibyte_p
= it
->multibyte_p
;
22331 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22332 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22333 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22334 || it
->phys_descent
> it
->descent
);
22335 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
22336 glyph
->face_id
= it
->face_id
;
22337 glyph
->u
.ch
= it
->char_to_display
;
22338 glyph
->slice
.img
= null_glyph_slice
;
22339 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22342 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22343 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22345 glyph
->bidi_type
= it
->bidi_it
.type
;
22349 glyph
->resolved_level
= 0;
22350 glyph
->bidi_type
= UNKNOWN_BT
;
22352 ++it
->glyph_row
->used
[area
];
22355 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22358 /* Store one glyph for the composition IT->cmp_it.id in
22359 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
22363 append_composite_glyph (struct it
*it
)
22365 struct glyph
*glyph
;
22366 enum glyph_row_area area
= it
->area
;
22368 xassert (it
->glyph_row
);
22370 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22371 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22373 /* If the glyph row is reversed, we need to prepend the glyph
22374 rather than append it. */
22375 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
22379 /* Make room for the new glyph. */
22380 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
22382 glyph
= it
->glyph_row
->glyphs
[it
->area
];
22384 glyph
->charpos
= it
->cmp_it
.charpos
;
22385 glyph
->object
= it
->object
;
22386 glyph
->pixel_width
= it
->pixel_width
;
22387 glyph
->ascent
= it
->ascent
;
22388 glyph
->descent
= it
->descent
;
22389 glyph
->voffset
= it
->voffset
;
22390 glyph
->type
= COMPOSITE_GLYPH
;
22391 if (it
->cmp_it
.ch
< 0)
22393 glyph
->u
.cmp
.automatic
= 0;
22394 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
22395 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
22399 glyph
->u
.cmp
.automatic
= 1;
22400 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
22401 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
22402 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
22404 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22405 glyph
->multibyte_p
= it
->multibyte_p
;
22406 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22407 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22408 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22409 || it
->phys_descent
> it
->descent
);
22410 glyph
->padding_p
= 0;
22411 glyph
->glyph_not_available_p
= 0;
22412 glyph
->face_id
= it
->face_id
;
22413 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22416 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22417 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22419 glyph
->bidi_type
= it
->bidi_it
.type
;
22421 ++it
->glyph_row
->used
[area
];
22424 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22428 /* Change IT->ascent and IT->height according to the setting of
22432 take_vertical_position_into_account (struct it
*it
)
22436 if (it
->voffset
< 0)
22437 /* Increase the ascent so that we can display the text higher
22439 it
->ascent
-= it
->voffset
;
22441 /* Increase the descent so that we can display the text lower
22443 it
->descent
+= it
->voffset
;
22448 /* Produce glyphs/get display metrics for the image IT is loaded with.
22449 See the description of struct display_iterator in dispextern.h for
22450 an overview of struct display_iterator. */
22453 produce_image_glyph (struct it
*it
)
22457 int glyph_ascent
, crop
;
22458 struct glyph_slice slice
;
22460 xassert (it
->what
== IT_IMAGE
);
22462 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22464 /* Make sure X resources of the face is loaded. */
22465 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22467 if (it
->image_id
< 0)
22469 /* Fringe bitmap. */
22470 it
->ascent
= it
->phys_ascent
= 0;
22471 it
->descent
= it
->phys_descent
= 0;
22472 it
->pixel_width
= 0;
22477 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
22479 /* Make sure X resources of the image is loaded. */
22480 prepare_image_for_display (it
->f
, img
);
22482 slice
.x
= slice
.y
= 0;
22483 slice
.width
= img
->width
;
22484 slice
.height
= img
->height
;
22486 if (INTEGERP (it
->slice
.x
))
22487 slice
.x
= XINT (it
->slice
.x
);
22488 else if (FLOATP (it
->slice
.x
))
22489 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
22491 if (INTEGERP (it
->slice
.y
))
22492 slice
.y
= XINT (it
->slice
.y
);
22493 else if (FLOATP (it
->slice
.y
))
22494 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
22496 if (INTEGERP (it
->slice
.width
))
22497 slice
.width
= XINT (it
->slice
.width
);
22498 else if (FLOATP (it
->slice
.width
))
22499 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
22501 if (INTEGERP (it
->slice
.height
))
22502 slice
.height
= XINT (it
->slice
.height
);
22503 else if (FLOATP (it
->slice
.height
))
22504 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
22506 if (slice
.x
>= img
->width
)
22507 slice
.x
= img
->width
;
22508 if (slice
.y
>= img
->height
)
22509 slice
.y
= img
->height
;
22510 if (slice
.x
+ slice
.width
>= img
->width
)
22511 slice
.width
= img
->width
- slice
.x
;
22512 if (slice
.y
+ slice
.height
> img
->height
)
22513 slice
.height
= img
->height
- slice
.y
;
22515 if (slice
.width
== 0 || slice
.height
== 0)
22518 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
22520 it
->descent
= slice
.height
- glyph_ascent
;
22522 it
->descent
+= img
->vmargin
;
22523 if (slice
.y
+ slice
.height
== img
->height
)
22524 it
->descent
+= img
->vmargin
;
22525 it
->phys_descent
= it
->descent
;
22527 it
->pixel_width
= slice
.width
;
22529 it
->pixel_width
+= img
->hmargin
;
22530 if (slice
.x
+ slice
.width
== img
->width
)
22531 it
->pixel_width
+= img
->hmargin
;
22533 /* It's quite possible for images to have an ascent greater than
22534 their height, so don't get confused in that case. */
22535 if (it
->descent
< 0)
22540 if (face
->box
!= FACE_NO_BOX
)
22542 if (face
->box_line_width
> 0)
22545 it
->ascent
+= face
->box_line_width
;
22546 if (slice
.y
+ slice
.height
== img
->height
)
22547 it
->descent
+= face
->box_line_width
;
22550 if (it
->start_of_box_run_p
&& slice
.x
== 0)
22551 it
->pixel_width
+= eabs (face
->box_line_width
);
22552 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
22553 it
->pixel_width
+= eabs (face
->box_line_width
);
22556 take_vertical_position_into_account (it
);
22558 /* Automatically crop wide image glyphs at right edge so we can
22559 draw the cursor on same display row. */
22560 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
22561 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
22563 it
->pixel_width
-= crop
;
22564 slice
.width
-= crop
;
22569 struct glyph
*glyph
;
22570 enum glyph_row_area area
= it
->area
;
22572 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22573 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22575 glyph
->charpos
= CHARPOS (it
->position
);
22576 glyph
->object
= it
->object
;
22577 glyph
->pixel_width
= it
->pixel_width
;
22578 glyph
->ascent
= glyph_ascent
;
22579 glyph
->descent
= it
->descent
;
22580 glyph
->voffset
= it
->voffset
;
22581 glyph
->type
= IMAGE_GLYPH
;
22582 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22583 glyph
->multibyte_p
= it
->multibyte_p
;
22584 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22585 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22586 glyph
->overlaps_vertically_p
= 0;
22587 glyph
->padding_p
= 0;
22588 glyph
->glyph_not_available_p
= 0;
22589 glyph
->face_id
= it
->face_id
;
22590 glyph
->u
.img_id
= img
->id
;
22591 glyph
->slice
.img
= slice
;
22592 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22595 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22596 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22598 glyph
->bidi_type
= it
->bidi_it
.type
;
22600 ++it
->glyph_row
->used
[area
];
22603 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22608 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
22609 of the glyph, WIDTH and HEIGHT are the width and height of the
22610 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
22613 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
22614 int width
, int height
, int ascent
)
22616 struct glyph
*glyph
;
22617 enum glyph_row_area area
= it
->area
;
22619 xassert (ascent
>= 0 && ascent
<= height
);
22621 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22622 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22624 /* If the glyph row is reversed, we need to prepend the glyph
22625 rather than append it. */
22626 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22630 /* Make room for the additional glyph. */
22631 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22633 glyph
= it
->glyph_row
->glyphs
[area
];
22635 glyph
->charpos
= CHARPOS (it
->position
);
22636 glyph
->object
= object
;
22637 glyph
->pixel_width
= width
;
22638 glyph
->ascent
= ascent
;
22639 glyph
->descent
= height
- ascent
;
22640 glyph
->voffset
= it
->voffset
;
22641 glyph
->type
= STRETCH_GLYPH
;
22642 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22643 glyph
->multibyte_p
= it
->multibyte_p
;
22644 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22645 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22646 glyph
->overlaps_vertically_p
= 0;
22647 glyph
->padding_p
= 0;
22648 glyph
->glyph_not_available_p
= 0;
22649 glyph
->face_id
= it
->face_id
;
22650 glyph
->u
.stretch
.ascent
= ascent
;
22651 glyph
->u
.stretch
.height
= height
;
22652 glyph
->slice
.img
= null_glyph_slice
;
22653 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22656 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22657 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22659 glyph
->bidi_type
= it
->bidi_it
.type
;
22663 glyph
->resolved_level
= 0;
22664 glyph
->bidi_type
= UNKNOWN_BT
;
22666 ++it
->glyph_row
->used
[area
];
22669 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22673 /* Produce a stretch glyph for iterator IT. IT->object is the value
22674 of the glyph property displayed. The value must be a list
22675 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
22678 1. `:width WIDTH' specifies that the space should be WIDTH *
22679 canonical char width wide. WIDTH may be an integer or floating
22682 2. `:relative-width FACTOR' specifies that the width of the stretch
22683 should be computed from the width of the first character having the
22684 `glyph' property, and should be FACTOR times that width.
22686 3. `:align-to HPOS' specifies that the space should be wide enough
22687 to reach HPOS, a value in canonical character units.
22689 Exactly one of the above pairs must be present.
22691 4. `:height HEIGHT' specifies that the height of the stretch produced
22692 should be HEIGHT, measured in canonical character units.
22694 5. `:relative-height FACTOR' specifies that the height of the
22695 stretch should be FACTOR times the height of the characters having
22696 the glyph property.
22698 Either none or exactly one of 4 or 5 must be present.
22700 6. `:ascent ASCENT' specifies that ASCENT percent of the height
22701 of the stretch should be used for the ascent of the stretch.
22702 ASCENT must be in the range 0 <= ASCENT <= 100. */
22705 produce_stretch_glyph (struct it
*it
)
22707 /* (space :width WIDTH :height HEIGHT ...) */
22708 Lisp_Object prop
, plist
;
22709 int width
= 0, height
= 0, align_to
= -1;
22710 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
22713 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22714 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22716 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22718 /* List should start with `space'. */
22719 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
22720 plist
= XCDR (it
->object
);
22722 /* Compute the width of the stretch. */
22723 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
22724 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
22726 /* Absolute width `:width WIDTH' specified and valid. */
22727 zero_width_ok_p
= 1;
22730 else if (prop
= Fplist_get (plist
, QCrelative_width
),
22733 /* Relative width `:relative-width FACTOR' specified and valid.
22734 Compute the width of the characters having the `glyph'
22737 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
22740 if (it
->multibyte_p
)
22741 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
22744 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
22745 if (! ASCII_CHAR_P (it2
.c
))
22746 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
22749 it2
.glyph_row
= NULL
;
22750 it2
.what
= IT_CHARACTER
;
22751 x_produce_glyphs (&it2
);
22752 width
= NUMVAL (prop
) * it2
.pixel_width
;
22754 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
22755 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
22757 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
22758 align_to
= (align_to
< 0
22760 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
22761 else if (align_to
< 0)
22762 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
22763 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
22764 zero_width_ok_p
= 1;
22767 /* Nothing specified -> width defaults to canonical char width. */
22768 width
= FRAME_COLUMN_WIDTH (it
->f
);
22770 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
22773 /* Compute height. */
22774 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
22775 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22778 zero_height_ok_p
= 1;
22780 else if (prop
= Fplist_get (plist
, QCrelative_height
),
22782 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
22784 height
= FONT_HEIGHT (font
);
22786 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
22789 /* Compute percentage of height used for ascent. If
22790 `:ascent ASCENT' is present and valid, use that. Otherwise,
22791 derive the ascent from the font in use. */
22792 if (prop
= Fplist_get (plist
, QCascent
),
22793 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
22794 ascent
= height
* NUMVAL (prop
) / 100.0;
22795 else if (!NILP (prop
)
22796 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22797 ascent
= min (max (0, (int)tem
), height
);
22799 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
22801 if (width
> 0 && it
->line_wrap
!= TRUNCATE
22802 && it
->current_x
+ width
> it
->last_visible_x
)
22803 width
= it
->last_visible_x
- it
->current_x
- 1;
22805 if (width
> 0 && height
> 0 && it
->glyph_row
)
22807 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
22808 if (!STRINGP (object
))
22809 object
= it
->w
->buffer
;
22810 append_stretch_glyph (it
, object
, width
, height
, ascent
);
22813 it
->pixel_width
= width
;
22814 it
->ascent
= it
->phys_ascent
= ascent
;
22815 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
22816 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
22818 take_vertical_position_into_account (it
);
22821 /* Calculate line-height and line-spacing properties.
22822 An integer value specifies explicit pixel value.
22823 A float value specifies relative value to current face height.
22824 A cons (float . face-name) specifies relative value to
22825 height of specified face font.
22827 Returns height in pixels, or nil. */
22831 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
22832 int boff
, int override
)
22834 Lisp_Object face_name
= Qnil
;
22835 int ascent
, descent
, height
;
22837 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
22842 face_name
= XCAR (val
);
22844 if (!NUMBERP (val
))
22845 val
= make_number (1);
22846 if (NILP (face_name
))
22848 height
= it
->ascent
+ it
->descent
;
22853 if (NILP (face_name
))
22855 font
= FRAME_FONT (it
->f
);
22856 boff
= FRAME_BASELINE_OFFSET (it
->f
);
22858 else if (EQ (face_name
, Qt
))
22867 face_id
= lookup_named_face (it
->f
, face_name
, 0);
22869 return make_number (-1);
22871 face
= FACE_FROM_ID (it
->f
, face_id
);
22874 return make_number (-1);
22875 boff
= font
->baseline_offset
;
22876 if (font
->vertical_centering
)
22877 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22880 ascent
= FONT_BASE (font
) + boff
;
22881 descent
= FONT_DESCENT (font
) - boff
;
22885 it
->override_ascent
= ascent
;
22886 it
->override_descent
= descent
;
22887 it
->override_boff
= boff
;
22890 height
= ascent
+ descent
;
22894 height
= (int)(XFLOAT_DATA (val
) * height
);
22895 else if (INTEGERP (val
))
22896 height
*= XINT (val
);
22898 return make_number (height
);
22902 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
22903 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
22904 and only if this is for a character for which no font was found.
22906 If the display method (it->glyphless_method) is
22907 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
22908 length of the acronym or the hexadecimal string, UPPER_XOFF and
22909 UPPER_YOFF are pixel offsets for the upper part of the string,
22910 LOWER_XOFF and LOWER_YOFF are for the lower part.
22912 For the other display methods, LEN through LOWER_YOFF are zero. */
22915 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
22916 short upper_xoff
, short upper_yoff
,
22917 short lower_xoff
, short lower_yoff
)
22919 struct glyph
*glyph
;
22920 enum glyph_row_area area
= it
->area
;
22922 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22923 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22925 /* If the glyph row is reversed, we need to prepend the glyph
22926 rather than append it. */
22927 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22931 /* Make room for the additional glyph. */
22932 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22934 glyph
= it
->glyph_row
->glyphs
[area
];
22936 glyph
->charpos
= CHARPOS (it
->position
);
22937 glyph
->object
= it
->object
;
22938 glyph
->pixel_width
= it
->pixel_width
;
22939 glyph
->ascent
= it
->ascent
;
22940 glyph
->descent
= it
->descent
;
22941 glyph
->voffset
= it
->voffset
;
22942 glyph
->type
= GLYPHLESS_GLYPH
;
22943 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
22944 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
22945 glyph
->u
.glyphless
.len
= len
;
22946 glyph
->u
.glyphless
.ch
= it
->c
;
22947 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
22948 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
22949 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
22950 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
22951 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22952 glyph
->multibyte_p
= it
->multibyte_p
;
22953 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22954 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22955 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22956 || it
->phys_descent
> it
->descent
);
22957 glyph
->padding_p
= 0;
22958 glyph
->glyph_not_available_p
= 0;
22959 glyph
->face_id
= face_id
;
22960 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22963 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22964 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22966 glyph
->bidi_type
= it
->bidi_it
.type
;
22968 ++it
->glyph_row
->used
[area
];
22971 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22975 /* Produce a glyph for a glyphless character for iterator IT.
22976 IT->glyphless_method specifies which method to use for displaying
22977 the character. See the description of enum
22978 glyphless_display_method in dispextern.h for the detail.
22980 FOR_NO_FONT is nonzero if and only if this is for a character for
22981 which no font was found. ACRONYM, if non-nil, is an acronym string
22982 for the character. */
22985 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
22990 int base_width
, base_height
, width
, height
;
22991 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
22994 /* Get the metrics of the base font. We always refer to the current
22996 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
22997 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22998 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
22999 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
23000 base_height
= it
->ascent
+ it
->descent
;
23001 base_width
= font
->average_width
;
23003 /* Get a face ID for the glyph by utilizing a cache (the same way as
23004 doen for `escape-glyph' in get_next_display_element). */
23005 if (it
->f
== last_glyphless_glyph_frame
23006 && it
->face_id
== last_glyphless_glyph_face_id
)
23008 face_id
= last_glyphless_glyph_merged_face_id
;
23012 /* Merge the `glyphless-char' face into the current face. */
23013 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
23014 last_glyphless_glyph_frame
= it
->f
;
23015 last_glyphless_glyph_face_id
= it
->face_id
;
23016 last_glyphless_glyph_merged_face_id
= face_id
;
23019 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
23021 it
->pixel_width
= THIN_SPACE_WIDTH
;
23023 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
23025 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
23027 width
= CHAR_WIDTH (it
->c
);
23030 else if (width
> 4)
23032 it
->pixel_width
= base_width
* width
;
23034 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
23040 unsigned int code
[6];
23042 int ascent
, descent
;
23043 struct font_metrics metrics_upper
, metrics_lower
;
23045 face
= FACE_FROM_ID (it
->f
, face_id
);
23046 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23047 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23049 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
23051 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
23052 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
23053 if (CONSP (acronym
))
23054 acronym
= XCAR (acronym
);
23055 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
23059 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
23060 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
23063 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
23064 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
23065 upper_len
= (len
+ 1) / 2;
23066 font
->driver
->text_extents (font
, code
, upper_len
,
23068 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
23073 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
23074 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
23075 upper_xoff
= upper_yoff
= 2; /* the typical case */
23076 if (base_width
>= width
)
23078 /* Align the upper to the left, the lower to the right. */
23079 it
->pixel_width
= base_width
;
23080 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
23084 /* Center the shorter one. */
23085 it
->pixel_width
= width
;
23086 if (metrics_upper
.width
>= metrics_lower
.width
)
23087 lower_xoff
= (width
- metrics_lower
.width
) / 2;
23090 /* FIXME: This code doesn't look right. It formerly was
23091 missing the "lower_xoff = 0;", which couldn't have
23092 been right since it left lower_xoff uninitialized. */
23094 upper_xoff
= (width
- metrics_upper
.width
) / 2;
23098 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
23099 top, bottom, and between upper and lower strings. */
23100 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
23101 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
23102 /* Center vertically.
23103 H:base_height, D:base_descent
23104 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
23106 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
23107 descent = D - H/2 + h/2;
23108 lower_yoff = descent - 2 - ld;
23109 upper_yoff = lower_yoff - la - 1 - ud; */
23110 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
23111 descent
= it
->descent
- (base_height
- height
) / 2;
23112 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
23113 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
23114 - metrics_upper
.descent
);
23115 /* Don't make the height shorter than the base height. */
23116 if (height
> base_height
)
23118 it
->ascent
= ascent
;
23119 it
->descent
= descent
;
23123 it
->phys_ascent
= it
->ascent
;
23124 it
->phys_descent
= it
->descent
;
23126 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
23127 upper_xoff
, upper_yoff
,
23128 lower_xoff
, lower_yoff
);
23130 take_vertical_position_into_account (it
);
23135 Produce glyphs/get display metrics for the display element IT is
23136 loaded with. See the description of struct it in dispextern.h
23137 for an overview of struct it. */
23140 x_produce_glyphs (struct it
*it
)
23142 int extra_line_spacing
= it
->extra_line_spacing
;
23144 it
->glyph_not_available_p
= 0;
23146 if (it
->what
== IT_CHARACTER
)
23149 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23150 struct font
*font
= face
->font
;
23151 struct font_metrics
*pcm
= NULL
;
23152 int boff
; /* baseline offset */
23156 /* When no suitable font is found, display this character by
23157 the method specified in the first extra slot of
23158 Vglyphless_char_display. */
23159 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
23161 xassert (it
->what
== IT_GLYPHLESS
);
23162 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
23166 boff
= font
->baseline_offset
;
23167 if (font
->vertical_centering
)
23168 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23170 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
23176 if (it
->override_ascent
>= 0)
23178 it
->ascent
= it
->override_ascent
;
23179 it
->descent
= it
->override_descent
;
23180 boff
= it
->override_boff
;
23184 it
->ascent
= FONT_BASE (font
) + boff
;
23185 it
->descent
= FONT_DESCENT (font
) - boff
;
23188 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
23190 pcm
= get_per_char_metric (font
, &char2b
);
23191 if (pcm
->width
== 0
23192 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
23198 it
->phys_ascent
= pcm
->ascent
+ boff
;
23199 it
->phys_descent
= pcm
->descent
- boff
;
23200 it
->pixel_width
= pcm
->width
;
23204 it
->glyph_not_available_p
= 1;
23205 it
->phys_ascent
= it
->ascent
;
23206 it
->phys_descent
= it
->descent
;
23207 it
->pixel_width
= font
->space_width
;
23210 if (it
->constrain_row_ascent_descent_p
)
23212 if (it
->descent
> it
->max_descent
)
23214 it
->ascent
+= it
->descent
- it
->max_descent
;
23215 it
->descent
= it
->max_descent
;
23217 if (it
->ascent
> it
->max_ascent
)
23219 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
23220 it
->ascent
= it
->max_ascent
;
23222 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
23223 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
23224 extra_line_spacing
= 0;
23227 /* If this is a space inside a region of text with
23228 `space-width' property, change its width. */
23229 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
23231 it
->pixel_width
*= XFLOATINT (it
->space_width
);
23233 /* If face has a box, add the box thickness to the character
23234 height. If character has a box line to the left and/or
23235 right, add the box line width to the character's width. */
23236 if (face
->box
!= FACE_NO_BOX
)
23238 int thick
= face
->box_line_width
;
23242 it
->ascent
+= thick
;
23243 it
->descent
+= thick
;
23248 if (it
->start_of_box_run_p
)
23249 it
->pixel_width
+= thick
;
23250 if (it
->end_of_box_run_p
)
23251 it
->pixel_width
+= thick
;
23254 /* If face has an overline, add the height of the overline
23255 (1 pixel) and a 1 pixel margin to the character height. */
23256 if (face
->overline_p
)
23257 it
->ascent
+= overline_margin
;
23259 if (it
->constrain_row_ascent_descent_p
)
23261 if (it
->ascent
> it
->max_ascent
)
23262 it
->ascent
= it
->max_ascent
;
23263 if (it
->descent
> it
->max_descent
)
23264 it
->descent
= it
->max_descent
;
23267 take_vertical_position_into_account (it
);
23269 /* If we have to actually produce glyphs, do it. */
23274 /* Translate a space with a `space-width' property
23275 into a stretch glyph. */
23276 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
23277 / FONT_HEIGHT (font
));
23278 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
23279 it
->ascent
+ it
->descent
, ascent
);
23284 /* If characters with lbearing or rbearing are displayed
23285 in this line, record that fact in a flag of the
23286 glyph row. This is used to optimize X output code. */
23287 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
23288 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23290 if (! stretched_p
&& it
->pixel_width
== 0)
23291 /* We assure that all visible glyphs have at least 1-pixel
23293 it
->pixel_width
= 1;
23295 else if (it
->char_to_display
== '\n')
23297 /* A newline has no width, but we need the height of the
23298 line. But if previous part of the line sets a height,
23299 don't increase that height */
23301 Lisp_Object height
;
23302 Lisp_Object total_height
= Qnil
;
23304 it
->override_ascent
= -1;
23305 it
->pixel_width
= 0;
23308 height
= get_it_property (it
, Qline_height
);
23309 /* Split (line-height total-height) list */
23311 && CONSP (XCDR (height
))
23312 && NILP (XCDR (XCDR (height
))))
23314 total_height
= XCAR (XCDR (height
));
23315 height
= XCAR (height
);
23317 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
23319 if (it
->override_ascent
>= 0)
23321 it
->ascent
= it
->override_ascent
;
23322 it
->descent
= it
->override_descent
;
23323 boff
= it
->override_boff
;
23327 it
->ascent
= FONT_BASE (font
) + boff
;
23328 it
->descent
= FONT_DESCENT (font
) - boff
;
23331 if (EQ (height
, Qt
))
23333 if (it
->descent
> it
->max_descent
)
23335 it
->ascent
+= it
->descent
- it
->max_descent
;
23336 it
->descent
= it
->max_descent
;
23338 if (it
->ascent
> it
->max_ascent
)
23340 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
23341 it
->ascent
= it
->max_ascent
;
23343 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
23344 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
23345 it
->constrain_row_ascent_descent_p
= 1;
23346 extra_line_spacing
= 0;
23350 Lisp_Object spacing
;
23352 it
->phys_ascent
= it
->ascent
;
23353 it
->phys_descent
= it
->descent
;
23355 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
23356 && face
->box
!= FACE_NO_BOX
23357 && face
->box_line_width
> 0)
23359 it
->ascent
+= face
->box_line_width
;
23360 it
->descent
+= face
->box_line_width
;
23363 && XINT (height
) > it
->ascent
+ it
->descent
)
23364 it
->ascent
= XINT (height
) - it
->descent
;
23366 if (!NILP (total_height
))
23367 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
23370 spacing
= get_it_property (it
, Qline_spacing
);
23371 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
23373 if (INTEGERP (spacing
))
23375 extra_line_spacing
= XINT (spacing
);
23376 if (!NILP (total_height
))
23377 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
23381 else /* i.e. (it->char_to_display == '\t') */
23383 if (font
->space_width
> 0)
23385 int tab_width
= it
->tab_width
* font
->space_width
;
23386 int x
= it
->current_x
+ it
->continuation_lines_width
;
23387 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
23389 /* If the distance from the current position to the next tab
23390 stop is less than a space character width, use the
23391 tab stop after that. */
23392 if (next_tab_x
- x
< font
->space_width
)
23393 next_tab_x
+= tab_width
;
23395 it
->pixel_width
= next_tab_x
- x
;
23397 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
23398 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
23402 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
23403 it
->ascent
+ it
->descent
, it
->ascent
);
23408 it
->pixel_width
= 0;
23413 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
23415 /* A static composition.
23417 Note: A composition is represented as one glyph in the
23418 glyph matrix. There are no padding glyphs.
23420 Important note: pixel_width, ascent, and descent are the
23421 values of what is drawn by draw_glyphs (i.e. the values of
23422 the overall glyphs composed). */
23423 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23424 int boff
; /* baseline offset */
23425 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
23426 int glyph_len
= cmp
->glyph_len
;
23427 struct font
*font
= face
->font
;
23431 /* If we have not yet calculated pixel size data of glyphs of
23432 the composition for the current face font, calculate them
23433 now. Theoretically, we have to check all fonts for the
23434 glyphs, but that requires much time and memory space. So,
23435 here we check only the font of the first glyph. This may
23436 lead to incorrect display, but it's very rare, and C-l
23437 (recenter-top-bottom) can correct the display anyway. */
23438 if (! cmp
->font
|| cmp
->font
!= font
)
23440 /* Ascent and descent of the font of the first character
23441 of this composition (adjusted by baseline offset).
23442 Ascent and descent of overall glyphs should not be less
23443 than these, respectively. */
23444 int font_ascent
, font_descent
, font_height
;
23445 /* Bounding box of the overall glyphs. */
23446 int leftmost
, rightmost
, lowest
, highest
;
23447 int lbearing
, rbearing
;
23448 int i
, width
, ascent
, descent
;
23449 int left_padded
= 0, right_padded
= 0;
23450 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
23452 struct font_metrics
*pcm
;
23453 int font_not_found_p
;
23456 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
23457 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
23459 if (glyph_len
< cmp
->glyph_len
)
23461 for (i
= 0; i
< glyph_len
; i
++)
23463 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
23465 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
23470 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
23471 : IT_CHARPOS (*it
));
23472 /* If no suitable font is found, use the default font. */
23473 font_not_found_p
= font
== NULL
;
23474 if (font_not_found_p
)
23476 face
= face
->ascii_face
;
23479 boff
= font
->baseline_offset
;
23480 if (font
->vertical_centering
)
23481 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
23482 font_ascent
= FONT_BASE (font
) + boff
;
23483 font_descent
= FONT_DESCENT (font
) - boff
;
23484 font_height
= FONT_HEIGHT (font
);
23486 cmp
->font
= (void *) font
;
23489 if (! font_not_found_p
)
23491 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
23493 pcm
= get_per_char_metric (font
, &char2b
);
23496 /* Initialize the bounding box. */
23499 width
= pcm
->width
;
23500 ascent
= pcm
->ascent
;
23501 descent
= pcm
->descent
;
23502 lbearing
= pcm
->lbearing
;
23503 rbearing
= pcm
->rbearing
;
23507 width
= font
->space_width
;
23508 ascent
= FONT_BASE (font
);
23509 descent
= FONT_DESCENT (font
);
23516 lowest
= - descent
+ boff
;
23517 highest
= ascent
+ boff
;
23519 if (! font_not_found_p
23520 && font
->default_ascent
23521 && CHAR_TABLE_P (Vuse_default_ascent
)
23522 && !NILP (Faref (Vuse_default_ascent
,
23523 make_number (it
->char_to_display
))))
23524 highest
= font
->default_ascent
+ boff
;
23526 /* Draw the first glyph at the normal position. It may be
23527 shifted to right later if some other glyphs are drawn
23529 cmp
->offsets
[i
* 2] = 0;
23530 cmp
->offsets
[i
* 2 + 1] = boff
;
23531 cmp
->lbearing
= lbearing
;
23532 cmp
->rbearing
= rbearing
;
23534 /* Set cmp->offsets for the remaining glyphs. */
23535 for (i
++; i
< glyph_len
; i
++)
23537 int left
, right
, btm
, top
;
23538 int ch
= COMPOSITION_GLYPH (cmp
, i
);
23540 struct face
*this_face
;
23544 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
23545 this_face
= FACE_FROM_ID (it
->f
, face_id
);
23546 font
= this_face
->font
;
23552 get_char_face_and_encoding (it
->f
, ch
, face_id
,
23554 pcm
= get_per_char_metric (font
, &char2b
);
23557 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
23560 width
= pcm
->width
;
23561 ascent
= pcm
->ascent
;
23562 descent
= pcm
->descent
;
23563 lbearing
= pcm
->lbearing
;
23564 rbearing
= pcm
->rbearing
;
23565 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
23567 /* Relative composition with or without
23568 alternate chars. */
23569 left
= (leftmost
+ rightmost
- width
) / 2;
23570 btm
= - descent
+ boff
;
23571 if (font
->relative_compose
23572 && (! CHAR_TABLE_P (Vignore_relative_composition
)
23573 || NILP (Faref (Vignore_relative_composition
,
23574 make_number (ch
)))))
23577 if (- descent
>= font
->relative_compose
)
23578 /* One extra pixel between two glyphs. */
23580 else if (ascent
<= 0)
23581 /* One extra pixel between two glyphs. */
23582 btm
= lowest
- 1 - ascent
- descent
;
23587 /* A composition rule is specified by an integer
23588 value that encodes global and new reference
23589 points (GREF and NREF). GREF and NREF are
23590 specified by numbers as below:
23592 0---1---2 -- ascent
23596 9--10--11 -- center
23598 ---3---4---5--- baseline
23600 6---7---8 -- descent
23602 int rule
= COMPOSITION_RULE (cmp
, i
);
23603 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
23605 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
23606 grefx
= gref
% 3, nrefx
= nref
% 3;
23607 grefy
= gref
/ 3, nrefy
= nref
/ 3;
23609 xoff
= font_height
* (xoff
- 128) / 256;
23611 yoff
= font_height
* (yoff
- 128) / 256;
23614 + grefx
* (rightmost
- leftmost
) / 2
23615 - nrefx
* width
/ 2
23618 btm
= ((grefy
== 0 ? highest
23620 : grefy
== 2 ? lowest
23621 : (highest
+ lowest
) / 2)
23622 - (nrefy
== 0 ? ascent
+ descent
23623 : nrefy
== 1 ? descent
- boff
23625 : (ascent
+ descent
) / 2)
23629 cmp
->offsets
[i
* 2] = left
;
23630 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
23632 /* Update the bounding box of the overall glyphs. */
23635 right
= left
+ width
;
23636 if (left
< leftmost
)
23638 if (right
> rightmost
)
23641 top
= btm
+ descent
+ ascent
;
23647 if (cmp
->lbearing
> left
+ lbearing
)
23648 cmp
->lbearing
= left
+ lbearing
;
23649 if (cmp
->rbearing
< left
+ rbearing
)
23650 cmp
->rbearing
= left
+ rbearing
;
23654 /* If there are glyphs whose x-offsets are negative,
23655 shift all glyphs to the right and make all x-offsets
23659 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23660 cmp
->offsets
[i
* 2] -= leftmost
;
23661 rightmost
-= leftmost
;
23662 cmp
->lbearing
-= leftmost
;
23663 cmp
->rbearing
-= leftmost
;
23666 if (left_padded
&& cmp
->lbearing
< 0)
23668 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23669 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
23670 rightmost
-= cmp
->lbearing
;
23671 cmp
->rbearing
-= cmp
->lbearing
;
23674 if (right_padded
&& rightmost
< cmp
->rbearing
)
23676 rightmost
= cmp
->rbearing
;
23679 cmp
->pixel_width
= rightmost
;
23680 cmp
->ascent
= highest
;
23681 cmp
->descent
= - lowest
;
23682 if (cmp
->ascent
< font_ascent
)
23683 cmp
->ascent
= font_ascent
;
23684 if (cmp
->descent
< font_descent
)
23685 cmp
->descent
= font_descent
;
23689 && (cmp
->lbearing
< 0
23690 || cmp
->rbearing
> cmp
->pixel_width
))
23691 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23693 it
->pixel_width
= cmp
->pixel_width
;
23694 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
23695 it
->descent
= it
->phys_descent
= cmp
->descent
;
23696 if (face
->box
!= FACE_NO_BOX
)
23698 int thick
= face
->box_line_width
;
23702 it
->ascent
+= thick
;
23703 it
->descent
+= thick
;
23708 if (it
->start_of_box_run_p
)
23709 it
->pixel_width
+= thick
;
23710 if (it
->end_of_box_run_p
)
23711 it
->pixel_width
+= thick
;
23714 /* If face has an overline, add the height of the overline
23715 (1 pixel) and a 1 pixel margin to the character height. */
23716 if (face
->overline_p
)
23717 it
->ascent
+= overline_margin
;
23719 take_vertical_position_into_account (it
);
23720 if (it
->ascent
< 0)
23722 if (it
->descent
< 0)
23726 append_composite_glyph (it
);
23728 else if (it
->what
== IT_COMPOSITION
)
23730 /* A dynamic (automatic) composition. */
23731 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23732 Lisp_Object gstring
;
23733 struct font_metrics metrics
;
23735 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
23737 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
23740 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
23741 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23742 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
23743 it
->descent
= it
->phys_descent
= metrics
.descent
;
23744 if (face
->box
!= FACE_NO_BOX
)
23746 int thick
= face
->box_line_width
;
23750 it
->ascent
+= thick
;
23751 it
->descent
+= thick
;
23756 if (it
->start_of_box_run_p
)
23757 it
->pixel_width
+= thick
;
23758 if (it
->end_of_box_run_p
)
23759 it
->pixel_width
+= thick
;
23761 /* If face has an overline, add the height of the overline
23762 (1 pixel) and a 1 pixel margin to the character height. */
23763 if (face
->overline_p
)
23764 it
->ascent
+= overline_margin
;
23765 take_vertical_position_into_account (it
);
23766 if (it
->ascent
< 0)
23768 if (it
->descent
< 0)
23772 append_composite_glyph (it
);
23774 else if (it
->what
== IT_GLYPHLESS
)
23775 produce_glyphless_glyph (it
, 0, Qnil
);
23776 else if (it
->what
== IT_IMAGE
)
23777 produce_image_glyph (it
);
23778 else if (it
->what
== IT_STRETCH
)
23779 produce_stretch_glyph (it
);
23782 /* Accumulate dimensions. Note: can't assume that it->descent > 0
23783 because this isn't true for images with `:ascent 100'. */
23784 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
23785 if (it
->area
== TEXT_AREA
)
23786 it
->current_x
+= it
->pixel_width
;
23788 if (extra_line_spacing
> 0)
23790 it
->descent
+= extra_line_spacing
;
23791 if (extra_line_spacing
> it
->max_extra_line_spacing
)
23792 it
->max_extra_line_spacing
= extra_line_spacing
;
23795 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
23796 it
->max_descent
= max (it
->max_descent
, it
->descent
);
23797 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
23798 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
23802 Output LEN glyphs starting at START at the nominal cursor position.
23803 Advance the nominal cursor over the text. The global variable
23804 updated_window contains the window being updated, updated_row is
23805 the glyph row being updated, and updated_area is the area of that
23806 row being updated. */
23809 x_write_glyphs (struct glyph
*start
, int len
)
23813 xassert (updated_window
&& updated_row
);
23816 /* Write glyphs. */
23818 hpos
= start
- updated_row
->glyphs
[updated_area
];
23819 x
= draw_glyphs (updated_window
, output_cursor
.x
,
23820 updated_row
, updated_area
,
23822 DRAW_NORMAL_TEXT
, 0);
23824 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
23825 if (updated_area
== TEXT_AREA
23826 && updated_window
->phys_cursor_on_p
23827 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
23828 && updated_window
->phys_cursor
.hpos
>= hpos
23829 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
23830 updated_window
->phys_cursor_on_p
= 0;
23834 /* Advance the output cursor. */
23835 output_cursor
.hpos
+= len
;
23836 output_cursor
.x
= x
;
23841 Insert LEN glyphs from START at the nominal cursor position. */
23844 x_insert_glyphs (struct glyph
*start
, int len
)
23848 int line_height
, shift_by_width
, shifted_region_width
;
23849 struct glyph_row
*row
;
23850 struct glyph
*glyph
;
23851 int frame_x
, frame_y
;
23854 xassert (updated_window
&& updated_row
);
23856 w
= updated_window
;
23857 f
= XFRAME (WINDOW_FRAME (w
));
23859 /* Get the height of the line we are in. */
23861 line_height
= row
->height
;
23863 /* Get the width of the glyphs to insert. */
23864 shift_by_width
= 0;
23865 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
23866 shift_by_width
+= glyph
->pixel_width
;
23868 /* Get the width of the region to shift right. */
23869 shifted_region_width
= (window_box_width (w
, updated_area
)
23874 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
23875 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
23877 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
23878 line_height
, shift_by_width
);
23880 /* Write the glyphs. */
23881 hpos
= start
- row
->glyphs
[updated_area
];
23882 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
23884 DRAW_NORMAL_TEXT
, 0);
23886 /* Advance the output cursor. */
23887 output_cursor
.hpos
+= len
;
23888 output_cursor
.x
+= shift_by_width
;
23894 Erase the current text line from the nominal cursor position
23895 (inclusive) to pixel column TO_X (exclusive). The idea is that
23896 everything from TO_X onward is already erased.
23898 TO_X is a pixel position relative to updated_area of
23899 updated_window. TO_X == -1 means clear to the end of this area. */
23902 x_clear_end_of_line (int to_x
)
23905 struct window
*w
= updated_window
;
23906 int max_x
, min_y
, max_y
;
23907 int from_x
, from_y
, to_y
;
23909 xassert (updated_window
&& updated_row
);
23910 f
= XFRAME (w
->frame
);
23912 if (updated_row
->full_width_p
)
23913 max_x
= WINDOW_TOTAL_WIDTH (w
);
23915 max_x
= window_box_width (w
, updated_area
);
23916 max_y
= window_text_bottom_y (w
);
23918 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
23919 of window. For TO_X > 0, truncate to end of drawing area. */
23925 to_x
= min (to_x
, max_x
);
23927 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
23929 /* Notice if the cursor will be cleared by this operation. */
23930 if (!updated_row
->full_width_p
)
23931 notice_overwritten_cursor (w
, updated_area
,
23932 output_cursor
.x
, -1,
23934 MATRIX_ROW_BOTTOM_Y (updated_row
));
23936 from_x
= output_cursor
.x
;
23938 /* Translate to frame coordinates. */
23939 if (updated_row
->full_width_p
)
23941 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
23942 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
23946 int area_left
= window_box_left (w
, updated_area
);
23947 from_x
+= area_left
;
23951 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
23952 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
23953 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
23955 /* Prevent inadvertently clearing to end of the X window. */
23956 if (to_x
> from_x
&& to_y
> from_y
)
23959 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
23960 to_x
- from_x
, to_y
- from_y
);
23965 #endif /* HAVE_WINDOW_SYSTEM */
23969 /***********************************************************************
23971 ***********************************************************************/
23973 /* Value is the internal representation of the specified cursor type
23974 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
23975 of the bar cursor. */
23977 static enum text_cursor_kinds
23978 get_specified_cursor_type (Lisp_Object arg
, int *width
)
23980 enum text_cursor_kinds type
;
23985 if (EQ (arg
, Qbox
))
23986 return FILLED_BOX_CURSOR
;
23988 if (EQ (arg
, Qhollow
))
23989 return HOLLOW_BOX_CURSOR
;
23991 if (EQ (arg
, Qbar
))
23998 && EQ (XCAR (arg
), Qbar
)
23999 && INTEGERP (XCDR (arg
))
24000 && XINT (XCDR (arg
)) >= 0)
24002 *width
= XINT (XCDR (arg
));
24006 if (EQ (arg
, Qhbar
))
24009 return HBAR_CURSOR
;
24013 && EQ (XCAR (arg
), Qhbar
)
24014 && INTEGERP (XCDR (arg
))
24015 && XINT (XCDR (arg
)) >= 0)
24017 *width
= XINT (XCDR (arg
));
24018 return HBAR_CURSOR
;
24021 /* Treat anything unknown as "hollow box cursor".
24022 It was bad to signal an error; people have trouble fixing
24023 .Xdefaults with Emacs, when it has something bad in it. */
24024 type
= HOLLOW_BOX_CURSOR
;
24029 /* Set the default cursor types for specified frame. */
24031 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
24036 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
24037 FRAME_CURSOR_WIDTH (f
) = width
;
24039 /* By default, set up the blink-off state depending on the on-state. */
24041 tem
= Fassoc (arg
, Vblink_cursor_alist
);
24044 FRAME_BLINK_OFF_CURSOR (f
)
24045 = get_specified_cursor_type (XCDR (tem
), &width
);
24046 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
24049 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
24053 #ifdef HAVE_WINDOW_SYSTEM
24055 /* Return the cursor we want to be displayed in window W. Return
24056 width of bar/hbar cursor through WIDTH arg. Return with
24057 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
24058 (i.e. if the `system caret' should track this cursor).
24060 In a mini-buffer window, we want the cursor only to appear if we
24061 are reading input from this window. For the selected window, we
24062 want the cursor type given by the frame parameter or buffer local
24063 setting of cursor-type. If explicitly marked off, draw no cursor.
24064 In all other cases, we want a hollow box cursor. */
24066 static enum text_cursor_kinds
24067 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
24068 int *active_cursor
)
24070 struct frame
*f
= XFRAME (w
->frame
);
24071 struct buffer
*b
= XBUFFER (w
->buffer
);
24072 int cursor_type
= DEFAULT_CURSOR
;
24073 Lisp_Object alt_cursor
;
24074 int non_selected
= 0;
24076 *active_cursor
= 1;
24079 if (cursor_in_echo_area
24080 && FRAME_HAS_MINIBUF_P (f
)
24081 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
24083 if (w
== XWINDOW (echo_area_window
))
24085 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
24087 *width
= FRAME_CURSOR_WIDTH (f
);
24088 return FRAME_DESIRED_CURSOR (f
);
24091 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
24094 *active_cursor
= 0;
24098 /* Detect a nonselected window or nonselected frame. */
24099 else if (w
!= XWINDOW (f
->selected_window
)
24100 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
24102 *active_cursor
= 0;
24104 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
24110 /* Never display a cursor in a window in which cursor-type is nil. */
24111 if (NILP (BVAR (b
, cursor_type
)))
24114 /* Get the normal cursor type for this window. */
24115 if (EQ (BVAR (b
, cursor_type
), Qt
))
24117 cursor_type
= FRAME_DESIRED_CURSOR (f
);
24118 *width
= FRAME_CURSOR_WIDTH (f
);
24121 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
24123 /* Use cursor-in-non-selected-windows instead
24124 for non-selected window or frame. */
24127 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
24128 if (!EQ (Qt
, alt_cursor
))
24129 return get_specified_cursor_type (alt_cursor
, width
);
24130 /* t means modify the normal cursor type. */
24131 if (cursor_type
== FILLED_BOX_CURSOR
)
24132 cursor_type
= HOLLOW_BOX_CURSOR
;
24133 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
24135 return cursor_type
;
24138 /* Use normal cursor if not blinked off. */
24139 if (!w
->cursor_off_p
)
24141 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
24143 if (cursor_type
== FILLED_BOX_CURSOR
)
24145 /* Using a block cursor on large images can be very annoying.
24146 So use a hollow cursor for "large" images.
24147 If image is not transparent (no mask), also use hollow cursor. */
24148 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
24149 if (img
!= NULL
&& IMAGEP (img
->spec
))
24151 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
24152 where N = size of default frame font size.
24153 This should cover most of the "tiny" icons people may use. */
24155 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
24156 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
24157 cursor_type
= HOLLOW_BOX_CURSOR
;
24160 else if (cursor_type
!= NO_CURSOR
)
24162 /* Display current only supports BOX and HOLLOW cursors for images.
24163 So for now, unconditionally use a HOLLOW cursor when cursor is
24164 not a solid box cursor. */
24165 cursor_type
= HOLLOW_BOX_CURSOR
;
24168 return cursor_type
;
24171 /* Cursor is blinked off, so determine how to "toggle" it. */
24173 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
24174 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
24175 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
24177 /* Then see if frame has specified a specific blink off cursor type. */
24178 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
24180 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
24181 return FRAME_BLINK_OFF_CURSOR (f
);
24185 /* Some people liked having a permanently visible blinking cursor,
24186 while others had very strong opinions against it. So it was
24187 decided to remove it. KFS 2003-09-03 */
24189 /* Finally perform built-in cursor blinking:
24190 filled box <-> hollow box
24191 wide [h]bar <-> narrow [h]bar
24192 narrow [h]bar <-> no cursor
24193 other type <-> no cursor */
24195 if (cursor_type
== FILLED_BOX_CURSOR
)
24196 return HOLLOW_BOX_CURSOR
;
24198 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
24201 return cursor_type
;
24209 /* Notice when the text cursor of window W has been completely
24210 overwritten by a drawing operation that outputs glyphs in AREA
24211 starting at X0 and ending at X1 in the line starting at Y0 and
24212 ending at Y1. X coordinates are area-relative. X1 < 0 means all
24213 the rest of the line after X0 has been written. Y coordinates
24214 are window-relative. */
24217 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
24218 int x0
, int x1
, int y0
, int y1
)
24220 int cx0
, cx1
, cy0
, cy1
;
24221 struct glyph_row
*row
;
24223 if (!w
->phys_cursor_on_p
)
24225 if (area
!= TEXT_AREA
)
24228 if (w
->phys_cursor
.vpos
< 0
24229 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
24230 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
24231 !(row
->enabled_p
&& row
->displays_text_p
)))
24234 if (row
->cursor_in_fringe_p
)
24236 row
->cursor_in_fringe_p
= 0;
24237 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
24238 w
->phys_cursor_on_p
= 0;
24242 cx0
= w
->phys_cursor
.x
;
24243 cx1
= cx0
+ w
->phys_cursor_width
;
24244 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
24247 /* The cursor image will be completely removed from the
24248 screen if the output area intersects the cursor area in
24249 y-direction. When we draw in [y0 y1[, and some part of
24250 the cursor is at y < y0, that part must have been drawn
24251 before. When scrolling, the cursor is erased before
24252 actually scrolling, so we don't come here. When not
24253 scrolling, the rows above the old cursor row must have
24254 changed, and in this case these rows must have written
24255 over the cursor image.
24257 Likewise if part of the cursor is below y1, with the
24258 exception of the cursor being in the first blank row at
24259 the buffer and window end because update_text_area
24260 doesn't draw that row. (Except when it does, but
24261 that's handled in update_text_area.) */
24263 cy0
= w
->phys_cursor
.y
;
24264 cy1
= cy0
+ w
->phys_cursor_height
;
24265 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
24268 w
->phys_cursor_on_p
= 0;
24271 #endif /* HAVE_WINDOW_SYSTEM */
24274 /************************************************************************
24276 ************************************************************************/
24278 #ifdef HAVE_WINDOW_SYSTEM
24281 Fix the display of area AREA of overlapping row ROW in window W
24282 with respect to the overlapping part OVERLAPS. */
24285 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
24286 enum glyph_row_area area
, int overlaps
)
24293 for (i
= 0; i
< row
->used
[area
];)
24295 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
24297 int start
= i
, start_x
= x
;
24301 x
+= row
->glyphs
[area
][i
].pixel_width
;
24304 while (i
< row
->used
[area
]
24305 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
24307 draw_glyphs (w
, start_x
, row
, area
,
24309 DRAW_NORMAL_TEXT
, overlaps
);
24313 x
+= row
->glyphs
[area
][i
].pixel_width
;
24323 Draw the cursor glyph of window W in glyph row ROW. See the
24324 comment of draw_glyphs for the meaning of HL. */
24327 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
24328 enum draw_glyphs_face hl
)
24330 /* If cursor hpos is out of bounds, don't draw garbage. This can
24331 happen in mini-buffer windows when switching between echo area
24332 glyphs and mini-buffer. */
24333 if ((row
->reversed_p
24334 ? (w
->phys_cursor
.hpos
>= 0)
24335 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
24337 int on_p
= w
->phys_cursor_on_p
;
24339 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
24340 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
24342 w
->phys_cursor_on_p
= on_p
;
24344 if (hl
== DRAW_CURSOR
)
24345 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
24346 /* When we erase the cursor, and ROW is overlapped by other
24347 rows, make sure that these overlapping parts of other rows
24349 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
24351 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
24353 if (row
> w
->current_matrix
->rows
24354 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
24355 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
24356 OVERLAPS_ERASED_CURSOR
);
24358 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
24359 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
24360 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
24361 OVERLAPS_ERASED_CURSOR
);
24368 Erase the image of a cursor of window W from the screen. */
24371 erase_phys_cursor (struct window
*w
)
24373 struct frame
*f
= XFRAME (w
->frame
);
24374 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
24375 int hpos
= w
->phys_cursor
.hpos
;
24376 int vpos
= w
->phys_cursor
.vpos
;
24377 int mouse_face_here_p
= 0;
24378 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
24379 struct glyph_row
*cursor_row
;
24380 struct glyph
*cursor_glyph
;
24381 enum draw_glyphs_face hl
;
24383 /* No cursor displayed or row invalidated => nothing to do on the
24385 if (w
->phys_cursor_type
== NO_CURSOR
)
24386 goto mark_cursor_off
;
24388 /* VPOS >= active_glyphs->nrows means that window has been resized.
24389 Don't bother to erase the cursor. */
24390 if (vpos
>= active_glyphs
->nrows
)
24391 goto mark_cursor_off
;
24393 /* If row containing cursor is marked invalid, there is nothing we
24395 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
24396 if (!cursor_row
->enabled_p
)
24397 goto mark_cursor_off
;
24399 /* If line spacing is > 0, old cursor may only be partially visible in
24400 window after split-window. So adjust visible height. */
24401 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
24402 window_text_bottom_y (w
) - cursor_row
->y
);
24404 /* If row is completely invisible, don't attempt to delete a cursor which
24405 isn't there. This can happen if cursor is at top of a window, and
24406 we switch to a buffer with a header line in that window. */
24407 if (cursor_row
->visible_height
<= 0)
24408 goto mark_cursor_off
;
24410 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
24411 if (cursor_row
->cursor_in_fringe_p
)
24413 cursor_row
->cursor_in_fringe_p
= 0;
24414 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
24415 goto mark_cursor_off
;
24418 /* This can happen when the new row is shorter than the old one.
24419 In this case, either draw_glyphs or clear_end_of_line
24420 should have cleared the cursor. Note that we wouldn't be
24421 able to erase the cursor in this case because we don't have a
24422 cursor glyph at hand. */
24423 if ((cursor_row
->reversed_p
24424 ? (w
->phys_cursor
.hpos
< 0)
24425 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
24426 goto mark_cursor_off
;
24428 /* If the cursor is in the mouse face area, redisplay that when
24429 we clear the cursor. */
24430 if (! NILP (hlinfo
->mouse_face_window
)
24431 && coords_in_mouse_face_p (w
, hpos
, vpos
)
24432 /* Don't redraw the cursor's spot in mouse face if it is at the
24433 end of a line (on a newline). The cursor appears there, but
24434 mouse highlighting does not. */
24435 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
24436 mouse_face_here_p
= 1;
24438 /* Maybe clear the display under the cursor. */
24439 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
24442 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
24445 cursor_glyph
= get_phys_cursor_glyph (w
);
24446 if (cursor_glyph
== NULL
)
24447 goto mark_cursor_off
;
24449 width
= cursor_glyph
->pixel_width
;
24450 left_x
= window_box_left_offset (w
, TEXT_AREA
);
24451 x
= w
->phys_cursor
.x
;
24453 width
-= left_x
- x
;
24454 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
24455 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
24456 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
24459 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
24462 /* Erase the cursor by redrawing the character underneath it. */
24463 if (mouse_face_here_p
)
24464 hl
= DRAW_MOUSE_FACE
;
24466 hl
= DRAW_NORMAL_TEXT
;
24467 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
24470 w
->phys_cursor_on_p
= 0;
24471 w
->phys_cursor_type
= NO_CURSOR
;
24476 Display or clear cursor of window W. If ON is zero, clear the
24477 cursor. If it is non-zero, display the cursor. If ON is nonzero,
24478 where to put the cursor is specified by HPOS, VPOS, X and Y. */
24481 display_and_set_cursor (struct window
*w
, int on
,
24482 int hpos
, int vpos
, int x
, int y
)
24484 struct frame
*f
= XFRAME (w
->frame
);
24485 int new_cursor_type
;
24486 int new_cursor_width
;
24488 struct glyph_row
*glyph_row
;
24489 struct glyph
*glyph
;
24491 /* This is pointless on invisible frames, and dangerous on garbaged
24492 windows and frames; in the latter case, the frame or window may
24493 be in the midst of changing its size, and x and y may be off the
24495 if (! FRAME_VISIBLE_P (f
)
24496 || FRAME_GARBAGED_P (f
)
24497 || vpos
>= w
->current_matrix
->nrows
24498 || hpos
>= w
->current_matrix
->matrix_w
)
24501 /* If cursor is off and we want it off, return quickly. */
24502 if (!on
&& !w
->phys_cursor_on_p
)
24505 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
24506 /* If cursor row is not enabled, we don't really know where to
24507 display the cursor. */
24508 if (!glyph_row
->enabled_p
)
24510 w
->phys_cursor_on_p
= 0;
24515 if (!glyph_row
->exact_window_width_line_p
24516 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
24517 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
24519 xassert (interrupt_input_blocked
);
24521 /* Set new_cursor_type to the cursor we want to be displayed. */
24522 new_cursor_type
= get_window_cursor_type (w
, glyph
,
24523 &new_cursor_width
, &active_cursor
);
24525 /* If cursor is currently being shown and we don't want it to be or
24526 it is in the wrong place, or the cursor type is not what we want,
24528 if (w
->phys_cursor_on_p
24530 || w
->phys_cursor
.x
!= x
24531 || w
->phys_cursor
.y
!= y
24532 || new_cursor_type
!= w
->phys_cursor_type
24533 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
24534 && new_cursor_width
!= w
->phys_cursor_width
)))
24535 erase_phys_cursor (w
);
24537 /* Don't check phys_cursor_on_p here because that flag is only set
24538 to zero in some cases where we know that the cursor has been
24539 completely erased, to avoid the extra work of erasing the cursor
24540 twice. In other words, phys_cursor_on_p can be 1 and the cursor
24541 still not be visible, or it has only been partly erased. */
24544 w
->phys_cursor_ascent
= glyph_row
->ascent
;
24545 w
->phys_cursor_height
= glyph_row
->height
;
24547 /* Set phys_cursor_.* before x_draw_.* is called because some
24548 of them may need the information. */
24549 w
->phys_cursor
.x
= x
;
24550 w
->phys_cursor
.y
= glyph_row
->y
;
24551 w
->phys_cursor
.hpos
= hpos
;
24552 w
->phys_cursor
.vpos
= vpos
;
24555 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
24556 new_cursor_type
, new_cursor_width
,
24557 on
, active_cursor
);
24561 /* Switch the display of W's cursor on or off, according to the value
24565 update_window_cursor (struct window
*w
, int on
)
24567 /* Don't update cursor in windows whose frame is in the process
24568 of being deleted. */
24569 if (w
->current_matrix
)
24572 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24573 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24579 /* Call update_window_cursor with parameter ON_P on all leaf windows
24580 in the window tree rooted at W. */
24583 update_cursor_in_window_tree (struct window
*w
, int on_p
)
24587 if (!NILP (w
->hchild
))
24588 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
24589 else if (!NILP (w
->vchild
))
24590 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
24592 update_window_cursor (w
, on_p
);
24594 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
24600 Display the cursor on window W, or clear it, according to ON_P.
24601 Don't change the cursor's position. */
24604 x_update_cursor (struct frame
*f
, int on_p
)
24606 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
24611 Clear the cursor of window W to background color, and mark the
24612 cursor as not shown. This is used when the text where the cursor
24613 is about to be rewritten. */
24616 x_clear_cursor (struct window
*w
)
24618 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
24619 update_window_cursor (w
, 0);
24622 #endif /* HAVE_WINDOW_SYSTEM */
24624 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
24627 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
24628 int start_hpos
, int end_hpos
,
24629 enum draw_glyphs_face draw
)
24631 #ifdef HAVE_WINDOW_SYSTEM
24632 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
24634 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
24638 #if defined (HAVE_GPM) || defined (MSDOS)
24639 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
24643 /* Display the active region described by mouse_face_* according to DRAW. */
24646 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
24648 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
24649 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24651 if (/* If window is in the process of being destroyed, don't bother
24653 w
->current_matrix
!= NULL
24654 /* Don't update mouse highlight if hidden */
24655 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
24656 /* Recognize when we are called to operate on rows that don't exist
24657 anymore. This can happen when a window is split. */
24658 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
24660 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
24661 struct glyph_row
*row
, *first
, *last
;
24663 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
24664 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
24666 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
24668 int start_hpos
, end_hpos
, start_x
;
24670 /* For all but the first row, the highlight starts at column 0. */
24673 /* R2L rows have BEG and END in reversed order, but the
24674 screen drawing geometry is always left to right. So
24675 we need to mirror the beginning and end of the
24676 highlighted area in R2L rows. */
24677 if (!row
->reversed_p
)
24679 start_hpos
= hlinfo
->mouse_face_beg_col
;
24680 start_x
= hlinfo
->mouse_face_beg_x
;
24682 else if (row
== last
)
24684 start_hpos
= hlinfo
->mouse_face_end_col
;
24685 start_x
= hlinfo
->mouse_face_end_x
;
24693 else if (row
->reversed_p
&& row
== last
)
24695 start_hpos
= hlinfo
->mouse_face_end_col
;
24696 start_x
= hlinfo
->mouse_face_end_x
;
24706 if (!row
->reversed_p
)
24707 end_hpos
= hlinfo
->mouse_face_end_col
;
24708 else if (row
== first
)
24709 end_hpos
= hlinfo
->mouse_face_beg_col
;
24712 end_hpos
= row
->used
[TEXT_AREA
];
24713 if (draw
== DRAW_NORMAL_TEXT
)
24714 row
->fill_line_p
= 1; /* Clear to end of line */
24717 else if (row
->reversed_p
&& row
== first
)
24718 end_hpos
= hlinfo
->mouse_face_beg_col
;
24721 end_hpos
= row
->used
[TEXT_AREA
];
24722 if (draw
== DRAW_NORMAL_TEXT
)
24723 row
->fill_line_p
= 1; /* Clear to end of line */
24726 if (end_hpos
> start_hpos
)
24728 draw_row_with_mouse_face (w
, start_x
, row
,
24729 start_hpos
, end_hpos
, draw
);
24732 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
24736 #ifdef HAVE_WINDOW_SYSTEM
24737 /* When we've written over the cursor, arrange for it to
24738 be displayed again. */
24739 if (FRAME_WINDOW_P (f
)
24740 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
24743 display_and_set_cursor (w
, 1,
24744 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24745 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24748 #endif /* HAVE_WINDOW_SYSTEM */
24751 #ifdef HAVE_WINDOW_SYSTEM
24752 /* Change the mouse cursor. */
24753 if (FRAME_WINDOW_P (f
))
24755 if (draw
== DRAW_NORMAL_TEXT
24756 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
24757 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
24758 else if (draw
== DRAW_MOUSE_FACE
)
24759 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
24761 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
24763 #endif /* HAVE_WINDOW_SYSTEM */
24767 Clear out the mouse-highlighted active region.
24768 Redraw it un-highlighted first. Value is non-zero if mouse
24769 face was actually drawn unhighlighted. */
24772 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
24776 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
24778 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
24782 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
24783 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
24784 hlinfo
->mouse_face_window
= Qnil
;
24785 hlinfo
->mouse_face_overlay
= Qnil
;
24789 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
24790 within the mouse face on that window. */
24792 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
24794 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
24796 /* Quickly resolve the easy cases. */
24797 if (!(WINDOWP (hlinfo
->mouse_face_window
)
24798 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
24800 if (vpos
< hlinfo
->mouse_face_beg_row
24801 || vpos
> hlinfo
->mouse_face_end_row
)
24803 if (vpos
> hlinfo
->mouse_face_beg_row
24804 && vpos
< hlinfo
->mouse_face_end_row
)
24807 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
24809 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24811 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
24814 else if ((vpos
== hlinfo
->mouse_face_beg_row
24815 && hpos
>= hlinfo
->mouse_face_beg_col
)
24816 || (vpos
== hlinfo
->mouse_face_end_row
24817 && hpos
< hlinfo
->mouse_face_end_col
))
24822 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24824 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
24827 else if ((vpos
== hlinfo
->mouse_face_beg_row
24828 && hpos
<= hlinfo
->mouse_face_beg_col
)
24829 || (vpos
== hlinfo
->mouse_face_end_row
24830 && hpos
> hlinfo
->mouse_face_end_col
))
24838 Non-zero if physical cursor of window W is within mouse face. */
24841 cursor_in_mouse_face_p (struct window
*w
)
24843 return coords_in_mouse_face_p (w
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
);
24848 /* Find the glyph rows START_ROW and END_ROW of window W that display
24849 characters between buffer positions START_CHARPOS and END_CHARPOS
24850 (excluding END_CHARPOS). This is similar to row_containing_pos,
24851 but is more accurate when bidi reordering makes buffer positions
24852 change non-linearly with glyph rows. */
24854 rows_from_pos_range (struct window
*w
,
24855 EMACS_INT start_charpos
, EMACS_INT end_charpos
,
24856 struct glyph_row
**start
, struct glyph_row
**end
)
24858 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24859 int last_y
= window_text_bottom_y (w
);
24860 struct glyph_row
*row
;
24865 while (!first
->enabled_p
24866 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
24869 /* Find the START row. */
24871 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
24874 /* A row can potentially be the START row if the range of the
24875 characters it displays intersects the range
24876 [START_CHARPOS..END_CHARPOS). */
24877 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
24878 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
24879 /* See the commentary in row_containing_pos, for the
24880 explanation of the complicated way to check whether
24881 some position is beyond the end of the characters
24882 displayed by a row. */
24883 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24884 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24885 && !row
->ends_at_zv_p
24886 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
24887 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24888 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24889 && !row
->ends_at_zv_p
24890 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
24892 /* Found a candidate row. Now make sure at least one of the
24893 glyphs it displays has a charpos from the range
24894 [START_CHARPOS..END_CHARPOS).
24896 This is not obvious because bidi reordering could make
24897 buffer positions of a row be 1,2,3,102,101,100, and if we
24898 want to highlight characters in [50..60), we don't want
24899 this row, even though [50..60) does intersect [1..103),
24900 the range of character positions given by the row's start
24901 and end positions. */
24902 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
24903 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
24907 if (BUFFERP (g
->object
)
24908 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24917 /* Find the END row. */
24919 /* If the last row is partially visible, start looking for END
24920 from that row, instead of starting from FIRST. */
24921 && !(row
->enabled_p
24922 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
24924 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
24926 struct glyph_row
*next
= row
+ 1;
24928 if (!next
->enabled_p
24929 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
24930 /* The first row >= START whose range of displayed characters
24931 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
24932 is the row END + 1. */
24933 || (start_charpos
< MATRIX_ROW_START_CHARPOS (next
)
24934 && end_charpos
< MATRIX_ROW_START_CHARPOS (next
))
24935 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24936 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24937 && !next
->ends_at_zv_p
24938 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
24939 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24940 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24941 && !next
->ends_at_zv_p
24942 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
24949 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
24950 but none of the characters it displays are in the range, it is
24952 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
24953 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
24957 if (BUFFERP (g
->object
)
24958 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24971 /* This function sets the mouse_face_* elements of HLINFO, assuming
24972 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
24973 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
24974 for the overlay or run of text properties specifying the mouse
24975 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
24976 before-string and after-string that must also be highlighted.
24977 COVER_STRING, if non-nil, is a display string that may cover some
24978 or all of the highlighted text. */
24981 mouse_face_from_buffer_pos (Lisp_Object window
,
24982 Mouse_HLInfo
*hlinfo
,
24983 EMACS_INT mouse_charpos
,
24984 EMACS_INT start_charpos
,
24985 EMACS_INT end_charpos
,
24986 Lisp_Object before_string
,
24987 Lisp_Object after_string
,
24988 Lisp_Object cover_string
)
24990 struct window
*w
= XWINDOW (window
);
24991 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24992 struct glyph_row
*r1
, *r2
;
24993 struct glyph
*glyph
, *end
;
24994 EMACS_INT ignore
, pos
;
24997 xassert (NILP (cover_string
) || STRINGP (cover_string
));
24998 xassert (NILP (before_string
) || STRINGP (before_string
));
24999 xassert (NILP (after_string
) || STRINGP (after_string
));
25001 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
25002 rows_from_pos_range (w
, start_charpos
, end_charpos
, &r1
, &r2
);
25004 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
25005 /* If the before-string or display-string contains newlines,
25006 rows_from_pos_range skips to its last row. Move back. */
25007 if (!NILP (before_string
) || !NILP (cover_string
))
25009 struct glyph_row
*prev
;
25010 while ((prev
= r1
- 1, prev
>= first
)
25011 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
25012 && prev
->used
[TEXT_AREA
] > 0)
25014 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
25015 glyph
= beg
+ prev
->used
[TEXT_AREA
];
25016 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
25018 || !(EQ (glyph
->object
, before_string
)
25019 || EQ (glyph
->object
, cover_string
)))
25026 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
25027 hlinfo
->mouse_face_past_end
= 1;
25029 else if (!NILP (after_string
))
25031 /* If the after-string has newlines, advance to its last row. */
25032 struct glyph_row
*next
;
25033 struct glyph_row
*last
25034 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
25036 for (next
= r2
+ 1;
25038 && next
->used
[TEXT_AREA
] > 0
25039 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
25043 /* The rest of the display engine assumes that mouse_face_beg_row is
25044 either above below mouse_face_end_row or identical to it. But
25045 with bidi-reordered continued lines, the row for START_CHARPOS
25046 could be below the row for END_CHARPOS. If so, swap the rows and
25047 store them in correct order. */
25050 struct glyph_row
*tem
= r2
;
25056 hlinfo
->mouse_face_beg_y
= r1
->y
;
25057 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
25058 hlinfo
->mouse_face_end_y
= r2
->y
;
25059 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
25061 /* For a bidi-reordered row, the positions of BEFORE_STRING,
25062 AFTER_STRING, COVER_STRING, START_CHARPOS, and END_CHARPOS
25063 could be anywhere in the row and in any order. The strategy
25064 below is to find the leftmost and the rightmost glyph that
25065 belongs to either of these 3 strings, or whose position is
25066 between START_CHARPOS and END_CHARPOS, and highlight all the
25067 glyphs between those two. This may cover more than just the text
25068 between START_CHARPOS and END_CHARPOS if the range of characters
25069 strides the bidi level boundary, e.g. if the beginning is in R2L
25070 text while the end is in L2R text or vice versa. */
25071 if (!r1
->reversed_p
)
25073 /* This row is in a left to right paragraph. Scan it left to
25075 glyph
= r1
->glyphs
[TEXT_AREA
];
25076 end
= glyph
+ r1
->used
[TEXT_AREA
];
25079 /* Skip truncation glyphs at the start of the glyph row. */
25080 if (r1
->displays_text_p
)
25082 && INTEGERP (glyph
->object
)
25083 && glyph
->charpos
< 0;
25085 x
+= glyph
->pixel_width
;
25087 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
25088 or COVER_STRING, and the first glyph from buffer whose
25089 position is between START_CHARPOS and END_CHARPOS. */
25091 && !INTEGERP (glyph
->object
)
25092 && !EQ (glyph
->object
, cover_string
)
25093 && !(BUFFERP (glyph
->object
)
25094 && (glyph
->charpos
>= start_charpos
25095 && glyph
->charpos
< end_charpos
));
25098 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25099 are present at buffer positions between START_CHARPOS and
25100 END_CHARPOS, or if they come from an overlay. */
25101 if (EQ (glyph
->object
, before_string
))
25103 pos
= string_buffer_position (before_string
,
25105 /* If pos == 0, it means before_string came from an
25106 overlay, not from a buffer position. */
25107 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25110 else if (EQ (glyph
->object
, after_string
))
25112 pos
= string_buffer_position (after_string
, end_charpos
);
25113 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25116 x
+= glyph
->pixel_width
;
25118 hlinfo
->mouse_face_beg_x
= x
;
25119 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
25123 /* This row is in a right to left paragraph. Scan it right to
25127 end
= r1
->glyphs
[TEXT_AREA
] - 1;
25128 glyph
= end
+ r1
->used
[TEXT_AREA
];
25130 /* Skip truncation glyphs at the start of the glyph row. */
25131 if (r1
->displays_text_p
)
25133 && INTEGERP (glyph
->object
)
25134 && glyph
->charpos
< 0;
25138 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
25139 or COVER_STRING, and the first glyph from buffer whose
25140 position is between START_CHARPOS and END_CHARPOS. */
25142 && !INTEGERP (glyph
->object
)
25143 && !EQ (glyph
->object
, cover_string
)
25144 && !(BUFFERP (glyph
->object
)
25145 && (glyph
->charpos
>= start_charpos
25146 && glyph
->charpos
< end_charpos
));
25149 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25150 are present at buffer positions between START_CHARPOS and
25151 END_CHARPOS, or if they come from an overlay. */
25152 if (EQ (glyph
->object
, before_string
))
25154 pos
= string_buffer_position (before_string
, start_charpos
);
25155 /* If pos == 0, it means before_string came from an
25156 overlay, not from a buffer position. */
25157 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25160 else if (EQ (glyph
->object
, after_string
))
25162 pos
= string_buffer_position (after_string
, end_charpos
);
25163 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25168 glyph
++; /* first glyph to the right of the highlighted area */
25169 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
25170 x
+= g
->pixel_width
;
25171 hlinfo
->mouse_face_beg_x
= x
;
25172 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
25175 /* If the highlight ends in a different row, compute GLYPH and END
25176 for the end row. Otherwise, reuse the values computed above for
25177 the row where the highlight begins. */
25180 if (!r2
->reversed_p
)
25182 glyph
= r2
->glyphs
[TEXT_AREA
];
25183 end
= glyph
+ r2
->used
[TEXT_AREA
];
25188 end
= r2
->glyphs
[TEXT_AREA
] - 1;
25189 glyph
= end
+ r2
->used
[TEXT_AREA
];
25193 if (!r2
->reversed_p
)
25195 /* Skip truncation and continuation glyphs near the end of the
25196 row, and also blanks and stretch glyphs inserted by
25197 extend_face_to_end_of_line. */
25199 && INTEGERP ((end
- 1)->object
)
25200 && (end
- 1)->charpos
<= 0)
25202 /* Scan the rest of the glyph row from the end, looking for the
25203 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
25204 COVER_STRING, or whose position is between START_CHARPOS
25208 && !INTEGERP (end
->object
)
25209 && !EQ (end
->object
, cover_string
)
25210 && !(BUFFERP (end
->object
)
25211 && (end
->charpos
>= start_charpos
25212 && end
->charpos
< end_charpos
));
25215 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25216 are present at buffer positions between START_CHARPOS and
25217 END_CHARPOS, or if they come from an overlay. */
25218 if (EQ (end
->object
, before_string
))
25220 pos
= string_buffer_position (before_string
, start_charpos
);
25221 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25224 else if (EQ (end
->object
, after_string
))
25226 pos
= string_buffer_position (after_string
, end_charpos
);
25227 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25231 /* Find the X coordinate of the last glyph to be highlighted. */
25232 for (; glyph
<= end
; ++glyph
)
25233 x
+= glyph
->pixel_width
;
25235 hlinfo
->mouse_face_end_x
= x
;
25236 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
25240 /* Skip truncation and continuation glyphs near the end of the
25241 row, and also blanks and stretch glyphs inserted by
25242 extend_face_to_end_of_line. */
25246 && INTEGERP (end
->object
)
25247 && end
->charpos
<= 0)
25249 x
+= end
->pixel_width
;
25252 /* Scan the rest of the glyph row from the end, looking for the
25253 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
25254 COVER_STRING, or whose position is between START_CHARPOS
25258 && !INTEGERP (end
->object
)
25259 && !EQ (end
->object
, cover_string
)
25260 && !(BUFFERP (end
->object
)
25261 && (end
->charpos
>= start_charpos
25262 && end
->charpos
< end_charpos
));
25265 /* BEFORE_STRING or AFTER_STRING are only relevant if they
25266 are present at buffer positions between START_CHARPOS and
25267 END_CHARPOS, or if they come from an overlay. */
25268 if (EQ (end
->object
, before_string
))
25270 pos
= string_buffer_position (before_string
, start_charpos
);
25271 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25274 else if (EQ (end
->object
, after_string
))
25276 pos
= string_buffer_position (after_string
, end_charpos
);
25277 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
25280 x
+= end
->pixel_width
;
25282 hlinfo
->mouse_face_end_x
= x
;
25283 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
25286 hlinfo
->mouse_face_window
= window
;
25287 hlinfo
->mouse_face_face_id
25288 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
25290 !hlinfo
->mouse_face_hidden
, -1);
25291 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25294 /* The following function is not used anymore (replaced with
25295 mouse_face_from_string_pos), but I leave it here for the time
25296 being, in case someone would. */
25298 #if 0 /* not used */
25300 /* Find the position of the glyph for position POS in OBJECT in
25301 window W's current matrix, and return in *X, *Y the pixel
25302 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
25304 RIGHT_P non-zero means return the position of the right edge of the
25305 glyph, RIGHT_P zero means return the left edge position.
25307 If no glyph for POS exists in the matrix, return the position of
25308 the glyph with the next smaller position that is in the matrix, if
25309 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
25310 exists in the matrix, return the position of the glyph with the
25311 next larger position in OBJECT.
25313 Value is non-zero if a glyph was found. */
25316 fast_find_string_pos (struct window
*w
, EMACS_INT pos
, Lisp_Object object
,
25317 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
25319 int yb
= window_text_bottom_y (w
);
25320 struct glyph_row
*r
;
25321 struct glyph
*best_glyph
= NULL
;
25322 struct glyph_row
*best_row
= NULL
;
25325 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25326 r
->enabled_p
&& r
->y
< yb
;
25329 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
25330 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
25333 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
25334 if (EQ (g
->object
, object
))
25336 if (g
->charpos
== pos
)
25343 else if (best_glyph
== NULL
25344 || ((eabs (g
->charpos
- pos
)
25345 < eabs (best_glyph
->charpos
- pos
))
25348 : g
->charpos
> pos
)))
25362 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
25366 *x
+= best_glyph
->pixel_width
;
25371 *vpos
= best_row
- w
->current_matrix
->rows
;
25374 return best_glyph
!= NULL
;
25376 #endif /* not used */
25378 /* Find the positions of the first and the last glyphs in window W's
25379 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
25380 (assumed to be a string), and return in HLINFO's mouse_face_*
25381 members the pixel and column/row coordinates of those glyphs. */
25384 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
25385 Lisp_Object object
,
25386 EMACS_INT startpos
, EMACS_INT endpos
)
25388 int yb
= window_text_bottom_y (w
);
25389 struct glyph_row
*r
;
25390 struct glyph
*g
, *e
;
25394 /* Find the glyph row with at least one position in the range
25395 [STARTPOS..ENDPOS], and the first glyph in that row whose
25396 position belongs to that range. */
25397 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
25398 r
->enabled_p
&& r
->y
< yb
;
25401 if (!r
->reversed_p
)
25403 g
= r
->glyphs
[TEXT_AREA
];
25404 e
= g
+ r
->used
[TEXT_AREA
];
25405 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
25406 if (EQ (g
->object
, object
)
25407 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
25409 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
25410 hlinfo
->mouse_face_beg_y
= r
->y
;
25411 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
25412 hlinfo
->mouse_face_beg_x
= gx
;
25421 e
= r
->glyphs
[TEXT_AREA
];
25422 g
= e
+ r
->used
[TEXT_AREA
];
25423 for ( ; g
> e
; --g
)
25424 if (EQ ((g
-1)->object
, object
)
25425 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
25427 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
25428 hlinfo
->mouse_face_beg_y
= r
->y
;
25429 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
25430 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
25431 gx
+= g1
->pixel_width
;
25432 hlinfo
->mouse_face_beg_x
= gx
;
25444 /* Starting with the next row, look for the first row which does NOT
25445 include any glyphs whose positions are in the range. */
25446 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
25448 g
= r
->glyphs
[TEXT_AREA
];
25449 e
= g
+ r
->used
[TEXT_AREA
];
25451 for ( ; g
< e
; ++g
)
25452 if (EQ (g
->object
, object
)
25453 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
25462 /* The highlighted region ends on the previous row. */
25465 /* Set the end row and its vertical pixel coordinate. */
25466 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
25467 hlinfo
->mouse_face_end_y
= r
->y
;
25469 /* Compute and set the end column and the end column's horizontal
25470 pixel coordinate. */
25471 if (!r
->reversed_p
)
25473 g
= r
->glyphs
[TEXT_AREA
];
25474 e
= g
+ r
->used
[TEXT_AREA
];
25475 for ( ; e
> g
; --e
)
25476 if (EQ ((e
-1)->object
, object
)
25477 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
25479 hlinfo
->mouse_face_end_col
= e
- g
;
25481 for (gx
= r
->x
; g
< e
; ++g
)
25482 gx
+= g
->pixel_width
;
25483 hlinfo
->mouse_face_end_x
= gx
;
25487 e
= r
->glyphs
[TEXT_AREA
];
25488 g
= e
+ r
->used
[TEXT_AREA
];
25489 for (gx
= r
->x
; e
< g
; ++e
)
25491 if (EQ (e
->object
, object
)
25492 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
25494 gx
+= e
->pixel_width
;
25496 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
25497 hlinfo
->mouse_face_end_x
= gx
;
25501 #ifdef HAVE_WINDOW_SYSTEM
25503 /* See if position X, Y is within a hot-spot of an image. */
25506 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
25508 if (!CONSP (hot_spot
))
25511 if (EQ (XCAR (hot_spot
), Qrect
))
25513 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
25514 Lisp_Object rect
= XCDR (hot_spot
);
25518 if (!CONSP (XCAR (rect
)))
25520 if (!CONSP (XCDR (rect
)))
25522 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
25524 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
25526 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
25528 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
25532 else if (EQ (XCAR (hot_spot
), Qcircle
))
25534 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
25535 Lisp_Object circ
= XCDR (hot_spot
);
25536 Lisp_Object lr
, lx0
, ly0
;
25538 && CONSP (XCAR (circ
))
25539 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
25540 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
25541 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
25543 double r
= XFLOATINT (lr
);
25544 double dx
= XINT (lx0
) - x
;
25545 double dy
= XINT (ly0
) - y
;
25546 return (dx
* dx
+ dy
* dy
<= r
* r
);
25549 else if (EQ (XCAR (hot_spot
), Qpoly
))
25551 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
25552 if (VECTORP (XCDR (hot_spot
)))
25554 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
25555 Lisp_Object
*poly
= v
->contents
;
25556 int n
= v
->header
.size
;
25559 Lisp_Object lx
, ly
;
25562 /* Need an even number of coordinates, and at least 3 edges. */
25563 if (n
< 6 || n
& 1)
25566 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
25567 If count is odd, we are inside polygon. Pixels on edges
25568 may or may not be included depending on actual geometry of the
25570 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
25571 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
25573 x0
= XINT (lx
), y0
= XINT (ly
);
25574 for (i
= 0; i
< n
; i
+= 2)
25576 int x1
= x0
, y1
= y0
;
25577 if ((lx
= poly
[i
], !INTEGERP (lx
))
25578 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
25580 x0
= XINT (lx
), y0
= XINT (ly
);
25582 /* Does this segment cross the X line? */
25590 if (y
> y0
&& y
> y1
)
25592 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
25602 find_hot_spot (Lisp_Object map
, int x
, int y
)
25604 while (CONSP (map
))
25606 if (CONSP (XCAR (map
))
25607 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
25615 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
25617 doc
: /* Lookup in image map MAP coordinates X and Y.
25618 An image map is an alist where each element has the format (AREA ID PLIST).
25619 An AREA is specified as either a rectangle, a circle, or a polygon:
25620 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
25621 pixel coordinates of the upper left and bottom right corners.
25622 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
25623 and the radius of the circle; r may be a float or integer.
25624 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
25625 vector describes one corner in the polygon.
25626 Returns the alist element for the first matching AREA in MAP. */)
25627 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
25635 return find_hot_spot (map
, XINT (x
), XINT (y
));
25639 /* Display frame CURSOR, optionally using shape defined by POINTER. */
25641 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
25643 /* Do not change cursor shape while dragging mouse. */
25644 if (!NILP (do_mouse_tracking
))
25647 if (!NILP (pointer
))
25649 if (EQ (pointer
, Qarrow
))
25650 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25651 else if (EQ (pointer
, Qhand
))
25652 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
25653 else if (EQ (pointer
, Qtext
))
25654 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25655 else if (EQ (pointer
, intern ("hdrag")))
25656 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25657 #ifdef HAVE_X_WINDOWS
25658 else if (EQ (pointer
, intern ("vdrag")))
25659 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
25661 else if (EQ (pointer
, intern ("hourglass")))
25662 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
25663 else if (EQ (pointer
, Qmodeline
))
25664 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
25666 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25669 if (cursor
!= No_Cursor
)
25670 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
25673 #endif /* HAVE_WINDOW_SYSTEM */
25675 /* Take proper action when mouse has moved to the mode or header line
25676 or marginal area AREA of window W, x-position X and y-position Y.
25677 X is relative to the start of the text display area of W, so the
25678 width of bitmap areas and scroll bars must be subtracted to get a
25679 position relative to the start of the mode line. */
25682 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
25683 enum window_part area
)
25685 struct window
*w
= XWINDOW (window
);
25686 struct frame
*f
= XFRAME (w
->frame
);
25687 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25688 #ifdef HAVE_WINDOW_SYSTEM
25689 Display_Info
*dpyinfo
;
25691 Cursor cursor
= No_Cursor
;
25692 Lisp_Object pointer
= Qnil
;
25693 int dx
, dy
, width
, height
;
25695 Lisp_Object string
, object
= Qnil
;
25696 Lisp_Object pos
, help
;
25698 Lisp_Object mouse_face
;
25699 int original_x_pixel
= x
;
25700 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
25701 struct glyph_row
*row
;
25703 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
25708 /* Kludge alert: mode_line_string takes X/Y in pixels, but
25709 returns them in row/column units! */
25710 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
25711 &object
, &dx
, &dy
, &width
, &height
);
25713 row
= (area
== ON_MODE_LINE
25714 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
25715 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
25717 /* Find the glyph under the mouse pointer. */
25718 if (row
->mode_line_p
&& row
->enabled_p
)
25720 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
25721 end
= glyph
+ row
->used
[TEXT_AREA
];
25723 for (x0
= original_x_pixel
;
25724 glyph
< end
&& x0
>= glyph
->pixel_width
;
25726 x0
-= glyph
->pixel_width
;
25734 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
25735 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
25736 returns them in row/column units! */
25737 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
25738 &object
, &dx
, &dy
, &width
, &height
);
25743 #ifdef HAVE_WINDOW_SYSTEM
25744 if (IMAGEP (object
))
25746 Lisp_Object image_map
, hotspot
;
25747 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
25749 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
25751 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25755 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
25756 If so, we could look for mouse-enter, mouse-leave
25757 properties in PLIST (and do something...). */
25758 hotspot
= XCDR (hotspot
);
25759 if (CONSP (hotspot
)
25760 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25762 pointer
= Fplist_get (plist
, Qpointer
);
25763 if (NILP (pointer
))
25765 help
= Fplist_get (plist
, Qhelp_echo
);
25768 help_echo_string
= help
;
25769 /* Is this correct? ++kfs */
25770 XSETWINDOW (help_echo_window
, w
);
25771 help_echo_object
= w
->buffer
;
25772 help_echo_pos
= charpos
;
25776 if (NILP (pointer
))
25777 pointer
= Fplist_get (XCDR (object
), QCpointer
);
25779 #endif /* HAVE_WINDOW_SYSTEM */
25781 if (STRINGP (string
))
25783 pos
= make_number (charpos
);
25784 /* If we're on a string with `help-echo' text property, arrange
25785 for the help to be displayed. This is done by setting the
25786 global variable help_echo_string to the help string. */
25789 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
25792 help_echo_string
= help
;
25793 XSETWINDOW (help_echo_window
, w
);
25794 help_echo_object
= string
;
25795 help_echo_pos
= charpos
;
25799 #ifdef HAVE_WINDOW_SYSTEM
25800 if (FRAME_WINDOW_P (f
))
25802 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25803 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25804 if (NILP (pointer
))
25805 pointer
= Fget_text_property (pos
, Qpointer
, string
);
25807 /* Change the mouse pointer according to what is under X/Y. */
25809 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
25812 map
= Fget_text_property (pos
, Qlocal_map
, string
);
25813 if (!KEYMAPP (map
))
25814 map
= Fget_text_property (pos
, Qkeymap
, string
);
25815 if (!KEYMAPP (map
))
25816 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
25821 /* Change the mouse face according to what is under X/Y. */
25822 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
25823 if (!NILP (mouse_face
)
25824 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25829 struct glyph
* tmp_glyph
;
25833 int total_pixel_width
;
25834 EMACS_INT begpos
, endpos
, ignore
;
25838 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
25839 Qmouse_face
, string
, Qnil
);
25845 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
25847 endpos
= SCHARS (string
);
25851 /* Calculate the glyph position GPOS of GLYPH in the
25852 displayed string, relative to the beginning of the
25853 highlighted part of the string.
25855 Note: GPOS is different from CHARPOS. CHARPOS is the
25856 position of GLYPH in the internal string object. A mode
25857 line string format has structures which are converted to
25858 a flattened string by the Emacs Lisp interpreter. The
25859 internal string is an element of those structures. The
25860 displayed string is the flattened string. */
25861 tmp_glyph
= row_start_glyph
;
25862 while (tmp_glyph
< glyph
25863 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25864 && begpos
<= tmp_glyph
->charpos
25865 && tmp_glyph
->charpos
< endpos
)))
25867 gpos
= glyph
- tmp_glyph
;
25869 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
25870 the highlighted part of the displayed string to which
25871 GLYPH belongs. Note: GSEQ_LENGTH is different from
25872 SCHARS (STRING), because the latter returns the length of
25873 the internal string. */
25874 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
25876 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25877 && begpos
<= tmp_glyph
->charpos
25878 && tmp_glyph
->charpos
< endpos
));
25881 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
25883 /* Calculate the total pixel width of all the glyphs between
25884 the beginning of the highlighted area and GLYPH. */
25885 total_pixel_width
= 0;
25886 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
25887 total_pixel_width
+= tmp_glyph
->pixel_width
;
25889 /* Pre calculation of re-rendering position. Note: X is in
25890 column units here, after the call to mode_line_string or
25891 marginal_area_string. */
25893 vpos
= (area
== ON_MODE_LINE
25894 ? (w
->current_matrix
)->nrows
- 1
25897 /* If GLYPH's position is included in the region that is
25898 already drawn in mouse face, we have nothing to do. */
25899 if ( EQ (window
, hlinfo
->mouse_face_window
)
25900 && (!row
->reversed_p
25901 ? (hlinfo
->mouse_face_beg_col
<= hpos
25902 && hpos
< hlinfo
->mouse_face_end_col
)
25903 /* In R2L rows we swap BEG and END, see below. */
25904 : (hlinfo
->mouse_face_end_col
<= hpos
25905 && hpos
< hlinfo
->mouse_face_beg_col
))
25906 && hlinfo
->mouse_face_beg_row
== vpos
)
25909 if (clear_mouse_face (hlinfo
))
25910 cursor
= No_Cursor
;
25912 if (!row
->reversed_p
)
25914 hlinfo
->mouse_face_beg_col
= hpos
;
25915 hlinfo
->mouse_face_beg_x
= original_x_pixel
25916 - (total_pixel_width
+ dx
);
25917 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
25918 hlinfo
->mouse_face_end_x
= 0;
25922 /* In R2L rows, show_mouse_face expects BEG and END
25923 coordinates to be swapped. */
25924 hlinfo
->mouse_face_end_col
= hpos
;
25925 hlinfo
->mouse_face_end_x
= original_x_pixel
25926 - (total_pixel_width
+ dx
);
25927 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
25928 hlinfo
->mouse_face_beg_x
= 0;
25931 hlinfo
->mouse_face_beg_row
= vpos
;
25932 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
25933 hlinfo
->mouse_face_beg_y
= 0;
25934 hlinfo
->mouse_face_end_y
= 0;
25935 hlinfo
->mouse_face_past_end
= 0;
25936 hlinfo
->mouse_face_window
= window
;
25938 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
25944 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25946 if (NILP (pointer
))
25949 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25950 clear_mouse_face (hlinfo
);
25952 #ifdef HAVE_WINDOW_SYSTEM
25953 if (FRAME_WINDOW_P (f
))
25954 define_frame_cursor1 (f
, cursor
, pointer
);
25960 Take proper action when the mouse has moved to position X, Y on
25961 frame F as regards highlighting characters that have mouse-face
25962 properties. Also de-highlighting chars where the mouse was before.
25963 X and Y can be negative or out of range. */
25966 note_mouse_highlight (struct frame
*f
, int x
, int y
)
25968 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25969 enum window_part part
;
25970 Lisp_Object window
;
25972 Cursor cursor
= No_Cursor
;
25973 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
25976 /* When a menu is active, don't highlight because this looks odd. */
25977 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
25978 if (popup_activated ())
25982 if (NILP (Vmouse_highlight
)
25983 || !f
->glyphs_initialized_p
25984 || f
->pointer_invisible
)
25987 hlinfo
->mouse_face_mouse_x
= x
;
25988 hlinfo
->mouse_face_mouse_y
= y
;
25989 hlinfo
->mouse_face_mouse_frame
= f
;
25991 if (hlinfo
->mouse_face_defer
)
25994 if (gc_in_progress
)
25996 hlinfo
->mouse_face_deferred_gc
= 1;
26000 /* Which window is that in? */
26001 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
26003 /* If we were displaying active text in another window, clear that.
26004 Also clear if we move out of text area in same window. */
26005 if (! EQ (window
, hlinfo
->mouse_face_window
)
26006 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
26007 && !NILP (hlinfo
->mouse_face_window
)))
26008 clear_mouse_face (hlinfo
);
26010 /* Not on a window -> return. */
26011 if (!WINDOWP (window
))
26014 /* Reset help_echo_string. It will get recomputed below. */
26015 help_echo_string
= Qnil
;
26017 /* Convert to window-relative pixel coordinates. */
26018 w
= XWINDOW (window
);
26019 frame_to_window_pixel_xy (w
, &x
, &y
);
26021 #ifdef HAVE_WINDOW_SYSTEM
26022 /* Handle tool-bar window differently since it doesn't display a
26024 if (EQ (window
, f
->tool_bar_window
))
26026 note_tool_bar_highlight (f
, x
, y
);
26031 /* Mouse is on the mode, header line or margin? */
26032 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
26033 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
26035 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
26039 #ifdef HAVE_WINDOW_SYSTEM
26040 if (part
== ON_VERTICAL_BORDER
)
26042 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
26043 help_echo_string
= build_string ("drag-mouse-1: resize");
26045 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
26046 || part
== ON_SCROLL_BAR
)
26047 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26049 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
26052 /* Are we in a window whose display is up to date?
26053 And verify the buffer's text has not changed. */
26054 b
= XBUFFER (w
->buffer
);
26055 if (part
== ON_TEXT
26056 && EQ (w
->window_end_valid
, w
->buffer
)
26057 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
26058 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
26060 int hpos
, vpos
, i
, dx
, dy
, area
;
26062 struct glyph
*glyph
;
26063 Lisp_Object object
;
26064 Lisp_Object mouse_face
= Qnil
, position
;
26065 Lisp_Object
*overlay_vec
= NULL
;
26067 struct buffer
*obuf
;
26068 EMACS_INT obegv
, ozv
;
26071 /* Find the glyph under X/Y. */
26072 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
26074 #ifdef HAVE_WINDOW_SYSTEM
26075 /* Look for :pointer property on image. */
26076 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26078 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26079 if (img
!= NULL
&& IMAGEP (img
->spec
))
26081 Lisp_Object image_map
, hotspot
;
26082 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
26084 && (hotspot
= find_hot_spot (image_map
,
26085 glyph
->slice
.img
.x
+ dx
,
26086 glyph
->slice
.img
.y
+ dy
),
26088 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
26092 /* Could check XCAR (hotspot) to see if we enter/leave
26094 If so, we could look for mouse-enter, mouse-leave
26095 properties in PLIST (and do something...). */
26096 hotspot
= XCDR (hotspot
);
26097 if (CONSP (hotspot
)
26098 && (plist
= XCAR (hotspot
), CONSP (plist
)))
26100 pointer
= Fplist_get (plist
, Qpointer
);
26101 if (NILP (pointer
))
26103 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
26104 if (!NILP (help_echo_string
))
26106 help_echo_window
= window
;
26107 help_echo_object
= glyph
->object
;
26108 help_echo_pos
= glyph
->charpos
;
26112 if (NILP (pointer
))
26113 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
26116 #endif /* HAVE_WINDOW_SYSTEM */
26118 /* Clear mouse face if X/Y not over text. */
26120 || area
!= TEXT_AREA
26121 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
26122 /* Glyph's OBJECT is an integer for glyphs inserted by the
26123 display engine for its internal purposes, like truncation
26124 and continuation glyphs and blanks beyond the end of
26125 line's text on text terminals. If we are over such a
26126 glyph, we are not over any text. */
26127 || INTEGERP (glyph
->object
)
26128 /* R2L rows have a stretch glyph at their front, which
26129 stands for no text, whereas L2R rows have no glyphs at
26130 all beyond the end of text. Treat such stretch glyphs
26131 like we do with NULL glyphs in L2R rows. */
26132 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
26133 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
26134 && glyph
->type
== STRETCH_GLYPH
26135 && glyph
->avoid_cursor_p
))
26137 if (clear_mouse_face (hlinfo
))
26138 cursor
= No_Cursor
;
26139 #ifdef HAVE_WINDOW_SYSTEM
26140 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
26142 if (area
!= TEXT_AREA
)
26143 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
26145 pointer
= Vvoid_text_area_pointer
;
26151 pos
= glyph
->charpos
;
26152 object
= glyph
->object
;
26153 if (!STRINGP (object
) && !BUFFERP (object
))
26156 /* If we get an out-of-range value, return now; avoid an error. */
26157 if (BUFFERP (object
) && pos
> BUF_Z (b
))
26160 /* Make the window's buffer temporarily current for
26161 overlays_at and compute_char_face. */
26162 obuf
= current_buffer
;
26163 current_buffer
= b
;
26169 /* Is this char mouse-active or does it have help-echo? */
26170 position
= make_number (pos
);
26172 if (BUFFERP (object
))
26174 /* Put all the overlays we want in a vector in overlay_vec. */
26175 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
26176 /* Sort overlays into increasing priority order. */
26177 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
26182 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
26185 cursor
= No_Cursor
;
26187 /* Check mouse-face highlighting. */
26189 /* If there exists an overlay with mouse-face overlapping
26190 the one we are currently highlighting, we have to
26191 check if we enter the overlapping overlay, and then
26192 highlight only that. */
26193 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
26194 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
26196 /* Find the highest priority overlay with a mouse-face. */
26197 Lisp_Object overlay
= Qnil
;
26198 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
26200 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
26201 if (!NILP (mouse_face
))
26202 overlay
= overlay_vec
[i
];
26205 /* If we're highlighting the same overlay as before, there's
26206 no need to do that again. */
26207 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
26208 goto check_help_echo
;
26209 hlinfo
->mouse_face_overlay
= overlay
;
26211 /* Clear the display of the old active region, if any. */
26212 if (clear_mouse_face (hlinfo
))
26213 cursor
= No_Cursor
;
26215 /* If no overlay applies, get a text property. */
26216 if (NILP (overlay
))
26217 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
26219 /* Next, compute the bounds of the mouse highlighting and
26221 if (!NILP (mouse_face
) && STRINGP (object
))
26223 /* The mouse-highlighting comes from a display string
26224 with a mouse-face. */
26228 s
= Fprevious_single_property_change
26229 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
26230 e
= Fnext_single_property_change
26231 (position
, Qmouse_face
, object
, Qnil
);
26233 s
= make_number (0);
26235 e
= make_number (SCHARS (object
) - 1);
26236 mouse_face_from_string_pos (w
, hlinfo
, object
,
26237 XINT (s
), XINT (e
));
26238 hlinfo
->mouse_face_past_end
= 0;
26239 hlinfo
->mouse_face_window
= window
;
26240 hlinfo
->mouse_face_face_id
26241 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
26242 glyph
->face_id
, 1);
26243 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26244 cursor
= No_Cursor
;
26248 /* The mouse-highlighting, if any, comes from an overlay
26249 or text property in the buffer. */
26250 Lisp_Object buffer
IF_LINT (= Qnil
);
26251 Lisp_Object cover_string
IF_LINT (= Qnil
);
26253 if (STRINGP (object
))
26255 /* If we are on a display string with no mouse-face,
26256 check if the text under it has one. */
26257 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
26258 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26259 pos
= string_buffer_position (object
, start
);
26262 mouse_face
= get_char_property_and_overlay
26263 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
26264 buffer
= w
->buffer
;
26265 cover_string
= object
;
26271 cover_string
= Qnil
;
26274 if (!NILP (mouse_face
))
26276 Lisp_Object before
, after
;
26277 Lisp_Object before_string
, after_string
;
26278 /* To correctly find the limits of mouse highlight
26279 in a bidi-reordered buffer, we must not use the
26280 optimization of limiting the search in
26281 previous-single-property-change and
26282 next-single-property-change, because
26283 rows_from_pos_range needs the real start and end
26284 positions to DTRT in this case. That's because
26285 the first row visible in a window does not
26286 necessarily display the character whose position
26287 is the smallest. */
26289 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
26290 ? Fmarker_position (w
->start
)
26293 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
26294 ? make_number (BUF_Z (XBUFFER (buffer
))
26295 - XFASTINT (w
->window_end_pos
))
26298 if (NILP (overlay
))
26300 /* Handle the text property case. */
26301 before
= Fprevious_single_property_change
26302 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
26303 after
= Fnext_single_property_change
26304 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
26305 before_string
= after_string
= Qnil
;
26309 /* Handle the overlay case. */
26310 before
= Foverlay_start (overlay
);
26311 after
= Foverlay_end (overlay
);
26312 before_string
= Foverlay_get (overlay
, Qbefore_string
);
26313 after_string
= Foverlay_get (overlay
, Qafter_string
);
26315 if (!STRINGP (before_string
)) before_string
= Qnil
;
26316 if (!STRINGP (after_string
)) after_string
= Qnil
;
26319 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
26322 before_string
, after_string
,
26324 cursor
= No_Cursor
;
26331 /* Look for a `help-echo' property. */
26332 if (NILP (help_echo_string
)) {
26333 Lisp_Object help
, overlay
;
26335 /* Check overlays first. */
26336 help
= overlay
= Qnil
;
26337 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
26339 overlay
= overlay_vec
[i
];
26340 help
= Foverlay_get (overlay
, Qhelp_echo
);
26345 help_echo_string
= help
;
26346 help_echo_window
= window
;
26347 help_echo_object
= overlay
;
26348 help_echo_pos
= pos
;
26352 Lisp_Object obj
= glyph
->object
;
26353 EMACS_INT charpos
= glyph
->charpos
;
26355 /* Try text properties. */
26358 && charpos
< SCHARS (obj
))
26360 help
= Fget_text_property (make_number (charpos
),
26364 /* If the string itself doesn't specify a help-echo,
26365 see if the buffer text ``under'' it does. */
26366 struct glyph_row
*r
26367 = MATRIX_ROW (w
->current_matrix
, vpos
);
26368 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26369 EMACS_INT p
= string_buffer_position (obj
, start
);
26372 help
= Fget_char_property (make_number (p
),
26373 Qhelp_echo
, w
->buffer
);
26382 else if (BUFFERP (obj
)
26385 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
26390 help_echo_string
= help
;
26391 help_echo_window
= window
;
26392 help_echo_object
= obj
;
26393 help_echo_pos
= charpos
;
26398 #ifdef HAVE_WINDOW_SYSTEM
26399 /* Look for a `pointer' property. */
26400 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
26402 /* Check overlays first. */
26403 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
26404 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
26406 if (NILP (pointer
))
26408 Lisp_Object obj
= glyph
->object
;
26409 EMACS_INT charpos
= glyph
->charpos
;
26411 /* Try text properties. */
26414 && charpos
< SCHARS (obj
))
26416 pointer
= Fget_text_property (make_number (charpos
),
26418 if (NILP (pointer
))
26420 /* If the string itself doesn't specify a pointer,
26421 see if the buffer text ``under'' it does. */
26422 struct glyph_row
*r
26423 = MATRIX_ROW (w
->current_matrix
, vpos
);
26424 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
26425 EMACS_INT p
= string_buffer_position (obj
, start
);
26427 pointer
= Fget_char_property (make_number (p
),
26428 Qpointer
, w
->buffer
);
26431 else if (BUFFERP (obj
)
26434 pointer
= Fget_text_property (make_number (charpos
),
26438 #endif /* HAVE_WINDOW_SYSTEM */
26442 current_buffer
= obuf
;
26447 #ifdef HAVE_WINDOW_SYSTEM
26448 if (FRAME_WINDOW_P (f
))
26449 define_frame_cursor1 (f
, cursor
, pointer
);
26451 /* This is here to prevent a compiler error, about "label at end of
26452 compound statement". */
26459 Clear any mouse-face on window W. This function is part of the
26460 redisplay interface, and is called from try_window_id and similar
26461 functions to ensure the mouse-highlight is off. */
26464 x_clear_window_mouse_face (struct window
*w
)
26466 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26467 Lisp_Object window
;
26470 XSETWINDOW (window
, w
);
26471 if (EQ (window
, hlinfo
->mouse_face_window
))
26472 clear_mouse_face (hlinfo
);
26478 Just discard the mouse face information for frame F, if any.
26479 This is used when the size of F is changed. */
26482 cancel_mouse_face (struct frame
*f
)
26484 Lisp_Object window
;
26485 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26487 window
= hlinfo
->mouse_face_window
;
26488 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
26490 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26491 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26492 hlinfo
->mouse_face_window
= Qnil
;
26498 /***********************************************************************
26500 ***********************************************************************/
26502 #ifdef HAVE_WINDOW_SYSTEM
26504 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
26505 which intersects rectangle R. R is in window-relative coordinates. */
26508 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
26509 enum glyph_row_area area
)
26511 struct glyph
*first
= row
->glyphs
[area
];
26512 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
26513 struct glyph
*last
;
26514 int first_x
, start_x
, x
;
26516 if (area
== TEXT_AREA
&& row
->fill_line_p
)
26517 /* If row extends face to end of line write the whole line. */
26518 draw_glyphs (w
, 0, row
, area
,
26519 0, row
->used
[area
],
26520 DRAW_NORMAL_TEXT
, 0);
26523 /* Set START_X to the window-relative start position for drawing glyphs of
26524 AREA. The first glyph of the text area can be partially visible.
26525 The first glyphs of other areas cannot. */
26526 start_x
= window_box_left_offset (w
, area
);
26528 if (area
== TEXT_AREA
)
26531 /* Find the first glyph that must be redrawn. */
26533 && x
+ first
->pixel_width
< r
->x
)
26535 x
+= first
->pixel_width
;
26539 /* Find the last one. */
26543 && x
< r
->x
+ r
->width
)
26545 x
+= last
->pixel_width
;
26551 draw_glyphs (w
, first_x
- start_x
, row
, area
,
26552 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
26553 DRAW_NORMAL_TEXT
, 0);
26558 /* Redraw the parts of the glyph row ROW on window W intersecting
26559 rectangle R. R is in window-relative coordinates. Value is
26560 non-zero if mouse-face was overwritten. */
26563 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
26565 xassert (row
->enabled_p
);
26567 if (row
->mode_line_p
|| w
->pseudo_window_p
)
26568 draw_glyphs (w
, 0, row
, TEXT_AREA
,
26569 0, row
->used
[TEXT_AREA
],
26570 DRAW_NORMAL_TEXT
, 0);
26573 if (row
->used
[LEFT_MARGIN_AREA
])
26574 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
26575 if (row
->used
[TEXT_AREA
])
26576 expose_area (w
, row
, r
, TEXT_AREA
);
26577 if (row
->used
[RIGHT_MARGIN_AREA
])
26578 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
26579 draw_row_fringe_bitmaps (w
, row
);
26582 return row
->mouse_face_p
;
26586 /* Redraw those parts of glyphs rows during expose event handling that
26587 overlap other rows. Redrawing of an exposed line writes over parts
26588 of lines overlapping that exposed line; this function fixes that.
26590 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
26591 row in W's current matrix that is exposed and overlaps other rows.
26592 LAST_OVERLAPPING_ROW is the last such row. */
26595 expose_overlaps (struct window
*w
,
26596 struct glyph_row
*first_overlapping_row
,
26597 struct glyph_row
*last_overlapping_row
,
26600 struct glyph_row
*row
;
26602 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
26603 if (row
->overlapping_p
)
26605 xassert (row
->enabled_p
&& !row
->mode_line_p
);
26608 if (row
->used
[LEFT_MARGIN_AREA
])
26609 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
26611 if (row
->used
[TEXT_AREA
])
26612 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
26614 if (row
->used
[RIGHT_MARGIN_AREA
])
26615 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
26621 /* Return non-zero if W's cursor intersects rectangle R. */
26624 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
26626 XRectangle cr
, result
;
26627 struct glyph
*cursor_glyph
;
26628 struct glyph_row
*row
;
26630 if (w
->phys_cursor
.vpos
>= 0
26631 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
26632 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
26634 && row
->cursor_in_fringe_p
)
26636 /* Cursor is in the fringe. */
26637 cr
.x
= window_box_right_offset (w
,
26638 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
26639 ? RIGHT_MARGIN_AREA
26642 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
26643 cr
.height
= row
->height
;
26644 return x_intersect_rectangles (&cr
, r
, &result
);
26647 cursor_glyph
= get_phys_cursor_glyph (w
);
26650 /* r is relative to W's box, but w->phys_cursor.x is relative
26651 to left edge of W's TEXT area. Adjust it. */
26652 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
26653 cr
.y
= w
->phys_cursor
.y
;
26654 cr
.width
= cursor_glyph
->pixel_width
;
26655 cr
.height
= w
->phys_cursor_height
;
26656 /* ++KFS: W32 version used W32-specific IntersectRect here, but
26657 I assume the effect is the same -- and this is portable. */
26658 return x_intersect_rectangles (&cr
, r
, &result
);
26660 /* If we don't understand the format, pretend we're not in the hot-spot. */
26666 Draw a vertical window border to the right of window W if W doesn't
26667 have vertical scroll bars. */
26670 x_draw_vertical_border (struct window
*w
)
26672 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26674 /* We could do better, if we knew what type of scroll-bar the adjacent
26675 windows (on either side) have... But we don't :-(
26676 However, I think this works ok. ++KFS 2003-04-25 */
26678 /* Redraw borders between horizontally adjacent windows. Don't
26679 do it for frames with vertical scroll bars because either the
26680 right scroll bar of a window, or the left scroll bar of its
26681 neighbor will suffice as a border. */
26682 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
26685 if (!WINDOW_RIGHTMOST_P (w
)
26686 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
26688 int x0
, x1
, y0
, y1
;
26690 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26693 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26696 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
26698 else if (!WINDOW_LEFTMOST_P (w
)
26699 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
26701 int x0
, x1
, y0
, y1
;
26703 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26706 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26709 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
26714 /* Redraw the part of window W intersection rectangle FR. Pixel
26715 coordinates in FR are frame-relative. Call this function with
26716 input blocked. Value is non-zero if the exposure overwrites
26720 expose_window (struct window
*w
, XRectangle
*fr
)
26722 struct frame
*f
= XFRAME (w
->frame
);
26724 int mouse_face_overwritten_p
= 0;
26726 /* If window is not yet fully initialized, do nothing. This can
26727 happen when toolkit scroll bars are used and a window is split.
26728 Reconfiguring the scroll bar will generate an expose for a newly
26730 if (w
->current_matrix
== NULL
)
26733 /* When we're currently updating the window, display and current
26734 matrix usually don't agree. Arrange for a thorough display
26736 if (w
== updated_window
)
26738 SET_FRAME_GARBAGED (f
);
26742 /* Frame-relative pixel rectangle of W. */
26743 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
26744 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
26745 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
26746 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
26748 if (x_intersect_rectangles (fr
, &wr
, &r
))
26750 int yb
= window_text_bottom_y (w
);
26751 struct glyph_row
*row
;
26752 int cursor_cleared_p
;
26753 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
26755 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
26756 r
.x
, r
.y
, r
.width
, r
.height
));
26758 /* Convert to window coordinates. */
26759 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
26760 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
26762 /* Turn off the cursor. */
26763 if (!w
->pseudo_window_p
26764 && phys_cursor_in_rect_p (w
, &r
))
26766 x_clear_cursor (w
);
26767 cursor_cleared_p
= 1;
26770 cursor_cleared_p
= 0;
26772 /* Update lines intersecting rectangle R. */
26773 first_overlapping_row
= last_overlapping_row
= NULL
;
26774 for (row
= w
->current_matrix
->rows
;
26779 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
26781 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
26782 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
26783 || (r
.y
>= y0
&& r
.y
< y1
)
26784 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
26786 /* A header line may be overlapping, but there is no need
26787 to fix overlapping areas for them. KFS 2005-02-12 */
26788 if (row
->overlapping_p
&& !row
->mode_line_p
)
26790 if (first_overlapping_row
== NULL
)
26791 first_overlapping_row
= row
;
26792 last_overlapping_row
= row
;
26796 if (expose_line (w
, row
, &r
))
26797 mouse_face_overwritten_p
= 1;
26800 else if (row
->overlapping_p
)
26802 /* We must redraw a row overlapping the exposed area. */
26804 ? y0
+ row
->phys_height
> r
.y
26805 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
26807 if (first_overlapping_row
== NULL
)
26808 first_overlapping_row
= row
;
26809 last_overlapping_row
= row
;
26817 /* Display the mode line if there is one. */
26818 if (WINDOW_WANTS_MODELINE_P (w
)
26819 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
26821 && row
->y
< r
.y
+ r
.height
)
26823 if (expose_line (w
, row
, &r
))
26824 mouse_face_overwritten_p
= 1;
26827 if (!w
->pseudo_window_p
)
26829 /* Fix the display of overlapping rows. */
26830 if (first_overlapping_row
)
26831 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
26834 /* Draw border between windows. */
26835 x_draw_vertical_border (w
);
26837 /* Turn the cursor on again. */
26838 if (cursor_cleared_p
)
26839 update_window_cursor (w
, 1);
26843 return mouse_face_overwritten_p
;
26848 /* Redraw (parts) of all windows in the window tree rooted at W that
26849 intersect R. R contains frame pixel coordinates. Value is
26850 non-zero if the exposure overwrites mouse-face. */
26853 expose_window_tree (struct window
*w
, XRectangle
*r
)
26855 struct frame
*f
= XFRAME (w
->frame
);
26856 int mouse_face_overwritten_p
= 0;
26858 while (w
&& !FRAME_GARBAGED_P (f
))
26860 if (!NILP (w
->hchild
))
26861 mouse_face_overwritten_p
26862 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
26863 else if (!NILP (w
->vchild
))
26864 mouse_face_overwritten_p
26865 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
26867 mouse_face_overwritten_p
|= expose_window (w
, r
);
26869 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
26872 return mouse_face_overwritten_p
;
26877 Redisplay an exposed area of frame F. X and Y are the upper-left
26878 corner of the exposed rectangle. W and H are width and height of
26879 the exposed area. All are pixel values. W or H zero means redraw
26880 the entire frame. */
26883 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
26886 int mouse_face_overwritten_p
= 0;
26888 TRACE ((stderr
, "expose_frame "));
26890 /* No need to redraw if frame will be redrawn soon. */
26891 if (FRAME_GARBAGED_P (f
))
26893 TRACE ((stderr
, " garbaged\n"));
26897 /* If basic faces haven't been realized yet, there is no point in
26898 trying to redraw anything. This can happen when we get an expose
26899 event while Emacs is starting, e.g. by moving another window. */
26900 if (FRAME_FACE_CACHE (f
) == NULL
26901 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
26903 TRACE ((stderr
, " no faces\n"));
26907 if (w
== 0 || h
== 0)
26910 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
26911 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
26921 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
26922 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
26924 if (WINDOWP (f
->tool_bar_window
))
26925 mouse_face_overwritten_p
26926 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
26928 #ifdef HAVE_X_WINDOWS
26930 #ifndef USE_X_TOOLKIT
26931 if (WINDOWP (f
->menu_bar_window
))
26932 mouse_face_overwritten_p
26933 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
26934 #endif /* not USE_X_TOOLKIT */
26938 /* Some window managers support a focus-follows-mouse style with
26939 delayed raising of frames. Imagine a partially obscured frame,
26940 and moving the mouse into partially obscured mouse-face on that
26941 frame. The visible part of the mouse-face will be highlighted,
26942 then the WM raises the obscured frame. With at least one WM, KDE
26943 2.1, Emacs is not getting any event for the raising of the frame
26944 (even tried with SubstructureRedirectMask), only Expose events.
26945 These expose events will draw text normally, i.e. not
26946 highlighted. Which means we must redo the highlight here.
26947 Subsume it under ``we love X''. --gerd 2001-08-15 */
26948 /* Included in Windows version because Windows most likely does not
26949 do the right thing if any third party tool offers
26950 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
26951 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
26953 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26954 if (f
== hlinfo
->mouse_face_mouse_frame
)
26956 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
26957 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
26958 clear_mouse_face (hlinfo
);
26959 note_mouse_highlight (f
, mouse_x
, mouse_y
);
26966 Determine the intersection of two rectangles R1 and R2. Return
26967 the intersection in *RESULT. Value is non-zero if RESULT is not
26971 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
26973 XRectangle
*left
, *right
;
26974 XRectangle
*upper
, *lower
;
26975 int intersection_p
= 0;
26977 /* Rearrange so that R1 is the left-most rectangle. */
26979 left
= r1
, right
= r2
;
26981 left
= r2
, right
= r1
;
26983 /* X0 of the intersection is right.x0, if this is inside R1,
26984 otherwise there is no intersection. */
26985 if (right
->x
<= left
->x
+ left
->width
)
26987 result
->x
= right
->x
;
26989 /* The right end of the intersection is the minimum of the
26990 the right ends of left and right. */
26991 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
26994 /* Same game for Y. */
26996 upper
= r1
, lower
= r2
;
26998 upper
= r2
, lower
= r1
;
27000 /* The upper end of the intersection is lower.y0, if this is inside
27001 of upper. Otherwise, there is no intersection. */
27002 if (lower
->y
<= upper
->y
+ upper
->height
)
27004 result
->y
= lower
->y
;
27006 /* The lower end of the intersection is the minimum of the lower
27007 ends of upper and lower. */
27008 result
->height
= (min (lower
->y
+ lower
->height
,
27009 upper
->y
+ upper
->height
)
27011 intersection_p
= 1;
27015 return intersection_p
;
27018 #endif /* HAVE_WINDOW_SYSTEM */
27021 /***********************************************************************
27023 ***********************************************************************/
27026 syms_of_xdisp (void)
27028 Vwith_echo_area_save_vector
= Qnil
;
27029 staticpro (&Vwith_echo_area_save_vector
);
27031 Vmessage_stack
= Qnil
;
27032 staticpro (&Vmessage_stack
);
27034 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
27035 staticpro (&Qinhibit_redisplay
);
27037 message_dolog_marker1
= Fmake_marker ();
27038 staticpro (&message_dolog_marker1
);
27039 message_dolog_marker2
= Fmake_marker ();
27040 staticpro (&message_dolog_marker2
);
27041 message_dolog_marker3
= Fmake_marker ();
27042 staticpro (&message_dolog_marker3
);
27045 defsubr (&Sdump_frame_glyph_matrix
);
27046 defsubr (&Sdump_glyph_matrix
);
27047 defsubr (&Sdump_glyph_row
);
27048 defsubr (&Sdump_tool_bar_row
);
27049 defsubr (&Strace_redisplay
);
27050 defsubr (&Strace_to_stderr
);
27052 #ifdef HAVE_WINDOW_SYSTEM
27053 defsubr (&Stool_bar_lines_needed
);
27054 defsubr (&Slookup_image_map
);
27056 defsubr (&Sformat_mode_line
);
27057 defsubr (&Sinvisible_p
);
27058 defsubr (&Scurrent_bidi_paragraph_direction
);
27060 staticpro (&Qmenu_bar_update_hook
);
27061 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
27063 staticpro (&Qoverriding_terminal_local_map
);
27064 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
27066 staticpro (&Qoverriding_local_map
);
27067 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
27069 staticpro (&Qwindow_scroll_functions
);
27070 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
27072 staticpro (&Qwindow_text_change_functions
);
27073 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
27075 staticpro (&Qredisplay_end_trigger_functions
);
27076 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
27078 staticpro (&Qinhibit_point_motion_hooks
);
27079 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
27081 Qeval
= intern_c_string ("eval");
27082 staticpro (&Qeval
);
27084 QCdata
= intern_c_string (":data");
27085 staticpro (&QCdata
);
27086 Qdisplay
= intern_c_string ("display");
27087 staticpro (&Qdisplay
);
27088 Qspace_width
= intern_c_string ("space-width");
27089 staticpro (&Qspace_width
);
27090 Qraise
= intern_c_string ("raise");
27091 staticpro (&Qraise
);
27092 Qslice
= intern_c_string ("slice");
27093 staticpro (&Qslice
);
27094 Qspace
= intern_c_string ("space");
27095 staticpro (&Qspace
);
27096 Qmargin
= intern_c_string ("margin");
27097 staticpro (&Qmargin
);
27098 Qpointer
= intern_c_string ("pointer");
27099 staticpro (&Qpointer
);
27100 Qleft_margin
= intern_c_string ("left-margin");
27101 staticpro (&Qleft_margin
);
27102 Qright_margin
= intern_c_string ("right-margin");
27103 staticpro (&Qright_margin
);
27104 Qcenter
= intern_c_string ("center");
27105 staticpro (&Qcenter
);
27106 Qline_height
= intern_c_string ("line-height");
27107 staticpro (&Qline_height
);
27108 QCalign_to
= intern_c_string (":align-to");
27109 staticpro (&QCalign_to
);
27110 QCrelative_width
= intern_c_string (":relative-width");
27111 staticpro (&QCrelative_width
);
27112 QCrelative_height
= intern_c_string (":relative-height");
27113 staticpro (&QCrelative_height
);
27114 QCeval
= intern_c_string (":eval");
27115 staticpro (&QCeval
);
27116 QCpropertize
= intern_c_string (":propertize");
27117 staticpro (&QCpropertize
);
27118 QCfile
= intern_c_string (":file");
27119 staticpro (&QCfile
);
27120 Qfontified
= intern_c_string ("fontified");
27121 staticpro (&Qfontified
);
27122 Qfontification_functions
= intern_c_string ("fontification-functions");
27123 staticpro (&Qfontification_functions
);
27124 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
27125 staticpro (&Qtrailing_whitespace
);
27126 Qescape_glyph
= intern_c_string ("escape-glyph");
27127 staticpro (&Qescape_glyph
);
27128 Qnobreak_space
= intern_c_string ("nobreak-space");
27129 staticpro (&Qnobreak_space
);
27130 Qimage
= intern_c_string ("image");
27131 staticpro (&Qimage
);
27132 Qtext
= intern_c_string ("text");
27133 staticpro (&Qtext
);
27134 Qboth
= intern_c_string ("both");
27135 staticpro (&Qboth
);
27136 Qboth_horiz
= intern_c_string ("both-horiz");
27137 staticpro (&Qboth_horiz
);
27138 Qtext_image_horiz
= intern_c_string ("text-image-horiz");
27139 staticpro (&Qtext_image_horiz
);
27140 QCmap
= intern_c_string (":map");
27141 staticpro (&QCmap
);
27142 QCpointer
= intern_c_string (":pointer");
27143 staticpro (&QCpointer
);
27144 Qrect
= intern_c_string ("rect");
27145 staticpro (&Qrect
);
27146 Qcircle
= intern_c_string ("circle");
27147 staticpro (&Qcircle
);
27148 Qpoly
= intern_c_string ("poly");
27149 staticpro (&Qpoly
);
27150 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
27151 staticpro (&Qmessage_truncate_lines
);
27152 Qgrow_only
= intern_c_string ("grow-only");
27153 staticpro (&Qgrow_only
);
27154 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
27155 staticpro (&Qinhibit_menubar_update
);
27156 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
27157 staticpro (&Qinhibit_eval_during_redisplay
);
27158 Qposition
= intern_c_string ("position");
27159 staticpro (&Qposition
);
27160 Qbuffer_position
= intern_c_string ("buffer-position");
27161 staticpro (&Qbuffer_position
);
27162 Qobject
= intern_c_string ("object");
27163 staticpro (&Qobject
);
27164 Qbar
= intern_c_string ("bar");
27166 Qhbar
= intern_c_string ("hbar");
27167 staticpro (&Qhbar
);
27168 Qbox
= intern_c_string ("box");
27170 Qhollow
= intern_c_string ("hollow");
27171 staticpro (&Qhollow
);
27172 Qhand
= intern_c_string ("hand");
27173 staticpro (&Qhand
);
27174 Qarrow
= intern_c_string ("arrow");
27175 staticpro (&Qarrow
);
27176 Qtext
= intern_c_string ("text");
27177 staticpro (&Qtext
);
27178 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
27179 staticpro (&Qinhibit_free_realized_faces
);
27181 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
27182 Fcons (intern_c_string ("void-variable"), Qnil
)),
27184 staticpro (&list_of_error
);
27186 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
27187 staticpro (&Qlast_arrow_position
);
27188 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
27189 staticpro (&Qlast_arrow_string
);
27191 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
27192 staticpro (&Qoverlay_arrow_string
);
27193 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
27194 staticpro (&Qoverlay_arrow_bitmap
);
27196 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
27197 staticpro (&echo_buffer
[0]);
27198 staticpro (&echo_buffer
[1]);
27200 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
27201 staticpro (&echo_area_buffer
[0]);
27202 staticpro (&echo_area_buffer
[1]);
27204 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
27205 staticpro (&Vmessages_buffer_name
);
27207 mode_line_proptrans_alist
= Qnil
;
27208 staticpro (&mode_line_proptrans_alist
);
27209 mode_line_string_list
= Qnil
;
27210 staticpro (&mode_line_string_list
);
27211 mode_line_string_face
= Qnil
;
27212 staticpro (&mode_line_string_face
);
27213 mode_line_string_face_prop
= Qnil
;
27214 staticpro (&mode_line_string_face_prop
);
27215 Vmode_line_unwind_vector
= Qnil
;
27216 staticpro (&Vmode_line_unwind_vector
);
27218 help_echo_string
= Qnil
;
27219 staticpro (&help_echo_string
);
27220 help_echo_object
= Qnil
;
27221 staticpro (&help_echo_object
);
27222 help_echo_window
= Qnil
;
27223 staticpro (&help_echo_window
);
27224 previous_help_echo_string
= Qnil
;
27225 staticpro (&previous_help_echo_string
);
27226 help_echo_pos
= -1;
27228 Qright_to_left
= intern_c_string ("right-to-left");
27229 staticpro (&Qright_to_left
);
27230 Qleft_to_right
= intern_c_string ("left-to-right");
27231 staticpro (&Qleft_to_right
);
27233 #ifdef HAVE_WINDOW_SYSTEM
27234 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
27235 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
27236 For example, if a block cursor is over a tab, it will be drawn as
27237 wide as that tab on the display. */);
27238 x_stretch_cursor_p
= 0;
27241 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
27242 doc
: /* *Non-nil means highlight trailing whitespace.
27243 The face used for trailing whitespace is `trailing-whitespace'. */);
27244 Vshow_trailing_whitespace
= Qnil
;
27246 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
27247 doc
: /* *Control highlighting of nobreak space and soft hyphen.
27248 A value of t means highlight the character itself (for nobreak space,
27249 use face `nobreak-space').
27250 A value of nil means no highlighting.
27251 Other values mean display the escape glyph followed by an ordinary
27252 space or ordinary hyphen. */);
27253 Vnobreak_char_display
= Qt
;
27255 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
27256 doc
: /* *The pointer shape to show in void text areas.
27257 A value of nil means to show the text pointer. Other options are `arrow',
27258 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
27259 Vvoid_text_area_pointer
= Qarrow
;
27261 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
27262 doc
: /* Non-nil means don't actually do any redisplay.
27263 This is used for internal purposes. */);
27264 Vinhibit_redisplay
= Qnil
;
27266 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
27267 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
27268 Vglobal_mode_string
= Qnil
;
27270 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
27271 doc
: /* Marker for where to display an arrow on top of the buffer text.
27272 This must be the beginning of a line in order to work.
27273 See also `overlay-arrow-string'. */);
27274 Voverlay_arrow_position
= Qnil
;
27276 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
27277 doc
: /* String to display as an arrow in non-window frames.
27278 See also `overlay-arrow-position'. */);
27279 Voverlay_arrow_string
= make_pure_c_string ("=>");
27281 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
27282 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
27283 The symbols on this list are examined during redisplay to determine
27284 where to display overlay arrows. */);
27285 Voverlay_arrow_variable_list
27286 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
27288 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
27289 doc
: /* *The number of lines to try scrolling a window by when point moves out.
27290 If that fails to bring point back on frame, point is centered instead.
27291 If this is zero, point is always centered after it moves off frame.
27292 If you want scrolling to always be a line at a time, you should set
27293 `scroll-conservatively' to a large value rather than set this to 1. */);
27295 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
27296 doc
: /* *Scroll up to this many lines, to bring point back on screen.
27297 If point moves off-screen, redisplay will scroll by up to
27298 `scroll-conservatively' lines in order to bring point just barely
27299 onto the screen again. If that cannot be done, then redisplay
27300 recenters point as usual.
27302 If the value is greater than 100, redisplay will never recenter point,
27303 but will always scroll just enough text to bring point into view, even
27304 if you move far away.
27306 A value of zero means always recenter point if it moves off screen. */);
27307 scroll_conservatively
= 0;
27309 DEFVAR_INT ("scroll-margin", scroll_margin
,
27310 doc
: /* *Number of lines of margin at the top and bottom of a window.
27311 Recenter the window whenever point gets within this many lines
27312 of the top or bottom of the window. */);
27315 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
27316 doc
: /* Pixels per inch value for non-window system displays.
27317 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
27318 Vdisplay_pixels_per_inch
= make_float (72.0);
27321 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
27324 DEFVAR_LISP ("truncate-partial-width-windows",
27325 Vtruncate_partial_width_windows
,
27326 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
27327 For an integer value, truncate lines in each window narrower than the
27328 full frame width, provided the window width is less than that integer;
27329 otherwise, respect the value of `truncate-lines'.
27331 For any other non-nil value, truncate lines in all windows that do
27332 not span the full frame width.
27334 A value of nil means to respect the value of `truncate-lines'.
27336 If `word-wrap' is enabled, you might want to reduce this. */);
27337 Vtruncate_partial_width_windows
= make_number (50);
27339 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
27340 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
27341 Any other value means to use the appropriate face, `mode-line',
27342 `header-line', or `menu' respectively. */);
27343 mode_line_inverse_video
= 1;
27345 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
27346 doc
: /* *Maximum buffer size for which line number should be displayed.
27347 If the buffer is bigger than this, the line number does not appear
27348 in the mode line. A value of nil means no limit. */);
27349 Vline_number_display_limit
= Qnil
;
27351 DEFVAR_INT ("line-number-display-limit-width",
27352 line_number_display_limit_width
,
27353 doc
: /* *Maximum line width (in characters) for line number display.
27354 If the average length of the lines near point is bigger than this, then the
27355 line number may be omitted from the mode line. */);
27356 line_number_display_limit_width
= 200;
27358 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
27359 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
27360 highlight_nonselected_windows
= 0;
27362 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
27363 doc
: /* Non-nil if more than one frame is visible on this display.
27364 Minibuffer-only frames don't count, but iconified frames do.
27365 This variable is not guaranteed to be accurate except while processing
27366 `frame-title-format' and `icon-title-format'. */);
27368 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
27369 doc
: /* Template for displaying the title bar of visible frames.
27370 \(Assuming the window manager supports this feature.)
27372 This variable has the same structure as `mode-line-format', except that
27373 the %c and %l constructs are ignored. It is used only on frames for
27374 which no explicit name has been set \(see `modify-frame-parameters'). */);
27376 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
27377 doc
: /* Template for displaying the title bar of an iconified frame.
27378 \(Assuming the window manager supports this feature.)
27379 This variable has the same structure as `mode-line-format' (which see),
27380 and is used only on frames for which no explicit name has been set
27381 \(see `modify-frame-parameters'). */);
27383 = Vframe_title_format
27384 = pure_cons (intern_c_string ("multiple-frames"),
27385 pure_cons (make_pure_c_string ("%b"),
27386 pure_cons (pure_cons (empty_unibyte_string
,
27387 pure_cons (intern_c_string ("invocation-name"),
27388 pure_cons (make_pure_c_string ("@"),
27389 pure_cons (intern_c_string ("system-name"),
27393 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
27394 doc
: /* Maximum number of lines to keep in the message log buffer.
27395 If nil, disable message logging. If t, log messages but don't truncate
27396 the buffer when it becomes large. */);
27397 Vmessage_log_max
= make_number (100);
27399 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
27400 doc
: /* Functions called before redisplay, if window sizes have changed.
27401 The value should be a list of functions that take one argument.
27402 Just before redisplay, for each frame, if any of its windows have changed
27403 size since the last redisplay, or have been split or deleted,
27404 all the functions in the list are called, with the frame as argument. */);
27405 Vwindow_size_change_functions
= Qnil
;
27407 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
27408 doc
: /* List of functions to call before redisplaying a window with scrolling.
27409 Each function is called with two arguments, the window and its new
27410 display-start position. Note that these functions are also called by
27411 `set-window-buffer'. Also note that the value of `window-end' is not
27412 valid when these functions are called. */);
27413 Vwindow_scroll_functions
= Qnil
;
27415 DEFVAR_LISP ("window-text-change-functions",
27416 Vwindow_text_change_functions
,
27417 doc
: /* Functions to call in redisplay when text in the window might change. */);
27418 Vwindow_text_change_functions
= Qnil
;
27420 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
27421 doc
: /* Functions called when redisplay of a window reaches the end trigger.
27422 Each function is called with two arguments, the window and the end trigger value.
27423 See `set-window-redisplay-end-trigger'. */);
27424 Vredisplay_end_trigger_functions
= Qnil
;
27426 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
27427 doc
: /* *Non-nil means autoselect window with mouse pointer.
27428 If nil, do not autoselect windows.
27429 A positive number means delay autoselection by that many seconds: a
27430 window is autoselected only after the mouse has remained in that
27431 window for the duration of the delay.
27432 A negative number has a similar effect, but causes windows to be
27433 autoselected only after the mouse has stopped moving. \(Because of
27434 the way Emacs compares mouse events, you will occasionally wait twice
27435 that time before the window gets selected.\)
27436 Any other value means to autoselect window instantaneously when the
27437 mouse pointer enters it.
27439 Autoselection selects the minibuffer only if it is active, and never
27440 unselects the minibuffer if it is active.
27442 When customizing this variable make sure that the actual value of
27443 `focus-follows-mouse' matches the behavior of your window manager. */);
27444 Vmouse_autoselect_window
= Qnil
;
27446 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
27447 doc
: /* *Non-nil means automatically resize tool-bars.
27448 This dynamically changes the tool-bar's height to the minimum height
27449 that is needed to make all tool-bar items visible.
27450 If value is `grow-only', the tool-bar's height is only increased
27451 automatically; to decrease the tool-bar height, use \\[recenter]. */);
27452 Vauto_resize_tool_bars
= Qt
;
27454 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
27455 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
27456 auto_raise_tool_bar_buttons_p
= 1;
27458 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
27459 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
27460 make_cursor_line_fully_visible_p
= 1;
27462 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
27463 doc
: /* *Border below tool-bar in pixels.
27464 If an integer, use it as the height of the border.
27465 If it is one of `internal-border-width' or `border-width', use the
27466 value of the corresponding frame parameter.
27467 Otherwise, no border is added below the tool-bar. */);
27468 Vtool_bar_border
= Qinternal_border_width
;
27470 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
27471 doc
: /* *Margin around tool-bar buttons in pixels.
27472 If an integer, use that for both horizontal and vertical margins.
27473 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
27474 HORZ specifying the horizontal margin, and VERT specifying the
27475 vertical margin. */);
27476 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
27478 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
27479 doc
: /* *Relief thickness of tool-bar buttons. */);
27480 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
27482 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
27483 doc
: /* Tool bar style to use.
27485 image - show images only
27486 text - show text only
27487 both - show both, text below image
27488 both-horiz - show text to the right of the image
27489 text-image-horiz - show text to the left of the image
27490 any other - use system default or image if no system default. */);
27491 Vtool_bar_style
= Qnil
;
27493 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
27494 doc
: /* *Maximum number of characters a label can have to be shown.
27495 The tool bar style must also show labels for this to have any effect, see
27496 `tool-bar-style'. */);
27497 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
27499 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
27500 doc
: /* List of functions to call to fontify regions of text.
27501 Each function is called with one argument POS. Functions must
27502 fontify a region starting at POS in the current buffer, and give
27503 fontified regions the property `fontified'. */);
27504 Vfontification_functions
= Qnil
;
27505 Fmake_variable_buffer_local (Qfontification_functions
);
27507 DEFVAR_BOOL ("unibyte-display-via-language-environment",
27508 unibyte_display_via_language_environment
,
27509 doc
: /* *Non-nil means display unibyte text according to language environment.
27510 Specifically, this means that raw bytes in the range 160-255 decimal
27511 are displayed by converting them to the equivalent multibyte characters
27512 according to the current language environment. As a result, they are
27513 displayed according to the current fontset.
27515 Note that this variable affects only how these bytes are displayed,
27516 but does not change the fact they are interpreted as raw bytes. */);
27517 unibyte_display_via_language_environment
= 0;
27519 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
27520 doc
: /* *Maximum height for resizing mini-windows.
27521 If a float, it specifies a fraction of the mini-window frame's height.
27522 If an integer, it specifies a number of lines. */);
27523 Vmax_mini_window_height
= make_float (0.25);
27525 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
27526 doc
: /* *How to resize mini-windows.
27527 A value of nil means don't automatically resize mini-windows.
27528 A value of t means resize them to fit the text displayed in them.
27529 A value of `grow-only', the default, means let mini-windows grow
27530 only, until their display becomes empty, at which point the windows
27531 go back to their normal size. */);
27532 Vresize_mini_windows
= Qgrow_only
;
27534 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
27535 doc
: /* Alist specifying how to blink the cursor off.
27536 Each element has the form (ON-STATE . OFF-STATE). Whenever the
27537 `cursor-type' frame-parameter or variable equals ON-STATE,
27538 comparing using `equal', Emacs uses OFF-STATE to specify
27539 how to blink it off. ON-STATE and OFF-STATE are values for
27540 the `cursor-type' frame parameter.
27542 If a frame's ON-STATE has no entry in this list,
27543 the frame's other specifications determine how to blink the cursor off. */);
27544 Vblink_cursor_alist
= Qnil
;
27546 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
27547 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
27548 If non-nil, windows are automatically scrolled horizontally to make
27549 point visible. */);
27550 automatic_hscrolling_p
= 1;
27551 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
27552 staticpro (&Qauto_hscroll_mode
);
27554 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
27555 doc
: /* *How many columns away from the window edge point is allowed to get
27556 before automatic hscrolling will horizontally scroll the window. */);
27557 hscroll_margin
= 5;
27559 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
27560 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
27561 When point is less than `hscroll-margin' columns from the window
27562 edge, automatic hscrolling will scroll the window by the amount of columns
27563 determined by this variable. If its value is a positive integer, scroll that
27564 many columns. If it's a positive floating-point number, it specifies the
27565 fraction of the window's width to scroll. If it's nil or zero, point will be
27566 centered horizontally after the scroll. Any other value, including negative
27567 numbers, are treated as if the value were zero.
27569 Automatic hscrolling always moves point outside the scroll margin, so if
27570 point was more than scroll step columns inside the margin, the window will
27571 scroll more than the value given by the scroll step.
27573 Note that the lower bound for automatic hscrolling specified by `scroll-left'
27574 and `scroll-right' overrides this variable's effect. */);
27575 Vhscroll_step
= make_number (0);
27577 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
27578 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
27579 Bind this around calls to `message' to let it take effect. */);
27580 message_truncate_lines
= 0;
27582 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
27583 doc
: /* Normal hook run to update the menu bar definitions.
27584 Redisplay runs this hook before it redisplays the menu bar.
27585 This is used to update submenus such as Buffers,
27586 whose contents depend on various data. */);
27587 Vmenu_bar_update_hook
= Qnil
;
27589 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
27590 doc
: /* Frame for which we are updating a menu.
27591 The enable predicate for a menu binding should check this variable. */);
27592 Vmenu_updating_frame
= Qnil
;
27594 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
27595 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
27596 inhibit_menubar_update
= 0;
27598 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
27599 doc
: /* Prefix prepended to all continuation lines at display time.
27600 The value may be a string, an image, or a stretch-glyph; it is
27601 interpreted in the same way as the value of a `display' text property.
27603 This variable is overridden by any `wrap-prefix' text or overlay
27606 To add a prefix to non-continuation lines, use `line-prefix'. */);
27607 Vwrap_prefix
= Qnil
;
27608 staticpro (&Qwrap_prefix
);
27609 Qwrap_prefix
= intern_c_string ("wrap-prefix");
27610 Fmake_variable_buffer_local (Qwrap_prefix
);
27612 DEFVAR_LISP ("line-prefix", Vline_prefix
,
27613 doc
: /* Prefix prepended to all non-continuation lines at display time.
27614 The value may be a string, an image, or a stretch-glyph; it is
27615 interpreted in the same way as the value of a `display' text property.
27617 This variable is overridden by any `line-prefix' text or overlay
27620 To add a prefix to continuation lines, use `wrap-prefix'. */);
27621 Vline_prefix
= Qnil
;
27622 staticpro (&Qline_prefix
);
27623 Qline_prefix
= intern_c_string ("line-prefix");
27624 Fmake_variable_buffer_local (Qline_prefix
);
27626 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
27627 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
27628 inhibit_eval_during_redisplay
= 0;
27630 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
27631 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
27632 inhibit_free_realized_faces
= 0;
27635 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
27636 doc
: /* Inhibit try_window_id display optimization. */);
27637 inhibit_try_window_id
= 0;
27639 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
27640 doc
: /* Inhibit try_window_reusing display optimization. */);
27641 inhibit_try_window_reusing
= 0;
27643 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
27644 doc
: /* Inhibit try_cursor_movement display optimization. */);
27645 inhibit_try_cursor_movement
= 0;
27646 #endif /* GLYPH_DEBUG */
27648 DEFVAR_INT ("overline-margin", overline_margin
,
27649 doc
: /* *Space between overline and text, in pixels.
27650 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
27651 margin to the caracter height. */);
27652 overline_margin
= 2;
27654 DEFVAR_INT ("underline-minimum-offset",
27655 underline_minimum_offset
,
27656 doc
: /* Minimum distance between baseline and underline.
27657 This can improve legibility of underlined text at small font sizes,
27658 particularly when using variable `x-use-underline-position-properties'
27659 with fonts that specify an UNDERLINE_POSITION relatively close to the
27660 baseline. The default value is 1. */);
27661 underline_minimum_offset
= 1;
27663 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
27664 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
27665 This feature only works when on a window system that can change
27666 cursor shapes. */);
27667 display_hourglass_p
= 1;
27669 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
27670 doc
: /* *Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
27671 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
27673 hourglass_atimer
= NULL
;
27674 hourglass_shown_p
= 0;
27676 DEFSYM (Qglyphless_char
, "glyphless-char");
27677 DEFSYM (Qhex_code
, "hex-code");
27678 DEFSYM (Qempty_box
, "empty-box");
27679 DEFSYM (Qthin_space
, "thin-space");
27680 DEFSYM (Qzero_width
, "zero-width");
27682 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
27683 /* Intern this now in case it isn't already done.
27684 Setting this variable twice is harmless.
27685 But don't staticpro it here--that is done in alloc.c. */
27686 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
27687 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
27689 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
27690 doc
: /* Char-table defining glyphless characters.
27691 Each element, if non-nil, should be one of the following:
27692 an ASCII acronym string: display this string in a box
27693 `hex-code': display the hexadecimal code of a character in a box
27694 `empty-box': display as an empty box
27695 `thin-space': display as 1-pixel width space
27696 `zero-width': don't display
27697 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
27698 display method for graphical terminals and text terminals respectively.
27699 GRAPHICAL and TEXT should each have one of the values listed above.
27701 The char-table has one extra slot to control the display of a character for
27702 which no font is found. This slot only takes effect on graphical terminals.
27703 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
27704 `thin-space'. The default is `empty-box'. */);
27705 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
27706 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
27711 /* Initialize this module when Emacs starts. */
27716 Lisp_Object root_window
;
27717 struct window
*mini_w
;
27719 current_header_line_height
= current_mode_line_height
= -1;
27721 CHARPOS (this_line_start_pos
) = 0;
27723 mini_w
= XWINDOW (minibuf_window
);
27724 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
27725 echo_area_window
= minibuf_window
;
27727 if (!noninteractive
)
27729 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
27732 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
27733 set_window_height (root_window
,
27734 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
27736 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
27737 set_window_height (minibuf_window
, 1, 0);
27739 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
27740 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
27742 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
27743 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
27744 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
27746 /* The default ellipsis glyphs `...'. */
27747 for (i
= 0; i
< 3; ++i
)
27748 default_invis_vector
[i
] = make_number ('.');
27752 /* Allocate the buffer for frame titles.
27753 Also used for `format-mode-line'. */
27755 mode_line_noprop_buf
= (char *) xmalloc (size
);
27756 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
27757 mode_line_noprop_ptr
= mode_line_noprop_buf
;
27758 mode_line_target
= MODE_LINE_DISPLAY
;
27761 help_echo_showing_p
= 0;
27764 /* Since w32 does not support atimers, it defines its own implementation of
27765 the following three functions in w32fns.c. */
27768 /* Platform-independent portion of hourglass implementation. */
27770 /* Return non-zero if houglass timer has been started or hourglass is shown. */
27772 hourglass_started (void)
27774 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
27777 /* Cancel a currently active hourglass timer, and start a new one. */
27779 start_hourglass (void)
27781 #if defined (HAVE_WINDOW_SYSTEM)
27783 int secs
, usecs
= 0;
27785 cancel_hourglass ();
27787 if (INTEGERP (Vhourglass_delay
)
27788 && XINT (Vhourglass_delay
) > 0)
27789 secs
= XFASTINT (Vhourglass_delay
);
27790 else if (FLOATP (Vhourglass_delay
)
27791 && XFLOAT_DATA (Vhourglass_delay
) > 0)
27794 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
27795 secs
= XFASTINT (tem
);
27796 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
27799 secs
= DEFAULT_HOURGLASS_DELAY
;
27801 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
27802 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
27803 show_hourglass
, NULL
);
27808 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
27811 cancel_hourglass (void)
27813 #if defined (HAVE_WINDOW_SYSTEM)
27814 if (hourglass_atimer
)
27816 cancel_atimer (hourglass_atimer
);
27817 hourglass_atimer
= NULL
;
27820 if (hourglass_shown_p
)
27824 #endif /* ! WINDOWSNT */