1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985,86,87,88,93,94,95,97,98,99,2000,01,02,03,04
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
185 #include "termhooks.h"
186 #include "intervals.h"
189 #include "region-cache.h"
191 #include "blockinput.h"
193 #ifdef HAVE_X_WINDOWS
203 #ifndef FRAME_X_OUTPUT
204 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
207 #define INFINITY 10000000
209 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
211 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
212 extern int pending_menu_activation
;
215 extern int interrupt_input
;
216 extern int command_loop_level
;
218 extern Lisp_Object do_mouse_tracking
;
220 extern int minibuffer_auto_raise
;
221 extern Lisp_Object Vminibuffer_list
;
223 extern Lisp_Object Qface
;
224 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
226 extern Lisp_Object Voverriding_local_map
;
227 extern Lisp_Object Voverriding_local_map_menu_flag
;
228 extern Lisp_Object Qmenu_item
;
229 extern Lisp_Object Qwhen
;
230 extern Lisp_Object Qhelp_echo
;
232 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
233 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
234 Lisp_Object Qredisplay_end_trigger_functions
;
235 Lisp_Object Qinhibit_point_motion_hooks
;
236 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
237 Lisp_Object Qfontified
;
238 Lisp_Object Qgrow_only
;
239 Lisp_Object Qinhibit_eval_during_redisplay
;
240 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
243 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
246 Lisp_Object Qarrow
, Qhand
, Qtext
;
248 Lisp_Object Qrisky_local_variable
;
250 /* Holds the list (error). */
251 Lisp_Object list_of_error
;
253 /* Functions called to fontify regions of text. */
255 Lisp_Object Vfontification_functions
;
256 Lisp_Object Qfontification_functions
;
258 /* Non-zero means automatically select any window when the mouse
259 cursor moves into it. */
260 int mouse_autoselect_window
;
262 /* Non-zero means draw tool bar buttons raised when the mouse moves
265 int auto_raise_tool_bar_buttons_p
;
267 /* Non-zero means to reposition window if cursor line is only partially visible. */
269 int make_cursor_line_fully_visible_p
;
271 /* Margin around tool bar buttons in pixels. */
273 Lisp_Object Vtool_bar_button_margin
;
275 /* Thickness of shadow to draw around tool bar buttons. */
277 EMACS_INT tool_bar_button_relief
;
279 /* Non-zero means automatically resize tool-bars so that all tool-bar
280 items are visible, and no blank lines remain. */
282 int auto_resize_tool_bars_p
;
284 /* Non-zero means draw block and hollow cursor as wide as the glyph
285 under it. For example, if a block cursor is over a tab, it will be
286 drawn as wide as that tab on the display. */
288 int x_stretch_cursor_p
;
290 /* Non-nil means don't actually do any redisplay. */
292 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
294 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
296 int inhibit_eval_during_redisplay
;
298 /* Names of text properties relevant for redisplay. */
300 Lisp_Object Qdisplay
;
301 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
303 /* Symbols used in text property values. */
305 Lisp_Object Vdisplay_pixels_per_inch
;
306 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
307 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
310 Lisp_Object Qmargin
, Qpointer
;
311 Lisp_Object Qline_height
;
312 extern Lisp_Object Qheight
;
313 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
314 extern Lisp_Object Qscroll_bar
;
315 extern Lisp_Object Qcursor
;
317 /* Non-nil means highlight trailing whitespace. */
319 Lisp_Object Vshow_trailing_whitespace
;
321 /* Non-nil means escape non-break space and hyphens. */
323 Lisp_Object Vshow_nonbreak_escape
;
325 #ifdef HAVE_WINDOW_SYSTEM
326 extern Lisp_Object Voverflow_newline_into_fringe
;
328 /* Test if overflow newline into fringe. Called with iterator IT
329 at or past right window margin, and with IT->current_x set. */
331 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
332 (!NILP (Voverflow_newline_into_fringe) \
333 && FRAME_WINDOW_P (it->f) \
334 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
335 && it->current_x == it->last_visible_x)
337 #endif /* HAVE_WINDOW_SYSTEM */
339 /* Non-nil means show the text cursor in void text areas
340 i.e. in blank areas after eol and eob. This used to be
341 the default in 21.3. */
343 Lisp_Object Vvoid_text_area_pointer
;
345 /* Name of the face used to highlight trailing whitespace. */
347 Lisp_Object Qtrailing_whitespace
;
349 /* Name and number of the face used to highlight escape glyphs. */
351 Lisp_Object Qescape_glyph
;
353 /* The symbol `image' which is the car of the lists used to represent
358 /* The image map types. */
359 Lisp_Object QCmap
, QCpointer
;
360 Lisp_Object Qrect
, Qcircle
, Qpoly
;
362 /* Non-zero means print newline to stdout before next mini-buffer
365 int noninteractive_need_newline
;
367 /* Non-zero means print newline to message log before next message. */
369 static int message_log_need_newline
;
371 /* Three markers that message_dolog uses.
372 It could allocate them itself, but that causes trouble
373 in handling memory-full errors. */
374 static Lisp_Object message_dolog_marker1
;
375 static Lisp_Object message_dolog_marker2
;
376 static Lisp_Object message_dolog_marker3
;
378 /* The buffer position of the first character appearing entirely or
379 partially on the line of the selected window which contains the
380 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
381 redisplay optimization in redisplay_internal. */
383 static struct text_pos this_line_start_pos
;
385 /* Number of characters past the end of the line above, including the
386 terminating newline. */
388 static struct text_pos this_line_end_pos
;
390 /* The vertical positions and the height of this line. */
392 static int this_line_vpos
;
393 static int this_line_y
;
394 static int this_line_pixel_height
;
396 /* X position at which this display line starts. Usually zero;
397 negative if first character is partially visible. */
399 static int this_line_start_x
;
401 /* Buffer that this_line_.* variables are referring to. */
403 static struct buffer
*this_line_buffer
;
405 /* Nonzero means truncate lines in all windows less wide than the
408 int truncate_partial_width_windows
;
410 /* A flag to control how to display unibyte 8-bit character. */
412 int unibyte_display_via_language_environment
;
414 /* Nonzero means we have more than one non-mini-buffer-only frame.
415 Not guaranteed to be accurate except while parsing
416 frame-title-format. */
420 Lisp_Object Vglobal_mode_string
;
423 /* List of variables (symbols) which hold markers for overlay arrows.
424 The symbols on this list are examined during redisplay to determine
425 where to display overlay arrows. */
427 Lisp_Object Voverlay_arrow_variable_list
;
429 /* Marker for where to display an arrow on top of the buffer text. */
431 Lisp_Object Voverlay_arrow_position
;
433 /* String to display for the arrow. Only used on terminal frames. */
435 Lisp_Object Voverlay_arrow_string
;
437 /* Values of those variables at last redisplay are stored as
438 properties on `overlay-arrow-position' symbol. However, if
439 Voverlay_arrow_position is a marker, last-arrow-position is its
440 numerical position. */
442 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
444 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
445 properties on a symbol in overlay-arrow-variable-list. */
447 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
449 /* Like mode-line-format, but for the title bar on a visible frame. */
451 Lisp_Object Vframe_title_format
;
453 /* Like mode-line-format, but for the title bar on an iconified frame. */
455 Lisp_Object Vicon_title_format
;
457 /* List of functions to call when a window's size changes. These
458 functions get one arg, a frame on which one or more windows' sizes
461 static Lisp_Object Vwindow_size_change_functions
;
463 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
465 /* Nonzero if overlay arrow has been displayed once in this window. */
467 static int overlay_arrow_seen
;
469 /* Nonzero means highlight the region even in nonselected windows. */
471 int highlight_nonselected_windows
;
473 /* If cursor motion alone moves point off frame, try scrolling this
474 many lines up or down if that will bring it back. */
476 static EMACS_INT scroll_step
;
478 /* Nonzero means scroll just far enough to bring point back on the
479 screen, when appropriate. */
481 static EMACS_INT scroll_conservatively
;
483 /* Recenter the window whenever point gets within this many lines of
484 the top or bottom of the window. This value is translated into a
485 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
486 that there is really a fixed pixel height scroll margin. */
488 EMACS_INT scroll_margin
;
490 /* Number of windows showing the buffer of the selected window (or
491 another buffer with the same base buffer). keyboard.c refers to
496 /* Vector containing glyphs for an ellipsis `...'. */
498 static Lisp_Object default_invis_vector
[3];
500 /* Zero means display the mode-line/header-line/menu-bar in the default face
501 (this slightly odd definition is for compatibility with previous versions
502 of emacs), non-zero means display them using their respective faces.
504 This variable is deprecated. */
506 int mode_line_inverse_video
;
508 /* Prompt to display in front of the mini-buffer contents. */
510 Lisp_Object minibuf_prompt
;
512 /* Width of current mini-buffer prompt. Only set after display_line
513 of the line that contains the prompt. */
515 int minibuf_prompt_width
;
517 /* This is the window where the echo area message was displayed. It
518 is always a mini-buffer window, but it may not be the same window
519 currently active as a mini-buffer. */
521 Lisp_Object echo_area_window
;
523 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
524 pushes the current message and the value of
525 message_enable_multibyte on the stack, the function restore_message
526 pops the stack and displays MESSAGE again. */
528 Lisp_Object Vmessage_stack
;
530 /* Nonzero means multibyte characters were enabled when the echo area
531 message was specified. */
533 int message_enable_multibyte
;
535 /* Nonzero if we should redraw the mode lines on the next redisplay. */
537 int update_mode_lines
;
539 /* Nonzero if window sizes or contents have changed since last
540 redisplay that finished. */
542 int windows_or_buffers_changed
;
544 /* Nonzero means a frame's cursor type has been changed. */
546 int cursor_type_changed
;
548 /* Nonzero after display_mode_line if %l was used and it displayed a
551 int line_number_displayed
;
553 /* Maximum buffer size for which to display line numbers. */
555 Lisp_Object Vline_number_display_limit
;
557 /* Line width to consider when repositioning for line number display. */
559 static EMACS_INT line_number_display_limit_width
;
561 /* Number of lines to keep in the message log buffer. t means
562 infinite. nil means don't log at all. */
564 Lisp_Object Vmessage_log_max
;
566 /* The name of the *Messages* buffer, a string. */
568 static Lisp_Object Vmessages_buffer_name
;
570 /* Current, index 0, and last displayed echo area message. Either
571 buffers from echo_buffers, or nil to indicate no message. */
573 Lisp_Object echo_area_buffer
[2];
575 /* The buffers referenced from echo_area_buffer. */
577 static Lisp_Object echo_buffer
[2];
579 /* A vector saved used in with_area_buffer to reduce consing. */
581 static Lisp_Object Vwith_echo_area_save_vector
;
583 /* Non-zero means display_echo_area should display the last echo area
584 message again. Set by redisplay_preserve_echo_area. */
586 static int display_last_displayed_message_p
;
588 /* Nonzero if echo area is being used by print; zero if being used by
591 int message_buf_print
;
593 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
595 Lisp_Object Qinhibit_menubar_update
;
596 int inhibit_menubar_update
;
598 /* Maximum height for resizing mini-windows. Either a float
599 specifying a fraction of the available height, or an integer
600 specifying a number of lines. */
602 Lisp_Object Vmax_mini_window_height
;
604 /* Non-zero means messages should be displayed with truncated
605 lines instead of being continued. */
607 int message_truncate_lines
;
608 Lisp_Object Qmessage_truncate_lines
;
610 /* Set to 1 in clear_message to make redisplay_internal aware
611 of an emptied echo area. */
613 static int message_cleared_p
;
615 /* Non-zero means we want a hollow cursor in windows that are not
616 selected. Zero means there's no cursor in such windows. */
618 Lisp_Object Vcursor_in_non_selected_windows
;
619 Lisp_Object Qcursor_in_non_selected_windows
;
621 /* How to blink the default frame cursor off. */
622 Lisp_Object Vblink_cursor_alist
;
624 /* A scratch glyph row with contents used for generating truncation
625 glyphs. Also used in direct_output_for_insert. */
627 #define MAX_SCRATCH_GLYPHS 100
628 struct glyph_row scratch_glyph_row
;
629 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
631 /* Ascent and height of the last line processed by move_it_to. */
633 static int last_max_ascent
, last_height
;
635 /* Non-zero if there's a help-echo in the echo area. */
637 int help_echo_showing_p
;
639 /* If >= 0, computed, exact values of mode-line and header-line height
640 to use in the macros CURRENT_MODE_LINE_HEIGHT and
641 CURRENT_HEADER_LINE_HEIGHT. */
643 int current_mode_line_height
, current_header_line_height
;
645 /* The maximum distance to look ahead for text properties. Values
646 that are too small let us call compute_char_face and similar
647 functions too often which is expensive. Values that are too large
648 let us call compute_char_face and alike too often because we
649 might not be interested in text properties that far away. */
651 #define TEXT_PROP_DISTANCE_LIMIT 100
655 /* Variables to turn off display optimizations from Lisp. */
657 int inhibit_try_window_id
, inhibit_try_window_reusing
;
658 int inhibit_try_cursor_movement
;
660 /* Non-zero means print traces of redisplay if compiled with
663 int trace_redisplay_p
;
665 #endif /* GLYPH_DEBUG */
667 #ifdef DEBUG_TRACE_MOVE
668 /* Non-zero means trace with TRACE_MOVE to stderr. */
671 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
673 #define TRACE_MOVE(x) (void) 0
676 /* Non-zero means automatically scroll windows horizontally to make
679 int automatic_hscrolling_p
;
681 /* How close to the margin can point get before the window is scrolled
683 EMACS_INT hscroll_margin
;
685 /* How much to scroll horizontally when point is inside the above margin. */
686 Lisp_Object Vhscroll_step
;
688 /* The variable `resize-mini-windows'. If nil, don't resize
689 mini-windows. If t, always resize them to fit the text they
690 display. If `grow-only', let mini-windows grow only until they
693 Lisp_Object Vresize_mini_windows
;
695 /* Buffer being redisplayed -- for redisplay_window_error. */
697 struct buffer
*displayed_buffer
;
699 /* Value returned from text property handlers (see below). */
704 HANDLED_RECOMPUTE_PROPS
,
705 HANDLED_OVERLAY_STRING_CONSUMED
,
709 /* A description of text properties that redisplay is interested
714 /* The name of the property. */
717 /* A unique index for the property. */
720 /* A handler function called to set up iterator IT from the property
721 at IT's current position. Value is used to steer handle_stop. */
722 enum prop_handled (*handler
) P_ ((struct it
*it
));
725 static enum prop_handled handle_face_prop
P_ ((struct it
*));
726 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
727 static enum prop_handled handle_display_prop
P_ ((struct it
*));
728 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
729 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
730 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
732 /* Properties handled by iterators. */
734 static struct props it_props
[] =
736 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
737 /* Handle `face' before `display' because some sub-properties of
738 `display' need to know the face. */
739 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
740 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
741 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
742 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
746 /* Value is the position described by X. If X is a marker, value is
747 the marker_position of X. Otherwise, value is X. */
749 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
751 /* Enumeration returned by some move_it_.* functions internally. */
755 /* Not used. Undefined value. */
758 /* Move ended at the requested buffer position or ZV. */
759 MOVE_POS_MATCH_OR_ZV
,
761 /* Move ended at the requested X pixel position. */
764 /* Move within a line ended at the end of a line that must be
768 /* Move within a line ended at the end of a line that would
769 be displayed truncated. */
772 /* Move within a line ended at a line end. */
776 /* This counter is used to clear the face cache every once in a while
777 in redisplay_internal. It is incremented for each redisplay.
778 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
781 #define CLEAR_FACE_CACHE_COUNT 500
782 static int clear_face_cache_count
;
784 /* Record the previous terminal frame we displayed. */
786 static struct frame
*previous_terminal_frame
;
788 /* Non-zero while redisplay_internal is in progress. */
792 /* Non-zero means don't free realized faces. Bound while freeing
793 realized faces is dangerous because glyph matrices might still
796 int inhibit_free_realized_faces
;
797 Lisp_Object Qinhibit_free_realized_faces
;
799 /* If a string, XTread_socket generates an event to display that string.
800 (The display is done in read_char.) */
802 Lisp_Object help_echo_string
;
803 Lisp_Object help_echo_window
;
804 Lisp_Object help_echo_object
;
807 /* Temporary variable for XTread_socket. */
809 Lisp_Object previous_help_echo_string
;
811 /* Null glyph slice */
813 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
816 /* Function prototypes. */
818 static void setup_for_ellipsis
P_ ((struct it
*, int));
819 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
820 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
821 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
822 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
823 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
824 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
827 static int invisible_text_between_p
P_ ((struct it
*, int, int));
830 static int next_element_from_ellipsis
P_ ((struct it
*));
831 static void pint2str
P_ ((char *, int, int));
832 static void pint2hrstr
P_ ((char *, int, int));
833 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
835 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
836 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
837 static void store_frame_title_char
P_ ((char));
838 static int store_frame_title
P_ ((const unsigned char *, int, int));
839 static void x_consider_frame_title
P_ ((Lisp_Object
));
840 static void handle_stop
P_ ((struct it
*));
841 static int tool_bar_lines_needed
P_ ((struct frame
*));
842 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
843 static void ensure_echo_area_buffers
P_ ((void));
844 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
845 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
846 static int with_echo_area_buffer
P_ ((struct window
*, int,
847 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
848 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
849 static void clear_garbaged_frames
P_ ((void));
850 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
851 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
852 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
853 static int display_echo_area
P_ ((struct window
*));
854 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
855 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
856 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
857 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
858 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
860 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
861 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
862 static void insert_left_trunc_glyphs
P_ ((struct it
*));
863 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
865 static void extend_face_to_end_of_line
P_ ((struct it
*));
866 static int append_space_for_newline
P_ ((struct it
*, int));
867 static int make_cursor_line_fully_visible
P_ ((struct window
*, int));
868 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
869 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
870 static int trailing_whitespace_p
P_ ((int));
871 static int message_log_check_duplicate
P_ ((int, int, int, int));
872 static void push_it
P_ ((struct it
*));
873 static void pop_it
P_ ((struct it
*));
874 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
875 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
876 static void redisplay_internal
P_ ((int));
877 static int echo_area_display
P_ ((int));
878 static void redisplay_windows
P_ ((Lisp_Object
));
879 static void redisplay_window
P_ ((Lisp_Object
, int));
880 static Lisp_Object
redisplay_window_error ();
881 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
882 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
883 static void update_menu_bar
P_ ((struct frame
*, int));
884 static int try_window_reusing_current_matrix
P_ ((struct window
*));
885 static int try_window_id
P_ ((struct window
*));
886 static int display_line
P_ ((struct it
*));
887 static int display_mode_lines
P_ ((struct window
*));
888 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
889 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
890 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
891 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
892 static void display_menu_bar
P_ ((struct window
*));
893 static int display_count_lines
P_ ((int, int, int, int, int *));
894 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
895 int, int, struct it
*, int, int, int, int));
896 static void compute_line_metrics
P_ ((struct it
*));
897 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
898 static int get_overlay_strings
P_ ((struct it
*, int));
899 static void next_overlay_string
P_ ((struct it
*));
900 static void reseat
P_ ((struct it
*, struct text_pos
, int));
901 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
902 static void back_to_previous_visible_line_start
P_ ((struct it
*));
903 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
904 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
905 static int next_element_from_display_vector
P_ ((struct it
*));
906 static int next_element_from_string
P_ ((struct it
*));
907 static int next_element_from_c_string
P_ ((struct it
*));
908 static int next_element_from_buffer
P_ ((struct it
*));
909 static int next_element_from_composition
P_ ((struct it
*));
910 static int next_element_from_image
P_ ((struct it
*));
911 static int next_element_from_stretch
P_ ((struct it
*));
912 static void load_overlay_strings
P_ ((struct it
*, int));
913 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
914 struct display_pos
*));
915 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
916 Lisp_Object
, int, int, int, int));
917 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
919 void move_it_vertically_backward
P_ ((struct it
*, int));
920 static void init_to_row_start
P_ ((struct it
*, struct window
*,
921 struct glyph_row
*));
922 static int init_to_row_end
P_ ((struct it
*, struct window
*,
923 struct glyph_row
*));
924 static void back_to_previous_line_start
P_ ((struct it
*));
925 static int forward_to_next_line_start
P_ ((struct it
*, int *));
926 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
928 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
929 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
930 static int number_of_chars
P_ ((unsigned char *, int));
931 static void compute_stop_pos
P_ ((struct it
*));
932 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
934 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
935 static int next_overlay_change
P_ ((int));
936 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
937 Lisp_Object
, struct text_pos
*,
939 static int underlying_face_id
P_ ((struct it
*));
940 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
943 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
944 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
946 #ifdef HAVE_WINDOW_SYSTEM
948 static void update_tool_bar
P_ ((struct frame
*, int));
949 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
950 static int redisplay_tool_bar
P_ ((struct frame
*));
951 static void display_tool_bar_line
P_ ((struct it
*));
952 static void notice_overwritten_cursor
P_ ((struct window
*,
954 int, int, int, int));
958 #endif /* HAVE_WINDOW_SYSTEM */
961 /***********************************************************************
962 Window display dimensions
963 ***********************************************************************/
965 /* Return the bottom boundary y-position for text lines in window W.
966 This is the first y position at which a line cannot start.
967 It is relative to the top of the window.
969 This is the height of W minus the height of a mode line, if any. */
972 window_text_bottom_y (w
)
975 int height
= WINDOW_TOTAL_HEIGHT (w
);
977 if (WINDOW_WANTS_MODELINE_P (w
))
978 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
982 /* Return the pixel width of display area AREA of window W. AREA < 0
983 means return the total width of W, not including fringes to
984 the left and right of the window. */
987 window_box_width (w
, area
)
991 int cols
= XFASTINT (w
->total_cols
);
994 if (!w
->pseudo_window_p
)
996 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
998 if (area
== TEXT_AREA
)
1000 if (INTEGERP (w
->left_margin_cols
))
1001 cols
-= XFASTINT (w
->left_margin_cols
);
1002 if (INTEGERP (w
->right_margin_cols
))
1003 cols
-= XFASTINT (w
->right_margin_cols
);
1004 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1006 else if (area
== LEFT_MARGIN_AREA
)
1008 cols
= (INTEGERP (w
->left_margin_cols
)
1009 ? XFASTINT (w
->left_margin_cols
) : 0);
1012 else if (area
== RIGHT_MARGIN_AREA
)
1014 cols
= (INTEGERP (w
->right_margin_cols
)
1015 ? XFASTINT (w
->right_margin_cols
) : 0);
1020 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1024 /* Return the pixel height of the display area of window W, not
1025 including mode lines of W, if any. */
1028 window_box_height (w
)
1031 struct frame
*f
= XFRAME (w
->frame
);
1032 int height
= WINDOW_TOTAL_HEIGHT (w
);
1034 xassert (height
>= 0);
1036 /* Note: the code below that determines the mode-line/header-line
1037 height is essentially the same as that contained in the macro
1038 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1039 the appropriate glyph row has its `mode_line_p' flag set,
1040 and if it doesn't, uses estimate_mode_line_height instead. */
1042 if (WINDOW_WANTS_MODELINE_P (w
))
1044 struct glyph_row
*ml_row
1045 = (w
->current_matrix
&& w
->current_matrix
->rows
1046 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1048 if (ml_row
&& ml_row
->mode_line_p
)
1049 height
-= ml_row
->height
;
1051 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1054 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1056 struct glyph_row
*hl_row
1057 = (w
->current_matrix
&& w
->current_matrix
->rows
1058 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1060 if (hl_row
&& hl_row
->mode_line_p
)
1061 height
-= hl_row
->height
;
1063 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1066 /* With a very small font and a mode-line that's taller than
1067 default, we might end up with a negative height. */
1068 return max (0, height
);
1071 /* Return the window-relative coordinate of the left edge of display
1072 area AREA of window W. AREA < 0 means return the left edge of the
1073 whole window, to the right of the left fringe of W. */
1076 window_box_left_offset (w
, area
)
1082 if (w
->pseudo_window_p
)
1085 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1087 if (area
== TEXT_AREA
)
1088 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1089 + window_box_width (w
, LEFT_MARGIN_AREA
));
1090 else if (area
== RIGHT_MARGIN_AREA
)
1091 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1092 + window_box_width (w
, LEFT_MARGIN_AREA
)
1093 + window_box_width (w
, TEXT_AREA
)
1094 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1096 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1097 else if (area
== LEFT_MARGIN_AREA
1098 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1099 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1105 /* Return the window-relative coordinate of the right edge of display
1106 area AREA of window W. AREA < 0 means return the left edge of the
1107 whole window, to the left of the right fringe of W. */
1110 window_box_right_offset (w
, area
)
1114 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1117 /* Return the frame-relative coordinate of the left edge of display
1118 area AREA of window W. AREA < 0 means return the left edge of the
1119 whole window, to the right of the left fringe of W. */
1122 window_box_left (w
, area
)
1126 struct frame
*f
= XFRAME (w
->frame
);
1129 if (w
->pseudo_window_p
)
1130 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1132 x
= (WINDOW_LEFT_EDGE_X (w
)
1133 + window_box_left_offset (w
, area
));
1139 /* Return the frame-relative coordinate of the right edge of display
1140 area AREA of window W. AREA < 0 means return the left edge of the
1141 whole window, to the left of the right fringe of W. */
1144 window_box_right (w
, area
)
1148 return window_box_left (w
, area
) + window_box_width (w
, area
);
1151 /* Get the bounding box of the display area AREA of window W, without
1152 mode lines, in frame-relative coordinates. AREA < 0 means the
1153 whole window, not including the left and right fringes of
1154 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1155 coordinates of the upper-left corner of the box. Return in
1156 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1159 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1162 int *box_x
, *box_y
, *box_width
, *box_height
;
1165 *box_width
= window_box_width (w
, area
);
1167 *box_height
= window_box_height (w
);
1169 *box_x
= window_box_left (w
, area
);
1172 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1173 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1174 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1179 /* Get the bounding box of the display area AREA of window W, without
1180 mode lines. AREA < 0 means the whole window, not including the
1181 left and right fringe of the window. Return in *TOP_LEFT_X
1182 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1183 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1184 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1188 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1189 bottom_right_x
, bottom_right_y
)
1192 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1194 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1196 *bottom_right_x
+= *top_left_x
;
1197 *bottom_right_y
+= *top_left_y
;
1202 /***********************************************************************
1204 ***********************************************************************/
1206 /* Return the bottom y-position of the line the iterator IT is in.
1207 This can modify IT's settings. */
1213 int line_height
= it
->max_ascent
+ it
->max_descent
;
1214 int line_top_y
= it
->current_y
;
1216 if (line_height
== 0)
1219 line_height
= last_height
;
1220 else if (IT_CHARPOS (*it
) < ZV
)
1222 move_it_by_lines (it
, 1, 1);
1223 line_height
= (it
->max_ascent
|| it
->max_descent
1224 ? it
->max_ascent
+ it
->max_descent
1229 struct glyph_row
*row
= it
->glyph_row
;
1231 /* Use the default character height. */
1232 it
->glyph_row
= NULL
;
1233 it
->what
= IT_CHARACTER
;
1236 PRODUCE_GLYPHS (it
);
1237 line_height
= it
->ascent
+ it
->descent
;
1238 it
->glyph_row
= row
;
1242 return line_top_y
+ line_height
;
1246 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1247 1 if POS is visible and the line containing POS is fully visible.
1248 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1249 and header-lines heights. */
1252 pos_visible_p (w
, charpos
, fully
, x
, y
, exact_mode_line_heights_p
)
1254 int charpos
, *fully
, *x
, *y
, exact_mode_line_heights_p
;
1257 struct text_pos top
;
1259 struct buffer
*old_buffer
= NULL
;
1261 if (XBUFFER (w
->buffer
) != current_buffer
)
1263 old_buffer
= current_buffer
;
1264 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1267 *fully
= visible_p
= 0;
1268 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1270 /* Compute exact mode line heights, if requested. */
1271 if (exact_mode_line_heights_p
)
1273 if (WINDOW_WANTS_MODELINE_P (w
))
1274 current_mode_line_height
1275 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1276 current_buffer
->mode_line_format
);
1278 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1279 current_header_line_height
1280 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1281 current_buffer
->header_line_format
);
1284 start_display (&it
, w
, top
);
1285 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1286 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1288 /* Note that we may overshoot because of invisible text. */
1289 if (IT_CHARPOS (it
) >= charpos
)
1291 int top_y
= it
.current_y
;
1292 int bottom_y
= line_bottom_y (&it
);
1293 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1295 if (top_y
< window_top_y
)
1296 visible_p
= bottom_y
> window_top_y
;
1297 else if (top_y
< it
.last_visible_y
)
1300 *fully
= bottom_y
<= it
.last_visible_y
;
1305 *y
= max (top_y
+ it
.max_ascent
- it
.ascent
, window_top_y
);
1308 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1313 move_it_by_lines (&it
, 1, 0);
1314 if (charpos
< IT_CHARPOS (it
))
1319 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1321 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1327 set_buffer_internal_1 (old_buffer
);
1329 current_header_line_height
= current_mode_line_height
= -1;
1335 /* Return the next character from STR which is MAXLEN bytes long.
1336 Return in *LEN the length of the character. This is like
1337 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1338 we find one, we return a `?', but with the length of the invalid
1342 string_char_and_length (str
, maxlen
, len
)
1343 const unsigned char *str
;
1348 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1349 if (!CHAR_VALID_P (c
, 1))
1350 /* We may not change the length here because other places in Emacs
1351 don't use this function, i.e. they silently accept invalid
1360 /* Given a position POS containing a valid character and byte position
1361 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1363 static struct text_pos
1364 string_pos_nchars_ahead (pos
, string
, nchars
)
1365 struct text_pos pos
;
1369 xassert (STRINGP (string
) && nchars
>= 0);
1371 if (STRING_MULTIBYTE (string
))
1373 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1374 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1379 string_char_and_length (p
, rest
, &len
);
1380 p
+= len
, rest
-= len
;
1381 xassert (rest
>= 0);
1383 BYTEPOS (pos
) += len
;
1387 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1393 /* Value is the text position, i.e. character and byte position,
1394 for character position CHARPOS in STRING. */
1396 static INLINE
struct text_pos
1397 string_pos (charpos
, string
)
1401 struct text_pos pos
;
1402 xassert (STRINGP (string
));
1403 xassert (charpos
>= 0);
1404 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1409 /* Value is a text position, i.e. character and byte position, for
1410 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1411 means recognize multibyte characters. */
1413 static struct text_pos
1414 c_string_pos (charpos
, s
, multibyte_p
)
1419 struct text_pos pos
;
1421 xassert (s
!= NULL
);
1422 xassert (charpos
>= 0);
1426 int rest
= strlen (s
), len
;
1428 SET_TEXT_POS (pos
, 0, 0);
1431 string_char_and_length (s
, rest
, &len
);
1432 s
+= len
, rest
-= len
;
1433 xassert (rest
>= 0);
1435 BYTEPOS (pos
) += len
;
1439 SET_TEXT_POS (pos
, charpos
, charpos
);
1445 /* Value is the number of characters in C string S. MULTIBYTE_P
1446 non-zero means recognize multibyte characters. */
1449 number_of_chars (s
, multibyte_p
)
1457 int rest
= strlen (s
), len
;
1458 unsigned char *p
= (unsigned char *) s
;
1460 for (nchars
= 0; rest
> 0; ++nchars
)
1462 string_char_and_length (p
, rest
, &len
);
1463 rest
-= len
, p
+= len
;
1467 nchars
= strlen (s
);
1473 /* Compute byte position NEWPOS->bytepos corresponding to
1474 NEWPOS->charpos. POS is a known position in string STRING.
1475 NEWPOS->charpos must be >= POS.charpos. */
1478 compute_string_pos (newpos
, pos
, string
)
1479 struct text_pos
*newpos
, pos
;
1482 xassert (STRINGP (string
));
1483 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1485 if (STRING_MULTIBYTE (string
))
1486 *newpos
= string_pos_nchars_ahead (pos
, string
,
1487 CHARPOS (*newpos
) - CHARPOS (pos
));
1489 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1493 Return an estimation of the pixel height of mode or top lines on
1494 frame F. FACE_ID specifies what line's height to estimate. */
1497 estimate_mode_line_height (f
, face_id
)
1499 enum face_id face_id
;
1501 #ifdef HAVE_WINDOW_SYSTEM
1502 if (FRAME_WINDOW_P (f
))
1504 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1506 /* This function is called so early when Emacs starts that the face
1507 cache and mode line face are not yet initialized. */
1508 if (FRAME_FACE_CACHE (f
))
1510 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1514 height
= FONT_HEIGHT (face
->font
);
1515 if (face
->box_line_width
> 0)
1516 height
+= 2 * face
->box_line_width
;
1527 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1528 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1529 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1530 not force the value into range. */
1533 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1535 register int pix_x
, pix_y
;
1537 NativeRectangle
*bounds
;
1541 #ifdef HAVE_WINDOW_SYSTEM
1542 if (FRAME_WINDOW_P (f
))
1544 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1545 even for negative values. */
1547 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1549 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1551 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1552 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1555 STORE_NATIVE_RECT (*bounds
,
1556 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1557 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1558 FRAME_COLUMN_WIDTH (f
) - 1,
1559 FRAME_LINE_HEIGHT (f
) - 1);
1565 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1566 pix_x
= FRAME_TOTAL_COLS (f
);
1570 else if (pix_y
> FRAME_LINES (f
))
1571 pix_y
= FRAME_LINES (f
);
1581 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1582 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1583 can't tell the positions because W's display is not up to date,
1587 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1590 int *frame_x
, *frame_y
;
1592 #ifdef HAVE_WINDOW_SYSTEM
1593 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1597 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1598 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1600 if (display_completed
)
1602 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1603 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1604 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1610 hpos
+= glyph
->pixel_width
;
1614 /* If first glyph is partially visible, its first visible position is still 0. */
1626 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1627 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1638 #ifdef HAVE_WINDOW_SYSTEM
1640 /* Find the glyph under window-relative coordinates X/Y in window W.
1641 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1642 strings. Return in *HPOS and *VPOS the row and column number of
1643 the glyph found. Return in *AREA the glyph area containing X.
1644 Value is a pointer to the glyph found or null if X/Y is not on
1645 text, or we can't tell because W's current matrix is not up to
1648 static struct glyph
*
1649 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1652 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1654 struct glyph
*glyph
, *end
;
1655 struct glyph_row
*row
= NULL
;
1658 /* Find row containing Y. Give up if some row is not enabled. */
1659 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1661 row
= MATRIX_ROW (w
->current_matrix
, i
);
1662 if (!row
->enabled_p
)
1664 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1671 /* Give up if Y is not in the window. */
1672 if (i
== w
->current_matrix
->nrows
)
1675 /* Get the glyph area containing X. */
1676 if (w
->pseudo_window_p
)
1683 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1685 *area
= LEFT_MARGIN_AREA
;
1686 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1688 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1691 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1695 *area
= RIGHT_MARGIN_AREA
;
1696 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1700 /* Find glyph containing X. */
1701 glyph
= row
->glyphs
[*area
];
1702 end
= glyph
+ row
->used
[*area
];
1704 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1706 x
-= glyph
->pixel_width
;
1716 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1719 *hpos
= glyph
- row
->glyphs
[*area
];
1725 Convert frame-relative x/y to coordinates relative to window W.
1726 Takes pseudo-windows into account. */
1729 frame_to_window_pixel_xy (w
, x
, y
)
1733 if (w
->pseudo_window_p
)
1735 /* A pseudo-window is always full-width, and starts at the
1736 left edge of the frame, plus a frame border. */
1737 struct frame
*f
= XFRAME (w
->frame
);
1738 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1739 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1743 *x
-= WINDOW_LEFT_EDGE_X (w
);
1744 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1749 Return in *R the clipping rectangle for glyph string S. */
1752 get_glyph_string_clip_rect (s
, nr
)
1753 struct glyph_string
*s
;
1754 NativeRectangle
*nr
;
1758 if (s
->row
->full_width_p
)
1760 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1761 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1762 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1764 /* Unless displaying a mode or menu bar line, which are always
1765 fully visible, clip to the visible part of the row. */
1766 if (s
->w
->pseudo_window_p
)
1767 r
.height
= s
->row
->visible_height
;
1769 r
.height
= s
->height
;
1773 /* This is a text line that may be partially visible. */
1774 r
.x
= window_box_left (s
->w
, s
->area
);
1775 r
.width
= window_box_width (s
->w
, s
->area
);
1776 r
.height
= s
->row
->visible_height
;
1779 /* If S draws overlapping rows, it's sufficient to use the top and
1780 bottom of the window for clipping because this glyph string
1781 intentionally draws over other lines. */
1782 if (s
->for_overlaps_p
)
1784 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1785 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1789 /* Don't use S->y for clipping because it doesn't take partially
1790 visible lines into account. For example, it can be negative for
1791 partially visible lines at the top of a window. */
1792 if (!s
->row
->full_width_p
1793 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1794 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1796 r
.y
= max (0, s
->row
->y
);
1798 /* If drawing a tool-bar window, draw it over the internal border
1799 at the top of the window. */
1800 if (WINDOWP (s
->f
->tool_bar_window
)
1801 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1802 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1805 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1807 /* If drawing the cursor, don't let glyph draw outside its
1808 advertised boundaries. Cleartype does this under some circumstances. */
1809 if (s
->hl
== DRAW_CURSOR
)
1811 struct glyph
*glyph
= s
->first_glyph
;
1816 r
.width
-= s
->x
- r
.x
;
1819 r
.width
= min (r
.width
, glyph
->pixel_width
);
1821 /* Don't draw cursor glyph taller than our actual glyph. */
1822 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1823 if (height
< r
.height
)
1825 int max_y
= r
.y
+ r
.height
;
1826 r
.y
= min (max_y
, s
->ybase
+ glyph
->descent
- height
);
1827 r
.height
= min (max_y
- r
.y
, height
);
1831 #ifdef CONVERT_FROM_XRECT
1832 CONVERT_FROM_XRECT (r
, *nr
);
1838 #endif /* HAVE_WINDOW_SYSTEM */
1841 /***********************************************************************
1842 Lisp form evaluation
1843 ***********************************************************************/
1845 /* Error handler for safe_eval and safe_call. */
1848 safe_eval_handler (arg
)
1851 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1856 /* Evaluate SEXPR and return the result, or nil if something went
1857 wrong. Prevent redisplay during the evaluation. */
1865 if (inhibit_eval_during_redisplay
)
1869 int count
= SPECPDL_INDEX ();
1870 struct gcpro gcpro1
;
1873 specbind (Qinhibit_redisplay
, Qt
);
1874 /* Use Qt to ensure debugger does not run,
1875 so there is no possibility of wanting to redisplay. */
1876 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1879 val
= unbind_to (count
, val
);
1886 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1887 Return the result, or nil if something went wrong. Prevent
1888 redisplay during the evaluation. */
1891 safe_call (nargs
, args
)
1897 if (inhibit_eval_during_redisplay
)
1901 int count
= SPECPDL_INDEX ();
1902 struct gcpro gcpro1
;
1905 gcpro1
.nvars
= nargs
;
1906 specbind (Qinhibit_redisplay
, Qt
);
1907 /* Use Qt to ensure debugger does not run,
1908 so there is no possibility of wanting to redisplay. */
1909 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1912 val
= unbind_to (count
, val
);
1919 /* Call function FN with one argument ARG.
1920 Return the result, or nil if something went wrong. */
1923 safe_call1 (fn
, arg
)
1924 Lisp_Object fn
, arg
;
1926 Lisp_Object args
[2];
1929 return safe_call (2, args
);
1934 /***********************************************************************
1936 ***********************************************************************/
1940 /* Define CHECK_IT to perform sanity checks on iterators.
1941 This is for debugging. It is too slow to do unconditionally. */
1947 if (it
->method
== next_element_from_string
)
1949 xassert (STRINGP (it
->string
));
1950 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1954 xassert (IT_STRING_CHARPOS (*it
) < 0);
1955 if (it
->method
== next_element_from_buffer
)
1957 /* Check that character and byte positions agree. */
1958 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1963 xassert (it
->current
.dpvec_index
>= 0);
1965 xassert (it
->current
.dpvec_index
< 0);
1968 #define CHECK_IT(IT) check_it ((IT))
1972 #define CHECK_IT(IT) (void) 0
1979 /* Check that the window end of window W is what we expect it
1980 to be---the last row in the current matrix displaying text. */
1983 check_window_end (w
)
1986 if (!MINI_WINDOW_P (w
)
1987 && !NILP (w
->window_end_valid
))
1989 struct glyph_row
*row
;
1990 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1991 XFASTINT (w
->window_end_vpos
)),
1993 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1994 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1998 #define CHECK_WINDOW_END(W) check_window_end ((W))
2000 #else /* not GLYPH_DEBUG */
2002 #define CHECK_WINDOW_END(W) (void) 0
2004 #endif /* not GLYPH_DEBUG */
2008 /***********************************************************************
2009 Iterator initialization
2010 ***********************************************************************/
2012 /* Initialize IT for displaying current_buffer in window W, starting
2013 at character position CHARPOS. CHARPOS < 0 means that no buffer
2014 position is specified which is useful when the iterator is assigned
2015 a position later. BYTEPOS is the byte position corresponding to
2016 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2018 If ROW is not null, calls to produce_glyphs with IT as parameter
2019 will produce glyphs in that row.
2021 BASE_FACE_ID is the id of a base face to use. It must be one of
2022 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2023 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2024 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2026 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2027 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2028 will be initialized to use the corresponding mode line glyph row of
2029 the desired matrix of W. */
2032 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2035 int charpos
, bytepos
;
2036 struct glyph_row
*row
;
2037 enum face_id base_face_id
;
2039 int highlight_region_p
;
2041 /* Some precondition checks. */
2042 xassert (w
!= NULL
&& it
!= NULL
);
2043 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2046 /* If face attributes have been changed since the last redisplay,
2047 free realized faces now because they depend on face definitions
2048 that might have changed. Don't free faces while there might be
2049 desired matrices pending which reference these faces. */
2050 if (face_change_count
&& !inhibit_free_realized_faces
)
2052 face_change_count
= 0;
2053 free_all_realized_faces (Qnil
);
2056 /* Use one of the mode line rows of W's desired matrix if
2060 if (base_face_id
== MODE_LINE_FACE_ID
2061 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2062 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2063 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2064 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2068 bzero (it
, sizeof *it
);
2069 it
->current
.overlay_string_index
= -1;
2070 it
->current
.dpvec_index
= -1;
2071 it
->base_face_id
= base_face_id
;
2073 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2075 /* The window in which we iterate over current_buffer: */
2076 XSETWINDOW (it
->window
, w
);
2078 it
->f
= XFRAME (w
->frame
);
2080 /* Extra space between lines (on window systems only). */
2081 if (base_face_id
== DEFAULT_FACE_ID
2082 && FRAME_WINDOW_P (it
->f
))
2084 if (NATNUMP (current_buffer
->extra_line_spacing
))
2085 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2086 else if (FLOATP (current_buffer
->extra_line_spacing
))
2087 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2088 * FRAME_LINE_HEIGHT (it
->f
));
2089 else if (it
->f
->extra_line_spacing
> 0)
2090 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2091 it
->max_extra_line_spacing
= 0;
2094 /* If realized faces have been removed, e.g. because of face
2095 attribute changes of named faces, recompute them. When running
2096 in batch mode, the face cache of Vterminal_frame is null. If
2097 we happen to get called, make a dummy face cache. */
2098 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2099 init_frame_faces (it
->f
);
2100 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2101 recompute_basic_faces (it
->f
);
2103 /* Current value of the `slice', `space-width', and 'height' properties. */
2104 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2105 it
->space_width
= Qnil
;
2106 it
->font_height
= Qnil
;
2107 it
->override_ascent
= -1;
2109 /* Are control characters displayed as `^C'? */
2110 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2112 /* -1 means everything between a CR and the following line end
2113 is invisible. >0 means lines indented more than this value are
2115 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2116 ? XFASTINT (current_buffer
->selective_display
)
2117 : (!NILP (current_buffer
->selective_display
)
2119 it
->selective_display_ellipsis_p
2120 = !NILP (current_buffer
->selective_display_ellipses
);
2122 /* Display table to use. */
2123 it
->dp
= window_display_table (w
);
2125 /* Are multibyte characters enabled in current_buffer? */
2126 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2128 /* Non-zero if we should highlight the region. */
2130 = (!NILP (Vtransient_mark_mode
)
2131 && !NILP (current_buffer
->mark_active
)
2132 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2134 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2135 start and end of a visible region in window IT->w. Set both to
2136 -1 to indicate no region. */
2137 if (highlight_region_p
2138 /* Maybe highlight only in selected window. */
2139 && (/* Either show region everywhere. */
2140 highlight_nonselected_windows
2141 /* Or show region in the selected window. */
2142 || w
== XWINDOW (selected_window
)
2143 /* Or show the region if we are in the mini-buffer and W is
2144 the window the mini-buffer refers to. */
2145 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2146 && WINDOWP (minibuf_selected_window
)
2147 && w
== XWINDOW (minibuf_selected_window
))))
2149 int charpos
= marker_position (current_buffer
->mark
);
2150 it
->region_beg_charpos
= min (PT
, charpos
);
2151 it
->region_end_charpos
= max (PT
, charpos
);
2154 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2156 /* Get the position at which the redisplay_end_trigger hook should
2157 be run, if it is to be run at all. */
2158 if (MARKERP (w
->redisplay_end_trigger
)
2159 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2160 it
->redisplay_end_trigger_charpos
2161 = marker_position (w
->redisplay_end_trigger
);
2162 else if (INTEGERP (w
->redisplay_end_trigger
))
2163 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2165 /* Correct bogus values of tab_width. */
2166 it
->tab_width
= XINT (current_buffer
->tab_width
);
2167 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2170 /* Are lines in the display truncated? */
2171 it
->truncate_lines_p
2172 = (base_face_id
!= DEFAULT_FACE_ID
2173 || XINT (it
->w
->hscroll
)
2174 || (truncate_partial_width_windows
2175 && !WINDOW_FULL_WIDTH_P (it
->w
))
2176 || !NILP (current_buffer
->truncate_lines
));
2178 /* Get dimensions of truncation and continuation glyphs. These are
2179 displayed as fringe bitmaps under X, so we don't need them for such
2181 if (!FRAME_WINDOW_P (it
->f
))
2183 if (it
->truncate_lines_p
)
2185 /* We will need the truncation glyph. */
2186 xassert (it
->glyph_row
== NULL
);
2187 produce_special_glyphs (it
, IT_TRUNCATION
);
2188 it
->truncation_pixel_width
= it
->pixel_width
;
2192 /* We will need the continuation glyph. */
2193 xassert (it
->glyph_row
== NULL
);
2194 produce_special_glyphs (it
, IT_CONTINUATION
);
2195 it
->continuation_pixel_width
= it
->pixel_width
;
2198 /* Reset these values to zero because the produce_special_glyphs
2199 above has changed them. */
2200 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2201 it
->phys_ascent
= it
->phys_descent
= 0;
2204 /* Set this after getting the dimensions of truncation and
2205 continuation glyphs, so that we don't produce glyphs when calling
2206 produce_special_glyphs, above. */
2207 it
->glyph_row
= row
;
2208 it
->area
= TEXT_AREA
;
2210 /* Get the dimensions of the display area. The display area
2211 consists of the visible window area plus a horizontally scrolled
2212 part to the left of the window. All x-values are relative to the
2213 start of this total display area. */
2214 if (base_face_id
!= DEFAULT_FACE_ID
)
2216 /* Mode lines, menu bar in terminal frames. */
2217 it
->first_visible_x
= 0;
2218 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2223 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2224 it
->last_visible_x
= (it
->first_visible_x
2225 + window_box_width (w
, TEXT_AREA
));
2227 /* If we truncate lines, leave room for the truncator glyph(s) at
2228 the right margin. Otherwise, leave room for the continuation
2229 glyph(s). Truncation and continuation glyphs are not inserted
2230 for window-based redisplay. */
2231 if (!FRAME_WINDOW_P (it
->f
))
2233 if (it
->truncate_lines_p
)
2234 it
->last_visible_x
-= it
->truncation_pixel_width
;
2236 it
->last_visible_x
-= it
->continuation_pixel_width
;
2239 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2240 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2243 /* Leave room for a border glyph. */
2244 if (!FRAME_WINDOW_P (it
->f
)
2245 && !WINDOW_RIGHTMOST_P (it
->w
))
2246 it
->last_visible_x
-= 1;
2248 it
->last_visible_y
= window_text_bottom_y (w
);
2250 /* For mode lines and alike, arrange for the first glyph having a
2251 left box line if the face specifies a box. */
2252 if (base_face_id
!= DEFAULT_FACE_ID
)
2256 it
->face_id
= base_face_id
;
2258 /* If we have a boxed mode line, make the first character appear
2259 with a left box line. */
2260 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2261 if (face
->box
!= FACE_NO_BOX
)
2262 it
->start_of_box_run_p
= 1;
2265 /* If a buffer position was specified, set the iterator there,
2266 getting overlays and face properties from that position. */
2267 if (charpos
>= BUF_BEG (current_buffer
))
2269 it
->end_charpos
= ZV
;
2271 IT_CHARPOS (*it
) = charpos
;
2273 /* Compute byte position if not specified. */
2274 if (bytepos
< charpos
)
2275 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2277 IT_BYTEPOS (*it
) = bytepos
;
2279 it
->start
= it
->current
;
2281 /* Compute faces etc. */
2282 reseat (it
, it
->current
.pos
, 1);
2289 /* Initialize IT for the display of window W with window start POS. */
2292 start_display (it
, w
, pos
)
2295 struct text_pos pos
;
2297 struct glyph_row
*row
;
2298 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2300 row
= w
->desired_matrix
->rows
+ first_vpos
;
2301 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2302 it
->first_vpos
= first_vpos
;
2304 if (!it
->truncate_lines_p
)
2306 int start_at_line_beg_p
;
2307 int first_y
= it
->current_y
;
2309 /* If window start is not at a line start, skip forward to POS to
2310 get the correct continuation lines width. */
2311 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2312 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2313 if (!start_at_line_beg_p
)
2317 reseat_at_previous_visible_line_start (it
);
2318 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2320 new_x
= it
->current_x
+ it
->pixel_width
;
2322 /* If lines are continued, this line may end in the middle
2323 of a multi-glyph character (e.g. a control character
2324 displayed as \003, or in the middle of an overlay
2325 string). In this case move_it_to above will not have
2326 taken us to the start of the continuation line but to the
2327 end of the continued line. */
2328 if (it
->current_x
> 0
2329 && !it
->truncate_lines_p
/* Lines are continued. */
2330 && (/* And glyph doesn't fit on the line. */
2331 new_x
> it
->last_visible_x
2332 /* Or it fits exactly and we're on a window
2334 || (new_x
== it
->last_visible_x
2335 && FRAME_WINDOW_P (it
->f
))))
2337 if (it
->current
.dpvec_index
>= 0
2338 || it
->current
.overlay_string_index
>= 0)
2340 set_iterator_to_next (it
, 1);
2341 move_it_in_display_line_to (it
, -1, -1, 0);
2344 it
->continuation_lines_width
+= it
->current_x
;
2347 /* We're starting a new display line, not affected by the
2348 height of the continued line, so clear the appropriate
2349 fields in the iterator structure. */
2350 it
->max_ascent
= it
->max_descent
= 0;
2351 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2353 it
->current_y
= first_y
;
2355 it
->current_x
= it
->hpos
= 0;
2359 #if 0 /* Don't assert the following because start_display is sometimes
2360 called intentionally with a window start that is not at a
2361 line start. Please leave this code in as a comment. */
2363 /* Window start should be on a line start, now. */
2364 xassert (it
->continuation_lines_width
2365 || IT_CHARPOS (it
) == BEGV
2366 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2371 /* Return 1 if POS is a position in ellipses displayed for invisible
2372 text. W is the window we display, for text property lookup. */
2375 in_ellipses_for_invisible_text_p (pos
, w
)
2376 struct display_pos
*pos
;
2379 Lisp_Object prop
, window
;
2381 int charpos
= CHARPOS (pos
->pos
);
2383 /* If POS specifies a position in a display vector, this might
2384 be for an ellipsis displayed for invisible text. We won't
2385 get the iterator set up for delivering that ellipsis unless
2386 we make sure that it gets aware of the invisible text. */
2387 if (pos
->dpvec_index
>= 0
2388 && pos
->overlay_string_index
< 0
2389 && CHARPOS (pos
->string_pos
) < 0
2391 && (XSETWINDOW (window
, w
),
2392 prop
= Fget_char_property (make_number (charpos
),
2393 Qinvisible
, window
),
2394 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2396 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2398 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2405 /* Initialize IT for stepping through current_buffer in window W,
2406 starting at position POS that includes overlay string and display
2407 vector/ control character translation position information. Value
2408 is zero if there are overlay strings with newlines at POS. */
2411 init_from_display_pos (it
, w
, pos
)
2414 struct display_pos
*pos
;
2416 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2417 int i
, overlay_strings_with_newlines
= 0;
2419 /* If POS specifies a position in a display vector, this might
2420 be for an ellipsis displayed for invisible text. We won't
2421 get the iterator set up for delivering that ellipsis unless
2422 we make sure that it gets aware of the invisible text. */
2423 if (in_ellipses_for_invisible_text_p (pos
, w
))
2429 /* Keep in mind: the call to reseat in init_iterator skips invisible
2430 text, so we might end up at a position different from POS. This
2431 is only a problem when POS is a row start after a newline and an
2432 overlay starts there with an after-string, and the overlay has an
2433 invisible property. Since we don't skip invisible text in
2434 display_line and elsewhere immediately after consuming the
2435 newline before the row start, such a POS will not be in a string,
2436 but the call to init_iterator below will move us to the
2438 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2440 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
2442 const char *s
= SDATA (it
->overlay_strings
[i
]);
2443 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2445 while (s
< e
&& *s
!= '\n')
2450 overlay_strings_with_newlines
= 1;
2455 /* If position is within an overlay string, set up IT to the right
2457 if (pos
->overlay_string_index
>= 0)
2461 /* If the first overlay string happens to have a `display'
2462 property for an image, the iterator will be set up for that
2463 image, and we have to undo that setup first before we can
2464 correct the overlay string index. */
2465 if (it
->method
== next_element_from_image
)
2468 /* We already have the first chunk of overlay strings in
2469 IT->overlay_strings. Load more until the one for
2470 pos->overlay_string_index is in IT->overlay_strings. */
2471 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2473 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2474 it
->current
.overlay_string_index
= 0;
2477 load_overlay_strings (it
, 0);
2478 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2482 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2483 relative_index
= (it
->current
.overlay_string_index
2484 % OVERLAY_STRING_CHUNK_SIZE
);
2485 it
->string
= it
->overlay_strings
[relative_index
];
2486 xassert (STRINGP (it
->string
));
2487 it
->current
.string_pos
= pos
->string_pos
;
2488 it
->method
= next_element_from_string
;
2491 #if 0 /* This is bogus because POS not having an overlay string
2492 position does not mean it's after the string. Example: A
2493 line starting with a before-string and initialization of IT
2494 to the previous row's end position. */
2495 else if (it
->current
.overlay_string_index
>= 0)
2497 /* If POS says we're already after an overlay string ending at
2498 POS, make sure to pop the iterator because it will be in
2499 front of that overlay string. When POS is ZV, we've thereby
2500 also ``processed'' overlay strings at ZV. */
2503 it
->current
.overlay_string_index
= -1;
2504 it
->method
= next_element_from_buffer
;
2505 if (CHARPOS (pos
->pos
) == ZV
)
2506 it
->overlay_strings_at_end_processed_p
= 1;
2510 if (CHARPOS (pos
->string_pos
) >= 0)
2512 /* Recorded position is not in an overlay string, but in another
2513 string. This can only be a string from a `display' property.
2514 IT should already be filled with that string. */
2515 it
->current
.string_pos
= pos
->string_pos
;
2516 xassert (STRINGP (it
->string
));
2519 /* Restore position in display vector translations, control
2520 character translations or ellipses. */
2521 if (pos
->dpvec_index
>= 0)
2523 if (it
->dpvec
== NULL
)
2524 get_next_display_element (it
);
2525 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2526 it
->current
.dpvec_index
= pos
->dpvec_index
;
2530 return !overlay_strings_with_newlines
;
2534 /* Initialize IT for stepping through current_buffer in window W
2535 starting at ROW->start. */
2538 init_to_row_start (it
, w
, row
)
2541 struct glyph_row
*row
;
2543 init_from_display_pos (it
, w
, &row
->start
);
2544 it
->start
= row
->start
;
2545 it
->continuation_lines_width
= row
->continuation_lines_width
;
2550 /* Initialize IT for stepping through current_buffer in window W
2551 starting in the line following ROW, i.e. starting at ROW->end.
2552 Value is zero if there are overlay strings with newlines at ROW's
2556 init_to_row_end (it
, w
, row
)
2559 struct glyph_row
*row
;
2563 if (init_from_display_pos (it
, w
, &row
->end
))
2565 if (row
->continued_p
)
2566 it
->continuation_lines_width
2567 = row
->continuation_lines_width
+ row
->pixel_width
;
2578 /***********************************************************************
2580 ***********************************************************************/
2582 /* Called when IT reaches IT->stop_charpos. Handle text property and
2583 overlay changes. Set IT->stop_charpos to the next position where
2590 enum prop_handled handled
;
2591 int handle_overlay_change_p
= 1;
2595 it
->current
.dpvec_index
= -1;
2599 handled
= HANDLED_NORMALLY
;
2601 /* Call text property handlers. */
2602 for (p
= it_props
; p
->handler
; ++p
)
2604 handled
= p
->handler (it
);
2606 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2608 else if (handled
== HANDLED_RETURN
)
2610 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2611 handle_overlay_change_p
= 0;
2614 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2616 /* Don't check for overlay strings below when set to deliver
2617 characters from a display vector. */
2618 if (it
->method
== next_element_from_display_vector
)
2619 handle_overlay_change_p
= 0;
2621 /* Handle overlay changes. */
2622 if (handle_overlay_change_p
)
2623 handled
= handle_overlay_change (it
);
2625 /* Determine where to stop next. */
2626 if (handled
== HANDLED_NORMALLY
)
2627 compute_stop_pos (it
);
2630 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2634 /* Compute IT->stop_charpos from text property and overlay change
2635 information for IT's current position. */
2638 compute_stop_pos (it
)
2641 register INTERVAL iv
, next_iv
;
2642 Lisp_Object object
, limit
, position
;
2644 /* If nowhere else, stop at the end. */
2645 it
->stop_charpos
= it
->end_charpos
;
2647 if (STRINGP (it
->string
))
2649 /* Strings are usually short, so don't limit the search for
2651 object
= it
->string
;
2653 position
= make_number (IT_STRING_CHARPOS (*it
));
2659 /* If next overlay change is in front of the current stop pos
2660 (which is IT->end_charpos), stop there. Note: value of
2661 next_overlay_change is point-max if no overlay change
2663 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2664 if (charpos
< it
->stop_charpos
)
2665 it
->stop_charpos
= charpos
;
2667 /* If showing the region, we have to stop at the region
2668 start or end because the face might change there. */
2669 if (it
->region_beg_charpos
> 0)
2671 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2672 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2673 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2674 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2677 /* Set up variables for computing the stop position from text
2678 property changes. */
2679 XSETBUFFER (object
, current_buffer
);
2680 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2681 position
= make_number (IT_CHARPOS (*it
));
2685 /* Get the interval containing IT's position. Value is a null
2686 interval if there isn't such an interval. */
2687 iv
= validate_interval_range (object
, &position
, &position
, 0);
2688 if (!NULL_INTERVAL_P (iv
))
2690 Lisp_Object values_here
[LAST_PROP_IDX
];
2693 /* Get properties here. */
2694 for (p
= it_props
; p
->handler
; ++p
)
2695 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2697 /* Look for an interval following iv that has different
2699 for (next_iv
= next_interval (iv
);
2700 (!NULL_INTERVAL_P (next_iv
)
2702 || XFASTINT (limit
) > next_iv
->position
));
2703 next_iv
= next_interval (next_iv
))
2705 for (p
= it_props
; p
->handler
; ++p
)
2707 Lisp_Object new_value
;
2709 new_value
= textget (next_iv
->plist
, *p
->name
);
2710 if (!EQ (values_here
[p
->idx
], new_value
))
2718 if (!NULL_INTERVAL_P (next_iv
))
2720 if (INTEGERP (limit
)
2721 && next_iv
->position
>= XFASTINT (limit
))
2722 /* No text property change up to limit. */
2723 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2725 /* Text properties change in next_iv. */
2726 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2730 xassert (STRINGP (it
->string
)
2731 || (it
->stop_charpos
>= BEGV
2732 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2736 /* Return the position of the next overlay change after POS in
2737 current_buffer. Value is point-max if no overlay change
2738 follows. This is like `next-overlay-change' but doesn't use
2742 next_overlay_change (pos
)
2747 Lisp_Object
*overlays
;
2750 /* Get all overlays at the given position. */
2751 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
2753 /* If any of these overlays ends before endpos,
2754 use its ending point instead. */
2755 for (i
= 0; i
< noverlays
; ++i
)
2760 oend
= OVERLAY_END (overlays
[i
]);
2761 oendpos
= OVERLAY_POSITION (oend
);
2762 endpos
= min (endpos
, oendpos
);
2770 /***********************************************************************
2772 ***********************************************************************/
2774 /* Handle changes in the `fontified' property of the current buffer by
2775 calling hook functions from Qfontification_functions to fontify
2778 static enum prop_handled
2779 handle_fontified_prop (it
)
2782 Lisp_Object prop
, pos
;
2783 enum prop_handled handled
= HANDLED_NORMALLY
;
2785 /* Get the value of the `fontified' property at IT's current buffer
2786 position. (The `fontified' property doesn't have a special
2787 meaning in strings.) If the value is nil, call functions from
2788 Qfontification_functions. */
2789 if (!STRINGP (it
->string
)
2791 && !NILP (Vfontification_functions
)
2792 && !NILP (Vrun_hooks
)
2793 && (pos
= make_number (IT_CHARPOS (*it
)),
2794 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2797 int count
= SPECPDL_INDEX ();
2800 val
= Vfontification_functions
;
2801 specbind (Qfontification_functions
, Qnil
);
2803 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2804 safe_call1 (val
, pos
);
2807 Lisp_Object globals
, fn
;
2808 struct gcpro gcpro1
, gcpro2
;
2811 GCPRO2 (val
, globals
);
2813 for (; CONSP (val
); val
= XCDR (val
))
2819 /* A value of t indicates this hook has a local
2820 binding; it means to run the global binding too.
2821 In a global value, t should not occur. If it
2822 does, we must ignore it to avoid an endless
2824 for (globals
= Fdefault_value (Qfontification_functions
);
2826 globals
= XCDR (globals
))
2828 fn
= XCAR (globals
);
2830 safe_call1 (fn
, pos
);
2834 safe_call1 (fn
, pos
);
2840 unbind_to (count
, Qnil
);
2842 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2843 something. This avoids an endless loop if they failed to
2844 fontify the text for which reason ever. */
2845 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2846 handled
= HANDLED_RECOMPUTE_PROPS
;
2854 /***********************************************************************
2856 ***********************************************************************/
2858 /* Set up iterator IT from face properties at its current position.
2859 Called from handle_stop. */
2861 static enum prop_handled
2862 handle_face_prop (it
)
2865 int new_face_id
, next_stop
;
2867 if (!STRINGP (it
->string
))
2870 = face_at_buffer_position (it
->w
,
2872 it
->region_beg_charpos
,
2873 it
->region_end_charpos
,
2876 + TEXT_PROP_DISTANCE_LIMIT
),
2879 /* Is this a start of a run of characters with box face?
2880 Caveat: this can be called for a freshly initialized
2881 iterator; face_id is -1 in this case. We know that the new
2882 face will not change until limit, i.e. if the new face has a
2883 box, all characters up to limit will have one. But, as
2884 usual, we don't know whether limit is really the end. */
2885 if (new_face_id
!= it
->face_id
)
2887 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2889 /* If new face has a box but old face has not, this is
2890 the start of a run of characters with box, i.e. it has
2891 a shadow on the left side. The value of face_id of the
2892 iterator will be -1 if this is the initial call that gets
2893 the face. In this case, we have to look in front of IT's
2894 position and see whether there is a face != new_face_id. */
2895 it
->start_of_box_run_p
2896 = (new_face
->box
!= FACE_NO_BOX
2897 && (it
->face_id
>= 0
2898 || IT_CHARPOS (*it
) == BEG
2899 || new_face_id
!= face_before_it_pos (it
)));
2900 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2905 int base_face_id
, bufpos
;
2907 if (it
->current
.overlay_string_index
>= 0)
2908 bufpos
= IT_CHARPOS (*it
);
2912 /* For strings from a buffer, i.e. overlay strings or strings
2913 from a `display' property, use the face at IT's current
2914 buffer position as the base face to merge with, so that
2915 overlay strings appear in the same face as surrounding
2916 text, unless they specify their own faces. */
2917 base_face_id
= underlying_face_id (it
);
2919 new_face_id
= face_at_string_position (it
->w
,
2921 IT_STRING_CHARPOS (*it
),
2923 it
->region_beg_charpos
,
2924 it
->region_end_charpos
,
2928 #if 0 /* This shouldn't be neccessary. Let's check it. */
2929 /* If IT is used to display a mode line we would really like to
2930 use the mode line face instead of the frame's default face. */
2931 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2932 && new_face_id
== DEFAULT_FACE_ID
)
2933 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2936 /* Is this a start of a run of characters with box? Caveat:
2937 this can be called for a freshly allocated iterator; face_id
2938 is -1 is this case. We know that the new face will not
2939 change until the next check pos, i.e. if the new face has a
2940 box, all characters up to that position will have a
2941 box. But, as usual, we don't know whether that position
2942 is really the end. */
2943 if (new_face_id
!= it
->face_id
)
2945 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2946 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2948 /* If new face has a box but old face hasn't, this is the
2949 start of a run of characters with box, i.e. it has a
2950 shadow on the left side. */
2951 it
->start_of_box_run_p
2952 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2953 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2957 it
->face_id
= new_face_id
;
2958 return HANDLED_NORMALLY
;
2962 /* Return the ID of the face ``underlying'' IT's current position,
2963 which is in a string. If the iterator is associated with a
2964 buffer, return the face at IT's current buffer position.
2965 Otherwise, use the iterator's base_face_id. */
2968 underlying_face_id (it
)
2971 int face_id
= it
->base_face_id
, i
;
2973 xassert (STRINGP (it
->string
));
2975 for (i
= it
->sp
- 1; i
>= 0; --i
)
2976 if (NILP (it
->stack
[i
].string
))
2977 face_id
= it
->stack
[i
].face_id
;
2983 /* Compute the face one character before or after the current position
2984 of IT. BEFORE_P non-zero means get the face in front of IT's
2985 position. Value is the id of the face. */
2988 face_before_or_after_it_pos (it
, before_p
)
2993 int next_check_charpos
;
2994 struct text_pos pos
;
2996 xassert (it
->s
== NULL
);
2998 if (STRINGP (it
->string
))
3000 int bufpos
, base_face_id
;
3002 /* No face change past the end of the string (for the case
3003 we are padding with spaces). No face change before the
3005 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3006 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3009 /* Set pos to the position before or after IT's current position. */
3011 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3013 /* For composition, we must check the character after the
3015 pos
= (it
->what
== IT_COMPOSITION
3016 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3017 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3019 if (it
->current
.overlay_string_index
>= 0)
3020 bufpos
= IT_CHARPOS (*it
);
3024 base_face_id
= underlying_face_id (it
);
3026 /* Get the face for ASCII, or unibyte. */
3027 face_id
= face_at_string_position (it
->w
,
3031 it
->region_beg_charpos
,
3032 it
->region_end_charpos
,
3033 &next_check_charpos
,
3036 /* Correct the face for charsets different from ASCII. Do it
3037 for the multibyte case only. The face returned above is
3038 suitable for unibyte text if IT->string is unibyte. */
3039 if (STRING_MULTIBYTE (it
->string
))
3041 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3042 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3044 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3046 c
= string_char_and_length (p
, rest
, &len
);
3047 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3052 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3053 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3056 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3057 pos
= it
->current
.pos
;
3060 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3063 if (it
->what
== IT_COMPOSITION
)
3064 /* For composition, we must check the position after the
3066 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3068 INC_TEXT_POS (pos
, it
->multibyte_p
);
3071 /* Determine face for CHARSET_ASCII, or unibyte. */
3072 face_id
= face_at_buffer_position (it
->w
,
3074 it
->region_beg_charpos
,
3075 it
->region_end_charpos
,
3076 &next_check_charpos
,
3079 /* Correct the face for charsets different from ASCII. Do it
3080 for the multibyte case only. The face returned above is
3081 suitable for unibyte text if current_buffer is unibyte. */
3082 if (it
->multibyte_p
)
3084 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3085 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3086 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3095 /***********************************************************************
3097 ***********************************************************************/
3099 /* Set up iterator IT from invisible properties at its current
3100 position. Called from handle_stop. */
3102 static enum prop_handled
3103 handle_invisible_prop (it
)
3106 enum prop_handled handled
= HANDLED_NORMALLY
;
3108 if (STRINGP (it
->string
))
3110 extern Lisp_Object Qinvisible
;
3111 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3113 /* Get the value of the invisible text property at the
3114 current position. Value will be nil if there is no such
3116 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3117 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3120 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3122 handled
= HANDLED_RECOMPUTE_PROPS
;
3124 /* Get the position at which the next change of the
3125 invisible text property can be found in IT->string.
3126 Value will be nil if the property value is the same for
3127 all the rest of IT->string. */
3128 XSETINT (limit
, SCHARS (it
->string
));
3129 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3132 /* Text at current position is invisible. The next
3133 change in the property is at position end_charpos.
3134 Move IT's current position to that position. */
3135 if (INTEGERP (end_charpos
)
3136 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3138 struct text_pos old
;
3139 old
= it
->current
.string_pos
;
3140 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3141 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3145 /* The rest of the string is invisible. If this is an
3146 overlay string, proceed with the next overlay string
3147 or whatever comes and return a character from there. */
3148 if (it
->current
.overlay_string_index
>= 0)
3150 next_overlay_string (it
);
3151 /* Don't check for overlay strings when we just
3152 finished processing them. */
3153 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3157 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3158 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3165 int invis_p
, newpos
, next_stop
, start_charpos
;
3166 Lisp_Object pos
, prop
, overlay
;
3168 /* First of all, is there invisible text at this position? */
3169 start_charpos
= IT_CHARPOS (*it
);
3170 pos
= make_number (IT_CHARPOS (*it
));
3171 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3173 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3175 /* If we are on invisible text, skip over it. */
3176 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3178 /* Record whether we have to display an ellipsis for the
3180 int display_ellipsis_p
= invis_p
== 2;
3182 handled
= HANDLED_RECOMPUTE_PROPS
;
3184 /* Loop skipping over invisible text. The loop is left at
3185 ZV or with IT on the first char being visible again. */
3188 /* Try to skip some invisible text. Return value is the
3189 position reached which can be equal to IT's position
3190 if there is nothing invisible here. This skips both
3191 over invisible text properties and overlays with
3192 invisible property. */
3193 newpos
= skip_invisible (IT_CHARPOS (*it
),
3194 &next_stop
, ZV
, it
->window
);
3196 /* If we skipped nothing at all we weren't at invisible
3197 text in the first place. If everything to the end of
3198 the buffer was skipped, end the loop. */
3199 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3203 /* We skipped some characters but not necessarily
3204 all there are. Check if we ended up on visible
3205 text. Fget_char_property returns the property of
3206 the char before the given position, i.e. if we
3207 get invis_p = 0, this means that the char at
3208 newpos is visible. */
3209 pos
= make_number (newpos
);
3210 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3211 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3214 /* If we ended up on invisible text, proceed to
3215 skip starting with next_stop. */
3217 IT_CHARPOS (*it
) = next_stop
;
3221 /* The position newpos is now either ZV or on visible text. */
3222 IT_CHARPOS (*it
) = newpos
;
3223 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3225 /* If there are before-strings at the start of invisible
3226 text, and the text is invisible because of a text
3227 property, arrange to show before-strings because 20.x did
3228 it that way. (If the text is invisible because of an
3229 overlay property instead of a text property, this is
3230 already handled in the overlay code.) */
3232 && get_overlay_strings (it
, start_charpos
))
3234 handled
= HANDLED_RECOMPUTE_PROPS
;
3235 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3237 else if (display_ellipsis_p
)
3238 setup_for_ellipsis (it
, 0);
3246 /* Make iterator IT return `...' next.
3247 Replaces LEN characters from buffer. */
3250 setup_for_ellipsis (it
, len
)
3254 /* Use the display table definition for `...'. Invalid glyphs
3255 will be handled by the method returning elements from dpvec. */
3256 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3258 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3259 it
->dpvec
= v
->contents
;
3260 it
->dpend
= v
->contents
+ v
->size
;
3264 /* Default `...'. */
3265 it
->dpvec
= default_invis_vector
;
3266 it
->dpend
= default_invis_vector
+ 3;
3269 it
->dpvec_char_len
= len
;
3270 it
->current
.dpvec_index
= 0;
3271 it
->dpvec_face_id
= -1;
3273 /* Remember the current face id in case glyphs specify faces.
3274 IT's face is restored in set_iterator_to_next. */
3275 it
->saved_face_id
= it
->face_id
;
3276 it
->method
= next_element_from_display_vector
;
3282 /***********************************************************************
3284 ***********************************************************************/
3286 /* Set up iterator IT from `display' property at its current position.
3287 Called from handle_stop.
3288 We return HANDLED_RETURN if some part of the display property
3289 overrides the display of the buffer text itself.
3290 Otherwise we return HANDLED_NORMALLY. */
3292 static enum prop_handled
3293 handle_display_prop (it
)
3296 Lisp_Object prop
, object
;
3297 struct text_pos
*position
;
3298 /* Nonzero if some property replaces the display of the text itself. */
3299 int display_replaced_p
= 0;
3301 if (STRINGP (it
->string
))
3303 object
= it
->string
;
3304 position
= &it
->current
.string_pos
;
3308 object
= it
->w
->buffer
;
3309 position
= &it
->current
.pos
;
3312 /* Reset those iterator values set from display property values. */
3313 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3314 it
->space_width
= Qnil
;
3315 it
->font_height
= Qnil
;
3318 /* We don't support recursive `display' properties, i.e. string
3319 values that have a string `display' property, that have a string
3320 `display' property etc. */
3321 if (!it
->string_from_display_prop_p
)
3322 it
->area
= TEXT_AREA
;
3324 prop
= Fget_char_property (make_number (position
->charpos
),
3327 return HANDLED_NORMALLY
;
3330 /* Simple properties. */
3331 && !EQ (XCAR (prop
), Qimage
)
3332 && !EQ (XCAR (prop
), Qspace
)
3333 && !EQ (XCAR (prop
), Qwhen
)
3334 && !EQ (XCAR (prop
), Qslice
)
3335 && !EQ (XCAR (prop
), Qspace_width
)
3336 && !EQ (XCAR (prop
), Qheight
)
3337 && !EQ (XCAR (prop
), Qraise
)
3338 /* Marginal area specifications. */
3339 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3340 && !EQ (XCAR (prop
), Qleft_fringe
)
3341 && !EQ (XCAR (prop
), Qright_fringe
)
3342 && !NILP (XCAR (prop
)))
3344 for (; CONSP (prop
); prop
= XCDR (prop
))
3346 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3347 position
, display_replaced_p
))
3348 display_replaced_p
= 1;
3351 else if (VECTORP (prop
))
3354 for (i
= 0; i
< ASIZE (prop
); ++i
)
3355 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3356 position
, display_replaced_p
))
3357 display_replaced_p
= 1;
3361 if (handle_single_display_spec (it
, prop
, object
, position
, 0))
3362 display_replaced_p
= 1;
3365 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3369 /* Value is the position of the end of the `display' property starting
3370 at START_POS in OBJECT. */
3372 static struct text_pos
3373 display_prop_end (it
, object
, start_pos
)
3376 struct text_pos start_pos
;
3379 struct text_pos end_pos
;
3381 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3382 Qdisplay
, object
, Qnil
);
3383 CHARPOS (end_pos
) = XFASTINT (end
);
3384 if (STRINGP (object
))
3385 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3387 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3393 /* Set up IT from a single `display' specification PROP. OBJECT
3394 is the object in which the `display' property was found. *POSITION
3395 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3396 means that we previously saw a display specification which already
3397 replaced text display with something else, for example an image;
3398 we ignore such properties after the first one has been processed.
3400 If PROP is a `space' or `image' specification, and in some other
3401 cases too, set *POSITION to the position where the `display'
3404 Value is non-zero if something was found which replaces the display
3405 of buffer or string text. */
3408 handle_single_display_spec (it
, spec
, object
, position
,
3409 display_replaced_before_p
)
3413 struct text_pos
*position
;
3414 int display_replaced_before_p
;
3417 Lisp_Object location
, value
;
3418 struct text_pos start_pos
;
3421 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3422 If the result is non-nil, use VALUE instead of SPEC. */
3424 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3433 if (!NILP (form
) && !EQ (form
, Qt
))
3435 int count
= SPECPDL_INDEX ();
3436 struct gcpro gcpro1
;
3438 /* Bind `object' to the object having the `display' property, a
3439 buffer or string. Bind `position' to the position in the
3440 object where the property was found, and `buffer-position'
3441 to the current position in the buffer. */
3442 specbind (Qobject
, object
);
3443 specbind (Qposition
, make_number (CHARPOS (*position
)));
3444 specbind (Qbuffer_position
,
3445 make_number (STRINGP (object
)
3446 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3448 form
= safe_eval (form
);
3450 unbind_to (count
, Qnil
);
3456 /* Handle `(height HEIGHT)' specifications. */
3458 && EQ (XCAR (spec
), Qheight
)
3459 && CONSP (XCDR (spec
)))
3461 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3464 it
->font_height
= XCAR (XCDR (spec
));
3465 if (!NILP (it
->font_height
))
3467 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3468 int new_height
= -1;
3470 if (CONSP (it
->font_height
)
3471 && (EQ (XCAR (it
->font_height
), Qplus
)
3472 || EQ (XCAR (it
->font_height
), Qminus
))
3473 && CONSP (XCDR (it
->font_height
))
3474 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3476 /* `(+ N)' or `(- N)' where N is an integer. */
3477 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3478 if (EQ (XCAR (it
->font_height
), Qplus
))
3480 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3482 else if (FUNCTIONP (it
->font_height
))
3484 /* Call function with current height as argument.
3485 Value is the new height. */
3487 height
= safe_call1 (it
->font_height
,
3488 face
->lface
[LFACE_HEIGHT_INDEX
]);
3489 if (NUMBERP (height
))
3490 new_height
= XFLOATINT (height
);
3492 else if (NUMBERP (it
->font_height
))
3494 /* Value is a multiple of the canonical char height. */
3497 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3498 new_height
= (XFLOATINT (it
->font_height
)
3499 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3503 /* Evaluate IT->font_height with `height' bound to the
3504 current specified height to get the new height. */
3505 int count
= SPECPDL_INDEX ();
3507 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3508 value
= safe_eval (it
->font_height
);
3509 unbind_to (count
, Qnil
);
3511 if (NUMBERP (value
))
3512 new_height
= XFLOATINT (value
);
3516 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3522 /* Handle `(space_width WIDTH)'. */
3524 && EQ (XCAR (spec
), Qspace_width
)
3525 && CONSP (XCDR (spec
)))
3527 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3530 value
= XCAR (XCDR (spec
));
3531 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3532 it
->space_width
= value
;
3537 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3539 && EQ (XCAR (spec
), Qslice
))
3543 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3546 if (tem
= XCDR (spec
), CONSP (tem
))
3548 it
->slice
.x
= XCAR (tem
);
3549 if (tem
= XCDR (tem
), CONSP (tem
))
3551 it
->slice
.y
= XCAR (tem
);
3552 if (tem
= XCDR (tem
), CONSP (tem
))
3554 it
->slice
.width
= XCAR (tem
);
3555 if (tem
= XCDR (tem
), CONSP (tem
))
3556 it
->slice
.height
= XCAR (tem
);
3564 /* Handle `(raise FACTOR)'. */
3566 && EQ (XCAR (spec
), Qraise
)
3567 && CONSP (XCDR (spec
)))
3569 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3572 #ifdef HAVE_WINDOW_SYSTEM
3573 value
= XCAR (XCDR (spec
));
3574 if (NUMBERP (value
))
3576 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3577 it
->voffset
= - (XFLOATINT (value
)
3578 * (FONT_HEIGHT (face
->font
)));
3580 #endif /* HAVE_WINDOW_SYSTEM */
3585 /* Don't handle the other kinds of display specifications
3586 inside a string that we got from a `display' property. */
3587 if (it
->string_from_display_prop_p
)
3590 /* Characters having this form of property are not displayed, so
3591 we have to find the end of the property. */
3592 start_pos
= *position
;
3593 *position
= display_prop_end (it
, object
, start_pos
);
3596 /* Stop the scan at that end position--we assume that all
3597 text properties change there. */
3598 it
->stop_charpos
= position
->charpos
;
3600 /* Handle `(left-fringe BITMAP [FACE])'
3601 and `(right-fringe BITMAP [FACE])'. */
3603 && (EQ (XCAR (spec
), Qleft_fringe
)
3604 || EQ (XCAR (spec
), Qright_fringe
))
3605 && CONSP (XCDR (spec
)))
3607 int face_id
= DEFAULT_FACE_ID
;
3610 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3611 /* If we return here, POSITION has been advanced
3612 across the text with this property. */
3615 #ifdef HAVE_WINDOW_SYSTEM
3616 value
= XCAR (XCDR (spec
));
3617 if (!SYMBOLP (value
)
3618 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
3619 /* If we return here, POSITION has been advanced
3620 across the text with this property. */
3623 if (CONSP (XCDR (XCDR (spec
))))
3625 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
3626 int face_id2
= lookup_named_face (it
->f
, face_name
, 'A', 0);
3631 /* Save current settings of IT so that we can restore them
3632 when we are finished with the glyph property value. */
3636 it
->area
= TEXT_AREA
;
3637 it
->what
= IT_IMAGE
;
3638 it
->image_id
= -1; /* no image */
3639 it
->position
= start_pos
;
3640 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3641 it
->method
= next_element_from_image
;
3642 it
->face_id
= face_id
;
3644 /* Say that we haven't consumed the characters with
3645 `display' property yet. The call to pop_it in
3646 set_iterator_to_next will clean this up. */
3647 *position
= start_pos
;
3649 if (EQ (XCAR (spec
), Qleft_fringe
))
3651 it
->left_user_fringe_bitmap
= fringe_bitmap
;
3652 it
->left_user_fringe_face_id
= face_id
;
3656 it
->right_user_fringe_bitmap
= fringe_bitmap
;
3657 it
->right_user_fringe_face_id
= face_id
;
3659 #endif /* HAVE_WINDOW_SYSTEM */
3663 /* Prepare to handle `((margin left-margin) ...)',
3664 `((margin right-margin) ...)' and `((margin nil) ...)'
3665 prefixes for display specifications. */
3666 location
= Qunbound
;
3667 if (CONSP (spec
) && CONSP (XCAR (spec
)))
3671 value
= XCDR (spec
);
3673 value
= XCAR (value
);
3676 if (EQ (XCAR (tem
), Qmargin
)
3677 && (tem
= XCDR (tem
),
3678 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3680 || EQ (tem
, Qleft_margin
)
3681 || EQ (tem
, Qright_margin
))))
3685 if (EQ (location
, Qunbound
))
3691 /* After this point, VALUE is the property after any
3692 margin prefix has been stripped. It must be a string,
3693 an image specification, or `(space ...)'.
3695 LOCATION specifies where to display: `left-margin',
3696 `right-margin' or nil. */
3698 valid_p
= (STRINGP (value
)
3699 #ifdef HAVE_WINDOW_SYSTEM
3700 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
3701 #endif /* not HAVE_WINDOW_SYSTEM */
3702 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3704 if (valid_p
&& !display_replaced_before_p
)
3706 /* Save current settings of IT so that we can restore them
3707 when we are finished with the glyph property value. */
3710 if (NILP (location
))
3711 it
->area
= TEXT_AREA
;
3712 else if (EQ (location
, Qleft_margin
))
3713 it
->area
= LEFT_MARGIN_AREA
;
3715 it
->area
= RIGHT_MARGIN_AREA
;
3717 if (STRINGP (value
))
3720 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3721 it
->current
.overlay_string_index
= -1;
3722 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3723 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3724 it
->method
= next_element_from_string
;
3725 it
->stop_charpos
= 0;
3726 it
->string_from_display_prop_p
= 1;
3727 /* Say that we haven't consumed the characters with
3728 `display' property yet. The call to pop_it in
3729 set_iterator_to_next will clean this up. */
3730 *position
= start_pos
;
3732 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3734 it
->method
= next_element_from_stretch
;
3736 it
->current
.pos
= it
->position
= start_pos
;
3738 #ifdef HAVE_WINDOW_SYSTEM
3741 it
->what
= IT_IMAGE
;
3742 it
->image_id
= lookup_image (it
->f
, value
);
3743 it
->position
= start_pos
;
3744 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3745 it
->method
= next_element_from_image
;
3747 /* Say that we haven't consumed the characters with
3748 `display' property yet. The call to pop_it in
3749 set_iterator_to_next will clean this up. */
3750 *position
= start_pos
;
3752 #endif /* HAVE_WINDOW_SYSTEM */
3757 /* Invalid property or property not supported. Restore
3758 POSITION to what it was before. */
3759 *position
= start_pos
;
3764 /* Check if SPEC is a display specification value whose text should be
3765 treated as intangible. */
3768 single_display_spec_intangible_p (prop
)
3771 /* Skip over `when FORM'. */
3772 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3786 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3787 we don't need to treat text as intangible. */
3788 if (EQ (XCAR (prop
), Qmargin
))
3796 || EQ (XCAR (prop
), Qleft_margin
)
3797 || EQ (XCAR (prop
), Qright_margin
))
3801 return (CONSP (prop
)
3802 && (EQ (XCAR (prop
), Qimage
)
3803 || EQ (XCAR (prop
), Qspace
)));
3807 /* Check if PROP is a display property value whose text should be
3808 treated as intangible. */
3811 display_prop_intangible_p (prop
)
3815 && CONSP (XCAR (prop
))
3816 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3818 /* A list of sub-properties. */
3819 while (CONSP (prop
))
3821 if (single_display_spec_intangible_p (XCAR (prop
)))
3826 else if (VECTORP (prop
))
3828 /* A vector of sub-properties. */
3830 for (i
= 0; i
< ASIZE (prop
); ++i
)
3831 if (single_display_spec_intangible_p (AREF (prop
, i
)))
3835 return single_display_spec_intangible_p (prop
);
3841 /* Return 1 if PROP is a display sub-property value containing STRING. */
3844 single_display_spec_string_p (prop
, string
)
3845 Lisp_Object prop
, string
;
3847 if (EQ (string
, prop
))
3850 /* Skip over `when FORM'. */
3851 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3860 /* Skip over `margin LOCATION'. */
3861 if (EQ (XCAR (prop
), Qmargin
))
3872 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3876 /* Return 1 if STRING appears in the `display' property PROP. */
3879 display_prop_string_p (prop
, string
)
3880 Lisp_Object prop
, string
;
3883 && CONSP (XCAR (prop
))
3884 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3886 /* A list of sub-properties. */
3887 while (CONSP (prop
))
3889 if (single_display_spec_string_p (XCAR (prop
), string
))
3894 else if (VECTORP (prop
))
3896 /* A vector of sub-properties. */
3898 for (i
= 0; i
< ASIZE (prop
); ++i
)
3899 if (single_display_spec_string_p (AREF (prop
, i
), string
))
3903 return single_display_spec_string_p (prop
, string
);
3909 /* Determine from which buffer position in W's buffer STRING comes
3910 from. AROUND_CHARPOS is an approximate position where it could
3911 be from. Value is the buffer position or 0 if it couldn't be
3914 W's buffer must be current.
3916 This function is necessary because we don't record buffer positions
3917 in glyphs generated from strings (to keep struct glyph small).
3918 This function may only use code that doesn't eval because it is
3919 called asynchronously from note_mouse_highlight. */
3922 string_buffer_position (w
, string
, around_charpos
)
3927 Lisp_Object limit
, prop
, pos
;
3928 const int MAX_DISTANCE
= 1000;
3931 pos
= make_number (around_charpos
);
3932 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3933 while (!found
&& !EQ (pos
, limit
))
3935 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3936 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3939 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3944 pos
= make_number (around_charpos
);
3945 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3946 while (!found
&& !EQ (pos
, limit
))
3948 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3949 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3952 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3957 return found
? XINT (pos
) : 0;
3962 /***********************************************************************
3963 `composition' property
3964 ***********************************************************************/
3966 /* Set up iterator IT from `composition' property at its current
3967 position. Called from handle_stop. */
3969 static enum prop_handled
3970 handle_composition_prop (it
)
3973 Lisp_Object prop
, string
;
3974 int pos
, pos_byte
, end
;
3975 enum prop_handled handled
= HANDLED_NORMALLY
;
3977 if (STRINGP (it
->string
))
3979 pos
= IT_STRING_CHARPOS (*it
);
3980 pos_byte
= IT_STRING_BYTEPOS (*it
);
3981 string
= it
->string
;
3985 pos
= IT_CHARPOS (*it
);
3986 pos_byte
= IT_BYTEPOS (*it
);
3990 /* If there's a valid composition and point is not inside of the
3991 composition (in the case that the composition is from the current
3992 buffer), draw a glyph composed from the composition components. */
3993 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3994 && COMPOSITION_VALID_P (pos
, end
, prop
)
3995 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3997 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4001 it
->method
= next_element_from_composition
;
4003 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4004 /* For a terminal, draw only the first character of the
4006 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4007 it
->len
= (STRINGP (it
->string
)
4008 ? string_char_to_byte (it
->string
, end
)
4009 : CHAR_TO_BYTE (end
)) - pos_byte
;
4010 it
->stop_charpos
= end
;
4011 handled
= HANDLED_RETURN
;
4020 /***********************************************************************
4022 ***********************************************************************/
4024 /* The following structure is used to record overlay strings for
4025 later sorting in load_overlay_strings. */
4027 struct overlay_entry
4029 Lisp_Object overlay
;
4036 /* Set up iterator IT from overlay strings at its current position.
4037 Called from handle_stop. */
4039 static enum prop_handled
4040 handle_overlay_change (it
)
4043 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4044 return HANDLED_RECOMPUTE_PROPS
;
4046 return HANDLED_NORMALLY
;
4050 /* Set up the next overlay string for delivery by IT, if there is an
4051 overlay string to deliver. Called by set_iterator_to_next when the
4052 end of the current overlay string is reached. If there are more
4053 overlay strings to display, IT->string and
4054 IT->current.overlay_string_index are set appropriately here.
4055 Otherwise IT->string is set to nil. */
4058 next_overlay_string (it
)
4061 ++it
->current
.overlay_string_index
;
4062 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4064 /* No more overlay strings. Restore IT's settings to what
4065 they were before overlay strings were processed, and
4066 continue to deliver from current_buffer. */
4067 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4070 xassert (it
->stop_charpos
>= BEGV
4071 && it
->stop_charpos
<= it
->end_charpos
);
4073 it
->current
.overlay_string_index
= -1;
4074 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4075 it
->n_overlay_strings
= 0;
4076 it
->method
= next_element_from_buffer
;
4078 /* If we're at the end of the buffer, record that we have
4079 processed the overlay strings there already, so that
4080 next_element_from_buffer doesn't try it again. */
4081 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4082 it
->overlay_strings_at_end_processed_p
= 1;
4084 /* If we have to display `...' for invisible text, set
4085 the iterator up for that. */
4086 if (display_ellipsis_p
)
4087 setup_for_ellipsis (it
, 0);
4091 /* There are more overlay strings to process. If
4092 IT->current.overlay_string_index has advanced to a position
4093 where we must load IT->overlay_strings with more strings, do
4095 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4097 if (it
->current
.overlay_string_index
&& i
== 0)
4098 load_overlay_strings (it
, 0);
4100 /* Initialize IT to deliver display elements from the overlay
4102 it
->string
= it
->overlay_strings
[i
];
4103 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4104 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4105 it
->method
= next_element_from_string
;
4106 it
->stop_charpos
= 0;
4113 /* Compare two overlay_entry structures E1 and E2. Used as a
4114 comparison function for qsort in load_overlay_strings. Overlay
4115 strings for the same position are sorted so that
4117 1. All after-strings come in front of before-strings, except
4118 when they come from the same overlay.
4120 2. Within after-strings, strings are sorted so that overlay strings
4121 from overlays with higher priorities come first.
4123 2. Within before-strings, strings are sorted so that overlay
4124 strings from overlays with higher priorities come last.
4126 Value is analogous to strcmp. */
4130 compare_overlay_entries (e1
, e2
)
4133 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4134 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4137 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4139 /* Let after-strings appear in front of before-strings if
4140 they come from different overlays. */
4141 if (EQ (entry1
->overlay
, entry2
->overlay
))
4142 result
= entry1
->after_string_p
? 1 : -1;
4144 result
= entry1
->after_string_p
? -1 : 1;
4146 else if (entry1
->after_string_p
)
4147 /* After-strings sorted in order of decreasing priority. */
4148 result
= entry2
->priority
- entry1
->priority
;
4150 /* Before-strings sorted in order of increasing priority. */
4151 result
= entry1
->priority
- entry2
->priority
;
4157 /* Load the vector IT->overlay_strings with overlay strings from IT's
4158 current buffer position, or from CHARPOS if that is > 0. Set
4159 IT->n_overlays to the total number of overlay strings found.
4161 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4162 a time. On entry into load_overlay_strings,
4163 IT->current.overlay_string_index gives the number of overlay
4164 strings that have already been loaded by previous calls to this
4167 IT->add_overlay_start contains an additional overlay start
4168 position to consider for taking overlay strings from, if non-zero.
4169 This position comes into play when the overlay has an `invisible'
4170 property, and both before and after-strings. When we've skipped to
4171 the end of the overlay, because of its `invisible' property, we
4172 nevertheless want its before-string to appear.
4173 IT->add_overlay_start will contain the overlay start position
4176 Overlay strings are sorted so that after-string strings come in
4177 front of before-string strings. Within before and after-strings,
4178 strings are sorted by overlay priority. See also function
4179 compare_overlay_entries. */
4182 load_overlay_strings (it
, charpos
)
4186 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4187 Lisp_Object overlay
, window
, str
, invisible
;
4188 struct Lisp_Overlay
*ov
;
4191 int n
= 0, i
, j
, invis_p
;
4192 struct overlay_entry
*entries
4193 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4196 charpos
= IT_CHARPOS (*it
);
4198 /* Append the overlay string STRING of overlay OVERLAY to vector
4199 `entries' which has size `size' and currently contains `n'
4200 elements. AFTER_P non-zero means STRING is an after-string of
4202 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4205 Lisp_Object priority; \
4209 int new_size = 2 * size; \
4210 struct overlay_entry *old = entries; \
4212 (struct overlay_entry *) alloca (new_size \
4213 * sizeof *entries); \
4214 bcopy (old, entries, size * sizeof *entries); \
4218 entries[n].string = (STRING); \
4219 entries[n].overlay = (OVERLAY); \
4220 priority = Foverlay_get ((OVERLAY), Qpriority); \
4221 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4222 entries[n].after_string_p = (AFTER_P); \
4227 /* Process overlay before the overlay center. */
4228 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4230 XSETMISC (overlay
, ov
);
4231 xassert (OVERLAYP (overlay
));
4232 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4233 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4238 /* Skip this overlay if it doesn't start or end at IT's current
4240 if (end
!= charpos
&& start
!= charpos
)
4243 /* Skip this overlay if it doesn't apply to IT->w. */
4244 window
= Foverlay_get (overlay
, Qwindow
);
4245 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4248 /* If the text ``under'' the overlay is invisible, both before-
4249 and after-strings from this overlay are visible; start and
4250 end position are indistinguishable. */
4251 invisible
= Foverlay_get (overlay
, Qinvisible
);
4252 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4254 /* If overlay has a non-empty before-string, record it. */
4255 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4256 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4258 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4260 /* If overlay has a non-empty after-string, record it. */
4261 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4262 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4264 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4267 /* Process overlays after the overlay center. */
4268 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4270 XSETMISC (overlay
, ov
);
4271 xassert (OVERLAYP (overlay
));
4272 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4273 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4275 if (start
> charpos
)
4278 /* Skip this overlay if it doesn't start or end at IT's current
4280 if (end
!= charpos
&& start
!= charpos
)
4283 /* Skip this overlay if it doesn't apply to IT->w. */
4284 window
= Foverlay_get (overlay
, Qwindow
);
4285 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4288 /* If the text ``under'' the overlay is invisible, it has a zero
4289 dimension, and both before- and after-strings apply. */
4290 invisible
= Foverlay_get (overlay
, Qinvisible
);
4291 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4293 /* If overlay has a non-empty before-string, record it. */
4294 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4295 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4297 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4299 /* If overlay has a non-empty after-string, record it. */
4300 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4301 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4303 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4306 #undef RECORD_OVERLAY_STRING
4310 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4312 /* Record the total number of strings to process. */
4313 it
->n_overlay_strings
= n
;
4315 /* IT->current.overlay_string_index is the number of overlay strings
4316 that have already been consumed by IT. Copy some of the
4317 remaining overlay strings to IT->overlay_strings. */
4319 j
= it
->current
.overlay_string_index
;
4320 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4321 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4327 /* Get the first chunk of overlay strings at IT's current buffer
4328 position, or at CHARPOS if that is > 0. Value is non-zero if at
4329 least one overlay string was found. */
4332 get_overlay_strings (it
, charpos
)
4336 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4337 process. This fills IT->overlay_strings with strings, and sets
4338 IT->n_overlay_strings to the total number of strings to process.
4339 IT->pos.overlay_string_index has to be set temporarily to zero
4340 because load_overlay_strings needs this; it must be set to -1
4341 when no overlay strings are found because a zero value would
4342 indicate a position in the first overlay string. */
4343 it
->current
.overlay_string_index
= 0;
4344 load_overlay_strings (it
, charpos
);
4346 /* If we found overlay strings, set up IT to deliver display
4347 elements from the first one. Otherwise set up IT to deliver
4348 from current_buffer. */
4349 if (it
->n_overlay_strings
)
4351 /* Make sure we know settings in current_buffer, so that we can
4352 restore meaningful values when we're done with the overlay
4354 compute_stop_pos (it
);
4355 xassert (it
->face_id
>= 0);
4357 /* Save IT's settings. They are restored after all overlay
4358 strings have been processed. */
4359 xassert (it
->sp
== 0);
4362 /* Set up IT to deliver display elements from the first overlay
4364 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4365 it
->string
= it
->overlay_strings
[0];
4366 it
->stop_charpos
= 0;
4367 xassert (STRINGP (it
->string
));
4368 it
->end_charpos
= SCHARS (it
->string
);
4369 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4370 it
->method
= next_element_from_string
;
4375 it
->current
.overlay_string_index
= -1;
4376 it
->method
= next_element_from_buffer
;
4381 /* Value is non-zero if we found at least one overlay string. */
4382 return STRINGP (it
->string
);
4387 /***********************************************************************
4388 Saving and restoring state
4389 ***********************************************************************/
4391 /* Save current settings of IT on IT->stack. Called, for example,
4392 before setting up IT for an overlay string, to be able to restore
4393 IT's settings to what they were after the overlay string has been
4400 struct iterator_stack_entry
*p
;
4402 xassert (it
->sp
< 2);
4403 p
= it
->stack
+ it
->sp
;
4405 p
->stop_charpos
= it
->stop_charpos
;
4406 xassert (it
->face_id
>= 0);
4407 p
->face_id
= it
->face_id
;
4408 p
->string
= it
->string
;
4409 p
->pos
= it
->current
;
4410 p
->end_charpos
= it
->end_charpos
;
4411 p
->string_nchars
= it
->string_nchars
;
4413 p
->multibyte_p
= it
->multibyte_p
;
4414 p
->slice
= it
->slice
;
4415 p
->space_width
= it
->space_width
;
4416 p
->font_height
= it
->font_height
;
4417 p
->voffset
= it
->voffset
;
4418 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4419 p
->display_ellipsis_p
= 0;
4424 /* Restore IT's settings from IT->stack. Called, for example, when no
4425 more overlay strings must be processed, and we return to delivering
4426 display elements from a buffer, or when the end of a string from a
4427 `display' property is reached and we return to delivering display
4428 elements from an overlay string, or from a buffer. */
4434 struct iterator_stack_entry
*p
;
4436 xassert (it
->sp
> 0);
4438 p
= it
->stack
+ it
->sp
;
4439 it
->stop_charpos
= p
->stop_charpos
;
4440 it
->face_id
= p
->face_id
;
4441 it
->string
= p
->string
;
4442 it
->current
= p
->pos
;
4443 it
->end_charpos
= p
->end_charpos
;
4444 it
->string_nchars
= p
->string_nchars
;
4446 it
->multibyte_p
= p
->multibyte_p
;
4447 it
->slice
= p
->slice
;
4448 it
->space_width
= p
->space_width
;
4449 it
->font_height
= p
->font_height
;
4450 it
->voffset
= p
->voffset
;
4451 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4456 /***********************************************************************
4458 ***********************************************************************/
4460 /* Set IT's current position to the previous line start. */
4463 back_to_previous_line_start (it
)
4466 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4467 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4471 /* Move IT to the next line start.
4473 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4474 we skipped over part of the text (as opposed to moving the iterator
4475 continuously over the text). Otherwise, don't change the value
4478 Newlines may come from buffer text, overlay strings, or strings
4479 displayed via the `display' property. That's the reason we can't
4480 simply use find_next_newline_no_quit.
4482 Note that this function may not skip over invisible text that is so
4483 because of text properties and immediately follows a newline. If
4484 it would, function reseat_at_next_visible_line_start, when called
4485 from set_iterator_to_next, would effectively make invisible
4486 characters following a newline part of the wrong glyph row, which
4487 leads to wrong cursor motion. */
4490 forward_to_next_line_start (it
, skipped_p
)
4494 int old_selective
, newline_found_p
, n
;
4495 const int MAX_NEWLINE_DISTANCE
= 500;
4497 /* If already on a newline, just consume it to avoid unintended
4498 skipping over invisible text below. */
4499 if (it
->what
== IT_CHARACTER
4501 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4503 set_iterator_to_next (it
, 0);
4508 /* Don't handle selective display in the following. It's (a)
4509 unnecessary because it's done by the caller, and (b) leads to an
4510 infinite recursion because next_element_from_ellipsis indirectly
4511 calls this function. */
4512 old_selective
= it
->selective
;
4515 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4516 from buffer text. */
4517 for (n
= newline_found_p
= 0;
4518 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4519 n
+= STRINGP (it
->string
) ? 0 : 1)
4521 if (!get_next_display_element (it
))
4523 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4524 set_iterator_to_next (it
, 0);
4527 /* If we didn't find a newline near enough, see if we can use a
4529 if (!newline_found_p
)
4531 int start
= IT_CHARPOS (*it
);
4532 int limit
= find_next_newline_no_quit (start
, 1);
4535 xassert (!STRINGP (it
->string
));
4537 /* If there isn't any `display' property in sight, and no
4538 overlays, we can just use the position of the newline in
4540 if (it
->stop_charpos
>= limit
4541 || ((pos
= Fnext_single_property_change (make_number (start
),
4543 Qnil
, make_number (limit
)),
4545 && next_overlay_change (start
) == ZV
))
4547 IT_CHARPOS (*it
) = limit
;
4548 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4549 *skipped_p
= newline_found_p
= 1;
4553 while (get_next_display_element (it
)
4554 && !newline_found_p
)
4556 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4557 set_iterator_to_next (it
, 0);
4562 it
->selective
= old_selective
;
4563 return newline_found_p
;
4567 /* Set IT's current position to the previous visible line start. Skip
4568 invisible text that is so either due to text properties or due to
4569 selective display. Caution: this does not change IT->current_x and
4573 back_to_previous_visible_line_start (it
)
4578 /* Go back one newline if not on BEGV already. */
4579 if (IT_CHARPOS (*it
) > BEGV
)
4580 back_to_previous_line_start (it
);
4582 /* Move over lines that are invisible because of selective display
4583 or text properties. */
4584 while (IT_CHARPOS (*it
) > BEGV
4589 /* If selective > 0, then lines indented more than that values
4591 if (it
->selective
> 0
4592 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4593 (double) it
->selective
)) /* iftc */
4599 /* Check the newline before point for invisibility. */
4600 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
4601 Qinvisible
, it
->window
);
4602 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4607 /* Commenting this out fixes the bug described in
4608 http://www.math.ku.dk/~larsh/emacs/emacs-loops-on-large-images/test-case.txt. */
4611 struct it it2
= *it
;
4613 if (handle_display_prop (&it2
) == HANDLED_RETURN
)
4618 /* Back one more newline if the current one is invisible. */
4620 back_to_previous_line_start (it
);
4623 xassert (IT_CHARPOS (*it
) >= BEGV
);
4624 xassert (IT_CHARPOS (*it
) == BEGV
4625 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4630 /* Reseat iterator IT at the previous visible line start. Skip
4631 invisible text that is so either due to text properties or due to
4632 selective display. At the end, update IT's overlay information,
4633 face information etc. */
4636 reseat_at_previous_visible_line_start (it
)
4639 back_to_previous_visible_line_start (it
);
4640 reseat (it
, it
->current
.pos
, 1);
4645 /* Reseat iterator IT on the next visible line start in the current
4646 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4647 preceding the line start. Skip over invisible text that is so
4648 because of selective display. Compute faces, overlays etc at the
4649 new position. Note that this function does not skip over text that
4650 is invisible because of text properties. */
4653 reseat_at_next_visible_line_start (it
, on_newline_p
)
4657 int newline_found_p
, skipped_p
= 0;
4659 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4661 /* Skip over lines that are invisible because they are indented
4662 more than the value of IT->selective. */
4663 if (it
->selective
> 0)
4664 while (IT_CHARPOS (*it
) < ZV
4665 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4666 (double) it
->selective
)) /* iftc */
4668 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4669 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4672 /* Position on the newline if that's what's requested. */
4673 if (on_newline_p
&& newline_found_p
)
4675 if (STRINGP (it
->string
))
4677 if (IT_STRING_CHARPOS (*it
) > 0)
4679 --IT_STRING_CHARPOS (*it
);
4680 --IT_STRING_BYTEPOS (*it
);
4683 else if (IT_CHARPOS (*it
) > BEGV
)
4687 reseat (it
, it
->current
.pos
, 0);
4691 reseat (it
, it
->current
.pos
, 0);
4698 /***********************************************************************
4699 Changing an iterator's position
4700 ***********************************************************************/
4702 /* Change IT's current position to POS in current_buffer. If FORCE_P
4703 is non-zero, always check for text properties at the new position.
4704 Otherwise, text properties are only looked up if POS >=
4705 IT->check_charpos of a property. */
4708 reseat (it
, pos
, force_p
)
4710 struct text_pos pos
;
4713 int original_pos
= IT_CHARPOS (*it
);
4715 reseat_1 (it
, pos
, 0);
4717 /* Determine where to check text properties. Avoid doing it
4718 where possible because text property lookup is very expensive. */
4720 || CHARPOS (pos
) > it
->stop_charpos
4721 || CHARPOS (pos
) < original_pos
)
4728 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4729 IT->stop_pos to POS, also. */
4732 reseat_1 (it
, pos
, set_stop_p
)
4734 struct text_pos pos
;
4737 /* Don't call this function when scanning a C string. */
4738 xassert (it
->s
== NULL
);
4740 /* POS must be a reasonable value. */
4741 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4743 it
->current
.pos
= it
->position
= pos
;
4744 XSETBUFFER (it
->object
, current_buffer
);
4745 it
->end_charpos
= ZV
;
4747 it
->current
.dpvec_index
= -1;
4748 it
->current
.overlay_string_index
= -1;
4749 IT_STRING_CHARPOS (*it
) = -1;
4750 IT_STRING_BYTEPOS (*it
) = -1;
4752 it
->method
= next_element_from_buffer
;
4753 /* RMS: I added this to fix a bug in move_it_vertically_backward
4754 where it->area continued to relate to the starting point
4755 for the backward motion. Bug report from
4756 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4757 However, I am not sure whether reseat still does the right thing
4758 in general after this change. */
4759 it
->area
= TEXT_AREA
;
4760 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4762 it
->face_before_selective_p
= 0;
4765 it
->stop_charpos
= CHARPOS (pos
);
4769 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4770 If S is non-null, it is a C string to iterate over. Otherwise,
4771 STRING gives a Lisp string to iterate over.
4773 If PRECISION > 0, don't return more then PRECISION number of
4774 characters from the string.
4776 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4777 characters have been returned. FIELD_WIDTH < 0 means an infinite
4780 MULTIBYTE = 0 means disable processing of multibyte characters,
4781 MULTIBYTE > 0 means enable it,
4782 MULTIBYTE < 0 means use IT->multibyte_p.
4784 IT must be initialized via a prior call to init_iterator before
4785 calling this function. */
4788 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4793 int precision
, field_width
, multibyte
;
4795 /* No region in strings. */
4796 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4798 /* No text property checks performed by default, but see below. */
4799 it
->stop_charpos
= -1;
4801 /* Set iterator position and end position. */
4802 bzero (&it
->current
, sizeof it
->current
);
4803 it
->current
.overlay_string_index
= -1;
4804 it
->current
.dpvec_index
= -1;
4805 xassert (charpos
>= 0);
4807 /* If STRING is specified, use its multibyteness, otherwise use the
4808 setting of MULTIBYTE, if specified. */
4810 it
->multibyte_p
= multibyte
> 0;
4814 xassert (STRINGP (string
));
4815 it
->string
= string
;
4817 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4818 it
->method
= next_element_from_string
;
4819 it
->current
.string_pos
= string_pos (charpos
, string
);
4826 /* Note that we use IT->current.pos, not it->current.string_pos,
4827 for displaying C strings. */
4828 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4829 if (it
->multibyte_p
)
4831 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4832 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4836 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4837 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4840 it
->method
= next_element_from_c_string
;
4843 /* PRECISION > 0 means don't return more than PRECISION characters
4845 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4846 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4848 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4849 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4850 FIELD_WIDTH < 0 means infinite field width. This is useful for
4851 padding with `-' at the end of a mode line. */
4852 if (field_width
< 0)
4853 field_width
= INFINITY
;
4854 if (field_width
> it
->end_charpos
- charpos
)
4855 it
->end_charpos
= charpos
+ field_width
;
4857 /* Use the standard display table for displaying strings. */
4858 if (DISP_TABLE_P (Vstandard_display_table
))
4859 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4861 it
->stop_charpos
= charpos
;
4867 /***********************************************************************
4869 ***********************************************************************/
4871 /* Load IT's display element fields with information about the next
4872 display element from the current position of IT. Value is zero if
4873 end of buffer (or C string) is reached. */
4876 get_next_display_element (it
)
4879 /* Non-zero means that we found a display element. Zero means that
4880 we hit the end of what we iterate over. Performance note: the
4881 function pointer `method' used here turns out to be faster than
4882 using a sequence of if-statements. */
4886 success_p
= (*it
->method
) (it
);
4888 if (it
->what
== IT_CHARACTER
)
4890 /* Map via display table or translate control characters.
4891 IT->c, IT->len etc. have been set to the next character by
4892 the function call above. If we have a display table, and it
4893 contains an entry for IT->c, translate it. Don't do this if
4894 IT->c itself comes from a display table, otherwise we could
4895 end up in an infinite recursion. (An alternative could be to
4896 count the recursion depth of this function and signal an
4897 error when a certain maximum depth is reached.) Is it worth
4899 if (success_p
&& it
->dpvec
== NULL
)
4904 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4907 struct Lisp_Vector
*v
= XVECTOR (dv
);
4909 /* Return the first character from the display table
4910 entry, if not empty. If empty, don't display the
4911 current character. */
4914 it
->dpvec_char_len
= it
->len
;
4915 it
->dpvec
= v
->contents
;
4916 it
->dpend
= v
->contents
+ v
->size
;
4917 it
->current
.dpvec_index
= 0;
4918 it
->dpvec_face_id
= -1;
4919 it
->saved_face_id
= it
->face_id
;
4920 it
->method
= next_element_from_display_vector
;
4925 set_iterator_to_next (it
, 0);
4930 /* Translate control characters into `\003' or `^C' form.
4931 Control characters coming from a display table entry are
4932 currently not translated because we use IT->dpvec to hold
4933 the translation. This could easily be changed but I
4934 don't believe that it is worth doing.
4936 If it->multibyte_p is nonzero, eight-bit characters and
4937 non-printable multibyte characters are also translated to
4940 If it->multibyte_p is zero, eight-bit characters that
4941 don't have corresponding multibyte char code are also
4942 translated to octal form. */
4943 else if ((it
->c
< ' '
4944 && (it
->area
!= TEXT_AREA
4945 /* In mode line, treat \n like other crl chars. */
4947 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
4948 || (it
->c
!= '\n' && it
->c
!= '\t')))
4952 || !CHAR_PRINTABLE_P (it
->c
)
4953 || (!NILP (Vshow_nonbreak_escape
)
4954 && (it
->c
== 0x8ad || it
->c
== 0x8a0)))
4956 && (!unibyte_display_via_language_environment
4957 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
4959 /* IT->c is a control character which must be displayed
4960 either as '\003' or as `^C' where the '\\' and '^'
4961 can be defined in the display table. Fill
4962 IT->ctl_chars with glyphs for what we have to
4963 display. Then, set IT->dpvec to these glyphs. */
4966 int face_id
, lface_id
;
4969 if (it
->c
< 128 && it
->ctl_arrow_p
)
4971 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4973 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4974 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4976 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4977 lface_id
= FAST_GLYPH_FACE (g
);
4980 g
= FAST_GLYPH_CHAR (g
);
4981 /* The function returns -1 if lface_id is invalid. */
4982 face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
4984 face_id
= merge_into_realized_face (it
->f
, Qnil
,
4985 face_id
, it
->face_id
);
4990 /* Merge the escape-glyph face into the current face. */
4991 face_id
= merge_into_realized_face (it
->f
, Qescape_glyph
,
4996 XSETINT (it
->ctl_chars
[0], g
);
4998 XSETINT (it
->ctl_chars
[1], g
);
5000 goto display_control
;
5004 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5005 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5007 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5008 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5011 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5012 /* The function returns -1 if lface_id is invalid. */
5013 face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
5015 face_id
= merge_into_realized_face (it
->f
, Qnil
,
5016 face_id
, it
->face_id
);
5021 /* Merge the escape-glyph face into the current face. */
5022 face_id
= merge_into_realized_face (it
->f
, Qescape_glyph
,
5024 escape_glyph
= '\\';
5027 if (it
->c
== 0x8a0 || it
->c
== 0x8ad)
5029 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5030 g
= it
->c
== 0x8ad ? '-' : ' ';
5031 XSETINT (it
->ctl_chars
[1], g
);
5033 goto display_control
;
5037 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5041 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5042 if (SINGLE_BYTE_CHAR_P (it
->c
))
5043 str
[0] = it
->c
, len
= 1;
5046 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5049 /* It's an invalid character, which shouldn't
5050 happen actually, but due to bugs it may
5051 happen. Let's print the char as is, there's
5052 not much meaningful we can do with it. */
5054 str
[1] = it
->c
>> 8;
5055 str
[2] = it
->c
>> 16;
5056 str
[3] = it
->c
>> 24;
5061 for (i
= 0; i
< len
; i
++)
5063 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5064 /* Insert three more glyphs into IT->ctl_chars for
5065 the octal display of the character. */
5066 g
= ((str
[i
] >> 6) & 7) + '0';
5067 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5068 g
= ((str
[i
] >> 3) & 7) + '0';
5069 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5070 g
= (str
[i
] & 7) + '0';
5071 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5077 /* Set up IT->dpvec and return first character from it. */
5078 it
->dpvec_char_len
= it
->len
;
5079 it
->dpvec
= it
->ctl_chars
;
5080 it
->dpend
= it
->dpvec
+ ctl_len
;
5081 it
->current
.dpvec_index
= 0;
5082 it
->dpvec_face_id
= face_id
;
5083 it
->saved_face_id
= it
->face_id
;
5084 it
->method
= next_element_from_display_vector
;
5090 /* Adjust face id for a multibyte character. There are no
5091 multibyte character in unibyte text. */
5094 && FRAME_WINDOW_P (it
->f
))
5096 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5097 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5101 /* Is this character the last one of a run of characters with
5102 box? If yes, set IT->end_of_box_run_p to 1. */
5109 it
->end_of_box_run_p
5110 = ((face_id
= face_after_it_pos (it
),
5111 face_id
!= it
->face_id
)
5112 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5113 face
->box
== FACE_NO_BOX
));
5116 /* Value is 0 if end of buffer or string reached. */
5121 /* Move IT to the next display element.
5123 RESEAT_P non-zero means if called on a newline in buffer text,
5124 skip to the next visible line start.
5126 Functions get_next_display_element and set_iterator_to_next are
5127 separate because I find this arrangement easier to handle than a
5128 get_next_display_element function that also increments IT's
5129 position. The way it is we can first look at an iterator's current
5130 display element, decide whether it fits on a line, and if it does,
5131 increment the iterator position. The other way around we probably
5132 would either need a flag indicating whether the iterator has to be
5133 incremented the next time, or we would have to implement a
5134 decrement position function which would not be easy to write. */
5137 set_iterator_to_next (it
, reseat_p
)
5141 /* Reset flags indicating start and end of a sequence of characters
5142 with box. Reset them at the start of this function because
5143 moving the iterator to a new position might set them. */
5144 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5146 if (it
->method
== next_element_from_buffer
)
5148 /* The current display element of IT is a character from
5149 current_buffer. Advance in the buffer, and maybe skip over
5150 invisible lines that are so because of selective display. */
5151 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5152 reseat_at_next_visible_line_start (it
, 0);
5155 xassert (it
->len
!= 0);
5156 IT_BYTEPOS (*it
) += it
->len
;
5157 IT_CHARPOS (*it
) += 1;
5158 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5161 else if (it
->method
== next_element_from_composition
)
5163 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5164 if (STRINGP (it
->string
))
5166 IT_STRING_BYTEPOS (*it
) += it
->len
;
5167 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5168 it
->method
= next_element_from_string
;
5169 goto consider_string_end
;
5173 IT_BYTEPOS (*it
) += it
->len
;
5174 IT_CHARPOS (*it
) += it
->cmp_len
;
5175 it
->method
= next_element_from_buffer
;
5178 else if (it
->method
== next_element_from_c_string
)
5180 /* Current display element of IT is from a C string. */
5181 IT_BYTEPOS (*it
) += it
->len
;
5182 IT_CHARPOS (*it
) += 1;
5184 else if (it
->method
== next_element_from_display_vector
)
5186 /* Current display element of IT is from a display table entry.
5187 Advance in the display table definition. Reset it to null if
5188 end reached, and continue with characters from buffers/
5190 ++it
->current
.dpvec_index
;
5192 /* Restore face of the iterator to what they were before the
5193 display vector entry (these entries may contain faces). */
5194 it
->face_id
= it
->saved_face_id
;
5196 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5199 it
->method
= next_element_from_c_string
;
5200 else if (STRINGP (it
->string
))
5201 it
->method
= next_element_from_string
;
5203 it
->method
= next_element_from_buffer
;
5206 it
->current
.dpvec_index
= -1;
5208 /* Skip over characters which were displayed via IT->dpvec. */
5209 if (it
->dpvec_char_len
< 0)
5210 reseat_at_next_visible_line_start (it
, 1);
5211 else if (it
->dpvec_char_len
> 0)
5213 it
->len
= it
->dpvec_char_len
;
5214 set_iterator_to_next (it
, reseat_p
);
5217 /* Recheck faces after display vector */
5218 it
->stop_charpos
= IT_CHARPOS (*it
);
5221 else if (it
->method
== next_element_from_string
)
5223 /* Current display element is a character from a Lisp string. */
5224 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5225 IT_STRING_BYTEPOS (*it
) += it
->len
;
5226 IT_STRING_CHARPOS (*it
) += 1;
5228 consider_string_end
:
5230 if (it
->current
.overlay_string_index
>= 0)
5232 /* IT->string is an overlay string. Advance to the
5233 next, if there is one. */
5234 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5235 next_overlay_string (it
);
5239 /* IT->string is not an overlay string. If we reached
5240 its end, and there is something on IT->stack, proceed
5241 with what is on the stack. This can be either another
5242 string, this time an overlay string, or a buffer. */
5243 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5247 if (!STRINGP (it
->string
))
5248 it
->method
= next_element_from_buffer
;
5250 goto consider_string_end
;
5254 else if (it
->method
== next_element_from_image
5255 || it
->method
== next_element_from_stretch
)
5257 /* The position etc with which we have to proceed are on
5258 the stack. The position may be at the end of a string,
5259 if the `display' property takes up the whole string. */
5262 if (STRINGP (it
->string
))
5264 it
->method
= next_element_from_string
;
5265 goto consider_string_end
;
5268 it
->method
= next_element_from_buffer
;
5271 /* There are no other methods defined, so this should be a bug. */
5274 xassert (it
->method
!= next_element_from_string
5275 || (STRINGP (it
->string
)
5276 && IT_STRING_CHARPOS (*it
) >= 0));
5279 /* Load IT's display element fields with information about the next
5280 display element which comes from a display table entry or from the
5281 result of translating a control character to one of the forms `^C'
5284 IT->dpvec holds the glyphs to return as characters.
5285 IT->saved_face_id holds the face id before the display vector--
5286 it is restored into IT->face_idin set_iterator_to_next. */
5289 next_element_from_display_vector (it
)
5293 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5295 if (INTEGERP (*it
->dpvec
)
5296 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5300 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5301 it
->c
= FAST_GLYPH_CHAR (g
);
5302 it
->len
= CHAR_BYTES (it
->c
);
5304 /* The entry may contain a face id to use. Such a face id is
5305 the id of a Lisp face, not a realized face. A face id of
5306 zero means no face is specified. */
5307 if (it
->dpvec_face_id
>= 0)
5308 it
->face_id
= it
->dpvec_face_id
;
5311 int lface_id
= FAST_GLYPH_FACE (g
);
5314 /* The function returns -1 if lface_id is invalid. */
5315 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
5317 it
->face_id
= face_id
;
5322 /* Display table entry is invalid. Return a space. */
5323 it
->c
= ' ', it
->len
= 1;
5325 /* Don't change position and object of the iterator here. They are
5326 still the values of the character that had this display table
5327 entry or was translated, and that's what we want. */
5328 it
->what
= IT_CHARACTER
;
5333 /* Load IT with the next display element from Lisp string IT->string.
5334 IT->current.string_pos is the current position within the string.
5335 If IT->current.overlay_string_index >= 0, the Lisp string is an
5339 next_element_from_string (it
)
5342 struct text_pos position
;
5344 xassert (STRINGP (it
->string
));
5345 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5346 position
= it
->current
.string_pos
;
5348 /* Time to check for invisible text? */
5349 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5350 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5354 /* Since a handler may have changed IT->method, we must
5356 return get_next_display_element (it
);
5359 if (it
->current
.overlay_string_index
>= 0)
5361 /* Get the next character from an overlay string. In overlay
5362 strings, There is no field width or padding with spaces to
5364 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5369 else if (STRING_MULTIBYTE (it
->string
))
5371 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5372 const unsigned char *s
= (SDATA (it
->string
)
5373 + IT_STRING_BYTEPOS (*it
));
5374 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5378 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5384 /* Get the next character from a Lisp string that is not an
5385 overlay string. Such strings come from the mode line, for
5386 example. We may have to pad with spaces, or truncate the
5387 string. See also next_element_from_c_string. */
5388 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5393 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5395 /* Pad with spaces. */
5396 it
->c
= ' ', it
->len
= 1;
5397 CHARPOS (position
) = BYTEPOS (position
) = -1;
5399 else if (STRING_MULTIBYTE (it
->string
))
5401 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5402 const unsigned char *s
= (SDATA (it
->string
)
5403 + IT_STRING_BYTEPOS (*it
));
5404 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5408 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5413 /* Record what we have and where it came from. Note that we store a
5414 buffer position in IT->position although it could arguably be a
5416 it
->what
= IT_CHARACTER
;
5417 it
->object
= it
->string
;
5418 it
->position
= position
;
5423 /* Load IT with next display element from C string IT->s.
5424 IT->string_nchars is the maximum number of characters to return
5425 from the string. IT->end_charpos may be greater than
5426 IT->string_nchars when this function is called, in which case we
5427 may have to return padding spaces. Value is zero if end of string
5428 reached, including padding spaces. */
5431 next_element_from_c_string (it
)
5437 it
->what
= IT_CHARACTER
;
5438 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5441 /* IT's position can be greater IT->string_nchars in case a field
5442 width or precision has been specified when the iterator was
5444 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5446 /* End of the game. */
5450 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5452 /* Pad with spaces. */
5453 it
->c
= ' ', it
->len
= 1;
5454 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5456 else if (it
->multibyte_p
)
5458 /* Implementation note: The calls to strlen apparently aren't a
5459 performance problem because there is no noticeable performance
5460 difference between Emacs running in unibyte or multibyte mode. */
5461 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5462 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5466 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5472 /* Set up IT to return characters from an ellipsis, if appropriate.
5473 The definition of the ellipsis glyphs may come from a display table
5474 entry. This function Fills IT with the first glyph from the
5475 ellipsis if an ellipsis is to be displayed. */
5478 next_element_from_ellipsis (it
)
5481 if (it
->selective_display_ellipsis_p
)
5482 setup_for_ellipsis (it
, it
->len
);
5485 /* The face at the current position may be different from the
5486 face we find after the invisible text. Remember what it
5487 was in IT->saved_face_id, and signal that it's there by
5488 setting face_before_selective_p. */
5489 it
->saved_face_id
= it
->face_id
;
5490 it
->method
= next_element_from_buffer
;
5491 reseat_at_next_visible_line_start (it
, 1);
5492 it
->face_before_selective_p
= 1;
5495 return get_next_display_element (it
);
5499 /* Deliver an image display element. The iterator IT is already
5500 filled with image information (done in handle_display_prop). Value
5505 next_element_from_image (it
)
5508 it
->what
= IT_IMAGE
;
5513 /* Fill iterator IT with next display element from a stretch glyph
5514 property. IT->object is the value of the text property. Value is
5518 next_element_from_stretch (it
)
5521 it
->what
= IT_STRETCH
;
5526 /* Load IT with the next display element from current_buffer. Value
5527 is zero if end of buffer reached. IT->stop_charpos is the next
5528 position at which to stop and check for text properties or buffer
5532 next_element_from_buffer (it
)
5537 /* Check this assumption, otherwise, we would never enter the
5538 if-statement, below. */
5539 xassert (IT_CHARPOS (*it
) >= BEGV
5540 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5542 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5544 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5546 int overlay_strings_follow_p
;
5548 /* End of the game, except when overlay strings follow that
5549 haven't been returned yet. */
5550 if (it
->overlay_strings_at_end_processed_p
)
5551 overlay_strings_follow_p
= 0;
5554 it
->overlay_strings_at_end_processed_p
= 1;
5555 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5558 if (overlay_strings_follow_p
)
5559 success_p
= get_next_display_element (it
);
5563 it
->position
= it
->current
.pos
;
5570 return get_next_display_element (it
);
5575 /* No face changes, overlays etc. in sight, so just return a
5576 character from current_buffer. */
5579 /* Maybe run the redisplay end trigger hook. Performance note:
5580 This doesn't seem to cost measurable time. */
5581 if (it
->redisplay_end_trigger_charpos
5583 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5584 run_redisplay_end_trigger_hook (it
);
5586 /* Get the next character, maybe multibyte. */
5587 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5588 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5590 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5591 - IT_BYTEPOS (*it
));
5592 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5595 it
->c
= *p
, it
->len
= 1;
5597 /* Record what we have and where it came from. */
5598 it
->what
= IT_CHARACTER
;;
5599 it
->object
= it
->w
->buffer
;
5600 it
->position
= it
->current
.pos
;
5602 /* Normally we return the character found above, except when we
5603 really want to return an ellipsis for selective display. */
5608 /* A value of selective > 0 means hide lines indented more
5609 than that number of columns. */
5610 if (it
->selective
> 0
5611 && IT_CHARPOS (*it
) + 1 < ZV
5612 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5613 IT_BYTEPOS (*it
) + 1,
5614 (double) it
->selective
)) /* iftc */
5616 success_p
= next_element_from_ellipsis (it
);
5617 it
->dpvec_char_len
= -1;
5620 else if (it
->c
== '\r' && it
->selective
== -1)
5622 /* A value of selective == -1 means that everything from the
5623 CR to the end of the line is invisible, with maybe an
5624 ellipsis displayed for it. */
5625 success_p
= next_element_from_ellipsis (it
);
5626 it
->dpvec_char_len
= -1;
5631 /* Value is zero if end of buffer reached. */
5632 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5637 /* Run the redisplay end trigger hook for IT. */
5640 run_redisplay_end_trigger_hook (it
)
5643 Lisp_Object args
[3];
5645 /* IT->glyph_row should be non-null, i.e. we should be actually
5646 displaying something, or otherwise we should not run the hook. */
5647 xassert (it
->glyph_row
);
5649 /* Set up hook arguments. */
5650 args
[0] = Qredisplay_end_trigger_functions
;
5651 args
[1] = it
->window
;
5652 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5653 it
->redisplay_end_trigger_charpos
= 0;
5655 /* Since we are *trying* to run these functions, don't try to run
5656 them again, even if they get an error. */
5657 it
->w
->redisplay_end_trigger
= Qnil
;
5658 Frun_hook_with_args (3, args
);
5660 /* Notice if it changed the face of the character we are on. */
5661 handle_face_prop (it
);
5665 /* Deliver a composition display element. The iterator IT is already
5666 filled with composition information (done in
5667 handle_composition_prop). Value is always 1. */
5670 next_element_from_composition (it
)
5673 it
->what
= IT_COMPOSITION
;
5674 it
->position
= (STRINGP (it
->string
)
5675 ? it
->current
.string_pos
5682 /***********************************************************************
5683 Moving an iterator without producing glyphs
5684 ***********************************************************************/
5686 /* Move iterator IT to a specified buffer or X position within one
5687 line on the display without producing glyphs.
5689 OP should be a bit mask including some or all of these bits:
5690 MOVE_TO_X: Stop on reaching x-position TO_X.
5691 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5692 Regardless of OP's value, stop in reaching the end of the display line.
5694 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5695 This means, in particular, that TO_X includes window's horizontal
5698 The return value has several possible values that
5699 say what condition caused the scan to stop:
5701 MOVE_POS_MATCH_OR_ZV
5702 - when TO_POS or ZV was reached.
5705 -when TO_X was reached before TO_POS or ZV were reached.
5708 - when we reached the end of the display area and the line must
5712 - when we reached the end of the display area and the line is
5716 - when we stopped at a line end, i.e. a newline or a CR and selective
5719 static enum move_it_result
5720 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5722 int to_charpos
, to_x
, op
;
5724 enum move_it_result result
= MOVE_UNDEFINED
;
5725 struct glyph_row
*saved_glyph_row
;
5727 /* Don't produce glyphs in produce_glyphs. */
5728 saved_glyph_row
= it
->glyph_row
;
5729 it
->glyph_row
= NULL
;
5731 #define BUFFER_POS_REACHED_P() \
5732 ((op & MOVE_TO_POS) != 0 \
5733 && BUFFERP (it->object) \
5734 && IT_CHARPOS (*it) >= to_charpos \
5735 && it->method == next_element_from_buffer)
5739 int x
, i
, ascent
= 0, descent
= 0;
5741 /* Stop when ZV reached.
5742 We used to stop here when TO_CHARPOS reached as well, but that is
5743 too soon if this glyph does not fit on this line. So we handle it
5744 explicitly below. */
5745 if (!get_next_display_element (it
)
5746 || (it
->truncate_lines_p
5747 && BUFFER_POS_REACHED_P ()))
5749 result
= MOVE_POS_MATCH_OR_ZV
;
5753 /* The call to produce_glyphs will get the metrics of the
5754 display element IT is loaded with. We record in x the
5755 x-position before this display element in case it does not
5759 /* Remember the line height so far in case the next element doesn't
5761 if (!it
->truncate_lines_p
)
5763 ascent
= it
->max_ascent
;
5764 descent
= it
->max_descent
;
5767 PRODUCE_GLYPHS (it
);
5769 if (it
->area
!= TEXT_AREA
)
5771 set_iterator_to_next (it
, 1);
5775 /* The number of glyphs we get back in IT->nglyphs will normally
5776 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5777 character on a terminal frame, or (iii) a line end. For the
5778 second case, IT->nglyphs - 1 padding glyphs will be present
5779 (on X frames, there is only one glyph produced for a
5780 composite character.
5782 The behavior implemented below means, for continuation lines,
5783 that as many spaces of a TAB as fit on the current line are
5784 displayed there. For terminal frames, as many glyphs of a
5785 multi-glyph character are displayed in the current line, too.
5786 This is what the old redisplay code did, and we keep it that
5787 way. Under X, the whole shape of a complex character must
5788 fit on the line or it will be completely displayed in the
5791 Note that both for tabs and padding glyphs, all glyphs have
5795 /* More than one glyph or glyph doesn't fit on line. All
5796 glyphs have the same width. */
5797 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5800 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5802 new_x
= x
+ single_glyph_width
;
5804 /* We want to leave anything reaching TO_X to the caller. */
5805 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5807 if (BUFFER_POS_REACHED_P ())
5808 goto buffer_pos_reached
;
5810 result
= MOVE_X_REACHED
;
5813 else if (/* Lines are continued. */
5814 !it
->truncate_lines_p
5815 && (/* And glyph doesn't fit on the line. */
5816 new_x
> it
->last_visible_x
5817 /* Or it fits exactly and we're on a window
5819 || (new_x
== it
->last_visible_x
5820 && FRAME_WINDOW_P (it
->f
))))
5822 if (/* IT->hpos == 0 means the very first glyph
5823 doesn't fit on the line, e.g. a wide image. */
5825 || (new_x
== it
->last_visible_x
5826 && FRAME_WINDOW_P (it
->f
)))
5829 it
->current_x
= new_x
;
5830 if (i
== it
->nglyphs
- 1)
5832 set_iterator_to_next (it
, 1);
5833 #ifdef HAVE_WINDOW_SYSTEM
5834 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5836 if (!get_next_display_element (it
))
5838 result
= MOVE_POS_MATCH_OR_ZV
;
5841 if (BUFFER_POS_REACHED_P ())
5843 if (ITERATOR_AT_END_OF_LINE_P (it
))
5844 result
= MOVE_POS_MATCH_OR_ZV
;
5846 result
= MOVE_LINE_CONTINUED
;
5849 if (ITERATOR_AT_END_OF_LINE_P (it
))
5851 result
= MOVE_NEWLINE_OR_CR
;
5855 #endif /* HAVE_WINDOW_SYSTEM */
5861 it
->max_ascent
= ascent
;
5862 it
->max_descent
= descent
;
5865 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5867 result
= MOVE_LINE_CONTINUED
;
5870 else if (BUFFER_POS_REACHED_P ())
5871 goto buffer_pos_reached
;
5872 else if (new_x
> it
->first_visible_x
)
5874 /* Glyph is visible. Increment number of glyphs that
5875 would be displayed. */
5880 /* Glyph is completely off the left margin of the display
5881 area. Nothing to do. */
5885 if (result
!= MOVE_UNDEFINED
)
5888 else if (BUFFER_POS_REACHED_P ())
5892 it
->max_ascent
= ascent
;
5893 it
->max_descent
= descent
;
5894 result
= MOVE_POS_MATCH_OR_ZV
;
5897 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5899 /* Stop when TO_X specified and reached. This check is
5900 necessary here because of lines consisting of a line end,
5901 only. The line end will not produce any glyphs and we
5902 would never get MOVE_X_REACHED. */
5903 xassert (it
->nglyphs
== 0);
5904 result
= MOVE_X_REACHED
;
5908 /* Is this a line end? If yes, we're done. */
5909 if (ITERATOR_AT_END_OF_LINE_P (it
))
5911 result
= MOVE_NEWLINE_OR_CR
;
5915 /* The current display element has been consumed. Advance
5917 set_iterator_to_next (it
, 1);
5919 /* Stop if lines are truncated and IT's current x-position is
5920 past the right edge of the window now. */
5921 if (it
->truncate_lines_p
5922 && it
->current_x
>= it
->last_visible_x
)
5924 #ifdef HAVE_WINDOW_SYSTEM
5925 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
5927 if (!get_next_display_element (it
)
5928 || BUFFER_POS_REACHED_P ())
5930 result
= MOVE_POS_MATCH_OR_ZV
;
5933 if (ITERATOR_AT_END_OF_LINE_P (it
))
5935 result
= MOVE_NEWLINE_OR_CR
;
5939 #endif /* HAVE_WINDOW_SYSTEM */
5940 result
= MOVE_LINE_TRUNCATED
;
5945 #undef BUFFER_POS_REACHED_P
5947 /* Restore the iterator settings altered at the beginning of this
5949 it
->glyph_row
= saved_glyph_row
;
5954 /* Move IT forward until it satisfies one or more of the criteria in
5955 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5957 OP is a bit-mask that specifies where to stop, and in particular,
5958 which of those four position arguments makes a difference. See the
5959 description of enum move_operation_enum.
5961 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5962 screen line, this function will set IT to the next position >
5966 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5968 int to_charpos
, to_x
, to_y
, to_vpos
;
5971 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5977 if (op
& MOVE_TO_VPOS
)
5979 /* If no TO_CHARPOS and no TO_X specified, stop at the
5980 start of the line TO_VPOS. */
5981 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5983 if (it
->vpos
== to_vpos
)
5989 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5993 /* TO_VPOS >= 0 means stop at TO_X in the line at
5994 TO_VPOS, or at TO_POS, whichever comes first. */
5995 if (it
->vpos
== to_vpos
)
6001 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6003 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6008 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6010 /* We have reached TO_X but not in the line we want. */
6011 skip
= move_it_in_display_line_to (it
, to_charpos
,
6013 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6021 else if (op
& MOVE_TO_Y
)
6023 struct it it_backup
;
6025 /* TO_Y specified means stop at TO_X in the line containing
6026 TO_Y---or at TO_CHARPOS if this is reached first. The
6027 problem is that we can't really tell whether the line
6028 contains TO_Y before we have completely scanned it, and
6029 this may skip past TO_X. What we do is to first scan to
6032 If TO_X is not specified, use a TO_X of zero. The reason
6033 is to make the outcome of this function more predictable.
6034 If we didn't use TO_X == 0, we would stop at the end of
6035 the line which is probably not what a caller would expect
6037 skip
= move_it_in_display_line_to (it
, to_charpos
,
6041 | (op
& MOVE_TO_POS
)));
6043 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6044 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6050 /* If TO_X was reached, we would like to know whether TO_Y
6051 is in the line. This can only be said if we know the
6052 total line height which requires us to scan the rest of
6054 if (skip
== MOVE_X_REACHED
)
6057 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6058 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6060 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6063 /* Now, decide whether TO_Y is in this line. */
6064 line_height
= it
->max_ascent
+ it
->max_descent
;
6065 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6067 if (to_y
>= it
->current_y
6068 && to_y
< it
->current_y
+ line_height
)
6070 if (skip
== MOVE_X_REACHED
)
6071 /* If TO_Y is in this line and TO_X was reached above,
6072 we scanned too far. We have to restore IT's settings
6073 to the ones before skipping. */
6077 else if (skip
== MOVE_X_REACHED
)
6080 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6088 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6092 case MOVE_POS_MATCH_OR_ZV
:
6096 case MOVE_NEWLINE_OR_CR
:
6097 set_iterator_to_next (it
, 1);
6098 it
->continuation_lines_width
= 0;
6101 case MOVE_LINE_TRUNCATED
:
6102 it
->continuation_lines_width
= 0;
6103 reseat_at_next_visible_line_start (it
, 0);
6104 if ((op
& MOVE_TO_POS
) != 0
6105 && IT_CHARPOS (*it
) > to_charpos
)
6112 case MOVE_LINE_CONTINUED
:
6113 it
->continuation_lines_width
+= it
->current_x
;
6120 /* Reset/increment for the next run. */
6121 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6122 it
->current_x
= it
->hpos
= 0;
6123 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6125 last_height
= it
->max_ascent
+ it
->max_descent
;
6126 last_max_ascent
= it
->max_ascent
;
6127 it
->max_ascent
= it
->max_descent
= 0;
6132 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6136 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6138 If DY > 0, move IT backward at least that many pixels. DY = 0
6139 means move IT backward to the preceding line start or BEGV. This
6140 function may move over more than DY pixels if IT->current_y - DY
6141 ends up in the middle of a line; in this case IT->current_y will be
6142 set to the top of the line moved to. */
6145 move_it_vertically_backward (it
, dy
)
6156 start_pos
= IT_CHARPOS (*it
);
6158 /* Estimate how many newlines we must move back. */
6159 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6161 /* Set the iterator's position that many lines back. */
6162 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6163 back_to_previous_visible_line_start (it
);
6165 /* Reseat the iterator here. When moving backward, we don't want
6166 reseat to skip forward over invisible text, set up the iterator
6167 to deliver from overlay strings at the new position etc. So,
6168 use reseat_1 here. */
6169 reseat_1 (it
, it
->current
.pos
, 1);
6171 /* We are now surely at a line start. */
6172 it
->current_x
= it
->hpos
= 0;
6173 it
->continuation_lines_width
= 0;
6175 /* Move forward and see what y-distance we moved. First move to the
6176 start of the next line so that we get its height. We need this
6177 height to be able to tell whether we reached the specified
6180 it2
.max_ascent
= it2
.max_descent
= 0;
6181 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6182 MOVE_TO_POS
| MOVE_TO_VPOS
);
6183 xassert (IT_CHARPOS (*it
) >= BEGV
);
6186 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6187 xassert (IT_CHARPOS (*it
) >= BEGV
);
6188 /* H is the actual vertical distance from the position in *IT
6189 and the starting position. */
6190 h
= it2
.current_y
- it
->current_y
;
6191 /* NLINES is the distance in number of lines. */
6192 nlines
= it2
.vpos
- it
->vpos
;
6194 /* Correct IT's y and vpos position
6195 so that they are relative to the starting point. */
6201 /* DY == 0 means move to the start of the screen line. The
6202 value of nlines is > 0 if continuation lines were involved. */
6204 move_it_by_lines (it
, nlines
, 1);
6205 xassert (IT_CHARPOS (*it
) <= start_pos
);
6209 /* The y-position we try to reach, relative to *IT.
6210 Note that H has been subtracted in front of the if-statement. */
6211 int target_y
= it
->current_y
+ h
- dy
;
6212 int y0
= it3
.current_y
;
6213 int y1
= line_bottom_y (&it3
);
6214 int line_height
= y1
- y0
;
6216 /* If we did not reach target_y, try to move further backward if
6217 we can. If we moved too far backward, try to move forward. */
6218 if (target_y
< it
->current_y
6219 /* This is heuristic. In a window that's 3 lines high, with
6220 a line height of 13 pixels each, recentering with point
6221 on the bottom line will try to move -39/2 = 19 pixels
6222 backward. Try to avoid moving into the first line. */
6223 && it
->current_y
- target_y
> line_height
* 2 / 3
6224 && IT_CHARPOS (*it
) > BEGV
)
6226 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6227 target_y
- it
->current_y
));
6228 dy
= it
->current_y
- target_y
;
6229 goto move_further_back
;
6231 else if (target_y
>= it
->current_y
+ line_height
6232 && IT_CHARPOS (*it
) < ZV
)
6234 /* Should move forward by at least one line, maybe more.
6236 Note: Calling move_it_by_lines can be expensive on
6237 terminal frames, where compute_motion is used (via
6238 vmotion) to do the job, when there are very long lines
6239 and truncate-lines is nil. That's the reason for
6240 treating terminal frames specially here. */
6242 if (!FRAME_WINDOW_P (it
->f
))
6243 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6248 move_it_by_lines (it
, 1, 1);
6250 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6253 xassert (IT_CHARPOS (*it
) >= BEGV
);
6259 /* Move IT by a specified amount of pixel lines DY. DY negative means
6260 move backwards. DY = 0 means move to start of screen line. At the
6261 end, IT will be on the start of a screen line. */
6264 move_it_vertically (it
, dy
)
6269 move_it_vertically_backward (it
, -dy
);
6272 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6273 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6274 MOVE_TO_POS
| MOVE_TO_Y
);
6275 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6277 /* If buffer ends in ZV without a newline, move to the start of
6278 the line to satisfy the post-condition. */
6279 if (IT_CHARPOS (*it
) == ZV
6280 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6281 move_it_by_lines (it
, 0, 0);
6286 /* Move iterator IT past the end of the text line it is in. */
6289 move_it_past_eol (it
)
6292 enum move_it_result rc
;
6294 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6295 if (rc
== MOVE_NEWLINE_OR_CR
)
6296 set_iterator_to_next (it
, 0);
6300 #if 0 /* Currently not used. */
6302 /* Return non-zero if some text between buffer positions START_CHARPOS
6303 and END_CHARPOS is invisible. IT->window is the window for text
6307 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6309 int start_charpos
, end_charpos
;
6311 Lisp_Object prop
, limit
;
6312 int invisible_found_p
;
6314 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6316 /* Is text at START invisible? */
6317 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6319 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6320 invisible_found_p
= 1;
6323 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6325 make_number (end_charpos
));
6326 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6329 return invisible_found_p
;
6335 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6336 negative means move up. DVPOS == 0 means move to the start of the
6337 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6338 NEED_Y_P is zero, IT->current_y will be left unchanged.
6340 Further optimization ideas: If we would know that IT->f doesn't use
6341 a face with proportional font, we could be faster for
6342 truncate-lines nil. */
6345 move_it_by_lines (it
, dvpos
, need_y_p
)
6347 int dvpos
, need_y_p
;
6349 struct position pos
;
6351 if (!FRAME_WINDOW_P (it
->f
))
6353 struct text_pos textpos
;
6355 /* We can use vmotion on frames without proportional fonts. */
6356 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6357 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6358 reseat (it
, textpos
, 1);
6359 it
->vpos
+= pos
.vpos
;
6360 it
->current_y
+= pos
.vpos
;
6362 else if (dvpos
== 0)
6364 /* DVPOS == 0 means move to the start of the screen line. */
6365 move_it_vertically_backward (it
, 0);
6366 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6367 /* Let next call to line_bottom_y calculate real line height */
6371 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6375 int start_charpos
, i
;
6377 /* Start at the beginning of the screen line containing IT's
6379 move_it_vertically_backward (it
, 0);
6381 /* Go back -DVPOS visible lines and reseat the iterator there. */
6382 start_charpos
= IT_CHARPOS (*it
);
6383 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6384 back_to_previous_visible_line_start (it
);
6385 reseat (it
, it
->current
.pos
, 1);
6386 it
->current_x
= it
->hpos
= 0;
6388 /* Above call may have moved too far if continuation lines
6389 are involved. Scan forward and see if it did. */
6391 it2
.vpos
= it2
.current_y
= 0;
6392 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6393 it
->vpos
-= it2
.vpos
;
6394 it
->current_y
-= it2
.current_y
;
6395 it
->current_x
= it
->hpos
= 0;
6397 /* If we moved too far, move IT some lines forward. */
6398 if (it2
.vpos
> -dvpos
)
6400 int delta
= it2
.vpos
+ dvpos
;
6401 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6406 /* Return 1 if IT points into the middle of a display vector. */
6409 in_display_vector_p (it
)
6412 return (it
->method
== next_element_from_display_vector
6413 && it
->current
.dpvec_index
> 0
6414 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6418 /***********************************************************************
6420 ***********************************************************************/
6423 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6427 add_to_log (format
, arg1
, arg2
)
6429 Lisp_Object arg1
, arg2
;
6431 Lisp_Object args
[3];
6432 Lisp_Object msg
, fmt
;
6435 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6438 /* Do nothing if called asynchronously. Inserting text into
6439 a buffer may call after-change-functions and alike and
6440 that would means running Lisp asynchronously. */
6441 if (handling_signal
)
6445 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6447 args
[0] = fmt
= build_string (format
);
6450 msg
= Fformat (3, args
);
6452 len
= SBYTES (msg
) + 1;
6453 SAFE_ALLOCA (buffer
, char *, len
);
6454 bcopy (SDATA (msg
), buffer
, len
);
6456 message_dolog (buffer
, len
- 1, 1, 0);
6463 /* Output a newline in the *Messages* buffer if "needs" one. */
6466 message_log_maybe_newline ()
6468 if (message_log_need_newline
)
6469 message_dolog ("", 0, 1, 0);
6473 /* Add a string M of length NBYTES to the message log, optionally
6474 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6475 nonzero, means interpret the contents of M as multibyte. This
6476 function calls low-level routines in order to bypass text property
6477 hooks, etc. which might not be safe to run. */
6480 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6482 int nbytes
, nlflag
, multibyte
;
6484 if (!NILP (Vmemory_full
))
6487 if (!NILP (Vmessage_log_max
))
6489 struct buffer
*oldbuf
;
6490 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6491 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6492 int point_at_end
= 0;
6494 Lisp_Object old_deactivate_mark
, tem
;
6495 struct gcpro gcpro1
;
6497 old_deactivate_mark
= Vdeactivate_mark
;
6498 oldbuf
= current_buffer
;
6499 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6500 current_buffer
->undo_list
= Qt
;
6502 oldpoint
= message_dolog_marker1
;
6503 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6504 oldbegv
= message_dolog_marker2
;
6505 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6506 oldzv
= message_dolog_marker3
;
6507 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6508 GCPRO1 (old_deactivate_mark
);
6516 BEGV_BYTE
= BEG_BYTE
;
6519 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6521 /* Insert the string--maybe converting multibyte to single byte
6522 or vice versa, so that all the text fits the buffer. */
6524 && NILP (current_buffer
->enable_multibyte_characters
))
6526 int i
, c
, char_bytes
;
6527 unsigned char work
[1];
6529 /* Convert a multibyte string to single-byte
6530 for the *Message* buffer. */
6531 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6533 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6534 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6536 : multibyte_char_to_unibyte (c
, Qnil
));
6537 insert_1_both (work
, 1, 1, 1, 0, 0);
6540 else if (! multibyte
6541 && ! NILP (current_buffer
->enable_multibyte_characters
))
6543 int i
, c
, char_bytes
;
6544 unsigned char *msg
= (unsigned char *) m
;
6545 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6546 /* Convert a single-byte string to multibyte
6547 for the *Message* buffer. */
6548 for (i
= 0; i
< nbytes
; i
++)
6550 c
= unibyte_char_to_multibyte (msg
[i
]);
6551 char_bytes
= CHAR_STRING (c
, str
);
6552 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6556 insert_1 (m
, nbytes
, 1, 0, 0);
6560 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6561 insert_1 ("\n", 1, 1, 0, 0);
6563 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6565 this_bol_byte
= PT_BYTE
;
6567 /* See if this line duplicates the previous one.
6568 If so, combine duplicates. */
6571 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6573 prev_bol_byte
= PT_BYTE
;
6575 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6576 this_bol
, this_bol_byte
);
6579 del_range_both (prev_bol
, prev_bol_byte
,
6580 this_bol
, this_bol_byte
, 0);
6586 /* If you change this format, don't forget to also
6587 change message_log_check_duplicate. */
6588 sprintf (dupstr
, " [%d times]", dup
);
6589 duplen
= strlen (dupstr
);
6590 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6591 insert_1 (dupstr
, duplen
, 1, 0, 1);
6596 /* If we have more than the desired maximum number of lines
6597 in the *Messages* buffer now, delete the oldest ones.
6598 This is safe because we don't have undo in this buffer. */
6600 if (NATNUMP (Vmessage_log_max
))
6602 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6603 -XFASTINT (Vmessage_log_max
) - 1, 0);
6604 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6607 BEGV
= XMARKER (oldbegv
)->charpos
;
6608 BEGV_BYTE
= marker_byte_position (oldbegv
);
6617 ZV
= XMARKER (oldzv
)->charpos
;
6618 ZV_BYTE
= marker_byte_position (oldzv
);
6622 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6624 /* We can't do Fgoto_char (oldpoint) because it will run some
6626 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6627 XMARKER (oldpoint
)->bytepos
);
6630 unchain_marker (XMARKER (oldpoint
));
6631 unchain_marker (XMARKER (oldbegv
));
6632 unchain_marker (XMARKER (oldzv
));
6634 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6635 set_buffer_internal (oldbuf
);
6637 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6638 message_log_need_newline
= !nlflag
;
6639 Vdeactivate_mark
= old_deactivate_mark
;
6644 /* We are at the end of the buffer after just having inserted a newline.
6645 (Note: We depend on the fact we won't be crossing the gap.)
6646 Check to see if the most recent message looks a lot like the previous one.
6647 Return 0 if different, 1 if the new one should just replace it, or a
6648 value N > 1 if we should also append " [N times]". */
6651 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6652 int prev_bol
, this_bol
;
6653 int prev_bol_byte
, this_bol_byte
;
6656 int len
= Z_BYTE
- 1 - this_bol_byte
;
6658 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6659 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6661 for (i
= 0; i
< len
; i
++)
6663 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6671 if (*p1
++ == ' ' && *p1
++ == '[')
6674 while (*p1
>= '0' && *p1
<= '9')
6675 n
= n
* 10 + *p1
++ - '0';
6676 if (strncmp (p1
, " times]\n", 8) == 0)
6683 /* Display an echo area message M with a specified length of NBYTES
6684 bytes. The string may include null characters. If M is 0, clear
6685 out any existing message, and let the mini-buffer text show
6688 The buffer M must continue to exist until after the echo area gets
6689 cleared or some other message gets displayed there. This means do
6690 not pass text that is stored in a Lisp string; do not pass text in
6691 a buffer that was alloca'd. */
6694 message2 (m
, nbytes
, multibyte
)
6699 /* First flush out any partial line written with print. */
6700 message_log_maybe_newline ();
6702 message_dolog (m
, nbytes
, 1, multibyte
);
6703 message2_nolog (m
, nbytes
, multibyte
);
6707 /* The non-logging counterpart of message2. */
6710 message2_nolog (m
, nbytes
, multibyte
)
6712 int nbytes
, multibyte
;
6714 struct frame
*sf
= SELECTED_FRAME ();
6715 message_enable_multibyte
= multibyte
;
6719 if (noninteractive_need_newline
)
6720 putc ('\n', stderr
);
6721 noninteractive_need_newline
= 0;
6723 fwrite (m
, nbytes
, 1, stderr
);
6724 if (cursor_in_echo_area
== 0)
6725 fprintf (stderr
, "\n");
6728 /* A null message buffer means that the frame hasn't really been
6729 initialized yet. Error messages get reported properly by
6730 cmd_error, so this must be just an informative message; toss it. */
6731 else if (INTERACTIVE
6732 && sf
->glyphs_initialized_p
6733 && FRAME_MESSAGE_BUF (sf
))
6735 Lisp_Object mini_window
;
6738 /* Get the frame containing the mini-buffer
6739 that the selected frame is using. */
6740 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6741 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6743 FRAME_SAMPLE_VISIBILITY (f
);
6744 if (FRAME_VISIBLE_P (sf
)
6745 && ! FRAME_VISIBLE_P (f
))
6746 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6750 set_message (m
, Qnil
, nbytes
, multibyte
);
6751 if (minibuffer_auto_raise
)
6752 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6755 clear_message (1, 1);
6757 do_pending_window_change (0);
6758 echo_area_display (1);
6759 do_pending_window_change (0);
6760 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6761 (*frame_up_to_date_hook
) (f
);
6766 /* Display an echo area message M with a specified length of NBYTES
6767 bytes. The string may include null characters. If M is not a
6768 string, clear out any existing message, and let the mini-buffer
6769 text show through. */
6772 message3 (m
, nbytes
, multibyte
)
6777 struct gcpro gcpro1
;
6780 clear_message (1,1);
6782 /* First flush out any partial line written with print. */
6783 message_log_maybe_newline ();
6785 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6786 message3_nolog (m
, nbytes
, multibyte
);
6792 /* The non-logging version of message3. */
6795 message3_nolog (m
, nbytes
, multibyte
)
6797 int nbytes
, multibyte
;
6799 struct frame
*sf
= SELECTED_FRAME ();
6800 message_enable_multibyte
= multibyte
;
6804 if (noninteractive_need_newline
)
6805 putc ('\n', stderr
);
6806 noninteractive_need_newline
= 0;
6808 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6809 if (cursor_in_echo_area
== 0)
6810 fprintf (stderr
, "\n");
6813 /* A null message buffer means that the frame hasn't really been
6814 initialized yet. Error messages get reported properly by
6815 cmd_error, so this must be just an informative message; toss it. */
6816 else if (INTERACTIVE
6817 && sf
->glyphs_initialized_p
6818 && FRAME_MESSAGE_BUF (sf
))
6820 Lisp_Object mini_window
;
6824 /* Get the frame containing the mini-buffer
6825 that the selected frame is using. */
6826 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6827 frame
= XWINDOW (mini_window
)->frame
;
6830 FRAME_SAMPLE_VISIBILITY (f
);
6831 if (FRAME_VISIBLE_P (sf
)
6832 && !FRAME_VISIBLE_P (f
))
6833 Fmake_frame_visible (frame
);
6835 if (STRINGP (m
) && SCHARS (m
) > 0)
6837 set_message (NULL
, m
, nbytes
, multibyte
);
6838 if (minibuffer_auto_raise
)
6839 Fraise_frame (frame
);
6842 clear_message (1, 1);
6844 do_pending_window_change (0);
6845 echo_area_display (1);
6846 do_pending_window_change (0);
6847 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6848 (*frame_up_to_date_hook
) (f
);
6853 /* Display a null-terminated echo area message M. If M is 0, clear
6854 out any existing message, and let the mini-buffer text show through.
6856 The buffer M must continue to exist until after the echo area gets
6857 cleared or some other message gets displayed there. Do not pass
6858 text that is stored in a Lisp string. Do not pass text in a buffer
6859 that was alloca'd. */
6865 message2 (m
, (m
? strlen (m
) : 0), 0);
6869 /* The non-logging counterpart of message1. */
6875 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6878 /* Display a message M which contains a single %s
6879 which gets replaced with STRING. */
6882 message_with_string (m
, string
, log
)
6887 CHECK_STRING (string
);
6893 if (noninteractive_need_newline
)
6894 putc ('\n', stderr
);
6895 noninteractive_need_newline
= 0;
6896 fprintf (stderr
, m
, SDATA (string
));
6897 if (cursor_in_echo_area
== 0)
6898 fprintf (stderr
, "\n");
6902 else if (INTERACTIVE
)
6904 /* The frame whose minibuffer we're going to display the message on.
6905 It may be larger than the selected frame, so we need
6906 to use its buffer, not the selected frame's buffer. */
6907 Lisp_Object mini_window
;
6908 struct frame
*f
, *sf
= SELECTED_FRAME ();
6910 /* Get the frame containing the minibuffer
6911 that the selected frame is using. */
6912 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6913 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6915 /* A null message buffer means that the frame hasn't really been
6916 initialized yet. Error messages get reported properly by
6917 cmd_error, so this must be just an informative message; toss it. */
6918 if (FRAME_MESSAGE_BUF (f
))
6920 Lisp_Object args
[2], message
;
6921 struct gcpro gcpro1
, gcpro2
;
6923 args
[0] = build_string (m
);
6924 args
[1] = message
= string
;
6925 GCPRO2 (args
[0], message
);
6928 message
= Fformat (2, args
);
6931 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6933 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6937 /* Print should start at the beginning of the message
6938 buffer next time. */
6939 message_buf_print
= 0;
6945 /* Dump an informative message to the minibuf. If M is 0, clear out
6946 any existing message, and let the mini-buffer text show through. */
6950 message (m
, a1
, a2
, a3
)
6952 EMACS_INT a1
, a2
, a3
;
6958 if (noninteractive_need_newline
)
6959 putc ('\n', stderr
);
6960 noninteractive_need_newline
= 0;
6961 fprintf (stderr
, m
, a1
, a2
, a3
);
6962 if (cursor_in_echo_area
== 0)
6963 fprintf (stderr
, "\n");
6967 else if (INTERACTIVE
)
6969 /* The frame whose mini-buffer we're going to display the message
6970 on. It may be larger than the selected frame, so we need to
6971 use its buffer, not the selected frame's buffer. */
6972 Lisp_Object mini_window
;
6973 struct frame
*f
, *sf
= SELECTED_FRAME ();
6975 /* Get the frame containing the mini-buffer
6976 that the selected frame is using. */
6977 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6978 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6980 /* A null message buffer means that the frame hasn't really been
6981 initialized yet. Error messages get reported properly by
6982 cmd_error, so this must be just an informative message; toss
6984 if (FRAME_MESSAGE_BUF (f
))
6995 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6996 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6998 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6999 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7001 #endif /* NO_ARG_ARRAY */
7003 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7008 /* Print should start at the beginning of the message
7009 buffer next time. */
7010 message_buf_print
= 0;
7016 /* The non-logging version of message. */
7019 message_nolog (m
, a1
, a2
, a3
)
7021 EMACS_INT a1
, a2
, a3
;
7023 Lisp_Object old_log_max
;
7024 old_log_max
= Vmessage_log_max
;
7025 Vmessage_log_max
= Qnil
;
7026 message (m
, a1
, a2
, a3
);
7027 Vmessage_log_max
= old_log_max
;
7031 /* Display the current message in the current mini-buffer. This is
7032 only called from error handlers in process.c, and is not time
7038 if (!NILP (echo_area_buffer
[0]))
7041 string
= Fcurrent_message ();
7042 message3 (string
, SBYTES (string
),
7043 !NILP (current_buffer
->enable_multibyte_characters
));
7048 /* Make sure echo area buffers in `echo_buffers' are live.
7049 If they aren't, make new ones. */
7052 ensure_echo_area_buffers ()
7056 for (i
= 0; i
< 2; ++i
)
7057 if (!BUFFERP (echo_buffer
[i
])
7058 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7061 Lisp_Object old_buffer
;
7064 old_buffer
= echo_buffer
[i
];
7065 sprintf (name
, " *Echo Area %d*", i
);
7066 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7067 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7069 for (j
= 0; j
< 2; ++j
)
7070 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7071 echo_area_buffer
[j
] = echo_buffer
[i
];
7076 /* Call FN with args A1..A4 with either the current or last displayed
7077 echo_area_buffer as current buffer.
7079 WHICH zero means use the current message buffer
7080 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7081 from echo_buffer[] and clear it.
7083 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7084 suitable buffer from echo_buffer[] and clear it.
7086 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
7087 that the current message becomes the last displayed one, make
7088 choose a suitable buffer for echo_area_buffer[0], and clear it.
7090 Value is what FN returns. */
7093 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7096 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7102 int this_one
, the_other
, clear_buffer_p
, rc
;
7103 int count
= SPECPDL_INDEX ();
7105 /* If buffers aren't live, make new ones. */
7106 ensure_echo_area_buffers ();
7111 this_one
= 0, the_other
= 1;
7113 this_one
= 1, the_other
= 0;
7116 this_one
= 0, the_other
= 1;
7119 /* We need a fresh one in case the current echo buffer equals
7120 the one containing the last displayed echo area message. */
7121 if (!NILP (echo_area_buffer
[this_one
])
7122 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
7123 echo_area_buffer
[this_one
] = Qnil
;
7126 /* Choose a suitable buffer from echo_buffer[] is we don't
7128 if (NILP (echo_area_buffer
[this_one
]))
7130 echo_area_buffer
[this_one
]
7131 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7132 ? echo_buffer
[the_other
]
7133 : echo_buffer
[this_one
]);
7137 buffer
= echo_area_buffer
[this_one
];
7139 /* Don't get confused by reusing the buffer used for echoing
7140 for a different purpose. */
7141 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7144 record_unwind_protect (unwind_with_echo_area_buffer
,
7145 with_echo_area_buffer_unwind_data (w
));
7147 /* Make the echo area buffer current. Note that for display
7148 purposes, it is not necessary that the displayed window's buffer
7149 == current_buffer, except for text property lookup. So, let's
7150 only set that buffer temporarily here without doing a full
7151 Fset_window_buffer. We must also change w->pointm, though,
7152 because otherwise an assertions in unshow_buffer fails, and Emacs
7154 set_buffer_internal_1 (XBUFFER (buffer
));
7158 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7161 current_buffer
->undo_list
= Qt
;
7162 current_buffer
->read_only
= Qnil
;
7163 specbind (Qinhibit_read_only
, Qt
);
7164 specbind (Qinhibit_modification_hooks
, Qt
);
7166 if (clear_buffer_p
&& Z
> BEG
)
7169 xassert (BEGV
>= BEG
);
7170 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7172 rc
= fn (a1
, a2
, a3
, a4
);
7174 xassert (BEGV
>= BEG
);
7175 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7177 unbind_to (count
, Qnil
);
7182 /* Save state that should be preserved around the call to the function
7183 FN called in with_echo_area_buffer. */
7186 with_echo_area_buffer_unwind_data (w
)
7192 /* Reduce consing by keeping one vector in
7193 Vwith_echo_area_save_vector. */
7194 vector
= Vwith_echo_area_save_vector
;
7195 Vwith_echo_area_save_vector
= Qnil
;
7198 vector
= Fmake_vector (make_number (7), Qnil
);
7200 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7201 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7202 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7206 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7207 AREF (vector
, i
) = w
->buffer
; ++i
;
7208 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7209 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7214 for (; i
< end
; ++i
)
7215 AREF (vector
, i
) = Qnil
;
7218 xassert (i
== ASIZE (vector
));
7223 /* Restore global state from VECTOR which was created by
7224 with_echo_area_buffer_unwind_data. */
7227 unwind_with_echo_area_buffer (vector
)
7230 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7231 Vdeactivate_mark
= AREF (vector
, 1);
7232 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7234 if (WINDOWP (AREF (vector
, 3)))
7237 Lisp_Object buffer
, charpos
, bytepos
;
7239 w
= XWINDOW (AREF (vector
, 3));
7240 buffer
= AREF (vector
, 4);
7241 charpos
= AREF (vector
, 5);
7242 bytepos
= AREF (vector
, 6);
7245 set_marker_both (w
->pointm
, buffer
,
7246 XFASTINT (charpos
), XFASTINT (bytepos
));
7249 Vwith_echo_area_save_vector
= vector
;
7254 /* Set up the echo area for use by print functions. MULTIBYTE_P
7255 non-zero means we will print multibyte. */
7258 setup_echo_area_for_printing (multibyte_p
)
7261 /* If we can't find an echo area any more, exit. */
7262 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7265 ensure_echo_area_buffers ();
7267 if (!message_buf_print
)
7269 /* A message has been output since the last time we printed.
7270 Choose a fresh echo area buffer. */
7271 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7272 echo_area_buffer
[0] = echo_buffer
[1];
7274 echo_area_buffer
[0] = echo_buffer
[0];
7276 /* Switch to that buffer and clear it. */
7277 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7278 current_buffer
->truncate_lines
= Qnil
;
7282 int count
= SPECPDL_INDEX ();
7283 specbind (Qinhibit_read_only
, Qt
);
7284 /* Note that undo recording is always disabled. */
7286 unbind_to (count
, Qnil
);
7288 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7290 /* Set up the buffer for the multibyteness we need. */
7292 != !NILP (current_buffer
->enable_multibyte_characters
))
7293 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7295 /* Raise the frame containing the echo area. */
7296 if (minibuffer_auto_raise
)
7298 struct frame
*sf
= SELECTED_FRAME ();
7299 Lisp_Object mini_window
;
7300 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7301 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7304 message_log_maybe_newline ();
7305 message_buf_print
= 1;
7309 if (NILP (echo_area_buffer
[0]))
7311 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7312 echo_area_buffer
[0] = echo_buffer
[1];
7314 echo_area_buffer
[0] = echo_buffer
[0];
7317 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7319 /* Someone switched buffers between print requests. */
7320 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7321 current_buffer
->truncate_lines
= Qnil
;
7327 /* Display an echo area message in window W. Value is non-zero if W's
7328 height is changed. If display_last_displayed_message_p is
7329 non-zero, display the message that was last displayed, otherwise
7330 display the current message. */
7333 display_echo_area (w
)
7336 int i
, no_message_p
, window_height_changed_p
, count
;
7338 /* Temporarily disable garbage collections while displaying the echo
7339 area. This is done because a GC can print a message itself.
7340 That message would modify the echo area buffer's contents while a
7341 redisplay of the buffer is going on, and seriously confuse
7343 count
= inhibit_garbage_collection ();
7345 /* If there is no message, we must call display_echo_area_1
7346 nevertheless because it resizes the window. But we will have to
7347 reset the echo_area_buffer in question to nil at the end because
7348 with_echo_area_buffer will sets it to an empty buffer. */
7349 i
= display_last_displayed_message_p
? 1 : 0;
7350 no_message_p
= NILP (echo_area_buffer
[i
]);
7352 window_height_changed_p
7353 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7354 display_echo_area_1
,
7355 (EMACS_INT
) w
, Qnil
, 0, 0);
7358 echo_area_buffer
[i
] = Qnil
;
7360 unbind_to (count
, Qnil
);
7361 return window_height_changed_p
;
7365 /* Helper for display_echo_area. Display the current buffer which
7366 contains the current echo area message in window W, a mini-window,
7367 a pointer to which is passed in A1. A2..A4 are currently not used.
7368 Change the height of W so that all of the message is displayed.
7369 Value is non-zero if height of W was changed. */
7372 display_echo_area_1 (a1
, a2
, a3
, a4
)
7377 struct window
*w
= (struct window
*) a1
;
7379 struct text_pos start
;
7380 int window_height_changed_p
= 0;
7382 /* Do this before displaying, so that we have a large enough glyph
7383 matrix for the display. */
7384 window_height_changed_p
= resize_mini_window (w
, 0);
7387 clear_glyph_matrix (w
->desired_matrix
);
7388 XSETWINDOW (window
, w
);
7389 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7390 try_window (window
, start
);
7392 return window_height_changed_p
;
7396 /* Resize the echo area window to exactly the size needed for the
7397 currently displayed message, if there is one. If a mini-buffer
7398 is active, don't shrink it. */
7401 resize_echo_area_exactly ()
7403 if (BUFFERP (echo_area_buffer
[0])
7404 && WINDOWP (echo_area_window
))
7406 struct window
*w
= XWINDOW (echo_area_window
);
7408 Lisp_Object resize_exactly
;
7410 if (minibuf_level
== 0)
7411 resize_exactly
= Qt
;
7413 resize_exactly
= Qnil
;
7415 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7416 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7419 ++windows_or_buffers_changed
;
7420 ++update_mode_lines
;
7421 redisplay_internal (0);
7427 /* Callback function for with_echo_area_buffer, when used from
7428 resize_echo_area_exactly. A1 contains a pointer to the window to
7429 resize, EXACTLY non-nil means resize the mini-window exactly to the
7430 size of the text displayed. A3 and A4 are not used. Value is what
7431 resize_mini_window returns. */
7434 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7436 Lisp_Object exactly
;
7439 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7443 /* Resize mini-window W to fit the size of its contents. EXACT:P
7444 means size the window exactly to the size needed. Otherwise, it's
7445 only enlarged until W's buffer is empty. Value is non-zero if
7446 the window height has been changed. */
7449 resize_mini_window (w
, exact_p
)
7453 struct frame
*f
= XFRAME (w
->frame
);
7454 int window_height_changed_p
= 0;
7456 xassert (MINI_WINDOW_P (w
));
7458 /* Don't resize windows while redisplaying a window; it would
7459 confuse redisplay functions when the size of the window they are
7460 displaying changes from under them. Such a resizing can happen,
7461 for instance, when which-func prints a long message while
7462 we are running fontification-functions. We're running these
7463 functions with safe_call which binds inhibit-redisplay to t. */
7464 if (!NILP (Vinhibit_redisplay
))
7467 /* Nil means don't try to resize. */
7468 if (NILP (Vresize_mini_windows
)
7469 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7472 if (!FRAME_MINIBUF_ONLY_P (f
))
7475 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7476 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7477 int height
, max_height
;
7478 int unit
= FRAME_LINE_HEIGHT (f
);
7479 struct text_pos start
;
7480 struct buffer
*old_current_buffer
= NULL
;
7482 if (current_buffer
!= XBUFFER (w
->buffer
))
7484 old_current_buffer
= current_buffer
;
7485 set_buffer_internal (XBUFFER (w
->buffer
));
7488 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7490 /* Compute the max. number of lines specified by the user. */
7491 if (FLOATP (Vmax_mini_window_height
))
7492 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7493 else if (INTEGERP (Vmax_mini_window_height
))
7494 max_height
= XINT (Vmax_mini_window_height
);
7496 max_height
= total_height
/ 4;
7498 /* Correct that max. height if it's bogus. */
7499 max_height
= max (1, max_height
);
7500 max_height
= min (total_height
, max_height
);
7502 /* Find out the height of the text in the window. */
7503 if (it
.truncate_lines_p
)
7508 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7509 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7510 height
= it
.current_y
+ last_height
;
7512 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7513 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
7514 height
= (height
+ unit
- 1) / unit
;
7517 /* Compute a suitable window start. */
7518 if (height
> max_height
)
7520 height
= max_height
;
7521 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7522 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7523 start
= it
.current
.pos
;
7526 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7527 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7529 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7531 /* Let it grow only, until we display an empty message, in which
7532 case the window shrinks again. */
7533 if (height
> WINDOW_TOTAL_LINES (w
))
7535 int old_height
= WINDOW_TOTAL_LINES (w
);
7536 freeze_window_starts (f
, 1);
7537 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7538 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7540 else if (height
< WINDOW_TOTAL_LINES (w
)
7541 && (exact_p
|| BEGV
== ZV
))
7543 int old_height
= WINDOW_TOTAL_LINES (w
);
7544 freeze_window_starts (f
, 0);
7545 shrink_mini_window (w
);
7546 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7551 /* Always resize to exact size needed. */
7552 if (height
> WINDOW_TOTAL_LINES (w
))
7554 int old_height
= WINDOW_TOTAL_LINES (w
);
7555 freeze_window_starts (f
, 1);
7556 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7557 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7559 else if (height
< WINDOW_TOTAL_LINES (w
))
7561 int old_height
= WINDOW_TOTAL_LINES (w
);
7562 freeze_window_starts (f
, 0);
7563 shrink_mini_window (w
);
7567 freeze_window_starts (f
, 1);
7568 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7571 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7575 if (old_current_buffer
)
7576 set_buffer_internal (old_current_buffer
);
7579 return window_height_changed_p
;
7583 /* Value is the current message, a string, or nil if there is no
7591 if (NILP (echo_area_buffer
[0]))
7595 with_echo_area_buffer (0, 0, current_message_1
,
7596 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7598 echo_area_buffer
[0] = Qnil
;
7606 current_message_1 (a1
, a2
, a3
, a4
)
7611 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7614 *msg
= make_buffer_string (BEG
, Z
, 1);
7621 /* Push the current message on Vmessage_stack for later restauration
7622 by restore_message. Value is non-zero if the current message isn't
7623 empty. This is a relatively infrequent operation, so it's not
7624 worth optimizing. */
7630 msg
= current_message ();
7631 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7632 return STRINGP (msg
);
7636 /* Restore message display from the top of Vmessage_stack. */
7643 xassert (CONSP (Vmessage_stack
));
7644 msg
= XCAR (Vmessage_stack
);
7646 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7648 message3_nolog (msg
, 0, 0);
7652 /* Handler for record_unwind_protect calling pop_message. */
7655 pop_message_unwind (dummy
)
7662 /* Pop the top-most entry off Vmessage_stack. */
7667 xassert (CONSP (Vmessage_stack
));
7668 Vmessage_stack
= XCDR (Vmessage_stack
);
7672 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7673 exits. If the stack is not empty, we have a missing pop_message
7677 check_message_stack ()
7679 if (!NILP (Vmessage_stack
))
7684 /* Truncate to NCHARS what will be displayed in the echo area the next
7685 time we display it---but don't redisplay it now. */
7688 truncate_echo_area (nchars
)
7692 echo_area_buffer
[0] = Qnil
;
7693 /* A null message buffer means that the frame hasn't really been
7694 initialized yet. Error messages get reported properly by
7695 cmd_error, so this must be just an informative message; toss it. */
7696 else if (!noninteractive
7698 && !NILP (echo_area_buffer
[0]))
7700 struct frame
*sf
= SELECTED_FRAME ();
7701 if (FRAME_MESSAGE_BUF (sf
))
7702 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7707 /* Helper function for truncate_echo_area. Truncate the current
7708 message to at most NCHARS characters. */
7711 truncate_message_1 (nchars
, a2
, a3
, a4
)
7716 if (BEG
+ nchars
< Z
)
7717 del_range (BEG
+ nchars
, Z
);
7719 echo_area_buffer
[0] = Qnil
;
7724 /* Set the current message to a substring of S or STRING.
7726 If STRING is a Lisp string, set the message to the first NBYTES
7727 bytes from STRING. NBYTES zero means use the whole string. If
7728 STRING is multibyte, the message will be displayed multibyte.
7730 If S is not null, set the message to the first LEN bytes of S. LEN
7731 zero means use the whole string. MULTIBYTE_P non-zero means S is
7732 multibyte. Display the message multibyte in that case. */
7735 set_message (s
, string
, nbytes
, multibyte_p
)
7738 int nbytes
, multibyte_p
;
7740 message_enable_multibyte
7741 = ((s
&& multibyte_p
)
7742 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7744 with_echo_area_buffer (0, -1, set_message_1
,
7745 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7746 message_buf_print
= 0;
7747 help_echo_showing_p
= 0;
7751 /* Helper function for set_message. Arguments have the same meaning
7752 as there, with A1 corresponding to S and A2 corresponding to STRING
7753 This function is called with the echo area buffer being
7757 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7760 EMACS_INT nbytes
, multibyte_p
;
7762 const char *s
= (const char *) a1
;
7763 Lisp_Object string
= a2
;
7767 /* Change multibyteness of the echo buffer appropriately. */
7768 if (message_enable_multibyte
7769 != !NILP (current_buffer
->enable_multibyte_characters
))
7770 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7772 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7774 /* Insert new message at BEG. */
7775 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7777 if (STRINGP (string
))
7782 nbytes
= SBYTES (string
);
7783 nchars
= string_byte_to_char (string
, nbytes
);
7785 /* This function takes care of single/multibyte conversion. We
7786 just have to ensure that the echo area buffer has the right
7787 setting of enable_multibyte_characters. */
7788 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7793 nbytes
= strlen (s
);
7795 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7797 /* Convert from multi-byte to single-byte. */
7799 unsigned char work
[1];
7801 /* Convert a multibyte string to single-byte. */
7802 for (i
= 0; i
< nbytes
; i
+= n
)
7804 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7805 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7807 : multibyte_char_to_unibyte (c
, Qnil
));
7808 insert_1_both (work
, 1, 1, 1, 0, 0);
7811 else if (!multibyte_p
7812 && !NILP (current_buffer
->enable_multibyte_characters
))
7814 /* Convert from single-byte to multi-byte. */
7816 const unsigned char *msg
= (const unsigned char *) s
;
7817 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7819 /* Convert a single-byte string to multibyte. */
7820 for (i
= 0; i
< nbytes
; i
++)
7822 c
= unibyte_char_to_multibyte (msg
[i
]);
7823 n
= CHAR_STRING (c
, str
);
7824 insert_1_both (str
, 1, n
, 1, 0, 0);
7828 insert_1 (s
, nbytes
, 1, 0, 0);
7835 /* Clear messages. CURRENT_P non-zero means clear the current
7836 message. LAST_DISPLAYED_P non-zero means clear the message
7840 clear_message (current_p
, last_displayed_p
)
7841 int current_p
, last_displayed_p
;
7845 echo_area_buffer
[0] = Qnil
;
7846 message_cleared_p
= 1;
7849 if (last_displayed_p
)
7850 echo_area_buffer
[1] = Qnil
;
7852 message_buf_print
= 0;
7855 /* Clear garbaged frames.
7857 This function is used where the old redisplay called
7858 redraw_garbaged_frames which in turn called redraw_frame which in
7859 turn called clear_frame. The call to clear_frame was a source of
7860 flickering. I believe a clear_frame is not necessary. It should
7861 suffice in the new redisplay to invalidate all current matrices,
7862 and ensure a complete redisplay of all windows. */
7865 clear_garbaged_frames ()
7869 Lisp_Object tail
, frame
;
7870 int changed_count
= 0;
7872 FOR_EACH_FRAME (tail
, frame
)
7874 struct frame
*f
= XFRAME (frame
);
7876 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7880 Fredraw_frame (frame
);
7881 f
->force_flush_display_p
= 1;
7883 clear_current_matrices (f
);
7892 ++windows_or_buffers_changed
;
7897 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7898 is non-zero update selected_frame. Value is non-zero if the
7899 mini-windows height has been changed. */
7902 echo_area_display (update_frame_p
)
7905 Lisp_Object mini_window
;
7908 int window_height_changed_p
= 0;
7909 struct frame
*sf
= SELECTED_FRAME ();
7911 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7912 w
= XWINDOW (mini_window
);
7913 f
= XFRAME (WINDOW_FRAME (w
));
7915 /* Don't display if frame is invisible or not yet initialized. */
7916 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7919 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7921 #ifdef HAVE_WINDOW_SYSTEM
7922 /* When Emacs starts, selected_frame may be a visible terminal
7923 frame, even if we run under a window system. If we let this
7924 through, a message would be displayed on the terminal. */
7925 if (EQ (selected_frame
, Vterminal_frame
)
7926 && !NILP (Vwindow_system
))
7928 #endif /* HAVE_WINDOW_SYSTEM */
7931 /* Redraw garbaged frames. */
7933 clear_garbaged_frames ();
7935 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7937 echo_area_window
= mini_window
;
7938 window_height_changed_p
= display_echo_area (w
);
7939 w
->must_be_updated_p
= 1;
7941 /* Update the display, unless called from redisplay_internal.
7942 Also don't update the screen during redisplay itself. The
7943 update will happen at the end of redisplay, and an update
7944 here could cause confusion. */
7945 if (update_frame_p
&& !redisplaying_p
)
7949 /* If the display update has been interrupted by pending
7950 input, update mode lines in the frame. Due to the
7951 pending input, it might have been that redisplay hasn't
7952 been called, so that mode lines above the echo area are
7953 garbaged. This looks odd, so we prevent it here. */
7954 if (!display_completed
)
7955 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7957 if (window_height_changed_p
7958 /* Don't do this if Emacs is shutting down. Redisplay
7959 needs to run hooks. */
7960 && !NILP (Vrun_hooks
))
7962 /* Must update other windows. Likewise as in other
7963 cases, don't let this update be interrupted by
7965 int count
= SPECPDL_INDEX ();
7966 specbind (Qredisplay_dont_pause
, Qt
);
7967 windows_or_buffers_changed
= 1;
7968 redisplay_internal (0);
7969 unbind_to (count
, Qnil
);
7971 else if (FRAME_WINDOW_P (f
) && n
== 0)
7973 /* Window configuration is the same as before.
7974 Can do with a display update of the echo area,
7975 unless we displayed some mode lines. */
7976 update_single_window (w
, 1);
7977 rif
->flush_display (f
);
7980 update_frame (f
, 1, 1);
7982 /* If cursor is in the echo area, make sure that the next
7983 redisplay displays the minibuffer, so that the cursor will
7984 be replaced with what the minibuffer wants. */
7985 if (cursor_in_echo_area
)
7986 ++windows_or_buffers_changed
;
7989 else if (!EQ (mini_window
, selected_window
))
7990 windows_or_buffers_changed
++;
7992 /* Last displayed message is now the current message. */
7993 echo_area_buffer
[1] = echo_area_buffer
[0];
7995 /* Prevent redisplay optimization in redisplay_internal by resetting
7996 this_line_start_pos. This is done because the mini-buffer now
7997 displays the message instead of its buffer text. */
7998 if (EQ (mini_window
, selected_window
))
7999 CHARPOS (this_line_start_pos
) = 0;
8001 return window_height_changed_p
;
8006 /***********************************************************************
8008 ***********************************************************************/
8011 /* The frame title buffering code is also used by Fformat_mode_line.
8012 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
8014 /* A buffer for constructing frame titles in it; allocated from the
8015 heap in init_xdisp and resized as needed in store_frame_title_char. */
8017 static char *frame_title_buf
;
8019 /* The buffer's end, and a current output position in it. */
8021 static char *frame_title_buf_end
;
8022 static char *frame_title_ptr
;
8025 /* Store a single character C for the frame title in frame_title_buf.
8026 Re-allocate frame_title_buf if necessary. */
8030 store_frame_title_char (char c
)
8032 store_frame_title_char (c
)
8036 /* If output position has reached the end of the allocated buffer,
8037 double the buffer's size. */
8038 if (frame_title_ptr
== frame_title_buf_end
)
8040 int len
= frame_title_ptr
- frame_title_buf
;
8041 int new_size
= 2 * len
* sizeof *frame_title_buf
;
8042 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
8043 frame_title_buf_end
= frame_title_buf
+ new_size
;
8044 frame_title_ptr
= frame_title_buf
+ len
;
8047 *frame_title_ptr
++ = c
;
8051 /* Store part of a frame title in frame_title_buf, beginning at
8052 frame_title_ptr. STR is the string to store. Do not copy
8053 characters that yield more columns than PRECISION; PRECISION <= 0
8054 means copy the whole string. Pad with spaces until FIELD_WIDTH
8055 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8056 pad. Called from display_mode_element when it is used to build a
8060 store_frame_title (str
, field_width
, precision
)
8061 const unsigned char *str
;
8062 int field_width
, precision
;
8067 /* Copy at most PRECISION chars from STR. */
8068 nbytes
= strlen (str
);
8069 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8071 store_frame_title_char (*str
++);
8073 /* Fill up with spaces until FIELD_WIDTH reached. */
8074 while (field_width
> 0
8077 store_frame_title_char (' ');
8084 #ifdef HAVE_WINDOW_SYSTEM
8086 /* Set the title of FRAME, if it has changed. The title format is
8087 Vicon_title_format if FRAME is iconified, otherwise it is
8088 frame_title_format. */
8091 x_consider_frame_title (frame
)
8094 struct frame
*f
= XFRAME (frame
);
8096 if (FRAME_WINDOW_P (f
)
8097 || FRAME_MINIBUF_ONLY_P (f
)
8098 || f
->explicit_name
)
8100 /* Do we have more than one visible frame on this X display? */
8103 struct buffer
*obuf
;
8107 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8109 Lisp_Object other_frame
= XCAR (tail
);
8110 struct frame
*tf
= XFRAME (other_frame
);
8113 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8114 && !FRAME_MINIBUF_ONLY_P (tf
)
8115 && !EQ (other_frame
, tip_frame
)
8116 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8120 /* Set global variable indicating that multiple frames exist. */
8121 multiple_frames
= CONSP (tail
);
8123 /* Switch to the buffer of selected window of the frame. Set up
8124 frame_title_ptr so that display_mode_element will output into it;
8125 then display the title. */
8126 obuf
= current_buffer
;
8127 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8128 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8129 frame_title_ptr
= frame_title_buf
;
8130 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8131 NULL
, DEFAULT_FACE_ID
);
8132 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8133 len
= frame_title_ptr
- frame_title_buf
;
8134 frame_title_ptr
= NULL
;
8135 set_buffer_internal_1 (obuf
);
8137 /* Set the title only if it's changed. This avoids consing in
8138 the common case where it hasn't. (If it turns out that we've
8139 already wasted too much time by walking through the list with
8140 display_mode_element, then we might need to optimize at a
8141 higher level than this.) */
8142 if (! STRINGP (f
->name
)
8143 || SBYTES (f
->name
) != len
8144 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
8145 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
8149 #endif /* not HAVE_WINDOW_SYSTEM */
8154 /***********************************************************************
8156 ***********************************************************************/
8159 /* Prepare for redisplay by updating menu-bar item lists when
8160 appropriate. This can call eval. */
8163 prepare_menu_bars ()
8166 struct gcpro gcpro1
, gcpro2
;
8168 Lisp_Object tooltip_frame
;
8170 #ifdef HAVE_WINDOW_SYSTEM
8171 tooltip_frame
= tip_frame
;
8173 tooltip_frame
= Qnil
;
8176 /* Update all frame titles based on their buffer names, etc. We do
8177 this before the menu bars so that the buffer-menu will show the
8178 up-to-date frame titles. */
8179 #ifdef HAVE_WINDOW_SYSTEM
8180 if (windows_or_buffers_changed
|| update_mode_lines
)
8182 Lisp_Object tail
, frame
;
8184 FOR_EACH_FRAME (tail
, frame
)
8187 if (!EQ (frame
, tooltip_frame
)
8188 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8189 x_consider_frame_title (frame
);
8192 #endif /* HAVE_WINDOW_SYSTEM */
8194 /* Update the menu bar item lists, if appropriate. This has to be
8195 done before any actual redisplay or generation of display lines. */
8196 all_windows
= (update_mode_lines
8197 || buffer_shared
> 1
8198 || windows_or_buffers_changed
);
8201 Lisp_Object tail
, frame
;
8202 int count
= SPECPDL_INDEX ();
8204 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8206 FOR_EACH_FRAME (tail
, frame
)
8210 /* Ignore tooltip frame. */
8211 if (EQ (frame
, tooltip_frame
))
8214 /* If a window on this frame changed size, report that to
8215 the user and clear the size-change flag. */
8216 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8218 Lisp_Object functions
;
8220 /* Clear flag first in case we get an error below. */
8221 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8222 functions
= Vwindow_size_change_functions
;
8223 GCPRO2 (tail
, functions
);
8225 while (CONSP (functions
))
8227 call1 (XCAR (functions
), frame
);
8228 functions
= XCDR (functions
);
8234 update_menu_bar (f
, 0);
8235 #ifdef HAVE_WINDOW_SYSTEM
8236 update_tool_bar (f
, 0);
8241 unbind_to (count
, Qnil
);
8245 struct frame
*sf
= SELECTED_FRAME ();
8246 update_menu_bar (sf
, 1);
8247 #ifdef HAVE_WINDOW_SYSTEM
8248 update_tool_bar (sf
, 1);
8252 /* Motif needs this. See comment in xmenu.c. Turn it off when
8253 pending_menu_activation is not defined. */
8254 #ifdef USE_X_TOOLKIT
8255 pending_menu_activation
= 0;
8260 /* Update the menu bar item list for frame F. This has to be done
8261 before we start to fill in any display lines, because it can call
8264 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8267 update_menu_bar (f
, save_match_data
)
8269 int save_match_data
;
8272 register struct window
*w
;
8274 /* If called recursively during a menu update, do nothing. This can
8275 happen when, for instance, an activate-menubar-hook causes a
8277 if (inhibit_menubar_update
)
8280 window
= FRAME_SELECTED_WINDOW (f
);
8281 w
= XWINDOW (window
);
8283 #if 0 /* The if statement below this if statement used to include the
8284 condition !NILP (w->update_mode_line), rather than using
8285 update_mode_lines directly, and this if statement may have
8286 been added to make that condition work. Now the if
8287 statement below matches its comment, this isn't needed. */
8288 if (update_mode_lines
)
8289 w
->update_mode_line
= Qt
;
8292 if (FRAME_WINDOW_P (f
)
8294 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8295 || defined (USE_GTK)
8296 FRAME_EXTERNAL_MENU_BAR (f
)
8298 FRAME_MENU_BAR_LINES (f
) > 0
8300 : FRAME_MENU_BAR_LINES (f
) > 0)
8302 /* If the user has switched buffers or windows, we need to
8303 recompute to reflect the new bindings. But we'll
8304 recompute when update_mode_lines is set too; that means
8305 that people can use force-mode-line-update to request
8306 that the menu bar be recomputed. The adverse effect on
8307 the rest of the redisplay algorithm is about the same as
8308 windows_or_buffers_changed anyway. */
8309 if (windows_or_buffers_changed
8310 /* This used to test w->update_mode_line, but we believe
8311 there is no need to recompute the menu in that case. */
8312 || update_mode_lines
8313 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8314 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8315 != !NILP (w
->last_had_star
))
8316 || ((!NILP (Vtransient_mark_mode
)
8317 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8318 != !NILP (w
->region_showing
)))
8320 struct buffer
*prev
= current_buffer
;
8321 int count
= SPECPDL_INDEX ();
8323 specbind (Qinhibit_menubar_update
, Qt
);
8325 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8326 if (save_match_data
)
8327 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8328 if (NILP (Voverriding_local_map_menu_flag
))
8330 specbind (Qoverriding_terminal_local_map
, Qnil
);
8331 specbind (Qoverriding_local_map
, Qnil
);
8334 /* Run the Lucid hook. */
8335 safe_run_hooks (Qactivate_menubar_hook
);
8337 /* If it has changed current-menubar from previous value,
8338 really recompute the menu-bar from the value. */
8339 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8340 call0 (Qrecompute_lucid_menubar
);
8342 safe_run_hooks (Qmenu_bar_update_hook
);
8343 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8345 /* Redisplay the menu bar in case we changed it. */
8346 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8347 || defined (USE_GTK)
8348 if (FRAME_WINDOW_P (f
)
8349 #if defined (MAC_OS)
8350 /* All frames on Mac OS share the same menubar. So only the
8351 selected frame should be allowed to set it. */
8352 && f
== SELECTED_FRAME ()
8355 set_frame_menubar (f
, 0, 0);
8357 /* On a terminal screen, the menu bar is an ordinary screen
8358 line, and this makes it get updated. */
8359 w
->update_mode_line
= Qt
;
8360 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8361 /* In the non-toolkit version, the menu bar is an ordinary screen
8362 line, and this makes it get updated. */
8363 w
->update_mode_line
= Qt
;
8364 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8366 unbind_to (count
, Qnil
);
8367 set_buffer_internal_1 (prev
);
8374 /***********************************************************************
8376 ***********************************************************************/
8378 #ifdef HAVE_WINDOW_SYSTEM
8381 Nominal cursor position -- where to draw output.
8382 HPOS and VPOS are window relative glyph matrix coordinates.
8383 X and Y are window relative pixel coordinates. */
8385 struct cursor_pos output_cursor
;
8389 Set the global variable output_cursor to CURSOR. All cursor
8390 positions are relative to updated_window. */
8393 set_output_cursor (cursor
)
8394 struct cursor_pos
*cursor
;
8396 output_cursor
.hpos
= cursor
->hpos
;
8397 output_cursor
.vpos
= cursor
->vpos
;
8398 output_cursor
.x
= cursor
->x
;
8399 output_cursor
.y
= cursor
->y
;
8404 Set a nominal cursor position.
8406 HPOS and VPOS are column/row positions in a window glyph matrix. X
8407 and Y are window text area relative pixel positions.
8409 If this is done during an update, updated_window will contain the
8410 window that is being updated and the position is the future output
8411 cursor position for that window. If updated_window is null, use
8412 selected_window and display the cursor at the given position. */
8415 x_cursor_to (vpos
, hpos
, y
, x
)
8416 int vpos
, hpos
, y
, x
;
8420 /* If updated_window is not set, work on selected_window. */
8424 w
= XWINDOW (selected_window
);
8426 /* Set the output cursor. */
8427 output_cursor
.hpos
= hpos
;
8428 output_cursor
.vpos
= vpos
;
8429 output_cursor
.x
= x
;
8430 output_cursor
.y
= y
;
8432 /* If not called as part of an update, really display the cursor.
8433 This will also set the cursor position of W. */
8434 if (updated_window
== NULL
)
8437 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8438 if (rif
->flush_display_optional
)
8439 rif
->flush_display_optional (SELECTED_FRAME ());
8444 #endif /* HAVE_WINDOW_SYSTEM */
8447 /***********************************************************************
8449 ***********************************************************************/
8451 #ifdef HAVE_WINDOW_SYSTEM
8453 /* Where the mouse was last time we reported a mouse event. */
8455 FRAME_PTR last_mouse_frame
;
8457 /* Tool-bar item index of the item on which a mouse button was pressed
8460 int last_tool_bar_item
;
8463 /* Update the tool-bar item list for frame F. This has to be done
8464 before we start to fill in any display lines. Called from
8465 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8466 and restore it here. */
8469 update_tool_bar (f
, save_match_data
)
8471 int save_match_data
;
8474 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8476 int do_update
= WINDOWP (f
->tool_bar_window
)
8477 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8485 window
= FRAME_SELECTED_WINDOW (f
);
8486 w
= XWINDOW (window
);
8488 /* If the user has switched buffers or windows, we need to
8489 recompute to reflect the new bindings. But we'll
8490 recompute when update_mode_lines is set too; that means
8491 that people can use force-mode-line-update to request
8492 that the menu bar be recomputed. The adverse effect on
8493 the rest of the redisplay algorithm is about the same as
8494 windows_or_buffers_changed anyway. */
8495 if (windows_or_buffers_changed
8496 || !NILP (w
->update_mode_line
)
8497 || update_mode_lines
8498 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8499 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8500 != !NILP (w
->last_had_star
))
8501 || ((!NILP (Vtransient_mark_mode
)
8502 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8503 != !NILP (w
->region_showing
)))
8505 struct buffer
*prev
= current_buffer
;
8506 int count
= SPECPDL_INDEX ();
8507 Lisp_Object new_tool_bar
;
8509 struct gcpro gcpro1
;
8511 /* Set current_buffer to the buffer of the selected
8512 window of the frame, so that we get the right local
8514 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8516 /* Save match data, if we must. */
8517 if (save_match_data
)
8518 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8520 /* Make sure that we don't accidentally use bogus keymaps. */
8521 if (NILP (Voverriding_local_map_menu_flag
))
8523 specbind (Qoverriding_terminal_local_map
, Qnil
);
8524 specbind (Qoverriding_local_map
, Qnil
);
8527 GCPRO1 (new_tool_bar
);
8529 /* Build desired tool-bar items from keymaps. */
8530 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
8533 /* Redisplay the tool-bar if we changed it. */
8534 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
8536 /* Redisplay that happens asynchronously due to an expose event
8537 may access f->tool_bar_items. Make sure we update both
8538 variables within BLOCK_INPUT so no such event interrupts. */
8540 f
->tool_bar_items
= new_tool_bar
;
8541 f
->n_tool_bar_items
= new_n_tool_bar
;
8542 w
->update_mode_line
= Qt
;
8548 unbind_to (count
, Qnil
);
8549 set_buffer_internal_1 (prev
);
8555 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8556 F's desired tool-bar contents. F->tool_bar_items must have
8557 been set up previously by calling prepare_menu_bars. */
8560 build_desired_tool_bar_string (f
)
8563 int i
, size
, size_needed
;
8564 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8565 Lisp_Object image
, plist
, props
;
8567 image
= plist
= props
= Qnil
;
8568 GCPRO3 (image
, plist
, props
);
8570 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8571 Otherwise, make a new string. */
8573 /* The size of the string we might be able to reuse. */
8574 size
= (STRINGP (f
->desired_tool_bar_string
)
8575 ? SCHARS (f
->desired_tool_bar_string
)
8578 /* We need one space in the string for each image. */
8579 size_needed
= f
->n_tool_bar_items
;
8581 /* Reuse f->desired_tool_bar_string, if possible. */
8582 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8583 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8587 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8588 Fremove_text_properties (make_number (0), make_number (size
),
8589 props
, f
->desired_tool_bar_string
);
8592 /* Put a `display' property on the string for the images to display,
8593 put a `menu_item' property on tool-bar items with a value that
8594 is the index of the item in F's tool-bar item vector. */
8595 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8597 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8599 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8600 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8601 int hmargin
, vmargin
, relief
, idx
, end
;
8602 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8604 /* If image is a vector, choose the image according to the
8606 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8607 if (VECTORP (image
))
8611 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8612 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8615 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8616 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8618 xassert (ASIZE (image
) >= idx
);
8619 image
= AREF (image
, idx
);
8624 /* Ignore invalid image specifications. */
8625 if (!valid_image_p (image
))
8628 /* Display the tool-bar button pressed, or depressed. */
8629 plist
= Fcopy_sequence (XCDR (image
));
8631 /* Compute margin and relief to draw. */
8632 relief
= (tool_bar_button_relief
>= 0
8633 ? tool_bar_button_relief
8634 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8635 hmargin
= vmargin
= relief
;
8637 if (INTEGERP (Vtool_bar_button_margin
)
8638 && XINT (Vtool_bar_button_margin
) > 0)
8640 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8641 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8643 else if (CONSP (Vtool_bar_button_margin
))
8645 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8646 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8647 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8649 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8650 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8651 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8654 if (auto_raise_tool_bar_buttons_p
)
8656 /* Add a `:relief' property to the image spec if the item is
8660 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8667 /* If image is selected, display it pressed, i.e. with a
8668 negative relief. If it's not selected, display it with a
8670 plist
= Fplist_put (plist
, QCrelief
,
8672 ? make_number (-relief
)
8673 : make_number (relief
)));
8678 /* Put a margin around the image. */
8679 if (hmargin
|| vmargin
)
8681 if (hmargin
== vmargin
)
8682 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8684 plist
= Fplist_put (plist
, QCmargin
,
8685 Fcons (make_number (hmargin
),
8686 make_number (vmargin
)));
8689 /* If button is not enabled, and we don't have special images
8690 for the disabled state, make the image appear disabled by
8691 applying an appropriate algorithm to it. */
8692 if (!enabled_p
&& idx
< 0)
8693 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8695 /* Put a `display' text property on the string for the image to
8696 display. Put a `menu-item' property on the string that gives
8697 the start of this item's properties in the tool-bar items
8699 image
= Fcons (Qimage
, plist
);
8700 props
= list4 (Qdisplay
, image
,
8701 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8703 /* Let the last image hide all remaining spaces in the tool bar
8704 string. The string can be longer than needed when we reuse a
8706 if (i
+ 1 == f
->n_tool_bar_items
)
8707 end
= SCHARS (f
->desired_tool_bar_string
);
8710 Fadd_text_properties (make_number (i
), make_number (end
),
8711 props
, f
->desired_tool_bar_string
);
8719 /* Display one line of the tool-bar of frame IT->f. */
8722 display_tool_bar_line (it
)
8725 struct glyph_row
*row
= it
->glyph_row
;
8726 int max_x
= it
->last_visible_x
;
8729 prepare_desired_row (row
);
8730 row
->y
= it
->current_y
;
8732 /* Note that this isn't made use of if the face hasn't a box,
8733 so there's no need to check the face here. */
8734 it
->start_of_box_run_p
= 1;
8736 while (it
->current_x
< max_x
)
8738 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8740 /* Get the next display element. */
8741 if (!get_next_display_element (it
))
8744 /* Produce glyphs. */
8745 x_before
= it
->current_x
;
8746 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8747 PRODUCE_GLYPHS (it
);
8749 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8754 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8756 if (x
+ glyph
->pixel_width
> max_x
)
8758 /* Glyph doesn't fit on line. */
8759 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8765 x
+= glyph
->pixel_width
;
8769 /* Stop at line ends. */
8770 if (ITERATOR_AT_END_OF_LINE_P (it
))
8773 set_iterator_to_next (it
, 1);
8778 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8779 extend_face_to_end_of_line (it
);
8780 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8781 last
->right_box_line_p
= 1;
8782 if (last
== row
->glyphs
[TEXT_AREA
])
8783 last
->left_box_line_p
= 1;
8784 compute_line_metrics (it
);
8786 /* If line is empty, make it occupy the rest of the tool-bar. */
8787 if (!row
->displays_text_p
)
8789 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8790 row
->ascent
= row
->phys_ascent
= 0;
8791 row
->extra_line_spacing
= 0;
8794 row
->full_width_p
= 1;
8795 row
->continued_p
= 0;
8796 row
->truncated_on_left_p
= 0;
8797 row
->truncated_on_right_p
= 0;
8799 it
->current_x
= it
->hpos
= 0;
8800 it
->current_y
+= row
->height
;
8806 /* Value is the number of screen lines needed to make all tool-bar
8807 items of frame F visible. */
8810 tool_bar_lines_needed (f
)
8813 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8816 /* Initialize an iterator for iteration over
8817 F->desired_tool_bar_string in the tool-bar window of frame F. */
8818 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8819 it
.first_visible_x
= 0;
8820 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8821 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8823 while (!ITERATOR_AT_END_P (&it
))
8825 it
.glyph_row
= w
->desired_matrix
->rows
;
8826 clear_glyph_row (it
.glyph_row
);
8827 display_tool_bar_line (&it
);
8830 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8834 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8836 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8845 frame
= selected_frame
;
8847 CHECK_FRAME (frame
);
8850 if (WINDOWP (f
->tool_bar_window
)
8851 || (w
= XWINDOW (f
->tool_bar_window
),
8852 WINDOW_TOTAL_LINES (w
) > 0))
8854 update_tool_bar (f
, 1);
8855 if (f
->n_tool_bar_items
)
8857 build_desired_tool_bar_string (f
);
8858 nlines
= tool_bar_lines_needed (f
);
8862 return make_number (nlines
);
8866 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8867 height should be changed. */
8870 redisplay_tool_bar (f
)
8875 struct glyph_row
*row
;
8876 int change_height_p
= 0;
8879 if (FRAME_EXTERNAL_TOOL_BAR (f
))
8880 update_frame_tool_bar (f
);
8884 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8885 do anything. This means you must start with tool-bar-lines
8886 non-zero to get the auto-sizing effect. Or in other words, you
8887 can turn off tool-bars by specifying tool-bar-lines zero. */
8888 if (!WINDOWP (f
->tool_bar_window
)
8889 || (w
= XWINDOW (f
->tool_bar_window
),
8890 WINDOW_TOTAL_LINES (w
) == 0))
8893 /* Set up an iterator for the tool-bar window. */
8894 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8895 it
.first_visible_x
= 0;
8896 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8899 /* Build a string that represents the contents of the tool-bar. */
8900 build_desired_tool_bar_string (f
);
8901 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8903 /* Display as many lines as needed to display all tool-bar items. */
8904 while (it
.current_y
< it
.last_visible_y
)
8905 display_tool_bar_line (&it
);
8907 /* It doesn't make much sense to try scrolling in the tool-bar
8908 window, so don't do it. */
8909 w
->desired_matrix
->no_scrolling_p
= 1;
8910 w
->must_be_updated_p
= 1;
8912 if (auto_resize_tool_bars_p
)
8916 /* If we couldn't display everything, change the tool-bar's
8918 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8919 change_height_p
= 1;
8921 /* If there are blank lines at the end, except for a partially
8922 visible blank line at the end that is smaller than
8923 FRAME_LINE_HEIGHT, change the tool-bar's height. */
8924 row
= it
.glyph_row
- 1;
8925 if (!row
->displays_text_p
8926 && row
->height
>= FRAME_LINE_HEIGHT (f
))
8927 change_height_p
= 1;
8929 /* If row displays tool-bar items, but is partially visible,
8930 change the tool-bar's height. */
8931 if (row
->displays_text_p
8932 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8933 change_height_p
= 1;
8935 /* Resize windows as needed by changing the `tool-bar-lines'
8938 && (nlines
= tool_bar_lines_needed (f
),
8939 nlines
!= WINDOW_TOTAL_LINES (w
)))
8941 extern Lisp_Object Qtool_bar_lines
;
8943 int old_height
= WINDOW_TOTAL_LINES (w
);
8945 XSETFRAME (frame
, f
);
8946 clear_glyph_matrix (w
->desired_matrix
);
8947 Fmodify_frame_parameters (frame
,
8948 Fcons (Fcons (Qtool_bar_lines
,
8949 make_number (nlines
)),
8951 if (WINDOW_TOTAL_LINES (w
) != old_height
)
8952 fonts_changed_p
= 1;
8956 return change_height_p
;
8960 /* Get information about the tool-bar item which is displayed in GLYPH
8961 on frame F. Return in *PROP_IDX the index where tool-bar item
8962 properties start in F->tool_bar_items. Value is zero if
8963 GLYPH doesn't display a tool-bar item. */
8966 tool_bar_item_info (f
, glyph
, prop_idx
)
8968 struct glyph
*glyph
;
8975 /* This function can be called asynchronously, which means we must
8976 exclude any possibility that Fget_text_property signals an
8978 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8979 charpos
= max (0, charpos
);
8981 /* Get the text property `menu-item' at pos. The value of that
8982 property is the start index of this item's properties in
8983 F->tool_bar_items. */
8984 prop
= Fget_text_property (make_number (charpos
),
8985 Qmenu_item
, f
->current_tool_bar_string
);
8986 if (INTEGERP (prop
))
8988 *prop_idx
= XINT (prop
);
8998 /* Get information about the tool-bar item at position X/Y on frame F.
8999 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9000 the current matrix of the tool-bar window of F, or NULL if not
9001 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9002 item in F->tool_bar_items. Value is
9004 -1 if X/Y is not on a tool-bar item
9005 0 if X/Y is on the same item that was highlighted before.
9009 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9012 struct glyph
**glyph
;
9013 int *hpos
, *vpos
, *prop_idx
;
9015 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9016 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9019 /* Find the glyph under X/Y. */
9020 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9024 /* Get the start of this tool-bar item's properties in
9025 f->tool_bar_items. */
9026 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9029 /* Is mouse on the highlighted item? */
9030 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9031 && *vpos
>= dpyinfo
->mouse_face_beg_row
9032 && *vpos
<= dpyinfo
->mouse_face_end_row
9033 && (*vpos
> dpyinfo
->mouse_face_beg_row
9034 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9035 && (*vpos
< dpyinfo
->mouse_face_end_row
9036 || *hpos
< dpyinfo
->mouse_face_end_col
9037 || dpyinfo
->mouse_face_past_end
))
9045 Handle mouse button event on the tool-bar of frame F, at
9046 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9047 0 for button release. MODIFIERS is event modifiers for button
9051 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9054 unsigned int modifiers
;
9056 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9057 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9058 int hpos
, vpos
, prop_idx
;
9059 struct glyph
*glyph
;
9060 Lisp_Object enabled_p
;
9062 /* If not on the highlighted tool-bar item, return. */
9063 frame_to_window_pixel_xy (w
, &x
, &y
);
9064 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9067 /* If item is disabled, do nothing. */
9068 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9069 if (NILP (enabled_p
))
9074 /* Show item in pressed state. */
9075 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9076 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9077 last_tool_bar_item
= prop_idx
;
9081 Lisp_Object key
, frame
;
9082 struct input_event event
;
9085 /* Show item in released state. */
9086 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9087 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9089 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9091 XSETFRAME (frame
, f
);
9092 event
.kind
= TOOL_BAR_EVENT
;
9093 event
.frame_or_window
= frame
;
9095 kbd_buffer_store_event (&event
);
9097 event
.kind
= TOOL_BAR_EVENT
;
9098 event
.frame_or_window
= frame
;
9100 event
.modifiers
= modifiers
;
9101 kbd_buffer_store_event (&event
);
9102 last_tool_bar_item
= -1;
9107 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9108 tool-bar window-relative coordinates X/Y. Called from
9109 note_mouse_highlight. */
9112 note_tool_bar_highlight (f
, x
, y
)
9116 Lisp_Object window
= f
->tool_bar_window
;
9117 struct window
*w
= XWINDOW (window
);
9118 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9120 struct glyph
*glyph
;
9121 struct glyph_row
*row
;
9123 Lisp_Object enabled_p
;
9125 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9126 int mouse_down_p
, rc
;
9128 /* Function note_mouse_highlight is called with negative x(y
9129 values when mouse moves outside of the frame. */
9130 if (x
<= 0 || y
<= 0)
9132 clear_mouse_face (dpyinfo
);
9136 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9139 /* Not on tool-bar item. */
9140 clear_mouse_face (dpyinfo
);
9144 /* On same tool-bar item as before. */
9147 clear_mouse_face (dpyinfo
);
9149 /* Mouse is down, but on different tool-bar item? */
9150 mouse_down_p
= (dpyinfo
->grabbed
9151 && f
== last_mouse_frame
9152 && FRAME_LIVE_P (f
));
9154 && last_tool_bar_item
!= prop_idx
)
9157 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9158 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9160 /* If tool-bar item is not enabled, don't highlight it. */
9161 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9162 if (!NILP (enabled_p
))
9164 /* Compute the x-position of the glyph. In front and past the
9165 image is a space. We include this in the highlighted area. */
9166 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9167 for (i
= x
= 0; i
< hpos
; ++i
)
9168 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9170 /* Record this as the current active region. */
9171 dpyinfo
->mouse_face_beg_col
= hpos
;
9172 dpyinfo
->mouse_face_beg_row
= vpos
;
9173 dpyinfo
->mouse_face_beg_x
= x
;
9174 dpyinfo
->mouse_face_beg_y
= row
->y
;
9175 dpyinfo
->mouse_face_past_end
= 0;
9177 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9178 dpyinfo
->mouse_face_end_row
= vpos
;
9179 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9180 dpyinfo
->mouse_face_end_y
= row
->y
;
9181 dpyinfo
->mouse_face_window
= window
;
9182 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9184 /* Display it as active. */
9185 show_mouse_face (dpyinfo
, draw
);
9186 dpyinfo
->mouse_face_image_state
= draw
;
9191 /* Set help_echo_string to a help string to display for this tool-bar item.
9192 XTread_socket does the rest. */
9193 help_echo_object
= help_echo_window
= Qnil
;
9195 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9196 if (NILP (help_echo_string
))
9197 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9200 #endif /* HAVE_WINDOW_SYSTEM */
9204 /************************************************************************
9205 Horizontal scrolling
9206 ************************************************************************/
9208 static int hscroll_window_tree
P_ ((Lisp_Object
));
9209 static int hscroll_windows
P_ ((Lisp_Object
));
9211 /* For all leaf windows in the window tree rooted at WINDOW, set their
9212 hscroll value so that PT is (i) visible in the window, and (ii) so
9213 that it is not within a certain margin at the window's left and
9214 right border. Value is non-zero if any window's hscroll has been
9218 hscroll_window_tree (window
)
9221 int hscrolled_p
= 0;
9222 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9223 int hscroll_step_abs
= 0;
9224 double hscroll_step_rel
= 0;
9226 if (hscroll_relative_p
)
9228 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9229 if (hscroll_step_rel
< 0)
9231 hscroll_relative_p
= 0;
9232 hscroll_step_abs
= 0;
9235 else if (INTEGERP (Vhscroll_step
))
9237 hscroll_step_abs
= XINT (Vhscroll_step
);
9238 if (hscroll_step_abs
< 0)
9239 hscroll_step_abs
= 0;
9242 hscroll_step_abs
= 0;
9244 while (WINDOWP (window
))
9246 struct window
*w
= XWINDOW (window
);
9248 if (WINDOWP (w
->hchild
))
9249 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9250 else if (WINDOWP (w
->vchild
))
9251 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9252 else if (w
->cursor
.vpos
>= 0)
9255 int text_area_width
;
9256 struct glyph_row
*current_cursor_row
9257 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9258 struct glyph_row
*desired_cursor_row
9259 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9260 struct glyph_row
*cursor_row
9261 = (desired_cursor_row
->enabled_p
9262 ? desired_cursor_row
9263 : current_cursor_row
);
9265 text_area_width
= window_box_width (w
, TEXT_AREA
);
9267 /* Scroll when cursor is inside this scroll margin. */
9268 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9270 if ((XFASTINT (w
->hscroll
)
9271 && w
->cursor
.x
<= h_margin
)
9272 || (cursor_row
->enabled_p
9273 && cursor_row
->truncated_on_right_p
9274 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9278 struct buffer
*saved_current_buffer
;
9282 /* Find point in a display of infinite width. */
9283 saved_current_buffer
= current_buffer
;
9284 current_buffer
= XBUFFER (w
->buffer
);
9286 if (w
== XWINDOW (selected_window
))
9287 pt
= BUF_PT (current_buffer
);
9290 pt
= marker_position (w
->pointm
);
9291 pt
= max (BEGV
, pt
);
9295 /* Move iterator to pt starting at cursor_row->start in
9296 a line with infinite width. */
9297 init_to_row_start (&it
, w
, cursor_row
);
9298 it
.last_visible_x
= INFINITY
;
9299 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9300 current_buffer
= saved_current_buffer
;
9302 /* Position cursor in window. */
9303 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9304 hscroll
= max (0, (it
.current_x
9305 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9306 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9307 : (text_area_width
/ 2))))
9308 / FRAME_COLUMN_WIDTH (it
.f
);
9309 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9311 if (hscroll_relative_p
)
9312 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9315 wanted_x
= text_area_width
9316 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9319 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9323 if (hscroll_relative_p
)
9324 wanted_x
= text_area_width
* hscroll_step_rel
9327 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9330 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9332 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9334 /* Don't call Fset_window_hscroll if value hasn't
9335 changed because it will prevent redisplay
9337 if (XFASTINT (w
->hscroll
) != hscroll
)
9339 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9340 w
->hscroll
= make_number (hscroll
);
9349 /* Value is non-zero if hscroll of any leaf window has been changed. */
9354 /* Set hscroll so that cursor is visible and not inside horizontal
9355 scroll margins for all windows in the tree rooted at WINDOW. See
9356 also hscroll_window_tree above. Value is non-zero if any window's
9357 hscroll has been changed. If it has, desired matrices on the frame
9358 of WINDOW are cleared. */
9361 hscroll_windows (window
)
9366 if (automatic_hscrolling_p
)
9368 hscrolled_p
= hscroll_window_tree (window
);
9370 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9379 /************************************************************************
9381 ************************************************************************/
9383 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9384 to a non-zero value. This is sometimes handy to have in a debugger
9389 /* First and last unchanged row for try_window_id. */
9391 int debug_first_unchanged_at_end_vpos
;
9392 int debug_last_unchanged_at_beg_vpos
;
9394 /* Delta vpos and y. */
9396 int debug_dvpos
, debug_dy
;
9398 /* Delta in characters and bytes for try_window_id. */
9400 int debug_delta
, debug_delta_bytes
;
9402 /* Values of window_end_pos and window_end_vpos at the end of
9405 EMACS_INT debug_end_pos
, debug_end_vpos
;
9407 /* Append a string to W->desired_matrix->method. FMT is a printf
9408 format string. A1...A9 are a supplement for a variable-length
9409 argument list. If trace_redisplay_p is non-zero also printf the
9410 resulting string to stderr. */
9413 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9416 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9419 char *method
= w
->desired_matrix
->method
;
9420 int len
= strlen (method
);
9421 int size
= sizeof w
->desired_matrix
->method
;
9422 int remaining
= size
- len
- 1;
9424 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9425 if (len
&& remaining
)
9431 strncpy (method
+ len
, buffer
, remaining
);
9433 if (trace_redisplay_p
)
9434 fprintf (stderr
, "%p (%s): %s\n",
9436 ((BUFFERP (w
->buffer
)
9437 && STRINGP (XBUFFER (w
->buffer
)->name
))
9438 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9443 #endif /* GLYPH_DEBUG */
9446 /* Value is non-zero if all changes in window W, which displays
9447 current_buffer, are in the text between START and END. START is a
9448 buffer position, END is given as a distance from Z. Used in
9449 redisplay_internal for display optimization. */
9452 text_outside_line_unchanged_p (w
, start
, end
)
9456 int unchanged_p
= 1;
9458 /* If text or overlays have changed, see where. */
9459 if (XFASTINT (w
->last_modified
) < MODIFF
9460 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9462 /* Gap in the line? */
9463 if (GPT
< start
|| Z
- GPT
< end
)
9466 /* Changes start in front of the line, or end after it? */
9468 && (BEG_UNCHANGED
< start
- 1
9469 || END_UNCHANGED
< end
))
9472 /* If selective display, can't optimize if changes start at the
9473 beginning of the line. */
9475 && INTEGERP (current_buffer
->selective_display
)
9476 && XINT (current_buffer
->selective_display
) > 0
9477 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9480 /* If there are overlays at the start or end of the line, these
9481 may have overlay strings with newlines in them. A change at
9482 START, for instance, may actually concern the display of such
9483 overlay strings as well, and they are displayed on different
9484 lines. So, quickly rule out this case. (For the future, it
9485 might be desirable to implement something more telling than
9486 just BEG/END_UNCHANGED.) */
9489 if (BEG
+ BEG_UNCHANGED
== start
9490 && overlay_touches_p (start
))
9492 if (END_UNCHANGED
== end
9493 && overlay_touches_p (Z
- end
))
9502 /* Do a frame update, taking possible shortcuts into account. This is
9503 the main external entry point for redisplay.
9505 If the last redisplay displayed an echo area message and that message
9506 is no longer requested, we clear the echo area or bring back the
9507 mini-buffer if that is in use. */
9512 redisplay_internal (0);
9517 overlay_arrow_string_or_property (var
, pbitmap
)
9521 Lisp_Object pstr
= Fget (var
, Qoverlay_arrow_string
);
9527 if (bitmap
= Fget (var
, Qoverlay_arrow_bitmap
), INTEGERP (bitmap
))
9528 *pbitmap
= XINT (bitmap
);
9533 return Voverlay_arrow_string
;
9536 /* Return 1 if there are any overlay-arrows in current_buffer. */
9538 overlay_arrow_in_current_buffer_p ()
9542 for (vlist
= Voverlay_arrow_variable_list
;
9544 vlist
= XCDR (vlist
))
9546 Lisp_Object var
= XCAR (vlist
);
9551 val
= find_symbol_value (var
);
9553 && current_buffer
== XMARKER (val
)->buffer
)
9560 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9564 overlay_arrows_changed_p ()
9568 for (vlist
= Voverlay_arrow_variable_list
;
9570 vlist
= XCDR (vlist
))
9572 Lisp_Object var
= XCAR (vlist
);
9573 Lisp_Object val
, pstr
;
9577 val
= find_symbol_value (var
);
9580 if (! EQ (COERCE_MARKER (val
),
9581 Fget (var
, Qlast_arrow_position
))
9582 || ! (pstr
= overlay_arrow_string_or_property (var
, 0),
9583 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9589 /* Mark overlay arrows to be updated on next redisplay. */
9592 update_overlay_arrows (up_to_date
)
9597 for (vlist
= Voverlay_arrow_variable_list
;
9599 vlist
= XCDR (vlist
))
9601 Lisp_Object var
= XCAR (vlist
);
9608 Lisp_Object val
= find_symbol_value (var
);
9609 Fput (var
, Qlast_arrow_position
,
9610 COERCE_MARKER (val
));
9611 Fput (var
, Qlast_arrow_string
,
9612 overlay_arrow_string_or_property (var
, 0));
9614 else if (up_to_date
< 0
9615 || !NILP (Fget (var
, Qlast_arrow_position
)))
9617 Fput (var
, Qlast_arrow_position
, Qt
);
9618 Fput (var
, Qlast_arrow_string
, Qt
);
9624 /* Return overlay arrow string to display at row.
9625 Return t if display as bitmap in left fringe.
9626 Return nil if no overlay arrow. */
9629 overlay_arrow_at_row (it
, row
, pbitmap
)
9631 struct glyph_row
*row
;
9636 for (vlist
= Voverlay_arrow_variable_list
;
9638 vlist
= XCDR (vlist
))
9640 Lisp_Object var
= XCAR (vlist
);
9646 val
= find_symbol_value (var
);
9649 && current_buffer
== XMARKER (val
)->buffer
9650 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9652 val
= overlay_arrow_string_or_property (var
, pbitmap
);
9653 if (FRAME_WINDOW_P (it
->f
)
9654 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
9666 /* Return 1 if point moved out of or into a composition. Otherwise
9667 return 0. PREV_BUF and PREV_PT are the last point buffer and
9668 position. BUF and PT are the current point buffer and position. */
9671 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9672 struct buffer
*prev_buf
, *buf
;
9679 XSETBUFFER (buffer
, buf
);
9680 /* Check a composition at the last point if point moved within the
9682 if (prev_buf
== buf
)
9685 /* Point didn't move. */
9688 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9689 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9690 && COMPOSITION_VALID_P (start
, end
, prop
)
9691 && start
< prev_pt
&& end
> prev_pt
)
9692 /* The last point was within the composition. Return 1 iff
9693 point moved out of the composition. */
9694 return (pt
<= start
|| pt
>= end
);
9697 /* Check a composition at the current point. */
9698 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9699 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9700 && COMPOSITION_VALID_P (start
, end
, prop
)
9701 && start
< pt
&& end
> pt
);
9705 /* Reconsider the setting of B->clip_changed which is displayed
9709 reconsider_clip_changes (w
, b
)
9714 && !NILP (w
->window_end_valid
)
9715 && w
->current_matrix
->buffer
== b
9716 && w
->current_matrix
->zv
== BUF_ZV (b
)
9717 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9718 b
->clip_changed
= 0;
9720 /* If display wasn't paused, and W is not a tool bar window, see if
9721 point has been moved into or out of a composition. In that case,
9722 we set b->clip_changed to 1 to force updating the screen. If
9723 b->clip_changed has already been set to 1, we can skip this
9725 if (!b
->clip_changed
9726 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9730 if (w
== XWINDOW (selected_window
))
9731 pt
= BUF_PT (current_buffer
);
9733 pt
= marker_position (w
->pointm
);
9735 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9736 || pt
!= XINT (w
->last_point
))
9737 && check_point_in_composition (w
->current_matrix
->buffer
,
9738 XINT (w
->last_point
),
9739 XBUFFER (w
->buffer
), pt
))
9740 b
->clip_changed
= 1;
9745 /* Select FRAME to forward the values of frame-local variables into C
9746 variables so that the redisplay routines can access those values
9750 select_frame_for_redisplay (frame
)
9753 Lisp_Object tail
, sym
, val
;
9754 Lisp_Object old
= selected_frame
;
9756 selected_frame
= frame
;
9758 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9759 if (CONSP (XCAR (tail
))
9760 && (sym
= XCAR (XCAR (tail
)),
9762 && (sym
= indirect_variable (sym
),
9763 val
= SYMBOL_VALUE (sym
),
9764 (BUFFER_LOCAL_VALUEP (val
)
9765 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9766 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9767 Fsymbol_value (sym
);
9769 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
9770 if (CONSP (XCAR (tail
))
9771 && (sym
= XCAR (XCAR (tail
)),
9773 && (sym
= indirect_variable (sym
),
9774 val
= SYMBOL_VALUE (sym
),
9775 (BUFFER_LOCAL_VALUEP (val
)
9776 || SOME_BUFFER_LOCAL_VALUEP (val
)))
9777 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
9778 Fsymbol_value (sym
);
9782 #define STOP_POLLING \
9783 do { if (! polling_stopped_here) stop_polling (); \
9784 polling_stopped_here = 1; } while (0)
9786 #define RESUME_POLLING \
9787 do { if (polling_stopped_here) start_polling (); \
9788 polling_stopped_here = 0; } while (0)
9791 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9792 response to any user action; therefore, we should preserve the echo
9793 area. (Actually, our caller does that job.) Perhaps in the future
9794 avoid recentering windows if it is not necessary; currently that
9795 causes some problems. */
9798 redisplay_internal (preserve_echo_area
)
9799 int preserve_echo_area
;
9801 struct window
*w
= XWINDOW (selected_window
);
9802 struct frame
*f
= XFRAME (w
->frame
);
9804 int must_finish
= 0;
9805 struct text_pos tlbufpos
, tlendpos
;
9806 int number_of_visible_frames
;
9808 struct frame
*sf
= SELECTED_FRAME ();
9809 int polling_stopped_here
= 0;
9811 /* Non-zero means redisplay has to consider all windows on all
9812 frames. Zero means, only selected_window is considered. */
9813 int consider_all_windows_p
;
9815 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9817 /* No redisplay if running in batch mode or frame is not yet fully
9818 initialized, or redisplay is explicitly turned off by setting
9819 Vinhibit_redisplay. */
9821 || !NILP (Vinhibit_redisplay
)
9822 || !f
->glyphs_initialized_p
)
9825 /* The flag redisplay_performed_directly_p is set by
9826 direct_output_for_insert when it already did the whole screen
9827 update necessary. */
9828 if (redisplay_performed_directly_p
)
9830 redisplay_performed_directly_p
= 0;
9831 if (!hscroll_windows (selected_window
))
9835 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9836 if (popup_activated ())
9840 /* I don't think this happens but let's be paranoid. */
9844 /* Record a function that resets redisplaying_p to its old value
9845 when we leave this function. */
9846 count
= SPECPDL_INDEX ();
9847 record_unwind_protect (unwind_redisplay
,
9848 Fcons (make_number (redisplaying_p
), selected_frame
));
9850 specbind (Qinhibit_free_realized_faces
, Qnil
);
9854 reconsider_clip_changes (w
, current_buffer
);
9856 /* If new fonts have been loaded that make a glyph matrix adjustment
9857 necessary, do it. */
9858 if (fonts_changed_p
)
9860 adjust_glyphs (NULL
);
9861 ++windows_or_buffers_changed
;
9862 fonts_changed_p
= 0;
9865 /* If face_change_count is non-zero, init_iterator will free all
9866 realized faces, which includes the faces referenced from current
9867 matrices. So, we can't reuse current matrices in this case. */
9868 if (face_change_count
)
9869 ++windows_or_buffers_changed
;
9871 if (! FRAME_WINDOW_P (sf
)
9872 && previous_terminal_frame
!= sf
)
9874 /* Since frames on an ASCII terminal share the same display
9875 area, displaying a different frame means redisplay the whole
9877 windows_or_buffers_changed
++;
9878 SET_FRAME_GARBAGED (sf
);
9879 XSETFRAME (Vterminal_frame
, sf
);
9881 previous_terminal_frame
= sf
;
9883 /* Set the visible flags for all frames. Do this before checking
9884 for resized or garbaged frames; they want to know if their frames
9885 are visible. See the comment in frame.h for
9886 FRAME_SAMPLE_VISIBILITY. */
9888 Lisp_Object tail
, frame
;
9890 number_of_visible_frames
= 0;
9892 FOR_EACH_FRAME (tail
, frame
)
9894 struct frame
*f
= XFRAME (frame
);
9896 FRAME_SAMPLE_VISIBILITY (f
);
9897 if (FRAME_VISIBLE_P (f
))
9898 ++number_of_visible_frames
;
9899 clear_desired_matrices (f
);
9903 /* Notice any pending interrupt request to change frame size. */
9904 do_pending_window_change (1);
9906 /* Clear frames marked as garbaged. */
9908 clear_garbaged_frames ();
9910 /* Build menubar and tool-bar items. */
9911 prepare_menu_bars ();
9913 if (windows_or_buffers_changed
)
9914 update_mode_lines
++;
9916 /* Detect case that we need to write or remove a star in the mode line. */
9917 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
9919 w
->update_mode_line
= Qt
;
9920 if (buffer_shared
> 1)
9921 update_mode_lines
++;
9924 /* If %c is in the mode line, update it if needed. */
9925 if (!NILP (w
->column_number_displayed
)
9926 /* This alternative quickly identifies a common case
9927 where no change is needed. */
9928 && !(PT
== XFASTINT (w
->last_point
)
9929 && XFASTINT (w
->last_modified
) >= MODIFF
9930 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9931 && (XFASTINT (w
->column_number_displayed
)
9932 != (int) current_column ())) /* iftc */
9933 w
->update_mode_line
= Qt
;
9935 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
9937 /* The variable buffer_shared is set in redisplay_window and
9938 indicates that we redisplay a buffer in different windows. See
9940 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
9941 || cursor_type_changed
);
9943 /* If specs for an arrow have changed, do thorough redisplay
9944 to ensure we remove any arrow that should no longer exist. */
9945 if (overlay_arrows_changed_p ())
9946 consider_all_windows_p
= windows_or_buffers_changed
= 1;
9948 /* Normally the message* functions will have already displayed and
9949 updated the echo area, but the frame may have been trashed, or
9950 the update may have been preempted, so display the echo area
9951 again here. Checking message_cleared_p captures the case that
9952 the echo area should be cleared. */
9953 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
9954 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
9955 || (message_cleared_p
9956 && minibuf_level
== 0
9957 /* If the mini-window is currently selected, this means the
9958 echo-area doesn't show through. */
9959 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
9961 int window_height_changed_p
= echo_area_display (0);
9964 /* If we don't display the current message, don't clear the
9965 message_cleared_p flag, because, if we did, we wouldn't clear
9966 the echo area in the next redisplay which doesn't preserve
9968 if (!display_last_displayed_message_p
)
9969 message_cleared_p
= 0;
9971 if (fonts_changed_p
)
9973 else if (window_height_changed_p
)
9975 consider_all_windows_p
= 1;
9976 ++update_mode_lines
;
9977 ++windows_or_buffers_changed
;
9979 /* If window configuration was changed, frames may have been
9980 marked garbaged. Clear them or we will experience
9981 surprises wrt scrolling. */
9983 clear_garbaged_frames ();
9986 else if (EQ (selected_window
, minibuf_window
)
9987 && (current_buffer
->clip_changed
9988 || XFASTINT (w
->last_modified
) < MODIFF
9989 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9990 && resize_mini_window (w
, 0))
9992 /* Resized active mini-window to fit the size of what it is
9993 showing if its contents might have changed. */
9995 consider_all_windows_p
= 1;
9996 ++windows_or_buffers_changed
;
9997 ++update_mode_lines
;
9999 /* If window configuration was changed, frames may have been
10000 marked garbaged. Clear them or we will experience
10001 surprises wrt scrolling. */
10002 if (frame_garbaged
)
10003 clear_garbaged_frames ();
10007 /* If showing the region, and mark has changed, we must redisplay
10008 the whole window. The assignment to this_line_start_pos prevents
10009 the optimization directly below this if-statement. */
10010 if (((!NILP (Vtransient_mark_mode
)
10011 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10012 != !NILP (w
->region_showing
))
10013 || (!NILP (w
->region_showing
)
10014 && !EQ (w
->region_showing
,
10015 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10016 CHARPOS (this_line_start_pos
) = 0;
10018 /* Optimize the case that only the line containing the cursor in the
10019 selected window has changed. Variables starting with this_ are
10020 set in display_line and record information about the line
10021 containing the cursor. */
10022 tlbufpos
= this_line_start_pos
;
10023 tlendpos
= this_line_end_pos
;
10024 if (!consider_all_windows_p
10025 && CHARPOS (tlbufpos
) > 0
10026 && NILP (w
->update_mode_line
)
10027 && !current_buffer
->clip_changed
10028 && !current_buffer
->prevent_redisplay_optimizations_p
10029 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10030 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10031 /* Make sure recorded data applies to current buffer, etc. */
10032 && this_line_buffer
== current_buffer
10033 && current_buffer
== XBUFFER (w
->buffer
)
10034 && NILP (w
->force_start
)
10035 && NILP (w
->optional_new_start
)
10036 /* Point must be on the line that we have info recorded about. */
10037 && PT
>= CHARPOS (tlbufpos
)
10038 && PT
<= Z
- CHARPOS (tlendpos
)
10039 /* All text outside that line, including its final newline,
10040 must be unchanged */
10041 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10042 CHARPOS (tlendpos
)))
10044 if (CHARPOS (tlbufpos
) > BEGV
10045 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10046 && (CHARPOS (tlbufpos
) == ZV
10047 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10048 /* Former continuation line has disappeared by becoming empty */
10050 else if (XFASTINT (w
->last_modified
) < MODIFF
10051 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10052 || MINI_WINDOW_P (w
))
10054 /* We have to handle the case of continuation around a
10055 wide-column character (See the comment in indent.c around
10058 For instance, in the following case:
10060 -------- Insert --------
10061 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10062 J_I_ ==> J_I_ `^^' are cursors.
10066 As we have to redraw the line above, we should goto cancel. */
10069 int line_height_before
= this_line_pixel_height
;
10071 /* Note that start_display will handle the case that the
10072 line starting at tlbufpos is a continuation lines. */
10073 start_display (&it
, w
, tlbufpos
);
10075 /* Implementation note: It this still necessary? */
10076 if (it
.current_x
!= this_line_start_x
)
10079 TRACE ((stderr
, "trying display optimization 1\n"));
10080 w
->cursor
.vpos
= -1;
10081 overlay_arrow_seen
= 0;
10082 it
.vpos
= this_line_vpos
;
10083 it
.current_y
= this_line_y
;
10084 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10085 display_line (&it
);
10087 /* If line contains point, is not continued,
10088 and ends at same distance from eob as before, we win */
10089 if (w
->cursor
.vpos
>= 0
10090 /* Line is not continued, otherwise this_line_start_pos
10091 would have been set to 0 in display_line. */
10092 && CHARPOS (this_line_start_pos
)
10093 /* Line ends as before. */
10094 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10095 /* Line has same height as before. Otherwise other lines
10096 would have to be shifted up or down. */
10097 && this_line_pixel_height
== line_height_before
)
10099 /* If this is not the window's last line, we must adjust
10100 the charstarts of the lines below. */
10101 if (it
.current_y
< it
.last_visible_y
)
10103 struct glyph_row
*row
10104 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10105 int delta
, delta_bytes
;
10107 if (Z
- CHARPOS (tlendpos
) == ZV
)
10109 /* This line ends at end of (accessible part of)
10110 buffer. There is no newline to count. */
10112 - CHARPOS (tlendpos
)
10113 - MATRIX_ROW_START_CHARPOS (row
));
10114 delta_bytes
= (Z_BYTE
10115 - BYTEPOS (tlendpos
)
10116 - MATRIX_ROW_START_BYTEPOS (row
));
10120 /* This line ends in a newline. Must take
10121 account of the newline and the rest of the
10122 text that follows. */
10124 - CHARPOS (tlendpos
)
10125 - MATRIX_ROW_START_CHARPOS (row
));
10126 delta_bytes
= (Z_BYTE
10127 - BYTEPOS (tlendpos
)
10128 - MATRIX_ROW_START_BYTEPOS (row
));
10131 increment_matrix_positions (w
->current_matrix
,
10132 this_line_vpos
+ 1,
10133 w
->current_matrix
->nrows
,
10134 delta
, delta_bytes
);
10137 /* If this row displays text now but previously didn't,
10138 or vice versa, w->window_end_vpos may have to be
10140 if ((it
.glyph_row
- 1)->displays_text_p
)
10142 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10143 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10145 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10146 && this_line_vpos
> 0)
10147 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10148 w
->window_end_valid
= Qnil
;
10150 /* Update hint: No need to try to scroll in update_window. */
10151 w
->desired_matrix
->no_scrolling_p
= 1;
10154 *w
->desired_matrix
->method
= 0;
10155 debug_method_add (w
, "optimization 1");
10157 #ifdef HAVE_WINDOW_SYSTEM
10158 update_window_fringes (w
, 0);
10165 else if (/* Cursor position hasn't changed. */
10166 PT
== XFASTINT (w
->last_point
)
10167 /* Make sure the cursor was last displayed
10168 in this window. Otherwise we have to reposition it. */
10169 && 0 <= w
->cursor
.vpos
10170 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10174 do_pending_window_change (1);
10176 /* We used to always goto end_of_redisplay here, but this
10177 isn't enough if we have a blinking cursor. */
10178 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10179 goto end_of_redisplay
;
10183 /* If highlighting the region, or if the cursor is in the echo area,
10184 then we can't just move the cursor. */
10185 else if (! (!NILP (Vtransient_mark_mode
)
10186 && !NILP (current_buffer
->mark_active
))
10187 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10188 || highlight_nonselected_windows
)
10189 && NILP (w
->region_showing
)
10190 && NILP (Vshow_trailing_whitespace
)
10191 && !cursor_in_echo_area
)
10194 struct glyph_row
*row
;
10196 /* Skip from tlbufpos to PT and see where it is. Note that
10197 PT may be in invisible text. If so, we will end at the
10198 next visible position. */
10199 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10200 NULL
, DEFAULT_FACE_ID
);
10201 it
.current_x
= this_line_start_x
;
10202 it
.current_y
= this_line_y
;
10203 it
.vpos
= this_line_vpos
;
10205 /* The call to move_it_to stops in front of PT, but
10206 moves over before-strings. */
10207 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10209 if (it
.vpos
== this_line_vpos
10210 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10213 xassert (this_line_vpos
== it
.vpos
);
10214 xassert (this_line_y
== it
.current_y
);
10215 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10217 *w
->desired_matrix
->method
= 0;
10218 debug_method_add (w
, "optimization 3");
10227 /* Text changed drastically or point moved off of line. */
10228 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10231 CHARPOS (this_line_start_pos
) = 0;
10232 consider_all_windows_p
|= buffer_shared
> 1;
10233 ++clear_face_cache_count
;
10236 /* Build desired matrices, and update the display. If
10237 consider_all_windows_p is non-zero, do it for all windows on all
10238 frames. Otherwise do it for selected_window, only. */
10240 if (consider_all_windows_p
)
10242 Lisp_Object tail
, frame
;
10243 int i
, n
= 0, size
= 50;
10244 struct frame
**updated
10245 = (struct frame
**) alloca (size
* sizeof *updated
);
10247 /* Clear the face cache eventually. */
10248 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10250 clear_face_cache (0);
10251 clear_face_cache_count
= 0;
10254 /* Recompute # windows showing selected buffer. This will be
10255 incremented each time such a window is displayed. */
10258 FOR_EACH_FRAME (tail
, frame
)
10260 struct frame
*f
= XFRAME (frame
);
10262 if (FRAME_WINDOW_P (f
) || f
== sf
)
10264 if (! EQ (frame
, selected_frame
))
10265 /* Select the frame, for the sake of frame-local
10267 select_frame_for_redisplay (frame
);
10269 #ifdef HAVE_WINDOW_SYSTEM
10270 if (clear_face_cache_count
% 50 == 0
10271 && FRAME_WINDOW_P (f
))
10272 clear_image_cache (f
, 0);
10273 #endif /* HAVE_WINDOW_SYSTEM */
10275 /* Mark all the scroll bars to be removed; we'll redeem
10276 the ones we want when we redisplay their windows. */
10277 if (condemn_scroll_bars_hook
)
10278 condemn_scroll_bars_hook (f
);
10280 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10281 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10283 /* Any scroll bars which redisplay_windows should have
10284 nuked should now go away. */
10285 if (judge_scroll_bars_hook
)
10286 judge_scroll_bars_hook (f
);
10288 /* If fonts changed, display again. */
10289 /* ??? rms: I suspect it is a mistake to jump all the way
10290 back to retry here. It should just retry this frame. */
10291 if (fonts_changed_p
)
10294 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10296 /* See if we have to hscroll. */
10297 if (hscroll_windows (f
->root_window
))
10300 /* Prevent various kinds of signals during display
10301 update. stdio is not robust about handling
10302 signals, which can cause an apparent I/O
10304 if (interrupt_input
)
10305 unrequest_sigio ();
10308 /* Update the display. */
10309 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10310 pause
|= update_frame (f
, 0, 0);
10311 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10318 int nbytes
= size
* sizeof *updated
;
10319 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10320 bcopy (updated
, p
, nbytes
);
10331 /* Do the mark_window_display_accurate after all windows have
10332 been redisplayed because this call resets flags in buffers
10333 which are needed for proper redisplay. */
10334 for (i
= 0; i
< n
; ++i
)
10336 struct frame
*f
= updated
[i
];
10337 mark_window_display_accurate (f
->root_window
, 1);
10338 if (frame_up_to_date_hook
)
10339 frame_up_to_date_hook (f
);
10343 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10345 Lisp_Object mini_window
;
10346 struct frame
*mini_frame
;
10348 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10349 /* Use list_of_error, not Qerror, so that
10350 we catch only errors and don't run the debugger. */
10351 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10353 redisplay_window_error
);
10355 /* Compare desired and current matrices, perform output. */
10358 /* If fonts changed, display again. */
10359 if (fonts_changed_p
)
10362 /* Prevent various kinds of signals during display update.
10363 stdio is not robust about handling signals,
10364 which can cause an apparent I/O error. */
10365 if (interrupt_input
)
10366 unrequest_sigio ();
10369 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10371 if (hscroll_windows (selected_window
))
10374 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10375 pause
= update_frame (sf
, 0, 0);
10378 /* We may have called echo_area_display at the top of this
10379 function. If the echo area is on another frame, that may
10380 have put text on a frame other than the selected one, so the
10381 above call to update_frame would not have caught it. Catch
10383 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10384 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10386 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10388 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10389 pause
|= update_frame (mini_frame
, 0, 0);
10390 if (!pause
&& hscroll_windows (mini_window
))
10395 /* If display was paused because of pending input, make sure we do a
10396 thorough update the next time. */
10399 /* Prevent the optimization at the beginning of
10400 redisplay_internal that tries a single-line update of the
10401 line containing the cursor in the selected window. */
10402 CHARPOS (this_line_start_pos
) = 0;
10404 /* Let the overlay arrow be updated the next time. */
10405 update_overlay_arrows (0);
10407 /* If we pause after scrolling, some rows in the current
10408 matrices of some windows are not valid. */
10409 if (!WINDOW_FULL_WIDTH_P (w
)
10410 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10411 update_mode_lines
= 1;
10415 if (!consider_all_windows_p
)
10417 /* This has already been done above if
10418 consider_all_windows_p is set. */
10419 mark_window_display_accurate_1 (w
, 1);
10421 /* Say overlay arrows are up to date. */
10422 update_overlay_arrows (1);
10424 if (frame_up_to_date_hook
!= 0)
10425 frame_up_to_date_hook (sf
);
10428 update_mode_lines
= 0;
10429 windows_or_buffers_changed
= 0;
10430 cursor_type_changed
= 0;
10433 /* Start SIGIO interrupts coming again. Having them off during the
10434 code above makes it less likely one will discard output, but not
10435 impossible, since there might be stuff in the system buffer here.
10436 But it is much hairier to try to do anything about that. */
10437 if (interrupt_input
)
10441 /* If a frame has become visible which was not before, redisplay
10442 again, so that we display it. Expose events for such a frame
10443 (which it gets when becoming visible) don't call the parts of
10444 redisplay constructing glyphs, so simply exposing a frame won't
10445 display anything in this case. So, we have to display these
10446 frames here explicitly. */
10449 Lisp_Object tail
, frame
;
10452 FOR_EACH_FRAME (tail
, frame
)
10454 int this_is_visible
= 0;
10456 if (XFRAME (frame
)->visible
)
10457 this_is_visible
= 1;
10458 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10459 if (XFRAME (frame
)->visible
)
10460 this_is_visible
= 1;
10462 if (this_is_visible
)
10466 if (new_count
!= number_of_visible_frames
)
10467 windows_or_buffers_changed
++;
10470 /* Change frame size now if a change is pending. */
10471 do_pending_window_change (1);
10473 /* If we just did a pending size change, or have additional
10474 visible frames, redisplay again. */
10475 if (windows_or_buffers_changed
&& !pause
)
10479 unbind_to (count
, Qnil
);
10484 /* Redisplay, but leave alone any recent echo area message unless
10485 another message has been requested in its place.
10487 This is useful in situations where you need to redisplay but no
10488 user action has occurred, making it inappropriate for the message
10489 area to be cleared. See tracking_off and
10490 wait_reading_process_output for examples of these situations.
10492 FROM_WHERE is an integer saying from where this function was
10493 called. This is useful for debugging. */
10496 redisplay_preserve_echo_area (from_where
)
10499 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10501 if (!NILP (echo_area_buffer
[1]))
10503 /* We have a previously displayed message, but no current
10504 message. Redisplay the previous message. */
10505 display_last_displayed_message_p
= 1;
10506 redisplay_internal (1);
10507 display_last_displayed_message_p
= 0;
10510 redisplay_internal (1);
10512 if (rif
!= NULL
&& rif
->flush_display_optional
)
10513 rif
->flush_display_optional (NULL
);
10517 /* Function registered with record_unwind_protect in
10518 redisplay_internal. Reset redisplaying_p to the value it had
10519 before redisplay_internal was called, and clear
10520 prevent_freeing_realized_faces_p. It also selects the previously
10524 unwind_redisplay (val
)
10527 Lisp_Object old_redisplaying_p
, old_frame
;
10529 old_redisplaying_p
= XCAR (val
);
10530 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10531 old_frame
= XCDR (val
);
10532 if (! EQ (old_frame
, selected_frame
))
10533 select_frame_for_redisplay (old_frame
);
10538 /* Mark the display of window W as accurate or inaccurate. If
10539 ACCURATE_P is non-zero mark display of W as accurate. If
10540 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10541 redisplay_internal is called. */
10544 mark_window_display_accurate_1 (w
, accurate_p
)
10548 if (BUFFERP (w
->buffer
))
10550 struct buffer
*b
= XBUFFER (w
->buffer
);
10553 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10554 w
->last_overlay_modified
10555 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10557 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10561 b
->clip_changed
= 0;
10562 b
->prevent_redisplay_optimizations_p
= 0;
10564 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10565 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10566 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10567 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10569 w
->current_matrix
->buffer
= b
;
10570 w
->current_matrix
->begv
= BUF_BEGV (b
);
10571 w
->current_matrix
->zv
= BUF_ZV (b
);
10573 w
->last_cursor
= w
->cursor
;
10574 w
->last_cursor_off_p
= w
->cursor_off_p
;
10576 if (w
== XWINDOW (selected_window
))
10577 w
->last_point
= make_number (BUF_PT (b
));
10579 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10585 w
->window_end_valid
= w
->buffer
;
10586 #if 0 /* This is incorrect with variable-height lines. */
10587 xassert (XINT (w
->window_end_vpos
)
10588 < (WINDOW_TOTAL_LINES (w
)
10589 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10591 w
->update_mode_line
= Qnil
;
10596 /* Mark the display of windows in the window tree rooted at WINDOW as
10597 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10598 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10599 be redisplayed the next time redisplay_internal is called. */
10602 mark_window_display_accurate (window
, accurate_p
)
10603 Lisp_Object window
;
10608 for (; !NILP (window
); window
= w
->next
)
10610 w
= XWINDOW (window
);
10611 mark_window_display_accurate_1 (w
, accurate_p
);
10613 if (!NILP (w
->vchild
))
10614 mark_window_display_accurate (w
->vchild
, accurate_p
);
10615 if (!NILP (w
->hchild
))
10616 mark_window_display_accurate (w
->hchild
, accurate_p
);
10621 update_overlay_arrows (1);
10625 /* Force a thorough redisplay the next time by setting
10626 last_arrow_position and last_arrow_string to t, which is
10627 unequal to any useful value of Voverlay_arrow_... */
10628 update_overlay_arrows (-1);
10633 /* Return value in display table DP (Lisp_Char_Table *) for character
10634 C. Since a display table doesn't have any parent, we don't have to
10635 follow parent. Do not call this function directly but use the
10636 macro DISP_CHAR_VECTOR. */
10639 disp_char_vector (dp
, c
)
10640 struct Lisp_Char_Table
*dp
;
10646 if (SINGLE_BYTE_CHAR_P (c
))
10647 return (dp
->contents
[c
]);
10649 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10652 else if (code
[2] < 32)
10655 /* Here, the possible range of code[0] (== charset ID) is
10656 128..max_charset. Since the top level char table contains data
10657 for multibyte characters after 256th element, we must increment
10658 code[0] by 128 to get a correct index. */
10660 code
[3] = -1; /* anchor */
10662 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10664 val
= dp
->contents
[code
[i
]];
10665 if (!SUB_CHAR_TABLE_P (val
))
10666 return (NILP (val
) ? dp
->defalt
: val
);
10669 /* Here, val is a sub char table. We return the default value of
10671 return (dp
->defalt
);
10676 /***********************************************************************
10678 ***********************************************************************/
10680 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10683 redisplay_windows (window
)
10684 Lisp_Object window
;
10686 while (!NILP (window
))
10688 struct window
*w
= XWINDOW (window
);
10690 if (!NILP (w
->hchild
))
10691 redisplay_windows (w
->hchild
);
10692 else if (!NILP (w
->vchild
))
10693 redisplay_windows (w
->vchild
);
10696 displayed_buffer
= XBUFFER (w
->buffer
);
10697 /* Use list_of_error, not Qerror, so that
10698 we catch only errors and don't run the debugger. */
10699 internal_condition_case_1 (redisplay_window_0
, window
,
10701 redisplay_window_error
);
10709 redisplay_window_error ()
10711 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10716 redisplay_window_0 (window
)
10717 Lisp_Object window
;
10719 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10720 redisplay_window (window
, 0);
10725 redisplay_window_1 (window
)
10726 Lisp_Object window
;
10728 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10729 redisplay_window (window
, 1);
10734 /* Increment GLYPH until it reaches END or CONDITION fails while
10735 adding (GLYPH)->pixel_width to X. */
10737 #define SKIP_GLYPHS(glyph, end, x, condition) \
10740 (x) += (glyph)->pixel_width; \
10743 while ((glyph) < (end) && (condition))
10746 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10747 DELTA is the number of bytes by which positions recorded in ROW
10748 differ from current buffer positions. */
10751 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10753 struct glyph_row
*row
;
10754 struct glyph_matrix
*matrix
;
10755 int delta
, delta_bytes
, dy
, dvpos
;
10757 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10758 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10759 struct glyph
*cursor
= NULL
;
10760 /* The first glyph that starts a sequence of glyphs from string. */
10761 struct glyph
*string_start
;
10762 /* The X coordinate of string_start. */
10763 int string_start_x
;
10764 /* The last known character position. */
10765 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10766 /* The last known character position before string_start. */
10767 int string_before_pos
;
10770 int cursor_from_overlay_pos
= 0;
10771 int pt_old
= PT
- delta
;
10773 /* Skip over glyphs not having an object at the start of the row.
10774 These are special glyphs like truncation marks on terminal
10776 if (row
->displays_text_p
)
10778 && INTEGERP (glyph
->object
)
10779 && glyph
->charpos
< 0)
10781 x
+= glyph
->pixel_width
;
10785 string_start
= NULL
;
10787 && !INTEGERP (glyph
->object
)
10788 && (!BUFFERP (glyph
->object
)
10789 || (last_pos
= glyph
->charpos
) < pt_old
))
10791 if (! STRINGP (glyph
->object
))
10793 string_start
= NULL
;
10794 x
+= glyph
->pixel_width
;
10796 if (cursor_from_overlay_pos
10797 && last_pos
> cursor_from_overlay_pos
)
10799 cursor_from_overlay_pos
= 0;
10805 string_before_pos
= last_pos
;
10806 string_start
= glyph
;
10807 string_start_x
= x
;
10808 /* Skip all glyphs from string. */
10812 if ((cursor
== NULL
|| glyph
> cursor
)
10813 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
10814 Qcursor
, (glyph
)->object
))
10815 && (pos
= string_buffer_position (w
, glyph
->object
,
10816 string_before_pos
),
10817 (pos
== 0 /* From overlay */
10818 || pos
== pt_old
)))
10820 /* Estimate overlay buffer position from the buffer
10821 positions of the glyphs before and after the overlay.
10822 Add 1 to last_pos so that if point corresponds to the
10823 glyph right after the overlay, we still use a 'cursor'
10824 property found in that overlay. */
10825 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
10829 x
+= glyph
->pixel_width
;
10832 while (glyph
< end
&& STRINGP (glyph
->object
));
10836 if (cursor
!= NULL
)
10841 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
10843 /* Scan back over the ellipsis glyphs, decrementing positions. */
10844 while (glyph
> row
->glyphs
[TEXT_AREA
]
10845 && (glyph
- 1)->charpos
== last_pos
)
10846 glyph
--, x
-= glyph
->pixel_width
;
10847 /* That loop always goes one position too far,
10848 including the glyph before the ellipsis.
10849 So scan forward over that one. */
10850 x
+= glyph
->pixel_width
;
10853 else if (string_start
10854 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10856 /* We may have skipped over point because the previous glyphs
10857 are from string. As there's no easy way to know the
10858 character position of the current glyph, find the correct
10859 glyph on point by scanning from string_start again. */
10861 Lisp_Object string
;
10864 limit
= make_number (pt_old
+ 1);
10866 glyph
= string_start
;
10867 x
= string_start_x
;
10868 string
= glyph
->object
;
10869 pos
= string_buffer_position (w
, string
, string_before_pos
);
10870 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10871 because we always put cursor after overlay strings. */
10872 while (pos
== 0 && glyph
< end
)
10874 string
= glyph
->object
;
10875 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10877 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10880 while (glyph
< end
)
10882 pos
= XINT (Fnext_single_char_property_change
10883 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10886 /* Skip glyphs from the same string. */
10887 string
= glyph
->object
;
10888 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10889 /* Skip glyphs from an overlay. */
10891 && ! string_buffer_position (w
, glyph
->object
, pos
))
10893 string
= glyph
->object
;
10894 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10899 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10901 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10902 w
->cursor
.y
= row
->y
+ dy
;
10904 if (w
== XWINDOW (selected_window
))
10906 if (!row
->continued_p
10907 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
10910 this_line_buffer
= XBUFFER (w
->buffer
);
10912 CHARPOS (this_line_start_pos
)
10913 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
10914 BYTEPOS (this_line_start_pos
)
10915 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
10917 CHARPOS (this_line_end_pos
)
10918 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
10919 BYTEPOS (this_line_end_pos
)
10920 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
10922 this_line_y
= w
->cursor
.y
;
10923 this_line_pixel_height
= row
->height
;
10924 this_line_vpos
= w
->cursor
.vpos
;
10925 this_line_start_x
= row
->x
;
10928 CHARPOS (this_line_start_pos
) = 0;
10933 /* Run window scroll functions, if any, for WINDOW with new window
10934 start STARTP. Sets the window start of WINDOW to that position.
10936 We assume that the window's buffer is really current. */
10938 static INLINE
struct text_pos
10939 run_window_scroll_functions (window
, startp
)
10940 Lisp_Object window
;
10941 struct text_pos startp
;
10943 struct window
*w
= XWINDOW (window
);
10944 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
10946 if (current_buffer
!= XBUFFER (w
->buffer
))
10949 if (!NILP (Vwindow_scroll_functions
))
10951 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
10952 make_number (CHARPOS (startp
)));
10953 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10954 /* In case the hook functions switch buffers. */
10955 if (current_buffer
!= XBUFFER (w
->buffer
))
10956 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10963 /* Make sure the line containing the cursor is fully visible.
10964 A value of 1 means there is nothing to be done.
10965 (Either the line is fully visible, or it cannot be made so,
10966 or we cannot tell.)
10968 If FORCE_P is non-zero, return 0 even if partial visible cursor row
10969 is higher than window.
10971 A value of 0 means the caller should do scrolling
10972 as if point had gone off the screen. */
10975 make_cursor_line_fully_visible (w
, force_p
)
10979 struct glyph_matrix
*matrix
;
10980 struct glyph_row
*row
;
10983 if (!make_cursor_line_fully_visible_p
)
10986 /* It's not always possible to find the cursor, e.g, when a window
10987 is full of overlay strings. Don't do anything in that case. */
10988 if (w
->cursor
.vpos
< 0)
10991 matrix
= w
->desired_matrix
;
10992 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
10994 /* If the cursor row is not partially visible, there's nothing to do. */
10995 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
10998 /* If the row the cursor is in is taller than the window's height,
10999 it's not clear what to do, so do nothing. */
11000 window_height
= window_box_height (w
);
11001 if (row
->height
>= window_height
)
11003 if (!force_p
|| w
->vscroll
)
11009 /* This code used to try to scroll the window just enough to make
11010 the line visible. It returned 0 to say that the caller should
11011 allocate larger glyph matrices. */
11013 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11015 int dy
= row
->height
- row
->visible_height
;
11018 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11020 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11022 int dy
= - (row
->height
- row
->visible_height
);
11025 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11028 /* When we change the cursor y-position of the selected window,
11029 change this_line_y as well so that the display optimization for
11030 the cursor line of the selected window in redisplay_internal uses
11031 the correct y-position. */
11032 if (w
== XWINDOW (selected_window
))
11033 this_line_y
= w
->cursor
.y
;
11035 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11036 redisplay with larger matrices. */
11037 if (matrix
->nrows
< required_matrix_height (w
))
11039 fonts_changed_p
= 1;
11048 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11049 non-zero means only WINDOW is redisplayed in redisplay_internal.
11050 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11051 in redisplay_window to bring a partially visible line into view in
11052 the case that only the cursor has moved.
11054 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11055 last screen line's vertical height extends past the end of the screen.
11059 1 if scrolling succeeded
11061 0 if scrolling didn't find point.
11063 -1 if new fonts have been loaded so that we must interrupt
11064 redisplay, adjust glyph matrices, and try again. */
11070 SCROLLING_NEED_LARGER_MATRICES
11074 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11075 scroll_step
, temp_scroll_step
, last_line_misfit
)
11076 Lisp_Object window
;
11077 int just_this_one_p
;
11078 EMACS_INT scroll_conservatively
, scroll_step
;
11079 int temp_scroll_step
;
11080 int last_line_misfit
;
11082 struct window
*w
= XWINDOW (window
);
11083 struct frame
*f
= XFRAME (w
->frame
);
11084 struct text_pos scroll_margin_pos
;
11085 struct text_pos pos
;
11086 struct text_pos startp
;
11088 Lisp_Object window_end
;
11089 int this_scroll_margin
;
11093 int amount_to_scroll
= 0;
11094 Lisp_Object aggressive
;
11096 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11099 debug_method_add (w
, "try_scrolling");
11102 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11104 /* Compute scroll margin height in pixels. We scroll when point is
11105 within this distance from the top or bottom of the window. */
11106 if (scroll_margin
> 0)
11108 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11109 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11112 this_scroll_margin
= 0;
11114 /* Force scroll_conservatively to have a reasonable value so it doesn't
11115 cause an overflow while computing how much to scroll. */
11116 if (scroll_conservatively
)
11117 scroll_conservatively
= min (scroll_conservatively
,
11118 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11120 /* Compute how much we should try to scroll maximally to bring point
11122 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11123 scroll_max
= max (scroll_step
,
11124 max (scroll_conservatively
, temp_scroll_step
));
11125 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11126 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11127 /* We're trying to scroll because of aggressive scrolling
11128 but no scroll_step is set. Choose an arbitrary one. Maybe
11129 there should be a variable for this. */
11133 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11135 /* Decide whether we have to scroll down. Start at the window end
11136 and move this_scroll_margin up to find the position of the scroll
11138 window_end
= Fwindow_end (window
, Qt
);
11142 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11143 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11145 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11147 start_display (&it
, w
, scroll_margin_pos
);
11148 if (this_scroll_margin
)
11149 move_it_vertically_backward (&it
, this_scroll_margin
);
11150 if (extra_scroll_margin_lines
)
11151 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11152 scroll_margin_pos
= it
.current
.pos
;
11155 if (PT
>= CHARPOS (scroll_margin_pos
))
11159 /* Point is in the scroll margin at the bottom of the window, or
11160 below. Compute a new window start that makes point visible. */
11162 /* Compute the distance from the scroll margin to PT.
11163 Give up if the distance is greater than scroll_max. */
11164 start_display (&it
, w
, scroll_margin_pos
);
11166 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11167 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11169 /* To make point visible, we have to move the window start
11170 down so that the line the cursor is in is visible, which
11171 means we have to add in the height of the cursor line. */
11172 dy
= line_bottom_y (&it
) - y0
;
11174 if (dy
> scroll_max
)
11175 return SCROLLING_FAILED
;
11177 /* Move the window start down. If scrolling conservatively,
11178 move it just enough down to make point visible. If
11179 scroll_step is set, move it down by scroll_step. */
11180 start_display (&it
, w
, startp
);
11182 if (scroll_conservatively
)
11183 /* Set AMOUNT_TO_SCROLL to at least one line,
11184 and at most scroll_conservatively lines. */
11186 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11187 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11188 else if (scroll_step
|| temp_scroll_step
)
11189 amount_to_scroll
= scroll_max
;
11192 aggressive
= current_buffer
->scroll_up_aggressively
;
11193 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11194 if (NUMBERP (aggressive
))
11196 double float_amount
= XFLOATINT (aggressive
) * height
;
11197 amount_to_scroll
= float_amount
;
11198 if (amount_to_scroll
== 0 && float_amount
> 0)
11199 amount_to_scroll
= 1;
11203 if (amount_to_scroll
<= 0)
11204 return SCROLLING_FAILED
;
11206 /* If moving by amount_to_scroll leaves STARTP unchanged,
11207 move it down one screen line. */
11209 move_it_vertically (&it
, amount_to_scroll
);
11210 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11211 move_it_by_lines (&it
, 1, 1);
11212 startp
= it
.current
.pos
;
11216 /* See if point is inside the scroll margin at the top of the
11218 scroll_margin_pos
= startp
;
11219 if (this_scroll_margin
)
11221 start_display (&it
, w
, startp
);
11222 move_it_vertically (&it
, this_scroll_margin
);
11223 scroll_margin_pos
= it
.current
.pos
;
11226 if (PT
< CHARPOS (scroll_margin_pos
))
11228 /* Point is in the scroll margin at the top of the window or
11229 above what is displayed in the window. */
11232 /* Compute the vertical distance from PT to the scroll
11233 margin position. Give up if distance is greater than
11235 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11236 start_display (&it
, w
, pos
);
11238 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11239 it
.last_visible_y
, -1,
11240 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11241 dy
= it
.current_y
- y0
;
11242 if (dy
> scroll_max
)
11243 return SCROLLING_FAILED
;
11245 /* Compute new window start. */
11246 start_display (&it
, w
, startp
);
11248 if (scroll_conservatively
)
11250 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11251 else if (scroll_step
|| temp_scroll_step
)
11252 amount_to_scroll
= scroll_max
;
11255 aggressive
= current_buffer
->scroll_down_aggressively
;
11256 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11257 if (NUMBERP (aggressive
))
11259 double float_amount
= XFLOATINT (aggressive
) * height
;
11260 amount_to_scroll
= float_amount
;
11261 if (amount_to_scroll
== 0 && float_amount
> 0)
11262 amount_to_scroll
= 1;
11266 if (amount_to_scroll
<= 0)
11267 return SCROLLING_FAILED
;
11269 move_it_vertically_backward (&it
, amount_to_scroll
);
11270 startp
= it
.current
.pos
;
11274 /* Run window scroll functions. */
11275 startp
= run_window_scroll_functions (window
, startp
);
11277 /* Display the window. Give up if new fonts are loaded, or if point
11279 if (!try_window (window
, startp
))
11280 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11281 else if (w
->cursor
.vpos
< 0)
11283 clear_glyph_matrix (w
->desired_matrix
);
11284 rc
= SCROLLING_FAILED
;
11288 /* Maybe forget recorded base line for line number display. */
11289 if (!just_this_one_p
11290 || current_buffer
->clip_changed
11291 || BEG_UNCHANGED
< CHARPOS (startp
))
11292 w
->base_line_number
= Qnil
;
11294 /* If cursor ends up on a partially visible line,
11295 treat that as being off the bottom of the screen. */
11296 if (! make_cursor_line_fully_visible (w
, extra_scroll_margin_lines
<= 1))
11298 clear_glyph_matrix (w
->desired_matrix
);
11299 ++extra_scroll_margin_lines
;
11302 rc
= SCROLLING_SUCCESS
;
11309 /* Compute a suitable window start for window W if display of W starts
11310 on a continuation line. Value is non-zero if a new window start
11313 The new window start will be computed, based on W's width, starting
11314 from the start of the continued line. It is the start of the
11315 screen line with the minimum distance from the old start W->start. */
11318 compute_window_start_on_continuation_line (w
)
11321 struct text_pos pos
, start_pos
;
11322 int window_start_changed_p
= 0;
11324 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11326 /* If window start is on a continuation line... Window start may be
11327 < BEGV in case there's invisible text at the start of the
11328 buffer (M-x rmail, for example). */
11329 if (CHARPOS (start_pos
) > BEGV
11330 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11333 struct glyph_row
*row
;
11335 /* Handle the case that the window start is out of range. */
11336 if (CHARPOS (start_pos
) < BEGV
)
11337 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11338 else if (CHARPOS (start_pos
) > ZV
)
11339 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11341 /* Find the start of the continued line. This should be fast
11342 because scan_buffer is fast (newline cache). */
11343 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11344 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11345 row
, DEFAULT_FACE_ID
);
11346 reseat_at_previous_visible_line_start (&it
);
11348 /* If the line start is "too far" away from the window start,
11349 say it takes too much time to compute a new window start. */
11350 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11351 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11353 int min_distance
, distance
;
11355 /* Move forward by display lines to find the new window
11356 start. If window width was enlarged, the new start can
11357 be expected to be > the old start. If window width was
11358 decreased, the new window start will be < the old start.
11359 So, we're looking for the display line start with the
11360 minimum distance from the old window start. */
11361 pos
= it
.current
.pos
;
11362 min_distance
= INFINITY
;
11363 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11364 distance
< min_distance
)
11366 min_distance
= distance
;
11367 pos
= it
.current
.pos
;
11368 move_it_by_lines (&it
, 1, 0);
11371 /* Set the window start there. */
11372 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11373 window_start_changed_p
= 1;
11377 return window_start_changed_p
;
11381 /* Try cursor movement in case text has not changed in window WINDOW,
11382 with window start STARTP. Value is
11384 CURSOR_MOVEMENT_SUCCESS if successful
11386 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11388 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11389 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11390 we want to scroll as if scroll-step were set to 1. See the code.
11392 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11393 which case we have to abort this redisplay, and adjust matrices
11398 CURSOR_MOVEMENT_SUCCESS
,
11399 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11400 CURSOR_MOVEMENT_MUST_SCROLL
,
11401 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11405 try_cursor_movement (window
, startp
, scroll_step
)
11406 Lisp_Object window
;
11407 struct text_pos startp
;
11410 struct window
*w
= XWINDOW (window
);
11411 struct frame
*f
= XFRAME (w
->frame
);
11412 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11415 if (inhibit_try_cursor_movement
)
11419 /* Handle case where text has not changed, only point, and it has
11420 not moved off the frame. */
11421 if (/* Point may be in this window. */
11422 PT
>= CHARPOS (startp
)
11423 /* Selective display hasn't changed. */
11424 && !current_buffer
->clip_changed
11425 /* Function force-mode-line-update is used to force a thorough
11426 redisplay. It sets either windows_or_buffers_changed or
11427 update_mode_lines. So don't take a shortcut here for these
11429 && !update_mode_lines
11430 && !windows_or_buffers_changed
11431 && !cursor_type_changed
11432 /* Can't use this case if highlighting a region. When a
11433 region exists, cursor movement has to do more than just
11435 && !(!NILP (Vtransient_mark_mode
)
11436 && !NILP (current_buffer
->mark_active
))
11437 && NILP (w
->region_showing
)
11438 && NILP (Vshow_trailing_whitespace
)
11439 /* Right after splitting windows, last_point may be nil. */
11440 && INTEGERP (w
->last_point
)
11441 /* This code is not used for mini-buffer for the sake of the case
11442 of redisplaying to replace an echo area message; since in
11443 that case the mini-buffer contents per se are usually
11444 unchanged. This code is of no real use in the mini-buffer
11445 since the handling of this_line_start_pos, etc., in redisplay
11446 handles the same cases. */
11447 && !EQ (window
, minibuf_window
)
11448 /* When splitting windows or for new windows, it happens that
11449 redisplay is called with a nil window_end_vpos or one being
11450 larger than the window. This should really be fixed in
11451 window.c. I don't have this on my list, now, so we do
11452 approximately the same as the old redisplay code. --gerd. */
11453 && INTEGERP (w
->window_end_vpos
)
11454 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11455 && (FRAME_WINDOW_P (f
)
11456 || !overlay_arrow_in_current_buffer_p ()))
11458 int this_scroll_margin
, top_scroll_margin
;
11459 struct glyph_row
*row
= NULL
;
11462 debug_method_add (w
, "cursor movement");
11465 /* Scroll if point within this distance from the top or bottom
11466 of the window. This is a pixel value. */
11467 this_scroll_margin
= max (0, scroll_margin
);
11468 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11469 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11471 top_scroll_margin
= this_scroll_margin
;
11472 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11473 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
11475 /* Start with the row the cursor was displayed during the last
11476 not paused redisplay. Give up if that row is not valid. */
11477 if (w
->last_cursor
.vpos
< 0
11478 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11479 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11482 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11483 if (row
->mode_line_p
)
11485 if (!row
->enabled_p
)
11486 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11489 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11492 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11494 if (PT
> XFASTINT (w
->last_point
))
11496 /* Point has moved forward. */
11497 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11498 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11500 xassert (row
->enabled_p
);
11504 /* The end position of a row equals the start position
11505 of the next row. If PT is there, we would rather
11506 display it in the next line. */
11507 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11508 && MATRIX_ROW_END_CHARPOS (row
) == PT
11509 && !cursor_row_p (w
, row
))
11512 /* If within the scroll margin, scroll. Note that
11513 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11514 the next line would be drawn, and that
11515 this_scroll_margin can be zero. */
11516 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11517 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11518 /* Line is completely visible last line in window
11519 and PT is to be set in the next line. */
11520 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11521 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11522 && !row
->ends_at_zv_p
11523 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11526 else if (PT
< XFASTINT (w
->last_point
))
11528 /* Cursor has to be moved backward. Note that PT >=
11529 CHARPOS (startp) because of the outer if-statement. */
11530 while (!row
->mode_line_p
11531 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11532 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11533 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11534 && (row
->y
> top_scroll_margin
11535 || CHARPOS (startp
) == BEGV
))
11537 xassert (row
->enabled_p
);
11541 /* Consider the following case: Window starts at BEGV,
11542 there is invisible, intangible text at BEGV, so that
11543 display starts at some point START > BEGV. It can
11544 happen that we are called with PT somewhere between
11545 BEGV and START. Try to handle that case. */
11546 if (row
< w
->current_matrix
->rows
11547 || row
->mode_line_p
)
11549 row
= w
->current_matrix
->rows
;
11550 if (row
->mode_line_p
)
11554 /* Due to newlines in overlay strings, we may have to
11555 skip forward over overlay strings. */
11556 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11557 && MATRIX_ROW_END_CHARPOS (row
) == PT
11558 && !cursor_row_p (w
, row
))
11561 /* If within the scroll margin, scroll. */
11562 if (row
->y
< top_scroll_margin
11563 && CHARPOS (startp
) != BEGV
)
11567 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11568 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11570 /* if PT is not in the glyph row, give up. */
11571 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11573 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
11574 && make_cursor_line_fully_visible_p
)
11576 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11577 && !row
->ends_at_zv_p
11578 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11579 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11580 else if (row
->height
> window_box_height (w
))
11582 /* If we end up in a partially visible line, let's
11583 make it fully visible, except when it's taller
11584 than the window, in which case we can't do much
11587 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11591 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11592 if (!make_cursor_line_fully_visible (w
, 0))
11593 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11595 rc
= CURSOR_MOVEMENT_SUCCESS
;
11599 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11602 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11603 rc
= CURSOR_MOVEMENT_SUCCESS
;
11612 set_vertical_scroll_bar (w
)
11615 int start
, end
, whole
;
11617 /* Calculate the start and end positions for the current window.
11618 At some point, it would be nice to choose between scrollbars
11619 which reflect the whole buffer size, with special markers
11620 indicating narrowing, and scrollbars which reflect only the
11623 Note that mini-buffers sometimes aren't displaying any text. */
11624 if (!MINI_WINDOW_P (w
)
11625 || (w
== XWINDOW (minibuf_window
)
11626 && NILP (echo_area_buffer
[0])))
11628 struct buffer
*buf
= XBUFFER (w
->buffer
);
11629 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11630 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11631 /* I don't think this is guaranteed to be right. For the
11632 moment, we'll pretend it is. */
11633 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11637 if (whole
< (end
- start
))
11638 whole
= end
- start
;
11641 start
= end
= whole
= 0;
11643 /* Indicate what this scroll bar ought to be displaying now. */
11644 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
11648 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11649 selected_window is redisplayed.
11651 We can return without actually redisplaying the window if
11652 fonts_changed_p is nonzero. In that case, redisplay_internal will
11656 redisplay_window (window
, just_this_one_p
)
11657 Lisp_Object window
;
11658 int just_this_one_p
;
11660 struct window
*w
= XWINDOW (window
);
11661 struct frame
*f
= XFRAME (w
->frame
);
11662 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11663 struct buffer
*old
= current_buffer
;
11664 struct text_pos lpoint
, opoint
, startp
;
11665 int update_mode_line
;
11668 /* Record it now because it's overwritten. */
11669 int current_matrix_up_to_date_p
= 0;
11670 int used_current_matrix_p
= 0;
11671 /* This is less strict than current_matrix_up_to_date_p.
11672 It indictes that the buffer contents and narrowing are unchanged. */
11673 int buffer_unchanged_p
= 0;
11674 int temp_scroll_step
= 0;
11675 int count
= SPECPDL_INDEX ();
11677 int centering_position
;
11678 int last_line_misfit
= 0;
11680 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11683 /* W must be a leaf window here. */
11684 xassert (!NILP (w
->buffer
));
11686 *w
->desired_matrix
->method
= 0;
11689 specbind (Qinhibit_point_motion_hooks
, Qt
);
11691 reconsider_clip_changes (w
, buffer
);
11693 /* Has the mode line to be updated? */
11694 update_mode_line
= (!NILP (w
->update_mode_line
)
11695 || update_mode_lines
11696 || buffer
->clip_changed
11697 || buffer
->prevent_redisplay_optimizations_p
);
11699 if (MINI_WINDOW_P (w
))
11701 if (w
== XWINDOW (echo_area_window
)
11702 && !NILP (echo_area_buffer
[0]))
11704 if (update_mode_line
)
11705 /* We may have to update a tty frame's menu bar or a
11706 tool-bar. Example `M-x C-h C-h C-g'. */
11707 goto finish_menu_bars
;
11709 /* We've already displayed the echo area glyphs in this window. */
11710 goto finish_scroll_bars
;
11712 else if ((w
!= XWINDOW (minibuf_window
)
11713 || minibuf_level
== 0)
11714 /* When buffer is nonempty, redisplay window normally. */
11715 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11716 /* Quail displays non-mini buffers in minibuffer window.
11717 In that case, redisplay the window normally. */
11718 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11720 /* W is a mini-buffer window, but it's not active, so clear
11722 int yb
= window_text_bottom_y (w
);
11723 struct glyph_row
*row
;
11726 for (y
= 0, row
= w
->desired_matrix
->rows
;
11728 y
+= row
->height
, ++row
)
11729 blank_row (w
, row
, y
);
11730 goto finish_scroll_bars
;
11733 clear_glyph_matrix (w
->desired_matrix
);
11736 /* Otherwise set up data on this window; select its buffer and point
11738 /* Really select the buffer, for the sake of buffer-local
11740 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11741 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11743 current_matrix_up_to_date_p
11744 = (!NILP (w
->window_end_valid
)
11745 && !current_buffer
->clip_changed
11746 && !current_buffer
->prevent_redisplay_optimizations_p
11747 && XFASTINT (w
->last_modified
) >= MODIFF
11748 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11751 = (!NILP (w
->window_end_valid
)
11752 && !current_buffer
->clip_changed
11753 && XFASTINT (w
->last_modified
) >= MODIFF
11754 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11756 /* When windows_or_buffers_changed is non-zero, we can't rely on
11757 the window end being valid, so set it to nil there. */
11758 if (windows_or_buffers_changed
)
11760 /* If window starts on a continuation line, maybe adjust the
11761 window start in case the window's width changed. */
11762 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11763 compute_window_start_on_continuation_line (w
);
11765 w
->window_end_valid
= Qnil
;
11768 /* Some sanity checks. */
11769 CHECK_WINDOW_END (w
);
11770 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11772 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11775 /* If %c is in mode line, update it if needed. */
11776 if (!NILP (w
->column_number_displayed
)
11777 /* This alternative quickly identifies a common case
11778 where no change is needed. */
11779 && !(PT
== XFASTINT (w
->last_point
)
11780 && XFASTINT (w
->last_modified
) >= MODIFF
11781 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11782 && (XFASTINT (w
->column_number_displayed
)
11783 != (int) current_column ())) /* iftc */
11784 update_mode_line
= 1;
11786 /* Count number of windows showing the selected buffer. An indirect
11787 buffer counts as its base buffer. */
11788 if (!just_this_one_p
)
11790 struct buffer
*current_base
, *window_base
;
11791 current_base
= current_buffer
;
11792 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11793 if (current_base
->base_buffer
)
11794 current_base
= current_base
->base_buffer
;
11795 if (window_base
->base_buffer
)
11796 window_base
= window_base
->base_buffer
;
11797 if (current_base
== window_base
)
11801 /* Point refers normally to the selected window. For any other
11802 window, set up appropriate value. */
11803 if (!EQ (window
, selected_window
))
11805 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11806 int new_pt_byte
= marker_byte_position (w
->pointm
);
11810 new_pt_byte
= BEGV_BYTE
;
11811 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11813 else if (new_pt
> (ZV
- 1))
11816 new_pt_byte
= ZV_BYTE
;
11817 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11820 /* We don't use SET_PT so that the point-motion hooks don't run. */
11821 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11824 /* If any of the character widths specified in the display table
11825 have changed, invalidate the width run cache. It's true that
11826 this may be a bit late to catch such changes, but the rest of
11827 redisplay goes (non-fatally) haywire when the display table is
11828 changed, so why should we worry about doing any better? */
11829 if (current_buffer
->width_run_cache
)
11831 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11833 if (! disptab_matches_widthtab (disptab
,
11834 XVECTOR (current_buffer
->width_table
)))
11836 invalidate_region_cache (current_buffer
,
11837 current_buffer
->width_run_cache
,
11839 recompute_width_table (current_buffer
, disptab
);
11843 /* If window-start is screwed up, choose a new one. */
11844 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
11847 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11849 /* If someone specified a new starting point but did not insist,
11850 check whether it can be used. */
11851 if (!NILP (w
->optional_new_start
)
11852 && CHARPOS (startp
) >= BEGV
11853 && CHARPOS (startp
) <= ZV
)
11855 w
->optional_new_start
= Qnil
;
11856 start_display (&it
, w
, startp
);
11857 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11858 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11859 if (IT_CHARPOS (it
) == PT
)
11860 w
->force_start
= Qt
;
11861 /* IT may overshoot PT if text at PT is invisible. */
11862 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
11863 w
->force_start
= Qt
;
11868 /* Handle case where place to start displaying has been specified,
11869 unless the specified location is outside the accessible range. */
11870 if (!NILP (w
->force_start
)
11871 || w
->frozen_window_start_p
)
11873 /* We set this later on if we have to adjust point. */
11876 w
->force_start
= Qnil
;
11878 w
->window_end_valid
= Qnil
;
11880 /* Forget any recorded base line for line number display. */
11881 if (!buffer_unchanged_p
)
11882 w
->base_line_number
= Qnil
;
11884 /* Redisplay the mode line. Select the buffer properly for that.
11885 Also, run the hook window-scroll-functions
11886 because we have scrolled. */
11887 /* Note, we do this after clearing force_start because
11888 if there's an error, it is better to forget about force_start
11889 than to get into an infinite loop calling the hook functions
11890 and having them get more errors. */
11891 if (!update_mode_line
11892 || ! NILP (Vwindow_scroll_functions
))
11894 update_mode_line
= 1;
11895 w
->update_mode_line
= Qt
;
11896 startp
= run_window_scroll_functions (window
, startp
);
11899 w
->last_modified
= make_number (0);
11900 w
->last_overlay_modified
= make_number (0);
11901 if (CHARPOS (startp
) < BEGV
)
11902 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
11903 else if (CHARPOS (startp
) > ZV
)
11904 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
11906 /* Redisplay, then check if cursor has been set during the
11907 redisplay. Give up if new fonts were loaded. */
11908 if (!try_window (window
, startp
))
11910 w
->force_start
= Qt
;
11911 clear_glyph_matrix (w
->desired_matrix
);
11912 goto need_larger_matrices
;
11915 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
11917 /* If point does not appear, try to move point so it does
11918 appear. The desired matrix has been built above, so we
11919 can use it here. */
11920 new_vpos
= window_box_height (w
) / 2;
11923 if (!make_cursor_line_fully_visible (w
, 0))
11925 /* Point does appear, but on a line partly visible at end of window.
11926 Move it back to a fully-visible line. */
11927 new_vpos
= window_box_height (w
);
11930 /* If we need to move point for either of the above reasons,
11931 now actually do it. */
11934 struct glyph_row
*row
;
11936 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
11937 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
11940 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
11941 MATRIX_ROW_START_BYTEPOS (row
));
11943 if (w
!= XWINDOW (selected_window
))
11944 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
11945 else if (current_buffer
== old
)
11946 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11948 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
11950 /* If we are highlighting the region, then we just changed
11951 the region, so redisplay to show it. */
11952 if (!NILP (Vtransient_mark_mode
)
11953 && !NILP (current_buffer
->mark_active
))
11955 clear_glyph_matrix (w
->desired_matrix
);
11956 if (!try_window (window
, startp
))
11957 goto need_larger_matrices
;
11962 debug_method_add (w
, "forced window start");
11967 /* Handle case where text has not changed, only point, and it has
11968 not moved off the frame, and we are not retrying after hscroll.
11969 (current_matrix_up_to_date_p is nonzero when retrying.) */
11970 if (current_matrix_up_to_date_p
11971 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
11972 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
11976 case CURSOR_MOVEMENT_SUCCESS
:
11977 used_current_matrix_p
= 1;
11980 #if 0 /* try_cursor_movement never returns this value. */
11981 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
11982 goto need_larger_matrices
;
11985 case CURSOR_MOVEMENT_MUST_SCROLL
:
11986 goto try_to_scroll
;
11992 /* If current starting point was originally the beginning of a line
11993 but no longer is, find a new starting point. */
11994 else if (!NILP (w
->start_at_line_beg
)
11995 && !(CHARPOS (startp
) <= BEGV
11996 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
11999 debug_method_add (w
, "recenter 1");
12004 /* Try scrolling with try_window_id. Value is > 0 if update has
12005 been done, it is -1 if we know that the same window start will
12006 not work. It is 0 if unsuccessful for some other reason. */
12007 else if ((tem
= try_window_id (w
)) != 0)
12010 debug_method_add (w
, "try_window_id %d", tem
);
12013 if (fonts_changed_p
)
12014 goto need_larger_matrices
;
12018 /* Otherwise try_window_id has returned -1 which means that we
12019 don't want the alternative below this comment to execute. */
12021 else if (CHARPOS (startp
) >= BEGV
12022 && CHARPOS (startp
) <= ZV
12023 && PT
>= CHARPOS (startp
)
12024 && (CHARPOS (startp
) < ZV
12025 /* Avoid starting at end of buffer. */
12026 || CHARPOS (startp
) == BEGV
12027 || (XFASTINT (w
->last_modified
) >= MODIFF
12028 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12031 debug_method_add (w
, "same window start");
12034 /* Try to redisplay starting at same place as before.
12035 If point has not moved off frame, accept the results. */
12036 if (!current_matrix_up_to_date_p
12037 /* Don't use try_window_reusing_current_matrix in this case
12038 because a window scroll function can have changed the
12040 || !NILP (Vwindow_scroll_functions
)
12041 || MINI_WINDOW_P (w
)
12042 || !(used_current_matrix_p
12043 = try_window_reusing_current_matrix (w
)))
12045 IF_DEBUG (debug_method_add (w
, "1"));
12046 try_window (window
, startp
);
12049 if (fonts_changed_p
)
12050 goto need_larger_matrices
;
12052 if (w
->cursor
.vpos
>= 0)
12054 if (!just_this_one_p
12055 || current_buffer
->clip_changed
12056 || BEG_UNCHANGED
< CHARPOS (startp
))
12057 /* Forget any recorded base line for line number display. */
12058 w
->base_line_number
= Qnil
;
12060 if (!make_cursor_line_fully_visible (w
, 1))
12062 clear_glyph_matrix (w
->desired_matrix
);
12063 last_line_misfit
= 1;
12065 /* Drop through and scroll. */
12070 clear_glyph_matrix (w
->desired_matrix
);
12075 w
->last_modified
= make_number (0);
12076 w
->last_overlay_modified
= make_number (0);
12078 /* Redisplay the mode line. Select the buffer properly for that. */
12079 if (!update_mode_line
)
12081 update_mode_line
= 1;
12082 w
->update_mode_line
= Qt
;
12085 /* Try to scroll by specified few lines. */
12086 if ((scroll_conservatively
12088 || temp_scroll_step
12089 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12090 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12091 && !current_buffer
->clip_changed
12092 && CHARPOS (startp
) >= BEGV
12093 && CHARPOS (startp
) <= ZV
)
12095 /* The function returns -1 if new fonts were loaded, 1 if
12096 successful, 0 if not successful. */
12097 int rc
= try_scrolling (window
, just_this_one_p
,
12098 scroll_conservatively
,
12100 temp_scroll_step
, last_line_misfit
);
12103 case SCROLLING_SUCCESS
:
12106 case SCROLLING_NEED_LARGER_MATRICES
:
12107 goto need_larger_matrices
;
12109 case SCROLLING_FAILED
:
12117 /* Finally, just choose place to start which centers point */
12120 centering_position
= window_box_height (w
) / 2;
12123 /* Jump here with centering_position already set to 0. */
12126 debug_method_add (w
, "recenter");
12129 /* w->vscroll = 0; */
12131 /* Forget any previously recorded base line for line number display. */
12132 if (!buffer_unchanged_p
)
12133 w
->base_line_number
= Qnil
;
12135 /* Move backward half the height of the window. */
12136 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12137 it
.current_y
= it
.last_visible_y
;
12138 move_it_vertically_backward (&it
, centering_position
);
12139 xassert (IT_CHARPOS (it
) >= BEGV
);
12141 /* The function move_it_vertically_backward may move over more
12142 than the specified y-distance. If it->w is small, e.g. a
12143 mini-buffer window, we may end up in front of the window's
12144 display area. Start displaying at the start of the line
12145 containing PT in this case. */
12146 if (it
.current_y
<= 0)
12148 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12149 move_it_vertically_backward (&it
, 0);
12150 xassert (IT_CHARPOS (it
) <= PT
);
12154 it
.current_x
= it
.hpos
= 0;
12156 /* Set startp here explicitly in case that helps avoid an infinite loop
12157 in case the window-scroll-functions functions get errors. */
12158 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12160 /* Run scroll hooks. */
12161 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12163 /* Redisplay the window. */
12164 if (!current_matrix_up_to_date_p
12165 || windows_or_buffers_changed
12166 || cursor_type_changed
12167 /* Don't use try_window_reusing_current_matrix in this case
12168 because it can have changed the buffer. */
12169 || !NILP (Vwindow_scroll_functions
)
12170 || !just_this_one_p
12171 || MINI_WINDOW_P (w
)
12172 || !(used_current_matrix_p
12173 = try_window_reusing_current_matrix (w
)))
12174 try_window (window
, startp
);
12176 /* If new fonts have been loaded (due to fontsets), give up. We
12177 have to start a new redisplay since we need to re-adjust glyph
12179 if (fonts_changed_p
)
12180 goto need_larger_matrices
;
12182 /* If cursor did not appear assume that the middle of the window is
12183 in the first line of the window. Do it again with the next line.
12184 (Imagine a window of height 100, displaying two lines of height
12185 60. Moving back 50 from it->last_visible_y will end in the first
12187 if (w
->cursor
.vpos
< 0)
12189 if (!NILP (w
->window_end_valid
)
12190 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12192 clear_glyph_matrix (w
->desired_matrix
);
12193 move_it_by_lines (&it
, 1, 0);
12194 try_window (window
, it
.current
.pos
);
12196 else if (PT
< IT_CHARPOS (it
))
12198 clear_glyph_matrix (w
->desired_matrix
);
12199 move_it_by_lines (&it
, -1, 0);
12200 try_window (window
, it
.current
.pos
);
12204 /* Not much we can do about it. */
12208 /* Consider the following case: Window starts at BEGV, there is
12209 invisible, intangible text at BEGV, so that display starts at
12210 some point START > BEGV. It can happen that we are called with
12211 PT somewhere between BEGV and START. Try to handle that case. */
12212 if (w
->cursor
.vpos
< 0)
12214 struct glyph_row
*row
= w
->current_matrix
->rows
;
12215 if (row
->mode_line_p
)
12217 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12220 if (!make_cursor_line_fully_visible (w
, centering_position
> 0))
12222 /* If vscroll is enabled, disable it and try again. */
12226 clear_glyph_matrix (w
->desired_matrix
);
12230 /* If centering point failed to make the whole line visible,
12231 put point at the top instead. That has to make the whole line
12232 visible, if it can be done. */
12233 clear_glyph_matrix (w
->desired_matrix
);
12234 centering_position
= 0;
12240 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12241 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12242 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12245 /* Display the mode line, if we must. */
12246 if ((update_mode_line
12247 /* If window not full width, must redo its mode line
12248 if (a) the window to its side is being redone and
12249 (b) we do a frame-based redisplay. This is a consequence
12250 of how inverted lines are drawn in frame-based redisplay. */
12251 || (!just_this_one_p
12252 && !FRAME_WINDOW_P (f
)
12253 && !WINDOW_FULL_WIDTH_P (w
))
12254 /* Line number to display. */
12255 || INTEGERP (w
->base_line_pos
)
12256 /* Column number is displayed and different from the one displayed. */
12257 || (!NILP (w
->column_number_displayed
)
12258 && (XFASTINT (w
->column_number_displayed
)
12259 != (int) current_column ()))) /* iftc */
12260 /* This means that the window has a mode line. */
12261 && (WINDOW_WANTS_MODELINE_P (w
)
12262 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12264 display_mode_lines (w
);
12266 /* If mode line height has changed, arrange for a thorough
12267 immediate redisplay using the correct mode line height. */
12268 if (WINDOW_WANTS_MODELINE_P (w
)
12269 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12271 fonts_changed_p
= 1;
12272 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12273 = DESIRED_MODE_LINE_HEIGHT (w
);
12276 /* If top line height has changed, arrange for a thorough
12277 immediate redisplay using the correct mode line height. */
12278 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12279 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12281 fonts_changed_p
= 1;
12282 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12283 = DESIRED_HEADER_LINE_HEIGHT (w
);
12286 if (fonts_changed_p
)
12287 goto need_larger_matrices
;
12290 if (!line_number_displayed
12291 && !BUFFERP (w
->base_line_pos
))
12293 w
->base_line_pos
= Qnil
;
12294 w
->base_line_number
= Qnil
;
12299 /* When we reach a frame's selected window, redo the frame's menu bar. */
12300 if (update_mode_line
12301 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12303 int redisplay_menu_p
= 0;
12304 int redisplay_tool_bar_p
= 0;
12306 if (FRAME_WINDOW_P (f
))
12308 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12309 || defined (USE_GTK)
12310 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12312 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12316 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12318 if (redisplay_menu_p
)
12319 display_menu_bar (w
);
12321 #ifdef HAVE_WINDOW_SYSTEM
12323 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12325 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12326 && (FRAME_TOOL_BAR_LINES (f
) > 0
12327 || auto_resize_tool_bars_p
);
12331 if (redisplay_tool_bar_p
)
12332 redisplay_tool_bar (f
);
12336 #ifdef HAVE_WINDOW_SYSTEM
12337 if (FRAME_WINDOW_P (f
)
12338 && update_window_fringes (w
, 0)
12339 && !just_this_one_p
12340 && (used_current_matrix_p
|| overlay_arrow_seen
)
12341 && !w
->pseudo_window_p
)
12345 if (draw_window_fringes (w
, 1))
12346 x_draw_vertical_border (w
);
12350 #endif /* HAVE_WINDOW_SYSTEM */
12352 /* We go to this label, with fonts_changed_p nonzero,
12353 if it is necessary to try again using larger glyph matrices.
12354 We have to redeem the scroll bar even in this case,
12355 because the loop in redisplay_internal expects that. */
12356 need_larger_matrices
:
12358 finish_scroll_bars
:
12360 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12362 /* Set the thumb's position and size. */
12363 set_vertical_scroll_bar (w
);
12365 /* Note that we actually used the scroll bar attached to this
12366 window, so it shouldn't be deleted at the end of redisplay. */
12367 redeem_scroll_bar_hook (w
);
12370 /* Restore current_buffer and value of point in it. */
12371 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12372 set_buffer_internal_1 (old
);
12373 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12375 unbind_to (count
, Qnil
);
12379 /* Build the complete desired matrix of WINDOW with a window start
12380 buffer position POS. Value is non-zero if successful. It is zero
12381 if fonts were loaded during redisplay which makes re-adjusting
12382 glyph matrices necessary. */
12385 try_window (window
, pos
)
12386 Lisp_Object window
;
12387 struct text_pos pos
;
12389 struct window
*w
= XWINDOW (window
);
12391 struct glyph_row
*last_text_row
= NULL
;
12393 /* Make POS the new window start. */
12394 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12396 /* Mark cursor position as unknown. No overlay arrow seen. */
12397 w
->cursor
.vpos
= -1;
12398 overlay_arrow_seen
= 0;
12400 /* Initialize iterator and info to start at POS. */
12401 start_display (&it
, w
, pos
);
12403 /* Display all lines of W. */
12404 while (it
.current_y
< it
.last_visible_y
)
12406 if (display_line (&it
))
12407 last_text_row
= it
.glyph_row
- 1;
12408 if (fonts_changed_p
)
12412 /* If bottom moved off end of frame, change mode line percentage. */
12413 if (XFASTINT (w
->window_end_pos
) <= 0
12414 && Z
!= IT_CHARPOS (it
))
12415 w
->update_mode_line
= Qt
;
12417 /* Set window_end_pos to the offset of the last character displayed
12418 on the window from the end of current_buffer. Set
12419 window_end_vpos to its row number. */
12422 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12423 w
->window_end_bytepos
12424 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12426 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12428 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12429 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12430 ->displays_text_p
);
12434 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12435 w
->window_end_pos
= make_number (Z
- ZV
);
12436 w
->window_end_vpos
= make_number (0);
12439 /* But that is not valid info until redisplay finishes. */
12440 w
->window_end_valid
= Qnil
;
12446 /************************************************************************
12447 Window redisplay reusing current matrix when buffer has not changed
12448 ************************************************************************/
12450 /* Try redisplay of window W showing an unchanged buffer with a
12451 different window start than the last time it was displayed by
12452 reusing its current matrix. Value is non-zero if successful.
12453 W->start is the new window start. */
12456 try_window_reusing_current_matrix (w
)
12459 struct frame
*f
= XFRAME (w
->frame
);
12460 struct glyph_row
*row
, *bottom_row
;
12463 struct text_pos start
, new_start
;
12464 int nrows_scrolled
, i
;
12465 struct glyph_row
*last_text_row
;
12466 struct glyph_row
*last_reused_text_row
;
12467 struct glyph_row
*start_row
;
12468 int start_vpos
, min_y
, max_y
;
12471 if (inhibit_try_window_reusing
)
12475 if (/* This function doesn't handle terminal frames. */
12476 !FRAME_WINDOW_P (f
)
12477 /* Don't try to reuse the display if windows have been split
12479 || windows_or_buffers_changed
12480 || cursor_type_changed
)
12483 /* Can't do this if region may have changed. */
12484 if ((!NILP (Vtransient_mark_mode
)
12485 && !NILP (current_buffer
->mark_active
))
12486 || !NILP (w
->region_showing
)
12487 || !NILP (Vshow_trailing_whitespace
))
12490 /* If top-line visibility has changed, give up. */
12491 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12492 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12495 /* Give up if old or new display is scrolled vertically. We could
12496 make this function handle this, but right now it doesn't. */
12497 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12498 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
12501 /* The variable new_start now holds the new window start. The old
12502 start `start' can be determined from the current matrix. */
12503 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12504 start
= start_row
->start
.pos
;
12505 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12507 /* Clear the desired matrix for the display below. */
12508 clear_glyph_matrix (w
->desired_matrix
);
12510 if (CHARPOS (new_start
) <= CHARPOS (start
))
12514 /* Don't use this method if the display starts with an ellipsis
12515 displayed for invisible text. It's not easy to handle that case
12516 below, and it's certainly not worth the effort since this is
12517 not a frequent case. */
12518 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12521 IF_DEBUG (debug_method_add (w
, "twu1"));
12523 /* Display up to a row that can be reused. The variable
12524 last_text_row is set to the last row displayed that displays
12525 text. Note that it.vpos == 0 if or if not there is a
12526 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12527 start_display (&it
, w
, new_start
);
12528 first_row_y
= it
.current_y
;
12529 w
->cursor
.vpos
= -1;
12530 last_text_row
= last_reused_text_row
= NULL
;
12532 while (it
.current_y
< it
.last_visible_y
12533 && !fonts_changed_p
)
12535 /* If we have reached into the characters in the START row,
12536 that means the line boundaries have changed. So we
12537 can't start copying with the row START. Maybe it will
12538 work to start copying with the following row. */
12539 while (IT_CHARPOS (it
) > CHARPOS (start
))
12541 /* Advance to the next row as the "start". */
12543 start
= start_row
->start
.pos
;
12544 /* If there are no more rows to try, or just one, give up. */
12545 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
12546 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
12547 || CHARPOS (start
) == ZV
)
12549 clear_glyph_matrix (w
->desired_matrix
);
12553 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12555 /* If we have reached alignment,
12556 we can copy the rest of the rows. */
12557 if (IT_CHARPOS (it
) == CHARPOS (start
))
12560 if (display_line (&it
))
12561 last_text_row
= it
.glyph_row
- 1;
12564 /* A value of current_y < last_visible_y means that we stopped
12565 at the previous window start, which in turn means that we
12566 have at least one reusable row. */
12567 if (it
.current_y
< it
.last_visible_y
)
12569 /* IT.vpos always starts from 0; it counts text lines. */
12570 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
12572 /* Find PT if not already found in the lines displayed. */
12573 if (w
->cursor
.vpos
< 0)
12575 int dy
= it
.current_y
- start_row
->y
;
12577 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12578 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12580 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12581 dy
, nrows_scrolled
);
12584 clear_glyph_matrix (w
->desired_matrix
);
12589 /* Scroll the display. Do it before the current matrix is
12590 changed. The problem here is that update has not yet
12591 run, i.e. part of the current matrix is not up to date.
12592 scroll_run_hook will clear the cursor, and use the
12593 current matrix to get the height of the row the cursor is
12595 run
.current_y
= start_row
->y
;
12596 run
.desired_y
= it
.current_y
;
12597 run
.height
= it
.last_visible_y
- it
.current_y
;
12599 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12602 rif
->update_window_begin_hook (w
);
12603 rif
->clear_window_mouse_face (w
);
12604 rif
->scroll_run_hook (w
, &run
);
12605 rif
->update_window_end_hook (w
, 0, 0);
12609 /* Shift current matrix down by nrows_scrolled lines. */
12610 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12611 rotate_matrix (w
->current_matrix
,
12613 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12616 /* Disable lines that must be updated. */
12617 for (i
= 0; i
< it
.vpos
; ++i
)
12618 (start_row
+ i
)->enabled_p
= 0;
12620 /* Re-compute Y positions. */
12621 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12622 max_y
= it
.last_visible_y
;
12623 for (row
= start_row
+ nrows_scrolled
;
12627 row
->y
= it
.current_y
;
12628 row
->visible_height
= row
->height
;
12630 if (row
->y
< min_y
)
12631 row
->visible_height
-= min_y
- row
->y
;
12632 if (row
->y
+ row
->height
> max_y
)
12633 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12634 row
->redraw_fringe_bitmaps_p
= 1;
12636 it
.current_y
+= row
->height
;
12638 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12639 last_reused_text_row
= row
;
12640 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12644 /* Disable lines in the current matrix which are now
12645 below the window. */
12646 for (++row
; row
< bottom_row
; ++row
)
12647 row
->enabled_p
= 0;
12650 /* Update window_end_pos etc.; last_reused_text_row is the last
12651 reused row from the current matrix containing text, if any.
12652 The value of last_text_row is the last displayed line
12653 containing text. */
12654 if (last_reused_text_row
)
12656 w
->window_end_bytepos
12657 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12659 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12661 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12662 w
->current_matrix
));
12664 else if (last_text_row
)
12666 w
->window_end_bytepos
12667 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12669 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12671 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12675 /* This window must be completely empty. */
12676 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12677 w
->window_end_pos
= make_number (Z
- ZV
);
12678 w
->window_end_vpos
= make_number (0);
12680 w
->window_end_valid
= Qnil
;
12682 /* Update hint: don't try scrolling again in update_window. */
12683 w
->desired_matrix
->no_scrolling_p
= 1;
12686 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12690 else if (CHARPOS (new_start
) > CHARPOS (start
))
12692 struct glyph_row
*pt_row
, *row
;
12693 struct glyph_row
*first_reusable_row
;
12694 struct glyph_row
*first_row_to_display
;
12696 int yb
= window_text_bottom_y (w
);
12698 /* Find the row starting at new_start, if there is one. Don't
12699 reuse a partially visible line at the end. */
12700 first_reusable_row
= start_row
;
12701 while (first_reusable_row
->enabled_p
12702 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12703 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12704 < CHARPOS (new_start
)))
12705 ++first_reusable_row
;
12707 /* Give up if there is no row to reuse. */
12708 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12709 || !first_reusable_row
->enabled_p
12710 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12711 != CHARPOS (new_start
)))
12714 /* We can reuse fully visible rows beginning with
12715 first_reusable_row to the end of the window. Set
12716 first_row_to_display to the first row that cannot be reused.
12717 Set pt_row to the row containing point, if there is any. */
12719 for (first_row_to_display
= first_reusable_row
;
12720 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12721 ++first_row_to_display
)
12723 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12724 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12725 pt_row
= first_row_to_display
;
12728 /* Start displaying at the start of first_row_to_display. */
12729 xassert (first_row_to_display
->y
< yb
);
12730 init_to_row_start (&it
, w
, first_row_to_display
);
12732 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12734 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12736 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12737 + WINDOW_HEADER_LINE_HEIGHT (w
));
12739 /* Display lines beginning with first_row_to_display in the
12740 desired matrix. Set last_text_row to the last row displayed
12741 that displays text. */
12742 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12743 if (pt_row
== NULL
)
12744 w
->cursor
.vpos
= -1;
12745 last_text_row
= NULL
;
12746 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12747 if (display_line (&it
))
12748 last_text_row
= it
.glyph_row
- 1;
12750 /* Give up If point isn't in a row displayed or reused. */
12751 if (w
->cursor
.vpos
< 0)
12753 clear_glyph_matrix (w
->desired_matrix
);
12757 /* If point is in a reused row, adjust y and vpos of the cursor
12761 w
->cursor
.vpos
-= nrows_scrolled
;
12762 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
12765 /* Scroll the display. */
12766 run
.current_y
= first_reusable_row
->y
;
12767 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12768 run
.height
= it
.last_visible_y
- run
.current_y
;
12769 dy
= run
.current_y
- run
.desired_y
;
12774 rif
->update_window_begin_hook (w
);
12775 rif
->clear_window_mouse_face (w
);
12776 rif
->scroll_run_hook (w
, &run
);
12777 rif
->update_window_end_hook (w
, 0, 0);
12781 /* Adjust Y positions of reused rows. */
12782 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12783 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12784 max_y
= it
.last_visible_y
;
12785 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12788 row
->visible_height
= row
->height
;
12789 if (row
->y
< min_y
)
12790 row
->visible_height
-= min_y
- row
->y
;
12791 if (row
->y
+ row
->height
> max_y
)
12792 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12793 row
->redraw_fringe_bitmaps_p
= 1;
12796 /* Scroll the current matrix. */
12797 xassert (nrows_scrolled
> 0);
12798 rotate_matrix (w
->current_matrix
,
12800 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12803 /* Disable rows not reused. */
12804 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12805 row
->enabled_p
= 0;
12807 /* Point may have moved to a different line, so we cannot assume that
12808 the previous cursor position is valid; locate the correct row. */
12811 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12812 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
12816 w
->cursor
.y
= row
->y
;
12818 if (row
< bottom_row
)
12820 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
12821 while (glyph
->charpos
< PT
)
12824 w
->cursor
.x
+= glyph
->pixel_width
;
12830 /* Adjust window end. A null value of last_text_row means that
12831 the window end is in reused rows which in turn means that
12832 only its vpos can have changed. */
12835 w
->window_end_bytepos
12836 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12838 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12840 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12845 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12848 w
->window_end_valid
= Qnil
;
12849 w
->desired_matrix
->no_scrolling_p
= 1;
12852 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12862 /************************************************************************
12863 Window redisplay reusing current matrix when buffer has changed
12864 ************************************************************************/
12866 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12867 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12869 static struct glyph_row
*
12870 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12871 struct glyph_row
*));
12874 /* Return the last row in MATRIX displaying text. If row START is
12875 non-null, start searching with that row. IT gives the dimensions
12876 of the display. Value is null if matrix is empty; otherwise it is
12877 a pointer to the row found. */
12879 static struct glyph_row
*
12880 find_last_row_displaying_text (matrix
, it
, start
)
12881 struct glyph_matrix
*matrix
;
12883 struct glyph_row
*start
;
12885 struct glyph_row
*row
, *row_found
;
12887 /* Set row_found to the last row in IT->w's current matrix
12888 displaying text. The loop looks funny but think of partially
12891 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
12892 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12894 xassert (row
->enabled_p
);
12896 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
12905 /* Return the last row in the current matrix of W that is not affected
12906 by changes at the start of current_buffer that occurred since W's
12907 current matrix was built. Value is null if no such row exists.
12909 BEG_UNCHANGED us the number of characters unchanged at the start of
12910 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
12911 first changed character in current_buffer. Characters at positions <
12912 BEG + BEG_UNCHANGED are at the same buffer positions as they were
12913 when the current matrix was built. */
12915 static struct glyph_row
*
12916 find_last_unchanged_at_beg_row (w
)
12919 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
12920 struct glyph_row
*row
;
12921 struct glyph_row
*row_found
= NULL
;
12922 int yb
= window_text_bottom_y (w
);
12924 /* Find the last row displaying unchanged text. */
12925 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12926 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12927 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
12929 if (/* If row ends before first_changed_pos, it is unchanged,
12930 except in some case. */
12931 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
12932 /* When row ends in ZV and we write at ZV it is not
12934 && !row
->ends_at_zv_p
12935 /* When first_changed_pos is the end of a continued line,
12936 row is not unchanged because it may be no longer
12938 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
12939 && (row
->continued_p
12940 || row
->exact_window_width_line_p
)))
12943 /* Stop if last visible row. */
12944 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
12954 /* Find the first glyph row in the current matrix of W that is not
12955 affected by changes at the end of current_buffer since the
12956 time W's current matrix was built.
12958 Return in *DELTA the number of chars by which buffer positions in
12959 unchanged text at the end of current_buffer must be adjusted.
12961 Return in *DELTA_BYTES the corresponding number of bytes.
12963 Value is null if no such row exists, i.e. all rows are affected by
12966 static struct glyph_row
*
12967 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
12969 int *delta
, *delta_bytes
;
12971 struct glyph_row
*row
;
12972 struct glyph_row
*row_found
= NULL
;
12974 *delta
= *delta_bytes
= 0;
12976 /* Display must not have been paused, otherwise the current matrix
12977 is not up to date. */
12978 if (NILP (w
->window_end_valid
))
12981 /* A value of window_end_pos >= END_UNCHANGED means that the window
12982 end is in the range of changed text. If so, there is no
12983 unchanged row at the end of W's current matrix. */
12984 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
12987 /* Set row to the last row in W's current matrix displaying text. */
12988 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12990 /* If matrix is entirely empty, no unchanged row exists. */
12991 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12993 /* The value of row is the last glyph row in the matrix having a
12994 meaningful buffer position in it. The end position of row
12995 corresponds to window_end_pos. This allows us to translate
12996 buffer positions in the current matrix to current buffer
12997 positions for characters not in changed text. */
12998 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12999 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13000 int last_unchanged_pos
, last_unchanged_pos_old
;
13001 struct glyph_row
*first_text_row
13002 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13004 *delta
= Z
- Z_old
;
13005 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13007 /* Set last_unchanged_pos to the buffer position of the last
13008 character in the buffer that has not been changed. Z is the
13009 index + 1 of the last character in current_buffer, i.e. by
13010 subtracting END_UNCHANGED we get the index of the last
13011 unchanged character, and we have to add BEG to get its buffer
13013 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13014 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13016 /* Search backward from ROW for a row displaying a line that
13017 starts at a minimum position >= last_unchanged_pos_old. */
13018 for (; row
> first_text_row
; --row
)
13020 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13023 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13028 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13035 /* Make sure that glyph rows in the current matrix of window W
13036 reference the same glyph memory as corresponding rows in the
13037 frame's frame matrix. This function is called after scrolling W's
13038 current matrix on a terminal frame in try_window_id and
13039 try_window_reusing_current_matrix. */
13042 sync_frame_with_window_matrix_rows (w
)
13045 struct frame
*f
= XFRAME (w
->frame
);
13046 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13048 /* Preconditions: W must be a leaf window and full-width. Its frame
13049 must have a frame matrix. */
13050 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13051 xassert (WINDOW_FULL_WIDTH_P (w
));
13052 xassert (!FRAME_WINDOW_P (f
));
13054 /* If W is a full-width window, glyph pointers in W's current matrix
13055 have, by definition, to be the same as glyph pointers in the
13056 corresponding frame matrix. Note that frame matrices have no
13057 marginal areas (see build_frame_matrix). */
13058 window_row
= w
->current_matrix
->rows
;
13059 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13060 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13061 while (window_row
< window_row_end
)
13063 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13064 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13066 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13067 frame_row
->glyphs
[TEXT_AREA
] = start
;
13068 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13069 frame_row
->glyphs
[LAST_AREA
] = end
;
13071 /* Disable frame rows whose corresponding window rows have
13072 been disabled in try_window_id. */
13073 if (!window_row
->enabled_p
)
13074 frame_row
->enabled_p
= 0;
13076 ++window_row
, ++frame_row
;
13081 /* Find the glyph row in window W containing CHARPOS. Consider all
13082 rows between START and END (not inclusive). END null means search
13083 all rows to the end of the display area of W. Value is the row
13084 containing CHARPOS or null. */
13087 row_containing_pos (w
, charpos
, start
, end
, dy
)
13090 struct glyph_row
*start
, *end
;
13093 struct glyph_row
*row
= start
;
13096 /* If we happen to start on a header-line, skip that. */
13097 if (row
->mode_line_p
)
13100 if ((end
&& row
>= end
) || !row
->enabled_p
)
13103 last_y
= window_text_bottom_y (w
) - dy
;
13107 /* Give up if we have gone too far. */
13108 if (end
&& row
>= end
)
13110 /* This formerly returned if they were equal.
13111 I think that both quantities are of a "last plus one" type;
13112 if so, when they are equal, the row is within the screen. -- rms. */
13113 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13116 /* If it is in this row, return this row. */
13117 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13118 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13119 /* The end position of a row equals the start
13120 position of the next row. If CHARPOS is there, we
13121 would rather display it in the next line, except
13122 when this line ends in ZV. */
13123 && !row
->ends_at_zv_p
13124 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13125 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13132 /* Try to redisplay window W by reusing its existing display. W's
13133 current matrix must be up to date when this function is called,
13134 i.e. window_end_valid must not be nil.
13138 1 if display has been updated
13139 0 if otherwise unsuccessful
13140 -1 if redisplay with same window start is known not to succeed
13142 The following steps are performed:
13144 1. Find the last row in the current matrix of W that is not
13145 affected by changes at the start of current_buffer. If no such row
13148 2. Find the first row in W's current matrix that is not affected by
13149 changes at the end of current_buffer. Maybe there is no such row.
13151 3. Display lines beginning with the row + 1 found in step 1 to the
13152 row found in step 2 or, if step 2 didn't find a row, to the end of
13155 4. If cursor is not known to appear on the window, give up.
13157 5. If display stopped at the row found in step 2, scroll the
13158 display and current matrix as needed.
13160 6. Maybe display some lines at the end of W, if we must. This can
13161 happen under various circumstances, like a partially visible line
13162 becoming fully visible, or because newly displayed lines are displayed
13163 in smaller font sizes.
13165 7. Update W's window end information. */
13171 struct frame
*f
= XFRAME (w
->frame
);
13172 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13173 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13174 struct glyph_row
*last_unchanged_at_beg_row
;
13175 struct glyph_row
*first_unchanged_at_end_row
;
13176 struct glyph_row
*row
;
13177 struct glyph_row
*bottom_row
;
13180 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13181 struct text_pos start_pos
;
13183 int first_unchanged_at_end_vpos
= 0;
13184 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13185 struct text_pos start
;
13186 int first_changed_charpos
, last_changed_charpos
;
13189 if (inhibit_try_window_id
)
13193 /* This is handy for debugging. */
13195 #define GIVE_UP(X) \
13197 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13201 #define GIVE_UP(X) return 0
13204 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13206 /* Don't use this for mini-windows because these can show
13207 messages and mini-buffers, and we don't handle that here. */
13208 if (MINI_WINDOW_P (w
))
13211 /* This flag is used to prevent redisplay optimizations. */
13212 if (windows_or_buffers_changed
|| cursor_type_changed
)
13215 /* Verify that narrowing has not changed.
13216 Also verify that we were not told to prevent redisplay optimizations.
13217 It would be nice to further
13218 reduce the number of cases where this prevents try_window_id. */
13219 if (current_buffer
->clip_changed
13220 || current_buffer
->prevent_redisplay_optimizations_p
)
13223 /* Window must either use window-based redisplay or be full width. */
13224 if (!FRAME_WINDOW_P (f
)
13225 && (!line_ins_del_ok
13226 || !WINDOW_FULL_WIDTH_P (w
)))
13229 /* Give up if point is not known NOT to appear in W. */
13230 if (PT
< CHARPOS (start
))
13233 /* Another way to prevent redisplay optimizations. */
13234 if (XFASTINT (w
->last_modified
) == 0)
13237 /* Verify that window is not hscrolled. */
13238 if (XFASTINT (w
->hscroll
) != 0)
13241 /* Verify that display wasn't paused. */
13242 if (NILP (w
->window_end_valid
))
13245 /* Can't use this if highlighting a region because a cursor movement
13246 will do more than just set the cursor. */
13247 if (!NILP (Vtransient_mark_mode
)
13248 && !NILP (current_buffer
->mark_active
))
13251 /* Likewise if highlighting trailing whitespace. */
13252 if (!NILP (Vshow_trailing_whitespace
))
13255 /* Likewise if showing a region. */
13256 if (!NILP (w
->region_showing
))
13259 /* Can use this if overlay arrow position and or string have changed. */
13260 if (overlay_arrows_changed_p ())
13264 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13265 only if buffer has really changed. The reason is that the gap is
13266 initially at Z for freshly visited files. The code below would
13267 set end_unchanged to 0 in that case. */
13268 if (MODIFF
> SAVE_MODIFF
13269 /* This seems to happen sometimes after saving a buffer. */
13270 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13272 if (GPT
- BEG
< BEG_UNCHANGED
)
13273 BEG_UNCHANGED
= GPT
- BEG
;
13274 if (Z
- GPT
< END_UNCHANGED
)
13275 END_UNCHANGED
= Z
- GPT
;
13278 /* The position of the first and last character that has been changed. */
13279 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13280 last_changed_charpos
= Z
- END_UNCHANGED
;
13282 /* If window starts after a line end, and the last change is in
13283 front of that newline, then changes don't affect the display.
13284 This case happens with stealth-fontification. Note that although
13285 the display is unchanged, glyph positions in the matrix have to
13286 be adjusted, of course. */
13287 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13288 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13289 && ((last_changed_charpos
< CHARPOS (start
)
13290 && CHARPOS (start
) == BEGV
)
13291 || (last_changed_charpos
< CHARPOS (start
) - 1
13292 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13294 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13295 struct glyph_row
*r0
;
13297 /* Compute how many chars/bytes have been added to or removed
13298 from the buffer. */
13299 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13300 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13302 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13304 /* Give up if PT is not in the window. Note that it already has
13305 been checked at the start of try_window_id that PT is not in
13306 front of the window start. */
13307 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13310 /* If window start is unchanged, we can reuse the whole matrix
13311 as is, after adjusting glyph positions. No need to compute
13312 the window end again, since its offset from Z hasn't changed. */
13313 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13314 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13315 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13316 /* PT must not be in a partially visible line. */
13317 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13318 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13320 /* Adjust positions in the glyph matrix. */
13321 if (delta
|| delta_bytes
)
13323 struct glyph_row
*r1
13324 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13325 increment_matrix_positions (w
->current_matrix
,
13326 MATRIX_ROW_VPOS (r0
, current_matrix
),
13327 MATRIX_ROW_VPOS (r1
, current_matrix
),
13328 delta
, delta_bytes
);
13331 /* Set the cursor. */
13332 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13334 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13341 /* Handle the case that changes are all below what is displayed in
13342 the window, and that PT is in the window. This shortcut cannot
13343 be taken if ZV is visible in the window, and text has been added
13344 there that is visible in the window. */
13345 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13346 /* ZV is not visible in the window, or there are no
13347 changes at ZV, actually. */
13348 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13349 || first_changed_charpos
== last_changed_charpos
))
13351 struct glyph_row
*r0
;
13353 /* Give up if PT is not in the window. Note that it already has
13354 been checked at the start of try_window_id that PT is not in
13355 front of the window start. */
13356 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13359 /* If window start is unchanged, we can reuse the whole matrix
13360 as is, without changing glyph positions since no text has
13361 been added/removed in front of the window end. */
13362 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13363 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13364 /* PT must not be in a partially visible line. */
13365 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13366 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13368 /* We have to compute the window end anew since text
13369 can have been added/removed after it. */
13371 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13372 w
->window_end_bytepos
13373 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13375 /* Set the cursor. */
13376 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13378 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13385 /* Give up if window start is in the changed area.
13387 The condition used to read
13389 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13391 but why that was tested escapes me at the moment. */
13392 if (CHARPOS (start
) >= first_changed_charpos
13393 && CHARPOS (start
) <= last_changed_charpos
)
13396 /* Check that window start agrees with the start of the first glyph
13397 row in its current matrix. Check this after we know the window
13398 start is not in changed text, otherwise positions would not be
13400 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13401 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13404 /* Give up if the window ends in strings. Overlay strings
13405 at the end are difficult to handle, so don't try. */
13406 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13407 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13410 /* Compute the position at which we have to start displaying new
13411 lines. Some of the lines at the top of the window might be
13412 reusable because they are not displaying changed text. Find the
13413 last row in W's current matrix not affected by changes at the
13414 start of current_buffer. Value is null if changes start in the
13415 first line of window. */
13416 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13417 if (last_unchanged_at_beg_row
)
13419 /* Avoid starting to display in the moddle of a character, a TAB
13420 for instance. This is easier than to set up the iterator
13421 exactly, and it's not a frequent case, so the additional
13422 effort wouldn't really pay off. */
13423 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13424 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13425 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13426 --last_unchanged_at_beg_row
;
13428 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13431 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13433 start_pos
= it
.current
.pos
;
13435 /* Start displaying new lines in the desired matrix at the same
13436 vpos we would use in the current matrix, i.e. below
13437 last_unchanged_at_beg_row. */
13438 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13440 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13441 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13443 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13447 /* There are no reusable lines at the start of the window.
13448 Start displaying in the first text line. */
13449 start_display (&it
, w
, start
);
13450 it
.vpos
= it
.first_vpos
;
13451 start_pos
= it
.current
.pos
;
13454 /* Find the first row that is not affected by changes at the end of
13455 the buffer. Value will be null if there is no unchanged row, in
13456 which case we must redisplay to the end of the window. delta
13457 will be set to the value by which buffer positions beginning with
13458 first_unchanged_at_end_row have to be adjusted due to text
13460 first_unchanged_at_end_row
13461 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13462 IF_DEBUG (debug_delta
= delta
);
13463 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13465 /* Set stop_pos to the buffer position up to which we will have to
13466 display new lines. If first_unchanged_at_end_row != NULL, this
13467 is the buffer position of the start of the line displayed in that
13468 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13469 that we don't stop at a buffer position. */
13471 if (first_unchanged_at_end_row
)
13473 xassert (last_unchanged_at_beg_row
== NULL
13474 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13476 /* If this is a continuation line, move forward to the next one
13477 that isn't. Changes in lines above affect this line.
13478 Caution: this may move first_unchanged_at_end_row to a row
13479 not displaying text. */
13480 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13481 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13482 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13483 < it
.last_visible_y
))
13484 ++first_unchanged_at_end_row
;
13486 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13487 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13488 >= it
.last_visible_y
))
13489 first_unchanged_at_end_row
= NULL
;
13492 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13494 first_unchanged_at_end_vpos
13495 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13496 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13499 else if (last_unchanged_at_beg_row
== NULL
)
13505 /* Either there is no unchanged row at the end, or the one we have
13506 now displays text. This is a necessary condition for the window
13507 end pos calculation at the end of this function. */
13508 xassert (first_unchanged_at_end_row
== NULL
13509 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13511 debug_last_unchanged_at_beg_vpos
13512 = (last_unchanged_at_beg_row
13513 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13515 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13517 #endif /* GLYPH_DEBUG != 0 */
13520 /* Display new lines. Set last_text_row to the last new line
13521 displayed which has text on it, i.e. might end up as being the
13522 line where the window_end_vpos is. */
13523 w
->cursor
.vpos
= -1;
13524 last_text_row
= NULL
;
13525 overlay_arrow_seen
= 0;
13526 while (it
.current_y
< it
.last_visible_y
13527 && !fonts_changed_p
13528 && (first_unchanged_at_end_row
== NULL
13529 || IT_CHARPOS (it
) < stop_pos
))
13531 if (display_line (&it
))
13532 last_text_row
= it
.glyph_row
- 1;
13535 if (fonts_changed_p
)
13539 /* Compute differences in buffer positions, y-positions etc. for
13540 lines reused at the bottom of the window. Compute what we can
13542 if (first_unchanged_at_end_row
13543 /* No lines reused because we displayed everything up to the
13544 bottom of the window. */
13545 && it
.current_y
< it
.last_visible_y
)
13548 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13550 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13551 run
.current_y
= first_unchanged_at_end_row
->y
;
13552 run
.desired_y
= run
.current_y
+ dy
;
13553 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13557 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13558 first_unchanged_at_end_row
= NULL
;
13560 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13563 /* Find the cursor if not already found. We have to decide whether
13564 PT will appear on this window (it sometimes doesn't, but this is
13565 not a very frequent case.) This decision has to be made before
13566 the current matrix is altered. A value of cursor.vpos < 0 means
13567 that PT is either in one of the lines beginning at
13568 first_unchanged_at_end_row or below the window. Don't care for
13569 lines that might be displayed later at the window end; as
13570 mentioned, this is not a frequent case. */
13571 if (w
->cursor
.vpos
< 0)
13573 /* Cursor in unchanged rows at the top? */
13574 if (PT
< CHARPOS (start_pos
)
13575 && last_unchanged_at_beg_row
)
13577 row
= row_containing_pos (w
, PT
,
13578 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13579 last_unchanged_at_beg_row
+ 1, 0);
13581 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13584 /* Start from first_unchanged_at_end_row looking for PT. */
13585 else if (first_unchanged_at_end_row
)
13587 row
= row_containing_pos (w
, PT
- delta
,
13588 first_unchanged_at_end_row
, NULL
, 0);
13590 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13591 delta_bytes
, dy
, dvpos
);
13594 /* Give up if cursor was not found. */
13595 if (w
->cursor
.vpos
< 0)
13597 clear_glyph_matrix (w
->desired_matrix
);
13602 /* Don't let the cursor end in the scroll margins. */
13604 int this_scroll_margin
, cursor_height
;
13606 this_scroll_margin
= max (0, scroll_margin
);
13607 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13608 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13609 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13611 if ((w
->cursor
.y
< this_scroll_margin
13612 && CHARPOS (start
) > BEGV
)
13613 /* Old redisplay didn't take scroll margin into account at the bottom,
13614 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
13615 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
13616 ? cursor_height
+ this_scroll_margin
13617 : 1)) > it
.last_visible_y
)
13619 w
->cursor
.vpos
= -1;
13620 clear_glyph_matrix (w
->desired_matrix
);
13625 /* Scroll the display. Do it before changing the current matrix so
13626 that xterm.c doesn't get confused about where the cursor glyph is
13628 if (dy
&& run
.height
)
13632 if (FRAME_WINDOW_P (f
))
13634 rif
->update_window_begin_hook (w
);
13635 rif
->clear_window_mouse_face (w
);
13636 rif
->scroll_run_hook (w
, &run
);
13637 rif
->update_window_end_hook (w
, 0, 0);
13641 /* Terminal frame. In this case, dvpos gives the number of
13642 lines to scroll by; dvpos < 0 means scroll up. */
13643 int first_unchanged_at_end_vpos
13644 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13645 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13646 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13647 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13648 + window_internal_height (w
));
13650 /* Perform the operation on the screen. */
13653 /* Scroll last_unchanged_at_beg_row to the end of the
13654 window down dvpos lines. */
13655 set_terminal_window (end
);
13657 /* On dumb terminals delete dvpos lines at the end
13658 before inserting dvpos empty lines. */
13659 if (!scroll_region_ok
)
13660 ins_del_lines (end
- dvpos
, -dvpos
);
13662 /* Insert dvpos empty lines in front of
13663 last_unchanged_at_beg_row. */
13664 ins_del_lines (from
, dvpos
);
13666 else if (dvpos
< 0)
13668 /* Scroll up last_unchanged_at_beg_vpos to the end of
13669 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13670 set_terminal_window (end
);
13672 /* Delete dvpos lines in front of
13673 last_unchanged_at_beg_vpos. ins_del_lines will set
13674 the cursor to the given vpos and emit |dvpos| delete
13676 ins_del_lines (from
+ dvpos
, dvpos
);
13678 /* On a dumb terminal insert dvpos empty lines at the
13680 if (!scroll_region_ok
)
13681 ins_del_lines (end
+ dvpos
, -dvpos
);
13684 set_terminal_window (0);
13690 /* Shift reused rows of the current matrix to the right position.
13691 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13693 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13694 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13697 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13698 bottom_vpos
, dvpos
);
13699 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13702 else if (dvpos
> 0)
13704 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13705 bottom_vpos
, dvpos
);
13706 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13707 first_unchanged_at_end_vpos
+ dvpos
, 0);
13710 /* For frame-based redisplay, make sure that current frame and window
13711 matrix are in sync with respect to glyph memory. */
13712 if (!FRAME_WINDOW_P (f
))
13713 sync_frame_with_window_matrix_rows (w
);
13715 /* Adjust buffer positions in reused rows. */
13717 increment_matrix_positions (current_matrix
,
13718 first_unchanged_at_end_vpos
+ dvpos
,
13719 bottom_vpos
, delta
, delta_bytes
);
13721 /* Adjust Y positions. */
13723 shift_glyph_matrix (w
, current_matrix
,
13724 first_unchanged_at_end_vpos
+ dvpos
,
13727 if (first_unchanged_at_end_row
)
13728 first_unchanged_at_end_row
+= dvpos
;
13730 /* If scrolling up, there may be some lines to display at the end of
13732 last_text_row_at_end
= NULL
;
13735 /* Scrolling up can leave for example a partially visible line
13736 at the end of the window to be redisplayed. */
13737 /* Set last_row to the glyph row in the current matrix where the
13738 window end line is found. It has been moved up or down in
13739 the matrix by dvpos. */
13740 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13741 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13743 /* If last_row is the window end line, it should display text. */
13744 xassert (last_row
->displays_text_p
);
13746 /* If window end line was partially visible before, begin
13747 displaying at that line. Otherwise begin displaying with the
13748 line following it. */
13749 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13751 init_to_row_start (&it
, w
, last_row
);
13752 it
.vpos
= last_vpos
;
13753 it
.current_y
= last_row
->y
;
13757 init_to_row_end (&it
, w
, last_row
);
13758 it
.vpos
= 1 + last_vpos
;
13759 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13763 /* We may start in a continuation line. If so, we have to
13764 get the right continuation_lines_width and current_x. */
13765 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13766 it
.hpos
= it
.current_x
= 0;
13768 /* Display the rest of the lines at the window end. */
13769 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13770 while (it
.current_y
< it
.last_visible_y
13771 && !fonts_changed_p
)
13773 /* Is it always sure that the display agrees with lines in
13774 the current matrix? I don't think so, so we mark rows
13775 displayed invalid in the current matrix by setting their
13776 enabled_p flag to zero. */
13777 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13778 if (display_line (&it
))
13779 last_text_row_at_end
= it
.glyph_row
- 1;
13783 /* Update window_end_pos and window_end_vpos. */
13784 if (first_unchanged_at_end_row
13785 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13786 && !last_text_row_at_end
)
13788 /* Window end line if one of the preserved rows from the current
13789 matrix. Set row to the last row displaying text in current
13790 matrix starting at first_unchanged_at_end_row, after
13792 xassert (first_unchanged_at_end_row
->displays_text_p
);
13793 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13794 first_unchanged_at_end_row
);
13795 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13797 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13798 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13800 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13801 xassert (w
->window_end_bytepos
>= 0);
13802 IF_DEBUG (debug_method_add (w
, "A"));
13804 else if (last_text_row_at_end
)
13807 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13808 w
->window_end_bytepos
13809 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13811 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13812 xassert (w
->window_end_bytepos
>= 0);
13813 IF_DEBUG (debug_method_add (w
, "B"));
13815 else if (last_text_row
)
13817 /* We have displayed either to the end of the window or at the
13818 end of the window, i.e. the last row with text is to be found
13819 in the desired matrix. */
13821 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13822 w
->window_end_bytepos
13823 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13825 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13826 xassert (w
->window_end_bytepos
>= 0);
13828 else if (first_unchanged_at_end_row
== NULL
13829 && last_text_row
== NULL
13830 && last_text_row_at_end
== NULL
)
13832 /* Displayed to end of window, but no line containing text was
13833 displayed. Lines were deleted at the end of the window. */
13834 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13835 int vpos
= XFASTINT (w
->window_end_vpos
);
13836 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13837 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13840 row
== NULL
&& vpos
>= first_vpos
;
13841 --vpos
, --current_row
, --desired_row
)
13843 if (desired_row
->enabled_p
)
13845 if (desired_row
->displays_text_p
)
13848 else if (current_row
->displays_text_p
)
13852 xassert (row
!= NULL
);
13853 w
->window_end_vpos
= make_number (vpos
+ 1);
13854 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13855 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13856 xassert (w
->window_end_bytepos
>= 0);
13857 IF_DEBUG (debug_method_add (w
, "C"));
13862 #if 0 /* This leads to problems, for instance when the cursor is
13863 at ZV, and the cursor line displays no text. */
13864 /* Disable rows below what's displayed in the window. This makes
13865 debugging easier. */
13866 enable_glyph_matrix_rows (current_matrix
,
13867 XFASTINT (w
->window_end_vpos
) + 1,
13871 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13872 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13874 /* Record that display has not been completed. */
13875 w
->window_end_valid
= Qnil
;
13876 w
->desired_matrix
->no_scrolling_p
= 1;
13884 /***********************************************************************
13885 More debugging support
13886 ***********************************************************************/
13890 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13891 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
13892 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
13895 /* Dump the contents of glyph matrix MATRIX on stderr.
13897 GLYPHS 0 means don't show glyph contents.
13898 GLYPHS 1 means show glyphs in short form
13899 GLYPHS > 1 means show glyphs in long form. */
13902 dump_glyph_matrix (matrix
, glyphs
)
13903 struct glyph_matrix
*matrix
;
13907 for (i
= 0; i
< matrix
->nrows
; ++i
)
13908 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
13912 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
13913 the glyph row and area where the glyph comes from. */
13916 dump_glyph (row
, glyph
, area
)
13917 struct glyph_row
*row
;
13918 struct glyph
*glyph
;
13921 if (glyph
->type
== CHAR_GLYPH
)
13924 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13925 glyph
- row
->glyphs
[TEXT_AREA
],
13928 (BUFFERP (glyph
->object
)
13930 : (STRINGP (glyph
->object
)
13933 glyph
->pixel_width
,
13935 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
13939 glyph
->left_box_line_p
,
13940 glyph
->right_box_line_p
);
13942 else if (glyph
->type
== STRETCH_GLYPH
)
13945 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13946 glyph
- row
->glyphs
[TEXT_AREA
],
13949 (BUFFERP (glyph
->object
)
13951 : (STRINGP (glyph
->object
)
13954 glyph
->pixel_width
,
13958 glyph
->left_box_line_p
,
13959 glyph
->right_box_line_p
);
13961 else if (glyph
->type
== IMAGE_GLYPH
)
13964 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13965 glyph
- row
->glyphs
[TEXT_AREA
],
13968 (BUFFERP (glyph
->object
)
13970 : (STRINGP (glyph
->object
)
13973 glyph
->pixel_width
,
13977 glyph
->left_box_line_p
,
13978 glyph
->right_box_line_p
);
13983 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
13984 GLYPHS 0 means don't show glyph contents.
13985 GLYPHS 1 means show glyphs in short form
13986 GLYPHS > 1 means show glyphs in long form. */
13989 dump_glyph_row (row
, vpos
, glyphs
)
13990 struct glyph_row
*row
;
13995 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
13996 fprintf (stderr
, "=======================================================================\n");
13998 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
13999 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14001 MATRIX_ROW_START_CHARPOS (row
),
14002 MATRIX_ROW_END_CHARPOS (row
),
14003 row
->used
[TEXT_AREA
],
14004 row
->contains_overlapping_glyphs_p
,
14006 row
->truncated_on_left_p
,
14007 row
->truncated_on_right_p
,
14008 row
->overlay_arrow_p
,
14010 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14011 row
->displays_text_p
,
14014 row
->ends_in_middle_of_char_p
,
14015 row
->starts_in_middle_of_char_p
,
14021 row
->visible_height
,
14024 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14025 row
->end
.overlay_string_index
,
14026 row
->continuation_lines_width
);
14027 fprintf (stderr
, "%9d %5d\n",
14028 CHARPOS (row
->start
.string_pos
),
14029 CHARPOS (row
->end
.string_pos
));
14030 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14031 row
->end
.dpvec_index
);
14038 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14040 struct glyph
*glyph
= row
->glyphs
[area
];
14041 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14043 /* Glyph for a line end in text. */
14044 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14047 if (glyph
< glyph_end
)
14048 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14050 for (; glyph
< glyph_end
; ++glyph
)
14051 dump_glyph (row
, glyph
, area
);
14054 else if (glyphs
== 1)
14058 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14060 char *s
= (char *) alloca (row
->used
[area
] + 1);
14063 for (i
= 0; i
< row
->used
[area
]; ++i
)
14065 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14066 if (glyph
->type
== CHAR_GLYPH
14067 && glyph
->u
.ch
< 0x80
14068 && glyph
->u
.ch
>= ' ')
14069 s
[i
] = glyph
->u
.ch
;
14075 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14081 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14082 Sdump_glyph_matrix
, 0, 1, "p",
14083 doc
: /* Dump the current matrix of the selected window to stderr.
14084 Shows contents of glyph row structures. With non-nil
14085 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14086 glyphs in short form, otherwise show glyphs in long form. */)
14088 Lisp_Object glyphs
;
14090 struct window
*w
= XWINDOW (selected_window
);
14091 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14093 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14094 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14095 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14096 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14097 fprintf (stderr
, "=============================================\n");
14098 dump_glyph_matrix (w
->current_matrix
,
14099 NILP (glyphs
) ? 0 : XINT (glyphs
));
14104 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14105 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14108 struct frame
*f
= XFRAME (selected_frame
);
14109 dump_glyph_matrix (f
->current_matrix
, 1);
14114 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14115 doc
: /* Dump glyph row ROW to stderr.
14116 GLYPH 0 means don't dump glyphs.
14117 GLYPH 1 means dump glyphs in short form.
14118 GLYPH > 1 or omitted means dump glyphs in long form. */)
14120 Lisp_Object row
, glyphs
;
14122 struct glyph_matrix
*matrix
;
14125 CHECK_NUMBER (row
);
14126 matrix
= XWINDOW (selected_window
)->current_matrix
;
14128 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14129 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14131 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14136 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14137 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14138 GLYPH 0 means don't dump glyphs.
14139 GLYPH 1 means dump glyphs in short form.
14140 GLYPH > 1 or omitted means dump glyphs in long form. */)
14142 Lisp_Object row
, glyphs
;
14144 struct frame
*sf
= SELECTED_FRAME ();
14145 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14148 CHECK_NUMBER (row
);
14150 if (vpos
>= 0 && vpos
< m
->nrows
)
14151 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14152 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14157 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14158 doc
: /* Toggle tracing of redisplay.
14159 With ARG, turn tracing on if and only if ARG is positive. */)
14164 trace_redisplay_p
= !trace_redisplay_p
;
14167 arg
= Fprefix_numeric_value (arg
);
14168 trace_redisplay_p
= XINT (arg
) > 0;
14175 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14176 doc
: /* Like `format', but print result to stderr.
14177 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14182 Lisp_Object s
= Fformat (nargs
, args
);
14183 fprintf (stderr
, "%s", SDATA (s
));
14187 #endif /* GLYPH_DEBUG */
14191 /***********************************************************************
14192 Building Desired Matrix Rows
14193 ***********************************************************************/
14195 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14196 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14198 static struct glyph_row
*
14199 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14201 Lisp_Object overlay_arrow_string
;
14203 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14204 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14205 struct buffer
*old
= current_buffer
;
14206 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14207 int arrow_len
= SCHARS (overlay_arrow_string
);
14208 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14209 const unsigned char *p
;
14212 int n_glyphs_before
;
14214 set_buffer_temp (buffer
);
14215 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14216 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14217 SET_TEXT_POS (it
.position
, 0, 0);
14219 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14221 while (p
< arrow_end
)
14223 Lisp_Object face
, ilisp
;
14225 /* Get the next character. */
14227 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14229 it
.c
= *p
, it
.len
= 1;
14232 /* Get its face. */
14233 ilisp
= make_number (p
- arrow_string
);
14234 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14235 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14237 /* Compute its width, get its glyphs. */
14238 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14239 SET_TEXT_POS (it
.position
, -1, -1);
14240 PRODUCE_GLYPHS (&it
);
14242 /* If this character doesn't fit any more in the line, we have
14243 to remove some glyphs. */
14244 if (it
.current_x
> it
.last_visible_x
)
14246 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14251 set_buffer_temp (old
);
14252 return it
.glyph_row
;
14256 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14257 glyphs are only inserted for terminal frames since we can't really
14258 win with truncation glyphs when partially visible glyphs are
14259 involved. Which glyphs to insert is determined by
14260 produce_special_glyphs. */
14263 insert_left_trunc_glyphs (it
)
14266 struct it truncate_it
;
14267 struct glyph
*from
, *end
, *to
, *toend
;
14269 xassert (!FRAME_WINDOW_P (it
->f
));
14271 /* Get the truncation glyphs. */
14273 truncate_it
.current_x
= 0;
14274 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14275 truncate_it
.glyph_row
= &scratch_glyph_row
;
14276 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14277 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14278 truncate_it
.object
= make_number (0);
14279 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14281 /* Overwrite glyphs from IT with truncation glyphs. */
14282 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14283 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14284 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14285 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14290 /* There may be padding glyphs left over. Overwrite them too. */
14291 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14293 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14299 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14303 /* Compute the pixel height and width of IT->glyph_row.
14305 Most of the time, ascent and height of a display line will be equal
14306 to the max_ascent and max_height values of the display iterator
14307 structure. This is not the case if
14309 1. We hit ZV without displaying anything. In this case, max_ascent
14310 and max_height will be zero.
14312 2. We have some glyphs that don't contribute to the line height.
14313 (The glyph row flag contributes_to_line_height_p is for future
14314 pixmap extensions).
14316 The first case is easily covered by using default values because in
14317 these cases, the line height does not really matter, except that it
14318 must not be zero. */
14321 compute_line_metrics (it
)
14324 struct glyph_row
*row
= it
->glyph_row
;
14327 if (FRAME_WINDOW_P (it
->f
))
14329 int i
, min_y
, max_y
;
14331 /* The line may consist of one space only, that was added to
14332 place the cursor on it. If so, the row's height hasn't been
14334 if (row
->height
== 0)
14336 if (it
->max_ascent
+ it
->max_descent
== 0)
14337 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14338 row
->ascent
= it
->max_ascent
;
14339 row
->height
= it
->max_ascent
+ it
->max_descent
;
14340 row
->phys_ascent
= it
->max_phys_ascent
;
14341 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14342 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14345 /* Compute the width of this line. */
14346 row
->pixel_width
= row
->x
;
14347 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14348 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14350 xassert (row
->pixel_width
>= 0);
14351 xassert (row
->ascent
>= 0 && row
->height
> 0);
14353 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14354 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14356 /* If first line's physical ascent is larger than its logical
14357 ascent, use the physical ascent, and make the row taller.
14358 This makes accented characters fully visible. */
14359 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14360 && row
->phys_ascent
> row
->ascent
)
14362 row
->height
+= row
->phys_ascent
- row
->ascent
;
14363 row
->ascent
= row
->phys_ascent
;
14366 /* Compute how much of the line is visible. */
14367 row
->visible_height
= row
->height
;
14369 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14370 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14372 if (row
->y
< min_y
)
14373 row
->visible_height
-= min_y
- row
->y
;
14374 if (row
->y
+ row
->height
> max_y
)
14375 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14379 row
->pixel_width
= row
->used
[TEXT_AREA
];
14380 if (row
->continued_p
)
14381 row
->pixel_width
-= it
->continuation_pixel_width
;
14382 else if (row
->truncated_on_right_p
)
14383 row
->pixel_width
-= it
->truncation_pixel_width
;
14384 row
->ascent
= row
->phys_ascent
= 0;
14385 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14386 row
->extra_line_spacing
= 0;
14389 /* Compute a hash code for this row. */
14391 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14392 for (i
= 0; i
< row
->used
[area
]; ++i
)
14393 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14394 + row
->glyphs
[area
][i
].u
.val
14395 + row
->glyphs
[area
][i
].face_id
14396 + row
->glyphs
[area
][i
].padding_p
14397 + (row
->glyphs
[area
][i
].type
<< 2));
14399 it
->max_ascent
= it
->max_descent
= 0;
14400 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14404 /* Append one space to the glyph row of iterator IT if doing a
14405 window-based redisplay. The space has the same face as
14406 IT->face_id. Value is non-zero if a space was added.
14408 This function is called to make sure that there is always one glyph
14409 at the end of a glyph row that the cursor can be set on under
14410 window-systems. (If there weren't such a glyph we would not know
14411 how wide and tall a box cursor should be displayed).
14413 At the same time this space let's a nicely handle clearing to the
14414 end of the line if the row ends in italic text. */
14417 append_space_for_newline (it
, default_face_p
)
14419 int default_face_p
;
14421 if (FRAME_WINDOW_P (it
->f
))
14423 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14425 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14426 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14428 /* Save some values that must not be changed.
14429 Must save IT->c and IT->len because otherwise
14430 ITERATOR_AT_END_P wouldn't work anymore after
14431 append_space_for_newline has been called. */
14432 enum display_element_type saved_what
= it
->what
;
14433 int saved_c
= it
->c
, saved_len
= it
->len
;
14434 int saved_x
= it
->current_x
;
14435 int saved_face_id
= it
->face_id
;
14436 struct text_pos saved_pos
;
14437 Lisp_Object saved_object
;
14440 saved_object
= it
->object
;
14441 saved_pos
= it
->position
;
14443 it
->what
= IT_CHARACTER
;
14444 bzero (&it
->position
, sizeof it
->position
);
14445 it
->object
= make_number (0);
14449 if (default_face_p
)
14450 it
->face_id
= DEFAULT_FACE_ID
;
14451 else if (it
->face_before_selective_p
)
14452 it
->face_id
= it
->saved_face_id
;
14453 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14454 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14456 PRODUCE_GLYPHS (it
);
14458 it
->override_ascent
= -1;
14459 it
->constrain_row_ascent_descent_p
= 0;
14460 it
->current_x
= saved_x
;
14461 it
->object
= saved_object
;
14462 it
->position
= saved_pos
;
14463 it
->what
= saved_what
;
14464 it
->face_id
= saved_face_id
;
14465 it
->len
= saved_len
;
14475 /* Extend the face of the last glyph in the text area of IT->glyph_row
14476 to the end of the display line. Called from display_line.
14477 If the glyph row is empty, add a space glyph to it so that we
14478 know the face to draw. Set the glyph row flag fill_line_p. */
14481 extend_face_to_end_of_line (it
)
14485 struct frame
*f
= it
->f
;
14487 /* If line is already filled, do nothing. */
14488 if (it
->current_x
>= it
->last_visible_x
)
14491 /* Face extension extends the background and box of IT->face_id
14492 to the end of the line. If the background equals the background
14493 of the frame, we don't have to do anything. */
14494 if (it
->face_before_selective_p
)
14495 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14497 face
= FACE_FROM_ID (f
, it
->face_id
);
14499 if (FRAME_WINDOW_P (f
)
14500 && face
->box
== FACE_NO_BOX
14501 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14505 /* Set the glyph row flag indicating that the face of the last glyph
14506 in the text area has to be drawn to the end of the text area. */
14507 it
->glyph_row
->fill_line_p
= 1;
14509 /* If current character of IT is not ASCII, make sure we have the
14510 ASCII face. This will be automatically undone the next time
14511 get_next_display_element returns a multibyte character. Note
14512 that the character will always be single byte in unibyte text. */
14513 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14515 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14518 if (FRAME_WINDOW_P (f
))
14520 /* If the row is empty, add a space with the current face of IT,
14521 so that we know which face to draw. */
14522 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14524 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14525 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14526 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14531 /* Save some values that must not be changed. */
14532 int saved_x
= it
->current_x
;
14533 struct text_pos saved_pos
;
14534 Lisp_Object saved_object
;
14535 enum display_element_type saved_what
= it
->what
;
14536 int saved_face_id
= it
->face_id
;
14538 saved_object
= it
->object
;
14539 saved_pos
= it
->position
;
14541 it
->what
= IT_CHARACTER
;
14542 bzero (&it
->position
, sizeof it
->position
);
14543 it
->object
= make_number (0);
14546 it
->face_id
= face
->id
;
14548 PRODUCE_GLYPHS (it
);
14550 while (it
->current_x
<= it
->last_visible_x
)
14551 PRODUCE_GLYPHS (it
);
14553 /* Don't count these blanks really. It would let us insert a left
14554 truncation glyph below and make us set the cursor on them, maybe. */
14555 it
->current_x
= saved_x
;
14556 it
->object
= saved_object
;
14557 it
->position
= saved_pos
;
14558 it
->what
= saved_what
;
14559 it
->face_id
= saved_face_id
;
14564 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14565 trailing whitespace. */
14568 trailing_whitespace_p (charpos
)
14571 int bytepos
= CHAR_TO_BYTE (charpos
);
14574 while (bytepos
< ZV_BYTE
14575 && (c
= FETCH_CHAR (bytepos
),
14576 c
== ' ' || c
== '\t'))
14579 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14581 if (bytepos
!= PT_BYTE
)
14588 /* Highlight trailing whitespace, if any, in ROW. */
14591 highlight_trailing_whitespace (f
, row
)
14593 struct glyph_row
*row
;
14595 int used
= row
->used
[TEXT_AREA
];
14599 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14600 struct glyph
*glyph
= start
+ used
- 1;
14602 /* Skip over glyphs inserted to display the cursor at the
14603 end of a line, for extending the face of the last glyph
14604 to the end of the line on terminals, and for truncation
14605 and continuation glyphs. */
14606 while (glyph
>= start
14607 && glyph
->type
== CHAR_GLYPH
14608 && INTEGERP (glyph
->object
))
14611 /* If last glyph is a space or stretch, and it's trailing
14612 whitespace, set the face of all trailing whitespace glyphs in
14613 IT->glyph_row to `trailing-whitespace'. */
14615 && BUFFERP (glyph
->object
)
14616 && (glyph
->type
== STRETCH_GLYPH
14617 || (glyph
->type
== CHAR_GLYPH
14618 && glyph
->u
.ch
== ' '))
14619 && trailing_whitespace_p (glyph
->charpos
))
14621 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
14625 while (glyph
>= start
14626 && BUFFERP (glyph
->object
)
14627 && (glyph
->type
== STRETCH_GLYPH
14628 || (glyph
->type
== CHAR_GLYPH
14629 && glyph
->u
.ch
== ' ')))
14630 (glyph
--)->face_id
= face_id
;
14636 /* Value is non-zero if glyph row ROW in window W should be
14637 used to hold the cursor. */
14640 cursor_row_p (w
, row
)
14642 struct glyph_row
*row
;
14644 int cursor_row_p
= 1;
14646 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14648 /* If the row ends with a newline from a string, we don't want
14649 the cursor there (if the row is continued it doesn't end in a
14651 if (CHARPOS (row
->end
.string_pos
) >= 0)
14652 cursor_row_p
= row
->continued_p
;
14653 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14655 /* If the row ends in middle of a real character,
14656 and the line is continued, we want the cursor here.
14657 That's because MATRIX_ROW_END_CHARPOS would equal
14658 PT if PT is before the character. */
14659 if (!row
->ends_in_ellipsis_p
)
14660 cursor_row_p
= row
->continued_p
;
14662 /* If the row ends in an ellipsis, then
14663 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
14664 We want that position to be displayed after the ellipsis. */
14667 /* If the row ends at ZV, display the cursor at the end of that
14668 row instead of at the start of the row below. */
14669 else if (row
->ends_at_zv_p
)
14675 return cursor_row_p
;
14679 /* Construct the glyph row IT->glyph_row in the desired matrix of
14680 IT->w from text at the current position of IT. See dispextern.h
14681 for an overview of struct it. Value is non-zero if
14682 IT->glyph_row displays text, as opposed to a line displaying ZV
14689 struct glyph_row
*row
= it
->glyph_row
;
14690 int overlay_arrow_bitmap
;
14691 Lisp_Object overlay_arrow_string
;
14693 /* We always start displaying at hpos zero even if hscrolled. */
14694 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14696 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14697 >= it
->w
->desired_matrix
->nrows
)
14699 it
->w
->nrows_scale_factor
++;
14700 fonts_changed_p
= 1;
14704 /* Is IT->w showing the region? */
14705 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14707 /* Clear the result glyph row and enable it. */
14708 prepare_desired_row (row
);
14710 row
->y
= it
->current_y
;
14711 row
->start
= it
->start
;
14712 row
->continuation_lines_width
= it
->continuation_lines_width
;
14713 row
->displays_text_p
= 1;
14714 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14715 it
->starts_in_middle_of_char_p
= 0;
14717 /* Arrange the overlays nicely for our purposes. Usually, we call
14718 display_line on only one line at a time, in which case this
14719 can't really hurt too much, or we call it on lines which appear
14720 one after another in the buffer, in which case all calls to
14721 recenter_overlay_lists but the first will be pretty cheap. */
14722 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14724 /* Move over display elements that are not visible because we are
14725 hscrolled. This may stop at an x-position < IT->first_visible_x
14726 if the first glyph is partially visible or if we hit a line end. */
14727 if (it
->current_x
< it
->first_visible_x
)
14729 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14730 MOVE_TO_POS
| MOVE_TO_X
);
14733 /* Get the initial row height. This is either the height of the
14734 text hscrolled, if there is any, or zero. */
14735 row
->ascent
= it
->max_ascent
;
14736 row
->height
= it
->max_ascent
+ it
->max_descent
;
14737 row
->phys_ascent
= it
->max_phys_ascent
;
14738 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14739 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14741 /* Loop generating characters. The loop is left with IT on the next
14742 character to display. */
14745 int n_glyphs_before
, hpos_before
, x_before
;
14747 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14749 /* Retrieve the next thing to display. Value is zero if end of
14751 if (!get_next_display_element (it
))
14753 /* Maybe add a space at the end of this line that is used to
14754 display the cursor there under X. Set the charpos of the
14755 first glyph of blank lines not corresponding to any text
14757 #ifdef HAVE_WINDOW_SYSTEM
14758 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14759 row
->exact_window_width_line_p
= 1;
14761 #endif /* HAVE_WINDOW_SYSTEM */
14762 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14763 || row
->used
[TEXT_AREA
] == 0)
14765 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14766 row
->displays_text_p
= 0;
14768 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14769 && (!MINI_WINDOW_P (it
->w
)
14770 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14771 row
->indicate_empty_line_p
= 1;
14774 it
->continuation_lines_width
= 0;
14775 row
->ends_at_zv_p
= 1;
14779 /* Now, get the metrics of what we want to display. This also
14780 generates glyphs in `row' (which is IT->glyph_row). */
14781 n_glyphs_before
= row
->used
[TEXT_AREA
];
14784 /* Remember the line height so far in case the next element doesn't
14785 fit on the line. */
14786 if (!it
->truncate_lines_p
)
14788 ascent
= it
->max_ascent
;
14789 descent
= it
->max_descent
;
14790 phys_ascent
= it
->max_phys_ascent
;
14791 phys_descent
= it
->max_phys_descent
;
14794 PRODUCE_GLYPHS (it
);
14796 /* If this display element was in marginal areas, continue with
14798 if (it
->area
!= TEXT_AREA
)
14800 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14801 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14802 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14803 row
->phys_height
= max (row
->phys_height
,
14804 it
->max_phys_ascent
+ it
->max_phys_descent
);
14805 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14806 it
->max_extra_line_spacing
);
14807 set_iterator_to_next (it
, 1);
14811 /* Does the display element fit on the line? If we truncate
14812 lines, we should draw past the right edge of the window. If
14813 we don't truncate, we want to stop so that we can display the
14814 continuation glyph before the right margin. If lines are
14815 continued, there are two possible strategies for characters
14816 resulting in more than 1 glyph (e.g. tabs): Display as many
14817 glyphs as possible in this line and leave the rest for the
14818 continuation line, or display the whole element in the next
14819 line. Original redisplay did the former, so we do it also. */
14820 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14821 hpos_before
= it
->hpos
;
14824 if (/* Not a newline. */
14826 /* Glyphs produced fit entirely in the line. */
14827 && it
->current_x
< it
->last_visible_x
)
14829 it
->hpos
+= nglyphs
;
14830 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14831 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14832 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14833 row
->phys_height
= max (row
->phys_height
,
14834 it
->max_phys_ascent
+ it
->max_phys_descent
);
14835 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14836 it
->max_extra_line_spacing
);
14837 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14838 row
->x
= x
- it
->first_visible_x
;
14843 struct glyph
*glyph
;
14845 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14847 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14848 new_x
= x
+ glyph
->pixel_width
;
14850 if (/* Lines are continued. */
14851 !it
->truncate_lines_p
14852 && (/* Glyph doesn't fit on the line. */
14853 new_x
> it
->last_visible_x
14854 /* Or it fits exactly on a window system frame. */
14855 || (new_x
== it
->last_visible_x
14856 && FRAME_WINDOW_P (it
->f
))))
14858 /* End of a continued line. */
14861 || (new_x
== it
->last_visible_x
14862 && FRAME_WINDOW_P (it
->f
)))
14864 /* Current glyph is the only one on the line or
14865 fits exactly on the line. We must continue
14866 the line because we can't draw the cursor
14867 after the glyph. */
14868 row
->continued_p
= 1;
14869 it
->current_x
= new_x
;
14870 it
->continuation_lines_width
+= new_x
;
14872 if (i
== nglyphs
- 1)
14874 set_iterator_to_next (it
, 1);
14875 #ifdef HAVE_WINDOW_SYSTEM
14876 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
14878 if (!get_next_display_element (it
))
14880 row
->exact_window_width_line_p
= 1;
14881 it
->continuation_lines_width
= 0;
14882 row
->continued_p
= 0;
14883 row
->ends_at_zv_p
= 1;
14885 else if (ITERATOR_AT_END_OF_LINE_P (it
))
14887 row
->continued_p
= 0;
14888 row
->exact_window_width_line_p
= 1;
14891 #endif /* HAVE_WINDOW_SYSTEM */
14894 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14895 && !FRAME_WINDOW_P (it
->f
))
14897 /* A padding glyph that doesn't fit on this line.
14898 This means the whole character doesn't fit
14900 row
->used
[TEXT_AREA
] = n_glyphs_before
;
14902 /* Fill the rest of the row with continuation
14903 glyphs like in 20.x. */
14904 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
14905 < row
->glyphs
[1 + TEXT_AREA
])
14906 produce_special_glyphs (it
, IT_CONTINUATION
);
14908 row
->continued_p
= 1;
14909 it
->current_x
= x_before
;
14910 it
->continuation_lines_width
+= x_before
;
14912 /* Restore the height to what it was before the
14913 element not fitting on the line. */
14914 it
->max_ascent
= ascent
;
14915 it
->max_descent
= descent
;
14916 it
->max_phys_ascent
= phys_ascent
;
14917 it
->max_phys_descent
= phys_descent
;
14919 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
14921 /* A TAB that extends past the right edge of the
14922 window. This produces a single glyph on
14923 window system frames. We leave the glyph in
14924 this row and let it fill the row, but don't
14925 consume the TAB. */
14926 it
->continuation_lines_width
+= it
->last_visible_x
;
14927 row
->ends_in_middle_of_char_p
= 1;
14928 row
->continued_p
= 1;
14929 glyph
->pixel_width
= it
->last_visible_x
- x
;
14930 it
->starts_in_middle_of_char_p
= 1;
14934 /* Something other than a TAB that draws past
14935 the right edge of the window. Restore
14936 positions to values before the element. */
14937 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14939 /* Display continuation glyphs. */
14940 if (!FRAME_WINDOW_P (it
->f
))
14941 produce_special_glyphs (it
, IT_CONTINUATION
);
14942 row
->continued_p
= 1;
14944 it
->continuation_lines_width
+= x
;
14946 if (nglyphs
> 1 && i
> 0)
14948 row
->ends_in_middle_of_char_p
= 1;
14949 it
->starts_in_middle_of_char_p
= 1;
14952 /* Restore the height to what it was before the
14953 element not fitting on the line. */
14954 it
->max_ascent
= ascent
;
14955 it
->max_descent
= descent
;
14956 it
->max_phys_ascent
= phys_ascent
;
14957 it
->max_phys_descent
= phys_descent
;
14962 else if (new_x
> it
->first_visible_x
)
14964 /* Increment number of glyphs actually displayed. */
14967 if (x
< it
->first_visible_x
)
14968 /* Glyph is partially visible, i.e. row starts at
14969 negative X position. */
14970 row
->x
= x
- it
->first_visible_x
;
14974 /* Glyph is completely off the left margin of the
14975 window. This should not happen because of the
14976 move_it_in_display_line at the start of this
14977 function, unless the text display area of the
14978 window is empty. */
14979 xassert (it
->first_visible_x
<= it
->last_visible_x
);
14983 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14984 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14985 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14986 row
->phys_height
= max (row
->phys_height
,
14987 it
->max_phys_ascent
+ it
->max_phys_descent
);
14988 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
14989 it
->max_extra_line_spacing
);
14991 /* End of this display line if row is continued. */
14992 if (row
->continued_p
|| row
->ends_at_zv_p
)
14997 /* Is this a line end? If yes, we're also done, after making
14998 sure that a non-default face is extended up to the right
14999 margin of the window. */
15000 if (ITERATOR_AT_END_OF_LINE_P (it
))
15002 int used_before
= row
->used
[TEXT_AREA
];
15004 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15006 #ifdef HAVE_WINDOW_SYSTEM
15007 /* Add a space at the end of the line that is used to
15008 display the cursor there. */
15009 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15010 append_space_for_newline (it
, 0);
15011 #endif /* HAVE_WINDOW_SYSTEM */
15013 /* Extend the face to the end of the line. */
15014 extend_face_to_end_of_line (it
);
15016 /* Make sure we have the position. */
15017 if (used_before
== 0)
15018 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15020 /* Consume the line end. This skips over invisible lines. */
15021 set_iterator_to_next (it
, 1);
15022 it
->continuation_lines_width
= 0;
15026 /* Proceed with next display element. Note that this skips
15027 over lines invisible because of selective display. */
15028 set_iterator_to_next (it
, 1);
15030 /* If we truncate lines, we are done when the last displayed
15031 glyphs reach past the right margin of the window. */
15032 if (it
->truncate_lines_p
15033 && (FRAME_WINDOW_P (it
->f
)
15034 ? (it
->current_x
>= it
->last_visible_x
)
15035 : (it
->current_x
> it
->last_visible_x
)))
15037 /* Maybe add truncation glyphs. */
15038 if (!FRAME_WINDOW_P (it
->f
))
15042 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15043 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15046 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15048 row
->used
[TEXT_AREA
] = i
;
15049 produce_special_glyphs (it
, IT_TRUNCATION
);
15052 #ifdef HAVE_WINDOW_SYSTEM
15055 /* Don't truncate if we can overflow newline into fringe. */
15056 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15058 if (!get_next_display_element (it
))
15060 it
->continuation_lines_width
= 0;
15061 row
->ends_at_zv_p
= 1;
15062 row
->exact_window_width_line_p
= 1;
15065 if (ITERATOR_AT_END_OF_LINE_P (it
))
15067 row
->exact_window_width_line_p
= 1;
15068 goto at_end_of_line
;
15072 #endif /* HAVE_WINDOW_SYSTEM */
15074 row
->truncated_on_right_p
= 1;
15075 it
->continuation_lines_width
= 0;
15076 reseat_at_next_visible_line_start (it
, 0);
15077 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15078 it
->hpos
= hpos_before
;
15079 it
->current_x
= x_before
;
15084 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15085 at the left window margin. */
15086 if (it
->first_visible_x
15087 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15089 if (!FRAME_WINDOW_P (it
->f
))
15090 insert_left_trunc_glyphs (it
);
15091 row
->truncated_on_left_p
= 1;
15094 /* If the start of this line is the overlay arrow-position, then
15095 mark this glyph row as the one containing the overlay arrow.
15096 This is clearly a mess with variable size fonts. It would be
15097 better to let it be displayed like cursors under X. */
15098 if (! overlay_arrow_seen
15099 && (overlay_arrow_string
15100 = overlay_arrow_at_row (it
, row
, &overlay_arrow_bitmap
),
15101 !NILP (overlay_arrow_string
)))
15103 /* Overlay arrow in window redisplay is a fringe bitmap. */
15104 if (STRINGP (overlay_arrow_string
))
15106 struct glyph_row
*arrow_row
15107 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15108 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15109 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15110 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15111 struct glyph
*p2
, *end
;
15113 /* Copy the arrow glyphs. */
15114 while (glyph
< arrow_end
)
15117 /* Throw away padding glyphs. */
15119 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15120 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15126 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15131 it
->w
->overlay_arrow_bitmap
= overlay_arrow_bitmap
;
15132 row
->overlay_arrow_p
= 1;
15134 overlay_arrow_seen
= 1;
15137 /* Compute pixel dimensions of this line. */
15138 compute_line_metrics (it
);
15140 /* Remember the position at which this line ends. */
15141 row
->end
= it
->current
;
15143 /* Record whether this row ends inside an ellipsis. */
15144 row
->ends_in_ellipsis_p
15145 = (it
->method
== next_element_from_display_vector
15146 && it
->ellipsis_p
);
15148 /* Save fringe bitmaps in this row. */
15149 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15150 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15151 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15152 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15154 it
->left_user_fringe_bitmap
= 0;
15155 it
->left_user_fringe_face_id
= 0;
15156 it
->right_user_fringe_bitmap
= 0;
15157 it
->right_user_fringe_face_id
= 0;
15159 /* Maybe set the cursor. */
15160 if (it
->w
->cursor
.vpos
< 0
15161 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15162 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15163 && cursor_row_p (it
->w
, row
))
15164 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15166 /* Highlight trailing whitespace. */
15167 if (!NILP (Vshow_trailing_whitespace
))
15168 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15170 /* Prepare for the next line. This line starts horizontally at (X
15171 HPOS) = (0 0). Vertical positions are incremented. As a
15172 convenience for the caller, IT->glyph_row is set to the next
15174 it
->current_x
= it
->hpos
= 0;
15175 it
->current_y
+= row
->height
;
15178 it
->start
= it
->current
;
15179 return row
->displays_text_p
;
15184 /***********************************************************************
15186 ***********************************************************************/
15188 /* Redisplay the menu bar in the frame for window W.
15190 The menu bar of X frames that don't have X toolkit support is
15191 displayed in a special window W->frame->menu_bar_window.
15193 The menu bar of terminal frames is treated specially as far as
15194 glyph matrices are concerned. Menu bar lines are not part of
15195 windows, so the update is done directly on the frame matrix rows
15196 for the menu bar. */
15199 display_menu_bar (w
)
15202 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15207 /* Don't do all this for graphical frames. */
15209 if (!NILP (Vwindow_system
))
15212 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15217 if (FRAME_MAC_P (f
))
15221 #ifdef USE_X_TOOLKIT
15222 xassert (!FRAME_WINDOW_P (f
));
15223 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15224 it
.first_visible_x
= 0;
15225 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15226 #else /* not USE_X_TOOLKIT */
15227 if (FRAME_WINDOW_P (f
))
15229 /* Menu bar lines are displayed in the desired matrix of the
15230 dummy window menu_bar_window. */
15231 struct window
*menu_w
;
15232 xassert (WINDOWP (f
->menu_bar_window
));
15233 menu_w
= XWINDOW (f
->menu_bar_window
);
15234 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15236 it
.first_visible_x
= 0;
15237 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15241 /* This is a TTY frame, i.e. character hpos/vpos are used as
15243 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15245 it
.first_visible_x
= 0;
15246 it
.last_visible_x
= FRAME_COLS (f
);
15248 #endif /* not USE_X_TOOLKIT */
15250 if (! mode_line_inverse_video
)
15251 /* Force the menu-bar to be displayed in the default face. */
15252 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15254 /* Clear all rows of the menu bar. */
15255 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15257 struct glyph_row
*row
= it
.glyph_row
+ i
;
15258 clear_glyph_row (row
);
15259 row
->enabled_p
= 1;
15260 row
->full_width_p
= 1;
15263 /* Display all items of the menu bar. */
15264 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15265 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15267 Lisp_Object string
;
15269 /* Stop at nil string. */
15270 string
= AREF (items
, i
+ 1);
15274 /* Remember where item was displayed. */
15275 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15277 /* Display the item, pad with one space. */
15278 if (it
.current_x
< it
.last_visible_x
)
15279 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15280 SCHARS (string
) + 1, 0, 0, -1);
15283 /* Fill out the line with spaces. */
15284 if (it
.current_x
< it
.last_visible_x
)
15285 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15287 /* Compute the total height of the lines. */
15288 compute_line_metrics (&it
);
15293 /***********************************************************************
15295 ***********************************************************************/
15297 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15298 FORCE is non-zero, redisplay mode lines unconditionally.
15299 Otherwise, redisplay only mode lines that are garbaged. Value is
15300 the number of windows whose mode lines were redisplayed. */
15303 redisplay_mode_lines (window
, force
)
15304 Lisp_Object window
;
15309 while (!NILP (window
))
15311 struct window
*w
= XWINDOW (window
);
15313 if (WINDOWP (w
->hchild
))
15314 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15315 else if (WINDOWP (w
->vchild
))
15316 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15318 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15319 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15321 struct text_pos lpoint
;
15322 struct buffer
*old
= current_buffer
;
15324 /* Set the window's buffer for the mode line display. */
15325 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15326 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15328 /* Point refers normally to the selected window. For any
15329 other window, set up appropriate value. */
15330 if (!EQ (window
, selected_window
))
15332 struct text_pos pt
;
15334 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15335 if (CHARPOS (pt
) < BEGV
)
15336 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15337 else if (CHARPOS (pt
) > (ZV
- 1))
15338 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15340 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15343 /* Display mode lines. */
15344 clear_glyph_matrix (w
->desired_matrix
);
15345 if (display_mode_lines (w
))
15348 w
->must_be_updated_p
= 1;
15351 /* Restore old settings. */
15352 set_buffer_internal_1 (old
);
15353 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15363 /* Display the mode and/or top line of window W. Value is the number
15364 of mode lines displayed. */
15367 display_mode_lines (w
)
15370 Lisp_Object old_selected_window
, old_selected_frame
;
15373 old_selected_frame
= selected_frame
;
15374 selected_frame
= w
->frame
;
15375 old_selected_window
= selected_window
;
15376 XSETWINDOW (selected_window
, w
);
15378 /* These will be set while the mode line specs are processed. */
15379 line_number_displayed
= 0;
15380 w
->column_number_displayed
= Qnil
;
15382 if (WINDOW_WANTS_MODELINE_P (w
))
15384 struct window
*sel_w
= XWINDOW (old_selected_window
);
15386 /* Select mode line face based on the real selected window. */
15387 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15388 current_buffer
->mode_line_format
);
15392 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15394 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15395 current_buffer
->header_line_format
);
15399 selected_frame
= old_selected_frame
;
15400 selected_window
= old_selected_window
;
15405 /* Display mode or top line of window W. FACE_ID specifies which line
15406 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15407 FORMAT is the mode line format to display. Value is the pixel
15408 height of the mode line displayed. */
15411 display_mode_line (w
, face_id
, format
)
15413 enum face_id face_id
;
15414 Lisp_Object format
;
15419 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15420 prepare_desired_row (it
.glyph_row
);
15422 it
.glyph_row
->mode_line_p
= 1;
15424 if (! mode_line_inverse_video
)
15425 /* Force the mode-line to be displayed in the default face. */
15426 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15428 /* Temporarily make frame's keyboard the current kboard so that
15429 kboard-local variables in the mode_line_format will get the right
15431 push_frame_kboard (it
.f
);
15432 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15433 pop_frame_kboard ();
15435 /* Fill up with spaces. */
15436 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15438 compute_line_metrics (&it
);
15439 it
.glyph_row
->full_width_p
= 1;
15440 it
.glyph_row
->continued_p
= 0;
15441 it
.glyph_row
->truncated_on_left_p
= 0;
15442 it
.glyph_row
->truncated_on_right_p
= 0;
15444 /* Make a 3D mode-line have a shadow at its right end. */
15445 face
= FACE_FROM_ID (it
.f
, face_id
);
15446 extend_face_to_end_of_line (&it
);
15447 if (face
->box
!= FACE_NO_BOX
)
15449 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15450 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15451 last
->right_box_line_p
= 1;
15454 return it
.glyph_row
->height
;
15457 /* Alist that caches the results of :propertize.
15458 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
15459 Lisp_Object mode_line_proptrans_alist
;
15461 /* List of strings making up the mode-line. */
15462 Lisp_Object mode_line_string_list
;
15464 /* Base face property when building propertized mode line string. */
15465 static Lisp_Object mode_line_string_face
;
15466 static Lisp_Object mode_line_string_face_prop
;
15469 /* Contribute ELT to the mode line for window IT->w. How it
15470 translates into text depends on its data type.
15472 IT describes the display environment in which we display, as usual.
15474 DEPTH is the depth in recursion. It is used to prevent
15475 infinite recursion here.
15477 FIELD_WIDTH is the number of characters the display of ELT should
15478 occupy in the mode line, and PRECISION is the maximum number of
15479 characters to display from ELT's representation. See
15480 display_string for details.
15482 Returns the hpos of the end of the text generated by ELT.
15484 PROPS is a property list to add to any string we encounter.
15486 If RISKY is nonzero, remove (disregard) any properties in any string
15487 we encounter, and ignore :eval and :propertize.
15489 If the global variable `frame_title_ptr' is non-NULL, then the output
15490 is passed to `store_frame_title' instead of `display_string'. */
15493 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15496 int field_width
, precision
;
15497 Lisp_Object elt
, props
;
15500 int n
= 0, field
, prec
;
15505 elt
= build_string ("*too-deep*");
15509 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15513 /* A string: output it and check for %-constructs within it. */
15515 const unsigned char *this, *lisp_string
;
15517 if (!NILP (props
) || risky
)
15519 Lisp_Object oprops
, aelt
;
15520 oprops
= Ftext_properties_at (make_number (0), elt
);
15522 /* If the starting string's properties are not what
15523 we want, translate the string. Also, if the string
15524 is risky, do that anyway. */
15526 if (NILP (Fequal (props
, oprops
)) || risky
)
15528 /* If the starting string has properties,
15529 merge the specified ones onto the existing ones. */
15530 if (! NILP (oprops
) && !risky
)
15534 oprops
= Fcopy_sequence (oprops
);
15536 while (CONSP (tem
))
15538 oprops
= Fplist_put (oprops
, XCAR (tem
),
15539 XCAR (XCDR (tem
)));
15540 tem
= XCDR (XCDR (tem
));
15545 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15546 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15548 mode_line_proptrans_alist
15549 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15556 elt
= Fcopy_sequence (elt
);
15557 Fset_text_properties (make_number (0), Flength (elt
),
15559 /* Add this item to mode_line_proptrans_alist. */
15560 mode_line_proptrans_alist
15561 = Fcons (Fcons (elt
, props
),
15562 mode_line_proptrans_alist
);
15563 /* Truncate mode_line_proptrans_alist
15564 to at most 50 elements. */
15565 tem
= Fnthcdr (make_number (50),
15566 mode_line_proptrans_alist
);
15568 XSETCDR (tem
, Qnil
);
15573 this = SDATA (elt
);
15574 lisp_string
= this;
15578 prec
= precision
- n
;
15579 if (frame_title_ptr
)
15580 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15581 else if (!NILP (mode_line_string_list
))
15582 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15584 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15585 0, prec
, 0, STRING_MULTIBYTE (elt
));
15590 while ((precision
<= 0 || n
< precision
)
15592 && (frame_title_ptr
15593 || !NILP (mode_line_string_list
)
15594 || it
->current_x
< it
->last_visible_x
))
15596 const unsigned char *last
= this;
15598 /* Advance to end of string or next format specifier. */
15599 while ((c
= *this++) != '\0' && c
!= '%')
15602 if (this - 1 != last
)
15604 int nchars
, nbytes
;
15606 /* Output to end of string or up to '%'. Field width
15607 is length of string. Don't output more than
15608 PRECISION allows us. */
15611 prec
= c_string_width (last
, this - last
, precision
- n
,
15614 if (frame_title_ptr
)
15615 n
+= store_frame_title (last
, 0, prec
);
15616 else if (!NILP (mode_line_string_list
))
15618 int bytepos
= last
- lisp_string
;
15619 int charpos
= string_byte_to_char (elt
, bytepos
);
15620 int endpos
= (precision
<= 0
15621 ? string_byte_to_char (elt
,
15622 this - lisp_string
)
15623 : charpos
+ nchars
);
15625 n
+= store_mode_line_string (NULL
,
15626 Fsubstring (elt
, make_number (charpos
),
15627 make_number (endpos
)),
15632 int bytepos
= last
- lisp_string
;
15633 int charpos
= string_byte_to_char (elt
, bytepos
);
15634 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15636 STRING_MULTIBYTE (elt
));
15639 else /* c == '%' */
15641 const unsigned char *percent_position
= this;
15643 /* Get the specified minimum width. Zero means
15646 while ((c
= *this++) >= '0' && c
<= '9')
15647 field
= field
* 10 + c
- '0';
15649 /* Don't pad beyond the total padding allowed. */
15650 if (field_width
- n
> 0 && field
> field_width
- n
)
15651 field
= field_width
- n
;
15653 /* Note that either PRECISION <= 0 or N < PRECISION. */
15654 prec
= precision
- n
;
15657 n
+= display_mode_element (it
, depth
, field
, prec
,
15658 Vglobal_mode_string
, props
,
15663 int bytepos
, charpos
;
15664 unsigned char *spec
;
15666 bytepos
= percent_position
- lisp_string
;
15667 charpos
= (STRING_MULTIBYTE (elt
)
15668 ? string_byte_to_char (elt
, bytepos
)
15672 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15674 if (frame_title_ptr
)
15675 n
+= store_frame_title (spec
, field
, prec
);
15676 else if (!NILP (mode_line_string_list
))
15678 int len
= strlen (spec
);
15679 Lisp_Object tem
= make_string (spec
, len
);
15680 props
= Ftext_properties_at (make_number (charpos
), elt
);
15681 /* Should only keep face property in props */
15682 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15686 int nglyphs_before
, nwritten
;
15688 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15689 nwritten
= display_string (spec
, Qnil
, elt
,
15694 /* Assign to the glyphs written above the
15695 string where the `%x' came from, position
15699 struct glyph
*glyph
15700 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15704 for (i
= 0; i
< nwritten
; ++i
)
15706 glyph
[i
].object
= elt
;
15707 glyph
[i
].charpos
= charpos
;
15722 /* A symbol: process the value of the symbol recursively
15723 as if it appeared here directly. Avoid error if symbol void.
15724 Special case: if value of symbol is a string, output the string
15727 register Lisp_Object tem
;
15729 /* If the variable is not marked as risky to set
15730 then its contents are risky to use. */
15731 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15734 tem
= Fboundp (elt
);
15737 tem
= Fsymbol_value (elt
);
15738 /* If value is a string, output that string literally:
15739 don't check for % within it. */
15743 if (!EQ (tem
, elt
))
15745 /* Give up right away for nil or t. */
15755 register Lisp_Object car
, tem
;
15757 /* A cons cell: five distinct cases.
15758 If first element is :eval or :propertize, do something special.
15759 If first element is a string or a cons, process all the elements
15760 and effectively concatenate them.
15761 If first element is a negative number, truncate displaying cdr to
15762 at most that many characters. If positive, pad (with spaces)
15763 to at least that many characters.
15764 If first element is a symbol, process the cadr or caddr recursively
15765 according to whether the symbol's value is non-nil or nil. */
15767 if (EQ (car
, QCeval
))
15769 /* An element of the form (:eval FORM) means evaluate FORM
15770 and use the result as mode line elements. */
15775 if (CONSP (XCDR (elt
)))
15778 spec
= safe_eval (XCAR (XCDR (elt
)));
15779 n
+= display_mode_element (it
, depth
, field_width
- n
,
15780 precision
- n
, spec
, props
,
15784 else if (EQ (car
, QCpropertize
))
15786 /* An element of the form (:propertize ELT PROPS...)
15787 means display ELT but applying properties PROPS. */
15792 if (CONSP (XCDR (elt
)))
15793 n
+= display_mode_element (it
, depth
, field_width
- n
,
15794 precision
- n
, XCAR (XCDR (elt
)),
15795 XCDR (XCDR (elt
)), risky
);
15797 else if (SYMBOLP (car
))
15799 tem
= Fboundp (car
);
15803 /* elt is now the cdr, and we know it is a cons cell.
15804 Use its car if CAR has a non-nil value. */
15807 tem
= Fsymbol_value (car
);
15814 /* Symbol's value is nil (or symbol is unbound)
15815 Get the cddr of the original list
15816 and if possible find the caddr and use that. */
15820 else if (!CONSP (elt
))
15825 else if (INTEGERP (car
))
15827 register int lim
= XINT (car
);
15831 /* Negative int means reduce maximum width. */
15832 if (precision
<= 0)
15835 precision
= min (precision
, -lim
);
15839 /* Padding specified. Don't let it be more than
15840 current maximum. */
15842 lim
= min (precision
, lim
);
15844 /* If that's more padding than already wanted, queue it.
15845 But don't reduce padding already specified even if
15846 that is beyond the current truncation point. */
15847 field_width
= max (lim
, field_width
);
15851 else if (STRINGP (car
) || CONSP (car
))
15853 register int limit
= 50;
15854 /* Limit is to protect against circular lists. */
15857 && (precision
<= 0 || n
< precision
))
15859 n
+= display_mode_element (it
, depth
, field_width
- n
,
15860 precision
- n
, XCAR (elt
),
15870 elt
= build_string ("*invalid*");
15874 /* Pad to FIELD_WIDTH. */
15875 if (field_width
> 0 && n
< field_width
)
15877 if (frame_title_ptr
)
15878 n
+= store_frame_title ("", field_width
- n
, 0);
15879 else if (!NILP (mode_line_string_list
))
15880 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15882 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15889 /* Store a mode-line string element in mode_line_string_list.
15891 If STRING is non-null, display that C string. Otherwise, the Lisp
15892 string LISP_STRING is displayed.
15894 FIELD_WIDTH is the minimum number of output glyphs to produce.
15895 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15896 with spaces. FIELD_WIDTH <= 0 means don't pad.
15898 PRECISION is the maximum number of characters to output from
15899 STRING. PRECISION <= 0 means don't truncate the string.
15901 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
15902 properties to the string.
15904 PROPS are the properties to add to the string.
15905 The mode_line_string_face face property is always added to the string.
15909 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
15911 Lisp_Object lisp_string
;
15920 if (string
!= NULL
)
15922 len
= strlen (string
);
15923 if (precision
> 0 && len
> precision
)
15925 lisp_string
= make_string (string
, len
);
15927 props
= mode_line_string_face_prop
;
15928 else if (!NILP (mode_line_string_face
))
15930 Lisp_Object face
= Fsafe_plist_get (props
, Qface
);
15931 props
= Fcopy_sequence (props
);
15933 face
= mode_line_string_face
;
15935 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15936 props
= Fplist_put (props
, Qface
, face
);
15938 Fadd_text_properties (make_number (0), make_number (len
),
15939 props
, lisp_string
);
15943 len
= XFASTINT (Flength (lisp_string
));
15944 if (precision
> 0 && len
> precision
)
15947 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
15950 if (!NILP (mode_line_string_face
))
15954 props
= Ftext_properties_at (make_number (0), lisp_string
);
15955 face
= Fsafe_plist_get (props
, Qface
);
15957 face
= mode_line_string_face
;
15959 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15960 props
= Fcons (Qface
, Fcons (face
, Qnil
));
15962 lisp_string
= Fcopy_sequence (lisp_string
);
15965 Fadd_text_properties (make_number (0), make_number (len
),
15966 props
, lisp_string
);
15971 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15975 if (field_width
> len
)
15977 field_width
-= len
;
15978 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
15980 Fadd_text_properties (make_number (0), make_number (field_width
),
15981 props
, lisp_string
);
15982 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15990 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
15992 doc
: /* Return the mode-line of selected window as a string.
15993 First arg FORMAT specifies the mode line format (see `mode-line-format' for
15994 details) to use. Second optional arg WINDOW specifies a different window to
15995 use as the context for the formatting. If third optional arg NO-PROPS is
15996 non-nil, string is not propertized. Fourth optional arg BUFFER specifies
15997 which buffer to use. */)
15998 (format
, window
, no_props
, buffer
)
15999 Lisp_Object format
, window
, no_props
, buffer
;
16004 struct buffer
*old_buffer
= NULL
;
16005 enum face_id face_id
= DEFAULT_FACE_ID
;
16008 window
= selected_window
;
16009 CHECK_WINDOW (window
);
16010 w
= XWINDOW (window
);
16013 buffer
= w
->buffer
;
16015 CHECK_BUFFER (buffer
);
16017 if (XBUFFER (buffer
) != current_buffer
)
16019 old_buffer
= current_buffer
;
16020 set_buffer_internal_1 (XBUFFER (buffer
));
16023 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16025 if (NILP (no_props
))
16027 mode_line_string_face
16028 = (face_id
== MODE_LINE_FACE_ID
? Qmode_line
16029 : face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
16030 : face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
16032 mode_line_string_face_prop
16033 = (NILP (mode_line_string_face
) ? Qnil
16034 : Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
)));
16036 /* We need a dummy last element in mode_line_string_list to
16037 indicate we are building the propertized mode-line string.
16038 Using mode_line_string_face_prop here GC protects it. */
16039 mode_line_string_list
16040 = Fcons (mode_line_string_face_prop
, Qnil
);
16041 frame_title_ptr
= NULL
;
16045 mode_line_string_face_prop
= Qnil
;
16046 mode_line_string_list
= Qnil
;
16047 frame_title_ptr
= frame_title_buf
;
16050 push_frame_kboard (it
.f
);
16051 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16052 pop_frame_kboard ();
16055 set_buffer_internal_1 (old_buffer
);
16057 if (NILP (no_props
))
16060 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16061 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
16062 make_string ("", 0));
16063 mode_line_string_face_prop
= Qnil
;
16064 mode_line_string_list
= Qnil
;
16068 len
= frame_title_ptr
- frame_title_buf
;
16069 if (len
> 0 && frame_title_ptr
[-1] == '-')
16071 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
16072 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
16074 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
16075 if (len
> frame_title_ptr
- frame_title_buf
)
16076 len
= frame_title_ptr
- frame_title_buf
;
16079 frame_title_ptr
= NULL
;
16080 return make_string (frame_title_buf
, len
);
16083 /* Write a null-terminated, right justified decimal representation of
16084 the positive integer D to BUF using a minimal field width WIDTH. */
16087 pint2str (buf
, width
, d
)
16088 register char *buf
;
16089 register int width
;
16092 register char *p
= buf
;
16100 *p
++ = d
% 10 + '0';
16105 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16116 /* Write a null-terminated, right justified decimal and "human
16117 readable" representation of the nonnegative integer D to BUF using
16118 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16120 static const char power_letter
[] =
16134 pint2hrstr (buf
, width
, d
)
16139 /* We aim to represent the nonnegative integer D as
16140 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16143 /* -1 means: do not use TENTHS. */
16147 /* Length of QUOTIENT.TENTHS as a string. */
16153 if (1000 <= quotient
)
16155 /* Scale to the appropriate EXPONENT. */
16158 remainder
= quotient
% 1000;
16162 while (1000 <= quotient
);
16164 /* Round to nearest and decide whether to use TENTHS or not. */
16167 tenths
= remainder
/ 100;
16168 if (50 <= remainder
% 100)
16175 if (quotient
== 10)
16183 if (500 <= remainder
)
16185 if (quotient
< 999)
16196 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16197 if (tenths
== -1 && quotient
<= 99)
16204 p
= psuffix
= buf
+ max (width
, length
);
16206 /* Print EXPONENT. */
16208 *psuffix
++ = power_letter
[exponent
];
16211 /* Print TENTHS. */
16214 *--p
= '0' + tenths
;
16218 /* Print QUOTIENT. */
16221 int digit
= quotient
% 10;
16222 *--p
= '0' + digit
;
16224 while ((quotient
/= 10) != 0);
16226 /* Print leading spaces. */
16231 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16232 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16233 type of CODING_SYSTEM. Return updated pointer into BUF. */
16235 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16238 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16239 Lisp_Object coding_system
;
16240 register char *buf
;
16244 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16245 const unsigned char *eol_str
;
16247 /* The EOL conversion we are using. */
16248 Lisp_Object eoltype
;
16250 val
= Fget (coding_system
, Qcoding_system
);
16253 if (!VECTORP (val
)) /* Not yet decided. */
16258 eoltype
= eol_mnemonic_undecided
;
16259 /* Don't mention EOL conversion if it isn't decided. */
16263 Lisp_Object eolvalue
;
16265 eolvalue
= Fget (coding_system
, Qeol_type
);
16268 *buf
++ = XFASTINT (AREF (val
, 1));
16272 /* The EOL conversion that is normal on this system. */
16274 if (NILP (eolvalue
)) /* Not yet decided. */
16275 eoltype
= eol_mnemonic_undecided
;
16276 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16277 eoltype
= eol_mnemonic_undecided
;
16278 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
16279 eoltype
= (XFASTINT (eolvalue
) == 0
16280 ? eol_mnemonic_unix
16281 : (XFASTINT (eolvalue
) == 1
16282 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16288 /* Mention the EOL conversion if it is not the usual one. */
16289 if (STRINGP (eoltype
))
16291 eol_str
= SDATA (eoltype
);
16292 eol_str_len
= SBYTES (eoltype
);
16294 else if (INTEGERP (eoltype
)
16295 && CHAR_VALID_P (XINT (eoltype
), 0))
16297 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16298 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16303 eol_str
= invalid_eol_type
;
16304 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16306 bcopy (eol_str
, buf
, eol_str_len
);
16307 buf
+= eol_str_len
;
16313 /* Return a string for the output of a mode line %-spec for window W,
16314 generated by character C. PRECISION >= 0 means don't return a
16315 string longer than that value. FIELD_WIDTH > 0 means pad the
16316 string returned with spaces to that value. Return 1 in *MULTIBYTE
16317 if the result is multibyte text.
16319 Note we operate on the current buffer for most purposes,
16320 the exception being w->base_line_pos. */
16322 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16325 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16328 int field_width
, precision
;
16332 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16333 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16334 struct buffer
*b
= current_buffer
;
16342 if (!NILP (b
->read_only
))
16344 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16349 /* This differs from %* only for a modified read-only buffer. */
16350 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16352 if (!NILP (b
->read_only
))
16357 /* This differs from %* in ignoring read-only-ness. */
16358 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16370 if (command_loop_level
> 5)
16372 p
= decode_mode_spec_buf
;
16373 for (i
= 0; i
< command_loop_level
; i
++)
16376 return decode_mode_spec_buf
;
16384 if (command_loop_level
> 5)
16386 p
= decode_mode_spec_buf
;
16387 for (i
= 0; i
< command_loop_level
; i
++)
16390 return decode_mode_spec_buf
;
16397 /* Let lots_of_dashes be a string of infinite length. */
16398 if (!NILP (mode_line_string_list
))
16400 if (field_width
<= 0
16401 || field_width
> sizeof (lots_of_dashes
))
16403 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16404 decode_mode_spec_buf
[i
] = '-';
16405 decode_mode_spec_buf
[i
] = '\0';
16406 return decode_mode_spec_buf
;
16409 return lots_of_dashes
;
16418 int col
= (int) current_column (); /* iftc */
16419 w
->column_number_displayed
= make_number (col
);
16420 pint2str (decode_mode_spec_buf
, field_width
, col
);
16421 return decode_mode_spec_buf
;
16425 /* %F displays the frame name. */
16426 if (!NILP (f
->title
))
16427 return (char *) SDATA (f
->title
);
16428 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16429 return (char *) SDATA (f
->name
);
16438 int size
= ZV
- BEGV
;
16439 pint2str (decode_mode_spec_buf
, field_width
, size
);
16440 return decode_mode_spec_buf
;
16445 int size
= ZV
- BEGV
;
16446 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16447 return decode_mode_spec_buf
;
16452 int startpos
= XMARKER (w
->start
)->charpos
;
16453 int startpos_byte
= marker_byte_position (w
->start
);
16454 int line
, linepos
, linepos_byte
, topline
;
16456 int height
= WINDOW_TOTAL_LINES (w
);
16458 /* If we decided that this buffer isn't suitable for line numbers,
16459 don't forget that too fast. */
16460 if (EQ (w
->base_line_pos
, w
->buffer
))
16462 /* But do forget it, if the window shows a different buffer now. */
16463 else if (BUFFERP (w
->base_line_pos
))
16464 w
->base_line_pos
= Qnil
;
16466 /* If the buffer is very big, don't waste time. */
16467 if (INTEGERP (Vline_number_display_limit
)
16468 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16470 w
->base_line_pos
= Qnil
;
16471 w
->base_line_number
= Qnil
;
16475 if (!NILP (w
->base_line_number
)
16476 && !NILP (w
->base_line_pos
)
16477 && XFASTINT (w
->base_line_pos
) <= startpos
)
16479 line
= XFASTINT (w
->base_line_number
);
16480 linepos
= XFASTINT (w
->base_line_pos
);
16481 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16486 linepos
= BUF_BEGV (b
);
16487 linepos_byte
= BUF_BEGV_BYTE (b
);
16490 /* Count lines from base line to window start position. */
16491 nlines
= display_count_lines (linepos
, linepos_byte
,
16495 topline
= nlines
+ line
;
16497 /* Determine a new base line, if the old one is too close
16498 or too far away, or if we did not have one.
16499 "Too close" means it's plausible a scroll-down would
16500 go back past it. */
16501 if (startpos
== BUF_BEGV (b
))
16503 w
->base_line_number
= make_number (topline
);
16504 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16506 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16507 || linepos
== BUF_BEGV (b
))
16509 int limit
= BUF_BEGV (b
);
16510 int limit_byte
= BUF_BEGV_BYTE (b
);
16512 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16514 if (startpos
- distance
> limit
)
16516 limit
= startpos
- distance
;
16517 limit_byte
= CHAR_TO_BYTE (limit
);
16520 nlines
= display_count_lines (startpos
, startpos_byte
,
16522 - (height
* 2 + 30),
16524 /* If we couldn't find the lines we wanted within
16525 line_number_display_limit_width chars per line,
16526 give up on line numbers for this window. */
16527 if (position
== limit_byte
&& limit
== startpos
- distance
)
16529 w
->base_line_pos
= w
->buffer
;
16530 w
->base_line_number
= Qnil
;
16534 w
->base_line_number
= make_number (topline
- nlines
);
16535 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16538 /* Now count lines from the start pos to point. */
16539 nlines
= display_count_lines (startpos
, startpos_byte
,
16540 PT_BYTE
, PT
, &junk
);
16542 /* Record that we did display the line number. */
16543 line_number_displayed
= 1;
16545 /* Make the string to show. */
16546 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16547 return decode_mode_spec_buf
;
16550 char* p
= decode_mode_spec_buf
;
16551 int pad
= field_width
- 2;
16557 return decode_mode_spec_buf
;
16563 obj
= b
->mode_name
;
16567 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16573 int pos
= marker_position (w
->start
);
16574 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16576 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16578 if (pos
<= BUF_BEGV (b
))
16583 else if (pos
<= BUF_BEGV (b
))
16587 if (total
> 1000000)
16588 /* Do it differently for a large value, to avoid overflow. */
16589 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16591 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16592 /* We can't normally display a 3-digit number,
16593 so get us a 2-digit number that is close. */
16596 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16597 return decode_mode_spec_buf
;
16601 /* Display percentage of size above the bottom of the screen. */
16604 int toppos
= marker_position (w
->start
);
16605 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16606 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16608 if (botpos
>= BUF_ZV (b
))
16610 if (toppos
<= BUF_BEGV (b
))
16617 if (total
> 1000000)
16618 /* Do it differently for a large value, to avoid overflow. */
16619 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16621 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16622 /* We can't normally display a 3-digit number,
16623 so get us a 2-digit number that is close. */
16626 if (toppos
<= BUF_BEGV (b
))
16627 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
16629 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16630 return decode_mode_spec_buf
;
16635 /* status of process */
16636 obj
= Fget_buffer_process (Fcurrent_buffer ());
16638 return "no process";
16639 #ifdef subprocesses
16640 obj
= Fsymbol_name (Fprocess_status (obj
));
16644 case 't': /* indicate TEXT or BINARY */
16645 #ifdef MODE_LINE_BINARY_TEXT
16646 return MODE_LINE_BINARY_TEXT (b
);
16652 /* coding-system (not including end-of-line format) */
16654 /* coding-system (including end-of-line type) */
16656 int eol_flag
= (c
== 'Z');
16657 char *p
= decode_mode_spec_buf
;
16659 if (! FRAME_WINDOW_P (f
))
16661 /* No need to mention EOL here--the terminal never needs
16662 to do EOL conversion. */
16663 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
16664 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
16666 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16669 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16670 #ifdef subprocesses
16671 obj
= Fget_buffer_process (Fcurrent_buffer ());
16672 if (PROCESSP (obj
))
16674 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16676 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16679 #endif /* subprocesses */
16682 return decode_mode_spec_buf
;
16688 *multibyte
= STRING_MULTIBYTE (obj
);
16689 return (char *) SDATA (obj
);
16696 /* Count up to COUNT lines starting from START / START_BYTE.
16697 But don't go beyond LIMIT_BYTE.
16698 Return the number of lines thus found (always nonnegative).
16700 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16703 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16704 int start
, start_byte
, limit_byte
, count
;
16707 register unsigned char *cursor
;
16708 unsigned char *base
;
16710 register int ceiling
;
16711 register unsigned char *ceiling_addr
;
16712 int orig_count
= count
;
16714 /* If we are not in selective display mode,
16715 check only for newlines. */
16716 int selective_display
= (!NILP (current_buffer
->selective_display
)
16717 && !INTEGERP (current_buffer
->selective_display
));
16721 while (start_byte
< limit_byte
)
16723 ceiling
= BUFFER_CEILING_OF (start_byte
);
16724 ceiling
= min (limit_byte
- 1, ceiling
);
16725 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16726 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16729 if (selective_display
)
16730 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16733 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16736 if (cursor
!= ceiling_addr
)
16740 start_byte
+= cursor
- base
+ 1;
16741 *byte_pos_ptr
= start_byte
;
16745 if (++cursor
== ceiling_addr
)
16751 start_byte
+= cursor
- base
;
16756 while (start_byte
> limit_byte
)
16758 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16759 ceiling
= max (limit_byte
, ceiling
);
16760 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16761 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16764 if (selective_display
)
16765 while (--cursor
!= ceiling_addr
16766 && *cursor
!= '\n' && *cursor
!= 015)
16769 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16772 if (cursor
!= ceiling_addr
)
16776 start_byte
+= cursor
- base
+ 1;
16777 *byte_pos_ptr
= start_byte
;
16778 /* When scanning backwards, we should
16779 not count the newline posterior to which we stop. */
16780 return - orig_count
- 1;
16786 /* Here we add 1 to compensate for the last decrement
16787 of CURSOR, which took it past the valid range. */
16788 start_byte
+= cursor
- base
+ 1;
16792 *byte_pos_ptr
= limit_byte
;
16795 return - orig_count
+ count
;
16796 return orig_count
- count
;
16802 /***********************************************************************
16804 ***********************************************************************/
16806 /* Display a NUL-terminated string, starting with index START.
16808 If STRING is non-null, display that C string. Otherwise, the Lisp
16809 string LISP_STRING is displayed.
16811 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16812 FACE_STRING. Display STRING or LISP_STRING with the face at
16813 FACE_STRING_POS in FACE_STRING:
16815 Display the string in the environment given by IT, but use the
16816 standard display table, temporarily.
16818 FIELD_WIDTH is the minimum number of output glyphs to produce.
16819 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16820 with spaces. If STRING has more characters, more than FIELD_WIDTH
16821 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16823 PRECISION is the maximum number of characters to output from
16824 STRING. PRECISION < 0 means don't truncate the string.
16826 This is roughly equivalent to printf format specifiers:
16828 FIELD_WIDTH PRECISION PRINTF
16829 ----------------------------------------
16835 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16836 display them, and < 0 means obey the current buffer's value of
16837 enable_multibyte_characters.
16839 Value is the number of glyphs produced. */
16842 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16843 start
, it
, field_width
, precision
, max_x
, multibyte
)
16844 unsigned char *string
;
16845 Lisp_Object lisp_string
;
16846 Lisp_Object face_string
;
16847 int face_string_pos
;
16850 int field_width
, precision
, max_x
;
16853 int hpos_at_start
= it
->hpos
;
16854 int saved_face_id
= it
->face_id
;
16855 struct glyph_row
*row
= it
->glyph_row
;
16857 /* Initialize the iterator IT for iteration over STRING beginning
16858 with index START. */
16859 reseat_to_string (it
, string
, lisp_string
, start
,
16860 precision
, field_width
, multibyte
);
16862 /* If displaying STRING, set up the face of the iterator
16863 from LISP_STRING, if that's given. */
16864 if (STRINGP (face_string
))
16870 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16871 0, it
->region_beg_charpos
,
16872 it
->region_end_charpos
,
16873 &endptr
, it
->base_face_id
, 0);
16874 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16875 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16878 /* Set max_x to the maximum allowed X position. Don't let it go
16879 beyond the right edge of the window. */
16881 max_x
= it
->last_visible_x
;
16883 max_x
= min (max_x
, it
->last_visible_x
);
16885 /* Skip over display elements that are not visible. because IT->w is
16887 if (it
->current_x
< it
->first_visible_x
)
16888 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
16889 MOVE_TO_POS
| MOVE_TO_X
);
16891 row
->ascent
= it
->max_ascent
;
16892 row
->height
= it
->max_ascent
+ it
->max_descent
;
16893 row
->phys_ascent
= it
->max_phys_ascent
;
16894 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16895 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16897 /* This condition is for the case that we are called with current_x
16898 past last_visible_x. */
16899 while (it
->current_x
< max_x
)
16901 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
16903 /* Get the next display element. */
16904 if (!get_next_display_element (it
))
16907 /* Produce glyphs. */
16908 x_before
= it
->current_x
;
16909 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16910 PRODUCE_GLYPHS (it
);
16912 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
16915 while (i
< nglyphs
)
16917 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16919 if (!it
->truncate_lines_p
16920 && x
+ glyph
->pixel_width
> max_x
)
16922 /* End of continued line or max_x reached. */
16923 if (CHAR_GLYPH_PADDING_P (*glyph
))
16925 /* A wide character is unbreakable. */
16926 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16927 it
->current_x
= x_before
;
16931 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16936 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
16938 /* Glyph is at least partially visible. */
16940 if (x
< it
->first_visible_x
)
16941 it
->glyph_row
->x
= x
- it
->first_visible_x
;
16945 /* Glyph is off the left margin of the display area.
16946 Should not happen. */
16950 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16951 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16952 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16953 row
->phys_height
= max (row
->phys_height
,
16954 it
->max_phys_ascent
+ it
->max_phys_descent
);
16955 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16956 it
->max_extra_line_spacing
);
16957 x
+= glyph
->pixel_width
;
16961 /* Stop if max_x reached. */
16965 /* Stop at line ends. */
16966 if (ITERATOR_AT_END_OF_LINE_P (it
))
16968 it
->continuation_lines_width
= 0;
16972 set_iterator_to_next (it
, 1);
16974 /* Stop if truncating at the right edge. */
16975 if (it
->truncate_lines_p
16976 && it
->current_x
>= it
->last_visible_x
)
16978 /* Add truncation mark, but don't do it if the line is
16979 truncated at a padding space. */
16980 if (IT_CHARPOS (*it
) < it
->string_nchars
)
16982 if (!FRAME_WINDOW_P (it
->f
))
16986 if (it
->current_x
> it
->last_visible_x
)
16988 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16989 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16991 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16993 row
->used
[TEXT_AREA
] = i
;
16994 produce_special_glyphs (it
, IT_TRUNCATION
);
16997 produce_special_glyphs (it
, IT_TRUNCATION
);
16999 it
->glyph_row
->truncated_on_right_p
= 1;
17005 /* Maybe insert a truncation at the left. */
17006 if (it
->first_visible_x
17007 && IT_CHARPOS (*it
) > 0)
17009 if (!FRAME_WINDOW_P (it
->f
))
17010 insert_left_trunc_glyphs (it
);
17011 it
->glyph_row
->truncated_on_left_p
= 1;
17014 it
->face_id
= saved_face_id
;
17016 /* Value is number of columns displayed. */
17017 return it
->hpos
- hpos_at_start
;
17022 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17023 appears as an element of LIST or as the car of an element of LIST.
17024 If PROPVAL is a list, compare each element against LIST in that
17025 way, and return 1/2 if any element of PROPVAL is found in LIST.
17026 Otherwise return 0. This function cannot quit.
17027 The return value is 2 if the text is invisible but with an ellipsis
17028 and 1 if it's invisible and without an ellipsis. */
17031 invisible_p (propval
, list
)
17032 register Lisp_Object propval
;
17035 register Lisp_Object tail
, proptail
;
17037 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17039 register Lisp_Object tem
;
17041 if (EQ (propval
, tem
))
17043 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17044 return NILP (XCDR (tem
)) ? 1 : 2;
17047 if (CONSP (propval
))
17049 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17051 Lisp_Object propelt
;
17052 propelt
= XCAR (proptail
);
17053 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17055 register Lisp_Object tem
;
17057 if (EQ (propelt
, tem
))
17059 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17060 return NILP (XCDR (tem
)) ? 1 : 2;
17068 /* Calculate a width or height in pixels from a specification using
17069 the following elements:
17072 NUM - a (fractional) multiple of the default font width/height
17073 (NUM) - specifies exactly NUM pixels
17074 UNIT - a fixed number of pixels, see below.
17075 ELEMENT - size of a display element in pixels, see below.
17076 (NUM . SPEC) - equals NUM * SPEC
17077 (+ SPEC SPEC ...) - add pixel values
17078 (- SPEC SPEC ...) - subtract pixel values
17079 (- SPEC) - negate pixel value
17082 INT or FLOAT - a number constant
17083 SYMBOL - use symbol's (buffer local) variable binding.
17086 in - pixels per inch *)
17087 mm - pixels per 1/1000 meter *)
17088 cm - pixels per 1/100 meter *)
17089 width - width of current font in pixels.
17090 height - height of current font in pixels.
17092 *) using the ratio(s) defined in display-pixels-per-inch.
17096 left-fringe - left fringe width in pixels
17097 right-fringe - right fringe width in pixels
17099 left-margin - left margin width in pixels
17100 right-margin - right margin width in pixels
17102 scroll-bar - scroll-bar area width in pixels
17106 Pixels corresponding to 5 inches:
17109 Total width of non-text areas on left side of window (if scroll-bar is on left):
17110 '(space :width (+ left-fringe left-margin scroll-bar))
17112 Align to first text column (in header line):
17113 '(space :align-to 0)
17115 Align to middle of text area minus half the width of variable `my-image'
17116 containing a loaded image:
17117 '(space :align-to (0.5 . (- text my-image)))
17119 Width of left margin minus width of 1 character in the default font:
17120 '(space :width (- left-margin 1))
17122 Width of left margin minus width of 2 characters in the current font:
17123 '(space :width (- left-margin (2 . width)))
17125 Center 1 character over left-margin (in header line):
17126 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17128 Different ways to express width of left fringe plus left margin minus one pixel:
17129 '(space :width (- (+ left-fringe left-margin) (1)))
17130 '(space :width (+ left-fringe left-margin (- (1))))
17131 '(space :width (+ left-fringe left-margin (-1)))
17135 #define NUMVAL(X) \
17136 ((INTEGERP (X) || FLOATP (X)) \
17141 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17146 int width_p
, *align_to
;
17150 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17151 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17154 return OK_PIXELS (0);
17156 if (SYMBOLP (prop
))
17158 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17160 char *unit
= SDATA (SYMBOL_NAME (prop
));
17162 if (unit
[0] == 'i' && unit
[1] == 'n')
17164 else if (unit
[0] == 'm' && unit
[1] == 'm')
17166 else if (unit
[0] == 'c' && unit
[1] == 'm')
17173 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
17174 || (CONSP (Vdisplay_pixels_per_inch
)
17176 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
17177 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
17179 return OK_PIXELS (ppi
/ pixels
);
17185 #ifdef HAVE_WINDOW_SYSTEM
17186 if (EQ (prop
, Qheight
))
17187 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
17188 if (EQ (prop
, Qwidth
))
17189 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
17191 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
17192 return OK_PIXELS (1);
17195 if (EQ (prop
, Qtext
))
17196 return OK_PIXELS (width_p
17197 ? window_box_width (it
->w
, TEXT_AREA
)
17198 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
17200 if (align_to
&& *align_to
< 0)
17203 if (EQ (prop
, Qleft
))
17204 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
17205 if (EQ (prop
, Qright
))
17206 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
17207 if (EQ (prop
, Qcenter
))
17208 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
17209 + window_box_width (it
->w
, TEXT_AREA
) / 2);
17210 if (EQ (prop
, Qleft_fringe
))
17211 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17212 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
17213 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
17214 if (EQ (prop
, Qright_fringe
))
17215 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17216 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17217 : window_box_right_offset (it
->w
, TEXT_AREA
));
17218 if (EQ (prop
, Qleft_margin
))
17219 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
17220 if (EQ (prop
, Qright_margin
))
17221 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
17222 if (EQ (prop
, Qscroll_bar
))
17223 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
17225 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17226 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17227 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
17232 if (EQ (prop
, Qleft_fringe
))
17233 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
17234 if (EQ (prop
, Qright_fringe
))
17235 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
17236 if (EQ (prop
, Qleft_margin
))
17237 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
17238 if (EQ (prop
, Qright_margin
))
17239 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
17240 if (EQ (prop
, Qscroll_bar
))
17241 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
17244 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
17247 if (INTEGERP (prop
) || FLOATP (prop
))
17249 int base_unit
= (width_p
17250 ? FRAME_COLUMN_WIDTH (it
->f
)
17251 : FRAME_LINE_HEIGHT (it
->f
));
17252 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
17257 Lisp_Object car
= XCAR (prop
);
17258 Lisp_Object cdr
= XCDR (prop
);
17262 #ifdef HAVE_WINDOW_SYSTEM
17263 if (valid_image_p (prop
))
17265 int id
= lookup_image (it
->f
, prop
);
17266 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
17268 return OK_PIXELS (width_p
? img
->width
: img
->height
);
17271 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
17277 while (CONSP (cdr
))
17279 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
17280 font
, width_p
, align_to
))
17283 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
17288 if (EQ (car
, Qminus
))
17290 return OK_PIXELS (pixels
);
17293 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17296 if (INTEGERP (car
) || FLOATP (car
))
17299 pixels
= XFLOATINT (car
);
17301 return OK_PIXELS (pixels
);
17302 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17303 font
, width_p
, align_to
))
17304 return OK_PIXELS (pixels
* fact
);
17315 /***********************************************************************
17317 ***********************************************************************/
17319 #ifdef HAVE_WINDOW_SYSTEM
17324 dump_glyph_string (s
)
17325 struct glyph_string
*s
;
17327 fprintf (stderr
, "glyph string\n");
17328 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17329 s
->x
, s
->y
, s
->width
, s
->height
);
17330 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17331 fprintf (stderr
, " hl = %d\n", s
->hl
);
17332 fprintf (stderr
, " left overhang = %d, right = %d\n",
17333 s
->left_overhang
, s
->right_overhang
);
17334 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17335 fprintf (stderr
, " extends to end of line = %d\n",
17336 s
->extends_to_end_of_line_p
);
17337 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17338 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17341 #endif /* GLYPH_DEBUG */
17343 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17344 of XChar2b structures for S; it can't be allocated in
17345 init_glyph_string because it must be allocated via `alloca'. W
17346 is the window on which S is drawn. ROW and AREA are the glyph row
17347 and area within the row from which S is constructed. START is the
17348 index of the first glyph structure covered by S. HL is a
17349 face-override for drawing S. */
17352 #define OPTIONAL_HDC(hdc) hdc,
17353 #define DECLARE_HDC(hdc) HDC hdc;
17354 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17355 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17358 #ifndef OPTIONAL_HDC
17359 #define OPTIONAL_HDC(hdc)
17360 #define DECLARE_HDC(hdc)
17361 #define ALLOCATE_HDC(hdc, f)
17362 #define RELEASE_HDC(hdc, f)
17366 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17367 struct glyph_string
*s
;
17371 struct glyph_row
*row
;
17372 enum glyph_row_area area
;
17374 enum draw_glyphs_face hl
;
17376 bzero (s
, sizeof *s
);
17378 s
->f
= XFRAME (w
->frame
);
17382 s
->display
= FRAME_X_DISPLAY (s
->f
);
17383 s
->window
= FRAME_X_WINDOW (s
->f
);
17384 s
->char2b
= char2b
;
17388 s
->first_glyph
= row
->glyphs
[area
] + start
;
17389 s
->height
= row
->height
;
17390 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17392 /* Display the internal border below the tool-bar window. */
17393 if (WINDOWP (s
->f
->tool_bar_window
)
17394 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17395 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17397 s
->ybase
= s
->y
+ row
->ascent
;
17401 /* Append the list of glyph strings with head H and tail T to the list
17402 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17405 append_glyph_string_lists (head
, tail
, h
, t
)
17406 struct glyph_string
**head
, **tail
;
17407 struct glyph_string
*h
, *t
;
17421 /* Prepend the list of glyph strings with head H and tail T to the
17422 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17426 prepend_glyph_string_lists (head
, tail
, h
, t
)
17427 struct glyph_string
**head
, **tail
;
17428 struct glyph_string
*h
, *t
;
17442 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17443 Set *HEAD and *TAIL to the resulting list. */
17446 append_glyph_string (head
, tail
, s
)
17447 struct glyph_string
**head
, **tail
;
17448 struct glyph_string
*s
;
17450 s
->next
= s
->prev
= NULL
;
17451 append_glyph_string_lists (head
, tail
, s
, s
);
17455 /* Get face and two-byte form of character glyph GLYPH on frame F.
17456 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17457 a pointer to a realized face that is ready for display. */
17459 static INLINE
struct face
*
17460 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17462 struct glyph
*glyph
;
17468 xassert (glyph
->type
== CHAR_GLYPH
);
17469 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17474 if (!glyph
->multibyte_p
)
17476 /* Unibyte case. We don't have to encode, but we have to make
17477 sure to use a face suitable for unibyte. */
17478 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17480 else if (glyph
->u
.ch
< 128
17481 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17483 /* Case of ASCII in a face known to fit ASCII. */
17484 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17488 int c1
, c2
, charset
;
17490 /* Split characters into bytes. If c2 is -1 afterwards, C is
17491 really a one-byte character so that byte1 is zero. */
17492 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17494 STORE_XCHAR2B (char2b
, c1
, c2
);
17496 STORE_XCHAR2B (char2b
, 0, c1
);
17498 /* Maybe encode the character in *CHAR2B. */
17499 if (charset
!= CHARSET_ASCII
)
17501 struct font_info
*font_info
17502 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17505 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17509 /* Make sure X resources of the face are allocated. */
17510 xassert (face
!= NULL
);
17511 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17516 /* Fill glyph string S with composition components specified by S->cmp.
17518 FACES is an array of faces for all components of this composition.
17519 S->gidx is the index of the first component for S.
17520 OVERLAPS_P non-zero means S should draw the foreground only, and
17521 use its physical height for clipping.
17523 Value is the index of a component not in S. */
17526 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17527 struct glyph_string
*s
;
17528 struct face
**faces
;
17535 s
->for_overlaps_p
= overlaps_p
;
17537 s
->face
= faces
[s
->gidx
];
17538 s
->font
= s
->face
->font
;
17539 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17541 /* For all glyphs of this composition, starting at the offset
17542 S->gidx, until we reach the end of the definition or encounter a
17543 glyph that requires the different face, add it to S. */
17545 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17548 /* All glyph strings for the same composition has the same width,
17549 i.e. the width set for the first component of the composition. */
17551 s
->width
= s
->first_glyph
->pixel_width
;
17553 /* If the specified font could not be loaded, use the frame's
17554 default font, but record the fact that we couldn't load it in
17555 the glyph string so that we can draw rectangles for the
17556 characters of the glyph string. */
17557 if (s
->font
== NULL
)
17559 s
->font_not_found_p
= 1;
17560 s
->font
= FRAME_FONT (s
->f
);
17563 /* Adjust base line for subscript/superscript text. */
17564 s
->ybase
+= s
->first_glyph
->voffset
;
17566 xassert (s
->face
&& s
->face
->gc
);
17568 /* This glyph string must always be drawn with 16-bit functions. */
17571 return s
->gidx
+ s
->nchars
;
17575 /* Fill glyph string S from a sequence of character glyphs.
17577 FACE_ID is the face id of the string. START is the index of the
17578 first glyph to consider, END is the index of the last + 1.
17579 OVERLAPS_P non-zero means S should draw the foreground only, and
17580 use its physical height for clipping.
17582 Value is the index of the first glyph not in S. */
17585 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17586 struct glyph_string
*s
;
17588 int start
, end
, overlaps_p
;
17590 struct glyph
*glyph
, *last
;
17592 int glyph_not_available_p
;
17594 xassert (s
->f
== XFRAME (s
->w
->frame
));
17595 xassert (s
->nchars
== 0);
17596 xassert (start
>= 0 && end
> start
);
17598 s
->for_overlaps_p
= overlaps_p
,
17599 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17600 last
= s
->row
->glyphs
[s
->area
] + end
;
17601 voffset
= glyph
->voffset
;
17603 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17605 while (glyph
< last
17606 && glyph
->type
== CHAR_GLYPH
17607 && glyph
->voffset
== voffset
17608 /* Same face id implies same font, nowadays. */
17609 && glyph
->face_id
== face_id
17610 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
17614 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
17615 s
->char2b
+ s
->nchars
,
17617 s
->two_byte_p
= two_byte_p
;
17619 xassert (s
->nchars
<= end
- start
);
17620 s
->width
+= glyph
->pixel_width
;
17624 s
->font
= s
->face
->font
;
17625 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17627 /* If the specified font could not be loaded, use the frame's font,
17628 but record the fact that we couldn't load it in
17629 S->font_not_found_p so that we can draw rectangles for the
17630 characters of the glyph string. */
17631 if (s
->font
== NULL
|| glyph_not_available_p
)
17633 s
->font_not_found_p
= 1;
17634 s
->font
= FRAME_FONT (s
->f
);
17637 /* Adjust base line for subscript/superscript text. */
17638 s
->ybase
+= voffset
;
17640 xassert (s
->face
&& s
->face
->gc
);
17641 return glyph
- s
->row
->glyphs
[s
->area
];
17645 /* Fill glyph string S from image glyph S->first_glyph. */
17648 fill_image_glyph_string (s
)
17649 struct glyph_string
*s
;
17651 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
17652 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
17654 s
->slice
= s
->first_glyph
->slice
;
17655 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
17656 s
->font
= s
->face
->font
;
17657 s
->width
= s
->first_glyph
->pixel_width
;
17659 /* Adjust base line for subscript/superscript text. */
17660 s
->ybase
+= s
->first_glyph
->voffset
;
17664 /* Fill glyph string S from a sequence of stretch glyphs.
17666 ROW is the glyph row in which the glyphs are found, AREA is the
17667 area within the row. START is the index of the first glyph to
17668 consider, END is the index of the last + 1.
17670 Value is the index of the first glyph not in S. */
17673 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
17674 struct glyph_string
*s
;
17675 struct glyph_row
*row
;
17676 enum glyph_row_area area
;
17679 struct glyph
*glyph
, *last
;
17680 int voffset
, face_id
;
17682 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
17684 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17685 last
= s
->row
->glyphs
[s
->area
] + end
;
17686 face_id
= glyph
->face_id
;
17687 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
17688 s
->font
= s
->face
->font
;
17689 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17690 s
->width
= glyph
->pixel_width
;
17691 voffset
= glyph
->voffset
;
17695 && glyph
->type
== STRETCH_GLYPH
17696 && glyph
->voffset
== voffset
17697 && glyph
->face_id
== face_id
);
17699 s
->width
+= glyph
->pixel_width
;
17701 /* Adjust base line for subscript/superscript text. */
17702 s
->ybase
+= voffset
;
17704 /* The case that face->gc == 0 is handled when drawing the glyph
17705 string by calling PREPARE_FACE_FOR_DISPLAY. */
17707 return glyph
- s
->row
->glyphs
[s
->area
];
17712 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
17713 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
17714 assumed to be zero. */
17717 x_get_glyph_overhangs (glyph
, f
, left
, right
)
17718 struct glyph
*glyph
;
17722 *left
= *right
= 0;
17724 if (glyph
->type
== CHAR_GLYPH
)
17728 struct font_info
*font_info
;
17732 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
17734 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17735 if (font
/* ++KFS: Should this be font_info ? */
17736 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
17738 if (pcm
->rbearing
> pcm
->width
)
17739 *right
= pcm
->rbearing
- pcm
->width
;
17740 if (pcm
->lbearing
< 0)
17741 *left
= -pcm
->lbearing
;
17747 /* Return the index of the first glyph preceding glyph string S that
17748 is overwritten by S because of S's left overhang. Value is -1
17749 if no glyphs are overwritten. */
17752 left_overwritten (s
)
17753 struct glyph_string
*s
;
17757 if (s
->left_overhang
)
17760 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17761 int first
= s
->first_glyph
- glyphs
;
17763 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
17764 x
-= glyphs
[i
].pixel_width
;
17775 /* Return the index of the first glyph preceding glyph string S that
17776 is overwriting S because of its right overhang. Value is -1 if no
17777 glyph in front of S overwrites S. */
17780 left_overwriting (s
)
17781 struct glyph_string
*s
;
17784 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17785 int first
= s
->first_glyph
- glyphs
;
17789 for (i
= first
- 1; i
>= 0; --i
)
17792 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17795 x
-= glyphs
[i
].pixel_width
;
17802 /* Return the index of the last glyph following glyph string S that is
17803 not overwritten by S because of S's right overhang. Value is -1 if
17804 no such glyph is found. */
17807 right_overwritten (s
)
17808 struct glyph_string
*s
;
17812 if (s
->right_overhang
)
17815 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17816 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17817 int end
= s
->row
->used
[s
->area
];
17819 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
17820 x
+= glyphs
[i
].pixel_width
;
17829 /* Return the index of the last glyph following glyph string S that
17830 overwrites S because of its left overhang. Value is negative
17831 if no such glyph is found. */
17834 right_overwriting (s
)
17835 struct glyph_string
*s
;
17838 int end
= s
->row
->used
[s
->area
];
17839 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
17840 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
17844 for (i
= first
; i
< end
; ++i
)
17847 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
17850 x
+= glyphs
[i
].pixel_width
;
17857 /* Get face and two-byte form of character C in face FACE_ID on frame
17858 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
17859 means we want to display multibyte text. DISPLAY_P non-zero means
17860 make sure that X resources for the face returned are allocated.
17861 Value is a pointer to a realized face that is ready for display if
17862 DISPLAY_P is non-zero. */
17864 static INLINE
struct face
*
17865 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
17869 int multibyte_p
, display_p
;
17871 struct face
*face
= FACE_FROM_ID (f
, face_id
);
17875 /* Unibyte case. We don't have to encode, but we have to make
17876 sure to use a face suitable for unibyte. */
17877 STORE_XCHAR2B (char2b
, 0, c
);
17878 face_id
= FACE_FOR_CHAR (f
, face
, c
);
17879 face
= FACE_FROM_ID (f
, face_id
);
17881 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
17883 /* Case of ASCII in a face known to fit ASCII. */
17884 STORE_XCHAR2B (char2b
, 0, c
);
17888 int c1
, c2
, charset
;
17890 /* Split characters into bytes. If c2 is -1 afterwards, C is
17891 really a one-byte character so that byte1 is zero. */
17892 SPLIT_CHAR (c
, charset
, c1
, c2
);
17894 STORE_XCHAR2B (char2b
, c1
, c2
);
17896 STORE_XCHAR2B (char2b
, 0, c1
);
17898 /* Maybe encode the character in *CHAR2B. */
17899 if (face
->font
!= NULL
)
17901 struct font_info
*font_info
17902 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17904 rif
->encode_char (c
, char2b
, font_info
, 0);
17908 /* Make sure X resources of the face are allocated. */
17909 #ifdef HAVE_X_WINDOWS
17913 xassert (face
!= NULL
);
17914 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17921 /* Set background width of glyph string S. START is the index of the
17922 first glyph following S. LAST_X is the right-most x-position + 1
17923 in the drawing area. */
17926 set_glyph_string_background_width (s
, start
, last_x
)
17927 struct glyph_string
*s
;
17931 /* If the face of this glyph string has to be drawn to the end of
17932 the drawing area, set S->extends_to_end_of_line_p. */
17933 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
17935 if (start
== s
->row
->used
[s
->area
]
17936 && s
->area
== TEXT_AREA
17937 && ((s
->hl
== DRAW_NORMAL_TEXT
17938 && (s
->row
->fill_line_p
17939 || s
->face
->background
!= default_face
->background
17940 || s
->face
->stipple
!= default_face
->stipple
17941 || s
->row
->mouse_face_p
))
17942 || s
->hl
== DRAW_MOUSE_FACE
17943 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
17944 && s
->row
->fill_line_p
)))
17945 s
->extends_to_end_of_line_p
= 1;
17947 /* If S extends its face to the end of the line, set its
17948 background_width to the distance to the right edge of the drawing
17950 if (s
->extends_to_end_of_line_p
)
17951 s
->background_width
= last_x
- s
->x
+ 1;
17953 s
->background_width
= s
->width
;
17957 /* Compute overhangs and x-positions for glyph string S and its
17958 predecessors, or successors. X is the starting x-position for S.
17959 BACKWARD_P non-zero means process predecessors. */
17962 compute_overhangs_and_x (s
, x
, backward_p
)
17963 struct glyph_string
*s
;
17971 if (rif
->compute_glyph_string_overhangs
)
17972 rif
->compute_glyph_string_overhangs (s
);
17982 if (rif
->compute_glyph_string_overhangs
)
17983 rif
->compute_glyph_string_overhangs (s
);
17993 /* The following macros are only called from draw_glyphs below.
17994 They reference the following parameters of that function directly:
17995 `w', `row', `area', and `overlap_p'
17996 as well as the following local variables:
17997 `s', `f', and `hdc' (in W32) */
18000 /* On W32, silently add local `hdc' variable to argument list of
18001 init_glyph_string. */
18002 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18003 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18005 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18006 init_glyph_string (s, char2b, w, row, area, start, hl)
18009 /* Add a glyph string for a stretch glyph to the list of strings
18010 between HEAD and TAIL. START is the index of the stretch glyph in
18011 row area AREA of glyph row ROW. END is the index of the last glyph
18012 in that glyph row area. X is the current output position assigned
18013 to the new glyph string constructed. HL overrides that face of the
18014 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18015 is the right-most x-position of the drawing area. */
18017 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18018 and below -- keep them on one line. */
18019 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18022 s = (struct glyph_string *) alloca (sizeof *s); \
18023 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18024 START = fill_stretch_glyph_string (s, row, area, START, END); \
18025 append_glyph_string (&HEAD, &TAIL, s); \
18031 /* Add a glyph string for an image glyph to the list of strings
18032 between HEAD and TAIL. START is the index of the image glyph in
18033 row area AREA of glyph row ROW. END is the index of the last glyph
18034 in that glyph row area. X is the current output position assigned
18035 to the new glyph string constructed. HL overrides that face of the
18036 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18037 is the right-most x-position of the drawing area. */
18039 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18042 s = (struct glyph_string *) alloca (sizeof *s); \
18043 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18044 fill_image_glyph_string (s); \
18045 append_glyph_string (&HEAD, &TAIL, s); \
18052 /* Add a glyph string for a sequence of character glyphs to the list
18053 of strings between HEAD and TAIL. START is the index of the first
18054 glyph in row area AREA of glyph row ROW that is part of the new
18055 glyph string. END is the index of the last glyph in that glyph row
18056 area. X is the current output position assigned to the new glyph
18057 string constructed. HL overrides that face of the glyph; e.g. it
18058 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18059 right-most x-position of the drawing area. */
18061 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18067 c = (row)->glyphs[area][START].u.ch; \
18068 face_id = (row)->glyphs[area][START].face_id; \
18070 s = (struct glyph_string *) alloca (sizeof *s); \
18071 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18072 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18073 append_glyph_string (&HEAD, &TAIL, s); \
18075 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
18080 /* Add a glyph string for a composite sequence to the list of strings
18081 between HEAD and TAIL. START is the index of the first glyph in
18082 row area AREA of glyph row ROW that is part of the new glyph
18083 string. END is the index of the last glyph in that glyph row area.
18084 X is the current output position assigned to the new glyph string
18085 constructed. HL overrides that face of the glyph; e.g. it is
18086 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18087 x-position of the drawing area. */
18089 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18091 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18092 int face_id = (row)->glyphs[area][START].face_id; \
18093 struct face *base_face = FACE_FROM_ID (f, face_id); \
18094 struct composition *cmp = composition_table[cmp_id]; \
18095 int glyph_len = cmp->glyph_len; \
18097 struct face **faces; \
18098 struct glyph_string *first_s = NULL; \
18101 base_face = base_face->ascii_face; \
18102 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18103 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18104 /* At first, fill in `char2b' and `faces'. */ \
18105 for (n = 0; n < glyph_len; n++) \
18107 int c = COMPOSITION_GLYPH (cmp, n); \
18108 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
18109 faces[n] = FACE_FROM_ID (f, this_face_id); \
18110 get_char_face_and_encoding (f, c, this_face_id, \
18111 char2b + n, 1, 1); \
18114 /* Make glyph_strings for each glyph sequence that is drawable by \
18115 the same face, and append them to HEAD/TAIL. */ \
18116 for (n = 0; n < cmp->glyph_len;) \
18118 s = (struct glyph_string *) alloca (sizeof *s); \
18119 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18120 append_glyph_string (&(HEAD), &(TAIL), s); \
18128 n = fill_composite_glyph_string (s, faces, overlaps_p); \
18136 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18137 of AREA of glyph row ROW on window W between indices START and END.
18138 HL overrides the face for drawing glyph strings, e.g. it is
18139 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18140 x-positions of the drawing area.
18142 This is an ugly monster macro construct because we must use alloca
18143 to allocate glyph strings (because draw_glyphs can be called
18144 asynchronously). */
18146 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18149 HEAD = TAIL = NULL; \
18150 while (START < END) \
18152 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18153 switch (first_glyph->type) \
18156 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
18160 case COMPOSITE_GLYPH: \
18161 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
18165 case STRETCH_GLYPH: \
18166 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
18170 case IMAGE_GLYPH: \
18171 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
18179 set_glyph_string_background_width (s, START, LAST_X); \
18186 /* Draw glyphs between START and END in AREA of ROW on window W,
18187 starting at x-position X. X is relative to AREA in W. HL is a
18188 face-override with the following meaning:
18190 DRAW_NORMAL_TEXT draw normally
18191 DRAW_CURSOR draw in cursor face
18192 DRAW_MOUSE_FACE draw in mouse face.
18193 DRAW_INVERSE_VIDEO draw in mode line face
18194 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
18195 DRAW_IMAGE_RAISED draw an image with a raised relief around it
18197 If OVERLAPS_P is non-zero, draw only the foreground of characters
18198 and clip to the physical height of ROW.
18200 Value is the x-position reached, relative to AREA of W. */
18203 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
18206 struct glyph_row
*row
;
18207 enum glyph_row_area area
;
18209 enum draw_glyphs_face hl
;
18212 struct glyph_string
*head
, *tail
;
18213 struct glyph_string
*s
;
18214 int last_x
, area_width
;
18217 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18220 ALLOCATE_HDC (hdc
, f
);
18222 /* Let's rather be paranoid than getting a SEGV. */
18223 end
= min (end
, row
->used
[area
]);
18224 start
= max (0, start
);
18225 start
= min (end
, start
);
18227 /* Translate X to frame coordinates. Set last_x to the right
18228 end of the drawing area. */
18229 if (row
->full_width_p
)
18231 /* X is relative to the left edge of W, without scroll bars
18233 x
+= WINDOW_LEFT_EDGE_X (w
);
18234 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18238 int area_left
= window_box_left (w
, area
);
18240 area_width
= window_box_width (w
, area
);
18241 last_x
= area_left
+ area_width
;
18244 /* Build a doubly-linked list of glyph_string structures between
18245 head and tail from what we have to draw. Note that the macro
18246 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18247 the reason we use a separate variable `i'. */
18249 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18251 x_reached
= tail
->x
+ tail
->background_width
;
18255 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18256 the row, redraw some glyphs in front or following the glyph
18257 strings built above. */
18258 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18261 struct glyph_string
*h
, *t
;
18263 /* Compute overhangs for all glyph strings. */
18264 if (rif
->compute_glyph_string_overhangs
)
18265 for (s
= head
; s
; s
= s
->next
)
18266 rif
->compute_glyph_string_overhangs (s
);
18268 /* Prepend glyph strings for glyphs in front of the first glyph
18269 string that are overwritten because of the first glyph
18270 string's left overhang. The background of all strings
18271 prepended must be drawn because the first glyph string
18273 i
= left_overwritten (head
);
18277 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18278 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18280 compute_overhangs_and_x (t
, head
->x
, 1);
18281 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18284 /* Prepend glyph strings for glyphs in front of the first glyph
18285 string that overwrite that glyph string because of their
18286 right overhang. For these strings, only the foreground must
18287 be drawn, because it draws over the glyph string at `head'.
18288 The background must not be drawn because this would overwrite
18289 right overhangs of preceding glyphs for which no glyph
18291 i
= left_overwriting (head
);
18294 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18295 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18296 for (s
= h
; s
; s
= s
->next
)
18297 s
->background_filled_p
= 1;
18298 compute_overhangs_and_x (t
, head
->x
, 1);
18299 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18302 /* Append glyphs strings for glyphs following the last glyph
18303 string tail that are overwritten by tail. The background of
18304 these strings has to be drawn because tail's foreground draws
18306 i
= right_overwritten (tail
);
18309 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18310 DRAW_NORMAL_TEXT
, x
, last_x
);
18311 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18312 append_glyph_string_lists (&head
, &tail
, h
, t
);
18315 /* Append glyph strings for glyphs following the last glyph
18316 string tail that overwrite tail. The foreground of such
18317 glyphs has to be drawn because it writes into the background
18318 of tail. The background must not be drawn because it could
18319 paint over the foreground of following glyphs. */
18320 i
= right_overwriting (tail
);
18323 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18324 DRAW_NORMAL_TEXT
, x
, last_x
);
18325 for (s
= h
; s
; s
= s
->next
)
18326 s
->background_filled_p
= 1;
18327 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18328 append_glyph_string_lists (&head
, &tail
, h
, t
);
18332 /* Draw all strings. */
18333 for (s
= head
; s
; s
= s
->next
)
18334 rif
->draw_glyph_string (s
);
18336 if (area
== TEXT_AREA
18337 && !row
->full_width_p
18338 /* When drawing overlapping rows, only the glyph strings'
18339 foreground is drawn, which doesn't erase a cursor
18343 int x0
= head
? head
->x
: x
;
18344 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
18346 int text_left
= window_box_left (w
, TEXT_AREA
);
18350 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18351 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18354 /* Value is the x-position up to which drawn, relative to AREA of W.
18355 This doesn't include parts drawn because of overhangs. */
18356 if (row
->full_width_p
)
18357 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18359 x_reached
-= window_box_left (w
, area
);
18361 RELEASE_HDC (hdc
, f
);
18366 /* Expand row matrix if too narrow. Don't expand if area
18369 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
18371 if (!fonts_changed_p \
18372 && (it->glyph_row->glyphs[area] \
18373 < it->glyph_row->glyphs[area + 1])) \
18375 it->w->ncols_scale_factor++; \
18376 fonts_changed_p = 1; \
18380 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18381 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18387 struct glyph
*glyph
;
18388 enum glyph_row_area area
= it
->area
;
18390 xassert (it
->glyph_row
);
18391 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18393 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18394 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18396 glyph
->charpos
= CHARPOS (it
->position
);
18397 glyph
->object
= it
->object
;
18398 glyph
->pixel_width
= it
->pixel_width
;
18399 glyph
->ascent
= it
->ascent
;
18400 glyph
->descent
= it
->descent
;
18401 glyph
->voffset
= it
->voffset
;
18402 glyph
->type
= CHAR_GLYPH
;
18403 glyph
->multibyte_p
= it
->multibyte_p
;
18404 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18405 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18406 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18407 || it
->phys_descent
> it
->descent
);
18408 glyph
->padding_p
= 0;
18409 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18410 glyph
->face_id
= it
->face_id
;
18411 glyph
->u
.ch
= it
->char_to_display
;
18412 glyph
->slice
= null_glyph_slice
;
18413 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18414 ++it
->glyph_row
->used
[area
];
18417 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18420 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18421 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18424 append_composite_glyph (it
)
18427 struct glyph
*glyph
;
18428 enum glyph_row_area area
= it
->area
;
18430 xassert (it
->glyph_row
);
18432 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18433 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18435 glyph
->charpos
= CHARPOS (it
->position
);
18436 glyph
->object
= it
->object
;
18437 glyph
->pixel_width
= it
->pixel_width
;
18438 glyph
->ascent
= it
->ascent
;
18439 glyph
->descent
= it
->descent
;
18440 glyph
->voffset
= it
->voffset
;
18441 glyph
->type
= COMPOSITE_GLYPH
;
18442 glyph
->multibyte_p
= it
->multibyte_p
;
18443 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18444 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18445 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18446 || it
->phys_descent
> it
->descent
);
18447 glyph
->padding_p
= 0;
18448 glyph
->glyph_not_available_p
= 0;
18449 glyph
->face_id
= it
->face_id
;
18450 glyph
->u
.cmp_id
= it
->cmp_id
;
18451 glyph
->slice
= null_glyph_slice
;
18452 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18453 ++it
->glyph_row
->used
[area
];
18456 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18460 /* Change IT->ascent and IT->height according to the setting of
18464 take_vertical_position_into_account (it
)
18469 if (it
->voffset
< 0)
18470 /* Increase the ascent so that we can display the text higher
18472 it
->ascent
-= it
->voffset
;
18474 /* Increase the descent so that we can display the text lower
18476 it
->descent
+= it
->voffset
;
18481 /* Produce glyphs/get display metrics for the image IT is loaded with.
18482 See the description of struct display_iterator in dispextern.h for
18483 an overview of struct display_iterator. */
18486 produce_image_glyph (it
)
18492 struct glyph_slice slice
;
18494 xassert (it
->what
== IT_IMAGE
);
18496 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18498 /* Make sure X resources of the face is loaded. */
18499 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18501 if (it
->image_id
< 0)
18503 /* Fringe bitmap. */
18504 it
->ascent
= it
->phys_ascent
= 0;
18505 it
->descent
= it
->phys_descent
= 0;
18506 it
->pixel_width
= 0;
18511 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18513 /* Make sure X resources of the image is loaded. */
18514 prepare_image_for_display (it
->f
, img
);
18516 slice
.x
= slice
.y
= 0;
18517 slice
.width
= img
->width
;
18518 slice
.height
= img
->height
;
18520 if (INTEGERP (it
->slice
.x
))
18521 slice
.x
= XINT (it
->slice
.x
);
18522 else if (FLOATP (it
->slice
.x
))
18523 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
18525 if (INTEGERP (it
->slice
.y
))
18526 slice
.y
= XINT (it
->slice
.y
);
18527 else if (FLOATP (it
->slice
.y
))
18528 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
18530 if (INTEGERP (it
->slice
.width
))
18531 slice
.width
= XINT (it
->slice
.width
);
18532 else if (FLOATP (it
->slice
.width
))
18533 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
18535 if (INTEGERP (it
->slice
.height
))
18536 slice
.height
= XINT (it
->slice
.height
);
18537 else if (FLOATP (it
->slice
.height
))
18538 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
18540 if (slice
.x
>= img
->width
)
18541 slice
.x
= img
->width
;
18542 if (slice
.y
>= img
->height
)
18543 slice
.y
= img
->height
;
18544 if (slice
.x
+ slice
.width
>= img
->width
)
18545 slice
.width
= img
->width
- slice
.x
;
18546 if (slice
.y
+ slice
.height
> img
->height
)
18547 slice
.height
= img
->height
- slice
.y
;
18549 if (slice
.width
== 0 || slice
.height
== 0)
18552 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
18554 it
->descent
= slice
.height
- glyph_ascent
;
18556 it
->descent
+= img
->vmargin
;
18557 if (slice
.y
+ slice
.height
== img
->height
)
18558 it
->descent
+= img
->vmargin
;
18559 it
->phys_descent
= it
->descent
;
18561 it
->pixel_width
= slice
.width
;
18563 it
->pixel_width
+= img
->hmargin
;
18564 if (slice
.x
+ slice
.width
== img
->width
)
18565 it
->pixel_width
+= img
->hmargin
;
18567 /* It's quite possible for images to have an ascent greater than
18568 their height, so don't get confused in that case. */
18569 if (it
->descent
< 0)
18572 #if 0 /* this breaks image tiling */
18573 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18574 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18575 if (face_ascent
> it
->ascent
)
18576 it
->ascent
= it
->phys_ascent
= face_ascent
;
18581 if (face
->box
!= FACE_NO_BOX
)
18583 if (face
->box_line_width
> 0)
18586 it
->ascent
+= face
->box_line_width
;
18587 if (slice
.y
+ slice
.height
== img
->height
)
18588 it
->descent
+= face
->box_line_width
;
18591 if (it
->start_of_box_run_p
&& slice
.x
== 0)
18592 it
->pixel_width
+= abs (face
->box_line_width
);
18593 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
18594 it
->pixel_width
+= abs (face
->box_line_width
);
18597 take_vertical_position_into_account (it
);
18601 struct glyph
*glyph
;
18602 enum glyph_row_area area
= it
->area
;
18604 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18605 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18607 glyph
->charpos
= CHARPOS (it
->position
);
18608 glyph
->object
= it
->object
;
18609 glyph
->pixel_width
= it
->pixel_width
;
18610 glyph
->ascent
= glyph_ascent
;
18611 glyph
->descent
= it
->descent
;
18612 glyph
->voffset
= it
->voffset
;
18613 glyph
->type
= IMAGE_GLYPH
;
18614 glyph
->multibyte_p
= it
->multibyte_p
;
18615 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18616 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18617 glyph
->overlaps_vertically_p
= 0;
18618 glyph
->padding_p
= 0;
18619 glyph
->glyph_not_available_p
= 0;
18620 glyph
->face_id
= it
->face_id
;
18621 glyph
->u
.img_id
= img
->id
;
18622 glyph
->slice
= slice
;
18623 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18624 ++it
->glyph_row
->used
[area
];
18627 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18632 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
18633 of the glyph, WIDTH and HEIGHT are the width and height of the
18634 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
18637 append_stretch_glyph (it
, object
, width
, height
, ascent
)
18639 Lisp_Object object
;
18643 struct glyph
*glyph
;
18644 enum glyph_row_area area
= it
->area
;
18646 xassert (ascent
>= 0 && ascent
<= height
);
18648 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18649 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18651 glyph
->charpos
= CHARPOS (it
->position
);
18652 glyph
->object
= object
;
18653 glyph
->pixel_width
= width
;
18654 glyph
->ascent
= ascent
;
18655 glyph
->descent
= height
- ascent
;
18656 glyph
->voffset
= it
->voffset
;
18657 glyph
->type
= STRETCH_GLYPH
;
18658 glyph
->multibyte_p
= it
->multibyte_p
;
18659 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18660 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18661 glyph
->overlaps_vertically_p
= 0;
18662 glyph
->padding_p
= 0;
18663 glyph
->glyph_not_available_p
= 0;
18664 glyph
->face_id
= it
->face_id
;
18665 glyph
->u
.stretch
.ascent
= ascent
;
18666 glyph
->u
.stretch
.height
= height
;
18667 glyph
->slice
= null_glyph_slice
;
18668 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18669 ++it
->glyph_row
->used
[area
];
18672 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18676 /* Produce a stretch glyph for iterator IT. IT->object is the value
18677 of the glyph property displayed. The value must be a list
18678 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
18681 1. `:width WIDTH' specifies that the space should be WIDTH *
18682 canonical char width wide. WIDTH may be an integer or floating
18685 2. `:relative-width FACTOR' specifies that the width of the stretch
18686 should be computed from the width of the first character having the
18687 `glyph' property, and should be FACTOR times that width.
18689 3. `:align-to HPOS' specifies that the space should be wide enough
18690 to reach HPOS, a value in canonical character units.
18692 Exactly one of the above pairs must be present.
18694 4. `:height HEIGHT' specifies that the height of the stretch produced
18695 should be HEIGHT, measured in canonical character units.
18697 5. `:relative-height FACTOR' specifies that the height of the
18698 stretch should be FACTOR times the height of the characters having
18699 the glyph property.
18701 Either none or exactly one of 4 or 5 must be present.
18703 6. `:ascent ASCENT' specifies that ASCENT percent of the height
18704 of the stretch should be used for the ascent of the stretch.
18705 ASCENT must be in the range 0 <= ASCENT <= 100. */
18708 produce_stretch_glyph (it
)
18711 /* (space :width WIDTH :height HEIGHT ...) */
18712 Lisp_Object prop
, plist
;
18713 int width
= 0, height
= 0, align_to
= -1;
18714 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
18717 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18718 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
18720 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18722 /* List should start with `space'. */
18723 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
18724 plist
= XCDR (it
->object
);
18726 /* Compute the width of the stretch. */
18727 if ((prop
= Fsafe_plist_get (plist
, QCwidth
), !NILP (prop
))
18728 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
18730 /* Absolute width `:width WIDTH' specified and valid. */
18731 zero_width_ok_p
= 1;
18734 else if (prop
= Fsafe_plist_get (plist
, QCrelative_width
),
18737 /* Relative width `:relative-width FACTOR' specified and valid.
18738 Compute the width of the characters having the `glyph'
18741 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
18744 if (it
->multibyte_p
)
18746 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
18747 - IT_BYTEPOS (*it
));
18748 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
18751 it2
.c
= *p
, it2
.len
= 1;
18753 it2
.glyph_row
= NULL
;
18754 it2
.what
= IT_CHARACTER
;
18755 x_produce_glyphs (&it2
);
18756 width
= NUMVAL (prop
) * it2
.pixel_width
;
18758 else if ((prop
= Fsafe_plist_get (plist
, QCalign_to
), !NILP (prop
))
18759 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
18761 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
18762 align_to
= (align_to
< 0
18764 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
18765 else if (align_to
< 0)
18766 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
18767 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
18768 zero_width_ok_p
= 1;
18771 /* Nothing specified -> width defaults to canonical char width. */
18772 width
= FRAME_COLUMN_WIDTH (it
->f
);
18774 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
18777 /* Compute height. */
18778 if ((prop
= Fsafe_plist_get (plist
, QCheight
), !NILP (prop
))
18779 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18782 zero_height_ok_p
= 1;
18784 else if (prop
= Fsafe_plist_get (plist
, QCrelative_height
),
18786 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
18788 height
= FONT_HEIGHT (font
);
18790 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
18793 /* Compute percentage of height used for ascent. If
18794 `:ascent ASCENT' is present and valid, use that. Otherwise,
18795 derive the ascent from the font in use. */
18796 if (prop
= Fsafe_plist_get (plist
, QCascent
),
18797 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
18798 ascent
= height
* NUMVAL (prop
) / 100.0;
18799 else if (!NILP (prop
)
18800 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
18801 ascent
= min (max (0, (int)tem
), height
);
18803 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
18805 if (width
> 0 && height
> 0 && it
->glyph_row
)
18807 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
18808 if (!STRINGP (object
))
18809 object
= it
->w
->buffer
;
18810 append_stretch_glyph (it
, object
, width
, height
, ascent
);
18813 it
->pixel_width
= width
;
18814 it
->ascent
= it
->phys_ascent
= ascent
;
18815 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
18816 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
18818 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
18820 if (face
->box_line_width
> 0)
18822 it
->ascent
+= face
->box_line_width
;
18823 it
->descent
+= face
->box_line_width
;
18826 if (it
->start_of_box_run_p
)
18827 it
->pixel_width
+= abs (face
->box_line_width
);
18828 if (it
->end_of_box_run_p
)
18829 it
->pixel_width
+= abs (face
->box_line_width
);
18832 take_vertical_position_into_account (it
);
18835 /* Get line-height and line-spacing property at point.
18836 If line-height has format (HEIGHT TOTAL), return TOTAL
18837 in TOTAL_HEIGHT. */
18840 get_line_height_property (it
, prop
)
18844 Lisp_Object position
, val
;
18846 if (STRINGP (it
->object
))
18847 position
= make_number (IT_STRING_CHARPOS (*it
));
18848 else if (BUFFERP (it
->object
))
18849 position
= make_number (IT_CHARPOS (*it
));
18853 return Fget_char_property (position
, prop
, it
->object
);
18856 /* Calculate line-height and line-spacing properties.
18857 An integer value specifies explicit pixel value.
18858 A float value specifies relative value to current face height.
18859 A cons (float . face-name) specifies relative value to
18860 height of specified face font.
18862 Returns height in pixels, or nil. */
18866 calc_line_height_property (it
, val
, font
, boff
, override
)
18870 int boff
, override
;
18872 Lisp_Object face_name
= Qnil
;
18873 int ascent
, descent
, height
;
18875 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
18880 face_name
= XCAR (val
);
18882 if (!NUMBERP (val
))
18883 val
= make_number (1);
18884 if (NILP (face_name
))
18886 height
= it
->ascent
+ it
->descent
;
18891 if (NILP (face_name
))
18893 font
= FRAME_FONT (it
->f
);
18894 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18896 else if (EQ (face_name
, Qt
))
18904 struct font_info
*font_info
;
18906 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
18908 return make_number (-1);
18910 face
= FACE_FROM_ID (it
->f
, face_id
);
18913 return make_number (-1);
18915 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18916 boff
= font_info
->baseline_offset
;
18917 if (font_info
->vertical_centering
)
18918 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18921 ascent
= FONT_BASE (font
) + boff
;
18922 descent
= FONT_DESCENT (font
) - boff
;
18926 it
->override_ascent
= ascent
;
18927 it
->override_descent
= descent
;
18928 it
->override_boff
= boff
;
18931 height
= ascent
+ descent
;
18935 height
= (int)(XFLOAT_DATA (val
) * height
);
18936 else if (INTEGERP (val
))
18937 height
*= XINT (val
);
18939 return make_number (height
);
18944 Produce glyphs/get display metrics for the display element IT is
18945 loaded with. See the description of struct display_iterator in
18946 dispextern.h for an overview of struct display_iterator. */
18949 x_produce_glyphs (it
)
18952 int extra_line_spacing
= it
->extra_line_spacing
;
18954 it
->glyph_not_available_p
= 0;
18956 if (it
->what
== IT_CHARACTER
)
18960 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18962 int font_not_found_p
;
18963 struct font_info
*font_info
;
18964 int boff
; /* baseline offset */
18965 /* We may change it->multibyte_p upon unibyte<->multibyte
18966 conversion. So, save the current value now and restore it
18969 Note: It seems that we don't have to record multibyte_p in
18970 struct glyph because the character code itself tells if or
18971 not the character is multibyte. Thus, in the future, we must
18972 consider eliminating the field `multibyte_p' in the struct
18974 int saved_multibyte_p
= it
->multibyte_p
;
18976 /* Maybe translate single-byte characters to multibyte, or the
18978 it
->char_to_display
= it
->c
;
18979 if (!ASCII_BYTE_P (it
->c
))
18981 if (unibyte_display_via_language_environment
18982 && SINGLE_BYTE_CHAR_P (it
->c
)
18984 || !NILP (Vnonascii_translation_table
)))
18986 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18987 it
->multibyte_p
= 1;
18988 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18989 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18991 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
18992 && !it
->multibyte_p
)
18994 it
->multibyte_p
= 1;
18995 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18996 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19000 /* Get font to use. Encode IT->char_to_display. */
19001 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19002 &char2b
, it
->multibyte_p
, 0);
19005 /* When no suitable font found, use the default font. */
19006 font_not_found_p
= font
== NULL
;
19007 if (font_not_found_p
)
19009 font
= FRAME_FONT (it
->f
);
19010 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19015 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19016 boff
= font_info
->baseline_offset
;
19017 if (font_info
->vertical_centering
)
19018 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19021 if (it
->char_to_display
>= ' '
19022 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19024 /* Either unibyte or ASCII. */
19029 pcm
= rif
->per_char_metric (font
, &char2b
,
19030 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19032 if (it
->override_ascent
>= 0)
19034 it
->ascent
= it
->override_ascent
;
19035 it
->descent
= it
->override_descent
;
19036 boff
= it
->override_boff
;
19040 it
->ascent
= FONT_BASE (font
) + boff
;
19041 it
->descent
= FONT_DESCENT (font
) - boff
;
19046 it
->phys_ascent
= pcm
->ascent
+ boff
;
19047 it
->phys_descent
= pcm
->descent
- boff
;
19048 it
->pixel_width
= pcm
->width
;
19052 it
->glyph_not_available_p
= 1;
19053 it
->phys_ascent
= it
->ascent
;
19054 it
->phys_descent
= it
->descent
;
19055 it
->pixel_width
= FONT_WIDTH (font
);
19058 if (it
->constrain_row_ascent_descent_p
)
19060 if (it
->descent
> it
->max_descent
)
19062 it
->ascent
+= it
->descent
- it
->max_descent
;
19063 it
->descent
= it
->max_descent
;
19065 if (it
->ascent
> it
->max_ascent
)
19067 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19068 it
->ascent
= it
->max_ascent
;
19070 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19071 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19072 extra_line_spacing
= 0;
19075 /* If this is a space inside a region of text with
19076 `space-width' property, change its width. */
19077 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19079 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19081 /* If face has a box, add the box thickness to the character
19082 height. If character has a box line to the left and/or
19083 right, add the box line width to the character's width. */
19084 if (face
->box
!= FACE_NO_BOX
)
19086 int thick
= face
->box_line_width
;
19090 it
->ascent
+= thick
;
19091 it
->descent
+= thick
;
19096 if (it
->start_of_box_run_p
)
19097 it
->pixel_width
+= thick
;
19098 if (it
->end_of_box_run_p
)
19099 it
->pixel_width
+= thick
;
19102 /* If face has an overline, add the height of the overline
19103 (1 pixel) and a 1 pixel margin to the character height. */
19104 if (face
->overline_p
)
19107 if (it
->constrain_row_ascent_descent_p
)
19109 if (it
->ascent
> it
->max_ascent
)
19110 it
->ascent
= it
->max_ascent
;
19111 if (it
->descent
> it
->max_descent
)
19112 it
->descent
= it
->max_descent
;
19115 take_vertical_position_into_account (it
);
19117 /* If we have to actually produce glyphs, do it. */
19122 /* Translate a space with a `space-width' property
19123 into a stretch glyph. */
19124 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19125 / FONT_HEIGHT (font
));
19126 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19127 it
->ascent
+ it
->descent
, ascent
);
19132 /* If characters with lbearing or rbearing are displayed
19133 in this line, record that fact in a flag of the
19134 glyph row. This is used to optimize X output code. */
19135 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
19136 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19139 else if (it
->char_to_display
== '\n')
19141 /* A newline has no width but we need the height of the line.
19142 But if previous part of the line set a height, don't
19143 increase that height */
19145 Lisp_Object height
;
19146 Lisp_Object total_height
= Qnil
;
19148 it
->override_ascent
= -1;
19149 it
->pixel_width
= 0;
19152 height
= get_line_height_property(it
, Qline_height
);
19153 /* Split (line-height total-height) list */
19155 && CONSP (XCDR (height
))
19156 && NILP (XCDR (XCDR (height
))))
19158 total_height
= XCAR (XCDR (height
));
19159 height
= XCAR (height
);
19161 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
19163 if (it
->override_ascent
>= 0)
19165 it
->ascent
= it
->override_ascent
;
19166 it
->descent
= it
->override_descent
;
19167 boff
= it
->override_boff
;
19171 it
->ascent
= FONT_BASE (font
) + boff
;
19172 it
->descent
= FONT_DESCENT (font
) - boff
;
19175 if (EQ (height
, Qt
))
19177 if (it
->descent
> it
->max_descent
)
19179 it
->ascent
+= it
->descent
- it
->max_descent
;
19180 it
->descent
= it
->max_descent
;
19182 if (it
->ascent
> it
->max_ascent
)
19184 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19185 it
->ascent
= it
->max_ascent
;
19187 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19188 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19189 it
->constrain_row_ascent_descent_p
= 1;
19190 extra_line_spacing
= 0;
19194 Lisp_Object spacing
;
19197 it
->phys_ascent
= it
->ascent
;
19198 it
->phys_descent
= it
->descent
;
19200 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
19201 && face
->box
!= FACE_NO_BOX
19202 && face
->box_line_width
> 0)
19204 it
->ascent
+= face
->box_line_width
;
19205 it
->descent
+= face
->box_line_width
;
19208 && XINT (height
) > it
->ascent
+ it
->descent
)
19209 it
->ascent
= XINT (height
) - it
->descent
;
19211 if (!NILP (total_height
))
19212 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
19215 spacing
= get_line_height_property(it
, Qline_spacing
);
19216 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
19218 if (INTEGERP (spacing
))
19220 extra_line_spacing
= XINT (spacing
);
19221 if (!NILP (total_height
))
19222 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19226 else if (it
->char_to_display
== '\t')
19228 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
19229 int x
= it
->current_x
+ it
->continuation_lines_width
;
19230 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
19232 /* If the distance from the current position to the next tab
19233 stop is less than a space character width, use the
19234 tab stop after that. */
19235 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
19236 next_tab_x
+= tab_width
;
19238 it
->pixel_width
= next_tab_x
- x
;
19240 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
19241 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19245 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19246 it
->ascent
+ it
->descent
, it
->ascent
);
19251 /* A multi-byte character. Assume that the display width of the
19252 character is the width of the character multiplied by the
19253 width of the font. */
19255 /* If we found a font, this font should give us the right
19256 metrics. If we didn't find a font, use the frame's
19257 default font and calculate the width of the character
19258 from the charset width; this is what old redisplay code
19261 pcm
= rif
->per_char_metric (font
, &char2b
,
19262 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
19264 if (font_not_found_p
|| !pcm
)
19266 int charset
= CHAR_CHARSET (it
->char_to_display
);
19268 it
->glyph_not_available_p
= 1;
19269 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
19270 * CHARSET_WIDTH (charset
));
19271 it
->phys_ascent
= FONT_BASE (font
) + boff
;
19272 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19276 it
->pixel_width
= pcm
->width
;
19277 it
->phys_ascent
= pcm
->ascent
+ boff
;
19278 it
->phys_descent
= pcm
->descent
- boff
;
19280 && (pcm
->lbearing
< 0
19281 || pcm
->rbearing
> pcm
->width
))
19282 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19285 it
->ascent
= FONT_BASE (font
) + boff
;
19286 it
->descent
= FONT_DESCENT (font
) - boff
;
19287 if (face
->box
!= FACE_NO_BOX
)
19289 int thick
= face
->box_line_width
;
19293 it
->ascent
+= thick
;
19294 it
->descent
+= thick
;
19299 if (it
->start_of_box_run_p
)
19300 it
->pixel_width
+= thick
;
19301 if (it
->end_of_box_run_p
)
19302 it
->pixel_width
+= thick
;
19305 /* If face has an overline, add the height of the overline
19306 (1 pixel) and a 1 pixel margin to the character height. */
19307 if (face
->overline_p
)
19310 take_vertical_position_into_account (it
);
19315 it
->multibyte_p
= saved_multibyte_p
;
19317 else if (it
->what
== IT_COMPOSITION
)
19319 /* Note: A composition is represented as one glyph in the
19320 glyph matrix. There are no padding glyphs. */
19323 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19325 int font_not_found_p
;
19326 struct font_info
*font_info
;
19327 int boff
; /* baseline offset */
19328 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19330 /* Maybe translate single-byte characters to multibyte. */
19331 it
->char_to_display
= it
->c
;
19332 if (unibyte_display_via_language_environment
19333 && SINGLE_BYTE_CHAR_P (it
->c
)
19336 && !NILP (Vnonascii_translation_table
))))
19338 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19341 /* Get face and font to use. Encode IT->char_to_display. */
19342 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19343 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19344 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19345 &char2b
, it
->multibyte_p
, 0);
19348 /* When no suitable font found, use the default font. */
19349 font_not_found_p
= font
== NULL
;
19350 if (font_not_found_p
)
19352 font
= FRAME_FONT (it
->f
);
19353 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19358 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19359 boff
= font_info
->baseline_offset
;
19360 if (font_info
->vertical_centering
)
19361 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19364 /* There are no padding glyphs, so there is only one glyph to
19365 produce for the composition. Important is that pixel_width,
19366 ascent and descent are the values of what is drawn by
19367 draw_glyphs (i.e. the values of the overall glyphs composed). */
19370 /* If we have not yet calculated pixel size data of glyphs of
19371 the composition for the current face font, calculate them
19372 now. Theoretically, we have to check all fonts for the
19373 glyphs, but that requires much time and memory space. So,
19374 here we check only the font of the first glyph. This leads
19375 to incorrect display very rarely, and C-l (recenter) can
19376 correct the display anyway. */
19377 if (cmp
->font
!= (void *) font
)
19379 /* Ascent and descent of the font of the first character of
19380 this composition (adjusted by baseline offset). Ascent
19381 and descent of overall glyphs should not be less than
19382 them respectively. */
19383 int font_ascent
= FONT_BASE (font
) + boff
;
19384 int font_descent
= FONT_DESCENT (font
) - boff
;
19385 /* Bounding box of the overall glyphs. */
19386 int leftmost
, rightmost
, lowest
, highest
;
19387 int i
, width
, ascent
, descent
;
19389 cmp
->font
= (void *) font
;
19391 /* Initialize the bounding box. */
19393 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19394 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19396 width
= pcm
->width
;
19397 ascent
= pcm
->ascent
;
19398 descent
= pcm
->descent
;
19402 width
= FONT_WIDTH (font
);
19403 ascent
= FONT_BASE (font
);
19404 descent
= FONT_DESCENT (font
);
19408 lowest
= - descent
+ boff
;
19409 highest
= ascent
+ boff
;
19413 && font_info
->default_ascent
19414 && CHAR_TABLE_P (Vuse_default_ascent
)
19415 && !NILP (Faref (Vuse_default_ascent
,
19416 make_number (it
->char_to_display
))))
19417 highest
= font_info
->default_ascent
+ boff
;
19419 /* Draw the first glyph at the normal position. It may be
19420 shifted to right later if some other glyphs are drawn at
19422 cmp
->offsets
[0] = 0;
19423 cmp
->offsets
[1] = boff
;
19425 /* Set cmp->offsets for the remaining glyphs. */
19426 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19428 int left
, right
, btm
, top
;
19429 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19430 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19432 face
= FACE_FROM_ID (it
->f
, face_id
);
19433 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19434 &char2b
, it
->multibyte_p
, 0);
19438 font
= FRAME_FONT (it
->f
);
19439 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19445 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19446 boff
= font_info
->baseline_offset
;
19447 if (font_info
->vertical_centering
)
19448 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19452 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19453 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19455 width
= pcm
->width
;
19456 ascent
= pcm
->ascent
;
19457 descent
= pcm
->descent
;
19461 width
= FONT_WIDTH (font
);
19466 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19468 /* Relative composition with or without
19469 alternate chars. */
19470 left
= (leftmost
+ rightmost
- width
) / 2;
19471 btm
= - descent
+ boff
;
19472 if (font_info
&& font_info
->relative_compose
19473 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19474 || NILP (Faref (Vignore_relative_composition
,
19475 make_number (ch
)))))
19478 if (- descent
>= font_info
->relative_compose
)
19479 /* One extra pixel between two glyphs. */
19481 else if (ascent
<= 0)
19482 /* One extra pixel between two glyphs. */
19483 btm
= lowest
- 1 - ascent
- descent
;
19488 /* A composition rule is specified by an integer
19489 value that encodes global and new reference
19490 points (GREF and NREF). GREF and NREF are
19491 specified by numbers as below:
19493 0---1---2 -- ascent
19497 9--10--11 -- center
19499 ---3---4---5--- baseline
19501 6---7---8 -- descent
19503 int rule
= COMPOSITION_RULE (cmp
, i
);
19504 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
19506 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
19507 grefx
= gref
% 3, nrefx
= nref
% 3;
19508 grefy
= gref
/ 3, nrefy
= nref
/ 3;
19511 + grefx
* (rightmost
- leftmost
) / 2
19512 - nrefx
* width
/ 2);
19513 btm
= ((grefy
== 0 ? highest
19515 : grefy
== 2 ? lowest
19516 : (highest
+ lowest
) / 2)
19517 - (nrefy
== 0 ? ascent
+ descent
19518 : nrefy
== 1 ? descent
- boff
19520 : (ascent
+ descent
) / 2));
19523 cmp
->offsets
[i
* 2] = left
;
19524 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
19526 /* Update the bounding box of the overall glyphs. */
19527 right
= left
+ width
;
19528 top
= btm
+ descent
+ ascent
;
19529 if (left
< leftmost
)
19531 if (right
> rightmost
)
19539 /* If there are glyphs whose x-offsets are negative,
19540 shift all glyphs to the right and make all x-offsets
19544 for (i
= 0; i
< cmp
->glyph_len
; i
++)
19545 cmp
->offsets
[i
* 2] -= leftmost
;
19546 rightmost
-= leftmost
;
19549 cmp
->pixel_width
= rightmost
;
19550 cmp
->ascent
= highest
;
19551 cmp
->descent
= - lowest
;
19552 if (cmp
->ascent
< font_ascent
)
19553 cmp
->ascent
= font_ascent
;
19554 if (cmp
->descent
< font_descent
)
19555 cmp
->descent
= font_descent
;
19558 it
->pixel_width
= cmp
->pixel_width
;
19559 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
19560 it
->descent
= it
->phys_descent
= cmp
->descent
;
19562 if (face
->box
!= FACE_NO_BOX
)
19564 int thick
= face
->box_line_width
;
19568 it
->ascent
+= thick
;
19569 it
->descent
+= thick
;
19574 if (it
->start_of_box_run_p
)
19575 it
->pixel_width
+= thick
;
19576 if (it
->end_of_box_run_p
)
19577 it
->pixel_width
+= thick
;
19580 /* If face has an overline, add the height of the overline
19581 (1 pixel) and a 1 pixel margin to the character height. */
19582 if (face
->overline_p
)
19585 take_vertical_position_into_account (it
);
19588 append_composite_glyph (it
);
19590 else if (it
->what
== IT_IMAGE
)
19591 produce_image_glyph (it
);
19592 else if (it
->what
== IT_STRETCH
)
19593 produce_stretch_glyph (it
);
19595 /* Accumulate dimensions. Note: can't assume that it->descent > 0
19596 because this isn't true for images with `:ascent 100'. */
19597 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
19598 if (it
->area
== TEXT_AREA
)
19599 it
->current_x
+= it
->pixel_width
;
19601 if (extra_line_spacing
> 0)
19603 it
->descent
+= extra_line_spacing
;
19604 if (extra_line_spacing
> it
->max_extra_line_spacing
)
19605 it
->max_extra_line_spacing
= extra_line_spacing
;
19608 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
19609 it
->max_descent
= max (it
->max_descent
, it
->descent
);
19610 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
19611 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
19615 Output LEN glyphs starting at START at the nominal cursor position.
19616 Advance the nominal cursor over the text. The global variable
19617 updated_window contains the window being updated, updated_row is
19618 the glyph row being updated, and updated_area is the area of that
19619 row being updated. */
19622 x_write_glyphs (start
, len
)
19623 struct glyph
*start
;
19628 xassert (updated_window
&& updated_row
);
19631 /* Write glyphs. */
19633 hpos
= start
- updated_row
->glyphs
[updated_area
];
19634 x
= draw_glyphs (updated_window
, output_cursor
.x
,
19635 updated_row
, updated_area
,
19637 DRAW_NORMAL_TEXT
, 0);
19639 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
19640 if (updated_area
== TEXT_AREA
19641 && updated_window
->phys_cursor_on_p
19642 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
19643 && updated_window
->phys_cursor
.hpos
>= hpos
19644 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
19645 updated_window
->phys_cursor_on_p
= 0;
19649 /* Advance the output cursor. */
19650 output_cursor
.hpos
+= len
;
19651 output_cursor
.x
= x
;
19656 Insert LEN glyphs from START at the nominal cursor position. */
19659 x_insert_glyphs (start
, len
)
19660 struct glyph
*start
;
19665 int line_height
, shift_by_width
, shifted_region_width
;
19666 struct glyph_row
*row
;
19667 struct glyph
*glyph
;
19668 int frame_x
, frame_y
, hpos
;
19670 xassert (updated_window
&& updated_row
);
19672 w
= updated_window
;
19673 f
= XFRAME (WINDOW_FRAME (w
));
19675 /* Get the height of the line we are in. */
19677 line_height
= row
->height
;
19679 /* Get the width of the glyphs to insert. */
19680 shift_by_width
= 0;
19681 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
19682 shift_by_width
+= glyph
->pixel_width
;
19684 /* Get the width of the region to shift right. */
19685 shifted_region_width
= (window_box_width (w
, updated_area
)
19690 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
19691 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
19693 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
19694 line_height
, shift_by_width
);
19696 /* Write the glyphs. */
19697 hpos
= start
- row
->glyphs
[updated_area
];
19698 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
19700 DRAW_NORMAL_TEXT
, 0);
19702 /* Advance the output cursor. */
19703 output_cursor
.hpos
+= len
;
19704 output_cursor
.x
+= shift_by_width
;
19710 Erase the current text line from the nominal cursor position
19711 (inclusive) to pixel column TO_X (exclusive). The idea is that
19712 everything from TO_X onward is already erased.
19714 TO_X is a pixel position relative to updated_area of
19715 updated_window. TO_X == -1 means clear to the end of this area. */
19718 x_clear_end_of_line (to_x
)
19722 struct window
*w
= updated_window
;
19723 int max_x
, min_y
, max_y
;
19724 int from_x
, from_y
, to_y
;
19726 xassert (updated_window
&& updated_row
);
19727 f
= XFRAME (w
->frame
);
19729 if (updated_row
->full_width_p
)
19730 max_x
= WINDOW_TOTAL_WIDTH (w
);
19732 max_x
= window_box_width (w
, updated_area
);
19733 max_y
= window_text_bottom_y (w
);
19735 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
19736 of window. For TO_X > 0, truncate to end of drawing area. */
19742 to_x
= min (to_x
, max_x
);
19744 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
19746 /* Notice if the cursor will be cleared by this operation. */
19747 if (!updated_row
->full_width_p
)
19748 notice_overwritten_cursor (w
, updated_area
,
19749 output_cursor
.x
, -1,
19751 MATRIX_ROW_BOTTOM_Y (updated_row
));
19753 from_x
= output_cursor
.x
;
19755 /* Translate to frame coordinates. */
19756 if (updated_row
->full_width_p
)
19758 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
19759 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
19763 int area_left
= window_box_left (w
, updated_area
);
19764 from_x
+= area_left
;
19768 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
19769 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
19770 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
19772 /* Prevent inadvertently clearing to end of the X window. */
19773 if (to_x
> from_x
&& to_y
> from_y
)
19776 rif
->clear_frame_area (f
, from_x
, from_y
,
19777 to_x
- from_x
, to_y
- from_y
);
19782 #endif /* HAVE_WINDOW_SYSTEM */
19786 /***********************************************************************
19788 ***********************************************************************/
19790 /* Value is the internal representation of the specified cursor type
19791 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
19792 of the bar cursor. */
19794 static enum text_cursor_kinds
19795 get_specified_cursor_type (arg
, width
)
19799 enum text_cursor_kinds type
;
19804 if (EQ (arg
, Qbox
))
19805 return FILLED_BOX_CURSOR
;
19807 if (EQ (arg
, Qhollow
))
19808 return HOLLOW_BOX_CURSOR
;
19810 if (EQ (arg
, Qbar
))
19817 && EQ (XCAR (arg
), Qbar
)
19818 && INTEGERP (XCDR (arg
))
19819 && XINT (XCDR (arg
)) >= 0)
19821 *width
= XINT (XCDR (arg
));
19825 if (EQ (arg
, Qhbar
))
19828 return HBAR_CURSOR
;
19832 && EQ (XCAR (arg
), Qhbar
)
19833 && INTEGERP (XCDR (arg
))
19834 && XINT (XCDR (arg
)) >= 0)
19836 *width
= XINT (XCDR (arg
));
19837 return HBAR_CURSOR
;
19840 /* Treat anything unknown as "hollow box cursor".
19841 It was bad to signal an error; people have trouble fixing
19842 .Xdefaults with Emacs, when it has something bad in it. */
19843 type
= HOLLOW_BOX_CURSOR
;
19848 /* Set the default cursor types for specified frame. */
19850 set_frame_cursor_types (f
, arg
)
19857 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
19858 FRAME_CURSOR_WIDTH (f
) = width
;
19860 /* By default, set up the blink-off state depending on the on-state. */
19862 tem
= Fassoc (arg
, Vblink_cursor_alist
);
19865 FRAME_BLINK_OFF_CURSOR (f
)
19866 = get_specified_cursor_type (XCDR (tem
), &width
);
19867 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
19870 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
19874 /* Return the cursor we want to be displayed in window W. Return
19875 width of bar/hbar cursor through WIDTH arg. Return with
19876 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
19877 (i.e. if the `system caret' should track this cursor).
19879 In a mini-buffer window, we want the cursor only to appear if we
19880 are reading input from this window. For the selected window, we
19881 want the cursor type given by the frame parameter or buffer local
19882 setting of cursor-type. If explicitly marked off, draw no cursor.
19883 In all other cases, we want a hollow box cursor. */
19885 static enum text_cursor_kinds
19886 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
19888 struct glyph
*glyph
;
19890 int *active_cursor
;
19892 struct frame
*f
= XFRAME (w
->frame
);
19893 struct buffer
*b
= XBUFFER (w
->buffer
);
19894 int cursor_type
= DEFAULT_CURSOR
;
19895 Lisp_Object alt_cursor
;
19896 int non_selected
= 0;
19898 *active_cursor
= 1;
19901 if (cursor_in_echo_area
19902 && FRAME_HAS_MINIBUF_P (f
)
19903 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
19905 if (w
== XWINDOW (echo_area_window
))
19907 *width
= FRAME_CURSOR_WIDTH (f
);
19908 return FRAME_DESIRED_CURSOR (f
);
19911 *active_cursor
= 0;
19915 /* Nonselected window or nonselected frame. */
19916 else if (w
!= XWINDOW (f
->selected_window
)
19917 #ifdef HAVE_WINDOW_SYSTEM
19918 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
19922 *active_cursor
= 0;
19924 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
19930 /* Never display a cursor in a window in which cursor-type is nil. */
19931 if (NILP (b
->cursor_type
))
19934 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
19937 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
19938 return get_specified_cursor_type (alt_cursor
, width
);
19941 /* Get the normal cursor type for this window. */
19942 if (EQ (b
->cursor_type
, Qt
))
19944 cursor_type
= FRAME_DESIRED_CURSOR (f
);
19945 *width
= FRAME_CURSOR_WIDTH (f
);
19948 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
19950 /* Use normal cursor if not blinked off. */
19951 if (!w
->cursor_off_p
)
19953 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
19954 if (cursor_type
== FILLED_BOX_CURSOR
)
19955 cursor_type
= HOLLOW_BOX_CURSOR
;
19957 return cursor_type
;
19960 /* Cursor is blinked off, so determine how to "toggle" it. */
19962 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
19963 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
19964 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
19966 /* Then see if frame has specified a specific blink off cursor type. */
19967 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
19969 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
19970 return FRAME_BLINK_OFF_CURSOR (f
);
19974 /* Some people liked having a permanently visible blinking cursor,
19975 while others had very strong opinions against it. So it was
19976 decided to remove it. KFS 2003-09-03 */
19978 /* Finally perform built-in cursor blinking:
19979 filled box <-> hollow box
19980 wide [h]bar <-> narrow [h]bar
19981 narrow [h]bar <-> no cursor
19982 other type <-> no cursor */
19984 if (cursor_type
== FILLED_BOX_CURSOR
)
19985 return HOLLOW_BOX_CURSOR
;
19987 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
19990 return cursor_type
;
19998 #ifdef HAVE_WINDOW_SYSTEM
20000 /* Notice when the text cursor of window W has been completely
20001 overwritten by a drawing operation that outputs glyphs in AREA
20002 starting at X0 and ending at X1 in the line starting at Y0 and
20003 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20004 the rest of the line after X0 has been written. Y coordinates
20005 are window-relative. */
20008 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20010 enum glyph_row_area area
;
20011 int x0
, y0
, x1
, y1
;
20013 int cx0
, cx1
, cy0
, cy1
;
20014 struct glyph_row
*row
;
20016 if (!w
->phys_cursor_on_p
)
20018 if (area
!= TEXT_AREA
)
20021 row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
;
20022 if (!row
->displays_text_p
)
20025 if (row
->cursor_in_fringe_p
)
20027 row
->cursor_in_fringe_p
= 0;
20028 draw_fringe_bitmap (w
, row
, 0);
20029 w
->phys_cursor_on_p
= 0;
20033 cx0
= w
->phys_cursor
.x
;
20034 cx1
= cx0
+ w
->phys_cursor_width
;
20035 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20038 /* The cursor image will be completely removed from the
20039 screen if the output area intersects the cursor area in
20040 y-direction. When we draw in [y0 y1[, and some part of
20041 the cursor is at y < y0, that part must have been drawn
20042 before. When scrolling, the cursor is erased before
20043 actually scrolling, so we don't come here. When not
20044 scrolling, the rows above the old cursor row must have
20045 changed, and in this case these rows must have written
20046 over the cursor image.
20048 Likewise if part of the cursor is below y1, with the
20049 exception of the cursor being in the first blank row at
20050 the buffer and window end because update_text_area
20051 doesn't draw that row. (Except when it does, but
20052 that's handled in update_text_area.) */
20054 cy0
= w
->phys_cursor
.y
;
20055 cy1
= cy0
+ w
->phys_cursor_height
;
20056 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20059 w
->phys_cursor_on_p
= 0;
20062 #endif /* HAVE_WINDOW_SYSTEM */
20065 /************************************************************************
20067 ************************************************************************/
20069 #ifdef HAVE_WINDOW_SYSTEM
20072 Fix the display of area AREA of overlapping row ROW in window W. */
20075 x_fix_overlapping_area (w
, row
, area
)
20077 struct glyph_row
*row
;
20078 enum glyph_row_area area
;
20085 for (i
= 0; i
< row
->used
[area
];)
20087 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20089 int start
= i
, start_x
= x
;
20093 x
+= row
->glyphs
[area
][i
].pixel_width
;
20096 while (i
< row
->used
[area
]
20097 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20099 draw_glyphs (w
, start_x
, row
, area
,
20101 DRAW_NORMAL_TEXT
, 1);
20105 x
+= row
->glyphs
[area
][i
].pixel_width
;
20115 Draw the cursor glyph of window W in glyph row ROW. See the
20116 comment of draw_glyphs for the meaning of HL. */
20119 draw_phys_cursor_glyph (w
, row
, hl
)
20121 struct glyph_row
*row
;
20122 enum draw_glyphs_face hl
;
20124 /* If cursor hpos is out of bounds, don't draw garbage. This can
20125 happen in mini-buffer windows when switching between echo area
20126 glyphs and mini-buffer. */
20127 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20129 int on_p
= w
->phys_cursor_on_p
;
20131 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20132 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
20134 w
->phys_cursor_on_p
= on_p
;
20136 if (hl
== DRAW_CURSOR
)
20137 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
20138 /* When we erase the cursor, and ROW is overlapped by other
20139 rows, make sure that these overlapping parts of other rows
20141 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
20143 if (row
> w
->current_matrix
->rows
20144 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
20145 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
20147 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
20148 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
20149 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
20156 Erase the image of a cursor of window W from the screen. */
20159 erase_phys_cursor (w
)
20162 struct frame
*f
= XFRAME (w
->frame
);
20163 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20164 int hpos
= w
->phys_cursor
.hpos
;
20165 int vpos
= w
->phys_cursor
.vpos
;
20166 int mouse_face_here_p
= 0;
20167 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
20168 struct glyph_row
*cursor_row
;
20169 struct glyph
*cursor_glyph
;
20170 enum draw_glyphs_face hl
;
20172 /* No cursor displayed or row invalidated => nothing to do on the
20174 if (w
->phys_cursor_type
== NO_CURSOR
)
20175 goto mark_cursor_off
;
20177 /* VPOS >= active_glyphs->nrows means that window has been resized.
20178 Don't bother to erase the cursor. */
20179 if (vpos
>= active_glyphs
->nrows
)
20180 goto mark_cursor_off
;
20182 /* If row containing cursor is marked invalid, there is nothing we
20184 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
20185 if (!cursor_row
->enabled_p
)
20186 goto mark_cursor_off
;
20188 /* If line spacing is > 0, old cursor may only be partially visible in
20189 window after split-window. So adjust visible height. */
20190 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
20191 window_text_bottom_y (w
) - cursor_row
->y
);
20193 /* If row is completely invisible, don't attempt to delete a cursor which
20194 isn't there. This can happen if cursor is at top of a window, and
20195 we switch to a buffer with a header line in that window. */
20196 if (cursor_row
->visible_height
<= 0)
20197 goto mark_cursor_off
;
20199 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
20200 if (cursor_row
->cursor_in_fringe_p
)
20202 cursor_row
->cursor_in_fringe_p
= 0;
20203 draw_fringe_bitmap (w
, cursor_row
, 0);
20204 goto mark_cursor_off
;
20207 /* This can happen when the new row is shorter than the old one.
20208 In this case, either draw_glyphs or clear_end_of_line
20209 should have cleared the cursor. Note that we wouldn't be
20210 able to erase the cursor in this case because we don't have a
20211 cursor glyph at hand. */
20212 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
20213 goto mark_cursor_off
;
20215 /* If the cursor is in the mouse face area, redisplay that when
20216 we clear the cursor. */
20217 if (! NILP (dpyinfo
->mouse_face_window
)
20218 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
20219 && (vpos
> dpyinfo
->mouse_face_beg_row
20220 || (vpos
== dpyinfo
->mouse_face_beg_row
20221 && hpos
>= dpyinfo
->mouse_face_beg_col
))
20222 && (vpos
< dpyinfo
->mouse_face_end_row
20223 || (vpos
== dpyinfo
->mouse_face_end_row
20224 && hpos
< dpyinfo
->mouse_face_end_col
))
20225 /* Don't redraw the cursor's spot in mouse face if it is at the
20226 end of a line (on a newline). The cursor appears there, but
20227 mouse highlighting does not. */
20228 && cursor_row
->used
[TEXT_AREA
] > hpos
)
20229 mouse_face_here_p
= 1;
20231 /* Maybe clear the display under the cursor. */
20232 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
20235 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
20238 cursor_glyph
= get_phys_cursor_glyph (w
);
20239 if (cursor_glyph
== NULL
)
20240 goto mark_cursor_off
;
20242 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
20243 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
20244 width
= min (cursor_glyph
->pixel_width
,
20245 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
20247 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
20250 /* Erase the cursor by redrawing the character underneath it. */
20251 if (mouse_face_here_p
)
20252 hl
= DRAW_MOUSE_FACE
;
20254 hl
= DRAW_NORMAL_TEXT
;
20255 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
20258 w
->phys_cursor_on_p
= 0;
20259 w
->phys_cursor_type
= NO_CURSOR
;
20264 Display or clear cursor of window W. If ON is zero, clear the
20265 cursor. If it is non-zero, display the cursor. If ON is nonzero,
20266 where to put the cursor is specified by HPOS, VPOS, X and Y. */
20269 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
20271 int on
, hpos
, vpos
, x
, y
;
20273 struct frame
*f
= XFRAME (w
->frame
);
20274 int new_cursor_type
;
20275 int new_cursor_width
;
20277 struct glyph_row
*glyph_row
;
20278 struct glyph
*glyph
;
20280 /* This is pointless on invisible frames, and dangerous on garbaged
20281 windows and frames; in the latter case, the frame or window may
20282 be in the midst of changing its size, and x and y may be off the
20284 if (! FRAME_VISIBLE_P (f
)
20285 || FRAME_GARBAGED_P (f
)
20286 || vpos
>= w
->current_matrix
->nrows
20287 || hpos
>= w
->current_matrix
->matrix_w
)
20290 /* If cursor is off and we want it off, return quickly. */
20291 if (!on
&& !w
->phys_cursor_on_p
)
20294 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
20295 /* If cursor row is not enabled, we don't really know where to
20296 display the cursor. */
20297 if (!glyph_row
->enabled_p
)
20299 w
->phys_cursor_on_p
= 0;
20304 if (!glyph_row
->exact_window_width_line_p
20305 || hpos
< glyph_row
->used
[TEXT_AREA
])
20306 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
20308 xassert (interrupt_input_blocked
);
20310 /* Set new_cursor_type to the cursor we want to be displayed. */
20311 new_cursor_type
= get_window_cursor_type (w
, glyph
,
20312 &new_cursor_width
, &active_cursor
);
20314 /* If cursor is currently being shown and we don't want it to be or
20315 it is in the wrong place, or the cursor type is not what we want,
20317 if (w
->phys_cursor_on_p
20319 || w
->phys_cursor
.x
!= x
20320 || w
->phys_cursor
.y
!= y
20321 || new_cursor_type
!= w
->phys_cursor_type
20322 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
20323 && new_cursor_width
!= w
->phys_cursor_width
)))
20324 erase_phys_cursor (w
);
20326 /* Don't check phys_cursor_on_p here because that flag is only set
20327 to zero in some cases where we know that the cursor has been
20328 completely erased, to avoid the extra work of erasing the cursor
20329 twice. In other words, phys_cursor_on_p can be 1 and the cursor
20330 still not be visible, or it has only been partly erased. */
20333 w
->phys_cursor_ascent
= glyph_row
->ascent
;
20334 w
->phys_cursor_height
= glyph_row
->height
;
20336 /* Set phys_cursor_.* before x_draw_.* is called because some
20337 of them may need the information. */
20338 w
->phys_cursor
.x
= x
;
20339 w
->phys_cursor
.y
= glyph_row
->y
;
20340 w
->phys_cursor
.hpos
= hpos
;
20341 w
->phys_cursor
.vpos
= vpos
;
20344 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
20345 new_cursor_type
, new_cursor_width
,
20346 on
, active_cursor
);
20350 /* Switch the display of W's cursor on or off, according to the value
20354 update_window_cursor (w
, on
)
20358 /* Don't update cursor in windows whose frame is in the process
20359 of being deleted. */
20360 if (w
->current_matrix
)
20363 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20364 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20370 /* Call update_window_cursor with parameter ON_P on all leaf windows
20371 in the window tree rooted at W. */
20374 update_cursor_in_window_tree (w
, on_p
)
20380 if (!NILP (w
->hchild
))
20381 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20382 else if (!NILP (w
->vchild
))
20383 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20385 update_window_cursor (w
, on_p
);
20387 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20393 Display the cursor on window W, or clear it, according to ON_P.
20394 Don't change the cursor's position. */
20397 x_update_cursor (f
, on_p
)
20401 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20406 Clear the cursor of window W to background color, and mark the
20407 cursor as not shown. This is used when the text where the cursor
20408 is is about to be rewritten. */
20414 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20415 update_window_cursor (w
, 0);
20420 Display the active region described by mouse_face_* according to DRAW. */
20423 show_mouse_face (dpyinfo
, draw
)
20424 Display_Info
*dpyinfo
;
20425 enum draw_glyphs_face draw
;
20427 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20428 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20430 if (/* If window is in the process of being destroyed, don't bother
20432 w
->current_matrix
!= NULL
20433 /* Don't update mouse highlight if hidden */
20434 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20435 /* Recognize when we are called to operate on rows that don't exist
20436 anymore. This can happen when a window is split. */
20437 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20439 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20440 struct glyph_row
*row
, *first
, *last
;
20442 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20443 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20445 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20447 int start_hpos
, end_hpos
, start_x
;
20449 /* For all but the first row, the highlight starts at column 0. */
20452 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20453 start_x
= dpyinfo
->mouse_face_beg_x
;
20462 end_hpos
= dpyinfo
->mouse_face_end_col
;
20464 end_hpos
= row
->used
[TEXT_AREA
];
20466 if (end_hpos
> start_hpos
)
20468 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20469 start_hpos
, end_hpos
,
20473 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20477 /* When we've written over the cursor, arrange for it to
20478 be displayed again. */
20479 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20482 display_and_set_cursor (w
, 1,
20483 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20484 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20489 /* Change the mouse cursor. */
20490 if (draw
== DRAW_NORMAL_TEXT
)
20491 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
20492 else if (draw
== DRAW_MOUSE_FACE
)
20493 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
20495 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
20499 Clear out the mouse-highlighted active region.
20500 Redraw it un-highlighted first. Value is non-zero if mouse
20501 face was actually drawn unhighlighted. */
20504 clear_mouse_face (dpyinfo
)
20505 Display_Info
*dpyinfo
;
20509 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
20511 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
20515 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20516 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20517 dpyinfo
->mouse_face_window
= Qnil
;
20518 dpyinfo
->mouse_face_overlay
= Qnil
;
20524 Non-zero if physical cursor of window W is within mouse face. */
20527 cursor_in_mouse_face_p (w
)
20530 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20531 int in_mouse_face
= 0;
20533 if (WINDOWP (dpyinfo
->mouse_face_window
)
20534 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
20536 int hpos
= w
->phys_cursor
.hpos
;
20537 int vpos
= w
->phys_cursor
.vpos
;
20539 if (vpos
>= dpyinfo
->mouse_face_beg_row
20540 && vpos
<= dpyinfo
->mouse_face_end_row
20541 && (vpos
> dpyinfo
->mouse_face_beg_row
20542 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20543 && (vpos
< dpyinfo
->mouse_face_end_row
20544 || hpos
< dpyinfo
->mouse_face_end_col
20545 || dpyinfo
->mouse_face_past_end
))
20549 return in_mouse_face
;
20555 /* Find the glyph matrix position of buffer position CHARPOS in window
20556 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
20557 current glyphs must be up to date. If CHARPOS is above window
20558 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
20559 of last line in W. In the row containing CHARPOS, stop before glyphs
20560 having STOP as object. */
20562 #if 1 /* This is a version of fast_find_position that's more correct
20563 in the presence of hscrolling, for example. I didn't install
20564 it right away because the problem fixed is minor, it failed
20565 in 20.x as well, and I think it's too risky to install
20566 so near the release of 21.1. 2001-09-25 gerd. */
20569 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
20572 int *hpos
, *vpos
, *x
, *y
;
20575 struct glyph_row
*row
, *first
;
20576 struct glyph
*glyph
, *end
;
20579 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20580 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
20585 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
20589 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
20592 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
20598 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20600 glyph
= row
->glyphs
[TEXT_AREA
];
20601 end
= glyph
+ row
->used
[TEXT_AREA
];
20603 /* Skip over glyphs not having an object at the start of the row.
20604 These are special glyphs like truncation marks on terminal
20606 if (row
->displays_text_p
)
20608 && INTEGERP (glyph
->object
)
20609 && !EQ (stop
, glyph
->object
)
20610 && glyph
->charpos
< 0)
20612 *x
+= glyph
->pixel_width
;
20617 && !INTEGERP (glyph
->object
)
20618 && !EQ (stop
, glyph
->object
)
20619 && (!BUFFERP (glyph
->object
)
20620 || glyph
->charpos
< charpos
))
20622 *x
+= glyph
->pixel_width
;
20626 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
20633 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
20636 int *hpos
, *vpos
, *x
, *y
;
20641 int maybe_next_line_p
= 0;
20642 int line_start_position
;
20643 int yb
= window_text_bottom_y (w
);
20644 struct glyph_row
*row
, *best_row
;
20645 int row_vpos
, best_row_vpos
;
20648 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20649 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
20651 while (row
->y
< yb
)
20653 if (row
->used
[TEXT_AREA
])
20654 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
20656 line_start_position
= 0;
20658 if (line_start_position
> pos
)
20660 /* If the position sought is the end of the buffer,
20661 don't include the blank lines at the bottom of the window. */
20662 else if (line_start_position
== pos
20663 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
20665 maybe_next_line_p
= 1;
20668 else if (line_start_position
> 0)
20671 best_row_vpos
= row_vpos
;
20674 if (row
->y
+ row
->height
>= yb
)
20681 /* Find the right column within BEST_ROW. */
20683 current_x
= best_row
->x
;
20684 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
20686 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
20687 int charpos
= glyph
->charpos
;
20689 if (BUFFERP (glyph
->object
))
20691 if (charpos
== pos
)
20694 *vpos
= best_row_vpos
;
20699 else if (charpos
> pos
)
20702 else if (EQ (glyph
->object
, stop
))
20707 current_x
+= glyph
->pixel_width
;
20710 /* If we're looking for the end of the buffer,
20711 and we didn't find it in the line we scanned,
20712 use the start of the following line. */
20713 if (maybe_next_line_p
)
20718 current_x
= best_row
->x
;
20721 *vpos
= best_row_vpos
;
20722 *hpos
= lastcol
+ 1;
20731 /* Find the position of the glyph for position POS in OBJECT in
20732 window W's current matrix, and return in *X, *Y the pixel
20733 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
20735 RIGHT_P non-zero means return the position of the right edge of the
20736 glyph, RIGHT_P zero means return the left edge position.
20738 If no glyph for POS exists in the matrix, return the position of
20739 the glyph with the next smaller position that is in the matrix, if
20740 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
20741 exists in the matrix, return the position of the glyph with the
20742 next larger position in OBJECT.
20744 Value is non-zero if a glyph was found. */
20747 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
20750 Lisp_Object object
;
20751 int *hpos
, *vpos
, *x
, *y
;
20754 int yb
= window_text_bottom_y (w
);
20755 struct glyph_row
*r
;
20756 struct glyph
*best_glyph
= NULL
;
20757 struct glyph_row
*best_row
= NULL
;
20760 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20761 r
->enabled_p
&& r
->y
< yb
;
20764 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
20765 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
20768 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
20769 if (EQ (g
->object
, object
))
20771 if (g
->charpos
== pos
)
20778 else if (best_glyph
== NULL
20779 || ((abs (g
->charpos
- pos
)
20780 < abs (best_glyph
->charpos
- pos
))
20783 : g
->charpos
> pos
)))
20797 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
20801 *x
+= best_glyph
->pixel_width
;
20806 *vpos
= best_row
- w
->current_matrix
->rows
;
20809 return best_glyph
!= NULL
;
20813 /* See if position X, Y is within a hot-spot of an image. */
20816 on_hot_spot_p (hot_spot
, x
, y
)
20817 Lisp_Object hot_spot
;
20820 if (!CONSP (hot_spot
))
20823 if (EQ (XCAR (hot_spot
), Qrect
))
20825 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
20826 Lisp_Object rect
= XCDR (hot_spot
);
20830 if (!CONSP (XCAR (rect
)))
20832 if (!CONSP (XCDR (rect
)))
20834 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
20836 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
20838 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
20840 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
20844 else if (EQ (XCAR (hot_spot
), Qcircle
))
20846 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
20847 Lisp_Object circ
= XCDR (hot_spot
);
20848 Lisp_Object lr
, lx0
, ly0
;
20850 && CONSP (XCAR (circ
))
20851 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
20852 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
20853 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
20855 double r
= XFLOATINT (lr
);
20856 double dx
= XINT (lx0
) - x
;
20857 double dy
= XINT (ly0
) - y
;
20858 return (dx
* dx
+ dy
* dy
<= r
* r
);
20861 else if (EQ (XCAR (hot_spot
), Qpoly
))
20863 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
20864 if (VECTORP (XCDR (hot_spot
)))
20866 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
20867 Lisp_Object
*poly
= v
->contents
;
20871 Lisp_Object lx
, ly
;
20874 /* Need an even number of coordinates, and at least 3 edges. */
20875 if (n
< 6 || n
& 1)
20878 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
20879 If count is odd, we are inside polygon. Pixels on edges
20880 may or may not be included depending on actual geometry of the
20882 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
20883 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
20885 x0
= XINT (lx
), y0
= XINT (ly
);
20886 for (i
= 0; i
< n
; i
+= 2)
20888 int x1
= x0
, y1
= y0
;
20889 if ((lx
= poly
[i
], !INTEGERP (lx
))
20890 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
20892 x0
= XINT (lx
), y0
= XINT (ly
);
20894 /* Does this segment cross the X line? */
20902 if (y
> y0
&& y
> y1
)
20904 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
20910 /* If we don't understand the format, pretend we're not in the hot-spot. */
20915 find_hot_spot (map
, x
, y
)
20919 while (CONSP (map
))
20921 if (CONSP (XCAR (map
))
20922 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
20930 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
20932 doc
: /* Lookup in image map MAP coordinates X and Y.
20933 An image map is an alist where each element has the format (AREA ID PLIST).
20934 An AREA is specified as either a rectangle, a circle, or a polygon:
20935 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
20936 pixel coordinates of the upper left and bottom right corners.
20937 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
20938 and the radius of the circle; r may be a float or integer.
20939 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
20940 vector describes one corner in the polygon.
20941 Returns the alist element for the first matching AREA in MAP. */)
20952 return find_hot_spot (map
, XINT (x
), XINT (y
));
20956 /* Display frame CURSOR, optionally using shape defined by POINTER. */
20958 define_frame_cursor1 (f
, cursor
, pointer
)
20961 Lisp_Object pointer
;
20963 /* Do not change cursor shape while dragging mouse. */
20964 if (!NILP (do_mouse_tracking
))
20967 if (!NILP (pointer
))
20969 if (EQ (pointer
, Qarrow
))
20970 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20971 else if (EQ (pointer
, Qhand
))
20972 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
20973 else if (EQ (pointer
, Qtext
))
20974 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
20975 else if (EQ (pointer
, intern ("hdrag")))
20976 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
20977 #ifdef HAVE_X_WINDOWS
20978 else if (EQ (pointer
, intern ("vdrag")))
20979 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
20981 else if (EQ (pointer
, intern ("hourglass")))
20982 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
20983 else if (EQ (pointer
, Qmodeline
))
20984 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
20986 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
20989 if (cursor
!= No_Cursor
)
20990 rif
->define_frame_cursor (f
, cursor
);
20993 /* Take proper action when mouse has moved to the mode or header line
20994 or marginal area AREA of window W, x-position X and y-position Y.
20995 X is relative to the start of the text display area of W, so the
20996 width of bitmap areas and scroll bars must be subtracted to get a
20997 position relative to the start of the mode line. */
21000 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
21003 enum window_part area
;
21005 struct frame
*f
= XFRAME (w
->frame
);
21006 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21007 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21008 Lisp_Object pointer
= Qnil
;
21009 int charpos
, dx
, dy
, width
, height
;
21010 Lisp_Object string
, object
= Qnil
;
21011 Lisp_Object pos
, help
;
21013 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21014 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21015 &object
, &dx
, &dy
, &width
, &height
);
21018 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
21019 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
21020 &object
, &dx
, &dy
, &width
, &height
);
21025 if (IMAGEP (object
))
21027 Lisp_Object image_map
, hotspot
;
21028 if ((image_map
= Fsafe_plist_get (XCDR (object
), QCmap
),
21030 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
21032 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21034 Lisp_Object area_id
, plist
;
21036 area_id
= XCAR (hotspot
);
21037 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21038 If so, we could look for mouse-enter, mouse-leave
21039 properties in PLIST (and do something...). */
21040 hotspot
= XCDR (hotspot
);
21041 if (CONSP (hotspot
)
21042 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21044 pointer
= Fsafe_plist_get (plist
, Qpointer
);
21045 if (NILP (pointer
))
21047 help
= Fsafe_plist_get (plist
, Qhelp_echo
);
21050 help_echo_string
= help
;
21051 /* Is this correct? ++kfs */
21052 XSETWINDOW (help_echo_window
, w
);
21053 help_echo_object
= w
->buffer
;
21054 help_echo_pos
= charpos
;
21057 if (NILP (pointer
))
21058 pointer
= Fsafe_plist_get (XCDR (object
), QCpointer
);
21062 if (STRINGP (string
))
21064 pos
= make_number (charpos
);
21065 /* If we're on a string with `help-echo' text property, arrange
21066 for the help to be displayed. This is done by setting the
21067 global variable help_echo_string to the help string. */
21070 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
21073 help_echo_string
= help
;
21074 XSETWINDOW (help_echo_window
, w
);
21075 help_echo_object
= string
;
21076 help_echo_pos
= charpos
;
21080 if (NILP (pointer
))
21081 pointer
= Fget_text_property (pos
, Qpointer
, string
);
21083 /* Change the mouse pointer according to what is under X/Y. */
21084 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
21087 map
= Fget_text_property (pos
, Qlocal_map
, string
);
21088 if (!KEYMAPP (map
))
21089 map
= Fget_text_property (pos
, Qkeymap
, string
);
21090 if (!KEYMAPP (map
))
21091 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
21095 define_frame_cursor1 (f
, cursor
, pointer
);
21100 Take proper action when the mouse has moved to position X, Y on
21101 frame F as regards highlighting characters that have mouse-face
21102 properties. Also de-highlighting chars where the mouse was before.
21103 X and Y can be negative or out of range. */
21106 note_mouse_highlight (f
, x
, y
)
21110 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21111 enum window_part part
;
21112 Lisp_Object window
;
21114 Cursor cursor
= No_Cursor
;
21115 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
21118 /* When a menu is active, don't highlight because this looks odd. */
21119 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
21120 if (popup_activated ())
21124 if (NILP (Vmouse_highlight
)
21125 || !f
->glyphs_initialized_p
)
21128 dpyinfo
->mouse_face_mouse_x
= x
;
21129 dpyinfo
->mouse_face_mouse_y
= y
;
21130 dpyinfo
->mouse_face_mouse_frame
= f
;
21132 if (dpyinfo
->mouse_face_defer
)
21135 if (gc_in_progress
)
21137 dpyinfo
->mouse_face_deferred_gc
= 1;
21141 /* Which window is that in? */
21142 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
21144 /* If we were displaying active text in another window, clear that.
21145 Also clear if we move out of text area in same window. */
21146 if (! EQ (window
, dpyinfo
->mouse_face_window
)
21147 || (part
!= ON_TEXT
&& !NILP (dpyinfo
->mouse_face_window
)))
21148 clear_mouse_face (dpyinfo
);
21150 /* Not on a window -> return. */
21151 if (!WINDOWP (window
))
21154 /* Reset help_echo_string. It will get recomputed below. */
21155 help_echo_string
= Qnil
;
21157 /* Convert to window-relative pixel coordinates. */
21158 w
= XWINDOW (window
);
21159 frame_to_window_pixel_xy (w
, &x
, &y
);
21161 /* Handle tool-bar window differently since it doesn't display a
21163 if (EQ (window
, f
->tool_bar_window
))
21165 note_tool_bar_highlight (f
, x
, y
);
21169 /* Mouse is on the mode, header line or margin? */
21170 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
21171 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
21173 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
21177 if (part
== ON_VERTICAL_BORDER
)
21178 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21179 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
21180 || part
== ON_SCROLL_BAR
)
21181 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21183 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21185 /* Are we in a window whose display is up to date?
21186 And verify the buffer's text has not changed. */
21187 b
= XBUFFER (w
->buffer
);
21188 if (part
== ON_TEXT
21189 && EQ (w
->window_end_valid
, w
->buffer
)
21190 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
21191 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
21193 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
21194 struct glyph
*glyph
;
21195 Lisp_Object object
;
21196 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
21197 Lisp_Object
*overlay_vec
= NULL
;
21199 struct buffer
*obuf
;
21200 int obegv
, ozv
, same_region
;
21202 /* Find the glyph under X/Y. */
21203 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
21205 /* Look for :pointer property on image. */
21206 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21208 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21209 if (img
!= NULL
&& IMAGEP (img
->spec
))
21211 Lisp_Object image_map
, hotspot
;
21212 if ((image_map
= Fsafe_plist_get (XCDR (img
->spec
), QCmap
),
21214 && (hotspot
= find_hot_spot (image_map
,
21215 glyph
->slice
.x
+ dx
,
21216 glyph
->slice
.y
+ dy
),
21218 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21220 Lisp_Object area_id
, plist
;
21222 area_id
= XCAR (hotspot
);
21223 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21224 If so, we could look for mouse-enter, mouse-leave
21225 properties in PLIST (and do something...). */
21226 hotspot
= XCDR (hotspot
);
21227 if (CONSP (hotspot
)
21228 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21230 pointer
= Fsafe_plist_get (plist
, Qpointer
);
21231 if (NILP (pointer
))
21233 help_echo_string
= Fsafe_plist_get (plist
, Qhelp_echo
);
21234 if (!NILP (help_echo_string
))
21236 help_echo_window
= window
;
21237 help_echo_object
= glyph
->object
;
21238 help_echo_pos
= glyph
->charpos
;
21242 if (NILP (pointer
))
21243 pointer
= Fsafe_plist_get (XCDR (img
->spec
), QCpointer
);
21247 /* Clear mouse face if X/Y not over text. */
21249 || area
!= TEXT_AREA
21250 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
21252 if (clear_mouse_face (dpyinfo
))
21253 cursor
= No_Cursor
;
21254 if (NILP (pointer
))
21256 if (area
!= TEXT_AREA
)
21257 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21259 pointer
= Vvoid_text_area_pointer
;
21264 pos
= glyph
->charpos
;
21265 object
= glyph
->object
;
21266 if (!STRINGP (object
) && !BUFFERP (object
))
21269 /* If we get an out-of-range value, return now; avoid an error. */
21270 if (BUFFERP (object
) && pos
> BUF_Z (b
))
21273 /* Make the window's buffer temporarily current for
21274 overlays_at and compute_char_face. */
21275 obuf
= current_buffer
;
21276 current_buffer
= b
;
21282 /* Is this char mouse-active or does it have help-echo? */
21283 position
= make_number (pos
);
21285 if (BUFFERP (object
))
21287 /* Put all the overlays we want in a vector in overlay_vec. */
21288 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
21289 /* Sort overlays into increasing priority order. */
21290 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
21295 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
21296 && vpos
>= dpyinfo
->mouse_face_beg_row
21297 && vpos
<= dpyinfo
->mouse_face_end_row
21298 && (vpos
> dpyinfo
->mouse_face_beg_row
21299 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21300 && (vpos
< dpyinfo
->mouse_face_end_row
21301 || hpos
< dpyinfo
->mouse_face_end_col
21302 || dpyinfo
->mouse_face_past_end
));
21305 cursor
= No_Cursor
;
21307 /* Check mouse-face highlighting. */
21309 /* If there exists an overlay with mouse-face overlapping
21310 the one we are currently highlighting, we have to
21311 check if we enter the overlapping overlay, and then
21312 highlight only that. */
21313 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
21314 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
21316 /* Find the highest priority overlay that has a mouse-face
21319 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
21321 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
21322 if (!NILP (mouse_face
))
21323 overlay
= overlay_vec
[i
];
21326 /* If we're actually highlighting the same overlay as
21327 before, there's no need to do that again. */
21328 if (!NILP (overlay
)
21329 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
21330 goto check_help_echo
;
21332 dpyinfo
->mouse_face_overlay
= overlay
;
21334 /* Clear the display of the old active region, if any. */
21335 if (clear_mouse_face (dpyinfo
))
21336 cursor
= No_Cursor
;
21338 /* If no overlay applies, get a text property. */
21339 if (NILP (overlay
))
21340 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
21342 /* Handle the overlay case. */
21343 if (!NILP (overlay
))
21345 /* Find the range of text around this char that
21346 should be active. */
21347 Lisp_Object before
, after
;
21350 before
= Foverlay_start (overlay
);
21351 after
= Foverlay_end (overlay
);
21352 /* Record this as the current active region. */
21353 fast_find_position (w
, XFASTINT (before
),
21354 &dpyinfo
->mouse_face_beg_col
,
21355 &dpyinfo
->mouse_face_beg_row
,
21356 &dpyinfo
->mouse_face_beg_x
,
21357 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21359 dpyinfo
->mouse_face_past_end
21360 = !fast_find_position (w
, XFASTINT (after
),
21361 &dpyinfo
->mouse_face_end_col
,
21362 &dpyinfo
->mouse_face_end_row
,
21363 &dpyinfo
->mouse_face_end_x
,
21364 &dpyinfo
->mouse_face_end_y
, Qnil
);
21365 dpyinfo
->mouse_face_window
= window
;
21367 dpyinfo
->mouse_face_face_id
21368 = face_at_buffer_position (w
, pos
, 0, 0,
21370 !dpyinfo
->mouse_face_hidden
);
21372 /* Display it as active. */
21373 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21374 cursor
= No_Cursor
;
21376 /* Handle the text property case. */
21377 else if (!NILP (mouse_face
) && BUFFERP (object
))
21379 /* Find the range of text around this char that
21380 should be active. */
21381 Lisp_Object before
, after
, beginning
, end
;
21384 beginning
= Fmarker_position (w
->start
);
21385 end
= make_number (BUF_Z (XBUFFER (object
))
21386 - XFASTINT (w
->window_end_pos
));
21388 = Fprevious_single_property_change (make_number (pos
+ 1),
21390 object
, beginning
);
21392 = Fnext_single_property_change (position
, Qmouse_face
,
21395 /* Record this as the current active region. */
21396 fast_find_position (w
, XFASTINT (before
),
21397 &dpyinfo
->mouse_face_beg_col
,
21398 &dpyinfo
->mouse_face_beg_row
,
21399 &dpyinfo
->mouse_face_beg_x
,
21400 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21401 dpyinfo
->mouse_face_past_end
21402 = !fast_find_position (w
, XFASTINT (after
),
21403 &dpyinfo
->mouse_face_end_col
,
21404 &dpyinfo
->mouse_face_end_row
,
21405 &dpyinfo
->mouse_face_end_x
,
21406 &dpyinfo
->mouse_face_end_y
, Qnil
);
21407 dpyinfo
->mouse_face_window
= window
;
21409 if (BUFFERP (object
))
21410 dpyinfo
->mouse_face_face_id
21411 = face_at_buffer_position (w
, pos
, 0, 0,
21413 !dpyinfo
->mouse_face_hidden
);
21415 /* Display it as active. */
21416 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21417 cursor
= No_Cursor
;
21419 else if (!NILP (mouse_face
) && STRINGP (object
))
21424 b
= Fprevious_single_property_change (make_number (pos
+ 1),
21427 e
= Fnext_single_property_change (position
, Qmouse_face
,
21430 b
= make_number (0);
21432 e
= make_number (SCHARS (object
) - 1);
21433 fast_find_string_pos (w
, XINT (b
), object
,
21434 &dpyinfo
->mouse_face_beg_col
,
21435 &dpyinfo
->mouse_face_beg_row
,
21436 &dpyinfo
->mouse_face_beg_x
,
21437 &dpyinfo
->mouse_face_beg_y
, 0);
21438 fast_find_string_pos (w
, XINT (e
), object
,
21439 &dpyinfo
->mouse_face_end_col
,
21440 &dpyinfo
->mouse_face_end_row
,
21441 &dpyinfo
->mouse_face_end_x
,
21442 &dpyinfo
->mouse_face_end_y
, 1);
21443 dpyinfo
->mouse_face_past_end
= 0;
21444 dpyinfo
->mouse_face_window
= window
;
21445 dpyinfo
->mouse_face_face_id
21446 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
21447 glyph
->face_id
, 1);
21448 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21449 cursor
= No_Cursor
;
21451 else if (STRINGP (object
) && NILP (mouse_face
))
21453 /* A string which doesn't have mouse-face, but
21454 the text ``under'' it might have. */
21455 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
21456 int start
= MATRIX_ROW_START_CHARPOS (r
);
21458 pos
= string_buffer_position (w
, object
, start
);
21460 mouse_face
= get_char_property_and_overlay (make_number (pos
),
21464 if (!NILP (mouse_face
) && !NILP (overlay
))
21466 Lisp_Object before
= Foverlay_start (overlay
);
21467 Lisp_Object after
= Foverlay_end (overlay
);
21470 /* Note that we might not be able to find position
21471 BEFORE in the glyph matrix if the overlay is
21472 entirely covered by a `display' property. In
21473 this case, we overshoot. So let's stop in
21474 the glyph matrix before glyphs for OBJECT. */
21475 fast_find_position (w
, XFASTINT (before
),
21476 &dpyinfo
->mouse_face_beg_col
,
21477 &dpyinfo
->mouse_face_beg_row
,
21478 &dpyinfo
->mouse_face_beg_x
,
21479 &dpyinfo
->mouse_face_beg_y
,
21482 dpyinfo
->mouse_face_past_end
21483 = !fast_find_position (w
, XFASTINT (after
),
21484 &dpyinfo
->mouse_face_end_col
,
21485 &dpyinfo
->mouse_face_end_row
,
21486 &dpyinfo
->mouse_face_end_x
,
21487 &dpyinfo
->mouse_face_end_y
,
21489 dpyinfo
->mouse_face_window
= window
;
21490 dpyinfo
->mouse_face_face_id
21491 = face_at_buffer_position (w
, pos
, 0, 0,
21493 !dpyinfo
->mouse_face_hidden
);
21495 /* Display it as active. */
21496 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21497 cursor
= No_Cursor
;
21504 /* Look for a `help-echo' property. */
21505 if (NILP (help_echo_string
)) {
21506 Lisp_Object help
, overlay
;
21508 /* Check overlays first. */
21509 help
= overlay
= Qnil
;
21510 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
21512 overlay
= overlay_vec
[i
];
21513 help
= Foverlay_get (overlay
, Qhelp_echo
);
21518 help_echo_string
= help
;
21519 help_echo_window
= window
;
21520 help_echo_object
= overlay
;
21521 help_echo_pos
= pos
;
21525 Lisp_Object object
= glyph
->object
;
21526 int charpos
= glyph
->charpos
;
21528 /* Try text properties. */
21529 if (STRINGP (object
)
21531 && charpos
< SCHARS (object
))
21533 help
= Fget_text_property (make_number (charpos
),
21534 Qhelp_echo
, object
);
21537 /* If the string itself doesn't specify a help-echo,
21538 see if the buffer text ``under'' it does. */
21539 struct glyph_row
*r
21540 = MATRIX_ROW (w
->current_matrix
, vpos
);
21541 int start
= MATRIX_ROW_START_CHARPOS (r
);
21542 int pos
= string_buffer_position (w
, object
, start
);
21545 help
= Fget_char_property (make_number (pos
),
21546 Qhelp_echo
, w
->buffer
);
21550 object
= w
->buffer
;
21555 else if (BUFFERP (object
)
21558 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
21563 help_echo_string
= help
;
21564 help_echo_window
= window
;
21565 help_echo_object
= object
;
21566 help_echo_pos
= charpos
;
21571 /* Look for a `pointer' property. */
21572 if (NILP (pointer
))
21574 /* Check overlays first. */
21575 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
21576 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
21578 if (NILP (pointer
))
21580 Lisp_Object object
= glyph
->object
;
21581 int charpos
= glyph
->charpos
;
21583 /* Try text properties. */
21584 if (STRINGP (object
)
21586 && charpos
< SCHARS (object
))
21588 pointer
= Fget_text_property (make_number (charpos
),
21590 if (NILP (pointer
))
21592 /* If the string itself doesn't specify a pointer,
21593 see if the buffer text ``under'' it does. */
21594 struct glyph_row
*r
21595 = MATRIX_ROW (w
->current_matrix
, vpos
);
21596 int start
= MATRIX_ROW_START_CHARPOS (r
);
21597 int pos
= string_buffer_position (w
, object
, start
);
21599 pointer
= Fget_char_property (make_number (pos
),
21600 Qpointer
, w
->buffer
);
21603 else if (BUFFERP (object
)
21606 pointer
= Fget_text_property (make_number (charpos
),
21613 current_buffer
= obuf
;
21618 define_frame_cursor1 (f
, cursor
, pointer
);
21623 Clear any mouse-face on window W. This function is part of the
21624 redisplay interface, and is called from try_window_id and similar
21625 functions to ensure the mouse-highlight is off. */
21628 x_clear_window_mouse_face (w
)
21631 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21632 Lisp_Object window
;
21635 XSETWINDOW (window
, w
);
21636 if (EQ (window
, dpyinfo
->mouse_face_window
))
21637 clear_mouse_face (dpyinfo
);
21643 Just discard the mouse face information for frame F, if any.
21644 This is used when the size of F is changed. */
21647 cancel_mouse_face (f
)
21650 Lisp_Object window
;
21651 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21653 window
= dpyinfo
->mouse_face_window
;
21654 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
21656 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21657 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21658 dpyinfo
->mouse_face_window
= Qnil
;
21663 #endif /* HAVE_WINDOW_SYSTEM */
21666 /***********************************************************************
21668 ***********************************************************************/
21670 #ifdef HAVE_WINDOW_SYSTEM
21672 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
21673 which intersects rectangle R. R is in window-relative coordinates. */
21676 expose_area (w
, row
, r
, area
)
21678 struct glyph_row
*row
;
21680 enum glyph_row_area area
;
21682 struct glyph
*first
= row
->glyphs
[area
];
21683 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
21684 struct glyph
*last
;
21685 int first_x
, start_x
, x
;
21687 if (area
== TEXT_AREA
&& row
->fill_line_p
)
21688 /* If row extends face to end of line write the whole line. */
21689 draw_glyphs (w
, 0, row
, area
,
21690 0, row
->used
[area
],
21691 DRAW_NORMAL_TEXT
, 0);
21694 /* Set START_X to the window-relative start position for drawing glyphs of
21695 AREA. The first glyph of the text area can be partially visible.
21696 The first glyphs of other areas cannot. */
21697 start_x
= window_box_left_offset (w
, area
);
21699 if (area
== TEXT_AREA
)
21702 /* Find the first glyph that must be redrawn. */
21704 && x
+ first
->pixel_width
< r
->x
)
21706 x
+= first
->pixel_width
;
21710 /* Find the last one. */
21714 && x
< r
->x
+ r
->width
)
21716 x
+= last
->pixel_width
;
21722 draw_glyphs (w
, first_x
- start_x
, row
, area
,
21723 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
21724 DRAW_NORMAL_TEXT
, 0);
21729 /* Redraw the parts of the glyph row ROW on window W intersecting
21730 rectangle R. R is in window-relative coordinates. Value is
21731 non-zero if mouse-face was overwritten. */
21734 expose_line (w
, row
, r
)
21736 struct glyph_row
*row
;
21739 xassert (row
->enabled_p
);
21741 if (row
->mode_line_p
|| w
->pseudo_window_p
)
21742 draw_glyphs (w
, 0, row
, TEXT_AREA
,
21743 0, row
->used
[TEXT_AREA
],
21744 DRAW_NORMAL_TEXT
, 0);
21747 if (row
->used
[LEFT_MARGIN_AREA
])
21748 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
21749 if (row
->used
[TEXT_AREA
])
21750 expose_area (w
, row
, r
, TEXT_AREA
);
21751 if (row
->used
[RIGHT_MARGIN_AREA
])
21752 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
21753 draw_row_fringe_bitmaps (w
, row
);
21756 return row
->mouse_face_p
;
21760 /* Redraw those parts of glyphs rows during expose event handling that
21761 overlap other rows. Redrawing of an exposed line writes over parts
21762 of lines overlapping that exposed line; this function fixes that.
21764 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
21765 row in W's current matrix that is exposed and overlaps other rows.
21766 LAST_OVERLAPPING_ROW is the last such row. */
21769 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
21771 struct glyph_row
*first_overlapping_row
;
21772 struct glyph_row
*last_overlapping_row
;
21774 struct glyph_row
*row
;
21776 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
21777 if (row
->overlapping_p
)
21779 xassert (row
->enabled_p
&& !row
->mode_line_p
);
21781 if (row
->used
[LEFT_MARGIN_AREA
])
21782 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
21784 if (row
->used
[TEXT_AREA
])
21785 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
21787 if (row
->used
[RIGHT_MARGIN_AREA
])
21788 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
21793 /* Return non-zero if W's cursor intersects rectangle R. */
21796 phys_cursor_in_rect_p (w
, r
)
21800 XRectangle cr
, result
;
21801 struct glyph
*cursor_glyph
;
21803 cursor_glyph
= get_phys_cursor_glyph (w
);
21806 /* r is relative to W's box, but w->phys_cursor.x is relative
21807 to left edge of W's TEXT area. Adjust it. */
21808 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
21809 cr
.y
= w
->phys_cursor
.y
;
21810 cr
.width
= cursor_glyph
->pixel_width
;
21811 cr
.height
= w
->phys_cursor_height
;
21812 /* ++KFS: W32 version used W32-specific IntersectRect here, but
21813 I assume the effect is the same -- and this is portable. */
21814 return x_intersect_rectangles (&cr
, r
, &result
);
21822 Draw a vertical window border to the right of window W if W doesn't
21823 have vertical scroll bars. */
21826 x_draw_vertical_border (w
)
21829 /* We could do better, if we knew what type of scroll-bar the adjacent
21830 windows (on either side) have... But we don't :-(
21831 However, I think this works ok. ++KFS 2003-04-25 */
21833 /* Redraw borders between horizontally adjacent windows. Don't
21834 do it for frames with vertical scroll bars because either the
21835 right scroll bar of a window, or the left scroll bar of its
21836 neighbor will suffice as a border. */
21837 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
21840 if (!WINDOW_RIGHTMOST_P (w
)
21841 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
21843 int x0
, x1
, y0
, y1
;
21845 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21848 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
21850 else if (!WINDOW_LEFTMOST_P (w
)
21851 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
21853 int x0
, x1
, y0
, y1
;
21855 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
21858 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
21863 /* Redraw the part of window W intersection rectangle FR. Pixel
21864 coordinates in FR are frame-relative. Call this function with
21865 input blocked. Value is non-zero if the exposure overwrites
21869 expose_window (w
, fr
)
21873 struct frame
*f
= XFRAME (w
->frame
);
21875 int mouse_face_overwritten_p
= 0;
21877 /* If window is not yet fully initialized, do nothing. This can
21878 happen when toolkit scroll bars are used and a window is split.
21879 Reconfiguring the scroll bar will generate an expose for a newly
21881 if (w
->current_matrix
== NULL
)
21884 /* When we're currently updating the window, display and current
21885 matrix usually don't agree. Arrange for a thorough display
21887 if (w
== updated_window
)
21889 SET_FRAME_GARBAGED (f
);
21893 /* Frame-relative pixel rectangle of W. */
21894 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
21895 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
21896 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
21897 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
21899 if (x_intersect_rectangles (fr
, &wr
, &r
))
21901 int yb
= window_text_bottom_y (w
);
21902 struct glyph_row
*row
;
21903 int cursor_cleared_p
;
21904 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
21906 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
21907 r
.x
, r
.y
, r
.width
, r
.height
));
21909 /* Convert to window coordinates. */
21910 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
21911 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
21913 /* Turn off the cursor. */
21914 if (!w
->pseudo_window_p
21915 && phys_cursor_in_rect_p (w
, &r
))
21917 x_clear_cursor (w
);
21918 cursor_cleared_p
= 1;
21921 cursor_cleared_p
= 0;
21923 /* Update lines intersecting rectangle R. */
21924 first_overlapping_row
= last_overlapping_row
= NULL
;
21925 for (row
= w
->current_matrix
->rows
;
21930 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
21932 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
21933 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
21934 || (r
.y
>= y0
&& r
.y
< y1
)
21935 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
21937 if (row
->overlapping_p
)
21939 if (first_overlapping_row
== NULL
)
21940 first_overlapping_row
= row
;
21941 last_overlapping_row
= row
;
21944 if (expose_line (w
, row
, &r
))
21945 mouse_face_overwritten_p
= 1;
21952 /* Display the mode line if there is one. */
21953 if (WINDOW_WANTS_MODELINE_P (w
)
21954 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
21956 && row
->y
< r
.y
+ r
.height
)
21958 if (expose_line (w
, row
, &r
))
21959 mouse_face_overwritten_p
= 1;
21962 if (!w
->pseudo_window_p
)
21964 /* Fix the display of overlapping rows. */
21965 if (first_overlapping_row
)
21966 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
21968 /* Draw border between windows. */
21969 x_draw_vertical_border (w
);
21971 /* Turn the cursor on again. */
21972 if (cursor_cleared_p
)
21973 update_window_cursor (w
, 1);
21977 return mouse_face_overwritten_p
;
21982 /* Redraw (parts) of all windows in the window tree rooted at W that
21983 intersect R. R contains frame pixel coordinates. Value is
21984 non-zero if the exposure overwrites mouse-face. */
21987 expose_window_tree (w
, r
)
21991 struct frame
*f
= XFRAME (w
->frame
);
21992 int mouse_face_overwritten_p
= 0;
21994 while (w
&& !FRAME_GARBAGED_P (f
))
21996 if (!NILP (w
->hchild
))
21997 mouse_face_overwritten_p
21998 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
21999 else if (!NILP (w
->vchild
))
22000 mouse_face_overwritten_p
22001 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
22003 mouse_face_overwritten_p
|= expose_window (w
, r
);
22005 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
22008 return mouse_face_overwritten_p
;
22013 Redisplay an exposed area of frame F. X and Y are the upper-left
22014 corner of the exposed rectangle. W and H are width and height of
22015 the exposed area. All are pixel values. W or H zero means redraw
22016 the entire frame. */
22019 expose_frame (f
, x
, y
, w
, h
)
22024 int mouse_face_overwritten_p
= 0;
22026 TRACE ((stderr
, "expose_frame "));
22028 /* No need to redraw if frame will be redrawn soon. */
22029 if (FRAME_GARBAGED_P (f
))
22031 TRACE ((stderr
, " garbaged\n"));
22035 /* If basic faces haven't been realized yet, there is no point in
22036 trying to redraw anything. This can happen when we get an expose
22037 event while Emacs is starting, e.g. by moving another window. */
22038 if (FRAME_FACE_CACHE (f
) == NULL
22039 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
22041 TRACE ((stderr
, " no faces\n"));
22045 if (w
== 0 || h
== 0)
22048 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
22049 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
22059 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
22060 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
22062 if (WINDOWP (f
->tool_bar_window
))
22063 mouse_face_overwritten_p
22064 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
22066 #ifdef HAVE_X_WINDOWS
22068 #ifndef USE_X_TOOLKIT
22069 if (WINDOWP (f
->menu_bar_window
))
22070 mouse_face_overwritten_p
22071 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
22072 #endif /* not USE_X_TOOLKIT */
22076 /* Some window managers support a focus-follows-mouse style with
22077 delayed raising of frames. Imagine a partially obscured frame,
22078 and moving the mouse into partially obscured mouse-face on that
22079 frame. The visible part of the mouse-face will be highlighted,
22080 then the WM raises the obscured frame. With at least one WM, KDE
22081 2.1, Emacs is not getting any event for the raising of the frame
22082 (even tried with SubstructureRedirectMask), only Expose events.
22083 These expose events will draw text normally, i.e. not
22084 highlighted. Which means we must redo the highlight here.
22085 Subsume it under ``we love X''. --gerd 2001-08-15 */
22086 /* Included in Windows version because Windows most likely does not
22087 do the right thing if any third party tool offers
22088 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
22089 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
22091 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22092 if (f
== dpyinfo
->mouse_face_mouse_frame
)
22094 int x
= dpyinfo
->mouse_face_mouse_x
;
22095 int y
= dpyinfo
->mouse_face_mouse_y
;
22096 clear_mouse_face (dpyinfo
);
22097 note_mouse_highlight (f
, x
, y
);
22104 Determine the intersection of two rectangles R1 and R2. Return
22105 the intersection in *RESULT. Value is non-zero if RESULT is not
22109 x_intersect_rectangles (r1
, r2
, result
)
22110 XRectangle
*r1
, *r2
, *result
;
22112 XRectangle
*left
, *right
;
22113 XRectangle
*upper
, *lower
;
22114 int intersection_p
= 0;
22116 /* Rearrange so that R1 is the left-most rectangle. */
22118 left
= r1
, right
= r2
;
22120 left
= r2
, right
= r1
;
22122 /* X0 of the intersection is right.x0, if this is inside R1,
22123 otherwise there is no intersection. */
22124 if (right
->x
<= left
->x
+ left
->width
)
22126 result
->x
= right
->x
;
22128 /* The right end of the intersection is the minimum of the
22129 the right ends of left and right. */
22130 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
22133 /* Same game for Y. */
22135 upper
= r1
, lower
= r2
;
22137 upper
= r2
, lower
= r1
;
22139 /* The upper end of the intersection is lower.y0, if this is inside
22140 of upper. Otherwise, there is no intersection. */
22141 if (lower
->y
<= upper
->y
+ upper
->height
)
22143 result
->y
= lower
->y
;
22145 /* The lower end of the intersection is the minimum of the lower
22146 ends of upper and lower. */
22147 result
->height
= (min (lower
->y
+ lower
->height
,
22148 upper
->y
+ upper
->height
)
22150 intersection_p
= 1;
22154 return intersection_p
;
22157 #endif /* HAVE_WINDOW_SYSTEM */
22160 /***********************************************************************
22162 ***********************************************************************/
22167 Vwith_echo_area_save_vector
= Qnil
;
22168 staticpro (&Vwith_echo_area_save_vector
);
22170 Vmessage_stack
= Qnil
;
22171 staticpro (&Vmessage_stack
);
22173 Qinhibit_redisplay
= intern ("inhibit-redisplay");
22174 staticpro (&Qinhibit_redisplay
);
22176 message_dolog_marker1
= Fmake_marker ();
22177 staticpro (&message_dolog_marker1
);
22178 message_dolog_marker2
= Fmake_marker ();
22179 staticpro (&message_dolog_marker2
);
22180 message_dolog_marker3
= Fmake_marker ();
22181 staticpro (&message_dolog_marker3
);
22184 defsubr (&Sdump_frame_glyph_matrix
);
22185 defsubr (&Sdump_glyph_matrix
);
22186 defsubr (&Sdump_glyph_row
);
22187 defsubr (&Sdump_tool_bar_row
);
22188 defsubr (&Strace_redisplay
);
22189 defsubr (&Strace_to_stderr
);
22191 #ifdef HAVE_WINDOW_SYSTEM
22192 defsubr (&Stool_bar_lines_needed
);
22193 defsubr (&Slookup_image_map
);
22195 defsubr (&Sformat_mode_line
);
22197 staticpro (&Qmenu_bar_update_hook
);
22198 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
22200 staticpro (&Qoverriding_terminal_local_map
);
22201 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
22203 staticpro (&Qoverriding_local_map
);
22204 Qoverriding_local_map
= intern ("overriding-local-map");
22206 staticpro (&Qwindow_scroll_functions
);
22207 Qwindow_scroll_functions
= intern ("window-scroll-functions");
22209 staticpro (&Qredisplay_end_trigger_functions
);
22210 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
22212 staticpro (&Qinhibit_point_motion_hooks
);
22213 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
22215 QCdata
= intern (":data");
22216 staticpro (&QCdata
);
22217 Qdisplay
= intern ("display");
22218 staticpro (&Qdisplay
);
22219 Qspace_width
= intern ("space-width");
22220 staticpro (&Qspace_width
);
22221 Qraise
= intern ("raise");
22222 staticpro (&Qraise
);
22223 Qslice
= intern ("slice");
22224 staticpro (&Qslice
);
22225 Qspace
= intern ("space");
22226 staticpro (&Qspace
);
22227 Qmargin
= intern ("margin");
22228 staticpro (&Qmargin
);
22229 Qpointer
= intern ("pointer");
22230 staticpro (&Qpointer
);
22231 Qleft_margin
= intern ("left-margin");
22232 staticpro (&Qleft_margin
);
22233 Qright_margin
= intern ("right-margin");
22234 staticpro (&Qright_margin
);
22235 Qcenter
= intern ("center");
22236 staticpro (&Qcenter
);
22237 Qline_height
= intern ("line-height");
22238 staticpro (&Qline_height
);
22239 QCalign_to
= intern (":align-to");
22240 staticpro (&QCalign_to
);
22241 QCrelative_width
= intern (":relative-width");
22242 staticpro (&QCrelative_width
);
22243 QCrelative_height
= intern (":relative-height");
22244 staticpro (&QCrelative_height
);
22245 QCeval
= intern (":eval");
22246 staticpro (&QCeval
);
22247 QCpropertize
= intern (":propertize");
22248 staticpro (&QCpropertize
);
22249 QCfile
= intern (":file");
22250 staticpro (&QCfile
);
22251 Qfontified
= intern ("fontified");
22252 staticpro (&Qfontified
);
22253 Qfontification_functions
= intern ("fontification-functions");
22254 staticpro (&Qfontification_functions
);
22255 Qtrailing_whitespace
= intern ("trailing-whitespace");
22256 staticpro (&Qtrailing_whitespace
);
22257 Qescape_glyph
= intern ("escape-glyph");
22258 staticpro (&Qescape_glyph
);
22259 Qimage
= intern ("image");
22260 staticpro (&Qimage
);
22261 QCmap
= intern (":map");
22262 staticpro (&QCmap
);
22263 QCpointer
= intern (":pointer");
22264 staticpro (&QCpointer
);
22265 Qrect
= intern ("rect");
22266 staticpro (&Qrect
);
22267 Qcircle
= intern ("circle");
22268 staticpro (&Qcircle
);
22269 Qpoly
= intern ("poly");
22270 staticpro (&Qpoly
);
22271 Qmessage_truncate_lines
= intern ("message-truncate-lines");
22272 staticpro (&Qmessage_truncate_lines
);
22273 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
22274 staticpro (&Qcursor_in_non_selected_windows
);
22275 Qgrow_only
= intern ("grow-only");
22276 staticpro (&Qgrow_only
);
22277 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
22278 staticpro (&Qinhibit_menubar_update
);
22279 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
22280 staticpro (&Qinhibit_eval_during_redisplay
);
22281 Qposition
= intern ("position");
22282 staticpro (&Qposition
);
22283 Qbuffer_position
= intern ("buffer-position");
22284 staticpro (&Qbuffer_position
);
22285 Qobject
= intern ("object");
22286 staticpro (&Qobject
);
22287 Qbar
= intern ("bar");
22289 Qhbar
= intern ("hbar");
22290 staticpro (&Qhbar
);
22291 Qbox
= intern ("box");
22293 Qhollow
= intern ("hollow");
22294 staticpro (&Qhollow
);
22295 Qhand
= intern ("hand");
22296 staticpro (&Qhand
);
22297 Qarrow
= intern ("arrow");
22298 staticpro (&Qarrow
);
22299 Qtext
= intern ("text");
22300 staticpro (&Qtext
);
22301 Qrisky_local_variable
= intern ("risky-local-variable");
22302 staticpro (&Qrisky_local_variable
);
22303 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
22304 staticpro (&Qinhibit_free_realized_faces
);
22306 list_of_error
= Fcons (Fcons (intern ("error"),
22307 Fcons (intern ("void-variable"), Qnil
)),
22309 staticpro (&list_of_error
);
22311 Qlast_arrow_position
= intern ("last-arrow-position");
22312 staticpro (&Qlast_arrow_position
);
22313 Qlast_arrow_string
= intern ("last-arrow-string");
22314 staticpro (&Qlast_arrow_string
);
22316 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
22317 staticpro (&Qoverlay_arrow_string
);
22318 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
22319 staticpro (&Qoverlay_arrow_bitmap
);
22321 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
22322 staticpro (&echo_buffer
[0]);
22323 staticpro (&echo_buffer
[1]);
22325 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
22326 staticpro (&echo_area_buffer
[0]);
22327 staticpro (&echo_area_buffer
[1]);
22329 Vmessages_buffer_name
= build_string ("*Messages*");
22330 staticpro (&Vmessages_buffer_name
);
22332 mode_line_proptrans_alist
= Qnil
;
22333 staticpro (&mode_line_proptrans_alist
);
22335 mode_line_string_list
= Qnil
;
22336 staticpro (&mode_line_string_list
);
22338 help_echo_string
= Qnil
;
22339 staticpro (&help_echo_string
);
22340 help_echo_object
= Qnil
;
22341 staticpro (&help_echo_object
);
22342 help_echo_window
= Qnil
;
22343 staticpro (&help_echo_window
);
22344 previous_help_echo_string
= Qnil
;
22345 staticpro (&previous_help_echo_string
);
22346 help_echo_pos
= -1;
22348 #ifdef HAVE_WINDOW_SYSTEM
22349 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
22350 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
22351 For example, if a block cursor is over a tab, it will be drawn as
22352 wide as that tab on the display. */);
22353 x_stretch_cursor_p
= 0;
22356 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
22357 doc
: /* *Non-nil means highlight trailing whitespace.
22358 The face used for trailing whitespace is `trailing-whitespace'. */);
22359 Vshow_trailing_whitespace
= Qnil
;
22361 DEFVAR_LISP ("show-nonbreak-escape", &Vshow_nonbreak_escape
,
22362 doc
: /* *Non-nil means display escape character before non-break space and hyphen. */);
22363 Vshow_nonbreak_escape
= Qt
;
22365 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
22366 doc
: /* *The pointer shape to show in void text areas.
22367 Nil means to show the text pointer. Other options are `arrow', `text',
22368 `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
22369 Vvoid_text_area_pointer
= Qarrow
;
22371 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
22372 doc
: /* Non-nil means don't actually do any redisplay.
22373 This is used for internal purposes. */);
22374 Vinhibit_redisplay
= Qnil
;
22376 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
22377 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
22378 Vglobal_mode_string
= Qnil
;
22380 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
22381 doc
: /* Marker for where to display an arrow on top of the buffer text.
22382 This must be the beginning of a line in order to work.
22383 See also `overlay-arrow-string'. */);
22384 Voverlay_arrow_position
= Qnil
;
22386 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
22387 doc
: /* String to display as an arrow in non-window frames.
22388 See also `overlay-arrow-position'. */);
22389 Voverlay_arrow_string
= Qnil
;
22391 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
22392 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
22393 The symbols on this list are examined during redisplay to determine
22394 where to display overlay arrows. */);
22395 Voverlay_arrow_variable_list
22396 = Fcons (intern ("overlay-arrow-position"), Qnil
);
22398 DEFVAR_INT ("scroll-step", &scroll_step
,
22399 doc
: /* *The number of lines to try scrolling a window by when point moves out.
22400 If that fails to bring point back on frame, point is centered instead.
22401 If this is zero, point is always centered after it moves off frame.
22402 If you want scrolling to always be a line at a time, you should set
22403 `scroll-conservatively' to a large value rather than set this to 1. */);
22405 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
22406 doc
: /* *Scroll up to this many lines, to bring point back on screen.
22407 A value of zero means to scroll the text to center point vertically
22408 in the window. */);
22409 scroll_conservatively
= 0;
22411 DEFVAR_INT ("scroll-margin", &scroll_margin
,
22412 doc
: /* *Number of lines of margin at the top and bottom of a window.
22413 Recenter the window whenever point gets within this many lines
22414 of the top or bottom of the window. */);
22417 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
22418 doc
: /* Pixels per inch on current display.
22419 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
22420 Vdisplay_pixels_per_inch
= make_float (72.0);
22423 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
22426 DEFVAR_BOOL ("truncate-partial-width-windows",
22427 &truncate_partial_width_windows
,
22428 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
22429 truncate_partial_width_windows
= 1;
22431 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
22432 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
22433 Any other value means to use the appropriate face, `mode-line',
22434 `header-line', or `menu' respectively. */);
22435 mode_line_inverse_video
= 1;
22437 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
22438 doc
: /* *Maximum buffer size for which line number should be displayed.
22439 If the buffer is bigger than this, the line number does not appear
22440 in the mode line. A value of nil means no limit. */);
22441 Vline_number_display_limit
= Qnil
;
22443 DEFVAR_INT ("line-number-display-limit-width",
22444 &line_number_display_limit_width
,
22445 doc
: /* *Maximum line width (in characters) for line number display.
22446 If the average length of the lines near point is bigger than this, then the
22447 line number may be omitted from the mode line. */);
22448 line_number_display_limit_width
= 200;
22450 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
22451 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
22452 highlight_nonselected_windows
= 0;
22454 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
22455 doc
: /* Non-nil if more than one frame is visible on this display.
22456 Minibuffer-only frames don't count, but iconified frames do.
22457 This variable is not guaranteed to be accurate except while processing
22458 `frame-title-format' and `icon-title-format'. */);
22460 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
22461 doc
: /* Template for displaying the title bar of visible frames.
22462 \(Assuming the window manager supports this feature.)
22463 This variable has the same structure as `mode-line-format' (which see),
22464 and is used only on frames for which no explicit name has been set
22465 \(see `modify-frame-parameters'). */);
22467 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
22468 doc
: /* Template for displaying the title bar of an iconified frame.
22469 \(Assuming the window manager supports this feature.)
22470 This variable has the same structure as `mode-line-format' (which see),
22471 and is used only on frames for which no explicit name has been set
22472 \(see `modify-frame-parameters'). */);
22474 = Vframe_title_format
22475 = Fcons (intern ("multiple-frames"),
22476 Fcons (build_string ("%b"),
22477 Fcons (Fcons (empty_string
,
22478 Fcons (intern ("invocation-name"),
22479 Fcons (build_string ("@"),
22480 Fcons (intern ("system-name"),
22484 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
22485 doc
: /* Maximum number of lines to keep in the message log buffer.
22486 If nil, disable message logging. If t, log messages but don't truncate
22487 the buffer when it becomes large. */);
22488 Vmessage_log_max
= make_number (50);
22490 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
22491 doc
: /* Functions called before redisplay, if window sizes have changed.
22492 The value should be a list of functions that take one argument.
22493 Just before redisplay, for each frame, if any of its windows have changed
22494 size since the last redisplay, or have been split or deleted,
22495 all the functions in the list are called, with the frame as argument. */);
22496 Vwindow_size_change_functions
= Qnil
;
22498 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
22499 doc
: /* List of functions to call before redisplaying a window with scrolling.
22500 Each function is called with two arguments, the window
22501 and its new display-start position. Note that the value of `window-end'
22502 is not valid when these functions are called. */);
22503 Vwindow_scroll_functions
= Qnil
;
22505 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
22506 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
22507 mouse_autoselect_window
= 0;
22509 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
22510 doc
: /* *Non-nil means automatically resize tool-bars.
22511 This increases a tool-bar's height if not all tool-bar items are visible.
22512 It decreases a tool-bar's height when it would display blank lines
22514 auto_resize_tool_bars_p
= 1;
22516 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
22517 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
22518 auto_raise_tool_bar_buttons_p
= 1;
22520 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
22521 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
22522 make_cursor_line_fully_visible_p
= 1;
22524 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
22525 doc
: /* *Margin around tool-bar buttons in pixels.
22526 If an integer, use that for both horizontal and vertical margins.
22527 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
22528 HORZ specifying the horizontal margin, and VERT specifying the
22529 vertical margin. */);
22530 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
22532 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
22533 doc
: /* *Relief thickness of tool-bar buttons. */);
22534 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
22536 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
22537 doc
: /* List of functions to call to fontify regions of text.
22538 Each function is called with one argument POS. Functions must
22539 fontify a region starting at POS in the current buffer, and give
22540 fontified regions the property `fontified'. */);
22541 Vfontification_functions
= Qnil
;
22542 Fmake_variable_buffer_local (Qfontification_functions
);
22544 DEFVAR_BOOL ("unibyte-display-via-language-environment",
22545 &unibyte_display_via_language_environment
,
22546 doc
: /* *Non-nil means display unibyte text according to language environment.
22547 Specifically this means that unibyte non-ASCII characters
22548 are displayed by converting them to the equivalent multibyte characters
22549 according to the current language environment. As a result, they are
22550 displayed according to the current fontset. */);
22551 unibyte_display_via_language_environment
= 0;
22553 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
22554 doc
: /* *Maximum height for resizing mini-windows.
22555 If a float, it specifies a fraction of the mini-window frame's height.
22556 If an integer, it specifies a number of lines. */);
22557 Vmax_mini_window_height
= make_float (0.25);
22559 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
22560 doc
: /* *How to resize mini-windows.
22561 A value of nil means don't automatically resize mini-windows.
22562 A value of t means resize them to fit the text displayed in them.
22563 A value of `grow-only', the default, means let mini-windows grow
22564 only, until their display becomes empty, at which point the windows
22565 go back to their normal size. */);
22566 Vresize_mini_windows
= Qgrow_only
;
22568 DEFVAR_LISP ("cursor-in-non-selected-windows",
22569 &Vcursor_in_non_selected_windows
,
22570 doc
: /* *Cursor type to display in non-selected windows.
22571 t means to use hollow box cursor. See `cursor-type' for other values. */);
22572 Vcursor_in_non_selected_windows
= Qt
;
22574 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
22575 doc
: /* Alist specifying how to blink the cursor off.
22576 Each element has the form (ON-STATE . OFF-STATE). Whenever the
22577 `cursor-type' frame-parameter or variable equals ON-STATE,
22578 comparing using `equal', Emacs uses OFF-STATE to specify
22579 how to blink it off. */);
22580 Vblink_cursor_alist
= Qnil
;
22582 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
22583 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
22584 automatic_hscrolling_p
= 1;
22586 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
22587 doc
: /* *How many columns away from the window edge point is allowed to get
22588 before automatic hscrolling will horizontally scroll the window. */);
22589 hscroll_margin
= 5;
22591 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
22592 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
22593 When point is less than `automatic-hscroll-margin' columns from the window
22594 edge, automatic hscrolling will scroll the window by the amount of columns
22595 determined by this variable. If its value is a positive integer, scroll that
22596 many columns. If it's a positive floating-point number, it specifies the
22597 fraction of the window's width to scroll. If it's nil or zero, point will be
22598 centered horizontally after the scroll. Any other value, including negative
22599 numbers, are treated as if the value were zero.
22601 Automatic hscrolling always moves point outside the scroll margin, so if
22602 point was more than scroll step columns inside the margin, the window will
22603 scroll more than the value given by the scroll step.
22605 Note that the lower bound for automatic hscrolling specified by `scroll-left'
22606 and `scroll-right' overrides this variable's effect. */);
22607 Vhscroll_step
= make_number (0);
22609 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
22610 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
22611 Bind this around calls to `message' to let it take effect. */);
22612 message_truncate_lines
= 0;
22614 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
22615 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
22616 Can be used to update submenus whose contents should vary. */);
22617 Vmenu_bar_update_hook
= Qnil
;
22619 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
22620 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
22621 inhibit_menubar_update
= 0;
22623 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
22624 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
22625 inhibit_eval_during_redisplay
= 0;
22627 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
22628 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
22629 inhibit_free_realized_faces
= 0;
22632 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
22633 doc
: /* Inhibit try_window_id display optimization. */);
22634 inhibit_try_window_id
= 0;
22636 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
22637 doc
: /* Inhibit try_window_reusing display optimization. */);
22638 inhibit_try_window_reusing
= 0;
22640 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
22641 doc
: /* Inhibit try_cursor_movement display optimization. */);
22642 inhibit_try_cursor_movement
= 0;
22643 #endif /* GLYPH_DEBUG */
22647 /* Initialize this module when Emacs starts. */
22652 Lisp_Object root_window
;
22653 struct window
*mini_w
;
22655 current_header_line_height
= current_mode_line_height
= -1;
22657 CHARPOS (this_line_start_pos
) = 0;
22659 mini_w
= XWINDOW (minibuf_window
);
22660 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
22662 if (!noninteractive
)
22664 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
22667 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
22668 set_window_height (root_window
,
22669 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
22671 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
22672 set_window_height (minibuf_window
, 1, 0);
22674 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
22675 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
22677 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
22678 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
22679 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
22681 /* The default ellipsis glyphs `...'. */
22682 for (i
= 0; i
< 3; ++i
)
22683 default_invis_vector
[i
] = make_number ('.');
22687 /* Allocate the buffer for frame titles.
22688 Also used for `format-mode-line'. */
22690 frame_title_buf
= (char *) xmalloc (size
);
22691 frame_title_buf_end
= frame_title_buf
+ size
;
22692 frame_title_ptr
= NULL
;
22695 help_echo_showing_p
= 0;
22699 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
22700 (do not change this comment) */