1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
27 Emacs separates the task of updating the display from code
28 modifying global state, e.g. buffer text. This way functions
29 operating on buffers don't also have to be concerned with updating
32 Updating the display is triggered by the Lisp interpreter when it
33 decides it's time to do it. This is done either automatically for
34 you as part of the interpreter's command loop or as the result of
35 calling Lisp functions like `sit-for'. The C function `redisplay'
36 in xdisp.c is the only entry into the inner redisplay code. (Or,
37 let's say almost---see the description of direct update
40 The following diagram shows how redisplay code is invoked. As you
41 can see, Lisp calls redisplay and vice versa. Under window systems
42 like X, some portions of the redisplay code are also called
43 asynchronously during mouse movement or expose events. It is very
44 important that these code parts do NOT use the C library (malloc,
45 free) because many C libraries under Unix are not reentrant. They
46 may also NOT call functions of the Lisp interpreter which could
47 change the interpreter's state. If you don't follow these rules,
48 you will encounter bugs which are very hard to explain.
50 (Direct functions, see below)
51 direct_output_for_insert,
52 direct_forward_char (dispnew.c)
53 +---------------------------------+
56 +--------------+ redisplay +----------------+
57 | Lisp machine |---------------->| Redisplay code |<--+
58 +--------------+ (xdisp.c) +----------------+ |
60 +----------------------------------+ |
61 Don't use this path when called |
64 expose_window (asynchronous) |
66 X expose events -----+
68 What does redisplay do? Obviously, it has to figure out somehow what
69 has been changed since the last time the display has been updated,
70 and to make these changes visible. Preferably it would do that in
71 a moderately intelligent way, i.e. fast.
73 Changes in buffer text can be deduced from window and buffer
74 structures, and from some global variables like `beg_unchanged' and
75 `end_unchanged'. The contents of the display are additionally
76 recorded in a `glyph matrix', a two-dimensional matrix of glyph
77 structures. Each row in such a matrix corresponds to a line on the
78 display, and each glyph in a row corresponds to a column displaying
79 a character, an image, or what else. This matrix is called the
80 `current glyph matrix' or `current matrix' in redisplay
83 For buffer parts that have been changed since the last update, a
84 second glyph matrix is constructed, the so called `desired glyph
85 matrix' or short `desired matrix'. Current and desired matrix are
86 then compared to find a cheap way to update the display, e.g. by
87 reusing part of the display by scrolling lines.
92 You will find a lot of redisplay optimizations when you start
93 looking at the innards of redisplay. The overall goal of all these
94 optimizations is to make redisplay fast because it is done
97 Two optimizations are not found in xdisp.c. These are the direct
98 operations mentioned above. As the name suggests they follow a
99 different principle than the rest of redisplay. Instead of
100 building a desired matrix and then comparing it with the current
101 display, they perform their actions directly on the display and on
104 One direct operation updates the display after one character has
105 been entered. The other one moves the cursor by one position
106 forward or backward. You find these functions under the names
107 `direct_output_for_insert' and `direct_output_forward_char' in
113 Desired matrices are always built per Emacs window. The function
114 `display_line' is the central function to look at if you are
115 interested. It constructs one row in a desired matrix given an
116 iterator structure containing both a buffer position and a
117 description of the environment in which the text is to be
118 displayed. But this is too early, read on.
120 Characters and pixmaps displayed for a range of buffer text depend
121 on various settings of buffers and windows, on overlays and text
122 properties, on display tables, on selective display. The good news
123 is that all this hairy stuff is hidden behind a small set of
124 interface functions taking an iterator structure (struct it)
127 Iteration over things to be displayed is then simple. It is
128 started by initializing an iterator with a call to init_iterator.
129 Calls to get_next_display_element fill the iterator structure with
130 relevant information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
174 #include "keyboard.h"
177 #include "termchar.h"
178 #include "dispextern.h"
182 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
190 #include "region-cache.h"
192 #include "blockinput.h"
194 #ifdef HAVE_X_WINDOWS
204 #ifndef FRAME_X_OUTPUT
205 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
208 #define INFINITY 10000000
210 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
212 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
213 extern int pending_menu_activation
;
216 extern int interrupt_input
;
217 extern int command_loop_level
;
219 extern Lisp_Object do_mouse_tracking
;
221 extern int minibuffer_auto_raise
;
222 extern Lisp_Object Vminibuffer_list
;
224 extern Lisp_Object Qface
;
225 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
227 extern Lisp_Object Voverriding_local_map
;
228 extern Lisp_Object Voverriding_local_map_menu_flag
;
229 extern Lisp_Object Qmenu_item
;
230 extern Lisp_Object Qwhen
;
231 extern Lisp_Object Qhelp_echo
;
233 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
234 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
235 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
236 Lisp_Object Qinhibit_point_motion_hooks
;
237 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
238 Lisp_Object Qfontified
;
239 Lisp_Object Qgrow_only
;
240 Lisp_Object Qinhibit_eval_during_redisplay
;
241 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
244 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
247 Lisp_Object Qarrow
, Qhand
, Qtext
;
249 Lisp_Object Qrisky_local_variable
;
251 /* Holds the list (error). */
252 Lisp_Object list_of_error
;
254 /* Functions called to fontify regions of text. */
256 Lisp_Object Vfontification_functions
;
257 Lisp_Object Qfontification_functions
;
259 /* Non-zero means automatically select any window when the mouse
260 cursor moves into it. */
261 int mouse_autoselect_window
;
263 /* Non-zero means draw tool bar buttons raised when the mouse moves
266 int auto_raise_tool_bar_buttons_p
;
268 /* Non-zero means to reposition window if cursor line is only partially visible. */
270 int make_cursor_line_fully_visible_p
;
272 /* Margin around tool bar buttons in pixels. */
274 Lisp_Object Vtool_bar_button_margin
;
276 /* Thickness of shadow to draw around tool bar buttons. */
278 EMACS_INT tool_bar_button_relief
;
280 /* Non-zero means automatically resize tool-bars so that all tool-bar
281 items are visible, and no blank lines remain. */
283 int auto_resize_tool_bars_p
;
285 /* Non-zero means draw block and hollow cursor as wide as the glyph
286 under it. For example, if a block cursor is over a tab, it will be
287 drawn as wide as that tab on the display. */
289 int x_stretch_cursor_p
;
291 /* Non-nil means don't actually do any redisplay. */
293 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
295 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
297 int inhibit_eval_during_redisplay
;
299 /* Names of text properties relevant for redisplay. */
301 Lisp_Object Qdisplay
;
302 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
304 /* Symbols used in text property values. */
306 Lisp_Object Vdisplay_pixels_per_inch
;
307 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
308 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
311 Lisp_Object Qmargin
, Qpointer
;
312 Lisp_Object Qline_height
;
313 extern Lisp_Object Qheight
;
314 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
315 extern Lisp_Object Qscroll_bar
;
316 extern Lisp_Object Qcursor
;
318 /* Non-nil means highlight trailing whitespace. */
320 Lisp_Object Vshow_trailing_whitespace
;
322 /* Non-nil means escape non-break space and hyphens. */
324 Lisp_Object Vnobreak_char_display
;
326 #ifdef HAVE_WINDOW_SYSTEM
327 extern Lisp_Object Voverflow_newline_into_fringe
;
329 /* Test if overflow newline into fringe. Called with iterator IT
330 at or past right window margin, and with IT->current_x set. */
332 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
333 (!NILP (Voverflow_newline_into_fringe) \
334 && FRAME_WINDOW_P (it->f) \
335 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
336 && it->current_x == it->last_visible_x)
338 #endif /* HAVE_WINDOW_SYSTEM */
340 /* Non-nil means show the text cursor in void text areas
341 i.e. in blank areas after eol and eob. This used to be
342 the default in 21.3. */
344 Lisp_Object Vvoid_text_area_pointer
;
346 /* Name of the face used to highlight trailing whitespace. */
348 Lisp_Object Qtrailing_whitespace
;
350 /* Name and number of the face used to highlight escape glyphs. */
352 Lisp_Object Qescape_glyph
;
354 /* Name and number of the face used to highlight non-breaking spaces. */
356 Lisp_Object Qnobreak_space
;
358 /* The symbol `image' which is the car of the lists used to represent
363 /* The image map types. */
364 Lisp_Object QCmap
, QCpointer
;
365 Lisp_Object Qrect
, Qcircle
, Qpoly
;
367 /* Non-zero means print newline to stdout before next mini-buffer
370 int noninteractive_need_newline
;
372 /* Non-zero means print newline to message log before next message. */
374 static int message_log_need_newline
;
376 /* Three markers that message_dolog uses.
377 It could allocate them itself, but that causes trouble
378 in handling memory-full errors. */
379 static Lisp_Object message_dolog_marker1
;
380 static Lisp_Object message_dolog_marker2
;
381 static Lisp_Object message_dolog_marker3
;
383 /* The buffer position of the first character appearing entirely or
384 partially on the line of the selected window which contains the
385 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
386 redisplay optimization in redisplay_internal. */
388 static struct text_pos this_line_start_pos
;
390 /* Number of characters past the end of the line above, including the
391 terminating newline. */
393 static struct text_pos this_line_end_pos
;
395 /* The vertical positions and the height of this line. */
397 static int this_line_vpos
;
398 static int this_line_y
;
399 static int this_line_pixel_height
;
401 /* X position at which this display line starts. Usually zero;
402 negative if first character is partially visible. */
404 static int this_line_start_x
;
406 /* Buffer that this_line_.* variables are referring to. */
408 static struct buffer
*this_line_buffer
;
410 /* Nonzero means truncate lines in all windows less wide than the
413 int truncate_partial_width_windows
;
415 /* A flag to control how to display unibyte 8-bit character. */
417 int unibyte_display_via_language_environment
;
419 /* Nonzero means we have more than one non-mini-buffer-only frame.
420 Not guaranteed to be accurate except while parsing
421 frame-title-format. */
425 Lisp_Object Vglobal_mode_string
;
428 /* List of variables (symbols) which hold markers for overlay arrows.
429 The symbols on this list are examined during redisplay to determine
430 where to display overlay arrows. */
432 Lisp_Object Voverlay_arrow_variable_list
;
434 /* Marker for where to display an arrow on top of the buffer text. */
436 Lisp_Object Voverlay_arrow_position
;
438 /* String to display for the arrow. Only used on terminal frames. */
440 Lisp_Object Voverlay_arrow_string
;
442 /* Values of those variables at last redisplay are stored as
443 properties on `overlay-arrow-position' symbol. However, if
444 Voverlay_arrow_position is a marker, last-arrow-position is its
445 numerical position. */
447 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
449 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
450 properties on a symbol in overlay-arrow-variable-list. */
452 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
454 /* Like mode-line-format, but for the title bar on a visible frame. */
456 Lisp_Object Vframe_title_format
;
458 /* Like mode-line-format, but for the title bar on an iconified frame. */
460 Lisp_Object Vicon_title_format
;
462 /* List of functions to call when a window's size changes. These
463 functions get one arg, a frame on which one or more windows' sizes
466 static Lisp_Object Vwindow_size_change_functions
;
468 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
470 /* Nonzero if an overlay arrow has been displayed in this window. */
472 static int overlay_arrow_seen
;
474 /* Nonzero means highlight the region even in nonselected windows. */
476 int highlight_nonselected_windows
;
478 /* If cursor motion alone moves point off frame, try scrolling this
479 many lines up or down if that will bring it back. */
481 static EMACS_INT scroll_step
;
483 /* Nonzero means scroll just far enough to bring point back on the
484 screen, when appropriate. */
486 static EMACS_INT scroll_conservatively
;
488 /* Recenter the window whenever point gets within this many lines of
489 the top or bottom of the window. This value is translated into a
490 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
491 that there is really a fixed pixel height scroll margin. */
493 EMACS_INT scroll_margin
;
495 /* Number of windows showing the buffer of the selected window (or
496 another buffer with the same base buffer). keyboard.c refers to
501 /* Vector containing glyphs for an ellipsis `...'. */
503 static Lisp_Object default_invis_vector
[3];
505 /* Zero means display the mode-line/header-line/menu-bar in the default face
506 (this slightly odd definition is for compatibility with previous versions
507 of emacs), non-zero means display them using their respective faces.
509 This variable is deprecated. */
511 int mode_line_inverse_video
;
513 /* Prompt to display in front of the mini-buffer contents. */
515 Lisp_Object minibuf_prompt
;
517 /* Width of current mini-buffer prompt. Only set after display_line
518 of the line that contains the prompt. */
520 int minibuf_prompt_width
;
522 /* This is the window where the echo area message was displayed. It
523 is always a mini-buffer window, but it may not be the same window
524 currently active as a mini-buffer. */
526 Lisp_Object echo_area_window
;
528 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
529 pushes the current message and the value of
530 message_enable_multibyte on the stack, the function restore_message
531 pops the stack and displays MESSAGE again. */
533 Lisp_Object Vmessage_stack
;
535 /* Nonzero means multibyte characters were enabled when the echo area
536 message was specified. */
538 int message_enable_multibyte
;
540 /* Nonzero if we should redraw the mode lines on the next redisplay. */
542 int update_mode_lines
;
544 /* Nonzero if window sizes or contents have changed since last
545 redisplay that finished. */
547 int windows_or_buffers_changed
;
549 /* Nonzero means a frame's cursor type has been changed. */
551 int cursor_type_changed
;
553 /* Nonzero after display_mode_line if %l was used and it displayed a
556 int line_number_displayed
;
558 /* Maximum buffer size for which to display line numbers. */
560 Lisp_Object Vline_number_display_limit
;
562 /* Line width to consider when repositioning for line number display. */
564 static EMACS_INT line_number_display_limit_width
;
566 /* Number of lines to keep in the message log buffer. t means
567 infinite. nil means don't log at all. */
569 Lisp_Object Vmessage_log_max
;
571 /* The name of the *Messages* buffer, a string. */
573 static Lisp_Object Vmessages_buffer_name
;
575 /* Current, index 0, and last displayed echo area message. Either
576 buffers from echo_buffers, or nil to indicate no message. */
578 Lisp_Object echo_area_buffer
[2];
580 /* The buffers referenced from echo_area_buffer. */
582 static Lisp_Object echo_buffer
[2];
584 /* A vector saved used in with_area_buffer to reduce consing. */
586 static Lisp_Object Vwith_echo_area_save_vector
;
588 /* Non-zero means display_echo_area should display the last echo area
589 message again. Set by redisplay_preserve_echo_area. */
591 static int display_last_displayed_message_p
;
593 /* Nonzero if echo area is being used by print; zero if being used by
596 int message_buf_print
;
598 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
600 Lisp_Object Qinhibit_menubar_update
;
601 int inhibit_menubar_update
;
603 /* Maximum height for resizing mini-windows. Either a float
604 specifying a fraction of the available height, or an integer
605 specifying a number of lines. */
607 Lisp_Object Vmax_mini_window_height
;
609 /* Non-zero means messages should be displayed with truncated
610 lines instead of being continued. */
612 int message_truncate_lines
;
613 Lisp_Object Qmessage_truncate_lines
;
615 /* Set to 1 in clear_message to make redisplay_internal aware
616 of an emptied echo area. */
618 static int message_cleared_p
;
620 /* How to blink the default frame cursor off. */
621 Lisp_Object Vblink_cursor_alist
;
623 /* A scratch glyph row with contents used for generating truncation
624 glyphs. Also used in direct_output_for_insert. */
626 #define MAX_SCRATCH_GLYPHS 100
627 struct glyph_row scratch_glyph_row
;
628 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
630 /* Ascent and height of the last line processed by move_it_to. */
632 static int last_max_ascent
, last_height
;
634 /* Non-zero if there's a help-echo in the echo area. */
636 int help_echo_showing_p
;
638 /* If >= 0, computed, exact values of mode-line and header-line height
639 to use in the macros CURRENT_MODE_LINE_HEIGHT and
640 CURRENT_HEADER_LINE_HEIGHT. */
642 int current_mode_line_height
, current_header_line_height
;
644 /* The maximum distance to look ahead for text properties. Values
645 that are too small let us call compute_char_face and similar
646 functions too often which is expensive. Values that are too large
647 let us call compute_char_face and alike too often because we
648 might not be interested in text properties that far away. */
650 #define TEXT_PROP_DISTANCE_LIMIT 100
654 /* Variables to turn off display optimizations from Lisp. */
656 int inhibit_try_window_id
, inhibit_try_window_reusing
;
657 int inhibit_try_cursor_movement
;
659 /* Non-zero means print traces of redisplay if compiled with
662 int trace_redisplay_p
;
664 #endif /* GLYPH_DEBUG */
666 #ifdef DEBUG_TRACE_MOVE
667 /* Non-zero means trace with TRACE_MOVE to stderr. */
670 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
672 #define TRACE_MOVE(x) (void) 0
675 /* Non-zero means automatically scroll windows horizontally to make
678 int automatic_hscrolling_p
;
680 /* How close to the margin can point get before the window is scrolled
682 EMACS_INT hscroll_margin
;
684 /* How much to scroll horizontally when point is inside the above margin. */
685 Lisp_Object Vhscroll_step
;
687 /* The variable `resize-mini-windows'. If nil, don't resize
688 mini-windows. If t, always resize them to fit the text they
689 display. If `grow-only', let mini-windows grow only until they
692 Lisp_Object Vresize_mini_windows
;
694 /* Buffer being redisplayed -- for redisplay_window_error. */
696 struct buffer
*displayed_buffer
;
698 /* Value returned from text property handlers (see below). */
703 HANDLED_RECOMPUTE_PROPS
,
704 HANDLED_OVERLAY_STRING_CONSUMED
,
708 /* A description of text properties that redisplay is interested
713 /* The name of the property. */
716 /* A unique index for the property. */
719 /* A handler function called to set up iterator IT from the property
720 at IT's current position. Value is used to steer handle_stop. */
721 enum prop_handled (*handler
) P_ ((struct it
*it
));
724 static enum prop_handled handle_face_prop
P_ ((struct it
*));
725 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
726 static enum prop_handled handle_display_prop
P_ ((struct it
*));
727 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
728 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
729 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
731 /* Properties handled by iterators. */
733 static struct props it_props
[] =
735 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
736 /* Handle `face' before `display' because some sub-properties of
737 `display' need to know the face. */
738 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
739 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
740 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
741 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
745 /* Value is the position described by X. If X is a marker, value is
746 the marker_position of X. Otherwise, value is X. */
748 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
750 /* Enumeration returned by some move_it_.* functions internally. */
754 /* Not used. Undefined value. */
757 /* Move ended at the requested buffer position or ZV. */
758 MOVE_POS_MATCH_OR_ZV
,
760 /* Move ended at the requested X pixel position. */
763 /* Move within a line ended at the end of a line that must be
767 /* Move within a line ended at the end of a line that would
768 be displayed truncated. */
771 /* Move within a line ended at a line end. */
775 /* This counter is used to clear the face cache every once in a while
776 in redisplay_internal. It is incremented for each redisplay.
777 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
780 #define CLEAR_FACE_CACHE_COUNT 500
781 static int clear_face_cache_count
;
783 /* Similarly for the image cache. */
785 #ifdef HAVE_WINDOW_SYSTEM
786 #define CLEAR_IMAGE_CACHE_COUNT 101
787 static int clear_image_cache_count
;
790 /* Non-zero while redisplay_internal is in progress. */
794 /* Non-zero means don't free realized faces. Bound while freeing
795 realized faces is dangerous because glyph matrices might still
798 int inhibit_free_realized_faces
;
799 Lisp_Object Qinhibit_free_realized_faces
;
801 /* If a string, XTread_socket generates an event to display that string.
802 (The display is done in read_char.) */
804 Lisp_Object help_echo_string
;
805 Lisp_Object help_echo_window
;
806 Lisp_Object help_echo_object
;
809 /* Temporary variable for XTread_socket. */
811 Lisp_Object previous_help_echo_string
;
813 /* Null glyph slice */
815 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
818 /* Function prototypes. */
820 static void setup_for_ellipsis
P_ ((struct it
*, int));
821 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
822 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
823 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
824 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
825 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
826 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
829 static int invisible_text_between_p
P_ ((struct it
*, int, int));
832 static void pint2str
P_ ((char *, int, int));
833 static void pint2hrstr
P_ ((char *, int, int));
834 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
836 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
837 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
838 static void store_mode_line_noprop_char
P_ ((char));
839 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
840 static void x_consider_frame_title
P_ ((Lisp_Object
));
841 static void handle_stop
P_ ((struct it
*));
842 static int tool_bar_lines_needed
P_ ((struct frame
*));
843 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
844 static void ensure_echo_area_buffers
P_ ((void));
845 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
846 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
847 static int with_echo_area_buffer
P_ ((struct window
*, int,
848 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
849 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
850 static void clear_garbaged_frames
P_ ((void));
851 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
852 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
853 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
854 static int display_echo_area
P_ ((struct window
*));
855 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
856 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
857 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
858 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
859 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
861 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
862 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
863 static void insert_left_trunc_glyphs
P_ ((struct it
*));
864 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
866 static void extend_face_to_end_of_line
P_ ((struct it
*));
867 static int append_space_for_newline
P_ ((struct it
*, int));
868 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
869 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
870 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
871 static int trailing_whitespace_p
P_ ((int));
872 static int message_log_check_duplicate
P_ ((int, int, int, int));
873 static void push_it
P_ ((struct it
*));
874 static void pop_it
P_ ((struct it
*));
875 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
876 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
877 static void redisplay_internal
P_ ((int));
878 static int echo_area_display
P_ ((int));
879 static void redisplay_windows
P_ ((Lisp_Object
));
880 static void redisplay_window
P_ ((Lisp_Object
, int));
881 static Lisp_Object
redisplay_window_error ();
882 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
883 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
884 static void update_menu_bar
P_ ((struct frame
*, int));
885 static int try_window_reusing_current_matrix
P_ ((struct window
*));
886 static int try_window_id
P_ ((struct window
*));
887 static int display_line
P_ ((struct it
*));
888 static int display_mode_lines
P_ ((struct window
*));
889 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
890 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
891 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
892 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
893 static void display_menu_bar
P_ ((struct window
*));
894 static int display_count_lines
P_ ((int, int, int, int, int *));
895 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
896 int, int, struct it
*, int, int, int, int));
897 static void compute_line_metrics
P_ ((struct it
*));
898 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
899 static int get_overlay_strings
P_ ((struct it
*, int));
900 static void next_overlay_string
P_ ((struct it
*));
901 static void reseat
P_ ((struct it
*, struct text_pos
, int));
902 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
903 static void back_to_previous_visible_line_start
P_ ((struct it
*));
904 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
905 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
906 static int next_element_from_ellipsis
P_ ((struct it
*));
907 static int next_element_from_display_vector
P_ ((struct it
*));
908 static int next_element_from_string
P_ ((struct it
*));
909 static int next_element_from_c_string
P_ ((struct it
*));
910 static int next_element_from_buffer
P_ ((struct it
*));
911 static int next_element_from_composition
P_ ((struct it
*));
912 static int next_element_from_image
P_ ((struct it
*));
913 static int next_element_from_stretch
P_ ((struct it
*));
914 static void load_overlay_strings
P_ ((struct it
*, int));
915 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
916 struct display_pos
*));
917 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
918 Lisp_Object
, int, int, int, int));
919 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
921 void move_it_vertically_backward
P_ ((struct it
*, int));
922 static void init_to_row_start
P_ ((struct it
*, struct window
*,
923 struct glyph_row
*));
924 static int init_to_row_end
P_ ((struct it
*, struct window
*,
925 struct glyph_row
*));
926 static void back_to_previous_line_start
P_ ((struct it
*));
927 static int forward_to_next_line_start
P_ ((struct it
*, int *));
928 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
930 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
931 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
932 static int number_of_chars
P_ ((unsigned char *, int));
933 static void compute_stop_pos
P_ ((struct it
*));
934 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
936 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
937 static int next_overlay_change
P_ ((int));
938 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
939 Lisp_Object
, struct text_pos
*,
941 static int underlying_face_id
P_ ((struct it
*));
942 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
945 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
946 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
948 #ifdef HAVE_WINDOW_SYSTEM
950 static void update_tool_bar
P_ ((struct frame
*, int));
951 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
952 static int redisplay_tool_bar
P_ ((struct frame
*));
953 static void display_tool_bar_line
P_ ((struct it
*));
954 static void notice_overwritten_cursor
P_ ((struct window
*,
956 int, int, int, int));
960 #endif /* HAVE_WINDOW_SYSTEM */
963 /***********************************************************************
964 Window display dimensions
965 ***********************************************************************/
967 /* Return the bottom boundary y-position for text lines in window W.
968 This is the first y position at which a line cannot start.
969 It is relative to the top of the window.
971 This is the height of W minus the height of a mode line, if any. */
974 window_text_bottom_y (w
)
977 int height
= WINDOW_TOTAL_HEIGHT (w
);
979 if (WINDOW_WANTS_MODELINE_P (w
))
980 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
984 /* Return the pixel width of display area AREA of window W. AREA < 0
985 means return the total width of W, not including fringes to
986 the left and right of the window. */
989 window_box_width (w
, area
)
993 int cols
= XFASTINT (w
->total_cols
);
996 if (!w
->pseudo_window_p
)
998 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1000 if (area
== TEXT_AREA
)
1002 if (INTEGERP (w
->left_margin_cols
))
1003 cols
-= XFASTINT (w
->left_margin_cols
);
1004 if (INTEGERP (w
->right_margin_cols
))
1005 cols
-= XFASTINT (w
->right_margin_cols
);
1006 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1008 else if (area
== LEFT_MARGIN_AREA
)
1010 cols
= (INTEGERP (w
->left_margin_cols
)
1011 ? XFASTINT (w
->left_margin_cols
) : 0);
1014 else if (area
== RIGHT_MARGIN_AREA
)
1016 cols
= (INTEGERP (w
->right_margin_cols
)
1017 ? XFASTINT (w
->right_margin_cols
) : 0);
1022 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1026 /* Return the pixel height of the display area of window W, not
1027 including mode lines of W, if any. */
1030 window_box_height (w
)
1033 struct frame
*f
= XFRAME (w
->frame
);
1034 int height
= WINDOW_TOTAL_HEIGHT (w
);
1036 xassert (height
>= 0);
1038 /* Note: the code below that determines the mode-line/header-line
1039 height is essentially the same as that contained in the macro
1040 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1041 the appropriate glyph row has its `mode_line_p' flag set,
1042 and if it doesn't, uses estimate_mode_line_height instead. */
1044 if (WINDOW_WANTS_MODELINE_P (w
))
1046 struct glyph_row
*ml_row
1047 = (w
->current_matrix
&& w
->current_matrix
->rows
1048 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1050 if (ml_row
&& ml_row
->mode_line_p
)
1051 height
-= ml_row
->height
;
1053 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1056 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1058 struct glyph_row
*hl_row
1059 = (w
->current_matrix
&& w
->current_matrix
->rows
1060 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1062 if (hl_row
&& hl_row
->mode_line_p
)
1063 height
-= hl_row
->height
;
1065 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1068 /* With a very small font and a mode-line that's taller than
1069 default, we might end up with a negative height. */
1070 return max (0, height
);
1073 /* Return the window-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_offset (w
, area
)
1084 if (w
->pseudo_window_p
)
1087 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1089 if (area
== TEXT_AREA
)
1090 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1091 + window_box_width (w
, LEFT_MARGIN_AREA
));
1092 else if (area
== RIGHT_MARGIN_AREA
)
1093 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1094 + window_box_width (w
, LEFT_MARGIN_AREA
)
1095 + window_box_width (w
, TEXT_AREA
)
1096 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1098 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1099 else if (area
== LEFT_MARGIN_AREA
1100 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1101 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1107 /* Return the window-relative coordinate of the right edge of display
1108 area AREA of window W. AREA < 0 means return the left edge of the
1109 whole window, to the left of the right fringe of W. */
1112 window_box_right_offset (w
, area
)
1116 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1119 /* Return the frame-relative coordinate of the left edge of display
1120 area AREA of window W. AREA < 0 means return the left edge of the
1121 whole window, to the right of the left fringe of W. */
1124 window_box_left (w
, area
)
1128 struct frame
*f
= XFRAME (w
->frame
);
1131 if (w
->pseudo_window_p
)
1132 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1134 x
= (WINDOW_LEFT_EDGE_X (w
)
1135 + window_box_left_offset (w
, area
));
1141 /* Return the frame-relative coordinate of the right edge of display
1142 area AREA of window W. AREA < 0 means return the left edge of the
1143 whole window, to the left of the right fringe of W. */
1146 window_box_right (w
, area
)
1150 return window_box_left (w
, area
) + window_box_width (w
, area
);
1153 /* Get the bounding box of the display area AREA of window W, without
1154 mode lines, in frame-relative coordinates. AREA < 0 means the
1155 whole window, not including the left and right fringes of
1156 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1157 coordinates of the upper-left corner of the box. Return in
1158 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1161 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1164 int *box_x
, *box_y
, *box_width
, *box_height
;
1167 *box_width
= window_box_width (w
, area
);
1169 *box_height
= window_box_height (w
);
1171 *box_x
= window_box_left (w
, area
);
1174 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1175 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1176 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1181 /* Get the bounding box of the display area AREA of window W, without
1182 mode lines. AREA < 0 means the whole window, not including the
1183 left and right fringe of the window. Return in *TOP_LEFT_X
1184 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1185 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1186 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1190 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1191 bottom_right_x
, bottom_right_y
)
1194 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1196 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1198 *bottom_right_x
+= *top_left_x
;
1199 *bottom_right_y
+= *top_left_y
;
1204 /***********************************************************************
1206 ***********************************************************************/
1208 /* Return the bottom y-position of the line the iterator IT is in.
1209 This can modify IT's settings. */
1215 int line_height
= it
->max_ascent
+ it
->max_descent
;
1216 int line_top_y
= it
->current_y
;
1218 if (line_height
== 0)
1221 line_height
= last_height
;
1222 else if (IT_CHARPOS (*it
) < ZV
)
1224 move_it_by_lines (it
, 1, 1);
1225 line_height
= (it
->max_ascent
|| it
->max_descent
1226 ? it
->max_ascent
+ it
->max_descent
1231 struct glyph_row
*row
= it
->glyph_row
;
1233 /* Use the default character height. */
1234 it
->glyph_row
= NULL
;
1235 it
->what
= IT_CHARACTER
;
1238 PRODUCE_GLYPHS (it
);
1239 line_height
= it
->ascent
+ it
->descent
;
1240 it
->glyph_row
= row
;
1244 return line_top_y
+ line_height
;
1248 /* Return 1 if position CHARPOS is visible in window W.
1249 If visible, set *X and *Y to pixel coordinates of top left corner.
1250 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1251 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1252 and header-lines heights. */
1255 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, exact_mode_line_heights_p
)
1257 int charpos
, *x
, *y
, *rtop
, *rbot
, exact_mode_line_heights_p
;
1260 struct text_pos top
;
1262 struct buffer
*old_buffer
= NULL
;
1267 if (XBUFFER (w
->buffer
) != current_buffer
)
1269 old_buffer
= current_buffer
;
1270 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1273 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1275 /* Compute exact mode line heights, if requested. */
1276 if (exact_mode_line_heights_p
)
1278 if (WINDOW_WANTS_MODELINE_P (w
))
1279 current_mode_line_height
1280 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1281 current_buffer
->mode_line_format
);
1283 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1284 current_header_line_height
1285 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1286 current_buffer
->header_line_format
);
1289 start_display (&it
, w
, top
);
1290 move_it_to (&it
, charpos
, -1, it
.last_visible_y
, -1,
1291 MOVE_TO_POS
| MOVE_TO_Y
);
1293 /* Note that we may overshoot because of invisible text. */
1294 if (IT_CHARPOS (it
) >= charpos
)
1296 int top_x
= it
.current_x
;
1297 int top_y
= it
.current_y
;
1298 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1299 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1301 if (top_y
< window_top_y
)
1302 visible_p
= bottom_y
> window_top_y
;
1303 else if (top_y
< it
.last_visible_y
)
1308 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1309 *rtop
= max (0, window_top_y
- top_y
);
1310 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1318 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1319 move_it_by_lines (&it
, 1, 0);
1320 if (charpos
< IT_CHARPOS (it
))
1323 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1325 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1326 *rtop
= max (0, -it2
.current_y
);
1327 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1328 - it
.last_visible_y
));
1333 set_buffer_internal_1 (old_buffer
);
1335 current_header_line_height
= current_mode_line_height
= -1;
1337 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1338 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1344 /* Return the next character from STR which is MAXLEN bytes long.
1345 Return in *LEN the length of the character. This is like
1346 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1347 we find one, we return a `?', but with the length of the invalid
1351 string_char_and_length (str
, maxlen
, len
)
1352 const unsigned char *str
;
1357 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1358 if (!CHAR_VALID_P (c
, 1))
1359 /* We may not change the length here because other places in Emacs
1360 don't use this function, i.e. they silently accept invalid
1369 /* Given a position POS containing a valid character and byte position
1370 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1372 static struct text_pos
1373 string_pos_nchars_ahead (pos
, string
, nchars
)
1374 struct text_pos pos
;
1378 xassert (STRINGP (string
) && nchars
>= 0);
1380 if (STRING_MULTIBYTE (string
))
1382 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1383 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1388 string_char_and_length (p
, rest
, &len
);
1389 p
+= len
, rest
-= len
;
1390 xassert (rest
>= 0);
1392 BYTEPOS (pos
) += len
;
1396 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1402 /* Value is the text position, i.e. character and byte position,
1403 for character position CHARPOS in STRING. */
1405 static INLINE
struct text_pos
1406 string_pos (charpos
, string
)
1410 struct text_pos pos
;
1411 xassert (STRINGP (string
));
1412 xassert (charpos
>= 0);
1413 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1418 /* Value is a text position, i.e. character and byte position, for
1419 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1420 means recognize multibyte characters. */
1422 static struct text_pos
1423 c_string_pos (charpos
, s
, multibyte_p
)
1428 struct text_pos pos
;
1430 xassert (s
!= NULL
);
1431 xassert (charpos
>= 0);
1435 int rest
= strlen (s
), len
;
1437 SET_TEXT_POS (pos
, 0, 0);
1440 string_char_and_length (s
, rest
, &len
);
1441 s
+= len
, rest
-= len
;
1442 xassert (rest
>= 0);
1444 BYTEPOS (pos
) += len
;
1448 SET_TEXT_POS (pos
, charpos
, charpos
);
1454 /* Value is the number of characters in C string S. MULTIBYTE_P
1455 non-zero means recognize multibyte characters. */
1458 number_of_chars (s
, multibyte_p
)
1466 int rest
= strlen (s
), len
;
1467 unsigned char *p
= (unsigned char *) s
;
1469 for (nchars
= 0; rest
> 0; ++nchars
)
1471 string_char_and_length (p
, rest
, &len
);
1472 rest
-= len
, p
+= len
;
1476 nchars
= strlen (s
);
1482 /* Compute byte position NEWPOS->bytepos corresponding to
1483 NEWPOS->charpos. POS is a known position in string STRING.
1484 NEWPOS->charpos must be >= POS.charpos. */
1487 compute_string_pos (newpos
, pos
, string
)
1488 struct text_pos
*newpos
, pos
;
1491 xassert (STRINGP (string
));
1492 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1494 if (STRING_MULTIBYTE (string
))
1495 *newpos
= string_pos_nchars_ahead (pos
, string
,
1496 CHARPOS (*newpos
) - CHARPOS (pos
));
1498 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1502 Return an estimation of the pixel height of mode or top lines on
1503 frame F. FACE_ID specifies what line's height to estimate. */
1506 estimate_mode_line_height (f
, face_id
)
1508 enum face_id face_id
;
1510 #ifdef HAVE_WINDOW_SYSTEM
1511 if (FRAME_WINDOW_P (f
))
1513 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1515 /* This function is called so early when Emacs starts that the face
1516 cache and mode line face are not yet initialized. */
1517 if (FRAME_FACE_CACHE (f
))
1519 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1523 height
= FONT_HEIGHT (face
->font
);
1524 if (face
->box_line_width
> 0)
1525 height
+= 2 * face
->box_line_width
;
1536 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1537 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1538 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1539 not force the value into range. */
1542 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1544 register int pix_x
, pix_y
;
1546 NativeRectangle
*bounds
;
1550 #ifdef HAVE_WINDOW_SYSTEM
1551 if (FRAME_WINDOW_P (f
))
1553 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1554 even for negative values. */
1556 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1558 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1560 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1561 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1564 STORE_NATIVE_RECT (*bounds
,
1565 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1566 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1567 FRAME_COLUMN_WIDTH (f
) - 1,
1568 FRAME_LINE_HEIGHT (f
) - 1);
1574 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1575 pix_x
= FRAME_TOTAL_COLS (f
);
1579 else if (pix_y
> FRAME_LINES (f
))
1580 pix_y
= FRAME_LINES (f
);
1590 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1591 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1592 can't tell the positions because W's display is not up to date,
1596 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1599 int *frame_x
, *frame_y
;
1601 #ifdef HAVE_WINDOW_SYSTEM
1602 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1606 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1607 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1609 if (display_completed
)
1611 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1612 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1613 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1619 hpos
+= glyph
->pixel_width
;
1623 /* If first glyph is partially visible, its first visible position is still 0. */
1635 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1636 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1647 #ifdef HAVE_WINDOW_SYSTEM
1649 /* Find the glyph under window-relative coordinates X/Y in window W.
1650 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1651 strings. Return in *HPOS and *VPOS the row and column number of
1652 the glyph found. Return in *AREA the glyph area containing X.
1653 Value is a pointer to the glyph found or null if X/Y is not on
1654 text, or we can't tell because W's current matrix is not up to
1657 static struct glyph
*
1658 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1661 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1663 struct glyph
*glyph
, *end
;
1664 struct glyph_row
*row
= NULL
;
1667 /* Find row containing Y. Give up if some row is not enabled. */
1668 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1670 row
= MATRIX_ROW (w
->current_matrix
, i
);
1671 if (!row
->enabled_p
)
1673 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1680 /* Give up if Y is not in the window. */
1681 if (i
== w
->current_matrix
->nrows
)
1684 /* Get the glyph area containing X. */
1685 if (w
->pseudo_window_p
)
1692 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1694 *area
= LEFT_MARGIN_AREA
;
1695 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1697 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1700 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1704 *area
= RIGHT_MARGIN_AREA
;
1705 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1709 /* Find glyph containing X. */
1710 glyph
= row
->glyphs
[*area
];
1711 end
= glyph
+ row
->used
[*area
];
1713 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1715 x
-= glyph
->pixel_width
;
1725 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1728 *hpos
= glyph
- row
->glyphs
[*area
];
1734 Convert frame-relative x/y to coordinates relative to window W.
1735 Takes pseudo-windows into account. */
1738 frame_to_window_pixel_xy (w
, x
, y
)
1742 if (w
->pseudo_window_p
)
1744 /* A pseudo-window is always full-width, and starts at the
1745 left edge of the frame, plus a frame border. */
1746 struct frame
*f
= XFRAME (w
->frame
);
1747 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1748 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1752 *x
-= WINDOW_LEFT_EDGE_X (w
);
1753 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1758 Return in RECTS[] at most N clipping rectangles for glyph string S.
1759 Return the number of stored rectangles. */
1762 get_glyph_string_clip_rects (s
, rects
, n
)
1763 struct glyph_string
*s
;
1764 NativeRectangle
*rects
;
1772 if (s
->row
->full_width_p
)
1774 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1775 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1776 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1778 /* Unless displaying a mode or menu bar line, which are always
1779 fully visible, clip to the visible part of the row. */
1780 if (s
->w
->pseudo_window_p
)
1781 r
.height
= s
->row
->visible_height
;
1783 r
.height
= s
->height
;
1787 /* This is a text line that may be partially visible. */
1788 r
.x
= window_box_left (s
->w
, s
->area
);
1789 r
.width
= window_box_width (s
->w
, s
->area
);
1790 r
.height
= s
->row
->visible_height
;
1794 if (r
.x
< s
->clip_head
->x
)
1796 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1797 r
.width
-= s
->clip_head
->x
- r
.x
;
1800 r
.x
= s
->clip_head
->x
;
1803 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1805 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1806 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1811 /* If S draws overlapping rows, it's sufficient to use the top and
1812 bottom of the window for clipping because this glyph string
1813 intentionally draws over other lines. */
1814 if (s
->for_overlaps
)
1816 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1817 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1819 /* Alas, the above simple strategy does not work for the
1820 environments with anti-aliased text: if the same text is
1821 drawn onto the same place multiple times, it gets thicker.
1822 If the overlap we are processing is for the erased cursor, we
1823 take the intersection with the rectagle of the cursor. */
1824 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1826 XRectangle rc
, r_save
= r
;
1828 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1829 rc
.y
= s
->w
->phys_cursor
.y
;
1830 rc
.width
= s
->w
->phys_cursor_width
;
1831 rc
.height
= s
->w
->phys_cursor_height
;
1833 x_intersect_rectangles (&r_save
, &rc
, &r
);
1838 /* Don't use S->y for clipping because it doesn't take partially
1839 visible lines into account. For example, it can be negative for
1840 partially visible lines at the top of a window. */
1841 if (!s
->row
->full_width_p
1842 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1843 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1845 r
.y
= max (0, s
->row
->y
);
1847 /* If drawing a tool-bar window, draw it over the internal border
1848 at the top of the window. */
1849 if (WINDOWP (s
->f
->tool_bar_window
)
1850 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1851 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1854 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1856 /* If drawing the cursor, don't let glyph draw outside its
1857 advertised boundaries. Cleartype does this under some circumstances. */
1858 if (s
->hl
== DRAW_CURSOR
)
1860 struct glyph
*glyph
= s
->first_glyph
;
1865 r
.width
-= s
->x
- r
.x
;
1868 r
.width
= min (r
.width
, glyph
->pixel_width
);
1870 /* If r.y is below window bottom, ensure that we still see a cursor. */
1871 height
= min (glyph
->ascent
+ glyph
->descent
,
1872 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1873 max_y
= window_text_bottom_y (s
->w
) - height
;
1874 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1875 if (s
->ybase
- glyph
->ascent
> max_y
)
1882 /* Don't draw cursor glyph taller than our actual glyph. */
1883 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1884 if (height
< r
.height
)
1886 max_y
= r
.y
+ r
.height
;
1887 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1888 r
.height
= min (max_y
- r
.y
, height
);
1893 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1894 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1896 #ifdef CONVERT_FROM_XRECT
1897 CONVERT_FROM_XRECT (r
, *rects
);
1905 /* If we are processing overlapping and allowed to return
1906 multiple clipping rectangles, we exclude the row of the glyph
1907 string from the clipping rectangle. This is to avoid drawing
1908 the same text on the environment with anti-aliasing. */
1909 #ifdef CONVERT_FROM_XRECT
1912 XRectangle
*rs
= rects
;
1914 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1916 if (s
->for_overlaps
& OVERLAPS_PRED
)
1919 if (r
.y
+ r
.height
> row_y
)
1922 rs
[i
].height
= row_y
- r
.y
;
1928 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1931 if (r
.y
< row_y
+ s
->row
->visible_height
)
1933 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1935 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1936 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1945 #ifdef CONVERT_FROM_XRECT
1946 for (i
= 0; i
< n
; i
++)
1947 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1954 Return in *NR the clipping rectangle for glyph string S. */
1957 get_glyph_string_clip_rect (s
, nr
)
1958 struct glyph_string
*s
;
1959 NativeRectangle
*nr
;
1961 get_glyph_string_clip_rects (s
, nr
, 1);
1966 Return the position and height of the phys cursor in window W.
1967 Set w->phys_cursor_width to width of phys cursor.
1971 get_phys_cursor_geometry (w
, row
, glyph
, heightp
)
1973 struct glyph_row
*row
;
1974 struct glyph
*glyph
;
1977 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1978 int y
, wd
, h
, h0
, y0
;
1980 /* Compute the width of the rectangle to draw. If on a stretch
1981 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1982 rectangle as wide as the glyph, but use a canonical character
1984 wd
= glyph
->pixel_width
- 1;
1988 if (glyph
->type
== STRETCH_GLYPH
1989 && !x_stretch_cursor_p
)
1990 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
1991 w
->phys_cursor_width
= wd
;
1993 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
1995 /* If y is below window bottom, ensure that we still see a cursor. */
1996 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
1998 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
1999 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2001 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2004 h
= max (h
- (y0
- y
) + 1, h0
);
2009 y0
= window_text_bottom_y (w
) - h0
;
2018 return WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2022 * Remember which glyph the mouse is over.
2026 remember_mouse_glyph (f
, gx
, gy
, rect
)
2029 NativeRectangle
*rect
;
2033 struct glyph_row
*r
, *gr
, *end_row
;
2034 enum window_part part
;
2035 enum glyph_row_area area
;
2036 int x
, y
, width
, height
;
2038 /* Try to determine frame pixel position and size of the glyph under
2039 frame pixel coordinates X/Y on frame F. */
2041 window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0);
2044 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2045 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2049 w
= XWINDOW (window
);
2050 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2051 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2053 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2054 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2056 if (w
->pseudo_window_p
)
2059 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2065 case ON_LEFT_MARGIN
:
2066 area
= LEFT_MARGIN_AREA
;
2069 case ON_RIGHT_MARGIN
:
2070 area
= RIGHT_MARGIN_AREA
;
2073 case ON_HEADER_LINE
:
2075 gr
= (part
== ON_HEADER_LINE
2076 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2077 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2080 goto text_glyph_row_found
;
2087 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2088 if (r
->y
+ r
->height
> y
)
2094 text_glyph_row_found
:
2097 struct glyph
*g
= gr
->glyphs
[area
];
2098 struct glyph
*end
= g
+ gr
->used
[area
];
2100 height
= gr
->height
;
2101 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2102 if (gx
+ g
->pixel_width
> x
)
2107 if (g
->type
== IMAGE_GLYPH
)
2109 /* Don't remember when mouse is over image, as
2110 image may have hot-spots. */
2111 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2114 width
= g
->pixel_width
;
2118 /* Use nominal char spacing at end of line. */
2120 gx
+= (x
/ width
) * width
;
2123 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2124 gx
+= window_box_left_offset (w
, area
);
2128 /* Use nominal line height at end of window. */
2129 gx
= (x
/ width
) * width
;
2131 gy
+= (y
/ height
) * height
;
2135 case ON_LEFT_FRINGE
:
2136 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2137 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2138 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2139 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2142 case ON_RIGHT_FRINGE
:
2143 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2144 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2145 : window_box_right_offset (w
, TEXT_AREA
));
2146 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2150 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2152 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2153 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2154 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2156 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2160 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2161 if (r
->y
+ r
->height
> y
)
2168 height
= gr
->height
;
2171 /* Use nominal line height at end of window. */
2173 gy
+= (y
/ height
) * height
;
2180 /* If there is no glyph under the mouse, then we divide the screen
2181 into a grid of the smallest glyph in the frame, and use that
2184 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2185 round down even for negative values. */
2191 gx
= (gx
/ width
) * width
;
2192 gy
= (gy
/ height
) * height
;
2197 gx
+= WINDOW_LEFT_EDGE_X (w
);
2198 gy
+= WINDOW_TOP_EDGE_Y (w
);
2201 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2203 /* Visible feedback for debugging. */
2206 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2207 f
->output_data
.x
->normal_gc
,
2208 gx
, gy
, width
, height
);
2214 #endif /* HAVE_WINDOW_SYSTEM */
2217 /***********************************************************************
2218 Lisp form evaluation
2219 ***********************************************************************/
2221 /* Error handler for safe_eval and safe_call. */
2224 safe_eval_handler (arg
)
2227 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2232 /* Evaluate SEXPR and return the result, or nil if something went
2233 wrong. Prevent redisplay during the evaluation. */
2241 if (inhibit_eval_during_redisplay
)
2245 int count
= SPECPDL_INDEX ();
2246 struct gcpro gcpro1
;
2249 specbind (Qinhibit_redisplay
, Qt
);
2250 /* Use Qt to ensure debugger does not run,
2251 so there is no possibility of wanting to redisplay. */
2252 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2255 val
= unbind_to (count
, val
);
2262 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2263 Return the result, or nil if something went wrong. Prevent
2264 redisplay during the evaluation. */
2267 safe_call (nargs
, args
)
2273 if (inhibit_eval_during_redisplay
)
2277 int count
= SPECPDL_INDEX ();
2278 struct gcpro gcpro1
;
2281 gcpro1
.nvars
= nargs
;
2282 specbind (Qinhibit_redisplay
, Qt
);
2283 /* Use Qt to ensure debugger does not run,
2284 so there is no possibility of wanting to redisplay. */
2285 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2288 val
= unbind_to (count
, val
);
2295 /* Call function FN with one argument ARG.
2296 Return the result, or nil if something went wrong. */
2299 safe_call1 (fn
, arg
)
2300 Lisp_Object fn
, arg
;
2302 Lisp_Object args
[2];
2305 return safe_call (2, args
);
2310 /***********************************************************************
2312 ***********************************************************************/
2316 /* Define CHECK_IT to perform sanity checks on iterators.
2317 This is for debugging. It is too slow to do unconditionally. */
2323 if (it
->method
== GET_FROM_STRING
)
2325 xassert (STRINGP (it
->string
));
2326 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2330 xassert (IT_STRING_CHARPOS (*it
) < 0);
2331 if (it
->method
== GET_FROM_BUFFER
)
2333 /* Check that character and byte positions agree. */
2334 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2339 xassert (it
->current
.dpvec_index
>= 0);
2341 xassert (it
->current
.dpvec_index
< 0);
2344 #define CHECK_IT(IT) check_it ((IT))
2348 #define CHECK_IT(IT) (void) 0
2355 /* Check that the window end of window W is what we expect it
2356 to be---the last row in the current matrix displaying text. */
2359 check_window_end (w
)
2362 if (!MINI_WINDOW_P (w
)
2363 && !NILP (w
->window_end_valid
))
2365 struct glyph_row
*row
;
2366 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2367 XFASTINT (w
->window_end_vpos
)),
2369 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2370 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2374 #define CHECK_WINDOW_END(W) check_window_end ((W))
2376 #else /* not GLYPH_DEBUG */
2378 #define CHECK_WINDOW_END(W) (void) 0
2380 #endif /* not GLYPH_DEBUG */
2384 /***********************************************************************
2385 Iterator initialization
2386 ***********************************************************************/
2388 /* Initialize IT for displaying current_buffer in window W, starting
2389 at character position CHARPOS. CHARPOS < 0 means that no buffer
2390 position is specified which is useful when the iterator is assigned
2391 a position later. BYTEPOS is the byte position corresponding to
2392 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2394 If ROW is not null, calls to produce_glyphs with IT as parameter
2395 will produce glyphs in that row.
2397 BASE_FACE_ID is the id of a base face to use. It must be one of
2398 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2399 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2400 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2402 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2403 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2404 will be initialized to use the corresponding mode line glyph row of
2405 the desired matrix of W. */
2408 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2411 int charpos
, bytepos
;
2412 struct glyph_row
*row
;
2413 enum face_id base_face_id
;
2415 int highlight_region_p
;
2417 /* Some precondition checks. */
2418 xassert (w
!= NULL
&& it
!= NULL
);
2419 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2422 /* If face attributes have been changed since the last redisplay,
2423 free realized faces now because they depend on face definitions
2424 that might have changed. Don't free faces while there might be
2425 desired matrices pending which reference these faces. */
2426 if (face_change_count
&& !inhibit_free_realized_faces
)
2428 face_change_count
= 0;
2429 free_all_realized_faces (Qnil
);
2432 /* Use one of the mode line rows of W's desired matrix if
2436 if (base_face_id
== MODE_LINE_FACE_ID
2437 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2438 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2439 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2440 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2444 bzero (it
, sizeof *it
);
2445 it
->current
.overlay_string_index
= -1;
2446 it
->current
.dpvec_index
= -1;
2447 it
->base_face_id
= base_face_id
;
2449 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2451 /* The window in which we iterate over current_buffer: */
2452 XSETWINDOW (it
->window
, w
);
2454 it
->f
= XFRAME (w
->frame
);
2456 /* Extra space between lines (on window systems only). */
2457 if (base_face_id
== DEFAULT_FACE_ID
2458 && FRAME_WINDOW_P (it
->f
))
2460 if (NATNUMP (current_buffer
->extra_line_spacing
))
2461 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2462 else if (FLOATP (current_buffer
->extra_line_spacing
))
2463 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2464 * FRAME_LINE_HEIGHT (it
->f
));
2465 else if (it
->f
->extra_line_spacing
> 0)
2466 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2467 it
->max_extra_line_spacing
= 0;
2470 /* If realized faces have been removed, e.g. because of face
2471 attribute changes of named faces, recompute them. When running
2472 in batch mode, the face cache of the initial frame is null. If
2473 we happen to get called, make a dummy face cache. */
2474 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2475 init_frame_faces (it
->f
);
2476 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2477 recompute_basic_faces (it
->f
);
2479 /* Current value of the `slice', `space-width', and 'height' properties. */
2480 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2481 it
->space_width
= Qnil
;
2482 it
->font_height
= Qnil
;
2483 it
->override_ascent
= -1;
2485 /* Are control characters displayed as `^C'? */
2486 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2488 /* -1 means everything between a CR and the following line end
2489 is invisible. >0 means lines indented more than this value are
2491 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2492 ? XFASTINT (current_buffer
->selective_display
)
2493 : (!NILP (current_buffer
->selective_display
)
2495 it
->selective_display_ellipsis_p
2496 = !NILP (current_buffer
->selective_display_ellipses
);
2498 /* Display table to use. */
2499 it
->dp
= window_display_table (w
);
2501 /* Are multibyte characters enabled in current_buffer? */
2502 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2504 /* Non-zero if we should highlight the region. */
2506 = (!NILP (Vtransient_mark_mode
)
2507 && !NILP (current_buffer
->mark_active
)
2508 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2510 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2511 start and end of a visible region in window IT->w. Set both to
2512 -1 to indicate no region. */
2513 if (highlight_region_p
2514 /* Maybe highlight only in selected window. */
2515 && (/* Either show region everywhere. */
2516 highlight_nonselected_windows
2517 /* Or show region in the selected window. */
2518 || w
== XWINDOW (selected_window
)
2519 /* Or show the region if we are in the mini-buffer and W is
2520 the window the mini-buffer refers to. */
2521 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2522 && WINDOWP (minibuf_selected_window
)
2523 && w
== XWINDOW (minibuf_selected_window
))))
2525 int charpos
= marker_position (current_buffer
->mark
);
2526 it
->region_beg_charpos
= min (PT
, charpos
);
2527 it
->region_end_charpos
= max (PT
, charpos
);
2530 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2532 /* Get the position at which the redisplay_end_trigger hook should
2533 be run, if it is to be run at all. */
2534 if (MARKERP (w
->redisplay_end_trigger
)
2535 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2536 it
->redisplay_end_trigger_charpos
2537 = marker_position (w
->redisplay_end_trigger
);
2538 else if (INTEGERP (w
->redisplay_end_trigger
))
2539 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2541 /* Correct bogus values of tab_width. */
2542 it
->tab_width
= XINT (current_buffer
->tab_width
);
2543 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2546 /* Are lines in the display truncated? */
2547 it
->truncate_lines_p
2548 = (base_face_id
!= DEFAULT_FACE_ID
2549 || XINT (it
->w
->hscroll
)
2550 || (truncate_partial_width_windows
2551 && !WINDOW_FULL_WIDTH_P (it
->w
))
2552 || !NILP (current_buffer
->truncate_lines
));
2554 /* Get dimensions of truncation and continuation glyphs. These are
2555 displayed as fringe bitmaps under X, so we don't need them for such
2557 if (!FRAME_WINDOW_P (it
->f
))
2559 if (it
->truncate_lines_p
)
2561 /* We will need the truncation glyph. */
2562 xassert (it
->glyph_row
== NULL
);
2563 produce_special_glyphs (it
, IT_TRUNCATION
);
2564 it
->truncation_pixel_width
= it
->pixel_width
;
2568 /* We will need the continuation glyph. */
2569 xassert (it
->glyph_row
== NULL
);
2570 produce_special_glyphs (it
, IT_CONTINUATION
);
2571 it
->continuation_pixel_width
= it
->pixel_width
;
2574 /* Reset these values to zero because the produce_special_glyphs
2575 above has changed them. */
2576 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2577 it
->phys_ascent
= it
->phys_descent
= 0;
2580 /* Set this after getting the dimensions of truncation and
2581 continuation glyphs, so that we don't produce glyphs when calling
2582 produce_special_glyphs, above. */
2583 it
->glyph_row
= row
;
2584 it
->area
= TEXT_AREA
;
2586 /* Get the dimensions of the display area. The display area
2587 consists of the visible window area plus a horizontally scrolled
2588 part to the left of the window. All x-values are relative to the
2589 start of this total display area. */
2590 if (base_face_id
!= DEFAULT_FACE_ID
)
2592 /* Mode lines, menu bar in terminal frames. */
2593 it
->first_visible_x
= 0;
2594 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2599 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2600 it
->last_visible_x
= (it
->first_visible_x
2601 + window_box_width (w
, TEXT_AREA
));
2603 /* If we truncate lines, leave room for the truncator glyph(s) at
2604 the right margin. Otherwise, leave room for the continuation
2605 glyph(s). Truncation and continuation glyphs are not inserted
2606 for window-based redisplay. */
2607 if (!FRAME_WINDOW_P (it
->f
))
2609 if (it
->truncate_lines_p
)
2610 it
->last_visible_x
-= it
->truncation_pixel_width
;
2612 it
->last_visible_x
-= it
->continuation_pixel_width
;
2615 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2616 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2619 /* Leave room for a border glyph. */
2620 if (!FRAME_WINDOW_P (it
->f
)
2621 && !WINDOW_RIGHTMOST_P (it
->w
))
2622 it
->last_visible_x
-= 1;
2624 it
->last_visible_y
= window_text_bottom_y (w
);
2626 /* For mode lines and alike, arrange for the first glyph having a
2627 left box line if the face specifies a box. */
2628 if (base_face_id
!= DEFAULT_FACE_ID
)
2632 it
->face_id
= base_face_id
;
2634 /* If we have a boxed mode line, make the first character appear
2635 with a left box line. */
2636 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2637 if (face
->box
!= FACE_NO_BOX
)
2638 it
->start_of_box_run_p
= 1;
2641 /* If a buffer position was specified, set the iterator there,
2642 getting overlays and face properties from that position. */
2643 if (charpos
>= BUF_BEG (current_buffer
))
2645 it
->end_charpos
= ZV
;
2647 IT_CHARPOS (*it
) = charpos
;
2649 /* Compute byte position if not specified. */
2650 if (bytepos
< charpos
)
2651 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2653 IT_BYTEPOS (*it
) = bytepos
;
2655 it
->start
= it
->current
;
2657 /* Compute faces etc. */
2658 reseat (it
, it
->current
.pos
, 1);
2665 /* Initialize IT for the display of window W with window start POS. */
2668 start_display (it
, w
, pos
)
2671 struct text_pos pos
;
2673 struct glyph_row
*row
;
2674 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2676 row
= w
->desired_matrix
->rows
+ first_vpos
;
2677 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2678 it
->first_vpos
= first_vpos
;
2680 /* Don't reseat to previous visible line start if current start
2681 position is in a string or image. */
2682 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2684 int start_at_line_beg_p
;
2685 int first_y
= it
->current_y
;
2687 /* If window start is not at a line start, skip forward to POS to
2688 get the correct continuation lines width. */
2689 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2690 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2691 if (!start_at_line_beg_p
)
2695 reseat_at_previous_visible_line_start (it
);
2696 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2698 new_x
= it
->current_x
+ it
->pixel_width
;
2700 /* If lines are continued, this line may end in the middle
2701 of a multi-glyph character (e.g. a control character
2702 displayed as \003, or in the middle of an overlay
2703 string). In this case move_it_to above will not have
2704 taken us to the start of the continuation line but to the
2705 end of the continued line. */
2706 if (it
->current_x
> 0
2707 && !it
->truncate_lines_p
/* Lines are continued. */
2708 && (/* And glyph doesn't fit on the line. */
2709 new_x
> it
->last_visible_x
2710 /* Or it fits exactly and we're on a window
2712 || (new_x
== it
->last_visible_x
2713 && FRAME_WINDOW_P (it
->f
))))
2715 if (it
->current
.dpvec_index
>= 0
2716 || it
->current
.overlay_string_index
>= 0)
2718 set_iterator_to_next (it
, 1);
2719 move_it_in_display_line_to (it
, -1, -1, 0);
2722 it
->continuation_lines_width
+= it
->current_x
;
2725 /* We're starting a new display line, not affected by the
2726 height of the continued line, so clear the appropriate
2727 fields in the iterator structure. */
2728 it
->max_ascent
= it
->max_descent
= 0;
2729 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2731 it
->current_y
= first_y
;
2733 it
->current_x
= it
->hpos
= 0;
2737 #if 0 /* Don't assert the following because start_display is sometimes
2738 called intentionally with a window start that is not at a
2739 line start. Please leave this code in as a comment. */
2741 /* Window start should be on a line start, now. */
2742 xassert (it
->continuation_lines_width
2743 || IT_CHARPOS (it
) == BEGV
2744 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2749 /* Return 1 if POS is a position in ellipses displayed for invisible
2750 text. W is the window we display, for text property lookup. */
2753 in_ellipses_for_invisible_text_p (pos
, w
)
2754 struct display_pos
*pos
;
2757 Lisp_Object prop
, window
;
2759 int charpos
= CHARPOS (pos
->pos
);
2761 /* If POS specifies a position in a display vector, this might
2762 be for an ellipsis displayed for invisible text. We won't
2763 get the iterator set up for delivering that ellipsis unless
2764 we make sure that it gets aware of the invisible text. */
2765 if (pos
->dpvec_index
>= 0
2766 && pos
->overlay_string_index
< 0
2767 && CHARPOS (pos
->string_pos
) < 0
2769 && (XSETWINDOW (window
, w
),
2770 prop
= Fget_char_property (make_number (charpos
),
2771 Qinvisible
, window
),
2772 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2774 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2776 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2783 /* Initialize IT for stepping through current_buffer in window W,
2784 starting at position POS that includes overlay string and display
2785 vector/ control character translation position information. Value
2786 is zero if there are overlay strings with newlines at POS. */
2789 init_from_display_pos (it
, w
, pos
)
2792 struct display_pos
*pos
;
2794 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2795 int i
, overlay_strings_with_newlines
= 0;
2797 /* If POS specifies a position in a display vector, this might
2798 be for an ellipsis displayed for invisible text. We won't
2799 get the iterator set up for delivering that ellipsis unless
2800 we make sure that it gets aware of the invisible text. */
2801 if (in_ellipses_for_invisible_text_p (pos
, w
))
2807 /* Keep in mind: the call to reseat in init_iterator skips invisible
2808 text, so we might end up at a position different from POS. This
2809 is only a problem when POS is a row start after a newline and an
2810 overlay starts there with an after-string, and the overlay has an
2811 invisible property. Since we don't skip invisible text in
2812 display_line and elsewhere immediately after consuming the
2813 newline before the row start, such a POS will not be in a string,
2814 but the call to init_iterator below will move us to the
2816 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2818 /* This only scans the current chunk -- it should scan all chunks.
2819 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2820 to 16 in 22.1 to make this a lesser problem. */
2821 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2823 const char *s
= SDATA (it
->overlay_strings
[i
]);
2824 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2826 while (s
< e
&& *s
!= '\n')
2831 overlay_strings_with_newlines
= 1;
2836 /* If position is within an overlay string, set up IT to the right
2838 if (pos
->overlay_string_index
>= 0)
2842 /* If the first overlay string happens to have a `display'
2843 property for an image, the iterator will be set up for that
2844 image, and we have to undo that setup first before we can
2845 correct the overlay string index. */
2846 if (it
->method
== GET_FROM_IMAGE
)
2849 /* We already have the first chunk of overlay strings in
2850 IT->overlay_strings. Load more until the one for
2851 pos->overlay_string_index is in IT->overlay_strings. */
2852 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2854 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2855 it
->current
.overlay_string_index
= 0;
2858 load_overlay_strings (it
, 0);
2859 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2863 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2864 relative_index
= (it
->current
.overlay_string_index
2865 % OVERLAY_STRING_CHUNK_SIZE
);
2866 it
->string
= it
->overlay_strings
[relative_index
];
2867 xassert (STRINGP (it
->string
));
2868 it
->current
.string_pos
= pos
->string_pos
;
2869 it
->method
= GET_FROM_STRING
;
2872 #if 0 /* This is bogus because POS not having an overlay string
2873 position does not mean it's after the string. Example: A
2874 line starting with a before-string and initialization of IT
2875 to the previous row's end position. */
2876 else if (it
->current
.overlay_string_index
>= 0)
2878 /* If POS says we're already after an overlay string ending at
2879 POS, make sure to pop the iterator because it will be in
2880 front of that overlay string. When POS is ZV, we've thereby
2881 also ``processed'' overlay strings at ZV. */
2884 it
->current
.overlay_string_index
= -1;
2885 it
->method
= GET_FROM_BUFFER
;
2886 if (CHARPOS (pos
->pos
) == ZV
)
2887 it
->overlay_strings_at_end_processed_p
= 1;
2891 if (CHARPOS (pos
->string_pos
) >= 0)
2893 /* Recorded position is not in an overlay string, but in another
2894 string. This can only be a string from a `display' property.
2895 IT should already be filled with that string. */
2896 it
->current
.string_pos
= pos
->string_pos
;
2897 xassert (STRINGP (it
->string
));
2900 /* Restore position in display vector translations, control
2901 character translations or ellipses. */
2902 if (pos
->dpvec_index
>= 0)
2904 if (it
->dpvec
== NULL
)
2905 get_next_display_element (it
);
2906 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2907 it
->current
.dpvec_index
= pos
->dpvec_index
;
2911 return !overlay_strings_with_newlines
;
2915 /* Initialize IT for stepping through current_buffer in window W
2916 starting at ROW->start. */
2919 init_to_row_start (it
, w
, row
)
2922 struct glyph_row
*row
;
2924 init_from_display_pos (it
, w
, &row
->start
);
2925 it
->start
= row
->start
;
2926 it
->continuation_lines_width
= row
->continuation_lines_width
;
2931 /* Initialize IT for stepping through current_buffer in window W
2932 starting in the line following ROW, i.e. starting at ROW->end.
2933 Value is zero if there are overlay strings with newlines at ROW's
2937 init_to_row_end (it
, w
, row
)
2940 struct glyph_row
*row
;
2944 if (init_from_display_pos (it
, w
, &row
->end
))
2946 if (row
->continued_p
)
2947 it
->continuation_lines_width
2948 = row
->continuation_lines_width
+ row
->pixel_width
;
2959 /***********************************************************************
2961 ***********************************************************************/
2963 /* Called when IT reaches IT->stop_charpos. Handle text property and
2964 overlay changes. Set IT->stop_charpos to the next position where
2971 enum prop_handled handled
;
2972 int handle_overlay_change_p
;
2976 it
->current
.dpvec_index
= -1;
2977 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
2978 it
->ignore_overlay_strings_at_pos_p
= 0;
2980 /* Use face of preceding text for ellipsis (if invisible) */
2981 if (it
->selective_display_ellipsis_p
)
2982 it
->saved_face_id
= it
->face_id
;
2986 handled
= HANDLED_NORMALLY
;
2988 /* Call text property handlers. */
2989 for (p
= it_props
; p
->handler
; ++p
)
2991 handled
= p
->handler (it
);
2993 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2995 else if (handled
== HANDLED_RETURN
)
2997 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2998 handle_overlay_change_p
= 0;
3001 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3003 /* Don't check for overlay strings below when set to deliver
3004 characters from a display vector. */
3005 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3006 handle_overlay_change_p
= 0;
3008 /* Handle overlay changes. */
3009 if (handle_overlay_change_p
)
3010 handled
= handle_overlay_change (it
);
3012 /* Determine where to stop next. */
3013 if (handled
== HANDLED_NORMALLY
)
3014 compute_stop_pos (it
);
3017 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3021 /* Compute IT->stop_charpos from text property and overlay change
3022 information for IT's current position. */
3025 compute_stop_pos (it
)
3028 register INTERVAL iv
, next_iv
;
3029 Lisp_Object object
, limit
, position
;
3031 /* If nowhere else, stop at the end. */
3032 it
->stop_charpos
= it
->end_charpos
;
3034 if (STRINGP (it
->string
))
3036 /* Strings are usually short, so don't limit the search for
3038 object
= it
->string
;
3040 position
= make_number (IT_STRING_CHARPOS (*it
));
3046 /* If next overlay change is in front of the current stop pos
3047 (which is IT->end_charpos), stop there. Note: value of
3048 next_overlay_change is point-max if no overlay change
3050 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3051 if (charpos
< it
->stop_charpos
)
3052 it
->stop_charpos
= charpos
;
3054 /* If showing the region, we have to stop at the region
3055 start or end because the face might change there. */
3056 if (it
->region_beg_charpos
> 0)
3058 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3059 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3060 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3061 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3064 /* Set up variables for computing the stop position from text
3065 property changes. */
3066 XSETBUFFER (object
, current_buffer
);
3067 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3068 position
= make_number (IT_CHARPOS (*it
));
3072 /* Get the interval containing IT's position. Value is a null
3073 interval if there isn't such an interval. */
3074 iv
= validate_interval_range (object
, &position
, &position
, 0);
3075 if (!NULL_INTERVAL_P (iv
))
3077 Lisp_Object values_here
[LAST_PROP_IDX
];
3080 /* Get properties here. */
3081 for (p
= it_props
; p
->handler
; ++p
)
3082 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3084 /* Look for an interval following iv that has different
3086 for (next_iv
= next_interval (iv
);
3087 (!NULL_INTERVAL_P (next_iv
)
3089 || XFASTINT (limit
) > next_iv
->position
));
3090 next_iv
= next_interval (next_iv
))
3092 for (p
= it_props
; p
->handler
; ++p
)
3094 Lisp_Object new_value
;
3096 new_value
= textget (next_iv
->plist
, *p
->name
);
3097 if (!EQ (values_here
[p
->idx
], new_value
))
3105 if (!NULL_INTERVAL_P (next_iv
))
3107 if (INTEGERP (limit
)
3108 && next_iv
->position
>= XFASTINT (limit
))
3109 /* No text property change up to limit. */
3110 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3112 /* Text properties change in next_iv. */
3113 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3117 xassert (STRINGP (it
->string
)
3118 || (it
->stop_charpos
>= BEGV
3119 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3123 /* Return the position of the next overlay change after POS in
3124 current_buffer. Value is point-max if no overlay change
3125 follows. This is like `next-overlay-change' but doesn't use
3129 next_overlay_change (pos
)
3134 Lisp_Object
*overlays
;
3137 /* Get all overlays at the given position. */
3138 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3140 /* If any of these overlays ends before endpos,
3141 use its ending point instead. */
3142 for (i
= 0; i
< noverlays
; ++i
)
3147 oend
= OVERLAY_END (overlays
[i
]);
3148 oendpos
= OVERLAY_POSITION (oend
);
3149 endpos
= min (endpos
, oendpos
);
3157 /***********************************************************************
3159 ***********************************************************************/
3161 /* Handle changes in the `fontified' property of the current buffer by
3162 calling hook functions from Qfontification_functions to fontify
3165 static enum prop_handled
3166 handle_fontified_prop (it
)
3169 Lisp_Object prop
, pos
;
3170 enum prop_handled handled
= HANDLED_NORMALLY
;
3172 if (!NILP (Vmemory_full
))
3175 /* Get the value of the `fontified' property at IT's current buffer
3176 position. (The `fontified' property doesn't have a special
3177 meaning in strings.) If the value is nil, call functions from
3178 Qfontification_functions. */
3179 if (!STRINGP (it
->string
)
3181 && !NILP (Vfontification_functions
)
3182 && !NILP (Vrun_hooks
)
3183 && (pos
= make_number (IT_CHARPOS (*it
)),
3184 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3187 int count
= SPECPDL_INDEX ();
3190 val
= Vfontification_functions
;
3191 specbind (Qfontification_functions
, Qnil
);
3193 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3194 safe_call1 (val
, pos
);
3197 Lisp_Object globals
, fn
;
3198 struct gcpro gcpro1
, gcpro2
;
3201 GCPRO2 (val
, globals
);
3203 for (; CONSP (val
); val
= XCDR (val
))
3209 /* A value of t indicates this hook has a local
3210 binding; it means to run the global binding too.
3211 In a global value, t should not occur. If it
3212 does, we must ignore it to avoid an endless
3214 for (globals
= Fdefault_value (Qfontification_functions
);
3216 globals
= XCDR (globals
))
3218 fn
= XCAR (globals
);
3220 safe_call1 (fn
, pos
);
3224 safe_call1 (fn
, pos
);
3230 unbind_to (count
, Qnil
);
3232 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3233 something. This avoids an endless loop if they failed to
3234 fontify the text for which reason ever. */
3235 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3236 handled
= HANDLED_RECOMPUTE_PROPS
;
3244 /***********************************************************************
3246 ***********************************************************************/
3248 /* Set up iterator IT from face properties at its current position.
3249 Called from handle_stop. */
3251 static enum prop_handled
3252 handle_face_prop (it
)
3255 int new_face_id
, next_stop
;
3257 if (!STRINGP (it
->string
))
3260 = face_at_buffer_position (it
->w
,
3262 it
->region_beg_charpos
,
3263 it
->region_end_charpos
,
3266 + TEXT_PROP_DISTANCE_LIMIT
),
3269 /* Is this a start of a run of characters with box face?
3270 Caveat: this can be called for a freshly initialized
3271 iterator; face_id is -1 in this case. We know that the new
3272 face will not change until limit, i.e. if the new face has a
3273 box, all characters up to limit will have one. But, as
3274 usual, we don't know whether limit is really the end. */
3275 if (new_face_id
!= it
->face_id
)
3277 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3279 /* If new face has a box but old face has not, this is
3280 the start of a run of characters with box, i.e. it has
3281 a shadow on the left side. The value of face_id of the
3282 iterator will be -1 if this is the initial call that gets
3283 the face. In this case, we have to look in front of IT's
3284 position and see whether there is a face != new_face_id. */
3285 it
->start_of_box_run_p
3286 = (new_face
->box
!= FACE_NO_BOX
3287 && (it
->face_id
>= 0
3288 || IT_CHARPOS (*it
) == BEG
3289 || new_face_id
!= face_before_it_pos (it
)));
3290 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3295 int base_face_id
, bufpos
;
3297 if (it
->current
.overlay_string_index
>= 0)
3298 bufpos
= IT_CHARPOS (*it
);
3302 /* For strings from a buffer, i.e. overlay strings or strings
3303 from a `display' property, use the face at IT's current
3304 buffer position as the base face to merge with, so that
3305 overlay strings appear in the same face as surrounding
3306 text, unless they specify their own faces. */
3307 base_face_id
= underlying_face_id (it
);
3309 new_face_id
= face_at_string_position (it
->w
,
3311 IT_STRING_CHARPOS (*it
),
3313 it
->region_beg_charpos
,
3314 it
->region_end_charpos
,
3318 #if 0 /* This shouldn't be neccessary. Let's check it. */
3319 /* If IT is used to display a mode line we would really like to
3320 use the mode line face instead of the frame's default face. */
3321 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3322 && new_face_id
== DEFAULT_FACE_ID
)
3323 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3326 /* Is this a start of a run of characters with box? Caveat:
3327 this can be called for a freshly allocated iterator; face_id
3328 is -1 is this case. We know that the new face will not
3329 change until the next check pos, i.e. if the new face has a
3330 box, all characters up to that position will have a
3331 box. But, as usual, we don't know whether that position
3332 is really the end. */
3333 if (new_face_id
!= it
->face_id
)
3335 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3336 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3338 /* If new face has a box but old face hasn't, this is the
3339 start of a run of characters with box, i.e. it has a
3340 shadow on the left side. */
3341 it
->start_of_box_run_p
3342 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3343 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3347 it
->face_id
= new_face_id
;
3348 return HANDLED_NORMALLY
;
3352 /* Return the ID of the face ``underlying'' IT's current position,
3353 which is in a string. If the iterator is associated with a
3354 buffer, return the face at IT's current buffer position.
3355 Otherwise, use the iterator's base_face_id. */
3358 underlying_face_id (it
)
3361 int face_id
= it
->base_face_id
, i
;
3363 xassert (STRINGP (it
->string
));
3365 for (i
= it
->sp
- 1; i
>= 0; --i
)
3366 if (NILP (it
->stack
[i
].string
))
3367 face_id
= it
->stack
[i
].face_id
;
3373 /* Compute the face one character before or after the current position
3374 of IT. BEFORE_P non-zero means get the face in front of IT's
3375 position. Value is the id of the face. */
3378 face_before_or_after_it_pos (it
, before_p
)
3383 int next_check_charpos
;
3384 struct text_pos pos
;
3386 xassert (it
->s
== NULL
);
3388 if (STRINGP (it
->string
))
3390 int bufpos
, base_face_id
;
3392 /* No face change past the end of the string (for the case
3393 we are padding with spaces). No face change before the
3395 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3396 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3399 /* Set pos to the position before or after IT's current position. */
3401 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3403 /* For composition, we must check the character after the
3405 pos
= (it
->what
== IT_COMPOSITION
3406 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3407 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3409 if (it
->current
.overlay_string_index
>= 0)
3410 bufpos
= IT_CHARPOS (*it
);
3414 base_face_id
= underlying_face_id (it
);
3416 /* Get the face for ASCII, or unibyte. */
3417 face_id
= face_at_string_position (it
->w
,
3421 it
->region_beg_charpos
,
3422 it
->region_end_charpos
,
3423 &next_check_charpos
,
3426 /* Correct the face for charsets different from ASCII. Do it
3427 for the multibyte case only. The face returned above is
3428 suitable for unibyte text if IT->string is unibyte. */
3429 if (STRING_MULTIBYTE (it
->string
))
3431 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3432 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3434 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3436 c
= string_char_and_length (p
, rest
, &len
);
3437 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3442 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3443 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3446 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3447 pos
= it
->current
.pos
;
3450 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3453 if (it
->what
== IT_COMPOSITION
)
3454 /* For composition, we must check the position after the
3456 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3458 INC_TEXT_POS (pos
, it
->multibyte_p
);
3461 /* Determine face for CHARSET_ASCII, or unibyte. */
3462 face_id
= face_at_buffer_position (it
->w
,
3464 it
->region_beg_charpos
,
3465 it
->region_end_charpos
,
3466 &next_check_charpos
,
3469 /* Correct the face for charsets different from ASCII. Do it
3470 for the multibyte case only. The face returned above is
3471 suitable for unibyte text if current_buffer is unibyte. */
3472 if (it
->multibyte_p
)
3474 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3475 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3476 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3485 /***********************************************************************
3487 ***********************************************************************/
3489 /* Set up iterator IT from invisible properties at its current
3490 position. Called from handle_stop. */
3492 static enum prop_handled
3493 handle_invisible_prop (it
)
3496 enum prop_handled handled
= HANDLED_NORMALLY
;
3498 if (STRINGP (it
->string
))
3500 extern Lisp_Object Qinvisible
;
3501 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3503 /* Get the value of the invisible text property at the
3504 current position. Value will be nil if there is no such
3506 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3507 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3510 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3512 handled
= HANDLED_RECOMPUTE_PROPS
;
3514 /* Get the position at which the next change of the
3515 invisible text property can be found in IT->string.
3516 Value will be nil if the property value is the same for
3517 all the rest of IT->string. */
3518 XSETINT (limit
, SCHARS (it
->string
));
3519 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3522 /* Text at current position is invisible. The next
3523 change in the property is at position end_charpos.
3524 Move IT's current position to that position. */
3525 if (INTEGERP (end_charpos
)
3526 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3528 struct text_pos old
;
3529 old
= it
->current
.string_pos
;
3530 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3531 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3535 /* The rest of the string is invisible. If this is an
3536 overlay string, proceed with the next overlay string
3537 or whatever comes and return a character from there. */
3538 if (it
->current
.overlay_string_index
>= 0)
3540 next_overlay_string (it
);
3541 /* Don't check for overlay strings when we just
3542 finished processing them. */
3543 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3547 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3548 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3555 int invis_p
, newpos
, next_stop
, start_charpos
;
3556 Lisp_Object pos
, prop
, overlay
;
3558 /* First of all, is there invisible text at this position? */
3559 start_charpos
= IT_CHARPOS (*it
);
3560 pos
= make_number (IT_CHARPOS (*it
));
3561 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3563 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3565 /* If we are on invisible text, skip over it. */
3566 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3568 /* Record whether we have to display an ellipsis for the
3570 int display_ellipsis_p
= invis_p
== 2;
3572 handled
= HANDLED_RECOMPUTE_PROPS
;
3574 /* Loop skipping over invisible text. The loop is left at
3575 ZV or with IT on the first char being visible again. */
3578 /* Try to skip some invisible text. Return value is the
3579 position reached which can be equal to IT's position
3580 if there is nothing invisible here. This skips both
3581 over invisible text properties and overlays with
3582 invisible property. */
3583 newpos
= skip_invisible (IT_CHARPOS (*it
),
3584 &next_stop
, ZV
, it
->window
);
3586 /* If we skipped nothing at all we weren't at invisible
3587 text in the first place. If everything to the end of
3588 the buffer was skipped, end the loop. */
3589 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3593 /* We skipped some characters but not necessarily
3594 all there are. Check if we ended up on visible
3595 text. Fget_char_property returns the property of
3596 the char before the given position, i.e. if we
3597 get invis_p = 0, this means that the char at
3598 newpos is visible. */
3599 pos
= make_number (newpos
);
3600 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3601 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3604 /* If we ended up on invisible text, proceed to
3605 skip starting with next_stop. */
3607 IT_CHARPOS (*it
) = next_stop
;
3611 /* The position newpos is now either ZV or on visible text. */
3612 IT_CHARPOS (*it
) = newpos
;
3613 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3615 /* If there are before-strings at the start of invisible
3616 text, and the text is invisible because of a text
3617 property, arrange to show before-strings because 20.x did
3618 it that way. (If the text is invisible because of an
3619 overlay property instead of a text property, this is
3620 already handled in the overlay code.) */
3622 && get_overlay_strings (it
, start_charpos
))
3624 handled
= HANDLED_RECOMPUTE_PROPS
;
3625 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3627 else if (display_ellipsis_p
)
3628 setup_for_ellipsis (it
, 0);
3636 /* Make iterator IT return `...' next.
3637 Replaces LEN characters from buffer. */
3640 setup_for_ellipsis (it
, len
)
3644 /* Use the display table definition for `...'. Invalid glyphs
3645 will be handled by the method returning elements from dpvec. */
3646 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3648 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3649 it
->dpvec
= v
->contents
;
3650 it
->dpend
= v
->contents
+ v
->size
;
3654 /* Default `...'. */
3655 it
->dpvec
= default_invis_vector
;
3656 it
->dpend
= default_invis_vector
+ 3;
3659 it
->dpvec_char_len
= len
;
3660 it
->current
.dpvec_index
= 0;
3661 it
->dpvec_face_id
= -1;
3663 /* Remember the current face id in case glyphs specify faces.
3664 IT's face is restored in set_iterator_to_next.
3665 saved_face_id was set to preceding char's face in handle_stop. */
3666 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3667 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3669 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3675 /***********************************************************************
3677 ***********************************************************************/
3679 /* Set up iterator IT from `display' property at its current position.
3680 Called from handle_stop.
3681 We return HANDLED_RETURN if some part of the display property
3682 overrides the display of the buffer text itself.
3683 Otherwise we return HANDLED_NORMALLY. */
3685 static enum prop_handled
3686 handle_display_prop (it
)
3689 Lisp_Object prop
, object
;
3690 struct text_pos
*position
;
3691 /* Nonzero if some property replaces the display of the text itself. */
3692 int display_replaced_p
= 0;
3694 if (STRINGP (it
->string
))
3696 object
= it
->string
;
3697 position
= &it
->current
.string_pos
;
3701 XSETWINDOW (object
, it
->w
);
3702 position
= &it
->current
.pos
;
3705 /* Reset those iterator values set from display property values. */
3706 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3707 it
->space_width
= Qnil
;
3708 it
->font_height
= Qnil
;
3711 /* We don't support recursive `display' properties, i.e. string
3712 values that have a string `display' property, that have a string
3713 `display' property etc. */
3714 if (!it
->string_from_display_prop_p
)
3715 it
->area
= TEXT_AREA
;
3717 prop
= Fget_char_property (make_number (position
->charpos
),
3720 return HANDLED_NORMALLY
;
3722 if (!STRINGP (it
->string
))
3723 object
= it
->w
->buffer
;
3726 /* Simple properties. */
3727 && !EQ (XCAR (prop
), Qimage
)
3728 && !EQ (XCAR (prop
), Qspace
)
3729 && !EQ (XCAR (prop
), Qwhen
)
3730 && !EQ (XCAR (prop
), Qslice
)
3731 && !EQ (XCAR (prop
), Qspace_width
)
3732 && !EQ (XCAR (prop
), Qheight
)
3733 && !EQ (XCAR (prop
), Qraise
)
3734 /* Marginal area specifications. */
3735 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3736 && !EQ (XCAR (prop
), Qleft_fringe
)
3737 && !EQ (XCAR (prop
), Qright_fringe
)
3738 && !NILP (XCAR (prop
)))
3740 for (; CONSP (prop
); prop
= XCDR (prop
))
3742 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3743 position
, display_replaced_p
))
3744 display_replaced_p
= 1;
3747 else if (VECTORP (prop
))
3750 for (i
= 0; i
< ASIZE (prop
); ++i
)
3751 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3752 position
, display_replaced_p
))
3753 display_replaced_p
= 1;
3757 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3758 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3759 return HANDLED_RECOMPUTE_PROPS
;
3761 display_replaced_p
= 1;
3764 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3768 /* Value is the position of the end of the `display' property starting
3769 at START_POS in OBJECT. */
3771 static struct text_pos
3772 display_prop_end (it
, object
, start_pos
)
3775 struct text_pos start_pos
;
3778 struct text_pos end_pos
;
3780 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3781 Qdisplay
, object
, Qnil
);
3782 CHARPOS (end_pos
) = XFASTINT (end
);
3783 if (STRINGP (object
))
3784 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3786 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3792 /* Set up IT from a single `display' specification PROP. OBJECT
3793 is the object in which the `display' property was found. *POSITION
3794 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3795 means that we previously saw a display specification which already
3796 replaced text display with something else, for example an image;
3797 we ignore such properties after the first one has been processed.
3799 If PROP is a `space' or `image' specification, and in some other
3800 cases too, set *POSITION to the position where the `display'
3803 Value is non-zero if something was found which replaces the display
3804 of buffer or string text. Specifically, the value is -1 if that
3805 "something" is "nothing". */
3808 handle_single_display_spec (it
, spec
, object
, position
,
3809 display_replaced_before_p
)
3813 struct text_pos
*position
;
3814 int display_replaced_before_p
;
3817 Lisp_Object location
, value
;
3818 struct text_pos start_pos
;
3821 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3822 If the result is non-nil, use VALUE instead of SPEC. */
3824 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3833 if (!NILP (form
) && !EQ (form
, Qt
))
3835 int count
= SPECPDL_INDEX ();
3836 struct gcpro gcpro1
;
3838 /* Bind `object' to the object having the `display' property, a
3839 buffer or string. Bind `position' to the position in the
3840 object where the property was found, and `buffer-position'
3841 to the current position in the buffer. */
3842 specbind (Qobject
, object
);
3843 specbind (Qposition
, make_number (CHARPOS (*position
)));
3844 specbind (Qbuffer_position
,
3845 make_number (STRINGP (object
)
3846 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3848 form
= safe_eval (form
);
3850 unbind_to (count
, Qnil
);
3856 /* Handle `(height HEIGHT)' specifications. */
3858 && EQ (XCAR (spec
), Qheight
)
3859 && CONSP (XCDR (spec
)))
3861 if (!FRAME_WINDOW_P (it
->f
))
3864 it
->font_height
= XCAR (XCDR (spec
));
3865 if (!NILP (it
->font_height
))
3867 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3868 int new_height
= -1;
3870 if (CONSP (it
->font_height
)
3871 && (EQ (XCAR (it
->font_height
), Qplus
)
3872 || EQ (XCAR (it
->font_height
), Qminus
))
3873 && CONSP (XCDR (it
->font_height
))
3874 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3876 /* `(+ N)' or `(- N)' where N is an integer. */
3877 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3878 if (EQ (XCAR (it
->font_height
), Qplus
))
3880 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3882 else if (FUNCTIONP (it
->font_height
))
3884 /* Call function with current height as argument.
3885 Value is the new height. */
3887 height
= safe_call1 (it
->font_height
,
3888 face
->lface
[LFACE_HEIGHT_INDEX
]);
3889 if (NUMBERP (height
))
3890 new_height
= XFLOATINT (height
);
3892 else if (NUMBERP (it
->font_height
))
3894 /* Value is a multiple of the canonical char height. */
3897 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3898 new_height
= (XFLOATINT (it
->font_height
)
3899 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3903 /* Evaluate IT->font_height with `height' bound to the
3904 current specified height to get the new height. */
3905 int count
= SPECPDL_INDEX ();
3907 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3908 value
= safe_eval (it
->font_height
);
3909 unbind_to (count
, Qnil
);
3911 if (NUMBERP (value
))
3912 new_height
= XFLOATINT (value
);
3916 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3922 /* Handle `(space_width WIDTH)'. */
3924 && EQ (XCAR (spec
), Qspace_width
)
3925 && CONSP (XCDR (spec
)))
3927 if (!FRAME_WINDOW_P (it
->f
))
3930 value
= XCAR (XCDR (spec
));
3931 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3932 it
->space_width
= value
;
3937 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3939 && EQ (XCAR (spec
), Qslice
))
3943 if (!FRAME_WINDOW_P (it
->f
))
3946 if (tem
= XCDR (spec
), CONSP (tem
))
3948 it
->slice
.x
= XCAR (tem
);
3949 if (tem
= XCDR (tem
), CONSP (tem
))
3951 it
->slice
.y
= XCAR (tem
);
3952 if (tem
= XCDR (tem
), CONSP (tem
))
3954 it
->slice
.width
= XCAR (tem
);
3955 if (tem
= XCDR (tem
), CONSP (tem
))
3956 it
->slice
.height
= XCAR (tem
);
3964 /* Handle `(raise FACTOR)'. */
3966 && EQ (XCAR (spec
), Qraise
)
3967 && CONSP (XCDR (spec
)))
3969 if (!FRAME_WINDOW_P (it
->f
))
3972 #ifdef HAVE_WINDOW_SYSTEM
3973 value
= XCAR (XCDR (spec
));
3974 if (NUMBERP (value
))
3976 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3977 it
->voffset
= - (XFLOATINT (value
)
3978 * (FONT_HEIGHT (face
->font
)));
3980 #endif /* HAVE_WINDOW_SYSTEM */
3985 /* Don't handle the other kinds of display specifications
3986 inside a string that we got from a `display' property. */
3987 if (it
->string_from_display_prop_p
)
3990 /* Characters having this form of property are not displayed, so
3991 we have to find the end of the property. */
3992 start_pos
= *position
;
3993 *position
= display_prop_end (it
, object
, start_pos
);
3996 /* Stop the scan at that end position--we assume that all
3997 text properties change there. */
3998 it
->stop_charpos
= position
->charpos
;
4000 /* Handle `(left-fringe BITMAP [FACE])'
4001 and `(right-fringe BITMAP [FACE])'. */
4003 && (EQ (XCAR (spec
), Qleft_fringe
)
4004 || EQ (XCAR (spec
), Qright_fringe
))
4005 && CONSP (XCDR (spec
)))
4007 int face_id
= DEFAULT_FACE_ID
;
4010 if (!FRAME_WINDOW_P (it
->f
))
4011 /* If we return here, POSITION has been advanced
4012 across the text with this property. */
4015 #ifdef HAVE_WINDOW_SYSTEM
4016 value
= XCAR (XCDR (spec
));
4017 if (!SYMBOLP (value
)
4018 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4019 /* If we return here, POSITION has been advanced
4020 across the text with this property. */
4023 if (CONSP (XCDR (XCDR (spec
))))
4025 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4026 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4027 'A', FRINGE_FACE_ID
, 0);
4032 /* Save current settings of IT so that we can restore them
4033 when we are finished with the glyph property value. */
4037 it
->area
= TEXT_AREA
;
4038 it
->what
= IT_IMAGE
;
4039 it
->image_id
= -1; /* no image */
4040 it
->position
= start_pos
;
4041 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4042 it
->method
= GET_FROM_IMAGE
;
4043 it
->face_id
= face_id
;
4045 /* Say that we haven't consumed the characters with
4046 `display' property yet. The call to pop_it in
4047 set_iterator_to_next will clean this up. */
4048 *position
= start_pos
;
4050 if (EQ (XCAR (spec
), Qleft_fringe
))
4052 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4053 it
->left_user_fringe_face_id
= face_id
;
4057 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4058 it
->right_user_fringe_face_id
= face_id
;
4060 #endif /* HAVE_WINDOW_SYSTEM */
4064 /* Prepare to handle `((margin left-margin) ...)',
4065 `((margin right-margin) ...)' and `((margin nil) ...)'
4066 prefixes for display specifications. */
4067 location
= Qunbound
;
4068 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4072 value
= XCDR (spec
);
4074 value
= XCAR (value
);
4077 if (EQ (XCAR (tem
), Qmargin
)
4078 && (tem
= XCDR (tem
),
4079 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4081 || EQ (tem
, Qleft_margin
)
4082 || EQ (tem
, Qright_margin
))))
4086 if (EQ (location
, Qunbound
))
4092 /* After this point, VALUE is the property after any
4093 margin prefix has been stripped. It must be a string,
4094 an image specification, or `(space ...)'.
4096 LOCATION specifies where to display: `left-margin',
4097 `right-margin' or nil. */
4099 valid_p
= (STRINGP (value
)
4100 #ifdef HAVE_WINDOW_SYSTEM
4101 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4102 #endif /* not HAVE_WINDOW_SYSTEM */
4103 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4105 if (valid_p
&& !display_replaced_before_p
)
4107 /* Save current settings of IT so that we can restore them
4108 when we are finished with the glyph property value. */
4110 if (NILP (location
))
4111 it
->area
= TEXT_AREA
;
4112 else if (EQ (location
, Qleft_margin
))
4113 it
->area
= LEFT_MARGIN_AREA
;
4115 it
->area
= RIGHT_MARGIN_AREA
;
4117 if (STRINGP (value
))
4119 if (SCHARS (value
) == 0)
4122 return -1; /* Replaced by "", i.e. nothing. */
4125 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4126 it
->current
.overlay_string_index
= -1;
4127 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4128 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4129 it
->method
= GET_FROM_STRING
;
4130 it
->stop_charpos
= 0;
4131 it
->string_from_display_prop_p
= 1;
4132 /* Say that we haven't consumed the characters with
4133 `display' property yet. The call to pop_it in
4134 set_iterator_to_next will clean this up. */
4135 *position
= start_pos
;
4137 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4139 it
->method
= GET_FROM_STRETCH
;
4141 it
->current
.pos
= it
->position
= start_pos
;
4144 #ifdef HAVE_WINDOW_SYSTEM
4147 it
->what
= IT_IMAGE
;
4148 it
->image_id
= lookup_image (it
->f
, value
);
4149 it
->position
= start_pos
;
4150 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4151 it
->method
= GET_FROM_IMAGE
;
4153 /* Say that we haven't consumed the characters with
4154 `display' property yet. The call to pop_it in
4155 set_iterator_to_next will clean this up. */
4156 *position
= start_pos
;
4158 #endif /* HAVE_WINDOW_SYSTEM */
4163 /* Invalid property or property not supported. Restore
4164 POSITION to what it was before. */
4165 *position
= start_pos
;
4170 /* Check if SPEC is a display sub-property value whose text should be
4171 treated as intangible. */
4174 single_display_spec_intangible_p (prop
)
4177 /* Skip over `when FORM'. */
4178 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4192 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4193 we don't need to treat text as intangible. */
4194 if (EQ (XCAR (prop
), Qmargin
))
4202 || EQ (XCAR (prop
), Qleft_margin
)
4203 || EQ (XCAR (prop
), Qright_margin
))
4207 return (CONSP (prop
)
4208 && (EQ (XCAR (prop
), Qimage
)
4209 || EQ (XCAR (prop
), Qspace
)));
4213 /* Check if PROP is a display property value whose text should be
4214 treated as intangible. */
4217 display_prop_intangible_p (prop
)
4221 && CONSP (XCAR (prop
))
4222 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4224 /* A list of sub-properties. */
4225 while (CONSP (prop
))
4227 if (single_display_spec_intangible_p (XCAR (prop
)))
4232 else if (VECTORP (prop
))
4234 /* A vector of sub-properties. */
4236 for (i
= 0; i
< ASIZE (prop
); ++i
)
4237 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4241 return single_display_spec_intangible_p (prop
);
4247 /* Return 1 if PROP is a display sub-property value containing STRING. */
4250 single_display_spec_string_p (prop
, string
)
4251 Lisp_Object prop
, string
;
4253 if (EQ (string
, prop
))
4256 /* Skip over `when FORM'. */
4257 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4266 /* Skip over `margin LOCATION'. */
4267 if (EQ (XCAR (prop
), Qmargin
))
4278 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4282 /* Return 1 if STRING appears in the `display' property PROP. */
4285 display_prop_string_p (prop
, string
)
4286 Lisp_Object prop
, string
;
4289 && CONSP (XCAR (prop
))
4290 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4292 /* A list of sub-properties. */
4293 while (CONSP (prop
))
4295 if (single_display_spec_string_p (XCAR (prop
), string
))
4300 else if (VECTORP (prop
))
4302 /* A vector of sub-properties. */
4304 for (i
= 0; i
< ASIZE (prop
); ++i
)
4305 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4309 return single_display_spec_string_p (prop
, string
);
4315 /* Determine from which buffer position in W's buffer STRING comes
4316 from. AROUND_CHARPOS is an approximate position where it could
4317 be from. Value is the buffer position or 0 if it couldn't be
4320 W's buffer must be current.
4322 This function is necessary because we don't record buffer positions
4323 in glyphs generated from strings (to keep struct glyph small).
4324 This function may only use code that doesn't eval because it is
4325 called asynchronously from note_mouse_highlight. */
4328 string_buffer_position (w
, string
, around_charpos
)
4333 Lisp_Object limit
, prop
, pos
;
4334 const int MAX_DISTANCE
= 1000;
4337 pos
= make_number (around_charpos
);
4338 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4339 while (!found
&& !EQ (pos
, limit
))
4341 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4342 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4345 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4350 pos
= make_number (around_charpos
);
4351 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4352 while (!found
&& !EQ (pos
, limit
))
4354 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4355 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4358 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4363 return found
? XINT (pos
) : 0;
4368 /***********************************************************************
4369 `composition' property
4370 ***********************************************************************/
4372 /* Set up iterator IT from `composition' property at its current
4373 position. Called from handle_stop. */
4375 static enum prop_handled
4376 handle_composition_prop (it
)
4379 Lisp_Object prop
, string
;
4380 int pos
, pos_byte
, end
;
4381 enum prop_handled handled
= HANDLED_NORMALLY
;
4383 if (STRINGP (it
->string
))
4385 pos
= IT_STRING_CHARPOS (*it
);
4386 pos_byte
= IT_STRING_BYTEPOS (*it
);
4387 string
= it
->string
;
4391 pos
= IT_CHARPOS (*it
);
4392 pos_byte
= IT_BYTEPOS (*it
);
4396 /* If there's a valid composition and point is not inside of the
4397 composition (in the case that the composition is from the current
4398 buffer), draw a glyph composed from the composition components. */
4399 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4400 && COMPOSITION_VALID_P (pos
, end
, prop
)
4401 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4403 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4407 it
->method
= GET_FROM_COMPOSITION
;
4409 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4410 /* For a terminal, draw only the first character of the
4412 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4413 it
->len
= (STRINGP (it
->string
)
4414 ? string_char_to_byte (it
->string
, end
)
4415 : CHAR_TO_BYTE (end
)) - pos_byte
;
4416 it
->stop_charpos
= end
;
4417 handled
= HANDLED_RETURN
;
4426 /***********************************************************************
4428 ***********************************************************************/
4430 /* The following structure is used to record overlay strings for
4431 later sorting in load_overlay_strings. */
4433 struct overlay_entry
4435 Lisp_Object overlay
;
4442 /* Set up iterator IT from overlay strings at its current position.
4443 Called from handle_stop. */
4445 static enum prop_handled
4446 handle_overlay_change (it
)
4449 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4450 return HANDLED_RECOMPUTE_PROPS
;
4452 return HANDLED_NORMALLY
;
4456 /* Set up the next overlay string for delivery by IT, if there is an
4457 overlay string to deliver. Called by set_iterator_to_next when the
4458 end of the current overlay string is reached. If there are more
4459 overlay strings to display, IT->string and
4460 IT->current.overlay_string_index are set appropriately here.
4461 Otherwise IT->string is set to nil. */
4464 next_overlay_string (it
)
4467 ++it
->current
.overlay_string_index
;
4468 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4470 /* No more overlay strings. Restore IT's settings to what
4471 they were before overlay strings were processed, and
4472 continue to deliver from current_buffer. */
4473 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4476 xassert (it
->stop_charpos
>= BEGV
4477 && it
->stop_charpos
<= it
->end_charpos
);
4479 it
->current
.overlay_string_index
= -1;
4480 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4481 it
->n_overlay_strings
= 0;
4482 it
->method
= GET_FROM_BUFFER
;
4484 /* If we're at the end of the buffer, record that we have
4485 processed the overlay strings there already, so that
4486 next_element_from_buffer doesn't try it again. */
4487 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4488 it
->overlay_strings_at_end_processed_p
= 1;
4490 /* If we have to display `...' for invisible text, set
4491 the iterator up for that. */
4492 if (display_ellipsis_p
)
4493 setup_for_ellipsis (it
, 0);
4497 /* There are more overlay strings to process. If
4498 IT->current.overlay_string_index has advanced to a position
4499 where we must load IT->overlay_strings with more strings, do
4501 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4503 if (it
->current
.overlay_string_index
&& i
== 0)
4504 load_overlay_strings (it
, 0);
4506 /* Initialize IT to deliver display elements from the overlay
4508 it
->string
= it
->overlay_strings
[i
];
4509 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4510 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4511 it
->method
= GET_FROM_STRING
;
4512 it
->stop_charpos
= 0;
4519 /* Compare two overlay_entry structures E1 and E2. Used as a
4520 comparison function for qsort in load_overlay_strings. Overlay
4521 strings for the same position are sorted so that
4523 1. All after-strings come in front of before-strings, except
4524 when they come from the same overlay.
4526 2. Within after-strings, strings are sorted so that overlay strings
4527 from overlays with higher priorities come first.
4529 2. Within before-strings, strings are sorted so that overlay
4530 strings from overlays with higher priorities come last.
4532 Value is analogous to strcmp. */
4536 compare_overlay_entries (e1
, e2
)
4539 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4540 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4543 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4545 /* Let after-strings appear in front of before-strings if
4546 they come from different overlays. */
4547 if (EQ (entry1
->overlay
, entry2
->overlay
))
4548 result
= entry1
->after_string_p
? 1 : -1;
4550 result
= entry1
->after_string_p
? -1 : 1;
4552 else if (entry1
->after_string_p
)
4553 /* After-strings sorted in order of decreasing priority. */
4554 result
= entry2
->priority
- entry1
->priority
;
4556 /* Before-strings sorted in order of increasing priority. */
4557 result
= entry1
->priority
- entry2
->priority
;
4563 /* Load the vector IT->overlay_strings with overlay strings from IT's
4564 current buffer position, or from CHARPOS if that is > 0. Set
4565 IT->n_overlays to the total number of overlay strings found.
4567 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4568 a time. On entry into load_overlay_strings,
4569 IT->current.overlay_string_index gives the number of overlay
4570 strings that have already been loaded by previous calls to this
4573 IT->add_overlay_start contains an additional overlay start
4574 position to consider for taking overlay strings from, if non-zero.
4575 This position comes into play when the overlay has an `invisible'
4576 property, and both before and after-strings. When we've skipped to
4577 the end of the overlay, because of its `invisible' property, we
4578 nevertheless want its before-string to appear.
4579 IT->add_overlay_start will contain the overlay start position
4582 Overlay strings are sorted so that after-string strings come in
4583 front of before-string strings. Within before and after-strings,
4584 strings are sorted by overlay priority. See also function
4585 compare_overlay_entries. */
4588 load_overlay_strings (it
, charpos
)
4592 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4593 Lisp_Object overlay
, window
, str
, invisible
;
4594 struct Lisp_Overlay
*ov
;
4597 int n
= 0, i
, j
, invis_p
;
4598 struct overlay_entry
*entries
4599 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4602 charpos
= IT_CHARPOS (*it
);
4604 /* Append the overlay string STRING of overlay OVERLAY to vector
4605 `entries' which has size `size' and currently contains `n'
4606 elements. AFTER_P non-zero means STRING is an after-string of
4608 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4611 Lisp_Object priority; \
4615 int new_size = 2 * size; \
4616 struct overlay_entry *old = entries; \
4618 (struct overlay_entry *) alloca (new_size \
4619 * sizeof *entries); \
4620 bcopy (old, entries, size * sizeof *entries); \
4624 entries[n].string = (STRING); \
4625 entries[n].overlay = (OVERLAY); \
4626 priority = Foverlay_get ((OVERLAY), Qpriority); \
4627 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4628 entries[n].after_string_p = (AFTER_P); \
4633 /* Process overlay before the overlay center. */
4634 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4636 XSETMISC (overlay
, ov
);
4637 xassert (OVERLAYP (overlay
));
4638 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4639 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4644 /* Skip this overlay if it doesn't start or end at IT's current
4646 if (end
!= charpos
&& start
!= charpos
)
4649 /* Skip this overlay if it doesn't apply to IT->w. */
4650 window
= Foverlay_get (overlay
, Qwindow
);
4651 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4654 /* If the text ``under'' the overlay is invisible, both before-
4655 and after-strings from this overlay are visible; start and
4656 end position are indistinguishable. */
4657 invisible
= Foverlay_get (overlay
, Qinvisible
);
4658 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4660 /* If overlay has a non-empty before-string, record it. */
4661 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4662 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4664 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4666 /* If overlay has a non-empty after-string, record it. */
4667 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4668 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4670 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4673 /* Process overlays after the overlay center. */
4674 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4676 XSETMISC (overlay
, ov
);
4677 xassert (OVERLAYP (overlay
));
4678 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4679 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4681 if (start
> charpos
)
4684 /* Skip this overlay if it doesn't start or end at IT's current
4686 if (end
!= charpos
&& start
!= charpos
)
4689 /* Skip this overlay if it doesn't apply to IT->w. */
4690 window
= Foverlay_get (overlay
, Qwindow
);
4691 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4694 /* If the text ``under'' the overlay is invisible, it has a zero
4695 dimension, and both before- and after-strings apply. */
4696 invisible
= Foverlay_get (overlay
, Qinvisible
);
4697 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4699 /* If overlay has a non-empty before-string, record it. */
4700 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4701 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4703 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4705 /* If overlay has a non-empty after-string, record it. */
4706 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4707 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4709 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4712 #undef RECORD_OVERLAY_STRING
4716 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4718 /* Record the total number of strings to process. */
4719 it
->n_overlay_strings
= n
;
4721 /* IT->current.overlay_string_index is the number of overlay strings
4722 that have already been consumed by IT. Copy some of the
4723 remaining overlay strings to IT->overlay_strings. */
4725 j
= it
->current
.overlay_string_index
;
4726 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4727 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4733 /* Get the first chunk of overlay strings at IT's current buffer
4734 position, or at CHARPOS if that is > 0. Value is non-zero if at
4735 least one overlay string was found. */
4738 get_overlay_strings (it
, charpos
)
4742 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4743 process. This fills IT->overlay_strings with strings, and sets
4744 IT->n_overlay_strings to the total number of strings to process.
4745 IT->pos.overlay_string_index has to be set temporarily to zero
4746 because load_overlay_strings needs this; it must be set to -1
4747 when no overlay strings are found because a zero value would
4748 indicate a position in the first overlay string. */
4749 it
->current
.overlay_string_index
= 0;
4750 load_overlay_strings (it
, charpos
);
4752 /* If we found overlay strings, set up IT to deliver display
4753 elements from the first one. Otherwise set up IT to deliver
4754 from current_buffer. */
4755 if (it
->n_overlay_strings
)
4757 /* Make sure we know settings in current_buffer, so that we can
4758 restore meaningful values when we're done with the overlay
4760 compute_stop_pos (it
);
4761 xassert (it
->face_id
>= 0);
4763 /* Save IT's settings. They are restored after all overlay
4764 strings have been processed. */
4765 xassert (it
->sp
== 0);
4768 /* Set up IT to deliver display elements from the first overlay
4770 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4771 it
->string
= it
->overlay_strings
[0];
4772 it
->stop_charpos
= 0;
4773 xassert (STRINGP (it
->string
));
4774 it
->end_charpos
= SCHARS (it
->string
);
4775 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4776 it
->method
= GET_FROM_STRING
;
4781 it
->current
.overlay_string_index
= -1;
4782 it
->method
= GET_FROM_BUFFER
;
4787 /* Value is non-zero if we found at least one overlay string. */
4788 return STRINGP (it
->string
);
4793 /***********************************************************************
4794 Saving and restoring state
4795 ***********************************************************************/
4797 /* Save current settings of IT on IT->stack. Called, for example,
4798 before setting up IT for an overlay string, to be able to restore
4799 IT's settings to what they were after the overlay string has been
4806 struct iterator_stack_entry
*p
;
4808 xassert (it
->sp
< 2);
4809 p
= it
->stack
+ it
->sp
;
4811 p
->stop_charpos
= it
->stop_charpos
;
4812 xassert (it
->face_id
>= 0);
4813 p
->face_id
= it
->face_id
;
4814 p
->string
= it
->string
;
4815 p
->pos
= it
->current
;
4816 p
->end_charpos
= it
->end_charpos
;
4817 p
->string_nchars
= it
->string_nchars
;
4819 p
->multibyte_p
= it
->multibyte_p
;
4820 p
->slice
= it
->slice
;
4821 p
->space_width
= it
->space_width
;
4822 p
->font_height
= it
->font_height
;
4823 p
->voffset
= it
->voffset
;
4824 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4825 p
->display_ellipsis_p
= 0;
4830 /* Restore IT's settings from IT->stack. Called, for example, when no
4831 more overlay strings must be processed, and we return to delivering
4832 display elements from a buffer, or when the end of a string from a
4833 `display' property is reached and we return to delivering display
4834 elements from an overlay string, or from a buffer. */
4840 struct iterator_stack_entry
*p
;
4842 xassert (it
->sp
> 0);
4844 p
= it
->stack
+ it
->sp
;
4845 it
->stop_charpos
= p
->stop_charpos
;
4846 it
->face_id
= p
->face_id
;
4847 it
->string
= p
->string
;
4848 it
->current
= p
->pos
;
4849 it
->end_charpos
= p
->end_charpos
;
4850 it
->string_nchars
= p
->string_nchars
;
4852 it
->multibyte_p
= p
->multibyte_p
;
4853 it
->slice
= p
->slice
;
4854 it
->space_width
= p
->space_width
;
4855 it
->font_height
= p
->font_height
;
4856 it
->voffset
= p
->voffset
;
4857 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4862 /***********************************************************************
4864 ***********************************************************************/
4866 /* Set IT's current position to the previous line start. */
4869 back_to_previous_line_start (it
)
4872 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4873 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4877 /* Move IT to the next line start.
4879 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4880 we skipped over part of the text (as opposed to moving the iterator
4881 continuously over the text). Otherwise, don't change the value
4884 Newlines may come from buffer text, overlay strings, or strings
4885 displayed via the `display' property. That's the reason we can't
4886 simply use find_next_newline_no_quit.
4888 Note that this function may not skip over invisible text that is so
4889 because of text properties and immediately follows a newline. If
4890 it would, function reseat_at_next_visible_line_start, when called
4891 from set_iterator_to_next, would effectively make invisible
4892 characters following a newline part of the wrong glyph row, which
4893 leads to wrong cursor motion. */
4896 forward_to_next_line_start (it
, skipped_p
)
4900 int old_selective
, newline_found_p
, n
;
4901 const int MAX_NEWLINE_DISTANCE
= 500;
4903 /* If already on a newline, just consume it to avoid unintended
4904 skipping over invisible text below. */
4905 if (it
->what
== IT_CHARACTER
4907 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4909 set_iterator_to_next (it
, 0);
4914 /* Don't handle selective display in the following. It's (a)
4915 unnecessary because it's done by the caller, and (b) leads to an
4916 infinite recursion because next_element_from_ellipsis indirectly
4917 calls this function. */
4918 old_selective
= it
->selective
;
4921 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4922 from buffer text. */
4923 for (n
= newline_found_p
= 0;
4924 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4925 n
+= STRINGP (it
->string
) ? 0 : 1)
4927 if (!get_next_display_element (it
))
4929 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4930 set_iterator_to_next (it
, 0);
4933 /* If we didn't find a newline near enough, see if we can use a
4935 if (!newline_found_p
)
4937 int start
= IT_CHARPOS (*it
);
4938 int limit
= find_next_newline_no_quit (start
, 1);
4941 xassert (!STRINGP (it
->string
));
4943 /* If there isn't any `display' property in sight, and no
4944 overlays, we can just use the position of the newline in
4946 if (it
->stop_charpos
>= limit
4947 || ((pos
= Fnext_single_property_change (make_number (start
),
4949 Qnil
, make_number (limit
)),
4951 && next_overlay_change (start
) == ZV
))
4953 IT_CHARPOS (*it
) = limit
;
4954 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4955 *skipped_p
= newline_found_p
= 1;
4959 while (get_next_display_element (it
)
4960 && !newline_found_p
)
4962 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4963 set_iterator_to_next (it
, 0);
4968 it
->selective
= old_selective
;
4969 return newline_found_p
;
4973 /* Set IT's current position to the previous visible line start. Skip
4974 invisible text that is so either due to text properties or due to
4975 selective display. Caution: this does not change IT->current_x and
4979 back_to_previous_visible_line_start (it
)
4982 while (IT_CHARPOS (*it
) > BEGV
)
4984 back_to_previous_line_start (it
);
4985 if (IT_CHARPOS (*it
) <= BEGV
)
4988 /* If selective > 0, then lines indented more than that values
4990 if (it
->selective
> 0
4991 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4992 (double) it
->selective
)) /* iftc */
4995 /* Check the newline before point for invisibility. */
4998 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
4999 Qinvisible
, it
->window
);
5000 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5004 /* If newline has a display property that replaces the newline with something
5005 else (image or text), find start of overlay or interval and continue search
5007 if (IT_CHARPOS (*it
) > BEGV
)
5009 struct it it2
= *it
;
5012 Lisp_Object val
, overlay
;
5014 pos
= --IT_CHARPOS (it2
);
5017 if (handle_display_prop (&it2
) == HANDLED_RETURN
5018 && !NILP (val
= get_char_property_and_overlay
5019 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5020 && (OVERLAYP (overlay
)
5021 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5022 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5026 IT_CHARPOS (*it
) = beg
;
5027 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5035 xassert (IT_CHARPOS (*it
) >= BEGV
);
5036 xassert (IT_CHARPOS (*it
) == BEGV
5037 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5042 /* Reseat iterator IT at the previous visible line start. Skip
5043 invisible text that is so either due to text properties or due to
5044 selective display. At the end, update IT's overlay information,
5045 face information etc. */
5048 reseat_at_previous_visible_line_start (it
)
5051 back_to_previous_visible_line_start (it
);
5052 reseat (it
, it
->current
.pos
, 1);
5057 /* Reseat iterator IT on the next visible line start in the current
5058 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5059 preceding the line start. Skip over invisible text that is so
5060 because of selective display. Compute faces, overlays etc at the
5061 new position. Note that this function does not skip over text that
5062 is invisible because of text properties. */
5065 reseat_at_next_visible_line_start (it
, on_newline_p
)
5069 int newline_found_p
, skipped_p
= 0;
5071 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5073 /* Skip over lines that are invisible because they are indented
5074 more than the value of IT->selective. */
5075 if (it
->selective
> 0)
5076 while (IT_CHARPOS (*it
) < ZV
5077 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5078 (double) it
->selective
)) /* iftc */
5080 xassert (IT_BYTEPOS (*it
) == BEGV
5081 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5082 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5085 /* Position on the newline if that's what's requested. */
5086 if (on_newline_p
&& newline_found_p
)
5088 if (STRINGP (it
->string
))
5090 if (IT_STRING_CHARPOS (*it
) > 0)
5092 --IT_STRING_CHARPOS (*it
);
5093 --IT_STRING_BYTEPOS (*it
);
5096 else if (IT_CHARPOS (*it
) > BEGV
)
5100 reseat (it
, it
->current
.pos
, 0);
5104 reseat (it
, it
->current
.pos
, 0);
5111 /***********************************************************************
5112 Changing an iterator's position
5113 ***********************************************************************/
5115 /* Change IT's current position to POS in current_buffer. If FORCE_P
5116 is non-zero, always check for text properties at the new position.
5117 Otherwise, text properties are only looked up if POS >=
5118 IT->check_charpos of a property. */
5121 reseat (it
, pos
, force_p
)
5123 struct text_pos pos
;
5126 int original_pos
= IT_CHARPOS (*it
);
5128 reseat_1 (it
, pos
, 0);
5130 /* Determine where to check text properties. Avoid doing it
5131 where possible because text property lookup is very expensive. */
5133 || CHARPOS (pos
) > it
->stop_charpos
5134 || CHARPOS (pos
) < original_pos
)
5141 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5142 IT->stop_pos to POS, also. */
5145 reseat_1 (it
, pos
, set_stop_p
)
5147 struct text_pos pos
;
5150 /* Don't call this function when scanning a C string. */
5151 xassert (it
->s
== NULL
);
5153 /* POS must be a reasonable value. */
5154 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5156 it
->current
.pos
= it
->position
= pos
;
5157 XSETBUFFER (it
->object
, current_buffer
);
5158 it
->end_charpos
= ZV
;
5160 it
->current
.dpvec_index
= -1;
5161 it
->current
.overlay_string_index
= -1;
5162 IT_STRING_CHARPOS (*it
) = -1;
5163 IT_STRING_BYTEPOS (*it
) = -1;
5165 it
->method
= GET_FROM_BUFFER
;
5166 /* RMS: I added this to fix a bug in move_it_vertically_backward
5167 where it->area continued to relate to the starting point
5168 for the backward motion. Bug report from
5169 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
5170 However, I am not sure whether reseat still does the right thing
5171 in general after this change. */
5172 it
->area
= TEXT_AREA
;
5173 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5175 it
->face_before_selective_p
= 0;
5178 it
->stop_charpos
= CHARPOS (pos
);
5182 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5183 If S is non-null, it is a C string to iterate over. Otherwise,
5184 STRING gives a Lisp string to iterate over.
5186 If PRECISION > 0, don't return more then PRECISION number of
5187 characters from the string.
5189 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5190 characters have been returned. FIELD_WIDTH < 0 means an infinite
5193 MULTIBYTE = 0 means disable processing of multibyte characters,
5194 MULTIBYTE > 0 means enable it,
5195 MULTIBYTE < 0 means use IT->multibyte_p.
5197 IT must be initialized via a prior call to init_iterator before
5198 calling this function. */
5201 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5206 int precision
, field_width
, multibyte
;
5208 /* No region in strings. */
5209 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5211 /* No text property checks performed by default, but see below. */
5212 it
->stop_charpos
= -1;
5214 /* Set iterator position and end position. */
5215 bzero (&it
->current
, sizeof it
->current
);
5216 it
->current
.overlay_string_index
= -1;
5217 it
->current
.dpvec_index
= -1;
5218 xassert (charpos
>= 0);
5220 /* If STRING is specified, use its multibyteness, otherwise use the
5221 setting of MULTIBYTE, if specified. */
5223 it
->multibyte_p
= multibyte
> 0;
5227 xassert (STRINGP (string
));
5228 it
->string
= string
;
5230 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5231 it
->method
= GET_FROM_STRING
;
5232 it
->current
.string_pos
= string_pos (charpos
, string
);
5239 /* Note that we use IT->current.pos, not it->current.string_pos,
5240 for displaying C strings. */
5241 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5242 if (it
->multibyte_p
)
5244 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5245 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5249 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5250 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5253 it
->method
= GET_FROM_C_STRING
;
5256 /* PRECISION > 0 means don't return more than PRECISION characters
5258 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5259 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5261 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5262 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5263 FIELD_WIDTH < 0 means infinite field width. This is useful for
5264 padding with `-' at the end of a mode line. */
5265 if (field_width
< 0)
5266 field_width
= INFINITY
;
5267 if (field_width
> it
->end_charpos
- charpos
)
5268 it
->end_charpos
= charpos
+ field_width
;
5270 /* Use the standard display table for displaying strings. */
5271 if (DISP_TABLE_P (Vstandard_display_table
))
5272 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5274 it
->stop_charpos
= charpos
;
5280 /***********************************************************************
5282 ***********************************************************************/
5284 /* Map enum it_method value to corresponding next_element_from_* function. */
5286 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5288 next_element_from_buffer
,
5289 next_element_from_display_vector
,
5290 next_element_from_composition
,
5291 next_element_from_string
,
5292 next_element_from_c_string
,
5293 next_element_from_image
,
5294 next_element_from_stretch
5298 /* Load IT's display element fields with information about the next
5299 display element from the current position of IT. Value is zero if
5300 end of buffer (or C string) is reached. */
5303 get_next_display_element (it
)
5306 /* Non-zero means that we found a display element. Zero means that
5307 we hit the end of what we iterate over. Performance note: the
5308 function pointer `method' used here turns out to be faster than
5309 using a sequence of if-statements. */
5313 success_p
= (*get_next_element
[it
->method
]) (it
);
5315 if (it
->what
== IT_CHARACTER
)
5317 /* Map via display table or translate control characters.
5318 IT->c, IT->len etc. have been set to the next character by
5319 the function call above. If we have a display table, and it
5320 contains an entry for IT->c, translate it. Don't do this if
5321 IT->c itself comes from a display table, otherwise we could
5322 end up in an infinite recursion. (An alternative could be to
5323 count the recursion depth of this function and signal an
5324 error when a certain maximum depth is reached.) Is it worth
5326 if (success_p
&& it
->dpvec
== NULL
)
5331 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5334 struct Lisp_Vector
*v
= XVECTOR (dv
);
5336 /* Return the first character from the display table
5337 entry, if not empty. If empty, don't display the
5338 current character. */
5341 it
->dpvec_char_len
= it
->len
;
5342 it
->dpvec
= v
->contents
;
5343 it
->dpend
= v
->contents
+ v
->size
;
5344 it
->current
.dpvec_index
= 0;
5345 it
->dpvec_face_id
= -1;
5346 it
->saved_face_id
= it
->face_id
;
5347 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5352 set_iterator_to_next (it
, 0);
5357 /* Translate control characters into `\003' or `^C' form.
5358 Control characters coming from a display table entry are
5359 currently not translated because we use IT->dpvec to hold
5360 the translation. This could easily be changed but I
5361 don't believe that it is worth doing.
5363 If it->multibyte_p is nonzero, eight-bit characters and
5364 non-printable multibyte characters are also translated to
5367 If it->multibyte_p is zero, eight-bit characters that
5368 don't have corresponding multibyte char code are also
5369 translated to octal form. */
5370 else if ((it
->c
< ' '
5371 && (it
->area
!= TEXT_AREA
5372 /* In mode line, treat \n like other crl chars. */
5374 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5375 || (it
->c
!= '\n' && it
->c
!= '\t')))
5379 || !CHAR_PRINTABLE_P (it
->c
)
5380 || (!NILP (Vnobreak_char_display
)
5381 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5382 || it
->c
== 0x920 || it
->c
== 0x92d
5383 || it
->c
== 0xe20 || it
->c
== 0xe2d
5384 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5386 && (!unibyte_display_via_language_environment
5387 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5389 /* IT->c is a control character which must be displayed
5390 either as '\003' or as `^C' where the '\\' and '^'
5391 can be defined in the display table. Fill
5392 IT->ctl_chars with glyphs for what we have to
5393 display. Then, set IT->dpvec to these glyphs. */
5396 int face_id
, lface_id
= 0 ;
5399 /* Handle control characters with ^. */
5401 if (it
->c
< 128 && it
->ctl_arrow_p
)
5403 g
= '^'; /* default glyph for Control */
5404 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5406 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5407 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5409 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5410 lface_id
= FAST_GLYPH_FACE (g
);
5414 g
= FAST_GLYPH_CHAR (g
);
5415 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5420 /* Merge the escape-glyph face into the current face. */
5421 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5425 XSETINT (it
->ctl_chars
[0], g
);
5427 XSETINT (it
->ctl_chars
[1], g
);
5429 goto display_control
;
5432 /* Handle non-break space in the mode where it only gets
5435 if (EQ (Vnobreak_char_display
, Qt
)
5436 && (it
->c
== 0x8a0 || it
->c
== 0x920
5437 || it
->c
== 0xe20 || it
->c
== 0xf20))
5439 /* Merge the no-break-space face into the current face. */
5440 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5444 XSETINT (it
->ctl_chars
[0], g
);
5446 goto display_control
;
5449 /* Handle sequences that start with the "escape glyph". */
5451 /* the default escape glyph is \. */
5452 escape_glyph
= '\\';
5455 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5456 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5458 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5459 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5463 /* The display table specified a face.
5464 Merge it into face_id and also into escape_glyph. */
5465 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5466 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5471 /* Merge the escape-glyph face into the current face. */
5472 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5476 /* Handle soft hyphens in the mode where they only get
5479 if (EQ (Vnobreak_char_display
, Qt
)
5480 && (it
->c
== 0x8ad || it
->c
== 0x92d
5481 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5484 XSETINT (it
->ctl_chars
[0], g
);
5486 goto display_control
;
5489 /* Handle non-break space and soft hyphen
5490 with the escape glyph. */
5492 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5493 || it
->c
== 0x920 || it
->c
== 0x92d
5494 || it
->c
== 0xe20 || it
->c
== 0xe2d
5495 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5497 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5498 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5499 XSETINT (it
->ctl_chars
[1], g
);
5501 goto display_control
;
5505 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5509 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5510 if (SINGLE_BYTE_CHAR_P (it
->c
))
5511 str
[0] = it
->c
, len
= 1;
5514 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5517 /* It's an invalid character, which shouldn't
5518 happen actually, but due to bugs it may
5519 happen. Let's print the char as is, there's
5520 not much meaningful we can do with it. */
5522 str
[1] = it
->c
>> 8;
5523 str
[2] = it
->c
>> 16;
5524 str
[3] = it
->c
>> 24;
5529 for (i
= 0; i
< len
; i
++)
5531 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5532 /* Insert three more glyphs into IT->ctl_chars for
5533 the octal display of the character. */
5534 g
= ((str
[i
] >> 6) & 7) + '0';
5535 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5536 g
= ((str
[i
] >> 3) & 7) + '0';
5537 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5538 g
= (str
[i
] & 7) + '0';
5539 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5545 /* Set up IT->dpvec and return first character from it. */
5546 it
->dpvec_char_len
= it
->len
;
5547 it
->dpvec
= it
->ctl_chars
;
5548 it
->dpend
= it
->dpvec
+ ctl_len
;
5549 it
->current
.dpvec_index
= 0;
5550 it
->dpvec_face_id
= face_id
;
5551 it
->saved_face_id
= it
->face_id
;
5552 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5558 /* Adjust face id for a multibyte character. There are no
5559 multibyte character in unibyte text. */
5562 && FRAME_WINDOW_P (it
->f
))
5564 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5565 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5569 /* Is this character the last one of a run of characters with
5570 box? If yes, set IT->end_of_box_run_p to 1. */
5577 it
->end_of_box_run_p
5578 = ((face_id
= face_after_it_pos (it
),
5579 face_id
!= it
->face_id
)
5580 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5581 face
->box
== FACE_NO_BOX
));
5584 /* Value is 0 if end of buffer or string reached. */
5589 /* Move IT to the next display element.
5591 RESEAT_P non-zero means if called on a newline in buffer text,
5592 skip to the next visible line start.
5594 Functions get_next_display_element and set_iterator_to_next are
5595 separate because I find this arrangement easier to handle than a
5596 get_next_display_element function that also increments IT's
5597 position. The way it is we can first look at an iterator's current
5598 display element, decide whether it fits on a line, and if it does,
5599 increment the iterator position. The other way around we probably
5600 would either need a flag indicating whether the iterator has to be
5601 incremented the next time, or we would have to implement a
5602 decrement position function which would not be easy to write. */
5605 set_iterator_to_next (it
, reseat_p
)
5609 /* Reset flags indicating start and end of a sequence of characters
5610 with box. Reset them at the start of this function because
5611 moving the iterator to a new position might set them. */
5612 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5616 case GET_FROM_BUFFER
:
5617 /* The current display element of IT is a character from
5618 current_buffer. Advance in the buffer, and maybe skip over
5619 invisible lines that are so because of selective display. */
5620 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5621 reseat_at_next_visible_line_start (it
, 0);
5624 xassert (it
->len
!= 0);
5625 IT_BYTEPOS (*it
) += it
->len
;
5626 IT_CHARPOS (*it
) += 1;
5627 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5631 case GET_FROM_COMPOSITION
:
5632 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5633 if (STRINGP (it
->string
))
5635 IT_STRING_BYTEPOS (*it
) += it
->len
;
5636 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5637 it
->method
= GET_FROM_STRING
;
5638 goto consider_string_end
;
5642 IT_BYTEPOS (*it
) += it
->len
;
5643 IT_CHARPOS (*it
) += it
->cmp_len
;
5644 it
->method
= GET_FROM_BUFFER
;
5648 case GET_FROM_C_STRING
:
5649 /* Current display element of IT is from a C string. */
5650 IT_BYTEPOS (*it
) += it
->len
;
5651 IT_CHARPOS (*it
) += 1;
5654 case GET_FROM_DISPLAY_VECTOR
:
5655 /* Current display element of IT is from a display table entry.
5656 Advance in the display table definition. Reset it to null if
5657 end reached, and continue with characters from buffers/
5659 ++it
->current
.dpvec_index
;
5661 /* Restore face of the iterator to what they were before the
5662 display vector entry (these entries may contain faces). */
5663 it
->face_id
= it
->saved_face_id
;
5665 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5668 it
->method
= GET_FROM_C_STRING
;
5669 else if (STRINGP (it
->string
))
5670 it
->method
= GET_FROM_STRING
;
5672 it
->method
= GET_FROM_BUFFER
;
5675 it
->current
.dpvec_index
= -1;
5677 /* Skip over characters which were displayed via IT->dpvec. */
5678 if (it
->dpvec_char_len
< 0)
5679 reseat_at_next_visible_line_start (it
, 1);
5680 else if (it
->dpvec_char_len
> 0)
5682 if (it
->method
== GET_FROM_STRING
5683 && it
->n_overlay_strings
> 0)
5684 it
->ignore_overlay_strings_at_pos_p
= 1;
5685 it
->len
= it
->dpvec_char_len
;
5686 set_iterator_to_next (it
, reseat_p
);
5689 /* Recheck faces after display vector */
5690 it
->stop_charpos
= IT_CHARPOS (*it
);
5694 case GET_FROM_STRING
:
5695 /* Current display element is a character from a Lisp string. */
5696 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5697 IT_STRING_BYTEPOS (*it
) += it
->len
;
5698 IT_STRING_CHARPOS (*it
) += 1;
5700 consider_string_end
:
5702 if (it
->current
.overlay_string_index
>= 0)
5704 /* IT->string is an overlay string. Advance to the
5705 next, if there is one. */
5706 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5707 next_overlay_string (it
);
5711 /* IT->string is not an overlay string. If we reached
5712 its end, and there is something on IT->stack, proceed
5713 with what is on the stack. This can be either another
5714 string, this time an overlay string, or a buffer. */
5715 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5719 if (STRINGP (it
->string
))
5720 goto consider_string_end
;
5721 it
->method
= GET_FROM_BUFFER
;
5726 case GET_FROM_IMAGE
:
5727 case GET_FROM_STRETCH
:
5728 /* The position etc with which we have to proceed are on
5729 the stack. The position may be at the end of a string,
5730 if the `display' property takes up the whole string. */
5731 xassert (it
->sp
> 0);
5734 if (STRINGP (it
->string
))
5736 it
->method
= GET_FROM_STRING
;
5737 goto consider_string_end
;
5739 it
->method
= GET_FROM_BUFFER
;
5743 /* There are no other methods defined, so this should be a bug. */
5747 xassert (it
->method
!= GET_FROM_STRING
5748 || (STRINGP (it
->string
)
5749 && IT_STRING_CHARPOS (*it
) >= 0));
5752 /* Load IT's display element fields with information about the next
5753 display element which comes from a display table entry or from the
5754 result of translating a control character to one of the forms `^C'
5757 IT->dpvec holds the glyphs to return as characters.
5758 IT->saved_face_id holds the face id before the display vector--
5759 it is restored into IT->face_idin set_iterator_to_next. */
5762 next_element_from_display_vector (it
)
5766 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5768 it
->face_id
= it
->saved_face_id
;
5770 if (INTEGERP (*it
->dpvec
)
5771 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5775 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5776 it
->c
= FAST_GLYPH_CHAR (g
);
5777 it
->len
= CHAR_BYTES (it
->c
);
5779 /* The entry may contain a face id to use. Such a face id is
5780 the id of a Lisp face, not a realized face. A face id of
5781 zero means no face is specified. */
5782 if (it
->dpvec_face_id
>= 0)
5783 it
->face_id
= it
->dpvec_face_id
;
5786 int lface_id
= FAST_GLYPH_FACE (g
);
5788 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5793 /* Display table entry is invalid. Return a space. */
5794 it
->c
= ' ', it
->len
= 1;
5796 /* Don't change position and object of the iterator here. They are
5797 still the values of the character that had this display table
5798 entry or was translated, and that's what we want. */
5799 it
->what
= IT_CHARACTER
;
5804 /* Load IT with the next display element from Lisp string IT->string.
5805 IT->current.string_pos is the current position within the string.
5806 If IT->current.overlay_string_index >= 0, the Lisp string is an
5810 next_element_from_string (it
)
5813 struct text_pos position
;
5815 xassert (STRINGP (it
->string
));
5816 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5817 position
= it
->current
.string_pos
;
5819 /* Time to check for invisible text? */
5820 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5821 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5825 /* Since a handler may have changed IT->method, we must
5827 return get_next_display_element (it
);
5830 if (it
->current
.overlay_string_index
>= 0)
5832 /* Get the next character from an overlay string. In overlay
5833 strings, There is no field width or padding with spaces to
5835 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5840 else if (STRING_MULTIBYTE (it
->string
))
5842 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5843 const unsigned char *s
= (SDATA (it
->string
)
5844 + IT_STRING_BYTEPOS (*it
));
5845 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5849 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5855 /* Get the next character from a Lisp string that is not an
5856 overlay string. Such strings come from the mode line, for
5857 example. We may have to pad with spaces, or truncate the
5858 string. See also next_element_from_c_string. */
5859 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5864 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5866 /* Pad with spaces. */
5867 it
->c
= ' ', it
->len
= 1;
5868 CHARPOS (position
) = BYTEPOS (position
) = -1;
5870 else if (STRING_MULTIBYTE (it
->string
))
5872 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5873 const unsigned char *s
= (SDATA (it
->string
)
5874 + IT_STRING_BYTEPOS (*it
));
5875 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5879 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5884 /* Record what we have and where it came from. Note that we store a
5885 buffer position in IT->position although it could arguably be a
5887 it
->what
= IT_CHARACTER
;
5888 it
->object
= it
->string
;
5889 it
->position
= position
;
5894 /* Load IT with next display element from C string IT->s.
5895 IT->string_nchars is the maximum number of characters to return
5896 from the string. IT->end_charpos may be greater than
5897 IT->string_nchars when this function is called, in which case we
5898 may have to return padding spaces. Value is zero if end of string
5899 reached, including padding spaces. */
5902 next_element_from_c_string (it
)
5908 it
->what
= IT_CHARACTER
;
5909 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5912 /* IT's position can be greater IT->string_nchars in case a field
5913 width or precision has been specified when the iterator was
5915 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5917 /* End of the game. */
5921 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5923 /* Pad with spaces. */
5924 it
->c
= ' ', it
->len
= 1;
5925 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5927 else if (it
->multibyte_p
)
5929 /* Implementation note: The calls to strlen apparently aren't a
5930 performance problem because there is no noticeable performance
5931 difference between Emacs running in unibyte or multibyte mode. */
5932 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5933 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5937 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5943 /* Set up IT to return characters from an ellipsis, if appropriate.
5944 The definition of the ellipsis glyphs may come from a display table
5945 entry. This function Fills IT with the first glyph from the
5946 ellipsis if an ellipsis is to be displayed. */
5949 next_element_from_ellipsis (it
)
5952 if (it
->selective_display_ellipsis_p
)
5953 setup_for_ellipsis (it
, it
->len
);
5956 /* The face at the current position may be different from the
5957 face we find after the invisible text. Remember what it
5958 was in IT->saved_face_id, and signal that it's there by
5959 setting face_before_selective_p. */
5960 it
->saved_face_id
= it
->face_id
;
5961 it
->method
= GET_FROM_BUFFER
;
5962 reseat_at_next_visible_line_start (it
, 1);
5963 it
->face_before_selective_p
= 1;
5966 return get_next_display_element (it
);
5970 /* Deliver an image display element. The iterator IT is already
5971 filled with image information (done in handle_display_prop). Value
5976 next_element_from_image (it
)
5979 it
->what
= IT_IMAGE
;
5984 /* Fill iterator IT with next display element from a stretch glyph
5985 property. IT->object is the value of the text property. Value is
5989 next_element_from_stretch (it
)
5992 it
->what
= IT_STRETCH
;
5997 /* Load IT with the next display element from current_buffer. Value
5998 is zero if end of buffer reached. IT->stop_charpos is the next
5999 position at which to stop and check for text properties or buffer
6003 next_element_from_buffer (it
)
6008 /* Check this assumption, otherwise, we would never enter the
6009 if-statement, below. */
6010 xassert (IT_CHARPOS (*it
) >= BEGV
6011 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6013 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6015 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6017 int overlay_strings_follow_p
;
6019 /* End of the game, except when overlay strings follow that
6020 haven't been returned yet. */
6021 if (it
->overlay_strings_at_end_processed_p
)
6022 overlay_strings_follow_p
= 0;
6025 it
->overlay_strings_at_end_processed_p
= 1;
6026 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6029 if (overlay_strings_follow_p
)
6030 success_p
= get_next_display_element (it
);
6034 it
->position
= it
->current
.pos
;
6041 return get_next_display_element (it
);
6046 /* No face changes, overlays etc. in sight, so just return a
6047 character from current_buffer. */
6050 /* Maybe run the redisplay end trigger hook. Performance note:
6051 This doesn't seem to cost measurable time. */
6052 if (it
->redisplay_end_trigger_charpos
6054 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6055 run_redisplay_end_trigger_hook (it
);
6057 /* Get the next character, maybe multibyte. */
6058 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6059 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6061 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6062 - IT_BYTEPOS (*it
));
6063 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6066 it
->c
= *p
, it
->len
= 1;
6068 /* Record what we have and where it came from. */
6069 it
->what
= IT_CHARACTER
;;
6070 it
->object
= it
->w
->buffer
;
6071 it
->position
= it
->current
.pos
;
6073 /* Normally we return the character found above, except when we
6074 really want to return an ellipsis for selective display. */
6079 /* A value of selective > 0 means hide lines indented more
6080 than that number of columns. */
6081 if (it
->selective
> 0
6082 && IT_CHARPOS (*it
) + 1 < ZV
6083 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6084 IT_BYTEPOS (*it
) + 1,
6085 (double) it
->selective
)) /* iftc */
6087 success_p
= next_element_from_ellipsis (it
);
6088 it
->dpvec_char_len
= -1;
6091 else if (it
->c
== '\r' && it
->selective
== -1)
6093 /* A value of selective == -1 means that everything from the
6094 CR to the end of the line is invisible, with maybe an
6095 ellipsis displayed for it. */
6096 success_p
= next_element_from_ellipsis (it
);
6097 it
->dpvec_char_len
= -1;
6102 /* Value is zero if end of buffer reached. */
6103 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6108 /* Run the redisplay end trigger hook for IT. */
6111 run_redisplay_end_trigger_hook (it
)
6114 Lisp_Object args
[3];
6116 /* IT->glyph_row should be non-null, i.e. we should be actually
6117 displaying something, or otherwise we should not run the hook. */
6118 xassert (it
->glyph_row
);
6120 /* Set up hook arguments. */
6121 args
[0] = Qredisplay_end_trigger_functions
;
6122 args
[1] = it
->window
;
6123 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6124 it
->redisplay_end_trigger_charpos
= 0;
6126 /* Since we are *trying* to run these functions, don't try to run
6127 them again, even if they get an error. */
6128 it
->w
->redisplay_end_trigger
= Qnil
;
6129 Frun_hook_with_args (3, args
);
6131 /* Notice if it changed the face of the character we are on. */
6132 handle_face_prop (it
);
6136 /* Deliver a composition display element. The iterator IT is already
6137 filled with composition information (done in
6138 handle_composition_prop). Value is always 1. */
6141 next_element_from_composition (it
)
6144 it
->what
= IT_COMPOSITION
;
6145 it
->position
= (STRINGP (it
->string
)
6146 ? it
->current
.string_pos
6153 /***********************************************************************
6154 Moving an iterator without producing glyphs
6155 ***********************************************************************/
6157 /* Check if iterator is at a position corresponding to a valid buffer
6158 position after some move_it_ call. */
6160 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6161 ((it)->method == GET_FROM_STRING \
6162 ? IT_STRING_CHARPOS (*it) == 0 \
6166 /* Move iterator IT to a specified buffer or X position within one
6167 line on the display without producing glyphs.
6169 OP should be a bit mask including some or all of these bits:
6170 MOVE_TO_X: Stop on reaching x-position TO_X.
6171 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6172 Regardless of OP's value, stop in reaching the end of the display line.
6174 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6175 This means, in particular, that TO_X includes window's horizontal
6178 The return value has several possible values that
6179 say what condition caused the scan to stop:
6181 MOVE_POS_MATCH_OR_ZV
6182 - when TO_POS or ZV was reached.
6185 -when TO_X was reached before TO_POS or ZV were reached.
6188 - when we reached the end of the display area and the line must
6192 - when we reached the end of the display area and the line is
6196 - when we stopped at a line end, i.e. a newline or a CR and selective
6199 static enum move_it_result
6200 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6202 int to_charpos
, to_x
, op
;
6204 enum move_it_result result
= MOVE_UNDEFINED
;
6205 struct glyph_row
*saved_glyph_row
;
6207 /* Don't produce glyphs in produce_glyphs. */
6208 saved_glyph_row
= it
->glyph_row
;
6209 it
->glyph_row
= NULL
;
6211 #define BUFFER_POS_REACHED_P() \
6212 ((op & MOVE_TO_POS) != 0 \
6213 && BUFFERP (it->object) \
6214 && IT_CHARPOS (*it) >= to_charpos \
6215 && (it->method == GET_FROM_BUFFER \
6216 || (it->method == GET_FROM_DISPLAY_VECTOR \
6217 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6222 int x
, i
, ascent
= 0, descent
= 0;
6224 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6225 if ((op
& MOVE_TO_POS
) != 0
6226 && BUFFERP (it
->object
)
6227 && it
->method
== GET_FROM_BUFFER
6228 && IT_CHARPOS (*it
) > to_charpos
)
6230 result
= MOVE_POS_MATCH_OR_ZV
;
6234 /* Stop when ZV reached.
6235 We used to stop here when TO_CHARPOS reached as well, but that is
6236 too soon if this glyph does not fit on this line. So we handle it
6237 explicitly below. */
6238 if (!get_next_display_element (it
)
6239 || (it
->truncate_lines_p
6240 && BUFFER_POS_REACHED_P ()))
6242 result
= MOVE_POS_MATCH_OR_ZV
;
6246 /* The call to produce_glyphs will get the metrics of the
6247 display element IT is loaded with. We record in x the
6248 x-position before this display element in case it does not
6252 /* Remember the line height so far in case the next element doesn't
6254 if (!it
->truncate_lines_p
)
6256 ascent
= it
->max_ascent
;
6257 descent
= it
->max_descent
;
6260 PRODUCE_GLYPHS (it
);
6262 if (it
->area
!= TEXT_AREA
)
6264 set_iterator_to_next (it
, 1);
6268 /* The number of glyphs we get back in IT->nglyphs will normally
6269 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6270 character on a terminal frame, or (iii) a line end. For the
6271 second case, IT->nglyphs - 1 padding glyphs will be present
6272 (on X frames, there is only one glyph produced for a
6273 composite character.
6275 The behavior implemented below means, for continuation lines,
6276 that as many spaces of a TAB as fit on the current line are
6277 displayed there. For terminal frames, as many glyphs of a
6278 multi-glyph character are displayed in the current line, too.
6279 This is what the old redisplay code did, and we keep it that
6280 way. Under X, the whole shape of a complex character must
6281 fit on the line or it will be completely displayed in the
6284 Note that both for tabs and padding glyphs, all glyphs have
6288 /* More than one glyph or glyph doesn't fit on line. All
6289 glyphs have the same width. */
6290 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6292 int x_before_this_char
= x
;
6293 int hpos_before_this_char
= it
->hpos
;
6295 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6297 new_x
= x
+ single_glyph_width
;
6299 /* We want to leave anything reaching TO_X to the caller. */
6300 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6302 if (BUFFER_POS_REACHED_P ())
6303 goto buffer_pos_reached
;
6305 result
= MOVE_X_REACHED
;
6308 else if (/* Lines are continued. */
6309 !it
->truncate_lines_p
6310 && (/* And glyph doesn't fit on the line. */
6311 new_x
> it
->last_visible_x
6312 /* Or it fits exactly and we're on a window
6314 || (new_x
== it
->last_visible_x
6315 && FRAME_WINDOW_P (it
->f
))))
6317 if (/* IT->hpos == 0 means the very first glyph
6318 doesn't fit on the line, e.g. a wide image. */
6320 || (new_x
== it
->last_visible_x
6321 && FRAME_WINDOW_P (it
->f
)))
6324 it
->current_x
= new_x
;
6326 /* The character's last glyph just barely fits
6328 if (i
== it
->nglyphs
- 1)
6330 /* If this is the destination position,
6331 return a position *before* it in this row,
6332 now that we know it fits in this row. */
6333 if (BUFFER_POS_REACHED_P ())
6335 it
->hpos
= hpos_before_this_char
;
6336 it
->current_x
= x_before_this_char
;
6337 result
= MOVE_POS_MATCH_OR_ZV
;
6341 set_iterator_to_next (it
, 1);
6342 #ifdef HAVE_WINDOW_SYSTEM
6343 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6345 if (!get_next_display_element (it
))
6347 result
= MOVE_POS_MATCH_OR_ZV
;
6350 if (BUFFER_POS_REACHED_P ())
6352 if (ITERATOR_AT_END_OF_LINE_P (it
))
6353 result
= MOVE_POS_MATCH_OR_ZV
;
6355 result
= MOVE_LINE_CONTINUED
;
6358 if (ITERATOR_AT_END_OF_LINE_P (it
))
6360 result
= MOVE_NEWLINE_OR_CR
;
6364 #endif /* HAVE_WINDOW_SYSTEM */
6370 it
->max_ascent
= ascent
;
6371 it
->max_descent
= descent
;
6374 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6376 result
= MOVE_LINE_CONTINUED
;
6379 else if (BUFFER_POS_REACHED_P ())
6380 goto buffer_pos_reached
;
6381 else if (new_x
> it
->first_visible_x
)
6383 /* Glyph is visible. Increment number of glyphs that
6384 would be displayed. */
6389 /* Glyph is completely off the left margin of the display
6390 area. Nothing to do. */
6394 if (result
!= MOVE_UNDEFINED
)
6397 else if (BUFFER_POS_REACHED_P ())
6401 it
->max_ascent
= ascent
;
6402 it
->max_descent
= descent
;
6403 result
= MOVE_POS_MATCH_OR_ZV
;
6406 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6408 /* Stop when TO_X specified and reached. This check is
6409 necessary here because of lines consisting of a line end,
6410 only. The line end will not produce any glyphs and we
6411 would never get MOVE_X_REACHED. */
6412 xassert (it
->nglyphs
== 0);
6413 result
= MOVE_X_REACHED
;
6417 /* Is this a line end? If yes, we're done. */
6418 if (ITERATOR_AT_END_OF_LINE_P (it
))
6420 result
= MOVE_NEWLINE_OR_CR
;
6424 /* The current display element has been consumed. Advance
6426 set_iterator_to_next (it
, 1);
6428 /* Stop if lines are truncated and IT's current x-position is
6429 past the right edge of the window now. */
6430 if (it
->truncate_lines_p
6431 && it
->current_x
>= it
->last_visible_x
)
6433 #ifdef HAVE_WINDOW_SYSTEM
6434 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6436 if (!get_next_display_element (it
)
6437 || BUFFER_POS_REACHED_P ())
6439 result
= MOVE_POS_MATCH_OR_ZV
;
6442 if (ITERATOR_AT_END_OF_LINE_P (it
))
6444 result
= MOVE_NEWLINE_OR_CR
;
6448 #endif /* HAVE_WINDOW_SYSTEM */
6449 result
= MOVE_LINE_TRUNCATED
;
6454 #undef BUFFER_POS_REACHED_P
6456 /* Restore the iterator settings altered at the beginning of this
6458 it
->glyph_row
= saved_glyph_row
;
6463 /* Move IT forward until it satisfies one or more of the criteria in
6464 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6466 OP is a bit-mask that specifies where to stop, and in particular,
6467 which of those four position arguments makes a difference. See the
6468 description of enum move_operation_enum.
6470 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6471 screen line, this function will set IT to the next position >
6475 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6477 int to_charpos
, to_x
, to_y
, to_vpos
;
6480 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6486 if (op
& MOVE_TO_VPOS
)
6488 /* If no TO_CHARPOS and no TO_X specified, stop at the
6489 start of the line TO_VPOS. */
6490 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6492 if (it
->vpos
== to_vpos
)
6498 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6502 /* TO_VPOS >= 0 means stop at TO_X in the line at
6503 TO_VPOS, or at TO_POS, whichever comes first. */
6504 if (it
->vpos
== to_vpos
)
6510 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6512 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6517 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6519 /* We have reached TO_X but not in the line we want. */
6520 skip
= move_it_in_display_line_to (it
, to_charpos
,
6522 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6530 else if (op
& MOVE_TO_Y
)
6532 struct it it_backup
;
6534 /* TO_Y specified means stop at TO_X in the line containing
6535 TO_Y---or at TO_CHARPOS if this is reached first. The
6536 problem is that we can't really tell whether the line
6537 contains TO_Y before we have completely scanned it, and
6538 this may skip past TO_X. What we do is to first scan to
6541 If TO_X is not specified, use a TO_X of zero. The reason
6542 is to make the outcome of this function more predictable.
6543 If we didn't use TO_X == 0, we would stop at the end of
6544 the line which is probably not what a caller would expect
6546 skip
= move_it_in_display_line_to (it
, to_charpos
,
6550 | (op
& MOVE_TO_POS
)));
6552 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6553 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6559 /* If TO_X was reached, we would like to know whether TO_Y
6560 is in the line. This can only be said if we know the
6561 total line height which requires us to scan the rest of
6563 if (skip
== MOVE_X_REACHED
)
6566 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6567 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6569 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6572 /* Now, decide whether TO_Y is in this line. */
6573 line_height
= it
->max_ascent
+ it
->max_descent
;
6574 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6576 if (to_y
>= it
->current_y
6577 && to_y
< it
->current_y
+ line_height
)
6579 if (skip
== MOVE_X_REACHED
)
6580 /* If TO_Y is in this line and TO_X was reached above,
6581 we scanned too far. We have to restore IT's settings
6582 to the ones before skipping. */
6586 else if (skip
== MOVE_X_REACHED
)
6589 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6597 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6601 case MOVE_POS_MATCH_OR_ZV
:
6605 case MOVE_NEWLINE_OR_CR
:
6606 set_iterator_to_next (it
, 1);
6607 it
->continuation_lines_width
= 0;
6610 case MOVE_LINE_TRUNCATED
:
6611 it
->continuation_lines_width
= 0;
6612 reseat_at_next_visible_line_start (it
, 0);
6613 if ((op
& MOVE_TO_POS
) != 0
6614 && IT_CHARPOS (*it
) > to_charpos
)
6621 case MOVE_LINE_CONTINUED
:
6622 it
->continuation_lines_width
+= it
->current_x
;
6629 /* Reset/increment for the next run. */
6630 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6631 it
->current_x
= it
->hpos
= 0;
6632 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6634 last_height
= it
->max_ascent
+ it
->max_descent
;
6635 last_max_ascent
= it
->max_ascent
;
6636 it
->max_ascent
= it
->max_descent
= 0;
6641 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6645 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6647 If DY > 0, move IT backward at least that many pixels. DY = 0
6648 means move IT backward to the preceding line start or BEGV. This
6649 function may move over more than DY pixels if IT->current_y - DY
6650 ends up in the middle of a line; in this case IT->current_y will be
6651 set to the top of the line moved to. */
6654 move_it_vertically_backward (it
, dy
)
6665 start_pos
= IT_CHARPOS (*it
);
6667 /* Estimate how many newlines we must move back. */
6668 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6670 /* Set the iterator's position that many lines back. */
6671 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6672 back_to_previous_visible_line_start (it
);
6674 /* Reseat the iterator here. When moving backward, we don't want
6675 reseat to skip forward over invisible text, set up the iterator
6676 to deliver from overlay strings at the new position etc. So,
6677 use reseat_1 here. */
6678 reseat_1 (it
, it
->current
.pos
, 1);
6680 /* We are now surely at a line start. */
6681 it
->current_x
= it
->hpos
= 0;
6682 it
->continuation_lines_width
= 0;
6684 /* Move forward and see what y-distance we moved. First move to the
6685 start of the next line so that we get its height. We need this
6686 height to be able to tell whether we reached the specified
6689 it2
.max_ascent
= it2
.max_descent
= 0;
6692 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6693 MOVE_TO_POS
| MOVE_TO_VPOS
);
6695 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6696 xassert (IT_CHARPOS (*it
) >= BEGV
);
6699 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6700 xassert (IT_CHARPOS (*it
) >= BEGV
);
6701 /* H is the actual vertical distance from the position in *IT
6702 and the starting position. */
6703 h
= it2
.current_y
- it
->current_y
;
6704 /* NLINES is the distance in number of lines. */
6705 nlines
= it2
.vpos
- it
->vpos
;
6707 /* Correct IT's y and vpos position
6708 so that they are relative to the starting point. */
6714 /* DY == 0 means move to the start of the screen line. The
6715 value of nlines is > 0 if continuation lines were involved. */
6717 move_it_by_lines (it
, nlines
, 1);
6719 /* I think this assert is bogus if buffer contains
6720 invisible text or images. KFS. */
6721 xassert (IT_CHARPOS (*it
) <= start_pos
);
6726 /* The y-position we try to reach, relative to *IT.
6727 Note that H has been subtracted in front of the if-statement. */
6728 int target_y
= it
->current_y
+ h
- dy
;
6729 int y0
= it3
.current_y
;
6730 int y1
= line_bottom_y (&it3
);
6731 int line_height
= y1
- y0
;
6733 /* If we did not reach target_y, try to move further backward if
6734 we can. If we moved too far backward, try to move forward. */
6735 if (target_y
< it
->current_y
6736 /* This is heuristic. In a window that's 3 lines high, with
6737 a line height of 13 pixels each, recentering with point
6738 on the bottom line will try to move -39/2 = 19 pixels
6739 backward. Try to avoid moving into the first line. */
6740 && (it
->current_y
- target_y
6741 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6742 && IT_CHARPOS (*it
) > BEGV
)
6744 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6745 target_y
- it
->current_y
));
6746 dy
= it
->current_y
- target_y
;
6747 goto move_further_back
;
6749 else if (target_y
>= it
->current_y
+ line_height
6750 && IT_CHARPOS (*it
) < ZV
)
6752 /* Should move forward by at least one line, maybe more.
6754 Note: Calling move_it_by_lines can be expensive on
6755 terminal frames, where compute_motion is used (via
6756 vmotion) to do the job, when there are very long lines
6757 and truncate-lines is nil. That's the reason for
6758 treating terminal frames specially here. */
6760 if (!FRAME_WINDOW_P (it
->f
))
6761 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6766 move_it_by_lines (it
, 1, 1);
6768 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6772 /* I think this assert is bogus if buffer contains
6773 invisible text or images. KFS. */
6774 xassert (IT_CHARPOS (*it
) >= BEGV
);
6781 /* Move IT by a specified amount of pixel lines DY. DY negative means
6782 move backwards. DY = 0 means move to start of screen line. At the
6783 end, IT will be on the start of a screen line. */
6786 move_it_vertically (it
, dy
)
6791 move_it_vertically_backward (it
, -dy
);
6794 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6795 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6796 MOVE_TO_POS
| MOVE_TO_Y
);
6797 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6799 /* If buffer ends in ZV without a newline, move to the start of
6800 the line to satisfy the post-condition. */
6801 if (IT_CHARPOS (*it
) == ZV
6803 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6804 move_it_by_lines (it
, 0, 0);
6809 /* Move iterator IT past the end of the text line it is in. */
6812 move_it_past_eol (it
)
6815 enum move_it_result rc
;
6817 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6818 if (rc
== MOVE_NEWLINE_OR_CR
)
6819 set_iterator_to_next (it
, 0);
6823 #if 0 /* Currently not used. */
6825 /* Return non-zero if some text between buffer positions START_CHARPOS
6826 and END_CHARPOS is invisible. IT->window is the window for text
6830 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6832 int start_charpos
, end_charpos
;
6834 Lisp_Object prop
, limit
;
6835 int invisible_found_p
;
6837 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6839 /* Is text at START invisible? */
6840 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6842 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6843 invisible_found_p
= 1;
6846 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6848 make_number (end_charpos
));
6849 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6852 return invisible_found_p
;
6858 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6859 negative means move up. DVPOS == 0 means move to the start of the
6860 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6861 NEED_Y_P is zero, IT->current_y will be left unchanged.
6863 Further optimization ideas: If we would know that IT->f doesn't use
6864 a face with proportional font, we could be faster for
6865 truncate-lines nil. */
6868 move_it_by_lines (it
, dvpos
, need_y_p
)
6870 int dvpos
, need_y_p
;
6872 struct position pos
;
6874 if (!FRAME_WINDOW_P (it
->f
))
6876 struct text_pos textpos
;
6878 /* We can use vmotion on frames without proportional fonts. */
6879 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6880 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6881 reseat (it
, textpos
, 1);
6882 it
->vpos
+= pos
.vpos
;
6883 it
->current_y
+= pos
.vpos
;
6885 else if (dvpos
== 0)
6887 /* DVPOS == 0 means move to the start of the screen line. */
6888 move_it_vertically_backward (it
, 0);
6889 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6890 /* Let next call to line_bottom_y calculate real line height */
6895 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6896 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
6897 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
6902 int start_charpos
, i
;
6904 /* Start at the beginning of the screen line containing IT's
6905 position. This may actually move vertically backwards,
6906 in case of overlays, so adjust dvpos accordingly. */
6908 move_it_vertically_backward (it
, 0);
6911 /* Go back -DVPOS visible lines and reseat the iterator there. */
6912 start_charpos
= IT_CHARPOS (*it
);
6913 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
6914 back_to_previous_visible_line_start (it
);
6915 reseat (it
, it
->current
.pos
, 1);
6917 /* Move further back if we end up in a string or an image. */
6918 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
6920 /* First try to move to start of display line. */
6922 move_it_vertically_backward (it
, 0);
6924 if (IT_POS_VALID_AFTER_MOVE_P (it
))
6926 /* If start of line is still in string or image,
6927 move further back. */
6928 back_to_previous_visible_line_start (it
);
6929 reseat (it
, it
->current
.pos
, 1);
6933 it
->current_x
= it
->hpos
= 0;
6935 /* Above call may have moved too far if continuation lines
6936 are involved. Scan forward and see if it did. */
6938 it2
.vpos
= it2
.current_y
= 0;
6939 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6940 it
->vpos
-= it2
.vpos
;
6941 it
->current_y
-= it2
.current_y
;
6942 it
->current_x
= it
->hpos
= 0;
6944 /* If we moved too far back, move IT some lines forward. */
6945 if (it2
.vpos
> -dvpos
)
6947 int delta
= it2
.vpos
+ dvpos
;
6949 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6950 /* Move back again if we got too far ahead. */
6951 if (IT_CHARPOS (*it
) >= start_charpos
)
6957 /* Return 1 if IT points into the middle of a display vector. */
6960 in_display_vector_p (it
)
6963 return (it
->method
== GET_FROM_DISPLAY_VECTOR
6964 && it
->current
.dpvec_index
> 0
6965 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6969 /***********************************************************************
6971 ***********************************************************************/
6974 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6978 add_to_log (format
, arg1
, arg2
)
6980 Lisp_Object arg1
, arg2
;
6982 Lisp_Object args
[3];
6983 Lisp_Object msg
, fmt
;
6986 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6989 /* Do nothing if called asynchronously. Inserting text into
6990 a buffer may call after-change-functions and alike and
6991 that would means running Lisp asynchronously. */
6992 if (handling_signal
)
6996 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6998 args
[0] = fmt
= build_string (format
);
7001 msg
= Fformat (3, args
);
7003 len
= SBYTES (msg
) + 1;
7004 SAFE_ALLOCA (buffer
, char *, len
);
7005 bcopy (SDATA (msg
), buffer
, len
);
7007 message_dolog (buffer
, len
- 1, 1, 0);
7014 /* Output a newline in the *Messages* buffer if "needs" one. */
7017 message_log_maybe_newline ()
7019 if (message_log_need_newline
)
7020 message_dolog ("", 0, 1, 0);
7024 /* Add a string M of length NBYTES to the message log, optionally
7025 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7026 nonzero, means interpret the contents of M as multibyte. This
7027 function calls low-level routines in order to bypass text property
7028 hooks, etc. which might not be safe to run.
7030 This may GC (insert may run before/after change hooks),
7031 so the buffer M must NOT point to a Lisp string. */
7034 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7036 int nbytes
, nlflag
, multibyte
;
7038 if (!NILP (Vmemory_full
))
7041 if (!NILP (Vmessage_log_max
))
7043 struct buffer
*oldbuf
;
7044 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7045 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7046 int point_at_end
= 0;
7048 Lisp_Object old_deactivate_mark
, tem
;
7049 struct gcpro gcpro1
;
7051 old_deactivate_mark
= Vdeactivate_mark
;
7052 oldbuf
= current_buffer
;
7053 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7054 current_buffer
->undo_list
= Qt
;
7056 oldpoint
= message_dolog_marker1
;
7057 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7058 oldbegv
= message_dolog_marker2
;
7059 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7060 oldzv
= message_dolog_marker3
;
7061 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7062 GCPRO1 (old_deactivate_mark
);
7070 BEGV_BYTE
= BEG_BYTE
;
7073 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7075 /* Insert the string--maybe converting multibyte to single byte
7076 or vice versa, so that all the text fits the buffer. */
7078 && NILP (current_buffer
->enable_multibyte_characters
))
7080 int i
, c
, char_bytes
;
7081 unsigned char work
[1];
7083 /* Convert a multibyte string to single-byte
7084 for the *Message* buffer. */
7085 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7087 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7088 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7090 : multibyte_char_to_unibyte (c
, Qnil
));
7091 insert_1_both (work
, 1, 1, 1, 0, 0);
7094 else if (! multibyte
7095 && ! NILP (current_buffer
->enable_multibyte_characters
))
7097 int i
, c
, char_bytes
;
7098 unsigned char *msg
= (unsigned char *) m
;
7099 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7100 /* Convert a single-byte string to multibyte
7101 for the *Message* buffer. */
7102 for (i
= 0; i
< nbytes
; i
++)
7104 c
= unibyte_char_to_multibyte (msg
[i
]);
7105 char_bytes
= CHAR_STRING (c
, str
);
7106 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7110 insert_1 (m
, nbytes
, 1, 0, 0);
7114 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7115 insert_1 ("\n", 1, 1, 0, 0);
7117 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7119 this_bol_byte
= PT_BYTE
;
7121 /* See if this line duplicates the previous one.
7122 If so, combine duplicates. */
7125 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7127 prev_bol_byte
= PT_BYTE
;
7129 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7130 this_bol
, this_bol_byte
);
7133 del_range_both (prev_bol
, prev_bol_byte
,
7134 this_bol
, this_bol_byte
, 0);
7140 /* If you change this format, don't forget to also
7141 change message_log_check_duplicate. */
7142 sprintf (dupstr
, " [%d times]", dup
);
7143 duplen
= strlen (dupstr
);
7144 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7145 insert_1 (dupstr
, duplen
, 1, 0, 1);
7150 /* If we have more than the desired maximum number of lines
7151 in the *Messages* buffer now, delete the oldest ones.
7152 This is safe because we don't have undo in this buffer. */
7154 if (NATNUMP (Vmessage_log_max
))
7156 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7157 -XFASTINT (Vmessage_log_max
) - 1, 0);
7158 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7161 BEGV
= XMARKER (oldbegv
)->charpos
;
7162 BEGV_BYTE
= marker_byte_position (oldbegv
);
7171 ZV
= XMARKER (oldzv
)->charpos
;
7172 ZV_BYTE
= marker_byte_position (oldzv
);
7176 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7178 /* We can't do Fgoto_char (oldpoint) because it will run some
7180 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7181 XMARKER (oldpoint
)->bytepos
);
7184 unchain_marker (XMARKER (oldpoint
));
7185 unchain_marker (XMARKER (oldbegv
));
7186 unchain_marker (XMARKER (oldzv
));
7188 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7189 set_buffer_internal (oldbuf
);
7191 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7192 message_log_need_newline
= !nlflag
;
7193 Vdeactivate_mark
= old_deactivate_mark
;
7198 /* We are at the end of the buffer after just having inserted a newline.
7199 (Note: We depend on the fact we won't be crossing the gap.)
7200 Check to see if the most recent message looks a lot like the previous one.
7201 Return 0 if different, 1 if the new one should just replace it, or a
7202 value N > 1 if we should also append " [N times]". */
7205 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7206 int prev_bol
, this_bol
;
7207 int prev_bol_byte
, this_bol_byte
;
7210 int len
= Z_BYTE
- 1 - this_bol_byte
;
7212 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7213 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7215 for (i
= 0; i
< len
; i
++)
7217 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7225 if (*p1
++ == ' ' && *p1
++ == '[')
7228 while (*p1
>= '0' && *p1
<= '9')
7229 n
= n
* 10 + *p1
++ - '0';
7230 if (strncmp (p1
, " times]\n", 8) == 0)
7237 /* Display an echo area message M with a specified length of NBYTES
7238 bytes. The string may include null characters. If M is 0, clear
7239 out any existing message, and let the mini-buffer text show
7242 This may GC, so the buffer M must NOT point to a Lisp string. */
7245 message2 (m
, nbytes
, multibyte
)
7250 /* First flush out any partial line written with print. */
7251 message_log_maybe_newline ();
7253 message_dolog (m
, nbytes
, 1, multibyte
);
7254 message2_nolog (m
, nbytes
, multibyte
);
7258 /* The non-logging counterpart of message2. */
7261 message2_nolog (m
, nbytes
, multibyte
)
7263 int nbytes
, multibyte
;
7265 struct frame
*sf
= SELECTED_FRAME ();
7266 message_enable_multibyte
= multibyte
;
7270 if (noninteractive_need_newline
)
7271 putc ('\n', stderr
);
7272 noninteractive_need_newline
= 0;
7274 fwrite (m
, nbytes
, 1, stderr
);
7275 if (cursor_in_echo_area
== 0)
7276 fprintf (stderr
, "\n");
7279 /* A null message buffer means that the frame hasn't really been
7280 initialized yet. Error messages get reported properly by
7281 cmd_error, so this must be just an informative message; toss it. */
7282 else if (INTERACTIVE
7283 && sf
->glyphs_initialized_p
7284 && FRAME_MESSAGE_BUF (sf
))
7286 Lisp_Object mini_window
;
7289 /* Get the frame containing the mini-buffer
7290 that the selected frame is using. */
7291 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7292 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7294 FRAME_SAMPLE_VISIBILITY (f
);
7295 if (FRAME_VISIBLE_P (sf
)
7296 && ! FRAME_VISIBLE_P (f
))
7297 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7301 set_message (m
, Qnil
, nbytes
, multibyte
);
7302 if (minibuffer_auto_raise
)
7303 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7306 clear_message (1, 1);
7308 do_pending_window_change (0);
7309 echo_area_display (1);
7310 do_pending_window_change (0);
7311 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7312 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7317 /* Display an echo area message M with a specified length of NBYTES
7318 bytes. The string may include null characters. If M is not a
7319 string, clear out any existing message, and let the mini-buffer
7322 This function cancels echoing. */
7325 message3 (m
, nbytes
, multibyte
)
7330 struct gcpro gcpro1
;
7333 clear_message (1,1);
7336 /* First flush out any partial line written with print. */
7337 message_log_maybe_newline ();
7343 SAFE_ALLOCA (buffer
, char *, nbytes
);
7344 bcopy (SDATA (m
), buffer
, nbytes
);
7345 message_dolog (buffer
, nbytes
, 1, multibyte
);
7348 message3_nolog (m
, nbytes
, multibyte
);
7354 /* The non-logging version of message3.
7355 This does not cancel echoing, because it is used for echoing.
7356 Perhaps we need to make a separate function for echoing
7357 and make this cancel echoing. */
7360 message3_nolog (m
, nbytes
, multibyte
)
7362 int nbytes
, multibyte
;
7364 struct frame
*sf
= SELECTED_FRAME ();
7365 message_enable_multibyte
= multibyte
;
7369 if (noninteractive_need_newline
)
7370 putc ('\n', stderr
);
7371 noninteractive_need_newline
= 0;
7373 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7374 if (cursor_in_echo_area
== 0)
7375 fprintf (stderr
, "\n");
7378 /* A null message buffer means that the frame hasn't really been
7379 initialized yet. Error messages get reported properly by
7380 cmd_error, so this must be just an informative message; toss it. */
7381 else if (INTERACTIVE
7382 && sf
->glyphs_initialized_p
7383 && FRAME_MESSAGE_BUF (sf
))
7385 Lisp_Object mini_window
;
7389 /* Get the frame containing the mini-buffer
7390 that the selected frame is using. */
7391 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7392 frame
= XWINDOW (mini_window
)->frame
;
7395 FRAME_SAMPLE_VISIBILITY (f
);
7396 if (FRAME_VISIBLE_P (sf
)
7397 && !FRAME_VISIBLE_P (f
))
7398 Fmake_frame_visible (frame
);
7400 if (STRINGP (m
) && SCHARS (m
) > 0)
7402 set_message (NULL
, m
, nbytes
, multibyte
);
7403 if (minibuffer_auto_raise
)
7404 Fraise_frame (frame
);
7405 /* Assume we are not echoing.
7406 (If we are, echo_now will override this.) */
7407 echo_message_buffer
= Qnil
;
7410 clear_message (1, 1);
7412 do_pending_window_change (0);
7413 echo_area_display (1);
7414 do_pending_window_change (0);
7415 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7416 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7421 /* Display a null-terminated echo area message M. If M is 0, clear
7422 out any existing message, and let the mini-buffer text show through.
7424 The buffer M must continue to exist until after the echo area gets
7425 cleared or some other message gets displayed there. Do not pass
7426 text that is stored in a Lisp string. Do not pass text in a buffer
7427 that was alloca'd. */
7433 message2 (m
, (m
? strlen (m
) : 0), 0);
7437 /* The non-logging counterpart of message1. */
7443 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7446 /* Display a message M which contains a single %s
7447 which gets replaced with STRING. */
7450 message_with_string (m
, string
, log
)
7455 CHECK_STRING (string
);
7461 if (noninteractive_need_newline
)
7462 putc ('\n', stderr
);
7463 noninteractive_need_newline
= 0;
7464 fprintf (stderr
, m
, SDATA (string
));
7465 if (cursor_in_echo_area
== 0)
7466 fprintf (stderr
, "\n");
7470 else if (INTERACTIVE
)
7472 /* The frame whose minibuffer we're going to display the message on.
7473 It may be larger than the selected frame, so we need
7474 to use its buffer, not the selected frame's buffer. */
7475 Lisp_Object mini_window
;
7476 struct frame
*f
, *sf
= SELECTED_FRAME ();
7478 /* Get the frame containing the minibuffer
7479 that the selected frame is using. */
7480 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7481 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7483 /* A null message buffer means that the frame hasn't really been
7484 initialized yet. Error messages get reported properly by
7485 cmd_error, so this must be just an informative message; toss it. */
7486 if (FRAME_MESSAGE_BUF (f
))
7488 Lisp_Object args
[2], message
;
7489 struct gcpro gcpro1
, gcpro2
;
7491 args
[0] = build_string (m
);
7492 args
[1] = message
= string
;
7493 GCPRO2 (args
[0], message
);
7496 message
= Fformat (2, args
);
7499 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7501 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7505 /* Print should start at the beginning of the message
7506 buffer next time. */
7507 message_buf_print
= 0;
7513 /* Dump an informative message to the minibuf. If M is 0, clear out
7514 any existing message, and let the mini-buffer text show through. */
7518 message (m
, a1
, a2
, a3
)
7520 EMACS_INT a1
, a2
, a3
;
7526 if (noninteractive_need_newline
)
7527 putc ('\n', stderr
);
7528 noninteractive_need_newline
= 0;
7529 fprintf (stderr
, m
, a1
, a2
, a3
);
7530 if (cursor_in_echo_area
== 0)
7531 fprintf (stderr
, "\n");
7535 else if (INTERACTIVE
)
7537 /* The frame whose mini-buffer we're going to display the message
7538 on. It may be larger than the selected frame, so we need to
7539 use its buffer, not the selected frame's buffer. */
7540 Lisp_Object mini_window
;
7541 struct frame
*f
, *sf
= SELECTED_FRAME ();
7543 /* Get the frame containing the mini-buffer
7544 that the selected frame is using. */
7545 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7546 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7548 /* A null message buffer means that the frame hasn't really been
7549 initialized yet. Error messages get reported properly by
7550 cmd_error, so this must be just an informative message; toss
7552 if (FRAME_MESSAGE_BUF (f
))
7563 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7564 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7566 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7567 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7569 #endif /* NO_ARG_ARRAY */
7571 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7576 /* Print should start at the beginning of the message
7577 buffer next time. */
7578 message_buf_print
= 0;
7584 /* The non-logging version of message. */
7587 message_nolog (m
, a1
, a2
, a3
)
7589 EMACS_INT a1
, a2
, a3
;
7591 Lisp_Object old_log_max
;
7592 old_log_max
= Vmessage_log_max
;
7593 Vmessage_log_max
= Qnil
;
7594 message (m
, a1
, a2
, a3
);
7595 Vmessage_log_max
= old_log_max
;
7599 /* Display the current message in the current mini-buffer. This is
7600 only called from error handlers in process.c, and is not time
7606 if (!NILP (echo_area_buffer
[0]))
7609 string
= Fcurrent_message ();
7610 message3 (string
, SBYTES (string
),
7611 !NILP (current_buffer
->enable_multibyte_characters
));
7616 /* Make sure echo area buffers in `echo_buffers' are live.
7617 If they aren't, make new ones. */
7620 ensure_echo_area_buffers ()
7624 for (i
= 0; i
< 2; ++i
)
7625 if (!BUFFERP (echo_buffer
[i
])
7626 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7629 Lisp_Object old_buffer
;
7632 old_buffer
= echo_buffer
[i
];
7633 sprintf (name
, " *Echo Area %d*", i
);
7634 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7635 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7637 for (j
= 0; j
< 2; ++j
)
7638 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7639 echo_area_buffer
[j
] = echo_buffer
[i
];
7644 /* Call FN with args A1..A4 with either the current or last displayed
7645 echo_area_buffer as current buffer.
7647 WHICH zero means use the current message buffer
7648 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7649 from echo_buffer[] and clear it.
7651 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7652 suitable buffer from echo_buffer[] and clear it.
7654 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
7655 that the current message becomes the last displayed one, make
7656 choose a suitable buffer for echo_area_buffer[0], and clear it.
7658 Value is what FN returns. */
7661 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7664 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7670 int this_one
, the_other
, clear_buffer_p
, rc
;
7671 int count
= SPECPDL_INDEX ();
7673 /* If buffers aren't live, make new ones. */
7674 ensure_echo_area_buffers ();
7679 this_one
= 0, the_other
= 1;
7681 this_one
= 1, the_other
= 0;
7684 this_one
= 0, the_other
= 1;
7687 /* We need a fresh one in case the current echo buffer equals
7688 the one containing the last displayed echo area message. */
7689 if (!NILP (echo_area_buffer
[this_one
])
7690 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
7691 echo_area_buffer
[this_one
] = Qnil
;
7694 /* Choose a suitable buffer from echo_buffer[] is we don't
7696 if (NILP (echo_area_buffer
[this_one
]))
7698 echo_area_buffer
[this_one
]
7699 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7700 ? echo_buffer
[the_other
]
7701 : echo_buffer
[this_one
]);
7705 buffer
= echo_area_buffer
[this_one
];
7707 /* Don't get confused by reusing the buffer used for echoing
7708 for a different purpose. */
7709 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7712 record_unwind_protect (unwind_with_echo_area_buffer
,
7713 with_echo_area_buffer_unwind_data (w
));
7715 /* Make the echo area buffer current. Note that for display
7716 purposes, it is not necessary that the displayed window's buffer
7717 == current_buffer, except for text property lookup. So, let's
7718 only set that buffer temporarily here without doing a full
7719 Fset_window_buffer. We must also change w->pointm, though,
7720 because otherwise an assertions in unshow_buffer fails, and Emacs
7722 set_buffer_internal_1 (XBUFFER (buffer
));
7726 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7729 current_buffer
->undo_list
= Qt
;
7730 current_buffer
->read_only
= Qnil
;
7731 specbind (Qinhibit_read_only
, Qt
);
7732 specbind (Qinhibit_modification_hooks
, Qt
);
7734 if (clear_buffer_p
&& Z
> BEG
)
7737 xassert (BEGV
>= BEG
);
7738 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7740 rc
= fn (a1
, a2
, a3
, a4
);
7742 xassert (BEGV
>= BEG
);
7743 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7745 unbind_to (count
, Qnil
);
7750 /* Save state that should be preserved around the call to the function
7751 FN called in with_echo_area_buffer. */
7754 with_echo_area_buffer_unwind_data (w
)
7760 /* Reduce consing by keeping one vector in
7761 Vwith_echo_area_save_vector. */
7762 vector
= Vwith_echo_area_save_vector
;
7763 Vwith_echo_area_save_vector
= Qnil
;
7766 vector
= Fmake_vector (make_number (7), Qnil
);
7768 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7769 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7770 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7774 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7775 AREF (vector
, i
) = w
->buffer
; ++i
;
7776 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7777 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7782 for (; i
< end
; ++i
)
7783 AREF (vector
, i
) = Qnil
;
7786 xassert (i
== ASIZE (vector
));
7791 /* Restore global state from VECTOR which was created by
7792 with_echo_area_buffer_unwind_data. */
7795 unwind_with_echo_area_buffer (vector
)
7798 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7799 Vdeactivate_mark
= AREF (vector
, 1);
7800 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7802 if (WINDOWP (AREF (vector
, 3)))
7805 Lisp_Object buffer
, charpos
, bytepos
;
7807 w
= XWINDOW (AREF (vector
, 3));
7808 buffer
= AREF (vector
, 4);
7809 charpos
= AREF (vector
, 5);
7810 bytepos
= AREF (vector
, 6);
7813 set_marker_both (w
->pointm
, buffer
,
7814 XFASTINT (charpos
), XFASTINT (bytepos
));
7817 Vwith_echo_area_save_vector
= vector
;
7822 /* Set up the echo area for use by print functions. MULTIBYTE_P
7823 non-zero means we will print multibyte. */
7826 setup_echo_area_for_printing (multibyte_p
)
7829 /* If we can't find an echo area any more, exit. */
7830 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7833 ensure_echo_area_buffers ();
7835 if (!message_buf_print
)
7837 /* A message has been output since the last time we printed.
7838 Choose a fresh echo area buffer. */
7839 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7840 echo_area_buffer
[0] = echo_buffer
[1];
7842 echo_area_buffer
[0] = echo_buffer
[0];
7844 /* Switch to that buffer and clear it. */
7845 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7846 current_buffer
->truncate_lines
= Qnil
;
7850 int count
= SPECPDL_INDEX ();
7851 specbind (Qinhibit_read_only
, Qt
);
7852 /* Note that undo recording is always disabled. */
7854 unbind_to (count
, Qnil
);
7856 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7858 /* Set up the buffer for the multibyteness we need. */
7860 != !NILP (current_buffer
->enable_multibyte_characters
))
7861 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7863 /* Raise the frame containing the echo area. */
7864 if (minibuffer_auto_raise
)
7866 struct frame
*sf
= SELECTED_FRAME ();
7867 Lisp_Object mini_window
;
7868 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7869 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7872 message_log_maybe_newline ();
7873 message_buf_print
= 1;
7877 if (NILP (echo_area_buffer
[0]))
7879 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7880 echo_area_buffer
[0] = echo_buffer
[1];
7882 echo_area_buffer
[0] = echo_buffer
[0];
7885 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7887 /* Someone switched buffers between print requests. */
7888 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7889 current_buffer
->truncate_lines
= Qnil
;
7895 /* Display an echo area message in window W. Value is non-zero if W's
7896 height is changed. If display_last_displayed_message_p is
7897 non-zero, display the message that was last displayed, otherwise
7898 display the current message. */
7901 display_echo_area (w
)
7904 int i
, no_message_p
, window_height_changed_p
, count
;
7906 /* Temporarily disable garbage collections while displaying the echo
7907 area. This is done because a GC can print a message itself.
7908 That message would modify the echo area buffer's contents while a
7909 redisplay of the buffer is going on, and seriously confuse
7911 count
= inhibit_garbage_collection ();
7913 /* If there is no message, we must call display_echo_area_1
7914 nevertheless because it resizes the window. But we will have to
7915 reset the echo_area_buffer in question to nil at the end because
7916 with_echo_area_buffer will sets it to an empty buffer. */
7917 i
= display_last_displayed_message_p
? 1 : 0;
7918 no_message_p
= NILP (echo_area_buffer
[i
]);
7920 window_height_changed_p
7921 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7922 display_echo_area_1
,
7923 (EMACS_INT
) w
, Qnil
, 0, 0);
7926 echo_area_buffer
[i
] = Qnil
;
7928 unbind_to (count
, Qnil
);
7929 return window_height_changed_p
;
7933 /* Helper for display_echo_area. Display the current buffer which
7934 contains the current echo area message in window W, a mini-window,
7935 a pointer to which is passed in A1. A2..A4 are currently not used.
7936 Change the height of W so that all of the message is displayed.
7937 Value is non-zero if height of W was changed. */
7940 display_echo_area_1 (a1
, a2
, a3
, a4
)
7945 struct window
*w
= (struct window
*) a1
;
7947 struct text_pos start
;
7948 int window_height_changed_p
= 0;
7950 /* Do this before displaying, so that we have a large enough glyph
7951 matrix for the display. If we can't get enough space for the
7952 whole text, display the last N lines. That works by setting w->start. */
7953 window_height_changed_p
= resize_mini_window (w
, 0);
7955 /* Use the starting position chosen by resize_mini_window. */
7956 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
7959 clear_glyph_matrix (w
->desired_matrix
);
7960 XSETWINDOW (window
, w
);
7961 try_window (window
, start
, 0);
7963 return window_height_changed_p
;
7967 /* Resize the echo area window to exactly the size needed for the
7968 currently displayed message, if there is one. If a mini-buffer
7969 is active, don't shrink it. */
7972 resize_echo_area_exactly ()
7974 if (BUFFERP (echo_area_buffer
[0])
7975 && WINDOWP (echo_area_window
))
7977 struct window
*w
= XWINDOW (echo_area_window
);
7979 Lisp_Object resize_exactly
;
7981 if (minibuf_level
== 0)
7982 resize_exactly
= Qt
;
7984 resize_exactly
= Qnil
;
7986 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7987 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7990 ++windows_or_buffers_changed
;
7991 ++update_mode_lines
;
7992 redisplay_internal (0);
7998 /* Callback function for with_echo_area_buffer, when used from
7999 resize_echo_area_exactly. A1 contains a pointer to the window to
8000 resize, EXACTLY non-nil means resize the mini-window exactly to the
8001 size of the text displayed. A3 and A4 are not used. Value is what
8002 resize_mini_window returns. */
8005 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8007 Lisp_Object exactly
;
8010 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8014 /* Resize mini-window W to fit the size of its contents. EXACT:P
8015 means size the window exactly to the size needed. Otherwise, it's
8016 only enlarged until W's buffer is empty.
8018 Set W->start to the right place to begin display. If the whole
8019 contents fit, start at the beginning. Otherwise, start so as
8020 to make the end of the contents appear. This is particularly
8021 important for y-or-n-p, but seems desirable generally.
8023 Value is non-zero if the window height has been changed. */
8026 resize_mini_window (w
, exact_p
)
8030 struct frame
*f
= XFRAME (w
->frame
);
8031 int window_height_changed_p
= 0;
8033 xassert (MINI_WINDOW_P (w
));
8035 /* By default, start display at the beginning. */
8036 set_marker_both (w
->start
, w
->buffer
,
8037 BUF_BEGV (XBUFFER (w
->buffer
)),
8038 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8040 /* Don't resize windows while redisplaying a window; it would
8041 confuse redisplay functions when the size of the window they are
8042 displaying changes from under them. Such a resizing can happen,
8043 for instance, when which-func prints a long message while
8044 we are running fontification-functions. We're running these
8045 functions with safe_call which binds inhibit-redisplay to t. */
8046 if (!NILP (Vinhibit_redisplay
))
8049 /* Nil means don't try to resize. */
8050 if (NILP (Vresize_mini_windows
)
8051 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8054 if (!FRAME_MINIBUF_ONLY_P (f
))
8057 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8058 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8059 int height
, max_height
;
8060 int unit
= FRAME_LINE_HEIGHT (f
);
8061 struct text_pos start
;
8062 struct buffer
*old_current_buffer
= NULL
;
8064 if (current_buffer
!= XBUFFER (w
->buffer
))
8066 old_current_buffer
= current_buffer
;
8067 set_buffer_internal (XBUFFER (w
->buffer
));
8070 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8072 /* Compute the max. number of lines specified by the user. */
8073 if (FLOATP (Vmax_mini_window_height
))
8074 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8075 else if (INTEGERP (Vmax_mini_window_height
))
8076 max_height
= XINT (Vmax_mini_window_height
);
8078 max_height
= total_height
/ 4;
8080 /* Correct that max. height if it's bogus. */
8081 max_height
= max (1, max_height
);
8082 max_height
= min (total_height
, max_height
);
8084 /* Find out the height of the text in the window. */
8085 if (it
.truncate_lines_p
)
8090 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8091 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8092 height
= it
.current_y
+ last_height
;
8094 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8095 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8096 height
= (height
+ unit
- 1) / unit
;
8099 /* Compute a suitable window start. */
8100 if (height
> max_height
)
8102 height
= max_height
;
8103 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8104 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8105 start
= it
.current
.pos
;
8108 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8109 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8111 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8113 /* Let it grow only, until we display an empty message, in which
8114 case the window shrinks again. */
8115 if (height
> WINDOW_TOTAL_LINES (w
))
8117 int old_height
= WINDOW_TOTAL_LINES (w
);
8118 freeze_window_starts (f
, 1);
8119 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8120 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8122 else if (height
< WINDOW_TOTAL_LINES (w
)
8123 && (exact_p
|| BEGV
== ZV
))
8125 int old_height
= WINDOW_TOTAL_LINES (w
);
8126 freeze_window_starts (f
, 0);
8127 shrink_mini_window (w
);
8128 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8133 /* Always resize to exact size needed. */
8134 if (height
> WINDOW_TOTAL_LINES (w
))
8136 int old_height
= WINDOW_TOTAL_LINES (w
);
8137 freeze_window_starts (f
, 1);
8138 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8139 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8141 else if (height
< WINDOW_TOTAL_LINES (w
))
8143 int old_height
= WINDOW_TOTAL_LINES (w
);
8144 freeze_window_starts (f
, 0);
8145 shrink_mini_window (w
);
8149 freeze_window_starts (f
, 1);
8150 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8153 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8157 if (old_current_buffer
)
8158 set_buffer_internal (old_current_buffer
);
8161 return window_height_changed_p
;
8165 /* Value is the current message, a string, or nil if there is no
8173 if (NILP (echo_area_buffer
[0]))
8177 with_echo_area_buffer (0, 0, current_message_1
,
8178 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8180 echo_area_buffer
[0] = Qnil
;
8188 current_message_1 (a1
, a2
, a3
, a4
)
8193 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8196 *msg
= make_buffer_string (BEG
, Z
, 1);
8203 /* Push the current message on Vmessage_stack for later restauration
8204 by restore_message. Value is non-zero if the current message isn't
8205 empty. This is a relatively infrequent operation, so it's not
8206 worth optimizing. */
8212 msg
= current_message ();
8213 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8214 return STRINGP (msg
);
8218 /* Restore message display from the top of Vmessage_stack. */
8225 xassert (CONSP (Vmessage_stack
));
8226 msg
= XCAR (Vmessage_stack
);
8228 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8230 message3_nolog (msg
, 0, 0);
8234 /* Handler for record_unwind_protect calling pop_message. */
8237 pop_message_unwind (dummy
)
8244 /* Pop the top-most entry off Vmessage_stack. */
8249 xassert (CONSP (Vmessage_stack
));
8250 Vmessage_stack
= XCDR (Vmessage_stack
);
8254 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8255 exits. If the stack is not empty, we have a missing pop_message
8259 check_message_stack ()
8261 if (!NILP (Vmessage_stack
))
8266 /* Truncate to NCHARS what will be displayed in the echo area the next
8267 time we display it---but don't redisplay it now. */
8270 truncate_echo_area (nchars
)
8274 echo_area_buffer
[0] = Qnil
;
8275 /* A null message buffer means that the frame hasn't really been
8276 initialized yet. Error messages get reported properly by
8277 cmd_error, so this must be just an informative message; toss it. */
8278 else if (!noninteractive
8280 && !NILP (echo_area_buffer
[0]))
8282 struct frame
*sf
= SELECTED_FRAME ();
8283 if (FRAME_MESSAGE_BUF (sf
))
8284 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8289 /* Helper function for truncate_echo_area. Truncate the current
8290 message to at most NCHARS characters. */
8293 truncate_message_1 (nchars
, a2
, a3
, a4
)
8298 if (BEG
+ nchars
< Z
)
8299 del_range (BEG
+ nchars
, Z
);
8301 echo_area_buffer
[0] = Qnil
;
8306 /* Set the current message to a substring of S or STRING.
8308 If STRING is a Lisp string, set the message to the first NBYTES
8309 bytes from STRING. NBYTES zero means use the whole string. If
8310 STRING is multibyte, the message will be displayed multibyte.
8312 If S is not null, set the message to the first LEN bytes of S. LEN
8313 zero means use the whole string. MULTIBYTE_P non-zero means S is
8314 multibyte. Display the message multibyte in that case.
8316 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8317 to t before calling set_message_1 (which calls insert).
8321 set_message (s
, string
, nbytes
, multibyte_p
)
8324 int nbytes
, multibyte_p
;
8326 message_enable_multibyte
8327 = ((s
&& multibyte_p
)
8328 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8330 with_echo_area_buffer (0, -1, set_message_1
,
8331 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8332 message_buf_print
= 0;
8333 help_echo_showing_p
= 0;
8337 /* Helper function for set_message. Arguments have the same meaning
8338 as there, with A1 corresponding to S and A2 corresponding to STRING
8339 This function is called with the echo area buffer being
8343 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8346 EMACS_INT nbytes
, multibyte_p
;
8348 const char *s
= (const char *) a1
;
8349 Lisp_Object string
= a2
;
8351 /* Change multibyteness of the echo buffer appropriately. */
8352 if (message_enable_multibyte
8353 != !NILP (current_buffer
->enable_multibyte_characters
))
8354 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8356 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8358 /* Insert new message at BEG. */
8359 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8361 if (STRINGP (string
))
8366 nbytes
= SBYTES (string
);
8367 nchars
= string_byte_to_char (string
, nbytes
);
8369 /* This function takes care of single/multibyte conversion. We
8370 just have to ensure that the echo area buffer has the right
8371 setting of enable_multibyte_characters. */
8372 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8377 nbytes
= strlen (s
);
8379 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8381 /* Convert from multi-byte to single-byte. */
8383 unsigned char work
[1];
8385 /* Convert a multibyte string to single-byte. */
8386 for (i
= 0; i
< nbytes
; i
+= n
)
8388 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8389 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8391 : multibyte_char_to_unibyte (c
, Qnil
));
8392 insert_1_both (work
, 1, 1, 1, 0, 0);
8395 else if (!multibyte_p
8396 && !NILP (current_buffer
->enable_multibyte_characters
))
8398 /* Convert from single-byte to multi-byte. */
8400 const unsigned char *msg
= (const unsigned char *) s
;
8401 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8403 /* Convert a single-byte string to multibyte. */
8404 for (i
= 0; i
< nbytes
; i
++)
8406 c
= unibyte_char_to_multibyte (msg
[i
]);
8407 n
= CHAR_STRING (c
, str
);
8408 insert_1_both (str
, 1, n
, 1, 0, 0);
8412 insert_1 (s
, nbytes
, 1, 0, 0);
8419 /* Clear messages. CURRENT_P non-zero means clear the current
8420 message. LAST_DISPLAYED_P non-zero means clear the message
8424 clear_message (current_p
, last_displayed_p
)
8425 int current_p
, last_displayed_p
;
8429 echo_area_buffer
[0] = Qnil
;
8430 message_cleared_p
= 1;
8433 if (last_displayed_p
)
8434 echo_area_buffer
[1] = Qnil
;
8436 message_buf_print
= 0;
8439 /* Clear garbaged frames.
8441 This function is used where the old redisplay called
8442 redraw_garbaged_frames which in turn called redraw_frame which in
8443 turn called clear_frame. The call to clear_frame was a source of
8444 flickering. I believe a clear_frame is not necessary. It should
8445 suffice in the new redisplay to invalidate all current matrices,
8446 and ensure a complete redisplay of all windows. */
8449 clear_garbaged_frames ()
8453 Lisp_Object tail
, frame
;
8454 int changed_count
= 0;
8456 FOR_EACH_FRAME (tail
, frame
)
8458 struct frame
*f
= XFRAME (frame
);
8460 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8464 Fredraw_frame (frame
);
8465 f
->force_flush_display_p
= 1;
8467 clear_current_matrices (f
);
8476 ++windows_or_buffers_changed
;
8481 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8482 is non-zero update selected_frame. Value is non-zero if the
8483 mini-windows height has been changed. */
8486 echo_area_display (update_frame_p
)
8489 Lisp_Object mini_window
;
8492 int window_height_changed_p
= 0;
8493 struct frame
*sf
= SELECTED_FRAME ();
8495 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8496 w
= XWINDOW (mini_window
);
8497 f
= XFRAME (WINDOW_FRAME (w
));
8499 /* Don't display if frame is invisible or not yet initialized. */
8500 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8503 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8505 #ifdef HAVE_WINDOW_SYSTEM
8506 /* When Emacs starts, selected_frame may be the initial terminal
8507 frame. If we let this through, a message would be displayed on
8509 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
8511 #endif /* HAVE_WINDOW_SYSTEM */
8514 /* Redraw garbaged frames. */
8516 clear_garbaged_frames ();
8518 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8520 echo_area_window
= mini_window
;
8521 window_height_changed_p
= display_echo_area (w
);
8522 w
->must_be_updated_p
= 1;
8524 /* Update the display, unless called from redisplay_internal.
8525 Also don't update the screen during redisplay itself. The
8526 update will happen at the end of redisplay, and an update
8527 here could cause confusion. */
8528 if (update_frame_p
&& !redisplaying_p
)
8532 /* If the display update has been interrupted by pending
8533 input, update mode lines in the frame. Due to the
8534 pending input, it might have been that redisplay hasn't
8535 been called, so that mode lines above the echo area are
8536 garbaged. This looks odd, so we prevent it here. */
8537 if (!display_completed
)
8538 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8540 if (window_height_changed_p
8541 /* Don't do this if Emacs is shutting down. Redisplay
8542 needs to run hooks. */
8543 && !NILP (Vrun_hooks
))
8545 /* Must update other windows. Likewise as in other
8546 cases, don't let this update be interrupted by
8548 int count
= SPECPDL_INDEX ();
8549 specbind (Qredisplay_dont_pause
, Qt
);
8550 windows_or_buffers_changed
= 1;
8551 redisplay_internal (0);
8552 unbind_to (count
, Qnil
);
8554 else if (FRAME_WINDOW_P (f
) && n
== 0)
8556 /* Window configuration is the same as before.
8557 Can do with a display update of the echo area,
8558 unless we displayed some mode lines. */
8559 update_single_window (w
, 1);
8560 FRAME_RIF (f
)->flush_display (f
);
8563 update_frame (f
, 1, 1);
8565 /* If cursor is in the echo area, make sure that the next
8566 redisplay displays the minibuffer, so that the cursor will
8567 be replaced with what the minibuffer wants. */
8568 if (cursor_in_echo_area
)
8569 ++windows_or_buffers_changed
;
8572 else if (!EQ (mini_window
, selected_window
))
8573 windows_or_buffers_changed
++;
8575 /* Last displayed message is now the current message. */
8576 echo_area_buffer
[1] = echo_area_buffer
[0];
8577 /* Inform read_char that we're not echoing. */
8578 echo_message_buffer
= Qnil
;
8580 /* Prevent redisplay optimization in redisplay_internal by resetting
8581 this_line_start_pos. This is done because the mini-buffer now
8582 displays the message instead of its buffer text. */
8583 if (EQ (mini_window
, selected_window
))
8584 CHARPOS (this_line_start_pos
) = 0;
8586 return window_height_changed_p
;
8591 /***********************************************************************
8592 Mode Lines and Frame Titles
8593 ***********************************************************************/
8595 /* A buffer for constructing non-propertized mode-line strings and
8596 frame titles in it; allocated from the heap in init_xdisp and
8597 resized as needed in store_mode_line_noprop_char. */
8599 static char *mode_line_noprop_buf
;
8601 /* The buffer's end, and a current output position in it. */
8603 static char *mode_line_noprop_buf_end
;
8604 static char *mode_line_noprop_ptr
;
8606 #define MODE_LINE_NOPROP_LEN(start) \
8607 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8610 MODE_LINE_DISPLAY
= 0,
8616 /* Alist that caches the results of :propertize.
8617 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8618 static Lisp_Object mode_line_proptrans_alist
;
8620 /* List of strings making up the mode-line. */
8621 static Lisp_Object mode_line_string_list
;
8623 /* Base face property when building propertized mode line string. */
8624 static Lisp_Object mode_line_string_face
;
8625 static Lisp_Object mode_line_string_face_prop
;
8628 /* Unwind data for mode line strings */
8630 static Lisp_Object Vmode_line_unwind_vector
;
8633 format_mode_line_unwind_data (obuf
, save_proptrans
)
8634 struct buffer
*obuf
;
8638 /* Reduce consing by keeping one vector in
8639 Vwith_echo_area_save_vector. */
8640 vector
= Vmode_line_unwind_vector
;
8641 Vmode_line_unwind_vector
= Qnil
;
8644 vector
= Fmake_vector (make_number (7), Qnil
);
8646 AREF (vector
, 0) = make_number (mode_line_target
);
8647 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8648 AREF (vector
, 2) = mode_line_string_list
;
8649 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8650 AREF (vector
, 4) = mode_line_string_face
;
8651 AREF (vector
, 5) = mode_line_string_face_prop
;
8654 XSETBUFFER (AREF (vector
, 6), obuf
);
8656 AREF (vector
, 6) = Qnil
;
8662 unwind_format_mode_line (vector
)
8665 mode_line_target
= XINT (AREF (vector
, 0));
8666 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8667 mode_line_string_list
= AREF (vector
, 2);
8668 if (! EQ (AREF (vector
, 3), Qt
))
8669 mode_line_proptrans_alist
= AREF (vector
, 3);
8670 mode_line_string_face
= AREF (vector
, 4);
8671 mode_line_string_face_prop
= AREF (vector
, 5);
8673 if (!NILP (AREF (vector
, 6)))
8675 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8676 AREF (vector
, 6) = Qnil
;
8679 Vmode_line_unwind_vector
= vector
;
8684 /* Store a single character C for the frame title in mode_line_noprop_buf.
8685 Re-allocate mode_line_noprop_buf if necessary. */
8689 store_mode_line_noprop_char (char c
)
8691 store_mode_line_noprop_char (c
)
8695 /* If output position has reached the end of the allocated buffer,
8696 double the buffer's size. */
8697 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8699 int len
= MODE_LINE_NOPROP_LEN (0);
8700 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8701 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8702 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8703 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8706 *mode_line_noprop_ptr
++ = c
;
8710 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8711 mode_line_noprop_ptr. STR is the string to store. Do not copy
8712 characters that yield more columns than PRECISION; PRECISION <= 0
8713 means copy the whole string. Pad with spaces until FIELD_WIDTH
8714 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8715 pad. Called from display_mode_element when it is used to build a
8719 store_mode_line_noprop (str
, field_width
, precision
)
8720 const unsigned char *str
;
8721 int field_width
, precision
;
8726 /* Copy at most PRECISION chars from STR. */
8727 nbytes
= strlen (str
);
8728 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8730 store_mode_line_noprop_char (*str
++);
8732 /* Fill up with spaces until FIELD_WIDTH reached. */
8733 while (field_width
> 0
8736 store_mode_line_noprop_char (' ');
8743 /***********************************************************************
8745 ***********************************************************************/
8747 #ifdef HAVE_WINDOW_SYSTEM
8749 /* Set the title of FRAME, if it has changed. The title format is
8750 Vicon_title_format if FRAME is iconified, otherwise it is
8751 frame_title_format. */
8754 x_consider_frame_title (frame
)
8757 struct frame
*f
= XFRAME (frame
);
8759 if (FRAME_WINDOW_P (f
)
8760 || FRAME_MINIBUF_ONLY_P (f
)
8761 || f
->explicit_name
)
8763 /* Do we have more than one visible frame on this X display? */
8770 int count
= SPECPDL_INDEX ();
8772 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8774 Lisp_Object other_frame
= XCAR (tail
);
8775 struct frame
*tf
= XFRAME (other_frame
);
8778 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8779 && !FRAME_MINIBUF_ONLY_P (tf
)
8780 && !EQ (other_frame
, tip_frame
)
8781 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8785 /* Set global variable indicating that multiple frames exist. */
8786 multiple_frames
= CONSP (tail
);
8788 /* Switch to the buffer of selected window of the frame. Set up
8789 mode_line_target so that display_mode_element will output into
8790 mode_line_noprop_buf; then display the title. */
8791 record_unwind_protect (unwind_format_mode_line
,
8792 format_mode_line_unwind_data (current_buffer
, 0));
8794 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8795 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8797 mode_line_target
= MODE_LINE_TITLE
;
8798 title_start
= MODE_LINE_NOPROP_LEN (0);
8799 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8800 NULL
, DEFAULT_FACE_ID
);
8801 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8802 len
= MODE_LINE_NOPROP_LEN (title_start
);
8803 title
= mode_line_noprop_buf
+ title_start
;
8804 unbind_to (count
, Qnil
);
8806 /* Set the title only if it's changed. This avoids consing in
8807 the common case where it hasn't. (If it turns out that we've
8808 already wasted too much time by walking through the list with
8809 display_mode_element, then we might need to optimize at a
8810 higher level than this.) */
8811 if (! STRINGP (f
->name
)
8812 || SBYTES (f
->name
) != len
8813 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8814 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8818 #endif /* not HAVE_WINDOW_SYSTEM */
8823 /***********************************************************************
8825 ***********************************************************************/
8828 /* Prepare for redisplay by updating menu-bar item lists when
8829 appropriate. This can call eval. */
8832 prepare_menu_bars ()
8835 struct gcpro gcpro1
, gcpro2
;
8837 Lisp_Object tooltip_frame
;
8839 #ifdef HAVE_WINDOW_SYSTEM
8840 tooltip_frame
= tip_frame
;
8842 tooltip_frame
= Qnil
;
8845 /* Update all frame titles based on their buffer names, etc. We do
8846 this before the menu bars so that the buffer-menu will show the
8847 up-to-date frame titles. */
8848 #ifdef HAVE_WINDOW_SYSTEM
8849 if (windows_or_buffers_changed
|| update_mode_lines
)
8851 Lisp_Object tail
, frame
;
8853 FOR_EACH_FRAME (tail
, frame
)
8856 if (!EQ (frame
, tooltip_frame
)
8857 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8858 x_consider_frame_title (frame
);
8861 #endif /* HAVE_WINDOW_SYSTEM */
8863 /* Update the menu bar item lists, if appropriate. This has to be
8864 done before any actual redisplay or generation of display lines. */
8865 all_windows
= (update_mode_lines
8866 || buffer_shared
> 1
8867 || windows_or_buffers_changed
);
8870 Lisp_Object tail
, frame
;
8871 int count
= SPECPDL_INDEX ();
8873 record_unwind_save_match_data ();
8875 FOR_EACH_FRAME (tail
, frame
)
8879 /* Ignore tooltip frame. */
8880 if (EQ (frame
, tooltip_frame
))
8883 /* If a window on this frame changed size, report that to
8884 the user and clear the size-change flag. */
8885 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8887 Lisp_Object functions
;
8889 /* Clear flag first in case we get an error below. */
8890 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8891 functions
= Vwindow_size_change_functions
;
8892 GCPRO2 (tail
, functions
);
8894 while (CONSP (functions
))
8896 call1 (XCAR (functions
), frame
);
8897 functions
= XCDR (functions
);
8903 update_menu_bar (f
, 0);
8904 #ifdef HAVE_WINDOW_SYSTEM
8905 update_tool_bar (f
, 0);
8910 unbind_to (count
, Qnil
);
8914 struct frame
*sf
= SELECTED_FRAME ();
8915 update_menu_bar (sf
, 1);
8916 #ifdef HAVE_WINDOW_SYSTEM
8917 update_tool_bar (sf
, 1);
8921 /* Motif needs this. See comment in xmenu.c. Turn it off when
8922 pending_menu_activation is not defined. */
8923 #ifdef USE_X_TOOLKIT
8924 pending_menu_activation
= 0;
8929 /* Update the menu bar item list for frame F. This has to be done
8930 before we start to fill in any display lines, because it can call
8933 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8936 update_menu_bar (f
, save_match_data
)
8938 int save_match_data
;
8941 register struct window
*w
;
8943 /* If called recursively during a menu update, do nothing. This can
8944 happen when, for instance, an activate-menubar-hook causes a
8946 if (inhibit_menubar_update
)
8949 window
= FRAME_SELECTED_WINDOW (f
);
8950 w
= XWINDOW (window
);
8952 #if 0 /* The if statement below this if statement used to include the
8953 condition !NILP (w->update_mode_line), rather than using
8954 update_mode_lines directly, and this if statement may have
8955 been added to make that condition work. Now the if
8956 statement below matches its comment, this isn't needed. */
8957 if (update_mode_lines
)
8958 w
->update_mode_line
= Qt
;
8961 if (FRAME_WINDOW_P (f
)
8963 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8964 || defined (USE_GTK)
8965 FRAME_EXTERNAL_MENU_BAR (f
)
8967 FRAME_MENU_BAR_LINES (f
) > 0
8969 : FRAME_MENU_BAR_LINES (f
) > 0)
8971 /* If the user has switched buffers or windows, we need to
8972 recompute to reflect the new bindings. But we'll
8973 recompute when update_mode_lines is set too; that means
8974 that people can use force-mode-line-update to request
8975 that the menu bar be recomputed. The adverse effect on
8976 the rest of the redisplay algorithm is about the same as
8977 windows_or_buffers_changed anyway. */
8978 if (windows_or_buffers_changed
8979 /* This used to test w->update_mode_line, but we believe
8980 there is no need to recompute the menu in that case. */
8981 || update_mode_lines
8982 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8983 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8984 != !NILP (w
->last_had_star
))
8985 || ((!NILP (Vtransient_mark_mode
)
8986 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8987 != !NILP (w
->region_showing
)))
8989 struct buffer
*prev
= current_buffer
;
8990 int count
= SPECPDL_INDEX ();
8992 specbind (Qinhibit_menubar_update
, Qt
);
8994 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8995 if (save_match_data
)
8996 record_unwind_save_match_data ();
8997 if (NILP (Voverriding_local_map_menu_flag
))
8999 specbind (Qoverriding_terminal_local_map
, Qnil
);
9000 specbind (Qoverriding_local_map
, Qnil
);
9003 /* Run the Lucid hook. */
9004 safe_run_hooks (Qactivate_menubar_hook
);
9006 /* If it has changed current-menubar from previous value,
9007 really recompute the menu-bar from the value. */
9008 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9009 call0 (Qrecompute_lucid_menubar
);
9011 safe_run_hooks (Qmenu_bar_update_hook
);
9012 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9014 /* Redisplay the menu bar in case we changed it. */
9015 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9016 || defined (USE_GTK)
9017 if (FRAME_WINDOW_P (f
)
9018 #if defined (MAC_OS)
9019 /* All frames on Mac OS share the same menubar. So only the
9020 selected frame should be allowed to set it. */
9021 && f
== SELECTED_FRAME ()
9024 set_frame_menubar (f
, 0, 0);
9026 /* On a terminal screen, the menu bar is an ordinary screen
9027 line, and this makes it get updated. */
9028 w
->update_mode_line
= Qt
;
9029 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9030 /* In the non-toolkit version, the menu bar is an ordinary screen
9031 line, and this makes it get updated. */
9032 w
->update_mode_line
= Qt
;
9033 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9035 unbind_to (count
, Qnil
);
9036 set_buffer_internal_1 (prev
);
9043 /***********************************************************************
9045 ***********************************************************************/
9047 #ifdef HAVE_WINDOW_SYSTEM
9050 Nominal cursor position -- where to draw output.
9051 HPOS and VPOS are window relative glyph matrix coordinates.
9052 X and Y are window relative pixel coordinates. */
9054 struct cursor_pos output_cursor
;
9058 Set the global variable output_cursor to CURSOR. All cursor
9059 positions are relative to updated_window. */
9062 set_output_cursor (cursor
)
9063 struct cursor_pos
*cursor
;
9065 output_cursor
.hpos
= cursor
->hpos
;
9066 output_cursor
.vpos
= cursor
->vpos
;
9067 output_cursor
.x
= cursor
->x
;
9068 output_cursor
.y
= cursor
->y
;
9073 Set a nominal cursor position.
9075 HPOS and VPOS are column/row positions in a window glyph matrix. X
9076 and Y are window text area relative pixel positions.
9078 If this is done during an update, updated_window will contain the
9079 window that is being updated and the position is the future output
9080 cursor position for that window. If updated_window is null, use
9081 selected_window and display the cursor at the given position. */
9084 x_cursor_to (vpos
, hpos
, y
, x
)
9085 int vpos
, hpos
, y
, x
;
9089 /* If updated_window is not set, work on selected_window. */
9093 w
= XWINDOW (selected_window
);
9095 /* Set the output cursor. */
9096 output_cursor
.hpos
= hpos
;
9097 output_cursor
.vpos
= vpos
;
9098 output_cursor
.x
= x
;
9099 output_cursor
.y
= y
;
9101 /* If not called as part of an update, really display the cursor.
9102 This will also set the cursor position of W. */
9103 if (updated_window
== NULL
)
9106 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9107 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9108 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9113 #endif /* HAVE_WINDOW_SYSTEM */
9116 /***********************************************************************
9118 ***********************************************************************/
9120 #ifdef HAVE_WINDOW_SYSTEM
9122 /* Where the mouse was last time we reported a mouse event. */
9124 FRAME_PTR last_mouse_frame
;
9126 /* Tool-bar item index of the item on which a mouse button was pressed
9129 int last_tool_bar_item
;
9132 /* Update the tool-bar item list for frame F. This has to be done
9133 before we start to fill in any display lines. Called from
9134 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9135 and restore it here. */
9138 update_tool_bar (f
, save_match_data
)
9140 int save_match_data
;
9143 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9145 int do_update
= WINDOWP (f
->tool_bar_window
)
9146 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9154 window
= FRAME_SELECTED_WINDOW (f
);
9155 w
= XWINDOW (window
);
9157 /* If the user has switched buffers or windows, we need to
9158 recompute to reflect the new bindings. But we'll
9159 recompute when update_mode_lines is set too; that means
9160 that people can use force-mode-line-update to request
9161 that the menu bar be recomputed. The adverse effect on
9162 the rest of the redisplay algorithm is about the same as
9163 windows_or_buffers_changed anyway. */
9164 if (windows_or_buffers_changed
9165 || !NILP (w
->update_mode_line
)
9166 || update_mode_lines
9167 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9168 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9169 != !NILP (w
->last_had_star
))
9170 || ((!NILP (Vtransient_mark_mode
)
9171 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9172 != !NILP (w
->region_showing
)))
9174 struct buffer
*prev
= current_buffer
;
9175 int count
= SPECPDL_INDEX ();
9176 Lisp_Object new_tool_bar
;
9178 struct gcpro gcpro1
;
9180 /* Set current_buffer to the buffer of the selected
9181 window of the frame, so that we get the right local
9183 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9185 /* Save match data, if we must. */
9186 if (save_match_data
)
9187 record_unwind_save_match_data ();
9189 /* Make sure that we don't accidentally use bogus keymaps. */
9190 if (NILP (Voverriding_local_map_menu_flag
))
9192 specbind (Qoverriding_terminal_local_map
, Qnil
);
9193 specbind (Qoverriding_local_map
, Qnil
);
9196 GCPRO1 (new_tool_bar
);
9198 /* Build desired tool-bar items from keymaps. */
9199 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9202 /* Redisplay the tool-bar if we changed it. */
9203 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9205 /* Redisplay that happens asynchronously due to an expose event
9206 may access f->tool_bar_items. Make sure we update both
9207 variables within BLOCK_INPUT so no such event interrupts. */
9209 f
->tool_bar_items
= new_tool_bar
;
9210 f
->n_tool_bar_items
= new_n_tool_bar
;
9211 w
->update_mode_line
= Qt
;
9217 unbind_to (count
, Qnil
);
9218 set_buffer_internal_1 (prev
);
9224 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9225 F's desired tool-bar contents. F->tool_bar_items must have
9226 been set up previously by calling prepare_menu_bars. */
9229 build_desired_tool_bar_string (f
)
9232 int i
, size
, size_needed
;
9233 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9234 Lisp_Object image
, plist
, props
;
9236 image
= plist
= props
= Qnil
;
9237 GCPRO3 (image
, plist
, props
);
9239 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9240 Otherwise, make a new string. */
9242 /* The size of the string we might be able to reuse. */
9243 size
= (STRINGP (f
->desired_tool_bar_string
)
9244 ? SCHARS (f
->desired_tool_bar_string
)
9247 /* We need one space in the string for each image. */
9248 size_needed
= f
->n_tool_bar_items
;
9250 /* Reuse f->desired_tool_bar_string, if possible. */
9251 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9252 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9256 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9257 Fremove_text_properties (make_number (0), make_number (size
),
9258 props
, f
->desired_tool_bar_string
);
9261 /* Put a `display' property on the string for the images to display,
9262 put a `menu_item' property on tool-bar items with a value that
9263 is the index of the item in F's tool-bar item vector. */
9264 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9266 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9268 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9269 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9270 int hmargin
, vmargin
, relief
, idx
, end
;
9271 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9273 /* If image is a vector, choose the image according to the
9275 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9276 if (VECTORP (image
))
9280 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9281 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9284 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9285 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9287 xassert (ASIZE (image
) >= idx
);
9288 image
= AREF (image
, idx
);
9293 /* Ignore invalid image specifications. */
9294 if (!valid_image_p (image
))
9297 /* Display the tool-bar button pressed, or depressed. */
9298 plist
= Fcopy_sequence (XCDR (image
));
9300 /* Compute margin and relief to draw. */
9301 relief
= (tool_bar_button_relief
>= 0
9302 ? tool_bar_button_relief
9303 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9304 hmargin
= vmargin
= relief
;
9306 if (INTEGERP (Vtool_bar_button_margin
)
9307 && XINT (Vtool_bar_button_margin
) > 0)
9309 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9310 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9312 else if (CONSP (Vtool_bar_button_margin
))
9314 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9315 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9316 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9318 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9319 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9320 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9323 if (auto_raise_tool_bar_buttons_p
)
9325 /* Add a `:relief' property to the image spec if the item is
9329 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9336 /* If image is selected, display it pressed, i.e. with a
9337 negative relief. If it's not selected, display it with a
9339 plist
= Fplist_put (plist
, QCrelief
,
9341 ? make_number (-relief
)
9342 : make_number (relief
)));
9347 /* Put a margin around the image. */
9348 if (hmargin
|| vmargin
)
9350 if (hmargin
== vmargin
)
9351 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9353 plist
= Fplist_put (plist
, QCmargin
,
9354 Fcons (make_number (hmargin
),
9355 make_number (vmargin
)));
9358 /* If button is not enabled, and we don't have special images
9359 for the disabled state, make the image appear disabled by
9360 applying an appropriate algorithm to it. */
9361 if (!enabled_p
&& idx
< 0)
9362 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9364 /* Put a `display' text property on the string for the image to
9365 display. Put a `menu-item' property on the string that gives
9366 the start of this item's properties in the tool-bar items
9368 image
= Fcons (Qimage
, plist
);
9369 props
= list4 (Qdisplay
, image
,
9370 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9372 /* Let the last image hide all remaining spaces in the tool bar
9373 string. The string can be longer than needed when we reuse a
9375 if (i
+ 1 == f
->n_tool_bar_items
)
9376 end
= SCHARS (f
->desired_tool_bar_string
);
9379 Fadd_text_properties (make_number (i
), make_number (end
),
9380 props
, f
->desired_tool_bar_string
);
9388 /* Display one line of the tool-bar of frame IT->f. */
9391 display_tool_bar_line (it
)
9394 struct glyph_row
*row
= it
->glyph_row
;
9395 int max_x
= it
->last_visible_x
;
9398 prepare_desired_row (row
);
9399 row
->y
= it
->current_y
;
9401 /* Note that this isn't made use of if the face hasn't a box,
9402 so there's no need to check the face here. */
9403 it
->start_of_box_run_p
= 1;
9405 while (it
->current_x
< max_x
)
9407 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9409 /* Get the next display element. */
9410 if (!get_next_display_element (it
))
9413 /* Produce glyphs. */
9414 x_before
= it
->current_x
;
9415 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9416 PRODUCE_GLYPHS (it
);
9418 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9423 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9425 if (x
+ glyph
->pixel_width
> max_x
)
9427 /* Glyph doesn't fit on line. */
9428 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9434 x
+= glyph
->pixel_width
;
9438 /* Stop at line ends. */
9439 if (ITERATOR_AT_END_OF_LINE_P (it
))
9442 set_iterator_to_next (it
, 1);
9447 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9448 extend_face_to_end_of_line (it
);
9449 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9450 last
->right_box_line_p
= 1;
9451 if (last
== row
->glyphs
[TEXT_AREA
])
9452 last
->left_box_line_p
= 1;
9453 compute_line_metrics (it
);
9455 /* If line is empty, make it occupy the rest of the tool-bar. */
9456 if (!row
->displays_text_p
)
9458 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9459 row
->ascent
= row
->phys_ascent
= 0;
9460 row
->extra_line_spacing
= 0;
9463 row
->full_width_p
= 1;
9464 row
->continued_p
= 0;
9465 row
->truncated_on_left_p
= 0;
9466 row
->truncated_on_right_p
= 0;
9468 it
->current_x
= it
->hpos
= 0;
9469 it
->current_y
+= row
->height
;
9475 /* Value is the number of screen lines needed to make all tool-bar
9476 items of frame F visible. */
9479 tool_bar_lines_needed (f
)
9482 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9485 /* Initialize an iterator for iteration over
9486 F->desired_tool_bar_string in the tool-bar window of frame F. */
9487 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9488 it
.first_visible_x
= 0;
9489 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9490 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9492 while (!ITERATOR_AT_END_P (&it
))
9494 it
.glyph_row
= w
->desired_matrix
->rows
;
9495 clear_glyph_row (it
.glyph_row
);
9496 display_tool_bar_line (&it
);
9499 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9503 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9505 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9514 frame
= selected_frame
;
9516 CHECK_FRAME (frame
);
9519 if (WINDOWP (f
->tool_bar_window
)
9520 || (w
= XWINDOW (f
->tool_bar_window
),
9521 WINDOW_TOTAL_LINES (w
) > 0))
9523 update_tool_bar (f
, 1);
9524 if (f
->n_tool_bar_items
)
9526 build_desired_tool_bar_string (f
);
9527 nlines
= tool_bar_lines_needed (f
);
9531 return make_number (nlines
);
9535 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9536 height should be changed. */
9539 redisplay_tool_bar (f
)
9544 struct glyph_row
*row
;
9545 int change_height_p
= 0;
9548 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9549 update_frame_tool_bar (f
);
9553 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9554 do anything. This means you must start with tool-bar-lines
9555 non-zero to get the auto-sizing effect. Or in other words, you
9556 can turn off tool-bars by specifying tool-bar-lines zero. */
9557 if (!WINDOWP (f
->tool_bar_window
)
9558 || (w
= XWINDOW (f
->tool_bar_window
),
9559 WINDOW_TOTAL_LINES (w
) == 0))
9562 /* Set up an iterator for the tool-bar window. */
9563 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9564 it
.first_visible_x
= 0;
9565 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9568 /* Build a string that represents the contents of the tool-bar. */
9569 build_desired_tool_bar_string (f
);
9570 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9572 /* Display as many lines as needed to display all tool-bar items. */
9573 while (it
.current_y
< it
.last_visible_y
)
9574 display_tool_bar_line (&it
);
9576 /* It doesn't make much sense to try scrolling in the tool-bar
9577 window, so don't do it. */
9578 w
->desired_matrix
->no_scrolling_p
= 1;
9579 w
->must_be_updated_p
= 1;
9581 if (auto_resize_tool_bars_p
)
9585 /* If we couldn't display everything, change the tool-bar's
9587 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9588 change_height_p
= 1;
9590 /* If there are blank lines at the end, except for a partially
9591 visible blank line at the end that is smaller than
9592 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9593 row
= it
.glyph_row
- 1;
9594 if (!row
->displays_text_p
9595 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9596 change_height_p
= 1;
9598 /* If row displays tool-bar items, but is partially visible,
9599 change the tool-bar's height. */
9600 if (row
->displays_text_p
9601 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9602 change_height_p
= 1;
9604 /* Resize windows as needed by changing the `tool-bar-lines'
9607 && (nlines
= tool_bar_lines_needed (f
),
9608 nlines
!= WINDOW_TOTAL_LINES (w
)))
9610 extern Lisp_Object Qtool_bar_lines
;
9612 int old_height
= WINDOW_TOTAL_LINES (w
);
9614 XSETFRAME (frame
, f
);
9615 clear_glyph_matrix (w
->desired_matrix
);
9616 Fmodify_frame_parameters (frame
,
9617 Fcons (Fcons (Qtool_bar_lines
,
9618 make_number (nlines
)),
9620 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9621 fonts_changed_p
= 1;
9625 return change_height_p
;
9629 /* Get information about the tool-bar item which is displayed in GLYPH
9630 on frame F. Return in *PROP_IDX the index where tool-bar item
9631 properties start in F->tool_bar_items. Value is zero if
9632 GLYPH doesn't display a tool-bar item. */
9635 tool_bar_item_info (f
, glyph
, prop_idx
)
9637 struct glyph
*glyph
;
9644 /* This function can be called asynchronously, which means we must
9645 exclude any possibility that Fget_text_property signals an
9647 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9648 charpos
= max (0, charpos
);
9650 /* Get the text property `menu-item' at pos. The value of that
9651 property is the start index of this item's properties in
9652 F->tool_bar_items. */
9653 prop
= Fget_text_property (make_number (charpos
),
9654 Qmenu_item
, f
->current_tool_bar_string
);
9655 if (INTEGERP (prop
))
9657 *prop_idx
= XINT (prop
);
9667 /* Get information about the tool-bar item at position X/Y on frame F.
9668 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9669 the current matrix of the tool-bar window of F, or NULL if not
9670 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9671 item in F->tool_bar_items. Value is
9673 -1 if X/Y is not on a tool-bar item
9674 0 if X/Y is on the same item that was highlighted before.
9678 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9681 struct glyph
**glyph
;
9682 int *hpos
, *vpos
, *prop_idx
;
9684 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9685 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9688 /* Find the glyph under X/Y. */
9689 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9693 /* Get the start of this tool-bar item's properties in
9694 f->tool_bar_items. */
9695 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9698 /* Is mouse on the highlighted item? */
9699 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9700 && *vpos
>= dpyinfo
->mouse_face_beg_row
9701 && *vpos
<= dpyinfo
->mouse_face_end_row
9702 && (*vpos
> dpyinfo
->mouse_face_beg_row
9703 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9704 && (*vpos
< dpyinfo
->mouse_face_end_row
9705 || *hpos
< dpyinfo
->mouse_face_end_col
9706 || dpyinfo
->mouse_face_past_end
))
9714 Handle mouse button event on the tool-bar of frame F, at
9715 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9716 0 for button release. MODIFIERS is event modifiers for button
9720 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9723 unsigned int modifiers
;
9725 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9726 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9727 int hpos
, vpos
, prop_idx
;
9728 struct glyph
*glyph
;
9729 Lisp_Object enabled_p
;
9731 /* If not on the highlighted tool-bar item, return. */
9732 frame_to_window_pixel_xy (w
, &x
, &y
);
9733 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9736 /* If item is disabled, do nothing. */
9737 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9738 if (NILP (enabled_p
))
9743 /* Show item in pressed state. */
9744 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9745 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9746 last_tool_bar_item
= prop_idx
;
9750 Lisp_Object key
, frame
;
9751 struct input_event event
;
9754 /* Show item in released state. */
9755 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9756 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9758 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9760 XSETFRAME (frame
, f
);
9761 event
.kind
= TOOL_BAR_EVENT
;
9762 event
.frame_or_window
= frame
;
9764 kbd_buffer_store_event (&event
);
9766 event
.kind
= TOOL_BAR_EVENT
;
9767 event
.frame_or_window
= frame
;
9769 event
.modifiers
= modifiers
;
9770 kbd_buffer_store_event (&event
);
9771 last_tool_bar_item
= -1;
9776 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9777 tool-bar window-relative coordinates X/Y. Called from
9778 note_mouse_highlight. */
9781 note_tool_bar_highlight (f
, x
, y
)
9785 Lisp_Object window
= f
->tool_bar_window
;
9786 struct window
*w
= XWINDOW (window
);
9787 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9789 struct glyph
*glyph
;
9790 struct glyph_row
*row
;
9792 Lisp_Object enabled_p
;
9794 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9795 int mouse_down_p
, rc
;
9797 /* Function note_mouse_highlight is called with negative x(y
9798 values when mouse moves outside of the frame. */
9799 if (x
<= 0 || y
<= 0)
9801 clear_mouse_face (dpyinfo
);
9805 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9808 /* Not on tool-bar item. */
9809 clear_mouse_face (dpyinfo
);
9813 /* On same tool-bar item as before. */
9816 clear_mouse_face (dpyinfo
);
9818 /* Mouse is down, but on different tool-bar item? */
9819 mouse_down_p
= (dpyinfo
->grabbed
9820 && f
== last_mouse_frame
9821 && FRAME_LIVE_P (f
));
9823 && last_tool_bar_item
!= prop_idx
)
9826 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9827 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9829 /* If tool-bar item is not enabled, don't highlight it. */
9830 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9831 if (!NILP (enabled_p
))
9833 /* Compute the x-position of the glyph. In front and past the
9834 image is a space. We include this in the highlighted area. */
9835 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9836 for (i
= x
= 0; i
< hpos
; ++i
)
9837 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9839 /* Record this as the current active region. */
9840 dpyinfo
->mouse_face_beg_col
= hpos
;
9841 dpyinfo
->mouse_face_beg_row
= vpos
;
9842 dpyinfo
->mouse_face_beg_x
= x
;
9843 dpyinfo
->mouse_face_beg_y
= row
->y
;
9844 dpyinfo
->mouse_face_past_end
= 0;
9846 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9847 dpyinfo
->mouse_face_end_row
= vpos
;
9848 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9849 dpyinfo
->mouse_face_end_y
= row
->y
;
9850 dpyinfo
->mouse_face_window
= window
;
9851 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9853 /* Display it as active. */
9854 show_mouse_face (dpyinfo
, draw
);
9855 dpyinfo
->mouse_face_image_state
= draw
;
9860 /* Set help_echo_string to a help string to display for this tool-bar item.
9861 XTread_socket does the rest. */
9862 help_echo_object
= help_echo_window
= Qnil
;
9864 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9865 if (NILP (help_echo_string
))
9866 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9869 #endif /* HAVE_WINDOW_SYSTEM */
9873 /************************************************************************
9874 Horizontal scrolling
9875 ************************************************************************/
9877 static int hscroll_window_tree
P_ ((Lisp_Object
));
9878 static int hscroll_windows
P_ ((Lisp_Object
));
9880 /* For all leaf windows in the window tree rooted at WINDOW, set their
9881 hscroll value so that PT is (i) visible in the window, and (ii) so
9882 that it is not within a certain margin at the window's left and
9883 right border. Value is non-zero if any window's hscroll has been
9887 hscroll_window_tree (window
)
9890 int hscrolled_p
= 0;
9891 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9892 int hscroll_step_abs
= 0;
9893 double hscroll_step_rel
= 0;
9895 if (hscroll_relative_p
)
9897 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9898 if (hscroll_step_rel
< 0)
9900 hscroll_relative_p
= 0;
9901 hscroll_step_abs
= 0;
9904 else if (INTEGERP (Vhscroll_step
))
9906 hscroll_step_abs
= XINT (Vhscroll_step
);
9907 if (hscroll_step_abs
< 0)
9908 hscroll_step_abs
= 0;
9911 hscroll_step_abs
= 0;
9913 while (WINDOWP (window
))
9915 struct window
*w
= XWINDOW (window
);
9917 if (WINDOWP (w
->hchild
))
9918 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9919 else if (WINDOWP (w
->vchild
))
9920 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9921 else if (w
->cursor
.vpos
>= 0)
9924 int text_area_width
;
9925 struct glyph_row
*current_cursor_row
9926 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9927 struct glyph_row
*desired_cursor_row
9928 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9929 struct glyph_row
*cursor_row
9930 = (desired_cursor_row
->enabled_p
9931 ? desired_cursor_row
9932 : current_cursor_row
);
9934 text_area_width
= window_box_width (w
, TEXT_AREA
);
9936 /* Scroll when cursor is inside this scroll margin. */
9937 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9939 if ((XFASTINT (w
->hscroll
)
9940 && w
->cursor
.x
<= h_margin
)
9941 || (cursor_row
->enabled_p
9942 && cursor_row
->truncated_on_right_p
9943 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9947 struct buffer
*saved_current_buffer
;
9951 /* Find point in a display of infinite width. */
9952 saved_current_buffer
= current_buffer
;
9953 current_buffer
= XBUFFER (w
->buffer
);
9955 if (w
== XWINDOW (selected_window
))
9956 pt
= BUF_PT (current_buffer
);
9959 pt
= marker_position (w
->pointm
);
9960 pt
= max (BEGV
, pt
);
9964 /* Move iterator to pt starting at cursor_row->start in
9965 a line with infinite width. */
9966 init_to_row_start (&it
, w
, cursor_row
);
9967 it
.last_visible_x
= INFINITY
;
9968 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9969 current_buffer
= saved_current_buffer
;
9971 /* Position cursor in window. */
9972 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9973 hscroll
= max (0, (it
.current_x
9974 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9975 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9976 : (text_area_width
/ 2))))
9977 / FRAME_COLUMN_WIDTH (it
.f
);
9978 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9980 if (hscroll_relative_p
)
9981 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9984 wanted_x
= text_area_width
9985 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9988 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9992 if (hscroll_relative_p
)
9993 wanted_x
= text_area_width
* hscroll_step_rel
9996 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9999 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10001 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10003 /* Don't call Fset_window_hscroll if value hasn't
10004 changed because it will prevent redisplay
10006 if (XFASTINT (w
->hscroll
) != hscroll
)
10008 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10009 w
->hscroll
= make_number (hscroll
);
10018 /* Value is non-zero if hscroll of any leaf window has been changed. */
10019 return hscrolled_p
;
10023 /* Set hscroll so that cursor is visible and not inside horizontal
10024 scroll margins for all windows in the tree rooted at WINDOW. See
10025 also hscroll_window_tree above. Value is non-zero if any window's
10026 hscroll has been changed. If it has, desired matrices on the frame
10027 of WINDOW are cleared. */
10030 hscroll_windows (window
)
10031 Lisp_Object window
;
10035 if (automatic_hscrolling_p
)
10037 hscrolled_p
= hscroll_window_tree (window
);
10039 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10043 return hscrolled_p
;
10048 /************************************************************************
10050 ************************************************************************/
10052 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10053 to a non-zero value. This is sometimes handy to have in a debugger
10058 /* First and last unchanged row for try_window_id. */
10060 int debug_first_unchanged_at_end_vpos
;
10061 int debug_last_unchanged_at_beg_vpos
;
10063 /* Delta vpos and y. */
10065 int debug_dvpos
, debug_dy
;
10067 /* Delta in characters and bytes for try_window_id. */
10069 int debug_delta
, debug_delta_bytes
;
10071 /* Values of window_end_pos and window_end_vpos at the end of
10074 EMACS_INT debug_end_pos
, debug_end_vpos
;
10076 /* Append a string to W->desired_matrix->method. FMT is a printf
10077 format string. A1...A9 are a supplement for a variable-length
10078 argument list. If trace_redisplay_p is non-zero also printf the
10079 resulting string to stderr. */
10082 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10085 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10088 char *method
= w
->desired_matrix
->method
;
10089 int len
= strlen (method
);
10090 int size
= sizeof w
->desired_matrix
->method
;
10091 int remaining
= size
- len
- 1;
10093 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10094 if (len
&& remaining
)
10097 --remaining
, ++len
;
10100 strncpy (method
+ len
, buffer
, remaining
);
10102 if (trace_redisplay_p
)
10103 fprintf (stderr
, "%p (%s): %s\n",
10105 ((BUFFERP (w
->buffer
)
10106 && STRINGP (XBUFFER (w
->buffer
)->name
))
10107 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10112 #endif /* GLYPH_DEBUG */
10115 /* Value is non-zero if all changes in window W, which displays
10116 current_buffer, are in the text between START and END. START is a
10117 buffer position, END is given as a distance from Z. Used in
10118 redisplay_internal for display optimization. */
10121 text_outside_line_unchanged_p (w
, start
, end
)
10125 int unchanged_p
= 1;
10127 /* If text or overlays have changed, see where. */
10128 if (XFASTINT (w
->last_modified
) < MODIFF
10129 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10131 /* Gap in the line? */
10132 if (GPT
< start
|| Z
- GPT
< end
)
10135 /* Changes start in front of the line, or end after it? */
10137 && (BEG_UNCHANGED
< start
- 1
10138 || END_UNCHANGED
< end
))
10141 /* If selective display, can't optimize if changes start at the
10142 beginning of the line. */
10144 && INTEGERP (current_buffer
->selective_display
)
10145 && XINT (current_buffer
->selective_display
) > 0
10146 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10149 /* If there are overlays at the start or end of the line, these
10150 may have overlay strings with newlines in them. A change at
10151 START, for instance, may actually concern the display of such
10152 overlay strings as well, and they are displayed on different
10153 lines. So, quickly rule out this case. (For the future, it
10154 might be desirable to implement something more telling than
10155 just BEG/END_UNCHANGED.) */
10158 if (BEG
+ BEG_UNCHANGED
== start
10159 && overlay_touches_p (start
))
10161 if (END_UNCHANGED
== end
10162 && overlay_touches_p (Z
- end
))
10167 return unchanged_p
;
10171 /* Do a frame update, taking possible shortcuts into account. This is
10172 the main external entry point for redisplay.
10174 If the last redisplay displayed an echo area message and that message
10175 is no longer requested, we clear the echo area or bring back the
10176 mini-buffer if that is in use. */
10181 redisplay_internal (0);
10186 overlay_arrow_string_or_property (var
)
10191 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10194 return Voverlay_arrow_string
;
10197 /* Return 1 if there are any overlay-arrows in current_buffer. */
10199 overlay_arrow_in_current_buffer_p ()
10203 for (vlist
= Voverlay_arrow_variable_list
;
10205 vlist
= XCDR (vlist
))
10207 Lisp_Object var
= XCAR (vlist
);
10210 if (!SYMBOLP (var
))
10212 val
= find_symbol_value (var
);
10214 && current_buffer
== XMARKER (val
)->buffer
)
10221 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10225 overlay_arrows_changed_p ()
10229 for (vlist
= Voverlay_arrow_variable_list
;
10231 vlist
= XCDR (vlist
))
10233 Lisp_Object var
= XCAR (vlist
);
10234 Lisp_Object val
, pstr
;
10236 if (!SYMBOLP (var
))
10238 val
= find_symbol_value (var
);
10239 if (!MARKERP (val
))
10241 if (! EQ (COERCE_MARKER (val
),
10242 Fget (var
, Qlast_arrow_position
))
10243 || ! (pstr
= overlay_arrow_string_or_property (var
),
10244 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10250 /* Mark overlay arrows to be updated on next redisplay. */
10253 update_overlay_arrows (up_to_date
)
10258 for (vlist
= Voverlay_arrow_variable_list
;
10260 vlist
= XCDR (vlist
))
10262 Lisp_Object var
= XCAR (vlist
);
10264 if (!SYMBOLP (var
))
10267 if (up_to_date
> 0)
10269 Lisp_Object val
= find_symbol_value (var
);
10270 Fput (var
, Qlast_arrow_position
,
10271 COERCE_MARKER (val
));
10272 Fput (var
, Qlast_arrow_string
,
10273 overlay_arrow_string_or_property (var
));
10275 else if (up_to_date
< 0
10276 || !NILP (Fget (var
, Qlast_arrow_position
)))
10278 Fput (var
, Qlast_arrow_position
, Qt
);
10279 Fput (var
, Qlast_arrow_string
, Qt
);
10285 /* Return overlay arrow string to display at row.
10286 Return integer (bitmap number) for arrow bitmap in left fringe.
10287 Return nil if no overlay arrow. */
10290 overlay_arrow_at_row (it
, row
)
10292 struct glyph_row
*row
;
10296 for (vlist
= Voverlay_arrow_variable_list
;
10298 vlist
= XCDR (vlist
))
10300 Lisp_Object var
= XCAR (vlist
);
10303 if (!SYMBOLP (var
))
10306 val
= find_symbol_value (var
);
10309 && current_buffer
== XMARKER (val
)->buffer
10310 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10312 if (FRAME_WINDOW_P (it
->f
)
10313 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10315 #ifdef HAVE_WINDOW_SYSTEM
10316 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10319 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10320 return make_number (fringe_bitmap
);
10323 return make_number (-1); /* Use default arrow bitmap */
10325 return overlay_arrow_string_or_property (var
);
10332 /* Return 1 if point moved out of or into a composition. Otherwise
10333 return 0. PREV_BUF and PREV_PT are the last point buffer and
10334 position. BUF and PT are the current point buffer and position. */
10337 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10338 struct buffer
*prev_buf
, *buf
;
10343 Lisp_Object buffer
;
10345 XSETBUFFER (buffer
, buf
);
10346 /* Check a composition at the last point if point moved within the
10348 if (prev_buf
== buf
)
10351 /* Point didn't move. */
10354 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10355 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10356 && COMPOSITION_VALID_P (start
, end
, prop
)
10357 && start
< prev_pt
&& end
> prev_pt
)
10358 /* The last point was within the composition. Return 1 iff
10359 point moved out of the composition. */
10360 return (pt
<= start
|| pt
>= end
);
10363 /* Check a composition at the current point. */
10364 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10365 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10366 && COMPOSITION_VALID_P (start
, end
, prop
)
10367 && start
< pt
&& end
> pt
);
10371 /* Reconsider the setting of B->clip_changed which is displayed
10375 reconsider_clip_changes (w
, b
)
10379 if (b
->clip_changed
10380 && !NILP (w
->window_end_valid
)
10381 && w
->current_matrix
->buffer
== b
10382 && w
->current_matrix
->zv
== BUF_ZV (b
)
10383 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10384 b
->clip_changed
= 0;
10386 /* If display wasn't paused, and W is not a tool bar window, see if
10387 point has been moved into or out of a composition. In that case,
10388 we set b->clip_changed to 1 to force updating the screen. If
10389 b->clip_changed has already been set to 1, we can skip this
10391 if (!b
->clip_changed
10392 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10396 if (w
== XWINDOW (selected_window
))
10397 pt
= BUF_PT (current_buffer
);
10399 pt
= marker_position (w
->pointm
);
10401 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10402 || pt
!= XINT (w
->last_point
))
10403 && check_point_in_composition (w
->current_matrix
->buffer
,
10404 XINT (w
->last_point
),
10405 XBUFFER (w
->buffer
), pt
))
10406 b
->clip_changed
= 1;
10411 /* Select FRAME to forward the values of frame-local variables into C
10412 variables so that the redisplay routines can access those values
10416 select_frame_for_redisplay (frame
)
10419 Lisp_Object tail
, sym
, val
;
10420 Lisp_Object old
= selected_frame
;
10422 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
10424 selected_frame
= frame
;
10426 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10427 if (CONSP (XCAR (tail
))
10428 && (sym
= XCAR (XCAR (tail
)),
10430 && (sym
= indirect_variable (sym
),
10431 val
= SYMBOL_VALUE (sym
),
10432 (BUFFER_LOCAL_VALUEP (val
)
10433 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10434 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10435 /* Use find_symbol_value rather than Fsymbol_value
10436 to avoid an error if it is void. */
10437 find_symbol_value (sym
);
10439 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10440 if (CONSP (XCAR (tail
))
10441 && (sym
= XCAR (XCAR (tail
)),
10443 && (sym
= indirect_variable (sym
),
10444 val
= SYMBOL_VALUE (sym
),
10445 (BUFFER_LOCAL_VALUEP (val
)
10446 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10447 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10448 find_symbol_value (sym
);
10452 #define STOP_POLLING \
10453 do { if (! polling_stopped_here) stop_polling (); \
10454 polling_stopped_here = 1; } while (0)
10456 #define RESUME_POLLING \
10457 do { if (polling_stopped_here) start_polling (); \
10458 polling_stopped_here = 0; } while (0)
10461 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10462 response to any user action; therefore, we should preserve the echo
10463 area. (Actually, our caller does that job.) Perhaps in the future
10464 avoid recentering windows if it is not necessary; currently that
10465 causes some problems. */
10468 redisplay_internal (preserve_echo_area
)
10469 int preserve_echo_area
;
10471 struct window
*w
= XWINDOW (selected_window
);
10472 struct frame
*f
= XFRAME (w
->frame
);
10474 int must_finish
= 0;
10475 struct text_pos tlbufpos
, tlendpos
;
10476 int number_of_visible_frames
;
10478 struct frame
*sf
= SELECTED_FRAME ();
10479 int polling_stopped_here
= 0;
10481 /* Non-zero means redisplay has to consider all windows on all
10482 frames. Zero means, only selected_window is considered. */
10483 int consider_all_windows_p
;
10485 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10487 /* No redisplay if running in batch mode or frame is not yet fully
10488 initialized, or redisplay is explicitly turned off by setting
10489 Vinhibit_redisplay. */
10491 || !NILP (Vinhibit_redisplay
)
10492 || !f
->glyphs_initialized_p
)
10495 /* The flag redisplay_performed_directly_p is set by
10496 direct_output_for_insert when it already did the whole screen
10497 update necessary. */
10498 if (redisplay_performed_directly_p
)
10500 redisplay_performed_directly_p
= 0;
10501 if (!hscroll_windows (selected_window
))
10505 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10506 if (popup_activated ())
10510 /* I don't think this happens but let's be paranoid. */
10511 if (redisplaying_p
)
10514 /* Record a function that resets redisplaying_p to its old value
10515 when we leave this function. */
10516 count
= SPECPDL_INDEX ();
10517 record_unwind_protect (unwind_redisplay
,
10518 Fcons (make_number (redisplaying_p
), selected_frame
));
10520 specbind (Qinhibit_free_realized_faces
, Qnil
);
10523 Lisp_Object tail
, frame
;
10525 FOR_EACH_FRAME (tail
, frame
)
10527 struct frame
*f
= XFRAME (frame
);
10528 f
->already_hscrolled_p
= 0;
10534 reconsider_clip_changes (w
, current_buffer
);
10536 /* If new fonts have been loaded that make a glyph matrix adjustment
10537 necessary, do it. */
10538 if (fonts_changed_p
)
10540 adjust_glyphs (NULL
);
10541 ++windows_or_buffers_changed
;
10542 fonts_changed_p
= 0;
10545 /* If face_change_count is non-zero, init_iterator will free all
10546 realized faces, which includes the faces referenced from current
10547 matrices. So, we can't reuse current matrices in this case. */
10548 if (face_change_count
)
10549 ++windows_or_buffers_changed
;
10551 if (FRAME_TERMCAP_P (sf
)
10552 && FRAME_TTY (sf
)->previous_frame
!= sf
)
10554 /* Since frames on a single ASCII terminal share the same
10555 display area, displaying a different frame means redisplay
10556 the whole thing. */
10557 windows_or_buffers_changed
++;
10558 SET_FRAME_GARBAGED (sf
);
10559 FRAME_TTY (sf
)->previous_frame
= sf
;
10562 /* Set the visible flags for all frames. Do this before checking
10563 for resized or garbaged frames; they want to know if their frames
10564 are visible. See the comment in frame.h for
10565 FRAME_SAMPLE_VISIBILITY. */
10567 Lisp_Object tail
, frame
;
10569 number_of_visible_frames
= 0;
10571 FOR_EACH_FRAME (tail
, frame
)
10573 struct frame
*f
= XFRAME (frame
);
10575 FRAME_SAMPLE_VISIBILITY (f
);
10576 if (FRAME_VISIBLE_P (f
))
10577 ++number_of_visible_frames
;
10578 clear_desired_matrices (f
);
10583 /* Notice any pending interrupt request to change frame size. */
10584 do_pending_window_change (1);
10586 /* Clear frames marked as garbaged. */
10587 if (frame_garbaged
)
10588 clear_garbaged_frames ();
10590 /* Build menubar and tool-bar items. */
10591 if (NILP (Vmemory_full
))
10592 prepare_menu_bars ();
10594 if (windows_or_buffers_changed
)
10595 update_mode_lines
++;
10597 /* Detect case that we need to write or remove a star in the mode line. */
10598 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10600 w
->update_mode_line
= Qt
;
10601 if (buffer_shared
> 1)
10602 update_mode_lines
++;
10605 /* If %c is in the mode line, update it if needed. */
10606 if (!NILP (w
->column_number_displayed
)
10607 /* This alternative quickly identifies a common case
10608 where no change is needed. */
10609 && !(PT
== XFASTINT (w
->last_point
)
10610 && XFASTINT (w
->last_modified
) >= MODIFF
10611 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10612 && (XFASTINT (w
->column_number_displayed
)
10613 != (int) current_column ())) /* iftc */
10614 w
->update_mode_line
= Qt
;
10616 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10618 /* The variable buffer_shared is set in redisplay_window and
10619 indicates that we redisplay a buffer in different windows. See
10621 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10622 || cursor_type_changed
);
10624 /* If specs for an arrow have changed, do thorough redisplay
10625 to ensure we remove any arrow that should no longer exist. */
10626 if (overlay_arrows_changed_p ())
10627 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10629 /* Normally the message* functions will have already displayed and
10630 updated the echo area, but the frame may have been trashed, or
10631 the update may have been preempted, so display the echo area
10632 again here. Checking message_cleared_p captures the case that
10633 the echo area should be cleared. */
10634 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10635 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10636 || (message_cleared_p
10637 && minibuf_level
== 0
10638 /* If the mini-window is currently selected, this means the
10639 echo-area doesn't show through. */
10640 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10642 int window_height_changed_p
= echo_area_display (0);
10645 /* If we don't display the current message, don't clear the
10646 message_cleared_p flag, because, if we did, we wouldn't clear
10647 the echo area in the next redisplay which doesn't preserve
10649 if (!display_last_displayed_message_p
)
10650 message_cleared_p
= 0;
10652 if (fonts_changed_p
)
10654 else if (window_height_changed_p
)
10656 consider_all_windows_p
= 1;
10657 ++update_mode_lines
;
10658 ++windows_or_buffers_changed
;
10660 /* If window configuration was changed, frames may have been
10661 marked garbaged. Clear them or we will experience
10662 surprises wrt scrolling. */
10663 if (frame_garbaged
)
10664 clear_garbaged_frames ();
10667 else if (EQ (selected_window
, minibuf_window
)
10668 && (current_buffer
->clip_changed
10669 || XFASTINT (w
->last_modified
) < MODIFF
10670 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10671 && resize_mini_window (w
, 0))
10673 /* Resized active mini-window to fit the size of what it is
10674 showing if its contents might have changed. */
10676 consider_all_windows_p
= 1;
10677 ++windows_or_buffers_changed
;
10678 ++update_mode_lines
;
10680 /* If window configuration was changed, frames may have been
10681 marked garbaged. Clear them or we will experience
10682 surprises wrt scrolling. */
10683 if (frame_garbaged
)
10684 clear_garbaged_frames ();
10688 /* If showing the region, and mark has changed, we must redisplay
10689 the whole window. The assignment to this_line_start_pos prevents
10690 the optimization directly below this if-statement. */
10691 if (((!NILP (Vtransient_mark_mode
)
10692 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10693 != !NILP (w
->region_showing
))
10694 || (!NILP (w
->region_showing
)
10695 && !EQ (w
->region_showing
,
10696 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10697 CHARPOS (this_line_start_pos
) = 0;
10699 /* Optimize the case that only the line containing the cursor in the
10700 selected window has changed. Variables starting with this_ are
10701 set in display_line and record information about the line
10702 containing the cursor. */
10703 tlbufpos
= this_line_start_pos
;
10704 tlendpos
= this_line_end_pos
;
10705 if (!consider_all_windows_p
10706 && CHARPOS (tlbufpos
) > 0
10707 && NILP (w
->update_mode_line
)
10708 && !current_buffer
->clip_changed
10709 && !current_buffer
->prevent_redisplay_optimizations_p
10710 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10711 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10712 /* Make sure recorded data applies to current buffer, etc. */
10713 && this_line_buffer
== current_buffer
10714 && current_buffer
== XBUFFER (w
->buffer
)
10715 && NILP (w
->force_start
)
10716 && NILP (w
->optional_new_start
)
10717 /* Point must be on the line that we have info recorded about. */
10718 && PT
>= CHARPOS (tlbufpos
)
10719 && PT
<= Z
- CHARPOS (tlendpos
)
10720 /* All text outside that line, including its final newline,
10721 must be unchanged */
10722 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10723 CHARPOS (tlendpos
)))
10725 if (CHARPOS (tlbufpos
) > BEGV
10726 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10727 && (CHARPOS (tlbufpos
) == ZV
10728 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10729 /* Former continuation line has disappeared by becoming empty */
10731 else if (XFASTINT (w
->last_modified
) < MODIFF
10732 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10733 || MINI_WINDOW_P (w
))
10735 /* We have to handle the case of continuation around a
10736 wide-column character (See the comment in indent.c around
10739 For instance, in the following case:
10741 -------- Insert --------
10742 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10743 J_I_ ==> J_I_ `^^' are cursors.
10747 As we have to redraw the line above, we should goto cancel. */
10750 int line_height_before
= this_line_pixel_height
;
10752 /* Note that start_display will handle the case that the
10753 line starting at tlbufpos is a continuation lines. */
10754 start_display (&it
, w
, tlbufpos
);
10756 /* Implementation note: It this still necessary? */
10757 if (it
.current_x
!= this_line_start_x
)
10760 TRACE ((stderr
, "trying display optimization 1\n"));
10761 w
->cursor
.vpos
= -1;
10762 overlay_arrow_seen
= 0;
10763 it
.vpos
= this_line_vpos
;
10764 it
.current_y
= this_line_y
;
10765 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10766 display_line (&it
);
10768 /* If line contains point, is not continued,
10769 and ends at same distance from eob as before, we win */
10770 if (w
->cursor
.vpos
>= 0
10771 /* Line is not continued, otherwise this_line_start_pos
10772 would have been set to 0 in display_line. */
10773 && CHARPOS (this_line_start_pos
)
10774 /* Line ends as before. */
10775 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10776 /* Line has same height as before. Otherwise other lines
10777 would have to be shifted up or down. */
10778 && this_line_pixel_height
== line_height_before
)
10780 /* If this is not the window's last line, we must adjust
10781 the charstarts of the lines below. */
10782 if (it
.current_y
< it
.last_visible_y
)
10784 struct glyph_row
*row
10785 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10786 int delta
, delta_bytes
;
10788 if (Z
- CHARPOS (tlendpos
) == ZV
)
10790 /* This line ends at end of (accessible part of)
10791 buffer. There is no newline to count. */
10793 - CHARPOS (tlendpos
)
10794 - MATRIX_ROW_START_CHARPOS (row
));
10795 delta_bytes
= (Z_BYTE
10796 - BYTEPOS (tlendpos
)
10797 - MATRIX_ROW_START_BYTEPOS (row
));
10801 /* This line ends in a newline. Must take
10802 account of the newline and the rest of the
10803 text that follows. */
10805 - CHARPOS (tlendpos
)
10806 - MATRIX_ROW_START_CHARPOS (row
));
10807 delta_bytes
= (Z_BYTE
10808 - BYTEPOS (tlendpos
)
10809 - MATRIX_ROW_START_BYTEPOS (row
));
10812 increment_matrix_positions (w
->current_matrix
,
10813 this_line_vpos
+ 1,
10814 w
->current_matrix
->nrows
,
10815 delta
, delta_bytes
);
10818 /* If this row displays text now but previously didn't,
10819 or vice versa, w->window_end_vpos may have to be
10821 if ((it
.glyph_row
- 1)->displays_text_p
)
10823 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10824 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10826 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10827 && this_line_vpos
> 0)
10828 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10829 w
->window_end_valid
= Qnil
;
10831 /* Update hint: No need to try to scroll in update_window. */
10832 w
->desired_matrix
->no_scrolling_p
= 1;
10835 *w
->desired_matrix
->method
= 0;
10836 debug_method_add (w
, "optimization 1");
10838 #ifdef HAVE_WINDOW_SYSTEM
10839 update_window_fringes (w
, 0);
10846 else if (/* Cursor position hasn't changed. */
10847 PT
== XFASTINT (w
->last_point
)
10848 /* Make sure the cursor was last displayed
10849 in this window. Otherwise we have to reposition it. */
10850 && 0 <= w
->cursor
.vpos
10851 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10855 do_pending_window_change (1);
10857 /* We used to always goto end_of_redisplay here, but this
10858 isn't enough if we have a blinking cursor. */
10859 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10860 goto end_of_redisplay
;
10864 /* If highlighting the region, or if the cursor is in the echo area,
10865 then we can't just move the cursor. */
10866 else if (! (!NILP (Vtransient_mark_mode
)
10867 && !NILP (current_buffer
->mark_active
))
10868 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10869 || highlight_nonselected_windows
)
10870 && NILP (w
->region_showing
)
10871 && NILP (Vshow_trailing_whitespace
)
10872 && !cursor_in_echo_area
)
10875 struct glyph_row
*row
;
10877 /* Skip from tlbufpos to PT and see where it is. Note that
10878 PT may be in invisible text. If so, we will end at the
10879 next visible position. */
10880 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10881 NULL
, DEFAULT_FACE_ID
);
10882 it
.current_x
= this_line_start_x
;
10883 it
.current_y
= this_line_y
;
10884 it
.vpos
= this_line_vpos
;
10886 /* The call to move_it_to stops in front of PT, but
10887 moves over before-strings. */
10888 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10890 if (it
.vpos
== this_line_vpos
10891 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10894 xassert (this_line_vpos
== it
.vpos
);
10895 xassert (this_line_y
== it
.current_y
);
10896 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10898 *w
->desired_matrix
->method
= 0;
10899 debug_method_add (w
, "optimization 3");
10908 /* Text changed drastically or point moved off of line. */
10909 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10912 CHARPOS (this_line_start_pos
) = 0;
10913 consider_all_windows_p
|= buffer_shared
> 1;
10914 ++clear_face_cache_count
;
10915 #ifdef HAVE_WINDOW_SYSTEM
10916 ++clear_image_cache_count
;
10919 /* Build desired matrices, and update the display. If
10920 consider_all_windows_p is non-zero, do it for all windows on all
10921 frames. Otherwise do it for selected_window, only. */
10923 if (consider_all_windows_p
)
10925 Lisp_Object tail
, frame
;
10927 FOR_EACH_FRAME (tail
, frame
)
10928 XFRAME (frame
)->updated_p
= 0;
10930 /* Recompute # windows showing selected buffer. This will be
10931 incremented each time such a window is displayed. */
10934 FOR_EACH_FRAME (tail
, frame
)
10936 struct frame
*f
= XFRAME (frame
);
10938 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
10940 if (! EQ (frame
, selected_frame
))
10941 /* Select the frame, for the sake of frame-local
10943 select_frame_for_redisplay (frame
);
10945 /* Mark all the scroll bars to be removed; we'll redeem
10946 the ones we want when we redisplay their windows. */
10947 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
10948 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
10950 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10951 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10953 /* Any scroll bars which redisplay_windows should have
10954 nuked should now go away. */
10955 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
10956 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
10958 /* If fonts changed, display again. */
10959 /* ??? rms: I suspect it is a mistake to jump all the way
10960 back to retry here. It should just retry this frame. */
10961 if (fonts_changed_p
)
10964 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10966 /* See if we have to hscroll. */
10967 if (!f
->already_hscrolled_p
)
10969 f
->already_hscrolled_p
= 1;
10970 if (hscroll_windows (f
->root_window
))
10974 /* Prevent various kinds of signals during display
10975 update. stdio is not robust about handling
10976 signals, which can cause an apparent I/O
10978 if (interrupt_input
)
10979 unrequest_sigio ();
10982 /* Update the display. */
10983 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10984 pause
|= update_frame (f
, 0, 0);
10985 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10997 /* Do the mark_window_display_accurate after all windows have
10998 been redisplayed because this call resets flags in buffers
10999 which are needed for proper redisplay. */
11000 FOR_EACH_FRAME (tail
, frame
)
11002 struct frame
*f
= XFRAME (frame
);
11005 mark_window_display_accurate (f
->root_window
, 1);
11006 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11007 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11012 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11014 Lisp_Object mini_window
;
11015 struct frame
*mini_frame
;
11017 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11018 /* Use list_of_error, not Qerror, so that
11019 we catch only errors and don't run the debugger. */
11020 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11022 redisplay_window_error
);
11024 /* Compare desired and current matrices, perform output. */
11027 /* If fonts changed, display again. */
11028 if (fonts_changed_p
)
11031 /* Prevent various kinds of signals during display update.
11032 stdio is not robust about handling signals,
11033 which can cause an apparent I/O error. */
11034 if (interrupt_input
)
11035 unrequest_sigio ();
11038 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11040 if (hscroll_windows (selected_window
))
11043 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11044 pause
= update_frame (sf
, 0, 0);
11047 /* We may have called echo_area_display at the top of this
11048 function. If the echo area is on another frame, that may
11049 have put text on a frame other than the selected one, so the
11050 above call to update_frame would not have caught it. Catch
11052 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11053 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11055 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11057 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11058 pause
|= update_frame (mini_frame
, 0, 0);
11059 if (!pause
&& hscroll_windows (mini_window
))
11064 /* If display was paused because of pending input, make sure we do a
11065 thorough update the next time. */
11068 /* Prevent the optimization at the beginning of
11069 redisplay_internal that tries a single-line update of the
11070 line containing the cursor in the selected window. */
11071 CHARPOS (this_line_start_pos
) = 0;
11073 /* Let the overlay arrow be updated the next time. */
11074 update_overlay_arrows (0);
11076 /* If we pause after scrolling, some rows in the current
11077 matrices of some windows are not valid. */
11078 if (!WINDOW_FULL_WIDTH_P (w
)
11079 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11080 update_mode_lines
= 1;
11084 if (!consider_all_windows_p
)
11086 /* This has already been done above if
11087 consider_all_windows_p is set. */
11088 mark_window_display_accurate_1 (w
, 1);
11090 /* Say overlay arrows are up to date. */
11091 update_overlay_arrows (1);
11093 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11094 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11097 update_mode_lines
= 0;
11098 windows_or_buffers_changed
= 0;
11099 cursor_type_changed
= 0;
11102 /* Start SIGIO interrupts coming again. Having them off during the
11103 code above makes it less likely one will discard output, but not
11104 impossible, since there might be stuff in the system buffer here.
11105 But it is much hairier to try to do anything about that. */
11106 if (interrupt_input
)
11110 /* If a frame has become visible which was not before, redisplay
11111 again, so that we display it. Expose events for such a frame
11112 (which it gets when becoming visible) don't call the parts of
11113 redisplay constructing glyphs, so simply exposing a frame won't
11114 display anything in this case. So, we have to display these
11115 frames here explicitly. */
11118 Lisp_Object tail
, frame
;
11121 FOR_EACH_FRAME (tail
, frame
)
11123 int this_is_visible
= 0;
11125 if (XFRAME (frame
)->visible
)
11126 this_is_visible
= 1;
11127 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11128 if (XFRAME (frame
)->visible
)
11129 this_is_visible
= 1;
11131 if (this_is_visible
)
11135 if (new_count
!= number_of_visible_frames
)
11136 windows_or_buffers_changed
++;
11139 /* Change frame size now if a change is pending. */
11140 do_pending_window_change (1);
11142 /* If we just did a pending size change, or have additional
11143 visible frames, redisplay again. */
11144 if (windows_or_buffers_changed
&& !pause
)
11147 /* Clear the face cache eventually. */
11148 if (consider_all_windows_p
)
11150 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11152 clear_face_cache (0);
11153 clear_face_cache_count
= 0;
11155 #ifdef HAVE_WINDOW_SYSTEM
11156 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11158 Lisp_Object tail
, frame
;
11159 FOR_EACH_FRAME (tail
, frame
)
11161 struct frame
*f
= XFRAME (frame
);
11162 if (FRAME_WINDOW_P (f
))
11163 clear_image_cache (f
, 0);
11165 clear_image_cache_count
= 0;
11167 #endif /* HAVE_WINDOW_SYSTEM */
11171 unbind_to (count
, Qnil
);
11176 /* Redisplay, but leave alone any recent echo area message unless
11177 another message has been requested in its place.
11179 This is useful in situations where you need to redisplay but no
11180 user action has occurred, making it inappropriate for the message
11181 area to be cleared. See tracking_off and
11182 wait_reading_process_output for examples of these situations.
11184 FROM_WHERE is an integer saying from where this function was
11185 called. This is useful for debugging. */
11188 redisplay_preserve_echo_area (from_where
)
11191 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11193 if (!NILP (echo_area_buffer
[1]))
11195 /* We have a previously displayed message, but no current
11196 message. Redisplay the previous message. */
11197 display_last_displayed_message_p
= 1;
11198 redisplay_internal (1);
11199 display_last_displayed_message_p
= 0;
11202 redisplay_internal (1);
11204 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
11205 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11206 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
11210 /* Function registered with record_unwind_protect in
11211 redisplay_internal. Reset redisplaying_p to the value it had
11212 before redisplay_internal was called, and clear
11213 prevent_freeing_realized_faces_p. It also selects the previously
11214 selected frame, unless it has been deleted (by an X connection
11215 failure during redisplay, for example). */
11218 unwind_redisplay (val
)
11221 Lisp_Object old_redisplaying_p
, old_frame
;
11223 old_redisplaying_p
= XCAR (val
);
11224 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11225 old_frame
= XCDR (val
);
11226 if (! EQ (old_frame
, selected_frame
)
11227 && FRAME_LIVE_P (XFRAME (old_frame
)))
11228 select_frame_for_redisplay (old_frame
);
11233 /* Mark the display of window W as accurate or inaccurate. If
11234 ACCURATE_P is non-zero mark display of W as accurate. If
11235 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11236 redisplay_internal is called. */
11239 mark_window_display_accurate_1 (w
, accurate_p
)
11243 if (BUFFERP (w
->buffer
))
11245 struct buffer
*b
= XBUFFER (w
->buffer
);
11248 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11249 w
->last_overlay_modified
11250 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11252 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11256 b
->clip_changed
= 0;
11257 b
->prevent_redisplay_optimizations_p
= 0;
11259 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11260 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11261 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11262 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11264 w
->current_matrix
->buffer
= b
;
11265 w
->current_matrix
->begv
= BUF_BEGV (b
);
11266 w
->current_matrix
->zv
= BUF_ZV (b
);
11268 w
->last_cursor
= w
->cursor
;
11269 w
->last_cursor_off_p
= w
->cursor_off_p
;
11271 if (w
== XWINDOW (selected_window
))
11272 w
->last_point
= make_number (BUF_PT (b
));
11274 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11280 w
->window_end_valid
= w
->buffer
;
11281 #if 0 /* This is incorrect with variable-height lines. */
11282 xassert (XINT (w
->window_end_vpos
)
11283 < (WINDOW_TOTAL_LINES (w
)
11284 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11286 w
->update_mode_line
= Qnil
;
11291 /* Mark the display of windows in the window tree rooted at WINDOW as
11292 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11293 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11294 be redisplayed the next time redisplay_internal is called. */
11297 mark_window_display_accurate (window
, accurate_p
)
11298 Lisp_Object window
;
11303 for (; !NILP (window
); window
= w
->next
)
11305 w
= XWINDOW (window
);
11306 mark_window_display_accurate_1 (w
, accurate_p
);
11308 if (!NILP (w
->vchild
))
11309 mark_window_display_accurate (w
->vchild
, accurate_p
);
11310 if (!NILP (w
->hchild
))
11311 mark_window_display_accurate (w
->hchild
, accurate_p
);
11316 update_overlay_arrows (1);
11320 /* Force a thorough redisplay the next time by setting
11321 last_arrow_position and last_arrow_string to t, which is
11322 unequal to any useful value of Voverlay_arrow_... */
11323 update_overlay_arrows (-1);
11328 /* Return value in display table DP (Lisp_Char_Table *) for character
11329 C. Since a display table doesn't have any parent, we don't have to
11330 follow parent. Do not call this function directly but use the
11331 macro DISP_CHAR_VECTOR. */
11334 disp_char_vector (dp
, c
)
11335 struct Lisp_Char_Table
*dp
;
11341 if (SINGLE_BYTE_CHAR_P (c
))
11342 return (dp
->contents
[c
]);
11344 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11347 else if (code
[2] < 32)
11350 /* Here, the possible range of code[0] (== charset ID) is
11351 128..max_charset. Since the top level char table contains data
11352 for multibyte characters after 256th element, we must increment
11353 code[0] by 128 to get a correct index. */
11355 code
[3] = -1; /* anchor */
11357 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11359 val
= dp
->contents
[code
[i
]];
11360 if (!SUB_CHAR_TABLE_P (val
))
11361 return (NILP (val
) ? dp
->defalt
: val
);
11364 /* Here, val is a sub char table. We return the default value of
11366 return (dp
->defalt
);
11371 /***********************************************************************
11373 ***********************************************************************/
11375 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11378 redisplay_windows (window
)
11379 Lisp_Object window
;
11381 while (!NILP (window
))
11383 struct window
*w
= XWINDOW (window
);
11385 if (!NILP (w
->hchild
))
11386 redisplay_windows (w
->hchild
);
11387 else if (!NILP (w
->vchild
))
11388 redisplay_windows (w
->vchild
);
11391 displayed_buffer
= XBUFFER (w
->buffer
);
11392 /* Use list_of_error, not Qerror, so that
11393 we catch only errors and don't run the debugger. */
11394 internal_condition_case_1 (redisplay_window_0
, window
,
11396 redisplay_window_error
);
11404 redisplay_window_error ()
11406 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11411 redisplay_window_0 (window
)
11412 Lisp_Object window
;
11414 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11415 redisplay_window (window
, 0);
11420 redisplay_window_1 (window
)
11421 Lisp_Object window
;
11423 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11424 redisplay_window (window
, 1);
11429 /* Increment GLYPH until it reaches END or CONDITION fails while
11430 adding (GLYPH)->pixel_width to X. */
11432 #define SKIP_GLYPHS(glyph, end, x, condition) \
11435 (x) += (glyph)->pixel_width; \
11438 while ((glyph) < (end) && (condition))
11441 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11442 DELTA is the number of bytes by which positions recorded in ROW
11443 differ from current buffer positions. */
11446 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11448 struct glyph_row
*row
;
11449 struct glyph_matrix
*matrix
;
11450 int delta
, delta_bytes
, dy
, dvpos
;
11452 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11453 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11454 struct glyph
*cursor
= NULL
;
11455 /* The first glyph that starts a sequence of glyphs from string. */
11456 struct glyph
*string_start
;
11457 /* The X coordinate of string_start. */
11458 int string_start_x
;
11459 /* The last known character position. */
11460 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11461 /* The last known character position before string_start. */
11462 int string_before_pos
;
11465 int cursor_from_overlay_pos
= 0;
11466 int pt_old
= PT
- delta
;
11468 /* Skip over glyphs not having an object at the start of the row.
11469 These are special glyphs like truncation marks on terminal
11471 if (row
->displays_text_p
)
11473 && INTEGERP (glyph
->object
)
11474 && glyph
->charpos
< 0)
11476 x
+= glyph
->pixel_width
;
11480 string_start
= NULL
;
11482 && !INTEGERP (glyph
->object
)
11483 && (!BUFFERP (glyph
->object
)
11484 || (last_pos
= glyph
->charpos
) < pt_old
))
11486 if (! STRINGP (glyph
->object
))
11488 string_start
= NULL
;
11489 x
+= glyph
->pixel_width
;
11491 if (cursor_from_overlay_pos
11492 && last_pos
> cursor_from_overlay_pos
)
11494 cursor_from_overlay_pos
= 0;
11500 string_before_pos
= last_pos
;
11501 string_start
= glyph
;
11502 string_start_x
= x
;
11503 /* Skip all glyphs from string. */
11507 if ((cursor
== NULL
|| glyph
> cursor
)
11508 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
11509 Qcursor
, (glyph
)->object
))
11510 && (pos
= string_buffer_position (w
, glyph
->object
,
11511 string_before_pos
),
11512 (pos
== 0 /* From overlay */
11513 || pos
== pt_old
)))
11515 /* Estimate overlay buffer position from the buffer
11516 positions of the glyphs before and after the overlay.
11517 Add 1 to last_pos so that if point corresponds to the
11518 glyph right after the overlay, we still use a 'cursor'
11519 property found in that overlay. */
11520 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
11524 x
+= glyph
->pixel_width
;
11527 while (glyph
< end
&& STRINGP (glyph
->object
));
11531 if (cursor
!= NULL
)
11536 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11538 /* Scan back over the ellipsis glyphs, decrementing positions. */
11539 while (glyph
> row
->glyphs
[TEXT_AREA
]
11540 && (glyph
- 1)->charpos
== last_pos
)
11541 glyph
--, x
-= glyph
->pixel_width
;
11542 /* That loop always goes one position too far,
11543 including the glyph before the ellipsis.
11544 So scan forward over that one. */
11545 x
+= glyph
->pixel_width
;
11548 else if (string_start
11549 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11551 /* We may have skipped over point because the previous glyphs
11552 are from string. As there's no easy way to know the
11553 character position of the current glyph, find the correct
11554 glyph on point by scanning from string_start again. */
11556 Lisp_Object string
;
11559 limit
= make_number (pt_old
+ 1);
11561 glyph
= string_start
;
11562 x
= string_start_x
;
11563 string
= glyph
->object
;
11564 pos
= string_buffer_position (w
, string
, string_before_pos
);
11565 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11566 because we always put cursor after overlay strings. */
11567 while (pos
== 0 && glyph
< end
)
11569 string
= glyph
->object
;
11570 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11572 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11575 while (glyph
< end
)
11577 pos
= XINT (Fnext_single_char_property_change
11578 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11581 /* Skip glyphs from the same string. */
11582 string
= glyph
->object
;
11583 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11584 /* Skip glyphs from an overlay. */
11586 && ! string_buffer_position (w
, glyph
->object
, pos
))
11588 string
= glyph
->object
;
11589 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11594 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11596 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11597 w
->cursor
.y
= row
->y
+ dy
;
11599 if (w
== XWINDOW (selected_window
))
11601 if (!row
->continued_p
11602 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11605 this_line_buffer
= XBUFFER (w
->buffer
);
11607 CHARPOS (this_line_start_pos
)
11608 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11609 BYTEPOS (this_line_start_pos
)
11610 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11612 CHARPOS (this_line_end_pos
)
11613 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11614 BYTEPOS (this_line_end_pos
)
11615 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11617 this_line_y
= w
->cursor
.y
;
11618 this_line_pixel_height
= row
->height
;
11619 this_line_vpos
= w
->cursor
.vpos
;
11620 this_line_start_x
= row
->x
;
11623 CHARPOS (this_line_start_pos
) = 0;
11628 /* Run window scroll functions, if any, for WINDOW with new window
11629 start STARTP. Sets the window start of WINDOW to that position.
11631 We assume that the window's buffer is really current. */
11633 static INLINE
struct text_pos
11634 run_window_scroll_functions (window
, startp
)
11635 Lisp_Object window
;
11636 struct text_pos startp
;
11638 struct window
*w
= XWINDOW (window
);
11639 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11641 if (current_buffer
!= XBUFFER (w
->buffer
))
11644 if (!NILP (Vwindow_scroll_functions
))
11646 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11647 make_number (CHARPOS (startp
)));
11648 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11649 /* In case the hook functions switch buffers. */
11650 if (current_buffer
!= XBUFFER (w
->buffer
))
11651 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11658 /* Make sure the line containing the cursor is fully visible.
11659 A value of 1 means there is nothing to be done.
11660 (Either the line is fully visible, or it cannot be made so,
11661 or we cannot tell.)
11663 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11664 is higher than window.
11666 A value of 0 means the caller should do scrolling
11667 as if point had gone off the screen. */
11670 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11673 int current_matrix_p
;
11675 struct glyph_matrix
*matrix
;
11676 struct glyph_row
*row
;
11679 if (!make_cursor_line_fully_visible_p
)
11682 /* It's not always possible to find the cursor, e.g, when a window
11683 is full of overlay strings. Don't do anything in that case. */
11684 if (w
->cursor
.vpos
< 0)
11687 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11688 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11690 /* If the cursor row is not partially visible, there's nothing to do. */
11691 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11694 /* If the row the cursor is in is taller than the window's height,
11695 it's not clear what to do, so do nothing. */
11696 window_height
= window_box_height (w
);
11697 if (row
->height
>= window_height
)
11699 if (!force_p
|| MINI_WINDOW_P (w
) || w
->vscroll
)
11705 /* This code used to try to scroll the window just enough to make
11706 the line visible. It returned 0 to say that the caller should
11707 allocate larger glyph matrices. */
11709 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11711 int dy
= row
->height
- row
->visible_height
;
11714 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11716 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11718 int dy
= - (row
->height
- row
->visible_height
);
11721 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11724 /* When we change the cursor y-position of the selected window,
11725 change this_line_y as well so that the display optimization for
11726 the cursor line of the selected window in redisplay_internal uses
11727 the correct y-position. */
11728 if (w
== XWINDOW (selected_window
))
11729 this_line_y
= w
->cursor
.y
;
11731 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11732 redisplay with larger matrices. */
11733 if (matrix
->nrows
< required_matrix_height (w
))
11735 fonts_changed_p
= 1;
11744 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11745 non-zero means only WINDOW is redisplayed in redisplay_internal.
11746 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11747 in redisplay_window to bring a partially visible line into view in
11748 the case that only the cursor has moved.
11750 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11751 last screen line's vertical height extends past the end of the screen.
11755 1 if scrolling succeeded
11757 0 if scrolling didn't find point.
11759 -1 if new fonts have been loaded so that we must interrupt
11760 redisplay, adjust glyph matrices, and try again. */
11766 SCROLLING_NEED_LARGER_MATRICES
11770 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11771 scroll_step
, temp_scroll_step
, last_line_misfit
)
11772 Lisp_Object window
;
11773 int just_this_one_p
;
11774 EMACS_INT scroll_conservatively
, scroll_step
;
11775 int temp_scroll_step
;
11776 int last_line_misfit
;
11778 struct window
*w
= XWINDOW (window
);
11779 struct frame
*f
= XFRAME (w
->frame
);
11780 struct text_pos scroll_margin_pos
;
11781 struct text_pos pos
;
11782 struct text_pos startp
;
11784 Lisp_Object window_end
;
11785 int this_scroll_margin
;
11789 int amount_to_scroll
= 0;
11790 Lisp_Object aggressive
;
11792 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11795 debug_method_add (w
, "try_scrolling");
11798 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11800 /* Compute scroll margin height in pixels. We scroll when point is
11801 within this distance from the top or bottom of the window. */
11802 if (scroll_margin
> 0)
11804 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11805 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11808 this_scroll_margin
= 0;
11810 /* Force scroll_conservatively to have a reasonable value so it doesn't
11811 cause an overflow while computing how much to scroll. */
11812 if (scroll_conservatively
)
11813 scroll_conservatively
= min (scroll_conservatively
,
11814 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11816 /* Compute how much we should try to scroll maximally to bring point
11818 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11819 scroll_max
= max (scroll_step
,
11820 max (scroll_conservatively
, temp_scroll_step
));
11821 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11822 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11823 /* We're trying to scroll because of aggressive scrolling
11824 but no scroll_step is set. Choose an arbitrary one. Maybe
11825 there should be a variable for this. */
11829 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11831 /* Decide whether we have to scroll down. Start at the window end
11832 and move this_scroll_margin up to find the position of the scroll
11834 window_end
= Fwindow_end (window
, Qt
);
11838 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11839 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11841 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11843 start_display (&it
, w
, scroll_margin_pos
);
11844 if (this_scroll_margin
)
11845 move_it_vertically_backward (&it
, this_scroll_margin
);
11846 if (extra_scroll_margin_lines
)
11847 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11848 scroll_margin_pos
= it
.current
.pos
;
11851 if (PT
>= CHARPOS (scroll_margin_pos
))
11855 /* Point is in the scroll margin at the bottom of the window, or
11856 below. Compute a new window start that makes point visible. */
11858 /* Compute the distance from the scroll margin to PT.
11859 Give up if the distance is greater than scroll_max. */
11860 start_display (&it
, w
, scroll_margin_pos
);
11862 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11863 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11865 /* To make point visible, we have to move the window start
11866 down so that the line the cursor is in is visible, which
11867 means we have to add in the height of the cursor line. */
11868 dy
= line_bottom_y (&it
) - y0
;
11870 if (dy
> scroll_max
)
11871 return SCROLLING_FAILED
;
11873 /* Move the window start down. If scrolling conservatively,
11874 move it just enough down to make point visible. If
11875 scroll_step is set, move it down by scroll_step. */
11876 start_display (&it
, w
, startp
);
11878 if (scroll_conservatively
)
11879 /* Set AMOUNT_TO_SCROLL to at least one line,
11880 and at most scroll_conservatively lines. */
11882 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11883 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11884 else if (scroll_step
|| temp_scroll_step
)
11885 amount_to_scroll
= scroll_max
;
11888 aggressive
= current_buffer
->scroll_up_aggressively
;
11889 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11890 if (NUMBERP (aggressive
))
11892 double float_amount
= XFLOATINT (aggressive
) * height
;
11893 amount_to_scroll
= float_amount
;
11894 if (amount_to_scroll
== 0 && float_amount
> 0)
11895 amount_to_scroll
= 1;
11899 if (amount_to_scroll
<= 0)
11900 return SCROLLING_FAILED
;
11902 /* If moving by amount_to_scroll leaves STARTP unchanged,
11903 move it down one screen line. */
11905 move_it_vertically (&it
, amount_to_scroll
);
11906 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11907 move_it_by_lines (&it
, 1, 1);
11908 startp
= it
.current
.pos
;
11912 /* See if point is inside the scroll margin at the top of the
11914 scroll_margin_pos
= startp
;
11915 if (this_scroll_margin
)
11917 start_display (&it
, w
, startp
);
11918 move_it_vertically (&it
, this_scroll_margin
);
11919 scroll_margin_pos
= it
.current
.pos
;
11922 if (PT
< CHARPOS (scroll_margin_pos
))
11924 /* Point is in the scroll margin at the top of the window or
11925 above what is displayed in the window. */
11928 /* Compute the vertical distance from PT to the scroll
11929 margin position. Give up if distance is greater than
11931 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11932 start_display (&it
, w
, pos
);
11934 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11935 it
.last_visible_y
, -1,
11936 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11937 dy
= it
.current_y
- y0
;
11938 if (dy
> scroll_max
)
11939 return SCROLLING_FAILED
;
11941 /* Compute new window start. */
11942 start_display (&it
, w
, startp
);
11944 if (scroll_conservatively
)
11946 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11947 else if (scroll_step
|| temp_scroll_step
)
11948 amount_to_scroll
= scroll_max
;
11951 aggressive
= current_buffer
->scroll_down_aggressively
;
11952 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11953 if (NUMBERP (aggressive
))
11955 double float_amount
= XFLOATINT (aggressive
) * height
;
11956 amount_to_scroll
= float_amount
;
11957 if (amount_to_scroll
== 0 && float_amount
> 0)
11958 amount_to_scroll
= 1;
11962 if (amount_to_scroll
<= 0)
11963 return SCROLLING_FAILED
;
11965 move_it_vertically_backward (&it
, amount_to_scroll
);
11966 startp
= it
.current
.pos
;
11970 /* Run window scroll functions. */
11971 startp
= run_window_scroll_functions (window
, startp
);
11973 /* Display the window. Give up if new fonts are loaded, or if point
11975 if (!try_window (window
, startp
, 0))
11976 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11977 else if (w
->cursor
.vpos
< 0)
11979 clear_glyph_matrix (w
->desired_matrix
);
11980 rc
= SCROLLING_FAILED
;
11984 /* Maybe forget recorded base line for line number display. */
11985 if (!just_this_one_p
11986 || current_buffer
->clip_changed
11987 || BEG_UNCHANGED
< CHARPOS (startp
))
11988 w
->base_line_number
= Qnil
;
11990 /* If cursor ends up on a partially visible line,
11991 treat that as being off the bottom of the screen. */
11992 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
11994 clear_glyph_matrix (w
->desired_matrix
);
11995 ++extra_scroll_margin_lines
;
11998 rc
= SCROLLING_SUCCESS
;
12005 /* Compute a suitable window start for window W if display of W starts
12006 on a continuation line. Value is non-zero if a new window start
12009 The new window start will be computed, based on W's width, starting
12010 from the start of the continued line. It is the start of the
12011 screen line with the minimum distance from the old start W->start. */
12014 compute_window_start_on_continuation_line (w
)
12017 struct text_pos pos
, start_pos
;
12018 int window_start_changed_p
= 0;
12020 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12022 /* If window start is on a continuation line... Window start may be
12023 < BEGV in case there's invisible text at the start of the
12024 buffer (M-x rmail, for example). */
12025 if (CHARPOS (start_pos
) > BEGV
12026 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12029 struct glyph_row
*row
;
12031 /* Handle the case that the window start is out of range. */
12032 if (CHARPOS (start_pos
) < BEGV
)
12033 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12034 else if (CHARPOS (start_pos
) > ZV
)
12035 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12037 /* Find the start of the continued line. This should be fast
12038 because scan_buffer is fast (newline cache). */
12039 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12040 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12041 row
, DEFAULT_FACE_ID
);
12042 reseat_at_previous_visible_line_start (&it
);
12044 /* If the line start is "too far" away from the window start,
12045 say it takes too much time to compute a new window start. */
12046 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12047 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12049 int min_distance
, distance
;
12051 /* Move forward by display lines to find the new window
12052 start. If window width was enlarged, the new start can
12053 be expected to be > the old start. If window width was
12054 decreased, the new window start will be < the old start.
12055 So, we're looking for the display line start with the
12056 minimum distance from the old window start. */
12057 pos
= it
.current
.pos
;
12058 min_distance
= INFINITY
;
12059 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12060 distance
< min_distance
)
12062 min_distance
= distance
;
12063 pos
= it
.current
.pos
;
12064 move_it_by_lines (&it
, 1, 0);
12067 /* Set the window start there. */
12068 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12069 window_start_changed_p
= 1;
12073 return window_start_changed_p
;
12077 /* Try cursor movement in case text has not changed in window WINDOW,
12078 with window start STARTP. Value is
12080 CURSOR_MOVEMENT_SUCCESS if successful
12082 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12084 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12085 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12086 we want to scroll as if scroll-step were set to 1. See the code.
12088 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12089 which case we have to abort this redisplay, and adjust matrices
12094 CURSOR_MOVEMENT_SUCCESS
,
12095 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12096 CURSOR_MOVEMENT_MUST_SCROLL
,
12097 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12101 try_cursor_movement (window
, startp
, scroll_step
)
12102 Lisp_Object window
;
12103 struct text_pos startp
;
12106 struct window
*w
= XWINDOW (window
);
12107 struct frame
*f
= XFRAME (w
->frame
);
12108 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12111 if (inhibit_try_cursor_movement
)
12115 /* Handle case where text has not changed, only point, and it has
12116 not moved off the frame. */
12117 if (/* Point may be in this window. */
12118 PT
>= CHARPOS (startp
)
12119 /* Selective display hasn't changed. */
12120 && !current_buffer
->clip_changed
12121 /* Function force-mode-line-update is used to force a thorough
12122 redisplay. It sets either windows_or_buffers_changed or
12123 update_mode_lines. So don't take a shortcut here for these
12125 && !update_mode_lines
12126 && !windows_or_buffers_changed
12127 && !cursor_type_changed
12128 /* Can't use this case if highlighting a region. When a
12129 region exists, cursor movement has to do more than just
12131 && !(!NILP (Vtransient_mark_mode
)
12132 && !NILP (current_buffer
->mark_active
))
12133 && NILP (w
->region_showing
)
12134 && NILP (Vshow_trailing_whitespace
)
12135 /* Right after splitting windows, last_point may be nil. */
12136 && INTEGERP (w
->last_point
)
12137 /* This code is not used for mini-buffer for the sake of the case
12138 of redisplaying to replace an echo area message; since in
12139 that case the mini-buffer contents per se are usually
12140 unchanged. This code is of no real use in the mini-buffer
12141 since the handling of this_line_start_pos, etc., in redisplay
12142 handles the same cases. */
12143 && !EQ (window
, minibuf_window
)
12144 /* When splitting windows or for new windows, it happens that
12145 redisplay is called with a nil window_end_vpos or one being
12146 larger than the window. This should really be fixed in
12147 window.c. I don't have this on my list, now, so we do
12148 approximately the same as the old redisplay code. --gerd. */
12149 && INTEGERP (w
->window_end_vpos
)
12150 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12151 && (FRAME_WINDOW_P (f
)
12152 || !overlay_arrow_in_current_buffer_p ()))
12154 int this_scroll_margin
, top_scroll_margin
;
12155 struct glyph_row
*row
= NULL
;
12158 debug_method_add (w
, "cursor movement");
12161 /* Scroll if point within this distance from the top or bottom
12162 of the window. This is a pixel value. */
12163 this_scroll_margin
= max (0, scroll_margin
);
12164 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12165 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12167 top_scroll_margin
= this_scroll_margin
;
12168 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12169 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12171 /* Start with the row the cursor was displayed during the last
12172 not paused redisplay. Give up if that row is not valid. */
12173 if (w
->last_cursor
.vpos
< 0
12174 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12175 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12178 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12179 if (row
->mode_line_p
)
12181 if (!row
->enabled_p
)
12182 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12185 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12188 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12190 if (PT
> XFASTINT (w
->last_point
))
12192 /* Point has moved forward. */
12193 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12194 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12196 xassert (row
->enabled_p
);
12200 /* The end position of a row equals the start position
12201 of the next row. If PT is there, we would rather
12202 display it in the next line. */
12203 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12204 && MATRIX_ROW_END_CHARPOS (row
) == PT
12205 && !cursor_row_p (w
, row
))
12208 /* If within the scroll margin, scroll. Note that
12209 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12210 the next line would be drawn, and that
12211 this_scroll_margin can be zero. */
12212 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12213 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12214 /* Line is completely visible last line in window
12215 and PT is to be set in the next line. */
12216 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12217 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12218 && !row
->ends_at_zv_p
12219 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12222 else if (PT
< XFASTINT (w
->last_point
))
12224 /* Cursor has to be moved backward. Note that PT >=
12225 CHARPOS (startp) because of the outer if-statement. */
12226 while (!row
->mode_line_p
12227 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12228 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12229 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12230 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12231 row
> w
->current_matrix
->rows
12232 && (row
-1)->ends_in_newline_from_string_p
))))
12233 && (row
->y
> top_scroll_margin
12234 || CHARPOS (startp
) == BEGV
))
12236 xassert (row
->enabled_p
);
12240 /* Consider the following case: Window starts at BEGV,
12241 there is invisible, intangible text at BEGV, so that
12242 display starts at some point START > BEGV. It can
12243 happen that we are called with PT somewhere between
12244 BEGV and START. Try to handle that case. */
12245 if (row
< w
->current_matrix
->rows
12246 || row
->mode_line_p
)
12248 row
= w
->current_matrix
->rows
;
12249 if (row
->mode_line_p
)
12253 /* Due to newlines in overlay strings, we may have to
12254 skip forward over overlay strings. */
12255 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12256 && MATRIX_ROW_END_CHARPOS (row
) == PT
12257 && !cursor_row_p (w
, row
))
12260 /* If within the scroll margin, scroll. */
12261 if (row
->y
< top_scroll_margin
12262 && CHARPOS (startp
) != BEGV
)
12267 /* Cursor did not move. So don't scroll even if cursor line
12268 is partially visible, as it was so before. */
12269 rc
= CURSOR_MOVEMENT_SUCCESS
;
12272 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12273 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12275 /* if PT is not in the glyph row, give up. */
12276 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12278 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12279 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12280 && make_cursor_line_fully_visible_p
)
12282 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12283 && !row
->ends_at_zv_p
12284 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12285 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12286 else if (row
->height
> window_box_height (w
))
12288 /* If we end up in a partially visible line, let's
12289 make it fully visible, except when it's taller
12290 than the window, in which case we can't do much
12293 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12297 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12298 if (!cursor_row_fully_visible_p (w
, 0, 1))
12299 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12301 rc
= CURSOR_MOVEMENT_SUCCESS
;
12305 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12308 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12309 rc
= CURSOR_MOVEMENT_SUCCESS
;
12318 set_vertical_scroll_bar (w
)
12321 int start
, end
, whole
;
12323 /* Calculate the start and end positions for the current window.
12324 At some point, it would be nice to choose between scrollbars
12325 which reflect the whole buffer size, with special markers
12326 indicating narrowing, and scrollbars which reflect only the
12329 Note that mini-buffers sometimes aren't displaying any text. */
12330 if (!MINI_WINDOW_P (w
)
12331 || (w
== XWINDOW (minibuf_window
)
12332 && NILP (echo_area_buffer
[0])))
12334 struct buffer
*buf
= XBUFFER (w
->buffer
);
12335 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12336 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12337 /* I don't think this is guaranteed to be right. For the
12338 moment, we'll pretend it is. */
12339 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12343 if (whole
< (end
- start
))
12344 whole
= end
- start
;
12347 start
= end
= whole
= 0;
12349 /* Indicate what this scroll bar ought to be displaying now. */
12350 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
12351 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
12352 (w
, end
- start
, whole
, start
);
12356 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12357 selected_window is redisplayed.
12359 We can return without actually redisplaying the window if
12360 fonts_changed_p is nonzero. In that case, redisplay_internal will
12364 redisplay_window (window
, just_this_one_p
)
12365 Lisp_Object window
;
12366 int just_this_one_p
;
12368 struct window
*w
= XWINDOW (window
);
12369 struct frame
*f
= XFRAME (w
->frame
);
12370 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12371 struct buffer
*old
= current_buffer
;
12372 struct text_pos lpoint
, opoint
, startp
;
12373 int update_mode_line
;
12376 /* Record it now because it's overwritten. */
12377 int current_matrix_up_to_date_p
= 0;
12378 int used_current_matrix_p
= 0;
12379 /* This is less strict than current_matrix_up_to_date_p.
12380 It indictes that the buffer contents and narrowing are unchanged. */
12381 int buffer_unchanged_p
= 0;
12382 int temp_scroll_step
= 0;
12383 int count
= SPECPDL_INDEX ();
12385 int centering_position
= -1;
12386 int last_line_misfit
= 0;
12388 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12391 /* W must be a leaf window here. */
12392 xassert (!NILP (w
->buffer
));
12394 *w
->desired_matrix
->method
= 0;
12397 specbind (Qinhibit_point_motion_hooks
, Qt
);
12399 reconsider_clip_changes (w
, buffer
);
12401 /* Has the mode line to be updated? */
12402 update_mode_line
= (!NILP (w
->update_mode_line
)
12403 || update_mode_lines
12404 || buffer
->clip_changed
12405 || buffer
->prevent_redisplay_optimizations_p
);
12407 if (MINI_WINDOW_P (w
))
12409 if (w
== XWINDOW (echo_area_window
)
12410 && !NILP (echo_area_buffer
[0]))
12412 if (update_mode_line
)
12413 /* We may have to update a tty frame's menu bar or a
12414 tool-bar. Example `M-x C-h C-h C-g'. */
12415 goto finish_menu_bars
;
12417 /* We've already displayed the echo area glyphs in this window. */
12418 goto finish_scroll_bars
;
12420 else if ((w
!= XWINDOW (minibuf_window
)
12421 || minibuf_level
== 0)
12422 /* When buffer is nonempty, redisplay window normally. */
12423 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12424 /* Quail displays non-mini buffers in minibuffer window.
12425 In that case, redisplay the window normally. */
12426 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12428 /* W is a mini-buffer window, but it's not active, so clear
12430 int yb
= window_text_bottom_y (w
);
12431 struct glyph_row
*row
;
12434 for (y
= 0, row
= w
->desired_matrix
->rows
;
12436 y
+= row
->height
, ++row
)
12437 blank_row (w
, row
, y
);
12438 goto finish_scroll_bars
;
12441 clear_glyph_matrix (w
->desired_matrix
);
12444 /* Otherwise set up data on this window; select its buffer and point
12446 /* Really select the buffer, for the sake of buffer-local
12448 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12449 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12451 current_matrix_up_to_date_p
12452 = (!NILP (w
->window_end_valid
)
12453 && !current_buffer
->clip_changed
12454 && !current_buffer
->prevent_redisplay_optimizations_p
12455 && XFASTINT (w
->last_modified
) >= MODIFF
12456 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12459 = (!NILP (w
->window_end_valid
)
12460 && !current_buffer
->clip_changed
12461 && XFASTINT (w
->last_modified
) >= MODIFF
12462 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12464 /* When windows_or_buffers_changed is non-zero, we can't rely on
12465 the window end being valid, so set it to nil there. */
12466 if (windows_or_buffers_changed
)
12468 /* If window starts on a continuation line, maybe adjust the
12469 window start in case the window's width changed. */
12470 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12471 compute_window_start_on_continuation_line (w
);
12473 w
->window_end_valid
= Qnil
;
12476 /* Some sanity checks. */
12477 CHECK_WINDOW_END (w
);
12478 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12480 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12483 /* If %c is in mode line, update it if needed. */
12484 if (!NILP (w
->column_number_displayed
)
12485 /* This alternative quickly identifies a common case
12486 where no change is needed. */
12487 && !(PT
== XFASTINT (w
->last_point
)
12488 && XFASTINT (w
->last_modified
) >= MODIFF
12489 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12490 && (XFASTINT (w
->column_number_displayed
)
12491 != (int) current_column ())) /* iftc */
12492 update_mode_line
= 1;
12494 /* Count number of windows showing the selected buffer. An indirect
12495 buffer counts as its base buffer. */
12496 if (!just_this_one_p
)
12498 struct buffer
*current_base
, *window_base
;
12499 current_base
= current_buffer
;
12500 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12501 if (current_base
->base_buffer
)
12502 current_base
= current_base
->base_buffer
;
12503 if (window_base
->base_buffer
)
12504 window_base
= window_base
->base_buffer
;
12505 if (current_base
== window_base
)
12509 /* Point refers normally to the selected window. For any other
12510 window, set up appropriate value. */
12511 if (!EQ (window
, selected_window
))
12513 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12514 int new_pt_byte
= marker_byte_position (w
->pointm
);
12518 new_pt_byte
= BEGV_BYTE
;
12519 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12521 else if (new_pt
> (ZV
- 1))
12524 new_pt_byte
= ZV_BYTE
;
12525 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12528 /* We don't use SET_PT so that the point-motion hooks don't run. */
12529 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12532 /* If any of the character widths specified in the display table
12533 have changed, invalidate the width run cache. It's true that
12534 this may be a bit late to catch such changes, but the rest of
12535 redisplay goes (non-fatally) haywire when the display table is
12536 changed, so why should we worry about doing any better? */
12537 if (current_buffer
->width_run_cache
)
12539 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12541 if (! disptab_matches_widthtab (disptab
,
12542 XVECTOR (current_buffer
->width_table
)))
12544 invalidate_region_cache (current_buffer
,
12545 current_buffer
->width_run_cache
,
12547 recompute_width_table (current_buffer
, disptab
);
12551 /* If window-start is screwed up, choose a new one. */
12552 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12555 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12557 /* If someone specified a new starting point but did not insist,
12558 check whether it can be used. */
12559 if (!NILP (w
->optional_new_start
)
12560 && CHARPOS (startp
) >= BEGV
12561 && CHARPOS (startp
) <= ZV
)
12563 w
->optional_new_start
= Qnil
;
12564 start_display (&it
, w
, startp
);
12565 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12566 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12567 if (IT_CHARPOS (it
) == PT
)
12568 w
->force_start
= Qt
;
12569 /* IT may overshoot PT if text at PT is invisible. */
12570 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12571 w
->force_start
= Qt
;
12576 /* Handle case where place to start displaying has been specified,
12577 unless the specified location is outside the accessible range. */
12578 if (!NILP (w
->force_start
)
12579 || w
->frozen_window_start_p
)
12581 /* We set this later on if we have to adjust point. */
12585 w
->force_start
= Qnil
;
12587 w
->window_end_valid
= Qnil
;
12589 /* Forget any recorded base line for line number display. */
12590 if (!buffer_unchanged_p
)
12591 w
->base_line_number
= Qnil
;
12593 /* Redisplay the mode line. Select the buffer properly for that.
12594 Also, run the hook window-scroll-functions
12595 because we have scrolled. */
12596 /* Note, we do this after clearing force_start because
12597 if there's an error, it is better to forget about force_start
12598 than to get into an infinite loop calling the hook functions
12599 and having them get more errors. */
12600 if (!update_mode_line
12601 || ! NILP (Vwindow_scroll_functions
))
12603 update_mode_line
= 1;
12604 w
->update_mode_line
= Qt
;
12605 startp
= run_window_scroll_functions (window
, startp
);
12608 w
->last_modified
= make_number (0);
12609 w
->last_overlay_modified
= make_number (0);
12610 if (CHARPOS (startp
) < BEGV
)
12611 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12612 else if (CHARPOS (startp
) > ZV
)
12613 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12615 /* Redisplay, then check if cursor has been set during the
12616 redisplay. Give up if new fonts were loaded. */
12617 val
= try_window (window
, startp
, 1);
12620 w
->force_start
= Qt
;
12621 clear_glyph_matrix (w
->desired_matrix
);
12622 goto need_larger_matrices
;
12624 /* Point was outside the scroll margins. */
12626 new_vpos
= window_box_height (w
) / 2;
12628 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12630 /* If point does not appear, try to move point so it does
12631 appear. The desired matrix has been built above, so we
12632 can use it here. */
12633 new_vpos
= window_box_height (w
) / 2;
12636 if (!cursor_row_fully_visible_p (w
, 0, 0))
12638 /* Point does appear, but on a line partly visible at end of window.
12639 Move it back to a fully-visible line. */
12640 new_vpos
= window_box_height (w
);
12643 /* If we need to move point for either of the above reasons,
12644 now actually do it. */
12647 struct glyph_row
*row
;
12649 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12650 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12653 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12654 MATRIX_ROW_START_BYTEPOS (row
));
12656 if (w
!= XWINDOW (selected_window
))
12657 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12658 else if (current_buffer
== old
)
12659 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12661 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12663 /* If we are highlighting the region, then we just changed
12664 the region, so redisplay to show it. */
12665 if (!NILP (Vtransient_mark_mode
)
12666 && !NILP (current_buffer
->mark_active
))
12668 clear_glyph_matrix (w
->desired_matrix
);
12669 if (!try_window (window
, startp
, 0))
12670 goto need_larger_matrices
;
12675 debug_method_add (w
, "forced window start");
12680 /* Handle case where text has not changed, only point, and it has
12681 not moved off the frame, and we are not retrying after hscroll.
12682 (current_matrix_up_to_date_p is nonzero when retrying.) */
12683 if (current_matrix_up_to_date_p
12684 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12685 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12689 case CURSOR_MOVEMENT_SUCCESS
:
12690 used_current_matrix_p
= 1;
12693 #if 0 /* try_cursor_movement never returns this value. */
12694 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12695 goto need_larger_matrices
;
12698 case CURSOR_MOVEMENT_MUST_SCROLL
:
12699 goto try_to_scroll
;
12705 /* If current starting point was originally the beginning of a line
12706 but no longer is, find a new starting point. */
12707 else if (!NILP (w
->start_at_line_beg
)
12708 && !(CHARPOS (startp
) <= BEGV
12709 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12712 debug_method_add (w
, "recenter 1");
12717 /* Try scrolling with try_window_id. Value is > 0 if update has
12718 been done, it is -1 if we know that the same window start will
12719 not work. It is 0 if unsuccessful for some other reason. */
12720 else if ((tem
= try_window_id (w
)) != 0)
12723 debug_method_add (w
, "try_window_id %d", tem
);
12726 if (fonts_changed_p
)
12727 goto need_larger_matrices
;
12731 /* Otherwise try_window_id has returned -1 which means that we
12732 don't want the alternative below this comment to execute. */
12734 else if (CHARPOS (startp
) >= BEGV
12735 && CHARPOS (startp
) <= ZV
12736 && PT
>= CHARPOS (startp
)
12737 && (CHARPOS (startp
) < ZV
12738 /* Avoid starting at end of buffer. */
12739 || CHARPOS (startp
) == BEGV
12740 || (XFASTINT (w
->last_modified
) >= MODIFF
12741 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12744 debug_method_add (w
, "same window start");
12747 /* Try to redisplay starting at same place as before.
12748 If point has not moved off frame, accept the results. */
12749 if (!current_matrix_up_to_date_p
12750 /* Don't use try_window_reusing_current_matrix in this case
12751 because a window scroll function can have changed the
12753 || !NILP (Vwindow_scroll_functions
)
12754 || MINI_WINDOW_P (w
)
12755 || !(used_current_matrix_p
12756 = try_window_reusing_current_matrix (w
)))
12758 IF_DEBUG (debug_method_add (w
, "1"));
12759 if (try_window (window
, startp
, 1) < 0)
12760 /* -1 means we need to scroll.
12761 0 means we need new matrices, but fonts_changed_p
12762 is set in that case, so we will detect it below. */
12763 goto try_to_scroll
;
12766 if (fonts_changed_p
)
12767 goto need_larger_matrices
;
12769 if (w
->cursor
.vpos
>= 0)
12771 if (!just_this_one_p
12772 || current_buffer
->clip_changed
12773 || BEG_UNCHANGED
< CHARPOS (startp
))
12774 /* Forget any recorded base line for line number display. */
12775 w
->base_line_number
= Qnil
;
12777 if (!cursor_row_fully_visible_p (w
, 1, 0))
12779 clear_glyph_matrix (w
->desired_matrix
);
12780 last_line_misfit
= 1;
12782 /* Drop through and scroll. */
12787 clear_glyph_matrix (w
->desired_matrix
);
12792 w
->last_modified
= make_number (0);
12793 w
->last_overlay_modified
= make_number (0);
12795 /* Redisplay the mode line. Select the buffer properly for that. */
12796 if (!update_mode_line
)
12798 update_mode_line
= 1;
12799 w
->update_mode_line
= Qt
;
12802 /* Try to scroll by specified few lines. */
12803 if ((scroll_conservatively
12805 || temp_scroll_step
12806 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12807 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12808 && !current_buffer
->clip_changed
12809 && CHARPOS (startp
) >= BEGV
12810 && CHARPOS (startp
) <= ZV
)
12812 /* The function returns -1 if new fonts were loaded, 1 if
12813 successful, 0 if not successful. */
12814 int rc
= try_scrolling (window
, just_this_one_p
,
12815 scroll_conservatively
,
12817 temp_scroll_step
, last_line_misfit
);
12820 case SCROLLING_SUCCESS
:
12823 case SCROLLING_NEED_LARGER_MATRICES
:
12824 goto need_larger_matrices
;
12826 case SCROLLING_FAILED
:
12834 /* Finally, just choose place to start which centers point */
12837 if (centering_position
< 0)
12838 centering_position
= window_box_height (w
) / 2;
12841 debug_method_add (w
, "recenter");
12844 /* w->vscroll = 0; */
12846 /* Forget any previously recorded base line for line number display. */
12847 if (!buffer_unchanged_p
)
12848 w
->base_line_number
= Qnil
;
12850 /* Move backward half the height of the window. */
12851 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12852 it
.current_y
= it
.last_visible_y
;
12853 move_it_vertically_backward (&it
, centering_position
);
12854 xassert (IT_CHARPOS (it
) >= BEGV
);
12856 /* The function move_it_vertically_backward may move over more
12857 than the specified y-distance. If it->w is small, e.g. a
12858 mini-buffer window, we may end up in front of the window's
12859 display area. Start displaying at the start of the line
12860 containing PT in this case. */
12861 if (it
.current_y
<= 0)
12863 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12864 move_it_vertically_backward (&it
, 0);
12866 /* I think this assert is bogus if buffer contains
12867 invisible text or images. KFS. */
12868 xassert (IT_CHARPOS (it
) <= PT
);
12873 it
.current_x
= it
.hpos
= 0;
12875 /* Set startp here explicitly in case that helps avoid an infinite loop
12876 in case the window-scroll-functions functions get errors. */
12877 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12879 /* Run scroll hooks. */
12880 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12882 /* Redisplay the window. */
12883 if (!current_matrix_up_to_date_p
12884 || windows_or_buffers_changed
12885 || cursor_type_changed
12886 /* Don't use try_window_reusing_current_matrix in this case
12887 because it can have changed the buffer. */
12888 || !NILP (Vwindow_scroll_functions
)
12889 || !just_this_one_p
12890 || MINI_WINDOW_P (w
)
12891 || !(used_current_matrix_p
12892 = try_window_reusing_current_matrix (w
)))
12893 try_window (window
, startp
, 0);
12895 /* If new fonts have been loaded (due to fontsets), give up. We
12896 have to start a new redisplay since we need to re-adjust glyph
12898 if (fonts_changed_p
)
12899 goto need_larger_matrices
;
12901 /* If cursor did not appear assume that the middle of the window is
12902 in the first line of the window. Do it again with the next line.
12903 (Imagine a window of height 100, displaying two lines of height
12904 60. Moving back 50 from it->last_visible_y will end in the first
12906 if (w
->cursor
.vpos
< 0)
12908 if (!NILP (w
->window_end_valid
)
12909 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12911 clear_glyph_matrix (w
->desired_matrix
);
12912 move_it_by_lines (&it
, 1, 0);
12913 try_window (window
, it
.current
.pos
, 0);
12915 else if (PT
< IT_CHARPOS (it
))
12917 clear_glyph_matrix (w
->desired_matrix
);
12918 move_it_by_lines (&it
, -1, 0);
12919 try_window (window
, it
.current
.pos
, 0);
12923 /* Not much we can do about it. */
12927 /* Consider the following case: Window starts at BEGV, there is
12928 invisible, intangible text at BEGV, so that display starts at
12929 some point START > BEGV. It can happen that we are called with
12930 PT somewhere between BEGV and START. Try to handle that case. */
12931 if (w
->cursor
.vpos
< 0)
12933 struct glyph_row
*row
= w
->current_matrix
->rows
;
12934 if (row
->mode_line_p
)
12936 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12939 if (!cursor_row_fully_visible_p (w
, 0, 0))
12941 /* If vscroll is enabled, disable it and try again. */
12945 clear_glyph_matrix (w
->desired_matrix
);
12949 /* If centering point failed to make the whole line visible,
12950 put point at the top instead. That has to make the whole line
12951 visible, if it can be done. */
12952 if (centering_position
== 0)
12955 clear_glyph_matrix (w
->desired_matrix
);
12956 centering_position
= 0;
12962 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12963 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12964 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12967 /* Display the mode line, if we must. */
12968 if ((update_mode_line
12969 /* If window not full width, must redo its mode line
12970 if (a) the window to its side is being redone and
12971 (b) we do a frame-based redisplay. This is a consequence
12972 of how inverted lines are drawn in frame-based redisplay. */
12973 || (!just_this_one_p
12974 && !FRAME_WINDOW_P (f
)
12975 && !WINDOW_FULL_WIDTH_P (w
))
12976 /* Line number to display. */
12977 || INTEGERP (w
->base_line_pos
)
12978 /* Column number is displayed and different from the one displayed. */
12979 || (!NILP (w
->column_number_displayed
)
12980 && (XFASTINT (w
->column_number_displayed
)
12981 != (int) current_column ()))) /* iftc */
12982 /* This means that the window has a mode line. */
12983 && (WINDOW_WANTS_MODELINE_P (w
)
12984 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12986 display_mode_lines (w
);
12988 /* If mode line height has changed, arrange for a thorough
12989 immediate redisplay using the correct mode line height. */
12990 if (WINDOW_WANTS_MODELINE_P (w
)
12991 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12993 fonts_changed_p
= 1;
12994 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12995 = DESIRED_MODE_LINE_HEIGHT (w
);
12998 /* If top line height has changed, arrange for a thorough
12999 immediate redisplay using the correct mode line height. */
13000 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13001 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13003 fonts_changed_p
= 1;
13004 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13005 = DESIRED_HEADER_LINE_HEIGHT (w
);
13008 if (fonts_changed_p
)
13009 goto need_larger_matrices
;
13012 if (!line_number_displayed
13013 && !BUFFERP (w
->base_line_pos
))
13015 w
->base_line_pos
= Qnil
;
13016 w
->base_line_number
= Qnil
;
13021 /* When we reach a frame's selected window, redo the frame's menu bar. */
13022 if (update_mode_line
13023 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13025 int redisplay_menu_p
= 0;
13026 int redisplay_tool_bar_p
= 0;
13028 if (FRAME_WINDOW_P (f
))
13030 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13031 || defined (USE_GTK)
13032 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13034 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13038 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13040 if (redisplay_menu_p
)
13041 display_menu_bar (w
);
13043 #ifdef HAVE_WINDOW_SYSTEM
13044 if (FRAME_WINDOW_P (f
))
13047 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13049 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13050 && (FRAME_TOOL_BAR_LINES (f
) > 0
13051 || auto_resize_tool_bars_p
);
13054 if (redisplay_tool_bar_p
)
13055 redisplay_tool_bar (f
);
13060 #ifdef HAVE_WINDOW_SYSTEM
13061 if (FRAME_WINDOW_P (f
)
13062 && update_window_fringes (w
, (just_this_one_p
13063 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13064 || w
->pseudo_window_p
)))
13068 if (draw_window_fringes (w
, 1))
13069 x_draw_vertical_border (w
);
13073 #endif /* HAVE_WINDOW_SYSTEM */
13075 /* We go to this label, with fonts_changed_p nonzero,
13076 if it is necessary to try again using larger glyph matrices.
13077 We have to redeem the scroll bar even in this case,
13078 because the loop in redisplay_internal expects that. */
13079 need_larger_matrices
:
13081 finish_scroll_bars
:
13083 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13085 /* Set the thumb's position and size. */
13086 set_vertical_scroll_bar (w
);
13088 /* Note that we actually used the scroll bar attached to this
13089 window, so it shouldn't be deleted at the end of redisplay. */
13090 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13091 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13094 /* Restore current_buffer and value of point in it. */
13095 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13096 set_buffer_internal_1 (old
);
13097 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13099 unbind_to (count
, Qnil
);
13103 /* Build the complete desired matrix of WINDOW with a window start
13104 buffer position POS.
13106 Value is 1 if successful. It is zero if fonts were loaded during
13107 redisplay which makes re-adjusting glyph matrices necessary, and -1
13108 if point would appear in the scroll margins.
13109 (We check that only if CHECK_MARGINS is nonzero. */
13112 try_window (window
, pos
, check_margins
)
13113 Lisp_Object window
;
13114 struct text_pos pos
;
13117 struct window
*w
= XWINDOW (window
);
13119 struct glyph_row
*last_text_row
= NULL
;
13121 /* Make POS the new window start. */
13122 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13124 /* Mark cursor position as unknown. No overlay arrow seen. */
13125 w
->cursor
.vpos
= -1;
13126 overlay_arrow_seen
= 0;
13128 /* Initialize iterator and info to start at POS. */
13129 start_display (&it
, w
, pos
);
13131 /* Display all lines of W. */
13132 while (it
.current_y
< it
.last_visible_y
)
13134 if (display_line (&it
))
13135 last_text_row
= it
.glyph_row
- 1;
13136 if (fonts_changed_p
)
13140 /* Don't let the cursor end in the scroll margins. */
13142 && !MINI_WINDOW_P (w
))
13144 int this_scroll_margin
;
13146 this_scroll_margin
= max (0, scroll_margin
);
13147 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13148 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13150 if ((w
->cursor
.y
< this_scroll_margin
13151 && CHARPOS (pos
) > BEGV
13152 && IT_CHARPOS (it
) < ZV
)
13153 /* rms: considering make_cursor_line_fully_visible_p here
13154 seems to give wrong results. We don't want to recenter
13155 when the last line is partly visible, we want to allow
13156 that case to be handled in the usual way. */
13157 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13159 w
->cursor
.vpos
= -1;
13160 clear_glyph_matrix (w
->desired_matrix
);
13165 /* If bottom moved off end of frame, change mode line percentage. */
13166 if (XFASTINT (w
->window_end_pos
) <= 0
13167 && Z
!= IT_CHARPOS (it
))
13168 w
->update_mode_line
= Qt
;
13170 /* Set window_end_pos to the offset of the last character displayed
13171 on the window from the end of current_buffer. Set
13172 window_end_vpos to its row number. */
13175 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13176 w
->window_end_bytepos
13177 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13179 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13181 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13182 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13183 ->displays_text_p
);
13187 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13188 w
->window_end_pos
= make_number (Z
- ZV
);
13189 w
->window_end_vpos
= make_number (0);
13192 /* But that is not valid info until redisplay finishes. */
13193 w
->window_end_valid
= Qnil
;
13199 /************************************************************************
13200 Window redisplay reusing current matrix when buffer has not changed
13201 ************************************************************************/
13203 /* Try redisplay of window W showing an unchanged buffer with a
13204 different window start than the last time it was displayed by
13205 reusing its current matrix. Value is non-zero if successful.
13206 W->start is the new window start. */
13209 try_window_reusing_current_matrix (w
)
13212 struct frame
*f
= XFRAME (w
->frame
);
13213 struct glyph_row
*row
, *bottom_row
;
13216 struct text_pos start
, new_start
;
13217 int nrows_scrolled
, i
;
13218 struct glyph_row
*last_text_row
;
13219 struct glyph_row
*last_reused_text_row
;
13220 struct glyph_row
*start_row
;
13221 int start_vpos
, min_y
, max_y
;
13224 if (inhibit_try_window_reusing
)
13228 if (/* This function doesn't handle terminal frames. */
13229 !FRAME_WINDOW_P (f
)
13230 /* Don't try to reuse the display if windows have been split
13232 || windows_or_buffers_changed
13233 || cursor_type_changed
)
13236 /* Can't do this if region may have changed. */
13237 if ((!NILP (Vtransient_mark_mode
)
13238 && !NILP (current_buffer
->mark_active
))
13239 || !NILP (w
->region_showing
)
13240 || !NILP (Vshow_trailing_whitespace
))
13243 /* If top-line visibility has changed, give up. */
13244 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13245 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13248 /* Give up if old or new display is scrolled vertically. We could
13249 make this function handle this, but right now it doesn't. */
13250 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13251 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13254 /* The variable new_start now holds the new window start. The old
13255 start `start' can be determined from the current matrix. */
13256 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13257 start
= start_row
->start
.pos
;
13258 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13260 /* Clear the desired matrix for the display below. */
13261 clear_glyph_matrix (w
->desired_matrix
);
13263 if (CHARPOS (new_start
) <= CHARPOS (start
))
13267 /* Don't use this method if the display starts with an ellipsis
13268 displayed for invisible text. It's not easy to handle that case
13269 below, and it's certainly not worth the effort since this is
13270 not a frequent case. */
13271 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13274 IF_DEBUG (debug_method_add (w
, "twu1"));
13276 /* Display up to a row that can be reused. The variable
13277 last_text_row is set to the last row displayed that displays
13278 text. Note that it.vpos == 0 if or if not there is a
13279 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13280 start_display (&it
, w
, new_start
);
13281 first_row_y
= it
.current_y
;
13282 w
->cursor
.vpos
= -1;
13283 last_text_row
= last_reused_text_row
= NULL
;
13285 while (it
.current_y
< it
.last_visible_y
13286 && !fonts_changed_p
)
13288 /* If we have reached into the characters in the START row,
13289 that means the line boundaries have changed. So we
13290 can't start copying with the row START. Maybe it will
13291 work to start copying with the following row. */
13292 while (IT_CHARPOS (it
) > CHARPOS (start
))
13294 /* Advance to the next row as the "start". */
13296 start
= start_row
->start
.pos
;
13297 /* If there are no more rows to try, or just one, give up. */
13298 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13299 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13300 || CHARPOS (start
) == ZV
)
13302 clear_glyph_matrix (w
->desired_matrix
);
13306 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13308 /* If we have reached alignment,
13309 we can copy the rest of the rows. */
13310 if (IT_CHARPOS (it
) == CHARPOS (start
))
13313 if (display_line (&it
))
13314 last_text_row
= it
.glyph_row
- 1;
13317 /* A value of current_y < last_visible_y means that we stopped
13318 at the previous window start, which in turn means that we
13319 have at least one reusable row. */
13320 if (it
.current_y
< it
.last_visible_y
)
13322 /* IT.vpos always starts from 0; it counts text lines. */
13323 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13325 /* Find PT if not already found in the lines displayed. */
13326 if (w
->cursor
.vpos
< 0)
13328 int dy
= it
.current_y
- start_row
->y
;
13330 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13331 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13333 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13334 dy
, nrows_scrolled
);
13337 clear_glyph_matrix (w
->desired_matrix
);
13342 /* Scroll the display. Do it before the current matrix is
13343 changed. The problem here is that update has not yet
13344 run, i.e. part of the current matrix is not up to date.
13345 scroll_run_hook will clear the cursor, and use the
13346 current matrix to get the height of the row the cursor is
13348 run
.current_y
= start_row
->y
;
13349 run
.desired_y
= it
.current_y
;
13350 run
.height
= it
.last_visible_y
- it
.current_y
;
13352 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13355 FRAME_RIF (f
)->update_window_begin_hook (w
);
13356 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13357 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13358 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13362 /* Shift current matrix down by nrows_scrolled lines. */
13363 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13364 rotate_matrix (w
->current_matrix
,
13366 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13369 /* Disable lines that must be updated. */
13370 for (i
= 0; i
< it
.vpos
; ++i
)
13371 (start_row
+ i
)->enabled_p
= 0;
13373 /* Re-compute Y positions. */
13374 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13375 max_y
= it
.last_visible_y
;
13376 for (row
= start_row
+ nrows_scrolled
;
13380 row
->y
= it
.current_y
;
13381 row
->visible_height
= row
->height
;
13383 if (row
->y
< min_y
)
13384 row
->visible_height
-= min_y
- row
->y
;
13385 if (row
->y
+ row
->height
> max_y
)
13386 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13387 row
->redraw_fringe_bitmaps_p
= 1;
13389 it
.current_y
+= row
->height
;
13391 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13392 last_reused_text_row
= row
;
13393 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13397 /* Disable lines in the current matrix which are now
13398 below the window. */
13399 for (++row
; row
< bottom_row
; ++row
)
13400 row
->enabled_p
= row
->mode_line_p
= 0;
13403 /* Update window_end_pos etc.; last_reused_text_row is the last
13404 reused row from the current matrix containing text, if any.
13405 The value of last_text_row is the last displayed line
13406 containing text. */
13407 if (last_reused_text_row
)
13409 w
->window_end_bytepos
13410 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13412 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13414 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13415 w
->current_matrix
));
13417 else if (last_text_row
)
13419 w
->window_end_bytepos
13420 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13422 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13424 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13428 /* This window must be completely empty. */
13429 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13430 w
->window_end_pos
= make_number (Z
- ZV
);
13431 w
->window_end_vpos
= make_number (0);
13433 w
->window_end_valid
= Qnil
;
13435 /* Update hint: don't try scrolling again in update_window. */
13436 w
->desired_matrix
->no_scrolling_p
= 1;
13439 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13443 else if (CHARPOS (new_start
) > CHARPOS (start
))
13445 struct glyph_row
*pt_row
, *row
;
13446 struct glyph_row
*first_reusable_row
;
13447 struct glyph_row
*first_row_to_display
;
13449 int yb
= window_text_bottom_y (w
);
13451 /* Find the row starting at new_start, if there is one. Don't
13452 reuse a partially visible line at the end. */
13453 first_reusable_row
= start_row
;
13454 while (first_reusable_row
->enabled_p
13455 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13456 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13457 < CHARPOS (new_start
)))
13458 ++first_reusable_row
;
13460 /* Give up if there is no row to reuse. */
13461 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13462 || !first_reusable_row
->enabled_p
13463 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13464 != CHARPOS (new_start
)))
13467 /* We can reuse fully visible rows beginning with
13468 first_reusable_row to the end of the window. Set
13469 first_row_to_display to the first row that cannot be reused.
13470 Set pt_row to the row containing point, if there is any. */
13472 for (first_row_to_display
= first_reusable_row
;
13473 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13474 ++first_row_to_display
)
13476 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13477 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13478 pt_row
= first_row_to_display
;
13481 /* Start displaying at the start of first_row_to_display. */
13482 xassert (first_row_to_display
->y
< yb
);
13483 init_to_row_start (&it
, w
, first_row_to_display
);
13485 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13487 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13489 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13490 + WINDOW_HEADER_LINE_HEIGHT (w
));
13492 /* Display lines beginning with first_row_to_display in the
13493 desired matrix. Set last_text_row to the last row displayed
13494 that displays text. */
13495 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13496 if (pt_row
== NULL
)
13497 w
->cursor
.vpos
= -1;
13498 last_text_row
= NULL
;
13499 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13500 if (display_line (&it
))
13501 last_text_row
= it
.glyph_row
- 1;
13503 /* Give up If point isn't in a row displayed or reused. */
13504 if (w
->cursor
.vpos
< 0)
13506 clear_glyph_matrix (w
->desired_matrix
);
13510 /* If point is in a reused row, adjust y and vpos of the cursor
13514 w
->cursor
.vpos
-= nrows_scrolled
;
13515 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13518 /* Scroll the display. */
13519 run
.current_y
= first_reusable_row
->y
;
13520 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13521 run
.height
= it
.last_visible_y
- run
.current_y
;
13522 dy
= run
.current_y
- run
.desired_y
;
13527 FRAME_RIF (f
)->update_window_begin_hook (w
);
13528 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13529 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13530 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13534 /* Adjust Y positions of reused rows. */
13535 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13536 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13537 max_y
= it
.last_visible_y
;
13538 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13541 row
->visible_height
= row
->height
;
13542 if (row
->y
< min_y
)
13543 row
->visible_height
-= min_y
- row
->y
;
13544 if (row
->y
+ row
->height
> max_y
)
13545 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13546 row
->redraw_fringe_bitmaps_p
= 1;
13549 /* Scroll the current matrix. */
13550 xassert (nrows_scrolled
> 0);
13551 rotate_matrix (w
->current_matrix
,
13553 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13556 /* Disable rows not reused. */
13557 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13558 row
->enabled_p
= 0;
13560 /* Point may have moved to a different line, so we cannot assume that
13561 the previous cursor position is valid; locate the correct row. */
13564 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13565 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13569 w
->cursor
.y
= row
->y
;
13571 if (row
< bottom_row
)
13573 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13574 while (glyph
->charpos
< PT
)
13577 w
->cursor
.x
+= glyph
->pixel_width
;
13583 /* Adjust window end. A null value of last_text_row means that
13584 the window end is in reused rows which in turn means that
13585 only its vpos can have changed. */
13588 w
->window_end_bytepos
13589 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13591 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13593 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13598 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13601 w
->window_end_valid
= Qnil
;
13602 w
->desired_matrix
->no_scrolling_p
= 1;
13605 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13615 /************************************************************************
13616 Window redisplay reusing current matrix when buffer has changed
13617 ************************************************************************/
13619 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13620 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13622 static struct glyph_row
*
13623 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13624 struct glyph_row
*));
13627 /* Return the last row in MATRIX displaying text. If row START is
13628 non-null, start searching with that row. IT gives the dimensions
13629 of the display. Value is null if matrix is empty; otherwise it is
13630 a pointer to the row found. */
13632 static struct glyph_row
*
13633 find_last_row_displaying_text (matrix
, it
, start
)
13634 struct glyph_matrix
*matrix
;
13636 struct glyph_row
*start
;
13638 struct glyph_row
*row
, *row_found
;
13640 /* Set row_found to the last row in IT->w's current matrix
13641 displaying text. The loop looks funny but think of partially
13644 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13645 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13647 xassert (row
->enabled_p
);
13649 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13658 /* Return the last row in the current matrix of W that is not affected
13659 by changes at the start of current_buffer that occurred since W's
13660 current matrix was built. Value is null if no such row exists.
13662 BEG_UNCHANGED us the number of characters unchanged at the start of
13663 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13664 first changed character in current_buffer. Characters at positions <
13665 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13666 when the current matrix was built. */
13668 static struct glyph_row
*
13669 find_last_unchanged_at_beg_row (w
)
13672 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13673 struct glyph_row
*row
;
13674 struct glyph_row
*row_found
= NULL
;
13675 int yb
= window_text_bottom_y (w
);
13677 /* Find the last row displaying unchanged text. */
13678 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13679 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13680 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13682 if (/* If row ends before first_changed_pos, it is unchanged,
13683 except in some case. */
13684 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13685 /* When row ends in ZV and we write at ZV it is not
13687 && !row
->ends_at_zv_p
13688 /* When first_changed_pos is the end of a continued line,
13689 row is not unchanged because it may be no longer
13691 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13692 && (row
->continued_p
13693 || row
->exact_window_width_line_p
)))
13696 /* Stop if last visible row. */
13697 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13707 /* Find the first glyph row in the current matrix of W that is not
13708 affected by changes at the end of current_buffer since the
13709 time W's current matrix was built.
13711 Return in *DELTA the number of chars by which buffer positions in
13712 unchanged text at the end of current_buffer must be adjusted.
13714 Return in *DELTA_BYTES the corresponding number of bytes.
13716 Value is null if no such row exists, i.e. all rows are affected by
13719 static struct glyph_row
*
13720 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13722 int *delta
, *delta_bytes
;
13724 struct glyph_row
*row
;
13725 struct glyph_row
*row_found
= NULL
;
13727 *delta
= *delta_bytes
= 0;
13729 /* Display must not have been paused, otherwise the current matrix
13730 is not up to date. */
13731 if (NILP (w
->window_end_valid
))
13734 /* A value of window_end_pos >= END_UNCHANGED means that the window
13735 end is in the range of changed text. If so, there is no
13736 unchanged row at the end of W's current matrix. */
13737 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13740 /* Set row to the last row in W's current matrix displaying text. */
13741 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13743 /* If matrix is entirely empty, no unchanged row exists. */
13744 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13746 /* The value of row is the last glyph row in the matrix having a
13747 meaningful buffer position in it. The end position of row
13748 corresponds to window_end_pos. This allows us to translate
13749 buffer positions in the current matrix to current buffer
13750 positions for characters not in changed text. */
13751 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13752 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13753 int last_unchanged_pos
, last_unchanged_pos_old
;
13754 struct glyph_row
*first_text_row
13755 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13757 *delta
= Z
- Z_old
;
13758 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13760 /* Set last_unchanged_pos to the buffer position of the last
13761 character in the buffer that has not been changed. Z is the
13762 index + 1 of the last character in current_buffer, i.e. by
13763 subtracting END_UNCHANGED we get the index of the last
13764 unchanged character, and we have to add BEG to get its buffer
13766 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13767 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13769 /* Search backward from ROW for a row displaying a line that
13770 starts at a minimum position >= last_unchanged_pos_old. */
13771 for (; row
> first_text_row
; --row
)
13773 /* This used to abort, but it can happen.
13774 It is ok to just stop the search instead here. KFS. */
13775 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13778 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13783 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13790 /* Make sure that glyph rows in the current matrix of window W
13791 reference the same glyph memory as corresponding rows in the
13792 frame's frame matrix. This function is called after scrolling W's
13793 current matrix on a terminal frame in try_window_id and
13794 try_window_reusing_current_matrix. */
13797 sync_frame_with_window_matrix_rows (w
)
13800 struct frame
*f
= XFRAME (w
->frame
);
13801 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13803 /* Preconditions: W must be a leaf window and full-width. Its frame
13804 must have a frame matrix. */
13805 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13806 xassert (WINDOW_FULL_WIDTH_P (w
));
13807 xassert (!FRAME_WINDOW_P (f
));
13809 /* If W is a full-width window, glyph pointers in W's current matrix
13810 have, by definition, to be the same as glyph pointers in the
13811 corresponding frame matrix. Note that frame matrices have no
13812 marginal areas (see build_frame_matrix). */
13813 window_row
= w
->current_matrix
->rows
;
13814 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13815 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13816 while (window_row
< window_row_end
)
13818 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13819 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13821 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13822 frame_row
->glyphs
[TEXT_AREA
] = start
;
13823 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13824 frame_row
->glyphs
[LAST_AREA
] = end
;
13826 /* Disable frame rows whose corresponding window rows have
13827 been disabled in try_window_id. */
13828 if (!window_row
->enabled_p
)
13829 frame_row
->enabled_p
= 0;
13831 ++window_row
, ++frame_row
;
13836 /* Find the glyph row in window W containing CHARPOS. Consider all
13837 rows between START and END (not inclusive). END null means search
13838 all rows to the end of the display area of W. Value is the row
13839 containing CHARPOS or null. */
13842 row_containing_pos (w
, charpos
, start
, end
, dy
)
13845 struct glyph_row
*start
, *end
;
13848 struct glyph_row
*row
= start
;
13851 /* If we happen to start on a header-line, skip that. */
13852 if (row
->mode_line_p
)
13855 if ((end
&& row
>= end
) || !row
->enabled_p
)
13858 last_y
= window_text_bottom_y (w
) - dy
;
13862 /* Give up if we have gone too far. */
13863 if (end
&& row
>= end
)
13865 /* This formerly returned if they were equal.
13866 I think that both quantities are of a "last plus one" type;
13867 if so, when they are equal, the row is within the screen. -- rms. */
13868 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13871 /* If it is in this row, return this row. */
13872 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13873 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13874 /* The end position of a row equals the start
13875 position of the next row. If CHARPOS is there, we
13876 would rather display it in the next line, except
13877 when this line ends in ZV. */
13878 && !row
->ends_at_zv_p
13879 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13880 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13887 /* Try to redisplay window W by reusing its existing display. W's
13888 current matrix must be up to date when this function is called,
13889 i.e. window_end_valid must not be nil.
13893 1 if display has been updated
13894 0 if otherwise unsuccessful
13895 -1 if redisplay with same window start is known not to succeed
13897 The following steps are performed:
13899 1. Find the last row in the current matrix of W that is not
13900 affected by changes at the start of current_buffer. If no such row
13903 2. Find the first row in W's current matrix that is not affected by
13904 changes at the end of current_buffer. Maybe there is no such row.
13906 3. Display lines beginning with the row + 1 found in step 1 to the
13907 row found in step 2 or, if step 2 didn't find a row, to the end of
13910 4. If cursor is not known to appear on the window, give up.
13912 5. If display stopped at the row found in step 2, scroll the
13913 display and current matrix as needed.
13915 6. Maybe display some lines at the end of W, if we must. This can
13916 happen under various circumstances, like a partially visible line
13917 becoming fully visible, or because newly displayed lines are displayed
13918 in smaller font sizes.
13920 7. Update W's window end information. */
13926 struct frame
*f
= XFRAME (w
->frame
);
13927 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13928 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13929 struct glyph_row
*last_unchanged_at_beg_row
;
13930 struct glyph_row
*first_unchanged_at_end_row
;
13931 struct glyph_row
*row
;
13932 struct glyph_row
*bottom_row
;
13935 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13936 struct text_pos start_pos
;
13938 int first_unchanged_at_end_vpos
= 0;
13939 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13940 struct text_pos start
;
13941 int first_changed_charpos
, last_changed_charpos
;
13944 if (inhibit_try_window_id
)
13948 /* This is handy for debugging. */
13950 #define GIVE_UP(X) \
13952 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13956 #define GIVE_UP(X) return 0
13959 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13961 /* Don't use this for mini-windows because these can show
13962 messages and mini-buffers, and we don't handle that here. */
13963 if (MINI_WINDOW_P (w
))
13966 /* This flag is used to prevent redisplay optimizations. */
13967 if (windows_or_buffers_changed
|| cursor_type_changed
)
13970 /* Verify that narrowing has not changed.
13971 Also verify that we were not told to prevent redisplay optimizations.
13972 It would be nice to further
13973 reduce the number of cases where this prevents try_window_id. */
13974 if (current_buffer
->clip_changed
13975 || current_buffer
->prevent_redisplay_optimizations_p
)
13978 /* Window must either use window-based redisplay or be full width. */
13979 if (!FRAME_WINDOW_P (f
)
13980 && (!FRAME_LINE_INS_DEL_OK (f
)
13981 || !WINDOW_FULL_WIDTH_P (w
)))
13984 /* Give up if point is not known NOT to appear in W. */
13985 if (PT
< CHARPOS (start
))
13988 /* Another way to prevent redisplay optimizations. */
13989 if (XFASTINT (w
->last_modified
) == 0)
13992 /* Verify that window is not hscrolled. */
13993 if (XFASTINT (w
->hscroll
) != 0)
13996 /* Verify that display wasn't paused. */
13997 if (NILP (w
->window_end_valid
))
14000 /* Can't use this if highlighting a region because a cursor movement
14001 will do more than just set the cursor. */
14002 if (!NILP (Vtransient_mark_mode
)
14003 && !NILP (current_buffer
->mark_active
))
14006 /* Likewise if highlighting trailing whitespace. */
14007 if (!NILP (Vshow_trailing_whitespace
))
14010 /* Likewise if showing a region. */
14011 if (!NILP (w
->region_showing
))
14014 /* Can use this if overlay arrow position and or string have changed. */
14015 if (overlay_arrows_changed_p ())
14019 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14020 only if buffer has really changed. The reason is that the gap is
14021 initially at Z for freshly visited files. The code below would
14022 set end_unchanged to 0 in that case. */
14023 if (MODIFF
> SAVE_MODIFF
14024 /* This seems to happen sometimes after saving a buffer. */
14025 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14027 if (GPT
- BEG
< BEG_UNCHANGED
)
14028 BEG_UNCHANGED
= GPT
- BEG
;
14029 if (Z
- GPT
< END_UNCHANGED
)
14030 END_UNCHANGED
= Z
- GPT
;
14033 /* The position of the first and last character that has been changed. */
14034 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14035 last_changed_charpos
= Z
- END_UNCHANGED
;
14037 /* If window starts after a line end, and the last change is in
14038 front of that newline, then changes don't affect the display.
14039 This case happens with stealth-fontification. Note that although
14040 the display is unchanged, glyph positions in the matrix have to
14041 be adjusted, of course. */
14042 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14043 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14044 && ((last_changed_charpos
< CHARPOS (start
)
14045 && CHARPOS (start
) == BEGV
)
14046 || (last_changed_charpos
< CHARPOS (start
) - 1
14047 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14049 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14050 struct glyph_row
*r0
;
14052 /* Compute how many chars/bytes have been added to or removed
14053 from the buffer. */
14054 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14055 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14057 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14059 /* Give up if PT is not in the window. Note that it already has
14060 been checked at the start of try_window_id that PT is not in
14061 front of the window start. */
14062 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14065 /* If window start is unchanged, we can reuse the whole matrix
14066 as is, after adjusting glyph positions. No need to compute
14067 the window end again, since its offset from Z hasn't changed. */
14068 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14069 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14070 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14071 /* PT must not be in a partially visible line. */
14072 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14073 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14075 /* Adjust positions in the glyph matrix. */
14076 if (delta
|| delta_bytes
)
14078 struct glyph_row
*r1
14079 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14080 increment_matrix_positions (w
->current_matrix
,
14081 MATRIX_ROW_VPOS (r0
, current_matrix
),
14082 MATRIX_ROW_VPOS (r1
, current_matrix
),
14083 delta
, delta_bytes
);
14086 /* Set the cursor. */
14087 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14089 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14096 /* Handle the case that changes are all below what is displayed in
14097 the window, and that PT is in the window. This shortcut cannot
14098 be taken if ZV is visible in the window, and text has been added
14099 there that is visible in the window. */
14100 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14101 /* ZV is not visible in the window, or there are no
14102 changes at ZV, actually. */
14103 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14104 || first_changed_charpos
== last_changed_charpos
))
14106 struct glyph_row
*r0
;
14108 /* Give up if PT is not in the window. Note that it already has
14109 been checked at the start of try_window_id that PT is not in
14110 front of the window start. */
14111 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14114 /* If window start is unchanged, we can reuse the whole matrix
14115 as is, without changing glyph positions since no text has
14116 been added/removed in front of the window end. */
14117 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14118 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14119 /* PT must not be in a partially visible line. */
14120 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14121 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14123 /* We have to compute the window end anew since text
14124 can have been added/removed after it. */
14126 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14127 w
->window_end_bytepos
14128 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14130 /* Set the cursor. */
14131 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14133 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14140 /* Give up if window start is in the changed area.
14142 The condition used to read
14144 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14146 but why that was tested escapes me at the moment. */
14147 if (CHARPOS (start
) >= first_changed_charpos
14148 && CHARPOS (start
) <= last_changed_charpos
)
14151 /* Check that window start agrees with the start of the first glyph
14152 row in its current matrix. Check this after we know the window
14153 start is not in changed text, otherwise positions would not be
14155 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14156 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14159 /* Give up if the window ends in strings. Overlay strings
14160 at the end are difficult to handle, so don't try. */
14161 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14162 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14165 /* Compute the position at which we have to start displaying new
14166 lines. Some of the lines at the top of the window might be
14167 reusable because they are not displaying changed text. Find the
14168 last row in W's current matrix not affected by changes at the
14169 start of current_buffer. Value is null if changes start in the
14170 first line of window. */
14171 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14172 if (last_unchanged_at_beg_row
)
14174 /* Avoid starting to display in the moddle of a character, a TAB
14175 for instance. This is easier than to set up the iterator
14176 exactly, and it's not a frequent case, so the additional
14177 effort wouldn't really pay off. */
14178 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14179 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14180 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14181 --last_unchanged_at_beg_row
;
14183 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14186 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14188 start_pos
= it
.current
.pos
;
14190 /* Start displaying new lines in the desired matrix at the same
14191 vpos we would use in the current matrix, i.e. below
14192 last_unchanged_at_beg_row. */
14193 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14195 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14196 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14198 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14202 /* There are no reusable lines at the start of the window.
14203 Start displaying in the first text line. */
14204 start_display (&it
, w
, start
);
14205 it
.vpos
= it
.first_vpos
;
14206 start_pos
= it
.current
.pos
;
14209 /* Find the first row that is not affected by changes at the end of
14210 the buffer. Value will be null if there is no unchanged row, in
14211 which case we must redisplay to the end of the window. delta
14212 will be set to the value by which buffer positions beginning with
14213 first_unchanged_at_end_row have to be adjusted due to text
14215 first_unchanged_at_end_row
14216 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14217 IF_DEBUG (debug_delta
= delta
);
14218 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14220 /* Set stop_pos to the buffer position up to which we will have to
14221 display new lines. If first_unchanged_at_end_row != NULL, this
14222 is the buffer position of the start of the line displayed in that
14223 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14224 that we don't stop at a buffer position. */
14226 if (first_unchanged_at_end_row
)
14228 xassert (last_unchanged_at_beg_row
== NULL
14229 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14231 /* If this is a continuation line, move forward to the next one
14232 that isn't. Changes in lines above affect this line.
14233 Caution: this may move first_unchanged_at_end_row to a row
14234 not displaying text. */
14235 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14236 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14237 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14238 < it
.last_visible_y
))
14239 ++first_unchanged_at_end_row
;
14241 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14242 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14243 >= it
.last_visible_y
))
14244 first_unchanged_at_end_row
= NULL
;
14247 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14249 first_unchanged_at_end_vpos
14250 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14251 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14254 else if (last_unchanged_at_beg_row
== NULL
)
14260 /* Either there is no unchanged row at the end, or the one we have
14261 now displays text. This is a necessary condition for the window
14262 end pos calculation at the end of this function. */
14263 xassert (first_unchanged_at_end_row
== NULL
14264 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14266 debug_last_unchanged_at_beg_vpos
14267 = (last_unchanged_at_beg_row
14268 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14270 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14272 #endif /* GLYPH_DEBUG != 0 */
14275 /* Display new lines. Set last_text_row to the last new line
14276 displayed which has text on it, i.e. might end up as being the
14277 line where the window_end_vpos is. */
14278 w
->cursor
.vpos
= -1;
14279 last_text_row
= NULL
;
14280 overlay_arrow_seen
= 0;
14281 while (it
.current_y
< it
.last_visible_y
14282 && !fonts_changed_p
14283 && (first_unchanged_at_end_row
== NULL
14284 || IT_CHARPOS (it
) < stop_pos
))
14286 if (display_line (&it
))
14287 last_text_row
= it
.glyph_row
- 1;
14290 if (fonts_changed_p
)
14294 /* Compute differences in buffer positions, y-positions etc. for
14295 lines reused at the bottom of the window. Compute what we can
14297 if (first_unchanged_at_end_row
14298 /* No lines reused because we displayed everything up to the
14299 bottom of the window. */
14300 && it
.current_y
< it
.last_visible_y
)
14303 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14305 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14306 run
.current_y
= first_unchanged_at_end_row
->y
;
14307 run
.desired_y
= run
.current_y
+ dy
;
14308 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14312 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14313 first_unchanged_at_end_row
= NULL
;
14315 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14318 /* Find the cursor if not already found. We have to decide whether
14319 PT will appear on this window (it sometimes doesn't, but this is
14320 not a very frequent case.) This decision has to be made before
14321 the current matrix is altered. A value of cursor.vpos < 0 means
14322 that PT is either in one of the lines beginning at
14323 first_unchanged_at_end_row or below the window. Don't care for
14324 lines that might be displayed later at the window end; as
14325 mentioned, this is not a frequent case. */
14326 if (w
->cursor
.vpos
< 0)
14328 /* Cursor in unchanged rows at the top? */
14329 if (PT
< CHARPOS (start_pos
)
14330 && last_unchanged_at_beg_row
)
14332 row
= row_containing_pos (w
, PT
,
14333 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14334 last_unchanged_at_beg_row
+ 1, 0);
14336 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14339 /* Start from first_unchanged_at_end_row looking for PT. */
14340 else if (first_unchanged_at_end_row
)
14342 row
= row_containing_pos (w
, PT
- delta
,
14343 first_unchanged_at_end_row
, NULL
, 0);
14345 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14346 delta_bytes
, dy
, dvpos
);
14349 /* Give up if cursor was not found. */
14350 if (w
->cursor
.vpos
< 0)
14352 clear_glyph_matrix (w
->desired_matrix
);
14357 /* Don't let the cursor end in the scroll margins. */
14359 int this_scroll_margin
, cursor_height
;
14361 this_scroll_margin
= max (0, scroll_margin
);
14362 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14363 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14364 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14366 if ((w
->cursor
.y
< this_scroll_margin
14367 && CHARPOS (start
) > BEGV
)
14368 /* Old redisplay didn't take scroll margin into account at the bottom,
14369 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14370 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14371 ? cursor_height
+ this_scroll_margin
14372 : 1)) > it
.last_visible_y
)
14374 w
->cursor
.vpos
= -1;
14375 clear_glyph_matrix (w
->desired_matrix
);
14380 /* Scroll the display. Do it before changing the current matrix so
14381 that xterm.c doesn't get confused about where the cursor glyph is
14383 if (dy
&& run
.height
)
14387 if (FRAME_WINDOW_P (f
))
14389 FRAME_RIF (f
)->update_window_begin_hook (w
);
14390 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14391 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14392 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14396 /* Terminal frame. In this case, dvpos gives the number of
14397 lines to scroll by; dvpos < 0 means scroll up. */
14398 int first_unchanged_at_end_vpos
14399 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14400 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14401 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14402 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14403 + window_internal_height (w
));
14405 /* Perform the operation on the screen. */
14408 /* Scroll last_unchanged_at_beg_row to the end of the
14409 window down dvpos lines. */
14410 set_terminal_window (f
, end
);
14412 /* On dumb terminals delete dvpos lines at the end
14413 before inserting dvpos empty lines. */
14414 if (!FRAME_SCROLL_REGION_OK (f
))
14415 ins_del_lines (f
, end
- dvpos
, -dvpos
);
14417 /* Insert dvpos empty lines in front of
14418 last_unchanged_at_beg_row. */
14419 ins_del_lines (f
, from
, dvpos
);
14421 else if (dvpos
< 0)
14423 /* Scroll up last_unchanged_at_beg_vpos to the end of
14424 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14425 set_terminal_window (f
, end
);
14427 /* Delete dvpos lines in front of
14428 last_unchanged_at_beg_vpos. ins_del_lines will set
14429 the cursor to the given vpos and emit |dvpos| delete
14431 ins_del_lines (f
, from
+ dvpos
, dvpos
);
14433 /* On a dumb terminal insert dvpos empty lines at the
14435 if (!FRAME_SCROLL_REGION_OK (f
))
14436 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
14439 set_terminal_window (f
, 0);
14445 /* Shift reused rows of the current matrix to the right position.
14446 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14448 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14449 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14452 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14453 bottom_vpos
, dvpos
);
14454 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14457 else if (dvpos
> 0)
14459 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14460 bottom_vpos
, dvpos
);
14461 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14462 first_unchanged_at_end_vpos
+ dvpos
, 0);
14465 /* For frame-based redisplay, make sure that current frame and window
14466 matrix are in sync with respect to glyph memory. */
14467 if (!FRAME_WINDOW_P (f
))
14468 sync_frame_with_window_matrix_rows (w
);
14470 /* Adjust buffer positions in reused rows. */
14472 increment_matrix_positions (current_matrix
,
14473 first_unchanged_at_end_vpos
+ dvpos
,
14474 bottom_vpos
, delta
, delta_bytes
);
14476 /* Adjust Y positions. */
14478 shift_glyph_matrix (w
, current_matrix
,
14479 first_unchanged_at_end_vpos
+ dvpos
,
14482 if (first_unchanged_at_end_row
)
14484 first_unchanged_at_end_row
+= dvpos
;
14485 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14486 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14487 first_unchanged_at_end_row
= NULL
;
14490 /* If scrolling up, there may be some lines to display at the end of
14492 last_text_row_at_end
= NULL
;
14495 /* Scrolling up can leave for example a partially visible line
14496 at the end of the window to be redisplayed. */
14497 /* Set last_row to the glyph row in the current matrix where the
14498 window end line is found. It has been moved up or down in
14499 the matrix by dvpos. */
14500 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14501 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14503 /* If last_row is the window end line, it should display text. */
14504 xassert (last_row
->displays_text_p
);
14506 /* If window end line was partially visible before, begin
14507 displaying at that line. Otherwise begin displaying with the
14508 line following it. */
14509 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14511 init_to_row_start (&it
, w
, last_row
);
14512 it
.vpos
= last_vpos
;
14513 it
.current_y
= last_row
->y
;
14517 init_to_row_end (&it
, w
, last_row
);
14518 it
.vpos
= 1 + last_vpos
;
14519 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14523 /* We may start in a continuation line. If so, we have to
14524 get the right continuation_lines_width and current_x. */
14525 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14526 it
.hpos
= it
.current_x
= 0;
14528 /* Display the rest of the lines at the window end. */
14529 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14530 while (it
.current_y
< it
.last_visible_y
14531 && !fonts_changed_p
)
14533 /* Is it always sure that the display agrees with lines in
14534 the current matrix? I don't think so, so we mark rows
14535 displayed invalid in the current matrix by setting their
14536 enabled_p flag to zero. */
14537 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14538 if (display_line (&it
))
14539 last_text_row_at_end
= it
.glyph_row
- 1;
14543 /* Update window_end_pos and window_end_vpos. */
14544 if (first_unchanged_at_end_row
14545 && !last_text_row_at_end
)
14547 /* Window end line if one of the preserved rows from the current
14548 matrix. Set row to the last row displaying text in current
14549 matrix starting at first_unchanged_at_end_row, after
14551 xassert (first_unchanged_at_end_row
->displays_text_p
);
14552 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14553 first_unchanged_at_end_row
);
14554 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14556 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14557 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14559 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14560 xassert (w
->window_end_bytepos
>= 0);
14561 IF_DEBUG (debug_method_add (w
, "A"));
14563 else if (last_text_row_at_end
)
14566 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14567 w
->window_end_bytepos
14568 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14570 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14571 xassert (w
->window_end_bytepos
>= 0);
14572 IF_DEBUG (debug_method_add (w
, "B"));
14574 else if (last_text_row
)
14576 /* We have displayed either to the end of the window or at the
14577 end of the window, i.e. the last row with text is to be found
14578 in the desired matrix. */
14580 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14581 w
->window_end_bytepos
14582 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14584 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14585 xassert (w
->window_end_bytepos
>= 0);
14587 else if (first_unchanged_at_end_row
== NULL
14588 && last_text_row
== NULL
14589 && last_text_row_at_end
== NULL
)
14591 /* Displayed to end of window, but no line containing text was
14592 displayed. Lines were deleted at the end of the window. */
14593 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14594 int vpos
= XFASTINT (w
->window_end_vpos
);
14595 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14596 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14599 row
== NULL
&& vpos
>= first_vpos
;
14600 --vpos
, --current_row
, --desired_row
)
14602 if (desired_row
->enabled_p
)
14604 if (desired_row
->displays_text_p
)
14607 else if (current_row
->displays_text_p
)
14611 xassert (row
!= NULL
);
14612 w
->window_end_vpos
= make_number (vpos
+ 1);
14613 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14614 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14615 xassert (w
->window_end_bytepos
>= 0);
14616 IF_DEBUG (debug_method_add (w
, "C"));
14621 #if 0 /* This leads to problems, for instance when the cursor is
14622 at ZV, and the cursor line displays no text. */
14623 /* Disable rows below what's displayed in the window. This makes
14624 debugging easier. */
14625 enable_glyph_matrix_rows (current_matrix
,
14626 XFASTINT (w
->window_end_vpos
) + 1,
14630 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14631 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14633 /* Record that display has not been completed. */
14634 w
->window_end_valid
= Qnil
;
14635 w
->desired_matrix
->no_scrolling_p
= 1;
14643 /***********************************************************************
14644 More debugging support
14645 ***********************************************************************/
14649 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14650 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14651 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14654 /* Dump the contents of glyph matrix MATRIX on stderr.
14656 GLYPHS 0 means don't show glyph contents.
14657 GLYPHS 1 means show glyphs in short form
14658 GLYPHS > 1 means show glyphs in long form. */
14661 dump_glyph_matrix (matrix
, glyphs
)
14662 struct glyph_matrix
*matrix
;
14666 for (i
= 0; i
< matrix
->nrows
; ++i
)
14667 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14671 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14672 the glyph row and area where the glyph comes from. */
14675 dump_glyph (row
, glyph
, area
)
14676 struct glyph_row
*row
;
14677 struct glyph
*glyph
;
14680 if (glyph
->type
== CHAR_GLYPH
)
14683 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14684 glyph
- row
->glyphs
[TEXT_AREA
],
14687 (BUFFERP (glyph
->object
)
14689 : (STRINGP (glyph
->object
)
14692 glyph
->pixel_width
,
14694 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14698 glyph
->left_box_line_p
,
14699 glyph
->right_box_line_p
);
14701 else if (glyph
->type
== STRETCH_GLYPH
)
14704 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14705 glyph
- row
->glyphs
[TEXT_AREA
],
14708 (BUFFERP (glyph
->object
)
14710 : (STRINGP (glyph
->object
)
14713 glyph
->pixel_width
,
14717 glyph
->left_box_line_p
,
14718 glyph
->right_box_line_p
);
14720 else if (glyph
->type
== IMAGE_GLYPH
)
14723 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14724 glyph
- row
->glyphs
[TEXT_AREA
],
14727 (BUFFERP (glyph
->object
)
14729 : (STRINGP (glyph
->object
)
14732 glyph
->pixel_width
,
14736 glyph
->left_box_line_p
,
14737 glyph
->right_box_line_p
);
14742 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14743 GLYPHS 0 means don't show glyph contents.
14744 GLYPHS 1 means show glyphs in short form
14745 GLYPHS > 1 means show glyphs in long form. */
14748 dump_glyph_row (row
, vpos
, glyphs
)
14749 struct glyph_row
*row
;
14754 fprintf (stderr
, "Row Start End Used oEI><\\CTZFesm X Y W H V A P\n");
14755 fprintf (stderr
, "======================================================================\n");
14757 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14758 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14760 MATRIX_ROW_START_CHARPOS (row
),
14761 MATRIX_ROW_END_CHARPOS (row
),
14762 row
->used
[TEXT_AREA
],
14763 row
->contains_overlapping_glyphs_p
,
14765 row
->truncated_on_left_p
,
14766 row
->truncated_on_right_p
,
14768 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14769 row
->displays_text_p
,
14772 row
->ends_in_middle_of_char_p
,
14773 row
->starts_in_middle_of_char_p
,
14779 row
->visible_height
,
14782 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14783 row
->end
.overlay_string_index
,
14784 row
->continuation_lines_width
);
14785 fprintf (stderr
, "%9d %5d\n",
14786 CHARPOS (row
->start
.string_pos
),
14787 CHARPOS (row
->end
.string_pos
));
14788 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14789 row
->end
.dpvec_index
);
14796 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14798 struct glyph
*glyph
= row
->glyphs
[area
];
14799 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14801 /* Glyph for a line end in text. */
14802 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14805 if (glyph
< glyph_end
)
14806 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14808 for (; glyph
< glyph_end
; ++glyph
)
14809 dump_glyph (row
, glyph
, area
);
14812 else if (glyphs
== 1)
14816 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14818 char *s
= (char *) alloca (row
->used
[area
] + 1);
14821 for (i
= 0; i
< row
->used
[area
]; ++i
)
14823 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14824 if (glyph
->type
== CHAR_GLYPH
14825 && glyph
->u
.ch
< 0x80
14826 && glyph
->u
.ch
>= ' ')
14827 s
[i
] = glyph
->u
.ch
;
14833 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14839 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14840 Sdump_glyph_matrix
, 0, 1, "p",
14841 doc
: /* Dump the current matrix of the selected window to stderr.
14842 Shows contents of glyph row structures. With non-nil
14843 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14844 glyphs in short form, otherwise show glyphs in long form. */)
14846 Lisp_Object glyphs
;
14848 struct window
*w
= XWINDOW (selected_window
);
14849 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14851 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14852 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14853 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14854 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14855 fprintf (stderr
, "=============================================\n");
14856 dump_glyph_matrix (w
->current_matrix
,
14857 NILP (glyphs
) ? 0 : XINT (glyphs
));
14862 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14863 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14866 struct frame
*f
= XFRAME (selected_frame
);
14867 dump_glyph_matrix (f
->current_matrix
, 1);
14872 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14873 doc
: /* Dump glyph row ROW to stderr.
14874 GLYPH 0 means don't dump glyphs.
14875 GLYPH 1 means dump glyphs in short form.
14876 GLYPH > 1 or omitted means dump glyphs in long form. */)
14878 Lisp_Object row
, glyphs
;
14880 struct glyph_matrix
*matrix
;
14883 CHECK_NUMBER (row
);
14884 matrix
= XWINDOW (selected_window
)->current_matrix
;
14886 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14887 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14889 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14894 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14895 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14896 GLYPH 0 means don't dump glyphs.
14897 GLYPH 1 means dump glyphs in short form.
14898 GLYPH > 1 or omitted means dump glyphs in long form. */)
14900 Lisp_Object row
, glyphs
;
14902 struct frame
*sf
= SELECTED_FRAME ();
14903 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14906 CHECK_NUMBER (row
);
14908 if (vpos
>= 0 && vpos
< m
->nrows
)
14909 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14910 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14915 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14916 doc
: /* Toggle tracing of redisplay.
14917 With ARG, turn tracing on if and only if ARG is positive. */)
14922 trace_redisplay_p
= !trace_redisplay_p
;
14925 arg
= Fprefix_numeric_value (arg
);
14926 trace_redisplay_p
= XINT (arg
) > 0;
14933 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14934 doc
: /* Like `format', but print result to stderr.
14935 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14940 Lisp_Object s
= Fformat (nargs
, args
);
14941 fprintf (stderr
, "%s", SDATA (s
));
14945 #endif /* GLYPH_DEBUG */
14949 /***********************************************************************
14950 Building Desired Matrix Rows
14951 ***********************************************************************/
14953 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14954 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14956 static struct glyph_row
*
14957 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14959 Lisp_Object overlay_arrow_string
;
14961 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14962 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14963 struct buffer
*old
= current_buffer
;
14964 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14965 int arrow_len
= SCHARS (overlay_arrow_string
);
14966 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14967 const unsigned char *p
;
14970 int n_glyphs_before
;
14972 set_buffer_temp (buffer
);
14973 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14974 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14975 SET_TEXT_POS (it
.position
, 0, 0);
14977 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14979 while (p
< arrow_end
)
14981 Lisp_Object face
, ilisp
;
14983 /* Get the next character. */
14985 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14987 it
.c
= *p
, it
.len
= 1;
14990 /* Get its face. */
14991 ilisp
= make_number (p
- arrow_string
);
14992 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14993 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14995 /* Compute its width, get its glyphs. */
14996 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14997 SET_TEXT_POS (it
.position
, -1, -1);
14998 PRODUCE_GLYPHS (&it
);
15000 /* If this character doesn't fit any more in the line, we have
15001 to remove some glyphs. */
15002 if (it
.current_x
> it
.last_visible_x
)
15004 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15009 set_buffer_temp (old
);
15010 return it
.glyph_row
;
15014 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15015 glyphs are only inserted for terminal frames since we can't really
15016 win with truncation glyphs when partially visible glyphs are
15017 involved. Which glyphs to insert is determined by
15018 produce_special_glyphs. */
15021 insert_left_trunc_glyphs (it
)
15024 struct it truncate_it
;
15025 struct glyph
*from
, *end
, *to
, *toend
;
15027 xassert (!FRAME_WINDOW_P (it
->f
));
15029 /* Get the truncation glyphs. */
15031 truncate_it
.current_x
= 0;
15032 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15033 truncate_it
.glyph_row
= &scratch_glyph_row
;
15034 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15035 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15036 truncate_it
.object
= make_number (0);
15037 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15039 /* Overwrite glyphs from IT with truncation glyphs. */
15040 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15041 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15042 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15043 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15048 /* There may be padding glyphs left over. Overwrite them too. */
15049 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15051 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15057 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15061 /* Compute the pixel height and width of IT->glyph_row.
15063 Most of the time, ascent and height of a display line will be equal
15064 to the max_ascent and max_height values of the display iterator
15065 structure. This is not the case if
15067 1. We hit ZV without displaying anything. In this case, max_ascent
15068 and max_height will be zero.
15070 2. We have some glyphs that don't contribute to the line height.
15071 (The glyph row flag contributes_to_line_height_p is for future
15072 pixmap extensions).
15074 The first case is easily covered by using default values because in
15075 these cases, the line height does not really matter, except that it
15076 must not be zero. */
15079 compute_line_metrics (it
)
15082 struct glyph_row
*row
= it
->glyph_row
;
15085 if (FRAME_WINDOW_P (it
->f
))
15087 int i
, min_y
, max_y
;
15089 /* The line may consist of one space only, that was added to
15090 place the cursor on it. If so, the row's height hasn't been
15092 if (row
->height
== 0)
15094 if (it
->max_ascent
+ it
->max_descent
== 0)
15095 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15096 row
->ascent
= it
->max_ascent
;
15097 row
->height
= it
->max_ascent
+ it
->max_descent
;
15098 row
->phys_ascent
= it
->max_phys_ascent
;
15099 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15100 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15103 /* Compute the width of this line. */
15104 row
->pixel_width
= row
->x
;
15105 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15106 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15108 xassert (row
->pixel_width
>= 0);
15109 xassert (row
->ascent
>= 0 && row
->height
> 0);
15111 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15112 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15114 /* If first line's physical ascent is larger than its logical
15115 ascent, use the physical ascent, and make the row taller.
15116 This makes accented characters fully visible. */
15117 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15118 && row
->phys_ascent
> row
->ascent
)
15120 row
->height
+= row
->phys_ascent
- row
->ascent
;
15121 row
->ascent
= row
->phys_ascent
;
15124 /* Compute how much of the line is visible. */
15125 row
->visible_height
= row
->height
;
15127 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15128 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15130 if (row
->y
< min_y
)
15131 row
->visible_height
-= min_y
- row
->y
;
15132 if (row
->y
+ row
->height
> max_y
)
15133 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15137 row
->pixel_width
= row
->used
[TEXT_AREA
];
15138 if (row
->continued_p
)
15139 row
->pixel_width
-= it
->continuation_pixel_width
;
15140 else if (row
->truncated_on_right_p
)
15141 row
->pixel_width
-= it
->truncation_pixel_width
;
15142 row
->ascent
= row
->phys_ascent
= 0;
15143 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15144 row
->extra_line_spacing
= 0;
15147 /* Compute a hash code for this row. */
15149 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15150 for (i
= 0; i
< row
->used
[area
]; ++i
)
15151 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15152 + row
->glyphs
[area
][i
].u
.val
15153 + row
->glyphs
[area
][i
].face_id
15154 + row
->glyphs
[area
][i
].padding_p
15155 + (row
->glyphs
[area
][i
].type
<< 2));
15157 it
->max_ascent
= it
->max_descent
= 0;
15158 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15162 /* Append one space to the glyph row of iterator IT if doing a
15163 window-based redisplay. The space has the same face as
15164 IT->face_id. Value is non-zero if a space was added.
15166 This function is called to make sure that there is always one glyph
15167 at the end of a glyph row that the cursor can be set on under
15168 window-systems. (If there weren't such a glyph we would not know
15169 how wide and tall a box cursor should be displayed).
15171 At the same time this space let's a nicely handle clearing to the
15172 end of the line if the row ends in italic text. */
15175 append_space_for_newline (it
, default_face_p
)
15177 int default_face_p
;
15179 if (FRAME_WINDOW_P (it
->f
))
15181 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15183 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15184 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15186 /* Save some values that must not be changed.
15187 Must save IT->c and IT->len because otherwise
15188 ITERATOR_AT_END_P wouldn't work anymore after
15189 append_space_for_newline has been called. */
15190 enum display_element_type saved_what
= it
->what
;
15191 int saved_c
= it
->c
, saved_len
= it
->len
;
15192 int saved_x
= it
->current_x
;
15193 int saved_face_id
= it
->face_id
;
15194 struct text_pos saved_pos
;
15195 Lisp_Object saved_object
;
15198 saved_object
= it
->object
;
15199 saved_pos
= it
->position
;
15201 it
->what
= IT_CHARACTER
;
15202 bzero (&it
->position
, sizeof it
->position
);
15203 it
->object
= make_number (0);
15207 if (default_face_p
)
15208 it
->face_id
= DEFAULT_FACE_ID
;
15209 else if (it
->face_before_selective_p
)
15210 it
->face_id
= it
->saved_face_id
;
15211 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15212 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15214 PRODUCE_GLYPHS (it
);
15216 it
->override_ascent
= -1;
15217 it
->constrain_row_ascent_descent_p
= 0;
15218 it
->current_x
= saved_x
;
15219 it
->object
= saved_object
;
15220 it
->position
= saved_pos
;
15221 it
->what
= saved_what
;
15222 it
->face_id
= saved_face_id
;
15223 it
->len
= saved_len
;
15233 /* Extend the face of the last glyph in the text area of IT->glyph_row
15234 to the end of the display line. Called from display_line.
15235 If the glyph row is empty, add a space glyph to it so that we
15236 know the face to draw. Set the glyph row flag fill_line_p. */
15239 extend_face_to_end_of_line (it
)
15243 struct frame
*f
= it
->f
;
15245 /* If line is already filled, do nothing. */
15246 if (it
->current_x
>= it
->last_visible_x
)
15249 /* Face extension extends the background and box of IT->face_id
15250 to the end of the line. If the background equals the background
15251 of the frame, we don't have to do anything. */
15252 if (it
->face_before_selective_p
)
15253 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15255 face
= FACE_FROM_ID (f
, it
->face_id
);
15257 if (FRAME_WINDOW_P (f
)
15258 && face
->box
== FACE_NO_BOX
15259 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15263 /* Set the glyph row flag indicating that the face of the last glyph
15264 in the text area has to be drawn to the end of the text area. */
15265 it
->glyph_row
->fill_line_p
= 1;
15267 /* If current character of IT is not ASCII, make sure we have the
15268 ASCII face. This will be automatically undone the next time
15269 get_next_display_element returns a multibyte character. Note
15270 that the character will always be single byte in unibyte text. */
15271 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15273 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15276 if (FRAME_WINDOW_P (f
))
15278 /* If the row is empty, add a space with the current face of IT,
15279 so that we know which face to draw. */
15280 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15282 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15283 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15284 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15289 /* Save some values that must not be changed. */
15290 int saved_x
= it
->current_x
;
15291 struct text_pos saved_pos
;
15292 Lisp_Object saved_object
;
15293 enum display_element_type saved_what
= it
->what
;
15294 int saved_face_id
= it
->face_id
;
15296 saved_object
= it
->object
;
15297 saved_pos
= it
->position
;
15299 it
->what
= IT_CHARACTER
;
15300 bzero (&it
->position
, sizeof it
->position
);
15301 it
->object
= make_number (0);
15304 it
->face_id
= face
->id
;
15306 PRODUCE_GLYPHS (it
);
15308 while (it
->current_x
<= it
->last_visible_x
)
15309 PRODUCE_GLYPHS (it
);
15311 /* Don't count these blanks really. It would let us insert a left
15312 truncation glyph below and make us set the cursor on them, maybe. */
15313 it
->current_x
= saved_x
;
15314 it
->object
= saved_object
;
15315 it
->position
= saved_pos
;
15316 it
->what
= saved_what
;
15317 it
->face_id
= saved_face_id
;
15322 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15323 trailing whitespace. */
15326 trailing_whitespace_p (charpos
)
15329 int bytepos
= CHAR_TO_BYTE (charpos
);
15332 while (bytepos
< ZV_BYTE
15333 && (c
= FETCH_CHAR (bytepos
),
15334 c
== ' ' || c
== '\t'))
15337 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15339 if (bytepos
!= PT_BYTE
)
15346 /* Highlight trailing whitespace, if any, in ROW. */
15349 highlight_trailing_whitespace (f
, row
)
15351 struct glyph_row
*row
;
15353 int used
= row
->used
[TEXT_AREA
];
15357 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15358 struct glyph
*glyph
= start
+ used
- 1;
15360 /* Skip over glyphs inserted to display the cursor at the
15361 end of a line, for extending the face of the last glyph
15362 to the end of the line on terminals, and for truncation
15363 and continuation glyphs. */
15364 while (glyph
>= start
15365 && glyph
->type
== CHAR_GLYPH
15366 && INTEGERP (glyph
->object
))
15369 /* If last glyph is a space or stretch, and it's trailing
15370 whitespace, set the face of all trailing whitespace glyphs in
15371 IT->glyph_row to `trailing-whitespace'. */
15373 && BUFFERP (glyph
->object
)
15374 && (glyph
->type
== STRETCH_GLYPH
15375 || (glyph
->type
== CHAR_GLYPH
15376 && glyph
->u
.ch
== ' '))
15377 && trailing_whitespace_p (glyph
->charpos
))
15379 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15383 while (glyph
>= start
15384 && BUFFERP (glyph
->object
)
15385 && (glyph
->type
== STRETCH_GLYPH
15386 || (glyph
->type
== CHAR_GLYPH
15387 && glyph
->u
.ch
== ' ')))
15388 (glyph
--)->face_id
= face_id
;
15394 /* Value is non-zero if glyph row ROW in window W should be
15395 used to hold the cursor. */
15398 cursor_row_p (w
, row
)
15400 struct glyph_row
*row
;
15402 int cursor_row_p
= 1;
15404 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15406 /* If the row ends with a newline from a string, we don't want
15407 the cursor there, but we still want it at the start of the
15408 string if the string starts in this row.
15409 If the row is continued it doesn't end in a newline. */
15410 if (CHARPOS (row
->end
.string_pos
) >= 0)
15411 cursor_row_p
= (row
->continued_p
15412 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15413 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15415 /* If the row ends in middle of a real character,
15416 and the line is continued, we want the cursor here.
15417 That's because MATRIX_ROW_END_CHARPOS would equal
15418 PT if PT is before the character. */
15419 if (!row
->ends_in_ellipsis_p
)
15420 cursor_row_p
= row
->continued_p
;
15422 /* If the row ends in an ellipsis, then
15423 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15424 We want that position to be displayed after the ellipsis. */
15427 /* If the row ends at ZV, display the cursor at the end of that
15428 row instead of at the start of the row below. */
15429 else if (row
->ends_at_zv_p
)
15435 return cursor_row_p
;
15439 /* Construct the glyph row IT->glyph_row in the desired matrix of
15440 IT->w from text at the current position of IT. See dispextern.h
15441 for an overview of struct it. Value is non-zero if
15442 IT->glyph_row displays text, as opposed to a line displaying ZV
15449 struct glyph_row
*row
= it
->glyph_row
;
15450 Lisp_Object overlay_arrow_string
;
15452 /* We always start displaying at hpos zero even if hscrolled. */
15453 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15455 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15456 >= it
->w
->desired_matrix
->nrows
)
15458 it
->w
->nrows_scale_factor
++;
15459 fonts_changed_p
= 1;
15463 /* Is IT->w showing the region? */
15464 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15466 /* Clear the result glyph row and enable it. */
15467 prepare_desired_row (row
);
15469 row
->y
= it
->current_y
;
15470 row
->start
= it
->start
;
15471 row
->continuation_lines_width
= it
->continuation_lines_width
;
15472 row
->displays_text_p
= 1;
15473 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15474 it
->starts_in_middle_of_char_p
= 0;
15476 /* Arrange the overlays nicely for our purposes. Usually, we call
15477 display_line on only one line at a time, in which case this
15478 can't really hurt too much, or we call it on lines which appear
15479 one after another in the buffer, in which case all calls to
15480 recenter_overlay_lists but the first will be pretty cheap. */
15481 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15483 /* Move over display elements that are not visible because we are
15484 hscrolled. This may stop at an x-position < IT->first_visible_x
15485 if the first glyph is partially visible or if we hit a line end. */
15486 if (it
->current_x
< it
->first_visible_x
)
15488 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15489 MOVE_TO_POS
| MOVE_TO_X
);
15492 /* Get the initial row height. This is either the height of the
15493 text hscrolled, if there is any, or zero. */
15494 row
->ascent
= it
->max_ascent
;
15495 row
->height
= it
->max_ascent
+ it
->max_descent
;
15496 row
->phys_ascent
= it
->max_phys_ascent
;
15497 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15498 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15500 /* Loop generating characters. The loop is left with IT on the next
15501 character to display. */
15504 int n_glyphs_before
, hpos_before
, x_before
;
15506 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15508 /* Retrieve the next thing to display. Value is zero if end of
15510 if (!get_next_display_element (it
))
15512 /* Maybe add a space at the end of this line that is used to
15513 display the cursor there under X. Set the charpos of the
15514 first glyph of blank lines not corresponding to any text
15516 #ifdef HAVE_WINDOW_SYSTEM
15517 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15518 row
->exact_window_width_line_p
= 1;
15520 #endif /* HAVE_WINDOW_SYSTEM */
15521 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15522 || row
->used
[TEXT_AREA
] == 0)
15524 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15525 row
->displays_text_p
= 0;
15527 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15528 && (!MINI_WINDOW_P (it
->w
)
15529 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15530 row
->indicate_empty_line_p
= 1;
15533 it
->continuation_lines_width
= 0;
15534 row
->ends_at_zv_p
= 1;
15538 /* Now, get the metrics of what we want to display. This also
15539 generates glyphs in `row' (which is IT->glyph_row). */
15540 n_glyphs_before
= row
->used
[TEXT_AREA
];
15543 /* Remember the line height so far in case the next element doesn't
15544 fit on the line. */
15545 if (!it
->truncate_lines_p
)
15547 ascent
= it
->max_ascent
;
15548 descent
= it
->max_descent
;
15549 phys_ascent
= it
->max_phys_ascent
;
15550 phys_descent
= it
->max_phys_descent
;
15553 PRODUCE_GLYPHS (it
);
15555 /* If this display element was in marginal areas, continue with
15557 if (it
->area
!= TEXT_AREA
)
15559 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15560 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15561 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15562 row
->phys_height
= max (row
->phys_height
,
15563 it
->max_phys_ascent
+ it
->max_phys_descent
);
15564 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15565 it
->max_extra_line_spacing
);
15566 set_iterator_to_next (it
, 1);
15570 /* Does the display element fit on the line? If we truncate
15571 lines, we should draw past the right edge of the window. If
15572 we don't truncate, we want to stop so that we can display the
15573 continuation glyph before the right margin. If lines are
15574 continued, there are two possible strategies for characters
15575 resulting in more than 1 glyph (e.g. tabs): Display as many
15576 glyphs as possible in this line and leave the rest for the
15577 continuation line, or display the whole element in the next
15578 line. Original redisplay did the former, so we do it also. */
15579 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15580 hpos_before
= it
->hpos
;
15583 if (/* Not a newline. */
15585 /* Glyphs produced fit entirely in the line. */
15586 && it
->current_x
< it
->last_visible_x
)
15588 it
->hpos
+= nglyphs
;
15589 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15590 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15591 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15592 row
->phys_height
= max (row
->phys_height
,
15593 it
->max_phys_ascent
+ it
->max_phys_descent
);
15594 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15595 it
->max_extra_line_spacing
);
15596 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15597 row
->x
= x
- it
->first_visible_x
;
15602 struct glyph
*glyph
;
15604 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15606 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15607 new_x
= x
+ glyph
->pixel_width
;
15609 if (/* Lines are continued. */
15610 !it
->truncate_lines_p
15611 && (/* Glyph doesn't fit on the line. */
15612 new_x
> it
->last_visible_x
15613 /* Or it fits exactly on a window system frame. */
15614 || (new_x
== it
->last_visible_x
15615 && FRAME_WINDOW_P (it
->f
))))
15617 /* End of a continued line. */
15620 || (new_x
== it
->last_visible_x
15621 && FRAME_WINDOW_P (it
->f
)))
15623 /* Current glyph is the only one on the line or
15624 fits exactly on the line. We must continue
15625 the line because we can't draw the cursor
15626 after the glyph. */
15627 row
->continued_p
= 1;
15628 it
->current_x
= new_x
;
15629 it
->continuation_lines_width
+= new_x
;
15631 if (i
== nglyphs
- 1)
15633 set_iterator_to_next (it
, 1);
15634 #ifdef HAVE_WINDOW_SYSTEM
15635 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15637 if (!get_next_display_element (it
))
15639 row
->exact_window_width_line_p
= 1;
15640 it
->continuation_lines_width
= 0;
15641 row
->continued_p
= 0;
15642 row
->ends_at_zv_p
= 1;
15644 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15646 row
->continued_p
= 0;
15647 row
->exact_window_width_line_p
= 1;
15650 #endif /* HAVE_WINDOW_SYSTEM */
15653 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15654 && !FRAME_WINDOW_P (it
->f
))
15656 /* A padding glyph that doesn't fit on this line.
15657 This means the whole character doesn't fit
15659 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15661 /* Fill the rest of the row with continuation
15662 glyphs like in 20.x. */
15663 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15664 < row
->glyphs
[1 + TEXT_AREA
])
15665 produce_special_glyphs (it
, IT_CONTINUATION
);
15667 row
->continued_p
= 1;
15668 it
->current_x
= x_before
;
15669 it
->continuation_lines_width
+= x_before
;
15671 /* Restore the height to what it was before the
15672 element not fitting on the line. */
15673 it
->max_ascent
= ascent
;
15674 it
->max_descent
= descent
;
15675 it
->max_phys_ascent
= phys_ascent
;
15676 it
->max_phys_descent
= phys_descent
;
15678 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15680 /* A TAB that extends past the right edge of the
15681 window. This produces a single glyph on
15682 window system frames. We leave the glyph in
15683 this row and let it fill the row, but don't
15684 consume the TAB. */
15685 it
->continuation_lines_width
+= it
->last_visible_x
;
15686 row
->ends_in_middle_of_char_p
= 1;
15687 row
->continued_p
= 1;
15688 glyph
->pixel_width
= it
->last_visible_x
- x
;
15689 it
->starts_in_middle_of_char_p
= 1;
15693 /* Something other than a TAB that draws past
15694 the right edge of the window. Restore
15695 positions to values before the element. */
15696 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15698 /* Display continuation glyphs. */
15699 if (!FRAME_WINDOW_P (it
->f
))
15700 produce_special_glyphs (it
, IT_CONTINUATION
);
15701 row
->continued_p
= 1;
15703 it
->current_x
= x_before
;
15704 it
->continuation_lines_width
+= x
;
15705 extend_face_to_end_of_line (it
);
15707 if (nglyphs
> 1 && i
> 0)
15709 row
->ends_in_middle_of_char_p
= 1;
15710 it
->starts_in_middle_of_char_p
= 1;
15713 /* Restore the height to what it was before the
15714 element not fitting on the line. */
15715 it
->max_ascent
= ascent
;
15716 it
->max_descent
= descent
;
15717 it
->max_phys_ascent
= phys_ascent
;
15718 it
->max_phys_descent
= phys_descent
;
15723 else if (new_x
> it
->first_visible_x
)
15725 /* Increment number of glyphs actually displayed. */
15728 if (x
< it
->first_visible_x
)
15729 /* Glyph is partially visible, i.e. row starts at
15730 negative X position. */
15731 row
->x
= x
- it
->first_visible_x
;
15735 /* Glyph is completely off the left margin of the
15736 window. This should not happen because of the
15737 move_it_in_display_line at the start of this
15738 function, unless the text display area of the
15739 window is empty. */
15740 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15744 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15745 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15746 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15747 row
->phys_height
= max (row
->phys_height
,
15748 it
->max_phys_ascent
+ it
->max_phys_descent
);
15749 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15750 it
->max_extra_line_spacing
);
15752 /* End of this display line if row is continued. */
15753 if (row
->continued_p
|| row
->ends_at_zv_p
)
15758 /* Is this a line end? If yes, we're also done, after making
15759 sure that a non-default face is extended up to the right
15760 margin of the window. */
15761 if (ITERATOR_AT_END_OF_LINE_P (it
))
15763 int used_before
= row
->used
[TEXT_AREA
];
15765 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15767 #ifdef HAVE_WINDOW_SYSTEM
15768 /* Add a space at the end of the line that is used to
15769 display the cursor there. */
15770 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15771 append_space_for_newline (it
, 0);
15772 #endif /* HAVE_WINDOW_SYSTEM */
15774 /* Extend the face to the end of the line. */
15775 extend_face_to_end_of_line (it
);
15777 /* Make sure we have the position. */
15778 if (used_before
== 0)
15779 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15781 /* Consume the line end. This skips over invisible lines. */
15782 set_iterator_to_next (it
, 1);
15783 it
->continuation_lines_width
= 0;
15787 /* Proceed with next display element. Note that this skips
15788 over lines invisible because of selective display. */
15789 set_iterator_to_next (it
, 1);
15791 /* If we truncate lines, we are done when the last displayed
15792 glyphs reach past the right margin of the window. */
15793 if (it
->truncate_lines_p
15794 && (FRAME_WINDOW_P (it
->f
)
15795 ? (it
->current_x
>= it
->last_visible_x
)
15796 : (it
->current_x
> it
->last_visible_x
)))
15798 /* Maybe add truncation glyphs. */
15799 if (!FRAME_WINDOW_P (it
->f
))
15803 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15804 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15807 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15809 row
->used
[TEXT_AREA
] = i
;
15810 produce_special_glyphs (it
, IT_TRUNCATION
);
15813 #ifdef HAVE_WINDOW_SYSTEM
15816 /* Don't truncate if we can overflow newline into fringe. */
15817 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15819 if (!get_next_display_element (it
))
15821 it
->continuation_lines_width
= 0;
15822 row
->ends_at_zv_p
= 1;
15823 row
->exact_window_width_line_p
= 1;
15826 if (ITERATOR_AT_END_OF_LINE_P (it
))
15828 row
->exact_window_width_line_p
= 1;
15829 goto at_end_of_line
;
15833 #endif /* HAVE_WINDOW_SYSTEM */
15835 row
->truncated_on_right_p
= 1;
15836 it
->continuation_lines_width
= 0;
15837 reseat_at_next_visible_line_start (it
, 0);
15838 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15839 it
->hpos
= hpos_before
;
15840 it
->current_x
= x_before
;
15845 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15846 at the left window margin. */
15847 if (it
->first_visible_x
15848 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15850 if (!FRAME_WINDOW_P (it
->f
))
15851 insert_left_trunc_glyphs (it
);
15852 row
->truncated_on_left_p
= 1;
15855 /* If the start of this line is the overlay arrow-position, then
15856 mark this glyph row as the one containing the overlay arrow.
15857 This is clearly a mess with variable size fonts. It would be
15858 better to let it be displayed like cursors under X. */
15859 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
15860 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
15861 !NILP (overlay_arrow_string
)))
15863 /* Overlay arrow in window redisplay is a fringe bitmap. */
15864 if (STRINGP (overlay_arrow_string
))
15866 struct glyph_row
*arrow_row
15867 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15868 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15869 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15870 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15871 struct glyph
*p2
, *end
;
15873 /* Copy the arrow glyphs. */
15874 while (glyph
< arrow_end
)
15877 /* Throw away padding glyphs. */
15879 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15880 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15886 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15891 xassert (INTEGERP (overlay_arrow_string
));
15892 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
15894 overlay_arrow_seen
= 1;
15897 /* Compute pixel dimensions of this line. */
15898 compute_line_metrics (it
);
15900 /* Remember the position at which this line ends. */
15901 row
->end
= it
->current
;
15903 /* Record whether this row ends inside an ellipsis. */
15904 row
->ends_in_ellipsis_p
15905 = (it
->method
== GET_FROM_DISPLAY_VECTOR
15906 && it
->ellipsis_p
);
15908 /* Save fringe bitmaps in this row. */
15909 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15910 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15911 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15912 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15914 it
->left_user_fringe_bitmap
= 0;
15915 it
->left_user_fringe_face_id
= 0;
15916 it
->right_user_fringe_bitmap
= 0;
15917 it
->right_user_fringe_face_id
= 0;
15919 /* Maybe set the cursor. */
15920 if (it
->w
->cursor
.vpos
< 0
15921 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15922 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15923 && cursor_row_p (it
->w
, row
))
15924 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15926 /* Highlight trailing whitespace. */
15927 if (!NILP (Vshow_trailing_whitespace
))
15928 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15930 /* Prepare for the next line. This line starts horizontally at (X
15931 HPOS) = (0 0). Vertical positions are incremented. As a
15932 convenience for the caller, IT->glyph_row is set to the next
15934 it
->current_x
= it
->hpos
= 0;
15935 it
->current_y
+= row
->height
;
15938 it
->start
= it
->current
;
15939 return row
->displays_text_p
;
15944 /***********************************************************************
15946 ***********************************************************************/
15948 /* Redisplay the menu bar in the frame for window W.
15950 The menu bar of X frames that don't have X toolkit support is
15951 displayed in a special window W->frame->menu_bar_window.
15953 The menu bar of terminal frames is treated specially as far as
15954 glyph matrices are concerned. Menu bar lines are not part of
15955 windows, so the update is done directly on the frame matrix rows
15956 for the menu bar. */
15959 display_menu_bar (w
)
15962 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15967 /* Don't do all this for graphical frames. */
15969 if (!NILP (Vwindow_system
))
15972 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15977 if (FRAME_MAC_P (f
))
15981 #ifdef USE_X_TOOLKIT
15982 xassert (!FRAME_WINDOW_P (f
));
15983 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15984 it
.first_visible_x
= 0;
15985 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15986 #else /* not USE_X_TOOLKIT */
15987 if (FRAME_WINDOW_P (f
))
15989 /* Menu bar lines are displayed in the desired matrix of the
15990 dummy window menu_bar_window. */
15991 struct window
*menu_w
;
15992 xassert (WINDOWP (f
->menu_bar_window
));
15993 menu_w
= XWINDOW (f
->menu_bar_window
);
15994 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15996 it
.first_visible_x
= 0;
15997 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16001 /* This is a TTY frame, i.e. character hpos/vpos are used as
16003 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16005 it
.first_visible_x
= 0;
16006 it
.last_visible_x
= FRAME_COLS (f
);
16008 #endif /* not USE_X_TOOLKIT */
16010 if (! mode_line_inverse_video
)
16011 /* Force the menu-bar to be displayed in the default face. */
16012 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16014 /* Clear all rows of the menu bar. */
16015 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16017 struct glyph_row
*row
= it
.glyph_row
+ i
;
16018 clear_glyph_row (row
);
16019 row
->enabled_p
= 1;
16020 row
->full_width_p
= 1;
16023 /* Display all items of the menu bar. */
16024 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16025 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16027 Lisp_Object string
;
16029 /* Stop at nil string. */
16030 string
= AREF (items
, i
+ 1);
16034 /* Remember where item was displayed. */
16035 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16037 /* Display the item, pad with one space. */
16038 if (it
.current_x
< it
.last_visible_x
)
16039 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16040 SCHARS (string
) + 1, 0, 0, -1);
16043 /* Fill out the line with spaces. */
16044 if (it
.current_x
< it
.last_visible_x
)
16045 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16047 /* Compute the total height of the lines. */
16048 compute_line_metrics (&it
);
16053 /***********************************************************************
16055 ***********************************************************************/
16057 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16058 FORCE is non-zero, redisplay mode lines unconditionally.
16059 Otherwise, redisplay only mode lines that are garbaged. Value is
16060 the number of windows whose mode lines were redisplayed. */
16063 redisplay_mode_lines (window
, force
)
16064 Lisp_Object window
;
16069 while (!NILP (window
))
16071 struct window
*w
= XWINDOW (window
);
16073 if (WINDOWP (w
->hchild
))
16074 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16075 else if (WINDOWP (w
->vchild
))
16076 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16078 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16079 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16081 struct text_pos lpoint
;
16082 struct buffer
*old
= current_buffer
;
16084 /* Set the window's buffer for the mode line display. */
16085 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16086 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16088 /* Point refers normally to the selected window. For any
16089 other window, set up appropriate value. */
16090 if (!EQ (window
, selected_window
))
16092 struct text_pos pt
;
16094 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16095 if (CHARPOS (pt
) < BEGV
)
16096 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16097 else if (CHARPOS (pt
) > (ZV
- 1))
16098 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16100 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16103 /* Display mode lines. */
16104 clear_glyph_matrix (w
->desired_matrix
);
16105 if (display_mode_lines (w
))
16108 w
->must_be_updated_p
= 1;
16111 /* Restore old settings. */
16112 set_buffer_internal_1 (old
);
16113 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16123 /* Display the mode and/or top line of window W. Value is the number
16124 of mode lines displayed. */
16127 display_mode_lines (w
)
16130 Lisp_Object old_selected_window
, old_selected_frame
;
16133 old_selected_frame
= selected_frame
;
16134 selected_frame
= w
->frame
;
16135 old_selected_window
= selected_window
;
16136 XSETWINDOW (selected_window
, w
);
16138 /* These will be set while the mode line specs are processed. */
16139 line_number_displayed
= 0;
16140 w
->column_number_displayed
= Qnil
;
16142 if (WINDOW_WANTS_MODELINE_P (w
))
16144 struct window
*sel_w
= XWINDOW (old_selected_window
);
16146 /* Select mode line face based on the real selected window. */
16147 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16148 current_buffer
->mode_line_format
);
16152 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16154 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16155 current_buffer
->header_line_format
);
16159 selected_frame
= old_selected_frame
;
16160 selected_window
= old_selected_window
;
16165 /* Display mode or top line of window W. FACE_ID specifies which line
16166 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16167 FORMAT is the mode line format to display. Value is the pixel
16168 height of the mode line displayed. */
16171 display_mode_line (w
, face_id
, format
)
16173 enum face_id face_id
;
16174 Lisp_Object format
;
16178 int count
= SPECPDL_INDEX ();
16180 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16181 prepare_desired_row (it
.glyph_row
);
16183 it
.glyph_row
->mode_line_p
= 1;
16185 if (! mode_line_inverse_video
)
16186 /* Force the mode-line to be displayed in the default face. */
16187 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16189 record_unwind_protect (unwind_format_mode_line
,
16190 format_mode_line_unwind_data (NULL
, 0));
16192 mode_line_target
= MODE_LINE_DISPLAY
;
16194 /* Temporarily make frame's keyboard the current kboard so that
16195 kboard-local variables in the mode_line_format will get the right
16197 push_kboard (FRAME_KBOARD (it
.f
));
16198 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16201 unbind_to (count
, Qnil
);
16203 /* Fill up with spaces. */
16204 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16206 compute_line_metrics (&it
);
16207 it
.glyph_row
->full_width_p
= 1;
16208 it
.glyph_row
->continued_p
= 0;
16209 it
.glyph_row
->truncated_on_left_p
= 0;
16210 it
.glyph_row
->truncated_on_right_p
= 0;
16212 /* Make a 3D mode-line have a shadow at its right end. */
16213 face
= FACE_FROM_ID (it
.f
, face_id
);
16214 extend_face_to_end_of_line (&it
);
16215 if (face
->box
!= FACE_NO_BOX
)
16217 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16218 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16219 last
->right_box_line_p
= 1;
16222 return it
.glyph_row
->height
;
16225 /* Move element ELT in LIST to the front of LIST.
16226 Return the updated list. */
16229 move_elt_to_front (elt
, list
)
16230 Lisp_Object elt
, list
;
16232 register Lisp_Object tail
, prev
;
16233 register Lisp_Object tem
;
16237 while (CONSP (tail
))
16243 /* Splice out the link TAIL. */
16245 list
= XCDR (tail
);
16247 Fsetcdr (prev
, XCDR (tail
));
16249 /* Now make it the first. */
16250 Fsetcdr (tail
, list
);
16255 tail
= XCDR (tail
);
16259 /* Not found--return unchanged LIST. */
16263 /* Contribute ELT to the mode line for window IT->w. How it
16264 translates into text depends on its data type.
16266 IT describes the display environment in which we display, as usual.
16268 DEPTH is the depth in recursion. It is used to prevent
16269 infinite recursion here.
16271 FIELD_WIDTH is the number of characters the display of ELT should
16272 occupy in the mode line, and PRECISION is the maximum number of
16273 characters to display from ELT's representation. See
16274 display_string for details.
16276 Returns the hpos of the end of the text generated by ELT.
16278 PROPS is a property list to add to any string we encounter.
16280 If RISKY is nonzero, remove (disregard) any properties in any string
16281 we encounter, and ignore :eval and :propertize.
16283 The global variable `mode_line_target' determines whether the
16284 output is passed to `store_mode_line_noprop',
16285 `store_mode_line_string', or `display_string'. */
16288 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16291 int field_width
, precision
;
16292 Lisp_Object elt
, props
;
16295 int n
= 0, field
, prec
;
16300 elt
= build_string ("*too-deep*");
16304 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16308 /* A string: output it and check for %-constructs within it. */
16312 if (SCHARS (elt
) > 0
16313 && (!NILP (props
) || risky
))
16315 Lisp_Object oprops
, aelt
;
16316 oprops
= Ftext_properties_at (make_number (0), elt
);
16318 /* If the starting string's properties are not what
16319 we want, translate the string. Also, if the string
16320 is risky, do that anyway. */
16322 if (NILP (Fequal (props
, oprops
)) || risky
)
16324 /* If the starting string has properties,
16325 merge the specified ones onto the existing ones. */
16326 if (! NILP (oprops
) && !risky
)
16330 oprops
= Fcopy_sequence (oprops
);
16332 while (CONSP (tem
))
16334 oprops
= Fplist_put (oprops
, XCAR (tem
),
16335 XCAR (XCDR (tem
)));
16336 tem
= XCDR (XCDR (tem
));
16341 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16342 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16344 /* AELT is what we want. Move it to the front
16345 without consing. */
16347 mode_line_proptrans_alist
16348 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16354 /* If AELT has the wrong props, it is useless.
16355 so get rid of it. */
16357 mode_line_proptrans_alist
16358 = Fdelq (aelt
, mode_line_proptrans_alist
);
16360 elt
= Fcopy_sequence (elt
);
16361 Fset_text_properties (make_number (0), Flength (elt
),
16363 /* Add this item to mode_line_proptrans_alist. */
16364 mode_line_proptrans_alist
16365 = Fcons (Fcons (elt
, props
),
16366 mode_line_proptrans_alist
);
16367 /* Truncate mode_line_proptrans_alist
16368 to at most 50 elements. */
16369 tem
= Fnthcdr (make_number (50),
16370 mode_line_proptrans_alist
);
16372 XSETCDR (tem
, Qnil
);
16381 prec
= precision
- n
;
16382 switch (mode_line_target
)
16384 case MODE_LINE_NOPROP
:
16385 case MODE_LINE_TITLE
:
16386 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16388 case MODE_LINE_STRING
:
16389 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16391 case MODE_LINE_DISPLAY
:
16392 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16393 0, prec
, 0, STRING_MULTIBYTE (elt
));
16400 /* Handle the non-literal case. */
16402 while ((precision
<= 0 || n
< precision
)
16403 && SREF (elt
, offset
) != 0
16404 && (mode_line_target
!= MODE_LINE_DISPLAY
16405 || it
->current_x
< it
->last_visible_x
))
16407 int last_offset
= offset
;
16409 /* Advance to end of string or next format specifier. */
16410 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16413 if (offset
- 1 != last_offset
)
16415 int nchars
, nbytes
;
16417 /* Output to end of string or up to '%'. Field width
16418 is length of string. Don't output more than
16419 PRECISION allows us. */
16422 prec
= c_string_width (SDATA (elt
) + last_offset
,
16423 offset
- last_offset
, precision
- n
,
16426 switch (mode_line_target
)
16428 case MODE_LINE_NOPROP
:
16429 case MODE_LINE_TITLE
:
16430 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16432 case MODE_LINE_STRING
:
16434 int bytepos
= last_offset
;
16435 int charpos
= string_byte_to_char (elt
, bytepos
);
16436 int endpos
= (precision
<= 0
16437 ? string_byte_to_char (elt
, offset
)
16438 : charpos
+ nchars
);
16440 n
+= store_mode_line_string (NULL
,
16441 Fsubstring (elt
, make_number (charpos
),
16442 make_number (endpos
)),
16446 case MODE_LINE_DISPLAY
:
16448 int bytepos
= last_offset
;
16449 int charpos
= string_byte_to_char (elt
, bytepos
);
16450 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16452 STRING_MULTIBYTE (elt
));
16457 else /* c == '%' */
16459 int percent_position
= offset
;
16461 /* Get the specified minimum width. Zero means
16464 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16465 field
= field
* 10 + c
- '0';
16467 /* Don't pad beyond the total padding allowed. */
16468 if (field_width
- n
> 0 && field
> field_width
- n
)
16469 field
= field_width
- n
;
16471 /* Note that either PRECISION <= 0 or N < PRECISION. */
16472 prec
= precision
- n
;
16475 n
+= display_mode_element (it
, depth
, field
, prec
,
16476 Vglobal_mode_string
, props
,
16481 int bytepos
, charpos
;
16482 unsigned char *spec
;
16484 bytepos
= percent_position
;
16485 charpos
= (STRING_MULTIBYTE (elt
)
16486 ? string_byte_to_char (elt
, bytepos
)
16490 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16492 switch (mode_line_target
)
16494 case MODE_LINE_NOPROP
:
16495 case MODE_LINE_TITLE
:
16496 n
+= store_mode_line_noprop (spec
, field
, prec
);
16498 case MODE_LINE_STRING
:
16500 int len
= strlen (spec
);
16501 Lisp_Object tem
= make_string (spec
, len
);
16502 props
= Ftext_properties_at (make_number (charpos
), elt
);
16503 /* Should only keep face property in props */
16504 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16507 case MODE_LINE_DISPLAY
:
16509 int nglyphs_before
, nwritten
;
16511 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16512 nwritten
= display_string (spec
, Qnil
, elt
,
16517 /* Assign to the glyphs written above the
16518 string where the `%x' came from, position
16522 struct glyph
*glyph
16523 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16527 for (i
= 0; i
< nwritten
; ++i
)
16529 glyph
[i
].object
= elt
;
16530 glyph
[i
].charpos
= charpos
;
16547 /* A symbol: process the value of the symbol recursively
16548 as if it appeared here directly. Avoid error if symbol void.
16549 Special case: if value of symbol is a string, output the string
16552 register Lisp_Object tem
;
16554 /* If the variable is not marked as risky to set
16555 then its contents are risky to use. */
16556 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16559 tem
= Fboundp (elt
);
16562 tem
= Fsymbol_value (elt
);
16563 /* If value is a string, output that string literally:
16564 don't check for % within it. */
16568 if (!EQ (tem
, elt
))
16570 /* Give up right away for nil or t. */
16580 register Lisp_Object car
, tem
;
16582 /* A cons cell: five distinct cases.
16583 If first element is :eval or :propertize, do something special.
16584 If first element is a string or a cons, process all the elements
16585 and effectively concatenate them.
16586 If first element is a negative number, truncate displaying cdr to
16587 at most that many characters. If positive, pad (with spaces)
16588 to at least that many characters.
16589 If first element is a symbol, process the cadr or caddr recursively
16590 according to whether the symbol's value is non-nil or nil. */
16592 if (EQ (car
, QCeval
))
16594 /* An element of the form (:eval FORM) means evaluate FORM
16595 and use the result as mode line elements. */
16600 if (CONSP (XCDR (elt
)))
16603 spec
= safe_eval (XCAR (XCDR (elt
)));
16604 n
+= display_mode_element (it
, depth
, field_width
- n
,
16605 precision
- n
, spec
, props
,
16609 else if (EQ (car
, QCpropertize
))
16611 /* An element of the form (:propertize ELT PROPS...)
16612 means display ELT but applying properties PROPS. */
16617 if (CONSP (XCDR (elt
)))
16618 n
+= display_mode_element (it
, depth
, field_width
- n
,
16619 precision
- n
, XCAR (XCDR (elt
)),
16620 XCDR (XCDR (elt
)), risky
);
16622 else if (SYMBOLP (car
))
16624 tem
= Fboundp (car
);
16628 /* elt is now the cdr, and we know it is a cons cell.
16629 Use its car if CAR has a non-nil value. */
16632 tem
= Fsymbol_value (car
);
16639 /* Symbol's value is nil (or symbol is unbound)
16640 Get the cddr of the original list
16641 and if possible find the caddr and use that. */
16645 else if (!CONSP (elt
))
16650 else if (INTEGERP (car
))
16652 register int lim
= XINT (car
);
16656 /* Negative int means reduce maximum width. */
16657 if (precision
<= 0)
16660 precision
= min (precision
, -lim
);
16664 /* Padding specified. Don't let it be more than
16665 current maximum. */
16667 lim
= min (precision
, lim
);
16669 /* If that's more padding than already wanted, queue it.
16670 But don't reduce padding already specified even if
16671 that is beyond the current truncation point. */
16672 field_width
= max (lim
, field_width
);
16676 else if (STRINGP (car
) || CONSP (car
))
16678 register int limit
= 50;
16679 /* Limit is to protect against circular lists. */
16682 && (precision
<= 0 || n
< precision
))
16684 n
+= display_mode_element (it
, depth
,
16685 /* Do padding only after the last
16686 element in the list. */
16687 (! CONSP (XCDR (elt
))
16690 precision
- n
, XCAR (elt
),
16700 elt
= build_string ("*invalid*");
16704 /* Pad to FIELD_WIDTH. */
16705 if (field_width
> 0 && n
< field_width
)
16707 switch (mode_line_target
)
16709 case MODE_LINE_NOPROP
:
16710 case MODE_LINE_TITLE
:
16711 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16713 case MODE_LINE_STRING
:
16714 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16716 case MODE_LINE_DISPLAY
:
16717 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16726 /* Store a mode-line string element in mode_line_string_list.
16728 If STRING is non-null, display that C string. Otherwise, the Lisp
16729 string LISP_STRING is displayed.
16731 FIELD_WIDTH is the minimum number of output glyphs to produce.
16732 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16733 with spaces. FIELD_WIDTH <= 0 means don't pad.
16735 PRECISION is the maximum number of characters to output from
16736 STRING. PRECISION <= 0 means don't truncate the string.
16738 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16739 properties to the string.
16741 PROPS are the properties to add to the string.
16742 The mode_line_string_face face property is always added to the string.
16746 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16748 Lisp_Object lisp_string
;
16757 if (string
!= NULL
)
16759 len
= strlen (string
);
16760 if (precision
> 0 && len
> precision
)
16762 lisp_string
= make_string (string
, len
);
16764 props
= mode_line_string_face_prop
;
16765 else if (!NILP (mode_line_string_face
))
16767 Lisp_Object face
= Fplist_get (props
, Qface
);
16768 props
= Fcopy_sequence (props
);
16770 face
= mode_line_string_face
;
16772 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16773 props
= Fplist_put (props
, Qface
, face
);
16775 Fadd_text_properties (make_number (0), make_number (len
),
16776 props
, lisp_string
);
16780 len
= XFASTINT (Flength (lisp_string
));
16781 if (precision
> 0 && len
> precision
)
16784 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16787 if (!NILP (mode_line_string_face
))
16791 props
= Ftext_properties_at (make_number (0), lisp_string
);
16792 face
= Fplist_get (props
, Qface
);
16794 face
= mode_line_string_face
;
16796 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16797 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16799 lisp_string
= Fcopy_sequence (lisp_string
);
16802 Fadd_text_properties (make_number (0), make_number (len
),
16803 props
, lisp_string
);
16808 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16812 if (field_width
> len
)
16814 field_width
-= len
;
16815 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16817 Fadd_text_properties (make_number (0), make_number (field_width
),
16818 props
, lisp_string
);
16819 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16827 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16829 doc
: /* Format a string out of a mode line format specification.
16830 First arg FORMAT specifies the mode line format (see `mode-line-format'
16831 for details) to use.
16833 Optional second arg FACE specifies the face property to put
16834 on all characters for which no face is specified.
16835 t means whatever face the window's mode line currently uses
16836 \(either `mode-line' or `mode-line-inactive', depending).
16837 nil means the default is no face property.
16838 If FACE is an integer, the value string has no text properties.
16840 Optional third and fourth args WINDOW and BUFFER specify the window
16841 and buffer to use as the context for the formatting (defaults
16842 are the selected window and the window's buffer). */)
16843 (format
, face
, window
, buffer
)
16844 Lisp_Object format
, face
, window
, buffer
;
16849 struct buffer
*old_buffer
= NULL
;
16851 int no_props
= INTEGERP (face
);
16852 int count
= SPECPDL_INDEX ();
16854 int string_start
= 0;
16857 window
= selected_window
;
16858 CHECK_WINDOW (window
);
16859 w
= XWINDOW (window
);
16862 buffer
= w
->buffer
;
16863 CHECK_BUFFER (buffer
);
16866 return build_string ("");
16874 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16875 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16879 face_id
= DEFAULT_FACE_ID
;
16881 if (XBUFFER (buffer
) != current_buffer
)
16882 old_buffer
= current_buffer
;
16884 /* Save things including mode_line_proptrans_alist,
16885 and set that to nil so that we don't alter the outer value. */
16886 record_unwind_protect (unwind_format_mode_line
,
16887 format_mode_line_unwind_data (old_buffer
, 1));
16888 mode_line_proptrans_alist
= Qnil
;
16891 set_buffer_internal_1 (XBUFFER (buffer
));
16893 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16897 mode_line_target
= MODE_LINE_NOPROP
;
16898 mode_line_string_face_prop
= Qnil
;
16899 mode_line_string_list
= Qnil
;
16900 string_start
= MODE_LINE_NOPROP_LEN (0);
16904 mode_line_target
= MODE_LINE_STRING
;
16905 mode_line_string_list
= Qnil
;
16906 mode_line_string_face
= face
;
16907 mode_line_string_face_prop
16908 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16911 push_kboard (FRAME_KBOARD (it
.f
));
16912 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16917 len
= MODE_LINE_NOPROP_LEN (string_start
);
16918 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
16922 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16923 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
16924 make_string ("", 0));
16927 unbind_to (count
, Qnil
);
16931 /* Write a null-terminated, right justified decimal representation of
16932 the positive integer D to BUF using a minimal field width WIDTH. */
16935 pint2str (buf
, width
, d
)
16936 register char *buf
;
16937 register int width
;
16940 register char *p
= buf
;
16948 *p
++ = d
% 10 + '0';
16953 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16964 /* Write a null-terminated, right justified decimal and "human
16965 readable" representation of the nonnegative integer D to BUF using
16966 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16968 static const char power_letter
[] =
16982 pint2hrstr (buf
, width
, d
)
16987 /* We aim to represent the nonnegative integer D as
16988 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16991 /* -1 means: do not use TENTHS. */
16995 /* Length of QUOTIENT.TENTHS as a string. */
17001 if (1000 <= quotient
)
17003 /* Scale to the appropriate EXPONENT. */
17006 remainder
= quotient
% 1000;
17010 while (1000 <= quotient
);
17012 /* Round to nearest and decide whether to use TENTHS or not. */
17015 tenths
= remainder
/ 100;
17016 if (50 <= remainder
% 100)
17023 if (quotient
== 10)
17031 if (500 <= remainder
)
17033 if (quotient
< 999)
17044 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17045 if (tenths
== -1 && quotient
<= 99)
17052 p
= psuffix
= buf
+ max (width
, length
);
17054 /* Print EXPONENT. */
17056 *psuffix
++ = power_letter
[exponent
];
17059 /* Print TENTHS. */
17062 *--p
= '0' + tenths
;
17066 /* Print QUOTIENT. */
17069 int digit
= quotient
% 10;
17070 *--p
= '0' + digit
;
17072 while ((quotient
/= 10) != 0);
17074 /* Print leading spaces. */
17079 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17080 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17081 type of CODING_SYSTEM. Return updated pointer into BUF. */
17083 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17086 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17087 Lisp_Object coding_system
;
17088 register char *buf
;
17092 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17093 const unsigned char *eol_str
;
17095 /* The EOL conversion we are using. */
17096 Lisp_Object eoltype
;
17098 val
= Fget (coding_system
, Qcoding_system
);
17101 if (!VECTORP (val
)) /* Not yet decided. */
17106 eoltype
= eol_mnemonic_undecided
;
17107 /* Don't mention EOL conversion if it isn't decided. */
17111 Lisp_Object eolvalue
;
17113 eolvalue
= Fget (coding_system
, Qeol_type
);
17116 *buf
++ = XFASTINT (AREF (val
, 1));
17120 /* The EOL conversion that is normal on this system. */
17122 if (NILP (eolvalue
)) /* Not yet decided. */
17123 eoltype
= eol_mnemonic_undecided
;
17124 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17125 eoltype
= eol_mnemonic_undecided
;
17126 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17127 eoltype
= (XFASTINT (eolvalue
) == 0
17128 ? eol_mnemonic_unix
17129 : (XFASTINT (eolvalue
) == 1
17130 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17136 /* Mention the EOL conversion if it is not the usual one. */
17137 if (STRINGP (eoltype
))
17139 eol_str
= SDATA (eoltype
);
17140 eol_str_len
= SBYTES (eoltype
);
17142 else if (INTEGERP (eoltype
)
17143 && CHAR_VALID_P (XINT (eoltype
), 0))
17145 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17146 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17151 eol_str
= invalid_eol_type
;
17152 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17154 bcopy (eol_str
, buf
, eol_str_len
);
17155 buf
+= eol_str_len
;
17161 /* Return a string for the output of a mode line %-spec for window W,
17162 generated by character C. PRECISION >= 0 means don't return a
17163 string longer than that value. FIELD_WIDTH > 0 means pad the
17164 string returned with spaces to that value. Return 1 in *MULTIBYTE
17165 if the result is multibyte text.
17167 Note we operate on the current buffer for most purposes,
17168 the exception being w->base_line_pos. */
17170 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17173 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17176 int field_width
, precision
;
17180 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17181 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17182 struct buffer
*b
= current_buffer
;
17190 if (!NILP (b
->read_only
))
17192 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17197 /* This differs from %* only for a modified read-only buffer. */
17198 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17200 if (!NILP (b
->read_only
))
17205 /* This differs from %* in ignoring read-only-ness. */
17206 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17218 if (command_loop_level
> 5)
17220 p
= decode_mode_spec_buf
;
17221 for (i
= 0; i
< command_loop_level
; i
++)
17224 return decode_mode_spec_buf
;
17232 if (command_loop_level
> 5)
17234 p
= decode_mode_spec_buf
;
17235 for (i
= 0; i
< command_loop_level
; i
++)
17238 return decode_mode_spec_buf
;
17245 /* Let lots_of_dashes be a string of infinite length. */
17246 if (mode_line_target
== MODE_LINE_NOPROP
||
17247 mode_line_target
== MODE_LINE_STRING
)
17249 if (field_width
<= 0
17250 || field_width
> sizeof (lots_of_dashes
))
17252 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17253 decode_mode_spec_buf
[i
] = '-';
17254 decode_mode_spec_buf
[i
] = '\0';
17255 return decode_mode_spec_buf
;
17258 return lots_of_dashes
;
17267 int col
= (int) current_column (); /* iftc */
17268 w
->column_number_displayed
= make_number (col
);
17269 pint2str (decode_mode_spec_buf
, field_width
, col
);
17270 return decode_mode_spec_buf
;
17274 #ifndef SYSTEM_MALLOC
17276 if (NILP (Vmemory_full
))
17279 return "!MEM FULL! ";
17286 /* %F displays the frame name. */
17287 if (!NILP (f
->title
))
17288 return (char *) SDATA (f
->title
);
17289 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17290 return (char *) SDATA (f
->name
);
17299 int size
= ZV
- BEGV
;
17300 pint2str (decode_mode_spec_buf
, field_width
, size
);
17301 return decode_mode_spec_buf
;
17306 int size
= ZV
- BEGV
;
17307 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17308 return decode_mode_spec_buf
;
17313 int startpos
= XMARKER (w
->start
)->charpos
;
17314 int startpos_byte
= marker_byte_position (w
->start
);
17315 int line
, linepos
, linepos_byte
, topline
;
17317 int height
= WINDOW_TOTAL_LINES (w
);
17319 /* If we decided that this buffer isn't suitable for line numbers,
17320 don't forget that too fast. */
17321 if (EQ (w
->base_line_pos
, w
->buffer
))
17323 /* But do forget it, if the window shows a different buffer now. */
17324 else if (BUFFERP (w
->base_line_pos
))
17325 w
->base_line_pos
= Qnil
;
17327 /* If the buffer is very big, don't waste time. */
17328 if (INTEGERP (Vline_number_display_limit
)
17329 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17331 w
->base_line_pos
= Qnil
;
17332 w
->base_line_number
= Qnil
;
17336 if (!NILP (w
->base_line_number
)
17337 && !NILP (w
->base_line_pos
)
17338 && XFASTINT (w
->base_line_pos
) <= startpos
)
17340 line
= XFASTINT (w
->base_line_number
);
17341 linepos
= XFASTINT (w
->base_line_pos
);
17342 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17347 linepos
= BUF_BEGV (b
);
17348 linepos_byte
= BUF_BEGV_BYTE (b
);
17351 /* Count lines from base line to window start position. */
17352 nlines
= display_count_lines (linepos
, linepos_byte
,
17356 topline
= nlines
+ line
;
17358 /* Determine a new base line, if the old one is too close
17359 or too far away, or if we did not have one.
17360 "Too close" means it's plausible a scroll-down would
17361 go back past it. */
17362 if (startpos
== BUF_BEGV (b
))
17364 w
->base_line_number
= make_number (topline
);
17365 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17367 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17368 || linepos
== BUF_BEGV (b
))
17370 int limit
= BUF_BEGV (b
);
17371 int limit_byte
= BUF_BEGV_BYTE (b
);
17373 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17375 if (startpos
- distance
> limit
)
17377 limit
= startpos
- distance
;
17378 limit_byte
= CHAR_TO_BYTE (limit
);
17381 nlines
= display_count_lines (startpos
, startpos_byte
,
17383 - (height
* 2 + 30),
17385 /* If we couldn't find the lines we wanted within
17386 line_number_display_limit_width chars per line,
17387 give up on line numbers for this window. */
17388 if (position
== limit_byte
&& limit
== startpos
- distance
)
17390 w
->base_line_pos
= w
->buffer
;
17391 w
->base_line_number
= Qnil
;
17395 w
->base_line_number
= make_number (topline
- nlines
);
17396 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17399 /* Now count lines from the start pos to point. */
17400 nlines
= display_count_lines (startpos
, startpos_byte
,
17401 PT_BYTE
, PT
, &junk
);
17403 /* Record that we did display the line number. */
17404 line_number_displayed
= 1;
17406 /* Make the string to show. */
17407 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17408 return decode_mode_spec_buf
;
17411 char* p
= decode_mode_spec_buf
;
17412 int pad
= field_width
- 2;
17418 return decode_mode_spec_buf
;
17424 obj
= b
->mode_name
;
17428 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17434 int pos
= marker_position (w
->start
);
17435 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17437 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17439 if (pos
<= BUF_BEGV (b
))
17444 else if (pos
<= BUF_BEGV (b
))
17448 if (total
> 1000000)
17449 /* Do it differently for a large value, to avoid overflow. */
17450 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17452 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17453 /* We can't normally display a 3-digit number,
17454 so get us a 2-digit number that is close. */
17457 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17458 return decode_mode_spec_buf
;
17462 /* Display percentage of size above the bottom of the screen. */
17465 int toppos
= marker_position (w
->start
);
17466 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17467 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17469 if (botpos
>= BUF_ZV (b
))
17471 if (toppos
<= BUF_BEGV (b
))
17478 if (total
> 1000000)
17479 /* Do it differently for a large value, to avoid overflow. */
17480 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17482 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17483 /* We can't normally display a 3-digit number,
17484 so get us a 2-digit number that is close. */
17487 if (toppos
<= BUF_BEGV (b
))
17488 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17490 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17491 return decode_mode_spec_buf
;
17496 /* status of process */
17497 obj
= Fget_buffer_process (Fcurrent_buffer ());
17499 return "no process";
17500 #ifdef subprocesses
17501 obj
= Fsymbol_name (Fprocess_status (obj
));
17505 case 't': /* indicate TEXT or BINARY */
17506 #ifdef MODE_LINE_BINARY_TEXT
17507 return MODE_LINE_BINARY_TEXT (b
);
17513 /* coding-system (not including end-of-line format) */
17515 /* coding-system (including end-of-line type) */
17517 int eol_flag
= (c
== 'Z');
17518 char *p
= decode_mode_spec_buf
;
17520 if (! FRAME_WINDOW_P (f
))
17522 /* No need to mention EOL here--the terminal never needs
17523 to do EOL conversion. */
17524 p
= decode_mode_spec_coding (FRAME_KEYBOARD_CODING (f
)->symbol
, p
, 0);
17525 p
= decode_mode_spec_coding (FRAME_TERMINAL_CODING (f
)->symbol
, p
, 0);
17527 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17530 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17531 #ifdef subprocesses
17532 obj
= Fget_buffer_process (Fcurrent_buffer ());
17533 if (PROCESSP (obj
))
17535 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17537 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17540 #endif /* subprocesses */
17543 return decode_mode_spec_buf
;
17549 *multibyte
= STRING_MULTIBYTE (obj
);
17550 return (char *) SDATA (obj
);
17557 /* Count up to COUNT lines starting from START / START_BYTE.
17558 But don't go beyond LIMIT_BYTE.
17559 Return the number of lines thus found (always nonnegative).
17561 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17564 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17565 int start
, start_byte
, limit_byte
, count
;
17568 register unsigned char *cursor
;
17569 unsigned char *base
;
17571 register int ceiling
;
17572 register unsigned char *ceiling_addr
;
17573 int orig_count
= count
;
17575 /* If we are not in selective display mode,
17576 check only for newlines. */
17577 int selective_display
= (!NILP (current_buffer
->selective_display
)
17578 && !INTEGERP (current_buffer
->selective_display
));
17582 while (start_byte
< limit_byte
)
17584 ceiling
= BUFFER_CEILING_OF (start_byte
);
17585 ceiling
= min (limit_byte
- 1, ceiling
);
17586 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17587 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17590 if (selective_display
)
17591 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17594 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17597 if (cursor
!= ceiling_addr
)
17601 start_byte
+= cursor
- base
+ 1;
17602 *byte_pos_ptr
= start_byte
;
17606 if (++cursor
== ceiling_addr
)
17612 start_byte
+= cursor
- base
;
17617 while (start_byte
> limit_byte
)
17619 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17620 ceiling
= max (limit_byte
, ceiling
);
17621 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17622 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17625 if (selective_display
)
17626 while (--cursor
!= ceiling_addr
17627 && *cursor
!= '\n' && *cursor
!= 015)
17630 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17633 if (cursor
!= ceiling_addr
)
17637 start_byte
+= cursor
- base
+ 1;
17638 *byte_pos_ptr
= start_byte
;
17639 /* When scanning backwards, we should
17640 not count the newline posterior to which we stop. */
17641 return - orig_count
- 1;
17647 /* Here we add 1 to compensate for the last decrement
17648 of CURSOR, which took it past the valid range. */
17649 start_byte
+= cursor
- base
+ 1;
17653 *byte_pos_ptr
= limit_byte
;
17656 return - orig_count
+ count
;
17657 return orig_count
- count
;
17663 /***********************************************************************
17665 ***********************************************************************/
17667 /* Display a NUL-terminated string, starting with index START.
17669 If STRING is non-null, display that C string. Otherwise, the Lisp
17670 string LISP_STRING is displayed.
17672 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17673 FACE_STRING. Display STRING or LISP_STRING with the face at
17674 FACE_STRING_POS in FACE_STRING:
17676 Display the string in the environment given by IT, but use the
17677 standard display table, temporarily.
17679 FIELD_WIDTH is the minimum number of output glyphs to produce.
17680 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17681 with spaces. If STRING has more characters, more than FIELD_WIDTH
17682 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17684 PRECISION is the maximum number of characters to output from
17685 STRING. PRECISION < 0 means don't truncate the string.
17687 This is roughly equivalent to printf format specifiers:
17689 FIELD_WIDTH PRECISION PRINTF
17690 ----------------------------------------
17696 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17697 display them, and < 0 means obey the current buffer's value of
17698 enable_multibyte_characters.
17700 Value is the number of glyphs produced. */
17703 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17704 start
, it
, field_width
, precision
, max_x
, multibyte
)
17705 unsigned char *string
;
17706 Lisp_Object lisp_string
;
17707 Lisp_Object face_string
;
17708 int face_string_pos
;
17711 int field_width
, precision
, max_x
;
17714 int hpos_at_start
= it
->hpos
;
17715 int saved_face_id
= it
->face_id
;
17716 struct glyph_row
*row
= it
->glyph_row
;
17718 /* Initialize the iterator IT for iteration over STRING beginning
17719 with index START. */
17720 reseat_to_string (it
, string
, lisp_string
, start
,
17721 precision
, field_width
, multibyte
);
17723 /* If displaying STRING, set up the face of the iterator
17724 from LISP_STRING, if that's given. */
17725 if (STRINGP (face_string
))
17731 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17732 0, it
->region_beg_charpos
,
17733 it
->region_end_charpos
,
17734 &endptr
, it
->base_face_id
, 0);
17735 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17736 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17739 /* Set max_x to the maximum allowed X position. Don't let it go
17740 beyond the right edge of the window. */
17742 max_x
= it
->last_visible_x
;
17744 max_x
= min (max_x
, it
->last_visible_x
);
17746 /* Skip over display elements that are not visible. because IT->w is
17748 if (it
->current_x
< it
->first_visible_x
)
17749 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17750 MOVE_TO_POS
| MOVE_TO_X
);
17752 row
->ascent
= it
->max_ascent
;
17753 row
->height
= it
->max_ascent
+ it
->max_descent
;
17754 row
->phys_ascent
= it
->max_phys_ascent
;
17755 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17756 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17758 /* This condition is for the case that we are called with current_x
17759 past last_visible_x. */
17760 while (it
->current_x
< max_x
)
17762 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17764 /* Get the next display element. */
17765 if (!get_next_display_element (it
))
17768 /* Produce glyphs. */
17769 x_before
= it
->current_x
;
17770 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17771 PRODUCE_GLYPHS (it
);
17773 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17776 while (i
< nglyphs
)
17778 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17780 if (!it
->truncate_lines_p
17781 && x
+ glyph
->pixel_width
> max_x
)
17783 /* End of continued line or max_x reached. */
17784 if (CHAR_GLYPH_PADDING_P (*glyph
))
17786 /* A wide character is unbreakable. */
17787 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17788 it
->current_x
= x_before
;
17792 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17797 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17799 /* Glyph is at least partially visible. */
17801 if (x
< it
->first_visible_x
)
17802 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17806 /* Glyph is off the left margin of the display area.
17807 Should not happen. */
17811 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17812 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17813 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17814 row
->phys_height
= max (row
->phys_height
,
17815 it
->max_phys_ascent
+ it
->max_phys_descent
);
17816 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17817 it
->max_extra_line_spacing
);
17818 x
+= glyph
->pixel_width
;
17822 /* Stop if max_x reached. */
17826 /* Stop at line ends. */
17827 if (ITERATOR_AT_END_OF_LINE_P (it
))
17829 it
->continuation_lines_width
= 0;
17833 set_iterator_to_next (it
, 1);
17835 /* Stop if truncating at the right edge. */
17836 if (it
->truncate_lines_p
17837 && it
->current_x
>= it
->last_visible_x
)
17839 /* Add truncation mark, but don't do it if the line is
17840 truncated at a padding space. */
17841 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17843 if (!FRAME_WINDOW_P (it
->f
))
17847 if (it
->current_x
> it
->last_visible_x
)
17849 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17850 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17852 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17854 row
->used
[TEXT_AREA
] = i
;
17855 produce_special_glyphs (it
, IT_TRUNCATION
);
17858 produce_special_glyphs (it
, IT_TRUNCATION
);
17860 it
->glyph_row
->truncated_on_right_p
= 1;
17866 /* Maybe insert a truncation at the left. */
17867 if (it
->first_visible_x
17868 && IT_CHARPOS (*it
) > 0)
17870 if (!FRAME_WINDOW_P (it
->f
))
17871 insert_left_trunc_glyphs (it
);
17872 it
->glyph_row
->truncated_on_left_p
= 1;
17875 it
->face_id
= saved_face_id
;
17877 /* Value is number of columns displayed. */
17878 return it
->hpos
- hpos_at_start
;
17883 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17884 appears as an element of LIST or as the car of an element of LIST.
17885 If PROPVAL is a list, compare each element against LIST in that
17886 way, and return 1/2 if any element of PROPVAL is found in LIST.
17887 Otherwise return 0. This function cannot quit.
17888 The return value is 2 if the text is invisible but with an ellipsis
17889 and 1 if it's invisible and without an ellipsis. */
17892 invisible_p (propval
, list
)
17893 register Lisp_Object propval
;
17896 register Lisp_Object tail
, proptail
;
17898 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17900 register Lisp_Object tem
;
17902 if (EQ (propval
, tem
))
17904 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17905 return NILP (XCDR (tem
)) ? 1 : 2;
17908 if (CONSP (propval
))
17910 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17912 Lisp_Object propelt
;
17913 propelt
= XCAR (proptail
);
17914 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17916 register Lisp_Object tem
;
17918 if (EQ (propelt
, tem
))
17920 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17921 return NILP (XCDR (tem
)) ? 1 : 2;
17929 /* Calculate a width or height in pixels from a specification using
17930 the following elements:
17933 NUM - a (fractional) multiple of the default font width/height
17934 (NUM) - specifies exactly NUM pixels
17935 UNIT - a fixed number of pixels, see below.
17936 ELEMENT - size of a display element in pixels, see below.
17937 (NUM . SPEC) - equals NUM * SPEC
17938 (+ SPEC SPEC ...) - add pixel values
17939 (- SPEC SPEC ...) - subtract pixel values
17940 (- SPEC) - negate pixel value
17943 INT or FLOAT - a number constant
17944 SYMBOL - use symbol's (buffer local) variable binding.
17947 in - pixels per inch *)
17948 mm - pixels per 1/1000 meter *)
17949 cm - pixels per 1/100 meter *)
17950 width - width of current font in pixels.
17951 height - height of current font in pixels.
17953 *) using the ratio(s) defined in display-pixels-per-inch.
17957 left-fringe - left fringe width in pixels
17958 right-fringe - right fringe width in pixels
17960 left-margin - left margin width in pixels
17961 right-margin - right margin width in pixels
17963 scroll-bar - scroll-bar area width in pixels
17967 Pixels corresponding to 5 inches:
17970 Total width of non-text areas on left side of window (if scroll-bar is on left):
17971 '(space :width (+ left-fringe left-margin scroll-bar))
17973 Align to first text column (in header line):
17974 '(space :align-to 0)
17976 Align to middle of text area minus half the width of variable `my-image'
17977 containing a loaded image:
17978 '(space :align-to (0.5 . (- text my-image)))
17980 Width of left margin minus width of 1 character in the default font:
17981 '(space :width (- left-margin 1))
17983 Width of left margin minus width of 2 characters in the current font:
17984 '(space :width (- left-margin (2 . width)))
17986 Center 1 character over left-margin (in header line):
17987 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17989 Different ways to express width of left fringe plus left margin minus one pixel:
17990 '(space :width (- (+ left-fringe left-margin) (1)))
17991 '(space :width (+ left-fringe left-margin (- (1))))
17992 '(space :width (+ left-fringe left-margin (-1)))
17996 #define NUMVAL(X) \
17997 ((INTEGERP (X) || FLOATP (X)) \
18002 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18007 int width_p
, *align_to
;
18011 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18012 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18015 return OK_PIXELS (0);
18017 xassert (FRAME_LIVE_P (it
->f
));
18019 if (SYMBOLP (prop
))
18021 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18023 char *unit
= SDATA (SYMBOL_NAME (prop
));
18025 if (unit
[0] == 'i' && unit
[1] == 'n')
18027 else if (unit
[0] == 'm' && unit
[1] == 'm')
18029 else if (unit
[0] == 'c' && unit
[1] == 'm')
18036 #ifdef HAVE_WINDOW_SYSTEM
18037 if (FRAME_WINDOW_P (it
->f
)
18039 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18040 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18042 return OK_PIXELS (ppi
/ pixels
);
18045 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18046 || (CONSP (Vdisplay_pixels_per_inch
)
18048 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18049 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18051 return OK_PIXELS (ppi
/ pixels
);
18057 #ifdef HAVE_WINDOW_SYSTEM
18058 if (EQ (prop
, Qheight
))
18059 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18060 if (EQ (prop
, Qwidth
))
18061 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18063 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18064 return OK_PIXELS (1);
18067 if (EQ (prop
, Qtext
))
18068 return OK_PIXELS (width_p
18069 ? window_box_width (it
->w
, TEXT_AREA
)
18070 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18072 if (align_to
&& *align_to
< 0)
18075 if (EQ (prop
, Qleft
))
18076 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18077 if (EQ (prop
, Qright
))
18078 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18079 if (EQ (prop
, Qcenter
))
18080 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18081 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18082 if (EQ (prop
, Qleft_fringe
))
18083 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18084 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18085 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18086 if (EQ (prop
, Qright_fringe
))
18087 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18088 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18089 : window_box_right_offset (it
->w
, TEXT_AREA
));
18090 if (EQ (prop
, Qleft_margin
))
18091 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18092 if (EQ (prop
, Qright_margin
))
18093 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18094 if (EQ (prop
, Qscroll_bar
))
18095 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18097 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18098 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18099 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18104 if (EQ (prop
, Qleft_fringe
))
18105 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18106 if (EQ (prop
, Qright_fringe
))
18107 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18108 if (EQ (prop
, Qleft_margin
))
18109 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18110 if (EQ (prop
, Qright_margin
))
18111 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18112 if (EQ (prop
, Qscroll_bar
))
18113 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18116 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18119 if (INTEGERP (prop
) || FLOATP (prop
))
18121 int base_unit
= (width_p
18122 ? FRAME_COLUMN_WIDTH (it
->f
)
18123 : FRAME_LINE_HEIGHT (it
->f
));
18124 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18129 Lisp_Object car
= XCAR (prop
);
18130 Lisp_Object cdr
= XCDR (prop
);
18134 #ifdef HAVE_WINDOW_SYSTEM
18135 if (FRAME_WINDOW_P (it
->f
)
18136 && valid_image_p (prop
))
18138 int id
= lookup_image (it
->f
, prop
);
18139 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18141 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18144 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18150 while (CONSP (cdr
))
18152 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18153 font
, width_p
, align_to
))
18156 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18161 if (EQ (car
, Qminus
))
18163 return OK_PIXELS (pixels
);
18166 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18169 if (INTEGERP (car
) || FLOATP (car
))
18172 pixels
= XFLOATINT (car
);
18174 return OK_PIXELS (pixels
);
18175 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18176 font
, width_p
, align_to
))
18177 return OK_PIXELS (pixels
* fact
);
18188 /***********************************************************************
18190 ***********************************************************************/
18192 #ifdef HAVE_WINDOW_SYSTEM
18197 dump_glyph_string (s
)
18198 struct glyph_string
*s
;
18200 fprintf (stderr
, "glyph string\n");
18201 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18202 s
->x
, s
->y
, s
->width
, s
->height
);
18203 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18204 fprintf (stderr
, " hl = %d\n", s
->hl
);
18205 fprintf (stderr
, " left overhang = %d, right = %d\n",
18206 s
->left_overhang
, s
->right_overhang
);
18207 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18208 fprintf (stderr
, " extends to end of line = %d\n",
18209 s
->extends_to_end_of_line_p
);
18210 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18211 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18214 #endif /* GLYPH_DEBUG */
18216 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18217 of XChar2b structures for S; it can't be allocated in
18218 init_glyph_string because it must be allocated via `alloca'. W
18219 is the window on which S is drawn. ROW and AREA are the glyph row
18220 and area within the row from which S is constructed. START is the
18221 index of the first glyph structure covered by S. HL is a
18222 face-override for drawing S. */
18225 #define OPTIONAL_HDC(hdc) hdc,
18226 #define DECLARE_HDC(hdc) HDC hdc;
18227 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18228 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18231 #ifndef OPTIONAL_HDC
18232 #define OPTIONAL_HDC(hdc)
18233 #define DECLARE_HDC(hdc)
18234 #define ALLOCATE_HDC(hdc, f)
18235 #define RELEASE_HDC(hdc, f)
18239 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18240 struct glyph_string
*s
;
18244 struct glyph_row
*row
;
18245 enum glyph_row_area area
;
18247 enum draw_glyphs_face hl
;
18249 bzero (s
, sizeof *s
);
18251 s
->f
= XFRAME (w
->frame
);
18255 s
->display
= FRAME_X_DISPLAY (s
->f
);
18256 s
->window
= FRAME_X_WINDOW (s
->f
);
18257 s
->char2b
= char2b
;
18261 s
->first_glyph
= row
->glyphs
[area
] + start
;
18262 s
->height
= row
->height
;
18263 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18265 /* Display the internal border below the tool-bar window. */
18266 if (WINDOWP (s
->f
->tool_bar_window
)
18267 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18268 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18270 s
->ybase
= s
->y
+ row
->ascent
;
18274 /* Append the list of glyph strings with head H and tail T to the list
18275 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18278 append_glyph_string_lists (head
, tail
, h
, t
)
18279 struct glyph_string
**head
, **tail
;
18280 struct glyph_string
*h
, *t
;
18294 /* Prepend the list of glyph strings with head H and tail T to the
18295 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18299 prepend_glyph_string_lists (head
, tail
, h
, t
)
18300 struct glyph_string
**head
, **tail
;
18301 struct glyph_string
*h
, *t
;
18315 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18316 Set *HEAD and *TAIL to the resulting list. */
18319 append_glyph_string (head
, tail
, s
)
18320 struct glyph_string
**head
, **tail
;
18321 struct glyph_string
*s
;
18323 s
->next
= s
->prev
= NULL
;
18324 append_glyph_string_lists (head
, tail
, s
, s
);
18328 /* Get face and two-byte form of character glyph GLYPH on frame F.
18329 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18330 a pointer to a realized face that is ready for display. */
18332 static INLINE
struct face
*
18333 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18335 struct glyph
*glyph
;
18341 xassert (glyph
->type
== CHAR_GLYPH
);
18342 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18347 if (!glyph
->multibyte_p
)
18349 /* Unibyte case. We don't have to encode, but we have to make
18350 sure to use a face suitable for unibyte. */
18351 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18353 else if (glyph
->u
.ch
< 128
18354 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
18356 /* Case of ASCII in a face known to fit ASCII. */
18357 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18361 int c1
, c2
, charset
;
18363 /* Split characters into bytes. If c2 is -1 afterwards, C is
18364 really a one-byte character so that byte1 is zero. */
18365 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18367 STORE_XCHAR2B (char2b
, c1
, c2
);
18369 STORE_XCHAR2B (char2b
, 0, c1
);
18371 /* Maybe encode the character in *CHAR2B. */
18372 if (charset
!= CHARSET_ASCII
)
18374 struct font_info
*font_info
18375 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18378 = FRAME_RIF (f
)->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18382 /* Make sure X resources of the face are allocated. */
18383 xassert (face
!= NULL
);
18384 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18389 /* Fill glyph string S with composition components specified by S->cmp.
18391 FACES is an array of faces for all components of this composition.
18392 S->gidx is the index of the first component for S.
18394 OVERLAPS non-zero means S should draw the foreground only, and use
18395 its physical height for clipping. See also draw_glyphs.
18397 Value is the index of a component not in S. */
18400 fill_composite_glyph_string (s
, faces
, overlaps
)
18401 struct glyph_string
*s
;
18402 struct face
**faces
;
18409 s
->for_overlaps
= overlaps
;
18411 s
->face
= faces
[s
->gidx
];
18412 s
->font
= s
->face
->font
;
18413 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18415 /* For all glyphs of this composition, starting at the offset
18416 S->gidx, until we reach the end of the definition or encounter a
18417 glyph that requires the different face, add it to S. */
18419 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18422 /* All glyph strings for the same composition has the same width,
18423 i.e. the width set for the first component of the composition. */
18425 s
->width
= s
->first_glyph
->pixel_width
;
18427 /* If the specified font could not be loaded, use the frame's
18428 default font, but record the fact that we couldn't load it in
18429 the glyph string so that we can draw rectangles for the
18430 characters of the glyph string. */
18431 if (s
->font
== NULL
)
18433 s
->font_not_found_p
= 1;
18434 s
->font
= FRAME_FONT (s
->f
);
18437 /* Adjust base line for subscript/superscript text. */
18438 s
->ybase
+= s
->first_glyph
->voffset
;
18440 xassert (s
->face
&& s
->face
->gc
);
18442 /* This glyph string must always be drawn with 16-bit functions. */
18445 return s
->gidx
+ s
->nchars
;
18449 /* Fill glyph string S from a sequence of character glyphs.
18451 FACE_ID is the face id of the string. START is the index of the
18452 first glyph to consider, END is the index of the last + 1.
18453 OVERLAPS non-zero means S should draw the foreground only, and use
18454 its physical height for clipping. See also draw_glyphs.
18456 Value is the index of the first glyph not in S. */
18459 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18460 struct glyph_string
*s
;
18462 int start
, end
, overlaps
;
18464 struct glyph
*glyph
, *last
;
18466 int glyph_not_available_p
;
18468 xassert (s
->f
== XFRAME (s
->w
->frame
));
18469 xassert (s
->nchars
== 0);
18470 xassert (start
>= 0 && end
> start
);
18472 s
->for_overlaps
= overlaps
,
18473 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18474 last
= s
->row
->glyphs
[s
->area
] + end
;
18475 voffset
= glyph
->voffset
;
18477 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18479 while (glyph
< last
18480 && glyph
->type
== CHAR_GLYPH
18481 && glyph
->voffset
== voffset
18482 /* Same face id implies same font, nowadays. */
18483 && glyph
->face_id
== face_id
18484 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18488 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18489 s
->char2b
+ s
->nchars
,
18491 s
->two_byte_p
= two_byte_p
;
18493 xassert (s
->nchars
<= end
- start
);
18494 s
->width
+= glyph
->pixel_width
;
18498 s
->font
= s
->face
->font
;
18499 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18501 /* If the specified font could not be loaded, use the frame's font,
18502 but record the fact that we couldn't load it in
18503 S->font_not_found_p so that we can draw rectangles for the
18504 characters of the glyph string. */
18505 if (s
->font
== NULL
|| glyph_not_available_p
)
18507 s
->font_not_found_p
= 1;
18508 s
->font
= FRAME_FONT (s
->f
);
18511 /* Adjust base line for subscript/superscript text. */
18512 s
->ybase
+= voffset
;
18514 xassert (s
->face
&& s
->face
->gc
);
18515 return glyph
- s
->row
->glyphs
[s
->area
];
18519 /* Fill glyph string S from image glyph S->first_glyph. */
18522 fill_image_glyph_string (s
)
18523 struct glyph_string
*s
;
18525 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18526 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18528 s
->slice
= s
->first_glyph
->slice
;
18529 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18530 s
->font
= s
->face
->font
;
18531 s
->width
= s
->first_glyph
->pixel_width
;
18533 /* Adjust base line for subscript/superscript text. */
18534 s
->ybase
+= s
->first_glyph
->voffset
;
18538 /* Fill glyph string S from a sequence of stretch glyphs.
18540 ROW is the glyph row in which the glyphs are found, AREA is the
18541 area within the row. START is the index of the first glyph to
18542 consider, END is the index of the last + 1.
18544 Value is the index of the first glyph not in S. */
18547 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18548 struct glyph_string
*s
;
18549 struct glyph_row
*row
;
18550 enum glyph_row_area area
;
18553 struct glyph
*glyph
, *last
;
18554 int voffset
, face_id
;
18556 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18558 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18559 last
= s
->row
->glyphs
[s
->area
] + end
;
18560 face_id
= glyph
->face_id
;
18561 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18562 s
->font
= s
->face
->font
;
18563 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18564 s
->width
= glyph
->pixel_width
;
18565 voffset
= glyph
->voffset
;
18569 && glyph
->type
== STRETCH_GLYPH
18570 && glyph
->voffset
== voffset
18571 && glyph
->face_id
== face_id
);
18573 s
->width
+= glyph
->pixel_width
;
18575 /* Adjust base line for subscript/superscript text. */
18576 s
->ybase
+= voffset
;
18578 /* The case that face->gc == 0 is handled when drawing the glyph
18579 string by calling PREPARE_FACE_FOR_DISPLAY. */
18581 return glyph
- s
->row
->glyphs
[s
->area
];
18586 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18587 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18588 assumed to be zero. */
18591 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18592 struct glyph
*glyph
;
18596 *left
= *right
= 0;
18598 if (glyph
->type
== CHAR_GLYPH
)
18602 struct font_info
*font_info
;
18606 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18608 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18609 if (font
/* ++KFS: Should this be font_info ? */
18610 && (pcm
= FRAME_RIF (f
)->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18612 if (pcm
->rbearing
> pcm
->width
)
18613 *right
= pcm
->rbearing
- pcm
->width
;
18614 if (pcm
->lbearing
< 0)
18615 *left
= -pcm
->lbearing
;
18621 /* Return the index of the first glyph preceding glyph string S that
18622 is overwritten by S because of S's left overhang. Value is -1
18623 if no glyphs are overwritten. */
18626 left_overwritten (s
)
18627 struct glyph_string
*s
;
18631 if (s
->left_overhang
)
18634 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18635 int first
= s
->first_glyph
- glyphs
;
18637 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18638 x
-= glyphs
[i
].pixel_width
;
18649 /* Return the index of the first glyph preceding glyph string S that
18650 is overwriting S because of its right overhang. Value is -1 if no
18651 glyph in front of S overwrites S. */
18654 left_overwriting (s
)
18655 struct glyph_string
*s
;
18658 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18659 int first
= s
->first_glyph
- glyphs
;
18663 for (i
= first
- 1; i
>= 0; --i
)
18666 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18669 x
-= glyphs
[i
].pixel_width
;
18676 /* Return the index of the last glyph following glyph string S that is
18677 not overwritten by S because of S's right overhang. Value is -1 if
18678 no such glyph is found. */
18681 right_overwritten (s
)
18682 struct glyph_string
*s
;
18686 if (s
->right_overhang
)
18689 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18690 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18691 int end
= s
->row
->used
[s
->area
];
18693 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18694 x
+= glyphs
[i
].pixel_width
;
18703 /* Return the index of the last glyph following glyph string S that
18704 overwrites S because of its left overhang. Value is negative
18705 if no such glyph is found. */
18708 right_overwriting (s
)
18709 struct glyph_string
*s
;
18712 int end
= s
->row
->used
[s
->area
];
18713 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18714 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18718 for (i
= first
; i
< end
; ++i
)
18721 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18724 x
+= glyphs
[i
].pixel_width
;
18731 /* Get face and two-byte form of character C in face FACE_ID on frame
18732 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18733 means we want to display multibyte text. DISPLAY_P non-zero means
18734 make sure that X resources for the face returned are allocated.
18735 Value is a pointer to a realized face that is ready for display if
18736 DISPLAY_P is non-zero. */
18738 static INLINE
struct face
*
18739 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18743 int multibyte_p
, display_p
;
18745 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18749 /* Unibyte case. We don't have to encode, but we have to make
18750 sure to use a face suitable for unibyte. */
18751 STORE_XCHAR2B (char2b
, 0, c
);
18752 face_id
= FACE_FOR_CHAR (f
, face
, c
);
18753 face
= FACE_FROM_ID (f
, face_id
);
18755 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18757 /* Case of ASCII in a face known to fit ASCII. */
18758 STORE_XCHAR2B (char2b
, 0, c
);
18762 int c1
, c2
, charset
;
18764 /* Split characters into bytes. If c2 is -1 afterwards, C is
18765 really a one-byte character so that byte1 is zero. */
18766 SPLIT_CHAR (c
, charset
, c1
, c2
);
18768 STORE_XCHAR2B (char2b
, c1
, c2
);
18770 STORE_XCHAR2B (char2b
, 0, c1
);
18772 /* Maybe encode the character in *CHAR2B. */
18773 if (face
->font
!= NULL
)
18775 struct font_info
*font_info
18776 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18778 FRAME_RIF (f
)->encode_char (c
, char2b
, font_info
, 0);
18782 /* Make sure X resources of the face are allocated. */
18783 #ifdef HAVE_X_WINDOWS
18787 xassert (face
!= NULL
);
18788 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18795 /* Set background width of glyph string S. START is the index of the
18796 first glyph following S. LAST_X is the right-most x-position + 1
18797 in the drawing area. */
18800 set_glyph_string_background_width (s
, start
, last_x
)
18801 struct glyph_string
*s
;
18805 /* If the face of this glyph string has to be drawn to the end of
18806 the drawing area, set S->extends_to_end_of_line_p. */
18808 if (start
== s
->row
->used
[s
->area
]
18809 && s
->area
== TEXT_AREA
18810 && ((s
->row
->fill_line_p
18811 && (s
->hl
== DRAW_NORMAL_TEXT
18812 || s
->hl
== DRAW_IMAGE_RAISED
18813 || s
->hl
== DRAW_IMAGE_SUNKEN
))
18814 || s
->hl
== DRAW_MOUSE_FACE
))
18815 s
->extends_to_end_of_line_p
= 1;
18817 /* If S extends its face to the end of the line, set its
18818 background_width to the distance to the right edge of the drawing
18820 if (s
->extends_to_end_of_line_p
)
18821 s
->background_width
= last_x
- s
->x
+ 1;
18823 s
->background_width
= s
->width
;
18827 /* Compute overhangs and x-positions for glyph string S and its
18828 predecessors, or successors. X is the starting x-position for S.
18829 BACKWARD_P non-zero means process predecessors. */
18832 compute_overhangs_and_x (s
, x
, backward_p
)
18833 struct glyph_string
*s
;
18841 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
18842 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
18852 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
18853 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
18863 /* The following macros are only called from draw_glyphs below.
18864 They reference the following parameters of that function directly:
18865 `w', `row', `area', and `overlap_p'
18866 as well as the following local variables:
18867 `s', `f', and `hdc' (in W32) */
18870 /* On W32, silently add local `hdc' variable to argument list of
18871 init_glyph_string. */
18872 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18873 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18875 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18876 init_glyph_string (s, char2b, w, row, area, start, hl)
18879 /* Add a glyph string for a stretch glyph to the list of strings
18880 between HEAD and TAIL. START is the index of the stretch glyph in
18881 row area AREA of glyph row ROW. END is the index of the last glyph
18882 in that glyph row area. X is the current output position assigned
18883 to the new glyph string constructed. HL overrides that face of the
18884 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18885 is the right-most x-position of the drawing area. */
18887 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18888 and below -- keep them on one line. */
18889 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18892 s = (struct glyph_string *) alloca (sizeof *s); \
18893 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18894 START = fill_stretch_glyph_string (s, row, area, START, END); \
18895 append_glyph_string (&HEAD, &TAIL, s); \
18901 /* Add a glyph string for an image glyph to the list of strings
18902 between HEAD and TAIL. START is the index of the image glyph in
18903 row area AREA of glyph row ROW. END is the index of the last glyph
18904 in that glyph row area. X is the current output position assigned
18905 to the new glyph string constructed. HL overrides that face of the
18906 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18907 is the right-most x-position of the drawing area. */
18909 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18912 s = (struct glyph_string *) alloca (sizeof *s); \
18913 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18914 fill_image_glyph_string (s); \
18915 append_glyph_string (&HEAD, &TAIL, s); \
18922 /* Add a glyph string for a sequence of character glyphs to the list
18923 of strings between HEAD and TAIL. START is the index of the first
18924 glyph in row area AREA of glyph row ROW that is part of the new
18925 glyph string. END is the index of the last glyph in that glyph row
18926 area. X is the current output position assigned to the new glyph
18927 string constructed. HL overrides that face of the glyph; e.g. it
18928 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18929 right-most x-position of the drawing area. */
18931 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18937 c = (row)->glyphs[area][START].u.ch; \
18938 face_id = (row)->glyphs[area][START].face_id; \
18940 s = (struct glyph_string *) alloca (sizeof *s); \
18941 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18942 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18943 append_glyph_string (&HEAD, &TAIL, s); \
18945 START = fill_glyph_string (s, face_id, START, END, overlaps); \
18950 /* Add a glyph string for a composite sequence to the list of strings
18951 between HEAD and TAIL. START is the index of the first glyph in
18952 row area AREA of glyph row ROW that is part of the new glyph
18953 string. END is the index of the last glyph in that glyph row area.
18954 X is the current output position assigned to the new glyph string
18955 constructed. HL overrides that face of the glyph; e.g. it is
18956 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18957 x-position of the drawing area. */
18959 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18961 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18962 int face_id = (row)->glyphs[area][START].face_id; \
18963 struct face *base_face = FACE_FROM_ID (f, face_id); \
18964 struct composition *cmp = composition_table[cmp_id]; \
18965 int glyph_len = cmp->glyph_len; \
18967 struct face **faces; \
18968 struct glyph_string *first_s = NULL; \
18971 base_face = base_face->ascii_face; \
18972 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18973 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18974 /* At first, fill in `char2b' and `faces'. */ \
18975 for (n = 0; n < glyph_len; n++) \
18977 int c = COMPOSITION_GLYPH (cmp, n); \
18978 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
18979 faces[n] = FACE_FROM_ID (f, this_face_id); \
18980 get_char_face_and_encoding (f, c, this_face_id, \
18981 char2b + n, 1, 1); \
18984 /* Make glyph_strings for each glyph sequence that is drawable by \
18985 the same face, and append them to HEAD/TAIL. */ \
18986 for (n = 0; n < cmp->glyph_len;) \
18988 s = (struct glyph_string *) alloca (sizeof *s); \
18989 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18990 append_glyph_string (&(HEAD), &(TAIL), s); \
18998 n = fill_composite_glyph_string (s, faces, overlaps); \
19006 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19007 of AREA of glyph row ROW on window W between indices START and END.
19008 HL overrides the face for drawing glyph strings, e.g. it is
19009 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19010 x-positions of the drawing area.
19012 This is an ugly monster macro construct because we must use alloca
19013 to allocate glyph strings (because draw_glyphs can be called
19014 asynchronously). */
19016 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19019 HEAD = TAIL = NULL; \
19020 while (START < END) \
19022 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19023 switch (first_glyph->type) \
19026 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19030 case COMPOSITE_GLYPH: \
19031 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19035 case STRETCH_GLYPH: \
19036 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19040 case IMAGE_GLYPH: \
19041 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19049 set_glyph_string_background_width (s, START, LAST_X); \
19056 /* Draw glyphs between START and END in AREA of ROW on window W,
19057 starting at x-position X. X is relative to AREA in W. HL is a
19058 face-override with the following meaning:
19060 DRAW_NORMAL_TEXT draw normally
19061 DRAW_CURSOR draw in cursor face
19062 DRAW_MOUSE_FACE draw in mouse face.
19063 DRAW_INVERSE_VIDEO draw in mode line face
19064 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19065 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19067 If OVERLAPS is non-zero, draw only the foreground of characters and
19068 clip to the physical height of ROW. Non-zero value also defines
19069 the overlapping part to be drawn:
19071 OVERLAPS_PRED overlap with preceding rows
19072 OVERLAPS_SUCC overlap with succeeding rows
19073 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19074 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19076 Value is the x-position reached, relative to AREA of W. */
19079 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19082 struct glyph_row
*row
;
19083 enum glyph_row_area area
;
19085 enum draw_glyphs_face hl
;
19088 struct glyph_string
*head
, *tail
;
19089 struct glyph_string
*s
;
19090 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19091 int last_x
, area_width
;
19094 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19097 ALLOCATE_HDC (hdc
, f
);
19099 /* Let's rather be paranoid than getting a SEGV. */
19100 end
= min (end
, row
->used
[area
]);
19101 start
= max (0, start
);
19102 start
= min (end
, start
);
19104 /* Translate X to frame coordinates. Set last_x to the right
19105 end of the drawing area. */
19106 if (row
->full_width_p
)
19108 /* X is relative to the left edge of W, without scroll bars
19110 x
+= WINDOW_LEFT_EDGE_X (w
);
19111 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19115 int area_left
= window_box_left (w
, area
);
19117 area_width
= window_box_width (w
, area
);
19118 last_x
= area_left
+ area_width
;
19121 /* Build a doubly-linked list of glyph_string structures between
19122 head and tail from what we have to draw. Note that the macro
19123 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19124 the reason we use a separate variable `i'. */
19126 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19128 x_reached
= tail
->x
+ tail
->background_width
;
19132 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19133 the row, redraw some glyphs in front or following the glyph
19134 strings built above. */
19135 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19138 struct glyph_string
*h
, *t
;
19140 /* Compute overhangs for all glyph strings. */
19141 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
19142 for (s
= head
; s
; s
= s
->next
)
19143 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
19145 /* Prepend glyph strings for glyphs in front of the first glyph
19146 string that are overwritten because of the first glyph
19147 string's left overhang. The background of all strings
19148 prepended must be drawn because the first glyph string
19150 i
= left_overwritten (head
);
19154 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19155 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19157 compute_overhangs_and_x (t
, head
->x
, 1);
19158 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19162 /* Prepend glyph strings for glyphs in front of the first glyph
19163 string that overwrite that glyph string because of their
19164 right overhang. For these strings, only the foreground must
19165 be drawn, because it draws over the glyph string at `head'.
19166 The background must not be drawn because this would overwrite
19167 right overhangs of preceding glyphs for which no glyph
19169 i
= left_overwriting (head
);
19173 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19174 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19175 for (s
= h
; s
; s
= s
->next
)
19176 s
->background_filled_p
= 1;
19177 compute_overhangs_and_x (t
, head
->x
, 1);
19178 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19181 /* Append glyphs strings for glyphs following the last glyph
19182 string tail that are overwritten by tail. The background of
19183 these strings has to be drawn because tail's foreground draws
19185 i
= right_overwritten (tail
);
19188 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19189 DRAW_NORMAL_TEXT
, x
, last_x
);
19190 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19191 append_glyph_string_lists (&head
, &tail
, h
, t
);
19195 /* Append glyph strings for glyphs following the last glyph
19196 string tail that overwrite tail. The foreground of such
19197 glyphs has to be drawn because it writes into the background
19198 of tail. The background must not be drawn because it could
19199 paint over the foreground of following glyphs. */
19200 i
= right_overwriting (tail
);
19204 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19205 DRAW_NORMAL_TEXT
, x
, last_x
);
19206 for (s
= h
; s
; s
= s
->next
)
19207 s
->background_filled_p
= 1;
19208 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19209 append_glyph_string_lists (&head
, &tail
, h
, t
);
19211 if (clip_head
|| clip_tail
)
19212 for (s
= head
; s
; s
= s
->next
)
19214 s
->clip_head
= clip_head
;
19215 s
->clip_tail
= clip_tail
;
19219 /* Draw all strings. */
19220 for (s
= head
; s
; s
= s
->next
)
19221 FRAME_RIF (f
)->draw_glyph_string (s
);
19223 if (area
== TEXT_AREA
19224 && !row
->full_width_p
19225 /* When drawing overlapping rows, only the glyph strings'
19226 foreground is drawn, which doesn't erase a cursor
19230 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19231 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19232 : (tail
? tail
->x
+ tail
->background_width
: x
));
19234 int text_left
= window_box_left (w
, TEXT_AREA
);
19238 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19239 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19242 /* Value is the x-position up to which drawn, relative to AREA of W.
19243 This doesn't include parts drawn because of overhangs. */
19244 if (row
->full_width_p
)
19245 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19247 x_reached
-= window_box_left (w
, area
);
19249 RELEASE_HDC (hdc
, f
);
19254 /* Expand row matrix if too narrow. Don't expand if area
19257 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19259 if (!fonts_changed_p \
19260 && (it->glyph_row->glyphs[area] \
19261 < it->glyph_row->glyphs[area + 1])) \
19263 it->w->ncols_scale_factor++; \
19264 fonts_changed_p = 1; \
19268 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19269 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19275 struct glyph
*glyph
;
19276 enum glyph_row_area area
= it
->area
;
19278 xassert (it
->glyph_row
);
19279 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19281 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19282 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19284 glyph
->charpos
= CHARPOS (it
->position
);
19285 glyph
->object
= it
->object
;
19286 glyph
->pixel_width
= it
->pixel_width
;
19287 glyph
->ascent
= it
->ascent
;
19288 glyph
->descent
= it
->descent
;
19289 glyph
->voffset
= it
->voffset
;
19290 glyph
->type
= CHAR_GLYPH
;
19291 glyph
->multibyte_p
= it
->multibyte_p
;
19292 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19293 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19294 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19295 || it
->phys_descent
> it
->descent
);
19296 glyph
->padding_p
= 0;
19297 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19298 glyph
->face_id
= it
->face_id
;
19299 glyph
->u
.ch
= it
->char_to_display
;
19300 glyph
->slice
= null_glyph_slice
;
19301 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19302 ++it
->glyph_row
->used
[area
];
19305 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19308 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19309 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19312 append_composite_glyph (it
)
19315 struct glyph
*glyph
;
19316 enum glyph_row_area area
= it
->area
;
19318 xassert (it
->glyph_row
);
19320 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19321 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19323 glyph
->charpos
= CHARPOS (it
->position
);
19324 glyph
->object
= it
->object
;
19325 glyph
->pixel_width
= it
->pixel_width
;
19326 glyph
->ascent
= it
->ascent
;
19327 glyph
->descent
= it
->descent
;
19328 glyph
->voffset
= it
->voffset
;
19329 glyph
->type
= COMPOSITE_GLYPH
;
19330 glyph
->multibyte_p
= it
->multibyte_p
;
19331 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19332 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19333 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19334 || it
->phys_descent
> it
->descent
);
19335 glyph
->padding_p
= 0;
19336 glyph
->glyph_not_available_p
= 0;
19337 glyph
->face_id
= it
->face_id
;
19338 glyph
->u
.cmp_id
= it
->cmp_id
;
19339 glyph
->slice
= null_glyph_slice
;
19340 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19341 ++it
->glyph_row
->used
[area
];
19344 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19348 /* Change IT->ascent and IT->height according to the setting of
19352 take_vertical_position_into_account (it
)
19357 if (it
->voffset
< 0)
19358 /* Increase the ascent so that we can display the text higher
19360 it
->ascent
-= it
->voffset
;
19362 /* Increase the descent so that we can display the text lower
19364 it
->descent
+= it
->voffset
;
19369 /* Produce glyphs/get display metrics for the image IT is loaded with.
19370 See the description of struct display_iterator in dispextern.h for
19371 an overview of struct display_iterator. */
19374 produce_image_glyph (it
)
19380 struct glyph_slice slice
;
19382 xassert (it
->what
== IT_IMAGE
);
19384 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19386 /* Make sure X resources of the face is loaded. */
19387 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19389 if (it
->image_id
< 0)
19391 /* Fringe bitmap. */
19392 it
->ascent
= it
->phys_ascent
= 0;
19393 it
->descent
= it
->phys_descent
= 0;
19394 it
->pixel_width
= 0;
19399 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19401 /* Make sure X resources of the image is loaded. */
19402 prepare_image_for_display (it
->f
, img
);
19404 slice
.x
= slice
.y
= 0;
19405 slice
.width
= img
->width
;
19406 slice
.height
= img
->height
;
19408 if (INTEGERP (it
->slice
.x
))
19409 slice
.x
= XINT (it
->slice
.x
);
19410 else if (FLOATP (it
->slice
.x
))
19411 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19413 if (INTEGERP (it
->slice
.y
))
19414 slice
.y
= XINT (it
->slice
.y
);
19415 else if (FLOATP (it
->slice
.y
))
19416 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19418 if (INTEGERP (it
->slice
.width
))
19419 slice
.width
= XINT (it
->slice
.width
);
19420 else if (FLOATP (it
->slice
.width
))
19421 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19423 if (INTEGERP (it
->slice
.height
))
19424 slice
.height
= XINT (it
->slice
.height
);
19425 else if (FLOATP (it
->slice
.height
))
19426 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19428 if (slice
.x
>= img
->width
)
19429 slice
.x
= img
->width
;
19430 if (slice
.y
>= img
->height
)
19431 slice
.y
= img
->height
;
19432 if (slice
.x
+ slice
.width
>= img
->width
)
19433 slice
.width
= img
->width
- slice
.x
;
19434 if (slice
.y
+ slice
.height
> img
->height
)
19435 slice
.height
= img
->height
- slice
.y
;
19437 if (slice
.width
== 0 || slice
.height
== 0)
19440 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19442 it
->descent
= slice
.height
- glyph_ascent
;
19444 it
->descent
+= img
->vmargin
;
19445 if (slice
.y
+ slice
.height
== img
->height
)
19446 it
->descent
+= img
->vmargin
;
19447 it
->phys_descent
= it
->descent
;
19449 it
->pixel_width
= slice
.width
;
19451 it
->pixel_width
+= img
->hmargin
;
19452 if (slice
.x
+ slice
.width
== img
->width
)
19453 it
->pixel_width
+= img
->hmargin
;
19455 /* It's quite possible for images to have an ascent greater than
19456 their height, so don't get confused in that case. */
19457 if (it
->descent
< 0)
19460 #if 0 /* this breaks image tiling */
19461 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19462 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19463 if (face_ascent
> it
->ascent
)
19464 it
->ascent
= it
->phys_ascent
= face_ascent
;
19469 if (face
->box
!= FACE_NO_BOX
)
19471 if (face
->box_line_width
> 0)
19474 it
->ascent
+= face
->box_line_width
;
19475 if (slice
.y
+ slice
.height
== img
->height
)
19476 it
->descent
+= face
->box_line_width
;
19479 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19480 it
->pixel_width
+= abs (face
->box_line_width
);
19481 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19482 it
->pixel_width
+= abs (face
->box_line_width
);
19485 take_vertical_position_into_account (it
);
19489 struct glyph
*glyph
;
19490 enum glyph_row_area area
= it
->area
;
19492 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19493 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19495 glyph
->charpos
= CHARPOS (it
->position
);
19496 glyph
->object
= it
->object
;
19497 glyph
->pixel_width
= it
->pixel_width
;
19498 glyph
->ascent
= glyph_ascent
;
19499 glyph
->descent
= it
->descent
;
19500 glyph
->voffset
= it
->voffset
;
19501 glyph
->type
= IMAGE_GLYPH
;
19502 glyph
->multibyte_p
= it
->multibyte_p
;
19503 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19504 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19505 glyph
->overlaps_vertically_p
= 0;
19506 glyph
->padding_p
= 0;
19507 glyph
->glyph_not_available_p
= 0;
19508 glyph
->face_id
= it
->face_id
;
19509 glyph
->u
.img_id
= img
->id
;
19510 glyph
->slice
= slice
;
19511 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19512 ++it
->glyph_row
->used
[area
];
19515 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19520 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19521 of the glyph, WIDTH and HEIGHT are the width and height of the
19522 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19525 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19527 Lisp_Object object
;
19531 struct glyph
*glyph
;
19532 enum glyph_row_area area
= it
->area
;
19534 xassert (ascent
>= 0 && ascent
<= height
);
19536 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19537 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19539 glyph
->charpos
= CHARPOS (it
->position
);
19540 glyph
->object
= object
;
19541 glyph
->pixel_width
= width
;
19542 glyph
->ascent
= ascent
;
19543 glyph
->descent
= height
- ascent
;
19544 glyph
->voffset
= it
->voffset
;
19545 glyph
->type
= STRETCH_GLYPH
;
19546 glyph
->multibyte_p
= it
->multibyte_p
;
19547 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19548 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19549 glyph
->overlaps_vertically_p
= 0;
19550 glyph
->padding_p
= 0;
19551 glyph
->glyph_not_available_p
= 0;
19552 glyph
->face_id
= it
->face_id
;
19553 glyph
->u
.stretch
.ascent
= ascent
;
19554 glyph
->u
.stretch
.height
= height
;
19555 glyph
->slice
= null_glyph_slice
;
19556 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19557 ++it
->glyph_row
->used
[area
];
19560 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19564 /* Produce a stretch glyph for iterator IT. IT->object is the value
19565 of the glyph property displayed. The value must be a list
19566 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19569 1. `:width WIDTH' specifies that the space should be WIDTH *
19570 canonical char width wide. WIDTH may be an integer or floating
19573 2. `:relative-width FACTOR' specifies that the width of the stretch
19574 should be computed from the width of the first character having the
19575 `glyph' property, and should be FACTOR times that width.
19577 3. `:align-to HPOS' specifies that the space should be wide enough
19578 to reach HPOS, a value in canonical character units.
19580 Exactly one of the above pairs must be present.
19582 4. `:height HEIGHT' specifies that the height of the stretch produced
19583 should be HEIGHT, measured in canonical character units.
19585 5. `:relative-height FACTOR' specifies that the height of the
19586 stretch should be FACTOR times the height of the characters having
19587 the glyph property.
19589 Either none or exactly one of 4 or 5 must be present.
19591 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19592 of the stretch should be used for the ascent of the stretch.
19593 ASCENT must be in the range 0 <= ASCENT <= 100. */
19596 produce_stretch_glyph (it
)
19599 /* (space :width WIDTH :height HEIGHT ...) */
19600 Lisp_Object prop
, plist
;
19601 int width
= 0, height
= 0, align_to
= -1;
19602 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19605 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19606 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19608 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19610 /* List should start with `space'. */
19611 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19612 plist
= XCDR (it
->object
);
19614 /* Compute the width of the stretch. */
19615 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19616 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19618 /* Absolute width `:width WIDTH' specified and valid. */
19619 zero_width_ok_p
= 1;
19622 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19625 /* Relative width `:relative-width FACTOR' specified and valid.
19626 Compute the width of the characters having the `glyph'
19629 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19632 if (it
->multibyte_p
)
19634 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19635 - IT_BYTEPOS (*it
));
19636 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19639 it2
.c
= *p
, it2
.len
= 1;
19641 it2
.glyph_row
= NULL
;
19642 it2
.what
= IT_CHARACTER
;
19643 x_produce_glyphs (&it2
);
19644 width
= NUMVAL (prop
) * it2
.pixel_width
;
19646 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19647 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19649 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19650 align_to
= (align_to
< 0
19652 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19653 else if (align_to
< 0)
19654 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19655 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19656 zero_width_ok_p
= 1;
19659 /* Nothing specified -> width defaults to canonical char width. */
19660 width
= FRAME_COLUMN_WIDTH (it
->f
);
19662 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19665 /* Compute height. */
19666 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19667 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19670 zero_height_ok_p
= 1;
19672 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19674 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19676 height
= FONT_HEIGHT (font
);
19678 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19681 /* Compute percentage of height used for ascent. If
19682 `:ascent ASCENT' is present and valid, use that. Otherwise,
19683 derive the ascent from the font in use. */
19684 if (prop
= Fplist_get (plist
, QCascent
),
19685 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19686 ascent
= height
* NUMVAL (prop
) / 100.0;
19687 else if (!NILP (prop
)
19688 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19689 ascent
= min (max (0, (int)tem
), height
);
19691 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19693 if (width
> 0 && height
> 0 && it
->glyph_row
)
19695 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19696 if (!STRINGP (object
))
19697 object
= it
->w
->buffer
;
19698 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19701 it
->pixel_width
= width
;
19702 it
->ascent
= it
->phys_ascent
= ascent
;
19703 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19704 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19706 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
19708 if (face
->box_line_width
> 0)
19710 it
->ascent
+= face
->box_line_width
;
19711 it
->descent
+= face
->box_line_width
;
19714 if (it
->start_of_box_run_p
)
19715 it
->pixel_width
+= abs (face
->box_line_width
);
19716 if (it
->end_of_box_run_p
)
19717 it
->pixel_width
+= abs (face
->box_line_width
);
19720 take_vertical_position_into_account (it
);
19723 /* Get line-height and line-spacing property at point.
19724 If line-height has format (HEIGHT TOTAL), return TOTAL
19725 in TOTAL_HEIGHT. */
19728 get_line_height_property (it
, prop
)
19732 Lisp_Object position
;
19734 if (STRINGP (it
->object
))
19735 position
= make_number (IT_STRING_CHARPOS (*it
));
19736 else if (BUFFERP (it
->object
))
19737 position
= make_number (IT_CHARPOS (*it
));
19741 return Fget_char_property (position
, prop
, it
->object
);
19744 /* Calculate line-height and line-spacing properties.
19745 An integer value specifies explicit pixel value.
19746 A float value specifies relative value to current face height.
19747 A cons (float . face-name) specifies relative value to
19748 height of specified face font.
19750 Returns height in pixels, or nil. */
19754 calc_line_height_property (it
, val
, font
, boff
, override
)
19758 int boff
, override
;
19760 Lisp_Object face_name
= Qnil
;
19761 int ascent
, descent
, height
;
19763 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19768 face_name
= XCAR (val
);
19770 if (!NUMBERP (val
))
19771 val
= make_number (1);
19772 if (NILP (face_name
))
19774 height
= it
->ascent
+ it
->descent
;
19779 if (NILP (face_name
))
19781 font
= FRAME_FONT (it
->f
);
19782 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19784 else if (EQ (face_name
, Qt
))
19792 struct font_info
*font_info
;
19794 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19796 return make_number (-1);
19798 face
= FACE_FROM_ID (it
->f
, face_id
);
19801 return make_number (-1);
19803 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19804 boff
= font_info
->baseline_offset
;
19805 if (font_info
->vertical_centering
)
19806 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19809 ascent
= FONT_BASE (font
) + boff
;
19810 descent
= FONT_DESCENT (font
) - boff
;
19814 it
->override_ascent
= ascent
;
19815 it
->override_descent
= descent
;
19816 it
->override_boff
= boff
;
19819 height
= ascent
+ descent
;
19823 height
= (int)(XFLOAT_DATA (val
) * height
);
19824 else if (INTEGERP (val
))
19825 height
*= XINT (val
);
19827 return make_number (height
);
19832 Produce glyphs/get display metrics for the display element IT is
19833 loaded with. See the description of struct display_iterator in
19834 dispextern.h for an overview of struct display_iterator. */
19837 x_produce_glyphs (it
)
19840 int extra_line_spacing
= it
->extra_line_spacing
;
19842 it
->glyph_not_available_p
= 0;
19844 if (it
->what
== IT_CHARACTER
)
19848 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19850 int font_not_found_p
;
19851 struct font_info
*font_info
;
19852 int boff
; /* baseline offset */
19853 /* We may change it->multibyte_p upon unibyte<->multibyte
19854 conversion. So, save the current value now and restore it
19857 Note: It seems that we don't have to record multibyte_p in
19858 struct glyph because the character code itself tells if or
19859 not the character is multibyte. Thus, in the future, we must
19860 consider eliminating the field `multibyte_p' in the struct
19862 int saved_multibyte_p
= it
->multibyte_p
;
19864 /* Maybe translate single-byte characters to multibyte, or the
19866 it
->char_to_display
= it
->c
;
19867 if (!ASCII_BYTE_P (it
->c
))
19869 if (unibyte_display_via_language_environment
19870 && SINGLE_BYTE_CHAR_P (it
->c
)
19872 || !NILP (Vnonascii_translation_table
)))
19874 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19875 it
->multibyte_p
= 1;
19876 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19877 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19879 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19880 && !it
->multibyte_p
)
19882 it
->multibyte_p
= 1;
19883 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19884 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19888 /* Get font to use. Encode IT->char_to_display. */
19889 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19890 &char2b
, it
->multibyte_p
, 0);
19893 /* When no suitable font found, use the default font. */
19894 font_not_found_p
= font
== NULL
;
19895 if (font_not_found_p
)
19897 font
= FRAME_FONT (it
->f
);
19898 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19903 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19904 boff
= font_info
->baseline_offset
;
19905 if (font_info
->vertical_centering
)
19906 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19909 if (it
->char_to_display
>= ' '
19910 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19912 /* Either unibyte or ASCII. */
19917 pcm
= FRAME_RIF (it
->f
)->per_char_metric
19918 (font
, &char2b
, FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19920 if (it
->override_ascent
>= 0)
19922 it
->ascent
= it
->override_ascent
;
19923 it
->descent
= it
->override_descent
;
19924 boff
= it
->override_boff
;
19928 it
->ascent
= FONT_BASE (font
) + boff
;
19929 it
->descent
= FONT_DESCENT (font
) - boff
;
19934 it
->phys_ascent
= pcm
->ascent
+ boff
;
19935 it
->phys_descent
= pcm
->descent
- boff
;
19936 it
->pixel_width
= pcm
->width
;
19940 it
->glyph_not_available_p
= 1;
19941 it
->phys_ascent
= it
->ascent
;
19942 it
->phys_descent
= it
->descent
;
19943 it
->pixel_width
= FONT_WIDTH (font
);
19946 if (it
->constrain_row_ascent_descent_p
)
19948 if (it
->descent
> it
->max_descent
)
19950 it
->ascent
+= it
->descent
- it
->max_descent
;
19951 it
->descent
= it
->max_descent
;
19953 if (it
->ascent
> it
->max_ascent
)
19955 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19956 it
->ascent
= it
->max_ascent
;
19958 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19959 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19960 extra_line_spacing
= 0;
19963 /* If this is a space inside a region of text with
19964 `space-width' property, change its width. */
19965 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19967 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19969 /* If face has a box, add the box thickness to the character
19970 height. If character has a box line to the left and/or
19971 right, add the box line width to the character's width. */
19972 if (face
->box
!= FACE_NO_BOX
)
19974 int thick
= face
->box_line_width
;
19978 it
->ascent
+= thick
;
19979 it
->descent
+= thick
;
19984 if (it
->start_of_box_run_p
)
19985 it
->pixel_width
+= thick
;
19986 if (it
->end_of_box_run_p
)
19987 it
->pixel_width
+= thick
;
19990 /* If face has an overline, add the height of the overline
19991 (1 pixel) and a 1 pixel margin to the character height. */
19992 if (face
->overline_p
)
19995 if (it
->constrain_row_ascent_descent_p
)
19997 if (it
->ascent
> it
->max_ascent
)
19998 it
->ascent
= it
->max_ascent
;
19999 if (it
->descent
> it
->max_descent
)
20000 it
->descent
= it
->max_descent
;
20003 take_vertical_position_into_account (it
);
20005 /* If we have to actually produce glyphs, do it. */
20010 /* Translate a space with a `space-width' property
20011 into a stretch glyph. */
20012 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20013 / FONT_HEIGHT (font
));
20014 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20015 it
->ascent
+ it
->descent
, ascent
);
20020 /* If characters with lbearing or rbearing are displayed
20021 in this line, record that fact in a flag of the
20022 glyph row. This is used to optimize X output code. */
20023 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20024 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20027 else if (it
->char_to_display
== '\n')
20029 /* A newline has no width but we need the height of the line.
20030 But if previous part of the line set a height, don't
20031 increase that height */
20033 Lisp_Object height
;
20034 Lisp_Object total_height
= Qnil
;
20036 it
->override_ascent
= -1;
20037 it
->pixel_width
= 0;
20040 height
= get_line_height_property(it
, Qline_height
);
20041 /* Split (line-height total-height) list */
20043 && CONSP (XCDR (height
))
20044 && NILP (XCDR (XCDR (height
))))
20046 total_height
= XCAR (XCDR (height
));
20047 height
= XCAR (height
);
20049 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20051 if (it
->override_ascent
>= 0)
20053 it
->ascent
= it
->override_ascent
;
20054 it
->descent
= it
->override_descent
;
20055 boff
= it
->override_boff
;
20059 it
->ascent
= FONT_BASE (font
) + boff
;
20060 it
->descent
= FONT_DESCENT (font
) - boff
;
20063 if (EQ (height
, Qt
))
20065 if (it
->descent
> it
->max_descent
)
20067 it
->ascent
+= it
->descent
- it
->max_descent
;
20068 it
->descent
= it
->max_descent
;
20070 if (it
->ascent
> it
->max_ascent
)
20072 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20073 it
->ascent
= it
->max_ascent
;
20075 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20076 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20077 it
->constrain_row_ascent_descent_p
= 1;
20078 extra_line_spacing
= 0;
20082 Lisp_Object spacing
;
20084 it
->phys_ascent
= it
->ascent
;
20085 it
->phys_descent
= it
->descent
;
20087 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20088 && face
->box
!= FACE_NO_BOX
20089 && face
->box_line_width
> 0)
20091 it
->ascent
+= face
->box_line_width
;
20092 it
->descent
+= face
->box_line_width
;
20095 && XINT (height
) > it
->ascent
+ it
->descent
)
20096 it
->ascent
= XINT (height
) - it
->descent
;
20098 if (!NILP (total_height
))
20099 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20102 spacing
= get_line_height_property(it
, Qline_spacing
);
20103 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20105 if (INTEGERP (spacing
))
20107 extra_line_spacing
= XINT (spacing
);
20108 if (!NILP (total_height
))
20109 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20113 else if (it
->char_to_display
== '\t')
20115 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20116 int x
= it
->current_x
+ it
->continuation_lines_width
;
20117 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20119 /* If the distance from the current position to the next tab
20120 stop is less than a space character width, use the
20121 tab stop after that. */
20122 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20123 next_tab_x
+= tab_width
;
20125 it
->pixel_width
= next_tab_x
- x
;
20127 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20128 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20132 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20133 it
->ascent
+ it
->descent
, it
->ascent
);
20138 /* A multi-byte character. Assume that the display width of the
20139 character is the width of the character multiplied by the
20140 width of the font. */
20142 /* If we found a font, this font should give us the right
20143 metrics. If we didn't find a font, use the frame's
20144 default font and calculate the width of the character
20145 from the charset width; this is what old redisplay code
20148 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20149 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20151 if (font_not_found_p
|| !pcm
)
20153 int charset
= CHAR_CHARSET (it
->char_to_display
);
20155 it
->glyph_not_available_p
= 1;
20156 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20157 * CHARSET_WIDTH (charset
));
20158 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20159 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20163 it
->pixel_width
= pcm
->width
;
20164 it
->phys_ascent
= pcm
->ascent
+ boff
;
20165 it
->phys_descent
= pcm
->descent
- boff
;
20167 && (pcm
->lbearing
< 0
20168 || pcm
->rbearing
> pcm
->width
))
20169 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20172 it
->ascent
= FONT_BASE (font
) + boff
;
20173 it
->descent
= FONT_DESCENT (font
) - boff
;
20174 if (face
->box
!= FACE_NO_BOX
)
20176 int thick
= face
->box_line_width
;
20180 it
->ascent
+= thick
;
20181 it
->descent
+= thick
;
20186 if (it
->start_of_box_run_p
)
20187 it
->pixel_width
+= thick
;
20188 if (it
->end_of_box_run_p
)
20189 it
->pixel_width
+= thick
;
20192 /* If face has an overline, add the height of the overline
20193 (1 pixel) and a 1 pixel margin to the character height. */
20194 if (face
->overline_p
)
20197 take_vertical_position_into_account (it
);
20202 it
->multibyte_p
= saved_multibyte_p
;
20204 else if (it
->what
== IT_COMPOSITION
)
20206 /* Note: A composition is represented as one glyph in the
20207 glyph matrix. There are no padding glyphs. */
20210 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20212 int font_not_found_p
;
20213 struct font_info
*font_info
;
20214 int boff
; /* baseline offset */
20215 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20217 /* Maybe translate single-byte characters to multibyte. */
20218 it
->char_to_display
= it
->c
;
20219 if (unibyte_display_via_language_environment
20220 && SINGLE_BYTE_CHAR_P (it
->c
)
20223 && !NILP (Vnonascii_translation_table
))))
20225 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20228 /* Get face and font to use. Encode IT->char_to_display. */
20229 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20230 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20231 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20232 &char2b
, it
->multibyte_p
, 0);
20235 /* When no suitable font found, use the default font. */
20236 font_not_found_p
= font
== NULL
;
20237 if (font_not_found_p
)
20239 font
= FRAME_FONT (it
->f
);
20240 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20245 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20246 boff
= font_info
->baseline_offset
;
20247 if (font_info
->vertical_centering
)
20248 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20251 /* There are no padding glyphs, so there is only one glyph to
20252 produce for the composition. Important is that pixel_width,
20253 ascent and descent are the values of what is drawn by
20254 draw_glyphs (i.e. the values of the overall glyphs composed). */
20257 /* If we have not yet calculated pixel size data of glyphs of
20258 the composition for the current face font, calculate them
20259 now. Theoretically, we have to check all fonts for the
20260 glyphs, but that requires much time and memory space. So,
20261 here we check only the font of the first glyph. This leads
20262 to incorrect display very rarely, and C-l (recenter) can
20263 correct the display anyway. */
20264 if (cmp
->font
!= (void *) font
)
20266 /* Ascent and descent of the font of the first character of
20267 this composition (adjusted by baseline offset). Ascent
20268 and descent of overall glyphs should not be less than
20269 them respectively. */
20270 int font_ascent
= FONT_BASE (font
) + boff
;
20271 int font_descent
= FONT_DESCENT (font
) - boff
;
20272 /* Bounding box of the overall glyphs. */
20273 int leftmost
, rightmost
, lowest
, highest
;
20274 int i
, width
, ascent
, descent
;
20276 cmp
->font
= (void *) font
;
20278 /* Initialize the bounding box. */
20280 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20281 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20283 width
= pcm
->width
;
20284 ascent
= pcm
->ascent
;
20285 descent
= pcm
->descent
;
20289 width
= FONT_WIDTH (font
);
20290 ascent
= FONT_BASE (font
);
20291 descent
= FONT_DESCENT (font
);
20295 lowest
= - descent
+ boff
;
20296 highest
= ascent
+ boff
;
20300 && font_info
->default_ascent
20301 && CHAR_TABLE_P (Vuse_default_ascent
)
20302 && !NILP (Faref (Vuse_default_ascent
,
20303 make_number (it
->char_to_display
))))
20304 highest
= font_info
->default_ascent
+ boff
;
20306 /* Draw the first glyph at the normal position. It may be
20307 shifted to right later if some other glyphs are drawn at
20309 cmp
->offsets
[0] = 0;
20310 cmp
->offsets
[1] = boff
;
20312 /* Set cmp->offsets for the remaining glyphs. */
20313 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20315 int left
, right
, btm
, top
;
20316 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20317 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20319 face
= FACE_FROM_ID (it
->f
, face_id
);
20320 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20321 &char2b
, it
->multibyte_p
, 0);
20325 font
= FRAME_FONT (it
->f
);
20326 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20332 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20333 boff
= font_info
->baseline_offset
;
20334 if (font_info
->vertical_centering
)
20335 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20339 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20340 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20342 width
= pcm
->width
;
20343 ascent
= pcm
->ascent
;
20344 descent
= pcm
->descent
;
20348 width
= FONT_WIDTH (font
);
20353 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20355 /* Relative composition with or without
20356 alternate chars. */
20357 left
= (leftmost
+ rightmost
- width
) / 2;
20358 btm
= - descent
+ boff
;
20359 if (font_info
&& font_info
->relative_compose
20360 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20361 || NILP (Faref (Vignore_relative_composition
,
20362 make_number (ch
)))))
20365 if (- descent
>= font_info
->relative_compose
)
20366 /* One extra pixel between two glyphs. */
20368 else if (ascent
<= 0)
20369 /* One extra pixel between two glyphs. */
20370 btm
= lowest
- 1 - ascent
- descent
;
20375 /* A composition rule is specified by an integer
20376 value that encodes global and new reference
20377 points (GREF and NREF). GREF and NREF are
20378 specified by numbers as below:
20380 0---1---2 -- ascent
20384 9--10--11 -- center
20386 ---3---4---5--- baseline
20388 6---7---8 -- descent
20390 int rule
= COMPOSITION_RULE (cmp
, i
);
20391 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20393 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20394 grefx
= gref
% 3, nrefx
= nref
% 3;
20395 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20398 + grefx
* (rightmost
- leftmost
) / 2
20399 - nrefx
* width
/ 2);
20400 btm
= ((grefy
== 0 ? highest
20402 : grefy
== 2 ? lowest
20403 : (highest
+ lowest
) / 2)
20404 - (nrefy
== 0 ? ascent
+ descent
20405 : nrefy
== 1 ? descent
- boff
20407 : (ascent
+ descent
) / 2));
20410 cmp
->offsets
[i
* 2] = left
;
20411 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20413 /* Update the bounding box of the overall glyphs. */
20414 right
= left
+ width
;
20415 top
= btm
+ descent
+ ascent
;
20416 if (left
< leftmost
)
20418 if (right
> rightmost
)
20426 /* If there are glyphs whose x-offsets are negative,
20427 shift all glyphs to the right and make all x-offsets
20431 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20432 cmp
->offsets
[i
* 2] -= leftmost
;
20433 rightmost
-= leftmost
;
20436 cmp
->pixel_width
= rightmost
;
20437 cmp
->ascent
= highest
;
20438 cmp
->descent
= - lowest
;
20439 if (cmp
->ascent
< font_ascent
)
20440 cmp
->ascent
= font_ascent
;
20441 if (cmp
->descent
< font_descent
)
20442 cmp
->descent
= font_descent
;
20445 it
->pixel_width
= cmp
->pixel_width
;
20446 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20447 it
->descent
= it
->phys_descent
= cmp
->descent
;
20449 if (face
->box
!= FACE_NO_BOX
)
20451 int thick
= face
->box_line_width
;
20455 it
->ascent
+= thick
;
20456 it
->descent
+= thick
;
20461 if (it
->start_of_box_run_p
)
20462 it
->pixel_width
+= thick
;
20463 if (it
->end_of_box_run_p
)
20464 it
->pixel_width
+= thick
;
20467 /* If face has an overline, add the height of the overline
20468 (1 pixel) and a 1 pixel margin to the character height. */
20469 if (face
->overline_p
)
20472 take_vertical_position_into_account (it
);
20475 append_composite_glyph (it
);
20477 else if (it
->what
== IT_IMAGE
)
20478 produce_image_glyph (it
);
20479 else if (it
->what
== IT_STRETCH
)
20480 produce_stretch_glyph (it
);
20482 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20483 because this isn't true for images with `:ascent 100'. */
20484 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20485 if (it
->area
== TEXT_AREA
)
20486 it
->current_x
+= it
->pixel_width
;
20488 if (extra_line_spacing
> 0)
20490 it
->descent
+= extra_line_spacing
;
20491 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20492 it
->max_extra_line_spacing
= extra_line_spacing
;
20495 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20496 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20497 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20498 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20502 Output LEN glyphs starting at START at the nominal cursor position.
20503 Advance the nominal cursor over the text. The global variable
20504 updated_window contains the window being updated, updated_row is
20505 the glyph row being updated, and updated_area is the area of that
20506 row being updated. */
20509 x_write_glyphs (start
, len
)
20510 struct glyph
*start
;
20515 xassert (updated_window
&& updated_row
);
20518 /* Write glyphs. */
20520 hpos
= start
- updated_row
->glyphs
[updated_area
];
20521 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20522 updated_row
, updated_area
,
20524 DRAW_NORMAL_TEXT
, 0);
20526 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20527 if (updated_area
== TEXT_AREA
20528 && updated_window
->phys_cursor_on_p
20529 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20530 && updated_window
->phys_cursor
.hpos
>= hpos
20531 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20532 updated_window
->phys_cursor_on_p
= 0;
20536 /* Advance the output cursor. */
20537 output_cursor
.hpos
+= len
;
20538 output_cursor
.x
= x
;
20543 Insert LEN glyphs from START at the nominal cursor position. */
20546 x_insert_glyphs (start
, len
)
20547 struct glyph
*start
;
20552 int line_height
, shift_by_width
, shifted_region_width
;
20553 struct glyph_row
*row
;
20554 struct glyph
*glyph
;
20555 int frame_x
, frame_y
, hpos
;
20557 xassert (updated_window
&& updated_row
);
20559 w
= updated_window
;
20560 f
= XFRAME (WINDOW_FRAME (w
));
20562 /* Get the height of the line we are in. */
20564 line_height
= row
->height
;
20566 /* Get the width of the glyphs to insert. */
20567 shift_by_width
= 0;
20568 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20569 shift_by_width
+= glyph
->pixel_width
;
20571 /* Get the width of the region to shift right. */
20572 shifted_region_width
= (window_box_width (w
, updated_area
)
20577 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20578 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20580 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20581 line_height
, shift_by_width
);
20583 /* Write the glyphs. */
20584 hpos
= start
- row
->glyphs
[updated_area
];
20585 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20587 DRAW_NORMAL_TEXT
, 0);
20589 /* Advance the output cursor. */
20590 output_cursor
.hpos
+= len
;
20591 output_cursor
.x
+= shift_by_width
;
20597 Erase the current text line from the nominal cursor position
20598 (inclusive) to pixel column TO_X (exclusive). The idea is that
20599 everything from TO_X onward is already erased.
20601 TO_X is a pixel position relative to updated_area of
20602 updated_window. TO_X == -1 means clear to the end of this area. */
20605 x_clear_end_of_line (to_x
)
20609 struct window
*w
= updated_window
;
20610 int max_x
, min_y
, max_y
;
20611 int from_x
, from_y
, to_y
;
20613 xassert (updated_window
&& updated_row
);
20614 f
= XFRAME (w
->frame
);
20616 if (updated_row
->full_width_p
)
20617 max_x
= WINDOW_TOTAL_WIDTH (w
);
20619 max_x
= window_box_width (w
, updated_area
);
20620 max_y
= window_text_bottom_y (w
);
20622 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20623 of window. For TO_X > 0, truncate to end of drawing area. */
20629 to_x
= min (to_x
, max_x
);
20631 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20633 /* Notice if the cursor will be cleared by this operation. */
20634 if (!updated_row
->full_width_p
)
20635 notice_overwritten_cursor (w
, updated_area
,
20636 output_cursor
.x
, -1,
20638 MATRIX_ROW_BOTTOM_Y (updated_row
));
20640 from_x
= output_cursor
.x
;
20642 /* Translate to frame coordinates. */
20643 if (updated_row
->full_width_p
)
20645 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20646 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20650 int area_left
= window_box_left (w
, updated_area
);
20651 from_x
+= area_left
;
20655 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20656 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20657 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20659 /* Prevent inadvertently clearing to end of the X window. */
20660 if (to_x
> from_x
&& to_y
> from_y
)
20663 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
20664 to_x
- from_x
, to_y
- from_y
);
20669 #endif /* HAVE_WINDOW_SYSTEM */
20673 /***********************************************************************
20675 ***********************************************************************/
20677 /* Value is the internal representation of the specified cursor type
20678 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20679 of the bar cursor. */
20681 static enum text_cursor_kinds
20682 get_specified_cursor_type (arg
, width
)
20686 enum text_cursor_kinds type
;
20691 if (EQ (arg
, Qbox
))
20692 return FILLED_BOX_CURSOR
;
20694 if (EQ (arg
, Qhollow
))
20695 return HOLLOW_BOX_CURSOR
;
20697 if (EQ (arg
, Qbar
))
20704 && EQ (XCAR (arg
), Qbar
)
20705 && INTEGERP (XCDR (arg
))
20706 && XINT (XCDR (arg
)) >= 0)
20708 *width
= XINT (XCDR (arg
));
20712 if (EQ (arg
, Qhbar
))
20715 return HBAR_CURSOR
;
20719 && EQ (XCAR (arg
), Qhbar
)
20720 && INTEGERP (XCDR (arg
))
20721 && XINT (XCDR (arg
)) >= 0)
20723 *width
= XINT (XCDR (arg
));
20724 return HBAR_CURSOR
;
20727 /* Treat anything unknown as "hollow box cursor".
20728 It was bad to signal an error; people have trouble fixing
20729 .Xdefaults with Emacs, when it has something bad in it. */
20730 type
= HOLLOW_BOX_CURSOR
;
20735 /* Set the default cursor types for specified frame. */
20737 set_frame_cursor_types (f
, arg
)
20744 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20745 FRAME_CURSOR_WIDTH (f
) = width
;
20747 /* By default, set up the blink-off state depending on the on-state. */
20749 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20752 FRAME_BLINK_OFF_CURSOR (f
)
20753 = get_specified_cursor_type (XCDR (tem
), &width
);
20754 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20757 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20761 /* Return the cursor we want to be displayed in window W. Return
20762 width of bar/hbar cursor through WIDTH arg. Return with
20763 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20764 (i.e. if the `system caret' should track this cursor).
20766 In a mini-buffer window, we want the cursor only to appear if we
20767 are reading input from this window. For the selected window, we
20768 want the cursor type given by the frame parameter or buffer local
20769 setting of cursor-type. If explicitly marked off, draw no cursor.
20770 In all other cases, we want a hollow box cursor. */
20772 static enum text_cursor_kinds
20773 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20775 struct glyph
*glyph
;
20777 int *active_cursor
;
20779 struct frame
*f
= XFRAME (w
->frame
);
20780 struct buffer
*b
= XBUFFER (w
->buffer
);
20781 int cursor_type
= DEFAULT_CURSOR
;
20782 Lisp_Object alt_cursor
;
20783 int non_selected
= 0;
20785 *active_cursor
= 1;
20788 if (cursor_in_echo_area
20789 && FRAME_HAS_MINIBUF_P (f
)
20790 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20792 if (w
== XWINDOW (echo_area_window
))
20794 *width
= FRAME_CURSOR_WIDTH (f
);
20795 return FRAME_DESIRED_CURSOR (f
);
20798 *active_cursor
= 0;
20802 /* Nonselected window or nonselected frame. */
20803 else if (w
!= XWINDOW (f
->selected_window
)
20804 #ifdef HAVE_WINDOW_SYSTEM
20805 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20809 *active_cursor
= 0;
20811 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20817 /* Never display a cursor in a window in which cursor-type is nil. */
20818 if (NILP (b
->cursor_type
))
20821 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20824 alt_cursor
= b
->cursor_in_non_selected_windows
;
20825 return get_specified_cursor_type (alt_cursor
, width
);
20828 /* Get the normal cursor type for this window. */
20829 if (EQ (b
->cursor_type
, Qt
))
20831 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20832 *width
= FRAME_CURSOR_WIDTH (f
);
20835 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20837 /* Use normal cursor if not blinked off. */
20838 if (!w
->cursor_off_p
)
20840 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20841 if (cursor_type
== FILLED_BOX_CURSOR
)
20842 cursor_type
= HOLLOW_BOX_CURSOR
;
20844 return cursor_type
;
20847 /* Cursor is blinked off, so determine how to "toggle" it. */
20849 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20850 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20851 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20853 /* Then see if frame has specified a specific blink off cursor type. */
20854 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20856 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20857 return FRAME_BLINK_OFF_CURSOR (f
);
20861 /* Some people liked having a permanently visible blinking cursor,
20862 while others had very strong opinions against it. So it was
20863 decided to remove it. KFS 2003-09-03 */
20865 /* Finally perform built-in cursor blinking:
20866 filled box <-> hollow box
20867 wide [h]bar <-> narrow [h]bar
20868 narrow [h]bar <-> no cursor
20869 other type <-> no cursor */
20871 if (cursor_type
== FILLED_BOX_CURSOR
)
20872 return HOLLOW_BOX_CURSOR
;
20874 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20877 return cursor_type
;
20885 #ifdef HAVE_WINDOW_SYSTEM
20887 /* Notice when the text cursor of window W has been completely
20888 overwritten by a drawing operation that outputs glyphs in AREA
20889 starting at X0 and ending at X1 in the line starting at Y0 and
20890 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20891 the rest of the line after X0 has been written. Y coordinates
20892 are window-relative. */
20895 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20897 enum glyph_row_area area
;
20898 int x0
, y0
, x1
, y1
;
20900 int cx0
, cx1
, cy0
, cy1
;
20901 struct glyph_row
*row
;
20903 if (!w
->phys_cursor_on_p
)
20905 if (area
!= TEXT_AREA
)
20908 if (w
->phys_cursor
.vpos
< 0
20909 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
20910 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
20911 !(row
->enabled_p
&& row
->displays_text_p
)))
20914 if (row
->cursor_in_fringe_p
)
20916 row
->cursor_in_fringe_p
= 0;
20917 draw_fringe_bitmap (w
, row
, 0);
20918 w
->phys_cursor_on_p
= 0;
20922 cx0
= w
->phys_cursor
.x
;
20923 cx1
= cx0
+ w
->phys_cursor_width
;
20924 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20927 /* The cursor image will be completely removed from the
20928 screen if the output area intersects the cursor area in
20929 y-direction. When we draw in [y0 y1[, and some part of
20930 the cursor is at y < y0, that part must have been drawn
20931 before. When scrolling, the cursor is erased before
20932 actually scrolling, so we don't come here. When not
20933 scrolling, the rows above the old cursor row must have
20934 changed, and in this case these rows must have written
20935 over the cursor image.
20937 Likewise if part of the cursor is below y1, with the
20938 exception of the cursor being in the first blank row at
20939 the buffer and window end because update_text_area
20940 doesn't draw that row. (Except when it does, but
20941 that's handled in update_text_area.) */
20943 cy0
= w
->phys_cursor
.y
;
20944 cy1
= cy0
+ w
->phys_cursor_height
;
20945 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20948 w
->phys_cursor_on_p
= 0;
20951 #endif /* HAVE_WINDOW_SYSTEM */
20954 /************************************************************************
20956 ************************************************************************/
20958 #ifdef HAVE_WINDOW_SYSTEM
20961 Fix the display of area AREA of overlapping row ROW in window W
20962 with respect to the overlapping part OVERLAPS. */
20965 x_fix_overlapping_area (w
, row
, area
, overlaps
)
20967 struct glyph_row
*row
;
20968 enum glyph_row_area area
;
20976 for (i
= 0; i
< row
->used
[area
];)
20978 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20980 int start
= i
, start_x
= x
;
20984 x
+= row
->glyphs
[area
][i
].pixel_width
;
20987 while (i
< row
->used
[area
]
20988 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20990 draw_glyphs (w
, start_x
, row
, area
,
20992 DRAW_NORMAL_TEXT
, overlaps
);
20996 x
+= row
->glyphs
[area
][i
].pixel_width
;
21006 Draw the cursor glyph of window W in glyph row ROW. See the
21007 comment of draw_glyphs for the meaning of HL. */
21010 draw_phys_cursor_glyph (w
, row
, hl
)
21012 struct glyph_row
*row
;
21013 enum draw_glyphs_face hl
;
21015 /* If cursor hpos is out of bounds, don't draw garbage. This can
21016 happen in mini-buffer windows when switching between echo area
21017 glyphs and mini-buffer. */
21018 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21020 int on_p
= w
->phys_cursor_on_p
;
21022 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21023 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21025 w
->phys_cursor_on_p
= on_p
;
21027 if (hl
== DRAW_CURSOR
)
21028 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21029 /* When we erase the cursor, and ROW is overlapped by other
21030 rows, make sure that these overlapping parts of other rows
21032 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21034 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21036 if (row
> w
->current_matrix
->rows
21037 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21038 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21039 OVERLAPS_ERASED_CURSOR
);
21041 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21042 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21043 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21044 OVERLAPS_ERASED_CURSOR
);
21051 Erase the image of a cursor of window W from the screen. */
21054 erase_phys_cursor (w
)
21057 struct frame
*f
= XFRAME (w
->frame
);
21058 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21059 int hpos
= w
->phys_cursor
.hpos
;
21060 int vpos
= w
->phys_cursor
.vpos
;
21061 int mouse_face_here_p
= 0;
21062 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21063 struct glyph_row
*cursor_row
;
21064 struct glyph
*cursor_glyph
;
21065 enum draw_glyphs_face hl
;
21067 /* No cursor displayed or row invalidated => nothing to do on the
21069 if (w
->phys_cursor_type
== NO_CURSOR
)
21070 goto mark_cursor_off
;
21072 /* VPOS >= active_glyphs->nrows means that window has been resized.
21073 Don't bother to erase the cursor. */
21074 if (vpos
>= active_glyphs
->nrows
)
21075 goto mark_cursor_off
;
21077 /* If row containing cursor is marked invalid, there is nothing we
21079 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21080 if (!cursor_row
->enabled_p
)
21081 goto mark_cursor_off
;
21083 /* If line spacing is > 0, old cursor may only be partially visible in
21084 window after split-window. So adjust visible height. */
21085 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21086 window_text_bottom_y (w
) - cursor_row
->y
);
21088 /* If row is completely invisible, don't attempt to delete a cursor which
21089 isn't there. This can happen if cursor is at top of a window, and
21090 we switch to a buffer with a header line in that window. */
21091 if (cursor_row
->visible_height
<= 0)
21092 goto mark_cursor_off
;
21094 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21095 if (cursor_row
->cursor_in_fringe_p
)
21097 cursor_row
->cursor_in_fringe_p
= 0;
21098 draw_fringe_bitmap (w
, cursor_row
, 0);
21099 goto mark_cursor_off
;
21102 /* This can happen when the new row is shorter than the old one.
21103 In this case, either draw_glyphs or clear_end_of_line
21104 should have cleared the cursor. Note that we wouldn't be
21105 able to erase the cursor in this case because we don't have a
21106 cursor glyph at hand. */
21107 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21108 goto mark_cursor_off
;
21110 /* If the cursor is in the mouse face area, redisplay that when
21111 we clear the cursor. */
21112 if (! NILP (dpyinfo
->mouse_face_window
)
21113 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21114 && (vpos
> dpyinfo
->mouse_face_beg_row
21115 || (vpos
== dpyinfo
->mouse_face_beg_row
21116 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21117 && (vpos
< dpyinfo
->mouse_face_end_row
21118 || (vpos
== dpyinfo
->mouse_face_end_row
21119 && hpos
< dpyinfo
->mouse_face_end_col
))
21120 /* Don't redraw the cursor's spot in mouse face if it is at the
21121 end of a line (on a newline). The cursor appears there, but
21122 mouse highlighting does not. */
21123 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21124 mouse_face_here_p
= 1;
21126 /* Maybe clear the display under the cursor. */
21127 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21130 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21133 cursor_glyph
= get_phys_cursor_glyph (w
);
21134 if (cursor_glyph
== NULL
)
21135 goto mark_cursor_off
;
21137 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
21138 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21139 width
= min (cursor_glyph
->pixel_width
,
21140 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
21142 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21145 /* Erase the cursor by redrawing the character underneath it. */
21146 if (mouse_face_here_p
)
21147 hl
= DRAW_MOUSE_FACE
;
21149 hl
= DRAW_NORMAL_TEXT
;
21150 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21153 w
->phys_cursor_on_p
= 0;
21154 w
->phys_cursor_type
= NO_CURSOR
;
21159 Display or clear cursor of window W. If ON is zero, clear the
21160 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21161 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21164 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21166 int on
, hpos
, vpos
, x
, y
;
21168 struct frame
*f
= XFRAME (w
->frame
);
21169 int new_cursor_type
;
21170 int new_cursor_width
;
21172 struct glyph_row
*glyph_row
;
21173 struct glyph
*glyph
;
21175 /* This is pointless on invisible frames, and dangerous on garbaged
21176 windows and frames; in the latter case, the frame or window may
21177 be in the midst of changing its size, and x and y may be off the
21179 if (! FRAME_VISIBLE_P (f
)
21180 || FRAME_GARBAGED_P (f
)
21181 || vpos
>= w
->current_matrix
->nrows
21182 || hpos
>= w
->current_matrix
->matrix_w
)
21185 /* If cursor is off and we want it off, return quickly. */
21186 if (!on
&& !w
->phys_cursor_on_p
)
21189 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21190 /* If cursor row is not enabled, we don't really know where to
21191 display the cursor. */
21192 if (!glyph_row
->enabled_p
)
21194 w
->phys_cursor_on_p
= 0;
21199 if (!glyph_row
->exact_window_width_line_p
21200 || hpos
< glyph_row
->used
[TEXT_AREA
])
21201 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21203 xassert (interrupt_input_blocked
);
21205 /* Set new_cursor_type to the cursor we want to be displayed. */
21206 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21207 &new_cursor_width
, &active_cursor
);
21209 /* If cursor is currently being shown and we don't want it to be or
21210 it is in the wrong place, or the cursor type is not what we want,
21212 if (w
->phys_cursor_on_p
21214 || w
->phys_cursor
.x
!= x
21215 || w
->phys_cursor
.y
!= y
21216 || new_cursor_type
!= w
->phys_cursor_type
21217 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21218 && new_cursor_width
!= w
->phys_cursor_width
)))
21219 erase_phys_cursor (w
);
21221 /* Don't check phys_cursor_on_p here because that flag is only set
21222 to zero in some cases where we know that the cursor has been
21223 completely erased, to avoid the extra work of erasing the cursor
21224 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21225 still not be visible, or it has only been partly erased. */
21228 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21229 w
->phys_cursor_height
= glyph_row
->height
;
21231 /* Set phys_cursor_.* before x_draw_.* is called because some
21232 of them may need the information. */
21233 w
->phys_cursor
.x
= x
;
21234 w
->phys_cursor
.y
= glyph_row
->y
;
21235 w
->phys_cursor
.hpos
= hpos
;
21236 w
->phys_cursor
.vpos
= vpos
;
21239 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
21240 new_cursor_type
, new_cursor_width
,
21241 on
, active_cursor
);
21245 /* Switch the display of W's cursor on or off, according to the value
21249 update_window_cursor (w
, on
)
21253 /* Don't update cursor in windows whose frame is in the process
21254 of being deleted. */
21255 if (w
->current_matrix
)
21258 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21259 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21265 /* Call update_window_cursor with parameter ON_P on all leaf windows
21266 in the window tree rooted at W. */
21269 update_cursor_in_window_tree (w
, on_p
)
21275 if (!NILP (w
->hchild
))
21276 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21277 else if (!NILP (w
->vchild
))
21278 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21280 update_window_cursor (w
, on_p
);
21282 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21288 Display the cursor on window W, or clear it, according to ON_P.
21289 Don't change the cursor's position. */
21292 x_update_cursor (f
, on_p
)
21296 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21301 Clear the cursor of window W to background color, and mark the
21302 cursor as not shown. This is used when the text where the cursor
21303 is is about to be rewritten. */
21309 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21310 update_window_cursor (w
, 0);
21315 Display the active region described by mouse_face_* according to DRAW. */
21318 show_mouse_face (dpyinfo
, draw
)
21319 Display_Info
*dpyinfo
;
21320 enum draw_glyphs_face draw
;
21322 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21323 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21325 if (/* If window is in the process of being destroyed, don't bother
21327 w
->current_matrix
!= NULL
21328 /* Don't update mouse highlight if hidden */
21329 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21330 /* Recognize when we are called to operate on rows that don't exist
21331 anymore. This can happen when a window is split. */
21332 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21334 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21335 struct glyph_row
*row
, *first
, *last
;
21337 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21338 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21340 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21342 int start_hpos
, end_hpos
, start_x
;
21344 /* For all but the first row, the highlight starts at column 0. */
21347 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21348 start_x
= dpyinfo
->mouse_face_beg_x
;
21357 end_hpos
= dpyinfo
->mouse_face_end_col
;
21360 end_hpos
= row
->used
[TEXT_AREA
];
21361 if (draw
== DRAW_NORMAL_TEXT
)
21362 row
->fill_line_p
= 1; /* Clear to end of line */
21365 if (end_hpos
> start_hpos
)
21367 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21368 start_hpos
, end_hpos
,
21372 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21376 /* When we've written over the cursor, arrange for it to
21377 be displayed again. */
21378 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21381 display_and_set_cursor (w
, 1,
21382 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21383 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21388 /* Change the mouse cursor. */
21389 if (draw
== DRAW_NORMAL_TEXT
)
21390 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21391 else if (draw
== DRAW_MOUSE_FACE
)
21392 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21394 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21398 Clear out the mouse-highlighted active region.
21399 Redraw it un-highlighted first. Value is non-zero if mouse
21400 face was actually drawn unhighlighted. */
21403 clear_mouse_face (dpyinfo
)
21404 Display_Info
*dpyinfo
;
21408 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21410 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21414 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21415 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21416 dpyinfo
->mouse_face_window
= Qnil
;
21417 dpyinfo
->mouse_face_overlay
= Qnil
;
21423 Non-zero if physical cursor of window W is within mouse face. */
21426 cursor_in_mouse_face_p (w
)
21429 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21430 int in_mouse_face
= 0;
21432 if (WINDOWP (dpyinfo
->mouse_face_window
)
21433 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21435 int hpos
= w
->phys_cursor
.hpos
;
21436 int vpos
= w
->phys_cursor
.vpos
;
21438 if (vpos
>= dpyinfo
->mouse_face_beg_row
21439 && vpos
<= dpyinfo
->mouse_face_end_row
21440 && (vpos
> dpyinfo
->mouse_face_beg_row
21441 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21442 && (vpos
< dpyinfo
->mouse_face_end_row
21443 || hpos
< dpyinfo
->mouse_face_end_col
21444 || dpyinfo
->mouse_face_past_end
))
21448 return in_mouse_face
;
21454 /* Find the glyph matrix position of buffer position CHARPOS in window
21455 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21456 current glyphs must be up to date. If CHARPOS is above window
21457 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21458 of last line in W. In the row containing CHARPOS, stop before glyphs
21459 having STOP as object. */
21461 #if 1 /* This is a version of fast_find_position that's more correct
21462 in the presence of hscrolling, for example. I didn't install
21463 it right away because the problem fixed is minor, it failed
21464 in 20.x as well, and I think it's too risky to install
21465 so near the release of 21.1. 2001-09-25 gerd. */
21468 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21471 int *hpos
, *vpos
, *x
, *y
;
21474 struct glyph_row
*row
, *first
;
21475 struct glyph
*glyph
, *end
;
21478 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21479 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21484 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21488 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21491 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21495 /* If whole rows or last part of a row came from a display overlay,
21496 row_containing_pos will skip over such rows because their end pos
21497 equals the start pos of the overlay or interval.
21499 Move back if we have a STOP object and previous row's
21500 end glyph came from STOP. */
21503 struct glyph_row
*prev
;
21504 while ((prev
= row
- 1, prev
>= first
)
21505 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21506 && prev
->used
[TEXT_AREA
] > 0)
21508 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21509 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21510 while (--glyph
>= beg
21511 && INTEGERP (glyph
->object
));
21513 || !EQ (stop
, glyph
->object
))
21521 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21523 glyph
= row
->glyphs
[TEXT_AREA
];
21524 end
= glyph
+ row
->used
[TEXT_AREA
];
21526 /* Skip over glyphs not having an object at the start of the row.
21527 These are special glyphs like truncation marks on terminal
21529 if (row
->displays_text_p
)
21531 && INTEGERP (glyph
->object
)
21532 && !EQ (stop
, glyph
->object
)
21533 && glyph
->charpos
< 0)
21535 *x
+= glyph
->pixel_width
;
21540 && !INTEGERP (glyph
->object
)
21541 && !EQ (stop
, glyph
->object
)
21542 && (!BUFFERP (glyph
->object
)
21543 || glyph
->charpos
< charpos
))
21545 *x
+= glyph
->pixel_width
;
21549 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21556 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21559 int *hpos
, *vpos
, *x
, *y
;
21564 int maybe_next_line_p
= 0;
21565 int line_start_position
;
21566 int yb
= window_text_bottom_y (w
);
21567 struct glyph_row
*row
, *best_row
;
21568 int row_vpos
, best_row_vpos
;
21571 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21572 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21574 while (row
->y
< yb
)
21576 if (row
->used
[TEXT_AREA
])
21577 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21579 line_start_position
= 0;
21581 if (line_start_position
> pos
)
21583 /* If the position sought is the end of the buffer,
21584 don't include the blank lines at the bottom of the window. */
21585 else if (line_start_position
== pos
21586 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21588 maybe_next_line_p
= 1;
21591 else if (line_start_position
> 0)
21594 best_row_vpos
= row_vpos
;
21597 if (row
->y
+ row
->height
>= yb
)
21604 /* Find the right column within BEST_ROW. */
21606 current_x
= best_row
->x
;
21607 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21609 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21610 int charpos
= glyph
->charpos
;
21612 if (BUFFERP (glyph
->object
))
21614 if (charpos
== pos
)
21617 *vpos
= best_row_vpos
;
21622 else if (charpos
> pos
)
21625 else if (EQ (glyph
->object
, stop
))
21630 current_x
+= glyph
->pixel_width
;
21633 /* If we're looking for the end of the buffer,
21634 and we didn't find it in the line we scanned,
21635 use the start of the following line. */
21636 if (maybe_next_line_p
)
21641 current_x
= best_row
->x
;
21644 *vpos
= best_row_vpos
;
21645 *hpos
= lastcol
+ 1;
21654 /* Find the position of the glyph for position POS in OBJECT in
21655 window W's current matrix, and return in *X, *Y the pixel
21656 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21658 RIGHT_P non-zero means return the position of the right edge of the
21659 glyph, RIGHT_P zero means return the left edge position.
21661 If no glyph for POS exists in the matrix, return the position of
21662 the glyph with the next smaller position that is in the matrix, if
21663 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21664 exists in the matrix, return the position of the glyph with the
21665 next larger position in OBJECT.
21667 Value is non-zero if a glyph was found. */
21670 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21673 Lisp_Object object
;
21674 int *hpos
, *vpos
, *x
, *y
;
21677 int yb
= window_text_bottom_y (w
);
21678 struct glyph_row
*r
;
21679 struct glyph
*best_glyph
= NULL
;
21680 struct glyph_row
*best_row
= NULL
;
21683 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21684 r
->enabled_p
&& r
->y
< yb
;
21687 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21688 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21691 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21692 if (EQ (g
->object
, object
))
21694 if (g
->charpos
== pos
)
21701 else if (best_glyph
== NULL
21702 || ((abs (g
->charpos
- pos
)
21703 < abs (best_glyph
->charpos
- pos
))
21706 : g
->charpos
> pos
)))
21720 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21724 *x
+= best_glyph
->pixel_width
;
21729 *vpos
= best_row
- w
->current_matrix
->rows
;
21732 return best_glyph
!= NULL
;
21736 /* See if position X, Y is within a hot-spot of an image. */
21739 on_hot_spot_p (hot_spot
, x
, y
)
21740 Lisp_Object hot_spot
;
21743 if (!CONSP (hot_spot
))
21746 if (EQ (XCAR (hot_spot
), Qrect
))
21748 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21749 Lisp_Object rect
= XCDR (hot_spot
);
21753 if (!CONSP (XCAR (rect
)))
21755 if (!CONSP (XCDR (rect
)))
21757 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21759 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21761 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21763 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21767 else if (EQ (XCAR (hot_spot
), Qcircle
))
21769 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21770 Lisp_Object circ
= XCDR (hot_spot
);
21771 Lisp_Object lr
, lx0
, ly0
;
21773 && CONSP (XCAR (circ
))
21774 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21775 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21776 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21778 double r
= XFLOATINT (lr
);
21779 double dx
= XINT (lx0
) - x
;
21780 double dy
= XINT (ly0
) - y
;
21781 return (dx
* dx
+ dy
* dy
<= r
* r
);
21784 else if (EQ (XCAR (hot_spot
), Qpoly
))
21786 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21787 if (VECTORP (XCDR (hot_spot
)))
21789 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21790 Lisp_Object
*poly
= v
->contents
;
21794 Lisp_Object lx
, ly
;
21797 /* Need an even number of coordinates, and at least 3 edges. */
21798 if (n
< 6 || n
& 1)
21801 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21802 If count is odd, we are inside polygon. Pixels on edges
21803 may or may not be included depending on actual geometry of the
21805 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21806 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21808 x0
= XINT (lx
), y0
= XINT (ly
);
21809 for (i
= 0; i
< n
; i
+= 2)
21811 int x1
= x0
, y1
= y0
;
21812 if ((lx
= poly
[i
], !INTEGERP (lx
))
21813 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21815 x0
= XINT (lx
), y0
= XINT (ly
);
21817 /* Does this segment cross the X line? */
21825 if (y
> y0
&& y
> y1
)
21827 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21837 find_hot_spot (map
, x
, y
)
21841 while (CONSP (map
))
21843 if (CONSP (XCAR (map
))
21844 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21852 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21854 doc
: /* Lookup in image map MAP coordinates X and Y.
21855 An image map is an alist where each element has the format (AREA ID PLIST).
21856 An AREA is specified as either a rectangle, a circle, or a polygon:
21857 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21858 pixel coordinates of the upper left and bottom right corners.
21859 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21860 and the radius of the circle; r may be a float or integer.
21861 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21862 vector describes one corner in the polygon.
21863 Returns the alist element for the first matching AREA in MAP. */)
21874 return find_hot_spot (map
, XINT (x
), XINT (y
));
21878 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21880 define_frame_cursor1 (f
, cursor
, pointer
)
21883 Lisp_Object pointer
;
21885 /* Do not change cursor shape while dragging mouse. */
21886 if (!NILP (do_mouse_tracking
))
21889 if (!NILP (pointer
))
21891 if (EQ (pointer
, Qarrow
))
21892 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21893 else if (EQ (pointer
, Qhand
))
21894 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21895 else if (EQ (pointer
, Qtext
))
21896 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21897 else if (EQ (pointer
, intern ("hdrag")))
21898 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21899 #ifdef HAVE_X_WINDOWS
21900 else if (EQ (pointer
, intern ("vdrag")))
21901 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21903 else if (EQ (pointer
, intern ("hourglass")))
21904 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21905 else if (EQ (pointer
, Qmodeline
))
21906 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21908 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21911 if (cursor
!= No_Cursor
)
21912 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
21915 /* Take proper action when mouse has moved to the mode or header line
21916 or marginal area AREA of window W, x-position X and y-position Y.
21917 X is relative to the start of the text display area of W, so the
21918 width of bitmap areas and scroll bars must be subtracted to get a
21919 position relative to the start of the mode line. */
21922 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
21923 Lisp_Object window
;
21925 enum window_part area
;
21927 struct window
*w
= XWINDOW (window
);
21928 struct frame
*f
= XFRAME (w
->frame
);
21929 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21930 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21931 Lisp_Object pointer
= Qnil
;
21932 int charpos
, dx
, dy
, width
, height
;
21933 Lisp_Object string
, object
= Qnil
;
21934 Lisp_Object pos
, help
;
21936 Lisp_Object mouse_face
;
21937 int original_x_pixel
= x
;
21938 struct glyph
* glyph
= NULL
;
21939 struct glyph_row
*row
;
21941 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21946 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21947 &object
, &dx
, &dy
, &width
, &height
);
21949 row
= (area
== ON_MODE_LINE
21950 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
21951 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
21954 if (row
->mode_line_p
&& row
->enabled_p
)
21956 glyph
= row
->glyphs
[TEXT_AREA
];
21957 end
= glyph
+ row
->used
[TEXT_AREA
];
21959 for (x0
= original_x_pixel
;
21960 glyph
< end
&& x0
>= glyph
->pixel_width
;
21962 x0
-= glyph
->pixel_width
;
21970 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
21971 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
21972 &object
, &dx
, &dy
, &width
, &height
);
21977 if (IMAGEP (object
))
21979 Lisp_Object image_map
, hotspot
;
21980 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
21982 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
21984 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21986 Lisp_Object area_id
, plist
;
21988 area_id
= XCAR (hotspot
);
21989 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21990 If so, we could look for mouse-enter, mouse-leave
21991 properties in PLIST (and do something...). */
21992 hotspot
= XCDR (hotspot
);
21993 if (CONSP (hotspot
)
21994 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21996 pointer
= Fplist_get (plist
, Qpointer
);
21997 if (NILP (pointer
))
21999 help
= Fplist_get (plist
, Qhelp_echo
);
22002 help_echo_string
= help
;
22003 /* Is this correct? ++kfs */
22004 XSETWINDOW (help_echo_window
, w
);
22005 help_echo_object
= w
->buffer
;
22006 help_echo_pos
= charpos
;
22010 if (NILP (pointer
))
22011 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22014 if (STRINGP (string
))
22016 pos
= make_number (charpos
);
22017 /* If we're on a string with `help-echo' text property, arrange
22018 for the help to be displayed. This is done by setting the
22019 global variable help_echo_string to the help string. */
22022 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22025 help_echo_string
= help
;
22026 XSETWINDOW (help_echo_window
, w
);
22027 help_echo_object
= string
;
22028 help_echo_pos
= charpos
;
22032 if (NILP (pointer
))
22033 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22035 /* Change the mouse pointer according to what is under X/Y. */
22036 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22039 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22040 if (!KEYMAPP (map
))
22041 map
= Fget_text_property (pos
, Qkeymap
, string
);
22042 if (!KEYMAPP (map
))
22043 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22046 /* Change the mouse face according to what is under X/Y. */
22047 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22048 if (!NILP (mouse_face
)
22049 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22054 struct glyph
* tmp_glyph
;
22058 int total_pixel_width
;
22063 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22064 Qmouse_face
, string
, Qnil
);
22066 b
= make_number (0);
22068 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22070 e
= make_number (SCHARS (string
));
22072 /* Calculate the position(glyph position: GPOS) of GLYPH in
22073 displayed string. GPOS is different from CHARPOS.
22075 CHARPOS is the position of glyph in internal string
22076 object. A mode line string format has structures which
22077 is converted to a flatten by emacs lisp interpreter.
22078 The internal string is an element of the structures.
22079 The displayed string is the flatten string. */
22080 for (tmp_glyph
= glyph
- 1, gpos
= 0;
22081 tmp_glyph
->charpos
>= XINT (b
);
22082 tmp_glyph
--, gpos
++)
22084 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22088 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22089 displayed string holding GLYPH.
22091 GSEQ_LENGTH is different from SCHARS (STRING).
22092 SCHARS (STRING) returns the length of the internal string. */
22093 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22094 tmp_glyph
->charpos
< XINT (e
);
22095 tmp_glyph
++, gseq_length
++)
22097 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22101 total_pixel_width
= 0;
22102 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22103 total_pixel_width
+= tmp_glyph
->pixel_width
;
22105 /* Pre calculation of re-rendering position */
22107 hpos
= (area
== ON_MODE_LINE
22108 ? (w
->current_matrix
)->nrows
- 1
22111 /* If the re-rendering position is included in the last
22112 re-rendering area, we should do nothing. */
22113 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22114 && dpyinfo
->mouse_face_beg_col
<= vpos
22115 && vpos
< dpyinfo
->mouse_face_end_col
22116 && dpyinfo
->mouse_face_beg_row
== hpos
)
22119 if (clear_mouse_face (dpyinfo
))
22120 cursor
= No_Cursor
;
22122 dpyinfo
->mouse_face_beg_col
= vpos
;
22123 dpyinfo
->mouse_face_beg_row
= hpos
;
22125 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22126 dpyinfo
->mouse_face_beg_y
= 0;
22128 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22129 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22131 dpyinfo
->mouse_face_end_x
= 0;
22132 dpyinfo
->mouse_face_end_y
= 0;
22134 dpyinfo
->mouse_face_past_end
= 0;
22135 dpyinfo
->mouse_face_window
= window
;
22137 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22140 glyph
->face_id
, 1);
22141 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22143 if (NILP (pointer
))
22146 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22147 clear_mouse_face (dpyinfo
);
22149 define_frame_cursor1 (f
, cursor
, pointer
);
22154 Take proper action when the mouse has moved to position X, Y on
22155 frame F as regards highlighting characters that have mouse-face
22156 properties. Also de-highlighting chars where the mouse was before.
22157 X and Y can be negative or out of range. */
22160 note_mouse_highlight (f
, x
, y
)
22164 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22165 enum window_part part
;
22166 Lisp_Object window
;
22168 Cursor cursor
= No_Cursor
;
22169 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22172 /* When a menu is active, don't highlight because this looks odd. */
22173 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
22174 if (popup_activated ())
22178 if (NILP (Vmouse_highlight
)
22179 || !f
->glyphs_initialized_p
)
22182 dpyinfo
->mouse_face_mouse_x
= x
;
22183 dpyinfo
->mouse_face_mouse_y
= y
;
22184 dpyinfo
->mouse_face_mouse_frame
= f
;
22186 if (dpyinfo
->mouse_face_defer
)
22189 if (gc_in_progress
)
22191 dpyinfo
->mouse_face_deferred_gc
= 1;
22195 /* Which window is that in? */
22196 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22198 /* If we were displaying active text in another window, clear that.
22199 Also clear if we move out of text area in same window. */
22200 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22201 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22202 && !NILP (dpyinfo
->mouse_face_window
)))
22203 clear_mouse_face (dpyinfo
);
22205 /* Not on a window -> return. */
22206 if (!WINDOWP (window
))
22209 /* Reset help_echo_string. It will get recomputed below. */
22210 help_echo_string
= Qnil
;
22212 /* Convert to window-relative pixel coordinates. */
22213 w
= XWINDOW (window
);
22214 frame_to_window_pixel_xy (w
, &x
, &y
);
22216 /* Handle tool-bar window differently since it doesn't display a
22218 if (EQ (window
, f
->tool_bar_window
))
22220 note_tool_bar_highlight (f
, x
, y
);
22224 /* Mouse is on the mode, header line or margin? */
22225 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22226 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22228 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22232 if (part
== ON_VERTICAL_BORDER
)
22233 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22234 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22235 || part
== ON_SCROLL_BAR
)
22236 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22238 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22240 /* Are we in a window whose display is up to date?
22241 And verify the buffer's text has not changed. */
22242 b
= XBUFFER (w
->buffer
);
22243 if (part
== ON_TEXT
22244 && EQ (w
->window_end_valid
, w
->buffer
)
22245 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22246 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22248 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22249 struct glyph
*glyph
;
22250 Lisp_Object object
;
22251 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22252 Lisp_Object
*overlay_vec
= NULL
;
22254 struct buffer
*obuf
;
22255 int obegv
, ozv
, same_region
;
22257 /* Find the glyph under X/Y. */
22258 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22260 /* Look for :pointer property on image. */
22261 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22263 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22264 if (img
!= NULL
&& IMAGEP (img
->spec
))
22266 Lisp_Object image_map
, hotspot
;
22267 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22269 && (hotspot
= find_hot_spot (image_map
,
22270 glyph
->slice
.x
+ dx
,
22271 glyph
->slice
.y
+ dy
),
22273 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22275 Lisp_Object area_id
, plist
;
22277 area_id
= XCAR (hotspot
);
22278 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22279 If so, we could look for mouse-enter, mouse-leave
22280 properties in PLIST (and do something...). */
22281 hotspot
= XCDR (hotspot
);
22282 if (CONSP (hotspot
)
22283 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22285 pointer
= Fplist_get (plist
, Qpointer
);
22286 if (NILP (pointer
))
22288 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22289 if (!NILP (help_echo_string
))
22291 help_echo_window
= window
;
22292 help_echo_object
= glyph
->object
;
22293 help_echo_pos
= glyph
->charpos
;
22297 if (NILP (pointer
))
22298 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22302 /* Clear mouse face if X/Y not over text. */
22304 || area
!= TEXT_AREA
22305 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22307 if (clear_mouse_face (dpyinfo
))
22308 cursor
= No_Cursor
;
22309 if (NILP (pointer
))
22311 if (area
!= TEXT_AREA
)
22312 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22314 pointer
= Vvoid_text_area_pointer
;
22319 pos
= glyph
->charpos
;
22320 object
= glyph
->object
;
22321 if (!STRINGP (object
) && !BUFFERP (object
))
22324 /* If we get an out-of-range value, return now; avoid an error. */
22325 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22328 /* Make the window's buffer temporarily current for
22329 overlays_at and compute_char_face. */
22330 obuf
= current_buffer
;
22331 current_buffer
= b
;
22337 /* Is this char mouse-active or does it have help-echo? */
22338 position
= make_number (pos
);
22340 if (BUFFERP (object
))
22342 /* Put all the overlays we want in a vector in overlay_vec. */
22343 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22344 /* Sort overlays into increasing priority order. */
22345 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22350 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22351 && vpos
>= dpyinfo
->mouse_face_beg_row
22352 && vpos
<= dpyinfo
->mouse_face_end_row
22353 && (vpos
> dpyinfo
->mouse_face_beg_row
22354 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22355 && (vpos
< dpyinfo
->mouse_face_end_row
22356 || hpos
< dpyinfo
->mouse_face_end_col
22357 || dpyinfo
->mouse_face_past_end
));
22360 cursor
= No_Cursor
;
22362 /* Check mouse-face highlighting. */
22364 /* If there exists an overlay with mouse-face overlapping
22365 the one we are currently highlighting, we have to
22366 check if we enter the overlapping overlay, and then
22367 highlight only that. */
22368 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22369 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22371 /* Find the highest priority overlay that has a mouse-face
22374 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22376 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22377 if (!NILP (mouse_face
))
22378 overlay
= overlay_vec
[i
];
22381 /* If we're actually highlighting the same overlay as
22382 before, there's no need to do that again. */
22383 if (!NILP (overlay
)
22384 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22385 goto check_help_echo
;
22387 dpyinfo
->mouse_face_overlay
= overlay
;
22389 /* Clear the display of the old active region, if any. */
22390 if (clear_mouse_face (dpyinfo
))
22391 cursor
= No_Cursor
;
22393 /* If no overlay applies, get a text property. */
22394 if (NILP (overlay
))
22395 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22397 /* Handle the overlay case. */
22398 if (!NILP (overlay
))
22400 /* Find the range of text around this char that
22401 should be active. */
22402 Lisp_Object before
, after
;
22405 before
= Foverlay_start (overlay
);
22406 after
= Foverlay_end (overlay
);
22407 /* Record this as the current active region. */
22408 fast_find_position (w
, XFASTINT (before
),
22409 &dpyinfo
->mouse_face_beg_col
,
22410 &dpyinfo
->mouse_face_beg_row
,
22411 &dpyinfo
->mouse_face_beg_x
,
22412 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22414 dpyinfo
->mouse_face_past_end
22415 = !fast_find_position (w
, XFASTINT (after
),
22416 &dpyinfo
->mouse_face_end_col
,
22417 &dpyinfo
->mouse_face_end_row
,
22418 &dpyinfo
->mouse_face_end_x
,
22419 &dpyinfo
->mouse_face_end_y
, Qnil
);
22420 dpyinfo
->mouse_face_window
= window
;
22422 dpyinfo
->mouse_face_face_id
22423 = face_at_buffer_position (w
, pos
, 0, 0,
22425 !dpyinfo
->mouse_face_hidden
);
22427 /* Display it as active. */
22428 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22429 cursor
= No_Cursor
;
22431 /* Handle the text property case. */
22432 else if (!NILP (mouse_face
) && BUFFERP (object
))
22434 /* Find the range of text around this char that
22435 should be active. */
22436 Lisp_Object before
, after
, beginning
, end
;
22439 beginning
= Fmarker_position (w
->start
);
22440 end
= make_number (BUF_Z (XBUFFER (object
))
22441 - XFASTINT (w
->window_end_pos
));
22443 = Fprevious_single_property_change (make_number (pos
+ 1),
22445 object
, beginning
);
22447 = Fnext_single_property_change (position
, Qmouse_face
,
22450 /* Record this as the current active region. */
22451 fast_find_position (w
, XFASTINT (before
),
22452 &dpyinfo
->mouse_face_beg_col
,
22453 &dpyinfo
->mouse_face_beg_row
,
22454 &dpyinfo
->mouse_face_beg_x
,
22455 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22456 dpyinfo
->mouse_face_past_end
22457 = !fast_find_position (w
, XFASTINT (after
),
22458 &dpyinfo
->mouse_face_end_col
,
22459 &dpyinfo
->mouse_face_end_row
,
22460 &dpyinfo
->mouse_face_end_x
,
22461 &dpyinfo
->mouse_face_end_y
, Qnil
);
22462 dpyinfo
->mouse_face_window
= window
;
22464 if (BUFFERP (object
))
22465 dpyinfo
->mouse_face_face_id
22466 = face_at_buffer_position (w
, pos
, 0, 0,
22468 !dpyinfo
->mouse_face_hidden
);
22470 /* Display it as active. */
22471 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22472 cursor
= No_Cursor
;
22474 else if (!NILP (mouse_face
) && STRINGP (object
))
22479 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22482 e
= Fnext_single_property_change (position
, Qmouse_face
,
22485 b
= make_number (0);
22487 e
= make_number (SCHARS (object
) - 1);
22489 fast_find_string_pos (w
, XINT (b
), object
,
22490 &dpyinfo
->mouse_face_beg_col
,
22491 &dpyinfo
->mouse_face_beg_row
,
22492 &dpyinfo
->mouse_face_beg_x
,
22493 &dpyinfo
->mouse_face_beg_y
, 0);
22494 fast_find_string_pos (w
, XINT (e
), object
,
22495 &dpyinfo
->mouse_face_end_col
,
22496 &dpyinfo
->mouse_face_end_row
,
22497 &dpyinfo
->mouse_face_end_x
,
22498 &dpyinfo
->mouse_face_end_y
, 1);
22499 dpyinfo
->mouse_face_past_end
= 0;
22500 dpyinfo
->mouse_face_window
= window
;
22501 dpyinfo
->mouse_face_face_id
22502 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22503 glyph
->face_id
, 1);
22504 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22505 cursor
= No_Cursor
;
22507 else if (STRINGP (object
) && NILP (mouse_face
))
22509 /* A string which doesn't have mouse-face, but
22510 the text ``under'' it might have. */
22511 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22512 int start
= MATRIX_ROW_START_CHARPOS (r
);
22514 pos
= string_buffer_position (w
, object
, start
);
22516 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22520 if (!NILP (mouse_face
) && !NILP (overlay
))
22522 Lisp_Object before
= Foverlay_start (overlay
);
22523 Lisp_Object after
= Foverlay_end (overlay
);
22526 /* Note that we might not be able to find position
22527 BEFORE in the glyph matrix if the overlay is
22528 entirely covered by a `display' property. In
22529 this case, we overshoot. So let's stop in
22530 the glyph matrix before glyphs for OBJECT. */
22531 fast_find_position (w
, XFASTINT (before
),
22532 &dpyinfo
->mouse_face_beg_col
,
22533 &dpyinfo
->mouse_face_beg_row
,
22534 &dpyinfo
->mouse_face_beg_x
,
22535 &dpyinfo
->mouse_face_beg_y
,
22538 dpyinfo
->mouse_face_past_end
22539 = !fast_find_position (w
, XFASTINT (after
),
22540 &dpyinfo
->mouse_face_end_col
,
22541 &dpyinfo
->mouse_face_end_row
,
22542 &dpyinfo
->mouse_face_end_x
,
22543 &dpyinfo
->mouse_face_end_y
,
22545 dpyinfo
->mouse_face_window
= window
;
22546 dpyinfo
->mouse_face_face_id
22547 = face_at_buffer_position (w
, pos
, 0, 0,
22549 !dpyinfo
->mouse_face_hidden
);
22551 /* Display it as active. */
22552 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22553 cursor
= No_Cursor
;
22560 /* Look for a `help-echo' property. */
22561 if (NILP (help_echo_string
)) {
22562 Lisp_Object help
, overlay
;
22564 /* Check overlays first. */
22565 help
= overlay
= Qnil
;
22566 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22568 overlay
= overlay_vec
[i
];
22569 help
= Foverlay_get (overlay
, Qhelp_echo
);
22574 help_echo_string
= help
;
22575 help_echo_window
= window
;
22576 help_echo_object
= overlay
;
22577 help_echo_pos
= pos
;
22581 Lisp_Object object
= glyph
->object
;
22582 int charpos
= glyph
->charpos
;
22584 /* Try text properties. */
22585 if (STRINGP (object
)
22587 && charpos
< SCHARS (object
))
22589 help
= Fget_text_property (make_number (charpos
),
22590 Qhelp_echo
, object
);
22593 /* If the string itself doesn't specify a help-echo,
22594 see if the buffer text ``under'' it does. */
22595 struct glyph_row
*r
22596 = MATRIX_ROW (w
->current_matrix
, vpos
);
22597 int start
= MATRIX_ROW_START_CHARPOS (r
);
22598 int pos
= string_buffer_position (w
, object
, start
);
22601 help
= Fget_char_property (make_number (pos
),
22602 Qhelp_echo
, w
->buffer
);
22606 object
= w
->buffer
;
22611 else if (BUFFERP (object
)
22614 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22619 help_echo_string
= help
;
22620 help_echo_window
= window
;
22621 help_echo_object
= object
;
22622 help_echo_pos
= charpos
;
22627 /* Look for a `pointer' property. */
22628 if (NILP (pointer
))
22630 /* Check overlays first. */
22631 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22632 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22634 if (NILP (pointer
))
22636 Lisp_Object object
= glyph
->object
;
22637 int charpos
= glyph
->charpos
;
22639 /* Try text properties. */
22640 if (STRINGP (object
)
22642 && charpos
< SCHARS (object
))
22644 pointer
= Fget_text_property (make_number (charpos
),
22646 if (NILP (pointer
))
22648 /* If the string itself doesn't specify a pointer,
22649 see if the buffer text ``under'' it does. */
22650 struct glyph_row
*r
22651 = MATRIX_ROW (w
->current_matrix
, vpos
);
22652 int start
= MATRIX_ROW_START_CHARPOS (r
);
22653 int pos
= string_buffer_position (w
, object
, start
);
22655 pointer
= Fget_char_property (make_number (pos
),
22656 Qpointer
, w
->buffer
);
22659 else if (BUFFERP (object
)
22662 pointer
= Fget_text_property (make_number (charpos
),
22669 current_buffer
= obuf
;
22674 define_frame_cursor1 (f
, cursor
, pointer
);
22679 Clear any mouse-face on window W. This function is part of the
22680 redisplay interface, and is called from try_window_id and similar
22681 functions to ensure the mouse-highlight is off. */
22684 x_clear_window_mouse_face (w
)
22687 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22688 Lisp_Object window
;
22691 XSETWINDOW (window
, w
);
22692 if (EQ (window
, dpyinfo
->mouse_face_window
))
22693 clear_mouse_face (dpyinfo
);
22699 Just discard the mouse face information for frame F, if any.
22700 This is used when the size of F is changed. */
22703 cancel_mouse_face (f
)
22706 Lisp_Object window
;
22707 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22709 window
= dpyinfo
->mouse_face_window
;
22710 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22712 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22713 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22714 dpyinfo
->mouse_face_window
= Qnil
;
22719 #endif /* HAVE_WINDOW_SYSTEM */
22722 /***********************************************************************
22724 ***********************************************************************/
22726 #ifdef HAVE_WINDOW_SYSTEM
22728 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22729 which intersects rectangle R. R is in window-relative coordinates. */
22732 expose_area (w
, row
, r
, area
)
22734 struct glyph_row
*row
;
22736 enum glyph_row_area area
;
22738 struct glyph
*first
= row
->glyphs
[area
];
22739 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22740 struct glyph
*last
;
22741 int first_x
, start_x
, x
;
22743 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22744 /* If row extends face to end of line write the whole line. */
22745 draw_glyphs (w
, 0, row
, area
,
22746 0, row
->used
[area
],
22747 DRAW_NORMAL_TEXT
, 0);
22750 /* Set START_X to the window-relative start position for drawing glyphs of
22751 AREA. The first glyph of the text area can be partially visible.
22752 The first glyphs of other areas cannot. */
22753 start_x
= window_box_left_offset (w
, area
);
22755 if (area
== TEXT_AREA
)
22758 /* Find the first glyph that must be redrawn. */
22760 && x
+ first
->pixel_width
< r
->x
)
22762 x
+= first
->pixel_width
;
22766 /* Find the last one. */
22770 && x
< r
->x
+ r
->width
)
22772 x
+= last
->pixel_width
;
22778 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22779 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22780 DRAW_NORMAL_TEXT
, 0);
22785 /* Redraw the parts of the glyph row ROW on window W intersecting
22786 rectangle R. R is in window-relative coordinates. Value is
22787 non-zero if mouse-face was overwritten. */
22790 expose_line (w
, row
, r
)
22792 struct glyph_row
*row
;
22795 xassert (row
->enabled_p
);
22797 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22798 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22799 0, row
->used
[TEXT_AREA
],
22800 DRAW_NORMAL_TEXT
, 0);
22803 if (row
->used
[LEFT_MARGIN_AREA
])
22804 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22805 if (row
->used
[TEXT_AREA
])
22806 expose_area (w
, row
, r
, TEXT_AREA
);
22807 if (row
->used
[RIGHT_MARGIN_AREA
])
22808 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
22809 draw_row_fringe_bitmaps (w
, row
);
22812 return row
->mouse_face_p
;
22816 /* Redraw those parts of glyphs rows during expose event handling that
22817 overlap other rows. Redrawing of an exposed line writes over parts
22818 of lines overlapping that exposed line; this function fixes that.
22820 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
22821 row in W's current matrix that is exposed and overlaps other rows.
22822 LAST_OVERLAPPING_ROW is the last such row. */
22825 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
22827 struct glyph_row
*first_overlapping_row
;
22828 struct glyph_row
*last_overlapping_row
;
22830 struct glyph_row
*row
;
22832 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
22833 if (row
->overlapping_p
)
22835 xassert (row
->enabled_p
&& !row
->mode_line_p
);
22837 if (row
->used
[LEFT_MARGIN_AREA
])
22838 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
22840 if (row
->used
[TEXT_AREA
])
22841 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
22843 if (row
->used
[RIGHT_MARGIN_AREA
])
22844 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
22849 /* Return non-zero if W's cursor intersects rectangle R. */
22852 phys_cursor_in_rect_p (w
, r
)
22856 XRectangle cr
, result
;
22857 struct glyph
*cursor_glyph
;
22859 cursor_glyph
= get_phys_cursor_glyph (w
);
22862 /* r is relative to W's box, but w->phys_cursor.x is relative
22863 to left edge of W's TEXT area. Adjust it. */
22864 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
22865 cr
.y
= w
->phys_cursor
.y
;
22866 cr
.width
= cursor_glyph
->pixel_width
;
22867 cr
.height
= w
->phys_cursor_height
;
22868 /* ++KFS: W32 version used W32-specific IntersectRect here, but
22869 I assume the effect is the same -- and this is portable. */
22870 return x_intersect_rectangles (&cr
, r
, &result
);
22872 /* If we don't understand the format, pretend we're not in the hot-spot. */
22878 Draw a vertical window border to the right of window W if W doesn't
22879 have vertical scroll bars. */
22882 x_draw_vertical_border (w
)
22885 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22887 /* We could do better, if we knew what type of scroll-bar the adjacent
22888 windows (on either side) have... But we don't :-(
22889 However, I think this works ok. ++KFS 2003-04-25 */
22891 /* Redraw borders between horizontally adjacent windows. Don't
22892 do it for frames with vertical scroll bars because either the
22893 right scroll bar of a window, or the left scroll bar of its
22894 neighbor will suffice as a border. */
22895 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
22898 if (!WINDOW_RIGHTMOST_P (w
)
22899 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
22901 int x0
, x1
, y0
, y1
;
22903 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22906 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22909 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
22911 else if (!WINDOW_LEFTMOST_P (w
)
22912 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22914 int x0
, x1
, y0
, y1
;
22916 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22919 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22922 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
22927 /* Redraw the part of window W intersection rectangle FR. Pixel
22928 coordinates in FR are frame-relative. Call this function with
22929 input blocked. Value is non-zero if the exposure overwrites
22933 expose_window (w
, fr
)
22937 struct frame
*f
= XFRAME (w
->frame
);
22939 int mouse_face_overwritten_p
= 0;
22941 /* If window is not yet fully initialized, do nothing. This can
22942 happen when toolkit scroll bars are used and a window is split.
22943 Reconfiguring the scroll bar will generate an expose for a newly
22945 if (w
->current_matrix
== NULL
)
22948 /* When we're currently updating the window, display and current
22949 matrix usually don't agree. Arrange for a thorough display
22951 if (w
== updated_window
)
22953 SET_FRAME_GARBAGED (f
);
22957 /* Frame-relative pixel rectangle of W. */
22958 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
22959 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
22960 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
22961 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
22963 if (x_intersect_rectangles (fr
, &wr
, &r
))
22965 int yb
= window_text_bottom_y (w
);
22966 struct glyph_row
*row
;
22967 int cursor_cleared_p
;
22968 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
22970 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
22971 r
.x
, r
.y
, r
.width
, r
.height
));
22973 /* Convert to window coordinates. */
22974 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
22975 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
22977 /* Turn off the cursor. */
22978 if (!w
->pseudo_window_p
22979 && phys_cursor_in_rect_p (w
, &r
))
22981 x_clear_cursor (w
);
22982 cursor_cleared_p
= 1;
22985 cursor_cleared_p
= 0;
22987 /* Update lines intersecting rectangle R. */
22988 first_overlapping_row
= last_overlapping_row
= NULL
;
22989 for (row
= w
->current_matrix
->rows
;
22994 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
22996 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
22997 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
22998 || (r
.y
>= y0
&& r
.y
< y1
)
22999 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23001 /* A header line may be overlapping, but there is no need
23002 to fix overlapping areas for them. KFS 2005-02-12 */
23003 if (row
->overlapping_p
&& !row
->mode_line_p
)
23005 if (first_overlapping_row
== NULL
)
23006 first_overlapping_row
= row
;
23007 last_overlapping_row
= row
;
23010 if (expose_line (w
, row
, &r
))
23011 mouse_face_overwritten_p
= 1;
23018 /* Display the mode line if there is one. */
23019 if (WINDOW_WANTS_MODELINE_P (w
)
23020 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23022 && row
->y
< r
.y
+ r
.height
)
23024 if (expose_line (w
, row
, &r
))
23025 mouse_face_overwritten_p
= 1;
23028 if (!w
->pseudo_window_p
)
23030 /* Fix the display of overlapping rows. */
23031 if (first_overlapping_row
)
23032 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23034 /* Draw border between windows. */
23035 x_draw_vertical_border (w
);
23037 /* Turn the cursor on again. */
23038 if (cursor_cleared_p
)
23039 update_window_cursor (w
, 1);
23043 return mouse_face_overwritten_p
;
23048 /* Redraw (parts) of all windows in the window tree rooted at W that
23049 intersect R. R contains frame pixel coordinates. Value is
23050 non-zero if the exposure overwrites mouse-face. */
23053 expose_window_tree (w
, r
)
23057 struct frame
*f
= XFRAME (w
->frame
);
23058 int mouse_face_overwritten_p
= 0;
23060 while (w
&& !FRAME_GARBAGED_P (f
))
23062 if (!NILP (w
->hchild
))
23063 mouse_face_overwritten_p
23064 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23065 else if (!NILP (w
->vchild
))
23066 mouse_face_overwritten_p
23067 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23069 mouse_face_overwritten_p
|= expose_window (w
, r
);
23071 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23074 return mouse_face_overwritten_p
;
23079 Redisplay an exposed area of frame F. X and Y are the upper-left
23080 corner of the exposed rectangle. W and H are width and height of
23081 the exposed area. All are pixel values. W or H zero means redraw
23082 the entire frame. */
23085 expose_frame (f
, x
, y
, w
, h
)
23090 int mouse_face_overwritten_p
= 0;
23092 TRACE ((stderr
, "expose_frame "));
23094 /* No need to redraw if frame will be redrawn soon. */
23095 if (FRAME_GARBAGED_P (f
))
23097 TRACE ((stderr
, " garbaged\n"));
23101 /* If basic faces haven't been realized yet, there is no point in
23102 trying to redraw anything. This can happen when we get an expose
23103 event while Emacs is starting, e.g. by moving another window. */
23104 if (FRAME_FACE_CACHE (f
) == NULL
23105 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23107 TRACE ((stderr
, " no faces\n"));
23111 if (w
== 0 || h
== 0)
23114 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23115 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23125 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23126 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23128 if (WINDOWP (f
->tool_bar_window
))
23129 mouse_face_overwritten_p
23130 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23132 #ifdef HAVE_X_WINDOWS
23134 #ifndef USE_X_TOOLKIT
23135 if (WINDOWP (f
->menu_bar_window
))
23136 mouse_face_overwritten_p
23137 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23138 #endif /* not USE_X_TOOLKIT */
23142 /* Some window managers support a focus-follows-mouse style with
23143 delayed raising of frames. Imagine a partially obscured frame,
23144 and moving the mouse into partially obscured mouse-face on that
23145 frame. The visible part of the mouse-face will be highlighted,
23146 then the WM raises the obscured frame. With at least one WM, KDE
23147 2.1, Emacs is not getting any event for the raising of the frame
23148 (even tried with SubstructureRedirectMask), only Expose events.
23149 These expose events will draw text normally, i.e. not
23150 highlighted. Which means we must redo the highlight here.
23151 Subsume it under ``we love X''. --gerd 2001-08-15 */
23152 /* Included in Windows version because Windows most likely does not
23153 do the right thing if any third party tool offers
23154 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23155 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23157 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23158 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23160 int x
= dpyinfo
->mouse_face_mouse_x
;
23161 int y
= dpyinfo
->mouse_face_mouse_y
;
23162 clear_mouse_face (dpyinfo
);
23163 note_mouse_highlight (f
, x
, y
);
23170 Determine the intersection of two rectangles R1 and R2. Return
23171 the intersection in *RESULT. Value is non-zero if RESULT is not
23175 x_intersect_rectangles (r1
, r2
, result
)
23176 XRectangle
*r1
, *r2
, *result
;
23178 XRectangle
*left
, *right
;
23179 XRectangle
*upper
, *lower
;
23180 int intersection_p
= 0;
23182 /* Rearrange so that R1 is the left-most rectangle. */
23184 left
= r1
, right
= r2
;
23186 left
= r2
, right
= r1
;
23188 /* X0 of the intersection is right.x0, if this is inside R1,
23189 otherwise there is no intersection. */
23190 if (right
->x
<= left
->x
+ left
->width
)
23192 result
->x
= right
->x
;
23194 /* The right end of the intersection is the minimum of the
23195 the right ends of left and right. */
23196 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23199 /* Same game for Y. */
23201 upper
= r1
, lower
= r2
;
23203 upper
= r2
, lower
= r1
;
23205 /* The upper end of the intersection is lower.y0, if this is inside
23206 of upper. Otherwise, there is no intersection. */
23207 if (lower
->y
<= upper
->y
+ upper
->height
)
23209 result
->y
= lower
->y
;
23211 /* The lower end of the intersection is the minimum of the lower
23212 ends of upper and lower. */
23213 result
->height
= (min (lower
->y
+ lower
->height
,
23214 upper
->y
+ upper
->height
)
23216 intersection_p
= 1;
23220 return intersection_p
;
23223 #endif /* HAVE_WINDOW_SYSTEM */
23226 /***********************************************************************
23228 ***********************************************************************/
23233 Vwith_echo_area_save_vector
= Qnil
;
23234 staticpro (&Vwith_echo_area_save_vector
);
23236 Vmessage_stack
= Qnil
;
23237 staticpro (&Vmessage_stack
);
23239 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23240 staticpro (&Qinhibit_redisplay
);
23242 message_dolog_marker1
= Fmake_marker ();
23243 staticpro (&message_dolog_marker1
);
23244 message_dolog_marker2
= Fmake_marker ();
23245 staticpro (&message_dolog_marker2
);
23246 message_dolog_marker3
= Fmake_marker ();
23247 staticpro (&message_dolog_marker3
);
23250 defsubr (&Sdump_frame_glyph_matrix
);
23251 defsubr (&Sdump_glyph_matrix
);
23252 defsubr (&Sdump_glyph_row
);
23253 defsubr (&Sdump_tool_bar_row
);
23254 defsubr (&Strace_redisplay
);
23255 defsubr (&Strace_to_stderr
);
23257 #ifdef HAVE_WINDOW_SYSTEM
23258 defsubr (&Stool_bar_lines_needed
);
23259 defsubr (&Slookup_image_map
);
23261 defsubr (&Sformat_mode_line
);
23263 staticpro (&Qmenu_bar_update_hook
);
23264 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23266 staticpro (&Qoverriding_terminal_local_map
);
23267 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23269 staticpro (&Qoverriding_local_map
);
23270 Qoverriding_local_map
= intern ("overriding-local-map");
23272 staticpro (&Qwindow_scroll_functions
);
23273 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23275 staticpro (&Qredisplay_end_trigger_functions
);
23276 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23278 staticpro (&Qinhibit_point_motion_hooks
);
23279 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23281 QCdata
= intern (":data");
23282 staticpro (&QCdata
);
23283 Qdisplay
= intern ("display");
23284 staticpro (&Qdisplay
);
23285 Qspace_width
= intern ("space-width");
23286 staticpro (&Qspace_width
);
23287 Qraise
= intern ("raise");
23288 staticpro (&Qraise
);
23289 Qslice
= intern ("slice");
23290 staticpro (&Qslice
);
23291 Qspace
= intern ("space");
23292 staticpro (&Qspace
);
23293 Qmargin
= intern ("margin");
23294 staticpro (&Qmargin
);
23295 Qpointer
= intern ("pointer");
23296 staticpro (&Qpointer
);
23297 Qleft_margin
= intern ("left-margin");
23298 staticpro (&Qleft_margin
);
23299 Qright_margin
= intern ("right-margin");
23300 staticpro (&Qright_margin
);
23301 Qcenter
= intern ("center");
23302 staticpro (&Qcenter
);
23303 Qline_height
= intern ("line-height");
23304 staticpro (&Qline_height
);
23305 QCalign_to
= intern (":align-to");
23306 staticpro (&QCalign_to
);
23307 QCrelative_width
= intern (":relative-width");
23308 staticpro (&QCrelative_width
);
23309 QCrelative_height
= intern (":relative-height");
23310 staticpro (&QCrelative_height
);
23311 QCeval
= intern (":eval");
23312 staticpro (&QCeval
);
23313 QCpropertize
= intern (":propertize");
23314 staticpro (&QCpropertize
);
23315 QCfile
= intern (":file");
23316 staticpro (&QCfile
);
23317 Qfontified
= intern ("fontified");
23318 staticpro (&Qfontified
);
23319 Qfontification_functions
= intern ("fontification-functions");
23320 staticpro (&Qfontification_functions
);
23321 Qtrailing_whitespace
= intern ("trailing-whitespace");
23322 staticpro (&Qtrailing_whitespace
);
23323 Qescape_glyph
= intern ("escape-glyph");
23324 staticpro (&Qescape_glyph
);
23325 Qnobreak_space
= intern ("nobreak-space");
23326 staticpro (&Qnobreak_space
);
23327 Qimage
= intern ("image");
23328 staticpro (&Qimage
);
23329 QCmap
= intern (":map");
23330 staticpro (&QCmap
);
23331 QCpointer
= intern (":pointer");
23332 staticpro (&QCpointer
);
23333 Qrect
= intern ("rect");
23334 staticpro (&Qrect
);
23335 Qcircle
= intern ("circle");
23336 staticpro (&Qcircle
);
23337 Qpoly
= intern ("poly");
23338 staticpro (&Qpoly
);
23339 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23340 staticpro (&Qmessage_truncate_lines
);
23341 Qgrow_only
= intern ("grow-only");
23342 staticpro (&Qgrow_only
);
23343 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23344 staticpro (&Qinhibit_menubar_update
);
23345 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23346 staticpro (&Qinhibit_eval_during_redisplay
);
23347 Qposition
= intern ("position");
23348 staticpro (&Qposition
);
23349 Qbuffer_position
= intern ("buffer-position");
23350 staticpro (&Qbuffer_position
);
23351 Qobject
= intern ("object");
23352 staticpro (&Qobject
);
23353 Qbar
= intern ("bar");
23355 Qhbar
= intern ("hbar");
23356 staticpro (&Qhbar
);
23357 Qbox
= intern ("box");
23359 Qhollow
= intern ("hollow");
23360 staticpro (&Qhollow
);
23361 Qhand
= intern ("hand");
23362 staticpro (&Qhand
);
23363 Qarrow
= intern ("arrow");
23364 staticpro (&Qarrow
);
23365 Qtext
= intern ("text");
23366 staticpro (&Qtext
);
23367 Qrisky_local_variable
= intern ("risky-local-variable");
23368 staticpro (&Qrisky_local_variable
);
23369 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23370 staticpro (&Qinhibit_free_realized_faces
);
23372 list_of_error
= Fcons (Fcons (intern ("error"),
23373 Fcons (intern ("void-variable"), Qnil
)),
23375 staticpro (&list_of_error
);
23377 Qlast_arrow_position
= intern ("last-arrow-position");
23378 staticpro (&Qlast_arrow_position
);
23379 Qlast_arrow_string
= intern ("last-arrow-string");
23380 staticpro (&Qlast_arrow_string
);
23382 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23383 staticpro (&Qoverlay_arrow_string
);
23384 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23385 staticpro (&Qoverlay_arrow_bitmap
);
23387 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23388 staticpro (&echo_buffer
[0]);
23389 staticpro (&echo_buffer
[1]);
23391 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23392 staticpro (&echo_area_buffer
[0]);
23393 staticpro (&echo_area_buffer
[1]);
23395 Vmessages_buffer_name
= build_string ("*Messages*");
23396 staticpro (&Vmessages_buffer_name
);
23398 mode_line_proptrans_alist
= Qnil
;
23399 staticpro (&mode_line_proptrans_alist
);
23400 mode_line_string_list
= Qnil
;
23401 staticpro (&mode_line_string_list
);
23402 mode_line_string_face
= Qnil
;
23403 staticpro (&mode_line_string_face
);
23404 mode_line_string_face_prop
= Qnil
;
23405 staticpro (&mode_line_string_face_prop
);
23406 Vmode_line_unwind_vector
= Qnil
;
23407 staticpro (&Vmode_line_unwind_vector
);
23409 help_echo_string
= Qnil
;
23410 staticpro (&help_echo_string
);
23411 help_echo_object
= Qnil
;
23412 staticpro (&help_echo_object
);
23413 help_echo_window
= Qnil
;
23414 staticpro (&help_echo_window
);
23415 previous_help_echo_string
= Qnil
;
23416 staticpro (&previous_help_echo_string
);
23417 help_echo_pos
= -1;
23419 #ifdef HAVE_WINDOW_SYSTEM
23420 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23421 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23422 For example, if a block cursor is over a tab, it will be drawn as
23423 wide as that tab on the display. */);
23424 x_stretch_cursor_p
= 0;
23427 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23428 doc
: /* *Non-nil means highlight trailing whitespace.
23429 The face used for trailing whitespace is `trailing-whitespace'. */);
23430 Vshow_trailing_whitespace
= Qnil
;
23432 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23433 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23434 A value of t means highlight the character itself (for nobreak space,
23435 use face `nobreak-space').
23436 A value of nil means no highlighting.
23437 Other values mean display the escape glyph followed by an ordinary
23438 space or ordinary hyphen. */);
23439 Vnobreak_char_display
= Qt
;
23441 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23442 doc
: /* *The pointer shape to show in void text areas.
23443 A value of nil means to show the text pointer. Other options are `arrow',
23444 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23445 Vvoid_text_area_pointer
= Qarrow
;
23447 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23448 doc
: /* Non-nil means don't actually do any redisplay.
23449 This is used for internal purposes. */);
23450 Vinhibit_redisplay
= Qnil
;
23452 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23453 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23454 Vglobal_mode_string
= Qnil
;
23456 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23457 doc
: /* Marker for where to display an arrow on top of the buffer text.
23458 This must be the beginning of a line in order to work.
23459 See also `overlay-arrow-string'. */);
23460 Voverlay_arrow_position
= Qnil
;
23462 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23463 doc
: /* String to display as an arrow in non-window frames.
23464 See also `overlay-arrow-position'. */);
23465 Voverlay_arrow_string
= build_string ("=>");
23467 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23468 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23469 The symbols on this list are examined during redisplay to determine
23470 where to display overlay arrows. */);
23471 Voverlay_arrow_variable_list
23472 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23474 DEFVAR_INT ("scroll-step", &scroll_step
,
23475 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23476 If that fails to bring point back on frame, point is centered instead.
23477 If this is zero, point is always centered after it moves off frame.
23478 If you want scrolling to always be a line at a time, you should set
23479 `scroll-conservatively' to a large value rather than set this to 1. */);
23481 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23482 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23483 A value of zero means to scroll the text to center point vertically
23484 in the window. */);
23485 scroll_conservatively
= 0;
23487 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23488 doc
: /* *Number of lines of margin at the top and bottom of a window.
23489 Recenter the window whenever point gets within this many lines
23490 of the top or bottom of the window. */);
23493 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23494 doc
: /* Pixels per inch value for non-window system displays.
23495 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23496 Vdisplay_pixels_per_inch
= make_float (72.0);
23499 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23502 DEFVAR_BOOL ("truncate-partial-width-windows",
23503 &truncate_partial_width_windows
,
23504 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23505 truncate_partial_width_windows
= 1;
23507 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23508 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23509 Any other value means to use the appropriate face, `mode-line',
23510 `header-line', or `menu' respectively. */);
23511 mode_line_inverse_video
= 1;
23513 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23514 doc
: /* *Maximum buffer size for which line number should be displayed.
23515 If the buffer is bigger than this, the line number does not appear
23516 in the mode line. A value of nil means no limit. */);
23517 Vline_number_display_limit
= Qnil
;
23519 DEFVAR_INT ("line-number-display-limit-width",
23520 &line_number_display_limit_width
,
23521 doc
: /* *Maximum line width (in characters) for line number display.
23522 If the average length of the lines near point is bigger than this, then the
23523 line number may be omitted from the mode line. */);
23524 line_number_display_limit_width
= 200;
23526 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23527 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23528 highlight_nonselected_windows
= 0;
23530 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23531 doc
: /* Non-nil if more than one frame is visible on this display.
23532 Minibuffer-only frames don't count, but iconified frames do.
23533 This variable is not guaranteed to be accurate except while processing
23534 `frame-title-format' and `icon-title-format'. */);
23536 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23537 doc
: /* Template for displaying the title bar of visible frames.
23538 \(Assuming the window manager supports this feature.)
23539 This variable has the same structure as `mode-line-format' (which see),
23540 and is used only on frames for which no explicit name has been set
23541 \(see `modify-frame-parameters'). */);
23543 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23544 doc
: /* Template for displaying the title bar of an iconified frame.
23545 \(Assuming the window manager supports this feature.)
23546 This variable has the same structure as `mode-line-format' (which see),
23547 and is used only on frames for which no explicit name has been set
23548 \(see `modify-frame-parameters'). */);
23550 = Vframe_title_format
23551 = Fcons (intern ("multiple-frames"),
23552 Fcons (build_string ("%b"),
23553 Fcons (Fcons (empty_string
,
23554 Fcons (intern ("invocation-name"),
23555 Fcons (build_string ("@"),
23556 Fcons (intern ("system-name"),
23560 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23561 doc
: /* Maximum number of lines to keep in the message log buffer.
23562 If nil, disable message logging. If t, log messages but don't truncate
23563 the buffer when it becomes large. */);
23564 Vmessage_log_max
= make_number (50);
23566 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23567 doc
: /* Functions called before redisplay, if window sizes have changed.
23568 The value should be a list of functions that take one argument.
23569 Just before redisplay, for each frame, if any of its windows have changed
23570 size since the last redisplay, or have been split or deleted,
23571 all the functions in the list are called, with the frame as argument. */);
23572 Vwindow_size_change_functions
= Qnil
;
23574 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23575 doc
: /* List of functions to call before redisplaying a window with scrolling.
23576 Each function is called with two arguments, the window
23577 and its new display-start position. Note that the value of `window-end'
23578 is not valid when these functions are called. */);
23579 Vwindow_scroll_functions
= Qnil
;
23581 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
23582 doc
: /* Functions called when redisplay of a window reaches the end trigger.
23583 Each function is called with two arguments, the window and the end trigger value.
23584 See `set-window-redisplay-end-trigger'. */);
23585 Vredisplay_end_trigger_functions
= Qnil
;
23587 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23588 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23589 mouse_autoselect_window
= 0;
23591 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23592 doc
: /* *Non-nil means automatically resize tool-bars.
23593 This increases a tool-bar's height if not all tool-bar items are visible.
23594 It decreases a tool-bar's height when it would display blank lines
23596 auto_resize_tool_bars_p
= 1;
23598 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23599 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23600 auto_raise_tool_bar_buttons_p
= 1;
23602 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23603 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23604 make_cursor_line_fully_visible_p
= 1;
23606 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23607 doc
: /* *Margin around tool-bar buttons in pixels.
23608 If an integer, use that for both horizontal and vertical margins.
23609 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23610 HORZ specifying the horizontal margin, and VERT specifying the
23611 vertical margin. */);
23612 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23614 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23615 doc
: /* *Relief thickness of tool-bar buttons. */);
23616 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23618 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23619 doc
: /* List of functions to call to fontify regions of text.
23620 Each function is called with one argument POS. Functions must
23621 fontify a region starting at POS in the current buffer, and give
23622 fontified regions the property `fontified'. */);
23623 Vfontification_functions
= Qnil
;
23624 Fmake_variable_buffer_local (Qfontification_functions
);
23626 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23627 &unibyte_display_via_language_environment
,
23628 doc
: /* *Non-nil means display unibyte text according to language environment.
23629 Specifically this means that unibyte non-ASCII characters
23630 are displayed by converting them to the equivalent multibyte characters
23631 according to the current language environment. As a result, they are
23632 displayed according to the current fontset. */);
23633 unibyte_display_via_language_environment
= 0;
23635 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23636 doc
: /* *Maximum height for resizing mini-windows.
23637 If a float, it specifies a fraction of the mini-window frame's height.
23638 If an integer, it specifies a number of lines. */);
23639 Vmax_mini_window_height
= make_float (0.25);
23641 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23642 doc
: /* *How to resize mini-windows.
23643 A value of nil means don't automatically resize mini-windows.
23644 A value of t means resize them to fit the text displayed in them.
23645 A value of `grow-only', the default, means let mini-windows grow
23646 only, until their display becomes empty, at which point the windows
23647 go back to their normal size. */);
23648 Vresize_mini_windows
= Qgrow_only
;
23650 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23651 doc
: /* Alist specifying how to blink the cursor off.
23652 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23653 `cursor-type' frame-parameter or variable equals ON-STATE,
23654 comparing using `equal', Emacs uses OFF-STATE to specify
23655 how to blink it off. ON-STATE and OFF-STATE are values for
23656 the `cursor-type' frame parameter.
23658 If a frame's ON-STATE has no entry in this list,
23659 the frame's other specifications determine how to blink the cursor off. */);
23660 Vblink_cursor_alist
= Qnil
;
23662 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23663 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23664 automatic_hscrolling_p
= 1;
23666 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23667 doc
: /* *How many columns away from the window edge point is allowed to get
23668 before automatic hscrolling will horizontally scroll the window. */);
23669 hscroll_margin
= 5;
23671 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23672 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23673 When point is less than `automatic-hscroll-margin' columns from the window
23674 edge, automatic hscrolling will scroll the window by the amount of columns
23675 determined by this variable. If its value is a positive integer, scroll that
23676 many columns. If it's a positive floating-point number, it specifies the
23677 fraction of the window's width to scroll. If it's nil or zero, point will be
23678 centered horizontally after the scroll. Any other value, including negative
23679 numbers, are treated as if the value were zero.
23681 Automatic hscrolling always moves point outside the scroll margin, so if
23682 point was more than scroll step columns inside the margin, the window will
23683 scroll more than the value given by the scroll step.
23685 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23686 and `scroll-right' overrides this variable's effect. */);
23687 Vhscroll_step
= make_number (0);
23689 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23690 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23691 Bind this around calls to `message' to let it take effect. */);
23692 message_truncate_lines
= 0;
23694 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23695 doc
: /* Normal hook run to update the menu bar definitions.
23696 Redisplay runs this hook before it redisplays the menu bar.
23697 This is used to update submenus such as Buffers,
23698 whose contents depend on various data. */);
23699 Vmenu_bar_update_hook
= Qnil
;
23701 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23702 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23703 inhibit_menubar_update
= 0;
23705 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23706 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23707 inhibit_eval_during_redisplay
= 0;
23709 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23710 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23711 inhibit_free_realized_faces
= 0;
23714 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23715 doc
: /* Inhibit try_window_id display optimization. */);
23716 inhibit_try_window_id
= 0;
23718 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23719 doc
: /* Inhibit try_window_reusing display optimization. */);
23720 inhibit_try_window_reusing
= 0;
23722 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23723 doc
: /* Inhibit try_cursor_movement display optimization. */);
23724 inhibit_try_cursor_movement
= 0;
23725 #endif /* GLYPH_DEBUG */
23729 /* Initialize this module when Emacs starts. */
23734 Lisp_Object root_window
;
23735 struct window
*mini_w
;
23737 current_header_line_height
= current_mode_line_height
= -1;
23739 CHARPOS (this_line_start_pos
) = 0;
23741 mini_w
= XWINDOW (minibuf_window
);
23742 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23744 if (!noninteractive
)
23746 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23749 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23750 set_window_height (root_window
,
23751 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23753 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23754 set_window_height (minibuf_window
, 1, 0);
23756 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23757 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23759 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23760 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23761 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23763 /* The default ellipsis glyphs `...'. */
23764 for (i
= 0; i
< 3; ++i
)
23765 default_invis_vector
[i
] = make_number ('.');
23769 /* Allocate the buffer for frame titles.
23770 Also used for `format-mode-line'. */
23772 mode_line_noprop_buf
= (char *) xmalloc (size
);
23773 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23774 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23775 mode_line_target
= MODE_LINE_DISPLAY
;
23778 help_echo_showing_p
= 0;
23782 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23783 (do not change this comment) */