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 int single_display_spec_intangible_p (Lisp_Object
);
787 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
788 static void ensure_echo_area_buffers (void);
789 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
790 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
791 static int with_echo_area_buffer (struct window
*, int,
792 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
793 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
794 static void clear_garbaged_frames (void);
795 static int current_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
796 static void pop_message (void);
797 static int truncate_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
798 static void set_message (const char *, Lisp_Object
, EMACS_INT
, int);
799 static int set_message_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
800 static int display_echo_area (struct window
*);
801 static int display_echo_area_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
802 static int resize_mini_window_1 (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
);
803 static Lisp_Object
unwind_redisplay (Lisp_Object
);
804 static int string_char_and_length (const unsigned char *, int *);
805 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
807 static int compute_window_start_on_continuation_line (struct window
*);
808 static Lisp_Object
safe_eval_handler (Lisp_Object
);
809 static void insert_left_trunc_glyphs (struct it
*);
810 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
812 static void extend_face_to_end_of_line (struct it
*);
813 static int append_space_for_newline (struct it
*, int);
814 static int cursor_row_fully_visible_p (struct window
*, int, int);
815 static int try_scrolling (Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int);
816 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
817 static int trailing_whitespace_p (EMACS_INT
);
818 static unsigned long int message_log_check_duplicate (EMACS_INT
, EMACS_INT
);
819 static void push_it (struct it
*, struct text_pos
*);
820 static void pop_it (struct it
*);
821 static void sync_frame_with_window_matrix_rows (struct window
*);
822 static void select_frame_for_redisplay (Lisp_Object
);
823 static void redisplay_internal (void);
824 static int echo_area_display (int);
825 static void redisplay_windows (Lisp_Object
);
826 static void redisplay_window (Lisp_Object
, int);
827 static Lisp_Object
redisplay_window_error (Lisp_Object
);
828 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
829 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
830 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
831 struct glyph_matrix
*, EMACS_INT
, EMACS_INT
,
833 static int update_menu_bar (struct frame
*, int, int);
834 static int try_window_reusing_current_matrix (struct window
*);
835 static int try_window_id (struct window
*);
836 static int display_line (struct it
*);
837 static int display_mode_lines (struct window
*);
838 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
839 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
840 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
841 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
842 static void display_menu_bar (struct window
*);
843 static EMACS_INT
display_count_lines (EMACS_INT
, EMACS_INT
, EMACS_INT
,
845 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
846 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int);
847 static void compute_line_metrics (struct it
*);
848 static void run_redisplay_end_trigger_hook (struct it
*);
849 static int get_overlay_strings (struct it
*, EMACS_INT
);
850 static int get_overlay_strings_1 (struct it
*, EMACS_INT
, int);
851 static void next_overlay_string (struct it
*);
852 static void reseat (struct it
*, struct text_pos
, int);
853 static void reseat_1 (struct it
*, struct text_pos
, int);
854 static void back_to_previous_visible_line_start (struct it
*);
855 void reseat_at_previous_visible_line_start (struct it
*);
856 static void reseat_at_next_visible_line_start (struct it
*, int);
857 static int next_element_from_ellipsis (struct it
*);
858 static int next_element_from_display_vector (struct it
*);
859 static int next_element_from_string (struct it
*);
860 static int next_element_from_c_string (struct it
*);
861 static int next_element_from_buffer (struct it
*);
862 static int next_element_from_composition (struct it
*);
863 static int next_element_from_image (struct it
*);
864 static int next_element_from_stretch (struct it
*);
865 static void load_overlay_strings (struct it
*, EMACS_INT
);
866 static int init_from_display_pos (struct it
*, struct window
*,
867 struct display_pos
*);
868 static void reseat_to_string (struct it
*, const char *,
869 Lisp_Object
, EMACS_INT
, EMACS_INT
, int, int);
870 static int get_next_display_element (struct it
*);
871 static enum move_it_result
872 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
873 enum move_operation_enum
);
874 void move_it_vertically_backward (struct it
*, int);
875 static void init_to_row_start (struct it
*, struct window
*,
877 static int init_to_row_end (struct it
*, struct window
*,
879 static void back_to_previous_line_start (struct it
*);
880 static int forward_to_next_line_start (struct it
*, int *);
881 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
882 Lisp_Object
, EMACS_INT
);
883 static struct text_pos
string_pos (EMACS_INT
, Lisp_Object
);
884 static struct text_pos
c_string_pos (EMACS_INT
, const char *, int);
885 static EMACS_INT
number_of_chars (const char *, int);
886 static void compute_stop_pos (struct it
*);
887 static void compute_string_pos (struct text_pos
*, struct text_pos
,
889 static int face_before_or_after_it_pos (struct it
*, int);
890 static EMACS_INT
next_overlay_change (EMACS_INT
);
891 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
892 Lisp_Object
, struct text_pos
*, EMACS_INT
, int);
893 static int handle_single_display_spec (struct it
*, Lisp_Object
,
894 Lisp_Object
, Lisp_Object
,
895 struct text_pos
*, EMACS_INT
, int, int);
896 static int underlying_face_id (struct it
*);
897 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
900 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
901 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
903 #ifdef HAVE_WINDOW_SYSTEM
905 static void x_consider_frame_title (Lisp_Object
);
906 static int tool_bar_lines_needed (struct frame
*, int *);
907 static void update_tool_bar (struct frame
*, int);
908 static void build_desired_tool_bar_string (struct frame
*f
);
909 static int redisplay_tool_bar (struct frame
*);
910 static void display_tool_bar_line (struct it
*, int);
911 static void notice_overwritten_cursor (struct window
*,
914 static void append_stretch_glyph (struct it
*, Lisp_Object
,
918 #endif /* HAVE_WINDOW_SYSTEM */
920 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
921 static int coords_in_mouse_face_p (struct window
*, int, int);
925 /***********************************************************************
926 Window display dimensions
927 ***********************************************************************/
929 /* Return the bottom boundary y-position for text lines in window W.
930 This is the first y position at which a line cannot start.
931 It is relative to the top of the window.
933 This is the height of W minus the height of a mode line, if any. */
936 window_text_bottom_y (struct window
*w
)
938 int height
= WINDOW_TOTAL_HEIGHT (w
);
940 if (WINDOW_WANTS_MODELINE_P (w
))
941 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
945 /* Return the pixel width of display area AREA of window W. AREA < 0
946 means return the total width of W, not including fringes to
947 the left and right of the window. */
950 window_box_width (struct window
*w
, int area
)
952 int cols
= XFASTINT (w
->total_cols
);
955 if (!w
->pseudo_window_p
)
957 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
959 if (area
== TEXT_AREA
)
961 if (INTEGERP (w
->left_margin_cols
))
962 cols
-= XFASTINT (w
->left_margin_cols
);
963 if (INTEGERP (w
->right_margin_cols
))
964 cols
-= XFASTINT (w
->right_margin_cols
);
965 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
967 else if (area
== LEFT_MARGIN_AREA
)
969 cols
= (INTEGERP (w
->left_margin_cols
)
970 ? XFASTINT (w
->left_margin_cols
) : 0);
973 else if (area
== RIGHT_MARGIN_AREA
)
975 cols
= (INTEGERP (w
->right_margin_cols
)
976 ? XFASTINT (w
->right_margin_cols
) : 0);
981 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
985 /* Return the pixel height of the display area of window W, not
986 including mode lines of W, if any. */
989 window_box_height (struct window
*w
)
991 struct frame
*f
= XFRAME (w
->frame
);
992 int height
= WINDOW_TOTAL_HEIGHT (w
);
994 xassert (height
>= 0);
996 /* Note: the code below that determines the mode-line/header-line
997 height is essentially the same as that contained in the macro
998 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
999 the appropriate glyph row has its `mode_line_p' flag set,
1000 and if it doesn't, uses estimate_mode_line_height instead. */
1002 if (WINDOW_WANTS_MODELINE_P (w
))
1004 struct glyph_row
*ml_row
1005 = (w
->current_matrix
&& w
->current_matrix
->rows
1006 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1008 if (ml_row
&& ml_row
->mode_line_p
)
1009 height
-= ml_row
->height
;
1011 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1014 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1016 struct glyph_row
*hl_row
1017 = (w
->current_matrix
&& w
->current_matrix
->rows
1018 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1020 if (hl_row
&& hl_row
->mode_line_p
)
1021 height
-= hl_row
->height
;
1023 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1026 /* With a very small font and a mode-line that's taller than
1027 default, we might end up with a negative height. */
1028 return max (0, height
);
1031 /* Return the window-relative coordinate of the left edge of display
1032 area AREA of window W. AREA < 0 means return the left edge of the
1033 whole window, to the right of the left fringe of W. */
1036 window_box_left_offset (struct window
*w
, int area
)
1040 if (w
->pseudo_window_p
)
1043 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1045 if (area
== TEXT_AREA
)
1046 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1047 + window_box_width (w
, LEFT_MARGIN_AREA
));
1048 else if (area
== RIGHT_MARGIN_AREA
)
1049 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1050 + window_box_width (w
, LEFT_MARGIN_AREA
)
1051 + window_box_width (w
, TEXT_AREA
)
1052 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1054 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1055 else if (area
== LEFT_MARGIN_AREA
1056 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1057 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1063 /* Return the window-relative coordinate of the right edge of display
1064 area AREA of window W. AREA < 0 means return the right edge of the
1065 whole window, to the left of the right fringe of W. */
1068 window_box_right_offset (struct window
*w
, int area
)
1070 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1073 /* Return the frame-relative coordinate of the left edge of display
1074 area AREA of window W. AREA < 0 means return the left edge of the
1075 whole window, to the right of the left fringe of W. */
1078 window_box_left (struct window
*w
, int area
)
1080 struct frame
*f
= XFRAME (w
->frame
);
1083 if (w
->pseudo_window_p
)
1084 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1086 x
= (WINDOW_LEFT_EDGE_X (w
)
1087 + window_box_left_offset (w
, area
));
1093 /* Return the frame-relative coordinate of the right edge of display
1094 area AREA of window W. AREA < 0 means return the right edge of the
1095 whole window, to the left of the right fringe of W. */
1098 window_box_right (struct window
*w
, int area
)
1100 return window_box_left (w
, area
) + window_box_width (w
, area
);
1103 /* Get the bounding box of the display area AREA of window W, without
1104 mode lines, in frame-relative coordinates. AREA < 0 means the
1105 whole window, not including the left and right fringes of
1106 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1107 coordinates of the upper-left corner of the box. Return in
1108 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1111 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1112 int *box_width
, int *box_height
)
1115 *box_width
= window_box_width (w
, area
);
1117 *box_height
= window_box_height (w
);
1119 *box_x
= window_box_left (w
, area
);
1122 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1123 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1124 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1129 /* Get the bounding box of the display area AREA of window W, without
1130 mode lines. AREA < 0 means the whole window, not including the
1131 left and right fringe of the window. Return in *TOP_LEFT_X
1132 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1133 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1134 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1138 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1139 int *bottom_right_x
, int *bottom_right_y
)
1141 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1143 *bottom_right_x
+= *top_left_x
;
1144 *bottom_right_y
+= *top_left_y
;
1149 /***********************************************************************
1151 ***********************************************************************/
1153 /* Return the bottom y-position of the line the iterator IT is in.
1154 This can modify IT's settings. */
1157 line_bottom_y (struct it
*it
)
1159 int line_height
= it
->max_ascent
+ it
->max_descent
;
1160 int line_top_y
= it
->current_y
;
1162 if (line_height
== 0)
1165 line_height
= last_height
;
1166 else if (IT_CHARPOS (*it
) < ZV
)
1168 move_it_by_lines (it
, 1);
1169 line_height
= (it
->max_ascent
|| it
->max_descent
1170 ? it
->max_ascent
+ it
->max_descent
1175 struct glyph_row
*row
= it
->glyph_row
;
1177 /* Use the default character height. */
1178 it
->glyph_row
= NULL
;
1179 it
->what
= IT_CHARACTER
;
1182 PRODUCE_GLYPHS (it
);
1183 line_height
= it
->ascent
+ it
->descent
;
1184 it
->glyph_row
= row
;
1188 return line_top_y
+ line_height
;
1192 /* Return 1 if position CHARPOS is visible in window W.
1193 CHARPOS < 0 means return info about WINDOW_END position.
1194 If visible, set *X and *Y to pixel coordinates of top left corner.
1195 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1196 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1199 pos_visible_p (struct window
*w
, EMACS_INT charpos
, int *x
, int *y
,
1200 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1203 struct text_pos top
;
1205 struct buffer
*old_buffer
= NULL
;
1207 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1210 if (XBUFFER (w
->buffer
) != current_buffer
)
1212 old_buffer
= current_buffer
;
1213 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1216 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1218 /* Compute exact mode line heights. */
1219 if (WINDOW_WANTS_MODELINE_P (w
))
1220 current_mode_line_height
1221 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1222 BVAR (current_buffer
, mode_line_format
));
1224 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1225 current_header_line_height
1226 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1227 BVAR (current_buffer
, header_line_format
));
1229 start_display (&it
, w
, top
);
1230 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1231 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1233 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1235 /* We have reached CHARPOS, or passed it. How the call to
1236 move_it_to can overshoot: (i) If CHARPOS is on invisible
1237 text, move_it_to stops at the end of the invisible text,
1238 after CHARPOS. (ii) If CHARPOS is in a display vector,
1239 move_it_to stops on its last glyph. */
1240 int top_x
= it
.current_x
;
1241 int top_y
= it
.current_y
;
1242 enum it_method it_method
= it
.method
;
1243 /* Calling line_bottom_y may change it.method, it.position, etc. */
1244 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1245 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1247 if (top_y
< window_top_y
)
1248 visible_p
= bottom_y
> window_top_y
;
1249 else if (top_y
< it
.last_visible_y
)
1253 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1255 /* We stopped on the last glyph of a display vector.
1256 Try and recompute. Hack alert! */
1257 if (charpos
< 2 || top
.charpos
>= charpos
)
1258 top_x
= it
.glyph_row
->x
;
1262 start_display (&it2
, w
, top
);
1263 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1264 get_next_display_element (&it2
);
1265 PRODUCE_GLYPHS (&it2
);
1266 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1267 || it2
.current_x
> it2
.last_visible_x
)
1268 top_x
= it
.glyph_row
->x
;
1271 top_x
= it2
.current_x
;
1272 top_y
= it2
.current_y
;
1278 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1279 *rtop
= max (0, window_top_y
- top_y
);
1280 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1281 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1282 - max (top_y
, window_top_y
)));
1291 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1292 move_it_by_lines (&it
, 1);
1293 if (charpos
< IT_CHARPOS (it
)
1294 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1297 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1299 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1300 *rtop
= max (0, -it2
.current_y
);
1301 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1302 - it
.last_visible_y
));
1303 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1305 - max (it2
.current_y
,
1306 WINDOW_HEADER_LINE_HEIGHT (w
))));
1312 set_buffer_internal_1 (old_buffer
);
1314 current_header_line_height
= current_mode_line_height
= -1;
1316 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1317 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1320 /* Debugging code. */
1322 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1323 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1325 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1332 /* Return the next character from STR. Return in *LEN the length of
1333 the character. This is like STRING_CHAR_AND_LENGTH but never
1334 returns an invalid character. If we find one, we return a `?', but
1335 with the length of the invalid character. */
1338 string_char_and_length (const unsigned char *str
, int *len
)
1342 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1343 if (!CHAR_VALID_P (c
, 1))
1344 /* We may not change the length here because other places in Emacs
1345 don't use this function, i.e. they silently accept invalid
1354 /* Given a position POS containing a valid character and byte position
1355 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1357 static struct text_pos
1358 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, EMACS_INT nchars
)
1360 xassert (STRINGP (string
) && nchars
>= 0);
1362 if (STRING_MULTIBYTE (string
))
1364 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1369 string_char_and_length (p
, &len
);
1372 BYTEPOS (pos
) += len
;
1376 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1382 /* Value is the text position, i.e. character and byte position,
1383 for character position CHARPOS in STRING. */
1385 static INLINE
struct text_pos
1386 string_pos (EMACS_INT charpos
, Lisp_Object string
)
1388 struct text_pos pos
;
1389 xassert (STRINGP (string
));
1390 xassert (charpos
>= 0);
1391 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1396 /* Value is a text position, i.e. character and byte position, for
1397 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1398 means recognize multibyte characters. */
1400 static struct text_pos
1401 c_string_pos (EMACS_INT charpos
, const char *s
, int multibyte_p
)
1403 struct text_pos pos
;
1405 xassert (s
!= NULL
);
1406 xassert (charpos
>= 0);
1412 SET_TEXT_POS (pos
, 0, 0);
1415 string_char_and_length ((const unsigned char *) s
, &len
);
1418 BYTEPOS (pos
) += len
;
1422 SET_TEXT_POS (pos
, charpos
, charpos
);
1428 /* Value is the number of characters in C string S. MULTIBYTE_P
1429 non-zero means recognize multibyte characters. */
1432 number_of_chars (const char *s
, int multibyte_p
)
1438 EMACS_INT rest
= strlen (s
);
1440 const unsigned char *p
= (const unsigned char *) s
;
1442 for (nchars
= 0; rest
> 0; ++nchars
)
1444 string_char_and_length (p
, &len
);
1445 rest
-= len
, p
+= len
;
1449 nchars
= strlen (s
);
1455 /* Compute byte position NEWPOS->bytepos corresponding to
1456 NEWPOS->charpos. POS is a known position in string STRING.
1457 NEWPOS->charpos must be >= POS.charpos. */
1460 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1462 xassert (STRINGP (string
));
1463 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1465 if (STRING_MULTIBYTE (string
))
1466 *newpos
= string_pos_nchars_ahead (pos
, string
,
1467 CHARPOS (*newpos
) - CHARPOS (pos
));
1469 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1473 Return an estimation of the pixel height of mode or header lines on
1474 frame F. FACE_ID specifies what line's height to estimate. */
1477 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1479 #ifdef HAVE_WINDOW_SYSTEM
1480 if (FRAME_WINDOW_P (f
))
1482 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1484 /* This function is called so early when Emacs starts that the face
1485 cache and mode line face are not yet initialized. */
1486 if (FRAME_FACE_CACHE (f
))
1488 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1492 height
= FONT_HEIGHT (face
->font
);
1493 if (face
->box_line_width
> 0)
1494 height
+= 2 * face
->box_line_width
;
1505 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1506 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1507 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1508 not force the value into range. */
1511 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1512 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1515 #ifdef HAVE_WINDOW_SYSTEM
1516 if (FRAME_WINDOW_P (f
))
1518 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1519 even for negative values. */
1521 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1523 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1525 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1526 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1529 STORE_NATIVE_RECT (*bounds
,
1530 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1531 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1532 FRAME_COLUMN_WIDTH (f
) - 1,
1533 FRAME_LINE_HEIGHT (f
) - 1);
1539 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1540 pix_x
= FRAME_TOTAL_COLS (f
);
1544 else if (pix_y
> FRAME_LINES (f
))
1545 pix_y
= FRAME_LINES (f
);
1555 /* Find the glyph under window-relative coordinates X/Y in window W.
1556 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1557 strings. Return in *HPOS and *VPOS the row and column number of
1558 the glyph found. Return in *AREA the glyph area containing X.
1559 Value is a pointer to the glyph found or null if X/Y is not on
1560 text, or we can't tell because W's current matrix is not up to
1565 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1566 int *dx
, int *dy
, int *area
)
1568 struct glyph
*glyph
, *end
;
1569 struct glyph_row
*row
= NULL
;
1572 /* Find row containing Y. Give up if some row is not enabled. */
1573 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1575 row
= MATRIX_ROW (w
->current_matrix
, i
);
1576 if (!row
->enabled_p
)
1578 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1585 /* Give up if Y is not in the window. */
1586 if (i
== w
->current_matrix
->nrows
)
1589 /* Get the glyph area containing X. */
1590 if (w
->pseudo_window_p
)
1597 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1599 *area
= LEFT_MARGIN_AREA
;
1600 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1602 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1605 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1609 *area
= RIGHT_MARGIN_AREA
;
1610 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1614 /* Find glyph containing X. */
1615 glyph
= row
->glyphs
[*area
];
1616 end
= glyph
+ row
->used
[*area
];
1618 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1620 x
-= glyph
->pixel_width
;
1630 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1633 *hpos
= glyph
- row
->glyphs
[*area
];
1637 /* Convert frame-relative x/y to coordinates relative to window W.
1638 Takes pseudo-windows into account. */
1641 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1643 if (w
->pseudo_window_p
)
1645 /* A pseudo-window is always full-width, and starts at the
1646 left edge of the frame, plus a frame border. */
1647 struct frame
*f
= XFRAME (w
->frame
);
1648 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1649 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1653 *x
-= WINDOW_LEFT_EDGE_X (w
);
1654 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1658 #ifdef HAVE_WINDOW_SYSTEM
1661 Return in RECTS[] at most N clipping rectangles for glyph string S.
1662 Return the number of stored rectangles. */
1665 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1672 if (s
->row
->full_width_p
)
1674 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1675 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1676 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1678 /* Unless displaying a mode or menu bar line, which are always
1679 fully visible, clip to the visible part of the row. */
1680 if (s
->w
->pseudo_window_p
)
1681 r
.height
= s
->row
->visible_height
;
1683 r
.height
= s
->height
;
1687 /* This is a text line that may be partially visible. */
1688 r
.x
= window_box_left (s
->w
, s
->area
);
1689 r
.width
= window_box_width (s
->w
, s
->area
);
1690 r
.height
= s
->row
->visible_height
;
1694 if (r
.x
< s
->clip_head
->x
)
1696 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1697 r
.width
-= s
->clip_head
->x
- r
.x
;
1700 r
.x
= s
->clip_head
->x
;
1703 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1705 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1706 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1711 /* If S draws overlapping rows, it's sufficient to use the top and
1712 bottom of the window for clipping because this glyph string
1713 intentionally draws over other lines. */
1714 if (s
->for_overlaps
)
1716 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1717 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1719 /* Alas, the above simple strategy does not work for the
1720 environments with anti-aliased text: if the same text is
1721 drawn onto the same place multiple times, it gets thicker.
1722 If the overlap we are processing is for the erased cursor, we
1723 take the intersection with the rectagle of the cursor. */
1724 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1726 XRectangle rc
, r_save
= r
;
1728 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1729 rc
.y
= s
->w
->phys_cursor
.y
;
1730 rc
.width
= s
->w
->phys_cursor_width
;
1731 rc
.height
= s
->w
->phys_cursor_height
;
1733 x_intersect_rectangles (&r_save
, &rc
, &r
);
1738 /* Don't use S->y for clipping because it doesn't take partially
1739 visible lines into account. For example, it can be negative for
1740 partially visible lines at the top of a window. */
1741 if (!s
->row
->full_width_p
1742 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1743 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1745 r
.y
= max (0, s
->row
->y
);
1748 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1750 /* If drawing the cursor, don't let glyph draw outside its
1751 advertised boundaries. Cleartype does this under some circumstances. */
1752 if (s
->hl
== DRAW_CURSOR
)
1754 struct glyph
*glyph
= s
->first_glyph
;
1759 r
.width
-= s
->x
- r
.x
;
1762 r
.width
= min (r
.width
, glyph
->pixel_width
);
1764 /* If r.y is below window bottom, ensure that we still see a cursor. */
1765 height
= min (glyph
->ascent
+ glyph
->descent
,
1766 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1767 max_y
= window_text_bottom_y (s
->w
) - height
;
1768 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1769 if (s
->ybase
- glyph
->ascent
> max_y
)
1776 /* Don't draw cursor glyph taller than our actual glyph. */
1777 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1778 if (height
< r
.height
)
1780 max_y
= r
.y
+ r
.height
;
1781 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1782 r
.height
= min (max_y
- r
.y
, height
);
1789 XRectangle r_save
= r
;
1791 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
1795 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1796 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1798 #ifdef CONVERT_FROM_XRECT
1799 CONVERT_FROM_XRECT (r
, *rects
);
1807 /* If we are processing overlapping and allowed to return
1808 multiple clipping rectangles, we exclude the row of the glyph
1809 string from the clipping rectangle. This is to avoid drawing
1810 the same text on the environment with anti-aliasing. */
1811 #ifdef CONVERT_FROM_XRECT
1814 XRectangle
*rs
= rects
;
1816 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1818 if (s
->for_overlaps
& OVERLAPS_PRED
)
1821 if (r
.y
+ r
.height
> row_y
)
1824 rs
[i
].height
= row_y
- r
.y
;
1830 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1833 if (r
.y
< row_y
+ s
->row
->visible_height
)
1835 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1837 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1838 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1847 #ifdef CONVERT_FROM_XRECT
1848 for (i
= 0; i
< n
; i
++)
1849 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1856 Return in *NR the clipping rectangle for glyph string S. */
1859 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
1861 get_glyph_string_clip_rects (s
, nr
, 1);
1866 Return the position and height of the phys cursor in window W.
1867 Set w->phys_cursor_width to width of phys cursor.
1871 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
1872 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
1874 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1875 int x
, y
, wd
, h
, h0
, y0
;
1877 /* Compute the width of the rectangle to draw. If on a stretch
1878 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1879 rectangle as wide as the glyph, but use a canonical character
1881 wd
= glyph
->pixel_width
- 1;
1882 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
1886 x
= w
->phys_cursor
.x
;
1893 if (glyph
->type
== STRETCH_GLYPH
1894 && !x_stretch_cursor_p
)
1895 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
1896 w
->phys_cursor_width
= wd
;
1898 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
1900 /* If y is below window bottom, ensure that we still see a cursor. */
1901 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
1903 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
1904 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
1906 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
1909 h
= max (h
- (y0
- y
) + 1, h0
);
1914 y0
= window_text_bottom_y (w
) - h0
;
1922 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
1923 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
1928 * Remember which glyph the mouse is over.
1932 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
1936 struct glyph_row
*r
, *gr
, *end_row
;
1937 enum window_part part
;
1938 enum glyph_row_area area
;
1939 int x
, y
, width
, height
;
1941 /* Try to determine frame pixel position and size of the glyph under
1942 frame pixel coordinates X/Y on frame F. */
1944 if (!f
->glyphs_initialized_p
1945 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
1948 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
1949 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
1953 w
= XWINDOW (window
);
1954 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
1955 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
1957 x
= window_relative_x_coord (w
, part
, gx
);
1958 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
1960 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1961 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1963 if (w
->pseudo_window_p
)
1966 part
= ON_MODE_LINE
; /* Don't adjust margin. */
1972 case ON_LEFT_MARGIN
:
1973 area
= LEFT_MARGIN_AREA
;
1976 case ON_RIGHT_MARGIN
:
1977 area
= RIGHT_MARGIN_AREA
;
1980 case ON_HEADER_LINE
:
1982 gr
= (part
== ON_HEADER_LINE
1983 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1984 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
1987 goto text_glyph_row_found
;
1994 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
1995 if (r
->y
+ r
->height
> y
)
2001 text_glyph_row_found
:
2004 struct glyph
*g
= gr
->glyphs
[area
];
2005 struct glyph
*end
= g
+ gr
->used
[area
];
2007 height
= gr
->height
;
2008 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2009 if (gx
+ g
->pixel_width
> x
)
2014 if (g
->type
== IMAGE_GLYPH
)
2016 /* Don't remember when mouse is over image, as
2017 image may have hot-spots. */
2018 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2021 width
= g
->pixel_width
;
2025 /* Use nominal char spacing at end of line. */
2027 gx
+= (x
/ width
) * width
;
2030 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2031 gx
+= window_box_left_offset (w
, area
);
2035 /* Use nominal line height at end of window. */
2036 gx
= (x
/ width
) * width
;
2038 gy
+= (y
/ height
) * height
;
2042 case ON_LEFT_FRINGE
:
2043 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2044 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2045 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2046 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2049 case ON_RIGHT_FRINGE
:
2050 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2051 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2052 : window_box_right_offset (w
, TEXT_AREA
));
2053 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2057 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2059 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2060 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2061 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2063 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2067 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2068 if (r
->y
+ r
->height
> y
)
2075 height
= gr
->height
;
2078 /* Use nominal line height at end of window. */
2080 gy
+= (y
/ height
) * height
;
2087 /* If there is no glyph under the mouse, then we divide the screen
2088 into a grid of the smallest glyph in the frame, and use that
2091 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2092 round down even for negative values. */
2098 gx
= (gx
/ width
) * width
;
2099 gy
= (gy
/ height
) * height
;
2104 gx
+= WINDOW_LEFT_EDGE_X (w
);
2105 gy
+= WINDOW_TOP_EDGE_Y (w
);
2108 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2110 /* Visible feedback for debugging. */
2113 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2114 f
->output_data
.x
->normal_gc
,
2115 gx
, gy
, width
, height
);
2121 #endif /* HAVE_WINDOW_SYSTEM */
2124 /***********************************************************************
2125 Lisp form evaluation
2126 ***********************************************************************/
2128 /* Error handler for safe_eval and safe_call. */
2131 safe_eval_handler (Lisp_Object arg
)
2133 add_to_log ("Error during redisplay: %S", arg
, Qnil
);
2138 /* Evaluate SEXPR and return the result, or nil if something went
2139 wrong. Prevent redisplay during the evaluation. */
2141 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2142 Return the result, or nil if something went wrong. Prevent
2143 redisplay during the evaluation. */
2146 safe_call (size_t nargs
, Lisp_Object
*args
)
2150 if (inhibit_eval_during_redisplay
)
2154 int count
= SPECPDL_INDEX ();
2155 struct gcpro gcpro1
;
2158 gcpro1
.nvars
= nargs
;
2159 specbind (Qinhibit_redisplay
, Qt
);
2160 /* Use Qt to ensure debugger does not run,
2161 so there is no possibility of wanting to redisplay. */
2162 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2165 val
= unbind_to (count
, val
);
2172 /* Call function FN with one argument ARG.
2173 Return the result, or nil if something went wrong. */
2176 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2178 Lisp_Object args
[2];
2181 return safe_call (2, args
);
2184 static Lisp_Object Qeval
;
2187 safe_eval (Lisp_Object sexpr
)
2189 return safe_call1 (Qeval
, sexpr
);
2192 /* Call function FN with one argument ARG.
2193 Return the result, or nil if something went wrong. */
2196 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2198 Lisp_Object args
[3];
2202 return safe_call (3, args
);
2207 /***********************************************************************
2209 ***********************************************************************/
2213 /* Define CHECK_IT to perform sanity checks on iterators.
2214 This is for debugging. It is too slow to do unconditionally. */
2220 if (it
->method
== GET_FROM_STRING
)
2222 xassert (STRINGP (it
->string
));
2223 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2227 xassert (IT_STRING_CHARPOS (*it
) < 0);
2228 if (it
->method
== GET_FROM_BUFFER
)
2230 /* Check that character and byte positions agree. */
2231 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2236 xassert (it
->current
.dpvec_index
>= 0);
2238 xassert (it
->current
.dpvec_index
< 0);
2241 #define CHECK_IT(IT) check_it ((IT))
2245 #define CHECK_IT(IT) (void) 0
2252 /* Check that the window end of window W is what we expect it
2253 to be---the last row in the current matrix displaying text. */
2256 check_window_end (w
)
2259 if (!MINI_WINDOW_P (w
)
2260 && !NILP (w
->window_end_valid
))
2262 struct glyph_row
*row
;
2263 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2264 XFASTINT (w
->window_end_vpos
)),
2266 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2267 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2271 #define CHECK_WINDOW_END(W) check_window_end ((W))
2273 #else /* not GLYPH_DEBUG */
2275 #define CHECK_WINDOW_END(W) (void) 0
2277 #endif /* not GLYPH_DEBUG */
2281 /***********************************************************************
2282 Iterator initialization
2283 ***********************************************************************/
2285 /* Initialize IT for displaying current_buffer in window W, starting
2286 at character position CHARPOS. CHARPOS < 0 means that no buffer
2287 position is specified which is useful when the iterator is assigned
2288 a position later. BYTEPOS is the byte position corresponding to
2289 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2291 If ROW is not null, calls to produce_glyphs with IT as parameter
2292 will produce glyphs in that row.
2294 BASE_FACE_ID is the id of a base face to use. It must be one of
2295 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2296 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2297 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2299 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2300 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2301 will be initialized to use the corresponding mode line glyph row of
2302 the desired matrix of W. */
2305 init_iterator (struct it
*it
, struct window
*w
,
2306 EMACS_INT charpos
, EMACS_INT bytepos
,
2307 struct glyph_row
*row
, enum face_id base_face_id
)
2309 int highlight_region_p
;
2310 enum face_id remapped_base_face_id
= base_face_id
;
2312 /* Some precondition checks. */
2313 xassert (w
!= NULL
&& it
!= NULL
);
2314 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2317 /* If face attributes have been changed since the last redisplay,
2318 free realized faces now because they depend on face definitions
2319 that might have changed. Don't free faces while there might be
2320 desired matrices pending which reference these faces. */
2321 if (face_change_count
&& !inhibit_free_realized_faces
)
2323 face_change_count
= 0;
2324 free_all_realized_faces (Qnil
);
2327 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2328 if (! NILP (Vface_remapping_alist
))
2329 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2331 /* Use one of the mode line rows of W's desired matrix if
2335 if (base_face_id
== MODE_LINE_FACE_ID
2336 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2337 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2338 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2339 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2343 memset (it
, 0, sizeof *it
);
2344 it
->current
.overlay_string_index
= -1;
2345 it
->current
.dpvec_index
= -1;
2346 it
->base_face_id
= remapped_base_face_id
;
2348 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2349 it
->paragraph_embedding
= L2R
;
2350 it
->bidi_it
.string
.lstring
= Qnil
;
2351 it
->bidi_it
.string
.s
= NULL
;
2352 it
->bidi_it
.string
.bufpos
= 0;
2354 /* The window in which we iterate over current_buffer: */
2355 XSETWINDOW (it
->window
, w
);
2357 it
->f
= XFRAME (w
->frame
);
2361 /* Extra space between lines (on window systems only). */
2362 if (base_face_id
== DEFAULT_FACE_ID
2363 && FRAME_WINDOW_P (it
->f
))
2365 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2366 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2367 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2368 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2369 * FRAME_LINE_HEIGHT (it
->f
));
2370 else if (it
->f
->extra_line_spacing
> 0)
2371 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2372 it
->max_extra_line_spacing
= 0;
2375 /* If realized faces have been removed, e.g. because of face
2376 attribute changes of named faces, recompute them. When running
2377 in batch mode, the face cache of the initial frame is null. If
2378 we happen to get called, make a dummy face cache. */
2379 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2380 init_frame_faces (it
->f
);
2381 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2382 recompute_basic_faces (it
->f
);
2384 /* Current value of the `slice', `space-width', and 'height' properties. */
2385 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2386 it
->space_width
= Qnil
;
2387 it
->font_height
= Qnil
;
2388 it
->override_ascent
= -1;
2390 /* Are control characters displayed as `^C'? */
2391 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2393 /* -1 means everything between a CR and the following line end
2394 is invisible. >0 means lines indented more than this value are
2396 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2397 ? XFASTINT (BVAR (current_buffer
, selective_display
))
2398 : (!NILP (BVAR (current_buffer
, selective_display
))
2400 it
->selective_display_ellipsis_p
2401 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2403 /* Display table to use. */
2404 it
->dp
= window_display_table (w
);
2406 /* Are multibyte characters enabled in current_buffer? */
2407 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2409 /* Do we need to reorder bidirectional text? Not if this is a
2410 unibyte buffer: by definition, none of the single-byte characters
2411 are strong R2L, so no reordering is needed. And bidi.c doesn't
2412 support unibyte buffers anyway. */
2414 = !NILP (BVAR (current_buffer
, bidi_display_reordering
)) && it
->multibyte_p
;
2416 /* Non-zero if we should highlight the region. */
2418 = (!NILP (Vtransient_mark_mode
)
2419 && !NILP (BVAR (current_buffer
, mark_active
))
2420 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= 0);
2422 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2423 start and end of a visible region in window IT->w. Set both to
2424 -1 to indicate no region. */
2425 if (highlight_region_p
2426 /* Maybe highlight only in selected window. */
2427 && (/* Either show region everywhere. */
2428 highlight_nonselected_windows
2429 /* Or show region in the selected window. */
2430 || w
== XWINDOW (selected_window
)
2431 /* Or show the region if we are in the mini-buffer and W is
2432 the window the mini-buffer refers to. */
2433 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2434 && WINDOWP (minibuf_selected_window
)
2435 && w
== XWINDOW (minibuf_selected_window
))))
2437 EMACS_INT markpos
= marker_position (BVAR (current_buffer
, mark
));
2438 it
->region_beg_charpos
= min (PT
, markpos
);
2439 it
->region_end_charpos
= max (PT
, markpos
);
2442 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2444 /* Get the position at which the redisplay_end_trigger hook should
2445 be run, if it is to be run at all. */
2446 if (MARKERP (w
->redisplay_end_trigger
)
2447 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2448 it
->redisplay_end_trigger_charpos
2449 = marker_position (w
->redisplay_end_trigger
);
2450 else if (INTEGERP (w
->redisplay_end_trigger
))
2451 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2453 /* Correct bogus values of tab_width. */
2454 it
->tab_width
= XINT (BVAR (current_buffer
, tab_width
));
2455 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2458 /* Are lines in the display truncated? */
2459 if (base_face_id
!= DEFAULT_FACE_ID
2460 || XINT (it
->w
->hscroll
)
2461 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2462 && ((!NILP (Vtruncate_partial_width_windows
)
2463 && !INTEGERP (Vtruncate_partial_width_windows
))
2464 || (INTEGERP (Vtruncate_partial_width_windows
)
2465 && (WINDOW_TOTAL_COLS (it
->w
)
2466 < XINT (Vtruncate_partial_width_windows
))))))
2467 it
->line_wrap
= TRUNCATE
;
2468 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2469 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2470 ? WINDOW_WRAP
: WORD_WRAP
;
2472 it
->line_wrap
= TRUNCATE
;
2474 /* Get dimensions of truncation and continuation glyphs. These are
2475 displayed as fringe bitmaps under X, so we don't need them for such
2477 if (!FRAME_WINDOW_P (it
->f
))
2479 if (it
->line_wrap
== TRUNCATE
)
2481 /* We will need the truncation glyph. */
2482 xassert (it
->glyph_row
== NULL
);
2483 produce_special_glyphs (it
, IT_TRUNCATION
);
2484 it
->truncation_pixel_width
= it
->pixel_width
;
2488 /* We will need the continuation glyph. */
2489 xassert (it
->glyph_row
== NULL
);
2490 produce_special_glyphs (it
, IT_CONTINUATION
);
2491 it
->continuation_pixel_width
= it
->pixel_width
;
2494 /* Reset these values to zero because the produce_special_glyphs
2495 above has changed them. */
2496 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2497 it
->phys_ascent
= it
->phys_descent
= 0;
2500 /* Set this after getting the dimensions of truncation and
2501 continuation glyphs, so that we don't produce glyphs when calling
2502 produce_special_glyphs, above. */
2503 it
->glyph_row
= row
;
2504 it
->area
= TEXT_AREA
;
2506 /* Forget any previous info about this row being reversed. */
2508 it
->glyph_row
->reversed_p
= 0;
2510 /* Get the dimensions of the display area. The display area
2511 consists of the visible window area plus a horizontally scrolled
2512 part to the left of the window. All x-values are relative to the
2513 start of this total display area. */
2514 if (base_face_id
!= DEFAULT_FACE_ID
)
2516 /* Mode lines, menu bar in terminal frames. */
2517 it
->first_visible_x
= 0;
2518 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2523 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2524 it
->last_visible_x
= (it
->first_visible_x
2525 + window_box_width (w
, TEXT_AREA
));
2527 /* If we truncate lines, leave room for the truncator glyph(s) at
2528 the right margin. Otherwise, leave room for the continuation
2529 glyph(s). Truncation and continuation glyphs are not inserted
2530 for window-based redisplay. */
2531 if (!FRAME_WINDOW_P (it
->f
))
2533 if (it
->line_wrap
== TRUNCATE
)
2534 it
->last_visible_x
-= it
->truncation_pixel_width
;
2536 it
->last_visible_x
-= it
->continuation_pixel_width
;
2539 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2540 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2543 /* Leave room for a border glyph. */
2544 if (!FRAME_WINDOW_P (it
->f
)
2545 && !WINDOW_RIGHTMOST_P (it
->w
))
2546 it
->last_visible_x
-= 1;
2548 it
->last_visible_y
= window_text_bottom_y (w
);
2550 /* For mode lines and alike, arrange for the first glyph having a
2551 left box line if the face specifies a box. */
2552 if (base_face_id
!= DEFAULT_FACE_ID
)
2556 it
->face_id
= remapped_base_face_id
;
2558 /* If we have a boxed mode line, make the first character appear
2559 with a left box line. */
2560 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2561 if (face
->box
!= FACE_NO_BOX
)
2562 it
->start_of_box_run_p
= 1;
2565 /* If a buffer position was specified, set the iterator there,
2566 getting overlays and face properties from that position. */
2567 if (charpos
>= BUF_BEG (current_buffer
))
2569 it
->end_charpos
= ZV
;
2571 IT_CHARPOS (*it
) = charpos
;
2573 /* Compute byte position if not specified. */
2574 if (bytepos
< charpos
)
2575 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2577 IT_BYTEPOS (*it
) = bytepos
;
2579 it
->start
= it
->current
;
2581 /* If we are to reorder bidirectional text, init the bidi
2585 /* Note the paragraph direction that this buffer wants to
2587 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2589 it
->paragraph_embedding
= L2R
;
2590 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2592 it
->paragraph_embedding
= R2L
;
2594 it
->paragraph_embedding
= NEUTRAL_DIR
;
2595 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2599 /* Compute faces etc. */
2600 reseat (it
, it
->current
.pos
, 1);
2607 /* Initialize IT for the display of window W with window start POS. */
2610 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2612 struct glyph_row
*row
;
2613 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2615 row
= w
->desired_matrix
->rows
+ first_vpos
;
2616 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2617 it
->first_vpos
= first_vpos
;
2619 /* Don't reseat to previous visible line start if current start
2620 position is in a string or image. */
2621 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2623 int start_at_line_beg_p
;
2624 int first_y
= it
->current_y
;
2626 /* If window start is not at a line start, skip forward to POS to
2627 get the correct continuation lines width. */
2628 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2629 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2630 if (!start_at_line_beg_p
)
2634 reseat_at_previous_visible_line_start (it
);
2635 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2637 new_x
= it
->current_x
+ it
->pixel_width
;
2639 /* If lines are continued, this line may end in the middle
2640 of a multi-glyph character (e.g. a control character
2641 displayed as \003, or in the middle of an overlay
2642 string). In this case move_it_to above will not have
2643 taken us to the start of the continuation line but to the
2644 end of the continued line. */
2645 if (it
->current_x
> 0
2646 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2647 && (/* And glyph doesn't fit on the line. */
2648 new_x
> it
->last_visible_x
2649 /* Or it fits exactly and we're on a window
2651 || (new_x
== it
->last_visible_x
2652 && FRAME_WINDOW_P (it
->f
))))
2654 if (it
->current
.dpvec_index
>= 0
2655 || it
->current
.overlay_string_index
>= 0)
2657 set_iterator_to_next (it
, 1);
2658 move_it_in_display_line_to (it
, -1, -1, 0);
2661 it
->continuation_lines_width
+= it
->current_x
;
2664 /* We're starting a new display line, not affected by the
2665 height of the continued line, so clear the appropriate
2666 fields in the iterator structure. */
2667 it
->max_ascent
= it
->max_descent
= 0;
2668 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2670 it
->current_y
= first_y
;
2672 it
->current_x
= it
->hpos
= 0;
2678 /* Return 1 if POS is a position in ellipses displayed for invisible
2679 text. W is the window we display, for text property lookup. */
2682 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2684 Lisp_Object prop
, window
;
2686 EMACS_INT charpos
= CHARPOS (pos
->pos
);
2688 /* If POS specifies a position in a display vector, this might
2689 be for an ellipsis displayed for invisible text. We won't
2690 get the iterator set up for delivering that ellipsis unless
2691 we make sure that it gets aware of the invisible text. */
2692 if (pos
->dpvec_index
>= 0
2693 && pos
->overlay_string_index
< 0
2694 && CHARPOS (pos
->string_pos
) < 0
2696 && (XSETWINDOW (window
, w
),
2697 prop
= Fget_char_property (make_number (charpos
),
2698 Qinvisible
, window
),
2699 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2701 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2703 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2710 /* Initialize IT for stepping through current_buffer in window W,
2711 starting at position POS that includes overlay string and display
2712 vector/ control character translation position information. Value
2713 is zero if there are overlay strings with newlines at POS. */
2716 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
2718 EMACS_INT charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2719 int i
, overlay_strings_with_newlines
= 0;
2721 /* If POS specifies a position in a display vector, this might
2722 be for an ellipsis displayed for invisible text. We won't
2723 get the iterator set up for delivering that ellipsis unless
2724 we make sure that it gets aware of the invisible text. */
2725 if (in_ellipses_for_invisible_text_p (pos
, w
))
2731 /* Keep in mind: the call to reseat in init_iterator skips invisible
2732 text, so we might end up at a position different from POS. This
2733 is only a problem when POS is a row start after a newline and an
2734 overlay starts there with an after-string, and the overlay has an
2735 invisible property. Since we don't skip invisible text in
2736 display_line and elsewhere immediately after consuming the
2737 newline before the row start, such a POS will not be in a string,
2738 but the call to init_iterator below will move us to the
2740 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2742 /* This only scans the current chunk -- it should scan all chunks.
2743 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2744 to 16 in 22.1 to make this a lesser problem. */
2745 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2747 const char *s
= SSDATA (it
->overlay_strings
[i
]);
2748 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2750 while (s
< e
&& *s
!= '\n')
2755 overlay_strings_with_newlines
= 1;
2760 /* If position is within an overlay string, set up IT to the right
2762 if (pos
->overlay_string_index
>= 0)
2766 /* If the first overlay string happens to have a `display'
2767 property for an image, the iterator will be set up for that
2768 image, and we have to undo that setup first before we can
2769 correct the overlay string index. */
2770 if (it
->method
== GET_FROM_IMAGE
)
2773 /* We already have the first chunk of overlay strings in
2774 IT->overlay_strings. Load more until the one for
2775 pos->overlay_string_index is in IT->overlay_strings. */
2776 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2778 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2779 it
->current
.overlay_string_index
= 0;
2782 load_overlay_strings (it
, 0);
2783 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2787 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2788 relative_index
= (it
->current
.overlay_string_index
2789 % OVERLAY_STRING_CHUNK_SIZE
);
2790 it
->string
= it
->overlay_strings
[relative_index
];
2791 xassert (STRINGP (it
->string
));
2792 it
->current
.string_pos
= pos
->string_pos
;
2793 it
->method
= GET_FROM_STRING
;
2796 if (CHARPOS (pos
->string_pos
) >= 0)
2798 /* Recorded position is not in an overlay string, but in another
2799 string. This can only be a string from a `display' property.
2800 IT should already be filled with that string. */
2801 it
->current
.string_pos
= pos
->string_pos
;
2802 xassert (STRINGP (it
->string
));
2805 /* Restore position in display vector translations, control
2806 character translations or ellipses. */
2807 if (pos
->dpvec_index
>= 0)
2809 if (it
->dpvec
== NULL
)
2810 get_next_display_element (it
);
2811 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2812 it
->current
.dpvec_index
= pos
->dpvec_index
;
2816 return !overlay_strings_with_newlines
;
2820 /* Initialize IT for stepping through current_buffer in window W
2821 starting at ROW->start. */
2824 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
2826 init_from_display_pos (it
, w
, &row
->start
);
2827 it
->start
= row
->start
;
2828 it
->continuation_lines_width
= row
->continuation_lines_width
;
2833 /* Initialize IT for stepping through current_buffer in window W
2834 starting in the line following ROW, i.e. starting at ROW->end.
2835 Value is zero if there are overlay strings with newlines at ROW's
2839 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
2843 if (init_from_display_pos (it
, w
, &row
->end
))
2845 if (row
->continued_p
)
2846 it
->continuation_lines_width
2847 = row
->continuation_lines_width
+ row
->pixel_width
;
2858 /***********************************************************************
2860 ***********************************************************************/
2862 /* Called when IT reaches IT->stop_charpos. Handle text property and
2863 overlay changes. Set IT->stop_charpos to the next position where
2867 handle_stop (struct it
*it
)
2869 enum prop_handled handled
;
2870 int handle_overlay_change_p
;
2874 it
->current
.dpvec_index
= -1;
2875 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
2876 it
->ignore_overlay_strings_at_pos_p
= 0;
2879 /* Use face of preceding text for ellipsis (if invisible) */
2880 if (it
->selective_display_ellipsis_p
)
2881 it
->saved_face_id
= it
->face_id
;
2885 handled
= HANDLED_NORMALLY
;
2887 /* Call text property handlers. */
2888 for (p
= it_props
; p
->handler
; ++p
)
2890 handled
= p
->handler (it
);
2892 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2894 else if (handled
== HANDLED_RETURN
)
2896 /* We still want to show before and after strings from
2897 overlays even if the actual buffer text is replaced. */
2898 if (!handle_overlay_change_p
2900 || !get_overlay_strings_1 (it
, 0, 0))
2903 setup_for_ellipsis (it
, 0);
2904 /* When handling a display spec, we might load an
2905 empty string. In that case, discard it here. We
2906 used to discard it in handle_single_display_spec,
2907 but that causes get_overlay_strings_1, above, to
2908 ignore overlay strings that we must check. */
2909 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
2913 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
2917 it
->ignore_overlay_strings_at_pos_p
= 1;
2918 it
->string_from_display_prop_p
= 0;
2919 handle_overlay_change_p
= 0;
2921 handled
= HANDLED_RECOMPUTE_PROPS
;
2924 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2925 handle_overlay_change_p
= 0;
2928 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2930 /* Don't check for overlay strings below when set to deliver
2931 characters from a display vector. */
2932 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
2933 handle_overlay_change_p
= 0;
2935 /* Handle overlay changes.
2936 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
2937 if it finds overlays. */
2938 if (handle_overlay_change_p
)
2939 handled
= handle_overlay_change (it
);
2944 setup_for_ellipsis (it
, 0);
2948 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2950 /* Determine where to stop next. */
2951 if (handled
== HANDLED_NORMALLY
)
2952 compute_stop_pos (it
);
2956 /* Compute IT->stop_charpos from text property and overlay change
2957 information for IT's current position. */
2960 compute_stop_pos (struct it
*it
)
2962 register INTERVAL iv
, next_iv
;
2963 Lisp_Object object
, limit
, position
;
2964 EMACS_INT charpos
, bytepos
;
2966 /* If nowhere else, stop at the end. */
2967 it
->stop_charpos
= it
->end_charpos
;
2969 if (STRINGP (it
->string
))
2971 /* Strings are usually short, so don't limit the search for
2973 object
= it
->string
;
2975 charpos
= IT_STRING_CHARPOS (*it
);
2976 bytepos
= IT_STRING_BYTEPOS (*it
);
2982 /* If next overlay change is in front of the current stop pos
2983 (which is IT->end_charpos), stop there. Note: value of
2984 next_overlay_change is point-max if no overlay change
2986 charpos
= IT_CHARPOS (*it
);
2987 bytepos
= IT_BYTEPOS (*it
);
2988 pos
= next_overlay_change (charpos
);
2989 if (pos
< it
->stop_charpos
)
2990 it
->stop_charpos
= pos
;
2992 /* If showing the region, we have to stop at the region
2993 start or end because the face might change there. */
2994 if (it
->region_beg_charpos
> 0)
2996 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2997 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2998 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2999 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3002 /* Set up variables for computing the stop position from text
3003 property changes. */
3004 XSETBUFFER (object
, current_buffer
);
3005 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3008 /* Get the interval containing IT's position. Value is a null
3009 interval if there isn't such an interval. */
3010 position
= make_number (charpos
);
3011 iv
= validate_interval_range (object
, &position
, &position
, 0);
3012 if (!NULL_INTERVAL_P (iv
))
3014 Lisp_Object values_here
[LAST_PROP_IDX
];
3017 /* Get properties here. */
3018 for (p
= it_props
; p
->handler
; ++p
)
3019 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3021 /* Look for an interval following iv that has different
3023 for (next_iv
= next_interval (iv
);
3024 (!NULL_INTERVAL_P (next_iv
)
3026 || XFASTINT (limit
) > next_iv
->position
));
3027 next_iv
= next_interval (next_iv
))
3029 for (p
= it_props
; p
->handler
; ++p
)
3031 Lisp_Object new_value
;
3033 new_value
= textget (next_iv
->plist
, *p
->name
);
3034 if (!EQ (values_here
[p
->idx
], new_value
))
3042 if (!NULL_INTERVAL_P (next_iv
))
3044 if (INTEGERP (limit
)
3045 && next_iv
->position
>= XFASTINT (limit
))
3046 /* No text property change up to limit. */
3047 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3049 /* Text properties change in next_iv. */
3050 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3054 if (it
->cmp_it
.id
< 0)
3056 EMACS_INT stoppos
= it
->end_charpos
;
3058 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3060 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3061 stoppos
, it
->string
);
3064 xassert (STRINGP (it
->string
)
3065 || (it
->stop_charpos
>= BEGV
3066 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3070 /* Return the position of the next overlay change after POS in
3071 current_buffer. Value is point-max if no overlay change
3072 follows. This is like `next-overlay-change' but doesn't use
3076 next_overlay_change (EMACS_INT pos
)
3080 Lisp_Object
*overlays
;
3083 /* Get all overlays at the given position. */
3084 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3086 /* If any of these overlays ends before endpos,
3087 use its ending point instead. */
3088 for (i
= 0; i
< noverlays
; ++i
)
3093 oend
= OVERLAY_END (overlays
[i
]);
3094 oendpos
= OVERLAY_POSITION (oend
);
3095 endpos
= min (endpos
, oendpos
);
3101 /* Return the character position of a display string at or after
3102 position specified by POSITION. If no display string exists at or
3103 after POSITION, return ZV. A display string is either an overlay
3104 with `display' property whose value is a string, or a `display'
3105 text property whose value is a string. STRING is data about the
3106 string to iterate; if STRING->lstring is nil, we are iterating a
3107 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3110 compute_display_string_pos (struct text_pos
*position
,
3111 struct bidi_string_data
*string
, int frame_window_p
)
3113 /* OBJECT = nil means current buffer. */
3114 Lisp_Object object
= string
? 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
= string
? string
->lstring
: Qnil
;
3176 Lisp_Object pos
= make_number (charpos
);
3177 EMACS_INT eob
= STRINGP (object
) ? string
->schars
: ZV
;
3182 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3185 /* Look forward for the first character where the `display' property
3187 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3189 return XFASTINT (pos
);
3194 /***********************************************************************
3196 ***********************************************************************/
3198 /* Handle changes in the `fontified' property of the current buffer by
3199 calling hook functions from Qfontification_functions to fontify
3202 static enum prop_handled
3203 handle_fontified_prop (struct it
*it
)
3205 Lisp_Object prop
, pos
;
3206 enum prop_handled handled
= HANDLED_NORMALLY
;
3208 if (!NILP (Vmemory_full
))
3211 /* Get the value of the `fontified' property at IT's current buffer
3212 position. (The `fontified' property doesn't have a special
3213 meaning in strings.) If the value is nil, call functions from
3214 Qfontification_functions. */
3215 if (!STRINGP (it
->string
)
3217 && !NILP (Vfontification_functions
)
3218 && !NILP (Vrun_hooks
)
3219 && (pos
= make_number (IT_CHARPOS (*it
)),
3220 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3221 /* Ignore the special cased nil value always present at EOB since
3222 no amount of fontifying will be able to change it. */
3223 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3225 int count
= SPECPDL_INDEX ();
3227 struct buffer
*obuf
= current_buffer
;
3228 int begv
= BEGV
, zv
= ZV
;
3229 int old_clip_changed
= current_buffer
->clip_changed
;
3231 val
= Vfontification_functions
;
3232 specbind (Qfontification_functions
, Qnil
);
3234 xassert (it
->end_charpos
== ZV
);
3236 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3237 safe_call1 (val
, pos
);
3240 Lisp_Object fns
, fn
;
3241 struct gcpro gcpro1
, gcpro2
;
3246 for (; CONSP (val
); val
= XCDR (val
))
3252 /* A value of t indicates this hook has a local
3253 binding; it means to run the global binding too.
3254 In a global value, t should not occur. If it
3255 does, we must ignore it to avoid an endless
3257 for (fns
= Fdefault_value (Qfontification_functions
);
3263 safe_call1 (fn
, pos
);
3267 safe_call1 (fn
, pos
);
3273 unbind_to (count
, Qnil
);
3275 /* Fontification functions routinely call `save-restriction'.
3276 Normally, this tags clip_changed, which can confuse redisplay
3277 (see discussion in Bug#6671). Since we don't perform any
3278 special handling of fontification changes in the case where
3279 `save-restriction' isn't called, there's no point doing so in
3280 this case either. So, if the buffer's restrictions are
3281 actually left unchanged, reset clip_changed. */
3282 if (obuf
== current_buffer
)
3284 if (begv
== BEGV
&& zv
== ZV
)
3285 current_buffer
->clip_changed
= old_clip_changed
;
3287 /* There isn't much we can reasonably do to protect against
3288 misbehaving fontification, but here's a fig leaf. */
3289 else if (!NILP (BVAR (obuf
, name
)))
3290 set_buffer_internal_1 (obuf
);
3292 /* The fontification code may have added/removed text.
3293 It could do even a lot worse, but let's at least protect against
3294 the most obvious case where only the text past `pos' gets changed',
3295 as is/was done in grep.el where some escapes sequences are turned
3296 into face properties (bug#7876). */
3297 it
->end_charpos
= ZV
;
3299 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3300 something. This avoids an endless loop if they failed to
3301 fontify the text for which reason ever. */
3302 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3303 handled
= HANDLED_RECOMPUTE_PROPS
;
3311 /***********************************************************************
3313 ***********************************************************************/
3315 /* Set up iterator IT from face properties at its current position.
3316 Called from handle_stop. */
3318 static enum prop_handled
3319 handle_face_prop (struct it
*it
)
3322 EMACS_INT next_stop
;
3324 if (!STRINGP (it
->string
))
3327 = face_at_buffer_position (it
->w
,
3329 it
->region_beg_charpos
,
3330 it
->region_end_charpos
,
3333 + TEXT_PROP_DISTANCE_LIMIT
),
3334 0, it
->base_face_id
);
3336 /* Is this a start of a run of characters with box face?
3337 Caveat: this can be called for a freshly initialized
3338 iterator; face_id is -1 in this case. We know that the new
3339 face will not change until limit, i.e. if the new face has a
3340 box, all characters up to limit will have one. But, as
3341 usual, we don't know whether limit is really the end. */
3342 if (new_face_id
!= it
->face_id
)
3344 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3346 /* If new face has a box but old face has not, this is
3347 the start of a run of characters with box, i.e. it has
3348 a shadow on the left side. The value of face_id of the
3349 iterator will be -1 if this is the initial call that gets
3350 the face. In this case, we have to look in front of IT's
3351 position and see whether there is a face != new_face_id. */
3352 it
->start_of_box_run_p
3353 = (new_face
->box
!= FACE_NO_BOX
3354 && (it
->face_id
>= 0
3355 || IT_CHARPOS (*it
) == BEG
3356 || new_face_id
!= face_before_it_pos (it
)));
3357 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3365 Lisp_Object from_overlay
3366 = (it
->current
.overlay_string_index
>= 0
3367 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3370 /* See if we got to this string directly or indirectly from
3371 an overlay property. That includes the before-string or
3372 after-string of an overlay, strings in display properties
3373 provided by an overlay, their text properties, etc.
3375 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3376 if (! NILP (from_overlay
))
3377 for (i
= it
->sp
- 1; i
>= 0; i
--)
3379 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3381 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3382 else if (! NILP (it
->stack
[i
].from_overlay
))
3383 from_overlay
= it
->stack
[i
].from_overlay
;
3385 if (!NILP (from_overlay
))
3389 if (! NILP (from_overlay
))
3391 bufpos
= IT_CHARPOS (*it
);
3392 /* For a string from an overlay, the base face depends
3393 only on text properties and ignores overlays. */
3395 = face_for_overlay_string (it
->w
,
3397 it
->region_beg_charpos
,
3398 it
->region_end_charpos
,
3401 + TEXT_PROP_DISTANCE_LIMIT
),
3409 /* For strings from a `display' property, use the face at
3410 IT's current buffer position as the base face to merge
3411 with, so that overlay strings appear in the same face as
3412 surrounding text, unless they specify their own
3414 base_face_id
= underlying_face_id (it
);
3417 new_face_id
= face_at_string_position (it
->w
,
3419 IT_STRING_CHARPOS (*it
),
3421 it
->region_beg_charpos
,
3422 it
->region_end_charpos
,
3426 /* Is this a start of a run of characters with box? Caveat:
3427 this can be called for a freshly allocated iterator; face_id
3428 is -1 is this case. We know that the new face will not
3429 change until the next check pos, i.e. if the new face has a
3430 box, all characters up to that position will have a
3431 box. But, as usual, we don't know whether that position
3432 is really the end. */
3433 if (new_face_id
!= it
->face_id
)
3435 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3436 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3438 /* If new face has a box but old face hasn't, this is the
3439 start of a run of characters with box, i.e. it has a
3440 shadow on the left side. */
3441 it
->start_of_box_run_p
3442 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3443 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3447 it
->face_id
= new_face_id
;
3448 return HANDLED_NORMALLY
;
3452 /* Return the ID of the face ``underlying'' IT's current position,
3453 which is in a string. If the iterator is associated with a
3454 buffer, return the face at IT's current buffer position.
3455 Otherwise, use the iterator's base_face_id. */
3458 underlying_face_id (struct it
*it
)
3460 int face_id
= it
->base_face_id
, i
;
3462 xassert (STRINGP (it
->string
));
3464 for (i
= it
->sp
- 1; i
>= 0; --i
)
3465 if (NILP (it
->stack
[i
].string
))
3466 face_id
= it
->stack
[i
].face_id
;
3472 /* Compute the face one character before or after the current position
3473 of IT. BEFORE_P non-zero means get the face in front of IT's
3474 position. Value is the id of the face. */
3477 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3480 EMACS_INT next_check_charpos
;
3481 struct text_pos pos
;
3483 xassert (it
->s
== NULL
);
3485 if (STRINGP (it
->string
))
3490 /* No face change past the end of the string (for the case
3491 we are padding with spaces). No face change before the
3493 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3494 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3497 /* Set pos to the position before or after IT's current position. */
3499 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3501 /* For composition, we must check the character after the
3503 pos
= (it
->what
== IT_COMPOSITION
3504 ? string_pos (IT_STRING_CHARPOS (*it
)
3505 + it
->cmp_it
.nchars
, it
->string
)
3506 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3508 if (it
->current
.overlay_string_index
>= 0)
3509 bufpos
= IT_CHARPOS (*it
);
3513 base_face_id
= underlying_face_id (it
);
3515 /* Get the face for ASCII, or unibyte. */
3516 face_id
= face_at_string_position (it
->w
,
3520 it
->region_beg_charpos
,
3521 it
->region_end_charpos
,
3522 &next_check_charpos
,
3525 /* Correct the face for charsets different from ASCII. Do it
3526 for the multibyte case only. The face returned above is
3527 suitable for unibyte text if IT->string is unibyte. */
3528 if (STRING_MULTIBYTE (it
->string
))
3530 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3532 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3534 c
= string_char_and_length (p
, &len
);
3535 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3540 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3541 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3544 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3545 pos
= it
->current
.pos
;
3548 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3551 if (it
->what
== IT_COMPOSITION
)
3552 /* For composition, we must check the position after the
3554 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3556 INC_TEXT_POS (pos
, it
->multibyte_p
);
3559 /* Determine face for CHARSET_ASCII, or unibyte. */
3560 face_id
= face_at_buffer_position (it
->w
,
3562 it
->region_beg_charpos
,
3563 it
->region_end_charpos
,
3564 &next_check_charpos
,
3567 /* Correct the face for charsets different from ASCII. Do it
3568 for the multibyte case only. The face returned above is
3569 suitable for unibyte text if current_buffer is unibyte. */
3570 if (it
->multibyte_p
)
3572 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3573 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3574 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3583 /***********************************************************************
3585 ***********************************************************************/
3587 /* Set up iterator IT from invisible properties at its current
3588 position. Called from handle_stop. */
3590 static enum prop_handled
3591 handle_invisible_prop (struct it
*it
)
3593 enum prop_handled handled
= HANDLED_NORMALLY
;
3595 if (STRINGP (it
->string
))
3597 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3599 /* Get the value of the invisible text property at the
3600 current position. Value will be nil if there is no such
3602 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3603 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3606 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3608 handled
= HANDLED_RECOMPUTE_PROPS
;
3610 /* Get the position at which the next change of the
3611 invisible text property can be found in IT->string.
3612 Value will be nil if the property value is the same for
3613 all the rest of IT->string. */
3614 XSETINT (limit
, SCHARS (it
->string
));
3615 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3618 /* Text at current position is invisible. The next
3619 change in the property is at position end_charpos.
3620 Move IT's current position to that position. */
3621 if (INTEGERP (end_charpos
)
3622 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3624 struct text_pos old
;
3625 old
= it
->current
.string_pos
;
3626 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3627 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3631 /* The rest of the string is invisible. If this is an
3632 overlay string, proceed with the next overlay string
3633 or whatever comes and return a character from there. */
3634 if (it
->current
.overlay_string_index
>= 0)
3636 next_overlay_string (it
);
3637 /* Don't check for overlay strings when we just
3638 finished processing them. */
3639 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3643 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3644 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3652 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
3653 Lisp_Object pos
, prop
, overlay
;
3655 /* First of all, is there invisible text at this position? */
3656 tem
= start_charpos
= IT_CHARPOS (*it
);
3657 pos
= make_number (tem
);
3658 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3660 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3662 /* If we are on invisible text, skip over it. */
3663 if (invis_p
&& start_charpos
< it
->end_charpos
)
3665 /* Record whether we have to display an ellipsis for the
3667 int display_ellipsis_p
= invis_p
== 2;
3669 handled
= HANDLED_RECOMPUTE_PROPS
;
3671 /* Loop skipping over invisible text. The loop is left at
3672 ZV or with IT on the first char being visible again. */
3675 /* Try to skip some invisible text. Return value is the
3676 position reached which can be equal to where we start
3677 if there is nothing invisible there. This skips both
3678 over invisible text properties and overlays with
3679 invisible property. */
3680 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
3682 /* If we skipped nothing at all we weren't at invisible
3683 text in the first place. If everything to the end of
3684 the buffer was skipped, end the loop. */
3685 if (newpos
== tem
|| newpos
>= ZV
)
3689 /* We skipped some characters but not necessarily
3690 all there are. Check if we ended up on visible
3691 text. Fget_char_property returns the property of
3692 the char before the given position, i.e. if we
3693 get invis_p = 0, this means that the char at
3694 newpos is visible. */
3695 pos
= make_number (newpos
);
3696 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3697 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3700 /* If we ended up on invisible text, proceed to
3701 skip starting with next_stop. */
3705 /* If there are adjacent invisible texts, don't lose the
3706 second one's ellipsis. */
3708 display_ellipsis_p
= 1;
3712 /* The position newpos is now either ZV or on visible text. */
3713 if (it
->bidi_p
&& newpos
< ZV
)
3715 /* With bidi iteration, the region of invisible text
3716 could start and/or end in the middle of a non-base
3717 embedding level. Therefore, we need to skip
3718 invisible text using the bidi iterator, starting at
3719 IT's current position, until we find ourselves
3720 outside the invisible text. Skipping invisible text
3721 _after_ bidi iteration avoids affecting the visual
3722 order of the displayed text when invisible properties
3723 are added or removed. */
3724 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
3726 /* If we were `reseat'ed to a new paragraph,
3727 determine the paragraph base direction. We need
3728 to do it now because next_element_from_buffer may
3729 not have a chance to do it, if we are going to
3730 skip any text at the beginning, which resets the
3732 bidi_paragraph_init (it
->paragraph_embedding
,
3737 bidi_move_to_visually_next (&it
->bidi_it
);
3739 while (it
->stop_charpos
<= it
->bidi_it
.charpos
3740 && it
->bidi_it
.charpos
< newpos
);
3741 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3742 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3743 /* If we overstepped NEWPOS, record its position in the
3744 iterator, so that we skip invisible text if later the
3745 bidi iteration lands us in the invisible region
3747 if (IT_CHARPOS (*it
) >= newpos
)
3748 it
->prev_stop
= newpos
;
3752 IT_CHARPOS (*it
) = newpos
;
3753 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3756 /* If there are before-strings at the start of invisible
3757 text, and the text is invisible because of a text
3758 property, arrange to show before-strings because 20.x did
3759 it that way. (If the text is invisible because of an
3760 overlay property instead of a text property, this is
3761 already handled in the overlay code.) */
3763 && get_overlay_strings (it
, it
->stop_charpos
))
3765 handled
= HANDLED_RECOMPUTE_PROPS
;
3766 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3768 else if (display_ellipsis_p
)
3770 /* Make sure that the glyphs of the ellipsis will get
3771 correct `charpos' values. If we would not update
3772 it->position here, the glyphs would belong to the
3773 last visible character _before_ the invisible
3774 text, which confuses `set_cursor_from_row'.
3776 We use the last invisible position instead of the
3777 first because this way the cursor is always drawn on
3778 the first "." of the ellipsis, whenever PT is inside
3779 the invisible text. Otherwise the cursor would be
3780 placed _after_ the ellipsis when the point is after the
3781 first invisible character. */
3782 if (!STRINGP (it
->object
))
3784 it
->position
.charpos
= newpos
- 1;
3785 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3788 /* Let the ellipsis display before
3789 considering any properties of the following char.
3790 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3791 handled
= HANDLED_RETURN
;
3800 /* Make iterator IT return `...' next.
3801 Replaces LEN characters from buffer. */
3804 setup_for_ellipsis (struct it
*it
, int len
)
3806 /* Use the display table definition for `...'. Invalid glyphs
3807 will be handled by the method returning elements from dpvec. */
3808 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3810 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3811 it
->dpvec
= v
->contents
;
3812 it
->dpend
= v
->contents
+ v
->header
.size
;
3816 /* Default `...'. */
3817 it
->dpvec
= default_invis_vector
;
3818 it
->dpend
= default_invis_vector
+ 3;
3821 it
->dpvec_char_len
= len
;
3822 it
->current
.dpvec_index
= 0;
3823 it
->dpvec_face_id
= -1;
3825 /* Remember the current face id in case glyphs specify faces.
3826 IT's face is restored in set_iterator_to_next.
3827 saved_face_id was set to preceding char's face in handle_stop. */
3828 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3829 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3831 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3837 /***********************************************************************
3839 ***********************************************************************/
3841 /* Set up iterator IT from `display' property at its current position.
3842 Called from handle_stop.
3843 We return HANDLED_RETURN if some part of the display property
3844 overrides the display of the buffer text itself.
3845 Otherwise we return HANDLED_NORMALLY. */
3847 static enum prop_handled
3848 handle_display_prop (struct it
*it
)
3850 Lisp_Object propval
, object
, overlay
;
3851 struct text_pos
*position
;
3853 /* Nonzero if some property replaces the display of the text itself. */
3854 int display_replaced_p
= 0;
3856 if (STRINGP (it
->string
))
3858 object
= it
->string
;
3859 position
= &it
->current
.string_pos
;
3860 bufpos
= CHARPOS (it
->current
.pos
);
3864 XSETWINDOW (object
, it
->w
);
3865 position
= &it
->current
.pos
;
3866 bufpos
= CHARPOS (*position
);
3869 /* Reset those iterator values set from display property values. */
3870 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3871 it
->space_width
= Qnil
;
3872 it
->font_height
= Qnil
;
3875 /* We don't support recursive `display' properties, i.e. string
3876 values that have a string `display' property, that have a string
3877 `display' property etc. */
3878 if (!it
->string_from_display_prop_p
)
3879 it
->area
= TEXT_AREA
;
3881 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
3882 Qdisplay
, object
, &overlay
);
3884 return HANDLED_NORMALLY
;
3885 /* Now OVERLAY is the overlay that gave us this property, or nil
3886 if it was a text property. */
3888 if (!STRINGP (it
->string
))
3889 object
= it
->w
->buffer
;
3891 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
3893 FRAME_WINDOW_P (it
->f
));
3895 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3898 /* Subroutine of handle_display_prop. Returns non-zero if the display
3899 specification in SPEC is a replacing specification, i.e. it would
3900 replace the text covered by `display' property with something else,
3901 such as an image or a display string.
3903 See handle_single_display_spec for documentation of arguments.
3904 frame_window_p is non-zero if the window being redisplayed is on a
3905 GUI frame; this argument is used only if IT is NULL, see below.
3907 IT can be NULL, if this is called by the bidi reordering code
3908 through compute_display_string_pos, which see. In that case, this
3909 function only examines SPEC, but does not otherwise "handle" it, in
3910 the sense that it doesn't set up members of IT from the display
3913 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
3914 Lisp_Object overlay
, struct text_pos
*position
,
3915 EMACS_INT bufpos
, int frame_window_p
)
3917 int replacing_p
= 0;
3920 /* Simple specerties. */
3921 && !EQ (XCAR (spec
), Qimage
)
3922 && !EQ (XCAR (spec
), Qspace
)
3923 && !EQ (XCAR (spec
), Qwhen
)
3924 && !EQ (XCAR (spec
), Qslice
)
3925 && !EQ (XCAR (spec
), Qspace_width
)
3926 && !EQ (XCAR (spec
), Qheight
)
3927 && !EQ (XCAR (spec
), Qraise
)
3928 /* Marginal area specifications. */
3929 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
3930 && !EQ (XCAR (spec
), Qleft_fringe
)
3931 && !EQ (XCAR (spec
), Qright_fringe
)
3932 && !NILP (XCAR (spec
)))
3934 for (; CONSP (spec
); spec
= XCDR (spec
))
3936 if (handle_single_display_spec (it
, XCAR (spec
), object
, overlay
,
3937 position
, bufpos
, replacing_p
,
3941 /* If some text in a string is replaced, `position' no
3942 longer points to the position of `object'. */
3943 if (!it
|| STRINGP (object
))
3948 else if (VECTORP (spec
))
3951 for (i
= 0; i
< ASIZE (spec
); ++i
)
3952 if (handle_single_display_spec (it
, AREF (spec
, i
), object
, overlay
,
3953 position
, bufpos
, replacing_p
,
3957 /* If some text in a string is replaced, `position' no
3958 longer points to the position of `object'. */
3959 if (!it
|| STRINGP (object
))
3965 if (handle_single_display_spec (it
, spec
, object
, overlay
,
3966 position
, bufpos
, 0, frame_window_p
))
3973 /* Value is the position of the end of the `display' property starting
3974 at START_POS in OBJECT. */
3976 static struct text_pos
3977 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
3980 struct text_pos end_pos
;
3982 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3983 Qdisplay
, object
, Qnil
);
3984 CHARPOS (end_pos
) = XFASTINT (end
);
3985 if (STRINGP (object
))
3986 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3988 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3994 /* Set up IT from a single `display' property specification SPEC. OBJECT
3995 is the object in which the `display' property was found. *POSITION
3996 is the position in OBJECT at which the `display' property was found.
3997 BUFPOS is the buffer position of OBJECT (different from POSITION if
3998 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
3999 previously saw a display specification which already replaced text
4000 display with something else, for example an image; we ignore such
4001 properties after the first one has been processed.
4003 OVERLAY is the overlay this `display' property came from,
4004 or nil if it was a text property.
4006 If SPEC is a `space' or `image' specification, and in some other
4007 cases too, set *POSITION to the position where the `display'
4010 If IT is NULL, only examine the property specification in SPEC, but
4011 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4012 is intended to be displayed in a window on a GUI frame.
4014 Value is non-zero if something was found which replaces the display
4015 of buffer or string text. */
4018 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4019 Lisp_Object overlay
, struct text_pos
*position
,
4020 EMACS_INT bufpos
, int display_replaced_p
,
4024 Lisp_Object location
, value
;
4025 struct text_pos start_pos
= *position
;
4028 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4029 If the result is non-nil, use VALUE instead of SPEC. */
4031 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4040 if (!NILP (form
) && !EQ (form
, Qt
))
4042 int count
= SPECPDL_INDEX ();
4043 struct gcpro gcpro1
;
4045 /* Bind `object' to the object having the `display' property, a
4046 buffer or string. Bind `position' to the position in the
4047 object where the property was found, and `buffer-position'
4048 to the current position in the buffer. */
4051 XSETBUFFER (object
, current_buffer
);
4052 specbind (Qobject
, object
);
4053 specbind (Qposition
, make_number (CHARPOS (*position
)));
4054 specbind (Qbuffer_position
, make_number (bufpos
));
4056 form
= safe_eval (form
);
4058 unbind_to (count
, Qnil
);
4064 /* Handle `(height HEIGHT)' specifications. */
4066 && EQ (XCAR (spec
), Qheight
)
4067 && CONSP (XCDR (spec
)))
4071 if (!FRAME_WINDOW_P (it
->f
))
4074 it
->font_height
= XCAR (XCDR (spec
));
4075 if (!NILP (it
->font_height
))
4077 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4078 int new_height
= -1;
4080 if (CONSP (it
->font_height
)
4081 && (EQ (XCAR (it
->font_height
), Qplus
)
4082 || EQ (XCAR (it
->font_height
), Qminus
))
4083 && CONSP (XCDR (it
->font_height
))
4084 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4086 /* `(+ N)' or `(- N)' where N is an integer. */
4087 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4088 if (EQ (XCAR (it
->font_height
), Qplus
))
4090 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4092 else if (FUNCTIONP (it
->font_height
))
4094 /* Call function with current height as argument.
4095 Value is the new height. */
4097 height
= safe_call1 (it
->font_height
,
4098 face
->lface
[LFACE_HEIGHT_INDEX
]);
4099 if (NUMBERP (height
))
4100 new_height
= XFLOATINT (height
);
4102 else if (NUMBERP (it
->font_height
))
4104 /* Value is a multiple of the canonical char height. */
4107 f
= FACE_FROM_ID (it
->f
,
4108 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4109 new_height
= (XFLOATINT (it
->font_height
)
4110 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4114 /* Evaluate IT->font_height with `height' bound to the
4115 current specified height to get the new height. */
4116 int count
= SPECPDL_INDEX ();
4118 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4119 value
= safe_eval (it
->font_height
);
4120 unbind_to (count
, Qnil
);
4122 if (NUMBERP (value
))
4123 new_height
= XFLOATINT (value
);
4127 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4134 /* Handle `(space-width WIDTH)'. */
4136 && EQ (XCAR (spec
), Qspace_width
)
4137 && CONSP (XCDR (spec
)))
4141 if (!FRAME_WINDOW_P (it
->f
))
4144 value
= XCAR (XCDR (spec
));
4145 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4146 it
->space_width
= value
;
4152 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4154 && EQ (XCAR (spec
), Qslice
))
4160 if (!FRAME_WINDOW_P (it
->f
))
4163 if (tem
= XCDR (spec
), CONSP (tem
))
4165 it
->slice
.x
= XCAR (tem
);
4166 if (tem
= XCDR (tem
), CONSP (tem
))
4168 it
->slice
.y
= XCAR (tem
);
4169 if (tem
= XCDR (tem
), CONSP (tem
))
4171 it
->slice
.width
= XCAR (tem
);
4172 if (tem
= XCDR (tem
), CONSP (tem
))
4173 it
->slice
.height
= XCAR (tem
);
4182 /* Handle `(raise FACTOR)'. */
4184 && EQ (XCAR (spec
), Qraise
)
4185 && CONSP (XCDR (spec
)))
4189 if (!FRAME_WINDOW_P (it
->f
))
4192 #ifdef HAVE_WINDOW_SYSTEM
4193 value
= XCAR (XCDR (spec
));
4194 if (NUMBERP (value
))
4196 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4197 it
->voffset
= - (XFLOATINT (value
)
4198 * (FONT_HEIGHT (face
->font
)));
4200 #endif /* HAVE_WINDOW_SYSTEM */
4206 /* Don't handle the other kinds of display specifications
4207 inside a string that we got from a `display' property. */
4208 if (it
&& it
->string_from_display_prop_p
)
4211 /* Characters having this form of property are not displayed, so
4212 we have to find the end of the property. */
4215 start_pos
= *position
;
4216 *position
= display_prop_end (it
, object
, start_pos
);
4220 /* Stop the scan at that end position--we assume that all
4221 text properties change there. */
4223 it
->stop_charpos
= position
->charpos
;
4225 /* Handle `(left-fringe BITMAP [FACE])'
4226 and `(right-fringe BITMAP [FACE])'. */
4228 && (EQ (XCAR (spec
), Qleft_fringe
)
4229 || EQ (XCAR (spec
), Qright_fringe
))
4230 && CONSP (XCDR (spec
)))
4236 if (!FRAME_WINDOW_P (it
->f
))
4237 /* If we return here, POSITION has been advanced
4238 across the text with this property. */
4241 else if (!frame_window_p
)
4244 #ifdef HAVE_WINDOW_SYSTEM
4245 value
= XCAR (XCDR (spec
));
4246 if (!SYMBOLP (value
)
4247 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4248 /* If we return here, POSITION has been advanced
4249 across the text with this property. */
4254 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4256 if (CONSP (XCDR (XCDR (spec
))))
4258 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4259 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4265 /* Save current settings of IT so that we can restore them
4266 when we are finished with the glyph property value. */
4267 push_it (it
, position
);
4269 it
->area
= TEXT_AREA
;
4270 it
->what
= IT_IMAGE
;
4271 it
->image_id
= -1; /* no image */
4272 it
->position
= start_pos
;
4273 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4274 it
->method
= GET_FROM_IMAGE
;
4275 it
->from_overlay
= Qnil
;
4276 it
->face_id
= face_id
;
4278 /* Say that we haven't consumed the characters with
4279 `display' property yet. The call to pop_it in
4280 set_iterator_to_next will clean this up. */
4281 *position
= start_pos
;
4283 if (EQ (XCAR (spec
), Qleft_fringe
))
4285 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4286 it
->left_user_fringe_face_id
= face_id
;
4290 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4291 it
->right_user_fringe_face_id
= face_id
;
4294 #endif /* HAVE_WINDOW_SYSTEM */
4298 /* Prepare to handle `((margin left-margin) ...)',
4299 `((margin right-margin) ...)' and `((margin nil) ...)'
4300 prefixes for display specifications. */
4301 location
= Qunbound
;
4302 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4306 value
= XCDR (spec
);
4308 value
= XCAR (value
);
4311 if (EQ (XCAR (tem
), Qmargin
)
4312 && (tem
= XCDR (tem
),
4313 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4315 || EQ (tem
, Qleft_margin
)
4316 || EQ (tem
, Qright_margin
))))
4320 if (EQ (location
, Qunbound
))
4326 /* After this point, VALUE is the property after any
4327 margin prefix has been stripped. It must be a string,
4328 an image specification, or `(space ...)'.
4330 LOCATION specifies where to display: `left-margin',
4331 `right-margin' or nil. */
4333 valid_p
= (STRINGP (value
)
4334 #ifdef HAVE_WINDOW_SYSTEM
4335 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4336 && valid_image_p (value
))
4337 #endif /* not HAVE_WINDOW_SYSTEM */
4338 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4340 if (valid_p
&& !display_replaced_p
)
4345 /* Save current settings of IT so that we can restore them
4346 when we are finished with the glyph property value. */
4347 push_it (it
, position
);
4348 it
->from_overlay
= overlay
;
4350 if (NILP (location
))
4351 it
->area
= TEXT_AREA
;
4352 else if (EQ (location
, Qleft_margin
))
4353 it
->area
= LEFT_MARGIN_AREA
;
4355 it
->area
= RIGHT_MARGIN_AREA
;
4357 if (STRINGP (value
))
4360 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4361 it
->current
.overlay_string_index
= -1;
4362 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4363 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4364 it
->method
= GET_FROM_STRING
;
4365 it
->stop_charpos
= 0;
4366 it
->string_from_display_prop_p
= 1;
4367 /* Say that we haven't consumed the characters with
4368 `display' property yet. The call to pop_it in
4369 set_iterator_to_next will clean this up. */
4370 if (BUFFERP (object
))
4371 *position
= start_pos
;
4373 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4375 it
->method
= GET_FROM_STRETCH
;
4377 *position
= it
->position
= start_pos
;
4379 #ifdef HAVE_WINDOW_SYSTEM
4382 it
->what
= IT_IMAGE
;
4383 it
->image_id
= lookup_image (it
->f
, value
);
4384 it
->position
= start_pos
;
4385 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4386 it
->method
= GET_FROM_IMAGE
;
4388 /* Say that we haven't consumed the characters with
4389 `display' property yet. The call to pop_it in
4390 set_iterator_to_next will clean this up. */
4391 *position
= start_pos
;
4393 #endif /* HAVE_WINDOW_SYSTEM */
4398 /* Invalid property or property not supported. Restore
4399 POSITION to what it was before. */
4400 *position
= start_pos
;
4404 /* Check if PROP is a display property value whose text should be
4405 treated as intangible. OVERLAY is the overlay from which PROP
4406 came, or nil if it came from a text property. CHARPOS and BYTEPOS
4407 specify the buffer position covered by PROP. */
4410 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
4411 EMACS_INT charpos
, EMACS_INT bytepos
)
4413 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
4414 struct text_pos position
;
4416 SET_TEXT_POS (position
, charpos
, bytepos
);
4417 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
4418 &position
, charpos
, frame_window_p
);
4422 /* Return 1 if PROP is a display sub-property value containing STRING.
4424 Implementation note: this and the following function are really
4425 special cases of handle_display_spec and
4426 handle_single_display_spec, and should ideally use the same code.
4427 Until they do, these two pairs must be consistent and must be
4428 modified in sync. */
4431 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
4433 if (EQ (string
, prop
))
4436 /* Skip over `when FORM'. */
4437 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4442 /* Actually, the condition following `when' should be eval'ed,
4443 like handle_single_display_spec does, and we should return
4444 zero if it evaluates to nil. However, this function is
4445 called only when the buffer was already displayed and some
4446 glyph in the glyph matrix was found to come from a display
4447 string. Therefore, the condition was already evaluated, and
4448 the result was non-nil, otherwise the display string wouldn't
4449 have been displayed and we would have never been called for
4450 this property. Thus, we can skip the evaluation and assume
4451 its result is non-nil. */
4456 /* Skip over `margin LOCATION'. */
4457 if (EQ (XCAR (prop
), Qmargin
))
4468 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
4472 /* Return 1 if STRING appears in the `display' property PROP. */
4475 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
4478 && !EQ (XCAR (prop
), Qwhen
)
4479 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
4481 /* A list of sub-properties. */
4482 while (CONSP (prop
))
4484 if (single_display_spec_string_p (XCAR (prop
), string
))
4489 else if (VECTORP (prop
))
4491 /* A vector of sub-properties. */
4493 for (i
= 0; i
< ASIZE (prop
); ++i
)
4494 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4498 return single_display_spec_string_p (prop
, string
);
4503 /* Look for STRING in overlays and text properties in the current
4504 buffer, between character positions FROM and TO (excluding TO).
4505 BACK_P non-zero means look back (in this case, TO is supposed to be
4507 Value is the first character position where STRING was found, or
4508 zero if it wasn't found before hitting TO.
4510 This function may only use code that doesn't eval because it is
4511 called asynchronously from note_mouse_highlight. */
4514 string_buffer_position_lim (Lisp_Object string
,
4515 EMACS_INT from
, EMACS_INT to
, int back_p
)
4517 Lisp_Object limit
, prop
, pos
;
4520 pos
= make_number (from
);
4522 if (!back_p
) /* looking forward */
4524 limit
= make_number (min (to
, ZV
));
4525 while (!found
&& !EQ (pos
, limit
))
4527 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4528 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4531 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4535 else /* looking back */
4537 limit
= make_number (max (to
, BEGV
));
4538 while (!found
&& !EQ (pos
, limit
))
4540 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4541 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4544 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4549 return found
? XINT (pos
) : 0;
4552 /* Determine which buffer position in current buffer STRING comes from.
4553 AROUND_CHARPOS is an approximate position where it could come from.
4554 Value is the buffer position or 0 if it couldn't be determined.
4556 This function is necessary because we don't record buffer positions
4557 in glyphs generated from strings (to keep struct glyph small).
4558 This function may only use code that doesn't eval because it is
4559 called asynchronously from note_mouse_highlight. */
4562 string_buffer_position (Lisp_Object string
, EMACS_INT around_charpos
)
4564 const int MAX_DISTANCE
= 1000;
4565 EMACS_INT found
= string_buffer_position_lim (string
, around_charpos
,
4566 around_charpos
+ MAX_DISTANCE
,
4570 found
= string_buffer_position_lim (string
, around_charpos
,
4571 around_charpos
- MAX_DISTANCE
, 1);
4577 /***********************************************************************
4578 `composition' property
4579 ***********************************************************************/
4581 /* Set up iterator IT from `composition' property at its current
4582 position. Called from handle_stop. */
4584 static enum prop_handled
4585 handle_composition_prop (struct it
*it
)
4587 Lisp_Object prop
, string
;
4588 EMACS_INT pos
, pos_byte
, start
, end
;
4590 if (STRINGP (it
->string
))
4594 pos
= IT_STRING_CHARPOS (*it
);
4595 pos_byte
= IT_STRING_BYTEPOS (*it
);
4596 string
= it
->string
;
4597 s
= SDATA (string
) + pos_byte
;
4598 it
->c
= STRING_CHAR (s
);
4602 pos
= IT_CHARPOS (*it
);
4603 pos_byte
= IT_BYTEPOS (*it
);
4605 it
->c
= FETCH_CHAR (pos_byte
);
4608 /* If there's a valid composition and point is not inside of the
4609 composition (in the case that the composition is from the current
4610 buffer), draw a glyph composed from the composition components. */
4611 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4612 && COMPOSITION_VALID_P (start
, end
, prop
)
4613 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4617 if (STRINGP (it
->string
))
4618 pos_byte
= string_char_to_byte (it
->string
, start
);
4620 pos_byte
= CHAR_TO_BYTE (start
);
4622 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4625 if (it
->cmp_it
.id
>= 0)
4628 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4629 it
->cmp_it
.nglyphs
= -1;
4633 return HANDLED_NORMALLY
;
4638 /***********************************************************************
4640 ***********************************************************************/
4642 /* The following structure is used to record overlay strings for
4643 later sorting in load_overlay_strings. */
4645 struct overlay_entry
4647 Lisp_Object overlay
;
4654 /* Set up iterator IT from overlay strings at its current position.
4655 Called from handle_stop. */
4657 static enum prop_handled
4658 handle_overlay_change (struct it
*it
)
4660 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4661 return HANDLED_RECOMPUTE_PROPS
;
4663 return HANDLED_NORMALLY
;
4667 /* Set up the next overlay string for delivery by IT, if there is an
4668 overlay string to deliver. Called by set_iterator_to_next when the
4669 end of the current overlay string is reached. If there are more
4670 overlay strings to display, IT->string and
4671 IT->current.overlay_string_index are set appropriately here.
4672 Otherwise IT->string is set to nil. */
4675 next_overlay_string (struct it
*it
)
4677 ++it
->current
.overlay_string_index
;
4678 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4680 /* No more overlay strings. Restore IT's settings to what
4681 they were before overlay strings were processed, and
4682 continue to deliver from current_buffer. */
4684 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4687 || (NILP (it
->string
)
4688 && it
->method
== GET_FROM_BUFFER
4689 && it
->stop_charpos
>= BEGV
4690 && it
->stop_charpos
<= it
->end_charpos
));
4691 it
->current
.overlay_string_index
= -1;
4692 it
->n_overlay_strings
= 0;
4693 it
->overlay_strings_charpos
= -1;
4695 /* If we're at the end of the buffer, record that we have
4696 processed the overlay strings there already, so that
4697 next_element_from_buffer doesn't try it again. */
4698 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4699 it
->overlay_strings_at_end_processed_p
= 1;
4703 /* There are more overlay strings to process. If
4704 IT->current.overlay_string_index has advanced to a position
4705 where we must load IT->overlay_strings with more strings, do
4706 it. We must load at the IT->overlay_strings_charpos where
4707 IT->n_overlay_strings was originally computed; when invisible
4708 text is present, this might not be IT_CHARPOS (Bug#7016). */
4709 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4711 if (it
->current
.overlay_string_index
&& i
== 0)
4712 load_overlay_strings (it
, it
->overlay_strings_charpos
);
4714 /* Initialize IT to deliver display elements from the overlay
4716 it
->string
= it
->overlay_strings
[i
];
4717 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4718 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4719 it
->method
= GET_FROM_STRING
;
4720 it
->stop_charpos
= 0;
4721 if (it
->cmp_it
.stop_pos
>= 0)
4722 it
->cmp_it
.stop_pos
= 0;
4729 /* Compare two overlay_entry structures E1 and E2. Used as a
4730 comparison function for qsort in load_overlay_strings. Overlay
4731 strings for the same position are sorted so that
4733 1. All after-strings come in front of before-strings, except
4734 when they come from the same overlay.
4736 2. Within after-strings, strings are sorted so that overlay strings
4737 from overlays with higher priorities come first.
4739 2. Within before-strings, strings are sorted so that overlay
4740 strings from overlays with higher priorities come last.
4742 Value is analogous to strcmp. */
4746 compare_overlay_entries (const void *e1
, const void *e2
)
4748 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4749 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4752 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4754 /* Let after-strings appear in front of before-strings if
4755 they come from different overlays. */
4756 if (EQ (entry1
->overlay
, entry2
->overlay
))
4757 result
= entry1
->after_string_p
? 1 : -1;
4759 result
= entry1
->after_string_p
? -1 : 1;
4761 else if (entry1
->after_string_p
)
4762 /* After-strings sorted in order of decreasing priority. */
4763 result
= entry2
->priority
- entry1
->priority
;
4765 /* Before-strings sorted in order of increasing priority. */
4766 result
= entry1
->priority
- entry2
->priority
;
4772 /* Load the vector IT->overlay_strings with overlay strings from IT's
4773 current buffer position, or from CHARPOS if that is > 0. Set
4774 IT->n_overlays to the total number of overlay strings found.
4776 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4777 a time. On entry into load_overlay_strings,
4778 IT->current.overlay_string_index gives the number of overlay
4779 strings that have already been loaded by previous calls to this
4782 IT->add_overlay_start contains an additional overlay start
4783 position to consider for taking overlay strings from, if non-zero.
4784 This position comes into play when the overlay has an `invisible'
4785 property, and both before and after-strings. When we've skipped to
4786 the end of the overlay, because of its `invisible' property, we
4787 nevertheless want its before-string to appear.
4788 IT->add_overlay_start will contain the overlay start position
4791 Overlay strings are sorted so that after-string strings come in
4792 front of before-string strings. Within before and after-strings,
4793 strings are sorted by overlay priority. See also function
4794 compare_overlay_entries. */
4797 load_overlay_strings (struct it
*it
, EMACS_INT charpos
)
4799 Lisp_Object overlay
, window
, str
, invisible
;
4800 struct Lisp_Overlay
*ov
;
4801 EMACS_INT start
, end
;
4803 int n
= 0, i
, j
, invis_p
;
4804 struct overlay_entry
*entries
4805 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4808 charpos
= IT_CHARPOS (*it
);
4810 /* Append the overlay string STRING of overlay OVERLAY to vector
4811 `entries' which has size `size' and currently contains `n'
4812 elements. AFTER_P non-zero means STRING is an after-string of
4814 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4817 Lisp_Object priority; \
4821 int new_size = 2 * size; \
4822 struct overlay_entry *old = entries; \
4824 (struct overlay_entry *) alloca (new_size \
4825 * sizeof *entries); \
4826 memcpy (entries, old, size * sizeof *entries); \
4830 entries[n].string = (STRING); \
4831 entries[n].overlay = (OVERLAY); \
4832 priority = Foverlay_get ((OVERLAY), Qpriority); \
4833 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4834 entries[n].after_string_p = (AFTER_P); \
4839 /* Process overlay before the overlay center. */
4840 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4842 XSETMISC (overlay
, ov
);
4843 xassert (OVERLAYP (overlay
));
4844 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4845 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4850 /* Skip this overlay if it doesn't start or end at IT's current
4852 if (end
!= charpos
&& start
!= charpos
)
4855 /* Skip this overlay if it doesn't apply to IT->w. */
4856 window
= Foverlay_get (overlay
, Qwindow
);
4857 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4860 /* If the text ``under'' the overlay is invisible, both before-
4861 and after-strings from this overlay are visible; start and
4862 end position are indistinguishable. */
4863 invisible
= Foverlay_get (overlay
, Qinvisible
);
4864 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4866 /* If overlay has a non-empty before-string, record it. */
4867 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4868 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4870 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4872 /* If overlay has a non-empty after-string, record it. */
4873 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4874 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4876 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4879 /* Process overlays after the overlay center. */
4880 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4882 XSETMISC (overlay
, ov
);
4883 xassert (OVERLAYP (overlay
));
4884 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4885 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4887 if (start
> charpos
)
4890 /* Skip this overlay if it doesn't start or end at IT's current
4892 if (end
!= charpos
&& start
!= charpos
)
4895 /* Skip this overlay if it doesn't apply to IT->w. */
4896 window
= Foverlay_get (overlay
, Qwindow
);
4897 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4900 /* If the text ``under'' the overlay is invisible, it has a zero
4901 dimension, and both before- and after-strings apply. */
4902 invisible
= Foverlay_get (overlay
, Qinvisible
);
4903 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4905 /* If overlay has a non-empty before-string, record it. */
4906 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4907 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4909 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4911 /* If overlay has a non-empty after-string, record it. */
4912 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4913 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4915 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4918 #undef RECORD_OVERLAY_STRING
4922 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4924 /* Record number of overlay strings, and where we computed it. */
4925 it
->n_overlay_strings
= n
;
4926 it
->overlay_strings_charpos
= charpos
;
4928 /* IT->current.overlay_string_index is the number of overlay strings
4929 that have already been consumed by IT. Copy some of the
4930 remaining overlay strings to IT->overlay_strings. */
4932 j
= it
->current
.overlay_string_index
;
4933 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4935 it
->overlay_strings
[i
] = entries
[j
].string
;
4936 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
4943 /* Get the first chunk of overlay strings at IT's current buffer
4944 position, or at CHARPOS if that is > 0. Value is non-zero if at
4945 least one overlay string was found. */
4948 get_overlay_strings_1 (struct it
*it
, EMACS_INT charpos
, int compute_stop_p
)
4950 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4951 process. This fills IT->overlay_strings with strings, and sets
4952 IT->n_overlay_strings to the total number of strings to process.
4953 IT->pos.overlay_string_index has to be set temporarily to zero
4954 because load_overlay_strings needs this; it must be set to -1
4955 when no overlay strings are found because a zero value would
4956 indicate a position in the first overlay string. */
4957 it
->current
.overlay_string_index
= 0;
4958 load_overlay_strings (it
, charpos
);
4960 /* If we found overlay strings, set up IT to deliver display
4961 elements from the first one. Otherwise set up IT to deliver
4962 from current_buffer. */
4963 if (it
->n_overlay_strings
)
4965 /* Make sure we know settings in current_buffer, so that we can
4966 restore meaningful values when we're done with the overlay
4969 compute_stop_pos (it
);
4970 xassert (it
->face_id
>= 0);
4972 /* Save IT's settings. They are restored after all overlay
4973 strings have been processed. */
4974 xassert (!compute_stop_p
|| it
->sp
== 0);
4976 /* When called from handle_stop, there might be an empty display
4977 string loaded. In that case, don't bother saving it. */
4978 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
4981 /* Set up IT to deliver display elements from the first overlay
4983 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4984 it
->string
= it
->overlay_strings
[0];
4985 it
->from_overlay
= Qnil
;
4986 it
->stop_charpos
= 0;
4987 xassert (STRINGP (it
->string
));
4988 it
->end_charpos
= SCHARS (it
->string
);
4989 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4990 it
->method
= GET_FROM_STRING
;
4994 it
->current
.overlay_string_index
= -1;
4999 get_overlay_strings (struct it
*it
, EMACS_INT charpos
)
5002 it
->method
= GET_FROM_BUFFER
;
5004 (void) get_overlay_strings_1 (it
, charpos
, 1);
5008 /* Value is non-zero if we found at least one overlay string. */
5009 return STRINGP (it
->string
);
5014 /***********************************************************************
5015 Saving and restoring state
5016 ***********************************************************************/
5018 /* Save current settings of IT on IT->stack. Called, for example,
5019 before setting up IT for an overlay string, to be able to restore
5020 IT's settings to what they were after the overlay string has been
5021 processed. If POSITION is non-NULL, it is the position to save on
5022 the stack instead of IT->position. */
5025 push_it (struct it
*it
, struct text_pos
*position
)
5027 struct iterator_stack_entry
*p
;
5029 xassert (it
->sp
< IT_STACK_SIZE
);
5030 p
= it
->stack
+ it
->sp
;
5032 p
->stop_charpos
= it
->stop_charpos
;
5033 p
->prev_stop
= it
->prev_stop
;
5034 p
->base_level_stop
= it
->base_level_stop
;
5035 p
->cmp_it
= it
->cmp_it
;
5036 xassert (it
->face_id
>= 0);
5037 p
->face_id
= it
->face_id
;
5038 p
->string
= it
->string
;
5039 p
->method
= it
->method
;
5040 p
->from_overlay
= it
->from_overlay
;
5043 case GET_FROM_IMAGE
:
5044 p
->u
.image
.object
= it
->object
;
5045 p
->u
.image
.image_id
= it
->image_id
;
5046 p
->u
.image
.slice
= it
->slice
;
5048 case GET_FROM_STRETCH
:
5049 p
->u
.stretch
.object
= it
->object
;
5052 p
->position
= position
? *position
: it
->position
;
5053 p
->current
= it
->current
;
5054 p
->end_charpos
= it
->end_charpos
;
5055 p
->string_nchars
= it
->string_nchars
;
5057 p
->multibyte_p
= it
->multibyte_p
;
5058 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5059 p
->space_width
= it
->space_width
;
5060 p
->font_height
= it
->font_height
;
5061 p
->voffset
= it
->voffset
;
5062 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5063 p
->display_ellipsis_p
= 0;
5064 p
->line_wrap
= it
->line_wrap
;
5069 iterate_out_of_display_property (struct it
*it
)
5071 /* Maybe initialize paragraph direction. If we are at the beginning
5072 of a new paragraph, next_element_from_buffer may not have a
5073 chance to do that. */
5074 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
5075 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5076 /* prev_stop can be zero, so check against BEGV as well. */
5077 while (it
->bidi_it
.charpos
>= BEGV
5078 && it
->prev_stop
<= it
->bidi_it
.charpos
5079 && it
->bidi_it
.charpos
< CHARPOS (it
->position
))
5080 bidi_move_to_visually_next (&it
->bidi_it
);
5081 /* Record the stop_pos we just crossed, for when we cross it
5083 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5084 it
->prev_stop
= CHARPOS (it
->position
);
5085 /* If we ended up not where pop_it put us, resync IT's
5086 positional members with the bidi iterator. */
5087 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5089 SET_TEXT_POS (it
->position
,
5090 it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5091 it
->current
.pos
= it
->position
;
5095 /* Restore IT's settings from IT->stack. Called, for example, when no
5096 more overlay strings must be processed, and we return to delivering
5097 display elements from a buffer, or when the end of a string from a
5098 `display' property is reached and we return to delivering display
5099 elements from an overlay string, or from a buffer. */
5102 pop_it (struct it
*it
)
5104 struct iterator_stack_entry
*p
;
5106 xassert (it
->sp
> 0);
5108 p
= it
->stack
+ it
->sp
;
5109 it
->stop_charpos
= p
->stop_charpos
;
5110 it
->prev_stop
= p
->prev_stop
;
5111 it
->base_level_stop
= p
->base_level_stop
;
5112 it
->cmp_it
= p
->cmp_it
;
5113 it
->face_id
= p
->face_id
;
5114 it
->current
= p
->current
;
5115 it
->position
= p
->position
;
5116 it
->string
= p
->string
;
5117 it
->from_overlay
= p
->from_overlay
;
5118 if (NILP (it
->string
))
5119 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5120 it
->method
= p
->method
;
5123 case GET_FROM_IMAGE
:
5124 it
->image_id
= p
->u
.image
.image_id
;
5125 it
->object
= p
->u
.image
.object
;
5126 it
->slice
= p
->u
.image
.slice
;
5128 case GET_FROM_STRETCH
:
5129 it
->object
= p
->u
.comp
.object
;
5131 case GET_FROM_BUFFER
:
5132 it
->object
= it
->w
->buffer
;
5135 /* Bidi-iterate until we get out of the portion of text, if
5136 any, covered by a `display' text property or an overlay
5137 with `display' property. (We cannot just jump there,
5138 because the internal coherency of the bidi iterator state
5139 can not be preserved across such jumps.) We also must
5140 determine the paragraph base direction if the overlay we
5141 just processed is at the beginning of a new
5143 iterate_out_of_display_property (it
);
5146 case GET_FROM_STRING
:
5147 it
->object
= it
->string
;
5149 case GET_FROM_DISPLAY_VECTOR
:
5151 it
->method
= GET_FROM_C_STRING
;
5152 else if (STRINGP (it
->string
))
5153 it
->method
= GET_FROM_STRING
;
5156 it
->method
= GET_FROM_BUFFER
;
5157 it
->object
= it
->w
->buffer
;
5160 it
->end_charpos
= p
->end_charpos
;
5161 it
->string_nchars
= p
->string_nchars
;
5163 it
->multibyte_p
= p
->multibyte_p
;
5164 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5165 it
->space_width
= p
->space_width
;
5166 it
->font_height
= p
->font_height
;
5167 it
->voffset
= p
->voffset
;
5168 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5169 it
->line_wrap
= p
->line_wrap
;
5174 /***********************************************************************
5176 ***********************************************************************/
5178 /* Set IT's current position to the previous line start. */
5181 back_to_previous_line_start (struct it
*it
)
5183 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5184 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5188 /* Move IT to the next line start.
5190 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5191 we skipped over part of the text (as opposed to moving the iterator
5192 continuously over the text). Otherwise, don't change the value
5195 Newlines may come from buffer text, overlay strings, or strings
5196 displayed via the `display' property. That's the reason we can't
5197 simply use find_next_newline_no_quit.
5199 Note that this function may not skip over invisible text that is so
5200 because of text properties and immediately follows a newline. If
5201 it would, function reseat_at_next_visible_line_start, when called
5202 from set_iterator_to_next, would effectively make invisible
5203 characters following a newline part of the wrong glyph row, which
5204 leads to wrong cursor motion. */
5207 forward_to_next_line_start (struct it
*it
, int *skipped_p
)
5209 int old_selective
, newline_found_p
, n
;
5210 const int MAX_NEWLINE_DISTANCE
= 500;
5212 /* If already on a newline, just consume it to avoid unintended
5213 skipping over invisible text below. */
5214 if (it
->what
== IT_CHARACTER
5216 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5218 set_iterator_to_next (it
, 0);
5223 /* Don't handle selective display in the following. It's (a)
5224 unnecessary because it's done by the caller, and (b) leads to an
5225 infinite recursion because next_element_from_ellipsis indirectly
5226 calls this function. */
5227 old_selective
= it
->selective
;
5230 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5231 from buffer text. */
5232 for (n
= newline_found_p
= 0;
5233 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5234 n
+= STRINGP (it
->string
) ? 0 : 1)
5236 if (!get_next_display_element (it
))
5238 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5239 set_iterator_to_next (it
, 0);
5242 /* If we didn't find a newline near enough, see if we can use a
5244 if (!newline_found_p
)
5246 EMACS_INT start
= IT_CHARPOS (*it
);
5247 EMACS_INT limit
= find_next_newline_no_quit (start
, 1);
5250 xassert (!STRINGP (it
->string
));
5252 /* If there isn't any `display' property in sight, and no
5253 overlays, we can just use the position of the newline in
5255 if (it
->stop_charpos
>= limit
5256 || ((pos
= Fnext_single_property_change (make_number (start
),
5258 Qnil
, make_number (limit
)),
5260 && next_overlay_change (start
) == ZV
))
5262 IT_CHARPOS (*it
) = limit
;
5263 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5264 *skipped_p
= newline_found_p
= 1;
5268 while (get_next_display_element (it
)
5269 && !newline_found_p
)
5271 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5272 set_iterator_to_next (it
, 0);
5277 it
->selective
= old_selective
;
5278 return newline_found_p
;
5282 /* Set IT's current position to the previous visible line start. Skip
5283 invisible text that is so either due to text properties or due to
5284 selective display. Caution: this does not change IT->current_x and
5288 back_to_previous_visible_line_start (struct it
*it
)
5290 while (IT_CHARPOS (*it
) > BEGV
)
5292 back_to_previous_line_start (it
);
5294 if (IT_CHARPOS (*it
) <= BEGV
)
5297 /* If selective > 0, then lines indented more than its value are
5299 if (it
->selective
> 0
5300 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5301 (double) it
->selective
)) /* iftc */
5304 /* Check the newline before point for invisibility. */
5307 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5308 Qinvisible
, it
->window
);
5309 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5313 if (IT_CHARPOS (*it
) <= BEGV
)
5320 Lisp_Object val
, overlay
;
5322 /* If newline is part of a composition, continue from start of composition */
5323 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5324 && beg
< IT_CHARPOS (*it
))
5327 /* If newline is replaced by a display property, find start of overlay
5328 or interval and continue search from that point. */
5330 pos
= --IT_CHARPOS (it2
);
5333 it2
.string_from_display_prop_p
= 0;
5334 if (handle_display_prop (&it2
) == HANDLED_RETURN
5335 && !NILP (val
= get_char_property_and_overlay
5336 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5337 && (OVERLAYP (overlay
)
5338 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5339 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5342 /* Newline is not replaced by anything -- so we are done. */
5348 IT_CHARPOS (*it
) = beg
;
5349 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5353 it
->continuation_lines_width
= 0;
5355 xassert (IT_CHARPOS (*it
) >= BEGV
);
5356 xassert (IT_CHARPOS (*it
) == BEGV
5357 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5362 /* Reseat iterator IT at the previous visible line start. Skip
5363 invisible text that is so either due to text properties or due to
5364 selective display. At the end, update IT's overlay information,
5365 face information etc. */
5368 reseat_at_previous_visible_line_start (struct it
*it
)
5370 back_to_previous_visible_line_start (it
);
5371 reseat (it
, it
->current
.pos
, 1);
5376 /* Reseat iterator IT on the next visible line start in the current
5377 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5378 preceding the line start. Skip over invisible text that is so
5379 because of selective display. Compute faces, overlays etc at the
5380 new position. Note that this function does not skip over text that
5381 is invisible because of text properties. */
5384 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
5386 int newline_found_p
, skipped_p
= 0;
5388 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5390 /* Skip over lines that are invisible because they are indented
5391 more than the value of IT->selective. */
5392 if (it
->selective
> 0)
5393 while (IT_CHARPOS (*it
) < ZV
5394 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5395 (double) it
->selective
)) /* iftc */
5397 xassert (IT_BYTEPOS (*it
) == BEGV
5398 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5399 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5402 /* Position on the newline if that's what's requested. */
5403 if (on_newline_p
&& newline_found_p
)
5405 if (STRINGP (it
->string
))
5407 if (IT_STRING_CHARPOS (*it
) > 0)
5409 --IT_STRING_CHARPOS (*it
);
5410 --IT_STRING_BYTEPOS (*it
);
5413 else if (IT_CHARPOS (*it
) > BEGV
)
5417 reseat (it
, it
->current
.pos
, 0);
5421 reseat (it
, it
->current
.pos
, 0);
5428 /***********************************************************************
5429 Changing an iterator's position
5430 ***********************************************************************/
5432 /* Change IT's current position to POS in current_buffer. If FORCE_P
5433 is non-zero, always check for text properties at the new position.
5434 Otherwise, text properties are only looked up if POS >=
5435 IT->check_charpos of a property. */
5438 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
5440 EMACS_INT original_pos
= IT_CHARPOS (*it
);
5442 reseat_1 (it
, pos
, 0);
5444 /* Determine where to check text properties. Avoid doing it
5445 where possible because text property lookup is very expensive. */
5447 || CHARPOS (pos
) > it
->stop_charpos
5448 || CHARPOS (pos
) < original_pos
)
5452 /* For bidi iteration, we need to prime prev_stop and
5453 base_level_stop with our best estimations. */
5454 if (CHARPOS (pos
) < it
->prev_stop
)
5456 handle_stop_backwards (it
, BEGV
);
5457 if (CHARPOS (pos
) < it
->base_level_stop
)
5458 it
->base_level_stop
= 0;
5460 else if (CHARPOS (pos
) > it
->stop_charpos
5461 && it
->stop_charpos
>= BEGV
)
5462 handle_stop_backwards (it
, it
->stop_charpos
);
5469 it
->prev_stop
= it
->base_level_stop
= 0;
5478 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5479 IT->stop_pos to POS, also. */
5482 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
5484 /* Don't call this function when scanning a C string. */
5485 xassert (it
->s
== NULL
);
5487 /* POS must be a reasonable value. */
5488 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5490 it
->current
.pos
= it
->position
= pos
;
5491 it
->end_charpos
= ZV
;
5493 it
->current
.dpvec_index
= -1;
5494 it
->current
.overlay_string_index
= -1;
5495 IT_STRING_CHARPOS (*it
) = -1;
5496 IT_STRING_BYTEPOS (*it
) = -1;
5498 it
->string_from_display_prop_p
= 0;
5499 it
->method
= GET_FROM_BUFFER
;
5500 it
->object
= it
->w
->buffer
;
5501 it
->area
= TEXT_AREA
;
5502 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
5504 it
->string_from_display_prop_p
= 0;
5505 it
->face_before_selective_p
= 0;
5508 it
->bidi_it
.first_elt
= 1;
5509 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5510 it
->bidi_it
.disp_pos
= -1;
5511 it
->bidi_it
.string
.s
= NULL
;
5512 it
->bidi_it
.string
.lstring
= Qnil
;
5513 it
->bidi_it
.string
.bufpos
= 0;
5518 it
->stop_charpos
= CHARPOS (pos
);
5519 it
->base_level_stop
= CHARPOS (pos
);
5524 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5525 If S is non-null, it is a C string to iterate over. Otherwise,
5526 STRING gives a Lisp string to iterate over.
5528 If PRECISION > 0, don't return more then PRECISION number of
5529 characters from the string.
5531 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5532 characters have been returned. FIELD_WIDTH < 0 means an infinite
5535 MULTIBYTE = 0 means disable processing of multibyte characters,
5536 MULTIBYTE > 0 means enable it,
5537 MULTIBYTE < 0 means use IT->multibyte_p.
5539 IT must be initialized via a prior call to init_iterator before
5540 calling this function. */
5543 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
5544 EMACS_INT charpos
, EMACS_INT precision
, int field_width
,
5547 /* No region in strings. */
5548 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5550 /* No text property checks performed by default, but see below. */
5551 it
->stop_charpos
= -1;
5553 /* Set iterator position and end position. */
5554 memset (&it
->current
, 0, sizeof it
->current
);
5555 it
->current
.overlay_string_index
= -1;
5556 it
->current
.dpvec_index
= -1;
5557 xassert (charpos
>= 0);
5559 /* If STRING is specified, use its multibyteness, otherwise use the
5560 setting of MULTIBYTE, if specified. */
5562 it
->multibyte_p
= multibyte
> 0;
5564 /* String reordering is controlled by the default value of
5565 bidi-display-reordering. */
5567 it
->multibyte_p
&& BVAR (&buffer_defaults
, bidi_display_reordering
);
5572 xassert (STRINGP (string
));
5573 it
->string
= string
;
5575 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5576 it
->method
= GET_FROM_STRING
;
5577 it
->current
.string_pos
= string_pos (charpos
, string
);
5581 it
->paragraph_embedding
= NEUTRAL_DIR
;
5582 it
->bidi_it
.string
.lstring
= string
;
5583 it
->bidi_it
.string
.s
= SDATA (string
);
5584 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5585 it
->bidi_it
.string
.bufpos
= 0;
5586 it
->bidi_it
.string
.from_disp_str
= 0;
5587 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
5588 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5594 it
->s
= (const unsigned char *) s
;
5597 /* Note that we use IT->current.pos, not it->current.string_pos,
5598 for displaying C strings. */
5599 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5600 if (it
->multibyte_p
)
5602 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5603 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5607 it
->paragraph_embedding
= NEUTRAL_DIR
;
5608 it
->bidi_it
.string
.lstring
= Qnil
;
5609 it
->bidi_it
.string
.s
= s
;
5610 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5611 it
->bidi_it
.string
.bufpos
= 0;
5612 it
->bidi_it
.string
.from_disp_str
= 0;
5613 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
5620 /* Unibyte (a.k.a. ASCII) C strings are never bidi-reordered. */
5621 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5622 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5625 it
->method
= GET_FROM_C_STRING
;
5628 /* PRECISION > 0 means don't return more than PRECISION characters
5630 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5632 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5635 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5639 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5640 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5641 FIELD_WIDTH < 0 means infinite field width. This is useful for
5642 padding with `-' at the end of a mode line. */
5643 if (field_width
< 0)
5644 field_width
= INFINITY
;
5645 /* Implementation note: We deliberately don't enlarge
5646 it->bidi_it.string.schars here to fit it->end_charpos, because
5647 the bidi iterator cannot produce characters out of thin air. */
5648 if (field_width
> it
->end_charpos
- charpos
)
5649 it
->end_charpos
= charpos
+ field_width
;
5651 /* Use the standard display table for displaying strings. */
5652 if (DISP_TABLE_P (Vstandard_display_table
))
5653 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5655 it
->stop_charpos
= charpos
;
5657 it
->prev_stop
= charpos
;
5658 it
->base_level_stop
= 0;
5661 it
->bidi_it
.first_elt
= 1;
5662 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
5663 it
->bidi_it
.disp_pos
= -1;
5666 if (s
== NULL
&& it
->multibyte_p
)
5668 EMACS_INT endpos
= SCHARS (it
->string
);
5669 if (endpos
> it
->end_charpos
)
5670 endpos
= it
->end_charpos
;
5671 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5679 /***********************************************************************
5681 ***********************************************************************/
5683 /* Map enum it_method value to corresponding next_element_from_* function. */
5685 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
5687 next_element_from_buffer
,
5688 next_element_from_display_vector
,
5689 next_element_from_string
,
5690 next_element_from_c_string
,
5691 next_element_from_image
,
5692 next_element_from_stretch
5695 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5698 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5699 (possibly with the following characters). */
5701 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5702 ((IT)->cmp_it.id >= 0 \
5703 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5704 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5705 END_CHARPOS, (IT)->w, \
5706 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5710 /* Lookup the char-table Vglyphless_char_display for character C (-1
5711 if we want information for no-font case), and return the display
5712 method symbol. By side-effect, update it->what and
5713 it->glyphless_method. This function is called from
5714 get_next_display_element for each character element, and from
5715 x_produce_glyphs when no suitable font was found. */
5718 lookup_glyphless_char_display (int c
, struct it
*it
)
5720 Lisp_Object glyphless_method
= Qnil
;
5722 if (CHAR_TABLE_P (Vglyphless_char_display
)
5723 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
5727 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
5728 if (CONSP (glyphless_method
))
5729 glyphless_method
= FRAME_WINDOW_P (it
->f
)
5730 ? XCAR (glyphless_method
)
5731 : XCDR (glyphless_method
);
5734 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
5738 if (NILP (glyphless_method
))
5741 /* The default is to display the character by a proper font. */
5743 /* The default for the no-font case is to display an empty box. */
5744 glyphless_method
= Qempty_box
;
5746 if (EQ (glyphless_method
, Qzero_width
))
5749 return glyphless_method
;
5750 /* This method can't be used for the no-font case. */
5751 glyphless_method
= Qempty_box
;
5753 if (EQ (glyphless_method
, Qthin_space
))
5754 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
5755 else if (EQ (glyphless_method
, Qempty_box
))
5756 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
5757 else if (EQ (glyphless_method
, Qhex_code
))
5758 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
5759 else if (STRINGP (glyphless_method
))
5760 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
5763 /* Invalid value. We use the default method. */
5764 glyphless_method
= Qnil
;
5767 it
->what
= IT_GLYPHLESS
;
5768 return glyphless_method
;
5771 /* Load IT's display element fields with information about the next
5772 display element from the current position of IT. Value is zero if
5773 end of buffer (or C string) is reached. */
5775 static struct frame
*last_escape_glyph_frame
= NULL
;
5776 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5777 static int last_escape_glyph_merged_face_id
= 0;
5779 struct frame
*last_glyphless_glyph_frame
= NULL
;
5780 unsigned last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
5781 int last_glyphless_glyph_merged_face_id
= 0;
5784 get_next_display_element (struct it
*it
)
5786 /* Non-zero means that we found a display element. Zero means that
5787 we hit the end of what we iterate over. Performance note: the
5788 function pointer `method' used here turns out to be faster than
5789 using a sequence of if-statements. */
5793 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5795 if (it
->what
== IT_CHARACTER
)
5797 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
5798 and only if (a) the resolved directionality of that character
5800 /* FIXME: Do we need an exception for characters from display
5802 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
5803 it
->c
= bidi_mirror_char (it
->c
);
5804 /* Map via display table or translate control characters.
5805 IT->c, IT->len etc. have been set to the next character by
5806 the function call above. If we have a display table, and it
5807 contains an entry for IT->c, translate it. Don't do this if
5808 IT->c itself comes from a display table, otherwise we could
5809 end up in an infinite recursion. (An alternative could be to
5810 count the recursion depth of this function and signal an
5811 error when a certain maximum depth is reached.) Is it worth
5813 if (success_p
&& it
->dpvec
== NULL
)
5816 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5817 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5818 nbsp_or_shy
= char_is_other
;
5819 int c
= it
->c
; /* This is the character to display. */
5821 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
5823 xassert (SINGLE_BYTE_CHAR_P (c
));
5824 if (unibyte_display_via_language_environment
)
5826 c
= DECODE_CHAR (unibyte
, c
);
5828 c
= BYTE8_TO_CHAR (it
->c
);
5831 c
= BYTE8_TO_CHAR (it
->c
);
5835 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
5838 struct Lisp_Vector
*v
= XVECTOR (dv
);
5840 /* Return the first character from the display table
5841 entry, if not empty. If empty, don't display the
5842 current character. */
5845 it
->dpvec_char_len
= it
->len
;
5846 it
->dpvec
= v
->contents
;
5847 it
->dpend
= v
->contents
+ v
->header
.size
;
5848 it
->current
.dpvec_index
= 0;
5849 it
->dpvec_face_id
= -1;
5850 it
->saved_face_id
= it
->face_id
;
5851 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5856 set_iterator_to_next (it
, 0);
5861 if (! NILP (lookup_glyphless_char_display (c
, it
)))
5863 if (it
->what
== IT_GLYPHLESS
)
5865 /* Don't display this character. */
5866 set_iterator_to_next (it
, 0);
5870 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
5871 nbsp_or_shy
= (c
== 0xA0 ? char_is_nbsp
5872 : c
== 0xAD ? char_is_soft_hyphen
5875 /* Translate control characters into `\003' or `^C' form.
5876 Control characters coming from a display table entry are
5877 currently not translated because we use IT->dpvec to hold
5878 the translation. This could easily be changed but I
5879 don't believe that it is worth doing.
5881 NBSP and SOFT-HYPEN are property translated too.
5883 Non-printable characters and raw-byte characters are also
5884 translated to octal form. */
5885 if (((c
< ' ' || c
== 127) /* ASCII control chars */
5886 ? (it
->area
!= TEXT_AREA
5887 /* In mode line, treat \n, \t like other crl chars. */
5890 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5891 || (c
!= '\n' && c
!= '\t'))
5894 || ! CHAR_PRINTABLE_P (c
))))
5896 /* C is a control character, NBSP, SOFT-HYPEN, raw-byte,
5897 or a non-printable character which must be displayed
5898 either as '\003' or as `^C' where the '\\' and '^'
5899 can be defined in the display table. Fill
5900 IT->ctl_chars with glyphs for what we have to
5901 display. Then, set IT->dpvec to these glyphs. */
5904 int face_id
, lface_id
= 0 ;
5907 /* Handle control characters with ^. */
5909 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
5913 g
= '^'; /* default glyph for Control */
5914 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5916 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5917 && GLYPH_CODE_CHAR_VALID_P (gc
))
5919 g
= GLYPH_CODE_CHAR (gc
);
5920 lface_id
= GLYPH_CODE_FACE (gc
);
5924 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5926 else if (it
->f
== last_escape_glyph_frame
5927 && it
->face_id
== last_escape_glyph_face_id
)
5929 face_id
= last_escape_glyph_merged_face_id
;
5933 /* Merge the escape-glyph face into the current face. */
5934 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5936 last_escape_glyph_frame
= it
->f
;
5937 last_escape_glyph_face_id
= it
->face_id
;
5938 last_escape_glyph_merged_face_id
= face_id
;
5941 XSETINT (it
->ctl_chars
[0], g
);
5942 XSETINT (it
->ctl_chars
[1], c
^ 0100);
5944 goto display_control
;
5947 /* Handle non-break space in the mode where it only gets
5950 if (EQ (Vnobreak_char_display
, Qt
)
5951 && nbsp_or_shy
== char_is_nbsp
)
5953 /* Merge the no-break-space face into the current face. */
5954 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5958 XSETINT (it
->ctl_chars
[0], ' ');
5960 goto display_control
;
5963 /* Handle sequences that start with the "escape glyph". */
5965 /* the default escape glyph is \. */
5966 escape_glyph
= '\\';
5969 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5970 && GLYPH_CODE_CHAR_VALID_P (gc
))
5972 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5973 lface_id
= GLYPH_CODE_FACE (gc
);
5977 /* The display table specified a face.
5978 Merge it into face_id and also into escape_glyph. */
5979 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5982 else if (it
->f
== last_escape_glyph_frame
5983 && it
->face_id
== last_escape_glyph_face_id
)
5985 face_id
= last_escape_glyph_merged_face_id
;
5989 /* Merge the escape-glyph face into the current face. */
5990 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5992 last_escape_glyph_frame
= it
->f
;
5993 last_escape_glyph_face_id
= it
->face_id
;
5994 last_escape_glyph_merged_face_id
= face_id
;
5997 /* Handle soft hyphens in the mode where they only get
6000 if (EQ (Vnobreak_char_display
, Qt
)
6001 && nbsp_or_shy
== char_is_soft_hyphen
)
6003 XSETINT (it
->ctl_chars
[0], '-');
6005 goto display_control
;
6008 /* Handle non-break space and soft hyphen
6009 with the escape glyph. */
6013 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6014 c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
6015 XSETINT (it
->ctl_chars
[1], c
);
6017 goto display_control
;
6024 if (CHAR_BYTE8_P (c
))
6025 /* Display \200 instead of \17777600. */
6026 c
= CHAR_TO_BYTE8 (c
);
6027 len
= sprintf (str
, "%03o", c
);
6029 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6030 for (i
= 0; i
< len
; i
++)
6031 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6036 /* Set up IT->dpvec and return first character from it. */
6037 it
->dpvec_char_len
= it
->len
;
6038 it
->dpvec
= it
->ctl_chars
;
6039 it
->dpend
= it
->dpvec
+ ctl_len
;
6040 it
->current
.dpvec_index
= 0;
6041 it
->dpvec_face_id
= face_id
;
6042 it
->saved_face_id
= it
->face_id
;
6043 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6047 it
->char_to_display
= c
;
6051 it
->char_to_display
= it
->c
;
6055 /* Adjust face id for a multibyte character. There are no multibyte
6056 character in unibyte text. */
6057 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6060 && FRAME_WINDOW_P (it
->f
))
6062 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6064 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6066 /* Automatic composition with glyph-string. */
6067 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6069 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6073 EMACS_INT pos
= (it
->s
? -1
6074 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6075 : IT_CHARPOS (*it
));
6077 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
, pos
,
6083 /* Is this character the last one of a run of characters with
6084 box? If yes, set IT->end_of_box_run_p to 1. */
6088 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6090 int face_id
= underlying_face_id (it
);
6091 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6095 if (face
->box
== FACE_NO_BOX
)
6097 /* If the box comes from face properties in a
6098 display string, check faces in that string. */
6099 int string_face_id
= face_after_it_pos (it
);
6100 it
->end_of_box_run_p
6101 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6104 /* Otherwise, the box comes from the underlying face.
6105 If this is the last string character displayed, check
6106 the next buffer location. */
6107 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6108 && (it
->current
.overlay_string_index
6109 == it
->n_overlay_strings
- 1))
6113 struct text_pos pos
= it
->current
.pos
;
6114 INC_TEXT_POS (pos
, it
->multibyte_p
);
6116 next_face_id
= face_at_buffer_position
6117 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6118 it
->region_end_charpos
, &ignore
,
6119 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6121 it
->end_of_box_run_p
6122 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6129 int face_id
= face_after_it_pos (it
);
6130 it
->end_of_box_run_p
6131 = (face_id
!= it
->face_id
6132 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6136 /* Value is 0 if end of buffer or string reached. */
6141 /* Move IT to the next display element.
6143 RESEAT_P non-zero means if called on a newline in buffer text,
6144 skip to the next visible line start.
6146 Functions get_next_display_element and set_iterator_to_next are
6147 separate because I find this arrangement easier to handle than a
6148 get_next_display_element function that also increments IT's
6149 position. The way it is we can first look at an iterator's current
6150 display element, decide whether it fits on a line, and if it does,
6151 increment the iterator position. The other way around we probably
6152 would either need a flag indicating whether the iterator has to be
6153 incremented the next time, or we would have to implement a
6154 decrement position function which would not be easy to write. */
6157 set_iterator_to_next (struct it
*it
, int reseat_p
)
6159 /* Reset flags indicating start and end of a sequence of characters
6160 with box. Reset them at the start of this function because
6161 moving the iterator to a new position might set them. */
6162 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6166 case GET_FROM_BUFFER
:
6167 /* The current display element of IT is a character from
6168 current_buffer. Advance in the buffer, and maybe skip over
6169 invisible lines that are so because of selective display. */
6170 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6171 reseat_at_next_visible_line_start (it
, 0);
6172 else if (it
->cmp_it
.id
>= 0)
6174 /* We are currently getting glyphs from a composition. */
6179 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6180 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6181 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6183 it
->cmp_it
.from
= it
->cmp_it
.to
;
6188 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6190 it
->end_charpos
, Qnil
);
6193 else if (! it
->cmp_it
.reversed_p
)
6195 /* Composition created while scanning forward. */
6196 /* Update IT's char/byte positions to point to the first
6197 character of the next grapheme cluster, or to the
6198 character visually after the current composition. */
6199 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6200 bidi_move_to_visually_next (&it
->bidi_it
);
6201 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6202 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6204 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6206 /* Proceed to the next grapheme cluster. */
6207 it
->cmp_it
.from
= it
->cmp_it
.to
;
6211 /* No more grapheme clusters in this composition.
6212 Find the next stop position. */
6213 EMACS_INT stop
= it
->end_charpos
;
6214 if (it
->bidi_it
.scan_dir
< 0)
6215 /* Now we are scanning backward and don't know
6218 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6219 IT_BYTEPOS (*it
), stop
, Qnil
);
6224 /* Composition created while scanning backward. */
6225 /* Update IT's char/byte positions to point to the last
6226 character of the previous grapheme cluster, or the
6227 character visually after the current composition. */
6228 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6229 bidi_move_to_visually_next (&it
->bidi_it
);
6230 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6231 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6232 if (it
->cmp_it
.from
> 0)
6234 /* Proceed to the previous grapheme cluster. */
6235 it
->cmp_it
.to
= it
->cmp_it
.from
;
6239 /* No more grapheme clusters in this composition.
6240 Find the next stop position. */
6241 EMACS_INT stop
= it
->end_charpos
;
6242 if (it
->bidi_it
.scan_dir
< 0)
6243 /* Now we are scanning backward and don't know
6246 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6247 IT_BYTEPOS (*it
), stop
, Qnil
);
6253 xassert (it
->len
!= 0);
6257 IT_BYTEPOS (*it
) += it
->len
;
6258 IT_CHARPOS (*it
) += 1;
6262 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
6263 /* If this is a new paragraph, determine its base
6264 direction (a.k.a. its base embedding level). */
6265 if (it
->bidi_it
.new_paragraph
)
6266 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6267 bidi_move_to_visually_next (&it
->bidi_it
);
6268 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6269 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6270 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
6272 /* As the scan direction was changed, we must
6273 re-compute the stop position for composition. */
6274 EMACS_INT stop
= it
->end_charpos
;
6275 if (it
->bidi_it
.scan_dir
< 0)
6277 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6278 IT_BYTEPOS (*it
), stop
, Qnil
);
6281 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6285 case GET_FROM_C_STRING
:
6286 /* Current display element of IT is from a C string. */
6287 IT_BYTEPOS (*it
) += it
->len
;
6288 IT_CHARPOS (*it
) += 1;
6291 case GET_FROM_DISPLAY_VECTOR
:
6292 /* Current display element of IT is from a display table entry.
6293 Advance in the display table definition. Reset it to null if
6294 end reached, and continue with characters from buffers/
6296 ++it
->current
.dpvec_index
;
6298 /* Restore face of the iterator to what they were before the
6299 display vector entry (these entries may contain faces). */
6300 it
->face_id
= it
->saved_face_id
;
6302 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6304 int recheck_faces
= it
->ellipsis_p
;
6307 it
->method
= GET_FROM_C_STRING
;
6308 else if (STRINGP (it
->string
))
6309 it
->method
= GET_FROM_STRING
;
6312 it
->method
= GET_FROM_BUFFER
;
6313 it
->object
= it
->w
->buffer
;
6317 it
->current
.dpvec_index
= -1;
6319 /* Skip over characters which were displayed via IT->dpvec. */
6320 if (it
->dpvec_char_len
< 0)
6321 reseat_at_next_visible_line_start (it
, 1);
6322 else if (it
->dpvec_char_len
> 0)
6324 if (it
->method
== GET_FROM_STRING
6325 && it
->n_overlay_strings
> 0)
6326 it
->ignore_overlay_strings_at_pos_p
= 1;
6327 it
->len
= it
->dpvec_char_len
;
6328 set_iterator_to_next (it
, reseat_p
);
6331 /* Maybe recheck faces after display vector */
6333 it
->stop_charpos
= IT_CHARPOS (*it
);
6337 case GET_FROM_STRING
:
6338 /* Current display element is a character from a Lisp string. */
6339 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6340 if (it
->cmp_it
.id
>= 0)
6342 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6343 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6344 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6345 it
->cmp_it
.from
= it
->cmp_it
.to
;
6349 composition_compute_stop_pos (&it
->cmp_it
,
6350 IT_STRING_CHARPOS (*it
),
6351 IT_STRING_BYTEPOS (*it
),
6352 it
->end_charpos
, it
->string
);
6357 IT_STRING_BYTEPOS (*it
) += it
->len
;
6358 IT_STRING_CHARPOS (*it
) += 1;
6361 consider_string_end
:
6363 if (it
->current
.overlay_string_index
>= 0)
6365 /* IT->string is an overlay string. Advance to the
6366 next, if there is one. */
6367 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6370 next_overlay_string (it
);
6372 setup_for_ellipsis (it
, 0);
6377 /* IT->string is not an overlay string. If we reached
6378 its end, and there is something on IT->stack, proceed
6379 with what is on the stack. This can be either another
6380 string, this time an overlay string, or a buffer. */
6381 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6385 if (it
->method
== GET_FROM_STRING
)
6386 goto consider_string_end
;
6391 case GET_FROM_IMAGE
:
6392 case GET_FROM_STRETCH
:
6393 /* The position etc with which we have to proceed are on
6394 the stack. The position may be at the end of a string,
6395 if the `display' property takes up the whole string. */
6396 xassert (it
->sp
> 0);
6398 if (it
->method
== GET_FROM_STRING
)
6399 goto consider_string_end
;
6403 /* There are no other methods defined, so this should be a bug. */
6407 xassert (it
->method
!= GET_FROM_STRING
6408 || (STRINGP (it
->string
)
6409 && IT_STRING_CHARPOS (*it
) >= 0));
6412 /* Load IT's display element fields with information about the next
6413 display element which comes from a display table entry or from the
6414 result of translating a control character to one of the forms `^C'
6417 IT->dpvec holds the glyphs to return as characters.
6418 IT->saved_face_id holds the face id before the display vector--it
6419 is restored into IT->face_id in set_iterator_to_next. */
6422 next_element_from_display_vector (struct it
*it
)
6427 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6429 it
->face_id
= it
->saved_face_id
;
6431 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6432 That seemed totally bogus - so I changed it... */
6433 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6435 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6437 it
->c
= GLYPH_CODE_CHAR (gc
);
6438 it
->len
= CHAR_BYTES (it
->c
);
6440 /* The entry may contain a face id to use. Such a face id is
6441 the id of a Lisp face, not a realized face. A face id of
6442 zero means no face is specified. */
6443 if (it
->dpvec_face_id
>= 0)
6444 it
->face_id
= it
->dpvec_face_id
;
6447 int lface_id
= GLYPH_CODE_FACE (gc
);
6449 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6454 /* Display table entry is invalid. Return a space. */
6455 it
->c
= ' ', it
->len
= 1;
6457 /* Don't change position and object of the iterator here. They are
6458 still the values of the character that had this display table
6459 entry or was translated, and that's what we want. */
6460 it
->what
= IT_CHARACTER
;
6465 /* Load IT with the next display element from Lisp string IT->string.
6466 IT->current.string_pos is the current position within the string.
6467 If IT->current.overlay_string_index >= 0, the Lisp string is an
6471 next_element_from_string (struct it
*it
)
6473 struct text_pos position
;
6475 xassert (STRINGP (it
->string
));
6476 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6477 position
= it
->current
.string_pos
;
6479 /* Time to check for invisible text? */
6480 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6481 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6485 /* Since a handler may have changed IT->method, we must
6487 return GET_NEXT_DISPLAY_ELEMENT (it
);
6490 if (it
->current
.overlay_string_index
>= 0)
6492 /* Get the next character from an overlay string. In overlay
6493 strings, There is no field width or padding with spaces to
6495 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6500 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6501 IT_STRING_BYTEPOS (*it
), SCHARS (it
->string
))
6502 && next_element_from_composition (it
))
6506 else if (STRING_MULTIBYTE (it
->string
))
6508 const unsigned char *s
= (SDATA (it
->string
)
6509 + IT_STRING_BYTEPOS (*it
));
6510 it
->c
= string_char_and_length (s
, &it
->len
);
6514 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6520 /* Get the next character from a Lisp string that is not an
6521 overlay string. Such strings come from the mode line, for
6522 example. We may have to pad with spaces, or truncate the
6523 string. See also next_element_from_c_string. */
6524 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6529 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6531 /* Pad with spaces. */
6532 it
->c
= ' ', it
->len
= 1;
6533 CHARPOS (position
) = BYTEPOS (position
) = -1;
6535 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6536 IT_STRING_BYTEPOS (*it
), it
->string_nchars
)
6537 && next_element_from_composition (it
))
6541 else if (STRING_MULTIBYTE (it
->string
))
6543 const unsigned char *s
= (SDATA (it
->string
)
6544 + IT_STRING_BYTEPOS (*it
));
6545 it
->c
= string_char_and_length (s
, &it
->len
);
6549 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6554 /* Record what we have and where it came from. */
6555 it
->what
= IT_CHARACTER
;
6556 it
->object
= it
->string
;
6557 it
->position
= position
;
6562 /* Load IT with next display element from C string IT->s.
6563 IT->string_nchars is the maximum number of characters to return
6564 from the string. IT->end_charpos may be greater than
6565 IT->string_nchars when this function is called, in which case we
6566 may have to return padding spaces. Value is zero if end of string
6567 reached, including padding spaces. */
6570 next_element_from_c_string (struct it
*it
)
6575 it
->what
= IT_CHARACTER
;
6576 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6579 /* IT's position can be greater IT->string_nchars in case a field
6580 width or precision has been specified when the iterator was
6582 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6584 /* End of the game. */
6588 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6590 /* Pad with spaces. */
6591 it
->c
= ' ', it
->len
= 1;
6592 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6594 else if (it
->multibyte_p
)
6595 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6597 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6603 /* Set up IT to return characters from an ellipsis, if appropriate.
6604 The definition of the ellipsis glyphs may come from a display table
6605 entry. This function fills IT with the first glyph from the
6606 ellipsis if an ellipsis is to be displayed. */
6609 next_element_from_ellipsis (struct it
*it
)
6611 if (it
->selective_display_ellipsis_p
)
6612 setup_for_ellipsis (it
, it
->len
);
6615 /* The face at the current position may be different from the
6616 face we find after the invisible text. Remember what it
6617 was in IT->saved_face_id, and signal that it's there by
6618 setting face_before_selective_p. */
6619 it
->saved_face_id
= it
->face_id
;
6620 it
->method
= GET_FROM_BUFFER
;
6621 it
->object
= it
->w
->buffer
;
6622 reseat_at_next_visible_line_start (it
, 1);
6623 it
->face_before_selective_p
= 1;
6626 return GET_NEXT_DISPLAY_ELEMENT (it
);
6630 /* Deliver an image display element. The iterator IT is already
6631 filled with image information (done in handle_display_prop). Value
6636 next_element_from_image (struct it
*it
)
6638 it
->what
= IT_IMAGE
;
6639 it
->ignore_overlay_strings_at_pos_p
= 0;
6644 /* Fill iterator IT with next display element from a stretch glyph
6645 property. IT->object is the value of the text property. Value is
6649 next_element_from_stretch (struct it
*it
)
6651 it
->what
= IT_STRETCH
;
6655 /* Scan forward from CHARPOS in the current buffer, until we find a
6656 stop position > current IT's position. Then handle the stop
6657 position before that. This is called when we bump into a stop
6658 position while reordering bidirectional text. CHARPOS should be
6659 the last previously processed stop_pos (or BEGV, if none were
6660 processed yet) whose position is less that IT's current
6664 handle_stop_backwards (struct it
*it
, EMACS_INT charpos
)
6666 EMACS_INT where_we_are
= IT_CHARPOS (*it
);
6667 struct display_pos save_current
= it
->current
;
6668 struct text_pos save_position
= it
->position
;
6669 struct text_pos pos1
;
6670 EMACS_INT next_stop
;
6672 /* Scan in strict logical order. */
6676 it
->prev_stop
= charpos
;
6677 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
6678 reseat_1 (it
, pos1
, 0);
6679 compute_stop_pos (it
);
6680 /* We must advance forward, right? */
6681 if (it
->stop_charpos
<= it
->prev_stop
)
6683 charpos
= it
->stop_charpos
;
6685 while (charpos
<= where_we_are
);
6687 next_stop
= it
->stop_charpos
;
6688 it
->stop_charpos
= it
->prev_stop
;
6690 it
->current
= save_current
;
6691 it
->position
= save_position
;
6693 it
->stop_charpos
= next_stop
;
6696 /* Load IT with the next display element from current_buffer. Value
6697 is zero if end of buffer reached. IT->stop_charpos is the next
6698 position at which to stop and check for text properties or buffer
6702 next_element_from_buffer (struct it
*it
)
6706 xassert (IT_CHARPOS (*it
) >= BEGV
);
6708 /* With bidi reordering, the character to display might not be the
6709 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
6710 we were reseat()ed to a new buffer position, which is potentially
6711 a different paragraph. */
6712 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6714 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6715 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6716 if (it
->bidi_it
.bytepos
== ZV_BYTE
)
6718 /* Nothing to do, but reset the FIRST_ELT flag, like
6719 bidi_paragraph_init does, because we are not going to
6721 it
->bidi_it
.first_elt
= 0;
6723 else if (it
->bidi_it
.bytepos
== BEGV_BYTE
6724 /* FIXME: Should support all Unicode line separators. */
6725 || FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6726 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')
6728 /* If we are at the beginning of a line, we can produce the
6729 next element right away. */
6730 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6731 bidi_move_to_visually_next (&it
->bidi_it
);
6735 EMACS_INT orig_bytepos
= IT_BYTEPOS (*it
);
6737 /* We need to prime the bidi iterator starting at the line's
6738 beginning, before we will be able to produce the next
6740 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), -1);
6741 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
6742 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6743 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6744 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
6747 /* Now return to buffer position where we were asked to
6748 get the next display element, and produce that. */
6749 bidi_move_to_visually_next (&it
->bidi_it
);
6751 while (it
->bidi_it
.bytepos
!= orig_bytepos
6752 && it
->bidi_it
.bytepos
< ZV_BYTE
);
6755 it
->bidi_it
.first_elt
= 0; /* paranoia: bidi.c does this */
6756 /* Adjust IT's position information to where we ended up. */
6757 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6758 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6759 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
6761 EMACS_INT stop
= it
->end_charpos
;
6762 if (it
->bidi_it
.scan_dir
< 0)
6764 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6765 IT_BYTEPOS (*it
), stop
, Qnil
);
6769 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6771 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6773 int overlay_strings_follow_p
;
6775 /* End of the game, except when overlay strings follow that
6776 haven't been returned yet. */
6777 if (it
->overlay_strings_at_end_processed_p
)
6778 overlay_strings_follow_p
= 0;
6781 it
->overlay_strings_at_end_processed_p
= 1;
6782 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6785 if (overlay_strings_follow_p
)
6786 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6790 it
->position
= it
->current
.pos
;
6794 else if (!(!it
->bidi_p
6795 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6796 || IT_CHARPOS (*it
) == it
->stop_charpos
))
6798 /* With bidi non-linear iteration, we could find ourselves
6799 far beyond the last computed stop_charpos, with several
6800 other stop positions in between that we missed. Scan
6801 them all now, in buffer's logical order, until we find
6802 and handle the last stop_charpos that precedes our
6803 current position. */
6804 handle_stop_backwards (it
, it
->stop_charpos
);
6805 return GET_NEXT_DISPLAY_ELEMENT (it
);
6811 /* Take note of the stop position we just moved across,
6812 for when we will move back across it. */
6813 it
->prev_stop
= it
->stop_charpos
;
6814 /* If we are at base paragraph embedding level, take
6815 note of the last stop position seen at this
6817 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6818 it
->base_level_stop
= it
->stop_charpos
;
6821 return GET_NEXT_DISPLAY_ELEMENT (it
);
6825 /* We can sometimes back up for reasons that have nothing
6826 to do with bidi reordering. E.g., compositions. The
6827 code below is only needed when we are above the base
6828 embedding level, so test for that explicitly. */
6829 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6830 && IT_CHARPOS (*it
) < it
->prev_stop
)
6832 if (it
->base_level_stop
<= 0)
6833 it
->base_level_stop
= BEGV
;
6834 if (IT_CHARPOS (*it
) < it
->base_level_stop
)
6836 handle_stop_backwards (it
, it
->base_level_stop
);
6837 return GET_NEXT_DISPLAY_ELEMENT (it
);
6841 /* No face changes, overlays etc. in sight, so just return a
6842 character from current_buffer. */
6846 /* Maybe run the redisplay end trigger hook. Performance note:
6847 This doesn't seem to cost measurable time. */
6848 if (it
->redisplay_end_trigger_charpos
6850 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6851 run_redisplay_end_trigger_hook (it
);
6853 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
6854 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6856 && next_element_from_composition (it
))
6861 /* Get the next character, maybe multibyte. */
6862 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6863 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6864 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
6866 it
->c
= *p
, it
->len
= 1;
6868 /* Record what we have and where it came from. */
6869 it
->what
= IT_CHARACTER
;
6870 it
->object
= it
->w
->buffer
;
6871 it
->position
= it
->current
.pos
;
6873 /* Normally we return the character found above, except when we
6874 really want to return an ellipsis for selective display. */
6879 /* A value of selective > 0 means hide lines indented more
6880 than that number of columns. */
6881 if (it
->selective
> 0
6882 && IT_CHARPOS (*it
) + 1 < ZV
6883 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6884 IT_BYTEPOS (*it
) + 1,
6885 (double) it
->selective
)) /* iftc */
6887 success_p
= next_element_from_ellipsis (it
);
6888 it
->dpvec_char_len
= -1;
6891 else if (it
->c
== '\r' && it
->selective
== -1)
6893 /* A value of selective == -1 means that everything from the
6894 CR to the end of the line is invisible, with maybe an
6895 ellipsis displayed for it. */
6896 success_p
= next_element_from_ellipsis (it
);
6897 it
->dpvec_char_len
= -1;
6902 /* Value is zero if end of buffer reached. */
6903 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6908 /* Run the redisplay end trigger hook for IT. */
6911 run_redisplay_end_trigger_hook (struct it
*it
)
6913 Lisp_Object args
[3];
6915 /* IT->glyph_row should be non-null, i.e. we should be actually
6916 displaying something, or otherwise we should not run the hook. */
6917 xassert (it
->glyph_row
);
6919 /* Set up hook arguments. */
6920 args
[0] = Qredisplay_end_trigger_functions
;
6921 args
[1] = it
->window
;
6922 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6923 it
->redisplay_end_trigger_charpos
= 0;
6925 /* Since we are *trying* to run these functions, don't try to run
6926 them again, even if they get an error. */
6927 it
->w
->redisplay_end_trigger
= Qnil
;
6928 Frun_hook_with_args (3, args
);
6930 /* Notice if it changed the face of the character we are on. */
6931 handle_face_prop (it
);
6935 /* Deliver a composition display element. Unlike the other
6936 next_element_from_XXX, this function is not registered in the array
6937 get_next_element[]. It is called from next_element_from_buffer and
6938 next_element_from_string when necessary. */
6941 next_element_from_composition (struct it
*it
)
6943 it
->what
= IT_COMPOSITION
;
6944 it
->len
= it
->cmp_it
.nbytes
;
6945 if (STRINGP (it
->string
))
6949 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6950 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6953 it
->position
= it
->current
.string_pos
;
6954 it
->object
= it
->string
;
6955 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6956 IT_STRING_BYTEPOS (*it
), it
->string
);
6962 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6963 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6966 if (it
->bidi_it
.new_paragraph
)
6967 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
6968 /* Resync the bidi iterator with IT's new position.
6969 FIXME: this doesn't support bidirectional text. */
6970 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
6971 bidi_move_to_visually_next (&it
->bidi_it
);
6975 it
->position
= it
->current
.pos
;
6976 it
->object
= it
->w
->buffer
;
6977 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6978 IT_BYTEPOS (*it
), Qnil
);
6985 /***********************************************************************
6986 Moving an iterator without producing glyphs
6987 ***********************************************************************/
6989 /* Check if iterator is at a position corresponding to a valid buffer
6990 position after some move_it_ call. */
6992 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6993 ((it)->method == GET_FROM_STRING \
6994 ? IT_STRING_CHARPOS (*it) == 0 \
6998 /* Move iterator IT to a specified buffer or X position within one
6999 line on the display without producing glyphs.
7001 OP should be a bit mask including some or all of these bits:
7002 MOVE_TO_X: Stop upon reaching x-position TO_X.
7003 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
7004 Regardless of OP's value, stop upon reaching the end of the display line.
7006 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
7007 This means, in particular, that TO_X includes window's horizontal
7010 The return value has several possible values that
7011 say what condition caused the scan to stop:
7013 MOVE_POS_MATCH_OR_ZV
7014 - when TO_POS or ZV was reached.
7017 -when TO_X was reached before TO_POS or ZV were reached.
7020 - when we reached the end of the display area and the line must
7024 - when we reached the end of the display area and the line is
7028 - when we stopped at a line end, i.e. a newline or a CR and selective
7031 static enum move_it_result
7032 move_it_in_display_line_to (struct it
*it
,
7033 EMACS_INT to_charpos
, int to_x
,
7034 enum move_operation_enum op
)
7036 enum move_it_result result
= MOVE_UNDEFINED
;
7037 struct glyph_row
*saved_glyph_row
;
7038 struct it wrap_it
, atpos_it
, atx_it
;
7040 enum it_method prev_method
= it
->method
;
7041 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
7043 /* Don't produce glyphs in produce_glyphs. */
7044 saved_glyph_row
= it
->glyph_row
;
7045 it
->glyph_row
= NULL
;
7047 /* Use wrap_it to save a copy of IT wherever a word wrap could
7048 occur. Use atpos_it to save a copy of IT at the desired buffer
7049 position, if found, so that we can scan ahead and check if the
7050 word later overshoots the window edge. Use atx_it similarly, for
7056 #define BUFFER_POS_REACHED_P() \
7057 ((op & MOVE_TO_POS) != 0 \
7058 && BUFFERP (it->object) \
7059 && (IT_CHARPOS (*it) == to_charpos \
7060 || (!it->bidi_p && IT_CHARPOS (*it) > to_charpos)) \
7061 && (it->method == GET_FROM_BUFFER \
7062 || (it->method == GET_FROM_DISPLAY_VECTOR \
7063 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
7065 /* If there's a line-/wrap-prefix, handle it. */
7066 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
7067 && it
->current_y
< it
->last_visible_y
)
7068 handle_line_prefix (it
);
7070 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7071 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7075 int x
, i
, ascent
= 0, descent
= 0;
7077 /* Utility macro to reset an iterator with x, ascent, and descent. */
7078 #define IT_RESET_X_ASCENT_DESCENT(IT) \
7079 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
7080 (IT)->max_descent = descent)
7082 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
7084 if ((op
& MOVE_TO_POS
) != 0
7085 && BUFFERP (it
->object
)
7086 && it
->method
== GET_FROM_BUFFER
7087 && ((!it
->bidi_p
&& IT_CHARPOS (*it
) > to_charpos
)
7089 && (prev_method
== GET_FROM_IMAGE
7090 || prev_method
== GET_FROM_STRETCH
)
7091 /* Passed TO_CHARPOS from left to right. */
7092 && ((prev_pos
< to_charpos
7093 && IT_CHARPOS (*it
) > to_charpos
)
7094 /* Passed TO_CHARPOS from right to left. */
7095 || (prev_pos
> to_charpos
7096 && IT_CHARPOS (*it
) < to_charpos
)))))
7098 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7100 result
= MOVE_POS_MATCH_OR_ZV
;
7103 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7104 /* If wrap_it is valid, the current position might be in a
7105 word that is wrapped. So, save the iterator in
7106 atpos_it and continue to see if wrapping happens. */
7110 prev_method
= it
->method
;
7111 if (it
->method
== GET_FROM_BUFFER
)
7112 prev_pos
= IT_CHARPOS (*it
);
7113 /* Stop when ZV reached.
7114 We used to stop here when TO_CHARPOS reached as well, but that is
7115 too soon if this glyph does not fit on this line. So we handle it
7116 explicitly below. */
7117 if (!get_next_display_element (it
))
7119 result
= MOVE_POS_MATCH_OR_ZV
;
7123 if (it
->line_wrap
== TRUNCATE
)
7125 if (BUFFER_POS_REACHED_P ())
7127 result
= MOVE_POS_MATCH_OR_ZV
;
7133 if (it
->line_wrap
== WORD_WRAP
)
7135 if (IT_DISPLAYING_WHITESPACE (it
))
7139 /* We have reached a glyph that follows one or more
7140 whitespace characters. If the position is
7141 already found, we are done. */
7142 if (atpos_it
.sp
>= 0)
7145 result
= MOVE_POS_MATCH_OR_ZV
;
7151 result
= MOVE_X_REACHED
;
7154 /* Otherwise, we can wrap here. */
7161 /* Remember the line height for the current line, in case
7162 the next element doesn't fit on the line. */
7163 ascent
= it
->max_ascent
;
7164 descent
= it
->max_descent
;
7166 /* The call to produce_glyphs will get the metrics of the
7167 display element IT is loaded with. Record the x-position
7168 before this display element, in case it doesn't fit on the
7172 PRODUCE_GLYPHS (it
);
7174 if (it
->area
!= TEXT_AREA
)
7176 set_iterator_to_next (it
, 1);
7177 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7178 SET_TEXT_POS (this_line_min_pos
,
7179 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7183 /* The number of glyphs we get back in IT->nglyphs will normally
7184 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7185 character on a terminal frame, or (iii) a line end. For the
7186 second case, IT->nglyphs - 1 padding glyphs will be present.
7187 (On X frames, there is only one glyph produced for a
7188 composite character.)
7190 The behavior implemented below means, for continuation lines,
7191 that as many spaces of a TAB as fit on the current line are
7192 displayed there. For terminal frames, as many glyphs of a
7193 multi-glyph character are displayed in the current line, too.
7194 This is what the old redisplay code did, and we keep it that
7195 way. Under X, the whole shape of a complex character must
7196 fit on the line or it will be completely displayed in the
7199 Note that both for tabs and padding glyphs, all glyphs have
7203 /* More than one glyph or glyph doesn't fit on line. All
7204 glyphs have the same width. */
7205 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7207 int x_before_this_char
= x
;
7208 int hpos_before_this_char
= it
->hpos
;
7210 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7212 new_x
= x
+ single_glyph_width
;
7214 /* We want to leave anything reaching TO_X to the caller. */
7215 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7217 if (BUFFER_POS_REACHED_P ())
7219 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7220 goto buffer_pos_reached
;
7221 if (atpos_it
.sp
< 0)
7224 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7229 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7232 result
= MOVE_X_REACHED
;
7238 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7243 if (/* Lines are continued. */
7244 it
->line_wrap
!= TRUNCATE
7245 && (/* And glyph doesn't fit on the line. */
7246 new_x
> it
->last_visible_x
7247 /* Or it fits exactly and we're on a window
7249 || (new_x
== it
->last_visible_x
7250 && FRAME_WINDOW_P (it
->f
))))
7252 if (/* IT->hpos == 0 means the very first glyph
7253 doesn't fit on the line, e.g. a wide image. */
7255 || (new_x
== it
->last_visible_x
7256 && FRAME_WINDOW_P (it
->f
)))
7259 it
->current_x
= new_x
;
7261 /* The character's last glyph just barely fits
7263 if (i
== it
->nglyphs
- 1)
7265 /* If this is the destination position,
7266 return a position *before* it in this row,
7267 now that we know it fits in this row. */
7268 if (BUFFER_POS_REACHED_P ())
7270 if (it
->line_wrap
!= WORD_WRAP
7273 it
->hpos
= hpos_before_this_char
;
7274 it
->current_x
= x_before_this_char
;
7275 result
= MOVE_POS_MATCH_OR_ZV
;
7278 if (it
->line_wrap
== WORD_WRAP
7282 atpos_it
.current_x
= x_before_this_char
;
7283 atpos_it
.hpos
= hpos_before_this_char
;
7287 set_iterator_to_next (it
, 1);
7288 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7289 SET_TEXT_POS (this_line_min_pos
,
7290 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7291 /* On graphical terminals, newlines may
7292 "overflow" into the fringe if
7293 overflow-newline-into-fringe is non-nil.
7294 On text-only terminals, newlines may
7295 overflow into the last glyph on the
7297 if (!FRAME_WINDOW_P (it
->f
)
7298 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7300 if (!get_next_display_element (it
))
7302 result
= MOVE_POS_MATCH_OR_ZV
;
7305 if (BUFFER_POS_REACHED_P ())
7307 if (ITERATOR_AT_END_OF_LINE_P (it
))
7308 result
= MOVE_POS_MATCH_OR_ZV
;
7310 result
= MOVE_LINE_CONTINUED
;
7313 if (ITERATOR_AT_END_OF_LINE_P (it
))
7315 result
= MOVE_NEWLINE_OR_CR
;
7322 IT_RESET_X_ASCENT_DESCENT (it
);
7324 if (wrap_it
.sp
>= 0)
7331 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7333 result
= MOVE_LINE_CONTINUED
;
7337 if (BUFFER_POS_REACHED_P ())
7339 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7340 goto buffer_pos_reached
;
7341 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7344 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7348 if (new_x
> it
->first_visible_x
)
7350 /* Glyph is visible. Increment number of glyphs that
7351 would be displayed. */
7356 if (result
!= MOVE_UNDEFINED
)
7359 else if (BUFFER_POS_REACHED_P ())
7362 IT_RESET_X_ASCENT_DESCENT (it
);
7363 result
= MOVE_POS_MATCH_OR_ZV
;
7366 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7368 /* Stop when TO_X specified and reached. This check is
7369 necessary here because of lines consisting of a line end,
7370 only. The line end will not produce any glyphs and we
7371 would never get MOVE_X_REACHED. */
7372 xassert (it
->nglyphs
== 0);
7373 result
= MOVE_X_REACHED
;
7377 /* Is this a line end? If yes, we're done. */
7378 if (ITERATOR_AT_END_OF_LINE_P (it
))
7380 result
= MOVE_NEWLINE_OR_CR
;
7384 if (it
->method
== GET_FROM_BUFFER
)
7385 prev_pos
= IT_CHARPOS (*it
);
7386 /* The current display element has been consumed. Advance
7388 set_iterator_to_next (it
, 1);
7389 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
7390 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7392 /* Stop if lines are truncated and IT's current x-position is
7393 past the right edge of the window now. */
7394 if (it
->line_wrap
== TRUNCATE
7395 && it
->current_x
>= it
->last_visible_x
)
7397 if (!FRAME_WINDOW_P (it
->f
)
7398 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7400 if (!get_next_display_element (it
)
7401 || BUFFER_POS_REACHED_P ())
7403 result
= MOVE_POS_MATCH_OR_ZV
;
7406 if (ITERATOR_AT_END_OF_LINE_P (it
))
7408 result
= MOVE_NEWLINE_OR_CR
;
7412 result
= MOVE_LINE_TRUNCATED
;
7415 #undef IT_RESET_X_ASCENT_DESCENT
7418 #undef BUFFER_POS_REACHED_P
7420 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7421 restore the saved iterator. */
7422 if (atpos_it
.sp
>= 0)
7424 else if (atx_it
.sp
>= 0)
7429 /* Restore the iterator settings altered at the beginning of this
7431 it
->glyph_row
= saved_glyph_row
;
7435 /* For external use. */
7437 move_it_in_display_line (struct it
*it
,
7438 EMACS_INT to_charpos
, int to_x
,
7439 enum move_operation_enum op
)
7441 if (it
->line_wrap
== WORD_WRAP
7442 && (op
& MOVE_TO_X
))
7444 struct it save_it
= *it
;
7445 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7446 /* When word-wrap is on, TO_X may lie past the end
7447 of a wrapped line. Then it->current is the
7448 character on the next line, so backtrack to the
7449 space before the wrap point. */
7450 if (skip
== MOVE_LINE_CONTINUED
)
7452 int prev_x
= max (it
->current_x
- 1, 0);
7454 move_it_in_display_line_to
7455 (it
, -1, prev_x
, MOVE_TO_X
);
7459 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7463 /* Move IT forward until it satisfies one or more of the criteria in
7464 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7466 OP is a bit-mask that specifies where to stop, and in particular,
7467 which of those four position arguments makes a difference. See the
7468 description of enum move_operation_enum.
7470 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7471 screen line, this function will set IT to the next position >
7475 move_it_to (struct it
*it
, EMACS_INT to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
7477 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7478 int line_height
, line_start_x
= 0, reached
= 0;
7482 if (op
& MOVE_TO_VPOS
)
7484 /* If no TO_CHARPOS and no TO_X specified, stop at the
7485 start of the line TO_VPOS. */
7486 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7488 if (it
->vpos
== to_vpos
)
7494 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7498 /* TO_VPOS >= 0 means stop at TO_X in the line at
7499 TO_VPOS, or at TO_POS, whichever comes first. */
7500 if (it
->vpos
== to_vpos
)
7506 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7508 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7513 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7515 /* We have reached TO_X but not in the line we want. */
7516 skip
= move_it_in_display_line_to (it
, to_charpos
,
7518 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7526 else if (op
& MOVE_TO_Y
)
7528 struct it it_backup
;
7530 if (it
->line_wrap
== WORD_WRAP
)
7533 /* TO_Y specified means stop at TO_X in the line containing
7534 TO_Y---or at TO_CHARPOS if this is reached first. The
7535 problem is that we can't really tell whether the line
7536 contains TO_Y before we have completely scanned it, and
7537 this may skip past TO_X. What we do is to first scan to
7540 If TO_X is not specified, use a TO_X of zero. The reason
7541 is to make the outcome of this function more predictable.
7542 If we didn't use TO_X == 0, we would stop at the end of
7543 the line which is probably not what a caller would expect
7545 skip
= move_it_in_display_line_to
7546 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7547 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7549 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7550 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7552 else if (skip
== MOVE_X_REACHED
)
7554 /* If TO_X was reached, we want to know whether TO_Y is
7555 in the line. We know this is the case if the already
7556 scanned glyphs make the line tall enough. Otherwise,
7557 we must check by scanning the rest of the line. */
7558 line_height
= it
->max_ascent
+ it
->max_descent
;
7559 if (to_y
>= it
->current_y
7560 && to_y
< it
->current_y
+ line_height
)
7566 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7567 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7569 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7570 line_height
= it
->max_ascent
+ it
->max_descent
;
7571 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7573 if (to_y
>= it
->current_y
7574 && to_y
< it
->current_y
+ line_height
)
7576 /* If TO_Y is in this line and TO_X was reached
7577 above, we scanned too far. We have to restore
7578 IT's settings to the ones before skipping. */
7585 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7591 /* Check whether TO_Y is in this line. */
7592 line_height
= it
->max_ascent
+ it
->max_descent
;
7593 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7595 if (to_y
>= it
->current_y
7596 && to_y
< it
->current_y
+ line_height
)
7598 /* When word-wrap is on, TO_X may lie past the end
7599 of a wrapped line. Then it->current is the
7600 character on the next line, so backtrack to the
7601 space before the wrap point. */
7602 if (skip
== MOVE_LINE_CONTINUED
7603 && it
->line_wrap
== WORD_WRAP
)
7605 int prev_x
= max (it
->current_x
- 1, 0);
7607 skip
= move_it_in_display_line_to
7608 (it
, -1, prev_x
, MOVE_TO_X
);
7617 else if (BUFFERP (it
->object
)
7618 && (it
->method
== GET_FROM_BUFFER
7619 || it
->method
== GET_FROM_STRETCH
)
7620 && IT_CHARPOS (*it
) >= to_charpos
)
7621 skip
= MOVE_POS_MATCH_OR_ZV
;
7623 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7627 case MOVE_POS_MATCH_OR_ZV
:
7631 case MOVE_NEWLINE_OR_CR
:
7632 set_iterator_to_next (it
, 1);
7633 it
->continuation_lines_width
= 0;
7636 case MOVE_LINE_TRUNCATED
:
7637 it
->continuation_lines_width
= 0;
7638 reseat_at_next_visible_line_start (it
, 0);
7639 if ((op
& MOVE_TO_POS
) != 0
7640 && IT_CHARPOS (*it
) > to_charpos
)
7647 case MOVE_LINE_CONTINUED
:
7648 /* For continued lines ending in a tab, some of the glyphs
7649 associated with the tab are displayed on the current
7650 line. Since it->current_x does not include these glyphs,
7651 we use it->last_visible_x instead. */
7654 it
->continuation_lines_width
+= it
->last_visible_x
;
7655 /* When moving by vpos, ensure that the iterator really
7656 advances to the next line (bug#847, bug#969). Fixme:
7657 do we need to do this in other circumstances? */
7658 if (it
->current_x
!= it
->last_visible_x
7659 && (op
& MOVE_TO_VPOS
)
7660 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7662 line_start_x
= it
->current_x
+ it
->pixel_width
7663 - it
->last_visible_x
;
7664 set_iterator_to_next (it
, 0);
7668 it
->continuation_lines_width
+= it
->current_x
;
7675 /* Reset/increment for the next run. */
7676 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7677 it
->current_x
= line_start_x
;
7680 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7682 last_height
= it
->max_ascent
+ it
->max_descent
;
7683 last_max_ascent
= it
->max_ascent
;
7684 it
->max_ascent
= it
->max_descent
= 0;
7689 /* On text terminals, we may stop at the end of a line in the middle
7690 of a multi-character glyph. If the glyph itself is continued,
7691 i.e. it is actually displayed on the next line, don't treat this
7692 stopping point as valid; move to the next line instead (unless
7693 that brings us offscreen). */
7694 if (!FRAME_WINDOW_P (it
->f
)
7696 && IT_CHARPOS (*it
) == to_charpos
7697 && it
->what
== IT_CHARACTER
7699 && it
->line_wrap
== WINDOW_WRAP
7700 && it
->current_x
== it
->last_visible_x
- 1
7703 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7705 it
->continuation_lines_width
+= it
->current_x
;
7706 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7707 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7709 last_height
= it
->max_ascent
+ it
->max_descent
;
7710 last_max_ascent
= it
->max_ascent
;
7713 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7717 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7719 If DY > 0, move IT backward at least that many pixels. DY = 0
7720 means move IT backward to the preceding line start or BEGV. This
7721 function may move over more than DY pixels if IT->current_y - DY
7722 ends up in the middle of a line; in this case IT->current_y will be
7723 set to the top of the line moved to. */
7726 move_it_vertically_backward (struct it
*it
, int dy
)
7730 EMACS_INT start_pos
;
7735 start_pos
= IT_CHARPOS (*it
);
7737 /* Estimate how many newlines we must move back. */
7738 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7740 /* Set the iterator's position that many lines back. */
7741 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7742 back_to_previous_visible_line_start (it
);
7744 /* Reseat the iterator here. When moving backward, we don't want
7745 reseat to skip forward over invisible text, set up the iterator
7746 to deliver from overlay strings at the new position etc. So,
7747 use reseat_1 here. */
7748 reseat_1 (it
, it
->current
.pos
, 1);
7750 /* We are now surely at a line start. */
7751 it
->current_x
= it
->hpos
= 0;
7752 it
->continuation_lines_width
= 0;
7754 /* Move forward and see what y-distance we moved. First move to the
7755 start of the next line so that we get its height. We need this
7756 height to be able to tell whether we reached the specified
7759 it2
.max_ascent
= it2
.max_descent
= 0;
7762 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7763 MOVE_TO_POS
| MOVE_TO_VPOS
);
7765 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7766 xassert (IT_CHARPOS (*it
) >= BEGV
);
7769 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7770 xassert (IT_CHARPOS (*it
) >= BEGV
);
7771 /* H is the actual vertical distance from the position in *IT
7772 and the starting position. */
7773 h
= it2
.current_y
- it
->current_y
;
7774 /* NLINES is the distance in number of lines. */
7775 nlines
= it2
.vpos
- it
->vpos
;
7777 /* Correct IT's y and vpos position
7778 so that they are relative to the starting point. */
7784 /* DY == 0 means move to the start of the screen line. The
7785 value of nlines is > 0 if continuation lines were involved. */
7787 move_it_by_lines (it
, nlines
);
7791 /* The y-position we try to reach, relative to *IT.
7792 Note that H has been subtracted in front of the if-statement. */
7793 int target_y
= it
->current_y
+ h
- dy
;
7794 int y0
= it3
.current_y
;
7795 int y1
= line_bottom_y (&it3
);
7796 int line_height
= y1
- y0
;
7798 /* If we did not reach target_y, try to move further backward if
7799 we can. If we moved too far backward, try to move forward. */
7800 if (target_y
< it
->current_y
7801 /* This is heuristic. In a window that's 3 lines high, with
7802 a line height of 13 pixels each, recentering with point
7803 on the bottom line will try to move -39/2 = 19 pixels
7804 backward. Try to avoid moving into the first line. */
7805 && (it
->current_y
- target_y
7806 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7807 && IT_CHARPOS (*it
) > BEGV
)
7809 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7810 target_y
- it
->current_y
));
7811 dy
= it
->current_y
- target_y
;
7812 goto move_further_back
;
7814 else if (target_y
>= it
->current_y
+ line_height
7815 && IT_CHARPOS (*it
) < ZV
)
7817 /* Should move forward by at least one line, maybe more.
7819 Note: Calling move_it_by_lines can be expensive on
7820 terminal frames, where compute_motion is used (via
7821 vmotion) to do the job, when there are very long lines
7822 and truncate-lines is nil. That's the reason for
7823 treating terminal frames specially here. */
7825 if (!FRAME_WINDOW_P (it
->f
))
7826 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7831 move_it_by_lines (it
, 1);
7833 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7840 /* Move IT by a specified amount of pixel lines DY. DY negative means
7841 move backwards. DY = 0 means move to start of screen line. At the
7842 end, IT will be on the start of a screen line. */
7845 move_it_vertically (struct it
*it
, int dy
)
7848 move_it_vertically_backward (it
, -dy
);
7851 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7852 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7853 MOVE_TO_POS
| MOVE_TO_Y
);
7854 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7856 /* If buffer ends in ZV without a newline, move to the start of
7857 the line to satisfy the post-condition. */
7858 if (IT_CHARPOS (*it
) == ZV
7860 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7861 move_it_by_lines (it
, 0);
7866 /* Move iterator IT past the end of the text line it is in. */
7869 move_it_past_eol (struct it
*it
)
7871 enum move_it_result rc
;
7873 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7874 if (rc
== MOVE_NEWLINE_OR_CR
)
7875 set_iterator_to_next (it
, 0);
7879 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7880 negative means move up. DVPOS == 0 means move to the start of the
7883 Optimization idea: If we would know that IT->f doesn't use
7884 a face with proportional font, we could be faster for
7885 truncate-lines nil. */
7888 move_it_by_lines (struct it
*it
, int dvpos
)
7891 /* The commented-out optimization uses vmotion on terminals. This
7892 gives bad results, because elements like it->what, on which
7893 callers such as pos_visible_p rely, aren't updated. */
7894 /* struct position pos;
7895 if (!FRAME_WINDOW_P (it->f))
7897 struct text_pos textpos;
7899 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7900 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7901 reseat (it, textpos, 1);
7902 it->vpos += pos.vpos;
7903 it->current_y += pos.vpos;
7909 /* DVPOS == 0 means move to the start of the screen line. */
7910 move_it_vertically_backward (it
, 0);
7911 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7912 /* Let next call to line_bottom_y calculate real line height */
7917 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7918 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7919 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7924 EMACS_INT start_charpos
, i
;
7926 /* Start at the beginning of the screen line containing IT's
7927 position. This may actually move vertically backwards,
7928 in case of overlays, so adjust dvpos accordingly. */
7930 move_it_vertically_backward (it
, 0);
7933 /* Go back -DVPOS visible lines and reseat the iterator there. */
7934 start_charpos
= IT_CHARPOS (*it
);
7935 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7936 back_to_previous_visible_line_start (it
);
7937 reseat (it
, it
->current
.pos
, 1);
7939 /* Move further back if we end up in a string or an image. */
7940 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7942 /* First try to move to start of display line. */
7944 move_it_vertically_backward (it
, 0);
7946 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7948 /* If start of line is still in string or image,
7949 move further back. */
7950 back_to_previous_visible_line_start (it
);
7951 reseat (it
, it
->current
.pos
, 1);
7955 it
->current_x
= it
->hpos
= 0;
7957 /* Above call may have moved too far if continuation lines
7958 are involved. Scan forward and see if it did. */
7960 it2
.vpos
= it2
.current_y
= 0;
7961 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7962 it
->vpos
-= it2
.vpos
;
7963 it
->current_y
-= it2
.current_y
;
7964 it
->current_x
= it
->hpos
= 0;
7966 /* If we moved too far back, move IT some lines forward. */
7967 if (it2
.vpos
> -dvpos
)
7969 int delta
= it2
.vpos
+ dvpos
;
7971 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7972 /* Move back again if we got too far ahead. */
7973 if (IT_CHARPOS (*it
) >= start_charpos
)
7979 /* Return 1 if IT points into the middle of a display vector. */
7982 in_display_vector_p (struct it
*it
)
7984 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7985 && it
->current
.dpvec_index
> 0
7986 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7990 /***********************************************************************
7992 ***********************************************************************/
7995 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7999 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
8001 Lisp_Object args
[3];
8002 Lisp_Object msg
, fmt
;
8005 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
8008 /* Do nothing if called asynchronously. Inserting text into
8009 a buffer may call after-change-functions and alike and
8010 that would means running Lisp asynchronously. */
8011 if (handling_signal
)
8015 GCPRO4 (fmt
, msg
, arg1
, arg2
);
8017 args
[0] = fmt
= build_string (format
);
8020 msg
= Fformat (3, args
);
8022 len
= SBYTES (msg
) + 1;
8023 SAFE_ALLOCA (buffer
, char *, len
);
8024 memcpy (buffer
, SDATA (msg
), len
);
8026 message_dolog (buffer
, len
- 1, 1, 0);
8033 /* Output a newline in the *Messages* buffer if "needs" one. */
8036 message_log_maybe_newline (void)
8038 if (message_log_need_newline
)
8039 message_dolog ("", 0, 1, 0);
8043 /* Add a string M of length NBYTES to the message log, optionally
8044 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
8045 nonzero, means interpret the contents of M as multibyte. This
8046 function calls low-level routines in order to bypass text property
8047 hooks, etc. which might not be safe to run.
8049 This may GC (insert may run before/after change hooks),
8050 so the buffer M must NOT point to a Lisp string. */
8053 message_dolog (const char *m
, EMACS_INT nbytes
, int nlflag
, int multibyte
)
8055 const unsigned char *msg
= (const unsigned char *) m
;
8057 if (!NILP (Vmemory_full
))
8060 if (!NILP (Vmessage_log_max
))
8062 struct buffer
*oldbuf
;
8063 Lisp_Object oldpoint
, oldbegv
, oldzv
;
8064 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
8065 EMACS_INT point_at_end
= 0;
8066 EMACS_INT zv_at_end
= 0;
8067 Lisp_Object old_deactivate_mark
, tem
;
8068 struct gcpro gcpro1
;
8070 old_deactivate_mark
= Vdeactivate_mark
;
8071 oldbuf
= current_buffer
;
8072 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
8073 BVAR (current_buffer
, undo_list
) = Qt
;
8075 oldpoint
= message_dolog_marker1
;
8076 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
8077 oldbegv
= message_dolog_marker2
;
8078 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
8079 oldzv
= message_dolog_marker3
;
8080 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
8081 GCPRO1 (old_deactivate_mark
);
8089 BEGV_BYTE
= BEG_BYTE
;
8092 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8094 /* Insert the string--maybe converting multibyte to single byte
8095 or vice versa, so that all the text fits the buffer. */
8097 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8103 /* Convert a multibyte string to single-byte
8104 for the *Message* buffer. */
8105 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
8107 c
= string_char_and_length (msg
+ i
, &char_bytes
);
8108 work
[0] = (ASCII_CHAR_P (c
)
8110 : multibyte_char_to_unibyte (c
));
8111 insert_1_both (work
, 1, 1, 1, 0, 0);
8114 else if (! multibyte
8115 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8119 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8120 /* Convert a single-byte string to multibyte
8121 for the *Message* buffer. */
8122 for (i
= 0; i
< nbytes
; i
++)
8125 MAKE_CHAR_MULTIBYTE (c
);
8126 char_bytes
= CHAR_STRING (c
, str
);
8127 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
8131 insert_1 (m
, nbytes
, 1, 0, 0);
8135 EMACS_INT this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
8136 unsigned long int dups
;
8137 insert_1 ("\n", 1, 1, 0, 0);
8139 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8141 this_bol_byte
= PT_BYTE
;
8143 /* See if this line duplicates the previous one.
8144 If so, combine duplicates. */
8147 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8149 prev_bol_byte
= PT_BYTE
;
8151 dups
= message_log_check_duplicate (prev_bol_byte
,
8155 del_range_both (prev_bol
, prev_bol_byte
,
8156 this_bol
, this_bol_byte
, 0);
8162 /* If you change this format, don't forget to also
8163 change message_log_check_duplicate. */
8164 sprintf (dupstr
, " [%lu times]", dups
);
8165 duplen
= strlen (dupstr
);
8166 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8167 insert_1 (dupstr
, duplen
, 1, 0, 1);
8172 /* If we have more than the desired maximum number of lines
8173 in the *Messages* buffer now, delete the oldest ones.
8174 This is safe because we don't have undo in this buffer. */
8176 if (NATNUMP (Vmessage_log_max
))
8178 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8179 -XFASTINT (Vmessage_log_max
) - 1, 0);
8180 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8183 BEGV
= XMARKER (oldbegv
)->charpos
;
8184 BEGV_BYTE
= marker_byte_position (oldbegv
);
8193 ZV
= XMARKER (oldzv
)->charpos
;
8194 ZV_BYTE
= marker_byte_position (oldzv
);
8198 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8200 /* We can't do Fgoto_char (oldpoint) because it will run some
8202 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8203 XMARKER (oldpoint
)->bytepos
);
8206 unchain_marker (XMARKER (oldpoint
));
8207 unchain_marker (XMARKER (oldbegv
));
8208 unchain_marker (XMARKER (oldzv
));
8210 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8211 set_buffer_internal (oldbuf
);
8213 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8214 message_log_need_newline
= !nlflag
;
8215 Vdeactivate_mark
= old_deactivate_mark
;
8220 /* We are at the end of the buffer after just having inserted a newline.
8221 (Note: We depend on the fact we won't be crossing the gap.)
8222 Check to see if the most recent message looks a lot like the previous one.
8223 Return 0 if different, 1 if the new one should just replace it, or a
8224 value N > 1 if we should also append " [N times]". */
8226 static unsigned long int
8227 message_log_check_duplicate (EMACS_INT prev_bol_byte
, EMACS_INT this_bol_byte
)
8230 EMACS_INT len
= Z_BYTE
- 1 - this_bol_byte
;
8232 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8233 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8235 for (i
= 0; i
< len
; i
++)
8237 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8245 if (*p1
++ == ' ' && *p1
++ == '[')
8248 unsigned long int n
= strtoul ((char *) p1
, &pend
, 10);
8249 if (strncmp (pend
, " times]\n", 8) == 0)
8256 /* Display an echo area message M with a specified length of NBYTES
8257 bytes. The string may include null characters. If M is 0, clear
8258 out any existing message, and let the mini-buffer text show
8261 This may GC, so the buffer M must NOT point to a Lisp string. */
8264 message2 (const char *m
, EMACS_INT nbytes
, int multibyte
)
8266 /* First flush out any partial line written with print. */
8267 message_log_maybe_newline ();
8269 message_dolog (m
, nbytes
, 1, multibyte
);
8270 message2_nolog (m
, nbytes
, multibyte
);
8274 /* The non-logging counterpart of message2. */
8277 message2_nolog (const char *m
, EMACS_INT nbytes
, int multibyte
)
8279 struct frame
*sf
= SELECTED_FRAME ();
8280 message_enable_multibyte
= multibyte
;
8282 if (FRAME_INITIAL_P (sf
))
8284 if (noninteractive_need_newline
)
8285 putc ('\n', stderr
);
8286 noninteractive_need_newline
= 0;
8288 fwrite (m
, nbytes
, 1, stderr
);
8289 if (cursor_in_echo_area
== 0)
8290 fprintf (stderr
, "\n");
8293 /* A null message buffer means that the frame hasn't really been
8294 initialized yet. Error messages get reported properly by
8295 cmd_error, so this must be just an informative message; toss it. */
8296 else if (INTERACTIVE
8297 && sf
->glyphs_initialized_p
8298 && FRAME_MESSAGE_BUF (sf
))
8300 Lisp_Object mini_window
;
8303 /* Get the frame containing the mini-buffer
8304 that the selected frame is using. */
8305 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8306 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8308 FRAME_SAMPLE_VISIBILITY (f
);
8309 if (FRAME_VISIBLE_P (sf
)
8310 && ! FRAME_VISIBLE_P (f
))
8311 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8315 set_message (m
, Qnil
, nbytes
, multibyte
);
8316 if (minibuffer_auto_raise
)
8317 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8320 clear_message (1, 1);
8322 do_pending_window_change (0);
8323 echo_area_display (1);
8324 do_pending_window_change (0);
8325 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8326 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8331 /* Display an echo area message M with a specified length of NBYTES
8332 bytes. The string may include null characters. If M is not a
8333 string, clear out any existing message, and let the mini-buffer
8336 This function cancels echoing. */
8339 message3 (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8341 struct gcpro gcpro1
;
8344 clear_message (1,1);
8347 /* First flush out any partial line written with print. */
8348 message_log_maybe_newline ();
8354 SAFE_ALLOCA (buffer
, char *, nbytes
);
8355 memcpy (buffer
, SDATA (m
), nbytes
);
8356 message_dolog (buffer
, nbytes
, 1, multibyte
);
8359 message3_nolog (m
, nbytes
, multibyte
);
8365 /* The non-logging version of message3.
8366 This does not cancel echoing, because it is used for echoing.
8367 Perhaps we need to make a separate function for echoing
8368 and make this cancel echoing. */
8371 message3_nolog (Lisp_Object m
, EMACS_INT nbytes
, int multibyte
)
8373 struct frame
*sf
= SELECTED_FRAME ();
8374 message_enable_multibyte
= multibyte
;
8376 if (FRAME_INITIAL_P (sf
))
8378 if (noninteractive_need_newline
)
8379 putc ('\n', stderr
);
8380 noninteractive_need_newline
= 0;
8382 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8383 if (cursor_in_echo_area
== 0)
8384 fprintf (stderr
, "\n");
8387 /* A null message buffer means that the frame hasn't really been
8388 initialized yet. Error messages get reported properly by
8389 cmd_error, so this must be just an informative message; toss it. */
8390 else if (INTERACTIVE
8391 && sf
->glyphs_initialized_p
8392 && FRAME_MESSAGE_BUF (sf
))
8394 Lisp_Object mini_window
;
8398 /* Get the frame containing the mini-buffer
8399 that the selected frame is using. */
8400 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8401 frame
= XWINDOW (mini_window
)->frame
;
8404 FRAME_SAMPLE_VISIBILITY (f
);
8405 if (FRAME_VISIBLE_P (sf
)
8406 && !FRAME_VISIBLE_P (f
))
8407 Fmake_frame_visible (frame
);
8409 if (STRINGP (m
) && SCHARS (m
) > 0)
8411 set_message (NULL
, m
, nbytes
, multibyte
);
8412 if (minibuffer_auto_raise
)
8413 Fraise_frame (frame
);
8414 /* Assume we are not echoing.
8415 (If we are, echo_now will override this.) */
8416 echo_message_buffer
= Qnil
;
8419 clear_message (1, 1);
8421 do_pending_window_change (0);
8422 echo_area_display (1);
8423 do_pending_window_change (0);
8424 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8425 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8430 /* Display a null-terminated echo area message M. If M is 0, clear
8431 out any existing message, and let the mini-buffer text show through.
8433 The buffer M must continue to exist until after the echo area gets
8434 cleared or some other message gets displayed there. Do not pass
8435 text that is stored in a Lisp string. Do not pass text in a buffer
8436 that was alloca'd. */
8439 message1 (const char *m
)
8441 message2 (m
, (m
? strlen (m
) : 0), 0);
8445 /* The non-logging counterpart of message1. */
8448 message1_nolog (const char *m
)
8450 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8453 /* Display a message M which contains a single %s
8454 which gets replaced with STRING. */
8457 message_with_string (const char *m
, Lisp_Object string
, int log
)
8459 CHECK_STRING (string
);
8465 if (noninteractive_need_newline
)
8466 putc ('\n', stderr
);
8467 noninteractive_need_newline
= 0;
8468 fprintf (stderr
, m
, SDATA (string
));
8469 if (!cursor_in_echo_area
)
8470 fprintf (stderr
, "\n");
8474 else if (INTERACTIVE
)
8476 /* The frame whose minibuffer we're going to display the message on.
8477 It may be larger than the selected frame, so we need
8478 to use its buffer, not the selected frame's buffer. */
8479 Lisp_Object mini_window
;
8480 struct frame
*f
, *sf
= SELECTED_FRAME ();
8482 /* Get the frame containing the minibuffer
8483 that the selected frame is using. */
8484 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8485 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8487 /* A null message buffer means that the frame hasn't really been
8488 initialized yet. Error messages get reported properly by
8489 cmd_error, so this must be just an informative message; toss it. */
8490 if (FRAME_MESSAGE_BUF (f
))
8492 Lisp_Object args
[2], msg
;
8493 struct gcpro gcpro1
, gcpro2
;
8495 args
[0] = build_string (m
);
8496 args
[1] = msg
= string
;
8497 GCPRO2 (args
[0], msg
);
8500 msg
= Fformat (2, args
);
8503 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8505 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8509 /* Print should start at the beginning of the message
8510 buffer next time. */
8511 message_buf_print
= 0;
8517 /* Dump an informative message to the minibuf. If M is 0, clear out
8518 any existing message, and let the mini-buffer text show through. */
8521 vmessage (const char *m
, va_list ap
)
8527 if (noninteractive_need_newline
)
8528 putc ('\n', stderr
);
8529 noninteractive_need_newline
= 0;
8530 vfprintf (stderr
, m
, ap
);
8531 if (cursor_in_echo_area
== 0)
8532 fprintf (stderr
, "\n");
8536 else if (INTERACTIVE
)
8538 /* The frame whose mini-buffer we're going to display the message
8539 on. It may be larger than the selected frame, so we need to
8540 use its buffer, not the selected frame's buffer. */
8541 Lisp_Object mini_window
;
8542 struct frame
*f
, *sf
= SELECTED_FRAME ();
8544 /* Get the frame containing the mini-buffer
8545 that the selected frame is using. */
8546 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8547 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8549 /* A null message buffer means that the frame hasn't really been
8550 initialized yet. Error messages get reported properly by
8551 cmd_error, so this must be just an informative message; toss
8553 if (FRAME_MESSAGE_BUF (f
))
8559 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8560 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
8562 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8567 /* Print should start at the beginning of the message
8568 buffer next time. */
8569 message_buf_print
= 0;
8575 message (const char *m
, ...)
8585 /* The non-logging version of message. */
8588 message_nolog (const char *m
, ...)
8590 Lisp_Object old_log_max
;
8593 old_log_max
= Vmessage_log_max
;
8594 Vmessage_log_max
= Qnil
;
8596 Vmessage_log_max
= old_log_max
;
8602 /* Display the current message in the current mini-buffer. This is
8603 only called from error handlers in process.c, and is not time
8607 update_echo_area (void)
8609 if (!NILP (echo_area_buffer
[0]))
8612 string
= Fcurrent_message ();
8613 message3 (string
, SBYTES (string
),
8614 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
8619 /* Make sure echo area buffers in `echo_buffers' are live.
8620 If they aren't, make new ones. */
8623 ensure_echo_area_buffers (void)
8627 for (i
= 0; i
< 2; ++i
)
8628 if (!BUFFERP (echo_buffer
[i
])
8629 || NILP (BVAR (XBUFFER (echo_buffer
[i
]), name
)))
8632 Lisp_Object old_buffer
;
8635 old_buffer
= echo_buffer
[i
];
8636 sprintf (name
, " *Echo Area %d*", i
);
8637 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8638 BVAR (XBUFFER (echo_buffer
[i
]), truncate_lines
) = Qnil
;
8639 /* to force word wrap in echo area -
8640 it was decided to postpone this*/
8641 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8643 for (j
= 0; j
< 2; ++j
)
8644 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8645 echo_area_buffer
[j
] = echo_buffer
[i
];
8650 /* Call FN with args A1..A4 with either the current or last displayed
8651 echo_area_buffer as current buffer.
8653 WHICH zero means use the current message buffer
8654 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8655 from echo_buffer[] and clear it.
8657 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8658 suitable buffer from echo_buffer[] and clear it.
8660 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8661 that the current message becomes the last displayed one, make
8662 choose a suitable buffer for echo_area_buffer[0], and clear it.
8664 Value is what FN returns. */
8667 with_echo_area_buffer (struct window
*w
, int which
,
8668 int (*fn
) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
8669 EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
8672 int this_one
, the_other
, clear_buffer_p
, rc
;
8673 int count
= SPECPDL_INDEX ();
8675 /* If buffers aren't live, make new ones. */
8676 ensure_echo_area_buffers ();
8681 this_one
= 0, the_other
= 1;
8683 this_one
= 1, the_other
= 0;
8686 this_one
= 0, the_other
= 1;
8689 /* We need a fresh one in case the current echo buffer equals
8690 the one containing the last displayed echo area message. */
8691 if (!NILP (echo_area_buffer
[this_one
])
8692 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8693 echo_area_buffer
[this_one
] = Qnil
;
8696 /* Choose a suitable buffer from echo_buffer[] is we don't
8698 if (NILP (echo_area_buffer
[this_one
]))
8700 echo_area_buffer
[this_one
]
8701 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8702 ? echo_buffer
[the_other
]
8703 : echo_buffer
[this_one
]);
8707 buffer
= echo_area_buffer
[this_one
];
8709 /* Don't get confused by reusing the buffer used for echoing
8710 for a different purpose. */
8711 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8714 record_unwind_protect (unwind_with_echo_area_buffer
,
8715 with_echo_area_buffer_unwind_data (w
));
8717 /* Make the echo area buffer current. Note that for display
8718 purposes, it is not necessary that the displayed window's buffer
8719 == current_buffer, except for text property lookup. So, let's
8720 only set that buffer temporarily here without doing a full
8721 Fset_window_buffer. We must also change w->pointm, though,
8722 because otherwise an assertions in unshow_buffer fails, and Emacs
8724 set_buffer_internal_1 (XBUFFER (buffer
));
8728 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8731 BVAR (current_buffer
, undo_list
) = Qt
;
8732 BVAR (current_buffer
, read_only
) = Qnil
;
8733 specbind (Qinhibit_read_only
, Qt
);
8734 specbind (Qinhibit_modification_hooks
, Qt
);
8736 if (clear_buffer_p
&& Z
> BEG
)
8739 xassert (BEGV
>= BEG
);
8740 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8742 rc
= fn (a1
, a2
, a3
, a4
);
8744 xassert (BEGV
>= BEG
);
8745 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8747 unbind_to (count
, Qnil
);
8752 /* Save state that should be preserved around the call to the function
8753 FN called in with_echo_area_buffer. */
8756 with_echo_area_buffer_unwind_data (struct window
*w
)
8759 Lisp_Object vector
, tmp
;
8761 /* Reduce consing by keeping one vector in
8762 Vwith_echo_area_save_vector. */
8763 vector
= Vwith_echo_area_save_vector
;
8764 Vwith_echo_area_save_vector
= Qnil
;
8767 vector
= Fmake_vector (make_number (7), Qnil
);
8769 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8770 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8771 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8775 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8776 ASET (vector
, i
, w
->buffer
); ++i
;
8777 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8778 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8783 for (; i
< end
; ++i
)
8784 ASET (vector
, i
, Qnil
);
8787 xassert (i
== ASIZE (vector
));
8792 /* Restore global state from VECTOR which was created by
8793 with_echo_area_buffer_unwind_data. */
8796 unwind_with_echo_area_buffer (Lisp_Object vector
)
8798 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8799 Vdeactivate_mark
= AREF (vector
, 1);
8800 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8802 if (WINDOWP (AREF (vector
, 3)))
8805 Lisp_Object buffer
, charpos
, bytepos
;
8807 w
= XWINDOW (AREF (vector
, 3));
8808 buffer
= AREF (vector
, 4);
8809 charpos
= AREF (vector
, 5);
8810 bytepos
= AREF (vector
, 6);
8813 set_marker_both (w
->pointm
, buffer
,
8814 XFASTINT (charpos
), XFASTINT (bytepos
));
8817 Vwith_echo_area_save_vector
= vector
;
8822 /* Set up the echo area for use by print functions. MULTIBYTE_P
8823 non-zero means we will print multibyte. */
8826 setup_echo_area_for_printing (int multibyte_p
)
8828 /* If we can't find an echo area any more, exit. */
8829 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8832 ensure_echo_area_buffers ();
8834 if (!message_buf_print
)
8836 /* A message has been output since the last time we printed.
8837 Choose a fresh echo area buffer. */
8838 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8839 echo_area_buffer
[0] = echo_buffer
[1];
8841 echo_area_buffer
[0] = echo_buffer
[0];
8843 /* Switch to that buffer and clear it. */
8844 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8845 BVAR (current_buffer
, truncate_lines
) = Qnil
;
8849 int count
= SPECPDL_INDEX ();
8850 specbind (Qinhibit_read_only
, Qt
);
8851 /* Note that undo recording is always disabled. */
8853 unbind_to (count
, Qnil
);
8855 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8857 /* Set up the buffer for the multibyteness we need. */
8859 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
8860 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8862 /* Raise the frame containing the echo area. */
8863 if (minibuffer_auto_raise
)
8865 struct frame
*sf
= SELECTED_FRAME ();
8866 Lisp_Object mini_window
;
8867 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8868 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8871 message_log_maybe_newline ();
8872 message_buf_print
= 1;
8876 if (NILP (echo_area_buffer
[0]))
8878 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8879 echo_area_buffer
[0] = echo_buffer
[1];
8881 echo_area_buffer
[0] = echo_buffer
[0];
8884 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8886 /* Someone switched buffers between print requests. */
8887 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8888 BVAR (current_buffer
, truncate_lines
) = Qnil
;
8894 /* Display an echo area message in window W. Value is non-zero if W's
8895 height is changed. If display_last_displayed_message_p is
8896 non-zero, display the message that was last displayed, otherwise
8897 display the current message. */
8900 display_echo_area (struct window
*w
)
8902 int i
, no_message_p
, window_height_changed_p
, count
;
8904 /* Temporarily disable garbage collections while displaying the echo
8905 area. This is done because a GC can print a message itself.
8906 That message would modify the echo area buffer's contents while a
8907 redisplay of the buffer is going on, and seriously confuse
8909 count
= inhibit_garbage_collection ();
8911 /* If there is no message, we must call display_echo_area_1
8912 nevertheless because it resizes the window. But we will have to
8913 reset the echo_area_buffer in question to nil at the end because
8914 with_echo_area_buffer will sets it to an empty buffer. */
8915 i
= display_last_displayed_message_p
? 1 : 0;
8916 no_message_p
= NILP (echo_area_buffer
[i
]);
8918 window_height_changed_p
8919 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8920 display_echo_area_1
,
8921 (intptr_t) w
, Qnil
, 0, 0);
8924 echo_area_buffer
[i
] = Qnil
;
8926 unbind_to (count
, Qnil
);
8927 return window_height_changed_p
;
8931 /* Helper for display_echo_area. Display the current buffer which
8932 contains the current echo area message in window W, a mini-window,
8933 a pointer to which is passed in A1. A2..A4 are currently not used.
8934 Change the height of W so that all of the message is displayed.
8935 Value is non-zero if height of W was changed. */
8938 display_echo_area_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
8941 struct window
*w
= (struct window
*) i1
;
8943 struct text_pos start
;
8944 int window_height_changed_p
= 0;
8946 /* Do this before displaying, so that we have a large enough glyph
8947 matrix for the display. If we can't get enough space for the
8948 whole text, display the last N lines. That works by setting w->start. */
8949 window_height_changed_p
= resize_mini_window (w
, 0);
8951 /* Use the starting position chosen by resize_mini_window. */
8952 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8955 clear_glyph_matrix (w
->desired_matrix
);
8956 XSETWINDOW (window
, w
);
8957 try_window (window
, start
, 0);
8959 return window_height_changed_p
;
8963 /* Resize the echo area window to exactly the size needed for the
8964 currently displayed message, if there is one. If a mini-buffer
8965 is active, don't shrink it. */
8968 resize_echo_area_exactly (void)
8970 if (BUFFERP (echo_area_buffer
[0])
8971 && WINDOWP (echo_area_window
))
8973 struct window
*w
= XWINDOW (echo_area_window
);
8975 Lisp_Object resize_exactly
;
8977 if (minibuf_level
== 0)
8978 resize_exactly
= Qt
;
8980 resize_exactly
= Qnil
;
8982 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8983 (intptr_t) w
, resize_exactly
,
8987 ++windows_or_buffers_changed
;
8988 ++update_mode_lines
;
8989 redisplay_internal ();
8995 /* Callback function for with_echo_area_buffer, when used from
8996 resize_echo_area_exactly. A1 contains a pointer to the window to
8997 resize, EXACTLY non-nil means resize the mini-window exactly to the
8998 size of the text displayed. A3 and A4 are not used. Value is what
8999 resize_mini_window returns. */
9002 resize_mini_window_1 (EMACS_INT a1
, Lisp_Object exactly
, EMACS_INT a3
, EMACS_INT a4
)
9005 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
9009 /* Resize mini-window W to fit the size of its contents. EXACT_P
9010 means size the window exactly to the size needed. Otherwise, it's
9011 only enlarged until W's buffer is empty.
9013 Set W->start to the right place to begin display. If the whole
9014 contents fit, start at the beginning. Otherwise, start so as
9015 to make the end of the contents appear. This is particularly
9016 important for y-or-n-p, but seems desirable generally.
9018 Value is non-zero if the window height has been changed. */
9021 resize_mini_window (struct window
*w
, int exact_p
)
9023 struct frame
*f
= XFRAME (w
->frame
);
9024 int window_height_changed_p
= 0;
9026 xassert (MINI_WINDOW_P (w
));
9028 /* By default, start display at the beginning. */
9029 set_marker_both (w
->start
, w
->buffer
,
9030 BUF_BEGV (XBUFFER (w
->buffer
)),
9031 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
9033 /* Don't resize windows while redisplaying a window; it would
9034 confuse redisplay functions when the size of the window they are
9035 displaying changes from under them. Such a resizing can happen,
9036 for instance, when which-func prints a long message while
9037 we are running fontification-functions. We're running these
9038 functions with safe_call which binds inhibit-redisplay to t. */
9039 if (!NILP (Vinhibit_redisplay
))
9042 /* Nil means don't try to resize. */
9043 if (NILP (Vresize_mini_windows
)
9044 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
9047 if (!FRAME_MINIBUF_ONLY_P (f
))
9050 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
9051 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
9052 int height
, max_height
;
9053 int unit
= FRAME_LINE_HEIGHT (f
);
9054 struct text_pos start
;
9055 struct buffer
*old_current_buffer
= NULL
;
9057 if (current_buffer
!= XBUFFER (w
->buffer
))
9059 old_current_buffer
= current_buffer
;
9060 set_buffer_internal (XBUFFER (w
->buffer
));
9063 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9065 /* Compute the max. number of lines specified by the user. */
9066 if (FLOATP (Vmax_mini_window_height
))
9067 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
9068 else if (INTEGERP (Vmax_mini_window_height
))
9069 max_height
= XINT (Vmax_mini_window_height
);
9071 max_height
= total_height
/ 4;
9073 /* Correct that max. height if it's bogus. */
9074 max_height
= max (1, max_height
);
9075 max_height
= min (total_height
, max_height
);
9077 /* Find out the height of the text in the window. */
9078 if (it
.line_wrap
== TRUNCATE
)
9083 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
9084 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
9085 height
= it
.current_y
+ last_height
;
9087 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9088 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9089 height
= (height
+ unit
- 1) / unit
;
9092 /* Compute a suitable window start. */
9093 if (height
> max_height
)
9095 height
= max_height
;
9096 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9097 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9098 start
= it
.current
.pos
;
9101 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9102 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9104 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9106 /* Let it grow only, until we display an empty message, in which
9107 case the window shrinks again. */
9108 if (height
> WINDOW_TOTAL_LINES (w
))
9110 int old_height
= WINDOW_TOTAL_LINES (w
);
9111 freeze_window_starts (f
, 1);
9112 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9113 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9115 else if (height
< WINDOW_TOTAL_LINES (w
)
9116 && (exact_p
|| BEGV
== ZV
))
9118 int old_height
= WINDOW_TOTAL_LINES (w
);
9119 freeze_window_starts (f
, 0);
9120 shrink_mini_window (w
);
9121 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9126 /* Always resize to exact size needed. */
9127 if (height
> WINDOW_TOTAL_LINES (w
))
9129 int old_height
= WINDOW_TOTAL_LINES (w
);
9130 freeze_window_starts (f
, 1);
9131 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9132 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9134 else if (height
< WINDOW_TOTAL_LINES (w
))
9136 int old_height
= WINDOW_TOTAL_LINES (w
);
9137 freeze_window_starts (f
, 0);
9138 shrink_mini_window (w
);
9142 freeze_window_starts (f
, 1);
9143 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9146 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9150 if (old_current_buffer
)
9151 set_buffer_internal (old_current_buffer
);
9154 return window_height_changed_p
;
9158 /* Value is the current message, a string, or nil if there is no
9162 current_message (void)
9166 if (!BUFFERP (echo_area_buffer
[0]))
9170 with_echo_area_buffer (0, 0, current_message_1
,
9171 (intptr_t) &msg
, Qnil
, 0, 0);
9173 echo_area_buffer
[0] = Qnil
;
9181 current_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9184 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
9187 *msg
= make_buffer_string (BEG
, Z
, 1);
9194 /* Push the current message on Vmessage_stack for later restauration
9195 by restore_message. Value is non-zero if the current message isn't
9196 empty. This is a relatively infrequent operation, so it's not
9197 worth optimizing. */
9203 msg
= current_message ();
9204 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9205 return STRINGP (msg
);
9209 /* Restore message display from the top of Vmessage_stack. */
9212 restore_message (void)
9216 xassert (CONSP (Vmessage_stack
));
9217 msg
= XCAR (Vmessage_stack
);
9219 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9221 message3_nolog (msg
, 0, 0);
9225 /* Handler for record_unwind_protect calling pop_message. */
9228 pop_message_unwind (Lisp_Object dummy
)
9234 /* Pop the top-most entry off Vmessage_stack. */
9239 xassert (CONSP (Vmessage_stack
));
9240 Vmessage_stack
= XCDR (Vmessage_stack
);
9244 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9245 exits. If the stack is not empty, we have a missing pop_message
9249 check_message_stack (void)
9251 if (!NILP (Vmessage_stack
))
9256 /* Truncate to NCHARS what will be displayed in the echo area the next
9257 time we display it---but don't redisplay it now. */
9260 truncate_echo_area (EMACS_INT nchars
)
9263 echo_area_buffer
[0] = Qnil
;
9264 /* A null message buffer means that the frame hasn't really been
9265 initialized yet. Error messages get reported properly by
9266 cmd_error, so this must be just an informative message; toss it. */
9267 else if (!noninteractive
9269 && !NILP (echo_area_buffer
[0]))
9271 struct frame
*sf
= SELECTED_FRAME ();
9272 if (FRAME_MESSAGE_BUF (sf
))
9273 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9278 /* Helper function for truncate_echo_area. Truncate the current
9279 message to at most NCHARS characters. */
9282 truncate_message_1 (EMACS_INT nchars
, Lisp_Object a2
, EMACS_INT a3
, EMACS_INT a4
)
9284 if (BEG
+ nchars
< Z
)
9285 del_range (BEG
+ nchars
, Z
);
9287 echo_area_buffer
[0] = Qnil
;
9292 /* Set the current message to a substring of S or STRING.
9294 If STRING is a Lisp string, set the message to the first NBYTES
9295 bytes from STRING. NBYTES zero means use the whole string. If
9296 STRING is multibyte, the message will be displayed multibyte.
9298 If S is not null, set the message to the first LEN bytes of S. LEN
9299 zero means use the whole string. MULTIBYTE_P non-zero means S is
9300 multibyte. Display the message multibyte in that case.
9302 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9303 to t before calling set_message_1 (which calls insert).
9307 set_message (const char *s
, Lisp_Object string
,
9308 EMACS_INT nbytes
, int multibyte_p
)
9310 message_enable_multibyte
9311 = ((s
&& multibyte_p
)
9312 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9314 with_echo_area_buffer (0, -1, set_message_1
,
9315 (intptr_t) s
, string
, nbytes
, multibyte_p
);
9316 message_buf_print
= 0;
9317 help_echo_showing_p
= 0;
9321 /* Helper function for set_message. Arguments have the same meaning
9322 as there, with A1 corresponding to S and A2 corresponding to STRING
9323 This function is called with the echo area buffer being
9327 set_message_1 (EMACS_INT a1
, Lisp_Object a2
, EMACS_INT nbytes
, EMACS_INT multibyte_p
)
9330 const char *s
= (const char *) i1
;
9331 const unsigned char *msg
= (const unsigned char *) s
;
9332 Lisp_Object string
= a2
;
9334 /* Change multibyteness of the echo buffer appropriately. */
9335 if (message_enable_multibyte
9336 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9337 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9339 BVAR (current_buffer
, truncate_lines
) = message_truncate_lines
? Qt
: Qnil
;
9340 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
9341 BVAR (current_buffer
, bidi_paragraph_direction
) = Qleft_to_right
;
9343 /* Insert new message at BEG. */
9344 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9346 if (STRINGP (string
))
9351 nbytes
= SBYTES (string
);
9352 nchars
= string_byte_to_char (string
, nbytes
);
9354 /* This function takes care of single/multibyte conversion. We
9355 just have to ensure that the echo area buffer has the right
9356 setting of enable_multibyte_characters. */
9357 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9362 nbytes
= strlen (s
);
9364 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9366 /* Convert from multi-byte to single-byte. */
9371 /* Convert a multibyte string to single-byte. */
9372 for (i
= 0; i
< nbytes
; i
+= n
)
9374 c
= string_char_and_length (msg
+ i
, &n
);
9375 work
[0] = (ASCII_CHAR_P (c
)
9377 : multibyte_char_to_unibyte (c
));
9378 insert_1_both (work
, 1, 1, 1, 0, 0);
9381 else if (!multibyte_p
9382 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9384 /* Convert from single-byte to multi-byte. */
9387 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9389 /* Convert a single-byte string to multibyte. */
9390 for (i
= 0; i
< nbytes
; i
++)
9393 MAKE_CHAR_MULTIBYTE (c
);
9394 n
= CHAR_STRING (c
, str
);
9395 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
9399 insert_1 (s
, nbytes
, 1, 0, 0);
9406 /* Clear messages. CURRENT_P non-zero means clear the current
9407 message. LAST_DISPLAYED_P non-zero means clear the message
9411 clear_message (int current_p
, int last_displayed_p
)
9415 echo_area_buffer
[0] = Qnil
;
9416 message_cleared_p
= 1;
9419 if (last_displayed_p
)
9420 echo_area_buffer
[1] = Qnil
;
9422 message_buf_print
= 0;
9425 /* Clear garbaged frames.
9427 This function is used where the old redisplay called
9428 redraw_garbaged_frames which in turn called redraw_frame which in
9429 turn called clear_frame. The call to clear_frame was a source of
9430 flickering. I believe a clear_frame is not necessary. It should
9431 suffice in the new redisplay to invalidate all current matrices,
9432 and ensure a complete redisplay of all windows. */
9435 clear_garbaged_frames (void)
9439 Lisp_Object tail
, frame
;
9440 int changed_count
= 0;
9442 FOR_EACH_FRAME (tail
, frame
)
9444 struct frame
*f
= XFRAME (frame
);
9446 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9450 Fredraw_frame (frame
);
9451 f
->force_flush_display_p
= 1;
9453 clear_current_matrices (f
);
9462 ++windows_or_buffers_changed
;
9467 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9468 is non-zero update selected_frame. Value is non-zero if the
9469 mini-windows height has been changed. */
9472 echo_area_display (int update_frame_p
)
9474 Lisp_Object mini_window
;
9477 int window_height_changed_p
= 0;
9478 struct frame
*sf
= SELECTED_FRAME ();
9480 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9481 w
= XWINDOW (mini_window
);
9482 f
= XFRAME (WINDOW_FRAME (w
));
9484 /* Don't display if frame is invisible or not yet initialized. */
9485 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9488 #ifdef HAVE_WINDOW_SYSTEM
9489 /* When Emacs starts, selected_frame may be the initial terminal
9490 frame. If we let this through, a message would be displayed on
9492 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9494 #endif /* HAVE_WINDOW_SYSTEM */
9496 /* Redraw garbaged frames. */
9498 clear_garbaged_frames ();
9500 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9502 echo_area_window
= mini_window
;
9503 window_height_changed_p
= display_echo_area (w
);
9504 w
->must_be_updated_p
= 1;
9506 /* Update the display, unless called from redisplay_internal.
9507 Also don't update the screen during redisplay itself. The
9508 update will happen at the end of redisplay, and an update
9509 here could cause confusion. */
9510 if (update_frame_p
&& !redisplaying_p
)
9514 /* If the display update has been interrupted by pending
9515 input, update mode lines in the frame. Due to the
9516 pending input, it might have been that redisplay hasn't
9517 been called, so that mode lines above the echo area are
9518 garbaged. This looks odd, so we prevent it here. */
9519 if (!display_completed
)
9520 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9522 if (window_height_changed_p
9523 /* Don't do this if Emacs is shutting down. Redisplay
9524 needs to run hooks. */
9525 && !NILP (Vrun_hooks
))
9527 /* Must update other windows. Likewise as in other
9528 cases, don't let this update be interrupted by
9530 int count
= SPECPDL_INDEX ();
9531 specbind (Qredisplay_dont_pause
, Qt
);
9532 windows_or_buffers_changed
= 1;
9533 redisplay_internal ();
9534 unbind_to (count
, Qnil
);
9536 else if (FRAME_WINDOW_P (f
) && n
== 0)
9538 /* Window configuration is the same as before.
9539 Can do with a display update of the echo area,
9540 unless we displayed some mode lines. */
9541 update_single_window (w
, 1);
9542 FRAME_RIF (f
)->flush_display (f
);
9545 update_frame (f
, 1, 1);
9547 /* If cursor is in the echo area, make sure that the next
9548 redisplay displays the minibuffer, so that the cursor will
9549 be replaced with what the minibuffer wants. */
9550 if (cursor_in_echo_area
)
9551 ++windows_or_buffers_changed
;
9554 else if (!EQ (mini_window
, selected_window
))
9555 windows_or_buffers_changed
++;
9557 /* Last displayed message is now the current message. */
9558 echo_area_buffer
[1] = echo_area_buffer
[0];
9559 /* Inform read_char that we're not echoing. */
9560 echo_message_buffer
= Qnil
;
9562 /* Prevent redisplay optimization in redisplay_internal by resetting
9563 this_line_start_pos. This is done because the mini-buffer now
9564 displays the message instead of its buffer text. */
9565 if (EQ (mini_window
, selected_window
))
9566 CHARPOS (this_line_start_pos
) = 0;
9568 return window_height_changed_p
;
9573 /***********************************************************************
9574 Mode Lines and Frame Titles
9575 ***********************************************************************/
9577 /* A buffer for constructing non-propertized mode-line strings and
9578 frame titles in it; allocated from the heap in init_xdisp and
9579 resized as needed in store_mode_line_noprop_char. */
9581 static char *mode_line_noprop_buf
;
9583 /* The buffer's end, and a current output position in it. */
9585 static char *mode_line_noprop_buf_end
;
9586 static char *mode_line_noprop_ptr
;
9588 #define MODE_LINE_NOPROP_LEN(start) \
9589 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9592 MODE_LINE_DISPLAY
= 0,
9598 /* Alist that caches the results of :propertize.
9599 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9600 static Lisp_Object mode_line_proptrans_alist
;
9602 /* List of strings making up the mode-line. */
9603 static Lisp_Object mode_line_string_list
;
9605 /* Base face property when building propertized mode line string. */
9606 static Lisp_Object mode_line_string_face
;
9607 static Lisp_Object mode_line_string_face_prop
;
9610 /* Unwind data for mode line strings */
9612 static Lisp_Object Vmode_line_unwind_vector
;
9615 format_mode_line_unwind_data (struct buffer
*obuf
,
9619 Lisp_Object vector
, tmp
;
9621 /* Reduce consing by keeping one vector in
9622 Vwith_echo_area_save_vector. */
9623 vector
= Vmode_line_unwind_vector
;
9624 Vmode_line_unwind_vector
= Qnil
;
9627 vector
= Fmake_vector (make_number (8), Qnil
);
9629 ASET (vector
, 0, make_number (mode_line_target
));
9630 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9631 ASET (vector
, 2, mode_line_string_list
);
9632 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9633 ASET (vector
, 4, mode_line_string_face
);
9634 ASET (vector
, 5, mode_line_string_face_prop
);
9637 XSETBUFFER (tmp
, obuf
);
9640 ASET (vector
, 6, tmp
);
9641 ASET (vector
, 7, owin
);
9647 unwind_format_mode_line (Lisp_Object vector
)
9649 mode_line_target
= XINT (AREF (vector
, 0));
9650 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9651 mode_line_string_list
= AREF (vector
, 2);
9652 if (! EQ (AREF (vector
, 3), Qt
))
9653 mode_line_proptrans_alist
= AREF (vector
, 3);
9654 mode_line_string_face
= AREF (vector
, 4);
9655 mode_line_string_face_prop
= AREF (vector
, 5);
9657 if (!NILP (AREF (vector
, 7)))
9658 /* Select window before buffer, since it may change the buffer. */
9659 Fselect_window (AREF (vector
, 7), Qt
);
9661 if (!NILP (AREF (vector
, 6)))
9663 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9664 ASET (vector
, 6, Qnil
);
9667 Vmode_line_unwind_vector
= vector
;
9672 /* Store a single character C for the frame title in mode_line_noprop_buf.
9673 Re-allocate mode_line_noprop_buf if necessary. */
9676 store_mode_line_noprop_char (char c
)
9678 /* If output position has reached the end of the allocated buffer,
9679 double the buffer's size. */
9680 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9682 int len
= MODE_LINE_NOPROP_LEN (0);
9683 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9684 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9685 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9686 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9689 *mode_line_noprop_ptr
++ = c
;
9693 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9694 mode_line_noprop_ptr. STRING is the string to store. Do not copy
9695 characters that yield more columns than PRECISION; PRECISION <= 0
9696 means copy the whole string. Pad with spaces until FIELD_WIDTH
9697 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9698 pad. Called from display_mode_element when it is used to build a
9702 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
9704 const unsigned char *str
= (const unsigned char *) string
;
9706 EMACS_INT dummy
, nbytes
;
9708 /* Copy at most PRECISION chars from STR. */
9709 nbytes
= strlen (string
);
9710 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9712 store_mode_line_noprop_char (*str
++);
9714 /* Fill up with spaces until FIELD_WIDTH reached. */
9715 while (field_width
> 0
9718 store_mode_line_noprop_char (' ');
9725 /***********************************************************************
9727 ***********************************************************************/
9729 #ifdef HAVE_WINDOW_SYSTEM
9731 /* Set the title of FRAME, if it has changed. The title format is
9732 Vicon_title_format if FRAME is iconified, otherwise it is
9733 frame_title_format. */
9736 x_consider_frame_title (Lisp_Object frame
)
9738 struct frame
*f
= XFRAME (frame
);
9740 if (FRAME_WINDOW_P (f
)
9741 || FRAME_MINIBUF_ONLY_P (f
)
9742 || f
->explicit_name
)
9744 /* Do we have more than one visible frame on this X display? */
9751 int count
= SPECPDL_INDEX ();
9753 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9755 Lisp_Object other_frame
= XCAR (tail
);
9756 struct frame
*tf
= XFRAME (other_frame
);
9759 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9760 && !FRAME_MINIBUF_ONLY_P (tf
)
9761 && !EQ (other_frame
, tip_frame
)
9762 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9766 /* Set global variable indicating that multiple frames exist. */
9767 multiple_frames
= CONSP (tail
);
9769 /* Switch to the buffer of selected window of the frame. Set up
9770 mode_line_target so that display_mode_element will output into
9771 mode_line_noprop_buf; then display the title. */
9772 record_unwind_protect (unwind_format_mode_line
,
9773 format_mode_line_unwind_data
9774 (current_buffer
, selected_window
, 0));
9776 Fselect_window (f
->selected_window
, Qt
);
9777 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9778 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9780 mode_line_target
= MODE_LINE_TITLE
;
9781 title_start
= MODE_LINE_NOPROP_LEN (0);
9782 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9783 NULL
, DEFAULT_FACE_ID
);
9784 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9785 len
= MODE_LINE_NOPROP_LEN (title_start
);
9786 title
= mode_line_noprop_buf
+ title_start
;
9787 unbind_to (count
, Qnil
);
9789 /* Set the title only if it's changed. This avoids consing in
9790 the common case where it hasn't. (If it turns out that we've
9791 already wasted too much time by walking through the list with
9792 display_mode_element, then we might need to optimize at a
9793 higher level than this.) */
9794 if (! STRINGP (f
->name
)
9795 || SBYTES (f
->name
) != len
9796 || memcmp (title
, SDATA (f
->name
), len
) != 0)
9797 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9801 #endif /* not HAVE_WINDOW_SYSTEM */
9806 /***********************************************************************
9808 ***********************************************************************/
9811 /* Prepare for redisplay by updating menu-bar item lists when
9812 appropriate. This can call eval. */
9815 prepare_menu_bars (void)
9818 struct gcpro gcpro1
, gcpro2
;
9820 Lisp_Object tooltip_frame
;
9822 #ifdef HAVE_WINDOW_SYSTEM
9823 tooltip_frame
= tip_frame
;
9825 tooltip_frame
= Qnil
;
9828 /* Update all frame titles based on their buffer names, etc. We do
9829 this before the menu bars so that the buffer-menu will show the
9830 up-to-date frame titles. */
9831 #ifdef HAVE_WINDOW_SYSTEM
9832 if (windows_or_buffers_changed
|| update_mode_lines
)
9834 Lisp_Object tail
, frame
;
9836 FOR_EACH_FRAME (tail
, frame
)
9839 if (!EQ (frame
, tooltip_frame
)
9840 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9841 x_consider_frame_title (frame
);
9844 #endif /* HAVE_WINDOW_SYSTEM */
9846 /* Update the menu bar item lists, if appropriate. This has to be
9847 done before any actual redisplay or generation of display lines. */
9848 all_windows
= (update_mode_lines
9849 || buffer_shared
> 1
9850 || windows_or_buffers_changed
);
9853 Lisp_Object tail
, frame
;
9854 int count
= SPECPDL_INDEX ();
9855 /* 1 means that update_menu_bar has run its hooks
9856 so any further calls to update_menu_bar shouldn't do so again. */
9857 int menu_bar_hooks_run
= 0;
9859 record_unwind_save_match_data ();
9861 FOR_EACH_FRAME (tail
, frame
)
9865 /* Ignore tooltip frame. */
9866 if (EQ (frame
, tooltip_frame
))
9869 /* If a window on this frame changed size, report that to
9870 the user and clear the size-change flag. */
9871 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9873 Lisp_Object functions
;
9875 /* Clear flag first in case we get an error below. */
9876 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9877 functions
= Vwindow_size_change_functions
;
9878 GCPRO2 (tail
, functions
);
9880 while (CONSP (functions
))
9882 if (!EQ (XCAR (functions
), Qt
))
9883 call1 (XCAR (functions
), frame
);
9884 functions
= XCDR (functions
);
9890 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9891 #ifdef HAVE_WINDOW_SYSTEM
9892 update_tool_bar (f
, 0);
9895 if (windows_or_buffers_changed
9897 ns_set_doc_edited (f
, Fbuffer_modified_p
9898 (XWINDOW (f
->selected_window
)->buffer
));
9903 unbind_to (count
, Qnil
);
9907 struct frame
*sf
= SELECTED_FRAME ();
9908 update_menu_bar (sf
, 1, 0);
9909 #ifdef HAVE_WINDOW_SYSTEM
9910 update_tool_bar (sf
, 1);
9916 /* Update the menu bar item list for frame F. This has to be done
9917 before we start to fill in any display lines, because it can call
9920 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9922 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9923 already ran the menu bar hooks for this redisplay, so there
9924 is no need to run them again. The return value is the
9925 updated value of this flag, to pass to the next call. */
9928 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
9931 register struct window
*w
;
9933 /* If called recursively during a menu update, do nothing. This can
9934 happen when, for instance, an activate-menubar-hook causes a
9936 if (inhibit_menubar_update
)
9939 window
= FRAME_SELECTED_WINDOW (f
);
9940 w
= XWINDOW (window
);
9942 if (FRAME_WINDOW_P (f
)
9944 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9945 || defined (HAVE_NS) || defined (USE_GTK)
9946 FRAME_EXTERNAL_MENU_BAR (f
)
9948 FRAME_MENU_BAR_LINES (f
) > 0
9950 : FRAME_MENU_BAR_LINES (f
) > 0)
9952 /* If the user has switched buffers or windows, we need to
9953 recompute to reflect the new bindings. But we'll
9954 recompute when update_mode_lines is set too; that means
9955 that people can use force-mode-line-update to request
9956 that the menu bar be recomputed. The adverse effect on
9957 the rest of the redisplay algorithm is about the same as
9958 windows_or_buffers_changed anyway. */
9959 if (windows_or_buffers_changed
9960 /* This used to test w->update_mode_line, but we believe
9961 there is no need to recompute the menu in that case. */
9962 || update_mode_lines
9963 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9964 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9965 != !NILP (w
->last_had_star
))
9966 || ((!NILP (Vtransient_mark_mode
)
9967 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
9968 != !NILP (w
->region_showing
)))
9970 struct buffer
*prev
= current_buffer
;
9971 int count
= SPECPDL_INDEX ();
9973 specbind (Qinhibit_menubar_update
, Qt
);
9975 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9976 if (save_match_data
)
9977 record_unwind_save_match_data ();
9978 if (NILP (Voverriding_local_map_menu_flag
))
9980 specbind (Qoverriding_terminal_local_map
, Qnil
);
9981 specbind (Qoverriding_local_map
, Qnil
);
9986 /* Run the Lucid hook. */
9987 safe_run_hooks (Qactivate_menubar_hook
);
9989 /* If it has changed current-menubar from previous value,
9990 really recompute the menu-bar from the value. */
9991 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9992 call0 (Qrecompute_lucid_menubar
);
9994 safe_run_hooks (Qmenu_bar_update_hook
);
9999 XSETFRAME (Vmenu_updating_frame
, f
);
10000 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
10002 /* Redisplay the menu bar in case we changed it. */
10003 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10004 || defined (HAVE_NS) || defined (USE_GTK)
10005 if (FRAME_WINDOW_P (f
))
10007 #if defined (HAVE_NS)
10008 /* All frames on Mac OS share the same menubar. So only
10009 the selected frame should be allowed to set it. */
10010 if (f
== SELECTED_FRAME ())
10012 set_frame_menubar (f
, 0, 0);
10015 /* On a terminal screen, the menu bar is an ordinary screen
10016 line, and this makes it get updated. */
10017 w
->update_mode_line
= Qt
;
10018 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10019 /* In the non-toolkit version, the menu bar is an ordinary screen
10020 line, and this makes it get updated. */
10021 w
->update_mode_line
= Qt
;
10022 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10024 unbind_to (count
, Qnil
);
10025 set_buffer_internal_1 (prev
);
10034 /***********************************************************************
10036 ***********************************************************************/
10038 #ifdef HAVE_WINDOW_SYSTEM
10041 Nominal cursor position -- where to draw output.
10042 HPOS and VPOS are window relative glyph matrix coordinates.
10043 X and Y are window relative pixel coordinates. */
10045 struct cursor_pos output_cursor
;
10049 Set the global variable output_cursor to CURSOR. All cursor
10050 positions are relative to updated_window. */
10053 set_output_cursor (struct cursor_pos
*cursor
)
10055 output_cursor
.hpos
= cursor
->hpos
;
10056 output_cursor
.vpos
= cursor
->vpos
;
10057 output_cursor
.x
= cursor
->x
;
10058 output_cursor
.y
= cursor
->y
;
10063 Set a nominal cursor position.
10065 HPOS and VPOS are column/row positions in a window glyph matrix. X
10066 and Y are window text area relative pixel positions.
10068 If this is done during an update, updated_window will contain the
10069 window that is being updated and the position is the future output
10070 cursor position for that window. If updated_window is null, use
10071 selected_window and display the cursor at the given position. */
10074 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
10078 /* If updated_window is not set, work on selected_window. */
10079 if (updated_window
)
10080 w
= updated_window
;
10082 w
= XWINDOW (selected_window
);
10084 /* Set the output cursor. */
10085 output_cursor
.hpos
= hpos
;
10086 output_cursor
.vpos
= vpos
;
10087 output_cursor
.x
= x
;
10088 output_cursor
.y
= y
;
10090 /* If not called as part of an update, really display the cursor.
10091 This will also set the cursor position of W. */
10092 if (updated_window
== NULL
)
10095 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10096 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10097 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10102 #endif /* HAVE_WINDOW_SYSTEM */
10105 /***********************************************************************
10107 ***********************************************************************/
10109 #ifdef HAVE_WINDOW_SYSTEM
10111 /* Where the mouse was last time we reported a mouse event. */
10113 FRAME_PTR last_mouse_frame
;
10115 /* Tool-bar item index of the item on which a mouse button was pressed
10118 int last_tool_bar_item
;
10122 update_tool_bar_unwind (Lisp_Object frame
)
10124 selected_frame
= frame
;
10128 /* Update the tool-bar item list for frame F. This has to be done
10129 before we start to fill in any display lines. Called from
10130 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10131 and restore it here. */
10134 update_tool_bar (struct frame
*f
, int save_match_data
)
10136 #if defined (USE_GTK) || defined (HAVE_NS)
10137 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10139 int do_update
= WINDOWP (f
->tool_bar_window
)
10140 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10145 Lisp_Object window
;
10148 window
= FRAME_SELECTED_WINDOW (f
);
10149 w
= XWINDOW (window
);
10151 /* If the user has switched buffers or windows, we need to
10152 recompute to reflect the new bindings. But we'll
10153 recompute when update_mode_lines is set too; that means
10154 that people can use force-mode-line-update to request
10155 that the menu bar be recomputed. The adverse effect on
10156 the rest of the redisplay algorithm is about the same as
10157 windows_or_buffers_changed anyway. */
10158 if (windows_or_buffers_changed
10159 || !NILP (w
->update_mode_line
)
10160 || update_mode_lines
10161 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10162 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10163 != !NILP (w
->last_had_star
))
10164 || ((!NILP (Vtransient_mark_mode
)
10165 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
10166 != !NILP (w
->region_showing
)))
10168 struct buffer
*prev
= current_buffer
;
10169 int count
= SPECPDL_INDEX ();
10170 Lisp_Object frame
, new_tool_bar
;
10171 int new_n_tool_bar
;
10172 struct gcpro gcpro1
;
10174 /* Set current_buffer to the buffer of the selected
10175 window of the frame, so that we get the right local
10177 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10179 /* Save match data, if we must. */
10180 if (save_match_data
)
10181 record_unwind_save_match_data ();
10183 /* Make sure that we don't accidentally use bogus keymaps. */
10184 if (NILP (Voverriding_local_map_menu_flag
))
10186 specbind (Qoverriding_terminal_local_map
, Qnil
);
10187 specbind (Qoverriding_local_map
, Qnil
);
10190 GCPRO1 (new_tool_bar
);
10192 /* We must temporarily set the selected frame to this frame
10193 before calling tool_bar_items, because the calculation of
10194 the tool-bar keymap uses the selected frame (see
10195 `tool-bar-make-keymap' in tool-bar.el). */
10196 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10197 XSETFRAME (frame
, f
);
10198 selected_frame
= frame
;
10200 /* Build desired tool-bar items from keymaps. */
10201 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10204 /* Redisplay the tool-bar if we changed it. */
10205 if (new_n_tool_bar
!= f
->n_tool_bar_items
10206 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10208 /* Redisplay that happens asynchronously due to an expose event
10209 may access f->tool_bar_items. Make sure we update both
10210 variables within BLOCK_INPUT so no such event interrupts. */
10212 f
->tool_bar_items
= new_tool_bar
;
10213 f
->n_tool_bar_items
= new_n_tool_bar
;
10214 w
->update_mode_line
= Qt
;
10220 unbind_to (count
, Qnil
);
10221 set_buffer_internal_1 (prev
);
10227 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10228 F's desired tool-bar contents. F->tool_bar_items must have
10229 been set up previously by calling prepare_menu_bars. */
10232 build_desired_tool_bar_string (struct frame
*f
)
10234 int i
, size
, size_needed
;
10235 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10236 Lisp_Object image
, plist
, props
;
10238 image
= plist
= props
= Qnil
;
10239 GCPRO3 (image
, plist
, props
);
10241 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10242 Otherwise, make a new string. */
10244 /* The size of the string we might be able to reuse. */
10245 size
= (STRINGP (f
->desired_tool_bar_string
)
10246 ? SCHARS (f
->desired_tool_bar_string
)
10249 /* We need one space in the string for each image. */
10250 size_needed
= f
->n_tool_bar_items
;
10252 /* Reuse f->desired_tool_bar_string, if possible. */
10253 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10254 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10255 make_number (' '));
10258 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10259 Fremove_text_properties (make_number (0), make_number (size
),
10260 props
, f
->desired_tool_bar_string
);
10263 /* Put a `display' property on the string for the images to display,
10264 put a `menu_item' property on tool-bar items with a value that
10265 is the index of the item in F's tool-bar item vector. */
10266 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10268 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10270 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10271 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10272 int hmargin
, vmargin
, relief
, idx
, end
;
10274 /* If image is a vector, choose the image according to the
10276 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10277 if (VECTORP (image
))
10281 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10282 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10285 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10286 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10288 xassert (ASIZE (image
) >= idx
);
10289 image
= AREF (image
, idx
);
10294 /* Ignore invalid image specifications. */
10295 if (!valid_image_p (image
))
10298 /* Display the tool-bar button pressed, or depressed. */
10299 plist
= Fcopy_sequence (XCDR (image
));
10301 /* Compute margin and relief to draw. */
10302 relief
= (tool_bar_button_relief
>= 0
10303 ? tool_bar_button_relief
10304 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10305 hmargin
= vmargin
= relief
;
10307 if (INTEGERP (Vtool_bar_button_margin
)
10308 && XINT (Vtool_bar_button_margin
) > 0)
10310 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10311 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10313 else if (CONSP (Vtool_bar_button_margin
))
10315 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10316 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10317 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10319 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10320 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10321 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10324 if (auto_raise_tool_bar_buttons_p
)
10326 /* Add a `:relief' property to the image spec if the item is
10330 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10337 /* If image is selected, display it pressed, i.e. with a
10338 negative relief. If it's not selected, display it with a
10340 plist
= Fplist_put (plist
, QCrelief
,
10342 ? make_number (-relief
)
10343 : make_number (relief
)));
10348 /* Put a margin around the image. */
10349 if (hmargin
|| vmargin
)
10351 if (hmargin
== vmargin
)
10352 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10354 plist
= Fplist_put (plist
, QCmargin
,
10355 Fcons (make_number (hmargin
),
10356 make_number (vmargin
)));
10359 /* If button is not enabled, and we don't have special images
10360 for the disabled state, make the image appear disabled by
10361 applying an appropriate algorithm to it. */
10362 if (!enabled_p
&& idx
< 0)
10363 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10365 /* Put a `display' text property on the string for the image to
10366 display. Put a `menu-item' property on the string that gives
10367 the start of this item's properties in the tool-bar items
10369 image
= Fcons (Qimage
, plist
);
10370 props
= list4 (Qdisplay
, image
,
10371 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10373 /* Let the last image hide all remaining spaces in the tool bar
10374 string. The string can be longer than needed when we reuse a
10375 previous string. */
10376 if (i
+ 1 == f
->n_tool_bar_items
)
10377 end
= SCHARS (f
->desired_tool_bar_string
);
10380 Fadd_text_properties (make_number (i
), make_number (end
),
10381 props
, f
->desired_tool_bar_string
);
10389 /* Display one line of the tool-bar of frame IT->f.
10391 HEIGHT specifies the desired height of the tool-bar line.
10392 If the actual height of the glyph row is less than HEIGHT, the
10393 row's height is increased to HEIGHT, and the icons are centered
10394 vertically in the new height.
10396 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10397 count a final empty row in case the tool-bar width exactly matches
10402 display_tool_bar_line (struct it
*it
, int height
)
10404 struct glyph_row
*row
= it
->glyph_row
;
10405 int max_x
= it
->last_visible_x
;
10406 struct glyph
*last
;
10408 prepare_desired_row (row
);
10409 row
->y
= it
->current_y
;
10411 /* Note that this isn't made use of if the face hasn't a box,
10412 so there's no need to check the face here. */
10413 it
->start_of_box_run_p
= 1;
10415 while (it
->current_x
< max_x
)
10417 int x
, n_glyphs_before
, i
, nglyphs
;
10418 struct it it_before
;
10420 /* Get the next display element. */
10421 if (!get_next_display_element (it
))
10423 /* Don't count empty row if we are counting needed tool-bar lines. */
10424 if (height
< 0 && !it
->hpos
)
10429 /* Produce glyphs. */
10430 n_glyphs_before
= row
->used
[TEXT_AREA
];
10433 PRODUCE_GLYPHS (it
);
10435 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10437 x
= it_before
.current_x
;
10438 while (i
< nglyphs
)
10440 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10442 if (x
+ glyph
->pixel_width
> max_x
)
10444 /* Glyph doesn't fit on line. Backtrack. */
10445 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10447 /* If this is the only glyph on this line, it will never fit on the
10448 tool-bar, so skip it. But ensure there is at least one glyph,
10449 so we don't accidentally disable the tool-bar. */
10450 if (n_glyphs_before
== 0
10451 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10457 x
+= glyph
->pixel_width
;
10461 /* Stop at line ends. */
10462 if (ITERATOR_AT_END_OF_LINE_P (it
))
10465 set_iterator_to_next (it
, 1);
10470 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10472 /* Use default face for the border below the tool bar.
10474 FIXME: When auto-resize-tool-bars is grow-only, there is
10475 no additional border below the possibly empty tool-bar lines.
10476 So to make the extra empty lines look "normal", we have to
10477 use the tool-bar face for the border too. */
10478 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10479 it
->face_id
= DEFAULT_FACE_ID
;
10481 extend_face_to_end_of_line (it
);
10482 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10483 last
->right_box_line_p
= 1;
10484 if (last
== row
->glyphs
[TEXT_AREA
])
10485 last
->left_box_line_p
= 1;
10487 /* Make line the desired height and center it vertically. */
10488 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10490 /* Don't add more than one line height. */
10491 height
%= FRAME_LINE_HEIGHT (it
->f
);
10492 it
->max_ascent
+= height
/ 2;
10493 it
->max_descent
+= (height
+ 1) / 2;
10496 compute_line_metrics (it
);
10498 /* If line is empty, make it occupy the rest of the tool-bar. */
10499 if (!row
->displays_text_p
)
10501 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10502 row
->visible_height
= row
->height
;
10503 row
->ascent
= row
->phys_ascent
= 0;
10504 row
->extra_line_spacing
= 0;
10507 row
->full_width_p
= 1;
10508 row
->continued_p
= 0;
10509 row
->truncated_on_left_p
= 0;
10510 row
->truncated_on_right_p
= 0;
10512 it
->current_x
= it
->hpos
= 0;
10513 it
->current_y
+= row
->height
;
10519 /* Max tool-bar height. */
10521 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10522 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10524 /* Value is the number of screen lines needed to make all tool-bar
10525 items of frame F visible. The number of actual rows needed is
10526 returned in *N_ROWS if non-NULL. */
10529 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
10531 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10533 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10534 the desired matrix, so use (unused) mode-line row as temporary row to
10535 avoid destroying the first tool-bar row. */
10536 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10538 /* Initialize an iterator for iteration over
10539 F->desired_tool_bar_string in the tool-bar window of frame F. */
10540 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10541 it
.first_visible_x
= 0;
10542 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10543 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10545 while (!ITERATOR_AT_END_P (&it
))
10547 clear_glyph_row (temp_row
);
10548 it
.glyph_row
= temp_row
;
10549 display_tool_bar_line (&it
, -1);
10551 clear_glyph_row (temp_row
);
10553 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10555 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10557 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10561 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10563 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10564 (Lisp_Object frame
)
10571 frame
= selected_frame
;
10573 CHECK_FRAME (frame
);
10574 f
= XFRAME (frame
);
10576 if (WINDOWP (f
->tool_bar_window
)
10577 || (w
= XWINDOW (f
->tool_bar_window
),
10578 WINDOW_TOTAL_LINES (w
) > 0))
10580 update_tool_bar (f
, 1);
10581 if (f
->n_tool_bar_items
)
10583 build_desired_tool_bar_string (f
);
10584 nlines
= tool_bar_lines_needed (f
, NULL
);
10588 return make_number (nlines
);
10592 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10593 height should be changed. */
10596 redisplay_tool_bar (struct frame
*f
)
10600 struct glyph_row
*row
;
10602 #if defined (USE_GTK) || defined (HAVE_NS)
10603 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10604 update_frame_tool_bar (f
);
10608 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10609 do anything. This means you must start with tool-bar-lines
10610 non-zero to get the auto-sizing effect. Or in other words, you
10611 can turn off tool-bars by specifying tool-bar-lines zero. */
10612 if (!WINDOWP (f
->tool_bar_window
)
10613 || (w
= XWINDOW (f
->tool_bar_window
),
10614 WINDOW_TOTAL_LINES (w
) == 0))
10617 /* Set up an iterator for the tool-bar window. */
10618 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10619 it
.first_visible_x
= 0;
10620 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10621 row
= it
.glyph_row
;
10623 /* Build a string that represents the contents of the tool-bar. */
10624 build_desired_tool_bar_string (f
);
10625 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10627 if (f
->n_tool_bar_rows
== 0)
10631 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10632 nlines
!= WINDOW_TOTAL_LINES (w
)))
10635 int old_height
= WINDOW_TOTAL_LINES (w
);
10637 XSETFRAME (frame
, f
);
10638 Fmodify_frame_parameters (frame
,
10639 Fcons (Fcons (Qtool_bar_lines
,
10640 make_number (nlines
)),
10642 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10644 clear_glyph_matrix (w
->desired_matrix
);
10645 fonts_changed_p
= 1;
10651 /* Display as many lines as needed to display all tool-bar items. */
10653 if (f
->n_tool_bar_rows
> 0)
10655 int border
, rows
, height
, extra
;
10657 if (INTEGERP (Vtool_bar_border
))
10658 border
= XINT (Vtool_bar_border
);
10659 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10660 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10661 else if (EQ (Vtool_bar_border
, Qborder_width
))
10662 border
= f
->border_width
;
10668 rows
= f
->n_tool_bar_rows
;
10669 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10670 extra
= it
.last_visible_y
- border
- height
* rows
;
10672 while (it
.current_y
< it
.last_visible_y
)
10675 if (extra
> 0 && rows
-- > 0)
10677 h
= (extra
+ rows
- 1) / rows
;
10680 display_tool_bar_line (&it
, height
+ h
);
10685 while (it
.current_y
< it
.last_visible_y
)
10686 display_tool_bar_line (&it
, 0);
10689 /* It doesn't make much sense to try scrolling in the tool-bar
10690 window, so don't do it. */
10691 w
->desired_matrix
->no_scrolling_p
= 1;
10692 w
->must_be_updated_p
= 1;
10694 if (!NILP (Vauto_resize_tool_bars
))
10696 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10697 int change_height_p
= 0;
10699 /* If we couldn't display everything, change the tool-bar's
10700 height if there is room for more. */
10701 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10702 && it
.current_y
< max_tool_bar_height
)
10703 change_height_p
= 1;
10705 row
= it
.glyph_row
- 1;
10707 /* If there are blank lines at the end, except for a partially
10708 visible blank line at the end that is smaller than
10709 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10710 if (!row
->displays_text_p
10711 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10712 change_height_p
= 1;
10714 /* If row displays tool-bar items, but is partially visible,
10715 change the tool-bar's height. */
10716 if (row
->displays_text_p
10717 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10718 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10719 change_height_p
= 1;
10721 /* Resize windows as needed by changing the `tool-bar-lines'
10722 frame parameter. */
10723 if (change_height_p
)
10726 int old_height
= WINDOW_TOTAL_LINES (w
);
10728 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10730 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10731 && !f
->minimize_tool_bar_window_p
)
10732 ? (nlines
> old_height
)
10733 : (nlines
!= old_height
));
10734 f
->minimize_tool_bar_window_p
= 0;
10736 if (change_height_p
)
10738 XSETFRAME (frame
, f
);
10739 Fmodify_frame_parameters (frame
,
10740 Fcons (Fcons (Qtool_bar_lines
,
10741 make_number (nlines
)),
10743 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10745 clear_glyph_matrix (w
->desired_matrix
);
10746 f
->n_tool_bar_rows
= nrows
;
10747 fonts_changed_p
= 1;
10754 f
->minimize_tool_bar_window_p
= 0;
10759 /* Get information about the tool-bar item which is displayed in GLYPH
10760 on frame F. Return in *PROP_IDX the index where tool-bar item
10761 properties start in F->tool_bar_items. Value is zero if
10762 GLYPH doesn't display a tool-bar item. */
10765 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
10771 /* This function can be called asynchronously, which means we must
10772 exclude any possibility that Fget_text_property signals an
10774 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10775 charpos
= max (0, charpos
);
10777 /* Get the text property `menu-item' at pos. The value of that
10778 property is the start index of this item's properties in
10779 F->tool_bar_items. */
10780 prop
= Fget_text_property (make_number (charpos
),
10781 Qmenu_item
, f
->current_tool_bar_string
);
10782 if (INTEGERP (prop
))
10784 *prop_idx
= XINT (prop
);
10794 /* Get information about the tool-bar item at position X/Y on frame F.
10795 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10796 the current matrix of the tool-bar window of F, or NULL if not
10797 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10798 item in F->tool_bar_items. Value is
10800 -1 if X/Y is not on a tool-bar item
10801 0 if X/Y is on the same item that was highlighted before.
10805 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
10806 int *hpos
, int *vpos
, int *prop_idx
)
10808 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10809 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10812 /* Find the glyph under X/Y. */
10813 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10814 if (*glyph
== NULL
)
10817 /* Get the start of this tool-bar item's properties in
10818 f->tool_bar_items. */
10819 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10822 /* Is mouse on the highlighted item? */
10823 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
10824 && *vpos
>= hlinfo
->mouse_face_beg_row
10825 && *vpos
<= hlinfo
->mouse_face_end_row
10826 && (*vpos
> hlinfo
->mouse_face_beg_row
10827 || *hpos
>= hlinfo
->mouse_face_beg_col
)
10828 && (*vpos
< hlinfo
->mouse_face_end_row
10829 || *hpos
< hlinfo
->mouse_face_end_col
10830 || hlinfo
->mouse_face_past_end
))
10838 Handle mouse button event on the tool-bar of frame F, at
10839 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10840 0 for button release. MODIFIERS is event modifiers for button
10844 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
10845 unsigned int modifiers
)
10847 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10848 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10849 int hpos
, vpos
, prop_idx
;
10850 struct glyph
*glyph
;
10851 Lisp_Object enabled_p
;
10853 /* If not on the highlighted tool-bar item, return. */
10854 frame_to_window_pixel_xy (w
, &x
, &y
);
10855 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10858 /* If item is disabled, do nothing. */
10859 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10860 if (NILP (enabled_p
))
10865 /* Show item in pressed state. */
10866 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
10867 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10868 last_tool_bar_item
= prop_idx
;
10872 Lisp_Object key
, frame
;
10873 struct input_event event
;
10874 EVENT_INIT (event
);
10876 /* Show item in released state. */
10877 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
10878 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10880 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10882 XSETFRAME (frame
, f
);
10883 event
.kind
= TOOL_BAR_EVENT
;
10884 event
.frame_or_window
= frame
;
10886 kbd_buffer_store_event (&event
);
10888 event
.kind
= TOOL_BAR_EVENT
;
10889 event
.frame_or_window
= frame
;
10891 event
.modifiers
= modifiers
;
10892 kbd_buffer_store_event (&event
);
10893 last_tool_bar_item
= -1;
10898 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10899 tool-bar window-relative coordinates X/Y. Called from
10900 note_mouse_highlight. */
10903 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
10905 Lisp_Object window
= f
->tool_bar_window
;
10906 struct window
*w
= XWINDOW (window
);
10907 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10908 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
10910 struct glyph
*glyph
;
10911 struct glyph_row
*row
;
10913 Lisp_Object enabled_p
;
10915 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10916 int mouse_down_p
, rc
;
10918 /* Function note_mouse_highlight is called with negative X/Y
10919 values when mouse moves outside of the frame. */
10920 if (x
<= 0 || y
<= 0)
10922 clear_mouse_face (hlinfo
);
10926 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10929 /* Not on tool-bar item. */
10930 clear_mouse_face (hlinfo
);
10934 /* On same tool-bar item as before. */
10935 goto set_help_echo
;
10937 clear_mouse_face (hlinfo
);
10939 /* Mouse is down, but on different tool-bar item? */
10940 mouse_down_p
= (dpyinfo
->grabbed
10941 && f
== last_mouse_frame
10942 && FRAME_LIVE_P (f
));
10944 && last_tool_bar_item
!= prop_idx
)
10947 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10948 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10950 /* If tool-bar item is not enabled, don't highlight it. */
10951 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10952 if (!NILP (enabled_p
))
10954 /* Compute the x-position of the glyph. In front and past the
10955 image is a space. We include this in the highlighted area. */
10956 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10957 for (i
= x
= 0; i
< hpos
; ++i
)
10958 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10960 /* Record this as the current active region. */
10961 hlinfo
->mouse_face_beg_col
= hpos
;
10962 hlinfo
->mouse_face_beg_row
= vpos
;
10963 hlinfo
->mouse_face_beg_x
= x
;
10964 hlinfo
->mouse_face_beg_y
= row
->y
;
10965 hlinfo
->mouse_face_past_end
= 0;
10967 hlinfo
->mouse_face_end_col
= hpos
+ 1;
10968 hlinfo
->mouse_face_end_row
= vpos
;
10969 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10970 hlinfo
->mouse_face_end_y
= row
->y
;
10971 hlinfo
->mouse_face_window
= window
;
10972 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10974 /* Display it as active. */
10975 show_mouse_face (hlinfo
, draw
);
10976 hlinfo
->mouse_face_image_state
= draw
;
10981 /* Set help_echo_string to a help string to display for this tool-bar item.
10982 XTread_socket does the rest. */
10983 help_echo_object
= help_echo_window
= Qnil
;
10984 help_echo_pos
= -1;
10985 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10986 if (NILP (help_echo_string
))
10987 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10990 #endif /* HAVE_WINDOW_SYSTEM */
10994 /************************************************************************
10995 Horizontal scrolling
10996 ************************************************************************/
10998 static int hscroll_window_tree (Lisp_Object
);
10999 static int hscroll_windows (Lisp_Object
);
11001 /* For all leaf windows in the window tree rooted at WINDOW, set their
11002 hscroll value so that PT is (i) visible in the window, and (ii) so
11003 that it is not within a certain margin at the window's left and
11004 right border. Value is non-zero if any window's hscroll has been
11008 hscroll_window_tree (Lisp_Object window
)
11010 int hscrolled_p
= 0;
11011 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
11012 int hscroll_step_abs
= 0;
11013 double hscroll_step_rel
= 0;
11015 if (hscroll_relative_p
)
11017 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
11018 if (hscroll_step_rel
< 0)
11020 hscroll_relative_p
= 0;
11021 hscroll_step_abs
= 0;
11024 else if (INTEGERP (Vhscroll_step
))
11026 hscroll_step_abs
= XINT (Vhscroll_step
);
11027 if (hscroll_step_abs
< 0)
11028 hscroll_step_abs
= 0;
11031 hscroll_step_abs
= 0;
11033 while (WINDOWP (window
))
11035 struct window
*w
= XWINDOW (window
);
11037 if (WINDOWP (w
->hchild
))
11038 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11039 else if (WINDOWP (w
->vchild
))
11040 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11041 else if (w
->cursor
.vpos
>= 0)
11044 int text_area_width
;
11045 struct glyph_row
*current_cursor_row
11046 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11047 struct glyph_row
*desired_cursor_row
11048 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11049 struct glyph_row
*cursor_row
11050 = (desired_cursor_row
->enabled_p
11051 ? desired_cursor_row
11052 : current_cursor_row
);
11054 text_area_width
= window_box_width (w
, TEXT_AREA
);
11056 /* Scroll when cursor is inside this scroll margin. */
11057 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11059 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11060 && ((XFASTINT (w
->hscroll
)
11061 && w
->cursor
.x
<= h_margin
)
11062 || (cursor_row
->enabled_p
11063 && cursor_row
->truncated_on_right_p
11064 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11068 struct buffer
*saved_current_buffer
;
11072 /* Find point in a display of infinite width. */
11073 saved_current_buffer
= current_buffer
;
11074 current_buffer
= XBUFFER (w
->buffer
);
11076 if (w
== XWINDOW (selected_window
))
11080 pt
= marker_position (w
->pointm
);
11081 pt
= max (BEGV
, pt
);
11085 /* Move iterator to pt starting at cursor_row->start in
11086 a line with infinite width. */
11087 init_to_row_start (&it
, w
, cursor_row
);
11088 it
.last_visible_x
= INFINITY
;
11089 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11090 current_buffer
= saved_current_buffer
;
11092 /* Position cursor in window. */
11093 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11094 hscroll
= max (0, (it
.current_x
11095 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11096 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11097 : (text_area_width
/ 2))))
11098 / FRAME_COLUMN_WIDTH (it
.f
);
11099 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11101 if (hscroll_relative_p
)
11102 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11105 wanted_x
= text_area_width
11106 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11109 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11113 if (hscroll_relative_p
)
11114 wanted_x
= text_area_width
* hscroll_step_rel
11117 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11120 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11122 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11124 /* Don't call Fset_window_hscroll if value hasn't
11125 changed because it will prevent redisplay
11127 if (XFASTINT (w
->hscroll
) != hscroll
)
11129 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11130 w
->hscroll
= make_number (hscroll
);
11139 /* Value is non-zero if hscroll of any leaf window has been changed. */
11140 return hscrolled_p
;
11144 /* Set hscroll so that cursor is visible and not inside horizontal
11145 scroll margins for all windows in the tree rooted at WINDOW. See
11146 also hscroll_window_tree above. Value is non-zero if any window's
11147 hscroll has been changed. If it has, desired matrices on the frame
11148 of WINDOW are cleared. */
11151 hscroll_windows (Lisp_Object window
)
11153 int hscrolled_p
= hscroll_window_tree (window
);
11155 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11156 return hscrolled_p
;
11161 /************************************************************************
11163 ************************************************************************/
11165 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11166 to a non-zero value. This is sometimes handy to have in a debugger
11171 /* First and last unchanged row for try_window_id. */
11173 int debug_first_unchanged_at_end_vpos
;
11174 int debug_last_unchanged_at_beg_vpos
;
11176 /* Delta vpos and y. */
11178 int debug_dvpos
, debug_dy
;
11180 /* Delta in characters and bytes for try_window_id. */
11182 EMACS_INT debug_delta
, debug_delta_bytes
;
11184 /* Values of window_end_pos and window_end_vpos at the end of
11187 EMACS_INT debug_end_vpos
;
11189 /* Append a string to W->desired_matrix->method. FMT is a printf
11190 format string. A1...A9 are a supplement for a variable-length
11191 argument list. If trace_redisplay_p is non-zero also printf the
11192 resulting string to stderr. */
11195 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11198 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11201 char *method
= w
->desired_matrix
->method
;
11202 int len
= strlen (method
);
11203 int size
= sizeof w
->desired_matrix
->method
;
11204 int remaining
= size
- len
- 1;
11206 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11207 if (len
&& remaining
)
11210 --remaining
, ++len
;
11213 strncpy (method
+ len
, buffer
, remaining
);
11215 if (trace_redisplay_p
)
11216 fprintf (stderr
, "%p (%s): %s\n",
11218 ((BUFFERP (w
->buffer
)
11219 && STRINGP (XBUFFER (w
->buffer
)->name
))
11220 ? SSDATA (XBUFFER (w
->buffer
)->name
)
11225 #endif /* GLYPH_DEBUG */
11228 /* Value is non-zero if all changes in window W, which displays
11229 current_buffer, are in the text between START and END. START is a
11230 buffer position, END is given as a distance from Z. Used in
11231 redisplay_internal for display optimization. */
11234 text_outside_line_unchanged_p (struct window
*w
,
11235 EMACS_INT start
, EMACS_INT end
)
11237 int unchanged_p
= 1;
11239 /* If text or overlays have changed, see where. */
11240 if (XFASTINT (w
->last_modified
) < MODIFF
11241 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11243 /* Gap in the line? */
11244 if (GPT
< start
|| Z
- GPT
< end
)
11247 /* Changes start in front of the line, or end after it? */
11249 && (BEG_UNCHANGED
< start
- 1
11250 || END_UNCHANGED
< end
))
11253 /* If selective display, can't optimize if changes start at the
11254 beginning of the line. */
11256 && INTEGERP (BVAR (current_buffer
, selective_display
))
11257 && XINT (BVAR (current_buffer
, selective_display
)) > 0
11258 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11261 /* If there are overlays at the start or end of the line, these
11262 may have overlay strings with newlines in them. A change at
11263 START, for instance, may actually concern the display of such
11264 overlay strings as well, and they are displayed on different
11265 lines. So, quickly rule out this case. (For the future, it
11266 might be desirable to implement something more telling than
11267 just BEG/END_UNCHANGED.) */
11270 if (BEG
+ BEG_UNCHANGED
== start
11271 && overlay_touches_p (start
))
11273 if (END_UNCHANGED
== end
11274 && overlay_touches_p (Z
- end
))
11278 /* Under bidi reordering, adding or deleting a character in the
11279 beginning of a paragraph, before the first strong directional
11280 character, can change the base direction of the paragraph (unless
11281 the buffer specifies a fixed paragraph direction), which will
11282 require to redisplay the whole paragraph. It might be worthwhile
11283 to find the paragraph limits and widen the range of redisplayed
11284 lines to that, but for now just give up this optimization. */
11285 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
11286 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
11290 return unchanged_p
;
11294 /* Do a frame update, taking possible shortcuts into account. This is
11295 the main external entry point for redisplay.
11297 If the last redisplay displayed an echo area message and that message
11298 is no longer requested, we clear the echo area or bring back the
11299 mini-buffer if that is in use. */
11304 redisplay_internal ();
11309 overlay_arrow_string_or_property (Lisp_Object var
)
11313 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11316 return Voverlay_arrow_string
;
11319 /* Return 1 if there are any overlay-arrows in current_buffer. */
11321 overlay_arrow_in_current_buffer_p (void)
11325 for (vlist
= Voverlay_arrow_variable_list
;
11327 vlist
= XCDR (vlist
))
11329 Lisp_Object var
= XCAR (vlist
);
11332 if (!SYMBOLP (var
))
11334 val
= find_symbol_value (var
);
11336 && current_buffer
== XMARKER (val
)->buffer
)
11343 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11347 overlay_arrows_changed_p (void)
11351 for (vlist
= Voverlay_arrow_variable_list
;
11353 vlist
= XCDR (vlist
))
11355 Lisp_Object var
= XCAR (vlist
);
11356 Lisp_Object val
, pstr
;
11358 if (!SYMBOLP (var
))
11360 val
= find_symbol_value (var
);
11361 if (!MARKERP (val
))
11363 if (! EQ (COERCE_MARKER (val
),
11364 Fget (var
, Qlast_arrow_position
))
11365 || ! (pstr
= overlay_arrow_string_or_property (var
),
11366 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11372 /* Mark overlay arrows to be updated on next redisplay. */
11375 update_overlay_arrows (int up_to_date
)
11379 for (vlist
= Voverlay_arrow_variable_list
;
11381 vlist
= XCDR (vlist
))
11383 Lisp_Object var
= XCAR (vlist
);
11385 if (!SYMBOLP (var
))
11388 if (up_to_date
> 0)
11390 Lisp_Object val
= find_symbol_value (var
);
11391 Fput (var
, Qlast_arrow_position
,
11392 COERCE_MARKER (val
));
11393 Fput (var
, Qlast_arrow_string
,
11394 overlay_arrow_string_or_property (var
));
11396 else if (up_to_date
< 0
11397 || !NILP (Fget (var
, Qlast_arrow_position
)))
11399 Fput (var
, Qlast_arrow_position
, Qt
);
11400 Fput (var
, Qlast_arrow_string
, Qt
);
11406 /* Return overlay arrow string to display at row.
11407 Return integer (bitmap number) for arrow bitmap in left fringe.
11408 Return nil if no overlay arrow. */
11411 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
11415 for (vlist
= Voverlay_arrow_variable_list
;
11417 vlist
= XCDR (vlist
))
11419 Lisp_Object var
= XCAR (vlist
);
11422 if (!SYMBOLP (var
))
11425 val
= find_symbol_value (var
);
11428 && current_buffer
== XMARKER (val
)->buffer
11429 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11431 if (FRAME_WINDOW_P (it
->f
)
11432 /* FIXME: if ROW->reversed_p is set, this should test
11433 the right fringe, not the left one. */
11434 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11436 #ifdef HAVE_WINDOW_SYSTEM
11437 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11440 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11441 return make_number (fringe_bitmap
);
11444 return make_number (-1); /* Use default arrow bitmap */
11446 return overlay_arrow_string_or_property (var
);
11453 /* Return 1 if point moved out of or into a composition. Otherwise
11454 return 0. PREV_BUF and PREV_PT are the last point buffer and
11455 position. BUF and PT are the current point buffer and position. */
11458 check_point_in_composition (struct buffer
*prev_buf
, EMACS_INT prev_pt
,
11459 struct buffer
*buf
, EMACS_INT pt
)
11461 EMACS_INT start
, end
;
11463 Lisp_Object buffer
;
11465 XSETBUFFER (buffer
, buf
);
11466 /* Check a composition at the last point if point moved within the
11468 if (prev_buf
== buf
)
11471 /* Point didn't move. */
11474 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11475 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11476 && COMPOSITION_VALID_P (start
, end
, prop
)
11477 && start
< prev_pt
&& end
> prev_pt
)
11478 /* The last point was within the composition. Return 1 iff
11479 point moved out of the composition. */
11480 return (pt
<= start
|| pt
>= end
);
11483 /* Check a composition at the current point. */
11484 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11485 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11486 && COMPOSITION_VALID_P (start
, end
, prop
)
11487 && start
< pt
&& end
> pt
);
11491 /* Reconsider the setting of B->clip_changed which is displayed
11495 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
11497 if (b
->clip_changed
11498 && !NILP (w
->window_end_valid
)
11499 && w
->current_matrix
->buffer
== b
11500 && w
->current_matrix
->zv
== BUF_ZV (b
)
11501 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11502 b
->clip_changed
= 0;
11504 /* If display wasn't paused, and W is not a tool bar window, see if
11505 point has been moved into or out of a composition. In that case,
11506 we set b->clip_changed to 1 to force updating the screen. If
11507 b->clip_changed has already been set to 1, we can skip this
11509 if (!b
->clip_changed
11510 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11514 if (w
== XWINDOW (selected_window
))
11517 pt
= marker_position (w
->pointm
);
11519 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11520 || pt
!= XINT (w
->last_point
))
11521 && check_point_in_composition (w
->current_matrix
->buffer
,
11522 XINT (w
->last_point
),
11523 XBUFFER (w
->buffer
), pt
))
11524 b
->clip_changed
= 1;
11529 /* Select FRAME to forward the values of frame-local variables into C
11530 variables so that the redisplay routines can access those values
11534 select_frame_for_redisplay (Lisp_Object frame
)
11536 Lisp_Object tail
, tem
;
11537 Lisp_Object old
= selected_frame
;
11538 struct Lisp_Symbol
*sym
;
11540 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11542 selected_frame
= frame
;
11545 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11546 if (CONSP (XCAR (tail
))
11547 && (tem
= XCAR (XCAR (tail
)),
11549 && (sym
= indirect_variable (XSYMBOL (tem
)),
11550 sym
->redirect
== SYMBOL_LOCALIZED
)
11551 && sym
->val
.blv
->frame_local
)
11552 /* Use find_symbol_value rather than Fsymbol_value
11553 to avoid an error if it is void. */
11554 find_symbol_value (tem
);
11555 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11559 #define STOP_POLLING \
11560 do { if (! polling_stopped_here) stop_polling (); \
11561 polling_stopped_here = 1; } while (0)
11563 #define RESUME_POLLING \
11564 do { if (polling_stopped_here) start_polling (); \
11565 polling_stopped_here = 0; } while (0)
11568 /* Perhaps in the future avoid recentering windows if it
11569 is not necessary; currently that causes some problems. */
11572 redisplay_internal (void)
11574 struct window
*w
= XWINDOW (selected_window
);
11578 int must_finish
= 0;
11579 struct text_pos tlbufpos
, tlendpos
;
11580 int number_of_visible_frames
;
11583 int polling_stopped_here
= 0;
11584 Lisp_Object old_frame
= selected_frame
;
11586 /* Non-zero means redisplay has to consider all windows on all
11587 frames. Zero means, only selected_window is considered. */
11588 int consider_all_windows_p
;
11590 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11592 /* No redisplay if running in batch mode or frame is not yet fully
11593 initialized, or redisplay is explicitly turned off by setting
11594 Vinhibit_redisplay. */
11595 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11596 || !NILP (Vinhibit_redisplay
))
11599 /* Don't examine these until after testing Vinhibit_redisplay.
11600 When Emacs is shutting down, perhaps because its connection to
11601 X has dropped, we should not look at them at all. */
11602 fr
= XFRAME (w
->frame
);
11603 sf
= SELECTED_FRAME ();
11605 if (!fr
->glyphs_initialized_p
)
11608 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11609 if (popup_activated ())
11613 /* I don't think this happens but let's be paranoid. */
11614 if (redisplaying_p
)
11617 /* Record a function that resets redisplaying_p to its old value
11618 when we leave this function. */
11619 count
= SPECPDL_INDEX ();
11620 record_unwind_protect (unwind_redisplay
,
11621 Fcons (make_number (redisplaying_p
), selected_frame
));
11623 specbind (Qinhibit_free_realized_faces
, Qnil
);
11626 Lisp_Object tail
, frame
;
11628 FOR_EACH_FRAME (tail
, frame
)
11630 struct frame
*f
= XFRAME (frame
);
11631 f
->already_hscrolled_p
= 0;
11636 /* Remember the currently selected window. */
11639 if (!EQ (old_frame
, selected_frame
)
11640 && FRAME_LIVE_P (XFRAME (old_frame
)))
11641 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11642 selected_frame and selected_window to be temporarily out-of-sync so
11643 when we come back here via `goto retry', we need to resync because we
11644 may need to run Elisp code (via prepare_menu_bars). */
11645 select_frame_for_redisplay (old_frame
);
11648 reconsider_clip_changes (w
, current_buffer
);
11649 last_escape_glyph_frame
= NULL
;
11650 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11651 last_glyphless_glyph_frame
= NULL
;
11652 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
11654 /* If new fonts have been loaded that make a glyph matrix adjustment
11655 necessary, do it. */
11656 if (fonts_changed_p
)
11658 adjust_glyphs (NULL
);
11659 ++windows_or_buffers_changed
;
11660 fonts_changed_p
= 0;
11663 /* If face_change_count is non-zero, init_iterator will free all
11664 realized faces, which includes the faces referenced from current
11665 matrices. So, we can't reuse current matrices in this case. */
11666 if (face_change_count
)
11667 ++windows_or_buffers_changed
;
11669 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11670 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11672 /* Since frames on a single ASCII terminal share the same
11673 display area, displaying a different frame means redisplay
11674 the whole thing. */
11675 windows_or_buffers_changed
++;
11676 SET_FRAME_GARBAGED (sf
);
11678 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11680 FRAME_TTY (sf
)->previous_frame
= sf
;
11683 /* Set the visible flags for all frames. Do this before checking
11684 for resized or garbaged frames; they want to know if their frames
11685 are visible. See the comment in frame.h for
11686 FRAME_SAMPLE_VISIBILITY. */
11688 Lisp_Object tail
, frame
;
11690 number_of_visible_frames
= 0;
11692 FOR_EACH_FRAME (tail
, frame
)
11694 struct frame
*f
= XFRAME (frame
);
11696 FRAME_SAMPLE_VISIBILITY (f
);
11697 if (FRAME_VISIBLE_P (f
))
11698 ++number_of_visible_frames
;
11699 clear_desired_matrices (f
);
11703 /* Notice any pending interrupt request to change frame size. */
11704 do_pending_window_change (1);
11706 /* do_pending_window_change could change the selected_window due to
11707 frame resizing which makes the selected window too small. */
11708 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
11711 reconsider_clip_changes (w
, current_buffer
);
11714 /* Clear frames marked as garbaged. */
11715 if (frame_garbaged
)
11716 clear_garbaged_frames ();
11718 /* Build menubar and tool-bar items. */
11719 if (NILP (Vmemory_full
))
11720 prepare_menu_bars ();
11722 if (windows_or_buffers_changed
)
11723 update_mode_lines
++;
11725 /* Detect case that we need to write or remove a star in the mode line. */
11726 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11728 w
->update_mode_line
= Qt
;
11729 if (buffer_shared
> 1)
11730 update_mode_lines
++;
11733 /* Avoid invocation of point motion hooks by `current_column' below. */
11734 count1
= SPECPDL_INDEX ();
11735 specbind (Qinhibit_point_motion_hooks
, Qt
);
11737 /* If %c is in the mode line, update it if needed. */
11738 if (!NILP (w
->column_number_displayed
)
11739 /* This alternative quickly identifies a common case
11740 where no change is needed. */
11741 && !(PT
== XFASTINT (w
->last_point
)
11742 && XFASTINT (w
->last_modified
) >= MODIFF
11743 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11744 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
11745 w
->update_mode_line
= Qt
;
11747 unbind_to (count1
, Qnil
);
11749 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11751 /* The variable buffer_shared is set in redisplay_window and
11752 indicates that we redisplay a buffer in different windows. See
11754 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11755 || cursor_type_changed
);
11757 /* If specs for an arrow have changed, do thorough redisplay
11758 to ensure we remove any arrow that should no longer exist. */
11759 if (overlay_arrows_changed_p ())
11760 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11762 /* Normally the message* functions will have already displayed and
11763 updated the echo area, but the frame may have been trashed, or
11764 the update may have been preempted, so display the echo area
11765 again here. Checking message_cleared_p captures the case that
11766 the echo area should be cleared. */
11767 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11768 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11769 || (message_cleared_p
11770 && minibuf_level
== 0
11771 /* If the mini-window is currently selected, this means the
11772 echo-area doesn't show through. */
11773 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11775 int window_height_changed_p
= echo_area_display (0);
11778 /* If we don't display the current message, don't clear the
11779 message_cleared_p flag, because, if we did, we wouldn't clear
11780 the echo area in the next redisplay which doesn't preserve
11782 if (!display_last_displayed_message_p
)
11783 message_cleared_p
= 0;
11785 if (fonts_changed_p
)
11787 else if (window_height_changed_p
)
11789 consider_all_windows_p
= 1;
11790 ++update_mode_lines
;
11791 ++windows_or_buffers_changed
;
11793 /* If window configuration was changed, frames may have been
11794 marked garbaged. Clear them or we will experience
11795 surprises wrt scrolling. */
11796 if (frame_garbaged
)
11797 clear_garbaged_frames ();
11800 else if (EQ (selected_window
, minibuf_window
)
11801 && (current_buffer
->clip_changed
11802 || XFASTINT (w
->last_modified
) < MODIFF
11803 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11804 && resize_mini_window (w
, 0))
11806 /* Resized active mini-window to fit the size of what it is
11807 showing if its contents might have changed. */
11809 /* FIXME: this causes all frames to be updated, which seems unnecessary
11810 since only the current frame needs to be considered. This function needs
11811 to be rewritten with two variables, consider_all_windows and
11812 consider_all_frames. */
11813 consider_all_windows_p
= 1;
11814 ++windows_or_buffers_changed
;
11815 ++update_mode_lines
;
11817 /* If window configuration was changed, frames may have been
11818 marked garbaged. Clear them or we will experience
11819 surprises wrt scrolling. */
11820 if (frame_garbaged
)
11821 clear_garbaged_frames ();
11825 /* If showing the region, and mark has changed, we must redisplay
11826 the whole window. The assignment to this_line_start_pos prevents
11827 the optimization directly below this if-statement. */
11828 if (((!NILP (Vtransient_mark_mode
)
11829 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11830 != !NILP (w
->region_showing
))
11831 || (!NILP (w
->region_showing
)
11832 && !EQ (w
->region_showing
,
11833 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
11834 CHARPOS (this_line_start_pos
) = 0;
11836 /* Optimize the case that only the line containing the cursor in the
11837 selected window has changed. Variables starting with this_ are
11838 set in display_line and record information about the line
11839 containing the cursor. */
11840 tlbufpos
= this_line_start_pos
;
11841 tlendpos
= this_line_end_pos
;
11842 if (!consider_all_windows_p
11843 && CHARPOS (tlbufpos
) > 0
11844 && NILP (w
->update_mode_line
)
11845 && !current_buffer
->clip_changed
11846 && !current_buffer
->prevent_redisplay_optimizations_p
11847 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11848 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11849 /* Make sure recorded data applies to current buffer, etc. */
11850 && this_line_buffer
== current_buffer
11851 && current_buffer
== XBUFFER (w
->buffer
)
11852 && NILP (w
->force_start
)
11853 && NILP (w
->optional_new_start
)
11854 /* Point must be on the line that we have info recorded about. */
11855 && PT
>= CHARPOS (tlbufpos
)
11856 && PT
<= Z
- CHARPOS (tlendpos
)
11857 /* All text outside that line, including its final newline,
11858 must be unchanged. */
11859 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11860 CHARPOS (tlendpos
)))
11862 if (CHARPOS (tlbufpos
) > BEGV
11863 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11864 && (CHARPOS (tlbufpos
) == ZV
11865 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11866 /* Former continuation line has disappeared by becoming empty. */
11868 else if (XFASTINT (w
->last_modified
) < MODIFF
11869 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11870 || MINI_WINDOW_P (w
))
11872 /* We have to handle the case of continuation around a
11873 wide-column character (see the comment in indent.c around
11876 For instance, in the following case:
11878 -------- Insert --------
11879 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11880 J_I_ ==> J_I_ `^^' are cursors.
11884 As we have to redraw the line above, we cannot use this
11888 int line_height_before
= this_line_pixel_height
;
11890 /* Note that start_display will handle the case that the
11891 line starting at tlbufpos is a continuation line. */
11892 start_display (&it
, w
, tlbufpos
);
11894 /* Implementation note: It this still necessary? */
11895 if (it
.current_x
!= this_line_start_x
)
11898 TRACE ((stderr
, "trying display optimization 1\n"));
11899 w
->cursor
.vpos
= -1;
11900 overlay_arrow_seen
= 0;
11901 it
.vpos
= this_line_vpos
;
11902 it
.current_y
= this_line_y
;
11903 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11904 display_line (&it
);
11906 /* If line contains point, is not continued,
11907 and ends at same distance from eob as before, we win. */
11908 if (w
->cursor
.vpos
>= 0
11909 /* Line is not continued, otherwise this_line_start_pos
11910 would have been set to 0 in display_line. */
11911 && CHARPOS (this_line_start_pos
)
11912 /* Line ends as before. */
11913 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11914 /* Line has same height as before. Otherwise other lines
11915 would have to be shifted up or down. */
11916 && this_line_pixel_height
== line_height_before
)
11918 /* If this is not the window's last line, we must adjust
11919 the charstarts of the lines below. */
11920 if (it
.current_y
< it
.last_visible_y
)
11922 struct glyph_row
*row
11923 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11924 EMACS_INT delta
, delta_bytes
;
11926 /* We used to distinguish between two cases here,
11927 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11928 when the line ends in a newline or the end of the
11929 buffer's accessible portion. But both cases did
11930 the same, so they were collapsed. */
11932 - CHARPOS (tlendpos
)
11933 - MATRIX_ROW_START_CHARPOS (row
));
11934 delta_bytes
= (Z_BYTE
11935 - BYTEPOS (tlendpos
)
11936 - MATRIX_ROW_START_BYTEPOS (row
));
11938 increment_matrix_positions (w
->current_matrix
,
11939 this_line_vpos
+ 1,
11940 w
->current_matrix
->nrows
,
11941 delta
, delta_bytes
);
11944 /* If this row displays text now but previously didn't,
11945 or vice versa, w->window_end_vpos may have to be
11947 if ((it
.glyph_row
- 1)->displays_text_p
)
11949 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11950 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11952 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11953 && this_line_vpos
> 0)
11954 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11955 w
->window_end_valid
= Qnil
;
11957 /* Update hint: No need to try to scroll in update_window. */
11958 w
->desired_matrix
->no_scrolling_p
= 1;
11961 *w
->desired_matrix
->method
= 0;
11962 debug_method_add (w
, "optimization 1");
11964 #ifdef HAVE_WINDOW_SYSTEM
11965 update_window_fringes (w
, 0);
11972 else if (/* Cursor position hasn't changed. */
11973 PT
== XFASTINT (w
->last_point
)
11974 /* Make sure the cursor was last displayed
11975 in this window. Otherwise we have to reposition it. */
11976 && 0 <= w
->cursor
.vpos
11977 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11981 do_pending_window_change (1);
11982 /* If selected_window changed, redisplay again. */
11983 if (WINDOWP (selected_window
)
11984 && (w
= XWINDOW (selected_window
)) != sw
)
11987 /* We used to always goto end_of_redisplay here, but this
11988 isn't enough if we have a blinking cursor. */
11989 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11990 goto end_of_redisplay
;
11994 /* If highlighting the region, or if the cursor is in the echo area,
11995 then we can't just move the cursor. */
11996 else if (! (!NILP (Vtransient_mark_mode
)
11997 && !NILP (BVAR (current_buffer
, mark_active
)))
11998 && (EQ (selected_window
, BVAR (current_buffer
, last_selected_window
))
11999 || highlight_nonselected_windows
)
12000 && NILP (w
->region_showing
)
12001 && NILP (Vshow_trailing_whitespace
)
12002 && !cursor_in_echo_area
)
12005 struct glyph_row
*row
;
12007 /* Skip from tlbufpos to PT and see where it is. Note that
12008 PT may be in invisible text. If so, we will end at the
12009 next visible position. */
12010 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
12011 NULL
, DEFAULT_FACE_ID
);
12012 it
.current_x
= this_line_start_x
;
12013 it
.current_y
= this_line_y
;
12014 it
.vpos
= this_line_vpos
;
12016 /* The call to move_it_to stops in front of PT, but
12017 moves over before-strings. */
12018 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
12020 if (it
.vpos
== this_line_vpos
12021 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12024 xassert (this_line_vpos
== it
.vpos
);
12025 xassert (this_line_y
== it
.current_y
);
12026 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12028 *w
->desired_matrix
->method
= 0;
12029 debug_method_add (w
, "optimization 3");
12038 /* Text changed drastically or point moved off of line. */
12039 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12042 CHARPOS (this_line_start_pos
) = 0;
12043 consider_all_windows_p
|= buffer_shared
> 1;
12044 ++clear_face_cache_count
;
12045 #ifdef HAVE_WINDOW_SYSTEM
12046 ++clear_image_cache_count
;
12049 /* Build desired matrices, and update the display. If
12050 consider_all_windows_p is non-zero, do it for all windows on all
12051 frames. Otherwise do it for selected_window, only. */
12053 if (consider_all_windows_p
)
12055 Lisp_Object tail
, frame
;
12057 FOR_EACH_FRAME (tail
, frame
)
12058 XFRAME (frame
)->updated_p
= 0;
12060 /* Recompute # windows showing selected buffer. This will be
12061 incremented each time such a window is displayed. */
12064 FOR_EACH_FRAME (tail
, frame
)
12066 struct frame
*f
= XFRAME (frame
);
12068 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12070 if (! EQ (frame
, selected_frame
))
12071 /* Select the frame, for the sake of frame-local
12073 select_frame_for_redisplay (frame
);
12075 /* Mark all the scroll bars to be removed; we'll redeem
12076 the ones we want when we redisplay their windows. */
12077 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12078 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12080 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12081 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12083 /* The X error handler may have deleted that frame. */
12084 if (!FRAME_LIVE_P (f
))
12087 /* Any scroll bars which redisplay_windows should have
12088 nuked should now go away. */
12089 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12090 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12092 /* If fonts changed, display again. */
12093 /* ??? rms: I suspect it is a mistake to jump all the way
12094 back to retry here. It should just retry this frame. */
12095 if (fonts_changed_p
)
12098 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12100 /* See if we have to hscroll. */
12101 if (!f
->already_hscrolled_p
)
12103 f
->already_hscrolled_p
= 1;
12104 if (hscroll_windows (f
->root_window
))
12108 /* Prevent various kinds of signals during display
12109 update. stdio is not robust about handling
12110 signals, which can cause an apparent I/O
12112 if (interrupt_input
)
12113 unrequest_sigio ();
12116 /* Update the display. */
12117 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12118 pending
|= update_frame (f
, 0, 0);
12124 if (!EQ (old_frame
, selected_frame
)
12125 && FRAME_LIVE_P (XFRAME (old_frame
)))
12126 /* We played a bit fast-and-loose above and allowed selected_frame
12127 and selected_window to be temporarily out-of-sync but let's make
12128 sure this stays contained. */
12129 select_frame_for_redisplay (old_frame
);
12130 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12134 /* Do the mark_window_display_accurate after all windows have
12135 been redisplayed because this call resets flags in buffers
12136 which are needed for proper redisplay. */
12137 FOR_EACH_FRAME (tail
, frame
)
12139 struct frame
*f
= XFRAME (frame
);
12142 mark_window_display_accurate (f
->root_window
, 1);
12143 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12144 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12149 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12151 Lisp_Object mini_window
;
12152 struct frame
*mini_frame
;
12154 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12155 /* Use list_of_error, not Qerror, so that
12156 we catch only errors and don't run the debugger. */
12157 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12159 redisplay_window_error
);
12161 /* Compare desired and current matrices, perform output. */
12164 /* If fonts changed, display again. */
12165 if (fonts_changed_p
)
12168 /* Prevent various kinds of signals during display update.
12169 stdio is not robust about handling signals,
12170 which can cause an apparent I/O error. */
12171 if (interrupt_input
)
12172 unrequest_sigio ();
12175 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12177 if (hscroll_windows (selected_window
))
12180 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12181 pending
= update_frame (sf
, 0, 0);
12184 /* We may have called echo_area_display at the top of this
12185 function. If the echo area is on another frame, that may
12186 have put text on a frame other than the selected one, so the
12187 above call to update_frame would not have caught it. Catch
12189 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12190 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12192 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12194 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12195 pending
|= update_frame (mini_frame
, 0, 0);
12196 if (!pending
&& hscroll_windows (mini_window
))
12201 /* If display was paused because of pending input, make sure we do a
12202 thorough update the next time. */
12205 /* Prevent the optimization at the beginning of
12206 redisplay_internal that tries a single-line update of the
12207 line containing the cursor in the selected window. */
12208 CHARPOS (this_line_start_pos
) = 0;
12210 /* Let the overlay arrow be updated the next time. */
12211 update_overlay_arrows (0);
12213 /* If we pause after scrolling, some rows in the current
12214 matrices of some windows are not valid. */
12215 if (!WINDOW_FULL_WIDTH_P (w
)
12216 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12217 update_mode_lines
= 1;
12221 if (!consider_all_windows_p
)
12223 /* This has already been done above if
12224 consider_all_windows_p is set. */
12225 mark_window_display_accurate_1 (w
, 1);
12227 /* Say overlay arrows are up to date. */
12228 update_overlay_arrows (1);
12230 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12231 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12234 update_mode_lines
= 0;
12235 windows_or_buffers_changed
= 0;
12236 cursor_type_changed
= 0;
12239 /* Start SIGIO interrupts coming again. Having them off during the
12240 code above makes it less likely one will discard output, but not
12241 impossible, since there might be stuff in the system buffer here.
12242 But it is much hairier to try to do anything about that. */
12243 if (interrupt_input
)
12247 /* If a frame has become visible which was not before, redisplay
12248 again, so that we display it. Expose events for such a frame
12249 (which it gets when becoming visible) don't call the parts of
12250 redisplay constructing glyphs, so simply exposing a frame won't
12251 display anything in this case. So, we have to display these
12252 frames here explicitly. */
12255 Lisp_Object tail
, frame
;
12258 FOR_EACH_FRAME (tail
, frame
)
12260 int this_is_visible
= 0;
12262 if (XFRAME (frame
)->visible
)
12263 this_is_visible
= 1;
12264 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12265 if (XFRAME (frame
)->visible
)
12266 this_is_visible
= 1;
12268 if (this_is_visible
)
12272 if (new_count
!= number_of_visible_frames
)
12273 windows_or_buffers_changed
++;
12276 /* Change frame size now if a change is pending. */
12277 do_pending_window_change (1);
12279 /* If we just did a pending size change, or have additional
12280 visible frames, or selected_window changed, redisplay again. */
12281 if ((windows_or_buffers_changed
&& !pending
)
12282 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
12285 /* Clear the face and image caches.
12287 We used to do this only if consider_all_windows_p. But the cache
12288 needs to be cleared if a timer creates images in the current
12289 buffer (e.g. the test case in Bug#6230). */
12291 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12293 clear_face_cache (0);
12294 clear_face_cache_count
= 0;
12297 #ifdef HAVE_WINDOW_SYSTEM
12298 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12300 clear_image_caches (Qnil
);
12301 clear_image_cache_count
= 0;
12303 #endif /* HAVE_WINDOW_SYSTEM */
12306 unbind_to (count
, Qnil
);
12311 /* Redisplay, but leave alone any recent echo area message unless
12312 another message has been requested in its place.
12314 This is useful in situations where you need to redisplay but no
12315 user action has occurred, making it inappropriate for the message
12316 area to be cleared. See tracking_off and
12317 wait_reading_process_output for examples of these situations.
12319 FROM_WHERE is an integer saying from where this function was
12320 called. This is useful for debugging. */
12323 redisplay_preserve_echo_area (int from_where
)
12325 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12327 if (!NILP (echo_area_buffer
[1]))
12329 /* We have a previously displayed message, but no current
12330 message. Redisplay the previous message. */
12331 display_last_displayed_message_p
= 1;
12332 redisplay_internal ();
12333 display_last_displayed_message_p
= 0;
12336 redisplay_internal ();
12338 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12339 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12340 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12344 /* Function registered with record_unwind_protect in
12345 redisplay_internal. Reset redisplaying_p to the value it had
12346 before redisplay_internal was called, and clear
12347 prevent_freeing_realized_faces_p. It also selects the previously
12348 selected frame, unless it has been deleted (by an X connection
12349 failure during redisplay, for example). */
12352 unwind_redisplay (Lisp_Object val
)
12354 Lisp_Object old_redisplaying_p
, old_frame
;
12356 old_redisplaying_p
= XCAR (val
);
12357 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12358 old_frame
= XCDR (val
);
12359 if (! EQ (old_frame
, selected_frame
)
12360 && FRAME_LIVE_P (XFRAME (old_frame
)))
12361 select_frame_for_redisplay (old_frame
);
12366 /* Mark the display of window W as accurate or inaccurate. If
12367 ACCURATE_P is non-zero mark display of W as accurate. If
12368 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12369 redisplay_internal is called. */
12372 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
12374 if (BUFFERP (w
->buffer
))
12376 struct buffer
*b
= XBUFFER (w
->buffer
);
12379 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12380 w
->last_overlay_modified
12381 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12383 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12387 b
->clip_changed
= 0;
12388 b
->prevent_redisplay_optimizations_p
= 0;
12390 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12391 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12392 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12393 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12395 w
->current_matrix
->buffer
= b
;
12396 w
->current_matrix
->begv
= BUF_BEGV (b
);
12397 w
->current_matrix
->zv
= BUF_ZV (b
);
12399 w
->last_cursor
= w
->cursor
;
12400 w
->last_cursor_off_p
= w
->cursor_off_p
;
12402 if (w
== XWINDOW (selected_window
))
12403 w
->last_point
= make_number (BUF_PT (b
));
12405 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12411 w
->window_end_valid
= w
->buffer
;
12412 w
->update_mode_line
= Qnil
;
12417 /* Mark the display of windows in the window tree rooted at WINDOW as
12418 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12419 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12420 be redisplayed the next time redisplay_internal is called. */
12423 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
12427 for (; !NILP (window
); window
= w
->next
)
12429 w
= XWINDOW (window
);
12430 mark_window_display_accurate_1 (w
, accurate_p
);
12432 if (!NILP (w
->vchild
))
12433 mark_window_display_accurate (w
->vchild
, accurate_p
);
12434 if (!NILP (w
->hchild
))
12435 mark_window_display_accurate (w
->hchild
, accurate_p
);
12440 update_overlay_arrows (1);
12444 /* Force a thorough redisplay the next time by setting
12445 last_arrow_position and last_arrow_string to t, which is
12446 unequal to any useful value of Voverlay_arrow_... */
12447 update_overlay_arrows (-1);
12452 /* Return value in display table DP (Lisp_Char_Table *) for character
12453 C. Since a display table doesn't have any parent, we don't have to
12454 follow parent. Do not call this function directly but use the
12455 macro DISP_CHAR_VECTOR. */
12458 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
12462 if (ASCII_CHAR_P (c
))
12465 if (SUB_CHAR_TABLE_P (val
))
12466 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12472 XSETCHAR_TABLE (table
, dp
);
12473 val
= char_table_ref (table
, c
);
12482 /***********************************************************************
12484 ***********************************************************************/
12486 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12489 redisplay_windows (Lisp_Object window
)
12491 while (!NILP (window
))
12493 struct window
*w
= XWINDOW (window
);
12495 if (!NILP (w
->hchild
))
12496 redisplay_windows (w
->hchild
);
12497 else if (!NILP (w
->vchild
))
12498 redisplay_windows (w
->vchild
);
12499 else if (!NILP (w
->buffer
))
12501 displayed_buffer
= XBUFFER (w
->buffer
);
12502 /* Use list_of_error, not Qerror, so that
12503 we catch only errors and don't run the debugger. */
12504 internal_condition_case_1 (redisplay_window_0
, window
,
12506 redisplay_window_error
);
12514 redisplay_window_error (Lisp_Object ignore
)
12516 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12521 redisplay_window_0 (Lisp_Object window
)
12523 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12524 redisplay_window (window
, 0);
12529 redisplay_window_1 (Lisp_Object window
)
12531 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12532 redisplay_window (window
, 1);
12537 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12538 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12539 which positions recorded in ROW differ from current buffer
12542 Return 0 if cursor is not on this row, 1 otherwise. */
12545 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
12546 struct glyph_matrix
*matrix
,
12547 EMACS_INT delta
, EMACS_INT delta_bytes
,
12550 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12551 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12552 struct glyph
*cursor
= NULL
;
12553 /* The last known character position in row. */
12554 EMACS_INT last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12556 EMACS_INT pt_old
= PT
- delta
;
12557 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12558 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12559 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
12560 /* A glyph beyond the edge of TEXT_AREA which we should never
12562 struct glyph
*glyphs_end
= end
;
12563 /* Non-zero means we've found a match for cursor position, but that
12564 glyph has the avoid_cursor_p flag set. */
12565 int match_with_avoid_cursor
= 0;
12566 /* Non-zero means we've seen at least one glyph that came from a
12568 int string_seen
= 0;
12569 /* Largest and smalles buffer positions seen so far during scan of
12571 EMACS_INT bpos_max
= pos_before
;
12572 EMACS_INT bpos_min
= pos_after
;
12573 /* Last buffer position covered by an overlay string with an integer
12574 `cursor' property. */
12575 EMACS_INT bpos_covered
= 0;
12577 /* Skip over glyphs not having an object at the start and the end of
12578 the row. These are special glyphs like truncation marks on
12579 terminal frames. */
12580 if (row
->displays_text_p
)
12582 if (!row
->reversed_p
)
12585 && INTEGERP (glyph
->object
)
12586 && glyph
->charpos
< 0)
12588 x
+= glyph
->pixel_width
;
12592 && INTEGERP ((end
- 1)->object
)
12593 /* CHARPOS is zero for blanks and stretch glyphs
12594 inserted by extend_face_to_end_of_line. */
12595 && (end
- 1)->charpos
<= 0)
12597 glyph_before
= glyph
- 1;
12604 /* If the glyph row is reversed, we need to process it from back
12605 to front, so swap the edge pointers. */
12606 glyphs_end
= end
= glyph
- 1;
12607 glyph
+= row
->used
[TEXT_AREA
] - 1;
12609 while (glyph
> end
+ 1
12610 && INTEGERP (glyph
->object
)
12611 && glyph
->charpos
< 0)
12614 x
-= glyph
->pixel_width
;
12616 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
12618 /* By default, in reversed rows we put the cursor on the
12619 rightmost (first in the reading order) glyph. */
12620 for (g
= end
+ 1; g
< glyph
; g
++)
12621 x
+= g
->pixel_width
;
12623 && INTEGERP ((end
+ 1)->object
)
12624 && (end
+ 1)->charpos
<= 0)
12626 glyph_before
= glyph
+ 1;
12630 else if (row
->reversed_p
)
12632 /* In R2L rows that don't display text, put the cursor on the
12633 rightmost glyph. Case in point: an empty last line that is
12634 part of an R2L paragraph. */
12636 /* Avoid placing the cursor on the last glyph of the row, where
12637 on terminal frames we hold the vertical border between
12638 adjacent windows. */
12639 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
12640 && !WINDOW_RIGHTMOST_P (w
)
12641 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
12643 x
= -1; /* will be computed below, at label compute_x */
12646 /* Step 1: Try to find the glyph whose character position
12647 corresponds to point. If that's not possible, find 2 glyphs
12648 whose character positions are the closest to point, one before
12649 point, the other after it. */
12650 if (!row
->reversed_p
)
12651 while (/* not marched to end of glyph row */
12653 /* glyph was not inserted by redisplay for internal purposes */
12654 && !INTEGERP (glyph
->object
))
12656 if (BUFFERP (glyph
->object
))
12658 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12660 if (glyph
->charpos
> bpos_max
)
12661 bpos_max
= glyph
->charpos
;
12662 if (glyph
->charpos
< bpos_min
)
12663 bpos_min
= glyph
->charpos
;
12664 if (!glyph
->avoid_cursor_p
)
12666 /* If we hit point, we've found the glyph on which to
12667 display the cursor. */
12670 match_with_avoid_cursor
= 0;
12673 /* See if we've found a better approximation to
12674 POS_BEFORE or to POS_AFTER. Note that we want the
12675 first (leftmost) glyph of all those that are the
12676 closest from below, and the last (rightmost) of all
12677 those from above. */
12678 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12680 pos_before
= glyph
->charpos
;
12681 glyph_before
= glyph
;
12683 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12685 pos_after
= glyph
->charpos
;
12686 glyph_after
= glyph
;
12689 else if (dpos
== 0)
12690 match_with_avoid_cursor
= 1;
12692 else if (STRINGP (glyph
->object
))
12694 Lisp_Object chprop
;
12695 EMACS_INT glyph_pos
= glyph
->charpos
;
12697 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12699 if (INTEGERP (chprop
))
12701 bpos_covered
= bpos_max
+ XINT (chprop
);
12702 /* If the `cursor' property covers buffer positions up
12703 to and including point, we should display cursor on
12704 this glyph. Note that overlays and text properties
12705 with string values stop bidi reordering, so every
12706 buffer position to the left of the string is always
12707 smaller than any position to the right of the
12708 string. Therefore, if a `cursor' property on one
12709 of the string's characters has an integer value, we
12710 will break out of the loop below _before_ we get to
12711 the position match above. IOW, integer values of
12712 the `cursor' property override the "exact match for
12713 point" strategy of positioning the cursor. */
12714 /* Implementation note: bpos_max == pt_old when, e.g.,
12715 we are in an empty line, where bpos_max is set to
12716 MATRIX_ROW_START_CHARPOS, see above. */
12717 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12726 x
+= glyph
->pixel_width
;
12729 else if (glyph
> end
) /* row is reversed */
12730 while (!INTEGERP (glyph
->object
))
12732 if (BUFFERP (glyph
->object
))
12734 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12736 if (glyph
->charpos
> bpos_max
)
12737 bpos_max
= glyph
->charpos
;
12738 if (glyph
->charpos
< bpos_min
)
12739 bpos_min
= glyph
->charpos
;
12740 if (!glyph
->avoid_cursor_p
)
12744 match_with_avoid_cursor
= 0;
12747 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12749 pos_before
= glyph
->charpos
;
12750 glyph_before
= glyph
;
12752 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12754 pos_after
= glyph
->charpos
;
12755 glyph_after
= glyph
;
12758 else if (dpos
== 0)
12759 match_with_avoid_cursor
= 1;
12761 else if (STRINGP (glyph
->object
))
12763 Lisp_Object chprop
;
12764 EMACS_INT glyph_pos
= glyph
->charpos
;
12766 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12768 if (INTEGERP (chprop
))
12770 bpos_covered
= bpos_max
+ XINT (chprop
);
12771 /* If the `cursor' property covers buffer positions up
12772 to and including point, we should display cursor on
12774 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12783 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
12785 x
--; /* can't use any pixel_width */
12788 x
-= glyph
->pixel_width
;
12791 /* Step 2: If we didn't find an exact match for point, we need to
12792 look for a proper place to put the cursor among glyphs between
12793 GLYPH_BEFORE and GLYPH_AFTER. */
12794 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
12795 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12796 && bpos_covered
< pt_old
)
12798 /* An empty line has a single glyph whose OBJECT is zero and
12799 whose CHARPOS is the position of a newline on that line.
12800 Note that on a TTY, there are more glyphs after that, which
12801 were produced by extend_face_to_end_of_line, but their
12802 CHARPOS is zero or negative. */
12804 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
12805 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
12807 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
12809 EMACS_INT ellipsis_pos
;
12811 /* Scan back over the ellipsis glyphs. */
12812 if (!row
->reversed_p
)
12814 ellipsis_pos
= (glyph
- 1)->charpos
;
12815 while (glyph
> row
->glyphs
[TEXT_AREA
]
12816 && (glyph
- 1)->charpos
== ellipsis_pos
)
12817 glyph
--, x
-= glyph
->pixel_width
;
12818 /* That loop always goes one position too far, including
12819 the glyph before the ellipsis. So scan forward over
12821 x
+= glyph
->pixel_width
;
12824 else /* row is reversed */
12826 ellipsis_pos
= (glyph
+ 1)->charpos
;
12827 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
12828 && (glyph
+ 1)->charpos
== ellipsis_pos
)
12829 glyph
++, x
+= glyph
->pixel_width
;
12830 x
-= glyph
->pixel_width
;
12834 else if (match_with_avoid_cursor
12835 /* A truncated row may not include PT among its
12836 character positions. Setting the cursor inside the
12837 scroll margin will trigger recalculation of hscroll
12838 in hscroll_window_tree. */
12839 || (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
12840 || (row
->truncated_on_right_p
&& pt_old
> bpos_max
)
12841 /* Zero-width characters produce no glyphs. */
12844 && (row
->reversed_p
12845 ? glyph_after
> glyphs_end
12846 : glyph_after
< glyphs_end
)))
12848 cursor
= glyph_after
;
12851 else if (string_seen
)
12853 int incr
= row
->reversed_p
? -1 : +1;
12855 /* Need to find the glyph that came out of a string which is
12856 present at point. That glyph is somewhere between
12857 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
12858 positioned between POS_BEFORE and POS_AFTER in the
12860 struct glyph
*start
, *stop
;
12861 EMACS_INT pos
= pos_before
;
12865 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
12866 correspond to POS_BEFORE and POS_AFTER, respectively. We
12867 need START and STOP in the order that corresponds to the
12868 row's direction as given by its reversed_p flag. If the
12869 directionality of characters between POS_BEFORE and
12870 POS_AFTER is the opposite of the row's base direction,
12871 these characters will have been reordered for display,
12872 and we need to reverse START and STOP. */
12873 if (!row
->reversed_p
)
12875 start
= min (glyph_before
, glyph_after
);
12876 stop
= max (glyph_before
, glyph_after
);
12880 start
= max (glyph_before
, glyph_after
);
12881 stop
= min (glyph_before
, glyph_after
);
12883 for (glyph
= start
+ incr
;
12884 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
12887 /* Any glyphs that come from the buffer are here because
12888 of bidi reordering. Skip them, and only pay
12889 attention to glyphs that came from some string. */
12890 if (STRINGP (glyph
->object
))
12895 str
= glyph
->object
;
12896 tem
= string_buffer_position_lim (str
, pos
, pos_after
, 0);
12897 if (tem
== 0 /* from overlay */
12900 /* If the string from which this glyph came is
12901 found in the buffer at point, then we've
12902 found the glyph we've been looking for. If
12903 it comes from an overlay (tem == 0), and it
12904 has the `cursor' property on one of its
12905 glyphs, record that glyph as a candidate for
12906 displaying the cursor. (As in the
12907 unidirectional version, we will display the
12908 cursor on the last candidate we find.) */
12909 if (tem
== 0 || tem
== pt_old
)
12911 /* The glyphs from this string could have
12912 been reordered. Find the one with the
12913 smallest string position. Or there could
12914 be a character in the string with the
12915 `cursor' property, which means display
12916 cursor on that character's glyph. */
12917 EMACS_INT strpos
= glyph
->charpos
;
12922 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12923 && EQ (glyph
->object
, str
);
12927 EMACS_INT gpos
= glyph
->charpos
;
12929 cprop
= Fget_char_property (make_number (gpos
),
12937 if (tem
&& glyph
->charpos
< strpos
)
12939 strpos
= glyph
->charpos
;
12948 pos
= tem
+ 1; /* don't find previous instances */
12950 /* This string is not what we want; skip all of the
12951 glyphs that came from it. */
12952 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12953 && EQ (glyph
->object
, str
))
12960 /* If we reached the end of the line, and END was from a string,
12961 the cursor is not on this line. */
12963 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
12964 && STRINGP (end
->object
)
12965 && row
->continued_p
)
12971 if (cursor
!= NULL
)
12977 /* Need to compute x that corresponds to GLYPH. */
12978 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
12980 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
12982 x
+= g
->pixel_width
;
12986 /* ROW could be part of a continued line, which, under bidi
12987 reordering, might have other rows whose start and end charpos
12988 occlude point. Only set w->cursor if we found a better
12989 approximation to the cursor position than we have from previously
12990 examined candidate rows belonging to the same continued line. */
12991 if (/* we already have a candidate row */
12992 w
->cursor
.vpos
>= 0
12993 /* that candidate is not the row we are processing */
12994 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
12995 /* the row we are processing is part of a continued line */
12996 && (row
->continued_p
|| MATRIX_ROW_CONTINUATION_LINE_P (row
))
12997 /* Make sure cursor.vpos specifies a row whose start and end
12998 charpos occlude point. This is because some callers of this
12999 function leave cursor.vpos at the row where the cursor was
13000 displayed during the last redisplay cycle. */
13001 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
13002 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
13005 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
13007 /* Don't consider glyphs that are outside TEXT_AREA. */
13008 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
13010 /* Keep the candidate whose buffer position is the closest to
13012 if (/* previous candidate is a glyph in TEXT_AREA of that row */
13013 w
->cursor
.hpos
>= 0
13014 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
13015 && BUFFERP (g1
->object
)
13016 && (g1
->charpos
== pt_old
/* an exact match always wins */
13017 || (BUFFERP (glyph
->object
)
13018 && eabs (g1
->charpos
- pt_old
)
13019 < eabs (glyph
->charpos
- pt_old
))))
13021 /* If this candidate gives an exact match, use that. */
13022 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13023 /* Otherwise, keep the candidate that comes from a row
13024 spanning less buffer positions. This may win when one or
13025 both candidate positions are on glyphs that came from
13026 display strings, for which we cannot compare buffer
13028 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13029 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13030 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
13033 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
13035 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
13036 w
->cursor
.y
= row
->y
+ dy
;
13038 if (w
== XWINDOW (selected_window
))
13040 if (!row
->continued_p
13041 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
13044 this_line_buffer
= XBUFFER (w
->buffer
);
13046 CHARPOS (this_line_start_pos
)
13047 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
13048 BYTEPOS (this_line_start_pos
)
13049 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
13051 CHARPOS (this_line_end_pos
)
13052 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
13053 BYTEPOS (this_line_end_pos
)
13054 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
13056 this_line_y
= w
->cursor
.y
;
13057 this_line_pixel_height
= row
->height
;
13058 this_line_vpos
= w
->cursor
.vpos
;
13059 this_line_start_x
= row
->x
;
13062 CHARPOS (this_line_start_pos
) = 0;
13069 /* Run window scroll functions, if any, for WINDOW with new window
13070 start STARTP. Sets the window start of WINDOW to that position.
13072 We assume that the window's buffer is really current. */
13074 static INLINE
struct text_pos
13075 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
13077 struct window
*w
= XWINDOW (window
);
13078 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13080 if (current_buffer
!= XBUFFER (w
->buffer
))
13083 if (!NILP (Vwindow_scroll_functions
))
13085 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13086 make_number (CHARPOS (startp
)));
13087 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13088 /* In case the hook functions switch buffers. */
13089 if (current_buffer
!= XBUFFER (w
->buffer
))
13090 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13097 /* Make sure the line containing the cursor is fully visible.
13098 A value of 1 means there is nothing to be done.
13099 (Either the line is fully visible, or it cannot be made so,
13100 or we cannot tell.)
13102 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13103 is higher than window.
13105 A value of 0 means the caller should do scrolling
13106 as if point had gone off the screen. */
13109 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
13111 struct glyph_matrix
*matrix
;
13112 struct glyph_row
*row
;
13115 if (!make_cursor_line_fully_visible_p
)
13118 /* It's not always possible to find the cursor, e.g, when a window
13119 is full of overlay strings. Don't do anything in that case. */
13120 if (w
->cursor
.vpos
< 0)
13123 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13124 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13126 /* If the cursor row is not partially visible, there's nothing to do. */
13127 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13130 /* If the row the cursor is in is taller than the window's height,
13131 it's not clear what to do, so do nothing. */
13132 window_height
= window_box_height (w
);
13133 if (row
->height
>= window_height
)
13135 if (!force_p
|| MINI_WINDOW_P (w
)
13136 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13143 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13144 non-zero means only WINDOW is redisplayed in redisplay_internal.
13145 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
13146 in redisplay_window to bring a partially visible line into view in
13147 the case that only the cursor has moved.
13149 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13150 last screen line's vertical height extends past the end of the screen.
13154 1 if scrolling succeeded
13156 0 if scrolling didn't find point.
13158 -1 if new fonts have been loaded so that we must interrupt
13159 redisplay, adjust glyph matrices, and try again. */
13165 SCROLLING_NEED_LARGER_MATRICES
13168 /* If scroll-conservatively is more than this, never recenter.
13170 If you change this, don't forget to update the doc string of
13171 `scroll-conservatively' and the Emacs manual. */
13172 #define SCROLL_LIMIT 100
13175 try_scrolling (Lisp_Object window
, int just_this_one_p
,
13176 EMACS_INT arg_scroll_conservatively
, EMACS_INT scroll_step
,
13177 int temp_scroll_step
, int last_line_misfit
)
13179 struct window
*w
= XWINDOW (window
);
13180 struct frame
*f
= XFRAME (w
->frame
);
13181 struct text_pos pos
, startp
;
13183 int this_scroll_margin
, scroll_max
, rc
, height
;
13184 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13185 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13186 Lisp_Object aggressive
;
13187 /* We will never try scrolling more than this number of lines. */
13188 int scroll_limit
= SCROLL_LIMIT
;
13191 debug_method_add (w
, "try_scrolling");
13194 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13196 /* Compute scroll margin height in pixels. We scroll when point is
13197 within this distance from the top or bottom of the window. */
13198 if (scroll_margin
> 0)
13199 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13200 * FRAME_LINE_HEIGHT (f
);
13202 this_scroll_margin
= 0;
13204 /* Force arg_scroll_conservatively to have a reasonable value, to
13205 avoid scrolling too far away with slow move_it_* functions. Note
13206 that the user can supply scroll-conservatively equal to
13207 `most-positive-fixnum', which can be larger than INT_MAX. */
13208 if (arg_scroll_conservatively
> scroll_limit
)
13210 arg_scroll_conservatively
= scroll_limit
+ 1;
13211 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
13213 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
13214 /* Compute how much we should try to scroll maximally to bring
13215 point into view. */
13216 scroll_max
= (max (scroll_step
,
13217 max (arg_scroll_conservatively
, temp_scroll_step
))
13218 * FRAME_LINE_HEIGHT (f
));
13219 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
13220 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
13221 /* We're trying to scroll because of aggressive scrolling but no
13222 scroll_step is set. Choose an arbitrary one. */
13223 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13229 /* Decide whether to scroll down. */
13230 if (PT
> CHARPOS (startp
))
13232 int scroll_margin_y
;
13234 /* Compute the pixel ypos of the scroll margin, then move it to
13235 either that ypos or PT, whichever comes first. */
13236 start_display (&it
, w
, startp
);
13237 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13238 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13239 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13240 (MOVE_TO_POS
| MOVE_TO_Y
));
13242 if (PT
> CHARPOS (it
.current
.pos
))
13244 int y0
= line_bottom_y (&it
);
13245 /* Compute how many pixels below window bottom to stop searching
13246 for PT. This avoids costly search for PT that is far away if
13247 the user limited scrolling by a small number of lines, but
13248 always finds PT if scroll_conservatively is set to a large
13249 number, such as most-positive-fixnum. */
13250 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
13251 int y_to_move
= it
.last_visible_y
+ slack
;
13253 /* Compute the distance from the scroll margin to PT or to
13254 the scroll limit, whichever comes first. This should
13255 include the height of the cursor line, to make that line
13257 move_it_to (&it
, PT
, -1, y_to_move
,
13258 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13259 dy
= line_bottom_y (&it
) - y0
;
13261 if (dy
> scroll_max
)
13262 return SCROLLING_FAILED
;
13270 /* Point is in or below the bottom scroll margin, so move the
13271 window start down. If scrolling conservatively, move it just
13272 enough down to make point visible. If scroll_step is set,
13273 move it down by scroll_step. */
13274 if (arg_scroll_conservatively
)
13276 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13277 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
13278 else if (scroll_step
|| temp_scroll_step
)
13279 amount_to_scroll
= scroll_max
;
13282 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
13283 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13284 if (NUMBERP (aggressive
))
13286 double float_amount
= XFLOATINT (aggressive
) * height
;
13287 amount_to_scroll
= float_amount
;
13288 if (amount_to_scroll
== 0 && float_amount
> 0)
13289 amount_to_scroll
= 1;
13290 /* Don't let point enter the scroll margin near top of
13292 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13293 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13297 if (amount_to_scroll
<= 0)
13298 return SCROLLING_FAILED
;
13300 start_display (&it
, w
, startp
);
13301 if (arg_scroll_conservatively
<= scroll_limit
)
13302 move_it_vertically (&it
, amount_to_scroll
);
13305 /* Extra precision for users who set scroll-conservatively
13306 to a large number: make sure the amount we scroll
13307 the window start is never less than amount_to_scroll,
13308 which was computed as distance from window bottom to
13309 point. This matters when lines at window top and lines
13310 below window bottom have different height. */
13311 struct it it1
= it
;
13312 /* We use a temporary it1 because line_bottom_y can modify
13313 its argument, if it moves one line down; see there. */
13314 int start_y
= line_bottom_y (&it1
);
13317 move_it_by_lines (&it
, 1);
13319 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
13322 /* If STARTP is unchanged, move it down another screen line. */
13323 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13324 move_it_by_lines (&it
, 1);
13325 startp
= it
.current
.pos
;
13329 struct text_pos scroll_margin_pos
= startp
;
13331 /* See if point is inside the scroll margin at the top of the
13333 if (this_scroll_margin
)
13335 start_display (&it
, w
, startp
);
13336 move_it_vertically (&it
, this_scroll_margin
);
13337 scroll_margin_pos
= it
.current
.pos
;
13340 if (PT
< CHARPOS (scroll_margin_pos
))
13342 /* Point is in the scroll margin at the top of the window or
13343 above what is displayed in the window. */
13346 /* Compute the vertical distance from PT to the scroll
13347 margin position. Move as far as scroll_max allows, or
13348 one screenful, or 10 screen lines, whichever is largest.
13349 Give up if distance is greater than scroll_max. */
13350 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13351 start_display (&it
, w
, pos
);
13353 y_to_move
= max (it
.last_visible_y
,
13354 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
13355 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13357 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13358 dy
= it
.current_y
- y0
;
13359 if (dy
> scroll_max
)
13360 return SCROLLING_FAILED
;
13362 /* Compute new window start. */
13363 start_display (&it
, w
, startp
);
13365 if (arg_scroll_conservatively
)
13366 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
13367 max (scroll_step
, temp_scroll_step
));
13368 else if (scroll_step
|| temp_scroll_step
)
13369 amount_to_scroll
= scroll_max
;
13372 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
13373 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13374 if (NUMBERP (aggressive
))
13376 double float_amount
= XFLOATINT (aggressive
) * height
;
13377 amount_to_scroll
= float_amount
;
13378 if (amount_to_scroll
== 0 && float_amount
> 0)
13379 amount_to_scroll
= 1;
13380 amount_to_scroll
-=
13381 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
13382 /* Don't let point enter the scroll margin near
13383 bottom of the window. */
13384 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
13385 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
13389 if (amount_to_scroll
<= 0)
13390 return SCROLLING_FAILED
;
13392 move_it_vertically_backward (&it
, amount_to_scroll
);
13393 startp
= it
.current
.pos
;
13397 /* Run window scroll functions. */
13398 startp
= run_window_scroll_functions (window
, startp
);
13400 /* Display the window. Give up if new fonts are loaded, or if point
13402 if (!try_window (window
, startp
, 0))
13403 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13404 else if (w
->cursor
.vpos
< 0)
13406 clear_glyph_matrix (w
->desired_matrix
);
13407 rc
= SCROLLING_FAILED
;
13411 /* Maybe forget recorded base line for line number display. */
13412 if (!just_this_one_p
13413 || current_buffer
->clip_changed
13414 || BEG_UNCHANGED
< CHARPOS (startp
))
13415 w
->base_line_number
= Qnil
;
13417 /* If cursor ends up on a partially visible line,
13418 treat that as being off the bottom of the screen. */
13419 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
13420 /* It's possible that the cursor is on the first line of the
13421 buffer, which is partially obscured due to a vscroll
13422 (Bug#7537). In that case, avoid looping forever . */
13423 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
13425 clear_glyph_matrix (w
->desired_matrix
);
13426 ++extra_scroll_margin_lines
;
13429 rc
= SCROLLING_SUCCESS
;
13436 /* Compute a suitable window start for window W if display of W starts
13437 on a continuation line. Value is non-zero if a new window start
13440 The new window start will be computed, based on W's width, starting
13441 from the start of the continued line. It is the start of the
13442 screen line with the minimum distance from the old start W->start. */
13445 compute_window_start_on_continuation_line (struct window
*w
)
13447 struct text_pos pos
, start_pos
;
13448 int window_start_changed_p
= 0;
13450 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13452 /* If window start is on a continuation line... Window start may be
13453 < BEGV in case there's invisible text at the start of the
13454 buffer (M-x rmail, for example). */
13455 if (CHARPOS (start_pos
) > BEGV
13456 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13459 struct glyph_row
*row
;
13461 /* Handle the case that the window start is out of range. */
13462 if (CHARPOS (start_pos
) < BEGV
)
13463 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13464 else if (CHARPOS (start_pos
) > ZV
)
13465 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13467 /* Find the start of the continued line. This should be fast
13468 because scan_buffer is fast (newline cache). */
13469 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13470 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13471 row
, DEFAULT_FACE_ID
);
13472 reseat_at_previous_visible_line_start (&it
);
13474 /* If the line start is "too far" away from the window start,
13475 say it takes too much time to compute a new window start. */
13476 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13477 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13479 int min_distance
, distance
;
13481 /* Move forward by display lines to find the new window
13482 start. If window width was enlarged, the new start can
13483 be expected to be > the old start. If window width was
13484 decreased, the new window start will be < the old start.
13485 So, we're looking for the display line start with the
13486 minimum distance from the old window start. */
13487 pos
= it
.current
.pos
;
13488 min_distance
= INFINITY
;
13489 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13490 distance
< min_distance
)
13492 min_distance
= distance
;
13493 pos
= it
.current
.pos
;
13494 move_it_by_lines (&it
, 1);
13497 /* Set the window start there. */
13498 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13499 window_start_changed_p
= 1;
13503 return window_start_changed_p
;
13507 /* Try cursor movement in case text has not changed in window WINDOW,
13508 with window start STARTP. Value is
13510 CURSOR_MOVEMENT_SUCCESS if successful
13512 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13514 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13515 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13516 we want to scroll as if scroll-step were set to 1. See the code.
13518 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13519 which case we have to abort this redisplay, and adjust matrices
13524 CURSOR_MOVEMENT_SUCCESS
,
13525 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13526 CURSOR_MOVEMENT_MUST_SCROLL
,
13527 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13531 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
13533 struct window
*w
= XWINDOW (window
);
13534 struct frame
*f
= XFRAME (w
->frame
);
13535 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13538 if (inhibit_try_cursor_movement
)
13542 /* Handle case where text has not changed, only point, and it has
13543 not moved off the frame. */
13544 if (/* Point may be in this window. */
13545 PT
>= CHARPOS (startp
)
13546 /* Selective display hasn't changed. */
13547 && !current_buffer
->clip_changed
13548 /* Function force-mode-line-update is used to force a thorough
13549 redisplay. It sets either windows_or_buffers_changed or
13550 update_mode_lines. So don't take a shortcut here for these
13552 && !update_mode_lines
13553 && !windows_or_buffers_changed
13554 && !cursor_type_changed
13555 /* Can't use this case if highlighting a region. When a
13556 region exists, cursor movement has to do more than just
13558 && !(!NILP (Vtransient_mark_mode
)
13559 && !NILP (BVAR (current_buffer
, mark_active
)))
13560 && NILP (w
->region_showing
)
13561 && NILP (Vshow_trailing_whitespace
)
13562 /* Right after splitting windows, last_point may be nil. */
13563 && INTEGERP (w
->last_point
)
13564 /* This code is not used for mini-buffer for the sake of the case
13565 of redisplaying to replace an echo area message; since in
13566 that case the mini-buffer contents per se are usually
13567 unchanged. This code is of no real use in the mini-buffer
13568 since the handling of this_line_start_pos, etc., in redisplay
13569 handles the same cases. */
13570 && !EQ (window
, minibuf_window
)
13571 /* When splitting windows or for new windows, it happens that
13572 redisplay is called with a nil window_end_vpos or one being
13573 larger than the window. This should really be fixed in
13574 window.c. I don't have this on my list, now, so we do
13575 approximately the same as the old redisplay code. --gerd. */
13576 && INTEGERP (w
->window_end_vpos
)
13577 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13578 && (FRAME_WINDOW_P (f
)
13579 || !overlay_arrow_in_current_buffer_p ()))
13581 int this_scroll_margin
, top_scroll_margin
;
13582 struct glyph_row
*row
= NULL
;
13585 debug_method_add (w
, "cursor movement");
13588 /* Scroll if point within this distance from the top or bottom
13589 of the window. This is a pixel value. */
13590 if (scroll_margin
> 0)
13592 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13593 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13596 this_scroll_margin
= 0;
13598 top_scroll_margin
= this_scroll_margin
;
13599 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13600 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13602 /* Start with the row the cursor was displayed during the last
13603 not paused redisplay. Give up if that row is not valid. */
13604 if (w
->last_cursor
.vpos
< 0
13605 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13606 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13609 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13610 if (row
->mode_line_p
)
13612 if (!row
->enabled_p
)
13613 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13616 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13618 int scroll_p
= 0, must_scroll
= 0;
13619 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13621 if (PT
> XFASTINT (w
->last_point
))
13623 /* Point has moved forward. */
13624 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13625 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13627 xassert (row
->enabled_p
);
13631 /* If the end position of a row equals the start
13632 position of the next row, and PT is at that position,
13633 we would rather display cursor in the next line. */
13634 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13635 && MATRIX_ROW_END_CHARPOS (row
) == PT
13636 && row
< w
->current_matrix
->rows
13637 + w
->current_matrix
->nrows
- 1
13638 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
13639 && !cursor_row_p (row
))
13642 /* If within the scroll margin, scroll. Note that
13643 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13644 the next line would be drawn, and that
13645 this_scroll_margin can be zero. */
13646 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13647 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13648 /* Line is completely visible last line in window
13649 and PT is to be set in the next line. */
13650 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13651 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13652 && !row
->ends_at_zv_p
13653 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13656 else if (PT
< XFASTINT (w
->last_point
))
13658 /* Cursor has to be moved backward. Note that PT >=
13659 CHARPOS (startp) because of the outer if-statement. */
13660 while (!row
->mode_line_p
13661 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13662 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13663 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13664 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13665 row
> w
->current_matrix
->rows
13666 && (row
-1)->ends_in_newline_from_string_p
))))
13667 && (row
->y
> top_scroll_margin
13668 || CHARPOS (startp
) == BEGV
))
13670 xassert (row
->enabled_p
);
13674 /* Consider the following case: Window starts at BEGV,
13675 there is invisible, intangible text at BEGV, so that
13676 display starts at some point START > BEGV. It can
13677 happen that we are called with PT somewhere between
13678 BEGV and START. Try to handle that case. */
13679 if (row
< w
->current_matrix
->rows
13680 || row
->mode_line_p
)
13682 row
= w
->current_matrix
->rows
;
13683 if (row
->mode_line_p
)
13687 /* Due to newlines in overlay strings, we may have to
13688 skip forward over overlay strings. */
13689 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13690 && MATRIX_ROW_END_CHARPOS (row
) == PT
13691 && !cursor_row_p (row
))
13694 /* If within the scroll margin, scroll. */
13695 if (row
->y
< top_scroll_margin
13696 && CHARPOS (startp
) != BEGV
)
13701 /* Cursor did not move. So don't scroll even if cursor line
13702 is partially visible, as it was so before. */
13703 rc
= CURSOR_MOVEMENT_SUCCESS
;
13706 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13707 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13709 /* if PT is not in the glyph row, give up. */
13710 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13713 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13714 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
13716 /* If rows are bidi-reordered and point moved, back up
13717 until we find a row that does not belong to a
13718 continuation line. This is because we must consider
13719 all rows of a continued line as candidates for the
13720 new cursor positioning, since row start and end
13721 positions change non-linearly with vertical position
13723 /* FIXME: Revisit this when glyph ``spilling'' in
13724 continuation lines' rows is implemented for
13725 bidi-reordered rows. */
13726 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
13728 xassert (row
->enabled_p
);
13730 /* If we hit the beginning of the displayed portion
13731 without finding the first row of a continued
13733 if (row
<= w
->current_matrix
->rows
)
13735 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13743 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13744 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13745 && make_cursor_line_fully_visible_p
)
13747 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13748 && !row
->ends_at_zv_p
13749 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13750 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13751 else if (row
->height
> window_box_height (w
))
13753 /* If we end up in a partially visible line, let's
13754 make it fully visible, except when it's taller
13755 than the window, in which case we can't do much
13758 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13762 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13763 if (!cursor_row_fully_visible_p (w
, 0, 1))
13764 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13766 rc
= CURSOR_MOVEMENT_SUCCESS
;
13770 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13771 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13772 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
13774 /* With bidi-reordered rows, there could be more than
13775 one candidate row whose start and end positions
13776 occlude point. We need to let set_cursor_from_row
13777 find the best candidate. */
13778 /* FIXME: Revisit this when glyph ``spilling'' in
13779 continuation lines' rows is implemented for
13780 bidi-reordered rows. */
13785 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
13786 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13787 && cursor_row_p (row
))
13788 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
13790 /* As soon as we've found the first suitable row
13791 whose ends_at_zv_p flag is set, we are done. */
13793 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
13795 rc
= CURSOR_MOVEMENT_SUCCESS
;
13800 while ((MATRIX_ROW_CONTINUATION_LINE_P (row
)
13801 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
13802 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13803 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
13804 /* If we didn't find any candidate rows, or exited the
13805 loop before all the candidates were examined, signal
13806 to the caller that this method failed. */
13807 if (rc
!= CURSOR_MOVEMENT_SUCCESS
13808 && (!rv
|| MATRIX_ROW_CONTINUATION_LINE_P (row
)))
13809 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13811 rc
= CURSOR_MOVEMENT_SUCCESS
;
13817 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13819 rc
= CURSOR_MOVEMENT_SUCCESS
;
13824 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13825 && MATRIX_ROW_START_CHARPOS (row
) == PT
13826 && cursor_row_p (row
));
13834 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
13838 set_vertical_scroll_bar (struct window
*w
)
13840 EMACS_INT start
, end
, whole
;
13842 /* Calculate the start and end positions for the current window.
13843 At some point, it would be nice to choose between scrollbars
13844 which reflect the whole buffer size, with special markers
13845 indicating narrowing, and scrollbars which reflect only the
13848 Note that mini-buffers sometimes aren't displaying any text. */
13849 if (!MINI_WINDOW_P (w
)
13850 || (w
== XWINDOW (minibuf_window
)
13851 && NILP (echo_area_buffer
[0])))
13853 struct buffer
*buf
= XBUFFER (w
->buffer
);
13854 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13855 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13856 /* I don't think this is guaranteed to be right. For the
13857 moment, we'll pretend it is. */
13858 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13862 if (whole
< (end
- start
))
13863 whole
= end
- start
;
13866 start
= end
= whole
= 0;
13868 /* Indicate what this scroll bar ought to be displaying now. */
13869 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13870 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13871 (w
, end
- start
, whole
, start
);
13875 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13876 selected_window is redisplayed.
13878 We can return without actually redisplaying the window if
13879 fonts_changed_p is nonzero. In that case, redisplay_internal will
13883 redisplay_window (Lisp_Object window
, int just_this_one_p
)
13885 struct window
*w
= XWINDOW (window
);
13886 struct frame
*f
= XFRAME (w
->frame
);
13887 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13888 struct buffer
*old
= current_buffer
;
13889 struct text_pos lpoint
, opoint
, startp
;
13890 int update_mode_line
;
13893 /* Record it now because it's overwritten. */
13894 int current_matrix_up_to_date_p
= 0;
13895 int used_current_matrix_p
= 0;
13896 /* This is less strict than current_matrix_up_to_date_p.
13897 It indictes that the buffer contents and narrowing are unchanged. */
13898 int buffer_unchanged_p
= 0;
13899 int temp_scroll_step
= 0;
13900 int count
= SPECPDL_INDEX ();
13902 int centering_position
= -1;
13903 int last_line_misfit
= 0;
13904 EMACS_INT beg_unchanged
, end_unchanged
;
13906 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13909 /* W must be a leaf window here. */
13910 xassert (!NILP (w
->buffer
));
13912 *w
->desired_matrix
->method
= 0;
13916 reconsider_clip_changes (w
, buffer
);
13918 /* Has the mode line to be updated? */
13919 update_mode_line
= (!NILP (w
->update_mode_line
)
13920 || update_mode_lines
13921 || buffer
->clip_changed
13922 || buffer
->prevent_redisplay_optimizations_p
);
13924 if (MINI_WINDOW_P (w
))
13926 if (w
== XWINDOW (echo_area_window
)
13927 && !NILP (echo_area_buffer
[0]))
13929 if (update_mode_line
)
13930 /* We may have to update a tty frame's menu bar or a
13931 tool-bar. Example `M-x C-h C-h C-g'. */
13932 goto finish_menu_bars
;
13934 /* We've already displayed the echo area glyphs in this window. */
13935 goto finish_scroll_bars
;
13937 else if ((w
!= XWINDOW (minibuf_window
)
13938 || minibuf_level
== 0)
13939 /* When buffer is nonempty, redisplay window normally. */
13940 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13941 /* Quail displays non-mini buffers in minibuffer window.
13942 In that case, redisplay the window normally. */
13943 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13945 /* W is a mini-buffer window, but it's not active, so clear
13947 int yb
= window_text_bottom_y (w
);
13948 struct glyph_row
*row
;
13951 for (y
= 0, row
= w
->desired_matrix
->rows
;
13953 y
+= row
->height
, ++row
)
13954 blank_row (w
, row
, y
);
13955 goto finish_scroll_bars
;
13958 clear_glyph_matrix (w
->desired_matrix
);
13961 /* Otherwise set up data on this window; select its buffer and point
13963 /* Really select the buffer, for the sake of buffer-local
13965 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13967 current_matrix_up_to_date_p
13968 = (!NILP (w
->window_end_valid
)
13969 && !current_buffer
->clip_changed
13970 && !current_buffer
->prevent_redisplay_optimizations_p
13971 && XFASTINT (w
->last_modified
) >= MODIFF
13972 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13974 /* Run the window-bottom-change-functions
13975 if it is possible that the text on the screen has changed
13976 (either due to modification of the text, or any other reason). */
13977 if (!current_matrix_up_to_date_p
13978 && !NILP (Vwindow_text_change_functions
))
13980 safe_run_hooks (Qwindow_text_change_functions
);
13984 beg_unchanged
= BEG_UNCHANGED
;
13985 end_unchanged
= END_UNCHANGED
;
13987 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13989 specbind (Qinhibit_point_motion_hooks
, Qt
);
13992 = (!NILP (w
->window_end_valid
)
13993 && !current_buffer
->clip_changed
13994 && XFASTINT (w
->last_modified
) >= MODIFF
13995 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13997 /* When windows_or_buffers_changed is non-zero, we can't rely on
13998 the window end being valid, so set it to nil there. */
13999 if (windows_or_buffers_changed
)
14001 /* If window starts on a continuation line, maybe adjust the
14002 window start in case the window's width changed. */
14003 if (XMARKER (w
->start
)->buffer
== current_buffer
)
14004 compute_window_start_on_continuation_line (w
);
14006 w
->window_end_valid
= Qnil
;
14009 /* Some sanity checks. */
14010 CHECK_WINDOW_END (w
);
14011 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
14013 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
14016 /* If %c is in mode line, update it if needed. */
14017 if (!NILP (w
->column_number_displayed
)
14018 /* This alternative quickly identifies a common case
14019 where no change is needed. */
14020 && !(PT
== XFASTINT (w
->last_point
)
14021 && XFASTINT (w
->last_modified
) >= MODIFF
14022 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
14023 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
14024 update_mode_line
= 1;
14026 /* Count number of windows showing the selected buffer. An indirect
14027 buffer counts as its base buffer. */
14028 if (!just_this_one_p
)
14030 struct buffer
*current_base
, *window_base
;
14031 current_base
= current_buffer
;
14032 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
14033 if (current_base
->base_buffer
)
14034 current_base
= current_base
->base_buffer
;
14035 if (window_base
->base_buffer
)
14036 window_base
= window_base
->base_buffer
;
14037 if (current_base
== window_base
)
14041 /* Point refers normally to the selected window. For any other
14042 window, set up appropriate value. */
14043 if (!EQ (window
, selected_window
))
14045 EMACS_INT new_pt
= XMARKER (w
->pointm
)->charpos
;
14046 EMACS_INT new_pt_byte
= marker_byte_position (w
->pointm
);
14050 new_pt_byte
= BEGV_BYTE
;
14051 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
14053 else if (new_pt
> (ZV
- 1))
14056 new_pt_byte
= ZV_BYTE
;
14057 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
14060 /* We don't use SET_PT so that the point-motion hooks don't run. */
14061 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
14064 /* If any of the character widths specified in the display table
14065 have changed, invalidate the width run cache. It's true that
14066 this may be a bit late to catch such changes, but the rest of
14067 redisplay goes (non-fatally) haywire when the display table is
14068 changed, so why should we worry about doing any better? */
14069 if (current_buffer
->width_run_cache
)
14071 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
14073 if (! disptab_matches_widthtab (disptab
,
14074 XVECTOR (BVAR (current_buffer
, width_table
))))
14076 invalidate_region_cache (current_buffer
,
14077 current_buffer
->width_run_cache
,
14079 recompute_width_table (current_buffer
, disptab
);
14083 /* If window-start is screwed up, choose a new one. */
14084 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
14087 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14089 /* If someone specified a new starting point but did not insist,
14090 check whether it can be used. */
14091 if (!NILP (w
->optional_new_start
)
14092 && CHARPOS (startp
) >= BEGV
14093 && CHARPOS (startp
) <= ZV
)
14095 w
->optional_new_start
= Qnil
;
14096 start_display (&it
, w
, startp
);
14097 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
14098 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14099 if (IT_CHARPOS (it
) == PT
)
14100 w
->force_start
= Qt
;
14101 /* IT may overshoot PT if text at PT is invisible. */
14102 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
14103 w
->force_start
= Qt
;
14108 /* Handle case where place to start displaying has been specified,
14109 unless the specified location is outside the accessible range. */
14110 if (!NILP (w
->force_start
)
14111 || w
->frozen_window_start_p
)
14113 /* We set this later on if we have to adjust point. */
14116 w
->force_start
= Qnil
;
14118 w
->window_end_valid
= Qnil
;
14120 /* Forget any recorded base line for line number display. */
14121 if (!buffer_unchanged_p
)
14122 w
->base_line_number
= Qnil
;
14124 /* Redisplay the mode line. Select the buffer properly for that.
14125 Also, run the hook window-scroll-functions
14126 because we have scrolled. */
14127 /* Note, we do this after clearing force_start because
14128 if there's an error, it is better to forget about force_start
14129 than to get into an infinite loop calling the hook functions
14130 and having them get more errors. */
14131 if (!update_mode_line
14132 || ! NILP (Vwindow_scroll_functions
))
14134 update_mode_line
= 1;
14135 w
->update_mode_line
= Qt
;
14136 startp
= run_window_scroll_functions (window
, startp
);
14139 w
->last_modified
= make_number (0);
14140 w
->last_overlay_modified
= make_number (0);
14141 if (CHARPOS (startp
) < BEGV
)
14142 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14143 else if (CHARPOS (startp
) > ZV
)
14144 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14146 /* Redisplay, then check if cursor has been set during the
14147 redisplay. Give up if new fonts were loaded. */
14148 /* We used to issue a CHECK_MARGINS argument to try_window here,
14149 but this causes scrolling to fail when point begins inside
14150 the scroll margin (bug#148) -- cyd */
14151 if (!try_window (window
, startp
, 0))
14153 w
->force_start
= Qt
;
14154 clear_glyph_matrix (w
->desired_matrix
);
14155 goto need_larger_matrices
;
14158 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14160 /* If point does not appear, try to move point so it does
14161 appear. The desired matrix has been built above, so we
14162 can use it here. */
14163 new_vpos
= window_box_height (w
) / 2;
14166 if (!cursor_row_fully_visible_p (w
, 0, 0))
14168 /* Point does appear, but on a line partly visible at end of window.
14169 Move it back to a fully-visible line. */
14170 new_vpos
= window_box_height (w
);
14173 /* If we need to move point for either of the above reasons,
14174 now actually do it. */
14177 struct glyph_row
*row
;
14179 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14180 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14183 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14184 MATRIX_ROW_START_BYTEPOS (row
));
14186 if (w
!= XWINDOW (selected_window
))
14187 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14188 else if (current_buffer
== old
)
14189 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14191 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14193 /* If we are highlighting the region, then we just changed
14194 the region, so redisplay to show it. */
14195 if (!NILP (Vtransient_mark_mode
)
14196 && !NILP (BVAR (current_buffer
, mark_active
)))
14198 clear_glyph_matrix (w
->desired_matrix
);
14199 if (!try_window (window
, startp
, 0))
14200 goto need_larger_matrices
;
14205 debug_method_add (w
, "forced window start");
14210 /* Handle case where text has not changed, only point, and it has
14211 not moved off the frame, and we are not retrying after hscroll.
14212 (current_matrix_up_to_date_p is nonzero when retrying.) */
14213 if (current_matrix_up_to_date_p
14214 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14215 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14219 case CURSOR_MOVEMENT_SUCCESS
:
14220 used_current_matrix_p
= 1;
14223 case CURSOR_MOVEMENT_MUST_SCROLL
:
14224 goto try_to_scroll
;
14230 /* If current starting point was originally the beginning of a line
14231 but no longer is, find a new starting point. */
14232 else if (!NILP (w
->start_at_line_beg
)
14233 && !(CHARPOS (startp
) <= BEGV
14234 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14237 debug_method_add (w
, "recenter 1");
14242 /* Try scrolling with try_window_id. Value is > 0 if update has
14243 been done, it is -1 if we know that the same window start will
14244 not work. It is 0 if unsuccessful for some other reason. */
14245 else if ((tem
= try_window_id (w
)) != 0)
14248 debug_method_add (w
, "try_window_id %d", tem
);
14251 if (fonts_changed_p
)
14252 goto need_larger_matrices
;
14256 /* Otherwise try_window_id has returned -1 which means that we
14257 don't want the alternative below this comment to execute. */
14259 else if (CHARPOS (startp
) >= BEGV
14260 && CHARPOS (startp
) <= ZV
14261 && PT
>= CHARPOS (startp
)
14262 && (CHARPOS (startp
) < ZV
14263 /* Avoid starting at end of buffer. */
14264 || CHARPOS (startp
) == BEGV
14265 || (XFASTINT (w
->last_modified
) >= MODIFF
14266 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14269 /* If first window line is a continuation line, and window start
14270 is inside the modified region, but the first change is before
14271 current window start, we must select a new window start.
14273 However, if this is the result of a down-mouse event (e.g. by
14274 extending the mouse-drag-overlay), we don't want to select a
14275 new window start, since that would change the position under
14276 the mouse, resulting in an unwanted mouse-movement rather
14277 than a simple mouse-click. */
14278 if (NILP (w
->start_at_line_beg
)
14279 && NILP (do_mouse_tracking
)
14280 && CHARPOS (startp
) > BEGV
14281 && CHARPOS (startp
) > BEG
+ beg_unchanged
14282 && CHARPOS (startp
) <= Z
- end_unchanged
14283 /* Even if w->start_at_line_beg is nil, a new window may
14284 start at a line_beg, since that's how set_buffer_window
14285 sets it. So, we need to check the return value of
14286 compute_window_start_on_continuation_line. (See also
14288 && XMARKER (w
->start
)->buffer
== current_buffer
14289 && compute_window_start_on_continuation_line (w
))
14291 w
->force_start
= Qt
;
14292 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14297 debug_method_add (w
, "same window start");
14300 /* Try to redisplay starting at same place as before.
14301 If point has not moved off frame, accept the results. */
14302 if (!current_matrix_up_to_date_p
14303 /* Don't use try_window_reusing_current_matrix in this case
14304 because a window scroll function can have changed the
14306 || !NILP (Vwindow_scroll_functions
)
14307 || MINI_WINDOW_P (w
)
14308 || !(used_current_matrix_p
14309 = try_window_reusing_current_matrix (w
)))
14311 IF_DEBUG (debug_method_add (w
, "1"));
14312 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
14313 /* -1 means we need to scroll.
14314 0 means we need new matrices, but fonts_changed_p
14315 is set in that case, so we will detect it below. */
14316 goto try_to_scroll
;
14319 if (fonts_changed_p
)
14320 goto need_larger_matrices
;
14322 if (w
->cursor
.vpos
>= 0)
14324 if (!just_this_one_p
14325 || current_buffer
->clip_changed
14326 || BEG_UNCHANGED
< CHARPOS (startp
))
14327 /* Forget any recorded base line for line number display. */
14328 w
->base_line_number
= Qnil
;
14330 if (!cursor_row_fully_visible_p (w
, 1, 0))
14332 clear_glyph_matrix (w
->desired_matrix
);
14333 last_line_misfit
= 1;
14335 /* Drop through and scroll. */
14340 clear_glyph_matrix (w
->desired_matrix
);
14345 w
->last_modified
= make_number (0);
14346 w
->last_overlay_modified
= make_number (0);
14348 /* Redisplay the mode line. Select the buffer properly for that. */
14349 if (!update_mode_line
)
14351 update_mode_line
= 1;
14352 w
->update_mode_line
= Qt
;
14355 /* Try to scroll by specified few lines. */
14356 if ((scroll_conservatively
14357 || emacs_scroll_step
14358 || temp_scroll_step
14359 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
14360 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
14361 && CHARPOS (startp
) >= BEGV
14362 && CHARPOS (startp
) <= ZV
)
14364 /* The function returns -1 if new fonts were loaded, 1 if
14365 successful, 0 if not successful. */
14366 int ss
= try_scrolling (window
, just_this_one_p
,
14367 scroll_conservatively
,
14369 temp_scroll_step
, last_line_misfit
);
14372 case SCROLLING_SUCCESS
:
14375 case SCROLLING_NEED_LARGER_MATRICES
:
14376 goto need_larger_matrices
;
14378 case SCROLLING_FAILED
:
14386 /* Finally, just choose a place to start which positions point
14387 according to user preferences. */
14392 debug_method_add (w
, "recenter");
14395 /* w->vscroll = 0; */
14397 /* Forget any previously recorded base line for line number display. */
14398 if (!buffer_unchanged_p
)
14399 w
->base_line_number
= Qnil
;
14401 /* Determine the window start relative to point. */
14402 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14403 it
.current_y
= it
.last_visible_y
;
14404 if (centering_position
< 0)
14408 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14410 EMACS_INT margin_pos
= CHARPOS (startp
);
14412 Lisp_Object aggressive
;
14414 /* If there is a scroll margin at the top of the window, find
14415 its character position. */
14417 /* Cannot call start_display if startp is not in the
14418 accessible region of the buffer. This can happen when we
14419 have just switched to a different buffer and/or changed
14420 its restriction. In that case, startp is initialized to
14421 the character position 1 (BEG) because we did not yet
14422 have chance to display the buffer even once. */
14423 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
14427 start_display (&it1
, w
, startp
);
14428 move_it_vertically (&it1
, margin
);
14429 margin_pos
= IT_CHARPOS (it1
);
14431 scrolling_up
= PT
> margin_pos
;
14434 ? BVAR (current_buffer
, scroll_up_aggressively
)
14435 : BVAR (current_buffer
, scroll_down_aggressively
);
14437 if (!MINI_WINDOW_P (w
)
14438 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
14442 /* Setting scroll-conservatively overrides
14443 scroll-*-aggressively. */
14444 if (!scroll_conservatively
&& NUMBERP (aggressive
))
14446 double float_amount
= XFLOATINT (aggressive
);
14448 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
14449 if (pt_offset
== 0 && float_amount
> 0)
14454 /* Compute how much to move the window start backward from
14455 point so that point will be displayed where the user
14459 centering_position
= it
.last_visible_y
;
14461 centering_position
-= pt_offset
;
14462 centering_position
-=
14463 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0));
14464 /* Don't let point enter the scroll margin near top of
14466 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
14467 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
14470 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
14473 /* Set the window start half the height of the window backward
14475 centering_position
= window_box_height (w
) / 2;
14477 move_it_vertically_backward (&it
, centering_position
);
14479 xassert (IT_CHARPOS (it
) >= BEGV
);
14481 /* The function move_it_vertically_backward may move over more
14482 than the specified y-distance. If it->w is small, e.g. a
14483 mini-buffer window, we may end up in front of the window's
14484 display area. Start displaying at the start of the line
14485 containing PT in this case. */
14486 if (it
.current_y
<= 0)
14488 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14489 move_it_vertically_backward (&it
, 0);
14493 it
.current_x
= it
.hpos
= 0;
14495 /* Set the window start position here explicitly, to avoid an
14496 infinite loop in case the functions in window-scroll-functions
14498 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14500 /* Run scroll hooks. */
14501 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14503 /* Redisplay the window. */
14504 if (!current_matrix_up_to_date_p
14505 || windows_or_buffers_changed
14506 || cursor_type_changed
14507 /* Don't use try_window_reusing_current_matrix in this case
14508 because it can have changed the buffer. */
14509 || !NILP (Vwindow_scroll_functions
)
14510 || !just_this_one_p
14511 || MINI_WINDOW_P (w
)
14512 || !(used_current_matrix_p
14513 = try_window_reusing_current_matrix (w
)))
14514 try_window (window
, startp
, 0);
14516 /* If new fonts have been loaded (due to fontsets), give up. We
14517 have to start a new redisplay since we need to re-adjust glyph
14519 if (fonts_changed_p
)
14520 goto need_larger_matrices
;
14522 /* If cursor did not appear assume that the middle of the window is
14523 in the first line of the window. Do it again with the next line.
14524 (Imagine a window of height 100, displaying two lines of height
14525 60. Moving back 50 from it->last_visible_y will end in the first
14527 if (w
->cursor
.vpos
< 0)
14529 if (!NILP (w
->window_end_valid
)
14530 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14532 clear_glyph_matrix (w
->desired_matrix
);
14533 move_it_by_lines (&it
, 1);
14534 try_window (window
, it
.current
.pos
, 0);
14536 else if (PT
< IT_CHARPOS (it
))
14538 clear_glyph_matrix (w
->desired_matrix
);
14539 move_it_by_lines (&it
, -1);
14540 try_window (window
, it
.current
.pos
, 0);
14544 /* Not much we can do about it. */
14548 /* Consider the following case: Window starts at BEGV, there is
14549 invisible, intangible text at BEGV, so that display starts at
14550 some point START > BEGV. It can happen that we are called with
14551 PT somewhere between BEGV and START. Try to handle that case. */
14552 if (w
->cursor
.vpos
< 0)
14554 struct glyph_row
*row
= w
->current_matrix
->rows
;
14555 if (row
->mode_line_p
)
14557 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14560 if (!cursor_row_fully_visible_p (w
, 0, 0))
14562 /* If vscroll is enabled, disable it and try again. */
14566 clear_glyph_matrix (w
->desired_matrix
);
14570 /* If centering point failed to make the whole line visible,
14571 put point at the top instead. That has to make the whole line
14572 visible, if it can be done. */
14573 if (centering_position
== 0)
14576 clear_glyph_matrix (w
->desired_matrix
);
14577 centering_position
= 0;
14583 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14584 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14585 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14588 /* Display the mode line, if we must. */
14589 if ((update_mode_line
14590 /* If window not full width, must redo its mode line
14591 if (a) the window to its side is being redone and
14592 (b) we do a frame-based redisplay. This is a consequence
14593 of how inverted lines are drawn in frame-based redisplay. */
14594 || (!just_this_one_p
14595 && !FRAME_WINDOW_P (f
)
14596 && !WINDOW_FULL_WIDTH_P (w
))
14597 /* Line number to display. */
14598 || INTEGERP (w
->base_line_pos
)
14599 /* Column number is displayed and different from the one displayed. */
14600 || (!NILP (w
->column_number_displayed
)
14601 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
14602 /* This means that the window has a mode line. */
14603 && (WINDOW_WANTS_MODELINE_P (w
)
14604 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14606 display_mode_lines (w
);
14608 /* If mode line height has changed, arrange for a thorough
14609 immediate redisplay using the correct mode line height. */
14610 if (WINDOW_WANTS_MODELINE_P (w
)
14611 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14613 fonts_changed_p
= 1;
14614 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14615 = DESIRED_MODE_LINE_HEIGHT (w
);
14618 /* If header line height has changed, arrange for a thorough
14619 immediate redisplay using the correct header line height. */
14620 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14621 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14623 fonts_changed_p
= 1;
14624 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14625 = DESIRED_HEADER_LINE_HEIGHT (w
);
14628 if (fonts_changed_p
)
14629 goto need_larger_matrices
;
14632 if (!line_number_displayed
14633 && !BUFFERP (w
->base_line_pos
))
14635 w
->base_line_pos
= Qnil
;
14636 w
->base_line_number
= Qnil
;
14641 /* When we reach a frame's selected window, redo the frame's menu bar. */
14642 if (update_mode_line
14643 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14645 int redisplay_menu_p
= 0;
14647 if (FRAME_WINDOW_P (f
))
14649 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14650 || defined (HAVE_NS) || defined (USE_GTK)
14651 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
14653 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14657 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14659 if (redisplay_menu_p
)
14660 display_menu_bar (w
);
14662 #ifdef HAVE_WINDOW_SYSTEM
14663 if (FRAME_WINDOW_P (f
))
14665 #if defined (USE_GTK) || defined (HAVE_NS)
14666 if (FRAME_EXTERNAL_TOOL_BAR (f
))
14667 redisplay_tool_bar (f
);
14669 if (WINDOWP (f
->tool_bar_window
)
14670 && (FRAME_TOOL_BAR_LINES (f
) > 0
14671 || !NILP (Vauto_resize_tool_bars
))
14672 && redisplay_tool_bar (f
))
14673 ignore_mouse_drag_p
= 1;
14679 #ifdef HAVE_WINDOW_SYSTEM
14680 if (FRAME_WINDOW_P (f
)
14681 && update_window_fringes (w
, (just_this_one_p
14682 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
14683 || w
->pseudo_window_p
)))
14687 if (draw_window_fringes (w
, 1))
14688 x_draw_vertical_border (w
);
14692 #endif /* HAVE_WINDOW_SYSTEM */
14694 /* We go to this label, with fonts_changed_p nonzero,
14695 if it is necessary to try again using larger glyph matrices.
14696 We have to redeem the scroll bar even in this case,
14697 because the loop in redisplay_internal expects that. */
14698 need_larger_matrices
:
14700 finish_scroll_bars
:
14702 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14704 /* Set the thumb's position and size. */
14705 set_vertical_scroll_bar (w
);
14707 /* Note that we actually used the scroll bar attached to this
14708 window, so it shouldn't be deleted at the end of redisplay. */
14709 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14710 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14713 /* Restore current_buffer and value of point in it. The window
14714 update may have changed the buffer, so first make sure `opoint'
14715 is still valid (Bug#6177). */
14716 if (CHARPOS (opoint
) < BEGV
)
14717 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
14718 else if (CHARPOS (opoint
) > ZV
)
14719 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
14721 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14723 set_buffer_internal_1 (old
);
14724 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14725 shorter. This can be caused by log truncation in *Messages*. */
14726 if (CHARPOS (lpoint
) <= ZV
)
14727 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14729 unbind_to (count
, Qnil
);
14733 /* Build the complete desired matrix of WINDOW with a window start
14734 buffer position POS.
14736 Value is 1 if successful. It is zero if fonts were loaded during
14737 redisplay which makes re-adjusting glyph matrices necessary, and -1
14738 if point would appear in the scroll margins.
14739 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
14740 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
14744 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
14746 struct window
*w
= XWINDOW (window
);
14748 struct glyph_row
*last_text_row
= NULL
;
14749 struct frame
*f
= XFRAME (w
->frame
);
14751 /* Make POS the new window start. */
14752 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14754 /* Mark cursor position as unknown. No overlay arrow seen. */
14755 w
->cursor
.vpos
= -1;
14756 overlay_arrow_seen
= 0;
14758 /* Initialize iterator and info to start at POS. */
14759 start_display (&it
, w
, pos
);
14761 /* Display all lines of W. */
14762 while (it
.current_y
< it
.last_visible_y
)
14764 if (display_line (&it
))
14765 last_text_row
= it
.glyph_row
- 1;
14766 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
14770 /* Don't let the cursor end in the scroll margins. */
14771 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
14772 && !MINI_WINDOW_P (w
))
14774 int this_scroll_margin
;
14776 if (scroll_margin
> 0)
14778 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14779 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14782 this_scroll_margin
= 0;
14784 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14785 && w
->cursor
.y
< this_scroll_margin
14786 && CHARPOS (pos
) > BEGV
14787 && IT_CHARPOS (it
) < ZV
)
14788 /* rms: considering make_cursor_line_fully_visible_p here
14789 seems to give wrong results. We don't want to recenter
14790 when the last line is partly visible, we want to allow
14791 that case to be handled in the usual way. */
14792 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14794 w
->cursor
.vpos
= -1;
14795 clear_glyph_matrix (w
->desired_matrix
);
14800 /* If bottom moved off end of frame, change mode line percentage. */
14801 if (XFASTINT (w
->window_end_pos
) <= 0
14802 && Z
!= IT_CHARPOS (it
))
14803 w
->update_mode_line
= Qt
;
14805 /* Set window_end_pos to the offset of the last character displayed
14806 on the window from the end of current_buffer. Set
14807 window_end_vpos to its row number. */
14810 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14811 w
->window_end_bytepos
14812 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14814 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14816 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14817 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14818 ->displays_text_p
);
14822 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14823 w
->window_end_pos
= make_number (Z
- ZV
);
14824 w
->window_end_vpos
= make_number (0);
14827 /* But that is not valid info until redisplay finishes. */
14828 w
->window_end_valid
= Qnil
;
14834 /************************************************************************
14835 Window redisplay reusing current matrix when buffer has not changed
14836 ************************************************************************/
14838 /* Try redisplay of window W showing an unchanged buffer with a
14839 different window start than the last time it was displayed by
14840 reusing its current matrix. Value is non-zero if successful.
14841 W->start is the new window start. */
14844 try_window_reusing_current_matrix (struct window
*w
)
14846 struct frame
*f
= XFRAME (w
->frame
);
14847 struct glyph_row
*bottom_row
;
14850 struct text_pos start
, new_start
;
14851 int nrows_scrolled
, i
;
14852 struct glyph_row
*last_text_row
;
14853 struct glyph_row
*last_reused_text_row
;
14854 struct glyph_row
*start_row
;
14855 int start_vpos
, min_y
, max_y
;
14858 if (inhibit_try_window_reusing
)
14862 if (/* This function doesn't handle terminal frames. */
14863 !FRAME_WINDOW_P (f
)
14864 /* Don't try to reuse the display if windows have been split
14866 || windows_or_buffers_changed
14867 || cursor_type_changed
)
14870 /* Can't do this if region may have changed. */
14871 if ((!NILP (Vtransient_mark_mode
)
14872 && !NILP (BVAR (current_buffer
, mark_active
)))
14873 || !NILP (w
->region_showing
)
14874 || !NILP (Vshow_trailing_whitespace
))
14877 /* If top-line visibility has changed, give up. */
14878 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14879 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14882 /* Give up if old or new display is scrolled vertically. We could
14883 make this function handle this, but right now it doesn't. */
14884 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14885 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14888 /* The variable new_start now holds the new window start. The old
14889 start `start' can be determined from the current matrix. */
14890 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14891 start
= start_row
->minpos
;
14892 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14894 /* Clear the desired matrix for the display below. */
14895 clear_glyph_matrix (w
->desired_matrix
);
14897 if (CHARPOS (new_start
) <= CHARPOS (start
))
14899 /* Don't use this method if the display starts with an ellipsis
14900 displayed for invisible text. It's not easy to handle that case
14901 below, and it's certainly not worth the effort since this is
14902 not a frequent case. */
14903 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14906 IF_DEBUG (debug_method_add (w
, "twu1"));
14908 /* Display up to a row that can be reused. The variable
14909 last_text_row is set to the last row displayed that displays
14910 text. Note that it.vpos == 0 if or if not there is a
14911 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14912 start_display (&it
, w
, new_start
);
14913 w
->cursor
.vpos
= -1;
14914 last_text_row
= last_reused_text_row
= NULL
;
14916 while (it
.current_y
< it
.last_visible_y
14917 && !fonts_changed_p
)
14919 /* If we have reached into the characters in the START row,
14920 that means the line boundaries have changed. So we
14921 can't start copying with the row START. Maybe it will
14922 work to start copying with the following row. */
14923 while (IT_CHARPOS (it
) > CHARPOS (start
))
14925 /* Advance to the next row as the "start". */
14927 start
= start_row
->minpos
;
14928 /* If there are no more rows to try, or just one, give up. */
14929 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14930 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14931 || CHARPOS (start
) == ZV
)
14933 clear_glyph_matrix (w
->desired_matrix
);
14937 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14939 /* If we have reached alignment,
14940 we can copy the rest of the rows. */
14941 if (IT_CHARPOS (it
) == CHARPOS (start
))
14944 if (display_line (&it
))
14945 last_text_row
= it
.glyph_row
- 1;
14948 /* A value of current_y < last_visible_y means that we stopped
14949 at the previous window start, which in turn means that we
14950 have at least one reusable row. */
14951 if (it
.current_y
< it
.last_visible_y
)
14953 struct glyph_row
*row
;
14955 /* IT.vpos always starts from 0; it counts text lines. */
14956 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14958 /* Find PT if not already found in the lines displayed. */
14959 if (w
->cursor
.vpos
< 0)
14961 int dy
= it
.current_y
- start_row
->y
;
14963 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14964 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14966 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14967 dy
, nrows_scrolled
);
14970 clear_glyph_matrix (w
->desired_matrix
);
14975 /* Scroll the display. Do it before the current matrix is
14976 changed. The problem here is that update has not yet
14977 run, i.e. part of the current matrix is not up to date.
14978 scroll_run_hook will clear the cursor, and use the
14979 current matrix to get the height of the row the cursor is
14981 run
.current_y
= start_row
->y
;
14982 run
.desired_y
= it
.current_y
;
14983 run
.height
= it
.last_visible_y
- it
.current_y
;
14985 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14988 FRAME_RIF (f
)->update_window_begin_hook (w
);
14989 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14990 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14991 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14995 /* Shift current matrix down by nrows_scrolled lines. */
14996 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14997 rotate_matrix (w
->current_matrix
,
14999 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15002 /* Disable lines that must be updated. */
15003 for (i
= 0; i
< nrows_scrolled
; ++i
)
15004 (start_row
+ i
)->enabled_p
= 0;
15006 /* Re-compute Y positions. */
15007 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15008 max_y
= it
.last_visible_y
;
15009 for (row
= start_row
+ nrows_scrolled
;
15013 row
->y
= it
.current_y
;
15014 row
->visible_height
= row
->height
;
15016 if (row
->y
< min_y
)
15017 row
->visible_height
-= min_y
- row
->y
;
15018 if (row
->y
+ row
->height
> max_y
)
15019 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15020 row
->redraw_fringe_bitmaps_p
= 1;
15022 it
.current_y
+= row
->height
;
15024 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15025 last_reused_text_row
= row
;
15026 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
15030 /* Disable lines in the current matrix which are now
15031 below the window. */
15032 for (++row
; row
< bottom_row
; ++row
)
15033 row
->enabled_p
= row
->mode_line_p
= 0;
15036 /* Update window_end_pos etc.; last_reused_text_row is the last
15037 reused row from the current matrix containing text, if any.
15038 The value of last_text_row is the last displayed line
15039 containing text. */
15040 if (last_reused_text_row
)
15042 w
->window_end_bytepos
15043 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
15045 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
15047 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
15048 w
->current_matrix
));
15050 else if (last_text_row
)
15052 w
->window_end_bytepos
15053 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15055 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15057 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15061 /* This window must be completely empty. */
15062 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
15063 w
->window_end_pos
= make_number (Z
- ZV
);
15064 w
->window_end_vpos
= make_number (0);
15066 w
->window_end_valid
= Qnil
;
15068 /* Update hint: don't try scrolling again in update_window. */
15069 w
->desired_matrix
->no_scrolling_p
= 1;
15072 debug_method_add (w
, "try_window_reusing_current_matrix 1");
15076 else if (CHARPOS (new_start
) > CHARPOS (start
))
15078 struct glyph_row
*pt_row
, *row
;
15079 struct glyph_row
*first_reusable_row
;
15080 struct glyph_row
*first_row_to_display
;
15082 int yb
= window_text_bottom_y (w
);
15084 /* Find the row starting at new_start, if there is one. Don't
15085 reuse a partially visible line at the end. */
15086 first_reusable_row
= start_row
;
15087 while (first_reusable_row
->enabled_p
15088 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
15089 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15090 < CHARPOS (new_start
)))
15091 ++first_reusable_row
;
15093 /* Give up if there is no row to reuse. */
15094 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
15095 || !first_reusable_row
->enabled_p
15096 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
15097 != CHARPOS (new_start
)))
15100 /* We can reuse fully visible rows beginning with
15101 first_reusable_row to the end of the window. Set
15102 first_row_to_display to the first row that cannot be reused.
15103 Set pt_row to the row containing point, if there is any. */
15105 for (first_row_to_display
= first_reusable_row
;
15106 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
15107 ++first_row_to_display
)
15109 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
15110 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
15111 pt_row
= first_row_to_display
;
15114 /* Start displaying at the start of first_row_to_display. */
15115 xassert (first_row_to_display
->y
< yb
);
15116 init_to_row_start (&it
, w
, first_row_to_display
);
15118 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
15120 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
15122 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
15123 + WINDOW_HEADER_LINE_HEIGHT (w
));
15125 /* Display lines beginning with first_row_to_display in the
15126 desired matrix. Set last_text_row to the last row displayed
15127 that displays text. */
15128 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
15129 if (pt_row
== NULL
)
15130 w
->cursor
.vpos
= -1;
15131 last_text_row
= NULL
;
15132 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
15133 if (display_line (&it
))
15134 last_text_row
= it
.glyph_row
- 1;
15136 /* If point is in a reused row, adjust y and vpos of the cursor
15140 w
->cursor
.vpos
-= nrows_scrolled
;
15141 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
15144 /* Give up if point isn't in a row displayed or reused. (This
15145 also handles the case where w->cursor.vpos < nrows_scrolled
15146 after the calls to display_line, which can happen with scroll
15147 margins. See bug#1295.) */
15148 if (w
->cursor
.vpos
< 0)
15150 clear_glyph_matrix (w
->desired_matrix
);
15154 /* Scroll the display. */
15155 run
.current_y
= first_reusable_row
->y
;
15156 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15157 run
.height
= it
.last_visible_y
- run
.current_y
;
15158 dy
= run
.current_y
- run
.desired_y
;
15163 FRAME_RIF (f
)->update_window_begin_hook (w
);
15164 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15165 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15166 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15170 /* Adjust Y positions of reused rows. */
15171 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15172 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15173 max_y
= it
.last_visible_y
;
15174 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15177 row
->visible_height
= row
->height
;
15178 if (row
->y
< min_y
)
15179 row
->visible_height
-= min_y
- row
->y
;
15180 if (row
->y
+ row
->height
> max_y
)
15181 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15182 row
->redraw_fringe_bitmaps_p
= 1;
15185 /* Scroll the current matrix. */
15186 xassert (nrows_scrolled
> 0);
15187 rotate_matrix (w
->current_matrix
,
15189 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15192 /* Disable rows not reused. */
15193 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15194 row
->enabled_p
= 0;
15196 /* Point may have moved to a different line, so we cannot assume that
15197 the previous cursor position is valid; locate the correct row. */
15200 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15201 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15205 w
->cursor
.y
= row
->y
;
15207 if (row
< bottom_row
)
15209 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15210 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15212 /* Can't use this optimization with bidi-reordered glyph
15213 rows, unless cursor is already at point. */
15214 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15216 if (!(w
->cursor
.hpos
>= 0
15217 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
15218 && BUFFERP (glyph
->object
)
15219 && glyph
->charpos
== PT
))
15224 && (!BUFFERP (glyph
->object
)
15225 || glyph
->charpos
< PT
);
15229 w
->cursor
.x
+= glyph
->pixel_width
;
15234 /* Adjust window end. A null value of last_text_row means that
15235 the window end is in reused rows which in turn means that
15236 only its vpos can have changed. */
15239 w
->window_end_bytepos
15240 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15242 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15244 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15249 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15252 w
->window_end_valid
= Qnil
;
15253 w
->desired_matrix
->no_scrolling_p
= 1;
15256 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15266 /************************************************************************
15267 Window redisplay reusing current matrix when buffer has changed
15268 ************************************************************************/
15270 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
15271 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
15272 EMACS_INT
*, EMACS_INT
*);
15273 static struct glyph_row
*
15274 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
15275 struct glyph_row
*);
15278 /* Return the last row in MATRIX displaying text. If row START is
15279 non-null, start searching with that row. IT gives the dimensions
15280 of the display. Value is null if matrix is empty; otherwise it is
15281 a pointer to the row found. */
15283 static struct glyph_row
*
15284 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
15285 struct glyph_row
*start
)
15287 struct glyph_row
*row
, *row_found
;
15289 /* Set row_found to the last row in IT->w's current matrix
15290 displaying text. The loop looks funny but think of partially
15293 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15294 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15296 xassert (row
->enabled_p
);
15298 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15307 /* Return the last row in the current matrix of W that is not affected
15308 by changes at the start of current_buffer that occurred since W's
15309 current matrix was built. Value is null if no such row exists.
15311 BEG_UNCHANGED us the number of characters unchanged at the start of
15312 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15313 first changed character in current_buffer. Characters at positions <
15314 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15315 when the current matrix was built. */
15317 static struct glyph_row
*
15318 find_last_unchanged_at_beg_row (struct window
*w
)
15320 EMACS_INT first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15321 struct glyph_row
*row
;
15322 struct glyph_row
*row_found
= NULL
;
15323 int yb
= window_text_bottom_y (w
);
15325 /* Find the last row displaying unchanged text. */
15326 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15327 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15328 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15331 if (/* If row ends before first_changed_pos, it is unchanged,
15332 except in some case. */
15333 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15334 /* When row ends in ZV and we write at ZV it is not
15336 && !row
->ends_at_zv_p
15337 /* When first_changed_pos is the end of a continued line,
15338 row is not unchanged because it may be no longer
15340 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15341 && (row
->continued_p
15342 || row
->exact_window_width_line_p
)))
15345 /* Stop if last visible row. */
15346 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15354 /* Find the first glyph row in the current matrix of W that is not
15355 affected by changes at the end of current_buffer since the
15356 time W's current matrix was built.
15358 Return in *DELTA the number of chars by which buffer positions in
15359 unchanged text at the end of current_buffer must be adjusted.
15361 Return in *DELTA_BYTES the corresponding number of bytes.
15363 Value is null if no such row exists, i.e. all rows are affected by
15366 static struct glyph_row
*
15367 find_first_unchanged_at_end_row (struct window
*w
,
15368 EMACS_INT
*delta
, EMACS_INT
*delta_bytes
)
15370 struct glyph_row
*row
;
15371 struct glyph_row
*row_found
= NULL
;
15373 *delta
= *delta_bytes
= 0;
15375 /* Display must not have been paused, otherwise the current matrix
15376 is not up to date. */
15377 eassert (!NILP (w
->window_end_valid
));
15379 /* A value of window_end_pos >= END_UNCHANGED means that the window
15380 end is in the range of changed text. If so, there is no
15381 unchanged row at the end of W's current matrix. */
15382 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15385 /* Set row to the last row in W's current matrix displaying text. */
15386 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15388 /* If matrix is entirely empty, no unchanged row exists. */
15389 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15391 /* The value of row is the last glyph row in the matrix having a
15392 meaningful buffer position in it. The end position of row
15393 corresponds to window_end_pos. This allows us to translate
15394 buffer positions in the current matrix to current buffer
15395 positions for characters not in changed text. */
15397 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15398 EMACS_INT Z_BYTE_old
=
15399 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15400 EMACS_INT last_unchanged_pos
, last_unchanged_pos_old
;
15401 struct glyph_row
*first_text_row
15402 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15404 *delta
= Z
- Z_old
;
15405 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15407 /* Set last_unchanged_pos to the buffer position of the last
15408 character in the buffer that has not been changed. Z is the
15409 index + 1 of the last character in current_buffer, i.e. by
15410 subtracting END_UNCHANGED we get the index of the last
15411 unchanged character, and we have to add BEG to get its buffer
15413 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15414 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15416 /* Search backward from ROW for a row displaying a line that
15417 starts at a minimum position >= last_unchanged_pos_old. */
15418 for (; row
> first_text_row
; --row
)
15420 /* This used to abort, but it can happen.
15421 It is ok to just stop the search instead here. KFS. */
15422 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15425 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15430 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15436 /* Make sure that glyph rows in the current matrix of window W
15437 reference the same glyph memory as corresponding rows in the
15438 frame's frame matrix. This function is called after scrolling W's
15439 current matrix on a terminal frame in try_window_id and
15440 try_window_reusing_current_matrix. */
15443 sync_frame_with_window_matrix_rows (struct window
*w
)
15445 struct frame
*f
= XFRAME (w
->frame
);
15446 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15448 /* Preconditions: W must be a leaf window and full-width. Its frame
15449 must have a frame matrix. */
15450 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15451 xassert (WINDOW_FULL_WIDTH_P (w
));
15452 xassert (!FRAME_WINDOW_P (f
));
15454 /* If W is a full-width window, glyph pointers in W's current matrix
15455 have, by definition, to be the same as glyph pointers in the
15456 corresponding frame matrix. Note that frame matrices have no
15457 marginal areas (see build_frame_matrix). */
15458 window_row
= w
->current_matrix
->rows
;
15459 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15460 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15461 while (window_row
< window_row_end
)
15463 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15464 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15466 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15467 frame_row
->glyphs
[TEXT_AREA
] = start
;
15468 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15469 frame_row
->glyphs
[LAST_AREA
] = end
;
15471 /* Disable frame rows whose corresponding window rows have
15472 been disabled in try_window_id. */
15473 if (!window_row
->enabled_p
)
15474 frame_row
->enabled_p
= 0;
15476 ++window_row
, ++frame_row
;
15481 /* Find the glyph row in window W containing CHARPOS. Consider all
15482 rows between START and END (not inclusive). END null means search
15483 all rows to the end of the display area of W. Value is the row
15484 containing CHARPOS or null. */
15487 row_containing_pos (struct window
*w
, EMACS_INT charpos
,
15488 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
15490 struct glyph_row
*row
= start
;
15491 struct glyph_row
*best_row
= NULL
;
15492 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15495 /* If we happen to start on a header-line, skip that. */
15496 if (row
->mode_line_p
)
15499 if ((end
&& row
>= end
) || !row
->enabled_p
)
15502 last_y
= window_text_bottom_y (w
) - dy
;
15506 /* Give up if we have gone too far. */
15507 if (end
&& row
>= end
)
15509 /* This formerly returned if they were equal.
15510 I think that both quantities are of a "last plus one" type;
15511 if so, when they are equal, the row is within the screen. -- rms. */
15512 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15515 /* If it is in this row, return this row. */
15516 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15517 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15518 /* The end position of a row equals the start
15519 position of the next row. If CHARPOS is there, we
15520 would rather display it in the next line, except
15521 when this line ends in ZV. */
15522 && !row
->ends_at_zv_p
15523 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15524 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15528 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
15529 || (!best_row
&& !row
->continued_p
))
15531 /* In bidi-reordered rows, there could be several rows
15532 occluding point, all of them belonging to the same
15533 continued line. We need to find the row which fits
15534 CHARPOS the best. */
15535 for (g
= row
->glyphs
[TEXT_AREA
];
15536 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15539 if (!STRINGP (g
->object
))
15541 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
15543 mindif
= eabs (g
->charpos
- charpos
);
15545 /* Exact match always wins. */
15552 else if (best_row
&& !row
->continued_p
)
15559 /* Try to redisplay window W by reusing its existing display. W's
15560 current matrix must be up to date when this function is called,
15561 i.e. window_end_valid must not be nil.
15565 1 if display has been updated
15566 0 if otherwise unsuccessful
15567 -1 if redisplay with same window start is known not to succeed
15569 The following steps are performed:
15571 1. Find the last row in the current matrix of W that is not
15572 affected by changes at the start of current_buffer. If no such row
15575 2. Find the first row in W's current matrix that is not affected by
15576 changes at the end of current_buffer. Maybe there is no such row.
15578 3. Display lines beginning with the row + 1 found in step 1 to the
15579 row found in step 2 or, if step 2 didn't find a row, to the end of
15582 4. If cursor is not known to appear on the window, give up.
15584 5. If display stopped at the row found in step 2, scroll the
15585 display and current matrix as needed.
15587 6. Maybe display some lines at the end of W, if we must. This can
15588 happen under various circumstances, like a partially visible line
15589 becoming fully visible, or because newly displayed lines are displayed
15590 in smaller font sizes.
15592 7. Update W's window end information. */
15595 try_window_id (struct window
*w
)
15597 struct frame
*f
= XFRAME (w
->frame
);
15598 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15599 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15600 struct glyph_row
*last_unchanged_at_beg_row
;
15601 struct glyph_row
*first_unchanged_at_end_row
;
15602 struct glyph_row
*row
;
15603 struct glyph_row
*bottom_row
;
15606 EMACS_INT delta
= 0, delta_bytes
= 0, stop_pos
;
15608 struct text_pos start_pos
;
15610 int first_unchanged_at_end_vpos
= 0;
15611 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15612 struct text_pos start
;
15613 EMACS_INT first_changed_charpos
, last_changed_charpos
;
15616 if (inhibit_try_window_id
)
15620 /* This is handy for debugging. */
15622 #define GIVE_UP(X) \
15624 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15628 #define GIVE_UP(X) return 0
15631 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15633 /* Don't use this for mini-windows because these can show
15634 messages and mini-buffers, and we don't handle that here. */
15635 if (MINI_WINDOW_P (w
))
15638 /* This flag is used to prevent redisplay optimizations. */
15639 if (windows_or_buffers_changed
|| cursor_type_changed
)
15642 /* Verify that narrowing has not changed.
15643 Also verify that we were not told to prevent redisplay optimizations.
15644 It would be nice to further
15645 reduce the number of cases where this prevents try_window_id. */
15646 if (current_buffer
->clip_changed
15647 || current_buffer
->prevent_redisplay_optimizations_p
)
15650 /* Window must either use window-based redisplay or be full width. */
15651 if (!FRAME_WINDOW_P (f
)
15652 && (!FRAME_LINE_INS_DEL_OK (f
)
15653 || !WINDOW_FULL_WIDTH_P (w
)))
15656 /* Give up if point is known NOT to appear in W. */
15657 if (PT
< CHARPOS (start
))
15660 /* Another way to prevent redisplay optimizations. */
15661 if (XFASTINT (w
->last_modified
) == 0)
15664 /* Verify that window is not hscrolled. */
15665 if (XFASTINT (w
->hscroll
) != 0)
15668 /* Verify that display wasn't paused. */
15669 if (NILP (w
->window_end_valid
))
15672 /* Can't use this if highlighting a region because a cursor movement
15673 will do more than just set the cursor. */
15674 if (!NILP (Vtransient_mark_mode
)
15675 && !NILP (BVAR (current_buffer
, mark_active
)))
15678 /* Likewise if highlighting trailing whitespace. */
15679 if (!NILP (Vshow_trailing_whitespace
))
15682 /* Likewise if showing a region. */
15683 if (!NILP (w
->region_showing
))
15686 /* Can't use this if overlay arrow position and/or string have
15688 if (overlay_arrows_changed_p ())
15691 /* When word-wrap is on, adding a space to the first word of a
15692 wrapped line can change the wrap position, altering the line
15693 above it. It might be worthwhile to handle this more
15694 intelligently, but for now just redisplay from scratch. */
15695 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
15698 /* Under bidi reordering, adding or deleting a character in the
15699 beginning of a paragraph, before the first strong directional
15700 character, can change the base direction of the paragraph (unless
15701 the buffer specifies a fixed paragraph direction), which will
15702 require to redisplay the whole paragraph. It might be worthwhile
15703 to find the paragraph limits and widen the range of redisplayed
15704 lines to that, but for now just give up this optimization and
15705 redisplay from scratch. */
15706 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
15707 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
15710 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
15711 only if buffer has really changed. The reason is that the gap is
15712 initially at Z for freshly visited files. The code below would
15713 set end_unchanged to 0 in that case. */
15714 if (MODIFF
> SAVE_MODIFF
15715 /* This seems to happen sometimes after saving a buffer. */
15716 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
15718 if (GPT
- BEG
< BEG_UNCHANGED
)
15719 BEG_UNCHANGED
= GPT
- BEG
;
15720 if (Z
- GPT
< END_UNCHANGED
)
15721 END_UNCHANGED
= Z
- GPT
;
15724 /* The position of the first and last character that has been changed. */
15725 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
15726 last_changed_charpos
= Z
- END_UNCHANGED
;
15728 /* If window starts after a line end, and the last change is in
15729 front of that newline, then changes don't affect the display.
15730 This case happens with stealth-fontification. Note that although
15731 the display is unchanged, glyph positions in the matrix have to
15732 be adjusted, of course. */
15733 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15734 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15735 && ((last_changed_charpos
< CHARPOS (start
)
15736 && CHARPOS (start
) == BEGV
)
15737 || (last_changed_charpos
< CHARPOS (start
) - 1
15738 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
15740 EMACS_INT Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
15741 struct glyph_row
*r0
;
15743 /* Compute how many chars/bytes have been added to or removed
15744 from the buffer. */
15745 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15746 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15747 Z_delta
= Z
- Z_old
;
15748 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15750 /* Give up if PT is not in the window. Note that it already has
15751 been checked at the start of try_window_id that PT is not in
15752 front of the window start. */
15753 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
15756 /* If window start is unchanged, we can reuse the whole matrix
15757 as is, after adjusting glyph positions. No need to compute
15758 the window end again, since its offset from Z hasn't changed. */
15759 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15760 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
15761 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
15762 /* PT must not be in a partially visible line. */
15763 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
15764 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15766 /* Adjust positions in the glyph matrix. */
15767 if (Z_delta
|| Z_delta_bytes
)
15769 struct glyph_row
*r1
15770 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15771 increment_matrix_positions (w
->current_matrix
,
15772 MATRIX_ROW_VPOS (r0
, current_matrix
),
15773 MATRIX_ROW_VPOS (r1
, current_matrix
),
15774 Z_delta
, Z_delta_bytes
);
15777 /* Set the cursor. */
15778 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15780 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15787 /* Handle the case that changes are all below what is displayed in
15788 the window, and that PT is in the window. This shortcut cannot
15789 be taken if ZV is visible in the window, and text has been added
15790 there that is visible in the window. */
15791 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15792 /* ZV is not visible in the window, or there are no
15793 changes at ZV, actually. */
15794 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15795 || first_changed_charpos
== last_changed_charpos
))
15797 struct glyph_row
*r0
;
15799 /* Give up if PT is not in the window. Note that it already has
15800 been checked at the start of try_window_id that PT is not in
15801 front of the window start. */
15802 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15805 /* If window start is unchanged, we can reuse the whole matrix
15806 as is, without changing glyph positions since no text has
15807 been added/removed in front of the window end. */
15808 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15809 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
15810 /* PT must not be in a partially visible line. */
15811 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15812 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15814 /* We have to compute the window end anew since text
15815 could have been added/removed after it. */
15817 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15818 w
->window_end_bytepos
15819 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15821 /* Set the cursor. */
15822 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15824 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15831 /* Give up if window start is in the changed area.
15833 The condition used to read
15835 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15837 but why that was tested escapes me at the moment. */
15838 if (CHARPOS (start
) >= first_changed_charpos
15839 && CHARPOS (start
) <= last_changed_charpos
)
15842 /* Check that window start agrees with the start of the first glyph
15843 row in its current matrix. Check this after we know the window
15844 start is not in changed text, otherwise positions would not be
15846 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15847 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
15850 /* Give up if the window ends in strings. Overlay strings
15851 at the end are difficult to handle, so don't try. */
15852 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15853 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15856 /* Compute the position at which we have to start displaying new
15857 lines. Some of the lines at the top of the window might be
15858 reusable because they are not displaying changed text. Find the
15859 last row in W's current matrix not affected by changes at the
15860 start of current_buffer. Value is null if changes start in the
15861 first line of window. */
15862 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15863 if (last_unchanged_at_beg_row
)
15865 /* Avoid starting to display in the moddle of a character, a TAB
15866 for instance. This is easier than to set up the iterator
15867 exactly, and it's not a frequent case, so the additional
15868 effort wouldn't really pay off. */
15869 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15870 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15871 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15872 --last_unchanged_at_beg_row
;
15874 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15877 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15879 start_pos
= it
.current
.pos
;
15881 /* Start displaying new lines in the desired matrix at the same
15882 vpos we would use in the current matrix, i.e. below
15883 last_unchanged_at_beg_row. */
15884 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15886 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15887 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15889 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15893 /* There are no reusable lines at the start of the window.
15894 Start displaying in the first text line. */
15895 start_display (&it
, w
, start
);
15896 it
.vpos
= it
.first_vpos
;
15897 start_pos
= it
.current
.pos
;
15900 /* Find the first row that is not affected by changes at the end of
15901 the buffer. Value will be null if there is no unchanged row, in
15902 which case we must redisplay to the end of the window. delta
15903 will be set to the value by which buffer positions beginning with
15904 first_unchanged_at_end_row have to be adjusted due to text
15906 first_unchanged_at_end_row
15907 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15908 IF_DEBUG (debug_delta
= delta
);
15909 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15911 /* Set stop_pos to the buffer position up to which we will have to
15912 display new lines. If first_unchanged_at_end_row != NULL, this
15913 is the buffer position of the start of the line displayed in that
15914 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15915 that we don't stop at a buffer position. */
15917 if (first_unchanged_at_end_row
)
15919 xassert (last_unchanged_at_beg_row
== NULL
15920 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15922 /* If this is a continuation line, move forward to the next one
15923 that isn't. Changes in lines above affect this line.
15924 Caution: this may move first_unchanged_at_end_row to a row
15925 not displaying text. */
15926 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15927 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15928 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15929 < it
.last_visible_y
))
15930 ++first_unchanged_at_end_row
;
15932 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15933 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15934 >= it
.last_visible_y
))
15935 first_unchanged_at_end_row
= NULL
;
15938 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15940 first_unchanged_at_end_vpos
15941 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15942 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15945 else if (last_unchanged_at_beg_row
== NULL
)
15951 /* Either there is no unchanged row at the end, or the one we have
15952 now displays text. This is a necessary condition for the window
15953 end pos calculation at the end of this function. */
15954 xassert (first_unchanged_at_end_row
== NULL
15955 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15957 debug_last_unchanged_at_beg_vpos
15958 = (last_unchanged_at_beg_row
15959 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15961 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15963 #endif /* GLYPH_DEBUG != 0 */
15966 /* Display new lines. Set last_text_row to the last new line
15967 displayed which has text on it, i.e. might end up as being the
15968 line where the window_end_vpos is. */
15969 w
->cursor
.vpos
= -1;
15970 last_text_row
= NULL
;
15971 overlay_arrow_seen
= 0;
15972 while (it
.current_y
< it
.last_visible_y
15973 && !fonts_changed_p
15974 && (first_unchanged_at_end_row
== NULL
15975 || IT_CHARPOS (it
) < stop_pos
))
15977 if (display_line (&it
))
15978 last_text_row
= it
.glyph_row
- 1;
15981 if (fonts_changed_p
)
15985 /* Compute differences in buffer positions, y-positions etc. for
15986 lines reused at the bottom of the window. Compute what we can
15988 if (first_unchanged_at_end_row
15989 /* No lines reused because we displayed everything up to the
15990 bottom of the window. */
15991 && it
.current_y
< it
.last_visible_y
)
15994 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15996 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15997 run
.current_y
= first_unchanged_at_end_row
->y
;
15998 run
.desired_y
= run
.current_y
+ dy
;
15999 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
16003 delta
= delta_bytes
= dvpos
= dy
16004 = run
.current_y
= run
.desired_y
= run
.height
= 0;
16005 first_unchanged_at_end_row
= NULL
;
16007 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
16010 /* Find the cursor if not already found. We have to decide whether
16011 PT will appear on this window (it sometimes doesn't, but this is
16012 not a very frequent case.) This decision has to be made before
16013 the current matrix is altered. A value of cursor.vpos < 0 means
16014 that PT is either in one of the lines beginning at
16015 first_unchanged_at_end_row or below the window. Don't care for
16016 lines that might be displayed later at the window end; as
16017 mentioned, this is not a frequent case. */
16018 if (w
->cursor
.vpos
< 0)
16020 /* Cursor in unchanged rows at the top? */
16021 if (PT
< CHARPOS (start_pos
)
16022 && last_unchanged_at_beg_row
)
16024 row
= row_containing_pos (w
, PT
,
16025 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
16026 last_unchanged_at_beg_row
+ 1, 0);
16028 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16031 /* Start from first_unchanged_at_end_row looking for PT. */
16032 else if (first_unchanged_at_end_row
)
16034 row
= row_containing_pos (w
, PT
- delta
,
16035 first_unchanged_at_end_row
, NULL
, 0);
16037 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
16038 delta_bytes
, dy
, dvpos
);
16041 /* Give up if cursor was not found. */
16042 if (w
->cursor
.vpos
< 0)
16044 clear_glyph_matrix (w
->desired_matrix
);
16049 /* Don't let the cursor end in the scroll margins. */
16051 int this_scroll_margin
, cursor_height
;
16053 this_scroll_margin
= max (0, scroll_margin
);
16054 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16055 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
16056 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
16058 if ((w
->cursor
.y
< this_scroll_margin
16059 && CHARPOS (start
) > BEGV
)
16060 /* Old redisplay didn't take scroll margin into account at the bottom,
16061 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
16062 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
16063 ? cursor_height
+ this_scroll_margin
16064 : 1)) > it
.last_visible_y
)
16066 w
->cursor
.vpos
= -1;
16067 clear_glyph_matrix (w
->desired_matrix
);
16072 /* Scroll the display. Do it before changing the current matrix so
16073 that xterm.c doesn't get confused about where the cursor glyph is
16075 if (dy
&& run
.height
)
16079 if (FRAME_WINDOW_P (f
))
16081 FRAME_RIF (f
)->update_window_begin_hook (w
);
16082 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16083 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16084 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16088 /* Terminal frame. In this case, dvpos gives the number of
16089 lines to scroll by; dvpos < 0 means scroll up. */
16091 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
16092 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
16093 int end
= (WINDOW_TOP_EDGE_LINE (w
)
16094 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
16095 + window_internal_height (w
));
16097 #if defined (HAVE_GPM) || defined (MSDOS)
16098 x_clear_window_mouse_face (w
);
16100 /* Perform the operation on the screen. */
16103 /* Scroll last_unchanged_at_beg_row to the end of the
16104 window down dvpos lines. */
16105 set_terminal_window (f
, end
);
16107 /* On dumb terminals delete dvpos lines at the end
16108 before inserting dvpos empty lines. */
16109 if (!FRAME_SCROLL_REGION_OK (f
))
16110 ins_del_lines (f
, end
- dvpos
, -dvpos
);
16112 /* Insert dvpos empty lines in front of
16113 last_unchanged_at_beg_row. */
16114 ins_del_lines (f
, from
, dvpos
);
16116 else if (dvpos
< 0)
16118 /* Scroll up last_unchanged_at_beg_vpos to the end of
16119 the window to last_unchanged_at_beg_vpos - |dvpos|. */
16120 set_terminal_window (f
, end
);
16122 /* Delete dvpos lines in front of
16123 last_unchanged_at_beg_vpos. ins_del_lines will set
16124 the cursor to the given vpos and emit |dvpos| delete
16126 ins_del_lines (f
, from
+ dvpos
, dvpos
);
16128 /* On a dumb terminal insert dvpos empty lines at the
16130 if (!FRAME_SCROLL_REGION_OK (f
))
16131 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
16134 set_terminal_window (f
, 0);
16140 /* Shift reused rows of the current matrix to the right position.
16141 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
16143 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16144 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
16147 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
16148 bottom_vpos
, dvpos
);
16149 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
16152 else if (dvpos
> 0)
16154 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
16155 bottom_vpos
, dvpos
);
16156 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
16157 first_unchanged_at_end_vpos
+ dvpos
, 0);
16160 /* For frame-based redisplay, make sure that current frame and window
16161 matrix are in sync with respect to glyph memory. */
16162 if (!FRAME_WINDOW_P (f
))
16163 sync_frame_with_window_matrix_rows (w
);
16165 /* Adjust buffer positions in reused rows. */
16166 if (delta
|| delta_bytes
)
16167 increment_matrix_positions (current_matrix
,
16168 first_unchanged_at_end_vpos
+ dvpos
,
16169 bottom_vpos
, delta
, delta_bytes
);
16171 /* Adjust Y positions. */
16173 shift_glyph_matrix (w
, current_matrix
,
16174 first_unchanged_at_end_vpos
+ dvpos
,
16177 if (first_unchanged_at_end_row
)
16179 first_unchanged_at_end_row
+= dvpos
;
16180 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16181 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16182 first_unchanged_at_end_row
= NULL
;
16185 /* If scrolling up, there may be some lines to display at the end of
16187 last_text_row_at_end
= NULL
;
16190 /* Scrolling up can leave for example a partially visible line
16191 at the end of the window to be redisplayed. */
16192 /* Set last_row to the glyph row in the current matrix where the
16193 window end line is found. It has been moved up or down in
16194 the matrix by dvpos. */
16195 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16196 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16198 /* If last_row is the window end line, it should display text. */
16199 xassert (last_row
->displays_text_p
);
16201 /* If window end line was partially visible before, begin
16202 displaying at that line. Otherwise begin displaying with the
16203 line following it. */
16204 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16206 init_to_row_start (&it
, w
, last_row
);
16207 it
.vpos
= last_vpos
;
16208 it
.current_y
= last_row
->y
;
16212 init_to_row_end (&it
, w
, last_row
);
16213 it
.vpos
= 1 + last_vpos
;
16214 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16218 /* We may start in a continuation line. If so, we have to
16219 get the right continuation_lines_width and current_x. */
16220 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16221 it
.hpos
= it
.current_x
= 0;
16223 /* Display the rest of the lines at the window end. */
16224 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16225 while (it
.current_y
< it
.last_visible_y
16226 && !fonts_changed_p
)
16228 /* Is it always sure that the display agrees with lines in
16229 the current matrix? I don't think so, so we mark rows
16230 displayed invalid in the current matrix by setting their
16231 enabled_p flag to zero. */
16232 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16233 if (display_line (&it
))
16234 last_text_row_at_end
= it
.glyph_row
- 1;
16238 /* Update window_end_pos and window_end_vpos. */
16239 if (first_unchanged_at_end_row
16240 && !last_text_row_at_end
)
16242 /* Window end line if one of the preserved rows from the current
16243 matrix. Set row to the last row displaying text in current
16244 matrix starting at first_unchanged_at_end_row, after
16246 xassert (first_unchanged_at_end_row
->displays_text_p
);
16247 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16248 first_unchanged_at_end_row
);
16249 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16251 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16252 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16254 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16255 xassert (w
->window_end_bytepos
>= 0);
16256 IF_DEBUG (debug_method_add (w
, "A"));
16258 else if (last_text_row_at_end
)
16261 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16262 w
->window_end_bytepos
16263 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16265 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16266 xassert (w
->window_end_bytepos
>= 0);
16267 IF_DEBUG (debug_method_add (w
, "B"));
16269 else if (last_text_row
)
16271 /* We have displayed either to the end of the window or at the
16272 end of the window, i.e. the last row with text is to be found
16273 in the desired matrix. */
16275 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16276 w
->window_end_bytepos
16277 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16279 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16280 xassert (w
->window_end_bytepos
>= 0);
16282 else if (first_unchanged_at_end_row
== NULL
16283 && last_text_row
== NULL
16284 && last_text_row_at_end
== NULL
)
16286 /* Displayed to end of window, but no line containing text was
16287 displayed. Lines were deleted at the end of the window. */
16288 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16289 int vpos
= XFASTINT (w
->window_end_vpos
);
16290 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16291 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16294 row
== NULL
&& vpos
>= first_vpos
;
16295 --vpos
, --current_row
, --desired_row
)
16297 if (desired_row
->enabled_p
)
16299 if (desired_row
->displays_text_p
)
16302 else if (current_row
->displays_text_p
)
16306 xassert (row
!= NULL
);
16307 w
->window_end_vpos
= make_number (vpos
+ 1);
16308 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16309 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16310 xassert (w
->window_end_bytepos
>= 0);
16311 IF_DEBUG (debug_method_add (w
, "C"));
16316 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16317 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16319 /* Record that display has not been completed. */
16320 w
->window_end_valid
= Qnil
;
16321 w
->desired_matrix
->no_scrolling_p
= 1;
16329 /***********************************************************************
16330 More debugging support
16331 ***********************************************************************/
16335 void dump_glyph_row (struct glyph_row
*, int, int);
16336 void dump_glyph_matrix (struct glyph_matrix
*, int);
16337 void dump_glyph (struct glyph_row
*, struct glyph
*, int);
16340 /* Dump the contents of glyph matrix MATRIX on stderr.
16342 GLYPHS 0 means don't show glyph contents.
16343 GLYPHS 1 means show glyphs in short form
16344 GLYPHS > 1 means show glyphs in long form. */
16347 dump_glyph_matrix (matrix
, glyphs
)
16348 struct glyph_matrix
*matrix
;
16352 for (i
= 0; i
< matrix
->nrows
; ++i
)
16353 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16357 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16358 the glyph row and area where the glyph comes from. */
16361 dump_glyph (row
, glyph
, area
)
16362 struct glyph_row
*row
;
16363 struct glyph
*glyph
;
16366 if (glyph
->type
== CHAR_GLYPH
)
16369 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16370 glyph
- row
->glyphs
[TEXT_AREA
],
16373 (BUFFERP (glyph
->object
)
16375 : (STRINGP (glyph
->object
)
16378 glyph
->pixel_width
,
16380 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16384 glyph
->left_box_line_p
,
16385 glyph
->right_box_line_p
);
16387 else if (glyph
->type
== STRETCH_GLYPH
)
16390 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16391 glyph
- row
->glyphs
[TEXT_AREA
],
16394 (BUFFERP (glyph
->object
)
16396 : (STRINGP (glyph
->object
)
16399 glyph
->pixel_width
,
16403 glyph
->left_box_line_p
,
16404 glyph
->right_box_line_p
);
16406 else if (glyph
->type
== IMAGE_GLYPH
)
16409 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16410 glyph
- row
->glyphs
[TEXT_AREA
],
16413 (BUFFERP (glyph
->object
)
16415 : (STRINGP (glyph
->object
)
16418 glyph
->pixel_width
,
16422 glyph
->left_box_line_p
,
16423 glyph
->right_box_line_p
);
16425 else if (glyph
->type
== COMPOSITE_GLYPH
)
16428 " %5d %4c %6d %c %3d 0x%05x",
16429 glyph
- row
->glyphs
[TEXT_AREA
],
16432 (BUFFERP (glyph
->object
)
16434 : (STRINGP (glyph
->object
)
16437 glyph
->pixel_width
,
16439 if (glyph
->u
.cmp
.automatic
)
16442 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
16443 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16445 glyph
->left_box_line_p
,
16446 glyph
->right_box_line_p
);
16451 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16452 GLYPHS 0 means don't show glyph contents.
16453 GLYPHS 1 means show glyphs in short form
16454 GLYPHS > 1 means show glyphs in long form. */
16457 dump_glyph_row (row
, vpos
, glyphs
)
16458 struct glyph_row
*row
;
16463 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16464 fprintf (stderr
, "======================================================================\n");
16466 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16467 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16469 MATRIX_ROW_START_CHARPOS (row
),
16470 MATRIX_ROW_END_CHARPOS (row
),
16471 row
->used
[TEXT_AREA
],
16472 row
->contains_overlapping_glyphs_p
,
16474 row
->truncated_on_left_p
,
16475 row
->truncated_on_right_p
,
16477 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16478 row
->displays_text_p
,
16481 row
->ends_in_middle_of_char_p
,
16482 row
->starts_in_middle_of_char_p
,
16488 row
->visible_height
,
16491 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16492 row
->end
.overlay_string_index
,
16493 row
->continuation_lines_width
);
16494 fprintf (stderr
, "%9d %5d\n",
16495 CHARPOS (row
->start
.string_pos
),
16496 CHARPOS (row
->end
.string_pos
));
16497 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16498 row
->end
.dpvec_index
);
16505 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16507 struct glyph
*glyph
= row
->glyphs
[area
];
16508 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16510 /* Glyph for a line end in text. */
16511 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16514 if (glyph
< glyph_end
)
16515 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16517 for (; glyph
< glyph_end
; ++glyph
)
16518 dump_glyph (row
, glyph
, area
);
16521 else if (glyphs
== 1)
16525 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16527 char *s
= (char *) alloca (row
->used
[area
] + 1);
16530 for (i
= 0; i
< row
->used
[area
]; ++i
)
16532 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16533 if (glyph
->type
== CHAR_GLYPH
16534 && glyph
->u
.ch
< 0x80
16535 && glyph
->u
.ch
>= ' ')
16536 s
[i
] = glyph
->u
.ch
;
16542 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16548 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16549 Sdump_glyph_matrix
, 0, 1, "p",
16550 doc
: /* Dump the current matrix of the selected window to stderr.
16551 Shows contents of glyph row structures. With non-nil
16552 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16553 glyphs in short form, otherwise show glyphs in long form. */)
16554 (Lisp_Object glyphs
)
16556 struct window
*w
= XWINDOW (selected_window
);
16557 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16559 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
16560 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16561 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16562 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16563 fprintf (stderr
, "=============================================\n");
16564 dump_glyph_matrix (w
->current_matrix
,
16565 NILP (glyphs
) ? 0 : XINT (glyphs
));
16570 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16571 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16574 struct frame
*f
= XFRAME (selected_frame
);
16575 dump_glyph_matrix (f
->current_matrix
, 1);
16580 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16581 doc
: /* Dump glyph row ROW to stderr.
16582 GLYPH 0 means don't dump glyphs.
16583 GLYPH 1 means dump glyphs in short form.
16584 GLYPH > 1 or omitted means dump glyphs in long form. */)
16585 (Lisp_Object row
, Lisp_Object glyphs
)
16587 struct glyph_matrix
*matrix
;
16590 CHECK_NUMBER (row
);
16591 matrix
= XWINDOW (selected_window
)->current_matrix
;
16593 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16594 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16596 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16601 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16602 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16603 GLYPH 0 means don't dump glyphs.
16604 GLYPH 1 means dump glyphs in short form.
16605 GLYPH > 1 or omitted means dump glyphs in long form. */)
16606 (Lisp_Object row
, Lisp_Object glyphs
)
16608 struct frame
*sf
= SELECTED_FRAME ();
16609 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16612 CHECK_NUMBER (row
);
16614 if (vpos
>= 0 && vpos
< m
->nrows
)
16615 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16616 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16621 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16622 doc
: /* Toggle tracing of redisplay.
16623 With ARG, turn tracing on if and only if ARG is positive. */)
16627 trace_redisplay_p
= !trace_redisplay_p
;
16630 arg
= Fprefix_numeric_value (arg
);
16631 trace_redisplay_p
= XINT (arg
) > 0;
16638 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16639 doc
: /* Like `format', but print result to stderr.
16640 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16641 (size_t nargs
, Lisp_Object
*args
)
16643 Lisp_Object s
= Fformat (nargs
, args
);
16644 fprintf (stderr
, "%s", SDATA (s
));
16648 #endif /* GLYPH_DEBUG */
16652 /***********************************************************************
16653 Building Desired Matrix Rows
16654 ***********************************************************************/
16656 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
16657 Used for non-window-redisplay windows, and for windows w/o left fringe. */
16659 static struct glyph_row
*
16660 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
16662 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16663 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16664 struct buffer
*old
= current_buffer
;
16665 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
16666 int arrow_len
= SCHARS (overlay_arrow_string
);
16667 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
16668 const unsigned char *p
;
16671 int n_glyphs_before
;
16673 set_buffer_temp (buffer
);
16674 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
16675 it
.glyph_row
->used
[TEXT_AREA
] = 0;
16676 SET_TEXT_POS (it
.position
, 0, 0);
16678 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
16680 while (p
< arrow_end
)
16682 Lisp_Object face
, ilisp
;
16684 /* Get the next character. */
16686 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
16689 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
16690 if (! ASCII_CHAR_P (it
.c
))
16691 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
16695 /* Get its face. */
16696 ilisp
= make_number (p
- arrow_string
);
16697 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
16698 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
16700 /* Compute its width, get its glyphs. */
16701 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
16702 SET_TEXT_POS (it
.position
, -1, -1);
16703 PRODUCE_GLYPHS (&it
);
16705 /* If this character doesn't fit any more in the line, we have
16706 to remove some glyphs. */
16707 if (it
.current_x
> it
.last_visible_x
)
16709 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16714 set_buffer_temp (old
);
16715 return it
.glyph_row
;
16719 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
16720 glyphs are only inserted for terminal frames since we can't really
16721 win with truncation glyphs when partially visible glyphs are
16722 involved. Which glyphs to insert is determined by
16723 produce_special_glyphs. */
16726 insert_left_trunc_glyphs (struct it
*it
)
16728 struct it truncate_it
;
16729 struct glyph
*from
, *end
, *to
, *toend
;
16731 xassert (!FRAME_WINDOW_P (it
->f
));
16733 /* Get the truncation glyphs. */
16735 truncate_it
.current_x
= 0;
16736 truncate_it
.face_id
= DEFAULT_FACE_ID
;
16737 truncate_it
.glyph_row
= &scratch_glyph_row
;
16738 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
16739 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
16740 truncate_it
.object
= make_number (0);
16741 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
16743 /* Overwrite glyphs from IT with truncation glyphs. */
16744 if (!it
->glyph_row
->reversed_p
)
16746 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16747 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
16748 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16749 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16754 /* There may be padding glyphs left over. Overwrite them too. */
16755 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16757 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16763 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16767 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
16768 that back to front. */
16769 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16770 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
16771 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16772 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
16774 while (from
>= end
&& to
>= toend
)
16776 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
16779 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
16780 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
16781 while (from
>= end
&& to
>= toend
)
16786 /* Need to free some room before prepending additional
16788 int move_by
= from
- end
+ 1;
16789 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16790 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
16792 for ( ; g
>= g0
; g
--)
16794 while (from
>= end
)
16796 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
16802 /* Compute the pixel height and width of IT->glyph_row.
16804 Most of the time, ascent and height of a display line will be equal
16805 to the max_ascent and max_height values of the display iterator
16806 structure. This is not the case if
16808 1. We hit ZV without displaying anything. In this case, max_ascent
16809 and max_height will be zero.
16811 2. We have some glyphs that don't contribute to the line height.
16812 (The glyph row flag contributes_to_line_height_p is for future
16813 pixmap extensions).
16815 The first case is easily covered by using default values because in
16816 these cases, the line height does not really matter, except that it
16817 must not be zero. */
16820 compute_line_metrics (struct it
*it
)
16822 struct glyph_row
*row
= it
->glyph_row
;
16824 if (FRAME_WINDOW_P (it
->f
))
16826 int i
, min_y
, max_y
;
16828 /* The line may consist of one space only, that was added to
16829 place the cursor on it. If so, the row's height hasn't been
16831 if (row
->height
== 0)
16833 if (it
->max_ascent
+ it
->max_descent
== 0)
16834 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16835 row
->ascent
= it
->max_ascent
;
16836 row
->height
= it
->max_ascent
+ it
->max_descent
;
16837 row
->phys_ascent
= it
->max_phys_ascent
;
16838 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16839 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16842 /* Compute the width of this line. */
16843 row
->pixel_width
= row
->x
;
16844 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16845 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16847 xassert (row
->pixel_width
>= 0);
16848 xassert (row
->ascent
>= 0 && row
->height
> 0);
16850 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16851 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16853 /* If first line's physical ascent is larger than its logical
16854 ascent, use the physical ascent, and make the row taller.
16855 This makes accented characters fully visible. */
16856 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16857 && row
->phys_ascent
> row
->ascent
)
16859 row
->height
+= row
->phys_ascent
- row
->ascent
;
16860 row
->ascent
= row
->phys_ascent
;
16863 /* Compute how much of the line is visible. */
16864 row
->visible_height
= row
->height
;
16866 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16867 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16869 if (row
->y
< min_y
)
16870 row
->visible_height
-= min_y
- row
->y
;
16871 if (row
->y
+ row
->height
> max_y
)
16872 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16876 row
->pixel_width
= row
->used
[TEXT_AREA
];
16877 if (row
->continued_p
)
16878 row
->pixel_width
-= it
->continuation_pixel_width
;
16879 else if (row
->truncated_on_right_p
)
16880 row
->pixel_width
-= it
->truncation_pixel_width
;
16881 row
->ascent
= row
->phys_ascent
= 0;
16882 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16883 row
->extra_line_spacing
= 0;
16886 /* Compute a hash code for this row. */
16890 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16891 for (i
= 0; i
< row
->used
[area
]; ++i
)
16892 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16893 + row
->glyphs
[area
][i
].u
.val
16894 + row
->glyphs
[area
][i
].face_id
16895 + row
->glyphs
[area
][i
].padding_p
16896 + (row
->glyphs
[area
][i
].type
<< 2));
16899 it
->max_ascent
= it
->max_descent
= 0;
16900 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16904 /* Append one space to the glyph row of iterator IT if doing a
16905 window-based redisplay. The space has the same face as
16906 IT->face_id. Value is non-zero if a space was added.
16908 This function is called to make sure that there is always one glyph
16909 at the end of a glyph row that the cursor can be set on under
16910 window-systems. (If there weren't such a glyph we would not know
16911 how wide and tall a box cursor should be displayed).
16913 At the same time this space let's a nicely handle clearing to the
16914 end of the line if the row ends in italic text. */
16917 append_space_for_newline (struct it
*it
, int default_face_p
)
16919 if (FRAME_WINDOW_P (it
->f
))
16921 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16923 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16924 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16926 /* Save some values that must not be changed.
16927 Must save IT->c and IT->len because otherwise
16928 ITERATOR_AT_END_P wouldn't work anymore after
16929 append_space_for_newline has been called. */
16930 enum display_element_type saved_what
= it
->what
;
16931 int saved_c
= it
->c
, saved_len
= it
->len
;
16932 int saved_char_to_display
= it
->char_to_display
;
16933 int saved_x
= it
->current_x
;
16934 int saved_face_id
= it
->face_id
;
16935 struct text_pos saved_pos
;
16936 Lisp_Object saved_object
;
16939 saved_object
= it
->object
;
16940 saved_pos
= it
->position
;
16942 it
->what
= IT_CHARACTER
;
16943 memset (&it
->position
, 0, sizeof it
->position
);
16944 it
->object
= make_number (0);
16945 it
->c
= it
->char_to_display
= ' ';
16948 if (default_face_p
)
16949 it
->face_id
= DEFAULT_FACE_ID
;
16950 else if (it
->face_before_selective_p
)
16951 it
->face_id
= it
->saved_face_id
;
16952 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16953 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16955 PRODUCE_GLYPHS (it
);
16957 it
->override_ascent
= -1;
16958 it
->constrain_row_ascent_descent_p
= 0;
16959 it
->current_x
= saved_x
;
16960 it
->object
= saved_object
;
16961 it
->position
= saved_pos
;
16962 it
->what
= saved_what
;
16963 it
->face_id
= saved_face_id
;
16964 it
->len
= saved_len
;
16966 it
->char_to_display
= saved_char_to_display
;
16975 /* Extend the face of the last glyph in the text area of IT->glyph_row
16976 to the end of the display line. Called from display_line. If the
16977 glyph row is empty, add a space glyph to it so that we know the
16978 face to draw. Set the glyph row flag fill_line_p. If the glyph
16979 row is R2L, prepend a stretch glyph to cover the empty space to the
16980 left of the leftmost glyph. */
16983 extend_face_to_end_of_line (struct it
*it
)
16986 struct frame
*f
= it
->f
;
16988 /* If line is already filled, do nothing. Non window-system frames
16989 get a grace of one more ``pixel'' because their characters are
16990 1-``pixel'' wide, so they hit the equality too early. This grace
16991 is needed only for R2L rows that are not continued, to produce
16992 one extra blank where we could display the cursor. */
16993 if (it
->current_x
>= it
->last_visible_x
16994 + (!FRAME_WINDOW_P (f
)
16995 && it
->glyph_row
->reversed_p
16996 && !it
->glyph_row
->continued_p
))
16999 /* Face extension extends the background and box of IT->face_id
17000 to the end of the line. If the background equals the background
17001 of the frame, we don't have to do anything. */
17002 if (it
->face_before_selective_p
)
17003 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
17005 face
= FACE_FROM_ID (f
, it
->face_id
);
17007 if (FRAME_WINDOW_P (f
)
17008 && it
->glyph_row
->displays_text_p
17009 && face
->box
== FACE_NO_BOX
17010 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
17012 && !it
->glyph_row
->reversed_p
)
17015 /* Set the glyph row flag indicating that the face of the last glyph
17016 in the text area has to be drawn to the end of the text area. */
17017 it
->glyph_row
->fill_line_p
= 1;
17019 /* If current character of IT is not ASCII, make sure we have the
17020 ASCII face. This will be automatically undone the next time
17021 get_next_display_element returns a multibyte character. Note
17022 that the character will always be single byte in unibyte
17024 if (!ASCII_CHAR_P (it
->c
))
17026 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
17029 if (FRAME_WINDOW_P (f
))
17031 /* If the row is empty, add a space with the current face of IT,
17032 so that we know which face to draw. */
17033 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
17035 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
17036 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
17037 it
->glyph_row
->used
[TEXT_AREA
] = 1;
17039 #ifdef HAVE_WINDOW_SYSTEM
17040 if (it
->glyph_row
->reversed_p
)
17042 /* Prepend a stretch glyph to the row, such that the
17043 rightmost glyph will be drawn flushed all the way to the
17044 right margin of the window. The stretch glyph that will
17045 occupy the empty space, if any, to the left of the
17047 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
17048 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
17049 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
17051 int row_width
, stretch_ascent
, stretch_width
;
17052 struct text_pos saved_pos
;
17053 int saved_face_id
, saved_avoid_cursor
;
17055 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
17056 row_width
+= g
->pixel_width
;
17057 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
17058 if (stretch_width
> 0)
17061 (((it
->ascent
+ it
->descent
)
17062 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
17063 saved_pos
= it
->position
;
17064 memset (&it
->position
, 0, sizeof it
->position
);
17065 saved_avoid_cursor
= it
->avoid_cursor_p
;
17066 it
->avoid_cursor_p
= 1;
17067 saved_face_id
= it
->face_id
;
17068 /* The last row's stretch glyph should get the default
17069 face, to avoid painting the rest of the window with
17070 the region face, if the region ends at ZV. */
17071 if (it
->glyph_row
->ends_at_zv_p
)
17072 it
->face_id
= DEFAULT_FACE_ID
;
17074 it
->face_id
= face
->id
;
17075 append_stretch_glyph (it
, make_number (0), stretch_width
,
17076 it
->ascent
+ it
->descent
, stretch_ascent
);
17077 it
->position
= saved_pos
;
17078 it
->avoid_cursor_p
= saved_avoid_cursor
;
17079 it
->face_id
= saved_face_id
;
17082 #endif /* HAVE_WINDOW_SYSTEM */
17086 /* Save some values that must not be changed. */
17087 int saved_x
= it
->current_x
;
17088 struct text_pos saved_pos
;
17089 Lisp_Object saved_object
;
17090 enum display_element_type saved_what
= it
->what
;
17091 int saved_face_id
= it
->face_id
;
17093 saved_object
= it
->object
;
17094 saved_pos
= it
->position
;
17096 it
->what
= IT_CHARACTER
;
17097 memset (&it
->position
, 0, sizeof it
->position
);
17098 it
->object
= make_number (0);
17099 it
->c
= it
->char_to_display
= ' ';
17101 /* The last row's blank glyphs should get the default face, to
17102 avoid painting the rest of the window with the region face,
17103 if the region ends at ZV. */
17104 if (it
->glyph_row
->ends_at_zv_p
)
17105 it
->face_id
= DEFAULT_FACE_ID
;
17107 it
->face_id
= face
->id
;
17109 PRODUCE_GLYPHS (it
);
17111 while (it
->current_x
<= it
->last_visible_x
)
17112 PRODUCE_GLYPHS (it
);
17114 /* Don't count these blanks really. It would let us insert a left
17115 truncation glyph below and make us set the cursor on them, maybe. */
17116 it
->current_x
= saved_x
;
17117 it
->object
= saved_object
;
17118 it
->position
= saved_pos
;
17119 it
->what
= saved_what
;
17120 it
->face_id
= saved_face_id
;
17125 /* Value is non-zero if text starting at CHARPOS in current_buffer is
17126 trailing whitespace. */
17129 trailing_whitespace_p (EMACS_INT charpos
)
17131 EMACS_INT bytepos
= CHAR_TO_BYTE (charpos
);
17134 while (bytepos
< ZV_BYTE
17135 && (c
= FETCH_CHAR (bytepos
),
17136 c
== ' ' || c
== '\t'))
17139 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
17141 if (bytepos
!= PT_BYTE
)
17148 /* Highlight trailing whitespace, if any, in ROW. */
17151 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
17153 int used
= row
->used
[TEXT_AREA
];
17157 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
17158 struct glyph
*glyph
= start
+ used
- 1;
17160 if (row
->reversed_p
)
17162 /* Right-to-left rows need to be processed in the opposite
17163 direction, so swap the edge pointers. */
17165 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
17168 /* Skip over glyphs inserted to display the cursor at the
17169 end of a line, for extending the face of the last glyph
17170 to the end of the line on terminals, and for truncation
17171 and continuation glyphs. */
17172 if (!row
->reversed_p
)
17174 while (glyph
>= start
17175 && glyph
->type
== CHAR_GLYPH
17176 && INTEGERP (glyph
->object
))
17181 while (glyph
<= start
17182 && glyph
->type
== CHAR_GLYPH
17183 && INTEGERP (glyph
->object
))
17187 /* If last glyph is a space or stretch, and it's trailing
17188 whitespace, set the face of all trailing whitespace glyphs in
17189 IT->glyph_row to `trailing-whitespace'. */
17190 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
17191 && BUFFERP (glyph
->object
)
17192 && (glyph
->type
== STRETCH_GLYPH
17193 || (glyph
->type
== CHAR_GLYPH
17194 && glyph
->u
.ch
== ' '))
17195 && trailing_whitespace_p (glyph
->charpos
))
17197 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
17201 if (!row
->reversed_p
)
17203 while (glyph
>= start
17204 && BUFFERP (glyph
->object
)
17205 && (glyph
->type
== STRETCH_GLYPH
17206 || (glyph
->type
== CHAR_GLYPH
17207 && glyph
->u
.ch
== ' ')))
17208 (glyph
--)->face_id
= face_id
;
17212 while (glyph
<= start
17213 && BUFFERP (glyph
->object
)
17214 && (glyph
->type
== STRETCH_GLYPH
17215 || (glyph
->type
== CHAR_GLYPH
17216 && glyph
->u
.ch
== ' ')))
17217 (glyph
++)->face_id
= face_id
;
17224 /* Value is non-zero if glyph row ROW should be
17225 used to hold the cursor. */
17228 cursor_row_p (struct glyph_row
*row
)
17232 if (PT
== CHARPOS (row
->end
.pos
))
17234 /* Suppose the row ends on a string.
17235 Unless the row is continued, that means it ends on a newline
17236 in the string. If it's anything other than a display string
17237 (e.g. a before-string from an overlay), we don't want the
17238 cursor there. (This heuristic seems to give the optimal
17239 behavior for the various types of multi-line strings.) */
17240 if (CHARPOS (row
->end
.string_pos
) >= 0)
17242 if (row
->continued_p
)
17246 /* Check for `display' property. */
17247 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17248 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17249 struct glyph
*glyph
;
17252 for (glyph
= end
; glyph
>= beg
; --glyph
)
17253 if (STRINGP (glyph
->object
))
17256 = Fget_char_property (make_number (PT
),
17260 && display_prop_string_p (prop
, glyph
->object
));
17265 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17267 /* If the row ends in middle of a real character,
17268 and the line is continued, we want the cursor here.
17269 That's because CHARPOS (ROW->end.pos) would equal
17270 PT if PT is before the character. */
17271 if (!row
->ends_in_ellipsis_p
)
17272 result
= row
->continued_p
;
17274 /* If the row ends in an ellipsis, then
17275 CHARPOS (ROW->end.pos) will equal point after the
17276 invisible text. We want that position to be displayed
17277 after the ellipsis. */
17280 /* If the row ends at ZV, display the cursor at the end of that
17281 row instead of at the start of the row below. */
17282 else if (row
->ends_at_zv_p
)
17293 /* Push the display property PROP so that it will be rendered at the
17294 current position in IT. Return 1 if PROP was successfully pushed,
17298 push_display_prop (struct it
*it
, Lisp_Object prop
)
17300 push_it (it
, NULL
);
17302 if (STRINGP (prop
))
17304 if (SCHARS (prop
) == 0)
17311 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17312 it
->current
.overlay_string_index
= -1;
17313 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17314 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17315 it
->method
= GET_FROM_STRING
;
17316 it
->stop_charpos
= 0;
17318 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17320 it
->method
= GET_FROM_STRETCH
;
17323 #ifdef HAVE_WINDOW_SYSTEM
17324 else if (IMAGEP (prop
))
17326 it
->what
= IT_IMAGE
;
17327 it
->image_id
= lookup_image (it
->f
, prop
);
17328 it
->method
= GET_FROM_IMAGE
;
17330 #endif /* HAVE_WINDOW_SYSTEM */
17333 pop_it (it
); /* bogus display property, give up */
17340 /* Return the character-property PROP at the current position in IT. */
17343 get_it_property (struct it
*it
, Lisp_Object prop
)
17345 Lisp_Object position
;
17347 if (STRINGP (it
->object
))
17348 position
= make_number (IT_STRING_CHARPOS (*it
));
17349 else if (BUFFERP (it
->object
))
17350 position
= make_number (IT_CHARPOS (*it
));
17354 return Fget_char_property (position
, prop
, it
->object
);
17357 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17360 handle_line_prefix (struct it
*it
)
17362 Lisp_Object prefix
;
17363 if (it
->continuation_lines_width
> 0)
17365 prefix
= get_it_property (it
, Qwrap_prefix
);
17367 prefix
= Vwrap_prefix
;
17371 prefix
= get_it_property (it
, Qline_prefix
);
17373 prefix
= Vline_prefix
;
17375 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17377 /* If the prefix is wider than the window, and we try to wrap
17378 it, it would acquire its own wrap prefix, and so on till the
17379 iterator stack overflows. So, don't wrap the prefix. */
17380 it
->line_wrap
= TRUNCATE
;
17381 it
->avoid_cursor_p
= 1;
17387 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
17388 only for R2L lines from display_line, when it decides that too many
17389 glyphs were produced by PRODUCE_GLYPHS, and the line needs to be
17392 unproduce_glyphs (struct it
*it
, int n
)
17394 struct glyph
*glyph
, *end
;
17396 xassert (it
->glyph_row
);
17397 xassert (it
->glyph_row
->reversed_p
);
17398 xassert (it
->area
== TEXT_AREA
);
17399 xassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
17401 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
17402 n
= it
->glyph_row
->used
[TEXT_AREA
];
17403 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
17404 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
17405 for ( ; glyph
< end
; glyph
++)
17406 glyph
[-n
] = *glyph
;
17409 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
17410 and ROW->maxpos. */
17412 find_row_edges (struct it
*it
, struct glyph_row
*row
,
17413 EMACS_INT min_pos
, EMACS_INT min_bpos
,
17414 EMACS_INT max_pos
, EMACS_INT max_bpos
)
17416 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17417 lines' rows is implemented for bidi-reordered rows. */
17419 /* ROW->minpos is the value of min_pos, the minimal buffer position
17422 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
17424 /* We didn't find _any_ valid buffer positions in any of the
17425 glyphs, so we must trust the iterator's computed positions. */
17426 row
->minpos
= row
->start
.pos
;
17429 max_pos
= CHARPOS (it
->current
.pos
);
17430 max_bpos
= BYTEPOS (it
->current
.pos
);
17433 /* Here are the various use-cases for ending the row, and the
17434 corresponding values for ROW->maxpos:
17436 Line ends in a newline from buffer eol_pos + 1
17437 Line is continued from buffer max_pos + 1
17438 Line is truncated on right it->current.pos
17439 Line ends in a newline from string max_pos
17440 Line is continued from string max_pos
17441 Line is continued from display vector max_pos
17442 Line is entirely from a string min_pos == max_pos
17443 Line is entirely from a display vector min_pos == max_pos
17444 Line that ends at ZV ZV
17446 If you discover other use-cases, please add them here as
17448 if (row
->ends_at_zv_p
)
17449 row
->maxpos
= it
->current
.pos
;
17450 else if (row
->used
[TEXT_AREA
])
17452 if (row
->ends_in_newline_from_string_p
)
17453 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17454 else if (CHARPOS (it
->eol_pos
) > 0)
17455 SET_TEXT_POS (row
->maxpos
,
17456 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
17457 else if (row
->continued_p
)
17459 /* If max_pos is different from IT's current position, it
17460 means IT->method does not belong to the display element
17461 at max_pos. However, it also means that the display
17462 element at max_pos was displayed in its entirety on this
17463 line, which is equivalent to saying that the next line
17464 starts at the next buffer position. */
17465 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
17466 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17469 INC_BOTH (max_pos
, max_bpos
);
17470 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
17473 else if (row
->truncated_on_right_p
)
17474 /* display_line already called reseat_at_next_visible_line_start,
17475 which puts the iterator at the beginning of the next line, in
17476 the logical order. */
17477 row
->maxpos
= it
->current
.pos
;
17478 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
17479 /* A line that is entirely from a string/image/stretch... */
17480 row
->maxpos
= row
->minpos
;
17485 row
->maxpos
= it
->current
.pos
;
17488 /* Construct the glyph row IT->glyph_row in the desired matrix of
17489 IT->w from text at the current position of IT. See dispextern.h
17490 for an overview of struct it. Value is non-zero if
17491 IT->glyph_row displays text, as opposed to a line displaying ZV
17495 display_line (struct it
*it
)
17497 struct glyph_row
*row
= it
->glyph_row
;
17498 Lisp_Object overlay_arrow_string
;
17500 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
17501 int wrap_row_used
= -1;
17502 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
17503 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
17504 int wrap_row_extra_line_spacing
IF_LINT (= 0);
17505 EMACS_INT wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
17506 EMACS_INT wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
17508 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
17509 EMACS_INT min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
17511 /* We always start displaying at hpos zero even if hscrolled. */
17512 xassert (it
->hpos
== 0 && it
->current_x
== 0);
17514 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
17515 >= it
->w
->desired_matrix
->nrows
)
17517 it
->w
->nrows_scale_factor
++;
17518 fonts_changed_p
= 1;
17522 /* Is IT->w showing the region? */
17523 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
17525 /* Clear the result glyph row and enable it. */
17526 prepare_desired_row (row
);
17528 row
->y
= it
->current_y
;
17529 row
->start
= it
->start
;
17530 row
->continuation_lines_width
= it
->continuation_lines_width
;
17531 row
->displays_text_p
= 1;
17532 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
17533 it
->starts_in_middle_of_char_p
= 0;
17535 /* Arrange the overlays nicely for our purposes. Usually, we call
17536 display_line on only one line at a time, in which case this
17537 can't really hurt too much, or we call it on lines which appear
17538 one after another in the buffer, in which case all calls to
17539 recenter_overlay_lists but the first will be pretty cheap. */
17540 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
17542 /* Move over display elements that are not visible because we are
17543 hscrolled. This may stop at an x-position < IT->first_visible_x
17544 if the first glyph is partially visible or if we hit a line end. */
17545 if (it
->current_x
< it
->first_visible_x
)
17547 this_line_min_pos
= row
->start
.pos
;
17548 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
17549 MOVE_TO_POS
| MOVE_TO_X
);
17550 /* Record the smallest positions seen while we moved over
17551 display elements that are not visible. This is needed by
17552 redisplay_internal for optimizing the case where the cursor
17553 stays inside the same line. The rest of this function only
17554 considers positions that are actually displayed, so
17555 RECORD_MAX_MIN_POS will not otherwise record positions that
17556 are hscrolled to the left of the left edge of the window. */
17557 min_pos
= CHARPOS (this_line_min_pos
);
17558 min_bpos
= BYTEPOS (this_line_min_pos
);
17562 /* We only do this when not calling `move_it_in_display_line_to'
17563 above, because move_it_in_display_line_to calls
17564 handle_line_prefix itself. */
17565 handle_line_prefix (it
);
17568 /* Get the initial row height. This is either the height of the
17569 text hscrolled, if there is any, or zero. */
17570 row
->ascent
= it
->max_ascent
;
17571 row
->height
= it
->max_ascent
+ it
->max_descent
;
17572 row
->phys_ascent
= it
->max_phys_ascent
;
17573 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17574 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17576 /* Utility macro to record max and min buffer positions seen until now. */
17577 #define RECORD_MAX_MIN_POS(IT) \
17580 if (IT_CHARPOS (*(IT)) < min_pos) \
17582 min_pos = IT_CHARPOS (*(IT)); \
17583 min_bpos = IT_BYTEPOS (*(IT)); \
17585 if (IT_CHARPOS (*(IT)) > max_pos) \
17587 max_pos = IT_CHARPOS (*(IT)); \
17588 max_bpos = IT_BYTEPOS (*(IT)); \
17593 /* Loop generating characters. The loop is left with IT on the next
17594 character to display. */
17597 int n_glyphs_before
, hpos_before
, x_before
;
17599 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17601 /* Retrieve the next thing to display. Value is zero if end of
17603 if (!get_next_display_element (it
))
17605 /* Maybe add a space at the end of this line that is used to
17606 display the cursor there under X. Set the charpos of the
17607 first glyph of blank lines not corresponding to any text
17609 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17610 row
->exact_window_width_line_p
= 1;
17611 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17612 || row
->used
[TEXT_AREA
] == 0)
17614 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17615 row
->displays_text_p
= 0;
17617 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
17618 && (!MINI_WINDOW_P (it
->w
)
17619 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17620 row
->indicate_empty_line_p
= 1;
17623 it
->continuation_lines_width
= 0;
17624 row
->ends_at_zv_p
= 1;
17625 /* A row that displays right-to-left text must always have
17626 its last face extended all the way to the end of line,
17627 even if this row ends in ZV, because we still write to
17628 the screen left to right. */
17629 if (row
->reversed_p
)
17630 extend_face_to_end_of_line (it
);
17634 /* Now, get the metrics of what we want to display. This also
17635 generates glyphs in `row' (which is IT->glyph_row). */
17636 n_glyphs_before
= row
->used
[TEXT_AREA
];
17639 /* Remember the line height so far in case the next element doesn't
17640 fit on the line. */
17641 if (it
->line_wrap
!= TRUNCATE
)
17643 ascent
= it
->max_ascent
;
17644 descent
= it
->max_descent
;
17645 phys_ascent
= it
->max_phys_ascent
;
17646 phys_descent
= it
->max_phys_descent
;
17648 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17650 if (IT_DISPLAYING_WHITESPACE (it
))
17656 wrap_row_used
= row
->used
[TEXT_AREA
];
17657 wrap_row_ascent
= row
->ascent
;
17658 wrap_row_height
= row
->height
;
17659 wrap_row_phys_ascent
= row
->phys_ascent
;
17660 wrap_row_phys_height
= row
->phys_height
;
17661 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
17662 wrap_row_min_pos
= min_pos
;
17663 wrap_row_min_bpos
= min_bpos
;
17664 wrap_row_max_pos
= max_pos
;
17665 wrap_row_max_bpos
= max_bpos
;
17671 PRODUCE_GLYPHS (it
);
17673 /* If this display element was in marginal areas, continue with
17675 if (it
->area
!= TEXT_AREA
)
17677 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17678 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17679 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17680 row
->phys_height
= max (row
->phys_height
,
17681 it
->max_phys_ascent
+ it
->max_phys_descent
);
17682 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17683 it
->max_extra_line_spacing
);
17684 set_iterator_to_next (it
, 1);
17688 /* Does the display element fit on the line? If we truncate
17689 lines, we should draw past the right edge of the window. If
17690 we don't truncate, we want to stop so that we can display the
17691 continuation glyph before the right margin. If lines are
17692 continued, there are two possible strategies for characters
17693 resulting in more than 1 glyph (e.g. tabs): Display as many
17694 glyphs as possible in this line and leave the rest for the
17695 continuation line, or display the whole element in the next
17696 line. Original redisplay did the former, so we do it also. */
17697 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
17698 hpos_before
= it
->hpos
;
17701 if (/* Not a newline. */
17703 /* Glyphs produced fit entirely in the line. */
17704 && it
->current_x
< it
->last_visible_x
)
17706 it
->hpos
+= nglyphs
;
17707 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17708 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17709 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17710 row
->phys_height
= max (row
->phys_height
,
17711 it
->max_phys_ascent
+ it
->max_phys_descent
);
17712 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17713 it
->max_extra_line_spacing
);
17714 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
17715 row
->x
= x
- it
->first_visible_x
;
17716 /* Record the maximum and minimum buffer positions seen so
17717 far in glyphs that will be displayed by this row. */
17719 RECORD_MAX_MIN_POS (it
);
17724 struct glyph
*glyph
;
17726 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
17728 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17729 new_x
= x
+ glyph
->pixel_width
;
17731 if (/* Lines are continued. */
17732 it
->line_wrap
!= TRUNCATE
17733 && (/* Glyph doesn't fit on the line. */
17734 new_x
> it
->last_visible_x
17735 /* Or it fits exactly on a window system frame. */
17736 || (new_x
== it
->last_visible_x
17737 && FRAME_WINDOW_P (it
->f
))))
17739 /* End of a continued line. */
17742 || (new_x
== it
->last_visible_x
17743 && FRAME_WINDOW_P (it
->f
)))
17745 /* Current glyph is the only one on the line or
17746 fits exactly on the line. We must continue
17747 the line because we can't draw the cursor
17748 after the glyph. */
17749 row
->continued_p
= 1;
17750 it
->current_x
= new_x
;
17751 it
->continuation_lines_width
+= new_x
;
17753 /* Record the maximum and minimum buffer
17754 positions seen so far in glyphs that will be
17755 displayed by this row. */
17757 RECORD_MAX_MIN_POS (it
);
17758 if (i
== nglyphs
- 1)
17760 /* If line-wrap is on, check if a previous
17761 wrap point was found. */
17762 if (wrap_row_used
> 0
17763 /* Even if there is a previous wrap
17764 point, continue the line here as
17765 usual, if (i) the previous character
17766 was a space or tab AND (ii) the
17767 current character is not. */
17769 || IT_DISPLAYING_WHITESPACE (it
)))
17772 set_iterator_to_next (it
, 1);
17773 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17775 if (!get_next_display_element (it
))
17777 row
->exact_window_width_line_p
= 1;
17778 it
->continuation_lines_width
= 0;
17779 row
->continued_p
= 0;
17780 row
->ends_at_zv_p
= 1;
17782 else if (ITERATOR_AT_END_OF_LINE_P (it
))
17784 row
->continued_p
= 0;
17785 row
->exact_window_width_line_p
= 1;
17790 else if (CHAR_GLYPH_PADDING_P (*glyph
)
17791 && !FRAME_WINDOW_P (it
->f
))
17793 /* A padding glyph that doesn't fit on this line.
17794 This means the whole character doesn't fit
17796 if (row
->reversed_p
)
17797 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
17798 - n_glyphs_before
);
17799 row
->used
[TEXT_AREA
] = n_glyphs_before
;
17801 /* Fill the rest of the row with continuation
17802 glyphs like in 20.x. */
17803 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
17804 < row
->glyphs
[1 + TEXT_AREA
])
17805 produce_special_glyphs (it
, IT_CONTINUATION
);
17807 row
->continued_p
= 1;
17808 it
->current_x
= x_before
;
17809 it
->continuation_lines_width
+= x_before
;
17811 /* Restore the height to what it was before the
17812 element not fitting on the line. */
17813 it
->max_ascent
= ascent
;
17814 it
->max_descent
= descent
;
17815 it
->max_phys_ascent
= phys_ascent
;
17816 it
->max_phys_descent
= phys_descent
;
17818 else if (wrap_row_used
> 0)
17821 if (row
->reversed_p
)
17822 unproduce_glyphs (it
,
17823 row
->used
[TEXT_AREA
] - wrap_row_used
);
17825 it
->continuation_lines_width
+= wrap_x
;
17826 row
->used
[TEXT_AREA
] = wrap_row_used
;
17827 row
->ascent
= wrap_row_ascent
;
17828 row
->height
= wrap_row_height
;
17829 row
->phys_ascent
= wrap_row_phys_ascent
;
17830 row
->phys_height
= wrap_row_phys_height
;
17831 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
17832 min_pos
= wrap_row_min_pos
;
17833 min_bpos
= wrap_row_min_bpos
;
17834 max_pos
= wrap_row_max_pos
;
17835 max_bpos
= wrap_row_max_bpos
;
17836 row
->continued_p
= 1;
17837 row
->ends_at_zv_p
= 0;
17838 row
->exact_window_width_line_p
= 0;
17839 it
->continuation_lines_width
+= x
;
17841 /* Make sure that a non-default face is extended
17842 up to the right margin of the window. */
17843 extend_face_to_end_of_line (it
);
17845 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
17847 /* A TAB that extends past the right edge of the
17848 window. This produces a single glyph on
17849 window system frames. We leave the glyph in
17850 this row and let it fill the row, but don't
17851 consume the TAB. */
17852 it
->continuation_lines_width
+= it
->last_visible_x
;
17853 row
->ends_in_middle_of_char_p
= 1;
17854 row
->continued_p
= 1;
17855 glyph
->pixel_width
= it
->last_visible_x
- x
;
17856 it
->starts_in_middle_of_char_p
= 1;
17860 /* Something other than a TAB that draws past
17861 the right edge of the window. Restore
17862 positions to values before the element. */
17863 if (row
->reversed_p
)
17864 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
17865 - (n_glyphs_before
+ i
));
17866 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17868 /* Display continuation glyphs. */
17869 if (!FRAME_WINDOW_P (it
->f
))
17870 produce_special_glyphs (it
, IT_CONTINUATION
);
17871 row
->continued_p
= 1;
17873 it
->current_x
= x_before
;
17874 it
->continuation_lines_width
+= x
;
17875 extend_face_to_end_of_line (it
);
17877 if (nglyphs
> 1 && i
> 0)
17879 row
->ends_in_middle_of_char_p
= 1;
17880 it
->starts_in_middle_of_char_p
= 1;
17883 /* Restore the height to what it was before the
17884 element not fitting on the line. */
17885 it
->max_ascent
= ascent
;
17886 it
->max_descent
= descent
;
17887 it
->max_phys_ascent
= phys_ascent
;
17888 it
->max_phys_descent
= phys_descent
;
17893 else if (new_x
> it
->first_visible_x
)
17895 /* Increment number of glyphs actually displayed. */
17898 /* Record the maximum and minimum buffer positions
17899 seen so far in glyphs that will be displayed by
17902 RECORD_MAX_MIN_POS (it
);
17904 if (x
< it
->first_visible_x
)
17905 /* Glyph is partially visible, i.e. row starts at
17906 negative X position. */
17907 row
->x
= x
- it
->first_visible_x
;
17911 /* Glyph is completely off the left margin of the
17912 window. This should not happen because of the
17913 move_it_in_display_line at the start of this
17914 function, unless the text display area of the
17915 window is empty. */
17916 xassert (it
->first_visible_x
<= it
->last_visible_x
);
17920 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17921 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17922 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17923 row
->phys_height
= max (row
->phys_height
,
17924 it
->max_phys_ascent
+ it
->max_phys_descent
);
17925 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17926 it
->max_extra_line_spacing
);
17928 /* End of this display line if row is continued. */
17929 if (row
->continued_p
|| row
->ends_at_zv_p
)
17934 /* Is this a line end? If yes, we're also done, after making
17935 sure that a non-default face is extended up to the right
17936 margin of the window. */
17937 if (ITERATOR_AT_END_OF_LINE_P (it
))
17939 int used_before
= row
->used
[TEXT_AREA
];
17941 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
17943 /* Add a space at the end of the line that is used to
17944 display the cursor there. */
17945 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17946 append_space_for_newline (it
, 0);
17948 /* Extend the face to the end of the line. */
17949 extend_face_to_end_of_line (it
);
17951 /* Make sure we have the position. */
17952 if (used_before
== 0)
17953 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
17955 /* Record the position of the newline, for use in
17957 it
->eol_pos
= it
->current
.pos
;
17959 /* Consume the line end. This skips over invisible lines. */
17960 set_iterator_to_next (it
, 1);
17961 it
->continuation_lines_width
= 0;
17965 /* Proceed with next display element. Note that this skips
17966 over lines invisible because of selective display. */
17967 set_iterator_to_next (it
, 1);
17969 /* If we truncate lines, we are done when the last displayed
17970 glyphs reach past the right margin of the window. */
17971 if (it
->line_wrap
== TRUNCATE
17972 && (FRAME_WINDOW_P (it
->f
)
17973 ? (it
->current_x
>= it
->last_visible_x
)
17974 : (it
->current_x
> it
->last_visible_x
)))
17976 /* Maybe add truncation glyphs. */
17977 if (!FRAME_WINDOW_P (it
->f
))
17981 if (!row
->reversed_p
)
17983 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17984 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17989 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
17990 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17992 /* Remove any padding glyphs at the front of ROW, to
17993 make room for the truncation glyphs we will be
17994 adding below. The loop below always inserts at
17995 least one truncation glyph, so also remove the
17996 last glyph added to ROW. */
17997 unproduce_glyphs (it
, i
+ 1);
17998 /* Adjust i for the loop below. */
17999 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
18002 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18004 row
->used
[TEXT_AREA
] = i
;
18005 produce_special_glyphs (it
, IT_TRUNCATION
);
18008 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
18010 /* Don't truncate if we can overflow newline into fringe. */
18011 if (!get_next_display_element (it
))
18013 it
->continuation_lines_width
= 0;
18014 row
->ends_at_zv_p
= 1;
18015 row
->exact_window_width_line_p
= 1;
18018 if (ITERATOR_AT_END_OF_LINE_P (it
))
18020 row
->exact_window_width_line_p
= 1;
18021 goto at_end_of_line
;
18025 row
->truncated_on_right_p
= 1;
18026 it
->continuation_lines_width
= 0;
18027 reseat_at_next_visible_line_start (it
, 0);
18028 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
18029 it
->hpos
= hpos_before
;
18030 it
->current_x
= x_before
;
18035 /* If line is not empty and hscrolled, maybe insert truncation glyphs
18036 at the left window margin. */
18037 if (it
->first_visible_x
18038 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
18040 if (!FRAME_WINDOW_P (it
->f
))
18041 insert_left_trunc_glyphs (it
);
18042 row
->truncated_on_left_p
= 1;
18045 /* Remember the position at which this line ends.
18047 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
18048 cannot be before the call to find_row_edges below, since that is
18049 where these positions are determined. */
18050 row
->end
= it
->current
;
18053 row
->minpos
= row
->start
.pos
;
18054 row
->maxpos
= row
->end
.pos
;
18058 /* ROW->minpos and ROW->maxpos must be the smallest and
18059 `1 + the largest' buffer positions in ROW. But if ROW was
18060 bidi-reordered, these two positions can be anywhere in the
18061 row, so we must determine them now. */
18062 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
18065 /* If the start of this line is the overlay arrow-position, then
18066 mark this glyph row as the one containing the overlay arrow.
18067 This is clearly a mess with variable size fonts. It would be
18068 better to let it be displayed like cursors under X. */
18069 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
18070 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
18071 !NILP (overlay_arrow_string
)))
18073 /* Overlay arrow in window redisplay is a fringe bitmap. */
18074 if (STRINGP (overlay_arrow_string
))
18076 struct glyph_row
*arrow_row
18077 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
18078 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
18079 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
18080 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
18081 struct glyph
*p2
, *end
;
18083 /* Copy the arrow glyphs. */
18084 while (glyph
< arrow_end
)
18087 /* Throw away padding glyphs. */
18089 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
18090 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
18096 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
18101 xassert (INTEGERP (overlay_arrow_string
));
18102 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
18104 overlay_arrow_seen
= 1;
18107 /* Compute pixel dimensions of this line. */
18108 compute_line_metrics (it
);
18110 /* Record whether this row ends inside an ellipsis. */
18111 row
->ends_in_ellipsis_p
18112 = (it
->method
== GET_FROM_DISPLAY_VECTOR
18113 && it
->ellipsis_p
);
18115 /* Save fringe bitmaps in this row. */
18116 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
18117 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
18118 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
18119 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
18121 it
->left_user_fringe_bitmap
= 0;
18122 it
->left_user_fringe_face_id
= 0;
18123 it
->right_user_fringe_bitmap
= 0;
18124 it
->right_user_fringe_face_id
= 0;
18126 /* Maybe set the cursor. */
18127 cvpos
= it
->w
->cursor
.vpos
;
18129 /* In bidi-reordered rows, keep checking for proper cursor
18130 position even if one has been found already, because buffer
18131 positions in such rows change non-linearly with ROW->VPOS,
18132 when a line is continued. One exception: when we are at ZV,
18133 display cursor on the first suitable glyph row, since all
18134 the empty rows after that also have their position set to ZV. */
18135 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18136 lines' rows is implemented for bidi-reordered rows. */
18138 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
18139 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
18140 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
18141 && cursor_row_p (row
))
18142 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
18144 /* Highlight trailing whitespace. */
18145 if (!NILP (Vshow_trailing_whitespace
))
18146 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
18148 /* Prepare for the next line. This line starts horizontally at (X
18149 HPOS) = (0 0). Vertical positions are incremented. As a
18150 convenience for the caller, IT->glyph_row is set to the next
18152 it
->current_x
= it
->hpos
= 0;
18153 it
->current_y
+= row
->height
;
18154 SET_TEXT_POS (it
->eol_pos
, 0, 0);
18157 /* The next row should by default use the same value of the
18158 reversed_p flag as this one. set_iterator_to_next decides when
18159 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
18160 the flag accordingly. */
18161 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
18162 it
->glyph_row
->reversed_p
= row
->reversed_p
;
18163 it
->start
= row
->end
;
18164 return row
->displays_text_p
;
18166 #undef RECORD_MAX_MIN_POS
18169 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
18170 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
18171 doc
: /* Return paragraph direction at point in BUFFER.
18172 Value is either `left-to-right' or `right-to-left'.
18173 If BUFFER is omitted or nil, it defaults to the current buffer.
18175 Paragraph direction determines how the text in the paragraph is displayed.
18176 In left-to-right paragraphs, text begins at the left margin of the window
18177 and the reading direction is generally left to right. In right-to-left
18178 paragraphs, text begins at the right margin and is read from right to left.
18180 See also `bidi-paragraph-direction'. */)
18181 (Lisp_Object buffer
)
18183 struct buffer
*buf
= current_buffer
;
18184 struct buffer
*old
= buf
;
18186 if (! NILP (buffer
))
18188 CHECK_BUFFER (buffer
);
18189 buf
= XBUFFER (buffer
);
18192 if (NILP (BVAR (buf
, bidi_display_reordering
)))
18193 return Qleft_to_right
;
18194 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
18195 return BVAR (buf
, bidi_paragraph_direction
);
18198 /* Determine the direction from buffer text. We could try to
18199 use current_matrix if it is up to date, but this seems fast
18200 enough as it is. */
18201 struct bidi_it itb
;
18202 EMACS_INT pos
= BUF_PT (buf
);
18203 EMACS_INT bytepos
= BUF_PT_BYTE (buf
);
18206 set_buffer_temp (buf
);
18207 /* bidi_paragraph_init finds the base direction of the paragraph
18208 by searching forward from paragraph start. We need the base
18209 direction of the current or _previous_ paragraph, so we need
18210 to make sure we are within that paragraph. To that end, find
18211 the previous non-empty line. */
18212 if (pos
>= ZV
&& pos
> BEGV
)
18215 bytepos
= CHAR_TO_BYTE (pos
);
18217 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
18218 || c
== ' ' || c
== '\t' || c
== '\f')
18220 if (bytepos
<= BEGV_BYTE
)
18225 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
18228 itb
.bytepos
= bytepos
;
18230 itb
.string
.s
= NULL
;
18231 itb
.frame_window_p
= FRAME_WINDOW_P (SELECTED_FRAME ()); /* guesswork */
18233 itb
.separator_limit
= -1;
18234 itb
.paragraph_dir
= NEUTRAL_DIR
;
18236 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
18237 set_buffer_temp (old
);
18238 switch (itb
.paragraph_dir
)
18241 return Qleft_to_right
;
18244 return Qright_to_left
;
18254 /***********************************************************************
18256 ***********************************************************************/
18258 /* Redisplay the menu bar in the frame for window W.
18260 The menu bar of X frames that don't have X toolkit support is
18261 displayed in a special window W->frame->menu_bar_window.
18263 The menu bar of terminal frames is treated specially as far as
18264 glyph matrices are concerned. Menu bar lines are not part of
18265 windows, so the update is done directly on the frame matrix rows
18266 for the menu bar. */
18269 display_menu_bar (struct window
*w
)
18271 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18276 /* Don't do all this for graphical frames. */
18278 if (FRAME_W32_P (f
))
18281 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
18287 if (FRAME_NS_P (f
))
18289 #endif /* HAVE_NS */
18291 #ifdef USE_X_TOOLKIT
18292 xassert (!FRAME_WINDOW_P (f
));
18293 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
18294 it
.first_visible_x
= 0;
18295 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18296 #else /* not USE_X_TOOLKIT */
18297 if (FRAME_WINDOW_P (f
))
18299 /* Menu bar lines are displayed in the desired matrix of the
18300 dummy window menu_bar_window. */
18301 struct window
*menu_w
;
18302 xassert (WINDOWP (f
->menu_bar_window
));
18303 menu_w
= XWINDOW (f
->menu_bar_window
);
18304 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
18306 it
.first_visible_x
= 0;
18307 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
18311 /* This is a TTY frame, i.e. character hpos/vpos are used as
18313 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
18315 it
.first_visible_x
= 0;
18316 it
.last_visible_x
= FRAME_COLS (f
);
18318 #endif /* not USE_X_TOOLKIT */
18320 if (! mode_line_inverse_video
)
18321 /* Force the menu-bar to be displayed in the default face. */
18322 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18324 /* Clear all rows of the menu bar. */
18325 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
18327 struct glyph_row
*row
= it
.glyph_row
+ i
;
18328 clear_glyph_row (row
);
18329 row
->enabled_p
= 1;
18330 row
->full_width_p
= 1;
18333 /* Display all items of the menu bar. */
18334 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
18335 for (i
= 0; i
< ASIZE (items
); i
+= 4)
18337 Lisp_Object string
;
18339 /* Stop at nil string. */
18340 string
= AREF (items
, i
+ 1);
18344 /* Remember where item was displayed. */
18345 ASET (items
, i
+ 3, make_number (it
.hpos
));
18347 /* Display the item, pad with one space. */
18348 if (it
.current_x
< it
.last_visible_x
)
18349 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
18350 SCHARS (string
) + 1, 0, 0, -1);
18353 /* Fill out the line with spaces. */
18354 if (it
.current_x
< it
.last_visible_x
)
18355 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
18357 /* Compute the total height of the lines. */
18358 compute_line_metrics (&it
);
18363 /***********************************************************************
18365 ***********************************************************************/
18367 /* Redisplay mode lines in the window tree whose root is WINDOW. If
18368 FORCE is non-zero, redisplay mode lines unconditionally.
18369 Otherwise, redisplay only mode lines that are garbaged. Value is
18370 the number of windows whose mode lines were redisplayed. */
18373 redisplay_mode_lines (Lisp_Object window
, int force
)
18377 while (!NILP (window
))
18379 struct window
*w
= XWINDOW (window
);
18381 if (WINDOWP (w
->hchild
))
18382 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
18383 else if (WINDOWP (w
->vchild
))
18384 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18386 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18387 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18389 struct text_pos lpoint
;
18390 struct buffer
*old
= current_buffer
;
18392 /* Set the window's buffer for the mode line display. */
18393 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18394 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18396 /* Point refers normally to the selected window. For any
18397 other window, set up appropriate value. */
18398 if (!EQ (window
, selected_window
))
18400 struct text_pos pt
;
18402 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18403 if (CHARPOS (pt
) < BEGV
)
18404 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18405 else if (CHARPOS (pt
) > (ZV
- 1))
18406 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18408 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18411 /* Display mode lines. */
18412 clear_glyph_matrix (w
->desired_matrix
);
18413 if (display_mode_lines (w
))
18416 w
->must_be_updated_p
= 1;
18419 /* Restore old settings. */
18420 set_buffer_internal_1 (old
);
18421 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18431 /* Display the mode and/or header line of window W. Value is the
18432 sum number of mode lines and header lines displayed. */
18435 display_mode_lines (struct window
*w
)
18437 Lisp_Object old_selected_window
, old_selected_frame
;
18440 old_selected_frame
= selected_frame
;
18441 selected_frame
= w
->frame
;
18442 old_selected_window
= selected_window
;
18443 XSETWINDOW (selected_window
, w
);
18445 /* These will be set while the mode line specs are processed. */
18446 line_number_displayed
= 0;
18447 w
->column_number_displayed
= Qnil
;
18449 if (WINDOW_WANTS_MODELINE_P (w
))
18451 struct window
*sel_w
= XWINDOW (old_selected_window
);
18453 /* Select mode line face based on the real selected window. */
18454 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18455 BVAR (current_buffer
, mode_line_format
));
18459 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18461 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18462 BVAR (current_buffer
, header_line_format
));
18466 selected_frame
= old_selected_frame
;
18467 selected_window
= old_selected_window
;
18472 /* Display mode or header line of window W. FACE_ID specifies which
18473 line to display; it is either MODE_LINE_FACE_ID or
18474 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18475 display. Value is the pixel height of the mode/header line
18479 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
18483 int count
= SPECPDL_INDEX ();
18485 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18486 /* Don't extend on a previously drawn mode-line.
18487 This may happen if called from pos_visible_p. */
18488 it
.glyph_row
->enabled_p
= 0;
18489 prepare_desired_row (it
.glyph_row
);
18491 it
.glyph_row
->mode_line_p
= 1;
18493 if (! mode_line_inverse_video
)
18494 /* Force the mode-line to be displayed in the default face. */
18495 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18497 record_unwind_protect (unwind_format_mode_line
,
18498 format_mode_line_unwind_data (NULL
, Qnil
, 0));
18500 mode_line_target
= MODE_LINE_DISPLAY
;
18502 /* Temporarily make frame's keyboard the current kboard so that
18503 kboard-local variables in the mode_line_format will get the right
18505 push_kboard (FRAME_KBOARD (it
.f
));
18506 record_unwind_save_match_data ();
18507 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18510 unbind_to (count
, Qnil
);
18512 /* Fill up with spaces. */
18513 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
18515 compute_line_metrics (&it
);
18516 it
.glyph_row
->full_width_p
= 1;
18517 it
.glyph_row
->continued_p
= 0;
18518 it
.glyph_row
->truncated_on_left_p
= 0;
18519 it
.glyph_row
->truncated_on_right_p
= 0;
18521 /* Make a 3D mode-line have a shadow at its right end. */
18522 face
= FACE_FROM_ID (it
.f
, face_id
);
18523 extend_face_to_end_of_line (&it
);
18524 if (face
->box
!= FACE_NO_BOX
)
18526 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
18527 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
18528 last
->right_box_line_p
= 1;
18531 return it
.glyph_row
->height
;
18534 /* Move element ELT in LIST to the front of LIST.
18535 Return the updated list. */
18538 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
18540 register Lisp_Object tail
, prev
;
18541 register Lisp_Object tem
;
18545 while (CONSP (tail
))
18551 /* Splice out the link TAIL. */
18553 list
= XCDR (tail
);
18555 Fsetcdr (prev
, XCDR (tail
));
18557 /* Now make it the first. */
18558 Fsetcdr (tail
, list
);
18563 tail
= XCDR (tail
);
18567 /* Not found--return unchanged LIST. */
18571 /* Contribute ELT to the mode line for window IT->w. How it
18572 translates into text depends on its data type.
18574 IT describes the display environment in which we display, as usual.
18576 DEPTH is the depth in recursion. It is used to prevent
18577 infinite recursion here.
18579 FIELD_WIDTH is the number of characters the display of ELT should
18580 occupy in the mode line, and PRECISION is the maximum number of
18581 characters to display from ELT's representation. See
18582 display_string for details.
18584 Returns the hpos of the end of the text generated by ELT.
18586 PROPS is a property list to add to any string we encounter.
18588 If RISKY is nonzero, remove (disregard) any properties in any string
18589 we encounter, and ignore :eval and :propertize.
18591 The global variable `mode_line_target' determines whether the
18592 output is passed to `store_mode_line_noprop',
18593 `store_mode_line_string', or `display_string'. */
18596 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
18597 Lisp_Object elt
, Lisp_Object props
, int risky
)
18599 int n
= 0, field
, prec
;
18604 elt
= build_string ("*too-deep*");
18608 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
18612 /* A string: output it and check for %-constructs within it. */
18614 EMACS_INT offset
= 0;
18616 if (SCHARS (elt
) > 0
18617 && (!NILP (props
) || risky
))
18619 Lisp_Object oprops
, aelt
;
18620 oprops
= Ftext_properties_at (make_number (0), elt
);
18622 /* If the starting string's properties are not what
18623 we want, translate the string. Also, if the string
18624 is risky, do that anyway. */
18626 if (NILP (Fequal (props
, oprops
)) || risky
)
18628 /* If the starting string has properties,
18629 merge the specified ones onto the existing ones. */
18630 if (! NILP (oprops
) && !risky
)
18634 oprops
= Fcopy_sequence (oprops
);
18636 while (CONSP (tem
))
18638 oprops
= Fplist_put (oprops
, XCAR (tem
),
18639 XCAR (XCDR (tem
)));
18640 tem
= XCDR (XCDR (tem
));
18645 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
18646 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
18648 /* AELT is what we want. Move it to the front
18649 without consing. */
18651 mode_line_proptrans_alist
18652 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
18658 /* If AELT has the wrong props, it is useless.
18659 so get rid of it. */
18661 mode_line_proptrans_alist
18662 = Fdelq (aelt
, mode_line_proptrans_alist
);
18664 elt
= Fcopy_sequence (elt
);
18665 Fset_text_properties (make_number (0), Flength (elt
),
18667 /* Add this item to mode_line_proptrans_alist. */
18668 mode_line_proptrans_alist
18669 = Fcons (Fcons (elt
, props
),
18670 mode_line_proptrans_alist
);
18671 /* Truncate mode_line_proptrans_alist
18672 to at most 50 elements. */
18673 tem
= Fnthcdr (make_number (50),
18674 mode_line_proptrans_alist
);
18676 XSETCDR (tem
, Qnil
);
18685 prec
= precision
- n
;
18686 switch (mode_line_target
)
18688 case MODE_LINE_NOPROP
:
18689 case MODE_LINE_TITLE
:
18690 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
18692 case MODE_LINE_STRING
:
18693 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
18695 case MODE_LINE_DISPLAY
:
18696 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
18697 0, prec
, 0, STRING_MULTIBYTE (elt
));
18704 /* Handle the non-literal case. */
18706 while ((precision
<= 0 || n
< precision
)
18707 && SREF (elt
, offset
) != 0
18708 && (mode_line_target
!= MODE_LINE_DISPLAY
18709 || it
->current_x
< it
->last_visible_x
))
18711 EMACS_INT last_offset
= offset
;
18713 /* Advance to end of string or next format specifier. */
18714 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
18717 if (offset
- 1 != last_offset
)
18719 EMACS_INT nchars
, nbytes
;
18721 /* Output to end of string or up to '%'. Field width
18722 is length of string. Don't output more than
18723 PRECISION allows us. */
18726 prec
= c_string_width (SDATA (elt
) + last_offset
,
18727 offset
- last_offset
, precision
- n
,
18730 switch (mode_line_target
)
18732 case MODE_LINE_NOPROP
:
18733 case MODE_LINE_TITLE
:
18734 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
18736 case MODE_LINE_STRING
:
18738 EMACS_INT bytepos
= last_offset
;
18739 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
18740 EMACS_INT endpos
= (precision
<= 0
18741 ? string_byte_to_char (elt
, offset
)
18742 : charpos
+ nchars
);
18744 n
+= store_mode_line_string (NULL
,
18745 Fsubstring (elt
, make_number (charpos
),
18746 make_number (endpos
)),
18750 case MODE_LINE_DISPLAY
:
18752 EMACS_INT bytepos
= last_offset
;
18753 EMACS_INT charpos
= string_byte_to_char (elt
, bytepos
);
18755 if (precision
<= 0)
18756 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
18757 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
18759 STRING_MULTIBYTE (elt
));
18764 else /* c == '%' */
18766 EMACS_INT percent_position
= offset
;
18768 /* Get the specified minimum width. Zero means
18771 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
18772 field
= field
* 10 + c
- '0';
18774 /* Don't pad beyond the total padding allowed. */
18775 if (field_width
- n
> 0 && field
> field_width
- n
)
18776 field
= field_width
- n
;
18778 /* Note that either PRECISION <= 0 or N < PRECISION. */
18779 prec
= precision
- n
;
18782 n
+= display_mode_element (it
, depth
, field
, prec
,
18783 Vglobal_mode_string
, props
,
18788 EMACS_INT bytepos
, charpos
;
18790 Lisp_Object string
;
18792 bytepos
= percent_position
;
18793 charpos
= (STRING_MULTIBYTE (elt
)
18794 ? string_byte_to_char (elt
, bytepos
)
18796 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
18797 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
18799 switch (mode_line_target
)
18801 case MODE_LINE_NOPROP
:
18802 case MODE_LINE_TITLE
:
18803 n
+= store_mode_line_noprop (spec
, field
, prec
);
18805 case MODE_LINE_STRING
:
18807 int len
= strlen (spec
);
18808 Lisp_Object tem
= make_string (spec
, len
);
18809 props
= Ftext_properties_at (make_number (charpos
), elt
);
18810 /* Should only keep face property in props */
18811 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
18814 case MODE_LINE_DISPLAY
:
18816 int nglyphs_before
, nwritten
;
18818 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18819 nwritten
= display_string (spec
, string
, elt
,
18824 /* Assign to the glyphs written above the
18825 string where the `%x' came from, position
18829 struct glyph
*glyph
18830 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
18834 for (i
= 0; i
< nwritten
; ++i
)
18836 glyph
[i
].object
= elt
;
18837 glyph
[i
].charpos
= charpos
;
18854 /* A symbol: process the value of the symbol recursively
18855 as if it appeared here directly. Avoid error if symbol void.
18856 Special case: if value of symbol is a string, output the string
18859 register Lisp_Object tem
;
18861 /* If the variable is not marked as risky to set
18862 then its contents are risky to use. */
18863 if (NILP (Fget (elt
, Qrisky_local_variable
)))
18866 tem
= Fboundp (elt
);
18869 tem
= Fsymbol_value (elt
);
18870 /* If value is a string, output that string literally:
18871 don't check for % within it. */
18875 if (!EQ (tem
, elt
))
18877 /* Give up right away for nil or t. */
18887 register Lisp_Object car
, tem
;
18889 /* A cons cell: five distinct cases.
18890 If first element is :eval or :propertize, do something special.
18891 If first element is a string or a cons, process all the elements
18892 and effectively concatenate them.
18893 If first element is a negative number, truncate displaying cdr to
18894 at most that many characters. If positive, pad (with spaces)
18895 to at least that many characters.
18896 If first element is a symbol, process the cadr or caddr recursively
18897 according to whether the symbol's value is non-nil or nil. */
18899 if (EQ (car
, QCeval
))
18901 /* An element of the form (:eval FORM) means evaluate FORM
18902 and use the result as mode line elements. */
18907 if (CONSP (XCDR (elt
)))
18910 spec
= safe_eval (XCAR (XCDR (elt
)));
18911 n
+= display_mode_element (it
, depth
, field_width
- n
,
18912 precision
- n
, spec
, props
,
18916 else if (EQ (car
, QCpropertize
))
18918 /* An element of the form (:propertize ELT PROPS...)
18919 means display ELT but applying properties PROPS. */
18924 if (CONSP (XCDR (elt
)))
18925 n
+= display_mode_element (it
, depth
, field_width
- n
,
18926 precision
- n
, XCAR (XCDR (elt
)),
18927 XCDR (XCDR (elt
)), risky
);
18929 else if (SYMBOLP (car
))
18931 tem
= Fboundp (car
);
18935 /* elt is now the cdr, and we know it is a cons cell.
18936 Use its car if CAR has a non-nil value. */
18939 tem
= Fsymbol_value (car
);
18946 /* Symbol's value is nil (or symbol is unbound)
18947 Get the cddr of the original list
18948 and if possible find the caddr and use that. */
18952 else if (!CONSP (elt
))
18957 else if (INTEGERP (car
))
18959 register int lim
= XINT (car
);
18963 /* Negative int means reduce maximum width. */
18964 if (precision
<= 0)
18967 precision
= min (precision
, -lim
);
18971 /* Padding specified. Don't let it be more than
18972 current maximum. */
18974 lim
= min (precision
, lim
);
18976 /* If that's more padding than already wanted, queue it.
18977 But don't reduce padding already specified even if
18978 that is beyond the current truncation point. */
18979 field_width
= max (lim
, field_width
);
18983 else if (STRINGP (car
) || CONSP (car
))
18985 Lisp_Object halftail
= elt
;
18989 && (precision
<= 0 || n
< precision
))
18991 n
+= display_mode_element (it
, depth
,
18992 /* Do padding only after the last
18993 element in the list. */
18994 (! CONSP (XCDR (elt
))
18997 precision
- n
, XCAR (elt
),
19001 if ((len
& 1) == 0)
19002 halftail
= XCDR (halftail
);
19003 /* Check for cycle. */
19004 if (EQ (halftail
, elt
))
19013 elt
= build_string ("*invalid*");
19017 /* Pad to FIELD_WIDTH. */
19018 if (field_width
> 0 && n
< field_width
)
19020 switch (mode_line_target
)
19022 case MODE_LINE_NOPROP
:
19023 case MODE_LINE_TITLE
:
19024 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
19026 case MODE_LINE_STRING
:
19027 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
19029 case MODE_LINE_DISPLAY
:
19030 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
19039 /* Store a mode-line string element in mode_line_string_list.
19041 If STRING is non-null, display that C string. Otherwise, the Lisp
19042 string LISP_STRING is displayed.
19044 FIELD_WIDTH is the minimum number of output glyphs to produce.
19045 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19046 with spaces. FIELD_WIDTH <= 0 means don't pad.
19048 PRECISION is the maximum number of characters to output from
19049 STRING. PRECISION <= 0 means don't truncate the string.
19051 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
19052 properties to the string.
19054 PROPS are the properties to add to the string.
19055 The mode_line_string_face face property is always added to the string.
19059 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
19060 int field_width
, int precision
, Lisp_Object props
)
19065 if (string
!= NULL
)
19067 len
= strlen (string
);
19068 if (precision
> 0 && len
> precision
)
19070 lisp_string
= make_string (string
, len
);
19072 props
= mode_line_string_face_prop
;
19073 else if (!NILP (mode_line_string_face
))
19075 Lisp_Object face
= Fplist_get (props
, Qface
);
19076 props
= Fcopy_sequence (props
);
19078 face
= mode_line_string_face
;
19080 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19081 props
= Fplist_put (props
, Qface
, face
);
19083 Fadd_text_properties (make_number (0), make_number (len
),
19084 props
, lisp_string
);
19088 len
= XFASTINT (Flength (lisp_string
));
19089 if (precision
> 0 && len
> precision
)
19092 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
19095 if (!NILP (mode_line_string_face
))
19099 props
= Ftext_properties_at (make_number (0), lisp_string
);
19100 face
= Fplist_get (props
, Qface
);
19102 face
= mode_line_string_face
;
19104 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
19105 props
= Fcons (Qface
, Fcons (face
, Qnil
));
19107 lisp_string
= Fcopy_sequence (lisp_string
);
19110 Fadd_text_properties (make_number (0), make_number (len
),
19111 props
, lisp_string
);
19116 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19120 if (field_width
> len
)
19122 field_width
-= len
;
19123 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
19125 Fadd_text_properties (make_number (0), make_number (field_width
),
19126 props
, lisp_string
);
19127 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
19135 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
19137 doc
: /* Format a string out of a mode line format specification.
19138 First arg FORMAT specifies the mode line format (see `mode-line-format'
19139 for details) to use.
19141 By default, the format is evaluated for the currently selected window.
19143 Optional second arg FACE specifies the face property to put on all
19144 characters for which no face is specified. The value nil means the
19145 default face. The value t means whatever face the window's mode line
19146 currently uses (either `mode-line' or `mode-line-inactive',
19147 depending on whether the window is the selected window or not).
19148 An integer value means the value string has no text
19151 Optional third and fourth args WINDOW and BUFFER specify the window
19152 and buffer to use as the context for the formatting (defaults
19153 are the selected window and the WINDOW's buffer). */)
19154 (Lisp_Object format
, Lisp_Object face
,
19155 Lisp_Object window
, Lisp_Object buffer
)
19160 struct buffer
*old_buffer
= NULL
;
19162 int no_props
= INTEGERP (face
);
19163 int count
= SPECPDL_INDEX ();
19165 int string_start
= 0;
19168 window
= selected_window
;
19169 CHECK_WINDOW (window
);
19170 w
= XWINDOW (window
);
19173 buffer
= w
->buffer
;
19174 CHECK_BUFFER (buffer
);
19176 /* Make formatting the modeline a non-op when noninteractive, otherwise
19177 there will be problems later caused by a partially initialized frame. */
19178 if (NILP (format
) || noninteractive
)
19179 return empty_unibyte_string
;
19184 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
19185 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
19186 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
19187 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
19188 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
19189 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
19190 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
19193 if (XBUFFER (buffer
) != current_buffer
)
19194 old_buffer
= current_buffer
;
19196 /* Save things including mode_line_proptrans_alist,
19197 and set that to nil so that we don't alter the outer value. */
19198 record_unwind_protect (unwind_format_mode_line
,
19199 format_mode_line_unwind_data
19200 (old_buffer
, selected_window
, 1));
19201 mode_line_proptrans_alist
= Qnil
;
19203 Fselect_window (window
, Qt
);
19205 set_buffer_internal_1 (XBUFFER (buffer
));
19207 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
19211 mode_line_target
= MODE_LINE_NOPROP
;
19212 mode_line_string_face_prop
= Qnil
;
19213 mode_line_string_list
= Qnil
;
19214 string_start
= MODE_LINE_NOPROP_LEN (0);
19218 mode_line_target
= MODE_LINE_STRING
;
19219 mode_line_string_list
= Qnil
;
19220 mode_line_string_face
= face
;
19221 mode_line_string_face_prop
19222 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
19225 push_kboard (FRAME_KBOARD (it
.f
));
19226 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
19231 len
= MODE_LINE_NOPROP_LEN (string_start
);
19232 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
19236 mode_line_string_list
= Fnreverse (mode_line_string_list
);
19237 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
19238 empty_unibyte_string
);
19241 unbind_to (count
, Qnil
);
19245 /* Write a null-terminated, right justified decimal representation of
19246 the positive integer D to BUF using a minimal field width WIDTH. */
19249 pint2str (register char *buf
, register int width
, register EMACS_INT d
)
19251 register char *p
= buf
;
19259 *p
++ = d
% 10 + '0';
19264 for (width
-= (int) (p
- buf
); width
> 0; --width
)
19275 /* Write a null-terminated, right justified decimal and "human
19276 readable" representation of the nonnegative integer D to BUF using
19277 a minimal field width WIDTH. D should be smaller than 999.5e24. */
19279 static const char power_letter
[] =
19293 pint2hrstr (char *buf
, int width
, EMACS_INT d
)
19295 /* We aim to represent the nonnegative integer D as
19296 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
19297 EMACS_INT quotient
= d
;
19299 /* -1 means: do not use TENTHS. */
19303 /* Length of QUOTIENT.TENTHS as a string. */
19309 if (1000 <= quotient
)
19311 /* Scale to the appropriate EXPONENT. */
19314 remainder
= quotient
% 1000;
19318 while (1000 <= quotient
);
19320 /* Round to nearest and decide whether to use TENTHS or not. */
19323 tenths
= remainder
/ 100;
19324 if (50 <= remainder
% 100)
19331 if (quotient
== 10)
19339 if (500 <= remainder
)
19341 if (quotient
< 999)
19352 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
19353 if (tenths
== -1 && quotient
<= 99)
19360 p
= psuffix
= buf
+ max (width
, length
);
19362 /* Print EXPONENT. */
19363 *psuffix
++ = power_letter
[exponent
];
19366 /* Print TENTHS. */
19369 *--p
= '0' + tenths
;
19373 /* Print QUOTIENT. */
19376 int digit
= quotient
% 10;
19377 *--p
= '0' + digit
;
19379 while ((quotient
/= 10) != 0);
19381 /* Print leading spaces. */
19386 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19387 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19388 type of CODING_SYSTEM. Return updated pointer into BUF. */
19390 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19393 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
19396 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
19397 const unsigned char *eol_str
;
19399 /* The EOL conversion we are using. */
19400 Lisp_Object eoltype
;
19402 val
= CODING_SYSTEM_SPEC (coding_system
);
19405 if (!VECTORP (val
)) /* Not yet decided. */
19410 eoltype
= eol_mnemonic_undecided
;
19411 /* Don't mention EOL conversion if it isn't decided. */
19416 Lisp_Object eolvalue
;
19418 attrs
= AREF (val
, 0);
19419 eolvalue
= AREF (val
, 2);
19422 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19426 /* The EOL conversion that is normal on this system. */
19428 if (NILP (eolvalue
)) /* Not yet decided. */
19429 eoltype
= eol_mnemonic_undecided
;
19430 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19431 eoltype
= eol_mnemonic_undecided
;
19432 else /* eolvalue is Qunix, Qdos, or Qmac. */
19433 eoltype
= (EQ (eolvalue
, Qunix
)
19434 ? eol_mnemonic_unix
19435 : (EQ (eolvalue
, Qdos
) == 1
19436 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19442 /* Mention the EOL conversion if it is not the usual one. */
19443 if (STRINGP (eoltype
))
19445 eol_str
= SDATA (eoltype
);
19446 eol_str_len
= SBYTES (eoltype
);
19448 else if (CHARACTERP (eoltype
))
19450 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19451 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19456 eol_str
= invalid_eol_type
;
19457 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19459 memcpy (buf
, eol_str
, eol_str_len
);
19460 buf
+= eol_str_len
;
19466 /* Return a string for the output of a mode line %-spec for window W,
19467 generated by character C. FIELD_WIDTH > 0 means pad the string
19468 returned with spaces to that value. Return a Lisp string in
19469 *STRING if the resulting string is taken from that Lisp string.
19471 Note we operate on the current buffer for most purposes,
19472 the exception being w->base_line_pos. */
19474 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19476 static const char *
19477 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
19478 Lisp_Object
*string
)
19481 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19482 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19483 struct buffer
*b
= current_buffer
;
19491 if (!NILP (BVAR (b
, read_only
)))
19493 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19498 /* This differs from %* only for a modified read-only buffer. */
19499 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19501 if (!NILP (BVAR (b
, read_only
)))
19506 /* This differs from %* in ignoring read-only-ness. */
19507 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19519 if (command_loop_level
> 5)
19521 p
= decode_mode_spec_buf
;
19522 for (i
= 0; i
< command_loop_level
; i
++)
19525 return decode_mode_spec_buf
;
19533 if (command_loop_level
> 5)
19535 p
= decode_mode_spec_buf
;
19536 for (i
= 0; i
< command_loop_level
; i
++)
19539 return decode_mode_spec_buf
;
19546 /* Let lots_of_dashes be a string of infinite length. */
19547 if (mode_line_target
== MODE_LINE_NOPROP
||
19548 mode_line_target
== MODE_LINE_STRING
)
19550 if (field_width
<= 0
19551 || field_width
> sizeof (lots_of_dashes
))
19553 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
19554 decode_mode_spec_buf
[i
] = '-';
19555 decode_mode_spec_buf
[i
] = '\0';
19556 return decode_mode_spec_buf
;
19559 return lots_of_dashes
;
19563 obj
= BVAR (b
, name
);
19567 /* %c and %l are ignored in `frame-title-format'.
19568 (In redisplay_internal, the frame title is drawn _before_ the
19569 windows are updated, so the stuff which depends on actual
19570 window contents (such as %l) may fail to render properly, or
19571 even crash emacs.) */
19572 if (mode_line_target
== MODE_LINE_TITLE
)
19576 EMACS_INT col
= current_column ();
19577 w
->column_number_displayed
= make_number (col
);
19578 pint2str (decode_mode_spec_buf
, field_width
, col
);
19579 return decode_mode_spec_buf
;
19583 #ifndef SYSTEM_MALLOC
19585 if (NILP (Vmemory_full
))
19588 return "!MEM FULL! ";
19595 /* %F displays the frame name. */
19596 if (!NILP (f
->title
))
19597 return SSDATA (f
->title
);
19598 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
19599 return SSDATA (f
->name
);
19603 obj
= BVAR (b
, filename
);
19608 EMACS_INT size
= ZV
- BEGV
;
19609 pint2str (decode_mode_spec_buf
, field_width
, size
);
19610 return decode_mode_spec_buf
;
19615 EMACS_INT size
= ZV
- BEGV
;
19616 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
19617 return decode_mode_spec_buf
;
19622 EMACS_INT startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
19623 EMACS_INT topline
, nlines
, height
;
19626 /* %c and %l are ignored in `frame-title-format'. */
19627 if (mode_line_target
== MODE_LINE_TITLE
)
19630 startpos
= XMARKER (w
->start
)->charpos
;
19631 startpos_byte
= marker_byte_position (w
->start
);
19632 height
= WINDOW_TOTAL_LINES (w
);
19634 /* If we decided that this buffer isn't suitable for line numbers,
19635 don't forget that too fast. */
19636 if (EQ (w
->base_line_pos
, w
->buffer
))
19638 /* But do forget it, if the window shows a different buffer now. */
19639 else if (BUFFERP (w
->base_line_pos
))
19640 w
->base_line_pos
= Qnil
;
19642 /* If the buffer is very big, don't waste time. */
19643 if (INTEGERP (Vline_number_display_limit
)
19644 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
19646 w
->base_line_pos
= Qnil
;
19647 w
->base_line_number
= Qnil
;
19651 if (INTEGERP (w
->base_line_number
)
19652 && INTEGERP (w
->base_line_pos
)
19653 && XFASTINT (w
->base_line_pos
) <= startpos
)
19655 line
= XFASTINT (w
->base_line_number
);
19656 linepos
= XFASTINT (w
->base_line_pos
);
19657 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
19662 linepos
= BUF_BEGV (b
);
19663 linepos_byte
= BUF_BEGV_BYTE (b
);
19666 /* Count lines from base line to window start position. */
19667 nlines
= display_count_lines (linepos_byte
,
19671 topline
= nlines
+ line
;
19673 /* Determine a new base line, if the old one is too close
19674 or too far away, or if we did not have one.
19675 "Too close" means it's plausible a scroll-down would
19676 go back past it. */
19677 if (startpos
== BUF_BEGV (b
))
19679 w
->base_line_number
= make_number (topline
);
19680 w
->base_line_pos
= make_number (BUF_BEGV (b
));
19682 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
19683 || linepos
== BUF_BEGV (b
))
19685 EMACS_INT limit
= BUF_BEGV (b
);
19686 EMACS_INT limit_byte
= BUF_BEGV_BYTE (b
);
19687 EMACS_INT position
;
19688 EMACS_INT distance
=
19689 (height
* 2 + 30) * line_number_display_limit_width
;
19691 if (startpos
- distance
> limit
)
19693 limit
= startpos
- distance
;
19694 limit_byte
= CHAR_TO_BYTE (limit
);
19697 nlines
= display_count_lines (startpos_byte
,
19699 - (height
* 2 + 30),
19701 /* If we couldn't find the lines we wanted within
19702 line_number_display_limit_width chars per line,
19703 give up on line numbers for this window. */
19704 if (position
== limit_byte
&& limit
== startpos
- distance
)
19706 w
->base_line_pos
= w
->buffer
;
19707 w
->base_line_number
= Qnil
;
19711 w
->base_line_number
= make_number (topline
- nlines
);
19712 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
19715 /* Now count lines from the start pos to point. */
19716 nlines
= display_count_lines (startpos_byte
,
19717 PT_BYTE
, PT
, &junk
);
19719 /* Record that we did display the line number. */
19720 line_number_displayed
= 1;
19722 /* Make the string to show. */
19723 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
19724 return decode_mode_spec_buf
;
19727 char* p
= decode_mode_spec_buf
;
19728 int pad
= field_width
- 2;
19734 return decode_mode_spec_buf
;
19740 obj
= BVAR (b
, mode_name
);
19744 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
19750 EMACS_INT pos
= marker_position (w
->start
);
19751 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
19753 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
19755 if (pos
<= BUF_BEGV (b
))
19760 else if (pos
<= BUF_BEGV (b
))
19764 if (total
> 1000000)
19765 /* Do it differently for a large value, to avoid overflow. */
19766 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19768 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19769 /* We can't normally display a 3-digit number,
19770 so get us a 2-digit number that is close. */
19773 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
19774 return decode_mode_spec_buf
;
19778 /* Display percentage of size above the bottom of the screen. */
19781 EMACS_INT toppos
= marker_position (w
->start
);
19782 EMACS_INT botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
19783 EMACS_INT total
= BUF_ZV (b
) - BUF_BEGV (b
);
19785 if (botpos
>= BUF_ZV (b
))
19787 if (toppos
<= BUF_BEGV (b
))
19794 if (total
> 1000000)
19795 /* Do it differently for a large value, to avoid overflow. */
19796 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19798 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19799 /* We can't normally display a 3-digit number,
19800 so get us a 2-digit number that is close. */
19803 if (toppos
<= BUF_BEGV (b
))
19804 sprintf (decode_mode_spec_buf
, "Top%2"pI
"d%%", total
);
19806 sprintf (decode_mode_spec_buf
, "%2"pI
"d%%", total
);
19807 return decode_mode_spec_buf
;
19812 /* status of process */
19813 obj
= Fget_buffer_process (Fcurrent_buffer ());
19815 return "no process";
19817 obj
= Fsymbol_name (Fprocess_status (obj
));
19823 int count
= inhibit_garbage_collection ();
19824 Lisp_Object val
= call1 (intern ("file-remote-p"),
19825 BVAR (current_buffer
, directory
));
19826 unbind_to (count
, Qnil
);
19834 case 't': /* indicate TEXT or BINARY */
19838 /* coding-system (not including end-of-line format) */
19840 /* coding-system (including end-of-line type) */
19842 int eol_flag
= (c
== 'Z');
19843 char *p
= decode_mode_spec_buf
;
19845 if (! FRAME_WINDOW_P (f
))
19847 /* No need to mention EOL here--the terminal never needs
19848 to do EOL conversion. */
19849 p
= decode_mode_spec_coding (CODING_ID_NAME
19850 (FRAME_KEYBOARD_CODING (f
)->id
),
19852 p
= decode_mode_spec_coding (CODING_ID_NAME
19853 (FRAME_TERMINAL_CODING (f
)->id
),
19856 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
19859 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
19860 #ifdef subprocesses
19861 obj
= Fget_buffer_process (Fcurrent_buffer ());
19862 if (PROCESSP (obj
))
19864 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
19866 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
19869 #endif /* subprocesses */
19872 return decode_mode_spec_buf
;
19879 return SSDATA (obj
);
19886 /* Count up to COUNT lines starting from START_BYTE.
19887 But don't go beyond LIMIT_BYTE.
19888 Return the number of lines thus found (always nonnegative).
19890 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
19893 display_count_lines (EMACS_INT start_byte
,
19894 EMACS_INT limit_byte
, EMACS_INT count
,
19895 EMACS_INT
*byte_pos_ptr
)
19897 register unsigned char *cursor
;
19898 unsigned char *base
;
19900 register EMACS_INT ceiling
;
19901 register unsigned char *ceiling_addr
;
19902 EMACS_INT orig_count
= count
;
19904 /* If we are not in selective display mode,
19905 check only for newlines. */
19906 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
19907 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
19911 while (start_byte
< limit_byte
)
19913 ceiling
= BUFFER_CEILING_OF (start_byte
);
19914 ceiling
= min (limit_byte
- 1, ceiling
);
19915 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
19916 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
19919 if (selective_display
)
19920 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
19923 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
19926 if (cursor
!= ceiling_addr
)
19930 start_byte
+= cursor
- base
+ 1;
19931 *byte_pos_ptr
= start_byte
;
19935 if (++cursor
== ceiling_addr
)
19941 start_byte
+= cursor
- base
;
19946 while (start_byte
> limit_byte
)
19948 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
19949 ceiling
= max (limit_byte
, ceiling
);
19950 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
19951 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
19954 if (selective_display
)
19955 while (--cursor
!= ceiling_addr
19956 && *cursor
!= '\n' && *cursor
!= 015)
19959 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
19962 if (cursor
!= ceiling_addr
)
19966 start_byte
+= cursor
- base
+ 1;
19967 *byte_pos_ptr
= start_byte
;
19968 /* When scanning backwards, we should
19969 not count the newline posterior to which we stop. */
19970 return - orig_count
- 1;
19976 /* Here we add 1 to compensate for the last decrement
19977 of CURSOR, which took it past the valid range. */
19978 start_byte
+= cursor
- base
+ 1;
19982 *byte_pos_ptr
= limit_byte
;
19985 return - orig_count
+ count
;
19986 return orig_count
- count
;
19992 /***********************************************************************
19994 ***********************************************************************/
19996 /* Display a NUL-terminated string, starting with index START.
19998 If STRING is non-null, display that C string. Otherwise, the Lisp
19999 string LISP_STRING is displayed. There's a case that STRING is
20000 non-null and LISP_STRING is not nil. It means STRING is a string
20001 data of LISP_STRING. In that case, we display LISP_STRING while
20002 ignoring its text properties.
20004 If FACE_STRING is not nil, FACE_STRING_POS is a position in
20005 FACE_STRING. Display STRING or LISP_STRING with the face at
20006 FACE_STRING_POS in FACE_STRING:
20008 Display the string in the environment given by IT, but use the
20009 standard display table, temporarily.
20011 FIELD_WIDTH is the minimum number of output glyphs to produce.
20012 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20013 with spaces. If STRING has more characters, more than FIELD_WIDTH
20014 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
20016 PRECISION is the maximum number of characters to output from
20017 STRING. PRECISION < 0 means don't truncate the string.
20019 This is roughly equivalent to printf format specifiers:
20021 FIELD_WIDTH PRECISION PRINTF
20022 ----------------------------------------
20028 MULTIBYTE zero means do not display multibyte chars, > 0 means do
20029 display them, and < 0 means obey the current buffer's value of
20030 enable_multibyte_characters.
20032 Value is the number of columns displayed. */
20035 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
20036 EMACS_INT face_string_pos
, EMACS_INT start
, struct it
*it
,
20037 int field_width
, int precision
, int max_x
, int multibyte
)
20039 int hpos_at_start
= it
->hpos
;
20040 int saved_face_id
= it
->face_id
;
20041 struct glyph_row
*row
= it
->glyph_row
;
20043 /* Initialize the iterator IT for iteration over STRING beginning
20044 with index START. */
20045 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
20046 precision
, field_width
, multibyte
);
20047 if (string
&& STRINGP (lisp_string
))
20048 /* LISP_STRING is the one returned by decode_mode_spec. We should
20049 ignore its text properties. */
20050 it
->stop_charpos
= it
->end_charpos
;
20052 /* If displaying STRING, set up the face of the iterator from
20053 FACE_STRING, if that's given. */
20054 if (STRINGP (face_string
))
20060 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
20061 0, it
->region_beg_charpos
,
20062 it
->region_end_charpos
,
20063 &endptr
, it
->base_face_id
, 0);
20064 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20065 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
20068 /* Set max_x to the maximum allowed X position. Don't let it go
20069 beyond the right edge of the window. */
20071 max_x
= it
->last_visible_x
;
20073 max_x
= min (max_x
, it
->last_visible_x
);
20075 /* Skip over display elements that are not visible. because IT->w is
20077 if (it
->current_x
< it
->first_visible_x
)
20078 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
20079 MOVE_TO_POS
| MOVE_TO_X
);
20081 row
->ascent
= it
->max_ascent
;
20082 row
->height
= it
->max_ascent
+ it
->max_descent
;
20083 row
->phys_ascent
= it
->max_phys_ascent
;
20084 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20085 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20087 /* This condition is for the case that we are called with current_x
20088 past last_visible_x. */
20089 while (it
->current_x
< max_x
)
20091 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
20093 /* Get the next display element. */
20094 if (!get_next_display_element (it
))
20097 /* Produce glyphs. */
20098 x_before
= it
->current_x
;
20099 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20100 PRODUCE_GLYPHS (it
);
20102 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
20105 while (i
< nglyphs
)
20107 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20109 if (it
->line_wrap
!= TRUNCATE
20110 && x
+ glyph
->pixel_width
> max_x
)
20112 /* End of continued line or max_x reached. */
20113 if (CHAR_GLYPH_PADDING_P (*glyph
))
20115 /* A wide character is unbreakable. */
20116 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
20117 it
->current_x
= x_before
;
20121 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20126 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
20128 /* Glyph is at least partially visible. */
20130 if (x
< it
->first_visible_x
)
20131 it
->glyph_row
->x
= x
- it
->first_visible_x
;
20135 /* Glyph is off the left margin of the display area.
20136 Should not happen. */
20140 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20141 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20142 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20143 row
->phys_height
= max (row
->phys_height
,
20144 it
->max_phys_ascent
+ it
->max_phys_descent
);
20145 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20146 it
->max_extra_line_spacing
);
20147 x
+= glyph
->pixel_width
;
20151 /* Stop if max_x reached. */
20155 /* Stop at line ends. */
20156 if (ITERATOR_AT_END_OF_LINE_P (it
))
20158 it
->continuation_lines_width
= 0;
20162 set_iterator_to_next (it
, 1);
20164 /* Stop if truncating at the right edge. */
20165 if (it
->line_wrap
== TRUNCATE
20166 && it
->current_x
>= it
->last_visible_x
)
20168 /* Add truncation mark, but don't do it if the line is
20169 truncated at a padding space. */
20170 if (IT_CHARPOS (*it
) < it
->string_nchars
)
20172 if (!FRAME_WINDOW_P (it
->f
))
20176 if (it
->current_x
> it
->last_visible_x
)
20178 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
20179 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
20181 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
20183 row
->used
[TEXT_AREA
] = ii
;
20184 produce_special_glyphs (it
, IT_TRUNCATION
);
20187 produce_special_glyphs (it
, IT_TRUNCATION
);
20189 it
->glyph_row
->truncated_on_right_p
= 1;
20195 /* Maybe insert a truncation at the left. */
20196 if (it
->first_visible_x
20197 && IT_CHARPOS (*it
) > 0)
20199 if (!FRAME_WINDOW_P (it
->f
))
20200 insert_left_trunc_glyphs (it
);
20201 it
->glyph_row
->truncated_on_left_p
= 1;
20204 it
->face_id
= saved_face_id
;
20206 /* Value is number of columns displayed. */
20207 return it
->hpos
- hpos_at_start
;
20212 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
20213 appears as an element of LIST or as the car of an element of LIST.
20214 If PROPVAL is a list, compare each element against LIST in that
20215 way, and return 1/2 if any element of PROPVAL is found in LIST.
20216 Otherwise return 0. This function cannot quit.
20217 The return value is 2 if the text is invisible but with an ellipsis
20218 and 1 if it's invisible and without an ellipsis. */
20221 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
20223 register Lisp_Object tail
, proptail
;
20225 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20227 register Lisp_Object tem
;
20229 if (EQ (propval
, tem
))
20231 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
20232 return NILP (XCDR (tem
)) ? 1 : 2;
20235 if (CONSP (propval
))
20237 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
20239 Lisp_Object propelt
;
20240 propelt
= XCAR (proptail
);
20241 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
20243 register Lisp_Object tem
;
20245 if (EQ (propelt
, tem
))
20247 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
20248 return NILP (XCDR (tem
)) ? 1 : 2;
20256 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
20257 doc
: /* Non-nil if the property makes the text invisible.
20258 POS-OR-PROP can be a marker or number, in which case it is taken to be
20259 a position in the current buffer and the value of the `invisible' property
20260 is checked; or it can be some other value, which is then presumed to be the
20261 value of the `invisible' property of the text of interest.
20262 The non-nil value returned can be t for truly invisible text or something
20263 else if the text is replaced by an ellipsis. */)
20264 (Lisp_Object pos_or_prop
)
20267 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
20268 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
20270 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
20271 return (invis
== 0 ? Qnil
20273 : make_number (invis
));
20276 /* Calculate a width or height in pixels from a specification using
20277 the following elements:
20280 NUM - a (fractional) multiple of the default font width/height
20281 (NUM) - specifies exactly NUM pixels
20282 UNIT - a fixed number of pixels, see below.
20283 ELEMENT - size of a display element in pixels, see below.
20284 (NUM . SPEC) - equals NUM * SPEC
20285 (+ SPEC SPEC ...) - add pixel values
20286 (- SPEC SPEC ...) - subtract pixel values
20287 (- SPEC) - negate pixel value
20290 INT or FLOAT - a number constant
20291 SYMBOL - use symbol's (buffer local) variable binding.
20294 in - pixels per inch *)
20295 mm - pixels per 1/1000 meter *)
20296 cm - pixels per 1/100 meter *)
20297 width - width of current font in pixels.
20298 height - height of current font in pixels.
20300 *) using the ratio(s) defined in display-pixels-per-inch.
20304 left-fringe - left fringe width in pixels
20305 right-fringe - right fringe width in pixels
20307 left-margin - left margin width in pixels
20308 right-margin - right margin width in pixels
20310 scroll-bar - scroll-bar area width in pixels
20314 Pixels corresponding to 5 inches:
20317 Total width of non-text areas on left side of window (if scroll-bar is on left):
20318 '(space :width (+ left-fringe left-margin scroll-bar))
20320 Align to first text column (in header line):
20321 '(space :align-to 0)
20323 Align to middle of text area minus half the width of variable `my-image'
20324 containing a loaded image:
20325 '(space :align-to (0.5 . (- text my-image)))
20327 Width of left margin minus width of 1 character in the default font:
20328 '(space :width (- left-margin 1))
20330 Width of left margin minus width of 2 characters in the current font:
20331 '(space :width (- left-margin (2 . width)))
20333 Center 1 character over left-margin (in header line):
20334 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
20336 Different ways to express width of left fringe plus left margin minus one pixel:
20337 '(space :width (- (+ left-fringe left-margin) (1)))
20338 '(space :width (+ left-fringe left-margin (- (1))))
20339 '(space :width (+ left-fringe left-margin (-1)))
20343 #define NUMVAL(X) \
20344 ((INTEGERP (X) || FLOATP (X)) \
20349 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
20350 struct font
*font
, int width_p
, int *align_to
)
20354 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20355 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20358 return OK_PIXELS (0);
20360 xassert (FRAME_LIVE_P (it
->f
));
20362 if (SYMBOLP (prop
))
20364 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20366 char *unit
= SSDATA (SYMBOL_NAME (prop
));
20368 if (unit
[0] == 'i' && unit
[1] == 'n')
20370 else if (unit
[0] == 'm' && unit
[1] == 'm')
20372 else if (unit
[0] == 'c' && unit
[1] == 'm')
20379 #ifdef HAVE_WINDOW_SYSTEM
20380 if (FRAME_WINDOW_P (it
->f
)
20382 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20383 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20385 return OK_PIXELS (ppi
/ pixels
);
20388 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20389 || (CONSP (Vdisplay_pixels_per_inch
)
20391 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20392 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20394 return OK_PIXELS (ppi
/ pixels
);
20400 #ifdef HAVE_WINDOW_SYSTEM
20401 if (EQ (prop
, Qheight
))
20402 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20403 if (EQ (prop
, Qwidth
))
20404 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20406 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20407 return OK_PIXELS (1);
20410 if (EQ (prop
, Qtext
))
20411 return OK_PIXELS (width_p
20412 ? window_box_width (it
->w
, TEXT_AREA
)
20413 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20415 if (align_to
&& *align_to
< 0)
20418 if (EQ (prop
, Qleft
))
20419 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20420 if (EQ (prop
, Qright
))
20421 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20422 if (EQ (prop
, Qcenter
))
20423 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20424 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20425 if (EQ (prop
, Qleft_fringe
))
20426 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20427 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20428 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20429 if (EQ (prop
, Qright_fringe
))
20430 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20431 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20432 : window_box_right_offset (it
->w
, TEXT_AREA
));
20433 if (EQ (prop
, Qleft_margin
))
20434 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20435 if (EQ (prop
, Qright_margin
))
20436 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20437 if (EQ (prop
, Qscroll_bar
))
20438 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20440 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20441 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20442 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20447 if (EQ (prop
, Qleft_fringe
))
20448 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20449 if (EQ (prop
, Qright_fringe
))
20450 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20451 if (EQ (prop
, Qleft_margin
))
20452 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20453 if (EQ (prop
, Qright_margin
))
20454 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20455 if (EQ (prop
, Qscroll_bar
))
20456 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20459 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20462 if (INTEGERP (prop
) || FLOATP (prop
))
20464 int base_unit
= (width_p
20465 ? FRAME_COLUMN_WIDTH (it
->f
)
20466 : FRAME_LINE_HEIGHT (it
->f
));
20467 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
20472 Lisp_Object car
= XCAR (prop
);
20473 Lisp_Object cdr
= XCDR (prop
);
20477 #ifdef HAVE_WINDOW_SYSTEM
20478 if (FRAME_WINDOW_P (it
->f
)
20479 && valid_image_p (prop
))
20481 int id
= lookup_image (it
->f
, prop
);
20482 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
20484 return OK_PIXELS (width_p
? img
->width
: img
->height
);
20487 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
20493 while (CONSP (cdr
))
20495 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
20496 font
, width_p
, align_to
))
20499 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
20504 if (EQ (car
, Qminus
))
20506 return OK_PIXELS (pixels
);
20509 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
20512 if (INTEGERP (car
) || FLOATP (car
))
20515 pixels
= XFLOATINT (car
);
20517 return OK_PIXELS (pixels
);
20518 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
20519 font
, width_p
, align_to
))
20520 return OK_PIXELS (pixels
* fact
);
20531 /***********************************************************************
20533 ***********************************************************************/
20535 #ifdef HAVE_WINDOW_SYSTEM
20540 dump_glyph_string (s
)
20541 struct glyph_string
*s
;
20543 fprintf (stderr
, "glyph string\n");
20544 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
20545 s
->x
, s
->y
, s
->width
, s
->height
);
20546 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
20547 fprintf (stderr
, " hl = %d\n", s
->hl
);
20548 fprintf (stderr
, " left overhang = %d, right = %d\n",
20549 s
->left_overhang
, s
->right_overhang
);
20550 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
20551 fprintf (stderr
, " extends to end of line = %d\n",
20552 s
->extends_to_end_of_line_p
);
20553 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
20554 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
20557 #endif /* GLYPH_DEBUG */
20559 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
20560 of XChar2b structures for S; it can't be allocated in
20561 init_glyph_string because it must be allocated via `alloca'. W
20562 is the window on which S is drawn. ROW and AREA are the glyph row
20563 and area within the row from which S is constructed. START is the
20564 index of the first glyph structure covered by S. HL is a
20565 face-override for drawing S. */
20568 #define OPTIONAL_HDC(hdc) HDC hdc,
20569 #define DECLARE_HDC(hdc) HDC hdc;
20570 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
20571 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
20574 #ifndef OPTIONAL_HDC
20575 #define OPTIONAL_HDC(hdc)
20576 #define DECLARE_HDC(hdc)
20577 #define ALLOCATE_HDC(hdc, f)
20578 #define RELEASE_HDC(hdc, f)
20582 init_glyph_string (struct glyph_string
*s
,
20584 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
20585 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
20587 memset (s
, 0, sizeof *s
);
20589 s
->f
= XFRAME (w
->frame
);
20593 s
->display
= FRAME_X_DISPLAY (s
->f
);
20594 s
->window
= FRAME_X_WINDOW (s
->f
);
20595 s
->char2b
= char2b
;
20599 s
->first_glyph
= row
->glyphs
[area
] + start
;
20600 s
->height
= row
->height
;
20601 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
20602 s
->ybase
= s
->y
+ row
->ascent
;
20606 /* Append the list of glyph strings with head H and tail T to the list
20607 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
20610 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20611 struct glyph_string
*h
, struct glyph_string
*t
)
20625 /* Prepend the list of glyph strings with head H and tail T to the
20626 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
20630 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
20631 struct glyph_string
*h
, struct glyph_string
*t
)
20645 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
20646 Set *HEAD and *TAIL to the resulting list. */
20649 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
20650 struct glyph_string
*s
)
20652 s
->next
= s
->prev
= NULL
;
20653 append_glyph_string_lists (head
, tail
, s
, s
);
20657 /* Get face and two-byte form of character C in face FACE_ID on frame F.
20658 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
20659 make sure that X resources for the face returned are allocated.
20660 Value is a pointer to a realized face that is ready for display if
20661 DISPLAY_P is non-zero. */
20663 static INLINE
struct face
*
20664 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
20665 XChar2b
*char2b
, int display_p
)
20667 struct face
*face
= FACE_FROM_ID (f
, face_id
);
20671 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
20673 if (code
!= FONT_INVALID_CODE
)
20674 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20676 STORE_XCHAR2B (char2b
, 0, 0);
20679 /* Make sure X resources of the face are allocated. */
20680 #ifdef HAVE_X_WINDOWS
20684 xassert (face
!= NULL
);
20685 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20692 /* Get face and two-byte form of character glyph GLYPH on frame F.
20693 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
20694 a pointer to a realized face that is ready for display. */
20696 static INLINE
struct face
*
20697 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
20698 XChar2b
*char2b
, int *two_byte_p
)
20702 xassert (glyph
->type
== CHAR_GLYPH
);
20703 face
= FACE_FROM_ID (f
, glyph
->face_id
);
20712 if (CHAR_BYTE8_P (glyph
->u
.ch
))
20713 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
20715 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
20717 if (code
!= FONT_INVALID_CODE
)
20718 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20720 STORE_XCHAR2B (char2b
, 0, 0);
20723 /* Make sure X resources of the face are allocated. */
20724 xassert (face
!= NULL
);
20725 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20730 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
20731 Retunr 1 if FONT has a glyph for C, otherwise return 0. */
20734 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
20738 if (CHAR_BYTE8_P (c
))
20739 code
= CHAR_TO_BYTE8 (c
);
20741 code
= font
->driver
->encode_char (font
, c
);
20743 if (code
== FONT_INVALID_CODE
)
20745 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20750 /* Fill glyph string S with composition components specified by S->cmp.
20752 BASE_FACE is the base face of the composition.
20753 S->cmp_from is the index of the first component for S.
20755 OVERLAPS non-zero means S should draw the foreground only, and use
20756 its physical height for clipping. See also draw_glyphs.
20758 Value is the index of a component not in S. */
20761 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
20765 /* For all glyphs of this composition, starting at the offset
20766 S->cmp_from, until we reach the end of the definition or encounter a
20767 glyph that requires the different face, add it to S. */
20772 s
->for_overlaps
= overlaps
;
20775 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
20777 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
20781 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
20784 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
20791 s
->font
= s
->face
->font
;
20793 else if (s
->face
!= face
)
20801 /* All glyph strings for the same composition has the same width,
20802 i.e. the width set for the first component of the composition. */
20803 s
->width
= s
->first_glyph
->pixel_width
;
20805 /* If the specified font could not be loaded, use the frame's
20806 default font, but record the fact that we couldn't load it in
20807 the glyph string so that we can draw rectangles for the
20808 characters of the glyph string. */
20809 if (s
->font
== NULL
)
20811 s
->font_not_found_p
= 1;
20812 s
->font
= FRAME_FONT (s
->f
);
20815 /* Adjust base line for subscript/superscript text. */
20816 s
->ybase
+= s
->first_glyph
->voffset
;
20818 /* This glyph string must always be drawn with 16-bit functions. */
20825 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
20826 int start
, int end
, int overlaps
)
20828 struct glyph
*glyph
, *last
;
20829 Lisp_Object lgstring
;
20832 s
->for_overlaps
= overlaps
;
20833 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20834 last
= s
->row
->glyphs
[s
->area
] + end
;
20835 s
->cmp_id
= glyph
->u
.cmp
.id
;
20836 s
->cmp_from
= glyph
->slice
.cmp
.from
;
20837 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
20838 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20839 lgstring
= composition_gstring_from_id (s
->cmp_id
);
20840 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
20842 while (glyph
< last
20843 && glyph
->u
.cmp
.automatic
20844 && glyph
->u
.cmp
.id
== s
->cmp_id
20845 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
20846 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
20848 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
20850 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
20851 unsigned code
= LGLYPH_CODE (lglyph
);
20853 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
20855 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
20856 return glyph
- s
->row
->glyphs
[s
->area
];
20860 /* Fill glyph string S from a sequence glyphs for glyphless characters.
20861 See the comment of fill_glyph_string for arguments.
20862 Value is the index of the first glyph not in S. */
20866 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
20867 int start
, int end
, int overlaps
)
20869 struct glyph
*glyph
, *last
;
20872 xassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
20873 s
->for_overlaps
= overlaps
;
20874 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20875 last
= s
->row
->glyphs
[s
->area
] + end
;
20876 voffset
= glyph
->voffset
;
20877 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20878 s
->font
= s
->face
->font
;
20880 s
->width
= glyph
->pixel_width
;
20882 while (glyph
< last
20883 && glyph
->type
== GLYPHLESS_GLYPH
20884 && glyph
->voffset
== voffset
20885 && glyph
->face_id
== face_id
)
20888 s
->width
+= glyph
->pixel_width
;
20891 s
->ybase
+= voffset
;
20892 return glyph
- s
->row
->glyphs
[s
->area
];
20896 /* Fill glyph string S from a sequence of character glyphs.
20898 FACE_ID is the face id of the string. START is the index of the
20899 first glyph to consider, END is the index of the last + 1.
20900 OVERLAPS non-zero means S should draw the foreground only, and use
20901 its physical height for clipping. See also draw_glyphs.
20903 Value is the index of the first glyph not in S. */
20906 fill_glyph_string (struct glyph_string
*s
, int face_id
,
20907 int start
, int end
, int overlaps
)
20909 struct glyph
*glyph
, *last
;
20911 int glyph_not_available_p
;
20913 xassert (s
->f
== XFRAME (s
->w
->frame
));
20914 xassert (s
->nchars
== 0);
20915 xassert (start
>= 0 && end
> start
);
20917 s
->for_overlaps
= overlaps
;
20918 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20919 last
= s
->row
->glyphs
[s
->area
] + end
;
20920 voffset
= glyph
->voffset
;
20921 s
->padding_p
= glyph
->padding_p
;
20922 glyph_not_available_p
= glyph
->glyph_not_available_p
;
20924 while (glyph
< last
20925 && glyph
->type
== CHAR_GLYPH
20926 && glyph
->voffset
== voffset
20927 /* Same face id implies same font, nowadays. */
20928 && glyph
->face_id
== face_id
20929 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
20933 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
20934 s
->char2b
+ s
->nchars
,
20936 s
->two_byte_p
= two_byte_p
;
20938 xassert (s
->nchars
<= end
- start
);
20939 s
->width
+= glyph
->pixel_width
;
20940 if (glyph
++->padding_p
!= s
->padding_p
)
20944 s
->font
= s
->face
->font
;
20946 /* If the specified font could not be loaded, use the frame's font,
20947 but record the fact that we couldn't load it in
20948 S->font_not_found_p so that we can draw rectangles for the
20949 characters of the glyph string. */
20950 if (s
->font
== NULL
|| glyph_not_available_p
)
20952 s
->font_not_found_p
= 1;
20953 s
->font
= FRAME_FONT (s
->f
);
20956 /* Adjust base line for subscript/superscript text. */
20957 s
->ybase
+= voffset
;
20959 xassert (s
->face
&& s
->face
->gc
);
20960 return glyph
- s
->row
->glyphs
[s
->area
];
20964 /* Fill glyph string S from image glyph S->first_glyph. */
20967 fill_image_glyph_string (struct glyph_string
*s
)
20969 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
20970 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
20972 s
->slice
= s
->first_glyph
->slice
.img
;
20973 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
20974 s
->font
= s
->face
->font
;
20975 s
->width
= s
->first_glyph
->pixel_width
;
20977 /* Adjust base line for subscript/superscript text. */
20978 s
->ybase
+= s
->first_glyph
->voffset
;
20982 /* Fill glyph string S from a sequence of stretch glyphs.
20984 START is the index of the first glyph to consider,
20985 END is the index of the last + 1.
20987 Value is the index of the first glyph not in S. */
20990 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
20992 struct glyph
*glyph
, *last
;
20993 int voffset
, face_id
;
20995 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
20997 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20998 last
= s
->row
->glyphs
[s
->area
] + end
;
20999 face_id
= glyph
->face_id
;
21000 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
21001 s
->font
= s
->face
->font
;
21002 s
->width
= glyph
->pixel_width
;
21004 voffset
= glyph
->voffset
;
21008 && glyph
->type
== STRETCH_GLYPH
21009 && glyph
->voffset
== voffset
21010 && glyph
->face_id
== face_id
);
21012 s
->width
+= glyph
->pixel_width
;
21014 /* Adjust base line for subscript/superscript text. */
21015 s
->ybase
+= voffset
;
21017 /* The case that face->gc == 0 is handled when drawing the glyph
21018 string by calling PREPARE_FACE_FOR_DISPLAY. */
21020 return glyph
- s
->row
->glyphs
[s
->area
];
21023 static struct font_metrics
*
21024 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
21026 static struct font_metrics metrics
;
21027 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
21029 if (! font
|| code
== FONT_INVALID_CODE
)
21031 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
21036 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
21037 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
21038 assumed to be zero. */
21041 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
21043 *left
= *right
= 0;
21045 if (glyph
->type
== CHAR_GLYPH
)
21049 struct font_metrics
*pcm
;
21051 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
21052 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
21054 if (pcm
->rbearing
> pcm
->width
)
21055 *right
= pcm
->rbearing
- pcm
->width
;
21056 if (pcm
->lbearing
< 0)
21057 *left
= -pcm
->lbearing
;
21060 else if (glyph
->type
== COMPOSITE_GLYPH
)
21062 if (! glyph
->u
.cmp
.automatic
)
21064 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
21066 if (cmp
->rbearing
> cmp
->pixel_width
)
21067 *right
= cmp
->rbearing
- cmp
->pixel_width
;
21068 if (cmp
->lbearing
< 0)
21069 *left
= - cmp
->lbearing
;
21073 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
21074 struct font_metrics metrics
;
21076 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
21077 glyph
->slice
.cmp
.to
+ 1, &metrics
);
21078 if (metrics
.rbearing
> metrics
.width
)
21079 *right
= metrics
.rbearing
- metrics
.width
;
21080 if (metrics
.lbearing
< 0)
21081 *left
= - metrics
.lbearing
;
21087 /* Return the index of the first glyph preceding glyph string S that
21088 is overwritten by S because of S's left overhang. Value is -1
21089 if no glyphs are overwritten. */
21092 left_overwritten (struct glyph_string
*s
)
21096 if (s
->left_overhang
)
21099 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21100 int first
= s
->first_glyph
- glyphs
;
21102 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
21103 x
-= glyphs
[i
].pixel_width
;
21114 /* Return the index of the first glyph preceding glyph string S that
21115 is overwriting S because of its right overhang. Value is -1 if no
21116 glyph in front of S overwrites S. */
21119 left_overwriting (struct glyph_string
*s
)
21122 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21123 int first
= s
->first_glyph
- glyphs
;
21127 for (i
= first
- 1; i
>= 0; --i
)
21130 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21133 x
-= glyphs
[i
].pixel_width
;
21140 /* Return the index of the last glyph following glyph string S that is
21141 overwritten by S because of S's right overhang. Value is -1 if
21142 no such glyph is found. */
21145 right_overwritten (struct glyph_string
*s
)
21149 if (s
->right_overhang
)
21152 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21153 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21154 int end
= s
->row
->used
[s
->area
];
21156 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
21157 x
+= glyphs
[i
].pixel_width
;
21166 /* Return the index of the last glyph following glyph string S that
21167 overwrites S because of its left overhang. Value is negative
21168 if no such glyph is found. */
21171 right_overwriting (struct glyph_string
*s
)
21174 int end
= s
->row
->used
[s
->area
];
21175 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
21176 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
21180 for (i
= first
; i
< end
; ++i
)
21183 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
21186 x
+= glyphs
[i
].pixel_width
;
21193 /* Set background width of glyph string S. START is the index of the
21194 first glyph following S. LAST_X is the right-most x-position + 1
21195 in the drawing area. */
21198 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
21200 /* If the face of this glyph string has to be drawn to the end of
21201 the drawing area, set S->extends_to_end_of_line_p. */
21203 if (start
== s
->row
->used
[s
->area
]
21204 && s
->area
== TEXT_AREA
21205 && ((s
->row
->fill_line_p
21206 && (s
->hl
== DRAW_NORMAL_TEXT
21207 || s
->hl
== DRAW_IMAGE_RAISED
21208 || s
->hl
== DRAW_IMAGE_SUNKEN
))
21209 || s
->hl
== DRAW_MOUSE_FACE
))
21210 s
->extends_to_end_of_line_p
= 1;
21212 /* If S extends its face to the end of the line, set its
21213 background_width to the distance to the right edge of the drawing
21215 if (s
->extends_to_end_of_line_p
)
21216 s
->background_width
= last_x
- s
->x
+ 1;
21218 s
->background_width
= s
->width
;
21222 /* Compute overhangs and x-positions for glyph string S and its
21223 predecessors, or successors. X is the starting x-position for S.
21224 BACKWARD_P non-zero means process predecessors. */
21227 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
21233 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21234 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21244 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
21245 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
21255 /* The following macros are only called from draw_glyphs below.
21256 They reference the following parameters of that function directly:
21257 `w', `row', `area', and `overlap_p'
21258 as well as the following local variables:
21259 `s', `f', and `hdc' (in W32) */
21262 /* On W32, silently add local `hdc' variable to argument list of
21263 init_glyph_string. */
21264 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21265 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
21267 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
21268 init_glyph_string (s, char2b, w, row, area, start, hl)
21271 /* Add a glyph string for a stretch glyph to the list of strings
21272 between HEAD and TAIL. START is the index of the stretch glyph in
21273 row area AREA of glyph row ROW. END is the index of the last glyph
21274 in that glyph row area. X is the current output position assigned
21275 to the new glyph string constructed. HL overrides that face of the
21276 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21277 is the right-most x-position of the drawing area. */
21279 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
21280 and below -- keep them on one line. */
21281 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21284 s = (struct glyph_string *) alloca (sizeof *s); \
21285 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21286 START = fill_stretch_glyph_string (s, START, END); \
21287 append_glyph_string (&HEAD, &TAIL, s); \
21293 /* Add a glyph string for an image glyph to the list of strings
21294 between HEAD and TAIL. START is the index of the image glyph in
21295 row area AREA of glyph row ROW. END is the index of the last glyph
21296 in that glyph row area. X is the current output position assigned
21297 to the new glyph string constructed. HL overrides that face of the
21298 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
21299 is the right-most x-position of the drawing area. */
21301 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21304 s = (struct glyph_string *) alloca (sizeof *s); \
21305 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21306 fill_image_glyph_string (s); \
21307 append_glyph_string (&HEAD, &TAIL, s); \
21314 /* Add a glyph string for a sequence of character glyphs to the list
21315 of strings between HEAD and TAIL. START is the index of the first
21316 glyph in row area AREA of glyph row ROW that is part of the new
21317 glyph string. END is the index of the last glyph in that glyph row
21318 area. X is the current output position assigned to the new glyph
21319 string constructed. HL overrides that face of the glyph; e.g. it
21320 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
21321 right-most x-position of the drawing area. */
21323 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21329 face_id = (row)->glyphs[area][START].face_id; \
21331 s = (struct glyph_string *) alloca (sizeof *s); \
21332 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
21333 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21334 append_glyph_string (&HEAD, &TAIL, s); \
21336 START = fill_glyph_string (s, face_id, START, END, overlaps); \
21341 /* Add a glyph string for a composite sequence to the list of strings
21342 between HEAD and TAIL. START is the index of the first glyph in
21343 row area AREA of glyph row ROW that is part of the new glyph
21344 string. END is the index of the last glyph in that glyph row area.
21345 X is the current output position assigned to the new glyph string
21346 constructed. HL overrides that face of the glyph; e.g. it is
21347 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
21348 x-position of the drawing area. */
21350 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21352 int face_id = (row)->glyphs[area][START].face_id; \
21353 struct face *base_face = FACE_FROM_ID (f, face_id); \
21354 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
21355 struct composition *cmp = composition_table[cmp_id]; \
21357 struct glyph_string *first_s IF_LINT (= NULL); \
21360 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21362 /* Make glyph_strings for each glyph sequence that is drawable by \
21363 the same face, and append them to HEAD/TAIL. */ \
21364 for (n = 0; n < cmp->glyph_len;) \
21366 s = (struct glyph_string *) alloca (sizeof *s); \
21367 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21368 append_glyph_string (&(HEAD), &(TAIL), s); \
21374 n = fill_composite_glyph_string (s, base_face, overlaps); \
21382 /* Add a glyph string for a glyph-string sequence to the list of strings
21383 between HEAD and TAIL. */
21385 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21389 Lisp_Object gstring; \
21391 face_id = (row)->glyphs[area][START].face_id; \
21392 gstring = (composition_gstring_from_id \
21393 ((row)->glyphs[area][START].u.cmp.id)); \
21394 s = (struct glyph_string *) alloca (sizeof *s); \
21395 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21396 * LGSTRING_GLYPH_LEN (gstring)); \
21397 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21398 append_glyph_string (&(HEAD), &(TAIL), s); \
21400 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21404 /* Add a glyph string for a sequence of glyphless character's glyphs
21405 to the list of strings between HEAD and TAIL. The meanings of
21406 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
21408 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21413 face_id = (row)->glyphs[area][START].face_id; \
21415 s = (struct glyph_string *) alloca (sizeof *s); \
21416 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
21417 append_glyph_string (&HEAD, &TAIL, s); \
21419 START = fill_glyphless_glyph_string (s, face_id, START, END, \
21425 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21426 of AREA of glyph row ROW on window W between indices START and END.
21427 HL overrides the face for drawing glyph strings, e.g. it is
21428 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21429 x-positions of the drawing area.
21431 This is an ugly monster macro construct because we must use alloca
21432 to allocate glyph strings (because draw_glyphs can be called
21433 asynchronously). */
21435 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21438 HEAD = TAIL = NULL; \
21439 while (START < END) \
21441 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21442 switch (first_glyph->type) \
21445 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21449 case COMPOSITE_GLYPH: \
21450 if (first_glyph->u.cmp.automatic) \
21451 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21454 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21458 case STRETCH_GLYPH: \
21459 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21463 case IMAGE_GLYPH: \
21464 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21468 case GLYPHLESS_GLYPH: \
21469 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
21479 set_glyph_string_background_width (s, START, LAST_X); \
21486 /* Draw glyphs between START and END in AREA of ROW on window W,
21487 starting at x-position X. X is relative to AREA in W. HL is a
21488 face-override with the following meaning:
21490 DRAW_NORMAL_TEXT draw normally
21491 DRAW_CURSOR draw in cursor face
21492 DRAW_MOUSE_FACE draw in mouse face.
21493 DRAW_INVERSE_VIDEO draw in mode line face
21494 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
21495 DRAW_IMAGE_RAISED draw an image with a raised relief around it
21497 If OVERLAPS is non-zero, draw only the foreground of characters and
21498 clip to the physical height of ROW. Non-zero value also defines
21499 the overlapping part to be drawn:
21501 OVERLAPS_PRED overlap with preceding rows
21502 OVERLAPS_SUCC overlap with succeeding rows
21503 OVERLAPS_BOTH overlap with both preceding/succeeding rows
21504 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
21506 Value is the x-position reached, relative to AREA of W. */
21509 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
21510 enum glyph_row_area area
, EMACS_INT start
, EMACS_INT end
,
21511 enum draw_glyphs_face hl
, int overlaps
)
21513 struct glyph_string
*head
, *tail
;
21514 struct glyph_string
*s
;
21515 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
21516 int i
, j
, x_reached
, last_x
, area_left
= 0;
21517 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21520 ALLOCATE_HDC (hdc
, f
);
21522 /* Let's rather be paranoid than getting a SEGV. */
21523 end
= min (end
, row
->used
[area
]);
21524 start
= max (0, start
);
21525 start
= min (end
, start
);
21527 /* Translate X to frame coordinates. Set last_x to the right
21528 end of the drawing area. */
21529 if (row
->full_width_p
)
21531 /* X is relative to the left edge of W, without scroll bars
21533 area_left
= WINDOW_LEFT_EDGE_X (w
);
21534 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
21538 area_left
= window_box_left (w
, area
);
21539 last_x
= area_left
+ window_box_width (w
, area
);
21543 /* Build a doubly-linked list of glyph_string structures between
21544 head and tail from what we have to draw. Note that the macro
21545 BUILD_GLYPH_STRINGS will modify its start parameter. That's
21546 the reason we use a separate variable `i'. */
21548 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
21550 x_reached
= tail
->x
+ tail
->background_width
;
21554 /* If there are any glyphs with lbearing < 0 or rbearing > width in
21555 the row, redraw some glyphs in front or following the glyph
21556 strings built above. */
21557 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
21559 struct glyph_string
*h
, *t
;
21560 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
21561 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
21562 int check_mouse_face
= 0;
21565 /* If mouse highlighting is on, we may need to draw adjacent
21566 glyphs using mouse-face highlighting. */
21567 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
21569 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
21571 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
21572 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
21574 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
21576 check_mouse_face
= 1;
21577 mouse_beg_col
= (row
== mouse_beg_row
)
21578 ? hlinfo
->mouse_face_beg_col
: 0;
21579 mouse_end_col
= (row
== mouse_end_row
)
21580 ? hlinfo
->mouse_face_end_col
21581 : row
->used
[TEXT_AREA
];
21585 /* Compute overhangs for all glyph strings. */
21586 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
21587 for (s
= head
; s
; s
= s
->next
)
21588 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
21590 /* Prepend glyph strings for glyphs in front of the first glyph
21591 string that are overwritten because of the first glyph
21592 string's left overhang. The background of all strings
21593 prepended must be drawn because the first glyph string
21595 i
= left_overwritten (head
);
21598 enum draw_glyphs_face overlap_hl
;
21600 /* If this row contains mouse highlighting, attempt to draw
21601 the overlapped glyphs with the correct highlight. This
21602 code fails if the overlap encompasses more than one glyph
21603 and mouse-highlight spans only some of these glyphs.
21604 However, making it work perfectly involves a lot more
21605 code, and I don't know if the pathological case occurs in
21606 practice, so we'll stick to this for now. --- cyd */
21607 if (check_mouse_face
21608 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21609 overlap_hl
= DRAW_MOUSE_FACE
;
21611 overlap_hl
= DRAW_NORMAL_TEXT
;
21614 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
21615 overlap_hl
, dummy_x
, last_x
);
21617 compute_overhangs_and_x (t
, head
->x
, 1);
21618 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21622 /* Prepend glyph strings for glyphs in front of the first glyph
21623 string that overwrite that glyph string because of their
21624 right overhang. For these strings, only the foreground must
21625 be drawn, because it draws over the glyph string at `head'.
21626 The background must not be drawn because this would overwrite
21627 right overhangs of preceding glyphs for which no glyph
21629 i
= left_overwriting (head
);
21632 enum draw_glyphs_face overlap_hl
;
21634 if (check_mouse_face
21635 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21636 overlap_hl
= DRAW_MOUSE_FACE
;
21638 overlap_hl
= DRAW_NORMAL_TEXT
;
21641 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
21642 overlap_hl
, dummy_x
, last_x
);
21643 for (s
= h
; s
; s
= s
->next
)
21644 s
->background_filled_p
= 1;
21645 compute_overhangs_and_x (t
, head
->x
, 1);
21646 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21649 /* Append glyphs strings for glyphs following the last glyph
21650 string tail that are overwritten by tail. The background of
21651 these strings has to be drawn because tail's foreground draws
21653 i
= right_overwritten (tail
);
21656 enum draw_glyphs_face overlap_hl
;
21658 if (check_mouse_face
21659 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21660 overlap_hl
= DRAW_MOUSE_FACE
;
21662 overlap_hl
= DRAW_NORMAL_TEXT
;
21664 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21665 overlap_hl
, x
, last_x
);
21666 /* Because BUILD_GLYPH_STRINGS updates the first argument,
21667 we don't have `end = i;' here. */
21668 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21669 append_glyph_string_lists (&head
, &tail
, h
, t
);
21673 /* Append glyph strings for glyphs following the last glyph
21674 string tail that overwrite tail. The foreground of such
21675 glyphs has to be drawn because it writes into the background
21676 of tail. The background must not be drawn because it could
21677 paint over the foreground of following glyphs. */
21678 i
= right_overwriting (tail
);
21681 enum draw_glyphs_face overlap_hl
;
21682 if (check_mouse_face
21683 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21684 overlap_hl
= DRAW_MOUSE_FACE
;
21686 overlap_hl
= DRAW_NORMAL_TEXT
;
21689 i
++; /* We must include the Ith glyph. */
21690 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21691 overlap_hl
, x
, last_x
);
21692 for (s
= h
; s
; s
= s
->next
)
21693 s
->background_filled_p
= 1;
21694 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21695 append_glyph_string_lists (&head
, &tail
, h
, t
);
21697 if (clip_head
|| clip_tail
)
21698 for (s
= head
; s
; s
= s
->next
)
21700 s
->clip_head
= clip_head
;
21701 s
->clip_tail
= clip_tail
;
21705 /* Draw all strings. */
21706 for (s
= head
; s
; s
= s
->next
)
21707 FRAME_RIF (f
)->draw_glyph_string (s
);
21710 /* When focus a sole frame and move horizontally, this sets on_p to 0
21711 causing a failure to erase prev cursor position. */
21712 if (area
== TEXT_AREA
21713 && !row
->full_width_p
21714 /* When drawing overlapping rows, only the glyph strings'
21715 foreground is drawn, which doesn't erase a cursor
21719 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
21720 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
21721 : (tail
? tail
->x
+ tail
->background_width
: x
));
21725 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
21726 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
21730 /* Value is the x-position up to which drawn, relative to AREA of W.
21731 This doesn't include parts drawn because of overhangs. */
21732 if (row
->full_width_p
)
21733 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
21735 x_reached
-= area_left
;
21737 RELEASE_HDC (hdc
, f
);
21742 /* Expand row matrix if too narrow. Don't expand if area
21745 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
21747 if (!fonts_changed_p \
21748 && (it->glyph_row->glyphs[area] \
21749 < it->glyph_row->glyphs[area + 1])) \
21751 it->w->ncols_scale_factor++; \
21752 fonts_changed_p = 1; \
21756 /* Store one glyph for IT->char_to_display in IT->glyph_row.
21757 Called from x_produce_glyphs when IT->glyph_row is non-null. */
21760 append_glyph (struct it
*it
)
21762 struct glyph
*glyph
;
21763 enum glyph_row_area area
= it
->area
;
21765 xassert (it
->glyph_row
);
21766 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
21768 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21769 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21771 /* If the glyph row is reversed, we need to prepend the glyph
21772 rather than append it. */
21773 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
21777 /* Make room for the additional glyph. */
21778 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
21780 glyph
= it
->glyph_row
->glyphs
[area
];
21782 glyph
->charpos
= CHARPOS (it
->position
);
21783 glyph
->object
= it
->object
;
21784 if (it
->pixel_width
> 0)
21786 glyph
->pixel_width
= it
->pixel_width
;
21787 glyph
->padding_p
= 0;
21791 /* Assure at least 1-pixel width. Otherwise, cursor can't
21792 be displayed correctly. */
21793 glyph
->pixel_width
= 1;
21794 glyph
->padding_p
= 1;
21796 glyph
->ascent
= it
->ascent
;
21797 glyph
->descent
= it
->descent
;
21798 glyph
->voffset
= it
->voffset
;
21799 glyph
->type
= CHAR_GLYPH
;
21800 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21801 glyph
->multibyte_p
= it
->multibyte_p
;
21802 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21803 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21804 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21805 || it
->phys_descent
> it
->descent
);
21806 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
21807 glyph
->face_id
= it
->face_id
;
21808 glyph
->u
.ch
= it
->char_to_display
;
21809 glyph
->slice
.img
= null_glyph_slice
;
21810 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21813 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21814 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21816 glyph
->bidi_type
= it
->bidi_it
.type
;
21820 glyph
->resolved_level
= 0;
21821 glyph
->bidi_type
= UNKNOWN_BT
;
21823 ++it
->glyph_row
->used
[area
];
21826 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21829 /* Store one glyph for the composition IT->cmp_it.id in
21830 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
21834 append_composite_glyph (struct it
*it
)
21836 struct glyph
*glyph
;
21837 enum glyph_row_area area
= it
->area
;
21839 xassert (it
->glyph_row
);
21841 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21842 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21844 /* If the glyph row is reversed, we need to prepend the glyph
21845 rather than append it. */
21846 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
21850 /* Make room for the new glyph. */
21851 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
21853 glyph
= it
->glyph_row
->glyphs
[it
->area
];
21855 glyph
->charpos
= it
->cmp_it
.charpos
;
21856 glyph
->object
= it
->object
;
21857 glyph
->pixel_width
= it
->pixel_width
;
21858 glyph
->ascent
= it
->ascent
;
21859 glyph
->descent
= it
->descent
;
21860 glyph
->voffset
= it
->voffset
;
21861 glyph
->type
= COMPOSITE_GLYPH
;
21862 if (it
->cmp_it
.ch
< 0)
21864 glyph
->u
.cmp
.automatic
= 0;
21865 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21866 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
21870 glyph
->u
.cmp
.automatic
= 1;
21871 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21872 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
21873 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
21875 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21876 glyph
->multibyte_p
= it
->multibyte_p
;
21877 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21878 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21879 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21880 || it
->phys_descent
> it
->descent
);
21881 glyph
->padding_p
= 0;
21882 glyph
->glyph_not_available_p
= 0;
21883 glyph
->face_id
= it
->face_id
;
21884 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21887 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21888 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21890 glyph
->bidi_type
= it
->bidi_it
.type
;
21892 ++it
->glyph_row
->used
[area
];
21895 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21899 /* Change IT->ascent and IT->height according to the setting of
21903 take_vertical_position_into_account (struct it
*it
)
21907 if (it
->voffset
< 0)
21908 /* Increase the ascent so that we can display the text higher
21910 it
->ascent
-= it
->voffset
;
21912 /* Increase the descent so that we can display the text lower
21914 it
->descent
+= it
->voffset
;
21919 /* Produce glyphs/get display metrics for the image IT is loaded with.
21920 See the description of struct display_iterator in dispextern.h for
21921 an overview of struct display_iterator. */
21924 produce_image_glyph (struct it
*it
)
21928 int glyph_ascent
, crop
;
21929 struct glyph_slice slice
;
21931 xassert (it
->what
== IT_IMAGE
);
21933 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21935 /* Make sure X resources of the face is loaded. */
21936 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21938 if (it
->image_id
< 0)
21940 /* Fringe bitmap. */
21941 it
->ascent
= it
->phys_ascent
= 0;
21942 it
->descent
= it
->phys_descent
= 0;
21943 it
->pixel_width
= 0;
21948 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
21950 /* Make sure X resources of the image is loaded. */
21951 prepare_image_for_display (it
->f
, img
);
21953 slice
.x
= slice
.y
= 0;
21954 slice
.width
= img
->width
;
21955 slice
.height
= img
->height
;
21957 if (INTEGERP (it
->slice
.x
))
21958 slice
.x
= XINT (it
->slice
.x
);
21959 else if (FLOATP (it
->slice
.x
))
21960 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
21962 if (INTEGERP (it
->slice
.y
))
21963 slice
.y
= XINT (it
->slice
.y
);
21964 else if (FLOATP (it
->slice
.y
))
21965 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
21967 if (INTEGERP (it
->slice
.width
))
21968 slice
.width
= XINT (it
->slice
.width
);
21969 else if (FLOATP (it
->slice
.width
))
21970 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
21972 if (INTEGERP (it
->slice
.height
))
21973 slice
.height
= XINT (it
->slice
.height
);
21974 else if (FLOATP (it
->slice
.height
))
21975 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
21977 if (slice
.x
>= img
->width
)
21978 slice
.x
= img
->width
;
21979 if (slice
.y
>= img
->height
)
21980 slice
.y
= img
->height
;
21981 if (slice
.x
+ slice
.width
>= img
->width
)
21982 slice
.width
= img
->width
- slice
.x
;
21983 if (slice
.y
+ slice
.height
> img
->height
)
21984 slice
.height
= img
->height
- slice
.y
;
21986 if (slice
.width
== 0 || slice
.height
== 0)
21989 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
21991 it
->descent
= slice
.height
- glyph_ascent
;
21993 it
->descent
+= img
->vmargin
;
21994 if (slice
.y
+ slice
.height
== img
->height
)
21995 it
->descent
+= img
->vmargin
;
21996 it
->phys_descent
= it
->descent
;
21998 it
->pixel_width
= slice
.width
;
22000 it
->pixel_width
+= img
->hmargin
;
22001 if (slice
.x
+ slice
.width
== img
->width
)
22002 it
->pixel_width
+= img
->hmargin
;
22004 /* It's quite possible for images to have an ascent greater than
22005 their height, so don't get confused in that case. */
22006 if (it
->descent
< 0)
22011 if (face
->box
!= FACE_NO_BOX
)
22013 if (face
->box_line_width
> 0)
22016 it
->ascent
+= face
->box_line_width
;
22017 if (slice
.y
+ slice
.height
== img
->height
)
22018 it
->descent
+= face
->box_line_width
;
22021 if (it
->start_of_box_run_p
&& slice
.x
== 0)
22022 it
->pixel_width
+= eabs (face
->box_line_width
);
22023 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
22024 it
->pixel_width
+= eabs (face
->box_line_width
);
22027 take_vertical_position_into_account (it
);
22029 /* Automatically crop wide image glyphs at right edge so we can
22030 draw the cursor on same display row. */
22031 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
22032 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
22034 it
->pixel_width
-= crop
;
22035 slice
.width
-= crop
;
22040 struct glyph
*glyph
;
22041 enum glyph_row_area area
= it
->area
;
22043 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22044 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22046 glyph
->charpos
= CHARPOS (it
->position
);
22047 glyph
->object
= it
->object
;
22048 glyph
->pixel_width
= it
->pixel_width
;
22049 glyph
->ascent
= glyph_ascent
;
22050 glyph
->descent
= it
->descent
;
22051 glyph
->voffset
= it
->voffset
;
22052 glyph
->type
= IMAGE_GLYPH
;
22053 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22054 glyph
->multibyte_p
= it
->multibyte_p
;
22055 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22056 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22057 glyph
->overlaps_vertically_p
= 0;
22058 glyph
->padding_p
= 0;
22059 glyph
->glyph_not_available_p
= 0;
22060 glyph
->face_id
= it
->face_id
;
22061 glyph
->u
.img_id
= img
->id
;
22062 glyph
->slice
.img
= slice
;
22063 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22066 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22067 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22069 glyph
->bidi_type
= it
->bidi_it
.type
;
22071 ++it
->glyph_row
->used
[area
];
22074 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22079 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
22080 of the glyph, WIDTH and HEIGHT are the width and height of the
22081 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
22084 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
22085 int width
, int height
, int ascent
)
22087 struct glyph
*glyph
;
22088 enum glyph_row_area area
= it
->area
;
22090 xassert (ascent
>= 0 && ascent
<= height
);
22092 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22093 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22095 /* If the glyph row is reversed, we need to prepend the glyph
22096 rather than append it. */
22097 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22101 /* Make room for the additional glyph. */
22102 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22104 glyph
= it
->glyph_row
->glyphs
[area
];
22106 glyph
->charpos
= CHARPOS (it
->position
);
22107 glyph
->object
= object
;
22108 glyph
->pixel_width
= width
;
22109 glyph
->ascent
= ascent
;
22110 glyph
->descent
= height
- ascent
;
22111 glyph
->voffset
= it
->voffset
;
22112 glyph
->type
= STRETCH_GLYPH
;
22113 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22114 glyph
->multibyte_p
= it
->multibyte_p
;
22115 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22116 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22117 glyph
->overlaps_vertically_p
= 0;
22118 glyph
->padding_p
= 0;
22119 glyph
->glyph_not_available_p
= 0;
22120 glyph
->face_id
= it
->face_id
;
22121 glyph
->u
.stretch
.ascent
= ascent
;
22122 glyph
->u
.stretch
.height
= height
;
22123 glyph
->slice
.img
= null_glyph_slice
;
22124 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22127 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22128 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22130 glyph
->bidi_type
= it
->bidi_it
.type
;
22134 glyph
->resolved_level
= 0;
22135 glyph
->bidi_type
= UNKNOWN_BT
;
22137 ++it
->glyph_row
->used
[area
];
22140 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22144 /* Produce a stretch glyph for iterator IT. IT->object is the value
22145 of the glyph property displayed. The value must be a list
22146 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
22149 1. `:width WIDTH' specifies that the space should be WIDTH *
22150 canonical char width wide. WIDTH may be an integer or floating
22153 2. `:relative-width FACTOR' specifies that the width of the stretch
22154 should be computed from the width of the first character having the
22155 `glyph' property, and should be FACTOR times that width.
22157 3. `:align-to HPOS' specifies that the space should be wide enough
22158 to reach HPOS, a value in canonical character units.
22160 Exactly one of the above pairs must be present.
22162 4. `:height HEIGHT' specifies that the height of the stretch produced
22163 should be HEIGHT, measured in canonical character units.
22165 5. `:relative-height FACTOR' specifies that the height of the
22166 stretch should be FACTOR times the height of the characters having
22167 the glyph property.
22169 Either none or exactly one of 4 or 5 must be present.
22171 6. `:ascent ASCENT' specifies that ASCENT percent of the height
22172 of the stretch should be used for the ascent of the stretch.
22173 ASCENT must be in the range 0 <= ASCENT <= 100. */
22176 produce_stretch_glyph (struct it
*it
)
22178 /* (space :width WIDTH :height HEIGHT ...) */
22179 Lisp_Object prop
, plist
;
22180 int width
= 0, height
= 0, align_to
= -1;
22181 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
22184 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22185 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22187 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22189 /* List should start with `space'. */
22190 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
22191 plist
= XCDR (it
->object
);
22193 /* Compute the width of the stretch. */
22194 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
22195 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
22197 /* Absolute width `:width WIDTH' specified and valid. */
22198 zero_width_ok_p
= 1;
22201 else if (prop
= Fplist_get (plist
, QCrelative_width
),
22204 /* Relative width `:relative-width FACTOR' specified and valid.
22205 Compute the width of the characters having the `glyph'
22208 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
22211 if (it
->multibyte_p
)
22212 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
22215 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
22216 if (! ASCII_CHAR_P (it2
.c
))
22217 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
22220 it2
.glyph_row
= NULL
;
22221 it2
.what
= IT_CHARACTER
;
22222 x_produce_glyphs (&it2
);
22223 width
= NUMVAL (prop
) * it2
.pixel_width
;
22225 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
22226 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
22228 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
22229 align_to
= (align_to
< 0
22231 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
22232 else if (align_to
< 0)
22233 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
22234 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
22235 zero_width_ok_p
= 1;
22238 /* Nothing specified -> width defaults to canonical char width. */
22239 width
= FRAME_COLUMN_WIDTH (it
->f
);
22241 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
22244 /* Compute height. */
22245 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
22246 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22249 zero_height_ok_p
= 1;
22251 else if (prop
= Fplist_get (plist
, QCrelative_height
),
22253 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
22255 height
= FONT_HEIGHT (font
);
22257 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
22260 /* Compute percentage of height used for ascent. If
22261 `:ascent ASCENT' is present and valid, use that. Otherwise,
22262 derive the ascent from the font in use. */
22263 if (prop
= Fplist_get (plist
, QCascent
),
22264 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
22265 ascent
= height
* NUMVAL (prop
) / 100.0;
22266 else if (!NILP (prop
)
22267 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
22268 ascent
= min (max (0, (int)tem
), height
);
22270 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
22272 if (width
> 0 && it
->line_wrap
!= TRUNCATE
22273 && it
->current_x
+ width
> it
->last_visible_x
)
22274 width
= it
->last_visible_x
- it
->current_x
- 1;
22276 if (width
> 0 && height
> 0 && it
->glyph_row
)
22278 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
22279 if (!STRINGP (object
))
22280 object
= it
->w
->buffer
;
22281 append_stretch_glyph (it
, object
, width
, height
, ascent
);
22284 it
->pixel_width
= width
;
22285 it
->ascent
= it
->phys_ascent
= ascent
;
22286 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
22287 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
22289 take_vertical_position_into_account (it
);
22292 /* Calculate line-height and line-spacing properties.
22293 An integer value specifies explicit pixel value.
22294 A float value specifies relative value to current face height.
22295 A cons (float . face-name) specifies relative value to
22296 height of specified face font.
22298 Returns height in pixels, or nil. */
22302 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
22303 int boff
, int override
)
22305 Lisp_Object face_name
= Qnil
;
22306 int ascent
, descent
, height
;
22308 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
22313 face_name
= XCAR (val
);
22315 if (!NUMBERP (val
))
22316 val
= make_number (1);
22317 if (NILP (face_name
))
22319 height
= it
->ascent
+ it
->descent
;
22324 if (NILP (face_name
))
22326 font
= FRAME_FONT (it
->f
);
22327 boff
= FRAME_BASELINE_OFFSET (it
->f
);
22329 else if (EQ (face_name
, Qt
))
22338 face_id
= lookup_named_face (it
->f
, face_name
, 0);
22340 return make_number (-1);
22342 face
= FACE_FROM_ID (it
->f
, face_id
);
22345 return make_number (-1);
22346 boff
= font
->baseline_offset
;
22347 if (font
->vertical_centering
)
22348 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22351 ascent
= FONT_BASE (font
) + boff
;
22352 descent
= FONT_DESCENT (font
) - boff
;
22356 it
->override_ascent
= ascent
;
22357 it
->override_descent
= descent
;
22358 it
->override_boff
= boff
;
22361 height
= ascent
+ descent
;
22365 height
= (int)(XFLOAT_DATA (val
) * height
);
22366 else if (INTEGERP (val
))
22367 height
*= XINT (val
);
22369 return make_number (height
);
22373 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
22374 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
22375 and only if this is for a character for which no font was found.
22377 If the display method (it->glyphless_method) is
22378 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
22379 length of the acronym or the hexadecimal string, UPPER_XOFF and
22380 UPPER_YOFF are pixel offsets for the upper part of the string,
22381 LOWER_XOFF and LOWER_YOFF are for the lower part.
22383 For the other display methods, LEN through LOWER_YOFF are zero. */
22386 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
22387 short upper_xoff
, short upper_yoff
,
22388 short lower_xoff
, short lower_yoff
)
22390 struct glyph
*glyph
;
22391 enum glyph_row_area area
= it
->area
;
22393 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
22394 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
22396 /* If the glyph row is reversed, we need to prepend the glyph
22397 rather than append it. */
22398 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
22402 /* Make room for the additional glyph. */
22403 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
22405 glyph
= it
->glyph_row
->glyphs
[area
];
22407 glyph
->charpos
= CHARPOS (it
->position
);
22408 glyph
->object
= it
->object
;
22409 glyph
->pixel_width
= it
->pixel_width
;
22410 glyph
->ascent
= it
->ascent
;
22411 glyph
->descent
= it
->descent
;
22412 glyph
->voffset
= it
->voffset
;
22413 glyph
->type
= GLYPHLESS_GLYPH
;
22414 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
22415 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
22416 glyph
->u
.glyphless
.len
= len
;
22417 glyph
->u
.glyphless
.ch
= it
->c
;
22418 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
22419 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
22420 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
22421 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
22422 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
22423 glyph
->multibyte_p
= it
->multibyte_p
;
22424 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
22425 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
22426 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
22427 || it
->phys_descent
> it
->descent
);
22428 glyph
->padding_p
= 0;
22429 glyph
->glyph_not_available_p
= 0;
22430 glyph
->face_id
= face_id
;
22431 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
22434 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
22435 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
22437 glyph
->bidi_type
= it
->bidi_it
.type
;
22439 ++it
->glyph_row
->used
[area
];
22442 IT_EXPAND_MATRIX_WIDTH (it
, area
);
22446 /* Produce a glyph for a glyphless character for iterator IT.
22447 IT->glyphless_method specifies which method to use for displaying
22448 the character. See the description of enum
22449 glyphless_display_method in dispextern.h for the detail.
22451 FOR_NO_FONT is nonzero if and only if this is for a character for
22452 which no font was found. ACRONYM, if non-nil, is an acronym string
22453 for the character. */
22456 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
22461 int base_width
, base_height
, width
, height
;
22462 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
22465 /* Get the metrics of the base font. We always refer to the current
22467 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
22468 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22469 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
22470 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
22471 base_height
= it
->ascent
+ it
->descent
;
22472 base_width
= font
->average_width
;
22474 /* Get a face ID for the glyph by utilizing a cache (the same way as
22475 doen for `escape-glyph' in get_next_display_element). */
22476 if (it
->f
== last_glyphless_glyph_frame
22477 && it
->face_id
== last_glyphless_glyph_face_id
)
22479 face_id
= last_glyphless_glyph_merged_face_id
;
22483 /* Merge the `glyphless-char' face into the current face. */
22484 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
22485 last_glyphless_glyph_frame
= it
->f
;
22486 last_glyphless_glyph_face_id
= it
->face_id
;
22487 last_glyphless_glyph_merged_face_id
= face_id
;
22490 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
22492 it
->pixel_width
= THIN_SPACE_WIDTH
;
22494 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22496 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
22498 width
= CHAR_WIDTH (it
->c
);
22501 else if (width
> 4)
22503 it
->pixel_width
= base_width
* width
;
22505 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
22511 unsigned int code
[6];
22513 int ascent
, descent
;
22514 struct font_metrics metrics_upper
, metrics_lower
;
22516 face
= FACE_FROM_ID (it
->f
, face_id
);
22517 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
22518 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
22520 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
22522 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
22523 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
22524 if (CONSP (acronym
))
22525 acronym
= XCAR (acronym
);
22526 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
22530 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
22531 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
22534 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
22535 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
22536 upper_len
= (len
+ 1) / 2;
22537 font
->driver
->text_extents (font
, code
, upper_len
,
22539 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
22544 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
22545 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
22546 upper_xoff
= upper_yoff
= 2; /* the typical case */
22547 if (base_width
>= width
)
22549 /* Align the upper to the left, the lower to the right. */
22550 it
->pixel_width
= base_width
;
22551 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
22555 /* Center the shorter one. */
22556 it
->pixel_width
= width
;
22557 if (metrics_upper
.width
>= metrics_lower
.width
)
22558 lower_xoff
= (width
- metrics_lower
.width
) / 2;
22561 /* FIXME: This code doesn't look right. It formerly was
22562 missing the "lower_xoff = 0;", which couldn't have
22563 been right since it left lower_xoff uninitialized. */
22565 upper_xoff
= (width
- metrics_upper
.width
) / 2;
22569 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
22570 top, bottom, and between upper and lower strings. */
22571 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
22572 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
22573 /* Center vertically.
22574 H:base_height, D:base_descent
22575 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
22577 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
22578 descent = D - H/2 + h/2;
22579 lower_yoff = descent - 2 - ld;
22580 upper_yoff = lower_yoff - la - 1 - ud; */
22581 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
22582 descent
= it
->descent
- (base_height
- height
) / 2;
22583 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
22584 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
22585 - metrics_upper
.descent
);
22586 /* Don't make the height shorter than the base height. */
22587 if (height
> base_height
)
22589 it
->ascent
= ascent
;
22590 it
->descent
= descent
;
22594 it
->phys_ascent
= it
->ascent
;
22595 it
->phys_descent
= it
->descent
;
22597 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
22598 upper_xoff
, upper_yoff
,
22599 lower_xoff
, lower_yoff
);
22601 take_vertical_position_into_account (it
);
22606 Produce glyphs/get display metrics for the display element IT is
22607 loaded with. See the description of struct it in dispextern.h
22608 for an overview of struct it. */
22611 x_produce_glyphs (struct it
*it
)
22613 int extra_line_spacing
= it
->extra_line_spacing
;
22615 it
->glyph_not_available_p
= 0;
22617 if (it
->what
== IT_CHARACTER
)
22620 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22621 struct font
*font
= face
->font
;
22622 struct font_metrics
*pcm
= NULL
;
22623 int boff
; /* baseline offset */
22627 /* When no suitable font is found, display this character by
22628 the method specified in the first extra slot of
22629 Vglyphless_char_display. */
22630 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
22632 xassert (it
->what
== IT_GLYPHLESS
);
22633 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
22637 boff
= font
->baseline_offset
;
22638 if (font
->vertical_centering
)
22639 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22641 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
22647 if (it
->override_ascent
>= 0)
22649 it
->ascent
= it
->override_ascent
;
22650 it
->descent
= it
->override_descent
;
22651 boff
= it
->override_boff
;
22655 it
->ascent
= FONT_BASE (font
) + boff
;
22656 it
->descent
= FONT_DESCENT (font
) - boff
;
22659 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
22661 pcm
= get_per_char_metric (font
, &char2b
);
22662 if (pcm
->width
== 0
22663 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
22669 it
->phys_ascent
= pcm
->ascent
+ boff
;
22670 it
->phys_descent
= pcm
->descent
- boff
;
22671 it
->pixel_width
= pcm
->width
;
22675 it
->glyph_not_available_p
= 1;
22676 it
->phys_ascent
= it
->ascent
;
22677 it
->phys_descent
= it
->descent
;
22678 it
->pixel_width
= font
->space_width
;
22681 if (it
->constrain_row_ascent_descent_p
)
22683 if (it
->descent
> it
->max_descent
)
22685 it
->ascent
+= it
->descent
- it
->max_descent
;
22686 it
->descent
= it
->max_descent
;
22688 if (it
->ascent
> it
->max_ascent
)
22690 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22691 it
->ascent
= it
->max_ascent
;
22693 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22694 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22695 extra_line_spacing
= 0;
22698 /* If this is a space inside a region of text with
22699 `space-width' property, change its width. */
22700 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
22702 it
->pixel_width
*= XFLOATINT (it
->space_width
);
22704 /* If face has a box, add the box thickness to the character
22705 height. If character has a box line to the left and/or
22706 right, add the box line width to the character's width. */
22707 if (face
->box
!= FACE_NO_BOX
)
22709 int thick
= face
->box_line_width
;
22713 it
->ascent
+= thick
;
22714 it
->descent
+= thick
;
22719 if (it
->start_of_box_run_p
)
22720 it
->pixel_width
+= thick
;
22721 if (it
->end_of_box_run_p
)
22722 it
->pixel_width
+= thick
;
22725 /* If face has an overline, add the height of the overline
22726 (1 pixel) and a 1 pixel margin to the character height. */
22727 if (face
->overline_p
)
22728 it
->ascent
+= overline_margin
;
22730 if (it
->constrain_row_ascent_descent_p
)
22732 if (it
->ascent
> it
->max_ascent
)
22733 it
->ascent
= it
->max_ascent
;
22734 if (it
->descent
> it
->max_descent
)
22735 it
->descent
= it
->max_descent
;
22738 take_vertical_position_into_account (it
);
22740 /* If we have to actually produce glyphs, do it. */
22745 /* Translate a space with a `space-width' property
22746 into a stretch glyph. */
22747 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
22748 / FONT_HEIGHT (font
));
22749 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22750 it
->ascent
+ it
->descent
, ascent
);
22755 /* If characters with lbearing or rbearing are displayed
22756 in this line, record that fact in a flag of the
22757 glyph row. This is used to optimize X output code. */
22758 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
22759 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22761 if (! stretched_p
&& it
->pixel_width
== 0)
22762 /* We assure that all visible glyphs have at least 1-pixel
22764 it
->pixel_width
= 1;
22766 else if (it
->char_to_display
== '\n')
22768 /* A newline has no width, but we need the height of the
22769 line. But if previous part of the line sets a height,
22770 don't increase that height */
22772 Lisp_Object height
;
22773 Lisp_Object total_height
= Qnil
;
22775 it
->override_ascent
= -1;
22776 it
->pixel_width
= 0;
22779 height
= get_it_property (it
, Qline_height
);
22780 /* Split (line-height total-height) list */
22782 && CONSP (XCDR (height
))
22783 && NILP (XCDR (XCDR (height
))))
22785 total_height
= XCAR (XCDR (height
));
22786 height
= XCAR (height
);
22788 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
22790 if (it
->override_ascent
>= 0)
22792 it
->ascent
= it
->override_ascent
;
22793 it
->descent
= it
->override_descent
;
22794 boff
= it
->override_boff
;
22798 it
->ascent
= FONT_BASE (font
) + boff
;
22799 it
->descent
= FONT_DESCENT (font
) - boff
;
22802 if (EQ (height
, Qt
))
22804 if (it
->descent
> it
->max_descent
)
22806 it
->ascent
+= it
->descent
- it
->max_descent
;
22807 it
->descent
= it
->max_descent
;
22809 if (it
->ascent
> it
->max_ascent
)
22811 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22812 it
->ascent
= it
->max_ascent
;
22814 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22815 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22816 it
->constrain_row_ascent_descent_p
= 1;
22817 extra_line_spacing
= 0;
22821 Lisp_Object spacing
;
22823 it
->phys_ascent
= it
->ascent
;
22824 it
->phys_descent
= it
->descent
;
22826 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
22827 && face
->box
!= FACE_NO_BOX
22828 && face
->box_line_width
> 0)
22830 it
->ascent
+= face
->box_line_width
;
22831 it
->descent
+= face
->box_line_width
;
22834 && XINT (height
) > it
->ascent
+ it
->descent
)
22835 it
->ascent
= XINT (height
) - it
->descent
;
22837 if (!NILP (total_height
))
22838 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
22841 spacing
= get_it_property (it
, Qline_spacing
);
22842 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
22844 if (INTEGERP (spacing
))
22846 extra_line_spacing
= XINT (spacing
);
22847 if (!NILP (total_height
))
22848 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
22852 else /* i.e. (it->char_to_display == '\t') */
22854 if (font
->space_width
> 0)
22856 int tab_width
= it
->tab_width
* font
->space_width
;
22857 int x
= it
->current_x
+ it
->continuation_lines_width
;
22858 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
22860 /* If the distance from the current position to the next tab
22861 stop is less than a space character width, use the
22862 tab stop after that. */
22863 if (next_tab_x
- x
< font
->space_width
)
22864 next_tab_x
+= tab_width
;
22866 it
->pixel_width
= next_tab_x
- x
;
22868 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
22869 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22873 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22874 it
->ascent
+ it
->descent
, it
->ascent
);
22879 it
->pixel_width
= 0;
22884 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
22886 /* A static composition.
22888 Note: A composition is represented as one glyph in the
22889 glyph matrix. There are no padding glyphs.
22891 Important note: pixel_width, ascent, and descent are the
22892 values of what is drawn by draw_glyphs (i.e. the values of
22893 the overall glyphs composed). */
22894 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22895 int boff
; /* baseline offset */
22896 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
22897 int glyph_len
= cmp
->glyph_len
;
22898 struct font
*font
= face
->font
;
22902 /* If we have not yet calculated pixel size data of glyphs of
22903 the composition for the current face font, calculate them
22904 now. Theoretically, we have to check all fonts for the
22905 glyphs, but that requires much time and memory space. So,
22906 here we check only the font of the first glyph. This may
22907 lead to incorrect display, but it's very rare, and C-l
22908 (recenter-top-bottom) can correct the display anyway. */
22909 if (! cmp
->font
|| cmp
->font
!= font
)
22911 /* Ascent and descent of the font of the first character
22912 of this composition (adjusted by baseline offset).
22913 Ascent and descent of overall glyphs should not be less
22914 than these, respectively. */
22915 int font_ascent
, font_descent
, font_height
;
22916 /* Bounding box of the overall glyphs. */
22917 int leftmost
, rightmost
, lowest
, highest
;
22918 int lbearing
, rbearing
;
22919 int i
, width
, ascent
, descent
;
22920 int left_padded
= 0, right_padded
= 0;
22921 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
22923 struct font_metrics
*pcm
;
22924 int font_not_found_p
;
22927 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
22928 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
22930 if (glyph_len
< cmp
->glyph_len
)
22932 for (i
= 0; i
< glyph_len
; i
++)
22934 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
22936 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22941 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
22942 : IT_CHARPOS (*it
));
22943 /* If no suitable font is found, use the default font. */
22944 font_not_found_p
= font
== NULL
;
22945 if (font_not_found_p
)
22947 face
= face
->ascii_face
;
22950 boff
= font
->baseline_offset
;
22951 if (font
->vertical_centering
)
22952 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22953 font_ascent
= FONT_BASE (font
) + boff
;
22954 font_descent
= FONT_DESCENT (font
) - boff
;
22955 font_height
= FONT_HEIGHT (font
);
22957 cmp
->font
= (void *) font
;
22960 if (! font_not_found_p
)
22962 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
22964 pcm
= get_per_char_metric (font
, &char2b
);
22967 /* Initialize the bounding box. */
22970 width
= pcm
->width
;
22971 ascent
= pcm
->ascent
;
22972 descent
= pcm
->descent
;
22973 lbearing
= pcm
->lbearing
;
22974 rbearing
= pcm
->rbearing
;
22978 width
= font
->space_width
;
22979 ascent
= FONT_BASE (font
);
22980 descent
= FONT_DESCENT (font
);
22987 lowest
= - descent
+ boff
;
22988 highest
= ascent
+ boff
;
22990 if (! font_not_found_p
22991 && font
->default_ascent
22992 && CHAR_TABLE_P (Vuse_default_ascent
)
22993 && !NILP (Faref (Vuse_default_ascent
,
22994 make_number (it
->char_to_display
))))
22995 highest
= font
->default_ascent
+ boff
;
22997 /* Draw the first glyph at the normal position. It may be
22998 shifted to right later if some other glyphs are drawn
23000 cmp
->offsets
[i
* 2] = 0;
23001 cmp
->offsets
[i
* 2 + 1] = boff
;
23002 cmp
->lbearing
= lbearing
;
23003 cmp
->rbearing
= rbearing
;
23005 /* Set cmp->offsets for the remaining glyphs. */
23006 for (i
++; i
< glyph_len
; i
++)
23008 int left
, right
, btm
, top
;
23009 int ch
= COMPOSITION_GLYPH (cmp
, i
);
23011 struct face
*this_face
;
23015 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
23016 this_face
= FACE_FROM_ID (it
->f
, face_id
);
23017 font
= this_face
->font
;
23023 get_char_face_and_encoding (it
->f
, ch
, face_id
,
23025 pcm
= get_per_char_metric (font
, &char2b
);
23028 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
23031 width
= pcm
->width
;
23032 ascent
= pcm
->ascent
;
23033 descent
= pcm
->descent
;
23034 lbearing
= pcm
->lbearing
;
23035 rbearing
= pcm
->rbearing
;
23036 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
23038 /* Relative composition with or without
23039 alternate chars. */
23040 left
= (leftmost
+ rightmost
- width
) / 2;
23041 btm
= - descent
+ boff
;
23042 if (font
->relative_compose
23043 && (! CHAR_TABLE_P (Vignore_relative_composition
)
23044 || NILP (Faref (Vignore_relative_composition
,
23045 make_number (ch
)))))
23048 if (- descent
>= font
->relative_compose
)
23049 /* One extra pixel between two glyphs. */
23051 else if (ascent
<= 0)
23052 /* One extra pixel between two glyphs. */
23053 btm
= lowest
- 1 - ascent
- descent
;
23058 /* A composition rule is specified by an integer
23059 value that encodes global and new reference
23060 points (GREF and NREF). GREF and NREF are
23061 specified by numbers as below:
23063 0---1---2 -- ascent
23067 9--10--11 -- center
23069 ---3---4---5--- baseline
23071 6---7---8 -- descent
23073 int rule
= COMPOSITION_RULE (cmp
, i
);
23074 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
23076 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
23077 grefx
= gref
% 3, nrefx
= nref
% 3;
23078 grefy
= gref
/ 3, nrefy
= nref
/ 3;
23080 xoff
= font_height
* (xoff
- 128) / 256;
23082 yoff
= font_height
* (yoff
- 128) / 256;
23085 + grefx
* (rightmost
- leftmost
) / 2
23086 - nrefx
* width
/ 2
23089 btm
= ((grefy
== 0 ? highest
23091 : grefy
== 2 ? lowest
23092 : (highest
+ lowest
) / 2)
23093 - (nrefy
== 0 ? ascent
+ descent
23094 : nrefy
== 1 ? descent
- boff
23096 : (ascent
+ descent
) / 2)
23100 cmp
->offsets
[i
* 2] = left
;
23101 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
23103 /* Update the bounding box of the overall glyphs. */
23106 right
= left
+ width
;
23107 if (left
< leftmost
)
23109 if (right
> rightmost
)
23112 top
= btm
+ descent
+ ascent
;
23118 if (cmp
->lbearing
> left
+ lbearing
)
23119 cmp
->lbearing
= left
+ lbearing
;
23120 if (cmp
->rbearing
< left
+ rbearing
)
23121 cmp
->rbearing
= left
+ rbearing
;
23125 /* If there are glyphs whose x-offsets are negative,
23126 shift all glyphs to the right and make all x-offsets
23130 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23131 cmp
->offsets
[i
* 2] -= leftmost
;
23132 rightmost
-= leftmost
;
23133 cmp
->lbearing
-= leftmost
;
23134 cmp
->rbearing
-= leftmost
;
23137 if (left_padded
&& cmp
->lbearing
< 0)
23139 for (i
= 0; i
< cmp
->glyph_len
; i
++)
23140 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
23141 rightmost
-= cmp
->lbearing
;
23142 cmp
->rbearing
-= cmp
->lbearing
;
23145 if (right_padded
&& rightmost
< cmp
->rbearing
)
23147 rightmost
= cmp
->rbearing
;
23150 cmp
->pixel_width
= rightmost
;
23151 cmp
->ascent
= highest
;
23152 cmp
->descent
= - lowest
;
23153 if (cmp
->ascent
< font_ascent
)
23154 cmp
->ascent
= font_ascent
;
23155 if (cmp
->descent
< font_descent
)
23156 cmp
->descent
= font_descent
;
23160 && (cmp
->lbearing
< 0
23161 || cmp
->rbearing
> cmp
->pixel_width
))
23162 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23164 it
->pixel_width
= cmp
->pixel_width
;
23165 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
23166 it
->descent
= it
->phys_descent
= cmp
->descent
;
23167 if (face
->box
!= FACE_NO_BOX
)
23169 int thick
= face
->box_line_width
;
23173 it
->ascent
+= thick
;
23174 it
->descent
+= thick
;
23179 if (it
->start_of_box_run_p
)
23180 it
->pixel_width
+= thick
;
23181 if (it
->end_of_box_run_p
)
23182 it
->pixel_width
+= thick
;
23185 /* If face has an overline, add the height of the overline
23186 (1 pixel) and a 1 pixel margin to the character height. */
23187 if (face
->overline_p
)
23188 it
->ascent
+= overline_margin
;
23190 take_vertical_position_into_account (it
);
23191 if (it
->ascent
< 0)
23193 if (it
->descent
< 0)
23197 append_composite_glyph (it
);
23199 else if (it
->what
== IT_COMPOSITION
)
23201 /* A dynamic (automatic) composition. */
23202 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23203 Lisp_Object gstring
;
23204 struct font_metrics metrics
;
23206 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
23208 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
23211 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
23212 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
23213 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
23214 it
->descent
= it
->phys_descent
= metrics
.descent
;
23215 if (face
->box
!= FACE_NO_BOX
)
23217 int thick
= face
->box_line_width
;
23221 it
->ascent
+= thick
;
23222 it
->descent
+= thick
;
23227 if (it
->start_of_box_run_p
)
23228 it
->pixel_width
+= thick
;
23229 if (it
->end_of_box_run_p
)
23230 it
->pixel_width
+= thick
;
23232 /* If face has an overline, add the height of the overline
23233 (1 pixel) and a 1 pixel margin to the character height. */
23234 if (face
->overline_p
)
23235 it
->ascent
+= overline_margin
;
23236 take_vertical_position_into_account (it
);
23237 if (it
->ascent
< 0)
23239 if (it
->descent
< 0)
23243 append_composite_glyph (it
);
23245 else if (it
->what
== IT_GLYPHLESS
)
23246 produce_glyphless_glyph (it
, 0, Qnil
);
23247 else if (it
->what
== IT_IMAGE
)
23248 produce_image_glyph (it
);
23249 else if (it
->what
== IT_STRETCH
)
23250 produce_stretch_glyph (it
);
23253 /* Accumulate dimensions. Note: can't assume that it->descent > 0
23254 because this isn't true for images with `:ascent 100'. */
23255 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
23256 if (it
->area
== TEXT_AREA
)
23257 it
->current_x
+= it
->pixel_width
;
23259 if (extra_line_spacing
> 0)
23261 it
->descent
+= extra_line_spacing
;
23262 if (extra_line_spacing
> it
->max_extra_line_spacing
)
23263 it
->max_extra_line_spacing
= extra_line_spacing
;
23266 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
23267 it
->max_descent
= max (it
->max_descent
, it
->descent
);
23268 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
23269 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
23273 Output LEN glyphs starting at START at the nominal cursor position.
23274 Advance the nominal cursor over the text. The global variable
23275 updated_window contains the window being updated, updated_row is
23276 the glyph row being updated, and updated_area is the area of that
23277 row being updated. */
23280 x_write_glyphs (struct glyph
*start
, int len
)
23284 xassert (updated_window
&& updated_row
);
23287 /* Write glyphs. */
23289 hpos
= start
- updated_row
->glyphs
[updated_area
];
23290 x
= draw_glyphs (updated_window
, output_cursor
.x
,
23291 updated_row
, updated_area
,
23293 DRAW_NORMAL_TEXT
, 0);
23295 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
23296 if (updated_area
== TEXT_AREA
23297 && updated_window
->phys_cursor_on_p
23298 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
23299 && updated_window
->phys_cursor
.hpos
>= hpos
23300 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
23301 updated_window
->phys_cursor_on_p
= 0;
23305 /* Advance the output cursor. */
23306 output_cursor
.hpos
+= len
;
23307 output_cursor
.x
= x
;
23312 Insert LEN glyphs from START at the nominal cursor position. */
23315 x_insert_glyphs (struct glyph
*start
, int len
)
23319 int line_height
, shift_by_width
, shifted_region_width
;
23320 struct glyph_row
*row
;
23321 struct glyph
*glyph
;
23322 int frame_x
, frame_y
;
23325 xassert (updated_window
&& updated_row
);
23327 w
= updated_window
;
23328 f
= XFRAME (WINDOW_FRAME (w
));
23330 /* Get the height of the line we are in. */
23332 line_height
= row
->height
;
23334 /* Get the width of the glyphs to insert. */
23335 shift_by_width
= 0;
23336 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
23337 shift_by_width
+= glyph
->pixel_width
;
23339 /* Get the width of the region to shift right. */
23340 shifted_region_width
= (window_box_width (w
, updated_area
)
23345 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
23346 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
23348 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
23349 line_height
, shift_by_width
);
23351 /* Write the glyphs. */
23352 hpos
= start
- row
->glyphs
[updated_area
];
23353 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
23355 DRAW_NORMAL_TEXT
, 0);
23357 /* Advance the output cursor. */
23358 output_cursor
.hpos
+= len
;
23359 output_cursor
.x
+= shift_by_width
;
23365 Erase the current text line from the nominal cursor position
23366 (inclusive) to pixel column TO_X (exclusive). The idea is that
23367 everything from TO_X onward is already erased.
23369 TO_X is a pixel position relative to updated_area of
23370 updated_window. TO_X == -1 means clear to the end of this area. */
23373 x_clear_end_of_line (int to_x
)
23376 struct window
*w
= updated_window
;
23377 int max_x
, min_y
, max_y
;
23378 int from_x
, from_y
, to_y
;
23380 xassert (updated_window
&& updated_row
);
23381 f
= XFRAME (w
->frame
);
23383 if (updated_row
->full_width_p
)
23384 max_x
= WINDOW_TOTAL_WIDTH (w
);
23386 max_x
= window_box_width (w
, updated_area
);
23387 max_y
= window_text_bottom_y (w
);
23389 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
23390 of window. For TO_X > 0, truncate to end of drawing area. */
23396 to_x
= min (to_x
, max_x
);
23398 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
23400 /* Notice if the cursor will be cleared by this operation. */
23401 if (!updated_row
->full_width_p
)
23402 notice_overwritten_cursor (w
, updated_area
,
23403 output_cursor
.x
, -1,
23405 MATRIX_ROW_BOTTOM_Y (updated_row
));
23407 from_x
= output_cursor
.x
;
23409 /* Translate to frame coordinates. */
23410 if (updated_row
->full_width_p
)
23412 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
23413 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
23417 int area_left
= window_box_left (w
, updated_area
);
23418 from_x
+= area_left
;
23422 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
23423 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
23424 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
23426 /* Prevent inadvertently clearing to end of the X window. */
23427 if (to_x
> from_x
&& to_y
> from_y
)
23430 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
23431 to_x
- from_x
, to_y
- from_y
);
23436 #endif /* HAVE_WINDOW_SYSTEM */
23440 /***********************************************************************
23442 ***********************************************************************/
23444 /* Value is the internal representation of the specified cursor type
23445 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
23446 of the bar cursor. */
23448 static enum text_cursor_kinds
23449 get_specified_cursor_type (Lisp_Object arg
, int *width
)
23451 enum text_cursor_kinds type
;
23456 if (EQ (arg
, Qbox
))
23457 return FILLED_BOX_CURSOR
;
23459 if (EQ (arg
, Qhollow
))
23460 return HOLLOW_BOX_CURSOR
;
23462 if (EQ (arg
, Qbar
))
23469 && EQ (XCAR (arg
), Qbar
)
23470 && INTEGERP (XCDR (arg
))
23471 && XINT (XCDR (arg
)) >= 0)
23473 *width
= XINT (XCDR (arg
));
23477 if (EQ (arg
, Qhbar
))
23480 return HBAR_CURSOR
;
23484 && EQ (XCAR (arg
), Qhbar
)
23485 && INTEGERP (XCDR (arg
))
23486 && XINT (XCDR (arg
)) >= 0)
23488 *width
= XINT (XCDR (arg
));
23489 return HBAR_CURSOR
;
23492 /* Treat anything unknown as "hollow box cursor".
23493 It was bad to signal an error; people have trouble fixing
23494 .Xdefaults with Emacs, when it has something bad in it. */
23495 type
= HOLLOW_BOX_CURSOR
;
23500 /* Set the default cursor types for specified frame. */
23502 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
23507 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
23508 FRAME_CURSOR_WIDTH (f
) = width
;
23510 /* By default, set up the blink-off state depending on the on-state. */
23512 tem
= Fassoc (arg
, Vblink_cursor_alist
);
23515 FRAME_BLINK_OFF_CURSOR (f
)
23516 = get_specified_cursor_type (XCDR (tem
), &width
);
23517 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
23520 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
23524 #ifdef HAVE_WINDOW_SYSTEM
23526 /* Return the cursor we want to be displayed in window W. Return
23527 width of bar/hbar cursor through WIDTH arg. Return with
23528 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
23529 (i.e. if the `system caret' should track this cursor).
23531 In a mini-buffer window, we want the cursor only to appear if we
23532 are reading input from this window. For the selected window, we
23533 want the cursor type given by the frame parameter or buffer local
23534 setting of cursor-type. If explicitly marked off, draw no cursor.
23535 In all other cases, we want a hollow box cursor. */
23537 static enum text_cursor_kinds
23538 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
23539 int *active_cursor
)
23541 struct frame
*f
= XFRAME (w
->frame
);
23542 struct buffer
*b
= XBUFFER (w
->buffer
);
23543 int cursor_type
= DEFAULT_CURSOR
;
23544 Lisp_Object alt_cursor
;
23545 int non_selected
= 0;
23547 *active_cursor
= 1;
23550 if (cursor_in_echo_area
23551 && FRAME_HAS_MINIBUF_P (f
)
23552 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
23554 if (w
== XWINDOW (echo_area_window
))
23556 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
23558 *width
= FRAME_CURSOR_WIDTH (f
);
23559 return FRAME_DESIRED_CURSOR (f
);
23562 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
23565 *active_cursor
= 0;
23569 /* Detect a nonselected window or nonselected frame. */
23570 else if (w
!= XWINDOW (f
->selected_window
)
23571 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
23573 *active_cursor
= 0;
23575 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
23581 /* Never display a cursor in a window in which cursor-type is nil. */
23582 if (NILP (BVAR (b
, cursor_type
)))
23585 /* Get the normal cursor type for this window. */
23586 if (EQ (BVAR (b
, cursor_type
), Qt
))
23588 cursor_type
= FRAME_DESIRED_CURSOR (f
);
23589 *width
= FRAME_CURSOR_WIDTH (f
);
23592 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
23594 /* Use cursor-in-non-selected-windows instead
23595 for non-selected window or frame. */
23598 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
23599 if (!EQ (Qt
, alt_cursor
))
23600 return get_specified_cursor_type (alt_cursor
, width
);
23601 /* t means modify the normal cursor type. */
23602 if (cursor_type
== FILLED_BOX_CURSOR
)
23603 cursor_type
= HOLLOW_BOX_CURSOR
;
23604 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
23606 return cursor_type
;
23609 /* Use normal cursor if not blinked off. */
23610 if (!w
->cursor_off_p
)
23612 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23614 if (cursor_type
== FILLED_BOX_CURSOR
)
23616 /* Using a block cursor on large images can be very annoying.
23617 So use a hollow cursor for "large" images.
23618 If image is not transparent (no mask), also use hollow cursor. */
23619 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23620 if (img
!= NULL
&& IMAGEP (img
->spec
))
23622 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
23623 where N = size of default frame font size.
23624 This should cover most of the "tiny" icons people may use. */
23626 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
23627 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
23628 cursor_type
= HOLLOW_BOX_CURSOR
;
23631 else if (cursor_type
!= NO_CURSOR
)
23633 /* Display current only supports BOX and HOLLOW cursors for images.
23634 So for now, unconditionally use a HOLLOW cursor when cursor is
23635 not a solid box cursor. */
23636 cursor_type
= HOLLOW_BOX_CURSOR
;
23639 return cursor_type
;
23642 /* Cursor is blinked off, so determine how to "toggle" it. */
23644 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
23645 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
23646 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
23648 /* Then see if frame has specified a specific blink off cursor type. */
23649 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
23651 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
23652 return FRAME_BLINK_OFF_CURSOR (f
);
23656 /* Some people liked having a permanently visible blinking cursor,
23657 while others had very strong opinions against it. So it was
23658 decided to remove it. KFS 2003-09-03 */
23660 /* Finally perform built-in cursor blinking:
23661 filled box <-> hollow box
23662 wide [h]bar <-> narrow [h]bar
23663 narrow [h]bar <-> no cursor
23664 other type <-> no cursor */
23666 if (cursor_type
== FILLED_BOX_CURSOR
)
23667 return HOLLOW_BOX_CURSOR
;
23669 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
23672 return cursor_type
;
23680 /* Notice when the text cursor of window W has been completely
23681 overwritten by a drawing operation that outputs glyphs in AREA
23682 starting at X0 and ending at X1 in the line starting at Y0 and
23683 ending at Y1. X coordinates are area-relative. X1 < 0 means all
23684 the rest of the line after X0 has been written. Y coordinates
23685 are window-relative. */
23688 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
23689 int x0
, int x1
, int y0
, int y1
)
23691 int cx0
, cx1
, cy0
, cy1
;
23692 struct glyph_row
*row
;
23694 if (!w
->phys_cursor_on_p
)
23696 if (area
!= TEXT_AREA
)
23699 if (w
->phys_cursor
.vpos
< 0
23700 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
23701 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
23702 !(row
->enabled_p
&& row
->displays_text_p
)))
23705 if (row
->cursor_in_fringe_p
)
23707 row
->cursor_in_fringe_p
= 0;
23708 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
23709 w
->phys_cursor_on_p
= 0;
23713 cx0
= w
->phys_cursor
.x
;
23714 cx1
= cx0
+ w
->phys_cursor_width
;
23715 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
23718 /* The cursor image will be completely removed from the
23719 screen if the output area intersects the cursor area in
23720 y-direction. When we draw in [y0 y1[, and some part of
23721 the cursor is at y < y0, that part must have been drawn
23722 before. When scrolling, the cursor is erased before
23723 actually scrolling, so we don't come here. When not
23724 scrolling, the rows above the old cursor row must have
23725 changed, and in this case these rows must have written
23726 over the cursor image.
23728 Likewise if part of the cursor is below y1, with the
23729 exception of the cursor being in the first blank row at
23730 the buffer and window end because update_text_area
23731 doesn't draw that row. (Except when it does, but
23732 that's handled in update_text_area.) */
23734 cy0
= w
->phys_cursor
.y
;
23735 cy1
= cy0
+ w
->phys_cursor_height
;
23736 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
23739 w
->phys_cursor_on_p
= 0;
23742 #endif /* HAVE_WINDOW_SYSTEM */
23745 /************************************************************************
23747 ************************************************************************/
23749 #ifdef HAVE_WINDOW_SYSTEM
23752 Fix the display of area AREA of overlapping row ROW in window W
23753 with respect to the overlapping part OVERLAPS. */
23756 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
23757 enum glyph_row_area area
, int overlaps
)
23764 for (i
= 0; i
< row
->used
[area
];)
23766 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
23768 int start
= i
, start_x
= x
;
23772 x
+= row
->glyphs
[area
][i
].pixel_width
;
23775 while (i
< row
->used
[area
]
23776 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
23778 draw_glyphs (w
, start_x
, row
, area
,
23780 DRAW_NORMAL_TEXT
, overlaps
);
23784 x
+= row
->glyphs
[area
][i
].pixel_width
;
23794 Draw the cursor glyph of window W in glyph row ROW. See the
23795 comment of draw_glyphs for the meaning of HL. */
23798 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
23799 enum draw_glyphs_face hl
)
23801 /* If cursor hpos is out of bounds, don't draw garbage. This can
23802 happen in mini-buffer windows when switching between echo area
23803 glyphs and mini-buffer. */
23804 if ((row
->reversed_p
23805 ? (w
->phys_cursor
.hpos
>= 0)
23806 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
23808 int on_p
= w
->phys_cursor_on_p
;
23810 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
23811 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
23813 w
->phys_cursor_on_p
= on_p
;
23815 if (hl
== DRAW_CURSOR
)
23816 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23817 /* When we erase the cursor, and ROW is overlapped by other
23818 rows, make sure that these overlapping parts of other rows
23820 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
23822 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23824 if (row
> w
->current_matrix
->rows
23825 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
23826 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
23827 OVERLAPS_ERASED_CURSOR
);
23829 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
23830 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
23831 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
23832 OVERLAPS_ERASED_CURSOR
);
23839 Erase the image of a cursor of window W from the screen. */
23842 erase_phys_cursor (struct window
*w
)
23844 struct frame
*f
= XFRAME (w
->frame
);
23845 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23846 int hpos
= w
->phys_cursor
.hpos
;
23847 int vpos
= w
->phys_cursor
.vpos
;
23848 int mouse_face_here_p
= 0;
23849 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
23850 struct glyph_row
*cursor_row
;
23851 struct glyph
*cursor_glyph
;
23852 enum draw_glyphs_face hl
;
23854 /* No cursor displayed or row invalidated => nothing to do on the
23856 if (w
->phys_cursor_type
== NO_CURSOR
)
23857 goto mark_cursor_off
;
23859 /* VPOS >= active_glyphs->nrows means that window has been resized.
23860 Don't bother to erase the cursor. */
23861 if (vpos
>= active_glyphs
->nrows
)
23862 goto mark_cursor_off
;
23864 /* If row containing cursor is marked invalid, there is nothing we
23866 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
23867 if (!cursor_row
->enabled_p
)
23868 goto mark_cursor_off
;
23870 /* If line spacing is > 0, old cursor may only be partially visible in
23871 window after split-window. So adjust visible height. */
23872 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
23873 window_text_bottom_y (w
) - cursor_row
->y
);
23875 /* If row is completely invisible, don't attempt to delete a cursor which
23876 isn't there. This can happen if cursor is at top of a window, and
23877 we switch to a buffer with a header line in that window. */
23878 if (cursor_row
->visible_height
<= 0)
23879 goto mark_cursor_off
;
23881 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
23882 if (cursor_row
->cursor_in_fringe_p
)
23884 cursor_row
->cursor_in_fringe_p
= 0;
23885 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
23886 goto mark_cursor_off
;
23889 /* This can happen when the new row is shorter than the old one.
23890 In this case, either draw_glyphs or clear_end_of_line
23891 should have cleared the cursor. Note that we wouldn't be
23892 able to erase the cursor in this case because we don't have a
23893 cursor glyph at hand. */
23894 if ((cursor_row
->reversed_p
23895 ? (w
->phys_cursor
.hpos
< 0)
23896 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
23897 goto mark_cursor_off
;
23899 /* If the cursor is in the mouse face area, redisplay that when
23900 we clear the cursor. */
23901 if (! NILP (hlinfo
->mouse_face_window
)
23902 && coords_in_mouse_face_p (w
, hpos
, vpos
)
23903 /* Don't redraw the cursor's spot in mouse face if it is at the
23904 end of a line (on a newline). The cursor appears there, but
23905 mouse highlighting does not. */
23906 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
23907 mouse_face_here_p
= 1;
23909 /* Maybe clear the display under the cursor. */
23910 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
23913 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
23916 cursor_glyph
= get_phys_cursor_glyph (w
);
23917 if (cursor_glyph
== NULL
)
23918 goto mark_cursor_off
;
23920 width
= cursor_glyph
->pixel_width
;
23921 left_x
= window_box_left_offset (w
, TEXT_AREA
);
23922 x
= w
->phys_cursor
.x
;
23924 width
-= left_x
- x
;
23925 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
23926 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
23927 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
23930 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
23933 /* Erase the cursor by redrawing the character underneath it. */
23934 if (mouse_face_here_p
)
23935 hl
= DRAW_MOUSE_FACE
;
23937 hl
= DRAW_NORMAL_TEXT
;
23938 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
23941 w
->phys_cursor_on_p
= 0;
23942 w
->phys_cursor_type
= NO_CURSOR
;
23947 Display or clear cursor of window W. If ON is zero, clear the
23948 cursor. If it is non-zero, display the cursor. If ON is nonzero,
23949 where to put the cursor is specified by HPOS, VPOS, X and Y. */
23952 display_and_set_cursor (struct window
*w
, int on
,
23953 int hpos
, int vpos
, int x
, int y
)
23955 struct frame
*f
= XFRAME (w
->frame
);
23956 int new_cursor_type
;
23957 int new_cursor_width
;
23959 struct glyph_row
*glyph_row
;
23960 struct glyph
*glyph
;
23962 /* This is pointless on invisible frames, and dangerous on garbaged
23963 windows and frames; in the latter case, the frame or window may
23964 be in the midst of changing its size, and x and y may be off the
23966 if (! FRAME_VISIBLE_P (f
)
23967 || FRAME_GARBAGED_P (f
)
23968 || vpos
>= w
->current_matrix
->nrows
23969 || hpos
>= w
->current_matrix
->matrix_w
)
23972 /* If cursor is off and we want it off, return quickly. */
23973 if (!on
&& !w
->phys_cursor_on_p
)
23976 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
23977 /* If cursor row is not enabled, we don't really know where to
23978 display the cursor. */
23979 if (!glyph_row
->enabled_p
)
23981 w
->phys_cursor_on_p
= 0;
23986 if (!glyph_row
->exact_window_width_line_p
23987 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
23988 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
23990 xassert (interrupt_input_blocked
);
23992 /* Set new_cursor_type to the cursor we want to be displayed. */
23993 new_cursor_type
= get_window_cursor_type (w
, glyph
,
23994 &new_cursor_width
, &active_cursor
);
23996 /* If cursor is currently being shown and we don't want it to be or
23997 it is in the wrong place, or the cursor type is not what we want,
23999 if (w
->phys_cursor_on_p
24001 || w
->phys_cursor
.x
!= x
24002 || w
->phys_cursor
.y
!= y
24003 || new_cursor_type
!= w
->phys_cursor_type
24004 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
24005 && new_cursor_width
!= w
->phys_cursor_width
)))
24006 erase_phys_cursor (w
);
24008 /* Don't check phys_cursor_on_p here because that flag is only set
24009 to zero in some cases where we know that the cursor has been
24010 completely erased, to avoid the extra work of erasing the cursor
24011 twice. In other words, phys_cursor_on_p can be 1 and the cursor
24012 still not be visible, or it has only been partly erased. */
24015 w
->phys_cursor_ascent
= glyph_row
->ascent
;
24016 w
->phys_cursor_height
= glyph_row
->height
;
24018 /* Set phys_cursor_.* before x_draw_.* is called because some
24019 of them may need the information. */
24020 w
->phys_cursor
.x
= x
;
24021 w
->phys_cursor
.y
= glyph_row
->y
;
24022 w
->phys_cursor
.hpos
= hpos
;
24023 w
->phys_cursor
.vpos
= vpos
;
24026 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
24027 new_cursor_type
, new_cursor_width
,
24028 on
, active_cursor
);
24032 /* Switch the display of W's cursor on or off, according to the value
24036 update_window_cursor (struct window
*w
, int on
)
24038 /* Don't update cursor in windows whose frame is in the process
24039 of being deleted. */
24040 if (w
->current_matrix
)
24043 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24044 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24050 /* Call update_window_cursor with parameter ON_P on all leaf windows
24051 in the window tree rooted at W. */
24054 update_cursor_in_window_tree (struct window
*w
, int on_p
)
24058 if (!NILP (w
->hchild
))
24059 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
24060 else if (!NILP (w
->vchild
))
24061 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
24063 update_window_cursor (w
, on_p
);
24065 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
24071 Display the cursor on window W, or clear it, according to ON_P.
24072 Don't change the cursor's position. */
24075 x_update_cursor (struct frame
*f
, int on_p
)
24077 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
24082 Clear the cursor of window W to background color, and mark the
24083 cursor as not shown. This is used when the text where the cursor
24084 is about to be rewritten. */
24087 x_clear_cursor (struct window
*w
)
24089 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
24090 update_window_cursor (w
, 0);
24093 #endif /* HAVE_WINDOW_SYSTEM */
24095 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
24098 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
24099 int start_hpos
, int end_hpos
,
24100 enum draw_glyphs_face draw
)
24102 #ifdef HAVE_WINDOW_SYSTEM
24103 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
24105 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
24109 #if defined (HAVE_GPM) || defined (MSDOS)
24110 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
24114 /* Display the active region described by mouse_face_* according to DRAW. */
24117 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
24119 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
24120 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24122 if (/* If window is in the process of being destroyed, don't bother
24124 w
->current_matrix
!= NULL
24125 /* Don't update mouse highlight if hidden */
24126 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
24127 /* Recognize when we are called to operate on rows that don't exist
24128 anymore. This can happen when a window is split. */
24129 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
24131 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
24132 struct glyph_row
*row
, *first
, *last
;
24134 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
24135 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
24137 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
24139 int start_hpos
, end_hpos
, start_x
;
24141 /* For all but the first row, the highlight starts at column 0. */
24144 /* R2L rows have BEG and END in reversed order, but the
24145 screen drawing geometry is always left to right. So
24146 we need to mirror the beginning and end of the
24147 highlighted area in R2L rows. */
24148 if (!row
->reversed_p
)
24150 start_hpos
= hlinfo
->mouse_face_beg_col
;
24151 start_x
= hlinfo
->mouse_face_beg_x
;
24153 else if (row
== last
)
24155 start_hpos
= hlinfo
->mouse_face_end_col
;
24156 start_x
= hlinfo
->mouse_face_end_x
;
24164 else if (row
->reversed_p
&& row
== last
)
24166 start_hpos
= hlinfo
->mouse_face_end_col
;
24167 start_x
= hlinfo
->mouse_face_end_x
;
24177 if (!row
->reversed_p
)
24178 end_hpos
= hlinfo
->mouse_face_end_col
;
24179 else if (row
== first
)
24180 end_hpos
= hlinfo
->mouse_face_beg_col
;
24183 end_hpos
= row
->used
[TEXT_AREA
];
24184 if (draw
== DRAW_NORMAL_TEXT
)
24185 row
->fill_line_p
= 1; /* Clear to end of line */
24188 else if (row
->reversed_p
&& row
== first
)
24189 end_hpos
= hlinfo
->mouse_face_beg_col
;
24192 end_hpos
= row
->used
[TEXT_AREA
];
24193 if (draw
== DRAW_NORMAL_TEXT
)
24194 row
->fill_line_p
= 1; /* Clear to end of line */
24197 if (end_hpos
> start_hpos
)
24199 draw_row_with_mouse_face (w
, start_x
, row
,
24200 start_hpos
, end_hpos
, draw
);
24203 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
24207 #ifdef HAVE_WINDOW_SYSTEM
24208 /* When we've written over the cursor, arrange for it to
24209 be displayed again. */
24210 if (FRAME_WINDOW_P (f
)
24211 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
24214 display_and_set_cursor (w
, 1,
24215 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
24216 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
24219 #endif /* HAVE_WINDOW_SYSTEM */
24222 #ifdef HAVE_WINDOW_SYSTEM
24223 /* Change the mouse cursor. */
24224 if (FRAME_WINDOW_P (f
))
24226 if (draw
== DRAW_NORMAL_TEXT
24227 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
24228 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
24229 else if (draw
== DRAW_MOUSE_FACE
)
24230 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
24232 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
24234 #endif /* HAVE_WINDOW_SYSTEM */
24238 Clear out the mouse-highlighted active region.
24239 Redraw it un-highlighted first. Value is non-zero if mouse
24240 face was actually drawn unhighlighted. */
24243 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
24247 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
24249 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
24253 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
24254 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
24255 hlinfo
->mouse_face_window
= Qnil
;
24256 hlinfo
->mouse_face_overlay
= Qnil
;
24260 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
24261 within the mouse face on that window. */
24263 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
24265 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
24267 /* Quickly resolve the easy cases. */
24268 if (!(WINDOWP (hlinfo
->mouse_face_window
)
24269 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
24271 if (vpos
< hlinfo
->mouse_face_beg_row
24272 || vpos
> hlinfo
->mouse_face_end_row
)
24274 if (vpos
> hlinfo
->mouse_face_beg_row
24275 && vpos
< hlinfo
->mouse_face_end_row
)
24278 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
24280 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24282 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
24285 else if ((vpos
== hlinfo
->mouse_face_beg_row
24286 && hpos
>= hlinfo
->mouse_face_beg_col
)
24287 || (vpos
== hlinfo
->mouse_face_end_row
24288 && hpos
< hlinfo
->mouse_face_end_col
))
24293 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
24295 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
24298 else if ((vpos
== hlinfo
->mouse_face_beg_row
24299 && hpos
<= hlinfo
->mouse_face_beg_col
)
24300 || (vpos
== hlinfo
->mouse_face_end_row
24301 && hpos
> hlinfo
->mouse_face_end_col
))
24309 Non-zero if physical cursor of window W is within mouse face. */
24312 cursor_in_mouse_face_p (struct window
*w
)
24314 return coords_in_mouse_face_p (w
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
);
24319 /* Find the glyph rows START_ROW and END_ROW of window W that display
24320 characters between buffer positions START_CHARPOS and END_CHARPOS
24321 (excluding END_CHARPOS). This is similar to row_containing_pos,
24322 but is more accurate when bidi reordering makes buffer positions
24323 change non-linearly with glyph rows. */
24325 rows_from_pos_range (struct window
*w
,
24326 EMACS_INT start_charpos
, EMACS_INT end_charpos
,
24327 struct glyph_row
**start
, struct glyph_row
**end
)
24329 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24330 int last_y
= window_text_bottom_y (w
);
24331 struct glyph_row
*row
;
24336 while (!first
->enabled_p
24337 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
24340 /* Find the START row. */
24342 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
24345 /* A row can potentially be the START row if the range of the
24346 characters it displays intersects the range
24347 [START_CHARPOS..END_CHARPOS). */
24348 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
24349 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
24350 /* See the commentary in row_containing_pos, for the
24351 explanation of the complicated way to check whether
24352 some position is beyond the end of the characters
24353 displayed by a row. */
24354 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24355 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24356 && !row
->ends_at_zv_p
24357 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
24358 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
24359 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
24360 && !row
->ends_at_zv_p
24361 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
24363 /* Found a candidate row. Now make sure at least one of the
24364 glyphs it displays has a charpos from the range
24365 [START_CHARPOS..END_CHARPOS).
24367 This is not obvious because bidi reordering could make
24368 buffer positions of a row be 1,2,3,102,101,100, and if we
24369 want to highlight characters in [50..60), we don't want
24370 this row, even though [50..60) does intersect [1..103),
24371 the range of character positions given by the row's start
24372 and end positions. */
24373 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
24374 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
24378 if (BUFFERP (g
->object
)
24379 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24388 /* Find the END row. */
24390 /* If the last row is partially visible, start looking for END
24391 from that row, instead of starting from FIRST. */
24392 && !(row
->enabled_p
24393 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
24395 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
24397 struct glyph_row
*next
= row
+ 1;
24399 if (!next
->enabled_p
24400 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
24401 /* The first row >= START whose range of displayed characters
24402 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
24403 is the row END + 1. */
24404 || (start_charpos
< MATRIX_ROW_START_CHARPOS (next
)
24405 && end_charpos
< MATRIX_ROW_START_CHARPOS (next
))
24406 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24407 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24408 && !next
->ends_at_zv_p
24409 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
24410 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
24411 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
24412 && !next
->ends_at_zv_p
24413 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
24420 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
24421 but none of the characters it displays are in the range, it is
24423 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
24424 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
24428 if (BUFFERP (g
->object
)
24429 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
24442 /* This function sets the mouse_face_* elements of HLINFO, assuming
24443 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
24444 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
24445 for the overlay or run of text properties specifying the mouse
24446 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
24447 before-string and after-string that must also be highlighted.
24448 COVER_STRING, if non-nil, is a display string that may cover some
24449 or all of the highlighted text. */
24452 mouse_face_from_buffer_pos (Lisp_Object window
,
24453 Mouse_HLInfo
*hlinfo
,
24454 EMACS_INT mouse_charpos
,
24455 EMACS_INT start_charpos
,
24456 EMACS_INT end_charpos
,
24457 Lisp_Object before_string
,
24458 Lisp_Object after_string
,
24459 Lisp_Object cover_string
)
24461 struct window
*w
= XWINDOW (window
);
24462 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24463 struct glyph_row
*r1
, *r2
;
24464 struct glyph
*glyph
, *end
;
24465 EMACS_INT ignore
, pos
;
24468 xassert (NILP (cover_string
) || STRINGP (cover_string
));
24469 xassert (NILP (before_string
) || STRINGP (before_string
));
24470 xassert (NILP (after_string
) || STRINGP (after_string
));
24472 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
24473 rows_from_pos_range (w
, start_charpos
, end_charpos
, &r1
, &r2
);
24475 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24476 /* If the before-string or display-string contains newlines,
24477 rows_from_pos_range skips to its last row. Move back. */
24478 if (!NILP (before_string
) || !NILP (cover_string
))
24480 struct glyph_row
*prev
;
24481 while ((prev
= r1
- 1, prev
>= first
)
24482 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
24483 && prev
->used
[TEXT_AREA
] > 0)
24485 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
24486 glyph
= beg
+ prev
->used
[TEXT_AREA
];
24487 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
24489 || !(EQ (glyph
->object
, before_string
)
24490 || EQ (glyph
->object
, cover_string
)))
24497 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24498 hlinfo
->mouse_face_past_end
= 1;
24500 else if (!NILP (after_string
))
24502 /* If the after-string has newlines, advance to its last row. */
24503 struct glyph_row
*next
;
24504 struct glyph_row
*last
24505 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
24507 for (next
= r2
+ 1;
24509 && next
->used
[TEXT_AREA
] > 0
24510 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
24514 /* The rest of the display engine assumes that mouse_face_beg_row is
24515 either above below mouse_face_end_row or identical to it. But
24516 with bidi-reordered continued lines, the row for START_CHARPOS
24517 could be below the row for END_CHARPOS. If so, swap the rows and
24518 store them in correct order. */
24521 struct glyph_row
*tem
= r2
;
24527 hlinfo
->mouse_face_beg_y
= r1
->y
;
24528 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
24529 hlinfo
->mouse_face_end_y
= r2
->y
;
24530 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
24532 /* For a bidi-reordered row, the positions of BEFORE_STRING,
24533 AFTER_STRING, COVER_STRING, START_CHARPOS, and END_CHARPOS
24534 could be anywhere in the row and in any order. The strategy
24535 below is to find the leftmost and the rightmost glyph that
24536 belongs to either of these 3 strings, or whose position is
24537 between START_CHARPOS and END_CHARPOS, and highlight all the
24538 glyphs between those two. This may cover more than just the text
24539 between START_CHARPOS and END_CHARPOS if the range of characters
24540 strides the bidi level boundary, e.g. if the beginning is in R2L
24541 text while the end is in L2R text or vice versa. */
24542 if (!r1
->reversed_p
)
24544 /* This row is in a left to right paragraph. Scan it left to
24546 glyph
= r1
->glyphs
[TEXT_AREA
];
24547 end
= glyph
+ r1
->used
[TEXT_AREA
];
24550 /* Skip truncation glyphs at the start of the glyph row. */
24551 if (r1
->displays_text_p
)
24553 && INTEGERP (glyph
->object
)
24554 && glyph
->charpos
< 0;
24556 x
+= glyph
->pixel_width
;
24558 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24559 or COVER_STRING, and the first glyph from buffer whose
24560 position is between START_CHARPOS and END_CHARPOS. */
24562 && !INTEGERP (glyph
->object
)
24563 && !EQ (glyph
->object
, cover_string
)
24564 && !(BUFFERP (glyph
->object
)
24565 && (glyph
->charpos
>= start_charpos
24566 && glyph
->charpos
< end_charpos
));
24569 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24570 are present at buffer positions between START_CHARPOS and
24571 END_CHARPOS, or if they come from an overlay. */
24572 if (EQ (glyph
->object
, before_string
))
24574 pos
= string_buffer_position (before_string
,
24576 /* If pos == 0, it means before_string came from an
24577 overlay, not from a buffer position. */
24578 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24581 else if (EQ (glyph
->object
, after_string
))
24583 pos
= string_buffer_position (after_string
, end_charpos
);
24584 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24587 x
+= glyph
->pixel_width
;
24589 hlinfo
->mouse_face_beg_x
= x
;
24590 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24594 /* This row is in a right to left paragraph. Scan it right to
24598 end
= r1
->glyphs
[TEXT_AREA
] - 1;
24599 glyph
= end
+ r1
->used
[TEXT_AREA
];
24601 /* Skip truncation glyphs at the start of the glyph row. */
24602 if (r1
->displays_text_p
)
24604 && INTEGERP (glyph
->object
)
24605 && glyph
->charpos
< 0;
24609 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
24610 or COVER_STRING, and the first glyph from buffer whose
24611 position is between START_CHARPOS and END_CHARPOS. */
24613 && !INTEGERP (glyph
->object
)
24614 && !EQ (glyph
->object
, cover_string
)
24615 && !(BUFFERP (glyph
->object
)
24616 && (glyph
->charpos
>= start_charpos
24617 && glyph
->charpos
< end_charpos
));
24620 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24621 are present at buffer positions between START_CHARPOS and
24622 END_CHARPOS, or if they come from an overlay. */
24623 if (EQ (glyph
->object
, before_string
))
24625 pos
= string_buffer_position (before_string
, start_charpos
);
24626 /* If pos == 0, it means before_string came from an
24627 overlay, not from a buffer position. */
24628 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24631 else if (EQ (glyph
->object
, after_string
))
24633 pos
= string_buffer_position (after_string
, end_charpos
);
24634 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24639 glyph
++; /* first glyph to the right of the highlighted area */
24640 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
24641 x
+= g
->pixel_width
;
24642 hlinfo
->mouse_face_beg_x
= x
;
24643 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
24646 /* If the highlight ends in a different row, compute GLYPH and END
24647 for the end row. Otherwise, reuse the values computed above for
24648 the row where the highlight begins. */
24651 if (!r2
->reversed_p
)
24653 glyph
= r2
->glyphs
[TEXT_AREA
];
24654 end
= glyph
+ r2
->used
[TEXT_AREA
];
24659 end
= r2
->glyphs
[TEXT_AREA
] - 1;
24660 glyph
= end
+ r2
->used
[TEXT_AREA
];
24664 if (!r2
->reversed_p
)
24666 /* Skip truncation and continuation glyphs near the end of the
24667 row, and also blanks and stretch glyphs inserted by
24668 extend_face_to_end_of_line. */
24670 && INTEGERP ((end
- 1)->object
)
24671 && (end
- 1)->charpos
<= 0)
24673 /* Scan the rest of the glyph row from the end, looking for the
24674 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
24675 COVER_STRING, or whose position is between START_CHARPOS
24679 && !INTEGERP (end
->object
)
24680 && !EQ (end
->object
, cover_string
)
24681 && !(BUFFERP (end
->object
)
24682 && (end
->charpos
>= start_charpos
24683 && end
->charpos
< end_charpos
));
24686 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24687 are present at buffer positions between START_CHARPOS and
24688 END_CHARPOS, or if they come from an overlay. */
24689 if (EQ (end
->object
, before_string
))
24691 pos
= string_buffer_position (before_string
, start_charpos
);
24692 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24695 else if (EQ (end
->object
, after_string
))
24697 pos
= string_buffer_position (after_string
, end_charpos
);
24698 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24702 /* Find the X coordinate of the last glyph to be highlighted. */
24703 for (; glyph
<= end
; ++glyph
)
24704 x
+= glyph
->pixel_width
;
24706 hlinfo
->mouse_face_end_x
= x
;
24707 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
24711 /* Skip truncation and continuation glyphs near the end of the
24712 row, and also blanks and stretch glyphs inserted by
24713 extend_face_to_end_of_line. */
24717 && INTEGERP (end
->object
)
24718 && end
->charpos
<= 0)
24720 x
+= end
->pixel_width
;
24723 /* Scan the rest of the glyph row from the end, looking for the
24724 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
24725 COVER_STRING, or whose position is between START_CHARPOS
24729 && !INTEGERP (end
->object
)
24730 && !EQ (end
->object
, cover_string
)
24731 && !(BUFFERP (end
->object
)
24732 && (end
->charpos
>= start_charpos
24733 && end
->charpos
< end_charpos
));
24736 /* BEFORE_STRING or AFTER_STRING are only relevant if they
24737 are present at buffer positions between START_CHARPOS and
24738 END_CHARPOS, or if they come from an overlay. */
24739 if (EQ (end
->object
, before_string
))
24741 pos
= string_buffer_position (before_string
, start_charpos
);
24742 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24745 else if (EQ (end
->object
, after_string
))
24747 pos
= string_buffer_position (after_string
, end_charpos
);
24748 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
24751 x
+= end
->pixel_width
;
24753 hlinfo
->mouse_face_end_x
= x
;
24754 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
24757 hlinfo
->mouse_face_window
= window
;
24758 hlinfo
->mouse_face_face_id
24759 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
24761 !hlinfo
->mouse_face_hidden
, -1);
24762 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
24765 /* The following function is not used anymore (replaced with
24766 mouse_face_from_string_pos), but I leave it here for the time
24767 being, in case someone would. */
24769 #if 0 /* not used */
24771 /* Find the position of the glyph for position POS in OBJECT in
24772 window W's current matrix, and return in *X, *Y the pixel
24773 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
24775 RIGHT_P non-zero means return the position of the right edge of the
24776 glyph, RIGHT_P zero means return the left edge position.
24778 If no glyph for POS exists in the matrix, return the position of
24779 the glyph with the next smaller position that is in the matrix, if
24780 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
24781 exists in the matrix, return the position of the glyph with the
24782 next larger position in OBJECT.
24784 Value is non-zero if a glyph was found. */
24787 fast_find_string_pos (struct window
*w
, EMACS_INT pos
, Lisp_Object object
,
24788 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
24790 int yb
= window_text_bottom_y (w
);
24791 struct glyph_row
*r
;
24792 struct glyph
*best_glyph
= NULL
;
24793 struct glyph_row
*best_row
= NULL
;
24796 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24797 r
->enabled_p
&& r
->y
< yb
;
24800 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
24801 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
24804 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
24805 if (EQ (g
->object
, object
))
24807 if (g
->charpos
== pos
)
24814 else if (best_glyph
== NULL
24815 || ((eabs (g
->charpos
- pos
)
24816 < eabs (best_glyph
->charpos
- pos
))
24819 : g
->charpos
> pos
)))
24833 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
24837 *x
+= best_glyph
->pixel_width
;
24842 *vpos
= best_row
- w
->current_matrix
->rows
;
24845 return best_glyph
!= NULL
;
24847 #endif /* not used */
24849 /* Find the positions of the first and the last glyphs in window W's
24850 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
24851 (assumed to be a string), and return in HLINFO's mouse_face_*
24852 members the pixel and column/row coordinates of those glyphs. */
24855 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
24856 Lisp_Object object
,
24857 EMACS_INT startpos
, EMACS_INT endpos
)
24859 int yb
= window_text_bottom_y (w
);
24860 struct glyph_row
*r
;
24861 struct glyph
*g
, *e
;
24865 /* Find the glyph row with at least one position in the range
24866 [STARTPOS..ENDPOS], and the first glyph in that row whose
24867 position belongs to that range. */
24868 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
24869 r
->enabled_p
&& r
->y
< yb
;
24872 if (!r
->reversed_p
)
24874 g
= r
->glyphs
[TEXT_AREA
];
24875 e
= g
+ r
->used
[TEXT_AREA
];
24876 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
24877 if (EQ (g
->object
, object
)
24878 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
24880 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
24881 hlinfo
->mouse_face_beg_y
= r
->y
;
24882 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
24883 hlinfo
->mouse_face_beg_x
= gx
;
24892 e
= r
->glyphs
[TEXT_AREA
];
24893 g
= e
+ r
->used
[TEXT_AREA
];
24894 for ( ; g
> e
; --g
)
24895 if (EQ ((g
-1)->object
, object
)
24896 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
24898 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
24899 hlinfo
->mouse_face_beg_y
= r
->y
;
24900 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
24901 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
24902 gx
+= g1
->pixel_width
;
24903 hlinfo
->mouse_face_beg_x
= gx
;
24915 /* Starting with the next row, look for the first row which does NOT
24916 include any glyphs whose positions are in the range. */
24917 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
24919 g
= r
->glyphs
[TEXT_AREA
];
24920 e
= g
+ r
->used
[TEXT_AREA
];
24922 for ( ; g
< e
; ++g
)
24923 if (EQ (g
->object
, object
)
24924 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
24933 /* The highlighted region ends on the previous row. */
24936 /* Set the end row and its vertical pixel coordinate. */
24937 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
24938 hlinfo
->mouse_face_end_y
= r
->y
;
24940 /* Compute and set the end column and the end column's horizontal
24941 pixel coordinate. */
24942 if (!r
->reversed_p
)
24944 g
= r
->glyphs
[TEXT_AREA
];
24945 e
= g
+ r
->used
[TEXT_AREA
];
24946 for ( ; e
> g
; --e
)
24947 if (EQ ((e
-1)->object
, object
)
24948 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
24950 hlinfo
->mouse_face_end_col
= e
- g
;
24952 for (gx
= r
->x
; g
< e
; ++g
)
24953 gx
+= g
->pixel_width
;
24954 hlinfo
->mouse_face_end_x
= gx
;
24958 e
= r
->glyphs
[TEXT_AREA
];
24959 g
= e
+ r
->used
[TEXT_AREA
];
24960 for (gx
= r
->x
; e
< g
; ++e
)
24962 if (EQ (e
->object
, object
)
24963 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
24965 gx
+= e
->pixel_width
;
24967 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
24968 hlinfo
->mouse_face_end_x
= gx
;
24972 #ifdef HAVE_WINDOW_SYSTEM
24974 /* See if position X, Y is within a hot-spot of an image. */
24977 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
24979 if (!CONSP (hot_spot
))
24982 if (EQ (XCAR (hot_spot
), Qrect
))
24984 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
24985 Lisp_Object rect
= XCDR (hot_spot
);
24989 if (!CONSP (XCAR (rect
)))
24991 if (!CONSP (XCDR (rect
)))
24993 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
24995 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
24997 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
24999 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
25003 else if (EQ (XCAR (hot_spot
), Qcircle
))
25005 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
25006 Lisp_Object circ
= XCDR (hot_spot
);
25007 Lisp_Object lr
, lx0
, ly0
;
25009 && CONSP (XCAR (circ
))
25010 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
25011 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
25012 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
25014 double r
= XFLOATINT (lr
);
25015 double dx
= XINT (lx0
) - x
;
25016 double dy
= XINT (ly0
) - y
;
25017 return (dx
* dx
+ dy
* dy
<= r
* r
);
25020 else if (EQ (XCAR (hot_spot
), Qpoly
))
25022 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
25023 if (VECTORP (XCDR (hot_spot
)))
25025 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
25026 Lisp_Object
*poly
= v
->contents
;
25027 int n
= v
->header
.size
;
25030 Lisp_Object lx
, ly
;
25033 /* Need an even number of coordinates, and at least 3 edges. */
25034 if (n
< 6 || n
& 1)
25037 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
25038 If count is odd, we are inside polygon. Pixels on edges
25039 may or may not be included depending on actual geometry of the
25041 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
25042 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
25044 x0
= XINT (lx
), y0
= XINT (ly
);
25045 for (i
= 0; i
< n
; i
+= 2)
25047 int x1
= x0
, y1
= y0
;
25048 if ((lx
= poly
[i
], !INTEGERP (lx
))
25049 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
25051 x0
= XINT (lx
), y0
= XINT (ly
);
25053 /* Does this segment cross the X line? */
25061 if (y
> y0
&& y
> y1
)
25063 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
25073 find_hot_spot (Lisp_Object map
, int x
, int y
)
25075 while (CONSP (map
))
25077 if (CONSP (XCAR (map
))
25078 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
25086 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
25088 doc
: /* Lookup in image map MAP coordinates X and Y.
25089 An image map is an alist where each element has the format (AREA ID PLIST).
25090 An AREA is specified as either a rectangle, a circle, or a polygon:
25091 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
25092 pixel coordinates of the upper left and bottom right corners.
25093 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
25094 and the radius of the circle; r may be a float or integer.
25095 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
25096 vector describes one corner in the polygon.
25097 Returns the alist element for the first matching AREA in MAP. */)
25098 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
25106 return find_hot_spot (map
, XINT (x
), XINT (y
));
25110 /* Display frame CURSOR, optionally using shape defined by POINTER. */
25112 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
25114 /* Do not change cursor shape while dragging mouse. */
25115 if (!NILP (do_mouse_tracking
))
25118 if (!NILP (pointer
))
25120 if (EQ (pointer
, Qarrow
))
25121 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25122 else if (EQ (pointer
, Qhand
))
25123 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
25124 else if (EQ (pointer
, Qtext
))
25125 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25126 else if (EQ (pointer
, intern ("hdrag")))
25127 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25128 #ifdef HAVE_X_WINDOWS
25129 else if (EQ (pointer
, intern ("vdrag")))
25130 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
25132 else if (EQ (pointer
, intern ("hourglass")))
25133 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
25134 else if (EQ (pointer
, Qmodeline
))
25135 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
25137 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25140 if (cursor
!= No_Cursor
)
25141 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
25144 #endif /* HAVE_WINDOW_SYSTEM */
25146 /* Take proper action when mouse has moved to the mode or header line
25147 or marginal area AREA of window W, x-position X and y-position Y.
25148 X is relative to the start of the text display area of W, so the
25149 width of bitmap areas and scroll bars must be subtracted to get a
25150 position relative to the start of the mode line. */
25153 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
25154 enum window_part area
)
25156 struct window
*w
= XWINDOW (window
);
25157 struct frame
*f
= XFRAME (w
->frame
);
25158 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25159 #ifdef HAVE_WINDOW_SYSTEM
25160 Display_Info
*dpyinfo
;
25162 Cursor cursor
= No_Cursor
;
25163 Lisp_Object pointer
= Qnil
;
25164 int dx
, dy
, width
, height
;
25166 Lisp_Object string
, object
= Qnil
;
25167 Lisp_Object pos
, help
;
25169 Lisp_Object mouse_face
;
25170 int original_x_pixel
= x
;
25171 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
25172 struct glyph_row
*row
;
25174 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
25179 /* Kludge alert: mode_line_string takes X/Y in pixels, but
25180 returns them in row/column units! */
25181 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
25182 &object
, &dx
, &dy
, &width
, &height
);
25184 row
= (area
== ON_MODE_LINE
25185 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
25186 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
25188 /* Find the glyph under the mouse pointer. */
25189 if (row
->mode_line_p
&& row
->enabled_p
)
25191 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
25192 end
= glyph
+ row
->used
[TEXT_AREA
];
25194 for (x0
= original_x_pixel
;
25195 glyph
< end
&& x0
>= glyph
->pixel_width
;
25197 x0
-= glyph
->pixel_width
;
25205 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
25206 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
25207 returns them in row/column units! */
25208 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
25209 &object
, &dx
, &dy
, &width
, &height
);
25214 #ifdef HAVE_WINDOW_SYSTEM
25215 if (IMAGEP (object
))
25217 Lisp_Object image_map
, hotspot
;
25218 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
25220 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
25222 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25226 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
25227 If so, we could look for mouse-enter, mouse-leave
25228 properties in PLIST (and do something...). */
25229 hotspot
= XCDR (hotspot
);
25230 if (CONSP (hotspot
)
25231 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25233 pointer
= Fplist_get (plist
, Qpointer
);
25234 if (NILP (pointer
))
25236 help
= Fplist_get (plist
, Qhelp_echo
);
25239 help_echo_string
= help
;
25240 /* Is this correct? ++kfs */
25241 XSETWINDOW (help_echo_window
, w
);
25242 help_echo_object
= w
->buffer
;
25243 help_echo_pos
= charpos
;
25247 if (NILP (pointer
))
25248 pointer
= Fplist_get (XCDR (object
), QCpointer
);
25250 #endif /* HAVE_WINDOW_SYSTEM */
25252 if (STRINGP (string
))
25254 pos
= make_number (charpos
);
25255 /* If we're on a string with `help-echo' text property, arrange
25256 for the help to be displayed. This is done by setting the
25257 global variable help_echo_string to the help string. */
25260 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
25263 help_echo_string
= help
;
25264 XSETWINDOW (help_echo_window
, w
);
25265 help_echo_object
= string
;
25266 help_echo_pos
= charpos
;
25270 #ifdef HAVE_WINDOW_SYSTEM
25271 if (FRAME_WINDOW_P (f
))
25273 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25274 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25275 if (NILP (pointer
))
25276 pointer
= Fget_text_property (pos
, Qpointer
, string
);
25278 /* Change the mouse pointer according to what is under X/Y. */
25280 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
25283 map
= Fget_text_property (pos
, Qlocal_map
, string
);
25284 if (!KEYMAPP (map
))
25285 map
= Fget_text_property (pos
, Qkeymap
, string
);
25286 if (!KEYMAPP (map
))
25287 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
25292 /* Change the mouse face according to what is under X/Y. */
25293 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
25294 if (!NILP (mouse_face
)
25295 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25300 struct glyph
* tmp_glyph
;
25304 int total_pixel_width
;
25305 EMACS_INT begpos
, endpos
, ignore
;
25309 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
25310 Qmouse_face
, string
, Qnil
);
25316 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
25318 endpos
= SCHARS (string
);
25322 /* Calculate the glyph position GPOS of GLYPH in the
25323 displayed string, relative to the beginning of the
25324 highlighted part of the string.
25326 Note: GPOS is different from CHARPOS. CHARPOS is the
25327 position of GLYPH in the internal string object. A mode
25328 line string format has structures which are converted to
25329 a flattened string by the Emacs Lisp interpreter. The
25330 internal string is an element of those structures. The
25331 displayed string is the flattened string. */
25332 tmp_glyph
= row_start_glyph
;
25333 while (tmp_glyph
< glyph
25334 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25335 && begpos
<= tmp_glyph
->charpos
25336 && tmp_glyph
->charpos
< endpos
)))
25338 gpos
= glyph
- tmp_glyph
;
25340 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
25341 the highlighted part of the displayed string to which
25342 GLYPH belongs. Note: GSEQ_LENGTH is different from
25343 SCHARS (STRING), because the latter returns the length of
25344 the internal string. */
25345 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
25347 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
25348 && begpos
<= tmp_glyph
->charpos
25349 && tmp_glyph
->charpos
< endpos
));
25352 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
25354 /* Calculate the total pixel width of all the glyphs between
25355 the beginning of the highlighted area and GLYPH. */
25356 total_pixel_width
= 0;
25357 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
25358 total_pixel_width
+= tmp_glyph
->pixel_width
;
25360 /* Pre calculation of re-rendering position. Note: X is in
25361 column units here, after the call to mode_line_string or
25362 marginal_area_string. */
25364 vpos
= (area
== ON_MODE_LINE
25365 ? (w
->current_matrix
)->nrows
- 1
25368 /* If GLYPH's position is included in the region that is
25369 already drawn in mouse face, we have nothing to do. */
25370 if ( EQ (window
, hlinfo
->mouse_face_window
)
25371 && (!row
->reversed_p
25372 ? (hlinfo
->mouse_face_beg_col
<= hpos
25373 && hpos
< hlinfo
->mouse_face_end_col
)
25374 /* In R2L rows we swap BEG and END, see below. */
25375 : (hlinfo
->mouse_face_end_col
<= hpos
25376 && hpos
< hlinfo
->mouse_face_beg_col
))
25377 && hlinfo
->mouse_face_beg_row
== vpos
)
25380 if (clear_mouse_face (hlinfo
))
25381 cursor
= No_Cursor
;
25383 if (!row
->reversed_p
)
25385 hlinfo
->mouse_face_beg_col
= hpos
;
25386 hlinfo
->mouse_face_beg_x
= original_x_pixel
25387 - (total_pixel_width
+ dx
);
25388 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
25389 hlinfo
->mouse_face_end_x
= 0;
25393 /* In R2L rows, show_mouse_face expects BEG and END
25394 coordinates to be swapped. */
25395 hlinfo
->mouse_face_end_col
= hpos
;
25396 hlinfo
->mouse_face_end_x
= original_x_pixel
25397 - (total_pixel_width
+ dx
);
25398 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
25399 hlinfo
->mouse_face_beg_x
= 0;
25402 hlinfo
->mouse_face_beg_row
= vpos
;
25403 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
25404 hlinfo
->mouse_face_beg_y
= 0;
25405 hlinfo
->mouse_face_end_y
= 0;
25406 hlinfo
->mouse_face_past_end
= 0;
25407 hlinfo
->mouse_face_window
= window
;
25409 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
25415 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25417 if (NILP (pointer
))
25420 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
25421 clear_mouse_face (hlinfo
);
25423 #ifdef HAVE_WINDOW_SYSTEM
25424 if (FRAME_WINDOW_P (f
))
25425 define_frame_cursor1 (f
, cursor
, pointer
);
25431 Take proper action when the mouse has moved to position X, Y on
25432 frame F as regards highlighting characters that have mouse-face
25433 properties. Also de-highlighting chars where the mouse was before.
25434 X and Y can be negative or out of range. */
25437 note_mouse_highlight (struct frame
*f
, int x
, int y
)
25439 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25440 enum window_part part
;
25441 Lisp_Object window
;
25443 Cursor cursor
= No_Cursor
;
25444 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
25447 /* When a menu is active, don't highlight because this looks odd. */
25448 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
25449 if (popup_activated ())
25453 if (NILP (Vmouse_highlight
)
25454 || !f
->glyphs_initialized_p
25455 || f
->pointer_invisible
)
25458 hlinfo
->mouse_face_mouse_x
= x
;
25459 hlinfo
->mouse_face_mouse_y
= y
;
25460 hlinfo
->mouse_face_mouse_frame
= f
;
25462 if (hlinfo
->mouse_face_defer
)
25465 if (gc_in_progress
)
25467 hlinfo
->mouse_face_deferred_gc
= 1;
25471 /* Which window is that in? */
25472 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
25474 /* If we were displaying active text in another window, clear that.
25475 Also clear if we move out of text area in same window. */
25476 if (! EQ (window
, hlinfo
->mouse_face_window
)
25477 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
25478 && !NILP (hlinfo
->mouse_face_window
)))
25479 clear_mouse_face (hlinfo
);
25481 /* Not on a window -> return. */
25482 if (!WINDOWP (window
))
25485 /* Reset help_echo_string. It will get recomputed below. */
25486 help_echo_string
= Qnil
;
25488 /* Convert to window-relative pixel coordinates. */
25489 w
= XWINDOW (window
);
25490 frame_to_window_pixel_xy (w
, &x
, &y
);
25492 #ifdef HAVE_WINDOW_SYSTEM
25493 /* Handle tool-bar window differently since it doesn't display a
25495 if (EQ (window
, f
->tool_bar_window
))
25497 note_tool_bar_highlight (f
, x
, y
);
25502 /* Mouse is on the mode, header line or margin? */
25503 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
25504 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
25506 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
25510 #ifdef HAVE_WINDOW_SYSTEM
25511 if (part
== ON_VERTICAL_BORDER
)
25513 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
25514 help_echo_string
= build_string ("drag-mouse-1: resize");
25516 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
25517 || part
== ON_SCROLL_BAR
)
25518 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25520 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
25523 /* Are we in a window whose display is up to date?
25524 And verify the buffer's text has not changed. */
25525 b
= XBUFFER (w
->buffer
);
25526 if (part
== ON_TEXT
25527 && EQ (w
->window_end_valid
, w
->buffer
)
25528 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
25529 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
25531 int hpos
, vpos
, i
, dx
, dy
, area
;
25533 struct glyph
*glyph
;
25534 Lisp_Object object
;
25535 Lisp_Object mouse_face
= Qnil
, position
;
25536 Lisp_Object
*overlay_vec
= NULL
;
25538 struct buffer
*obuf
;
25539 EMACS_INT obegv
, ozv
;
25542 /* Find the glyph under X/Y. */
25543 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
25545 #ifdef HAVE_WINDOW_SYSTEM
25546 /* Look for :pointer property on image. */
25547 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25549 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25550 if (img
!= NULL
&& IMAGEP (img
->spec
))
25552 Lisp_Object image_map
, hotspot
;
25553 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
25555 && (hotspot
= find_hot_spot (image_map
,
25556 glyph
->slice
.img
.x
+ dx
,
25557 glyph
->slice
.img
.y
+ dy
),
25559 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
25563 /* Could check XCAR (hotspot) to see if we enter/leave
25565 If so, we could look for mouse-enter, mouse-leave
25566 properties in PLIST (and do something...). */
25567 hotspot
= XCDR (hotspot
);
25568 if (CONSP (hotspot
)
25569 && (plist
= XCAR (hotspot
), CONSP (plist
)))
25571 pointer
= Fplist_get (plist
, Qpointer
);
25572 if (NILP (pointer
))
25574 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
25575 if (!NILP (help_echo_string
))
25577 help_echo_window
= window
;
25578 help_echo_object
= glyph
->object
;
25579 help_echo_pos
= glyph
->charpos
;
25583 if (NILP (pointer
))
25584 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
25587 #endif /* HAVE_WINDOW_SYSTEM */
25589 /* Clear mouse face if X/Y not over text. */
25591 || area
!= TEXT_AREA
25592 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
25593 /* Glyph's OBJECT is an integer for glyphs inserted by the
25594 display engine for its internal purposes, like truncation
25595 and continuation glyphs and blanks beyond the end of
25596 line's text on text terminals. If we are over such a
25597 glyph, we are not over any text. */
25598 || INTEGERP (glyph
->object
)
25599 /* R2L rows have a stretch glyph at their front, which
25600 stands for no text, whereas L2R rows have no glyphs at
25601 all beyond the end of text. Treat such stretch glyphs
25602 like we do with NULL glyphs in L2R rows. */
25603 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
25604 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
25605 && glyph
->type
== STRETCH_GLYPH
25606 && glyph
->avoid_cursor_p
))
25608 if (clear_mouse_face (hlinfo
))
25609 cursor
= No_Cursor
;
25610 #ifdef HAVE_WINDOW_SYSTEM
25611 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
25613 if (area
!= TEXT_AREA
)
25614 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
25616 pointer
= Vvoid_text_area_pointer
;
25622 pos
= glyph
->charpos
;
25623 object
= glyph
->object
;
25624 if (!STRINGP (object
) && !BUFFERP (object
))
25627 /* If we get an out-of-range value, return now; avoid an error. */
25628 if (BUFFERP (object
) && pos
> BUF_Z (b
))
25631 /* Make the window's buffer temporarily current for
25632 overlays_at and compute_char_face. */
25633 obuf
= current_buffer
;
25634 current_buffer
= b
;
25640 /* Is this char mouse-active or does it have help-echo? */
25641 position
= make_number (pos
);
25643 if (BUFFERP (object
))
25645 /* Put all the overlays we want in a vector in overlay_vec. */
25646 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
25647 /* Sort overlays into increasing priority order. */
25648 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
25653 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
25656 cursor
= No_Cursor
;
25658 /* Check mouse-face highlighting. */
25660 /* If there exists an overlay with mouse-face overlapping
25661 the one we are currently highlighting, we have to
25662 check if we enter the overlapping overlay, and then
25663 highlight only that. */
25664 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
25665 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
25667 /* Find the highest priority overlay with a mouse-face. */
25668 Lisp_Object overlay
= Qnil
;
25669 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
25671 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
25672 if (!NILP (mouse_face
))
25673 overlay
= overlay_vec
[i
];
25676 /* If we're highlighting the same overlay as before, there's
25677 no need to do that again. */
25678 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
25679 goto check_help_echo
;
25680 hlinfo
->mouse_face_overlay
= overlay
;
25682 /* Clear the display of the old active region, if any. */
25683 if (clear_mouse_face (hlinfo
))
25684 cursor
= No_Cursor
;
25686 /* If no overlay applies, get a text property. */
25687 if (NILP (overlay
))
25688 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
25690 /* Next, compute the bounds of the mouse highlighting and
25692 if (!NILP (mouse_face
) && STRINGP (object
))
25694 /* The mouse-highlighting comes from a display string
25695 with a mouse-face. */
25699 s
= Fprevious_single_property_change
25700 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
25701 e
= Fnext_single_property_change
25702 (position
, Qmouse_face
, object
, Qnil
);
25704 s
= make_number (0);
25706 e
= make_number (SCHARS (object
) - 1);
25707 mouse_face_from_string_pos (w
, hlinfo
, object
,
25708 XINT (s
), XINT (e
));
25709 hlinfo
->mouse_face_past_end
= 0;
25710 hlinfo
->mouse_face_window
= window
;
25711 hlinfo
->mouse_face_face_id
25712 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
25713 glyph
->face_id
, 1);
25714 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
25715 cursor
= No_Cursor
;
25719 /* The mouse-highlighting, if any, comes from an overlay
25720 or text property in the buffer. */
25721 Lisp_Object buffer
IF_LINT (= Qnil
);
25722 Lisp_Object cover_string
IF_LINT (= Qnil
);
25724 if (STRINGP (object
))
25726 /* If we are on a display string with no mouse-face,
25727 check if the text under it has one. */
25728 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
25729 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25730 pos
= string_buffer_position (object
, start
);
25733 mouse_face
= get_char_property_and_overlay
25734 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
25735 buffer
= w
->buffer
;
25736 cover_string
= object
;
25742 cover_string
= Qnil
;
25745 if (!NILP (mouse_face
))
25747 Lisp_Object before
, after
;
25748 Lisp_Object before_string
, after_string
;
25749 /* To correctly find the limits of mouse highlight
25750 in a bidi-reordered buffer, we must not use the
25751 optimization of limiting the search in
25752 previous-single-property-change and
25753 next-single-property-change, because
25754 rows_from_pos_range needs the real start and end
25755 positions to DTRT in this case. That's because
25756 the first row visible in a window does not
25757 necessarily display the character whose position
25758 is the smallest. */
25760 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
25761 ? Fmarker_position (w
->start
)
25764 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
25765 ? make_number (BUF_Z (XBUFFER (buffer
))
25766 - XFASTINT (w
->window_end_pos
))
25769 if (NILP (overlay
))
25771 /* Handle the text property case. */
25772 before
= Fprevious_single_property_change
25773 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
25774 after
= Fnext_single_property_change
25775 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
25776 before_string
= after_string
= Qnil
;
25780 /* Handle the overlay case. */
25781 before
= Foverlay_start (overlay
);
25782 after
= Foverlay_end (overlay
);
25783 before_string
= Foverlay_get (overlay
, Qbefore_string
);
25784 after_string
= Foverlay_get (overlay
, Qafter_string
);
25786 if (!STRINGP (before_string
)) before_string
= Qnil
;
25787 if (!STRINGP (after_string
)) after_string
= Qnil
;
25790 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
25793 before_string
, after_string
,
25795 cursor
= No_Cursor
;
25802 /* Look for a `help-echo' property. */
25803 if (NILP (help_echo_string
)) {
25804 Lisp_Object help
, overlay
;
25806 /* Check overlays first. */
25807 help
= overlay
= Qnil
;
25808 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
25810 overlay
= overlay_vec
[i
];
25811 help
= Foverlay_get (overlay
, Qhelp_echo
);
25816 help_echo_string
= help
;
25817 help_echo_window
= window
;
25818 help_echo_object
= overlay
;
25819 help_echo_pos
= pos
;
25823 Lisp_Object obj
= glyph
->object
;
25824 EMACS_INT charpos
= glyph
->charpos
;
25826 /* Try text properties. */
25829 && charpos
< SCHARS (obj
))
25831 help
= Fget_text_property (make_number (charpos
),
25835 /* If the string itself doesn't specify a help-echo,
25836 see if the buffer text ``under'' it does. */
25837 struct glyph_row
*r
25838 = MATRIX_ROW (w
->current_matrix
, vpos
);
25839 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25840 EMACS_INT p
= string_buffer_position (obj
, start
);
25843 help
= Fget_char_property (make_number (p
),
25844 Qhelp_echo
, w
->buffer
);
25853 else if (BUFFERP (obj
)
25856 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
25861 help_echo_string
= help
;
25862 help_echo_window
= window
;
25863 help_echo_object
= obj
;
25864 help_echo_pos
= charpos
;
25869 #ifdef HAVE_WINDOW_SYSTEM
25870 /* Look for a `pointer' property. */
25871 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
25873 /* Check overlays first. */
25874 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
25875 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
25877 if (NILP (pointer
))
25879 Lisp_Object obj
= glyph
->object
;
25880 EMACS_INT charpos
= glyph
->charpos
;
25882 /* Try text properties. */
25885 && charpos
< SCHARS (obj
))
25887 pointer
= Fget_text_property (make_number (charpos
),
25889 if (NILP (pointer
))
25891 /* If the string itself doesn't specify a pointer,
25892 see if the buffer text ``under'' it does. */
25893 struct glyph_row
*r
25894 = MATRIX_ROW (w
->current_matrix
, vpos
);
25895 EMACS_INT start
= MATRIX_ROW_START_CHARPOS (r
);
25896 EMACS_INT p
= string_buffer_position (obj
, start
);
25898 pointer
= Fget_char_property (make_number (p
),
25899 Qpointer
, w
->buffer
);
25902 else if (BUFFERP (obj
)
25905 pointer
= Fget_text_property (make_number (charpos
),
25909 #endif /* HAVE_WINDOW_SYSTEM */
25913 current_buffer
= obuf
;
25918 #ifdef HAVE_WINDOW_SYSTEM
25919 if (FRAME_WINDOW_P (f
))
25920 define_frame_cursor1 (f
, cursor
, pointer
);
25922 /* This is here to prevent a compiler error, about "label at end of
25923 compound statement". */
25930 Clear any mouse-face on window W. This function is part of the
25931 redisplay interface, and is called from try_window_id and similar
25932 functions to ensure the mouse-highlight is off. */
25935 x_clear_window_mouse_face (struct window
*w
)
25937 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
25938 Lisp_Object window
;
25941 XSETWINDOW (window
, w
);
25942 if (EQ (window
, hlinfo
->mouse_face_window
))
25943 clear_mouse_face (hlinfo
);
25949 Just discard the mouse face information for frame F, if any.
25950 This is used when the size of F is changed. */
25953 cancel_mouse_face (struct frame
*f
)
25955 Lisp_Object window
;
25956 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25958 window
= hlinfo
->mouse_face_window
;
25959 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
25961 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
25962 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
25963 hlinfo
->mouse_face_window
= Qnil
;
25969 /***********************************************************************
25971 ***********************************************************************/
25973 #ifdef HAVE_WINDOW_SYSTEM
25975 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
25976 which intersects rectangle R. R is in window-relative coordinates. */
25979 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
25980 enum glyph_row_area area
)
25982 struct glyph
*first
= row
->glyphs
[area
];
25983 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
25984 struct glyph
*last
;
25985 int first_x
, start_x
, x
;
25987 if (area
== TEXT_AREA
&& row
->fill_line_p
)
25988 /* If row extends face to end of line write the whole line. */
25989 draw_glyphs (w
, 0, row
, area
,
25990 0, row
->used
[area
],
25991 DRAW_NORMAL_TEXT
, 0);
25994 /* Set START_X to the window-relative start position for drawing glyphs of
25995 AREA. The first glyph of the text area can be partially visible.
25996 The first glyphs of other areas cannot. */
25997 start_x
= window_box_left_offset (w
, area
);
25999 if (area
== TEXT_AREA
)
26002 /* Find the first glyph that must be redrawn. */
26004 && x
+ first
->pixel_width
< r
->x
)
26006 x
+= first
->pixel_width
;
26010 /* Find the last one. */
26014 && x
< r
->x
+ r
->width
)
26016 x
+= last
->pixel_width
;
26022 draw_glyphs (w
, first_x
- start_x
, row
, area
,
26023 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
26024 DRAW_NORMAL_TEXT
, 0);
26029 /* Redraw the parts of the glyph row ROW on window W intersecting
26030 rectangle R. R is in window-relative coordinates. Value is
26031 non-zero if mouse-face was overwritten. */
26034 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
26036 xassert (row
->enabled_p
);
26038 if (row
->mode_line_p
|| w
->pseudo_window_p
)
26039 draw_glyphs (w
, 0, row
, TEXT_AREA
,
26040 0, row
->used
[TEXT_AREA
],
26041 DRAW_NORMAL_TEXT
, 0);
26044 if (row
->used
[LEFT_MARGIN_AREA
])
26045 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
26046 if (row
->used
[TEXT_AREA
])
26047 expose_area (w
, row
, r
, TEXT_AREA
);
26048 if (row
->used
[RIGHT_MARGIN_AREA
])
26049 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
26050 draw_row_fringe_bitmaps (w
, row
);
26053 return row
->mouse_face_p
;
26057 /* Redraw those parts of glyphs rows during expose event handling that
26058 overlap other rows. Redrawing of an exposed line writes over parts
26059 of lines overlapping that exposed line; this function fixes that.
26061 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
26062 row in W's current matrix that is exposed and overlaps other rows.
26063 LAST_OVERLAPPING_ROW is the last such row. */
26066 expose_overlaps (struct window
*w
,
26067 struct glyph_row
*first_overlapping_row
,
26068 struct glyph_row
*last_overlapping_row
,
26071 struct glyph_row
*row
;
26073 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
26074 if (row
->overlapping_p
)
26076 xassert (row
->enabled_p
&& !row
->mode_line_p
);
26079 if (row
->used
[LEFT_MARGIN_AREA
])
26080 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
26082 if (row
->used
[TEXT_AREA
])
26083 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
26085 if (row
->used
[RIGHT_MARGIN_AREA
])
26086 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
26092 /* Return non-zero if W's cursor intersects rectangle R. */
26095 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
26097 XRectangle cr
, result
;
26098 struct glyph
*cursor_glyph
;
26099 struct glyph_row
*row
;
26101 if (w
->phys_cursor
.vpos
>= 0
26102 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
26103 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
26105 && row
->cursor_in_fringe_p
)
26107 /* Cursor is in the fringe. */
26108 cr
.x
= window_box_right_offset (w
,
26109 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
26110 ? RIGHT_MARGIN_AREA
26113 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
26114 cr
.height
= row
->height
;
26115 return x_intersect_rectangles (&cr
, r
, &result
);
26118 cursor_glyph
= get_phys_cursor_glyph (w
);
26121 /* r is relative to W's box, but w->phys_cursor.x is relative
26122 to left edge of W's TEXT area. Adjust it. */
26123 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
26124 cr
.y
= w
->phys_cursor
.y
;
26125 cr
.width
= cursor_glyph
->pixel_width
;
26126 cr
.height
= w
->phys_cursor_height
;
26127 /* ++KFS: W32 version used W32-specific IntersectRect here, but
26128 I assume the effect is the same -- and this is portable. */
26129 return x_intersect_rectangles (&cr
, r
, &result
);
26131 /* If we don't understand the format, pretend we're not in the hot-spot. */
26137 Draw a vertical window border to the right of window W if W doesn't
26138 have vertical scroll bars. */
26141 x_draw_vertical_border (struct window
*w
)
26143 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26145 /* We could do better, if we knew what type of scroll-bar the adjacent
26146 windows (on either side) have... But we don't :-(
26147 However, I think this works ok. ++KFS 2003-04-25 */
26149 /* Redraw borders between horizontally adjacent windows. Don't
26150 do it for frames with vertical scroll bars because either the
26151 right scroll bar of a window, or the left scroll bar of its
26152 neighbor will suffice as a border. */
26153 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
26156 if (!WINDOW_RIGHTMOST_P (w
)
26157 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
26159 int x0
, x1
, y0
, y1
;
26161 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26164 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26167 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
26169 else if (!WINDOW_LEFTMOST_P (w
)
26170 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
26172 int x0
, x1
, y0
, y1
;
26174 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
26177 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
26180 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
26185 /* Redraw the part of window W intersection rectangle FR. Pixel
26186 coordinates in FR are frame-relative. Call this function with
26187 input blocked. Value is non-zero if the exposure overwrites
26191 expose_window (struct window
*w
, XRectangle
*fr
)
26193 struct frame
*f
= XFRAME (w
->frame
);
26195 int mouse_face_overwritten_p
= 0;
26197 /* If window is not yet fully initialized, do nothing. This can
26198 happen when toolkit scroll bars are used and a window is split.
26199 Reconfiguring the scroll bar will generate an expose for a newly
26201 if (w
->current_matrix
== NULL
)
26204 /* When we're currently updating the window, display and current
26205 matrix usually don't agree. Arrange for a thorough display
26207 if (w
== updated_window
)
26209 SET_FRAME_GARBAGED (f
);
26213 /* Frame-relative pixel rectangle of W. */
26214 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
26215 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
26216 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
26217 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
26219 if (x_intersect_rectangles (fr
, &wr
, &r
))
26221 int yb
= window_text_bottom_y (w
);
26222 struct glyph_row
*row
;
26223 int cursor_cleared_p
;
26224 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
26226 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
26227 r
.x
, r
.y
, r
.width
, r
.height
));
26229 /* Convert to window coordinates. */
26230 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
26231 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
26233 /* Turn off the cursor. */
26234 if (!w
->pseudo_window_p
26235 && phys_cursor_in_rect_p (w
, &r
))
26237 x_clear_cursor (w
);
26238 cursor_cleared_p
= 1;
26241 cursor_cleared_p
= 0;
26243 /* Update lines intersecting rectangle R. */
26244 first_overlapping_row
= last_overlapping_row
= NULL
;
26245 for (row
= w
->current_matrix
->rows
;
26250 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
26252 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
26253 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
26254 || (r
.y
>= y0
&& r
.y
< y1
)
26255 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
26257 /* A header line may be overlapping, but there is no need
26258 to fix overlapping areas for them. KFS 2005-02-12 */
26259 if (row
->overlapping_p
&& !row
->mode_line_p
)
26261 if (first_overlapping_row
== NULL
)
26262 first_overlapping_row
= row
;
26263 last_overlapping_row
= row
;
26267 if (expose_line (w
, row
, &r
))
26268 mouse_face_overwritten_p
= 1;
26271 else if (row
->overlapping_p
)
26273 /* We must redraw a row overlapping the exposed area. */
26275 ? y0
+ row
->phys_height
> r
.y
26276 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
26278 if (first_overlapping_row
== NULL
)
26279 first_overlapping_row
= row
;
26280 last_overlapping_row
= row
;
26288 /* Display the mode line if there is one. */
26289 if (WINDOW_WANTS_MODELINE_P (w
)
26290 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
26292 && row
->y
< r
.y
+ r
.height
)
26294 if (expose_line (w
, row
, &r
))
26295 mouse_face_overwritten_p
= 1;
26298 if (!w
->pseudo_window_p
)
26300 /* Fix the display of overlapping rows. */
26301 if (first_overlapping_row
)
26302 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
26305 /* Draw border between windows. */
26306 x_draw_vertical_border (w
);
26308 /* Turn the cursor on again. */
26309 if (cursor_cleared_p
)
26310 update_window_cursor (w
, 1);
26314 return mouse_face_overwritten_p
;
26319 /* Redraw (parts) of all windows in the window tree rooted at W that
26320 intersect R. R contains frame pixel coordinates. Value is
26321 non-zero if the exposure overwrites mouse-face. */
26324 expose_window_tree (struct window
*w
, XRectangle
*r
)
26326 struct frame
*f
= XFRAME (w
->frame
);
26327 int mouse_face_overwritten_p
= 0;
26329 while (w
&& !FRAME_GARBAGED_P (f
))
26331 if (!NILP (w
->hchild
))
26332 mouse_face_overwritten_p
26333 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
26334 else if (!NILP (w
->vchild
))
26335 mouse_face_overwritten_p
26336 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
26338 mouse_face_overwritten_p
|= expose_window (w
, r
);
26340 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
26343 return mouse_face_overwritten_p
;
26348 Redisplay an exposed area of frame F. X and Y are the upper-left
26349 corner of the exposed rectangle. W and H are width and height of
26350 the exposed area. All are pixel values. W or H zero means redraw
26351 the entire frame. */
26354 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
26357 int mouse_face_overwritten_p
= 0;
26359 TRACE ((stderr
, "expose_frame "));
26361 /* No need to redraw if frame will be redrawn soon. */
26362 if (FRAME_GARBAGED_P (f
))
26364 TRACE ((stderr
, " garbaged\n"));
26368 /* If basic faces haven't been realized yet, there is no point in
26369 trying to redraw anything. This can happen when we get an expose
26370 event while Emacs is starting, e.g. by moving another window. */
26371 if (FRAME_FACE_CACHE (f
) == NULL
26372 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
26374 TRACE ((stderr
, " no faces\n"));
26378 if (w
== 0 || h
== 0)
26381 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
26382 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
26392 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
26393 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
26395 if (WINDOWP (f
->tool_bar_window
))
26396 mouse_face_overwritten_p
26397 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
26399 #ifdef HAVE_X_WINDOWS
26401 #ifndef USE_X_TOOLKIT
26402 if (WINDOWP (f
->menu_bar_window
))
26403 mouse_face_overwritten_p
26404 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
26405 #endif /* not USE_X_TOOLKIT */
26409 /* Some window managers support a focus-follows-mouse style with
26410 delayed raising of frames. Imagine a partially obscured frame,
26411 and moving the mouse into partially obscured mouse-face on that
26412 frame. The visible part of the mouse-face will be highlighted,
26413 then the WM raises the obscured frame. With at least one WM, KDE
26414 2.1, Emacs is not getting any event for the raising of the frame
26415 (even tried with SubstructureRedirectMask), only Expose events.
26416 These expose events will draw text normally, i.e. not
26417 highlighted. Which means we must redo the highlight here.
26418 Subsume it under ``we love X''. --gerd 2001-08-15 */
26419 /* Included in Windows version because Windows most likely does not
26420 do the right thing if any third party tool offers
26421 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
26422 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
26424 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26425 if (f
== hlinfo
->mouse_face_mouse_frame
)
26427 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
26428 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
26429 clear_mouse_face (hlinfo
);
26430 note_mouse_highlight (f
, mouse_x
, mouse_y
);
26437 Determine the intersection of two rectangles R1 and R2. Return
26438 the intersection in *RESULT. Value is non-zero if RESULT is not
26442 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
26444 XRectangle
*left
, *right
;
26445 XRectangle
*upper
, *lower
;
26446 int intersection_p
= 0;
26448 /* Rearrange so that R1 is the left-most rectangle. */
26450 left
= r1
, right
= r2
;
26452 left
= r2
, right
= r1
;
26454 /* X0 of the intersection is right.x0, if this is inside R1,
26455 otherwise there is no intersection. */
26456 if (right
->x
<= left
->x
+ left
->width
)
26458 result
->x
= right
->x
;
26460 /* The right end of the intersection is the minimum of the
26461 the right ends of left and right. */
26462 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
26465 /* Same game for Y. */
26467 upper
= r1
, lower
= r2
;
26469 upper
= r2
, lower
= r1
;
26471 /* The upper end of the intersection is lower.y0, if this is inside
26472 of upper. Otherwise, there is no intersection. */
26473 if (lower
->y
<= upper
->y
+ upper
->height
)
26475 result
->y
= lower
->y
;
26477 /* The lower end of the intersection is the minimum of the lower
26478 ends of upper and lower. */
26479 result
->height
= (min (lower
->y
+ lower
->height
,
26480 upper
->y
+ upper
->height
)
26482 intersection_p
= 1;
26486 return intersection_p
;
26489 #endif /* HAVE_WINDOW_SYSTEM */
26492 /***********************************************************************
26494 ***********************************************************************/
26497 syms_of_xdisp (void)
26499 Vwith_echo_area_save_vector
= Qnil
;
26500 staticpro (&Vwith_echo_area_save_vector
);
26502 Vmessage_stack
= Qnil
;
26503 staticpro (&Vmessage_stack
);
26505 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
26506 staticpro (&Qinhibit_redisplay
);
26508 message_dolog_marker1
= Fmake_marker ();
26509 staticpro (&message_dolog_marker1
);
26510 message_dolog_marker2
= Fmake_marker ();
26511 staticpro (&message_dolog_marker2
);
26512 message_dolog_marker3
= Fmake_marker ();
26513 staticpro (&message_dolog_marker3
);
26516 defsubr (&Sdump_frame_glyph_matrix
);
26517 defsubr (&Sdump_glyph_matrix
);
26518 defsubr (&Sdump_glyph_row
);
26519 defsubr (&Sdump_tool_bar_row
);
26520 defsubr (&Strace_redisplay
);
26521 defsubr (&Strace_to_stderr
);
26523 #ifdef HAVE_WINDOW_SYSTEM
26524 defsubr (&Stool_bar_lines_needed
);
26525 defsubr (&Slookup_image_map
);
26527 defsubr (&Sformat_mode_line
);
26528 defsubr (&Sinvisible_p
);
26529 defsubr (&Scurrent_bidi_paragraph_direction
);
26531 staticpro (&Qmenu_bar_update_hook
);
26532 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
26534 staticpro (&Qoverriding_terminal_local_map
);
26535 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
26537 staticpro (&Qoverriding_local_map
);
26538 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
26540 staticpro (&Qwindow_scroll_functions
);
26541 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
26543 staticpro (&Qwindow_text_change_functions
);
26544 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
26546 staticpro (&Qredisplay_end_trigger_functions
);
26547 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
26549 staticpro (&Qinhibit_point_motion_hooks
);
26550 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
26552 Qeval
= intern_c_string ("eval");
26553 staticpro (&Qeval
);
26555 QCdata
= intern_c_string (":data");
26556 staticpro (&QCdata
);
26557 Qdisplay
= intern_c_string ("display");
26558 staticpro (&Qdisplay
);
26559 Qspace_width
= intern_c_string ("space-width");
26560 staticpro (&Qspace_width
);
26561 Qraise
= intern_c_string ("raise");
26562 staticpro (&Qraise
);
26563 Qslice
= intern_c_string ("slice");
26564 staticpro (&Qslice
);
26565 Qspace
= intern_c_string ("space");
26566 staticpro (&Qspace
);
26567 Qmargin
= intern_c_string ("margin");
26568 staticpro (&Qmargin
);
26569 Qpointer
= intern_c_string ("pointer");
26570 staticpro (&Qpointer
);
26571 Qleft_margin
= intern_c_string ("left-margin");
26572 staticpro (&Qleft_margin
);
26573 Qright_margin
= intern_c_string ("right-margin");
26574 staticpro (&Qright_margin
);
26575 Qcenter
= intern_c_string ("center");
26576 staticpro (&Qcenter
);
26577 Qline_height
= intern_c_string ("line-height");
26578 staticpro (&Qline_height
);
26579 QCalign_to
= intern_c_string (":align-to");
26580 staticpro (&QCalign_to
);
26581 QCrelative_width
= intern_c_string (":relative-width");
26582 staticpro (&QCrelative_width
);
26583 QCrelative_height
= intern_c_string (":relative-height");
26584 staticpro (&QCrelative_height
);
26585 QCeval
= intern_c_string (":eval");
26586 staticpro (&QCeval
);
26587 QCpropertize
= intern_c_string (":propertize");
26588 staticpro (&QCpropertize
);
26589 QCfile
= intern_c_string (":file");
26590 staticpro (&QCfile
);
26591 Qfontified
= intern_c_string ("fontified");
26592 staticpro (&Qfontified
);
26593 Qfontification_functions
= intern_c_string ("fontification-functions");
26594 staticpro (&Qfontification_functions
);
26595 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
26596 staticpro (&Qtrailing_whitespace
);
26597 Qescape_glyph
= intern_c_string ("escape-glyph");
26598 staticpro (&Qescape_glyph
);
26599 Qnobreak_space
= intern_c_string ("nobreak-space");
26600 staticpro (&Qnobreak_space
);
26601 Qimage
= intern_c_string ("image");
26602 staticpro (&Qimage
);
26603 Qtext
= intern_c_string ("text");
26604 staticpro (&Qtext
);
26605 Qboth
= intern_c_string ("both");
26606 staticpro (&Qboth
);
26607 Qboth_horiz
= intern_c_string ("both-horiz");
26608 staticpro (&Qboth_horiz
);
26609 Qtext_image_horiz
= intern_c_string ("text-image-horiz");
26610 staticpro (&Qtext_image_horiz
);
26611 QCmap
= intern_c_string (":map");
26612 staticpro (&QCmap
);
26613 QCpointer
= intern_c_string (":pointer");
26614 staticpro (&QCpointer
);
26615 Qrect
= intern_c_string ("rect");
26616 staticpro (&Qrect
);
26617 Qcircle
= intern_c_string ("circle");
26618 staticpro (&Qcircle
);
26619 Qpoly
= intern_c_string ("poly");
26620 staticpro (&Qpoly
);
26621 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
26622 staticpro (&Qmessage_truncate_lines
);
26623 Qgrow_only
= intern_c_string ("grow-only");
26624 staticpro (&Qgrow_only
);
26625 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
26626 staticpro (&Qinhibit_menubar_update
);
26627 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
26628 staticpro (&Qinhibit_eval_during_redisplay
);
26629 Qposition
= intern_c_string ("position");
26630 staticpro (&Qposition
);
26631 Qbuffer_position
= intern_c_string ("buffer-position");
26632 staticpro (&Qbuffer_position
);
26633 Qobject
= intern_c_string ("object");
26634 staticpro (&Qobject
);
26635 Qbar
= intern_c_string ("bar");
26637 Qhbar
= intern_c_string ("hbar");
26638 staticpro (&Qhbar
);
26639 Qbox
= intern_c_string ("box");
26641 Qhollow
= intern_c_string ("hollow");
26642 staticpro (&Qhollow
);
26643 Qhand
= intern_c_string ("hand");
26644 staticpro (&Qhand
);
26645 Qarrow
= intern_c_string ("arrow");
26646 staticpro (&Qarrow
);
26647 Qtext
= intern_c_string ("text");
26648 staticpro (&Qtext
);
26649 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
26650 staticpro (&Qinhibit_free_realized_faces
);
26652 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
26653 Fcons (intern_c_string ("void-variable"), Qnil
)),
26655 staticpro (&list_of_error
);
26657 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
26658 staticpro (&Qlast_arrow_position
);
26659 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
26660 staticpro (&Qlast_arrow_string
);
26662 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
26663 staticpro (&Qoverlay_arrow_string
);
26664 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
26665 staticpro (&Qoverlay_arrow_bitmap
);
26667 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
26668 staticpro (&echo_buffer
[0]);
26669 staticpro (&echo_buffer
[1]);
26671 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
26672 staticpro (&echo_area_buffer
[0]);
26673 staticpro (&echo_area_buffer
[1]);
26675 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
26676 staticpro (&Vmessages_buffer_name
);
26678 mode_line_proptrans_alist
= Qnil
;
26679 staticpro (&mode_line_proptrans_alist
);
26680 mode_line_string_list
= Qnil
;
26681 staticpro (&mode_line_string_list
);
26682 mode_line_string_face
= Qnil
;
26683 staticpro (&mode_line_string_face
);
26684 mode_line_string_face_prop
= Qnil
;
26685 staticpro (&mode_line_string_face_prop
);
26686 Vmode_line_unwind_vector
= Qnil
;
26687 staticpro (&Vmode_line_unwind_vector
);
26689 help_echo_string
= Qnil
;
26690 staticpro (&help_echo_string
);
26691 help_echo_object
= Qnil
;
26692 staticpro (&help_echo_object
);
26693 help_echo_window
= Qnil
;
26694 staticpro (&help_echo_window
);
26695 previous_help_echo_string
= Qnil
;
26696 staticpro (&previous_help_echo_string
);
26697 help_echo_pos
= -1;
26699 Qright_to_left
= intern_c_string ("right-to-left");
26700 staticpro (&Qright_to_left
);
26701 Qleft_to_right
= intern_c_string ("left-to-right");
26702 staticpro (&Qleft_to_right
);
26704 #ifdef HAVE_WINDOW_SYSTEM
26705 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
26706 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
26707 For example, if a block cursor is over a tab, it will be drawn as
26708 wide as that tab on the display. */);
26709 x_stretch_cursor_p
= 0;
26712 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
26713 doc
: /* *Non-nil means highlight trailing whitespace.
26714 The face used for trailing whitespace is `trailing-whitespace'. */);
26715 Vshow_trailing_whitespace
= Qnil
;
26717 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
26718 doc
: /* *Control highlighting of nobreak space and soft hyphen.
26719 A value of t means highlight the character itself (for nobreak space,
26720 use face `nobreak-space').
26721 A value of nil means no highlighting.
26722 Other values mean display the escape glyph followed by an ordinary
26723 space or ordinary hyphen. */);
26724 Vnobreak_char_display
= Qt
;
26726 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
26727 doc
: /* *The pointer shape to show in void text areas.
26728 A value of nil means to show the text pointer. Other options are `arrow',
26729 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
26730 Vvoid_text_area_pointer
= Qarrow
;
26732 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
26733 doc
: /* Non-nil means don't actually do any redisplay.
26734 This is used for internal purposes. */);
26735 Vinhibit_redisplay
= Qnil
;
26737 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
26738 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
26739 Vglobal_mode_string
= Qnil
;
26741 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
26742 doc
: /* Marker for where to display an arrow on top of the buffer text.
26743 This must be the beginning of a line in order to work.
26744 See also `overlay-arrow-string'. */);
26745 Voverlay_arrow_position
= Qnil
;
26747 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
26748 doc
: /* String to display as an arrow in non-window frames.
26749 See also `overlay-arrow-position'. */);
26750 Voverlay_arrow_string
= make_pure_c_string ("=>");
26752 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
26753 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
26754 The symbols on this list are examined during redisplay to determine
26755 where to display overlay arrows. */);
26756 Voverlay_arrow_variable_list
26757 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
26759 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
26760 doc
: /* *The number of lines to try scrolling a window by when point moves out.
26761 If that fails to bring point back on frame, point is centered instead.
26762 If this is zero, point is always centered after it moves off frame.
26763 If you want scrolling to always be a line at a time, you should set
26764 `scroll-conservatively' to a large value rather than set this to 1. */);
26766 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
26767 doc
: /* *Scroll up to this many lines, to bring point back on screen.
26768 If point moves off-screen, redisplay will scroll by up to
26769 `scroll-conservatively' lines in order to bring point just barely
26770 onto the screen again. If that cannot be done, then redisplay
26771 recenters point as usual.
26773 If the value is greater than 100, redisplay will never recenter point,
26774 but will always scroll just enough text to bring point into view, even
26775 if you move far away.
26777 A value of zero means always recenter point if it moves off screen. */);
26778 scroll_conservatively
= 0;
26780 DEFVAR_INT ("scroll-margin", scroll_margin
,
26781 doc
: /* *Number of lines of margin at the top and bottom of a window.
26782 Recenter the window whenever point gets within this many lines
26783 of the top or bottom of the window. */);
26786 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
26787 doc
: /* Pixels per inch value for non-window system displays.
26788 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
26789 Vdisplay_pixels_per_inch
= make_float (72.0);
26792 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
26795 DEFVAR_LISP ("truncate-partial-width-windows",
26796 Vtruncate_partial_width_windows
,
26797 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
26798 For an integer value, truncate lines in each window narrower than the
26799 full frame width, provided the window width is less than that integer;
26800 otherwise, respect the value of `truncate-lines'.
26802 For any other non-nil value, truncate lines in all windows that do
26803 not span the full frame width.
26805 A value of nil means to respect the value of `truncate-lines'.
26807 If `word-wrap' is enabled, you might want to reduce this. */);
26808 Vtruncate_partial_width_windows
= make_number (50);
26810 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
26811 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
26812 Any other value means to use the appropriate face, `mode-line',
26813 `header-line', or `menu' respectively. */);
26814 mode_line_inverse_video
= 1;
26816 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
26817 doc
: /* *Maximum buffer size for which line number should be displayed.
26818 If the buffer is bigger than this, the line number does not appear
26819 in the mode line. A value of nil means no limit. */);
26820 Vline_number_display_limit
= Qnil
;
26822 DEFVAR_INT ("line-number-display-limit-width",
26823 line_number_display_limit_width
,
26824 doc
: /* *Maximum line width (in characters) for line number display.
26825 If the average length of the lines near point is bigger than this, then the
26826 line number may be omitted from the mode line. */);
26827 line_number_display_limit_width
= 200;
26829 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
26830 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
26831 highlight_nonselected_windows
= 0;
26833 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
26834 doc
: /* Non-nil if more than one frame is visible on this display.
26835 Minibuffer-only frames don't count, but iconified frames do.
26836 This variable is not guaranteed to be accurate except while processing
26837 `frame-title-format' and `icon-title-format'. */);
26839 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
26840 doc
: /* Template for displaying the title bar of visible frames.
26841 \(Assuming the window manager supports this feature.)
26843 This variable has the same structure as `mode-line-format', except that
26844 the %c and %l constructs are ignored. It is used only on frames for
26845 which no explicit name has been set \(see `modify-frame-parameters'). */);
26847 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
26848 doc
: /* Template for displaying the title bar of an iconified frame.
26849 \(Assuming the window manager supports this feature.)
26850 This variable has the same structure as `mode-line-format' (which see),
26851 and is used only on frames for which no explicit name has been set
26852 \(see `modify-frame-parameters'). */);
26854 = Vframe_title_format
26855 = pure_cons (intern_c_string ("multiple-frames"),
26856 pure_cons (make_pure_c_string ("%b"),
26857 pure_cons (pure_cons (empty_unibyte_string
,
26858 pure_cons (intern_c_string ("invocation-name"),
26859 pure_cons (make_pure_c_string ("@"),
26860 pure_cons (intern_c_string ("system-name"),
26864 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
26865 doc
: /* Maximum number of lines to keep in the message log buffer.
26866 If nil, disable message logging. If t, log messages but don't truncate
26867 the buffer when it becomes large. */);
26868 Vmessage_log_max
= make_number (100);
26870 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
26871 doc
: /* Functions called before redisplay, if window sizes have changed.
26872 The value should be a list of functions that take one argument.
26873 Just before redisplay, for each frame, if any of its windows have changed
26874 size since the last redisplay, or have been split or deleted,
26875 all the functions in the list are called, with the frame as argument. */);
26876 Vwindow_size_change_functions
= Qnil
;
26878 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
26879 doc
: /* List of functions to call before redisplaying a window with scrolling.
26880 Each function is called with two arguments, the window and its new
26881 display-start position. Note that these functions are also called by
26882 `set-window-buffer'. Also note that the value of `window-end' is not
26883 valid when these functions are called. */);
26884 Vwindow_scroll_functions
= Qnil
;
26886 DEFVAR_LISP ("window-text-change-functions",
26887 Vwindow_text_change_functions
,
26888 doc
: /* Functions to call in redisplay when text in the window might change. */);
26889 Vwindow_text_change_functions
= Qnil
;
26891 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
26892 doc
: /* Functions called when redisplay of a window reaches the end trigger.
26893 Each function is called with two arguments, the window and the end trigger value.
26894 See `set-window-redisplay-end-trigger'. */);
26895 Vredisplay_end_trigger_functions
= Qnil
;
26897 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
26898 doc
: /* *Non-nil means autoselect window with mouse pointer.
26899 If nil, do not autoselect windows.
26900 A positive number means delay autoselection by that many seconds: a
26901 window is autoselected only after the mouse has remained in that
26902 window for the duration of the delay.
26903 A negative number has a similar effect, but causes windows to be
26904 autoselected only after the mouse has stopped moving. \(Because of
26905 the way Emacs compares mouse events, you will occasionally wait twice
26906 that time before the window gets selected.\)
26907 Any other value means to autoselect window instantaneously when the
26908 mouse pointer enters it.
26910 Autoselection selects the minibuffer only if it is active, and never
26911 unselects the minibuffer if it is active.
26913 When customizing this variable make sure that the actual value of
26914 `focus-follows-mouse' matches the behavior of your window manager. */);
26915 Vmouse_autoselect_window
= Qnil
;
26917 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
26918 doc
: /* *Non-nil means automatically resize tool-bars.
26919 This dynamically changes the tool-bar's height to the minimum height
26920 that is needed to make all tool-bar items visible.
26921 If value is `grow-only', the tool-bar's height is only increased
26922 automatically; to decrease the tool-bar height, use \\[recenter]. */);
26923 Vauto_resize_tool_bars
= Qt
;
26925 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
26926 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
26927 auto_raise_tool_bar_buttons_p
= 1;
26929 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
26930 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
26931 make_cursor_line_fully_visible_p
= 1;
26933 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
26934 doc
: /* *Border below tool-bar in pixels.
26935 If an integer, use it as the height of the border.
26936 If it is one of `internal-border-width' or `border-width', use the
26937 value of the corresponding frame parameter.
26938 Otherwise, no border is added below the tool-bar. */);
26939 Vtool_bar_border
= Qinternal_border_width
;
26941 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
26942 doc
: /* *Margin around tool-bar buttons in pixels.
26943 If an integer, use that for both horizontal and vertical margins.
26944 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
26945 HORZ specifying the horizontal margin, and VERT specifying the
26946 vertical margin. */);
26947 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
26949 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
26950 doc
: /* *Relief thickness of tool-bar buttons. */);
26951 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
26953 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
26954 doc
: /* Tool bar style to use.
26956 image - show images only
26957 text - show text only
26958 both - show both, text below image
26959 both-horiz - show text to the right of the image
26960 text-image-horiz - show text to the left of the image
26961 any other - use system default or image if no system default. */);
26962 Vtool_bar_style
= Qnil
;
26964 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
26965 doc
: /* *Maximum number of characters a label can have to be shown.
26966 The tool bar style must also show labels for this to have any effect, see
26967 `tool-bar-style'. */);
26968 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
26970 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
26971 doc
: /* List of functions to call to fontify regions of text.
26972 Each function is called with one argument POS. Functions must
26973 fontify a region starting at POS in the current buffer, and give
26974 fontified regions the property `fontified'. */);
26975 Vfontification_functions
= Qnil
;
26976 Fmake_variable_buffer_local (Qfontification_functions
);
26978 DEFVAR_BOOL ("unibyte-display-via-language-environment",
26979 unibyte_display_via_language_environment
,
26980 doc
: /* *Non-nil means display unibyte text according to language environment.
26981 Specifically, this means that raw bytes in the range 160-255 decimal
26982 are displayed by converting them to the equivalent multibyte characters
26983 according to the current language environment. As a result, they are
26984 displayed according to the current fontset.
26986 Note that this variable affects only how these bytes are displayed,
26987 but does not change the fact they are interpreted as raw bytes. */);
26988 unibyte_display_via_language_environment
= 0;
26990 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
26991 doc
: /* *Maximum height for resizing mini-windows.
26992 If a float, it specifies a fraction of the mini-window frame's height.
26993 If an integer, it specifies a number of lines. */);
26994 Vmax_mini_window_height
= make_float (0.25);
26996 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
26997 doc
: /* *How to resize mini-windows.
26998 A value of nil means don't automatically resize mini-windows.
26999 A value of t means resize them to fit the text displayed in them.
27000 A value of `grow-only', the default, means let mini-windows grow
27001 only, until their display becomes empty, at which point the windows
27002 go back to their normal size. */);
27003 Vresize_mini_windows
= Qgrow_only
;
27005 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
27006 doc
: /* Alist specifying how to blink the cursor off.
27007 Each element has the form (ON-STATE . OFF-STATE). Whenever the
27008 `cursor-type' frame-parameter or variable equals ON-STATE,
27009 comparing using `equal', Emacs uses OFF-STATE to specify
27010 how to blink it off. ON-STATE and OFF-STATE are values for
27011 the `cursor-type' frame parameter.
27013 If a frame's ON-STATE has no entry in this list,
27014 the frame's other specifications determine how to blink the cursor off. */);
27015 Vblink_cursor_alist
= Qnil
;
27017 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
27018 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
27019 If non-nil, windows are automatically scrolled horizontally to make
27020 point visible. */);
27021 automatic_hscrolling_p
= 1;
27022 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
27023 staticpro (&Qauto_hscroll_mode
);
27025 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
27026 doc
: /* *How many columns away from the window edge point is allowed to get
27027 before automatic hscrolling will horizontally scroll the window. */);
27028 hscroll_margin
= 5;
27030 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
27031 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
27032 When point is less than `hscroll-margin' columns from the window
27033 edge, automatic hscrolling will scroll the window by the amount of columns
27034 determined by this variable. If its value is a positive integer, scroll that
27035 many columns. If it's a positive floating-point number, it specifies the
27036 fraction of the window's width to scroll. If it's nil or zero, point will be
27037 centered horizontally after the scroll. Any other value, including negative
27038 numbers, are treated as if the value were zero.
27040 Automatic hscrolling always moves point outside the scroll margin, so if
27041 point was more than scroll step columns inside the margin, the window will
27042 scroll more than the value given by the scroll step.
27044 Note that the lower bound for automatic hscrolling specified by `scroll-left'
27045 and `scroll-right' overrides this variable's effect. */);
27046 Vhscroll_step
= make_number (0);
27048 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
27049 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
27050 Bind this around calls to `message' to let it take effect. */);
27051 message_truncate_lines
= 0;
27053 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
27054 doc
: /* Normal hook run to update the menu bar definitions.
27055 Redisplay runs this hook before it redisplays the menu bar.
27056 This is used to update submenus such as Buffers,
27057 whose contents depend on various data. */);
27058 Vmenu_bar_update_hook
= Qnil
;
27060 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
27061 doc
: /* Frame for which we are updating a menu.
27062 The enable predicate for a menu binding should check this variable. */);
27063 Vmenu_updating_frame
= Qnil
;
27065 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
27066 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
27067 inhibit_menubar_update
= 0;
27069 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
27070 doc
: /* Prefix prepended to all continuation lines at display time.
27071 The value may be a string, an image, or a stretch-glyph; it is
27072 interpreted in the same way as the value of a `display' text property.
27074 This variable is overridden by any `wrap-prefix' text or overlay
27077 To add a prefix to non-continuation lines, use `line-prefix'. */);
27078 Vwrap_prefix
= Qnil
;
27079 staticpro (&Qwrap_prefix
);
27080 Qwrap_prefix
= intern_c_string ("wrap-prefix");
27081 Fmake_variable_buffer_local (Qwrap_prefix
);
27083 DEFVAR_LISP ("line-prefix", Vline_prefix
,
27084 doc
: /* Prefix prepended to all non-continuation lines at display time.
27085 The value may be a string, an image, or a stretch-glyph; it is
27086 interpreted in the same way as the value of a `display' text property.
27088 This variable is overridden by any `line-prefix' text or overlay
27091 To add a prefix to continuation lines, use `wrap-prefix'. */);
27092 Vline_prefix
= Qnil
;
27093 staticpro (&Qline_prefix
);
27094 Qline_prefix
= intern_c_string ("line-prefix");
27095 Fmake_variable_buffer_local (Qline_prefix
);
27097 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
27098 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
27099 inhibit_eval_during_redisplay
= 0;
27101 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
27102 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
27103 inhibit_free_realized_faces
= 0;
27106 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
27107 doc
: /* Inhibit try_window_id display optimization. */);
27108 inhibit_try_window_id
= 0;
27110 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
27111 doc
: /* Inhibit try_window_reusing display optimization. */);
27112 inhibit_try_window_reusing
= 0;
27114 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
27115 doc
: /* Inhibit try_cursor_movement display optimization. */);
27116 inhibit_try_cursor_movement
= 0;
27117 #endif /* GLYPH_DEBUG */
27119 DEFVAR_INT ("overline-margin", overline_margin
,
27120 doc
: /* *Space between overline and text, in pixels.
27121 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
27122 margin to the caracter height. */);
27123 overline_margin
= 2;
27125 DEFVAR_INT ("underline-minimum-offset",
27126 underline_minimum_offset
,
27127 doc
: /* Minimum distance between baseline and underline.
27128 This can improve legibility of underlined text at small font sizes,
27129 particularly when using variable `x-use-underline-position-properties'
27130 with fonts that specify an UNDERLINE_POSITION relatively close to the
27131 baseline. The default value is 1. */);
27132 underline_minimum_offset
= 1;
27134 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
27135 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
27136 This feature only works when on a window system that can change
27137 cursor shapes. */);
27138 display_hourglass_p
= 1;
27140 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
27141 doc
: /* *Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
27142 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
27144 hourglass_atimer
= NULL
;
27145 hourglass_shown_p
= 0;
27147 DEFSYM (Qglyphless_char
, "glyphless-char");
27148 DEFSYM (Qhex_code
, "hex-code");
27149 DEFSYM (Qempty_box
, "empty-box");
27150 DEFSYM (Qthin_space
, "thin-space");
27151 DEFSYM (Qzero_width
, "zero-width");
27153 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
27154 /* Intern this now in case it isn't already done.
27155 Setting this variable twice is harmless.
27156 But don't staticpro it here--that is done in alloc.c. */
27157 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
27158 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
27160 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
27161 doc
: /* Char-table defining glyphless characters.
27162 Each element, if non-nil, should be one of the following:
27163 an ASCII acronym string: display this string in a box
27164 `hex-code': display the hexadecimal code of a character in a box
27165 `empty-box': display as an empty box
27166 `thin-space': display as 1-pixel width space
27167 `zero-width': don't display
27168 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
27169 display method for graphical terminals and text terminals respectively.
27170 GRAPHICAL and TEXT should each have one of the values listed above.
27172 The char-table has one extra slot to control the display of a character for
27173 which no font is found. This slot only takes effect on graphical terminals.
27174 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
27175 `thin-space'. The default is `empty-box'. */);
27176 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
27177 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
27182 /* Initialize this module when Emacs starts. */
27187 Lisp_Object root_window
;
27188 struct window
*mini_w
;
27190 current_header_line_height
= current_mode_line_height
= -1;
27192 CHARPOS (this_line_start_pos
) = 0;
27194 mini_w
= XWINDOW (minibuf_window
);
27195 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
27196 echo_area_window
= minibuf_window
;
27198 if (!noninteractive
)
27200 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
27203 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
27204 set_window_height (root_window
,
27205 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
27207 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
27208 set_window_height (minibuf_window
, 1, 0);
27210 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
27211 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
27213 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
27214 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
27215 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
27217 /* The default ellipsis glyphs `...'. */
27218 for (i
= 0; i
< 3; ++i
)
27219 default_invis_vector
[i
] = make_number ('.');
27223 /* Allocate the buffer for frame titles.
27224 Also used for `format-mode-line'. */
27226 mode_line_noprop_buf
= (char *) xmalloc (size
);
27227 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
27228 mode_line_noprop_ptr
= mode_line_noprop_buf
;
27229 mode_line_target
= MODE_LINE_DISPLAY
;
27232 help_echo_showing_p
= 0;
27235 /* Since w32 does not support atimers, it defines its own implementation of
27236 the following three functions in w32fns.c. */
27239 /* Platform-independent portion of hourglass implementation. */
27241 /* Return non-zero if houglass timer has been started or hourglass is shown. */
27243 hourglass_started (void)
27245 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
27248 /* Cancel a currently active hourglass timer, and start a new one. */
27250 start_hourglass (void)
27252 #if defined (HAVE_WINDOW_SYSTEM)
27254 int secs
, usecs
= 0;
27256 cancel_hourglass ();
27258 if (INTEGERP (Vhourglass_delay
)
27259 && XINT (Vhourglass_delay
) > 0)
27260 secs
= XFASTINT (Vhourglass_delay
);
27261 else if (FLOATP (Vhourglass_delay
)
27262 && XFLOAT_DATA (Vhourglass_delay
) > 0)
27265 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
27266 secs
= XFASTINT (tem
);
27267 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
27270 secs
= DEFAULT_HOURGLASS_DELAY
;
27272 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
27273 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
27274 show_hourglass
, NULL
);
27279 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
27282 cancel_hourglass (void)
27284 #if defined (HAVE_WINDOW_SYSTEM)
27285 if (hourglass_atimer
)
27287 cancel_atimer (hourglass_atimer
);
27288 hourglass_atimer
= NULL
;
27291 if (hourglass_shown_p
)
27295 #endif /* ! WINDOWSNT */