1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985,86,87,88,93,94,95,97,98,99, 2000, 2001, 2002, 2003
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
205 #ifndef FRAME_X_OUTPUT
206 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
209 #define INFINITY 10000000
211 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
213 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
214 extern int pending_menu_activation
;
217 extern int interrupt_input
;
218 extern int command_loop_level
;
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
;
245 Lisp_Object Qrisky_local_variable
;
247 /* Holds the list (error). */
248 Lisp_Object list_of_error
;
250 /* Functions called to fontify regions of text. */
252 Lisp_Object Vfontification_functions
;
253 Lisp_Object Qfontification_functions
;
255 /* Non-zero means automatically select any window when the mouse
256 cursor moves into it. */
257 int mouse_autoselect_window
;
259 /* Non-zero means draw tool bar buttons raised when the mouse moves
262 int auto_raise_tool_bar_buttons_p
;
264 /* Margin around tool bar buttons in pixels. */
266 Lisp_Object Vtool_bar_button_margin
;
268 /* Thickness of shadow to draw around tool bar buttons. */
270 EMACS_INT tool_bar_button_relief
;
272 /* Non-zero means automatically resize tool-bars so that all tool-bar
273 items are visible, and no blank lines remain. */
275 int auto_resize_tool_bars_p
;
277 /* Non-zero means draw block and hollow cursor as wide as the glyph
278 under it. For example, if a block cursor is over a tab, it will be
279 drawn as wide as that tab on the display. */
281 int x_stretch_cursor_p
;
283 /* Non-nil means don't actually do any redisplay. */
285 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
287 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
289 int inhibit_eval_during_redisplay
;
291 /* Names of text properties relevant for redisplay. */
293 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
294 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
296 /* Symbols used in text property values. */
298 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
299 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
301 extern Lisp_Object Qheight
;
302 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
304 /* Non-nil means highlight trailing whitespace. */
306 Lisp_Object Vshow_trailing_whitespace
;
308 /* Name of the face used to highlight trailing whitespace. */
310 Lisp_Object Qtrailing_whitespace
;
312 /* The symbol `image' which is the car of the lists used to represent
317 /* Non-zero means print newline to stdout before next mini-buffer
320 int noninteractive_need_newline
;
322 /* Non-zero means print newline to message log before next message. */
324 static int message_log_need_newline
;
326 /* Three markers that message_dolog uses.
327 It could allocate them itself, but that causes trouble
328 in handling memory-full errors. */
329 static Lisp_Object message_dolog_marker1
;
330 static Lisp_Object message_dolog_marker2
;
331 static Lisp_Object message_dolog_marker3
;
333 /* The buffer position of the first character appearing entirely or
334 partially on the line of the selected window which contains the
335 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
336 redisplay optimization in redisplay_internal. */
338 static struct text_pos this_line_start_pos
;
340 /* Number of characters past the end of the line above, including the
341 terminating newline. */
343 static struct text_pos this_line_end_pos
;
345 /* The vertical positions and the height of this line. */
347 static int this_line_vpos
;
348 static int this_line_y
;
349 static int this_line_pixel_height
;
351 /* X position at which this display line starts. Usually zero;
352 negative if first character is partially visible. */
354 static int this_line_start_x
;
356 /* Buffer that this_line_.* variables are referring to. */
358 static struct buffer
*this_line_buffer
;
360 /* Nonzero means truncate lines in all windows less wide than the
363 int truncate_partial_width_windows
;
365 /* A flag to control how to display unibyte 8-bit character. */
367 int unibyte_display_via_language_environment
;
369 /* Nonzero means we have more than one non-mini-buffer-only frame.
370 Not guaranteed to be accurate except while parsing
371 frame-title-format. */
375 Lisp_Object Vglobal_mode_string
;
377 /* Marker for where to display an arrow on top of the buffer text. */
379 Lisp_Object Voverlay_arrow_position
;
381 /* String to display for the arrow. Only used on terminal frames. */
383 Lisp_Object Voverlay_arrow_string
;
385 /* Values of those variables at last redisplay. However, if
386 Voverlay_arrow_position is a marker, last_arrow_position is its
387 numerical position. */
389 static Lisp_Object last_arrow_position
, last_arrow_string
;
391 /* Like mode-line-format, but for the title bar on a visible frame. */
393 Lisp_Object Vframe_title_format
;
395 /* Like mode-line-format, but for the title bar on an iconified frame. */
397 Lisp_Object Vicon_title_format
;
399 /* List of functions to call when a window's size changes. These
400 functions get one arg, a frame on which one or more windows' sizes
403 static Lisp_Object Vwindow_size_change_functions
;
405 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
407 /* Nonzero if overlay arrow has been displayed once in this window. */
409 static int overlay_arrow_seen
;
411 /* Nonzero means highlight the region even in nonselected windows. */
413 int highlight_nonselected_windows
;
415 /* If cursor motion alone moves point off frame, try scrolling this
416 many lines up or down if that will bring it back. */
418 static EMACS_INT scroll_step
;
420 /* Nonzero means scroll just far enough to bring point back on the
421 screen, when appropriate. */
423 static EMACS_INT scroll_conservatively
;
425 /* Recenter the window whenever point gets within this many lines of
426 the top or bottom of the window. This value is translated into a
427 pixel value by multiplying it with CANON_Y_UNIT, which means that
428 there is really a fixed pixel height scroll margin. */
430 EMACS_INT scroll_margin
;
432 /* Number of windows showing the buffer of the selected window (or
433 another buffer with the same base buffer). keyboard.c refers to
438 /* Vector containing glyphs for an ellipsis `...'. */
440 static Lisp_Object default_invis_vector
[3];
442 /* Zero means display the mode-line/header-line/menu-bar in the default face
443 (this slightly odd definition is for compatibility with previous versions
444 of emacs), non-zero means display them using their respective faces.
446 This variable is deprecated. */
448 int mode_line_inverse_video
;
450 /* Prompt to display in front of the mini-buffer contents. */
452 Lisp_Object minibuf_prompt
;
454 /* Width of current mini-buffer prompt. Only set after display_line
455 of the line that contains the prompt. */
457 int minibuf_prompt_width
;
459 /* This is the window where the echo area message was displayed. It
460 is always a mini-buffer window, but it may not be the same window
461 currently active as a mini-buffer. */
463 Lisp_Object echo_area_window
;
465 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
466 pushes the current message and the value of
467 message_enable_multibyte on the stack, the function restore_message
468 pops the stack and displays MESSAGE again. */
470 Lisp_Object Vmessage_stack
;
472 /* Nonzero means multibyte characters were enabled when the echo area
473 message was specified. */
475 int message_enable_multibyte
;
477 /* Nonzero if we should redraw the mode lines on the next redisplay. */
479 int update_mode_lines
;
481 /* Nonzero if window sizes or contents have changed since last
482 redisplay that finished. */
484 int windows_or_buffers_changed
;
486 /* Nonzero means a frame's cursor type has been changed. */
488 int cursor_type_changed
;
490 /* Nonzero after display_mode_line if %l was used and it displayed a
493 int line_number_displayed
;
495 /* Maximum buffer size for which to display line numbers. */
497 Lisp_Object Vline_number_display_limit
;
499 /* Line width to consider when repositioning for line number display. */
501 static EMACS_INT line_number_display_limit_width
;
503 /* Number of lines to keep in the message log buffer. t means
504 infinite. nil means don't log at all. */
506 Lisp_Object Vmessage_log_max
;
508 /* The name of the *Messages* buffer, a string. */
510 static Lisp_Object Vmessages_buffer_name
;
512 /* Current, index 0, and last displayed echo area message. Either
513 buffers from echo_buffers, or nil to indicate no message. */
515 Lisp_Object echo_area_buffer
[2];
517 /* The buffers referenced from echo_area_buffer. */
519 static Lisp_Object echo_buffer
[2];
521 /* A vector saved used in with_area_buffer to reduce consing. */
523 static Lisp_Object Vwith_echo_area_save_vector
;
525 /* Non-zero means display_echo_area should display the last echo area
526 message again. Set by redisplay_preserve_echo_area. */
528 static int display_last_displayed_message_p
;
530 /* Nonzero if echo area is being used by print; zero if being used by
533 int message_buf_print
;
535 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
537 Lisp_Object Qinhibit_menubar_update
;
538 int inhibit_menubar_update
;
540 /* Maximum height for resizing mini-windows. Either a float
541 specifying a fraction of the available height, or an integer
542 specifying a number of lines. */
544 Lisp_Object Vmax_mini_window_height
;
546 /* Non-zero means messages should be displayed with truncated
547 lines instead of being continued. */
549 int message_truncate_lines
;
550 Lisp_Object Qmessage_truncate_lines
;
552 /* Set to 1 in clear_message to make redisplay_internal aware
553 of an emptied echo area. */
555 static int message_cleared_p
;
557 /* Non-zero means we want a hollow cursor in windows that are not
558 selected. Zero means there's no cursor in such windows. */
560 Lisp_Object Vcursor_in_non_selected_windows
;
561 Lisp_Object Qcursor_in_non_selected_windows
;
563 /* How to blink the default frame cursor off. */
564 Lisp_Object Vblink_cursor_alist
;
566 /* A scratch glyph row with contents used for generating truncation
567 glyphs. Also used in direct_output_for_insert. */
569 #define MAX_SCRATCH_GLYPHS 100
570 struct glyph_row scratch_glyph_row
;
571 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
573 /* Ascent and height of the last line processed by move_it_to. */
575 static int last_max_ascent
, last_height
;
577 /* Non-zero if there's a help-echo in the echo area. */
579 int help_echo_showing_p
;
581 /* If >= 0, computed, exact values of mode-line and header-line height
582 to use in the macros CURRENT_MODE_LINE_HEIGHT and
583 CURRENT_HEADER_LINE_HEIGHT. */
585 int current_mode_line_height
, current_header_line_height
;
587 /* The maximum distance to look ahead for text properties. Values
588 that are too small let us call compute_char_face and similar
589 functions too often which is expensive. Values that are too large
590 let us call compute_char_face and alike too often because we
591 might not be interested in text properties that far away. */
593 #define TEXT_PROP_DISTANCE_LIMIT 100
597 /* Variables to turn off display optimizations from Lisp. */
599 int inhibit_try_window_id
, inhibit_try_window_reusing
;
600 int inhibit_try_cursor_movement
;
602 /* Non-zero means print traces of redisplay if compiled with
605 int trace_redisplay_p
;
607 #endif /* GLYPH_DEBUG */
609 #ifdef DEBUG_TRACE_MOVE
610 /* Non-zero means trace with TRACE_MOVE to stderr. */
613 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
615 #define TRACE_MOVE(x) (void) 0
618 /* Non-zero means automatically scroll windows horizontally to make
621 int automatic_hscrolling_p
;
623 /* How close to the margin can point get before the window is scrolled
625 EMACS_INT hscroll_margin
;
627 /* How much to scroll horizontally when point is inside the above margin. */
628 Lisp_Object Vhscroll_step
;
630 /* A list of symbols, one for each supported image type. */
632 Lisp_Object Vimage_types
;
634 /* The variable `resize-mini-windows'. If nil, don't resize
635 mini-windows. If t, always resize them to fit the text they
636 display. If `grow-only', let mini-windows grow only until they
639 Lisp_Object Vresize_mini_windows
;
641 /* Buffer being redisplayed -- for redisplay_window_error. */
643 struct buffer
*displayed_buffer
;
645 /* Value returned from text property handlers (see below). */
650 HANDLED_RECOMPUTE_PROPS
,
651 HANDLED_OVERLAY_STRING_CONSUMED
,
655 /* A description of text properties that redisplay is interested
660 /* The name of the property. */
663 /* A unique index for the property. */
666 /* A handler function called to set up iterator IT from the property
667 at IT's current position. Value is used to steer handle_stop. */
668 enum prop_handled (*handler
) P_ ((struct it
*it
));
671 static enum prop_handled handle_face_prop
P_ ((struct it
*));
672 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
673 static enum prop_handled handle_display_prop
P_ ((struct it
*));
674 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
675 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
676 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
678 /* Properties handled by iterators. */
680 static struct props it_props
[] =
682 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
683 /* Handle `face' before `display' because some sub-properties of
684 `display' need to know the face. */
685 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
686 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
687 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
688 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
692 /* Value is the position described by X. If X is a marker, value is
693 the marker_position of X. Otherwise, value is X. */
695 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
697 /* Enumeration returned by some move_it_.* functions internally. */
701 /* Not used. Undefined value. */
704 /* Move ended at the requested buffer position or ZV. */
705 MOVE_POS_MATCH_OR_ZV
,
707 /* Move ended at the requested X pixel position. */
710 /* Move within a line ended at the end of a line that must be
714 /* Move within a line ended at the end of a line that would
715 be displayed truncated. */
718 /* Move within a line ended at a line end. */
722 /* This counter is used to clear the face cache every once in a while
723 in redisplay_internal. It is incremented for each redisplay.
724 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
727 #define CLEAR_FACE_CACHE_COUNT 500
728 static int clear_face_cache_count
;
730 /* Record the previous terminal frame we displayed. */
732 static struct frame
*previous_terminal_frame
;
734 /* Non-zero while redisplay_internal is in progress. */
738 /* Non-zero means don't free realized faces. Bound while freeing
739 realized faces is dangerous because glyph matrices might still
742 int inhibit_free_realized_faces
;
743 Lisp_Object Qinhibit_free_realized_faces
;
745 /* If a string, XTread_socket generates an event to display that string.
746 (The display is done in read_char.) */
748 Lisp_Object help_echo_string
;
749 Lisp_Object help_echo_window
;
750 Lisp_Object help_echo_object
;
753 /* Temporary variable for XTread_socket. */
755 Lisp_Object previous_help_echo_string
;
759 /* Function prototypes. */
761 static void setup_for_ellipsis
P_ ((struct it
*));
762 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
763 static int single_display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
764 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
765 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
766 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
767 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
770 static int invisible_text_between_p
P_ ((struct it
*, int, int));
773 static int next_element_from_ellipsis
P_ ((struct it
*));
774 static void pint2str
P_ ((char *, int, int));
775 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
777 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
778 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
779 static void store_frame_title_char
P_ ((char));
780 static int store_frame_title
P_ ((const unsigned char *, int, int));
781 static void x_consider_frame_title
P_ ((Lisp_Object
));
782 static void handle_stop
P_ ((struct it
*));
783 static int tool_bar_lines_needed
P_ ((struct frame
*));
784 static int single_display_prop_intangible_p
P_ ((Lisp_Object
));
785 static void ensure_echo_area_buffers
P_ ((void));
786 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
787 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
788 static int with_echo_area_buffer
P_ ((struct window
*, int,
789 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
790 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
791 static void clear_garbaged_frames
P_ ((void));
792 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
793 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
794 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
795 static int display_echo_area
P_ ((struct window
*));
796 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
797 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
798 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
799 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
800 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
802 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
803 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
804 static void insert_left_trunc_glyphs
P_ ((struct it
*));
805 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
806 static void extend_face_to_end_of_line
P_ ((struct it
*));
807 static int append_space
P_ ((struct it
*, int));
808 static int make_cursor_line_fully_visible
P_ ((struct window
*));
809 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
810 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
811 static int trailing_whitespace_p
P_ ((int));
812 static int message_log_check_duplicate
P_ ((int, int, int, int));
813 static void push_it
P_ ((struct it
*));
814 static void pop_it
P_ ((struct it
*));
815 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
816 static void redisplay_internal
P_ ((int));
817 static int echo_area_display
P_ ((int));
818 static void redisplay_windows
P_ ((Lisp_Object
));
819 static void redisplay_window
P_ ((Lisp_Object
, int));
820 static Lisp_Object
redisplay_window_error ();
821 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
822 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
823 static void update_menu_bar
P_ ((struct frame
*, int));
824 static int try_window_reusing_current_matrix
P_ ((struct window
*));
825 static int try_window_id
P_ ((struct window
*));
826 static int display_line
P_ ((struct it
*));
827 static int display_mode_lines
P_ ((struct window
*));
828 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
829 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
830 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
831 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
832 static void display_menu_bar
P_ ((struct window
*));
833 static int display_count_lines
P_ ((int, int, int, int, int *));
834 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
835 int, int, struct it
*, int, int, int, int));
836 static void compute_line_metrics
P_ ((struct it
*));
837 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
838 static int get_overlay_strings
P_ ((struct it
*, int));
839 static void next_overlay_string
P_ ((struct it
*));
840 static void reseat
P_ ((struct it
*, struct text_pos
, int));
841 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
842 static void back_to_previous_visible_line_start
P_ ((struct it
*));
843 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
844 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
845 static int next_element_from_display_vector
P_ ((struct it
*));
846 static int next_element_from_string
P_ ((struct it
*));
847 static int next_element_from_c_string
P_ ((struct it
*));
848 static int next_element_from_buffer
P_ ((struct it
*));
849 static int next_element_from_composition
P_ ((struct it
*));
850 static int next_element_from_image
P_ ((struct it
*));
851 static int next_element_from_stretch
P_ ((struct it
*));
852 static void load_overlay_strings
P_ ((struct it
*, int));
853 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
854 struct display_pos
*));
855 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
856 Lisp_Object
, int, int, int, int));
857 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
859 void move_it_vertically_backward
P_ ((struct it
*, int));
860 static void init_to_row_start
P_ ((struct it
*, struct window
*,
861 struct glyph_row
*));
862 static int init_to_row_end
P_ ((struct it
*, struct window
*,
863 struct glyph_row
*));
864 static void back_to_previous_line_start
P_ ((struct it
*));
865 static int forward_to_next_line_start
P_ ((struct it
*, int *));
866 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
868 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
869 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
870 static int number_of_chars
P_ ((unsigned char *, int));
871 static void compute_stop_pos
P_ ((struct it
*));
872 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
874 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
875 static int next_overlay_change
P_ ((int));
876 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
877 Lisp_Object
, struct text_pos
*,
879 static int underlying_face_id
P_ ((struct it
*));
880 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
883 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
884 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
886 #ifdef HAVE_WINDOW_SYSTEM
888 static void update_tool_bar
P_ ((struct frame
*, int));
889 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
890 static int redisplay_tool_bar
P_ ((struct frame
*));
891 static void display_tool_bar_line
P_ ((struct it
*));
892 static void notice_overwritten_cursor
P_ ((struct window
*,
894 int, int, int, int));
898 #endif /* HAVE_WINDOW_SYSTEM */
901 /***********************************************************************
902 Window display dimensions
903 ***********************************************************************/
905 /* Return the bottom boundary y-position for text lines in window W.
906 This is the first y position at which a line cannot start.
907 It is relative to the top of the window.
909 This is the height of W minus the height of a mode line, if any. */
912 window_text_bottom_y (w
)
915 struct frame
*f
= XFRAME (w
->frame
);
916 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
918 if (WINDOW_WANTS_MODELINE_P (w
))
919 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
924 /* Return the pixel width of display area AREA of window W. AREA < 0
925 means return the total width of W, not including fringes to
926 the left and right of the window. */
929 window_box_width (w
, area
)
933 struct frame
*f
= XFRAME (w
->frame
);
934 int width
= XFASTINT (w
->width
);
936 if (!w
->pseudo_window_p
)
938 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FRINGE_COLS (f
);
940 if (area
== TEXT_AREA
)
942 if (INTEGERP (w
->left_margin_width
))
943 width
-= XFASTINT (w
->left_margin_width
);
944 if (INTEGERP (w
->right_margin_width
))
945 width
-= XFASTINT (w
->right_margin_width
);
947 else if (area
== LEFT_MARGIN_AREA
)
948 width
= (INTEGERP (w
->left_margin_width
)
949 ? XFASTINT (w
->left_margin_width
) : 0);
950 else if (area
== RIGHT_MARGIN_AREA
)
951 width
= (INTEGERP (w
->right_margin_width
)
952 ? XFASTINT (w
->right_margin_width
) : 0);
955 return width
* CANON_X_UNIT (f
);
959 /* Return the pixel height of the display area of window W, not
960 including mode lines of W, if any. */
963 window_box_height (w
)
966 struct frame
*f
= XFRAME (w
->frame
);
967 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
969 xassert (height
>= 0);
971 /* Note: the code below that determines the mode-line/header-line
972 height is essentially the same as that contained in the macro
973 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
974 the appropriate glyph row has its `mode_line_p' flag set,
975 and if it doesn't, uses estimate_mode_line_height instead. */
977 if (WINDOW_WANTS_MODELINE_P (w
))
979 struct glyph_row
*ml_row
980 = (w
->current_matrix
&& w
->current_matrix
->rows
981 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
983 if (ml_row
&& ml_row
->mode_line_p
)
984 height
-= ml_row
->height
;
986 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
989 if (WINDOW_WANTS_HEADER_LINE_P (w
))
991 struct glyph_row
*hl_row
992 = (w
->current_matrix
&& w
->current_matrix
->rows
993 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
995 if (hl_row
&& hl_row
->mode_line_p
)
996 height
-= hl_row
->height
;
998 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1001 /* With a very small font and a mode-line that's taller than
1002 default, we might end up with a negative height. */
1003 return max (0, height
);
1007 /* Return the frame-relative coordinate of the left edge of display
1008 area AREA of window W. AREA < 0 means return the left edge of the
1009 whole window, to the right of the left fringe of W. */
1012 window_box_left (w
, area
)
1016 struct frame
*f
= XFRAME (w
->frame
);
1017 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
1019 if (!w
->pseudo_window_p
)
1021 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
1022 + FRAME_LEFT_FRINGE_WIDTH (f
));
1024 if (area
== TEXT_AREA
)
1025 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
1026 else if (area
== RIGHT_MARGIN_AREA
)
1027 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
1028 + window_box_width (w
, TEXT_AREA
));
1035 /* Return the frame-relative coordinate of the right edge of display
1036 area AREA of window W. AREA < 0 means return the left edge of the
1037 whole window, to the left of the right fringe of W. */
1040 window_box_right (w
, area
)
1044 return window_box_left (w
, area
) + window_box_width (w
, area
);
1048 /* Get the bounding box of the display area AREA of window W, without
1049 mode lines, in frame-relative coordinates. AREA < 0 means the
1050 whole window, not including the left and right fringes of
1051 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1052 coordinates of the upper-left corner of the box. Return in
1053 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1056 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1059 int *box_x
, *box_y
, *box_width
, *box_height
;
1061 struct frame
*f
= XFRAME (w
->frame
);
1063 *box_width
= window_box_width (w
, area
);
1064 *box_height
= window_box_height (w
);
1065 *box_x
= window_box_left (w
, area
);
1066 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
1067 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
1068 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1069 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1073 /* Get the bounding box of the display area AREA of window W, without
1074 mode lines. AREA < 0 means the whole window, not including the
1075 left and right fringe of the window. Return in *TOP_LEFT_X
1076 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1077 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1078 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1082 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1083 bottom_right_x
, bottom_right_y
)
1086 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1088 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1090 *bottom_right_x
+= *top_left_x
;
1091 *bottom_right_y
+= *top_left_y
;
1096 /***********************************************************************
1098 ***********************************************************************/
1100 /* Return the bottom y-position of the line the iterator IT is in.
1101 This can modify IT's settings. */
1107 int line_height
= it
->max_ascent
+ it
->max_descent
;
1108 int line_top_y
= it
->current_y
;
1110 if (line_height
== 0)
1113 line_height
= last_height
;
1114 else if (IT_CHARPOS (*it
) < ZV
)
1116 move_it_by_lines (it
, 1, 1);
1117 line_height
= (it
->max_ascent
|| it
->max_descent
1118 ? it
->max_ascent
+ it
->max_descent
1123 struct glyph_row
*row
= it
->glyph_row
;
1125 /* Use the default character height. */
1126 it
->glyph_row
= NULL
;
1127 it
->what
= IT_CHARACTER
;
1130 PRODUCE_GLYPHS (it
);
1131 line_height
= it
->ascent
+ it
->descent
;
1132 it
->glyph_row
= row
;
1136 return line_top_y
+ line_height
;
1140 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1141 1 if POS is visible and the line containing POS is fully visible.
1142 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1143 and header-lines heights. */
1146 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1148 int charpos
, *fully
, exact_mode_line_heights_p
;
1151 struct text_pos top
;
1153 struct buffer
*old_buffer
= NULL
;
1155 if (XBUFFER (w
->buffer
) != current_buffer
)
1157 old_buffer
= current_buffer
;
1158 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1161 *fully
= visible_p
= 0;
1162 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1164 /* Compute exact mode line heights, if requested. */
1165 if (exact_mode_line_heights_p
)
1167 if (WINDOW_WANTS_MODELINE_P (w
))
1168 current_mode_line_height
1169 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1170 current_buffer
->mode_line_format
);
1172 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1173 current_header_line_height
1174 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1175 current_buffer
->header_line_format
);
1178 start_display (&it
, w
, top
);
1179 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1180 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1182 /* Note that we may overshoot because of invisible text. */
1183 if (IT_CHARPOS (it
) >= charpos
)
1185 int top_y
= it
.current_y
;
1186 int bottom_y
= line_bottom_y (&it
);
1187 int window_top_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1189 if (top_y
< window_top_y
)
1190 visible_p
= bottom_y
> window_top_y
;
1191 else if (top_y
< it
.last_visible_y
)
1194 *fully
= bottom_y
<= it
.last_visible_y
;
1197 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1199 move_it_by_lines (&it
, 1, 0);
1200 if (charpos
< IT_CHARPOS (it
))
1208 set_buffer_internal_1 (old_buffer
);
1210 current_header_line_height
= current_mode_line_height
= -1;
1215 /* Return the next character from STR which is MAXLEN bytes long.
1216 Return in *LEN the length of the character. This is like
1217 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1218 we find one, we return a `?', but with the length of the invalid
1222 string_char_and_length (str
, maxlen
, len
)
1223 const unsigned char *str
;
1228 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1229 if (!CHAR_VALID_P (c
, 1))
1230 /* We may not change the length here because other places in Emacs
1231 don't use this function, i.e. they silently accept invalid
1240 /* Given a position POS containing a valid character and byte position
1241 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1243 static struct text_pos
1244 string_pos_nchars_ahead (pos
, string
, nchars
)
1245 struct text_pos pos
;
1249 xassert (STRINGP (string
) && nchars
>= 0);
1251 if (STRING_MULTIBYTE (string
))
1253 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1254 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1259 string_char_and_length (p
, rest
, &len
);
1260 p
+= len
, rest
-= len
;
1261 xassert (rest
>= 0);
1263 BYTEPOS (pos
) += len
;
1267 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1273 /* Value is the text position, i.e. character and byte position,
1274 for character position CHARPOS in STRING. */
1276 static INLINE
struct text_pos
1277 string_pos (charpos
, string
)
1281 struct text_pos pos
;
1282 xassert (STRINGP (string
));
1283 xassert (charpos
>= 0);
1284 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1289 /* Value is a text position, i.e. character and byte position, for
1290 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1291 means recognize multibyte characters. */
1293 static struct text_pos
1294 c_string_pos (charpos
, s
, multibyte_p
)
1299 struct text_pos pos
;
1301 xassert (s
!= NULL
);
1302 xassert (charpos
>= 0);
1306 int rest
= strlen (s
), len
;
1308 SET_TEXT_POS (pos
, 0, 0);
1311 string_char_and_length (s
, rest
, &len
);
1312 s
+= len
, rest
-= len
;
1313 xassert (rest
>= 0);
1315 BYTEPOS (pos
) += len
;
1319 SET_TEXT_POS (pos
, charpos
, charpos
);
1325 /* Value is the number of characters in C string S. MULTIBYTE_P
1326 non-zero means recognize multibyte characters. */
1329 number_of_chars (s
, multibyte_p
)
1337 int rest
= strlen (s
), len
;
1338 unsigned char *p
= (unsigned char *) s
;
1340 for (nchars
= 0; rest
> 0; ++nchars
)
1342 string_char_and_length (p
, rest
, &len
);
1343 rest
-= len
, p
+= len
;
1347 nchars
= strlen (s
);
1353 /* Compute byte position NEWPOS->bytepos corresponding to
1354 NEWPOS->charpos. POS is a known position in string STRING.
1355 NEWPOS->charpos must be >= POS.charpos. */
1358 compute_string_pos (newpos
, pos
, string
)
1359 struct text_pos
*newpos
, pos
;
1362 xassert (STRINGP (string
));
1363 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1365 if (STRING_MULTIBYTE (string
))
1366 *newpos
= string_pos_nchars_ahead (pos
, string
,
1367 CHARPOS (*newpos
) - CHARPOS (pos
));
1369 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1373 Return an estimation of the pixel height of mode or top lines on
1374 frame F. FACE_ID specifies what line's height to estimate. */
1377 estimate_mode_line_height (f
, face_id
)
1379 enum face_id face_id
;
1381 #ifdef HAVE_WINDOW_SYSTEM
1382 if (FRAME_WINDOW_P (f
))
1384 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1386 /* This function is called so early when Emacs starts that the face
1387 cache and mode line face are not yet initialized. */
1388 if (FRAME_FACE_CACHE (f
))
1390 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1394 height
= FONT_HEIGHT (face
->font
);
1395 if (face
->box_line_width
> 0)
1396 height
+= 2 * face
->box_line_width
;
1407 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1408 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1409 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1410 not force the value into range. */
1413 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1415 register int pix_x
, pix_y
;
1417 NativeRectangle
*bounds
;
1421 #ifdef HAVE_WINDOW_SYSTEM
1422 if (FRAME_WINDOW_P (f
))
1424 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
1425 even for negative values. */
1427 pix_x
-= FONT_WIDTH (FRAME_FONT (f
)) - 1;
1429 pix_y
-= FRAME_X_OUTPUT(f
)->line_height
- 1;
1431 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
1432 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
1435 STORE_NATIVE_RECT (*bounds
,
1436 CHAR_TO_PIXEL_COL (f
, pix_x
),
1437 CHAR_TO_PIXEL_ROW (f
, pix_y
),
1438 FONT_WIDTH (FRAME_FONT (f
)) - 1,
1439 FRAME_X_OUTPUT (f
)->line_height
- 1);
1445 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
1446 pix_x
= FRAME_WINDOW_WIDTH (f
);
1450 else if (pix_y
> f
->height
)
1461 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1462 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1463 can't tell the positions because W's display is not up to date,
1467 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1470 int *frame_x
, *frame_y
;
1472 #ifdef HAVE_WINDOW_SYSTEM
1473 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1477 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1478 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1480 if (display_completed
)
1482 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1483 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1484 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1490 hpos
+= glyph
->pixel_width
;
1502 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1503 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1514 #ifdef HAVE_WINDOW_SYSTEM
1516 /* Find the glyph under window-relative coordinates X/Y in window W.
1517 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1518 strings. Return in *HPOS and *VPOS the row and column number of
1519 the glyph found. Return in *AREA the glyph area containing X.
1520 Value is a pointer to the glyph found or null if X/Y is not on
1521 text, or we can't tell because W's current matrix is not up to
1524 static struct glyph
*
1525 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
1528 int *hpos
, *vpos
, *area
;
1531 struct glyph
*glyph
, *end
;
1532 struct glyph_row
*row
= NULL
;
1533 int x0
, i
, left_area_width
;
1535 /* Find row containing Y. Give up if some row is not enabled. */
1536 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1538 row
= MATRIX_ROW (w
->current_matrix
, i
);
1539 if (!row
->enabled_p
)
1541 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1548 /* Give up if Y is not in the window. */
1549 if (i
== w
->current_matrix
->nrows
)
1552 /* Get the glyph area containing X. */
1553 if (w
->pseudo_window_p
)
1560 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
1561 if (x
< left_area_width
)
1563 *area
= LEFT_MARGIN_AREA
;
1566 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
1569 x0
= row
->x
+ left_area_width
;
1573 *area
= RIGHT_MARGIN_AREA
;
1574 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
1578 /* Find glyph containing X. */
1579 glyph
= row
->glyphs
[*area
];
1580 end
= glyph
+ row
->used
[*area
];
1583 if (x
< x0
+ glyph
->pixel_width
)
1585 if (w
->pseudo_window_p
)
1587 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
1591 x0
+= glyph
->pixel_width
;
1598 *hpos
= glyph
- row
->glyphs
[*area
];
1604 Convert frame-relative x/y to coordinates relative to window W.
1605 Takes pseudo-windows into account. */
1608 frame_to_window_pixel_xy (w
, x
, y
)
1612 if (w
->pseudo_window_p
)
1614 /* A pseudo-window is always full-width, and starts at the
1615 left edge of the frame, plus a frame border. */
1616 struct frame
*f
= XFRAME (w
->frame
);
1617 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
1618 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1622 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
1623 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1628 Return in *R the clipping rectangle for glyph string S. */
1631 get_glyph_string_clip_rect (s
, nr
)
1632 struct glyph_string
*s
;
1633 NativeRectangle
*nr
;
1637 if (s
->row
->full_width_p
)
1639 /* Draw full-width. X coordinates are relative to S->w->left. */
1640 int canon_x
= CANON_X_UNIT (s
->f
);
1642 r
.x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
1643 r
.width
= XFASTINT (s
->w
->width
) * canon_x
;
1645 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
1647 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
1648 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
1652 r
.x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1654 /* Unless displaying a mode or menu bar line, which are always
1655 fully visible, clip to the visible part of the row. */
1656 if (s
->w
->pseudo_window_p
)
1657 r
.height
= s
->row
->visible_height
;
1659 r
.height
= s
->height
;
1663 /* This is a text line that may be partially visible. */
1664 r
.x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
1665 r
.width
= window_box_width (s
->w
, s
->area
);
1666 r
.height
= s
->row
->visible_height
;
1669 /* If S draws overlapping rows, it's sufficient to use the top and
1670 bottom of the window for clipping because this glyph string
1671 intentionally draws over other lines. */
1672 if (s
->for_overlaps_p
)
1674 r
.y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
1675 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1679 /* Don't use S->y for clipping because it doesn't take partially
1680 visible lines into account. For example, it can be negative for
1681 partially visible lines at the top of a window. */
1682 if (!s
->row
->full_width_p
1683 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1684 r
.y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
1686 r
.y
= max (0, s
->row
->y
);
1688 /* If drawing a tool-bar window, draw it over the internal border
1689 at the top of the window. */
1690 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1691 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1694 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1697 /* ++KFS: From W32 port, but it looks ok for all platforms to me. */
1698 /* If drawing the cursor, don't let glyph draw outside its
1699 advertised boundaries. Cleartype does this under some circumstances. */
1700 if (s
->hl
== DRAW_CURSOR
)
1704 r
.width
-= s
->x
- r
.x
;
1707 r
.width
= min (r
.width
, s
->first_glyph
->pixel_width
);
1711 #ifdef CONVERT_FROM_XRECT
1712 CONVERT_FROM_XRECT (r
, *nr
);
1718 #endif /* HAVE_WINDOW_SYSTEM */
1721 /***********************************************************************
1722 Lisp form evaluation
1723 ***********************************************************************/
1725 /* Error handler for safe_eval and safe_call. */
1728 safe_eval_handler (arg
)
1731 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1736 /* Evaluate SEXPR and return the result, or nil if something went
1737 wrong. Prevent redisplay during the evaluation. */
1745 if (inhibit_eval_during_redisplay
)
1749 int count
= SPECPDL_INDEX ();
1750 struct gcpro gcpro1
;
1753 specbind (Qinhibit_redisplay
, Qt
);
1754 /* Use Qt to ensure debugger does not run,
1755 so there is no possibility of wanting to redisplay. */
1756 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1759 val
= unbind_to (count
, val
);
1766 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1767 Return the result, or nil if something went wrong. Prevent
1768 redisplay during the evaluation. */
1771 safe_call (nargs
, args
)
1777 if (inhibit_eval_during_redisplay
)
1781 int count
= SPECPDL_INDEX ();
1782 struct gcpro gcpro1
;
1785 gcpro1
.nvars
= nargs
;
1786 specbind (Qinhibit_redisplay
, Qt
);
1787 /* Use Qt to ensure debugger does not run,
1788 so there is no possibility of wanting to redisplay. */
1789 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1792 val
= unbind_to (count
, val
);
1799 /* Call function FN with one argument ARG.
1800 Return the result, or nil if something went wrong. */
1803 safe_call1 (fn
, arg
)
1804 Lisp_Object fn
, arg
;
1806 Lisp_Object args
[2];
1809 return safe_call (2, args
);
1814 /***********************************************************************
1816 ***********************************************************************/
1820 /* Define CHECK_IT to perform sanity checks on iterators.
1821 This is for debugging. It is too slow to do unconditionally. */
1827 if (it
->method
== next_element_from_string
)
1829 xassert (STRINGP (it
->string
));
1830 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1832 else if (it
->method
== next_element_from_buffer
)
1834 /* Check that character and byte positions agree. */
1835 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1839 xassert (it
->current
.dpvec_index
>= 0);
1841 xassert (it
->current
.dpvec_index
< 0);
1844 #define CHECK_IT(IT) check_it ((IT))
1848 #define CHECK_IT(IT) (void) 0
1855 /* Check that the window end of window W is what we expect it
1856 to be---the last row in the current matrix displaying text. */
1859 check_window_end (w
)
1862 if (!MINI_WINDOW_P (w
)
1863 && !NILP (w
->window_end_valid
))
1865 struct glyph_row
*row
;
1866 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1867 XFASTINT (w
->window_end_vpos
)),
1869 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1870 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1874 #define CHECK_WINDOW_END(W) check_window_end ((W))
1876 #else /* not GLYPH_DEBUG */
1878 #define CHECK_WINDOW_END(W) (void) 0
1880 #endif /* not GLYPH_DEBUG */
1884 /***********************************************************************
1885 Iterator initialization
1886 ***********************************************************************/
1888 /* Initialize IT for displaying current_buffer in window W, starting
1889 at character position CHARPOS. CHARPOS < 0 means that no buffer
1890 position is specified which is useful when the iterator is assigned
1891 a position later. BYTEPOS is the byte position corresponding to
1892 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1894 If ROW is not null, calls to produce_glyphs with IT as parameter
1895 will produce glyphs in that row.
1897 BASE_FACE_ID is the id of a base face to use. It must be one of
1898 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1899 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1900 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1902 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1903 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1904 will be initialized to use the corresponding mode line glyph row of
1905 the desired matrix of W. */
1908 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1911 int charpos
, bytepos
;
1912 struct glyph_row
*row
;
1913 enum face_id base_face_id
;
1915 int highlight_region_p
;
1917 /* Some precondition checks. */
1918 xassert (w
!= NULL
&& it
!= NULL
);
1919 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1922 /* If face attributes have been changed since the last redisplay,
1923 free realized faces now because they depend on face definitions
1924 that might have changed. Don't free faces while there might be
1925 desired matrices pending which reference these faces. */
1926 if (face_change_count
&& !inhibit_free_realized_faces
)
1928 face_change_count
= 0;
1929 free_all_realized_faces (Qnil
);
1932 /* Use one of the mode line rows of W's desired matrix if
1936 if (base_face_id
== MODE_LINE_FACE_ID
1937 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
1938 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1939 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1940 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1944 bzero (it
, sizeof *it
);
1945 it
->current
.overlay_string_index
= -1;
1946 it
->current
.dpvec_index
= -1;
1947 it
->base_face_id
= base_face_id
;
1949 /* The window in which we iterate over current_buffer: */
1950 XSETWINDOW (it
->window
, w
);
1952 it
->f
= XFRAME (w
->frame
);
1954 /* Extra space between lines (on window systems only). */
1955 if (base_face_id
== DEFAULT_FACE_ID
1956 && FRAME_WINDOW_P (it
->f
))
1958 if (NATNUMP (current_buffer
->extra_line_spacing
))
1959 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1960 else if (it
->f
->extra_line_spacing
> 0)
1961 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1964 /* If realized faces have been removed, e.g. because of face
1965 attribute changes of named faces, recompute them. When running
1966 in batch mode, the face cache of Vterminal_frame is null. If
1967 we happen to get called, make a dummy face cache. */
1972 FRAME_FACE_CACHE (it
->f
) == NULL
)
1973 init_frame_faces (it
->f
);
1974 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1975 recompute_basic_faces (it
->f
);
1977 /* Current value of the `space-width', and 'height' properties. */
1978 it
->space_width
= Qnil
;
1979 it
->font_height
= Qnil
;
1981 /* Are control characters displayed as `^C'? */
1982 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1984 /* -1 means everything between a CR and the following line end
1985 is invisible. >0 means lines indented more than this value are
1987 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1988 ? XFASTINT (current_buffer
->selective_display
)
1989 : (!NILP (current_buffer
->selective_display
)
1991 it
->selective_display_ellipsis_p
1992 = !NILP (current_buffer
->selective_display_ellipses
);
1994 /* Display table to use. */
1995 it
->dp
= window_display_table (w
);
1997 /* Are multibyte characters enabled in current_buffer? */
1998 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2000 /* Non-zero if we should highlight the region. */
2002 = (!NILP (Vtransient_mark_mode
)
2003 && !NILP (current_buffer
->mark_active
)
2004 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2006 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2007 start and end of a visible region in window IT->w. Set both to
2008 -1 to indicate no region. */
2009 if (highlight_region_p
2010 /* Maybe highlight only in selected window. */
2011 && (/* Either show region everywhere. */
2012 highlight_nonselected_windows
2013 /* Or show region in the selected window. */
2014 || w
== XWINDOW (selected_window
)
2015 /* Or show the region if we are in the mini-buffer and W is
2016 the window the mini-buffer refers to. */
2017 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2018 && WINDOWP (minibuf_selected_window
)
2019 && w
== XWINDOW (minibuf_selected_window
))))
2021 int charpos
= marker_position (current_buffer
->mark
);
2022 it
->region_beg_charpos
= min (PT
, charpos
);
2023 it
->region_end_charpos
= max (PT
, charpos
);
2026 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2028 /* Get the position at which the redisplay_end_trigger hook should
2029 be run, if it is to be run at all. */
2030 if (MARKERP (w
->redisplay_end_trigger
)
2031 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2032 it
->redisplay_end_trigger_charpos
2033 = marker_position (w
->redisplay_end_trigger
);
2034 else if (INTEGERP (w
->redisplay_end_trigger
))
2035 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2037 /* Correct bogus values of tab_width. */
2038 it
->tab_width
= XINT (current_buffer
->tab_width
);
2039 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2042 /* Are lines in the display truncated? */
2043 it
->truncate_lines_p
2044 = (base_face_id
!= DEFAULT_FACE_ID
2045 || XINT (it
->w
->hscroll
)
2046 || (truncate_partial_width_windows
2047 && !WINDOW_FULL_WIDTH_P (it
->w
))
2048 || !NILP (current_buffer
->truncate_lines
));
2050 /* Get dimensions of truncation and continuation glyphs. These are
2051 displayed as fringe bitmaps under X, so we don't need them for such
2053 if (!FRAME_WINDOW_P (it
->f
))
2055 if (it
->truncate_lines_p
)
2057 /* We will need the truncation glyph. */
2058 xassert (it
->glyph_row
== NULL
);
2059 produce_special_glyphs (it
, IT_TRUNCATION
);
2060 it
->truncation_pixel_width
= it
->pixel_width
;
2064 /* We will need the continuation glyph. */
2065 xassert (it
->glyph_row
== NULL
);
2066 produce_special_glyphs (it
, IT_CONTINUATION
);
2067 it
->continuation_pixel_width
= it
->pixel_width
;
2070 /* Reset these values to zero because the produce_special_glyphs
2071 above has changed them. */
2072 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2073 it
->phys_ascent
= it
->phys_descent
= 0;
2076 /* Set this after getting the dimensions of truncation and
2077 continuation glyphs, so that we don't produce glyphs when calling
2078 produce_special_glyphs, above. */
2079 it
->glyph_row
= row
;
2080 it
->area
= TEXT_AREA
;
2082 /* Get the dimensions of the display area. The display area
2083 consists of the visible window area plus a horizontally scrolled
2084 part to the left of the window. All x-values are relative to the
2085 start of this total display area. */
2086 if (base_face_id
!= DEFAULT_FACE_ID
)
2088 /* Mode lines, menu bar in terminal frames. */
2089 it
->first_visible_x
= 0;
2090 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
2095 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
2096 it
->last_visible_x
= (it
->first_visible_x
2097 + window_box_width (w
, TEXT_AREA
));
2099 /* If we truncate lines, leave room for the truncator glyph(s) at
2100 the right margin. Otherwise, leave room for the continuation
2101 glyph(s). Truncation and continuation glyphs are not inserted
2102 for window-based redisplay. */
2103 if (!FRAME_WINDOW_P (it
->f
))
2105 if (it
->truncate_lines_p
)
2106 it
->last_visible_x
-= it
->truncation_pixel_width
;
2108 it
->last_visible_x
-= it
->continuation_pixel_width
;
2111 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2112 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2115 /* Leave room for a border glyph. */
2116 if (!FRAME_WINDOW_P (it
->f
)
2117 && !WINDOW_RIGHTMOST_P (it
->w
))
2118 it
->last_visible_x
-= 1;
2120 it
->last_visible_y
= window_text_bottom_y (w
);
2122 /* For mode lines and alike, arrange for the first glyph having a
2123 left box line if the face specifies a box. */
2124 if (base_face_id
!= DEFAULT_FACE_ID
)
2128 it
->face_id
= base_face_id
;
2130 /* If we have a boxed mode line, make the first character appear
2131 with a left box line. */
2132 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2133 if (face
->box
!= FACE_NO_BOX
)
2134 it
->start_of_box_run_p
= 1;
2137 /* If a buffer position was specified, set the iterator there,
2138 getting overlays and face properties from that position. */
2139 if (charpos
>= BUF_BEG (current_buffer
))
2141 it
->end_charpos
= ZV
;
2143 IT_CHARPOS (*it
) = charpos
;
2145 /* Compute byte position if not specified. */
2146 if (bytepos
< charpos
)
2147 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2149 IT_BYTEPOS (*it
) = bytepos
;
2151 /* Compute faces etc. */
2152 reseat (it
, it
->current
.pos
, 1);
2159 /* Initialize IT for the display of window W with window start POS. */
2162 start_display (it
, w
, pos
)
2165 struct text_pos pos
;
2167 struct glyph_row
*row
;
2168 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2170 row
= w
->desired_matrix
->rows
+ first_vpos
;
2171 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2173 if (!it
->truncate_lines_p
)
2175 int start_at_line_beg_p
;
2176 int first_y
= it
->current_y
;
2178 /* If window start is not at a line start, skip forward to POS to
2179 get the correct continuation lines width. */
2180 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2181 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2182 if (!start_at_line_beg_p
)
2186 reseat_at_previous_visible_line_start (it
);
2187 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2189 new_x
= it
->current_x
+ it
->pixel_width
;
2191 /* If lines are continued, this line may end in the middle
2192 of a multi-glyph character (e.g. a control character
2193 displayed as \003, or in the middle of an overlay
2194 string). In this case move_it_to above will not have
2195 taken us to the start of the continuation line but to the
2196 end of the continued line. */
2197 if (it
->current_x
> 0
2198 && !it
->truncate_lines_p
/* Lines are continued. */
2199 && (/* And glyph doesn't fit on the line. */
2200 new_x
> it
->last_visible_x
2201 /* Or it fits exactly and we're on a window
2203 || (new_x
== it
->last_visible_x
2204 && FRAME_WINDOW_P (it
->f
))))
2206 if (it
->current
.dpvec_index
>= 0
2207 || it
->current
.overlay_string_index
>= 0)
2209 set_iterator_to_next (it
, 1);
2210 move_it_in_display_line_to (it
, -1, -1, 0);
2213 it
->continuation_lines_width
+= it
->current_x
;
2216 /* We're starting a new display line, not affected by the
2217 height of the continued line, so clear the appropriate
2218 fields in the iterator structure. */
2219 it
->max_ascent
= it
->max_descent
= 0;
2220 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2222 it
->current_y
= first_y
;
2224 it
->current_x
= it
->hpos
= 0;
2228 #if 0 /* Don't assert the following because start_display is sometimes
2229 called intentionally with a window start that is not at a
2230 line start. Please leave this code in as a comment. */
2232 /* Window start should be on a line start, now. */
2233 xassert (it
->continuation_lines_width
2234 || IT_CHARPOS (it
) == BEGV
2235 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2240 /* Return 1 if POS is a position in ellipses displayed for invisible
2241 text. W is the window we display, for text property lookup. */
2244 in_ellipses_for_invisible_text_p (pos
, w
)
2245 struct display_pos
*pos
;
2248 Lisp_Object prop
, window
;
2250 int charpos
= CHARPOS (pos
->pos
);
2252 /* If POS specifies a position in a display vector, this might
2253 be for an ellipsis displayed for invisible text. We won't
2254 get the iterator set up for delivering that ellipsis unless
2255 we make sure that it gets aware of the invisible text. */
2256 if (pos
->dpvec_index
>= 0
2257 && pos
->overlay_string_index
< 0
2258 && CHARPOS (pos
->string_pos
) < 0
2260 && (XSETWINDOW (window
, w
),
2261 prop
= Fget_char_property (make_number (charpos
),
2262 Qinvisible
, window
),
2263 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2265 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2267 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2274 /* Initialize IT for stepping through current_buffer in window W,
2275 starting at position POS that includes overlay string and display
2276 vector/ control character translation position information. Value
2277 is zero if there are overlay strings with newlines at POS. */
2280 init_from_display_pos (it
, w
, pos
)
2283 struct display_pos
*pos
;
2285 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2286 int i
, overlay_strings_with_newlines
= 0;
2288 /* If POS specifies a position in a display vector, this might
2289 be for an ellipsis displayed for invisible text. We won't
2290 get the iterator set up for delivering that ellipsis unless
2291 we make sure that it gets aware of the invisible text. */
2292 if (in_ellipses_for_invisible_text_p (pos
, w
))
2298 /* Keep in mind: the call to reseat in init_iterator skips invisible
2299 text, so we might end up at a position different from POS. This
2300 is only a problem when POS is a row start after a newline and an
2301 overlay starts there with an after-string, and the overlay has an
2302 invisible property. Since we don't skip invisible text in
2303 display_line and elsewhere immediately after consuming the
2304 newline before the row start, such a POS will not be in a string,
2305 but the call to init_iterator below will move us to the
2307 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2309 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
2311 const char *s
= SDATA (it
->overlay_strings
[i
]);
2312 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2314 while (s
< e
&& *s
!= '\n')
2319 overlay_strings_with_newlines
= 1;
2324 /* If position is within an overlay string, set up IT to the right
2326 if (pos
->overlay_string_index
>= 0)
2330 /* If the first overlay string happens to have a `display'
2331 property for an image, the iterator will be set up for that
2332 image, and we have to undo that setup first before we can
2333 correct the overlay string index. */
2334 if (it
->method
== next_element_from_image
)
2337 /* We already have the first chunk of overlay strings in
2338 IT->overlay_strings. Load more until the one for
2339 pos->overlay_string_index is in IT->overlay_strings. */
2340 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2342 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2343 it
->current
.overlay_string_index
= 0;
2346 load_overlay_strings (it
, 0);
2347 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2351 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2352 relative_index
= (it
->current
.overlay_string_index
2353 % OVERLAY_STRING_CHUNK_SIZE
);
2354 it
->string
= it
->overlay_strings
[relative_index
];
2355 xassert (STRINGP (it
->string
));
2356 it
->current
.string_pos
= pos
->string_pos
;
2357 it
->method
= next_element_from_string
;
2360 #if 0 /* This is bogus because POS not having an overlay string
2361 position does not mean it's after the string. Example: A
2362 line starting with a before-string and initialization of IT
2363 to the previous row's end position. */
2364 else if (it
->current
.overlay_string_index
>= 0)
2366 /* If POS says we're already after an overlay string ending at
2367 POS, make sure to pop the iterator because it will be in
2368 front of that overlay string. When POS is ZV, we've thereby
2369 also ``processed'' overlay strings at ZV. */
2372 it
->current
.overlay_string_index
= -1;
2373 it
->method
= next_element_from_buffer
;
2374 if (CHARPOS (pos
->pos
) == ZV
)
2375 it
->overlay_strings_at_end_processed_p
= 1;
2379 if (CHARPOS (pos
->string_pos
) >= 0)
2381 /* Recorded position is not in an overlay string, but in another
2382 string. This can only be a string from a `display' property.
2383 IT should already be filled with that string. */
2384 it
->current
.string_pos
= pos
->string_pos
;
2385 xassert (STRINGP (it
->string
));
2388 /* Restore position in display vector translations, control
2389 character translations or ellipses. */
2390 if (pos
->dpvec_index
>= 0)
2392 if (it
->dpvec
== NULL
)
2393 get_next_display_element (it
);
2394 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2395 it
->current
.dpvec_index
= pos
->dpvec_index
;
2399 return !overlay_strings_with_newlines
;
2403 /* Initialize IT for stepping through current_buffer in window W
2404 starting at ROW->start. */
2407 init_to_row_start (it
, w
, row
)
2410 struct glyph_row
*row
;
2412 init_from_display_pos (it
, w
, &row
->start
);
2413 it
->continuation_lines_width
= row
->continuation_lines_width
;
2418 /* Initialize IT for stepping through current_buffer in window W
2419 starting in the line following ROW, i.e. starting at ROW->end.
2420 Value is zero if there are overlay strings with newlines at ROW's
2424 init_to_row_end (it
, w
, row
)
2427 struct glyph_row
*row
;
2431 if (init_from_display_pos (it
, w
, &row
->end
))
2433 if (row
->continued_p
)
2434 it
->continuation_lines_width
2435 = row
->continuation_lines_width
+ row
->pixel_width
;
2446 /***********************************************************************
2448 ***********************************************************************/
2450 /* Called when IT reaches IT->stop_charpos. Handle text property and
2451 overlay changes. Set IT->stop_charpos to the next position where
2458 enum prop_handled handled
;
2459 int handle_overlay_change_p
= 1;
2463 it
->current
.dpvec_index
= -1;
2467 handled
= HANDLED_NORMALLY
;
2469 /* Call text property handlers. */
2470 for (p
= it_props
; p
->handler
; ++p
)
2472 handled
= p
->handler (it
);
2474 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2476 else if (handled
== HANDLED_RETURN
)
2478 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2479 handle_overlay_change_p
= 0;
2482 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2484 /* Don't check for overlay strings below when set to deliver
2485 characters from a display vector. */
2486 if (it
->method
== next_element_from_display_vector
)
2487 handle_overlay_change_p
= 0;
2489 /* Handle overlay changes. */
2490 if (handle_overlay_change_p
)
2491 handled
= handle_overlay_change (it
);
2493 /* Determine where to stop next. */
2494 if (handled
== HANDLED_NORMALLY
)
2495 compute_stop_pos (it
);
2498 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2502 /* Compute IT->stop_charpos from text property and overlay change
2503 information for IT's current position. */
2506 compute_stop_pos (it
)
2509 register INTERVAL iv
, next_iv
;
2510 Lisp_Object object
, limit
, position
;
2512 /* If nowhere else, stop at the end. */
2513 it
->stop_charpos
= it
->end_charpos
;
2515 if (STRINGP (it
->string
))
2517 /* Strings are usually short, so don't limit the search for
2519 object
= it
->string
;
2521 position
= make_number (IT_STRING_CHARPOS (*it
));
2527 /* If next overlay change is in front of the current stop pos
2528 (which is IT->end_charpos), stop there. Note: value of
2529 next_overlay_change is point-max if no overlay change
2531 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2532 if (charpos
< it
->stop_charpos
)
2533 it
->stop_charpos
= charpos
;
2535 /* If showing the region, we have to stop at the region
2536 start or end because the face might change there. */
2537 if (it
->region_beg_charpos
> 0)
2539 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2540 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2541 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2542 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2545 /* Set up variables for computing the stop position from text
2546 property changes. */
2547 XSETBUFFER (object
, current_buffer
);
2548 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2549 position
= make_number (IT_CHARPOS (*it
));
2553 /* Get the interval containing IT's position. Value is a null
2554 interval if there isn't such an interval. */
2555 iv
= validate_interval_range (object
, &position
, &position
, 0);
2556 if (!NULL_INTERVAL_P (iv
))
2558 Lisp_Object values_here
[LAST_PROP_IDX
];
2561 /* Get properties here. */
2562 for (p
= it_props
; p
->handler
; ++p
)
2563 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2565 /* Look for an interval following iv that has different
2567 for (next_iv
= next_interval (iv
);
2568 (!NULL_INTERVAL_P (next_iv
)
2570 || XFASTINT (limit
) > next_iv
->position
));
2571 next_iv
= next_interval (next_iv
))
2573 for (p
= it_props
; p
->handler
; ++p
)
2575 Lisp_Object new_value
;
2577 new_value
= textget (next_iv
->plist
, *p
->name
);
2578 if (!EQ (values_here
[p
->idx
], new_value
))
2586 if (!NULL_INTERVAL_P (next_iv
))
2588 if (INTEGERP (limit
)
2589 && next_iv
->position
>= XFASTINT (limit
))
2590 /* No text property change up to limit. */
2591 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2593 /* Text properties change in next_iv. */
2594 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2598 xassert (STRINGP (it
->string
)
2599 || (it
->stop_charpos
>= BEGV
2600 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2604 /* Return the position of the next overlay change after POS in
2605 current_buffer. Value is point-max if no overlay change
2606 follows. This is like `next-overlay-change' but doesn't use
2610 next_overlay_change (pos
)
2615 Lisp_Object
*overlays
;
2619 /* Get all overlays at the given position. */
2621 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2622 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2623 if (noverlays
> len
)
2626 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2627 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2630 /* If any of these overlays ends before endpos,
2631 use its ending point instead. */
2632 for (i
= 0; i
< noverlays
; ++i
)
2637 oend
= OVERLAY_END (overlays
[i
]);
2638 oendpos
= OVERLAY_POSITION (oend
);
2639 endpos
= min (endpos
, oendpos
);
2647 /***********************************************************************
2649 ***********************************************************************/
2651 /* Handle changes in the `fontified' property of the current buffer by
2652 calling hook functions from Qfontification_functions to fontify
2655 static enum prop_handled
2656 handle_fontified_prop (it
)
2659 Lisp_Object prop
, pos
;
2660 enum prop_handled handled
= HANDLED_NORMALLY
;
2662 /* Get the value of the `fontified' property at IT's current buffer
2663 position. (The `fontified' property doesn't have a special
2664 meaning in strings.) If the value is nil, call functions from
2665 Qfontification_functions. */
2666 if (!STRINGP (it
->string
)
2668 && !NILP (Vfontification_functions
)
2669 && !NILP (Vrun_hooks
)
2670 && (pos
= make_number (IT_CHARPOS (*it
)),
2671 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2674 int count
= SPECPDL_INDEX ();
2677 val
= Vfontification_functions
;
2678 specbind (Qfontification_functions
, Qnil
);
2680 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2681 safe_call1 (val
, pos
);
2684 Lisp_Object globals
, fn
;
2685 struct gcpro gcpro1
, gcpro2
;
2688 GCPRO2 (val
, globals
);
2690 for (; CONSP (val
); val
= XCDR (val
))
2696 /* A value of t indicates this hook has a local
2697 binding; it means to run the global binding too.
2698 In a global value, t should not occur. If it
2699 does, we must ignore it to avoid an endless
2701 for (globals
= Fdefault_value (Qfontification_functions
);
2703 globals
= XCDR (globals
))
2705 fn
= XCAR (globals
);
2707 safe_call1 (fn
, pos
);
2711 safe_call1 (fn
, pos
);
2717 unbind_to (count
, Qnil
);
2719 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2720 something. This avoids an endless loop if they failed to
2721 fontify the text for which reason ever. */
2722 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2723 handled
= HANDLED_RECOMPUTE_PROPS
;
2731 /***********************************************************************
2733 ***********************************************************************/
2735 /* Set up iterator IT from face properties at its current position.
2736 Called from handle_stop. */
2738 static enum prop_handled
2739 handle_face_prop (it
)
2742 int new_face_id
, next_stop
;
2744 if (!STRINGP (it
->string
))
2747 = face_at_buffer_position (it
->w
,
2749 it
->region_beg_charpos
,
2750 it
->region_end_charpos
,
2753 + TEXT_PROP_DISTANCE_LIMIT
),
2756 /* Is this a start of a run of characters with box face?
2757 Caveat: this can be called for a freshly initialized
2758 iterator; face_id is -1 in this case. We know that the new
2759 face will not change until limit, i.e. if the new face has a
2760 box, all characters up to limit will have one. But, as
2761 usual, we don't know whether limit is really the end. */
2762 if (new_face_id
!= it
->face_id
)
2764 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2766 /* If new face has a box but old face has not, this is
2767 the start of a run of characters with box, i.e. it has
2768 a shadow on the left side. The value of face_id of the
2769 iterator will be -1 if this is the initial call that gets
2770 the face. In this case, we have to look in front of IT's
2771 position and see whether there is a face != new_face_id. */
2772 it
->start_of_box_run_p
2773 = (new_face
->box
!= FACE_NO_BOX
2774 && (it
->face_id
>= 0
2775 || IT_CHARPOS (*it
) == BEG
2776 || new_face_id
!= face_before_it_pos (it
)));
2777 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2782 int base_face_id
, bufpos
;
2784 if (it
->current
.overlay_string_index
>= 0)
2785 bufpos
= IT_CHARPOS (*it
);
2789 /* For strings from a buffer, i.e. overlay strings or strings
2790 from a `display' property, use the face at IT's current
2791 buffer position as the base face to merge with, so that
2792 overlay strings appear in the same face as surrounding
2793 text, unless they specify their own faces. */
2794 base_face_id
= underlying_face_id (it
);
2796 new_face_id
= face_at_string_position (it
->w
,
2798 IT_STRING_CHARPOS (*it
),
2800 it
->region_beg_charpos
,
2801 it
->region_end_charpos
,
2805 #if 0 /* This shouldn't be neccessary. Let's check it. */
2806 /* If IT is used to display a mode line we would really like to
2807 use the mode line face instead of the frame's default face. */
2808 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2809 && new_face_id
== DEFAULT_FACE_ID
)
2810 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2813 /* Is this a start of a run of characters with box? Caveat:
2814 this can be called for a freshly allocated iterator; face_id
2815 is -1 is this case. We know that the new face will not
2816 change until the next check pos, i.e. if the new face has a
2817 box, all characters up to that position will have a
2818 box. But, as usual, we don't know whether that position
2819 is really the end. */
2820 if (new_face_id
!= it
->face_id
)
2822 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2823 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2825 /* If new face has a box but old face hasn't, this is the
2826 start of a run of characters with box, i.e. it has a
2827 shadow on the left side. */
2828 it
->start_of_box_run_p
2829 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2830 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2834 it
->face_id
= new_face_id
;
2835 return HANDLED_NORMALLY
;
2839 /* Return the ID of the face ``underlying'' IT's current position,
2840 which is in a string. If the iterator is associated with a
2841 buffer, return the face at IT's current buffer position.
2842 Otherwise, use the iterator's base_face_id. */
2845 underlying_face_id (it
)
2848 int face_id
= it
->base_face_id
, i
;
2850 xassert (STRINGP (it
->string
));
2852 for (i
= it
->sp
- 1; i
>= 0; --i
)
2853 if (NILP (it
->stack
[i
].string
))
2854 face_id
= it
->stack
[i
].face_id
;
2860 /* Compute the face one character before or after the current position
2861 of IT. BEFORE_P non-zero means get the face in front of IT's
2862 position. Value is the id of the face. */
2865 face_before_or_after_it_pos (it
, before_p
)
2870 int next_check_charpos
;
2871 struct text_pos pos
;
2873 xassert (it
->s
== NULL
);
2875 if (STRINGP (it
->string
))
2877 int bufpos
, base_face_id
;
2879 /* No face change past the end of the string (for the case
2880 we are padding with spaces). No face change before the
2882 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2883 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2886 /* Set pos to the position before or after IT's current position. */
2888 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2890 /* For composition, we must check the character after the
2892 pos
= (it
->what
== IT_COMPOSITION
2893 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2894 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2896 if (it
->current
.overlay_string_index
>= 0)
2897 bufpos
= IT_CHARPOS (*it
);
2901 base_face_id
= underlying_face_id (it
);
2903 /* Get the face for ASCII, or unibyte. */
2904 face_id
= face_at_string_position (it
->w
,
2908 it
->region_beg_charpos
,
2909 it
->region_end_charpos
,
2910 &next_check_charpos
,
2913 /* Correct the face for charsets different from ASCII. Do it
2914 for the multibyte case only. The face returned above is
2915 suitable for unibyte text if IT->string is unibyte. */
2916 if (STRING_MULTIBYTE (it
->string
))
2918 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
2919 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
2921 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2923 c
= string_char_and_length (p
, rest
, &len
);
2924 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2929 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2930 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2933 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2934 pos
= it
->current
.pos
;
2937 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2940 if (it
->what
== IT_COMPOSITION
)
2941 /* For composition, we must check the position after the
2943 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2945 INC_TEXT_POS (pos
, it
->multibyte_p
);
2948 /* Determine face for CHARSET_ASCII, or unibyte. */
2949 face_id
= face_at_buffer_position (it
->w
,
2951 it
->region_beg_charpos
,
2952 it
->region_end_charpos
,
2953 &next_check_charpos
,
2956 /* Correct the face for charsets different from ASCII. Do it
2957 for the multibyte case only. The face returned above is
2958 suitable for unibyte text if current_buffer is unibyte. */
2959 if (it
->multibyte_p
)
2961 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
2962 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2963 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2972 /***********************************************************************
2974 ***********************************************************************/
2976 /* Set up iterator IT from invisible properties at its current
2977 position. Called from handle_stop. */
2979 static enum prop_handled
2980 handle_invisible_prop (it
)
2983 enum prop_handled handled
= HANDLED_NORMALLY
;
2985 if (STRINGP (it
->string
))
2987 extern Lisp_Object Qinvisible
;
2988 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2990 /* Get the value of the invisible text property at the
2991 current position. Value will be nil if there is no such
2993 charpos
= make_number (IT_STRING_CHARPOS (*it
));
2994 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2997 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
2999 handled
= HANDLED_RECOMPUTE_PROPS
;
3001 /* Get the position at which the next change of the
3002 invisible text property can be found in IT->string.
3003 Value will be nil if the property value is the same for
3004 all the rest of IT->string. */
3005 XSETINT (limit
, SCHARS (it
->string
));
3006 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3009 /* Text at current position is invisible. The next
3010 change in the property is at position end_charpos.
3011 Move IT's current position to that position. */
3012 if (INTEGERP (end_charpos
)
3013 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3015 struct text_pos old
;
3016 old
= it
->current
.string_pos
;
3017 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3018 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3022 /* The rest of the string is invisible. If this is an
3023 overlay string, proceed with the next overlay string
3024 or whatever comes and return a character from there. */
3025 if (it
->current
.overlay_string_index
>= 0)
3027 next_overlay_string (it
);
3028 /* Don't check for overlay strings when we just
3029 finished processing them. */
3030 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3034 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3035 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3042 int invis_p
, newpos
, next_stop
, start_charpos
;
3043 Lisp_Object pos
, prop
, overlay
;
3045 /* First of all, is there invisible text at this position? */
3046 start_charpos
= IT_CHARPOS (*it
);
3047 pos
= make_number (IT_CHARPOS (*it
));
3048 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3050 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3052 /* If we are on invisible text, skip over it. */
3053 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3055 /* Record whether we have to display an ellipsis for the
3057 int display_ellipsis_p
= invis_p
== 2;
3059 handled
= HANDLED_RECOMPUTE_PROPS
;
3061 /* Loop skipping over invisible text. The loop is left at
3062 ZV or with IT on the first char being visible again. */
3065 /* Try to skip some invisible text. Return value is the
3066 position reached which can be equal to IT's position
3067 if there is nothing invisible here. This skips both
3068 over invisible text properties and overlays with
3069 invisible property. */
3070 newpos
= skip_invisible (IT_CHARPOS (*it
),
3071 &next_stop
, ZV
, it
->window
);
3073 /* If we skipped nothing at all we weren't at invisible
3074 text in the first place. If everything to the end of
3075 the buffer was skipped, end the loop. */
3076 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3080 /* We skipped some characters but not necessarily
3081 all there are. Check if we ended up on visible
3082 text. Fget_char_property returns the property of
3083 the char before the given position, i.e. if we
3084 get invis_p = 0, this means that the char at
3085 newpos is visible. */
3086 pos
= make_number (newpos
);
3087 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3088 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3091 /* If we ended up on invisible text, proceed to
3092 skip starting with next_stop. */
3094 IT_CHARPOS (*it
) = next_stop
;
3098 /* The position newpos is now either ZV or on visible text. */
3099 IT_CHARPOS (*it
) = newpos
;
3100 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3102 /* If there are before-strings at the start of invisible
3103 text, and the text is invisible because of a text
3104 property, arrange to show before-strings because 20.x did
3105 it that way. (If the text is invisible because of an
3106 overlay property instead of a text property, this is
3107 already handled in the overlay code.) */
3109 && get_overlay_strings (it
, start_charpos
))
3111 handled
= HANDLED_RECOMPUTE_PROPS
;
3112 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3114 else if (display_ellipsis_p
)
3115 setup_for_ellipsis (it
);
3123 /* Make iterator IT return `...' next. */
3126 setup_for_ellipsis (it
)
3130 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3132 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3133 it
->dpvec
= v
->contents
;
3134 it
->dpend
= v
->contents
+ v
->size
;
3138 /* Default `...'. */
3139 it
->dpvec
= default_invis_vector
;
3140 it
->dpend
= default_invis_vector
+ 3;
3143 /* The ellipsis display does not replace the display of the
3144 character at the new position. Indicate this by setting
3145 IT->dpvec_char_len to zero. */
3146 it
->dpvec_char_len
= 0;
3148 it
->current
.dpvec_index
= 0;
3149 it
->method
= next_element_from_display_vector
;
3154 /***********************************************************************
3156 ***********************************************************************/
3158 /* Set up iterator IT from `display' property at its current position.
3159 Called from handle_stop. */
3161 static enum prop_handled
3162 handle_display_prop (it
)
3165 Lisp_Object prop
, object
;
3166 struct text_pos
*position
;
3167 int display_replaced_p
= 0;
3169 if (STRINGP (it
->string
))
3171 object
= it
->string
;
3172 position
= &it
->current
.string_pos
;
3176 object
= it
->w
->buffer
;
3177 position
= &it
->current
.pos
;
3180 /* Reset those iterator values set from display property values. */
3181 it
->font_height
= Qnil
;
3182 it
->space_width
= Qnil
;
3185 /* We don't support recursive `display' properties, i.e. string
3186 values that have a string `display' property, that have a string
3187 `display' property etc. */
3188 if (!it
->string_from_display_prop_p
)
3189 it
->area
= TEXT_AREA
;
3191 prop
= Fget_char_property (make_number (position
->charpos
),
3194 return HANDLED_NORMALLY
;
3197 /* Simple properties. */
3198 && !EQ (XCAR (prop
), Qimage
)
3199 && !EQ (XCAR (prop
), Qspace
)
3200 && !EQ (XCAR (prop
), Qwhen
)
3201 && !EQ (XCAR (prop
), Qspace_width
)
3202 && !EQ (XCAR (prop
), Qheight
)
3203 && !EQ (XCAR (prop
), Qraise
)
3204 /* Marginal area specifications. */
3205 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3206 && !NILP (XCAR (prop
)))
3208 for (; CONSP (prop
); prop
= XCDR (prop
))
3210 if (handle_single_display_prop (it
, XCAR (prop
), object
,
3211 position
, display_replaced_p
))
3212 display_replaced_p
= 1;
3215 else if (VECTORP (prop
))
3218 for (i
= 0; i
< ASIZE (prop
); ++i
)
3219 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
3220 position
, display_replaced_p
))
3221 display_replaced_p
= 1;
3225 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
3226 display_replaced_p
= 1;
3229 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3233 /* Value is the position of the end of the `display' property starting
3234 at START_POS in OBJECT. */
3236 static struct text_pos
3237 display_prop_end (it
, object
, start_pos
)
3240 struct text_pos start_pos
;
3243 struct text_pos end_pos
;
3245 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3246 Qdisplay
, object
, Qnil
);
3247 CHARPOS (end_pos
) = XFASTINT (end
);
3248 if (STRINGP (object
))
3249 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3251 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3257 /* Set up IT from a single `display' sub-property value PROP. OBJECT
3258 is the object in which the `display' property was found. *POSITION
3259 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3260 means that we previously saw a display sub-property which already
3261 replaced text display with something else, for example an image;
3262 ignore such properties after the first one has been processed.
3264 If PROP is a `space' or `image' sub-property, set *POSITION to the
3265 end position of the `display' property.
3267 Value is non-zero if something was found which replaces the display
3268 of buffer or string text. */
3271 handle_single_display_prop (it
, prop
, object
, position
,
3272 display_replaced_before_p
)
3276 struct text_pos
*position
;
3277 int display_replaced_before_p
;
3280 int replaces_text_display_p
= 0;
3283 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
3284 evaluated. If the result is nil, VALUE is ignored. */
3286 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3295 if (!NILP (form
) && !EQ (form
, Qt
))
3297 int count
= SPECPDL_INDEX ();
3298 struct gcpro gcpro1
;
3300 /* Bind `object' to the object having the `display' property, a
3301 buffer or string. Bind `position' to the position in the
3302 object where the property was found, and `buffer-position'
3303 to the current position in the buffer. */
3304 specbind (Qobject
, object
);
3305 specbind (Qposition
, make_number (CHARPOS (*position
)));
3306 specbind (Qbuffer_position
,
3307 make_number (STRINGP (object
)
3308 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3310 form
= safe_eval (form
);
3312 unbind_to (count
, Qnil
);
3319 && EQ (XCAR (prop
), Qheight
)
3320 && CONSP (XCDR (prop
)))
3322 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3325 /* `(height HEIGHT)'. */
3326 it
->font_height
= XCAR (XCDR (prop
));
3327 if (!NILP (it
->font_height
))
3329 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3330 int new_height
= -1;
3332 if (CONSP (it
->font_height
)
3333 && (EQ (XCAR (it
->font_height
), Qplus
)
3334 || EQ (XCAR (it
->font_height
), Qminus
))
3335 && CONSP (XCDR (it
->font_height
))
3336 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3338 /* `(+ N)' or `(- N)' where N is an integer. */
3339 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3340 if (EQ (XCAR (it
->font_height
), Qplus
))
3342 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3344 else if (FUNCTIONP (it
->font_height
))
3346 /* Call function with current height as argument.
3347 Value is the new height. */
3349 height
= safe_call1 (it
->font_height
,
3350 face
->lface
[LFACE_HEIGHT_INDEX
]);
3351 if (NUMBERP (height
))
3352 new_height
= XFLOATINT (height
);
3354 else if (NUMBERP (it
->font_height
))
3356 /* Value is a multiple of the canonical char height. */
3359 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3360 new_height
= (XFLOATINT (it
->font_height
)
3361 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3365 /* Evaluate IT->font_height with `height' bound to the
3366 current specified height to get the new height. */
3368 int count
= SPECPDL_INDEX ();
3370 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3371 value
= safe_eval (it
->font_height
);
3372 unbind_to (count
, Qnil
);
3374 if (NUMBERP (value
))
3375 new_height
= XFLOATINT (value
);
3379 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3382 else if (CONSP (prop
)
3383 && EQ (XCAR (prop
), Qspace_width
)
3384 && CONSP (XCDR (prop
)))
3386 /* `(space_width WIDTH)'. */
3387 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3390 value
= XCAR (XCDR (prop
));
3391 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3392 it
->space_width
= value
;
3394 else if (CONSP (prop
)
3395 && EQ (XCAR (prop
), Qraise
)
3396 && CONSP (XCDR (prop
)))
3398 /* `(raise FACTOR)'. */
3399 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3402 #ifdef HAVE_WINDOW_SYSTEM
3403 value
= XCAR (XCDR (prop
));
3404 if (NUMBERP (value
))
3406 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3407 it
->voffset
= - (XFLOATINT (value
)
3408 * (FONT_HEIGHT (face
->font
)));
3410 #endif /* HAVE_WINDOW_SYSTEM */
3412 else if (!it
->string_from_display_prop_p
)
3414 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3415 VALUE) or `((margin nil) VALUE)' or VALUE. */
3416 Lisp_Object location
, value
;
3417 struct text_pos start_pos
;
3420 /* Characters having this form of property are not displayed, so
3421 we have to find the end of the property. */
3422 start_pos
= *position
;
3423 *position
= display_prop_end (it
, object
, start_pos
);
3426 /* Let's stop at the new position and assume that all
3427 text properties change there. */
3428 it
->stop_charpos
= position
->charpos
;
3430 location
= Qunbound
;
3431 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3435 value
= XCDR (prop
);
3437 value
= XCAR (value
);
3440 if (EQ (XCAR (tem
), Qmargin
)
3441 && (tem
= XCDR (tem
),
3442 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3444 || EQ (tem
, Qleft_margin
)
3445 || EQ (tem
, Qright_margin
))))
3449 if (EQ (location
, Qunbound
))
3455 #ifdef HAVE_WINDOW_SYSTEM
3456 if (FRAME_TERMCAP_P (it
->f
))
3457 valid_p
= STRINGP (value
);
3459 valid_p
= (STRINGP (value
)
3460 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3461 || valid_image_p (value
));
3462 #else /* not HAVE_WINDOW_SYSTEM */
3463 valid_p
= STRINGP (value
);
3464 #endif /* not HAVE_WINDOW_SYSTEM */
3466 if ((EQ (location
, Qleft_margin
)
3467 || EQ (location
, Qright_margin
)
3470 && !display_replaced_before_p
)
3472 replaces_text_display_p
= 1;
3474 /* Save current settings of IT so that we can restore them
3475 when we are finished with the glyph property value. */
3478 if (NILP (location
))
3479 it
->area
= TEXT_AREA
;
3480 else if (EQ (location
, Qleft_margin
))
3481 it
->area
= LEFT_MARGIN_AREA
;
3483 it
->area
= RIGHT_MARGIN_AREA
;
3485 if (STRINGP (value
))
3488 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3489 it
->current
.overlay_string_index
= -1;
3490 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3491 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3492 it
->method
= next_element_from_string
;
3493 it
->stop_charpos
= 0;
3494 it
->string_from_display_prop_p
= 1;
3495 /* Say that we haven't consumed the characters with
3496 `display' property yet. The call to pop_it in
3497 set_iterator_to_next will clean this up. */
3498 *position
= start_pos
;
3500 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3502 it
->method
= next_element_from_stretch
;
3504 it
->current
.pos
= it
->position
= start_pos
;
3506 #ifdef HAVE_WINDOW_SYSTEM
3509 it
->what
= IT_IMAGE
;
3510 it
->image_id
= lookup_image (it
->f
, value
);
3511 it
->position
= start_pos
;
3512 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3513 it
->method
= next_element_from_image
;
3515 /* Say that we haven't consumed the characters with
3516 `display' property yet. The call to pop_it in
3517 set_iterator_to_next will clean this up. */
3518 *position
= start_pos
;
3520 #endif /* HAVE_WINDOW_SYSTEM */
3523 /* Invalid property or property not supported. Restore
3524 the position to what it was before. */
3525 *position
= start_pos
;
3528 return replaces_text_display_p
;
3532 /* Check if PROP is a display sub-property value whose text should be
3533 treated as intangible. */
3536 single_display_prop_intangible_p (prop
)
3539 /* Skip over `when FORM'. */
3540 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3554 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3555 we don't need to treat text as intangible. */
3556 if (EQ (XCAR (prop
), Qmargin
))
3564 || EQ (XCAR (prop
), Qleft_margin
)
3565 || EQ (XCAR (prop
), Qright_margin
))
3569 return CONSP (prop
) && EQ (XCAR (prop
), Qimage
);
3573 /* Check if PROP is a display property value whose text should be
3574 treated as intangible. */
3577 display_prop_intangible_p (prop
)
3581 && CONSP (XCAR (prop
))
3582 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3584 /* A list of sub-properties. */
3585 while (CONSP (prop
))
3587 if (single_display_prop_intangible_p (XCAR (prop
)))
3592 else if (VECTORP (prop
))
3594 /* A vector of sub-properties. */
3596 for (i
= 0; i
< ASIZE (prop
); ++i
)
3597 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3601 return single_display_prop_intangible_p (prop
);
3607 /* Return 1 if PROP is a display sub-property value containing STRING. */
3610 single_display_prop_string_p (prop
, string
)
3611 Lisp_Object prop
, string
;
3613 if (EQ (string
, prop
))
3616 /* Skip over `when FORM'. */
3617 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3626 /* Skip over `margin LOCATION'. */
3627 if (EQ (XCAR (prop
), Qmargin
))
3638 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3642 /* Return 1 if STRING appears in the `display' property PROP. */
3645 display_prop_string_p (prop
, string
)
3646 Lisp_Object prop
, string
;
3649 && CONSP (XCAR (prop
))
3650 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3652 /* A list of sub-properties. */
3653 while (CONSP (prop
))
3655 if (single_display_prop_string_p (XCAR (prop
), string
))
3660 else if (VECTORP (prop
))
3662 /* A vector of sub-properties. */
3664 for (i
= 0; i
< ASIZE (prop
); ++i
)
3665 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3669 return single_display_prop_string_p (prop
, string
);
3675 /* Determine from which buffer position in W's buffer STRING comes
3676 from. AROUND_CHARPOS is an approximate position where it could
3677 be from. Value is the buffer position or 0 if it couldn't be
3680 W's buffer must be current.
3682 This function is necessary because we don't record buffer positions
3683 in glyphs generated from strings (to keep struct glyph small).
3684 This function may only use code that doesn't eval because it is
3685 called asynchronously from note_mouse_highlight. */
3688 string_buffer_position (w
, string
, around_charpos
)
3693 Lisp_Object limit
, prop
, pos
;
3694 const int MAX_DISTANCE
= 1000;
3697 pos
= make_number (around_charpos
);
3698 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3699 while (!found
&& !EQ (pos
, limit
))
3701 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3702 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3705 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3710 pos
= make_number (around_charpos
);
3711 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3712 while (!found
&& !EQ (pos
, limit
))
3714 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3715 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3718 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3723 return found
? XINT (pos
) : 0;
3728 /***********************************************************************
3729 `composition' property
3730 ***********************************************************************/
3732 /* Set up iterator IT from `composition' property at its current
3733 position. Called from handle_stop. */
3735 static enum prop_handled
3736 handle_composition_prop (it
)
3739 Lisp_Object prop
, string
;
3740 int pos
, pos_byte
, end
;
3741 enum prop_handled handled
= HANDLED_NORMALLY
;
3743 if (STRINGP (it
->string
))
3745 pos
= IT_STRING_CHARPOS (*it
);
3746 pos_byte
= IT_STRING_BYTEPOS (*it
);
3747 string
= it
->string
;
3751 pos
= IT_CHARPOS (*it
);
3752 pos_byte
= IT_BYTEPOS (*it
);
3756 /* If there's a valid composition and point is not inside of the
3757 composition (in the case that the composition is from the current
3758 buffer), draw a glyph composed from the composition components. */
3759 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3760 && COMPOSITION_VALID_P (pos
, end
, prop
)
3761 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3763 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3767 it
->method
= next_element_from_composition
;
3769 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3770 /* For a terminal, draw only the first character of the
3772 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3773 it
->len
= (STRINGP (it
->string
)
3774 ? string_char_to_byte (it
->string
, end
)
3775 : CHAR_TO_BYTE (end
)) - pos_byte
;
3776 it
->stop_charpos
= end
;
3777 handled
= HANDLED_RETURN
;
3786 /***********************************************************************
3788 ***********************************************************************/
3790 /* The following structure is used to record overlay strings for
3791 later sorting in load_overlay_strings. */
3793 struct overlay_entry
3795 Lisp_Object overlay
;
3802 /* Set up iterator IT from overlay strings at its current position.
3803 Called from handle_stop. */
3805 static enum prop_handled
3806 handle_overlay_change (it
)
3809 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3810 return HANDLED_RECOMPUTE_PROPS
;
3812 return HANDLED_NORMALLY
;
3816 /* Set up the next overlay string for delivery by IT, if there is an
3817 overlay string to deliver. Called by set_iterator_to_next when the
3818 end of the current overlay string is reached. If there are more
3819 overlay strings to display, IT->string and
3820 IT->current.overlay_string_index are set appropriately here.
3821 Otherwise IT->string is set to nil. */
3824 next_overlay_string (it
)
3827 ++it
->current
.overlay_string_index
;
3828 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3830 /* No more overlay strings. Restore IT's settings to what
3831 they were before overlay strings were processed, and
3832 continue to deliver from current_buffer. */
3833 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3836 xassert (it
->stop_charpos
>= BEGV
3837 && it
->stop_charpos
<= it
->end_charpos
);
3839 it
->current
.overlay_string_index
= -1;
3840 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3841 it
->n_overlay_strings
= 0;
3842 it
->method
= next_element_from_buffer
;
3844 /* If we're at the end of the buffer, record that we have
3845 processed the overlay strings there already, so that
3846 next_element_from_buffer doesn't try it again. */
3847 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3848 it
->overlay_strings_at_end_processed_p
= 1;
3850 /* If we have to display `...' for invisible text, set
3851 the iterator up for that. */
3852 if (display_ellipsis_p
)
3853 setup_for_ellipsis (it
);
3857 /* There are more overlay strings to process. If
3858 IT->current.overlay_string_index has advanced to a position
3859 where we must load IT->overlay_strings with more strings, do
3861 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3863 if (it
->current
.overlay_string_index
&& i
== 0)
3864 load_overlay_strings (it
, 0);
3866 /* Initialize IT to deliver display elements from the overlay
3868 it
->string
= it
->overlay_strings
[i
];
3869 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3870 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3871 it
->method
= next_element_from_string
;
3872 it
->stop_charpos
= 0;
3879 /* Compare two overlay_entry structures E1 and E2. Used as a
3880 comparison function for qsort in load_overlay_strings. Overlay
3881 strings for the same position are sorted so that
3883 1. All after-strings come in front of before-strings, except
3884 when they come from the same overlay.
3886 2. Within after-strings, strings are sorted so that overlay strings
3887 from overlays with higher priorities come first.
3889 2. Within before-strings, strings are sorted so that overlay
3890 strings from overlays with higher priorities come last.
3892 Value is analogous to strcmp. */
3896 compare_overlay_entries (e1
, e2
)
3899 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3900 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3903 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3905 /* Let after-strings appear in front of before-strings if
3906 they come from different overlays. */
3907 if (EQ (entry1
->overlay
, entry2
->overlay
))
3908 result
= entry1
->after_string_p
? 1 : -1;
3910 result
= entry1
->after_string_p
? -1 : 1;
3912 else if (entry1
->after_string_p
)
3913 /* After-strings sorted in order of decreasing priority. */
3914 result
= entry2
->priority
- entry1
->priority
;
3916 /* Before-strings sorted in order of increasing priority. */
3917 result
= entry1
->priority
- entry2
->priority
;
3923 /* Load the vector IT->overlay_strings with overlay strings from IT's
3924 current buffer position, or from CHARPOS if that is > 0. Set
3925 IT->n_overlays to the total number of overlay strings found.
3927 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3928 a time. On entry into load_overlay_strings,
3929 IT->current.overlay_string_index gives the number of overlay
3930 strings that have already been loaded by previous calls to this
3933 IT->add_overlay_start contains an additional overlay start
3934 position to consider for taking overlay strings from, if non-zero.
3935 This position comes into play when the overlay has an `invisible'
3936 property, and both before and after-strings. When we've skipped to
3937 the end of the overlay, because of its `invisible' property, we
3938 nevertheless want its before-string to appear.
3939 IT->add_overlay_start will contain the overlay start position
3942 Overlay strings are sorted so that after-string strings come in
3943 front of before-string strings. Within before and after-strings,
3944 strings are sorted by overlay priority. See also function
3945 compare_overlay_entries. */
3948 load_overlay_strings (it
, charpos
)
3952 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3953 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3956 int n
= 0, i
, j
, invis_p
;
3957 struct overlay_entry
*entries
3958 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3961 charpos
= IT_CHARPOS (*it
);
3963 /* Append the overlay string STRING of overlay OVERLAY to vector
3964 `entries' which has size `size' and currently contains `n'
3965 elements. AFTER_P non-zero means STRING is an after-string of
3967 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
3970 Lisp_Object priority; \
3974 int new_size = 2 * size; \
3975 struct overlay_entry *old = entries; \
3977 (struct overlay_entry *) alloca (new_size \
3978 * sizeof *entries); \
3979 bcopy (old, entries, size * sizeof *entries); \
3983 entries[n].string = (STRING); \
3984 entries[n].overlay = (OVERLAY); \
3985 priority = Foverlay_get ((OVERLAY), Qpriority); \
3986 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
3987 entries[n].after_string_p = (AFTER_P); \
3992 /* Process overlay before the overlay center. */
3993 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
3995 overlay
= XCAR (ov
);
3996 xassert (OVERLAYP (overlay
));
3997 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
3998 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4003 /* Skip this overlay if it doesn't start or end at IT's current
4005 if (end
!= charpos
&& start
!= charpos
)
4008 /* Skip this overlay if it doesn't apply to IT->w. */
4009 window
= Foverlay_get (overlay
, Qwindow
);
4010 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4013 /* If the text ``under'' the overlay is invisible, both before-
4014 and after-strings from this overlay are visible; start and
4015 end position are indistinguishable. */
4016 invisible
= Foverlay_get (overlay
, Qinvisible
);
4017 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4019 /* If overlay has a non-empty before-string, record it. */
4020 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4021 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4023 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4025 /* If overlay has a non-empty after-string, record it. */
4026 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4027 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4029 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4032 /* Process overlays after the overlay center. */
4033 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
4035 overlay
= XCAR (ov
);
4036 xassert (OVERLAYP (overlay
));
4037 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4038 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4040 if (start
> charpos
)
4043 /* Skip this overlay if it doesn't start or end at IT's current
4045 if (end
!= charpos
&& start
!= charpos
)
4048 /* Skip this overlay if it doesn't apply to IT->w. */
4049 window
= Foverlay_get (overlay
, Qwindow
);
4050 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4053 /* If the text ``under'' the overlay is invisible, it has a zero
4054 dimension, and both before- and after-strings apply. */
4055 invisible
= Foverlay_get (overlay
, Qinvisible
);
4056 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4058 /* If overlay has a non-empty before-string, record it. */
4059 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4060 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4062 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4064 /* If overlay has a non-empty after-string, record it. */
4065 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4066 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4068 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4071 #undef RECORD_OVERLAY_STRING
4075 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4077 /* Record the total number of strings to process. */
4078 it
->n_overlay_strings
= n
;
4080 /* IT->current.overlay_string_index is the number of overlay strings
4081 that have already been consumed by IT. Copy some of the
4082 remaining overlay strings to IT->overlay_strings. */
4084 j
= it
->current
.overlay_string_index
;
4085 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4086 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4092 /* Get the first chunk of overlay strings at IT's current buffer
4093 position, or at CHARPOS if that is > 0. Value is non-zero if at
4094 least one overlay string was found. */
4097 get_overlay_strings (it
, charpos
)
4101 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4102 process. This fills IT->overlay_strings with strings, and sets
4103 IT->n_overlay_strings to the total number of strings to process.
4104 IT->pos.overlay_string_index has to be set temporarily to zero
4105 because load_overlay_strings needs this; it must be set to -1
4106 when no overlay strings are found because a zero value would
4107 indicate a position in the first overlay string. */
4108 it
->current
.overlay_string_index
= 0;
4109 load_overlay_strings (it
, charpos
);
4111 /* If we found overlay strings, set up IT to deliver display
4112 elements from the first one. Otherwise set up IT to deliver
4113 from current_buffer. */
4114 if (it
->n_overlay_strings
)
4116 /* Make sure we know settings in current_buffer, so that we can
4117 restore meaningful values when we're done with the overlay
4119 compute_stop_pos (it
);
4120 xassert (it
->face_id
>= 0);
4122 /* Save IT's settings. They are restored after all overlay
4123 strings have been processed. */
4124 xassert (it
->sp
== 0);
4127 /* Set up IT to deliver display elements from the first overlay
4129 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4130 it
->string
= it
->overlay_strings
[0];
4131 it
->stop_charpos
= 0;
4132 xassert (STRINGP (it
->string
));
4133 it
->end_charpos
= SCHARS (it
->string
);
4134 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4135 it
->method
= next_element_from_string
;
4140 it
->current
.overlay_string_index
= -1;
4141 it
->method
= next_element_from_buffer
;
4146 /* Value is non-zero if we found at least one overlay string. */
4147 return STRINGP (it
->string
);
4152 /***********************************************************************
4153 Saving and restoring state
4154 ***********************************************************************/
4156 /* Save current settings of IT on IT->stack. Called, for example,
4157 before setting up IT for an overlay string, to be able to restore
4158 IT's settings to what they were after the overlay string has been
4165 struct iterator_stack_entry
*p
;
4167 xassert (it
->sp
< 2);
4168 p
= it
->stack
+ it
->sp
;
4170 p
->stop_charpos
= it
->stop_charpos
;
4171 xassert (it
->face_id
>= 0);
4172 p
->face_id
= it
->face_id
;
4173 p
->string
= it
->string
;
4174 p
->pos
= it
->current
;
4175 p
->end_charpos
= it
->end_charpos
;
4176 p
->string_nchars
= it
->string_nchars
;
4178 p
->multibyte_p
= it
->multibyte_p
;
4179 p
->space_width
= it
->space_width
;
4180 p
->font_height
= it
->font_height
;
4181 p
->voffset
= it
->voffset
;
4182 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4183 p
->display_ellipsis_p
= 0;
4188 /* Restore IT's settings from IT->stack. Called, for example, when no
4189 more overlay strings must be processed, and we return to delivering
4190 display elements from a buffer, or when the end of a string from a
4191 `display' property is reached and we return to delivering display
4192 elements from an overlay string, or from a buffer. */
4198 struct iterator_stack_entry
*p
;
4200 xassert (it
->sp
> 0);
4202 p
= it
->stack
+ it
->sp
;
4203 it
->stop_charpos
= p
->stop_charpos
;
4204 it
->face_id
= p
->face_id
;
4205 it
->string
= p
->string
;
4206 it
->current
= p
->pos
;
4207 it
->end_charpos
= p
->end_charpos
;
4208 it
->string_nchars
= p
->string_nchars
;
4210 it
->multibyte_p
= p
->multibyte_p
;
4211 it
->space_width
= p
->space_width
;
4212 it
->font_height
= p
->font_height
;
4213 it
->voffset
= p
->voffset
;
4214 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4219 /***********************************************************************
4221 ***********************************************************************/
4223 /* Set IT's current position to the previous line start. */
4226 back_to_previous_line_start (it
)
4229 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4230 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4234 /* Move IT to the next line start.
4236 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4237 we skipped over part of the text (as opposed to moving the iterator
4238 continuously over the text). Otherwise, don't change the value
4241 Newlines may come from buffer text, overlay strings, or strings
4242 displayed via the `display' property. That's the reason we can't
4243 simply use find_next_newline_no_quit.
4245 Note that this function may not skip over invisible text that is so
4246 because of text properties and immediately follows a newline. If
4247 it would, function reseat_at_next_visible_line_start, when called
4248 from set_iterator_to_next, would effectively make invisible
4249 characters following a newline part of the wrong glyph row, which
4250 leads to wrong cursor motion. */
4253 forward_to_next_line_start (it
, skipped_p
)
4257 int old_selective
, newline_found_p
, n
;
4258 const int MAX_NEWLINE_DISTANCE
= 500;
4260 /* If already on a newline, just consume it to avoid unintended
4261 skipping over invisible text below. */
4262 if (it
->what
== IT_CHARACTER
4264 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4266 set_iterator_to_next (it
, 0);
4271 /* Don't handle selective display in the following. It's (a)
4272 unnecessary because it's done by the caller, and (b) leads to an
4273 infinite recursion because next_element_from_ellipsis indirectly
4274 calls this function. */
4275 old_selective
= it
->selective
;
4278 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4279 from buffer text. */
4280 for (n
= newline_found_p
= 0;
4281 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4282 n
+= STRINGP (it
->string
) ? 0 : 1)
4284 if (!get_next_display_element (it
))
4286 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4287 set_iterator_to_next (it
, 0);
4290 /* If we didn't find a newline near enough, see if we can use a
4292 if (!newline_found_p
)
4294 int start
= IT_CHARPOS (*it
);
4295 int limit
= find_next_newline_no_quit (start
, 1);
4298 xassert (!STRINGP (it
->string
));
4300 /* If there isn't any `display' property in sight, and no
4301 overlays, we can just use the position of the newline in
4303 if (it
->stop_charpos
>= limit
4304 || ((pos
= Fnext_single_property_change (make_number (start
),
4306 Qnil
, make_number (limit
)),
4308 && next_overlay_change (start
) == ZV
))
4310 IT_CHARPOS (*it
) = limit
;
4311 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4312 *skipped_p
= newline_found_p
= 1;
4316 while (get_next_display_element (it
)
4317 && !newline_found_p
)
4319 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4320 set_iterator_to_next (it
, 0);
4325 it
->selective
= old_selective
;
4326 return newline_found_p
;
4330 /* Set IT's current position to the previous visible line start. Skip
4331 invisible text that is so either due to text properties or due to
4332 selective display. Caution: this does not change IT->current_x and
4336 back_to_previous_visible_line_start (it
)
4341 /* Go back one newline if not on BEGV already. */
4342 if (IT_CHARPOS (*it
) > BEGV
)
4343 back_to_previous_line_start (it
);
4345 /* Move over lines that are invisible because of selective display
4346 or text properties. */
4347 while (IT_CHARPOS (*it
) > BEGV
4352 /* If selective > 0, then lines indented more than that values
4354 if (it
->selective
> 0
4355 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4356 (double) it
->selective
)) /* iftc */
4362 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
4363 Qinvisible
, it
->window
);
4364 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4368 /* Back one more newline if the current one is invisible. */
4370 back_to_previous_line_start (it
);
4373 xassert (IT_CHARPOS (*it
) >= BEGV
);
4374 xassert (IT_CHARPOS (*it
) == BEGV
4375 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4380 /* Reseat iterator IT at the previous visible line start. Skip
4381 invisible text that is so either due to text properties or due to
4382 selective display. At the end, update IT's overlay information,
4383 face information etc. */
4386 reseat_at_previous_visible_line_start (it
)
4389 back_to_previous_visible_line_start (it
);
4390 reseat (it
, it
->current
.pos
, 1);
4395 /* Reseat iterator IT on the next visible line start in the current
4396 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4397 preceding the line start. Skip over invisible text that is so
4398 because of selective display. Compute faces, overlays etc at the
4399 new position. Note that this function does not skip over text that
4400 is invisible because of text properties. */
4403 reseat_at_next_visible_line_start (it
, on_newline_p
)
4407 int newline_found_p
, skipped_p
= 0;
4409 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4411 /* Skip over lines that are invisible because they are indented
4412 more than the value of IT->selective. */
4413 if (it
->selective
> 0)
4414 while (IT_CHARPOS (*it
) < ZV
4415 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4416 (double) it
->selective
)) /* iftc */
4418 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4419 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4422 /* Position on the newline if that's what's requested. */
4423 if (on_newline_p
&& newline_found_p
)
4425 if (STRINGP (it
->string
))
4427 if (IT_STRING_CHARPOS (*it
) > 0)
4429 --IT_STRING_CHARPOS (*it
);
4430 --IT_STRING_BYTEPOS (*it
);
4433 else if (IT_CHARPOS (*it
) > BEGV
)
4437 reseat (it
, it
->current
.pos
, 0);
4441 reseat (it
, it
->current
.pos
, 0);
4448 /***********************************************************************
4449 Changing an iterator's position
4450 ***********************************************************************/
4452 /* Change IT's current position to POS in current_buffer. If FORCE_P
4453 is non-zero, always check for text properties at the new position.
4454 Otherwise, text properties are only looked up if POS >=
4455 IT->check_charpos of a property. */
4458 reseat (it
, pos
, force_p
)
4460 struct text_pos pos
;
4463 int original_pos
= IT_CHARPOS (*it
);
4465 reseat_1 (it
, pos
, 0);
4467 /* Determine where to check text properties. Avoid doing it
4468 where possible because text property lookup is very expensive. */
4470 || CHARPOS (pos
) > it
->stop_charpos
4471 || CHARPOS (pos
) < original_pos
)
4478 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4479 IT->stop_pos to POS, also. */
4482 reseat_1 (it
, pos
, set_stop_p
)
4484 struct text_pos pos
;
4487 /* Don't call this function when scanning a C string. */
4488 xassert (it
->s
== NULL
);
4490 /* POS must be a reasonable value. */
4491 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4493 it
->current
.pos
= it
->position
= pos
;
4494 XSETBUFFER (it
->object
, current_buffer
);
4495 it
->end_charpos
= ZV
;
4497 it
->current
.dpvec_index
= -1;
4498 it
->current
.overlay_string_index
= -1;
4499 IT_STRING_CHARPOS (*it
) = -1;
4500 IT_STRING_BYTEPOS (*it
) = -1;
4502 it
->method
= next_element_from_buffer
;
4503 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4505 it
->face_before_selective_p
= 0;
4508 it
->stop_charpos
= CHARPOS (pos
);
4512 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4513 If S is non-null, it is a C string to iterate over. Otherwise,
4514 STRING gives a Lisp string to iterate over.
4516 If PRECISION > 0, don't return more then PRECISION number of
4517 characters from the string.
4519 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4520 characters have been returned. FIELD_WIDTH < 0 means an infinite
4523 MULTIBYTE = 0 means disable processing of multibyte characters,
4524 MULTIBYTE > 0 means enable it,
4525 MULTIBYTE < 0 means use IT->multibyte_p.
4527 IT must be initialized via a prior call to init_iterator before
4528 calling this function. */
4531 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4536 int precision
, field_width
, multibyte
;
4538 /* No region in strings. */
4539 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4541 /* No text property checks performed by default, but see below. */
4542 it
->stop_charpos
= -1;
4544 /* Set iterator position and end position. */
4545 bzero (&it
->current
, sizeof it
->current
);
4546 it
->current
.overlay_string_index
= -1;
4547 it
->current
.dpvec_index
= -1;
4548 xassert (charpos
>= 0);
4550 /* If STRING is specified, use its multibyteness, otherwise use the
4551 setting of MULTIBYTE, if specified. */
4553 it
->multibyte_p
= multibyte
> 0;
4557 xassert (STRINGP (string
));
4558 it
->string
= string
;
4560 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4561 it
->method
= next_element_from_string
;
4562 it
->current
.string_pos
= string_pos (charpos
, string
);
4569 /* Note that we use IT->current.pos, not it->current.string_pos,
4570 for displaying C strings. */
4571 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4572 if (it
->multibyte_p
)
4574 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4575 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4579 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4580 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4583 it
->method
= next_element_from_c_string
;
4586 /* PRECISION > 0 means don't return more than PRECISION characters
4588 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4589 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4591 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4592 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4593 FIELD_WIDTH < 0 means infinite field width. This is useful for
4594 padding with `-' at the end of a mode line. */
4595 if (field_width
< 0)
4596 field_width
= INFINITY
;
4597 if (field_width
> it
->end_charpos
- charpos
)
4598 it
->end_charpos
= charpos
+ field_width
;
4600 /* Use the standard display table for displaying strings. */
4601 if (DISP_TABLE_P (Vstandard_display_table
))
4602 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4604 it
->stop_charpos
= charpos
;
4610 /***********************************************************************
4612 ***********************************************************************/
4614 /* Load IT's display element fields with information about the next
4615 display element from the current position of IT. Value is zero if
4616 end of buffer (or C string) is reached. */
4619 get_next_display_element (it
)
4622 /* Non-zero means that we found a display element. Zero means that
4623 we hit the end of what we iterate over. Performance note: the
4624 function pointer `method' used here turns out to be faster than
4625 using a sequence of if-statements. */
4626 int success_p
= (*it
->method
) (it
);
4628 if (it
->what
== IT_CHARACTER
)
4630 /* Map via display table or translate control characters.
4631 IT->c, IT->len etc. have been set to the next character by
4632 the function call above. If we have a display table, and it
4633 contains an entry for IT->c, translate it. Don't do this if
4634 IT->c itself comes from a display table, otherwise we could
4635 end up in an infinite recursion. (An alternative could be to
4636 count the recursion depth of this function and signal an
4637 error when a certain maximum depth is reached.) Is it worth
4639 if (success_p
&& it
->dpvec
== NULL
)
4644 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4647 struct Lisp_Vector
*v
= XVECTOR (dv
);
4649 /* Return the first character from the display table
4650 entry, if not empty. If empty, don't display the
4651 current character. */
4654 it
->dpvec_char_len
= it
->len
;
4655 it
->dpvec
= v
->contents
;
4656 it
->dpend
= v
->contents
+ v
->size
;
4657 it
->current
.dpvec_index
= 0;
4658 it
->method
= next_element_from_display_vector
;
4659 success_p
= get_next_display_element (it
);
4663 set_iterator_to_next (it
, 0);
4664 success_p
= get_next_display_element (it
);
4668 /* Translate control characters into `\003' or `^C' form.
4669 Control characters coming from a display table entry are
4670 currently not translated because we use IT->dpvec to hold
4671 the translation. This could easily be changed but I
4672 don't believe that it is worth doing.
4674 If it->multibyte_p is nonzero, eight-bit characters and
4675 non-printable multibyte characters are also translated to
4678 If it->multibyte_p is zero, eight-bit characters that
4679 don't have corresponding multibyte char code are also
4680 translated to octal form. */
4681 else if ((it
->c
< ' '
4682 && (it
->area
!= TEXT_AREA
4683 || (it
->c
!= '\n' && it
->c
!= '\t')))
4687 || !CHAR_PRINTABLE_P (it
->c
))
4689 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4691 /* IT->c is a control character which must be displayed
4692 either as '\003' or as `^C' where the '\\' and '^'
4693 can be defined in the display table. Fill
4694 IT->ctl_chars with glyphs for what we have to
4695 display. Then, set IT->dpvec to these glyphs. */
4698 if (it
->c
< 128 && it
->ctl_arrow_p
)
4700 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4702 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4703 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4704 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4706 g
= FAST_MAKE_GLYPH ('^', 0);
4707 XSETINT (it
->ctl_chars
[0], g
);
4709 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4710 XSETINT (it
->ctl_chars
[1], g
);
4712 /* Set up IT->dpvec and return first character from it. */
4713 it
->dpvec_char_len
= it
->len
;
4714 it
->dpvec
= it
->ctl_chars
;
4715 it
->dpend
= it
->dpvec
+ 2;
4716 it
->current
.dpvec_index
= 0;
4717 it
->method
= next_element_from_display_vector
;
4718 get_next_display_element (it
);
4722 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4727 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4729 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4730 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4731 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4733 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4735 if (SINGLE_BYTE_CHAR_P (it
->c
))
4736 str
[0] = it
->c
, len
= 1;
4739 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4742 /* It's an invalid character, which
4743 shouldn't happen actually, but due to
4744 bugs it may happen. Let's print the char
4745 as is, there's not much meaningful we can
4748 str
[1] = it
->c
>> 8;
4749 str
[2] = it
->c
>> 16;
4750 str
[3] = it
->c
>> 24;
4755 for (i
= 0; i
< len
; i
++)
4757 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4758 /* Insert three more glyphs into IT->ctl_chars for
4759 the octal display of the character. */
4760 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4761 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4762 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4763 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4764 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4765 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4768 /* Set up IT->dpvec and return the first character
4770 it
->dpvec_char_len
= it
->len
;
4771 it
->dpvec
= it
->ctl_chars
;
4772 it
->dpend
= it
->dpvec
+ len
* 4;
4773 it
->current
.dpvec_index
= 0;
4774 it
->method
= next_element_from_display_vector
;
4775 get_next_display_element (it
);
4780 /* Adjust face id for a multibyte character. There are no
4781 multibyte character in unibyte text. */
4784 && FRAME_WINDOW_P (it
->f
))
4786 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4787 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4791 /* Is this character the last one of a run of characters with
4792 box? If yes, set IT->end_of_box_run_p to 1. */
4799 it
->end_of_box_run_p
4800 = ((face_id
= face_after_it_pos (it
),
4801 face_id
!= it
->face_id
)
4802 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4803 face
->box
== FACE_NO_BOX
));
4806 /* Value is 0 if end of buffer or string reached. */
4811 /* Move IT to the next display element.
4813 RESEAT_P non-zero means if called on a newline in buffer text,
4814 skip to the next visible line start.
4816 Functions get_next_display_element and set_iterator_to_next are
4817 separate because I find this arrangement easier to handle than a
4818 get_next_display_element function that also increments IT's
4819 position. The way it is we can first look at an iterator's current
4820 display element, decide whether it fits on a line, and if it does,
4821 increment the iterator position. The other way around we probably
4822 would either need a flag indicating whether the iterator has to be
4823 incremented the next time, or we would have to implement a
4824 decrement position function which would not be easy to write. */
4827 set_iterator_to_next (it
, reseat_p
)
4831 /* Reset flags indicating start and end of a sequence of characters
4832 with box. Reset them at the start of this function because
4833 moving the iterator to a new position might set them. */
4834 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4836 if (it
->method
== next_element_from_buffer
)
4838 /* The current display element of IT is a character from
4839 current_buffer. Advance in the buffer, and maybe skip over
4840 invisible lines that are so because of selective display. */
4841 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4842 reseat_at_next_visible_line_start (it
, 0);
4845 xassert (it
->len
!= 0);
4846 IT_BYTEPOS (*it
) += it
->len
;
4847 IT_CHARPOS (*it
) += 1;
4848 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4851 else if (it
->method
== next_element_from_composition
)
4853 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4854 if (STRINGP (it
->string
))
4856 IT_STRING_BYTEPOS (*it
) += it
->len
;
4857 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4858 it
->method
= next_element_from_string
;
4859 goto consider_string_end
;
4863 IT_BYTEPOS (*it
) += it
->len
;
4864 IT_CHARPOS (*it
) += it
->cmp_len
;
4865 it
->method
= next_element_from_buffer
;
4868 else if (it
->method
== next_element_from_c_string
)
4870 /* Current display element of IT is from a C string. */
4871 IT_BYTEPOS (*it
) += it
->len
;
4872 IT_CHARPOS (*it
) += 1;
4874 else if (it
->method
== next_element_from_display_vector
)
4876 /* Current display element of IT is from a display table entry.
4877 Advance in the display table definition. Reset it to null if
4878 end reached, and continue with characters from buffers/
4880 ++it
->current
.dpvec_index
;
4882 /* Restore face of the iterator to what they were before the
4883 display vector entry (these entries may contain faces). */
4884 it
->face_id
= it
->saved_face_id
;
4886 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4889 it
->method
= next_element_from_c_string
;
4890 else if (STRINGP (it
->string
))
4891 it
->method
= next_element_from_string
;
4893 it
->method
= next_element_from_buffer
;
4896 it
->current
.dpvec_index
= -1;
4898 /* Skip over characters which were displayed via IT->dpvec. */
4899 if (it
->dpvec_char_len
< 0)
4900 reseat_at_next_visible_line_start (it
, 1);
4901 else if (it
->dpvec_char_len
> 0)
4903 it
->len
= it
->dpvec_char_len
;
4904 set_iterator_to_next (it
, reseat_p
);
4908 else if (it
->method
== next_element_from_string
)
4910 /* Current display element is a character from a Lisp string. */
4911 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4912 IT_STRING_BYTEPOS (*it
) += it
->len
;
4913 IT_STRING_CHARPOS (*it
) += 1;
4915 consider_string_end
:
4917 if (it
->current
.overlay_string_index
>= 0)
4919 /* IT->string is an overlay string. Advance to the
4920 next, if there is one. */
4921 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4922 next_overlay_string (it
);
4926 /* IT->string is not an overlay string. If we reached
4927 its end, and there is something on IT->stack, proceed
4928 with what is on the stack. This can be either another
4929 string, this time an overlay string, or a buffer. */
4930 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
4934 if (!STRINGP (it
->string
))
4935 it
->method
= next_element_from_buffer
;
4937 goto consider_string_end
;
4941 else if (it
->method
== next_element_from_image
4942 || it
->method
== next_element_from_stretch
)
4944 /* The position etc with which we have to proceed are on
4945 the stack. The position may be at the end of a string,
4946 if the `display' property takes up the whole string. */
4949 if (STRINGP (it
->string
))
4951 it
->method
= next_element_from_string
;
4952 goto consider_string_end
;
4955 it
->method
= next_element_from_buffer
;
4958 /* There are no other methods defined, so this should be a bug. */
4961 xassert (it
->method
!= next_element_from_string
4962 || (STRINGP (it
->string
)
4963 && IT_STRING_CHARPOS (*it
) >= 0));
4967 /* Load IT's display element fields with information about the next
4968 display element which comes from a display table entry or from the
4969 result of translating a control character to one of the forms `^C'
4970 or `\003'. IT->dpvec holds the glyphs to return as characters. */
4973 next_element_from_display_vector (it
)
4977 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
4979 /* Remember the current face id in case glyphs specify faces.
4980 IT's face is restored in set_iterator_to_next. */
4981 it
->saved_face_id
= it
->face_id
;
4983 if (INTEGERP (*it
->dpvec
)
4984 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
4989 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
4990 it
->c
= FAST_GLYPH_CHAR (g
);
4991 it
->len
= CHAR_BYTES (it
->c
);
4993 /* The entry may contain a face id to use. Such a face id is
4994 the id of a Lisp face, not a realized face. A face id of
4995 zero means no face is specified. */
4996 lface_id
= FAST_GLYPH_FACE (g
);
4999 /* The function returns -1 if lface_id is invalid. */
5000 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
5002 it
->face_id
= face_id
;
5006 /* Display table entry is invalid. Return a space. */
5007 it
->c
= ' ', it
->len
= 1;
5009 /* Don't change position and object of the iterator here. They are
5010 still the values of the character that had this display table
5011 entry or was translated, and that's what we want. */
5012 it
->what
= IT_CHARACTER
;
5017 /* Load IT with the next display element from Lisp string IT->string.
5018 IT->current.string_pos is the current position within the string.
5019 If IT->current.overlay_string_index >= 0, the Lisp string is an
5023 next_element_from_string (it
)
5026 struct text_pos position
;
5028 xassert (STRINGP (it
->string
));
5029 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5030 position
= it
->current
.string_pos
;
5032 /* Time to check for invisible text? */
5033 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5034 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5038 /* Since a handler may have changed IT->method, we must
5040 return get_next_display_element (it
);
5043 if (it
->current
.overlay_string_index
>= 0)
5045 /* Get the next character from an overlay string. In overlay
5046 strings, There is no field width or padding with spaces to
5048 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5053 else if (STRING_MULTIBYTE (it
->string
))
5055 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5056 const unsigned char *s
= (SDATA (it
->string
)
5057 + IT_STRING_BYTEPOS (*it
));
5058 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5062 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5068 /* Get the next character from a Lisp string that is not an
5069 overlay string. Such strings come from the mode line, for
5070 example. We may have to pad with spaces, or truncate the
5071 string. See also next_element_from_c_string. */
5072 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5077 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5079 /* Pad with spaces. */
5080 it
->c
= ' ', it
->len
= 1;
5081 CHARPOS (position
) = BYTEPOS (position
) = -1;
5083 else if (STRING_MULTIBYTE (it
->string
))
5085 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5086 const unsigned char *s
= (SDATA (it
->string
)
5087 + IT_STRING_BYTEPOS (*it
));
5088 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5092 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5097 /* Record what we have and where it came from. Note that we store a
5098 buffer position in IT->position although it could arguably be a
5100 it
->what
= IT_CHARACTER
;
5101 it
->object
= it
->string
;
5102 it
->position
= position
;
5107 /* Load IT with next display element from C string IT->s.
5108 IT->string_nchars is the maximum number of characters to return
5109 from the string. IT->end_charpos may be greater than
5110 IT->string_nchars when this function is called, in which case we
5111 may have to return padding spaces. Value is zero if end of string
5112 reached, including padding spaces. */
5115 next_element_from_c_string (it
)
5121 it
->what
= IT_CHARACTER
;
5122 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5125 /* IT's position can be greater IT->string_nchars in case a field
5126 width or precision has been specified when the iterator was
5128 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5130 /* End of the game. */
5134 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5136 /* Pad with spaces. */
5137 it
->c
= ' ', it
->len
= 1;
5138 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5140 else if (it
->multibyte_p
)
5142 /* Implementation note: The calls to strlen apparently aren't a
5143 performance problem because there is no noticeable performance
5144 difference between Emacs running in unibyte or multibyte mode. */
5145 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5146 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5150 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5156 /* Set up IT to return characters from an ellipsis, if appropriate.
5157 The definition of the ellipsis glyphs may come from a display table
5158 entry. This function Fills IT with the first glyph from the
5159 ellipsis if an ellipsis is to be displayed. */
5162 next_element_from_ellipsis (it
)
5165 if (it
->selective_display_ellipsis_p
)
5167 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
5169 /* Use the display table definition for `...'. Invalid glyphs
5170 will be handled by the method returning elements from dpvec. */
5171 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
5172 it
->dpvec_char_len
= it
->len
;
5173 it
->dpvec
= v
->contents
;
5174 it
->dpend
= v
->contents
+ v
->size
;
5175 it
->current
.dpvec_index
= 0;
5176 it
->method
= next_element_from_display_vector
;
5180 /* Use default `...' which is stored in default_invis_vector. */
5181 it
->dpvec_char_len
= it
->len
;
5182 it
->dpvec
= default_invis_vector
;
5183 it
->dpend
= default_invis_vector
+ 3;
5184 it
->current
.dpvec_index
= 0;
5185 it
->method
= next_element_from_display_vector
;
5190 /* The face at the current position may be different from the
5191 face we find after the invisible text. Remember what it
5192 was in IT->saved_face_id, and signal that it's there by
5193 setting face_before_selective_p. */
5194 it
->saved_face_id
= it
->face_id
;
5195 it
->method
= next_element_from_buffer
;
5196 reseat_at_next_visible_line_start (it
, 1);
5197 it
->face_before_selective_p
= 1;
5200 return get_next_display_element (it
);
5204 /* Deliver an image display element. The iterator IT is already
5205 filled with image information (done in handle_display_prop). Value
5210 next_element_from_image (it
)
5213 it
->what
= IT_IMAGE
;
5218 /* Fill iterator IT with next display element from a stretch glyph
5219 property. IT->object is the value of the text property. Value is
5223 next_element_from_stretch (it
)
5226 it
->what
= IT_STRETCH
;
5231 /* Load IT with the next display element from current_buffer. Value
5232 is zero if end of buffer reached. IT->stop_charpos is the next
5233 position at which to stop and check for text properties or buffer
5237 next_element_from_buffer (it
)
5242 /* Check this assumption, otherwise, we would never enter the
5243 if-statement, below. */
5244 xassert (IT_CHARPOS (*it
) >= BEGV
5245 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5247 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5249 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5251 int overlay_strings_follow_p
;
5253 /* End of the game, except when overlay strings follow that
5254 haven't been returned yet. */
5255 if (it
->overlay_strings_at_end_processed_p
)
5256 overlay_strings_follow_p
= 0;
5259 it
->overlay_strings_at_end_processed_p
= 1;
5260 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5263 if (overlay_strings_follow_p
)
5264 success_p
= get_next_display_element (it
);
5268 it
->position
= it
->current
.pos
;
5275 return get_next_display_element (it
);
5280 /* No face changes, overlays etc. in sight, so just return a
5281 character from current_buffer. */
5284 /* Maybe run the redisplay end trigger hook. Performance note:
5285 This doesn't seem to cost measurable time. */
5286 if (it
->redisplay_end_trigger_charpos
5288 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5289 run_redisplay_end_trigger_hook (it
);
5291 /* Get the next character, maybe multibyte. */
5292 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5293 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5295 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5296 - IT_BYTEPOS (*it
));
5297 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5300 it
->c
= *p
, it
->len
= 1;
5302 /* Record what we have and where it came from. */
5303 it
->what
= IT_CHARACTER
;;
5304 it
->object
= it
->w
->buffer
;
5305 it
->position
= it
->current
.pos
;
5307 /* Normally we return the character found above, except when we
5308 really want to return an ellipsis for selective display. */
5313 /* A value of selective > 0 means hide lines indented more
5314 than that number of columns. */
5315 if (it
->selective
> 0
5316 && IT_CHARPOS (*it
) + 1 < ZV
5317 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5318 IT_BYTEPOS (*it
) + 1,
5319 (double) it
->selective
)) /* iftc */
5321 success_p
= next_element_from_ellipsis (it
);
5322 it
->dpvec_char_len
= -1;
5325 else if (it
->c
== '\r' && it
->selective
== -1)
5327 /* A value of selective == -1 means that everything from the
5328 CR to the end of the line is invisible, with maybe an
5329 ellipsis displayed for it. */
5330 success_p
= next_element_from_ellipsis (it
);
5331 it
->dpvec_char_len
= -1;
5336 /* Value is zero if end of buffer reached. */
5337 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5342 /* Run the redisplay end trigger hook for IT. */
5345 run_redisplay_end_trigger_hook (it
)
5348 Lisp_Object args
[3];
5350 /* IT->glyph_row should be non-null, i.e. we should be actually
5351 displaying something, or otherwise we should not run the hook. */
5352 xassert (it
->glyph_row
);
5354 /* Set up hook arguments. */
5355 args
[0] = Qredisplay_end_trigger_functions
;
5356 args
[1] = it
->window
;
5357 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5358 it
->redisplay_end_trigger_charpos
= 0;
5360 /* Since we are *trying* to run these functions, don't try to run
5361 them again, even if they get an error. */
5362 it
->w
->redisplay_end_trigger
= Qnil
;
5363 Frun_hook_with_args (3, args
);
5365 /* Notice if it changed the face of the character we are on. */
5366 handle_face_prop (it
);
5370 /* Deliver a composition display element. The iterator IT is already
5371 filled with composition information (done in
5372 handle_composition_prop). Value is always 1. */
5375 next_element_from_composition (it
)
5378 it
->what
= IT_COMPOSITION
;
5379 it
->position
= (STRINGP (it
->string
)
5380 ? it
->current
.string_pos
5387 /***********************************************************************
5388 Moving an iterator without producing glyphs
5389 ***********************************************************************/
5391 /* Move iterator IT to a specified buffer or X position within one
5392 line on the display without producing glyphs.
5394 OP should be a bit mask including some or all of these bits:
5395 MOVE_TO_X: Stop on reaching x-position TO_X.
5396 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5397 Regardless of OP's value, stop in reaching the end of the display line.
5399 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5400 This means, in particular, that TO_X includes window's horizontal
5403 The return value has several possible values that
5404 say what condition caused the scan to stop:
5406 MOVE_POS_MATCH_OR_ZV
5407 - when TO_POS or ZV was reached.
5410 -when TO_X was reached before TO_POS or ZV were reached.
5413 - when we reached the end of the display area and the line must
5417 - when we reached the end of the display area and the line is
5421 - when we stopped at a line end, i.e. a newline or a CR and selective
5424 static enum move_it_result
5425 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5427 int to_charpos
, to_x
, op
;
5429 enum move_it_result result
= MOVE_UNDEFINED
;
5430 struct glyph_row
*saved_glyph_row
;
5432 /* Don't produce glyphs in produce_glyphs. */
5433 saved_glyph_row
= it
->glyph_row
;
5434 it
->glyph_row
= NULL
;
5438 int x
, i
, ascent
= 0, descent
= 0;
5440 /* Stop when ZV or TO_CHARPOS reached. */
5441 if (!get_next_display_element (it
)
5442 || ((op
& MOVE_TO_POS
) != 0
5443 && BUFFERP (it
->object
)
5444 && IT_CHARPOS (*it
) >= to_charpos
))
5446 result
= MOVE_POS_MATCH_OR_ZV
;
5450 /* The call to produce_glyphs will get the metrics of the
5451 display element IT is loaded with. We record in x the
5452 x-position before this display element in case it does not
5456 /* Remember the line height so far in case the next element doesn't
5458 if (!it
->truncate_lines_p
)
5460 ascent
= it
->max_ascent
;
5461 descent
= it
->max_descent
;
5464 PRODUCE_GLYPHS (it
);
5466 if (it
->area
!= TEXT_AREA
)
5468 set_iterator_to_next (it
, 1);
5472 /* The number of glyphs we get back in IT->nglyphs will normally
5473 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5474 character on a terminal frame, or (iii) a line end. For the
5475 second case, IT->nglyphs - 1 padding glyphs will be present
5476 (on X frames, there is only one glyph produced for a
5477 composite character.
5479 The behavior implemented below means, for continuation lines,
5480 that as many spaces of a TAB as fit on the current line are
5481 displayed there. For terminal frames, as many glyphs of a
5482 multi-glyph character are displayed in the current line, too.
5483 This is what the old redisplay code did, and we keep it that
5484 way. Under X, the whole shape of a complex character must
5485 fit on the line or it will be completely displayed in the
5488 Note that both for tabs and padding glyphs, all glyphs have
5492 /* More than one glyph or glyph doesn't fit on line. All
5493 glyphs have the same width. */
5494 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5497 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5499 new_x
= x
+ single_glyph_width
;
5501 /* We want to leave anything reaching TO_X to the caller. */
5502 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5505 result
= MOVE_X_REACHED
;
5508 else if (/* Lines are continued. */
5509 !it
->truncate_lines_p
5510 && (/* And glyph doesn't fit on the line. */
5511 new_x
> it
->last_visible_x
5512 /* Or it fits exactly and we're on a window
5514 || (new_x
== it
->last_visible_x
5515 && FRAME_WINDOW_P (it
->f
))))
5517 if (/* IT->hpos == 0 means the very first glyph
5518 doesn't fit on the line, e.g. a wide image. */
5520 || (new_x
== it
->last_visible_x
5521 && FRAME_WINDOW_P (it
->f
)))
5524 it
->current_x
= new_x
;
5525 if (i
== it
->nglyphs
- 1)
5526 set_iterator_to_next (it
, 1);
5531 it
->max_ascent
= ascent
;
5532 it
->max_descent
= descent
;
5535 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5537 result
= MOVE_LINE_CONTINUED
;
5540 else if (new_x
> it
->first_visible_x
)
5542 /* Glyph is visible. Increment number of glyphs that
5543 would be displayed. */
5548 /* Glyph is completely off the left margin of the display
5549 area. Nothing to do. */
5553 if (result
!= MOVE_UNDEFINED
)
5556 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5558 /* Stop when TO_X specified and reached. This check is
5559 necessary here because of lines consisting of a line end,
5560 only. The line end will not produce any glyphs and we
5561 would never get MOVE_X_REACHED. */
5562 xassert (it
->nglyphs
== 0);
5563 result
= MOVE_X_REACHED
;
5567 /* Is this a line end? If yes, we're done. */
5568 if (ITERATOR_AT_END_OF_LINE_P (it
))
5570 result
= MOVE_NEWLINE_OR_CR
;
5574 /* The current display element has been consumed. Advance
5576 set_iterator_to_next (it
, 1);
5578 /* Stop if lines are truncated and IT's current x-position is
5579 past the right edge of the window now. */
5580 if (it
->truncate_lines_p
5581 && it
->current_x
>= it
->last_visible_x
)
5583 result
= MOVE_LINE_TRUNCATED
;
5588 /* Restore the iterator settings altered at the beginning of this
5590 it
->glyph_row
= saved_glyph_row
;
5595 /* Move IT forward until it satisfies one or more of the criteria in
5596 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5598 OP is a bit-mask that specifies where to stop, and in particular,
5599 which of those four position arguments makes a difference. See the
5600 description of enum move_operation_enum.
5602 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5603 screen line, this function will set IT to the next position >
5607 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5609 int to_charpos
, to_x
, to_y
, to_vpos
;
5612 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5618 if (op
& MOVE_TO_VPOS
)
5620 /* If no TO_CHARPOS and no TO_X specified, stop at the
5621 start of the line TO_VPOS. */
5622 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5624 if (it
->vpos
== to_vpos
)
5630 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5634 /* TO_VPOS >= 0 means stop at TO_X in the line at
5635 TO_VPOS, or at TO_POS, whichever comes first. */
5636 if (it
->vpos
== to_vpos
)
5642 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5644 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5649 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5651 /* We have reached TO_X but not in the line we want. */
5652 skip
= move_it_in_display_line_to (it
, to_charpos
,
5654 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5662 else if (op
& MOVE_TO_Y
)
5664 struct it it_backup
;
5666 /* TO_Y specified means stop at TO_X in the line containing
5667 TO_Y---or at TO_CHARPOS if this is reached first. The
5668 problem is that we can't really tell whether the line
5669 contains TO_Y before we have completely scanned it, and
5670 this may skip past TO_X. What we do is to first scan to
5673 If TO_X is not specified, use a TO_X of zero. The reason
5674 is to make the outcome of this function more predictable.
5675 If we didn't use TO_X == 0, we would stop at the end of
5676 the line which is probably not what a caller would expect
5678 skip
= move_it_in_display_line_to (it
, to_charpos
,
5682 | (op
& MOVE_TO_POS
)));
5684 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5685 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5691 /* If TO_X was reached, we would like to know whether TO_Y
5692 is in the line. This can only be said if we know the
5693 total line height which requires us to scan the rest of
5695 if (skip
== MOVE_X_REACHED
)
5698 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5699 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5701 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5704 /* Now, decide whether TO_Y is in this line. */
5705 line_height
= it
->max_ascent
+ it
->max_descent
;
5706 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5708 if (to_y
>= it
->current_y
5709 && to_y
< it
->current_y
+ line_height
)
5711 if (skip
== MOVE_X_REACHED
)
5712 /* If TO_Y is in this line and TO_X was reached above,
5713 we scanned too far. We have to restore IT's settings
5714 to the ones before skipping. */
5718 else if (skip
== MOVE_X_REACHED
)
5721 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5729 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5733 case MOVE_POS_MATCH_OR_ZV
:
5737 case MOVE_NEWLINE_OR_CR
:
5738 set_iterator_to_next (it
, 1);
5739 it
->continuation_lines_width
= 0;
5742 case MOVE_LINE_TRUNCATED
:
5743 it
->continuation_lines_width
= 0;
5744 reseat_at_next_visible_line_start (it
, 0);
5745 if ((op
& MOVE_TO_POS
) != 0
5746 && IT_CHARPOS (*it
) > to_charpos
)
5753 case MOVE_LINE_CONTINUED
:
5754 it
->continuation_lines_width
+= it
->current_x
;
5761 /* Reset/increment for the next run. */
5762 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5763 it
->current_x
= it
->hpos
= 0;
5764 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5766 last_height
= it
->max_ascent
+ it
->max_descent
;
5767 last_max_ascent
= it
->max_ascent
;
5768 it
->max_ascent
= it
->max_descent
= 0;
5773 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5777 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5779 If DY > 0, move IT backward at least that many pixels. DY = 0
5780 means move IT backward to the preceding line start or BEGV. This
5781 function may move over more than DY pixels if IT->current_y - DY
5782 ends up in the middle of a line; in this case IT->current_y will be
5783 set to the top of the line moved to. */
5786 move_it_vertically_backward (it
, dy
)
5792 int start_pos
= IT_CHARPOS (*it
);
5796 /* Estimate how many newlines we must move back. */
5797 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
5799 /* Set the iterator's position that many lines back. */
5800 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5801 back_to_previous_visible_line_start (it
);
5803 /* Reseat the iterator here. When moving backward, we don't want
5804 reseat to skip forward over invisible text, set up the iterator
5805 to deliver from overlay strings at the new position etc. So,
5806 use reseat_1 here. */
5807 reseat_1 (it
, it
->current
.pos
, 1);
5809 /* We are now surely at a line start. */
5810 it
->current_x
= it
->hpos
= 0;
5811 it
->continuation_lines_width
= 0;
5813 /* Move forward and see what y-distance we moved. First move to the
5814 start of the next line so that we get its height. We need this
5815 height to be able to tell whether we reached the specified
5818 it2
.max_ascent
= it2
.max_descent
= 0;
5819 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5820 MOVE_TO_POS
| MOVE_TO_VPOS
);
5821 xassert (IT_CHARPOS (*it
) >= BEGV
);
5824 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5825 xassert (IT_CHARPOS (*it
) >= BEGV
);
5826 h
= it2
.current_y
- it
->current_y
;
5827 nlines
= it2
.vpos
- it
->vpos
;
5829 /* Correct IT's y and vpos position. */
5835 /* DY == 0 means move to the start of the screen line. The
5836 value of nlines is > 0 if continuation lines were involved. */
5838 move_it_by_lines (it
, nlines
, 1);
5839 xassert (IT_CHARPOS (*it
) <= start_pos
);
5843 /* The y-position we try to reach. Note that h has been
5844 subtracted in front of the if-statement. */
5845 int target_y
= it
->current_y
+ h
- dy
;
5846 int y0
= it3
.current_y
;
5847 int y1
= line_bottom_y (&it3
);
5848 int line_height
= y1
- y0
;
5850 /* If we did not reach target_y, try to move further backward if
5851 we can. If we moved too far backward, try to move forward. */
5852 if (target_y
< it
->current_y
5853 /* This is heuristic. In a window that's 3 lines high, with
5854 a line height of 13 pixels each, recentering with point
5855 on the bottom line will try to move -39/2 = 19 pixels
5856 backward. Try to avoid moving into the first line. */
5857 && it
->current_y
- target_y
> line_height
/ 3 * 2
5858 && IT_CHARPOS (*it
) > BEGV
)
5860 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5861 target_y
- it
->current_y
));
5862 move_it_vertically (it
, target_y
- it
->current_y
);
5863 xassert (IT_CHARPOS (*it
) >= BEGV
);
5865 else if (target_y
>= it
->current_y
+ line_height
5866 && IT_CHARPOS (*it
) < ZV
)
5868 /* Should move forward by at least one line, maybe more.
5870 Note: Calling move_it_by_lines can be expensive on
5871 terminal frames, where compute_motion is used (via
5872 vmotion) to do the job, when there are very long lines
5873 and truncate-lines is nil. That's the reason for
5874 treating terminal frames specially here. */
5876 if (!FRAME_WINDOW_P (it
->f
))
5877 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5882 move_it_by_lines (it
, 1, 1);
5884 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5887 xassert (IT_CHARPOS (*it
) >= BEGV
);
5893 /* Move IT by a specified amount of pixel lines DY. DY negative means
5894 move backwards. DY = 0 means move to start of screen line. At the
5895 end, IT will be on the start of a screen line. */
5898 move_it_vertically (it
, dy
)
5903 move_it_vertically_backward (it
, -dy
);
5906 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5907 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5908 MOVE_TO_POS
| MOVE_TO_Y
);
5909 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5911 /* If buffer ends in ZV without a newline, move to the start of
5912 the line to satisfy the post-condition. */
5913 if (IT_CHARPOS (*it
) == ZV
5914 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5915 move_it_by_lines (it
, 0, 0);
5920 /* Move iterator IT past the end of the text line it is in. */
5923 move_it_past_eol (it
)
5926 enum move_it_result rc
;
5928 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5929 if (rc
== MOVE_NEWLINE_OR_CR
)
5930 set_iterator_to_next (it
, 0);
5934 #if 0 /* Currently not used. */
5936 /* Return non-zero if some text between buffer positions START_CHARPOS
5937 and END_CHARPOS is invisible. IT->window is the window for text
5941 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5943 int start_charpos
, end_charpos
;
5945 Lisp_Object prop
, limit
;
5946 int invisible_found_p
;
5948 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5950 /* Is text at START invisible? */
5951 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
5953 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5954 invisible_found_p
= 1;
5957 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
5959 make_number (end_charpos
));
5960 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
5963 return invisible_found_p
;
5969 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
5970 negative means move up. DVPOS == 0 means move to the start of the
5971 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
5972 NEED_Y_P is zero, IT->current_y will be left unchanged.
5974 Further optimization ideas: If we would know that IT->f doesn't use
5975 a face with proportional font, we could be faster for
5976 truncate-lines nil. */
5979 move_it_by_lines (it
, dvpos
, need_y_p
)
5981 int dvpos
, need_y_p
;
5983 struct position pos
;
5985 if (!FRAME_WINDOW_P (it
->f
))
5987 struct text_pos textpos
;
5989 /* We can use vmotion on frames without proportional fonts. */
5990 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
5991 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
5992 reseat (it
, textpos
, 1);
5993 it
->vpos
+= pos
.vpos
;
5994 it
->current_y
+= pos
.vpos
;
5996 else if (dvpos
== 0)
5998 /* DVPOS == 0 means move to the start of the screen line. */
5999 move_it_vertically_backward (it
, 0);
6000 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6003 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6007 int start_charpos
, i
;
6009 /* Start at the beginning of the screen line containing IT's
6011 move_it_vertically_backward (it
, 0);
6013 /* Go back -DVPOS visible lines and reseat the iterator there. */
6014 start_charpos
= IT_CHARPOS (*it
);
6015 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6016 back_to_previous_visible_line_start (it
);
6017 reseat (it
, it
->current
.pos
, 1);
6018 it
->current_x
= it
->hpos
= 0;
6020 /* Above call may have moved too far if continuation lines
6021 are involved. Scan forward and see if it did. */
6023 it2
.vpos
= it2
.current_y
= 0;
6024 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6025 it
->vpos
-= it2
.vpos
;
6026 it
->current_y
-= it2
.current_y
;
6027 it
->current_x
= it
->hpos
= 0;
6029 /* If we moved too far, move IT some lines forward. */
6030 if (it2
.vpos
> -dvpos
)
6032 int delta
= it2
.vpos
+ dvpos
;
6033 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6038 /* Return 1 if IT points into the middle of a display vector. */
6041 in_display_vector_p (it
)
6044 return (it
->method
== next_element_from_display_vector
6045 && it
->current
.dpvec_index
> 0
6046 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6050 /***********************************************************************
6052 ***********************************************************************/
6055 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6059 add_to_log (format
, arg1
, arg2
)
6061 Lisp_Object arg1
, arg2
;
6063 Lisp_Object args
[3];
6064 Lisp_Object msg
, fmt
;
6067 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6069 /* Do nothing if called asynchronously. Inserting text into
6070 a buffer may call after-change-functions and alike and
6071 that would means running Lisp asynchronously. */
6072 if (handling_signal
)
6076 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6078 args
[0] = fmt
= build_string (format
);
6081 msg
= Fformat (3, args
);
6083 len
= SBYTES (msg
) + 1;
6084 buffer
= (char *) alloca (len
);
6085 bcopy (SDATA (msg
), buffer
, len
);
6087 message_dolog (buffer
, len
- 1, 1, 0);
6092 /* Output a newline in the *Messages* buffer if "needs" one. */
6095 message_log_maybe_newline ()
6097 if (message_log_need_newline
)
6098 message_dolog ("", 0, 1, 0);
6102 /* Add a string M of length NBYTES to the message log, optionally
6103 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6104 nonzero, means interpret the contents of M as multibyte. This
6105 function calls low-level routines in order to bypass text property
6106 hooks, etc. which might not be safe to run. */
6109 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6111 int nbytes
, nlflag
, multibyte
;
6113 if (!NILP (Vmemory_full
))
6116 if (!NILP (Vmessage_log_max
))
6118 struct buffer
*oldbuf
;
6119 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6120 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6121 int point_at_end
= 0;
6123 Lisp_Object old_deactivate_mark
, tem
;
6124 struct gcpro gcpro1
;
6126 old_deactivate_mark
= Vdeactivate_mark
;
6127 oldbuf
= current_buffer
;
6128 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6129 current_buffer
->undo_list
= Qt
;
6131 oldpoint
= message_dolog_marker1
;
6132 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6133 oldbegv
= message_dolog_marker2
;
6134 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6135 oldzv
= message_dolog_marker3
;
6136 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6137 GCPRO1 (old_deactivate_mark
);
6145 BEGV_BYTE
= BEG_BYTE
;
6148 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6150 /* Insert the string--maybe converting multibyte to single byte
6151 or vice versa, so that all the text fits the buffer. */
6153 && NILP (current_buffer
->enable_multibyte_characters
))
6155 int i
, c
, char_bytes
;
6156 unsigned char work
[1];
6158 /* Convert a multibyte string to single-byte
6159 for the *Message* buffer. */
6160 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6162 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6163 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6165 : multibyte_char_to_unibyte (c
, Qnil
));
6166 insert_1_both (work
, 1, 1, 1, 0, 0);
6169 else if (! multibyte
6170 && ! NILP (current_buffer
->enable_multibyte_characters
))
6172 int i
, c
, char_bytes
;
6173 unsigned char *msg
= (unsigned char *) m
;
6174 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6175 /* Convert a single-byte string to multibyte
6176 for the *Message* buffer. */
6177 for (i
= 0; i
< nbytes
; i
++)
6179 c
= unibyte_char_to_multibyte (msg
[i
]);
6180 char_bytes
= CHAR_STRING (c
, str
);
6181 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6185 insert_1 (m
, nbytes
, 1, 0, 0);
6189 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6190 insert_1 ("\n", 1, 1, 0, 0);
6192 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6194 this_bol_byte
= PT_BYTE
;
6196 /* See if this line duplicates the previous one.
6197 If so, combine duplicates. */
6200 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6202 prev_bol_byte
= PT_BYTE
;
6204 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6205 this_bol
, this_bol_byte
);
6208 del_range_both (prev_bol
, prev_bol_byte
,
6209 this_bol
, this_bol_byte
, 0);
6215 /* If you change this format, don't forget to also
6216 change message_log_check_duplicate. */
6217 sprintf (dupstr
, " [%d times]", dup
);
6218 duplen
= strlen (dupstr
);
6219 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6220 insert_1 (dupstr
, duplen
, 1, 0, 1);
6225 /* If we have more than the desired maximum number of lines
6226 in the *Messages* buffer now, delete the oldest ones.
6227 This is safe because we don't have undo in this buffer. */
6229 if (NATNUMP (Vmessage_log_max
))
6231 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6232 -XFASTINT (Vmessage_log_max
) - 1, 0);
6233 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6236 BEGV
= XMARKER (oldbegv
)->charpos
;
6237 BEGV_BYTE
= marker_byte_position (oldbegv
);
6246 ZV
= XMARKER (oldzv
)->charpos
;
6247 ZV_BYTE
= marker_byte_position (oldzv
);
6251 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6253 /* We can't do Fgoto_char (oldpoint) because it will run some
6255 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6256 XMARKER (oldpoint
)->bytepos
);
6259 unchain_marker (oldpoint
);
6260 unchain_marker (oldbegv
);
6261 unchain_marker (oldzv
);
6263 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6264 set_buffer_internal (oldbuf
);
6266 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6267 message_log_need_newline
= !nlflag
;
6268 Vdeactivate_mark
= old_deactivate_mark
;
6273 /* We are at the end of the buffer after just having inserted a newline.
6274 (Note: We depend on the fact we won't be crossing the gap.)
6275 Check to see if the most recent message looks a lot like the previous one.
6276 Return 0 if different, 1 if the new one should just replace it, or a
6277 value N > 1 if we should also append " [N times]". */
6280 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6281 int prev_bol
, this_bol
;
6282 int prev_bol_byte
, this_bol_byte
;
6285 int len
= Z_BYTE
- 1 - this_bol_byte
;
6287 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6288 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6290 for (i
= 0; i
< len
; i
++)
6292 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6300 if (*p1
++ == ' ' && *p1
++ == '[')
6303 while (*p1
>= '0' && *p1
<= '9')
6304 n
= n
* 10 + *p1
++ - '0';
6305 if (strncmp (p1
, " times]\n", 8) == 0)
6312 /* Display an echo area message M with a specified length of NBYTES
6313 bytes. The string may include null characters. If M is 0, clear
6314 out any existing message, and let the mini-buffer text show
6317 The buffer M must continue to exist until after the echo area gets
6318 cleared or some other message gets displayed there. This means do
6319 not pass text that is stored in a Lisp string; do not pass text in
6320 a buffer that was alloca'd. */
6323 message2 (m
, nbytes
, multibyte
)
6328 /* First flush out any partial line written with print. */
6329 message_log_maybe_newline ();
6331 message_dolog (m
, nbytes
, 1, multibyte
);
6332 message2_nolog (m
, nbytes
, multibyte
);
6336 /* The non-logging counterpart of message2. */
6339 message2_nolog (m
, nbytes
, multibyte
)
6341 int nbytes
, multibyte
;
6343 struct frame
*sf
= SELECTED_FRAME ();
6344 message_enable_multibyte
= multibyte
;
6348 if (noninteractive_need_newline
)
6349 putc ('\n', stderr
);
6350 noninteractive_need_newline
= 0;
6352 fwrite (m
, nbytes
, 1, stderr
);
6353 if (cursor_in_echo_area
== 0)
6354 fprintf (stderr
, "\n");
6357 /* A null message buffer means that the frame hasn't really been
6358 initialized yet. Error messages get reported properly by
6359 cmd_error, so this must be just an informative message; toss it. */
6360 else if (INTERACTIVE
6361 && sf
->glyphs_initialized_p
6362 && FRAME_MESSAGE_BUF (sf
))
6364 Lisp_Object mini_window
;
6367 /* Get the frame containing the mini-buffer
6368 that the selected frame is using. */
6369 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6370 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6372 FRAME_SAMPLE_VISIBILITY (f
);
6373 if (FRAME_VISIBLE_P (sf
)
6374 && ! FRAME_VISIBLE_P (f
))
6375 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6379 set_message (m
, Qnil
, nbytes
, multibyte
);
6380 if (minibuffer_auto_raise
)
6381 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6384 clear_message (1, 1);
6386 do_pending_window_change (0);
6387 echo_area_display (1);
6388 do_pending_window_change (0);
6389 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6390 (*frame_up_to_date_hook
) (f
);
6395 /* Display an echo area message M with a specified length of NBYTES
6396 bytes. The string may include null characters. If M is not a
6397 string, clear out any existing message, and let the mini-buffer
6398 text show through. */
6401 message3 (m
, nbytes
, multibyte
)
6406 struct gcpro gcpro1
;
6410 /* First flush out any partial line written with print. */
6411 message_log_maybe_newline ();
6413 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6414 message3_nolog (m
, nbytes
, multibyte
);
6420 /* The non-logging version of message3. */
6423 message3_nolog (m
, nbytes
, multibyte
)
6425 int nbytes
, multibyte
;
6427 struct frame
*sf
= SELECTED_FRAME ();
6428 message_enable_multibyte
= multibyte
;
6432 if (noninteractive_need_newline
)
6433 putc ('\n', stderr
);
6434 noninteractive_need_newline
= 0;
6436 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6437 if (cursor_in_echo_area
== 0)
6438 fprintf (stderr
, "\n");
6441 /* A null message buffer means that the frame hasn't really been
6442 initialized yet. Error messages get reported properly by
6443 cmd_error, so this must be just an informative message; toss it. */
6444 else if (INTERACTIVE
6445 && sf
->glyphs_initialized_p
6446 && FRAME_MESSAGE_BUF (sf
))
6448 Lisp_Object mini_window
;
6452 /* Get the frame containing the mini-buffer
6453 that the selected frame is using. */
6454 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6455 frame
= XWINDOW (mini_window
)->frame
;
6458 FRAME_SAMPLE_VISIBILITY (f
);
6459 if (FRAME_VISIBLE_P (sf
)
6460 && !FRAME_VISIBLE_P (f
))
6461 Fmake_frame_visible (frame
);
6463 if (STRINGP (m
) && SCHARS (m
) > 0)
6465 set_message (NULL
, m
, nbytes
, multibyte
);
6466 if (minibuffer_auto_raise
)
6467 Fraise_frame (frame
);
6470 clear_message (1, 1);
6472 do_pending_window_change (0);
6473 echo_area_display (1);
6474 do_pending_window_change (0);
6475 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6476 (*frame_up_to_date_hook
) (f
);
6481 /* Display a null-terminated echo area message M. If M is 0, clear
6482 out any existing message, and let the mini-buffer text show through.
6484 The buffer M must continue to exist until after the echo area gets
6485 cleared or some other message gets displayed there. Do not pass
6486 text that is stored in a Lisp string. Do not pass text in a buffer
6487 that was alloca'd. */
6493 message2 (m
, (m
? strlen (m
) : 0), 0);
6497 /* The non-logging counterpart of message1. */
6503 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6506 /* Display a message M which contains a single %s
6507 which gets replaced with STRING. */
6510 message_with_string (m
, string
, log
)
6515 CHECK_STRING (string
);
6521 if (noninteractive_need_newline
)
6522 putc ('\n', stderr
);
6523 noninteractive_need_newline
= 0;
6524 fprintf (stderr
, m
, SDATA (string
));
6525 if (cursor_in_echo_area
== 0)
6526 fprintf (stderr
, "\n");
6530 else if (INTERACTIVE
)
6532 /* The frame whose minibuffer we're going to display the message on.
6533 It may be larger than the selected frame, so we need
6534 to use its buffer, not the selected frame's buffer. */
6535 Lisp_Object mini_window
;
6536 struct frame
*f
, *sf
= SELECTED_FRAME ();
6538 /* Get the frame containing the minibuffer
6539 that the selected frame is using. */
6540 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6541 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6543 /* A null message buffer means that the frame hasn't really been
6544 initialized yet. Error messages get reported properly by
6545 cmd_error, so this must be just an informative message; toss it. */
6546 if (FRAME_MESSAGE_BUF (f
))
6548 Lisp_Object args
[2], message
;
6549 struct gcpro gcpro1
, gcpro2
;
6551 args
[0] = build_string (m
);
6552 args
[1] = message
= string
;
6553 GCPRO2 (args
[0], message
);
6556 message
= Fformat (2, args
);
6559 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6561 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6565 /* Print should start at the beginning of the message
6566 buffer next time. */
6567 message_buf_print
= 0;
6573 /* Dump an informative message to the minibuf. If M is 0, clear out
6574 any existing message, and let the mini-buffer text show through. */
6578 message (m
, a1
, a2
, a3
)
6580 EMACS_INT a1
, a2
, a3
;
6586 if (noninteractive_need_newline
)
6587 putc ('\n', stderr
);
6588 noninteractive_need_newline
= 0;
6589 fprintf (stderr
, m
, a1
, a2
, a3
);
6590 if (cursor_in_echo_area
== 0)
6591 fprintf (stderr
, "\n");
6595 else if (INTERACTIVE
)
6597 /* The frame whose mini-buffer we're going to display the message
6598 on. It may be larger than the selected frame, so we need to
6599 use its buffer, not the selected frame's buffer. */
6600 Lisp_Object mini_window
;
6601 struct frame
*f
, *sf
= SELECTED_FRAME ();
6603 /* Get the frame containing the mini-buffer
6604 that the selected frame is using. */
6605 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6606 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6608 /* A null message buffer means that the frame hasn't really been
6609 initialized yet. Error messages get reported properly by
6610 cmd_error, so this must be just an informative message; toss
6612 if (FRAME_MESSAGE_BUF (f
))
6623 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6624 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6626 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6627 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6629 #endif /* NO_ARG_ARRAY */
6631 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6636 /* Print should start at the beginning of the message
6637 buffer next time. */
6638 message_buf_print
= 0;
6644 /* The non-logging version of message. */
6647 message_nolog (m
, a1
, a2
, a3
)
6649 EMACS_INT a1
, a2
, a3
;
6651 Lisp_Object old_log_max
;
6652 old_log_max
= Vmessage_log_max
;
6653 Vmessage_log_max
= Qnil
;
6654 message (m
, a1
, a2
, a3
);
6655 Vmessage_log_max
= old_log_max
;
6659 /* Display the current message in the current mini-buffer. This is
6660 only called from error handlers in process.c, and is not time
6666 if (!NILP (echo_area_buffer
[0]))
6669 string
= Fcurrent_message ();
6670 message3 (string
, SBYTES (string
),
6671 !NILP (current_buffer
->enable_multibyte_characters
));
6676 /* Make sure echo area buffers in `echo_buffers' are live.
6677 If they aren't, make new ones. */
6680 ensure_echo_area_buffers ()
6684 for (i
= 0; i
< 2; ++i
)
6685 if (!BUFFERP (echo_buffer
[i
])
6686 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6689 Lisp_Object old_buffer
;
6692 old_buffer
= echo_buffer
[i
];
6693 sprintf (name
, " *Echo Area %d*", i
);
6694 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6695 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6697 for (j
= 0; j
< 2; ++j
)
6698 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6699 echo_area_buffer
[j
] = echo_buffer
[i
];
6704 /* Call FN with args A1..A4 with either the current or last displayed
6705 echo_area_buffer as current buffer.
6707 WHICH zero means use the current message buffer
6708 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6709 from echo_buffer[] and clear it.
6711 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6712 suitable buffer from echo_buffer[] and clear it.
6714 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6715 that the current message becomes the last displayed one, make
6716 choose a suitable buffer for echo_area_buffer[0], and clear it.
6718 Value is what FN returns. */
6721 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6724 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6730 int this_one
, the_other
, clear_buffer_p
, rc
;
6731 int count
= SPECPDL_INDEX ();
6733 /* If buffers aren't live, make new ones. */
6734 ensure_echo_area_buffers ();
6739 this_one
= 0, the_other
= 1;
6741 this_one
= 1, the_other
= 0;
6744 this_one
= 0, the_other
= 1;
6747 /* We need a fresh one in case the current echo buffer equals
6748 the one containing the last displayed echo area message. */
6749 if (!NILP (echo_area_buffer
[this_one
])
6750 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6751 echo_area_buffer
[this_one
] = Qnil
;
6754 /* Choose a suitable buffer from echo_buffer[] is we don't
6756 if (NILP (echo_area_buffer
[this_one
]))
6758 echo_area_buffer
[this_one
]
6759 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6760 ? echo_buffer
[the_other
]
6761 : echo_buffer
[this_one
]);
6765 buffer
= echo_area_buffer
[this_one
];
6767 /* Don't get confused by reusing the buffer used for echoing
6768 for a different purpose. */
6769 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6772 record_unwind_protect (unwind_with_echo_area_buffer
,
6773 with_echo_area_buffer_unwind_data (w
));
6775 /* Make the echo area buffer current. Note that for display
6776 purposes, it is not necessary that the displayed window's buffer
6777 == current_buffer, except for text property lookup. So, let's
6778 only set that buffer temporarily here without doing a full
6779 Fset_window_buffer. We must also change w->pointm, though,
6780 because otherwise an assertions in unshow_buffer fails, and Emacs
6782 set_buffer_internal_1 (XBUFFER (buffer
));
6786 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6789 current_buffer
->undo_list
= Qt
;
6790 current_buffer
->read_only
= Qnil
;
6791 specbind (Qinhibit_read_only
, Qt
);
6792 specbind (Qinhibit_modification_hooks
, Qt
);
6794 if (clear_buffer_p
&& Z
> BEG
)
6797 xassert (BEGV
>= BEG
);
6798 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6800 rc
= fn (a1
, a2
, a3
, a4
);
6802 xassert (BEGV
>= BEG
);
6803 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6805 unbind_to (count
, Qnil
);
6810 /* Save state that should be preserved around the call to the function
6811 FN called in with_echo_area_buffer. */
6814 with_echo_area_buffer_unwind_data (w
)
6820 /* Reduce consing by keeping one vector in
6821 Vwith_echo_area_save_vector. */
6822 vector
= Vwith_echo_area_save_vector
;
6823 Vwith_echo_area_save_vector
= Qnil
;
6826 vector
= Fmake_vector (make_number (7), Qnil
);
6828 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6829 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6830 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6834 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6835 AREF (vector
, i
) = w
->buffer
; ++i
;
6836 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6837 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6842 for (; i
< end
; ++i
)
6843 AREF (vector
, i
) = Qnil
;
6846 xassert (i
== ASIZE (vector
));
6851 /* Restore global state from VECTOR which was created by
6852 with_echo_area_buffer_unwind_data. */
6855 unwind_with_echo_area_buffer (vector
)
6858 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6859 Vdeactivate_mark
= AREF (vector
, 1);
6860 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6862 if (WINDOWP (AREF (vector
, 3)))
6865 Lisp_Object buffer
, charpos
, bytepos
;
6867 w
= XWINDOW (AREF (vector
, 3));
6868 buffer
= AREF (vector
, 4);
6869 charpos
= AREF (vector
, 5);
6870 bytepos
= AREF (vector
, 6);
6873 set_marker_both (w
->pointm
, buffer
,
6874 XFASTINT (charpos
), XFASTINT (bytepos
));
6877 Vwith_echo_area_save_vector
= vector
;
6882 /* Set up the echo area for use by print functions. MULTIBYTE_P
6883 non-zero means we will print multibyte. */
6886 setup_echo_area_for_printing (multibyte_p
)
6889 /* If we can't find an echo area any more, exit. */
6890 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
6893 ensure_echo_area_buffers ();
6895 if (!message_buf_print
)
6897 /* A message has been output since the last time we printed.
6898 Choose a fresh echo area buffer. */
6899 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6900 echo_area_buffer
[0] = echo_buffer
[1];
6902 echo_area_buffer
[0] = echo_buffer
[0];
6904 /* Switch to that buffer and clear it. */
6905 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6906 current_buffer
->truncate_lines
= Qnil
;
6910 int count
= SPECPDL_INDEX ();
6911 specbind (Qinhibit_read_only
, Qt
);
6912 /* Note that undo recording is always disabled. */
6914 unbind_to (count
, Qnil
);
6916 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6918 /* Set up the buffer for the multibyteness we need. */
6920 != !NILP (current_buffer
->enable_multibyte_characters
))
6921 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6923 /* Raise the frame containing the echo area. */
6924 if (minibuffer_auto_raise
)
6926 struct frame
*sf
= SELECTED_FRAME ();
6927 Lisp_Object mini_window
;
6928 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6929 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6932 message_log_maybe_newline ();
6933 message_buf_print
= 1;
6937 if (NILP (echo_area_buffer
[0]))
6939 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6940 echo_area_buffer
[0] = echo_buffer
[1];
6942 echo_area_buffer
[0] = echo_buffer
[0];
6945 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6947 /* Someone switched buffers between print requests. */
6948 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6949 current_buffer
->truncate_lines
= Qnil
;
6955 /* Display an echo area message in window W. Value is non-zero if W's
6956 height is changed. If display_last_displayed_message_p is
6957 non-zero, display the message that was last displayed, otherwise
6958 display the current message. */
6961 display_echo_area (w
)
6964 int i
, no_message_p
, window_height_changed_p
, count
;
6966 /* Temporarily disable garbage collections while displaying the echo
6967 area. This is done because a GC can print a message itself.
6968 That message would modify the echo area buffer's contents while a
6969 redisplay of the buffer is going on, and seriously confuse
6971 count
= inhibit_garbage_collection ();
6973 /* If there is no message, we must call display_echo_area_1
6974 nevertheless because it resizes the window. But we will have to
6975 reset the echo_area_buffer in question to nil at the end because
6976 with_echo_area_buffer will sets it to an empty buffer. */
6977 i
= display_last_displayed_message_p
? 1 : 0;
6978 no_message_p
= NILP (echo_area_buffer
[i
]);
6980 window_height_changed_p
6981 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
6982 display_echo_area_1
,
6983 (EMACS_INT
) w
, Qnil
, 0, 0);
6986 echo_area_buffer
[i
] = Qnil
;
6988 unbind_to (count
, Qnil
);
6989 return window_height_changed_p
;
6993 /* Helper for display_echo_area. Display the current buffer which
6994 contains the current echo area message in window W, a mini-window,
6995 a pointer to which is passed in A1. A2..A4 are currently not used.
6996 Change the height of W so that all of the message is displayed.
6997 Value is non-zero if height of W was changed. */
7000 display_echo_area_1 (a1
, a2
, a3
, a4
)
7005 struct window
*w
= (struct window
*) a1
;
7007 struct text_pos start
;
7008 int window_height_changed_p
= 0;
7010 /* Do this before displaying, so that we have a large enough glyph
7011 matrix for the display. */
7012 window_height_changed_p
= resize_mini_window (w
, 0);
7015 clear_glyph_matrix (w
->desired_matrix
);
7016 XSETWINDOW (window
, w
);
7017 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7018 try_window (window
, start
);
7020 return window_height_changed_p
;
7024 /* Resize the echo area window to exactly the size needed for the
7025 currently displayed message, if there is one. If a mini-buffer
7026 is active, don't shrink it. */
7029 resize_echo_area_exactly ()
7031 if (BUFFERP (echo_area_buffer
[0])
7032 && WINDOWP (echo_area_window
))
7034 struct window
*w
= XWINDOW (echo_area_window
);
7036 Lisp_Object resize_exactly
;
7038 if (minibuf_level
== 0)
7039 resize_exactly
= Qt
;
7041 resize_exactly
= Qnil
;
7043 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7044 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7047 ++windows_or_buffers_changed
;
7048 ++update_mode_lines
;
7049 redisplay_internal (0);
7055 /* Callback function for with_echo_area_buffer, when used from
7056 resize_echo_area_exactly. A1 contains a pointer to the window to
7057 resize, EXACTLY non-nil means resize the mini-window exactly to the
7058 size of the text displayed. A3 and A4 are not used. Value is what
7059 resize_mini_window returns. */
7062 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7064 Lisp_Object exactly
;
7067 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7071 /* Resize mini-window W to fit the size of its contents. EXACT:P
7072 means size the window exactly to the size needed. Otherwise, it's
7073 only enlarged until W's buffer is empty. Value is non-zero if
7074 the window height has been changed. */
7077 resize_mini_window (w
, exact_p
)
7081 struct frame
*f
= XFRAME (w
->frame
);
7082 int window_height_changed_p
= 0;
7084 xassert (MINI_WINDOW_P (w
));
7086 /* Don't resize windows while redisplaying a window; it would
7087 confuse redisplay functions when the size of the window they are
7088 displaying changes from under them. Such a resizing can happen,
7089 for instance, when which-func prints a long message while
7090 we are running fontification-functions. We're running these
7091 functions with safe_call which binds inhibit-redisplay to t. */
7092 if (!NILP (Vinhibit_redisplay
))
7095 /* Nil means don't try to resize. */
7096 if (NILP (Vresize_mini_windows
)
7097 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7100 if (!FRAME_MINIBUF_ONLY_P (f
))
7103 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7104 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
7105 int height
, max_height
;
7106 int unit
= CANON_Y_UNIT (f
);
7107 struct text_pos start
;
7108 struct buffer
*old_current_buffer
= NULL
;
7110 if (current_buffer
!= XBUFFER (w
->buffer
))
7112 old_current_buffer
= current_buffer
;
7113 set_buffer_internal (XBUFFER (w
->buffer
));
7116 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7118 /* Compute the max. number of lines specified by the user. */
7119 if (FLOATP (Vmax_mini_window_height
))
7120 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_HEIGHT (f
);
7121 else if (INTEGERP (Vmax_mini_window_height
))
7122 max_height
= XINT (Vmax_mini_window_height
);
7124 max_height
= total_height
/ 4;
7126 /* Correct that max. height if it's bogus. */
7127 max_height
= max (1, max_height
);
7128 max_height
= min (total_height
, max_height
);
7130 /* Find out the height of the text in the window. */
7131 if (it
.truncate_lines_p
)
7136 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7137 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7138 height
= it
.current_y
+ last_height
;
7140 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7141 height
-= it
.extra_line_spacing
;
7142 height
= (height
+ unit
- 1) / unit
;
7145 /* Compute a suitable window start. */
7146 if (height
> max_height
)
7148 height
= max_height
;
7149 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7150 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7151 start
= it
.current
.pos
;
7154 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7155 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7157 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7159 /* Let it grow only, until we display an empty message, in which
7160 case the window shrinks again. */
7161 if (height
> XFASTINT (w
->height
))
7163 int old_height
= XFASTINT (w
->height
);
7164 freeze_window_starts (f
, 1);
7165 grow_mini_window (w
, height
- XFASTINT (w
->height
));
7166 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
7168 else if (height
< XFASTINT (w
->height
)
7169 && (exact_p
|| BEGV
== ZV
))
7171 int old_height
= XFASTINT (w
->height
);
7172 freeze_window_starts (f
, 0);
7173 shrink_mini_window (w
);
7174 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
7179 /* Always resize to exact size needed. */
7180 if (height
> XFASTINT (w
->height
))
7182 int old_height
= XFASTINT (w
->height
);
7183 freeze_window_starts (f
, 1);
7184 grow_mini_window (w
, height
- XFASTINT (w
->height
));
7185 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
7187 else if (height
< XFASTINT (w
->height
))
7189 int old_height
= XFASTINT (w
->height
);
7190 freeze_window_starts (f
, 0);
7191 shrink_mini_window (w
);
7195 freeze_window_starts (f
, 1);
7196 grow_mini_window (w
, height
- XFASTINT (w
->height
));
7199 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
7203 if (old_current_buffer
)
7204 set_buffer_internal (old_current_buffer
);
7207 return window_height_changed_p
;
7211 /* Value is the current message, a string, or nil if there is no
7219 if (NILP (echo_area_buffer
[0]))
7223 with_echo_area_buffer (0, 0, current_message_1
,
7224 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7226 echo_area_buffer
[0] = Qnil
;
7234 current_message_1 (a1
, a2
, a3
, a4
)
7239 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7242 *msg
= make_buffer_string (BEG
, Z
, 1);
7249 /* Push the current message on Vmessage_stack for later restauration
7250 by restore_message. Value is non-zero if the current message isn't
7251 empty. This is a relatively infrequent operation, so it's not
7252 worth optimizing. */
7258 msg
= current_message ();
7259 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7260 return STRINGP (msg
);
7264 /* Restore message display from the top of Vmessage_stack. */
7271 xassert (CONSP (Vmessage_stack
));
7272 msg
= XCAR (Vmessage_stack
);
7274 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7276 message3_nolog (msg
, 0, 0);
7280 /* Handler for record_unwind_protect calling pop_message. */
7283 pop_message_unwind (dummy
)
7290 /* Pop the top-most entry off Vmessage_stack. */
7295 xassert (CONSP (Vmessage_stack
));
7296 Vmessage_stack
= XCDR (Vmessage_stack
);
7300 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7301 exits. If the stack is not empty, we have a missing pop_message
7305 check_message_stack ()
7307 if (!NILP (Vmessage_stack
))
7312 /* Truncate to NCHARS what will be displayed in the echo area the next
7313 time we display it---but don't redisplay it now. */
7316 truncate_echo_area (nchars
)
7320 echo_area_buffer
[0] = Qnil
;
7321 /* A null message buffer means that the frame hasn't really been
7322 initialized yet. Error messages get reported properly by
7323 cmd_error, so this must be just an informative message; toss it. */
7324 else if (!noninteractive
7326 && !NILP (echo_area_buffer
[0]))
7328 struct frame
*sf
= SELECTED_FRAME ();
7329 if (FRAME_MESSAGE_BUF (sf
))
7330 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7335 /* Helper function for truncate_echo_area. Truncate the current
7336 message to at most NCHARS characters. */
7339 truncate_message_1 (nchars
, a2
, a3
, a4
)
7344 if (BEG
+ nchars
< Z
)
7345 del_range (BEG
+ nchars
, Z
);
7347 echo_area_buffer
[0] = Qnil
;
7352 /* Set the current message to a substring of S or STRING.
7354 If STRING is a Lisp string, set the message to the first NBYTES
7355 bytes from STRING. NBYTES zero means use the whole string. If
7356 STRING is multibyte, the message will be displayed multibyte.
7358 If S is not null, set the message to the first LEN bytes of S. LEN
7359 zero means use the whole string. MULTIBYTE_P non-zero means S is
7360 multibyte. Display the message multibyte in that case. */
7363 set_message (s
, string
, nbytes
, multibyte_p
)
7366 int nbytes
, multibyte_p
;
7368 message_enable_multibyte
7369 = ((s
&& multibyte_p
)
7370 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7372 with_echo_area_buffer (0, -1, set_message_1
,
7373 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7374 message_buf_print
= 0;
7375 help_echo_showing_p
= 0;
7379 /* Helper function for set_message. Arguments have the same meaning
7380 as there, with A1 corresponding to S and A2 corresponding to STRING
7381 This function is called with the echo area buffer being
7385 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7388 EMACS_INT nbytes
, multibyte_p
;
7390 const char *s
= (const char *) a1
;
7391 Lisp_Object string
= a2
;
7395 /* Change multibyteness of the echo buffer appropriately. */
7396 if (message_enable_multibyte
7397 != !NILP (current_buffer
->enable_multibyte_characters
))
7398 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7400 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7402 /* Insert new message at BEG. */
7403 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7405 if (STRINGP (string
))
7410 nbytes
= SBYTES (string
);
7411 nchars
= string_byte_to_char (string
, nbytes
);
7413 /* This function takes care of single/multibyte conversion. We
7414 just have to ensure that the echo area buffer has the right
7415 setting of enable_multibyte_characters. */
7416 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7421 nbytes
= strlen (s
);
7423 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7425 /* Convert from multi-byte to single-byte. */
7427 unsigned char work
[1];
7429 /* Convert a multibyte string to single-byte. */
7430 for (i
= 0; i
< nbytes
; i
+= n
)
7432 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7433 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7435 : multibyte_char_to_unibyte (c
, Qnil
));
7436 insert_1_both (work
, 1, 1, 1, 0, 0);
7439 else if (!multibyte_p
7440 && !NILP (current_buffer
->enable_multibyte_characters
))
7442 /* Convert from single-byte to multi-byte. */
7444 const unsigned char *msg
= (const unsigned char *) s
;
7445 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7447 /* Convert a single-byte string to multibyte. */
7448 for (i
= 0; i
< nbytes
; i
++)
7450 c
= unibyte_char_to_multibyte (msg
[i
]);
7451 n
= CHAR_STRING (c
, str
);
7452 insert_1_both (str
, 1, n
, 1, 0, 0);
7456 insert_1 (s
, nbytes
, 1, 0, 0);
7463 /* Clear messages. CURRENT_P non-zero means clear the current
7464 message. LAST_DISPLAYED_P non-zero means clear the message
7468 clear_message (current_p
, last_displayed_p
)
7469 int current_p
, last_displayed_p
;
7473 echo_area_buffer
[0] = Qnil
;
7474 message_cleared_p
= 1;
7477 if (last_displayed_p
)
7478 echo_area_buffer
[1] = Qnil
;
7480 message_buf_print
= 0;
7483 /* Clear garbaged frames.
7485 This function is used where the old redisplay called
7486 redraw_garbaged_frames which in turn called redraw_frame which in
7487 turn called clear_frame. The call to clear_frame was a source of
7488 flickering. I believe a clear_frame is not necessary. It should
7489 suffice in the new redisplay to invalidate all current matrices,
7490 and ensure a complete redisplay of all windows. */
7493 clear_garbaged_frames ()
7497 Lisp_Object tail
, frame
;
7498 int changed_count
= 0;
7500 FOR_EACH_FRAME (tail
, frame
)
7502 struct frame
*f
= XFRAME (frame
);
7504 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7507 Fredraw_frame (frame
);
7508 clear_current_matrices (f
);
7517 ++windows_or_buffers_changed
;
7522 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7523 is non-zero update selected_frame. Value is non-zero if the
7524 mini-windows height has been changed. */
7527 echo_area_display (update_frame_p
)
7530 Lisp_Object mini_window
;
7533 int window_height_changed_p
= 0;
7534 struct frame
*sf
= SELECTED_FRAME ();
7536 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7537 w
= XWINDOW (mini_window
);
7538 f
= XFRAME (WINDOW_FRAME (w
));
7540 /* Don't display if frame is invisible or not yet initialized. */
7541 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7544 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7546 #ifdef HAVE_WINDOW_SYSTEM
7547 /* When Emacs starts, selected_frame may be a visible terminal
7548 frame, even if we run under a window system. If we let this
7549 through, a message would be displayed on the terminal. */
7550 if (EQ (selected_frame
, Vterminal_frame
)
7551 && !NILP (Vwindow_system
))
7553 #endif /* HAVE_WINDOW_SYSTEM */
7556 /* Redraw garbaged frames. */
7558 clear_garbaged_frames ();
7560 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7562 echo_area_window
= mini_window
;
7563 window_height_changed_p
= display_echo_area (w
);
7564 w
->must_be_updated_p
= 1;
7566 /* Update the display, unless called from redisplay_internal.
7567 Also don't update the screen during redisplay itself. The
7568 update will happen at the end of redisplay, and an update
7569 here could cause confusion. */
7570 if (update_frame_p
&& !redisplaying_p
)
7574 /* If the display update has been interrupted by pending
7575 input, update mode lines in the frame. Due to the
7576 pending input, it might have been that redisplay hasn't
7577 been called, so that mode lines above the echo area are
7578 garbaged. This looks odd, so we prevent it here. */
7579 if (!display_completed
)
7580 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7582 if (window_height_changed_p
7583 /* Don't do this if Emacs is shutting down. Redisplay
7584 needs to run hooks. */
7585 && !NILP (Vrun_hooks
))
7587 /* Must update other windows. Likewise as in other
7588 cases, don't let this update be interrupted by
7590 int count
= SPECPDL_INDEX ();
7591 specbind (Qredisplay_dont_pause
, Qt
);
7592 windows_or_buffers_changed
= 1;
7593 redisplay_internal (0);
7594 unbind_to (count
, Qnil
);
7596 else if (FRAME_WINDOW_P (f
) && n
== 0)
7598 /* Window configuration is the same as before.
7599 Can do with a display update of the echo area,
7600 unless we displayed some mode lines. */
7601 update_single_window (w
, 1);
7602 rif
->flush_display (f
);
7605 update_frame (f
, 1, 1);
7607 /* If cursor is in the echo area, make sure that the next
7608 redisplay displays the minibuffer, so that the cursor will
7609 be replaced with what the minibuffer wants. */
7610 if (cursor_in_echo_area
)
7611 ++windows_or_buffers_changed
;
7614 else if (!EQ (mini_window
, selected_window
))
7615 windows_or_buffers_changed
++;
7617 /* Last displayed message is now the current message. */
7618 echo_area_buffer
[1] = echo_area_buffer
[0];
7620 /* Prevent redisplay optimization in redisplay_internal by resetting
7621 this_line_start_pos. This is done because the mini-buffer now
7622 displays the message instead of its buffer text. */
7623 if (EQ (mini_window
, selected_window
))
7624 CHARPOS (this_line_start_pos
) = 0;
7626 return window_height_changed_p
;
7631 /***********************************************************************
7633 ***********************************************************************/
7636 /* The frame title buffering code is also used by Fformat_mode_line.
7637 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7639 /* A buffer for constructing frame titles in it; allocated from the
7640 heap in init_xdisp and resized as needed in store_frame_title_char. */
7642 static char *frame_title_buf
;
7644 /* The buffer's end, and a current output position in it. */
7646 static char *frame_title_buf_end
;
7647 static char *frame_title_ptr
;
7650 /* Store a single character C for the frame title in frame_title_buf.
7651 Re-allocate frame_title_buf if necessary. */
7655 store_frame_title_char (char c
)
7657 store_frame_title_char (c
)
7661 /* If output position has reached the end of the allocated buffer,
7662 double the buffer's size. */
7663 if (frame_title_ptr
== frame_title_buf_end
)
7665 int len
= frame_title_ptr
- frame_title_buf
;
7666 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7667 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7668 frame_title_buf_end
= frame_title_buf
+ new_size
;
7669 frame_title_ptr
= frame_title_buf
+ len
;
7672 *frame_title_ptr
++ = c
;
7676 /* Store part of a frame title in frame_title_buf, beginning at
7677 frame_title_ptr. STR is the string to store. Do not copy
7678 characters that yield more columns than PRECISION; PRECISION <= 0
7679 means copy the whole string. Pad with spaces until FIELD_WIDTH
7680 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7681 pad. Called from display_mode_element when it is used to build a
7685 store_frame_title (str
, field_width
, precision
)
7686 const unsigned char *str
;
7687 int field_width
, precision
;
7692 /* Copy at most PRECISION chars from STR. */
7693 nbytes
= strlen (str
);
7694 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7696 store_frame_title_char (*str
++);
7698 /* Fill up with spaces until FIELD_WIDTH reached. */
7699 while (field_width
> 0
7702 store_frame_title_char (' ');
7709 #ifdef HAVE_WINDOW_SYSTEM
7711 /* Set the title of FRAME, if it has changed. The title format is
7712 Vicon_title_format if FRAME is iconified, otherwise it is
7713 frame_title_format. */
7716 x_consider_frame_title (frame
)
7719 struct frame
*f
= XFRAME (frame
);
7721 if (FRAME_WINDOW_P (f
)
7722 || FRAME_MINIBUF_ONLY_P (f
)
7723 || f
->explicit_name
)
7725 /* Do we have more than one visible frame on this X display? */
7728 struct buffer
*obuf
;
7732 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7734 Lisp_Object other_frame
= XCAR (tail
);
7735 struct frame
*tf
= XFRAME (other_frame
);
7738 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7739 && !FRAME_MINIBUF_ONLY_P (tf
)
7740 && !EQ (other_frame
, tip_frame
)
7741 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7745 /* Set global variable indicating that multiple frames exist. */
7746 multiple_frames
= CONSP (tail
);
7748 /* Switch to the buffer of selected window of the frame. Set up
7749 frame_title_ptr so that display_mode_element will output into it;
7750 then display the title. */
7751 obuf
= current_buffer
;
7752 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7753 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7754 frame_title_ptr
= frame_title_buf
;
7755 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7756 NULL
, DEFAULT_FACE_ID
);
7757 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
7758 len
= frame_title_ptr
- frame_title_buf
;
7759 frame_title_ptr
= NULL
;
7760 set_buffer_internal_1 (obuf
);
7762 /* Set the title only if it's changed. This avoids consing in
7763 the common case where it hasn't. (If it turns out that we've
7764 already wasted too much time by walking through the list with
7765 display_mode_element, then we might need to optimize at a
7766 higher level than this.) */
7767 if (! STRINGP (f
->name
)
7768 || SBYTES (f
->name
) != len
7769 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7770 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7774 #endif /* not HAVE_WINDOW_SYSTEM */
7779 /***********************************************************************
7781 ***********************************************************************/
7784 /* Prepare for redisplay by updating menu-bar item lists when
7785 appropriate. This can call eval. */
7788 prepare_menu_bars ()
7791 struct gcpro gcpro1
, gcpro2
;
7793 Lisp_Object tooltip_frame
;
7795 #ifdef HAVE_WINDOW_SYSTEM
7796 tooltip_frame
= tip_frame
;
7798 tooltip_frame
= Qnil
;
7801 /* Update all frame titles based on their buffer names, etc. We do
7802 this before the menu bars so that the buffer-menu will show the
7803 up-to-date frame titles. */
7804 #ifdef HAVE_WINDOW_SYSTEM
7805 if (windows_or_buffers_changed
|| update_mode_lines
)
7807 Lisp_Object tail
, frame
;
7809 FOR_EACH_FRAME (tail
, frame
)
7812 if (!EQ (frame
, tooltip_frame
)
7813 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7814 x_consider_frame_title (frame
);
7817 #endif /* HAVE_WINDOW_SYSTEM */
7819 /* Update the menu bar item lists, if appropriate. This has to be
7820 done before any actual redisplay or generation of display lines. */
7821 all_windows
= (update_mode_lines
7822 || buffer_shared
> 1
7823 || windows_or_buffers_changed
);
7826 Lisp_Object tail
, frame
;
7827 int count
= SPECPDL_INDEX ();
7829 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7831 FOR_EACH_FRAME (tail
, frame
)
7835 /* Ignore tooltip frame. */
7836 if (EQ (frame
, tooltip_frame
))
7839 /* If a window on this frame changed size, report that to
7840 the user and clear the size-change flag. */
7841 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7843 Lisp_Object functions
;
7845 /* Clear flag first in case we get an error below. */
7846 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7847 functions
= Vwindow_size_change_functions
;
7848 GCPRO2 (tail
, functions
);
7850 while (CONSP (functions
))
7852 call1 (XCAR (functions
), frame
);
7853 functions
= XCDR (functions
);
7859 update_menu_bar (f
, 0);
7860 #ifdef HAVE_WINDOW_SYSTEM
7861 update_tool_bar (f
, 0);
7866 unbind_to (count
, Qnil
);
7870 struct frame
*sf
= SELECTED_FRAME ();
7871 update_menu_bar (sf
, 1);
7872 #ifdef HAVE_WINDOW_SYSTEM
7873 update_tool_bar (sf
, 1);
7877 /* Motif needs this. See comment in xmenu.c. Turn it off when
7878 pending_menu_activation is not defined. */
7879 #ifdef USE_X_TOOLKIT
7880 pending_menu_activation
= 0;
7885 /* Update the menu bar item list for frame F. This has to be done
7886 before we start to fill in any display lines, because it can call
7889 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7892 update_menu_bar (f
, save_match_data
)
7894 int save_match_data
;
7897 register struct window
*w
;
7899 /* If called recursively during a menu update, do nothing. This can
7900 happen when, for instance, an activate-menubar-hook causes a
7902 if (inhibit_menubar_update
)
7905 window
= FRAME_SELECTED_WINDOW (f
);
7906 w
= XWINDOW (window
);
7908 #if 0 /* The if statement below this if statement used to include the
7909 condition !NILP (w->update_mode_line), rather than using
7910 update_mode_lines directly, and this if statement may have
7911 been added to make that condition work. Now the if
7912 statement below matches its comment, this isn't needed. */
7913 if (update_mode_lines
)
7914 w
->update_mode_line
= Qt
;
7917 if (FRAME_WINDOW_P (f
)
7919 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
7920 || defined (USE_GTK)
7921 FRAME_EXTERNAL_MENU_BAR (f
)
7923 FRAME_MENU_BAR_LINES (f
) > 0
7925 : FRAME_MENU_BAR_LINES (f
) > 0)
7927 /* If the user has switched buffers or windows, we need to
7928 recompute to reflect the new bindings. But we'll
7929 recompute when update_mode_lines is set too; that means
7930 that people can use force-mode-line-update to request
7931 that the menu bar be recomputed. The adverse effect on
7932 the rest of the redisplay algorithm is about the same as
7933 windows_or_buffers_changed anyway. */
7934 if (windows_or_buffers_changed
7935 /* This used to test w->update_mode_line, but we believe
7936 there is no need to recompute the menu in that case. */
7937 || update_mode_lines
7938 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7939 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7940 != !NILP (w
->last_had_star
))
7941 || ((!NILP (Vtransient_mark_mode
)
7942 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7943 != !NILP (w
->region_showing
)))
7945 struct buffer
*prev
= current_buffer
;
7946 int count
= SPECPDL_INDEX ();
7948 specbind (Qinhibit_menubar_update
, Qt
);
7950 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7951 if (save_match_data
)
7952 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7953 if (NILP (Voverriding_local_map_menu_flag
))
7955 specbind (Qoverriding_terminal_local_map
, Qnil
);
7956 specbind (Qoverriding_local_map
, Qnil
);
7959 /* Run the Lucid hook. */
7960 safe_run_hooks (Qactivate_menubar_hook
);
7962 /* If it has changed current-menubar from previous value,
7963 really recompute the menu-bar from the value. */
7964 if (! NILP (Vlucid_menu_bar_dirty_flag
))
7965 call0 (Qrecompute_lucid_menubar
);
7967 safe_run_hooks (Qmenu_bar_update_hook
);
7968 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
7970 /* Redisplay the menu bar in case we changed it. */
7971 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
7972 || defined (USE_GTK)
7973 if (FRAME_WINDOW_P (f
)
7974 #if defined (MAC_OS)
7975 /* All frames on Mac OS share the same menubar. So only the
7976 selected frame should be allowed to set it. */
7977 && f
== SELECTED_FRAME ()
7980 set_frame_menubar (f
, 0, 0);
7982 /* On a terminal screen, the menu bar is an ordinary screen
7983 line, and this makes it get updated. */
7984 w
->update_mode_line
= Qt
;
7985 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
7986 /* In the non-toolkit version, the menu bar is an ordinary screen
7987 line, and this makes it get updated. */
7988 w
->update_mode_line
= Qt
;
7989 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
7991 unbind_to (count
, Qnil
);
7992 set_buffer_internal_1 (prev
);
7999 /***********************************************************************
8001 ***********************************************************************/
8003 #ifdef HAVE_WINDOW_SYSTEM
8006 Nominal cursor position -- where to draw output.
8007 HPOS and VPOS are window relative glyph matrix coordinates.
8008 X and Y are window relative pixel coordinates. */
8010 struct cursor_pos output_cursor
;
8014 Set the global variable output_cursor to CURSOR. All cursor
8015 positions are relative to updated_window. */
8018 set_output_cursor (cursor
)
8019 struct cursor_pos
*cursor
;
8021 output_cursor
.hpos
= cursor
->hpos
;
8022 output_cursor
.vpos
= cursor
->vpos
;
8023 output_cursor
.x
= cursor
->x
;
8024 output_cursor
.y
= cursor
->y
;
8029 Set a nominal cursor position.
8031 HPOS and VPOS are column/row positions in a window glyph matrix. X
8032 and Y are window text area relative pixel positions.
8034 If this is done during an update, updated_window will contain the
8035 window that is being updated and the position is the future output
8036 cursor position for that window. If updated_window is null, use
8037 selected_window and display the cursor at the given position. */
8040 x_cursor_to (vpos
, hpos
, y
, x
)
8041 int vpos
, hpos
, y
, x
;
8045 /* If updated_window is not set, work on selected_window. */
8049 w
= XWINDOW (selected_window
);
8051 /* Set the output cursor. */
8052 output_cursor
.hpos
= hpos
;
8053 output_cursor
.vpos
= vpos
;
8054 output_cursor
.x
= x
;
8055 output_cursor
.y
= y
;
8057 /* If not called as part of an update, really display the cursor.
8058 This will also set the cursor position of W. */
8059 if (updated_window
== NULL
)
8062 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8063 if (rif
->flush_display_optional
)
8064 rif
->flush_display_optional (SELECTED_FRAME ());
8069 #endif /* HAVE_WINDOW_SYSTEM */
8072 /***********************************************************************
8074 ***********************************************************************/
8076 #ifdef HAVE_WINDOW_SYSTEM
8078 /* Where the mouse was last time we reported a mouse event. */
8080 FRAME_PTR last_mouse_frame
;
8082 /* Tool-bar item index of the item on which a mouse button was pressed
8085 int last_tool_bar_item
;
8088 /* Update the tool-bar item list for frame F. This has to be done
8089 before we start to fill in any display lines. Called from
8090 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8091 and restore it here. */
8094 update_tool_bar (f
, save_match_data
)
8096 int save_match_data
;
8099 int do_update
= FRAME_EXTERNAL_TOOL_BAR(f
);
8101 int do_update
= WINDOWP (f
->tool_bar_window
)
8102 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0;
8110 window
= FRAME_SELECTED_WINDOW (f
);
8111 w
= XWINDOW (window
);
8113 /* If the user has switched buffers or windows, we need to
8114 recompute to reflect the new bindings. But we'll
8115 recompute when update_mode_lines is set too; that means
8116 that people can use force-mode-line-update to request
8117 that the menu bar be recomputed. The adverse effect on
8118 the rest of the redisplay algorithm is about the same as
8119 windows_or_buffers_changed anyway. */
8120 if (windows_or_buffers_changed
8121 || !NILP (w
->update_mode_line
)
8122 || update_mode_lines
8123 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8124 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8125 != !NILP (w
->last_had_star
))
8126 || ((!NILP (Vtransient_mark_mode
)
8127 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8128 != !NILP (w
->region_showing
)))
8130 struct buffer
*prev
= current_buffer
;
8131 int count
= SPECPDL_INDEX ();
8132 Lisp_Object old_tool_bar
;
8133 struct gcpro gcpro1
;
8135 /* Set current_buffer to the buffer of the selected
8136 window of the frame, so that we get the right local
8138 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8140 /* Save match data, if we must. */
8141 if (save_match_data
)
8142 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8144 /* Make sure that we don't accidentally use bogus keymaps. */
8145 if (NILP (Voverriding_local_map_menu_flag
))
8147 specbind (Qoverriding_terminal_local_map
, Qnil
);
8148 specbind (Qoverriding_local_map
, Qnil
);
8151 old_tool_bar
= f
->tool_bar_items
;
8152 GCPRO1 (old_tool_bar
);
8154 /* Build desired tool-bar items from keymaps. */
8156 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
8158 /* Redisplay the tool-bar if we changed it. */
8159 if (! NILP (Fequal (old_tool_bar
, f
->tool_bar_items
)))
8160 w
->update_mode_line
= Qt
;
8162 unbind_to (count
, Qnil
);
8163 set_buffer_internal_1 (prev
);
8169 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8170 F's desired tool-bar contents. F->tool_bar_items must have
8171 been set up previously by calling prepare_menu_bars. */
8174 build_desired_tool_bar_string (f
)
8177 int i
, size
, size_needed
;
8178 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8179 Lisp_Object image
, plist
, props
;
8181 image
= plist
= props
= Qnil
;
8182 GCPRO3 (image
, plist
, props
);
8184 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8185 Otherwise, make a new string. */
8187 /* The size of the string we might be able to reuse. */
8188 size
= (STRINGP (f
->desired_tool_bar_string
)
8189 ? SCHARS (f
->desired_tool_bar_string
)
8192 /* We need one space in the string for each image. */
8193 size_needed
= f
->n_tool_bar_items
;
8195 /* Reuse f->desired_tool_bar_string, if possible. */
8196 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8197 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8201 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8202 Fremove_text_properties (make_number (0), make_number (size
),
8203 props
, f
->desired_tool_bar_string
);
8206 /* Put a `display' property on the string for the images to display,
8207 put a `menu_item' property on tool-bar items with a value that
8208 is the index of the item in F's tool-bar item vector. */
8209 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8211 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8213 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8214 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8215 int hmargin
, vmargin
, relief
, idx
, end
;
8216 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
8218 /* If image is a vector, choose the image according to the
8220 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8221 if (VECTORP (image
))
8225 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8226 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8229 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8230 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8232 xassert (ASIZE (image
) >= idx
);
8233 image
= AREF (image
, idx
);
8238 /* Ignore invalid image specifications. */
8239 if (!valid_image_p (image
))
8242 /* Display the tool-bar button pressed, or depressed. */
8243 plist
= Fcopy_sequence (XCDR (image
));
8245 /* Compute margin and relief to draw. */
8246 relief
= (tool_bar_button_relief
>= 0
8247 ? tool_bar_button_relief
8248 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8249 hmargin
= vmargin
= relief
;
8251 if (INTEGERP (Vtool_bar_button_margin
)
8252 && XINT (Vtool_bar_button_margin
) > 0)
8254 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8255 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8257 else if (CONSP (Vtool_bar_button_margin
))
8259 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8260 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8261 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8263 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8264 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8265 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8268 if (auto_raise_tool_bar_buttons_p
)
8270 /* Add a `:relief' property to the image spec if the item is
8274 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8281 /* If image is selected, display it pressed, i.e. with a
8282 negative relief. If it's not selected, display it with a
8284 plist
= Fplist_put (plist
, QCrelief
,
8286 ? make_number (-relief
)
8287 : make_number (relief
)));
8292 /* Put a margin around the image. */
8293 if (hmargin
|| vmargin
)
8295 if (hmargin
== vmargin
)
8296 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8298 plist
= Fplist_put (plist
, QCmargin
,
8299 Fcons (make_number (hmargin
),
8300 make_number (vmargin
)));
8303 /* If button is not enabled, and we don't have special images
8304 for the disabled state, make the image appear disabled by
8305 applying an appropriate algorithm to it. */
8306 if (!enabled_p
&& idx
< 0)
8307 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8309 /* Put a `display' text property on the string for the image to
8310 display. Put a `menu-item' property on the string that gives
8311 the start of this item's properties in the tool-bar items
8313 image
= Fcons (Qimage
, plist
);
8314 props
= list4 (Qdisplay
, image
,
8315 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8317 /* Let the last image hide all remaining spaces in the tool bar
8318 string. The string can be longer than needed when we reuse a
8320 if (i
+ 1 == f
->n_tool_bar_items
)
8321 end
= SCHARS (f
->desired_tool_bar_string
);
8324 Fadd_text_properties (make_number (i
), make_number (end
),
8325 props
, f
->desired_tool_bar_string
);
8333 /* Display one line of the tool-bar of frame IT->f. */
8336 display_tool_bar_line (it
)
8339 struct glyph_row
*row
= it
->glyph_row
;
8340 int max_x
= it
->last_visible_x
;
8343 prepare_desired_row (row
);
8344 row
->y
= it
->current_y
;
8346 /* Note that this isn't made use of if the face hasn't a box,
8347 so there's no need to check the face here. */
8348 it
->start_of_box_run_p
= 1;
8350 while (it
->current_x
< max_x
)
8352 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8354 /* Get the next display element. */
8355 if (!get_next_display_element (it
))
8358 /* Produce glyphs. */
8359 x_before
= it
->current_x
;
8360 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8361 PRODUCE_GLYPHS (it
);
8363 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8368 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8370 if (x
+ glyph
->pixel_width
> max_x
)
8372 /* Glyph doesn't fit on line. */
8373 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8379 x
+= glyph
->pixel_width
;
8383 /* Stop at line ends. */
8384 if (ITERATOR_AT_END_OF_LINE_P (it
))
8387 set_iterator_to_next (it
, 1);
8392 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8393 extend_face_to_end_of_line (it
);
8394 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8395 last
->right_box_line_p
= 1;
8396 if (last
== row
->glyphs
[TEXT_AREA
])
8397 last
->left_box_line_p
= 1;
8398 compute_line_metrics (it
);
8400 /* If line is empty, make it occupy the rest of the tool-bar. */
8401 if (!row
->displays_text_p
)
8403 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8404 row
->ascent
= row
->phys_ascent
= 0;
8407 row
->full_width_p
= 1;
8408 row
->continued_p
= 0;
8409 row
->truncated_on_left_p
= 0;
8410 row
->truncated_on_right_p
= 0;
8412 it
->current_x
= it
->hpos
= 0;
8413 it
->current_y
+= row
->height
;
8419 /* Value is the number of screen lines needed to make all tool-bar
8420 items of frame F visible. */
8423 tool_bar_lines_needed (f
)
8426 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8429 /* Initialize an iterator for iteration over
8430 F->desired_tool_bar_string in the tool-bar window of frame F. */
8431 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8432 it
.first_visible_x
= 0;
8433 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
8434 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8436 while (!ITERATOR_AT_END_P (&it
))
8438 it
.glyph_row
= w
->desired_matrix
->rows
;
8439 clear_glyph_row (it
.glyph_row
);
8440 display_tool_bar_line (&it
);
8443 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
8447 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8449 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8458 frame
= selected_frame
;
8460 CHECK_FRAME (frame
);
8463 if (WINDOWP (f
->tool_bar_window
)
8464 || (w
= XWINDOW (f
->tool_bar_window
),
8465 XFASTINT (w
->height
) > 0))
8467 update_tool_bar (f
, 1);
8468 if (f
->n_tool_bar_items
)
8470 build_desired_tool_bar_string (f
);
8471 nlines
= tool_bar_lines_needed (f
);
8475 return make_number (nlines
);
8479 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8480 height should be changed. */
8483 redisplay_tool_bar (f
)
8488 struct glyph_row
*row
;
8489 int change_height_p
= 0;
8492 if (FRAME_EXTERNAL_TOOL_BAR(f
))
8493 update_frame_tool_bar (f
);
8497 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8498 do anything. This means you must start with tool-bar-lines
8499 non-zero to get the auto-sizing effect. Or in other words, you
8500 can turn off tool-bars by specifying tool-bar-lines zero. */
8501 if (!WINDOWP (f
->tool_bar_window
)
8502 || (w
= XWINDOW (f
->tool_bar_window
),
8503 XFASTINT (w
->height
) == 0))
8506 /* Set up an iterator for the tool-bar window. */
8507 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8508 it
.first_visible_x
= 0;
8509 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
8512 /* Build a string that represents the contents of the tool-bar. */
8513 build_desired_tool_bar_string (f
);
8514 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8516 /* Display as many lines as needed to display all tool-bar items. */
8517 while (it
.current_y
< it
.last_visible_y
)
8518 display_tool_bar_line (&it
);
8520 /* It doesn't make much sense to try scrolling in the tool-bar
8521 window, so don't do it. */
8522 w
->desired_matrix
->no_scrolling_p
= 1;
8523 w
->must_be_updated_p
= 1;
8525 if (auto_resize_tool_bars_p
)
8529 /* If we couldn't display everything, change the tool-bar's
8531 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8532 change_height_p
= 1;
8534 /* If there are blank lines at the end, except for a partially
8535 visible blank line at the end that is smaller than
8536 CANON_Y_UNIT, change the tool-bar's height. */
8537 row
= it
.glyph_row
- 1;
8538 if (!row
->displays_text_p
8539 && row
->height
>= CANON_Y_UNIT (f
))
8540 change_height_p
= 1;
8542 /* If row displays tool-bar items, but is partially visible,
8543 change the tool-bar's height. */
8544 if (row
->displays_text_p
8545 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8546 change_height_p
= 1;
8548 /* Resize windows as needed by changing the `tool-bar-lines'
8551 && (nlines
= tool_bar_lines_needed (f
),
8552 nlines
!= XFASTINT (w
->height
)))
8554 extern Lisp_Object Qtool_bar_lines
;
8556 int old_height
= XFASTINT (w
->height
);
8558 XSETFRAME (frame
, f
);
8559 clear_glyph_matrix (w
->desired_matrix
);
8560 Fmodify_frame_parameters (frame
,
8561 Fcons (Fcons (Qtool_bar_lines
,
8562 make_number (nlines
)),
8564 if (XFASTINT (w
->height
) != old_height
)
8565 fonts_changed_p
= 1;
8569 return change_height_p
;
8573 /* Get information about the tool-bar item which is displayed in GLYPH
8574 on frame F. Return in *PROP_IDX the index where tool-bar item
8575 properties start in F->tool_bar_items. Value is zero if
8576 GLYPH doesn't display a tool-bar item. */
8579 tool_bar_item_info (f
, glyph
, prop_idx
)
8581 struct glyph
*glyph
;
8588 /* This function can be called asynchronously, which means we must
8589 exclude any possibility that Fget_text_property signals an
8591 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8592 charpos
= max (0, charpos
);
8594 /* Get the text property `menu-item' at pos. The value of that
8595 property is the start index of this item's properties in
8596 F->tool_bar_items. */
8597 prop
= Fget_text_property (make_number (charpos
),
8598 Qmenu_item
, f
->current_tool_bar_string
);
8599 if (INTEGERP (prop
))
8601 *prop_idx
= XINT (prop
);
8611 /* Get information about the tool-bar item at position X/Y on frame F.
8612 Return in *GLYPH a pointer to the glyph of the tool-bar item in
8613 the current matrix of the tool-bar window of F, or NULL if not
8614 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
8615 item in F->tool_bar_items. Value is
8617 -1 if X/Y is not on a tool-bar item
8618 0 if X/Y is on the same item that was highlighted before.
8622 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
8625 struct glyph
**glyph
;
8626 int *hpos
, *vpos
, *prop_idx
;
8628 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8629 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8632 /* Find the glyph under X/Y. */
8633 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
8637 /* Get the start of this tool-bar item's properties in
8638 f->tool_bar_items. */
8639 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
8642 /* Is mouse on the highlighted item? */
8643 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
8644 && *vpos
>= dpyinfo
->mouse_face_beg_row
8645 && *vpos
<= dpyinfo
->mouse_face_end_row
8646 && (*vpos
> dpyinfo
->mouse_face_beg_row
8647 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
8648 && (*vpos
< dpyinfo
->mouse_face_end_row
8649 || *hpos
< dpyinfo
->mouse_face_end_col
8650 || dpyinfo
->mouse_face_past_end
))
8658 Handle mouse button event on the tool-bar of frame F, at
8659 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
8660 0 for button release. MODIFIERS is event modifiers for button
8664 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
8667 unsigned int modifiers
;
8669 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8670 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8671 int hpos
, vpos
, prop_idx
;
8672 struct glyph
*glyph
;
8673 Lisp_Object enabled_p
;
8675 /* If not on the highlighted tool-bar item, return. */
8676 frame_to_window_pixel_xy (w
, &x
, &y
);
8677 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
8680 /* If item is disabled, do nothing. */
8681 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8682 if (NILP (enabled_p
))
8687 /* Show item in pressed state. */
8688 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
8689 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
8690 last_tool_bar_item
= prop_idx
;
8694 Lisp_Object key
, frame
;
8695 struct input_event event
;
8697 /* Show item in released state. */
8698 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
8699 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
8701 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
8703 XSETFRAME (frame
, f
);
8704 event
.kind
= TOOL_BAR_EVENT
;
8705 event
.frame_or_window
= frame
;
8707 kbd_buffer_store_event (&event
);
8709 event
.kind
= TOOL_BAR_EVENT
;
8710 event
.frame_or_window
= frame
;
8712 event
.modifiers
= modifiers
;
8713 kbd_buffer_store_event (&event
);
8714 last_tool_bar_item
= -1;
8719 /* Possibly highlight a tool-bar item on frame F when mouse moves to
8720 tool-bar window-relative coordinates X/Y. Called from
8721 note_mouse_highlight. */
8724 note_tool_bar_highlight (f
, x
, y
)
8728 Lisp_Object window
= f
->tool_bar_window
;
8729 struct window
*w
= XWINDOW (window
);
8730 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8732 struct glyph
*glyph
;
8733 struct glyph_row
*row
;
8735 Lisp_Object enabled_p
;
8737 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
8738 int mouse_down_p
, rc
;
8740 /* Function note_mouse_highlight is called with negative x(y
8741 values when mouse moves outside of the frame. */
8742 if (x
<= 0 || y
<= 0)
8744 clear_mouse_face (dpyinfo
);
8748 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
8751 /* Not on tool-bar item. */
8752 clear_mouse_face (dpyinfo
);
8756 /* On same tool-bar item as before. */
8759 clear_mouse_face (dpyinfo
);
8761 /* Mouse is down, but on different tool-bar item? */
8762 mouse_down_p
= (dpyinfo
->grabbed
8763 && f
== last_mouse_frame
8764 && FRAME_LIVE_P (f
));
8766 && last_tool_bar_item
!= prop_idx
)
8769 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
8770 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
8772 /* If tool-bar item is not enabled, don't highlight it. */
8773 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8774 if (!NILP (enabled_p
))
8776 /* Compute the x-position of the glyph. In front and past the
8777 image is a space. We include this is the highlighted area. */
8778 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
8779 for (i
= x
= 0; i
< hpos
; ++i
)
8780 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
8782 /* Record this as the current active region. */
8783 dpyinfo
->mouse_face_beg_col
= hpos
;
8784 dpyinfo
->mouse_face_beg_row
= vpos
;
8785 dpyinfo
->mouse_face_beg_x
= x
;
8786 dpyinfo
->mouse_face_beg_y
= row
->y
;
8787 dpyinfo
->mouse_face_past_end
= 0;
8789 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
8790 dpyinfo
->mouse_face_end_row
= vpos
;
8791 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
8792 dpyinfo
->mouse_face_end_y
= row
->y
;
8793 dpyinfo
->mouse_face_window
= window
;
8794 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
8796 /* Display it as active. */
8797 show_mouse_face (dpyinfo
, draw
);
8798 dpyinfo
->mouse_face_image_state
= draw
;
8803 /* Set help_echo_string to a help string to display for this tool-bar item.
8804 XTread_socket does the rest. */
8805 help_echo_object
= help_echo_window
= Qnil
;
8807 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
8808 if (NILP (help_echo_string
))
8809 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
8812 #endif /* HAVE_WINDOW_SYSTEM */
8816 /***********************************************************************
8818 ***********************************************************************/
8820 #ifdef HAVE_WINDOW_SYSTEM
8822 /* An arrow like this: `<-'. */
8823 static unsigned char left_bits
[] = {
8824 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
8826 /* Right truncation arrow bitmap `->'. */
8827 static unsigned char right_bits
[] = {
8828 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
8830 /* Marker for continued lines. */
8831 static unsigned char continued_bits
[] = {
8832 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
8834 /* Marker for continuation lines. */
8835 static unsigned char continuation_bits
[] = {
8836 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
8838 /* Overlay arrow bitmap. A triangular arrow. */
8839 static unsigned char ov_bits
[] = {
8840 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
8842 /* Bitmap drawn to indicate lines not displaying text if
8843 `indicate-empty-lines' is non-nil. */
8844 static unsigned char zv_bits
[] = {
8845 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8846 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8847 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8848 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8849 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8850 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8851 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8852 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
8854 struct fringe_bitmap fringe_bitmaps
[MAX_FRINGE_BITMAPS
] =
8856 { 0, 0, 0, NULL
/* NO_FRINGE_BITMAP */ },
8857 { 8, sizeof (left_bits
), 0, left_bits
},
8858 { 8, sizeof (right_bits
), 0, right_bits
},
8859 { 8, sizeof (continued_bits
), 0, continued_bits
},
8860 { 8, sizeof (continuation_bits
), 0, continuation_bits
},
8861 { 8, sizeof (ov_bits
), 0, ov_bits
},
8862 { 8, sizeof (zv_bits
), 3, zv_bits
}
8866 /* Draw the bitmap WHICH in one of the left or right fringes of
8867 window W. ROW is the glyph row for which to display the bitmap; it
8868 determines the vertical position at which the bitmap has to be
8872 draw_fringe_bitmap (w
, row
, which
, left_p
)
8874 struct glyph_row
*row
;
8875 enum fringe_bitmap_type which
;
8878 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8879 struct draw_fringe_bitmap_params p
;
8881 /* Convert row to frame coordinates. */
8882 p
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
8885 p
.wd
= fringe_bitmaps
[which
].width
;
8887 p
.h
= fringe_bitmaps
[which
].height
;
8888 p
.dh
= (fringe_bitmaps
[which
].period
8889 ? (p
.y
% fringe_bitmaps
[which
].period
)
8892 /* Clip bitmap if too high. */
8893 if (p
.h
> row
->height
)
8896 p
.face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
8897 PREPARE_FACE_FOR_DISPLAY (f
, p
.face
);
8899 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
8904 if (p
.wd
> FRAME_X_LEFT_FRINGE_WIDTH (f
))
8905 p
.wd
= FRAME_X_LEFT_FRINGE_WIDTH (f
);
8906 p
.x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
8908 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - p
.wd
) / 2);
8909 if (p
.wd
< FRAME_X_LEFT_FRINGE_WIDTH (f
) || row
->height
> p
.h
)
8911 /* If W has a vertical border to its left, don't draw over it. */
8912 int border
= ((XFASTINT (w
->left
) > 0
8913 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8915 p
.bx
= (window_box_left (w
, -1)
8916 - FRAME_X_LEFT_FRINGE_WIDTH (f
)
8918 p
.nx
= (FRAME_X_LEFT_FRINGE_WIDTH (f
) - border
);
8923 if (p
.wd
> FRAME_X_RIGHT_FRINGE_WIDTH (f
))
8924 p
.wd
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
8925 p
.x
= (window_box_right (w
, -1)
8926 + (FRAME_X_RIGHT_FRINGE_WIDTH (f
) - p
.wd
) / 2);
8927 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
8929 if (p
.wd
< FRAME_X_RIGHT_FRINGE_WIDTH (f
) || row
->height
> p
.h
)
8931 p
.bx
= window_box_right (w
, -1);
8932 p
.nx
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
8938 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
8940 p
.by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, row
->y
));
8941 p
.ny
= row
->visible_height
;
8944 /* Adjust y to the offset in the row to start drawing the bitmap. */
8945 p
.y
+= (row
->height
- p
.h
) / 2;
8947 rif
->draw_fringe_bitmap (w
, row
, &p
);
8950 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
8951 function with input blocked. */
8954 draw_row_fringe_bitmaps (w
, row
)
8956 struct glyph_row
*row
;
8958 struct frame
*f
= XFRAME (w
->frame
);
8959 enum fringe_bitmap_type bitmap
;
8961 xassert (interrupt_input_blocked
);
8963 /* If row is completely invisible, because of vscrolling, we
8964 don't have to draw anything. */
8965 if (row
->visible_height
<= 0)
8968 if (FRAME_X_LEFT_FRINGE_WIDTH (f
) != 0)
8970 /* Decide which bitmap to draw in the left fringe. */
8971 if (row
->overlay_arrow_p
)
8972 bitmap
= OVERLAY_ARROW_BITMAP
;
8973 else if (row
->truncated_on_left_p
)
8974 bitmap
= LEFT_TRUNCATION_BITMAP
;
8975 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
8976 bitmap
= CONTINUATION_LINE_BITMAP
;
8977 else if (row
->indicate_empty_line_p
)
8978 bitmap
= ZV_LINE_BITMAP
;
8980 bitmap
= NO_FRINGE_BITMAP
;
8982 draw_fringe_bitmap (w
, row
, bitmap
, 1);
8985 if (FRAME_X_RIGHT_FRINGE_WIDTH (f
) != 0)
8987 /* Decide which bitmap to draw in the right fringe. */
8988 if (row
->truncated_on_right_p
)
8989 bitmap
= RIGHT_TRUNCATION_BITMAP
;
8990 else if (row
->continued_p
)
8991 bitmap
= CONTINUED_LINE_BITMAP
;
8992 else if (row
->indicate_empty_line_p
&& FRAME_X_LEFT_FRINGE_WIDTH (f
) == 0)
8993 bitmap
= ZV_LINE_BITMAP
;
8995 bitmap
= NO_FRINGE_BITMAP
;
8997 draw_fringe_bitmap (w
, row
, bitmap
, 0);
9002 /* Compute actual fringe widths */
9005 compute_fringe_widths (f
, redraw
)
9009 int o_left
= FRAME_X_LEFT_FRINGE_WIDTH (f
);
9010 int o_right
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
9011 int o_cols
= FRAME_X_FRINGE_COLS (f
);
9013 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
9014 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
9015 int left_fringe_width
, right_fringe_width
;
9017 if (!NILP (left_fringe
))
9018 left_fringe
= Fcdr (left_fringe
);
9019 if (!NILP (right_fringe
))
9020 right_fringe
= Fcdr (right_fringe
);
9022 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
9023 XINT (left_fringe
));
9024 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
9025 XINT (right_fringe
));
9027 if (left_fringe_width
|| right_fringe_width
)
9029 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
9030 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
9031 int conf_wid
= left_wid
+ right_wid
;
9032 int font_wid
= FONT_WIDTH (FRAME_FONT (f
));
9033 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
9034 int real_wid
= cols
* font_wid
;
9035 if (left_wid
&& right_wid
)
9037 if (left_fringe_width
< 0)
9039 /* Left fringe width is fixed, adjust right fringe if necessary */
9040 FRAME_X_LEFT_FRINGE_WIDTH (f
) = left_wid
;
9041 FRAME_X_RIGHT_FRINGE_WIDTH (f
) = real_wid
- left_wid
;
9043 else if (right_fringe_width
< 0)
9045 /* Right fringe width is fixed, adjust left fringe if necessary */
9046 FRAME_X_LEFT_FRINGE_WIDTH (f
) = real_wid
- right_wid
;
9047 FRAME_X_RIGHT_FRINGE_WIDTH (f
) = right_wid
;
9051 /* Adjust both fringes with an equal amount.
9052 Note that we are doing integer arithmetic here, so don't
9053 lose a pixel if the total width is an odd number. */
9054 int fill
= real_wid
- conf_wid
;
9055 FRAME_X_LEFT_FRINGE_WIDTH (f
) = left_wid
+ fill
/2;
9056 FRAME_X_RIGHT_FRINGE_WIDTH (f
) = right_wid
+ fill
- fill
/2;
9059 else if (left_fringe_width
)
9061 FRAME_X_LEFT_FRINGE_WIDTH (f
) = real_wid
;
9062 FRAME_X_RIGHT_FRINGE_WIDTH (f
) = 0;
9066 FRAME_X_LEFT_FRINGE_WIDTH (f
) = 0;
9067 FRAME_X_RIGHT_FRINGE_WIDTH (f
) = real_wid
;
9069 FRAME_X_FRINGE_COLS (f
) = cols
;
9070 FRAME_X_FRINGE_WIDTH (f
) = real_wid
;
9074 FRAME_X_LEFT_FRINGE_WIDTH (f
) = 0;
9075 FRAME_X_RIGHT_FRINGE_WIDTH (f
) = 0;
9076 FRAME_X_FRINGE_COLS (f
) = 0;
9077 FRAME_X_FRINGE_WIDTH (f
) = 0;
9080 if (redraw
&& FRAME_VISIBLE_P (f
))
9081 if (o_left
!= FRAME_X_LEFT_FRINGE_WIDTH (f
) ||
9082 o_right
!= FRAME_X_RIGHT_FRINGE_WIDTH (f
) ||
9083 o_cols
!= FRAME_X_FRINGE_COLS (f
))
9087 #endif /* HAVE_WINDOW_SYSTEM */
9091 /************************************************************************
9092 Horizontal scrolling
9093 ************************************************************************/
9095 static int hscroll_window_tree
P_ ((Lisp_Object
));
9096 static int hscroll_windows
P_ ((Lisp_Object
));
9098 /* For all leaf windows in the window tree rooted at WINDOW, set their
9099 hscroll value so that PT is (i) visible in the window, and (ii) so
9100 that it is not within a certain margin at the window's left and
9101 right border. Value is non-zero if any window's hscroll has been
9105 hscroll_window_tree (window
)
9108 int hscrolled_p
= 0;
9109 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9110 int hscroll_step_abs
= 0;
9111 double hscroll_step_rel
= 0;
9113 if (hscroll_relative_p
)
9115 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9116 if (hscroll_step_rel
< 0)
9118 hscroll_relative_p
= 0;
9119 hscroll_step_abs
= 0;
9122 else if (INTEGERP (Vhscroll_step
))
9124 hscroll_step_abs
= XINT (Vhscroll_step
);
9125 if (hscroll_step_abs
< 0)
9126 hscroll_step_abs
= 0;
9129 hscroll_step_abs
= 0;
9131 while (WINDOWP (window
))
9133 struct window
*w
= XWINDOW (window
);
9135 if (WINDOWP (w
->hchild
))
9136 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9137 else if (WINDOWP (w
->vchild
))
9138 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9139 else if (w
->cursor
.vpos
>= 0)
9141 int h_margin
, text_area_x
, text_area_y
;
9142 int text_area_width
, text_area_height
;
9143 struct glyph_row
*current_cursor_row
9144 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9145 struct glyph_row
*desired_cursor_row
9146 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9147 struct glyph_row
*cursor_row
9148 = (desired_cursor_row
->enabled_p
9149 ? desired_cursor_row
9150 : current_cursor_row
);
9152 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
9153 &text_area_width
, &text_area_height
);
9155 /* Scroll when cursor is inside this scroll margin. */
9156 h_margin
= hscroll_margin
* CANON_X_UNIT (XFRAME (w
->frame
));
9158 if ((XFASTINT (w
->hscroll
)
9159 && w
->cursor
.x
<= h_margin
)
9160 || (cursor_row
->enabled_p
9161 && cursor_row
->truncated_on_right_p
9162 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9166 struct buffer
*saved_current_buffer
;
9170 /* Find point in a display of infinite width. */
9171 saved_current_buffer
= current_buffer
;
9172 current_buffer
= XBUFFER (w
->buffer
);
9174 if (w
== XWINDOW (selected_window
))
9175 pt
= BUF_PT (current_buffer
);
9178 pt
= marker_position (w
->pointm
);
9179 pt
= max (BEGV
, pt
);
9183 /* Move iterator to pt starting at cursor_row->start in
9184 a line with infinite width. */
9185 init_to_row_start (&it
, w
, cursor_row
);
9186 it
.last_visible_x
= INFINITY
;
9187 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9188 current_buffer
= saved_current_buffer
;
9190 /* Position cursor in window. */
9191 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9192 hscroll
= max (0, it
.current_x
- text_area_width
/ 2)
9193 / CANON_X_UNIT (it
.f
);
9194 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9196 if (hscroll_relative_p
)
9197 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9200 wanted_x
= text_area_width
9201 - hscroll_step_abs
* CANON_X_UNIT (it
.f
)
9204 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
9208 if (hscroll_relative_p
)
9209 wanted_x
= text_area_width
* hscroll_step_rel
9212 wanted_x
= hscroll_step_abs
* CANON_X_UNIT (it
.f
)
9215 = max (0, it
.current_x
- wanted_x
) / CANON_X_UNIT (it
.f
);
9217 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9219 /* Don't call Fset_window_hscroll if value hasn't
9220 changed because it will prevent redisplay
9222 if (XFASTINT (w
->hscroll
) != hscroll
)
9224 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9225 w
->hscroll
= make_number (hscroll
);
9234 /* Value is non-zero if hscroll of any leaf window has been changed. */
9239 /* Set hscroll so that cursor is visible and not inside horizontal
9240 scroll margins for all windows in the tree rooted at WINDOW. See
9241 also hscroll_window_tree above. Value is non-zero if any window's
9242 hscroll has been changed. If it has, desired matrices on the frame
9243 of WINDOW are cleared. */
9246 hscroll_windows (window
)
9251 if (automatic_hscrolling_p
)
9253 hscrolled_p
= hscroll_window_tree (window
);
9255 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9264 /************************************************************************
9266 ************************************************************************/
9268 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9269 to a non-zero value. This is sometimes handy to have in a debugger
9274 /* First and last unchanged row for try_window_id. */
9276 int debug_first_unchanged_at_end_vpos
;
9277 int debug_last_unchanged_at_beg_vpos
;
9279 /* Delta vpos and y. */
9281 int debug_dvpos
, debug_dy
;
9283 /* Delta in characters and bytes for try_window_id. */
9285 int debug_delta
, debug_delta_bytes
;
9287 /* Values of window_end_pos and window_end_vpos at the end of
9290 EMACS_INT debug_end_pos
, debug_end_vpos
;
9292 /* Append a string to W->desired_matrix->method. FMT is a printf
9293 format string. A1...A9 are a supplement for a variable-length
9294 argument list. If trace_redisplay_p is non-zero also printf the
9295 resulting string to stderr. */
9298 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9301 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9304 char *method
= w
->desired_matrix
->method
;
9305 int len
= strlen (method
);
9306 int size
= sizeof w
->desired_matrix
->method
;
9307 int remaining
= size
- len
- 1;
9309 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9310 if (len
&& remaining
)
9316 strncpy (method
+ len
, buffer
, remaining
);
9318 if (trace_redisplay_p
)
9319 fprintf (stderr
, "%p (%s): %s\n",
9321 ((BUFFERP (w
->buffer
)
9322 && STRINGP (XBUFFER (w
->buffer
)->name
))
9323 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9328 #endif /* GLYPH_DEBUG */
9331 /* Value is non-zero if all changes in window W, which displays
9332 current_buffer, are in the text between START and END. START is a
9333 buffer position, END is given as a distance from Z. Used in
9334 redisplay_internal for display optimization. */
9337 text_outside_line_unchanged_p (w
, start
, end
)
9341 int unchanged_p
= 1;
9343 /* If text or overlays have changed, see where. */
9344 if (XFASTINT (w
->last_modified
) < MODIFF
9345 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9347 /* Gap in the line? */
9348 if (GPT
< start
|| Z
- GPT
< end
)
9351 /* Changes start in front of the line, or end after it? */
9353 && (BEG_UNCHANGED
< start
- 1
9354 || END_UNCHANGED
< end
))
9357 /* If selective display, can't optimize if changes start at the
9358 beginning of the line. */
9360 && INTEGERP (current_buffer
->selective_display
)
9361 && XINT (current_buffer
->selective_display
) > 0
9362 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9365 /* If there are overlays at the start or end of the line, these
9366 may have overlay strings with newlines in them. A change at
9367 START, for instance, may actually concern the display of such
9368 overlay strings as well, and they are displayed on different
9369 lines. So, quickly rule out this case. (For the future, it
9370 might be desirable to implement something more telling than
9371 just BEG/END_UNCHANGED.) */
9374 if (BEG
+ BEG_UNCHANGED
== start
9375 && overlay_touches_p (start
))
9377 if (END_UNCHANGED
== end
9378 && overlay_touches_p (Z
- end
))
9387 /* Do a frame update, taking possible shortcuts into account. This is
9388 the main external entry point for redisplay.
9390 If the last redisplay displayed an echo area message and that message
9391 is no longer requested, we clear the echo area or bring back the
9392 mini-buffer if that is in use. */
9397 redisplay_internal (0);
9401 /* Return 1 if point moved out of or into a composition. Otherwise
9402 return 0. PREV_BUF and PREV_PT are the last point buffer and
9403 position. BUF and PT are the current point buffer and position. */
9406 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9407 struct buffer
*prev_buf
, *buf
;
9414 XSETBUFFER (buffer
, buf
);
9415 /* Check a composition at the last point if point moved within the
9417 if (prev_buf
== buf
)
9420 /* Point didn't move. */
9423 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9424 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9425 && COMPOSITION_VALID_P (start
, end
, prop
)
9426 && start
< prev_pt
&& end
> prev_pt
)
9427 /* The last point was within the composition. Return 1 iff
9428 point moved out of the composition. */
9429 return (pt
<= start
|| pt
>= end
);
9432 /* Check a composition at the current point. */
9433 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9434 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9435 && COMPOSITION_VALID_P (start
, end
, prop
)
9436 && start
< pt
&& end
> pt
);
9440 /* Reconsider the setting of B->clip_changed which is displayed
9444 reconsider_clip_changes (w
, b
)
9449 && !NILP (w
->window_end_valid
)
9450 && w
->current_matrix
->buffer
== b
9451 && w
->current_matrix
->zv
== BUF_ZV (b
)
9452 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9453 b
->clip_changed
= 0;
9455 /* If display wasn't paused, and W is not a tool bar window, see if
9456 point has been moved into or out of a composition. In that case,
9457 we set b->clip_changed to 1 to force updating the screen. If
9458 b->clip_changed has already been set to 1, we can skip this
9460 if (!b
->clip_changed
9461 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9465 if (w
== XWINDOW (selected_window
))
9466 pt
= BUF_PT (current_buffer
);
9468 pt
= marker_position (w
->pointm
);
9470 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9471 || pt
!= XINT (w
->last_point
))
9472 && check_point_in_composition (w
->current_matrix
->buffer
,
9473 XINT (w
->last_point
),
9474 XBUFFER (w
->buffer
), pt
))
9475 b
->clip_changed
= 1;
9479 #define STOP_POLLING \
9480 do { if (! polling_stopped_here) stop_polling (); \
9481 polling_stopped_here = 1; } while (0)
9483 #define RESUME_POLLING \
9484 do { if (polling_stopped_here) start_polling (); \
9485 polling_stopped_here = 0; } while (0)
9488 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9489 response to any user action; therefore, we should preserve the echo
9490 area. (Actually, our caller does that job.) Perhaps in the future
9491 avoid recentering windows if it is not necessary; currently that
9492 causes some problems. */
9495 redisplay_internal (preserve_echo_area
)
9496 int preserve_echo_area
;
9498 struct window
*w
= XWINDOW (selected_window
);
9499 struct frame
*f
= XFRAME (w
->frame
);
9501 int must_finish
= 0;
9502 struct text_pos tlbufpos
, tlendpos
;
9503 int number_of_visible_frames
;
9505 struct frame
*sf
= SELECTED_FRAME ();
9506 int polling_stopped_here
= 0;
9508 /* Non-zero means redisplay has to consider all windows on all
9509 frames. Zero means, only selected_window is considered. */
9510 int consider_all_windows_p
;
9512 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9514 /* No redisplay if running in batch mode or frame is not yet fully
9515 initialized, or redisplay is explicitly turned off by setting
9516 Vinhibit_redisplay. */
9518 || !NILP (Vinhibit_redisplay
)
9519 || !f
->glyphs_initialized_p
)
9522 /* The flag redisplay_performed_directly_p is set by
9523 direct_output_for_insert when it already did the whole screen
9524 update necessary. */
9525 if (redisplay_performed_directly_p
)
9527 redisplay_performed_directly_p
= 0;
9528 if (!hscroll_windows (selected_window
))
9532 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9533 if (popup_activated ())
9537 /* I don't think this happens but let's be paranoid. */
9541 /* Record a function that resets redisplaying_p to its old value
9542 when we leave this function. */
9543 count
= SPECPDL_INDEX ();
9544 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
9546 specbind (Qinhibit_free_realized_faces
, Qnil
);
9550 reconsider_clip_changes (w
, current_buffer
);
9552 /* If new fonts have been loaded that make a glyph matrix adjustment
9553 necessary, do it. */
9554 if (fonts_changed_p
)
9556 adjust_glyphs (NULL
);
9557 ++windows_or_buffers_changed
;
9558 fonts_changed_p
= 0;
9561 /* If face_change_count is non-zero, init_iterator will free all
9562 realized faces, which includes the faces referenced from current
9563 matrices. So, we can't reuse current matrices in this case. */
9564 if (face_change_count
)
9565 ++windows_or_buffers_changed
;
9567 if (! FRAME_WINDOW_P (sf
)
9568 && previous_terminal_frame
!= sf
)
9570 /* Since frames on an ASCII terminal share the same display
9571 area, displaying a different frame means redisplay the whole
9573 windows_or_buffers_changed
++;
9574 SET_FRAME_GARBAGED (sf
);
9575 XSETFRAME (Vterminal_frame
, sf
);
9577 previous_terminal_frame
= sf
;
9579 /* Set the visible flags for all frames. Do this before checking
9580 for resized or garbaged frames; they want to know if their frames
9581 are visible. See the comment in frame.h for
9582 FRAME_SAMPLE_VISIBILITY. */
9584 Lisp_Object tail
, frame
;
9586 number_of_visible_frames
= 0;
9588 FOR_EACH_FRAME (tail
, frame
)
9590 struct frame
*f
= XFRAME (frame
);
9592 FRAME_SAMPLE_VISIBILITY (f
);
9593 if (FRAME_VISIBLE_P (f
))
9594 ++number_of_visible_frames
;
9595 clear_desired_matrices (f
);
9599 /* Notice any pending interrupt request to change frame size. */
9600 do_pending_window_change (1);
9602 /* Clear frames marked as garbaged. */
9604 clear_garbaged_frames ();
9606 /* Build menubar and tool-bar items. */
9607 prepare_menu_bars ();
9609 if (windows_or_buffers_changed
)
9610 update_mode_lines
++;
9612 /* Detect case that we need to write or remove a star in the mode line. */
9613 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
9615 w
->update_mode_line
= Qt
;
9616 if (buffer_shared
> 1)
9617 update_mode_lines
++;
9620 /* If %c is in the mode line, update it if needed. */
9621 if (!NILP (w
->column_number_displayed
)
9622 /* This alternative quickly identifies a common case
9623 where no change is needed. */
9624 && !(PT
== XFASTINT (w
->last_point
)
9625 && XFASTINT (w
->last_modified
) >= MODIFF
9626 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9627 && (XFASTINT (w
->column_number_displayed
)
9628 != (int) current_column ())) /* iftc */
9629 w
->update_mode_line
= Qt
;
9631 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
9633 /* The variable buffer_shared is set in redisplay_window and
9634 indicates that we redisplay a buffer in different windows. See
9636 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
9637 || cursor_type_changed
);
9639 /* If specs for an arrow have changed, do thorough redisplay
9640 to ensure we remove any arrow that should no longer exist. */
9641 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
9642 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
9643 consider_all_windows_p
= windows_or_buffers_changed
= 1;
9645 /* Normally the message* functions will have already displayed and
9646 updated the echo area, but the frame may have been trashed, or
9647 the update may have been preempted, so display the echo area
9648 again here. Checking message_cleared_p captures the case that
9649 the echo area should be cleared. */
9650 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
9651 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
9652 || (message_cleared_p
9653 && minibuf_level
== 0
9654 /* If the mini-window is currently selected, this means the
9655 echo-area doesn't show through. */
9656 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
9658 int window_height_changed_p
= echo_area_display (0);
9661 /* If we don't display the current message, don't clear the
9662 message_cleared_p flag, because, if we did, we wouldn't clear
9663 the echo area in the next redisplay which doesn't preserve
9665 if (!display_last_displayed_message_p
)
9666 message_cleared_p
= 0;
9668 if (fonts_changed_p
)
9670 else if (window_height_changed_p
)
9672 consider_all_windows_p
= 1;
9673 ++update_mode_lines
;
9674 ++windows_or_buffers_changed
;
9676 /* If window configuration was changed, frames may have been
9677 marked garbaged. Clear them or we will experience
9678 surprises wrt scrolling. */
9680 clear_garbaged_frames ();
9683 else if (EQ (selected_window
, minibuf_window
)
9684 && (current_buffer
->clip_changed
9685 || XFASTINT (w
->last_modified
) < MODIFF
9686 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9687 && resize_mini_window (w
, 0))
9689 /* Resized active mini-window to fit the size of what it is
9690 showing if its contents might have changed. */
9692 consider_all_windows_p
= 1;
9693 ++windows_or_buffers_changed
;
9694 ++update_mode_lines
;
9696 /* If window configuration was changed, frames may have been
9697 marked garbaged. Clear them or we will experience
9698 surprises wrt scrolling. */
9700 clear_garbaged_frames ();
9704 /* If showing the region, and mark has changed, we must redisplay
9705 the whole window. The assignment to this_line_start_pos prevents
9706 the optimization directly below this if-statement. */
9707 if (((!NILP (Vtransient_mark_mode
)
9708 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9709 != !NILP (w
->region_showing
))
9710 || (!NILP (w
->region_showing
)
9711 && !EQ (w
->region_showing
,
9712 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
9713 CHARPOS (this_line_start_pos
) = 0;
9715 /* Optimize the case that only the line containing the cursor in the
9716 selected window has changed. Variables starting with this_ are
9717 set in display_line and record information about the line
9718 containing the cursor. */
9719 tlbufpos
= this_line_start_pos
;
9720 tlendpos
= this_line_end_pos
;
9721 if (!consider_all_windows_p
9722 && CHARPOS (tlbufpos
) > 0
9723 && NILP (w
->update_mode_line
)
9724 && !current_buffer
->clip_changed
9725 && !current_buffer
->prevent_redisplay_optimizations_p
9726 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
9727 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
9728 /* Make sure recorded data applies to current buffer, etc. */
9729 && this_line_buffer
== current_buffer
9730 && current_buffer
== XBUFFER (w
->buffer
)
9731 && NILP (w
->force_start
)
9732 && NILP (w
->optional_new_start
)
9733 /* Point must be on the line that we have info recorded about. */
9734 && PT
>= CHARPOS (tlbufpos
)
9735 && PT
<= Z
- CHARPOS (tlendpos
)
9736 /* All text outside that line, including its final newline,
9737 must be unchanged */
9738 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
9739 CHARPOS (tlendpos
)))
9741 if (CHARPOS (tlbufpos
) > BEGV
9742 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
9743 && (CHARPOS (tlbufpos
) == ZV
9744 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
9745 /* Former continuation line has disappeared by becoming empty */
9747 else if (XFASTINT (w
->last_modified
) < MODIFF
9748 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
9749 || MINI_WINDOW_P (w
))
9751 /* We have to handle the case of continuation around a
9752 wide-column character (See the comment in indent.c around
9755 For instance, in the following case:
9757 -------- Insert --------
9758 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
9759 J_I_ ==> J_I_ `^^' are cursors.
9763 As we have to redraw the line above, we should goto cancel. */
9766 int line_height_before
= this_line_pixel_height
;
9768 /* Note that start_display will handle the case that the
9769 line starting at tlbufpos is a continuation lines. */
9770 start_display (&it
, w
, tlbufpos
);
9772 /* Implementation note: It this still necessary? */
9773 if (it
.current_x
!= this_line_start_x
)
9776 TRACE ((stderr
, "trying display optimization 1\n"));
9777 w
->cursor
.vpos
= -1;
9778 overlay_arrow_seen
= 0;
9779 it
.vpos
= this_line_vpos
;
9780 it
.current_y
= this_line_y
;
9781 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
9784 /* If line contains point, is not continued,
9785 and ends at same distance from eob as before, we win */
9786 if (w
->cursor
.vpos
>= 0
9787 /* Line is not continued, otherwise this_line_start_pos
9788 would have been set to 0 in display_line. */
9789 && CHARPOS (this_line_start_pos
)
9790 /* Line ends as before. */
9791 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
9792 /* Line has same height as before. Otherwise other lines
9793 would have to be shifted up or down. */
9794 && this_line_pixel_height
== line_height_before
)
9796 /* If this is not the window's last line, we must adjust
9797 the charstarts of the lines below. */
9798 if (it
.current_y
< it
.last_visible_y
)
9800 struct glyph_row
*row
9801 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
9802 int delta
, delta_bytes
;
9804 if (Z
- CHARPOS (tlendpos
) == ZV
)
9806 /* This line ends at end of (accessible part of)
9807 buffer. There is no newline to count. */
9809 - CHARPOS (tlendpos
)
9810 - MATRIX_ROW_START_CHARPOS (row
));
9811 delta_bytes
= (Z_BYTE
9812 - BYTEPOS (tlendpos
)
9813 - MATRIX_ROW_START_BYTEPOS (row
));
9817 /* This line ends in a newline. Must take
9818 account of the newline and the rest of the
9819 text that follows. */
9821 - CHARPOS (tlendpos
)
9822 - MATRIX_ROW_START_CHARPOS (row
));
9823 delta_bytes
= (Z_BYTE
9824 - BYTEPOS (tlendpos
)
9825 - MATRIX_ROW_START_BYTEPOS (row
));
9828 increment_matrix_positions (w
->current_matrix
,
9830 w
->current_matrix
->nrows
,
9831 delta
, delta_bytes
);
9834 /* If this row displays text now but previously didn't,
9835 or vice versa, w->window_end_vpos may have to be
9837 if ((it
.glyph_row
- 1)->displays_text_p
)
9839 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
9840 XSETINT (w
->window_end_vpos
, this_line_vpos
);
9842 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
9843 && this_line_vpos
> 0)
9844 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
9845 w
->window_end_valid
= Qnil
;
9847 /* Update hint: No need to try to scroll in update_window. */
9848 w
->desired_matrix
->no_scrolling_p
= 1;
9851 *w
->desired_matrix
->method
= 0;
9852 debug_method_add (w
, "optimization 1");
9859 else if (/* Cursor position hasn't changed. */
9860 PT
== XFASTINT (w
->last_point
)
9861 /* Make sure the cursor was last displayed
9862 in this window. Otherwise we have to reposition it. */
9863 && 0 <= w
->cursor
.vpos
9864 && XINT (w
->height
) > w
->cursor
.vpos
)
9868 do_pending_window_change (1);
9870 /* We used to always goto end_of_redisplay here, but this
9871 isn't enough if we have a blinking cursor. */
9872 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
9873 goto end_of_redisplay
;
9877 /* If highlighting the region, or if the cursor is in the echo area,
9878 then we can't just move the cursor. */
9879 else if (! (!NILP (Vtransient_mark_mode
)
9880 && !NILP (current_buffer
->mark_active
))
9881 && (EQ (selected_window
, current_buffer
->last_selected_window
)
9882 || highlight_nonselected_windows
)
9883 && NILP (w
->region_showing
)
9884 && NILP (Vshow_trailing_whitespace
)
9885 && !cursor_in_echo_area
)
9888 struct glyph_row
*row
;
9890 /* Skip from tlbufpos to PT and see where it is. Note that
9891 PT may be in invisible text. If so, we will end at the
9892 next visible position. */
9893 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
9894 NULL
, DEFAULT_FACE_ID
);
9895 it
.current_x
= this_line_start_x
;
9896 it
.current_y
= this_line_y
;
9897 it
.vpos
= this_line_vpos
;
9899 /* The call to move_it_to stops in front of PT, but
9900 moves over before-strings. */
9901 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
9903 if (it
.vpos
== this_line_vpos
9904 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
9907 xassert (this_line_vpos
== it
.vpos
);
9908 xassert (this_line_y
== it
.current_y
);
9909 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9911 *w
->desired_matrix
->method
= 0;
9912 debug_method_add (w
, "optimization 3");
9921 /* Text changed drastically or point moved off of line. */
9922 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
9925 CHARPOS (this_line_start_pos
) = 0;
9926 consider_all_windows_p
|= buffer_shared
> 1;
9927 ++clear_face_cache_count
;
9930 /* Build desired matrices, and update the display. If
9931 consider_all_windows_p is non-zero, do it for all windows on all
9932 frames. Otherwise do it for selected_window, only. */
9934 if (consider_all_windows_p
)
9936 Lisp_Object tail
, frame
;
9937 int i
, n
= 0, size
= 50;
9938 struct frame
**updated
9939 = (struct frame
**) alloca (size
* sizeof *updated
);
9941 /* Clear the face cache eventually. */
9942 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
9944 clear_face_cache (0);
9945 clear_face_cache_count
= 0;
9948 /* Recompute # windows showing selected buffer. This will be
9949 incremented each time such a window is displayed. */
9952 FOR_EACH_FRAME (tail
, frame
)
9954 struct frame
*f
= XFRAME (frame
);
9956 if (FRAME_WINDOW_P (f
) || f
== sf
)
9958 #ifdef HAVE_WINDOW_SYSTEM
9959 if (clear_face_cache_count
% 50 == 0
9960 && FRAME_WINDOW_P (f
))
9961 clear_image_cache (f
, 0);
9962 #endif /* HAVE_WINDOW_SYSTEM */
9964 /* Mark all the scroll bars to be removed; we'll redeem
9965 the ones we want when we redisplay their windows. */
9966 if (condemn_scroll_bars_hook
)
9967 condemn_scroll_bars_hook (f
);
9969 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
9970 redisplay_windows (FRAME_ROOT_WINDOW (f
));
9972 /* Any scroll bars which redisplay_windows should have
9973 nuked should now go away. */
9974 if (judge_scroll_bars_hook
)
9975 judge_scroll_bars_hook (f
);
9977 /* If fonts changed, display again. */
9978 /* ??? rms: I suspect it is a mistake to jump all the way
9979 back to retry here. It should just retry this frame. */
9980 if (fonts_changed_p
)
9983 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
9985 /* See if we have to hscroll. */
9986 if (hscroll_windows (f
->root_window
))
9989 /* Prevent various kinds of signals during display
9990 update. stdio is not robust about handling
9991 signals, which can cause an apparent I/O
9993 if (interrupt_input
)
9997 /* Update the display. */
9998 set_window_update_flags (XWINDOW (f
->root_window
), 1);
9999 pause
|= update_frame (f
, 0, 0);
10005 int nbytes
= size
* sizeof *updated
;
10006 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10007 bcopy (updated
, p
, nbytes
);
10016 /* Do the mark_window_display_accurate after all windows have
10017 been redisplayed because this call resets flags in buffers
10018 which are needed for proper redisplay. */
10019 for (i
= 0; i
< n
; ++i
)
10021 struct frame
*f
= updated
[i
];
10022 mark_window_display_accurate (f
->root_window
, 1);
10023 if (frame_up_to_date_hook
)
10024 frame_up_to_date_hook (f
);
10027 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10029 Lisp_Object mini_window
;
10030 struct frame
*mini_frame
;
10032 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10033 /* Use list_of_error, not Qerror, so that
10034 we catch only errors and don't run the debugger. */
10035 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10037 redisplay_window_error
);
10039 /* Compare desired and current matrices, perform output. */
10042 /* If fonts changed, display again. */
10043 if (fonts_changed_p
)
10046 /* Prevent various kinds of signals during display update.
10047 stdio is not robust about handling signals,
10048 which can cause an apparent I/O error. */
10049 if (interrupt_input
)
10050 unrequest_sigio ();
10053 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10055 if (hscroll_windows (selected_window
))
10058 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10059 pause
= update_frame (sf
, 0, 0);
10062 /* We may have called echo_area_display at the top of this
10063 function. If the echo area is on another frame, that may
10064 have put text on a frame other than the selected one, so the
10065 above call to update_frame would not have caught it. Catch
10067 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10068 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10070 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10072 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10073 pause
|= update_frame (mini_frame
, 0, 0);
10074 if (!pause
&& hscroll_windows (mini_window
))
10079 /* If display was paused because of pending input, make sure we do a
10080 thorough update the next time. */
10083 /* Prevent the optimization at the beginning of
10084 redisplay_internal that tries a single-line update of the
10085 line containing the cursor in the selected window. */
10086 CHARPOS (this_line_start_pos
) = 0;
10088 /* Let the overlay arrow be updated the next time. */
10089 if (!NILP (last_arrow_position
))
10091 last_arrow_position
= Qt
;
10092 last_arrow_string
= Qt
;
10095 /* If we pause after scrolling, some rows in the current
10096 matrices of some windows are not valid. */
10097 if (!WINDOW_FULL_WIDTH_P (w
)
10098 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10099 update_mode_lines
= 1;
10103 if (!consider_all_windows_p
)
10105 /* This has already been done above if
10106 consider_all_windows_p is set. */
10107 mark_window_display_accurate_1 (w
, 1);
10109 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
10110 last_arrow_string
= Voverlay_arrow_string
;
10112 if (frame_up_to_date_hook
!= 0)
10113 frame_up_to_date_hook (sf
);
10116 update_mode_lines
= 0;
10117 windows_or_buffers_changed
= 0;
10118 cursor_type_changed
= 0;
10121 /* Start SIGIO interrupts coming again. Having them off during the
10122 code above makes it less likely one will discard output, but not
10123 impossible, since there might be stuff in the system buffer here.
10124 But it is much hairier to try to do anything about that. */
10125 if (interrupt_input
)
10129 /* If a frame has become visible which was not before, redisplay
10130 again, so that we display it. Expose events for such a frame
10131 (which it gets when becoming visible) don't call the parts of
10132 redisplay constructing glyphs, so simply exposing a frame won't
10133 display anything in this case. So, we have to display these
10134 frames here explicitly. */
10137 Lisp_Object tail
, frame
;
10140 FOR_EACH_FRAME (tail
, frame
)
10142 int this_is_visible
= 0;
10144 if (XFRAME (frame
)->visible
)
10145 this_is_visible
= 1;
10146 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10147 if (XFRAME (frame
)->visible
)
10148 this_is_visible
= 1;
10150 if (this_is_visible
)
10154 if (new_count
!= number_of_visible_frames
)
10155 windows_or_buffers_changed
++;
10158 /* Change frame size now if a change is pending. */
10159 do_pending_window_change (1);
10161 /* If we just did a pending size change, or have additional
10162 visible frames, redisplay again. */
10163 if (windows_or_buffers_changed
&& !pause
)
10167 unbind_to (count
, Qnil
);
10172 /* Redisplay, but leave alone any recent echo area message unless
10173 another message has been requested in its place.
10175 This is useful in situations where you need to redisplay but no
10176 user action has occurred, making it inappropriate for the message
10177 area to be cleared. See tracking_off and
10178 wait_reading_process_input for examples of these situations.
10180 FROM_WHERE is an integer saying from where this function was
10181 called. This is useful for debugging. */
10184 redisplay_preserve_echo_area (from_where
)
10187 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10189 if (!NILP (echo_area_buffer
[1]))
10191 /* We have a previously displayed message, but no current
10192 message. Redisplay the previous message. */
10193 display_last_displayed_message_p
= 1;
10194 redisplay_internal (1);
10195 display_last_displayed_message_p
= 0;
10198 redisplay_internal (1);
10202 /* Function registered with record_unwind_protect in
10203 redisplay_internal. Reset redisplaying_p to the value it had
10204 before redisplay_internal was called, and clear
10205 prevent_freeing_realized_faces_p. */
10208 unwind_redisplay (old_redisplaying_p
)
10209 Lisp_Object old_redisplaying_p
;
10211 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10216 /* Mark the display of window W as accurate or inaccurate. If
10217 ACCURATE_P is non-zero mark display of W as accurate. If
10218 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10219 redisplay_internal is called. */
10222 mark_window_display_accurate_1 (w
, accurate_p
)
10226 if (BUFFERP (w
->buffer
))
10228 struct buffer
*b
= XBUFFER (w
->buffer
);
10231 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10232 w
->last_overlay_modified
10233 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10235 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10239 b
->clip_changed
= 0;
10240 b
->prevent_redisplay_optimizations_p
= 0;
10242 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10243 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10244 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10245 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10247 w
->current_matrix
->buffer
= b
;
10248 w
->current_matrix
->begv
= BUF_BEGV (b
);
10249 w
->current_matrix
->zv
= BUF_ZV (b
);
10251 w
->last_cursor
= w
->cursor
;
10252 w
->last_cursor_off_p
= w
->cursor_off_p
;
10254 if (w
== XWINDOW (selected_window
))
10255 w
->last_point
= make_number (BUF_PT (b
));
10257 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10263 w
->window_end_valid
= w
->buffer
;
10264 #if 0 /* This is incorrect with variable-height lines. */
10265 xassert (XINT (w
->window_end_vpos
)
10266 < (XINT (w
->height
)
10267 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10269 w
->update_mode_line
= Qnil
;
10274 /* Mark the display of windows in the window tree rooted at WINDOW as
10275 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10276 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10277 be redisplayed the next time redisplay_internal is called. */
10280 mark_window_display_accurate (window
, accurate_p
)
10281 Lisp_Object window
;
10286 for (; !NILP (window
); window
= w
->next
)
10288 w
= XWINDOW (window
);
10289 mark_window_display_accurate_1 (w
, accurate_p
);
10291 if (!NILP (w
->vchild
))
10292 mark_window_display_accurate (w
->vchild
, accurate_p
);
10293 if (!NILP (w
->hchild
))
10294 mark_window_display_accurate (w
->hchild
, accurate_p
);
10299 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
10300 last_arrow_string
= Voverlay_arrow_string
;
10304 /* Force a thorough redisplay the next time by setting
10305 last_arrow_position and last_arrow_string to t, which is
10306 unequal to any useful value of Voverlay_arrow_... */
10307 last_arrow_position
= Qt
;
10308 last_arrow_string
= Qt
;
10313 /* Return value in display table DP (Lisp_Char_Table *) for character
10314 C. Since a display table doesn't have any parent, we don't have to
10315 follow parent. Do not call this function directly but use the
10316 macro DISP_CHAR_VECTOR. */
10319 disp_char_vector (dp
, c
)
10320 struct Lisp_Char_Table
*dp
;
10326 if (SINGLE_BYTE_CHAR_P (c
))
10327 return (dp
->contents
[c
]);
10329 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10332 else if (code
[2] < 32)
10335 /* Here, the possible range of code[0] (== charset ID) is
10336 128..max_charset. Since the top level char table contains data
10337 for multibyte characters after 256th element, we must increment
10338 code[0] by 128 to get a correct index. */
10340 code
[3] = -1; /* anchor */
10342 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10344 val
= dp
->contents
[code
[i
]];
10345 if (!SUB_CHAR_TABLE_P (val
))
10346 return (NILP (val
) ? dp
->defalt
: val
);
10349 /* Here, val is a sub char table. We return the default value of
10351 return (dp
->defalt
);
10356 /***********************************************************************
10358 ***********************************************************************/
10360 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10363 redisplay_windows (window
)
10364 Lisp_Object window
;
10366 while (!NILP (window
))
10368 struct window
*w
= XWINDOW (window
);
10370 if (!NILP (w
->hchild
))
10371 redisplay_windows (w
->hchild
);
10372 else if (!NILP (w
->vchild
))
10373 redisplay_windows (w
->vchild
);
10376 displayed_buffer
= XBUFFER (w
->buffer
);
10377 /* Use list_of_error, not Qerror, so that
10378 we catch only errors and don't run the debugger. */
10379 internal_condition_case_1 (redisplay_window_0
, window
,
10381 redisplay_window_error
);
10389 redisplay_window_error ()
10391 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10396 redisplay_window_0 (window
)
10397 Lisp_Object window
;
10399 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10400 redisplay_window (window
, 0);
10405 redisplay_window_1 (window
)
10406 Lisp_Object window
;
10408 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10409 redisplay_window (window
, 1);
10414 /* Increment GLYPH until it reaches END or CONDITION fails while
10415 adding (GLYPH)->pixel_width to X. */
10417 #define SKIP_GLYPHS(glyph, end, x, condition) \
10420 (x) += (glyph)->pixel_width; \
10423 while ((glyph) < (end) && (condition))
10426 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10427 DELTA is the number of bytes by which positions recorded in ROW
10428 differ from current buffer positions. */
10431 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10433 struct glyph_row
*row
;
10434 struct glyph_matrix
*matrix
;
10435 int delta
, delta_bytes
, dy
, dvpos
;
10437 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10438 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10439 /* The first glyph that starts a sequence of glyphs from string. */
10440 struct glyph
*string_start
;
10441 /* The X coordinate of string_start. */
10442 int string_start_x
;
10443 /* The last known character position. */
10444 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10445 /* The last known character position before string_start. */
10446 int string_before_pos
;
10448 int pt_old
= PT
- delta
;
10450 /* Skip over glyphs not having an object at the start of the row.
10451 These are special glyphs like truncation marks on terminal
10453 if (row
->displays_text_p
)
10455 && INTEGERP (glyph
->object
)
10456 && glyph
->charpos
< 0)
10458 x
+= glyph
->pixel_width
;
10462 string_start
= NULL
;
10464 && !INTEGERP (glyph
->object
)
10465 && (!BUFFERP (glyph
->object
)
10466 || (last_pos
= glyph
->charpos
) < pt_old
))
10468 if (! STRINGP (glyph
->object
))
10470 string_start
= NULL
;
10471 x
+= glyph
->pixel_width
;
10476 string_before_pos
= last_pos
;
10477 string_start
= glyph
;
10478 string_start_x
= x
;
10479 /* Skip all glyphs from string. */
10480 SKIP_GLYPHS (glyph
, end
, x
, STRINGP (glyph
->object
));
10485 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10487 /* We may have skipped over point because the previous glyphs
10488 are from string. As there's no easy way to know the
10489 character position of the current glyph, find the correct
10490 glyph on point by scanning from string_start again. */
10492 Lisp_Object string
;
10495 limit
= make_number (pt_old
+ 1);
10497 glyph
= string_start
;
10498 x
= string_start_x
;
10499 string
= glyph
->object
;
10500 pos
= string_buffer_position (w
, string
, string_before_pos
);
10501 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10502 because we always put cursor after overlay strings. */
10503 while (pos
== 0 && glyph
< end
)
10505 string
= glyph
->object
;
10506 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10508 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10511 while (glyph
< end
)
10513 pos
= XINT (Fnext_single_char_property_change
10514 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10517 /* Skip glyphs from the same string. */
10518 string
= glyph
->object
;
10519 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10520 /* Skip glyphs from an overlay. */
10522 && ! string_buffer_position (w
, glyph
->object
, pos
))
10524 string
= glyph
->object
;
10525 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10530 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10532 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10533 w
->cursor
.y
= row
->y
+ dy
;
10535 if (w
== XWINDOW (selected_window
))
10537 if (!row
->continued_p
10538 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
10541 this_line_buffer
= XBUFFER (w
->buffer
);
10543 CHARPOS (this_line_start_pos
)
10544 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
10545 BYTEPOS (this_line_start_pos
)
10546 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
10548 CHARPOS (this_line_end_pos
)
10549 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
10550 BYTEPOS (this_line_end_pos
)
10551 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
10553 this_line_y
= w
->cursor
.y
;
10554 this_line_pixel_height
= row
->height
;
10555 this_line_vpos
= w
->cursor
.vpos
;
10556 this_line_start_x
= row
->x
;
10559 CHARPOS (this_line_start_pos
) = 0;
10564 /* Run window scroll functions, if any, for WINDOW with new window
10565 start STARTP. Sets the window start of WINDOW to that position.
10567 We assume that the window's buffer is really current. */
10569 static INLINE
struct text_pos
10570 run_window_scroll_functions (window
, startp
)
10571 Lisp_Object window
;
10572 struct text_pos startp
;
10574 struct window
*w
= XWINDOW (window
);
10575 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
10577 if (current_buffer
!= XBUFFER (w
->buffer
))
10580 if (!NILP (Vwindow_scroll_functions
))
10582 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
10583 make_number (CHARPOS (startp
)));
10584 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10585 /* In case the hook functions switch buffers. */
10586 if (current_buffer
!= XBUFFER (w
->buffer
))
10587 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10594 /* Make sure the line containing the cursor is fully visible.
10595 A value of 1 means there is nothing to be done.
10596 (Either the line is fully visible, or it cannot be made so,
10597 or we cannot tell.)
10598 A value of 0 means the caller should do scrolling
10599 as if point had gone off the screen. */
10602 make_cursor_line_fully_visible (w
)
10605 struct glyph_matrix
*matrix
;
10606 struct glyph_row
*row
;
10609 /* It's not always possible to find the cursor, e.g, when a window
10610 is full of overlay strings. Don't do anything in that case. */
10611 if (w
->cursor
.vpos
< 0)
10614 matrix
= w
->desired_matrix
;
10615 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
10617 /* If the cursor row is not partially visible, there's nothing to do. */
10618 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10621 /* If the row the cursor is in is taller than the window's height,
10622 it's not clear what to do, so do nothing. */
10623 window_height
= window_box_height (w
);
10624 if (row
->height
>= window_height
)
10630 /* This code used to try to scroll the window just enough to make
10631 the line visible. It returned 0 to say that the caller should
10632 allocate larger glyph matrices. */
10634 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
10636 int dy
= row
->height
- row
->visible_height
;
10639 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10641 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
10643 int dy
= - (row
->height
- row
->visible_height
);
10646 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10649 /* When we change the cursor y-position of the selected window,
10650 change this_line_y as well so that the display optimization for
10651 the cursor line of the selected window in redisplay_internal uses
10652 the correct y-position. */
10653 if (w
== XWINDOW (selected_window
))
10654 this_line_y
= w
->cursor
.y
;
10656 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
10657 redisplay with larger matrices. */
10658 if (matrix
->nrows
< required_matrix_height (w
))
10660 fonts_changed_p
= 1;
10669 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
10670 non-zero means only WINDOW is redisplayed in redisplay_internal.
10671 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
10672 in redisplay_window to bring a partially visible line into view in
10673 the case that only the cursor has moved.
10675 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
10676 last screen line's vertical height extends past the end of the screen.
10680 1 if scrolling succeeded
10682 0 if scrolling didn't find point.
10684 -1 if new fonts have been loaded so that we must interrupt
10685 redisplay, adjust glyph matrices, and try again. */
10691 SCROLLING_NEED_LARGER_MATRICES
10695 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
10696 scroll_step
, temp_scroll_step
, last_line_misfit
)
10697 Lisp_Object window
;
10698 int just_this_one_p
;
10699 EMACS_INT scroll_conservatively
, scroll_step
;
10700 int temp_scroll_step
;
10701 int last_line_misfit
;
10703 struct window
*w
= XWINDOW (window
);
10704 struct frame
*f
= XFRAME (w
->frame
);
10705 struct text_pos scroll_margin_pos
;
10706 struct text_pos pos
;
10707 struct text_pos startp
;
10709 Lisp_Object window_end
;
10710 int this_scroll_margin
;
10714 int amount_to_scroll
= 0;
10715 Lisp_Object aggressive
;
10717 int end_scroll_margin
;
10720 debug_method_add (w
, "try_scrolling");
10723 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10725 /* Compute scroll margin height in pixels. We scroll when point is
10726 within this distance from the top or bottom of the window. */
10727 if (scroll_margin
> 0)
10729 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
10730 this_scroll_margin
*= CANON_Y_UNIT (f
);
10733 this_scroll_margin
= 0;
10735 /* Compute how much we should try to scroll maximally to bring point
10737 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
10738 scroll_max
= max (scroll_step
,
10739 max (scroll_conservatively
, temp_scroll_step
));
10740 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
10741 || NUMBERP (current_buffer
->scroll_up_aggressively
))
10742 /* We're trying to scroll because of aggressive scrolling
10743 but no scroll_step is set. Choose an arbitrary one. Maybe
10744 there should be a variable for this. */
10748 scroll_max
*= CANON_Y_UNIT (f
);
10750 /* Decide whether we have to scroll down. Start at the window end
10751 and move this_scroll_margin up to find the position of the scroll
10753 window_end
= Fwindow_end (window
, Qt
);
10757 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
10758 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
10760 end_scroll_margin
= this_scroll_margin
+ !!last_line_misfit
;
10761 if (end_scroll_margin
)
10763 start_display (&it
, w
, scroll_margin_pos
);
10764 move_it_vertically (&it
, - end_scroll_margin
);
10765 scroll_margin_pos
= it
.current
.pos
;
10768 if (PT
>= CHARPOS (scroll_margin_pos
))
10772 /* Point is in the scroll margin at the bottom of the window, or
10773 below. Compute a new window start that makes point visible. */
10775 /* Compute the distance from the scroll margin to PT.
10776 Give up if the distance is greater than scroll_max. */
10777 start_display (&it
, w
, scroll_margin_pos
);
10779 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10780 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10782 /* To make point visible, we have to move the window start
10783 down so that the line the cursor is in is visible, which
10784 means we have to add in the height of the cursor line. */
10785 dy
= line_bottom_y (&it
) - y0
;
10787 if (dy
> scroll_max
)
10788 return SCROLLING_FAILED
;
10790 /* Move the window start down. If scrolling conservatively,
10791 move it just enough down to make point visible. If
10792 scroll_step is set, move it down by scroll_step. */
10793 start_display (&it
, w
, startp
);
10795 if (scroll_conservatively
)
10796 /* Set AMOUNT_TO_SCROLL to at least one line,
10797 and at most scroll_conservatively lines. */
10799 = min (max (dy
, CANON_Y_UNIT (f
)),
10800 CANON_Y_UNIT (f
) * scroll_conservatively
);
10801 else if (scroll_step
|| temp_scroll_step
)
10802 amount_to_scroll
= scroll_max
;
10805 aggressive
= current_buffer
->scroll_up_aggressively
;
10806 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
10807 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10808 if (NUMBERP (aggressive
))
10809 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
10812 if (amount_to_scroll
<= 0)
10813 return SCROLLING_FAILED
;
10815 /* If moving by amount_to_scroll leaves STARTP unchanged,
10816 move it down one screen line. */
10818 move_it_vertically (&it
, amount_to_scroll
);
10819 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
10820 move_it_by_lines (&it
, 1, 1);
10821 startp
= it
.current
.pos
;
10825 /* See if point is inside the scroll margin at the top of the
10827 scroll_margin_pos
= startp
;
10828 if (this_scroll_margin
)
10830 start_display (&it
, w
, startp
);
10831 move_it_vertically (&it
, this_scroll_margin
);
10832 scroll_margin_pos
= it
.current
.pos
;
10835 if (PT
< CHARPOS (scroll_margin_pos
))
10837 /* Point is in the scroll margin at the top of the window or
10838 above what is displayed in the window. */
10841 /* Compute the vertical distance from PT to the scroll
10842 margin position. Give up if distance is greater than
10844 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
10845 start_display (&it
, w
, pos
);
10847 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
10848 it
.last_visible_y
, -1,
10849 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10850 dy
= it
.current_y
- y0
;
10851 if (dy
> scroll_max
)
10852 return SCROLLING_FAILED
;
10854 /* Compute new window start. */
10855 start_display (&it
, w
, startp
);
10857 if (scroll_conservatively
)
10859 max (dy
, CANON_Y_UNIT (f
) * max (scroll_step
, temp_scroll_step
));
10860 else if (scroll_step
|| temp_scroll_step
)
10861 amount_to_scroll
= scroll_max
;
10864 aggressive
= current_buffer
->scroll_down_aggressively
;
10865 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
10866 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
10867 if (NUMBERP (aggressive
))
10868 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
10871 if (amount_to_scroll
<= 0)
10872 return SCROLLING_FAILED
;
10874 move_it_vertically (&it
, - amount_to_scroll
);
10875 startp
= it
.current
.pos
;
10879 /* Run window scroll functions. */
10880 startp
= run_window_scroll_functions (window
, startp
);
10882 /* Display the window. Give up if new fonts are loaded, or if point
10884 if (!try_window (window
, startp
))
10885 rc
= SCROLLING_NEED_LARGER_MATRICES
;
10886 else if (w
->cursor
.vpos
< 0)
10888 clear_glyph_matrix (w
->desired_matrix
);
10889 rc
= SCROLLING_FAILED
;
10893 /* Maybe forget recorded base line for line number display. */
10894 if (!just_this_one_p
10895 || current_buffer
->clip_changed
10896 || BEG_UNCHANGED
< CHARPOS (startp
))
10897 w
->base_line_number
= Qnil
;
10899 /* If cursor ends up on a partially visible line,
10900 treat that as being off the bottom of the screen. */
10901 if (! make_cursor_line_fully_visible (w
))
10903 clear_glyph_matrix (w
->desired_matrix
);
10904 last_line_misfit
= 1;
10907 rc
= SCROLLING_SUCCESS
;
10914 /* Compute a suitable window start for window W if display of W starts
10915 on a continuation line. Value is non-zero if a new window start
10918 The new window start will be computed, based on W's width, starting
10919 from the start of the continued line. It is the start of the
10920 screen line with the minimum distance from the old start W->start. */
10923 compute_window_start_on_continuation_line (w
)
10926 struct text_pos pos
, start_pos
;
10927 int window_start_changed_p
= 0;
10929 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
10931 /* If window start is on a continuation line... Window start may be
10932 < BEGV in case there's invisible text at the start of the
10933 buffer (M-x rmail, for example). */
10934 if (CHARPOS (start_pos
) > BEGV
10935 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
10938 struct glyph_row
*row
;
10940 /* Handle the case that the window start is out of range. */
10941 if (CHARPOS (start_pos
) < BEGV
)
10942 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
10943 else if (CHARPOS (start_pos
) > ZV
)
10944 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
10946 /* Find the start of the continued line. This should be fast
10947 because scan_buffer is fast (newline cache). */
10948 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
10949 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
10950 row
, DEFAULT_FACE_ID
);
10951 reseat_at_previous_visible_line_start (&it
);
10953 /* If the line start is "too far" away from the window start,
10954 say it takes too much time to compute a new window start. */
10955 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
10956 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
10958 int min_distance
, distance
;
10960 /* Move forward by display lines to find the new window
10961 start. If window width was enlarged, the new start can
10962 be expected to be > the old start. If window width was
10963 decreased, the new window start will be < the old start.
10964 So, we're looking for the display line start with the
10965 minimum distance from the old window start. */
10966 pos
= it
.current
.pos
;
10967 min_distance
= INFINITY
;
10968 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
10969 distance
< min_distance
)
10971 min_distance
= distance
;
10972 pos
= it
.current
.pos
;
10973 move_it_by_lines (&it
, 1, 0);
10976 /* Set the window start there. */
10977 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
10978 window_start_changed_p
= 1;
10982 return window_start_changed_p
;
10986 /* Try cursor movement in case text has not changed in window WINDOW,
10987 with window start STARTP. Value is
10989 CURSOR_MOVEMENT_SUCCESS if successful
10991 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
10993 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
10994 display. *SCROLL_STEP is set to 1, under certain circumstances, if
10995 we want to scroll as if scroll-step were set to 1. See the code.
10997 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
10998 which case we have to abort this redisplay, and adjust matrices
11003 CURSOR_MOVEMENT_SUCCESS
,
11004 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11005 CURSOR_MOVEMENT_MUST_SCROLL
,
11006 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11010 try_cursor_movement (window
, startp
, scroll_step
)
11011 Lisp_Object window
;
11012 struct text_pos startp
;
11015 struct window
*w
= XWINDOW (window
);
11016 struct frame
*f
= XFRAME (w
->frame
);
11017 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11020 if (inhibit_try_cursor_movement
)
11024 /* Handle case where text has not changed, only point, and it has
11025 not moved off the frame. */
11026 if (/* Point may be in this window. */
11027 PT
>= CHARPOS (startp
)
11028 /* Selective display hasn't changed. */
11029 && !current_buffer
->clip_changed
11030 /* Function force-mode-line-update is used to force a thorough
11031 redisplay. It sets either windows_or_buffers_changed or
11032 update_mode_lines. So don't take a shortcut here for these
11034 && !update_mode_lines
11035 && !windows_or_buffers_changed
11036 && !cursor_type_changed
11037 /* Can't use this case if highlighting a region. When a
11038 region exists, cursor movement has to do more than just
11040 && !(!NILP (Vtransient_mark_mode
)
11041 && !NILP (current_buffer
->mark_active
))
11042 && NILP (w
->region_showing
)
11043 && NILP (Vshow_trailing_whitespace
)
11044 /* Right after splitting windows, last_point may be nil. */
11045 && INTEGERP (w
->last_point
)
11046 /* This code is not used for mini-buffer for the sake of the case
11047 of redisplaying to replace an echo area message; since in
11048 that case the mini-buffer contents per se are usually
11049 unchanged. This code is of no real use in the mini-buffer
11050 since the handling of this_line_start_pos, etc., in redisplay
11051 handles the same cases. */
11052 && !EQ (window
, minibuf_window
)
11053 /* When splitting windows or for new windows, it happens that
11054 redisplay is called with a nil window_end_vpos or one being
11055 larger than the window. This should really be fixed in
11056 window.c. I don't have this on my list, now, so we do
11057 approximately the same as the old redisplay code. --gerd. */
11058 && INTEGERP (w
->window_end_vpos
)
11059 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11060 && (FRAME_WINDOW_P (f
)
11061 || !MARKERP (Voverlay_arrow_position
)
11062 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
11064 int this_scroll_margin
;
11065 struct glyph_row
*row
= NULL
;
11068 debug_method_add (w
, "cursor movement");
11071 /* Scroll if point within this distance from the top or bottom
11072 of the window. This is a pixel value. */
11073 this_scroll_margin
= max (0, scroll_margin
);
11074 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
11075 this_scroll_margin
*= CANON_Y_UNIT (f
);
11077 /* Start with the row the cursor was displayed during the last
11078 not paused redisplay. Give up if that row is not valid. */
11079 if (w
->last_cursor
.vpos
< 0
11080 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11081 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11084 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11085 if (row
->mode_line_p
)
11087 if (!row
->enabled_p
)
11088 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11091 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11094 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11096 if (PT
> XFASTINT (w
->last_point
))
11098 /* Point has moved forward. */
11099 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11100 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11102 xassert (row
->enabled_p
);
11106 /* The end position of a row equals the start position
11107 of the next row. If PT is there, we would rather
11108 display it in the next line. */
11109 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11110 && MATRIX_ROW_END_CHARPOS (row
) == PT
11111 && !cursor_row_p (w
, row
))
11114 /* If within the scroll margin, scroll. Note that
11115 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11116 the next line would be drawn, and that
11117 this_scroll_margin can be zero. */
11118 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11119 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11120 /* Line is completely visible last line in window
11121 and PT is to be set in the next line. */
11122 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11123 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11124 && !row
->ends_at_zv_p
11125 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11128 else if (PT
< XFASTINT (w
->last_point
))
11130 /* Cursor has to be moved backward. Note that PT >=
11131 CHARPOS (startp) because of the outer
11133 while (!row
->mode_line_p
11134 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11135 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11136 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11137 && (row
->y
> this_scroll_margin
11138 || CHARPOS (startp
) == BEGV
))
11140 xassert (row
->enabled_p
);
11144 /* Consider the following case: Window starts at BEGV,
11145 there is invisible, intangible text at BEGV, so that
11146 display starts at some point START > BEGV. It can
11147 happen that we are called with PT somewhere between
11148 BEGV and START. Try to handle that case. */
11149 if (row
< w
->current_matrix
->rows
11150 || row
->mode_line_p
)
11152 row
= w
->current_matrix
->rows
;
11153 if (row
->mode_line_p
)
11157 /* Due to newlines in overlay strings, we may have to
11158 skip forward over overlay strings. */
11159 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11160 && MATRIX_ROW_END_CHARPOS (row
) == PT
11161 && !cursor_row_p (w
, row
))
11164 /* If within the scroll margin, scroll. */
11165 if (row
->y
< this_scroll_margin
11166 && CHARPOS (startp
) != BEGV
)
11170 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11171 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11173 /* if PT is not in the glyph row, give up. */
11174 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11176 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
11178 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11179 && !row
->ends_at_zv_p
11180 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11181 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11182 else if (row
->height
> window_box_height (w
))
11184 /* If we end up in a partially visible line, let's
11185 make it fully visible, except when it's taller
11186 than the window, in which case we can't do much
11189 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11193 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11194 if (!make_cursor_line_fully_visible (w
))
11195 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11197 rc
= CURSOR_MOVEMENT_SUCCESS
;
11201 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11204 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11205 rc
= CURSOR_MOVEMENT_SUCCESS
;
11214 set_vertical_scroll_bar (w
)
11217 int start
, end
, whole
;
11219 /* Calculate the start and end positions for the current window.
11220 At some point, it would be nice to choose between scrollbars
11221 which reflect the whole buffer size, with special markers
11222 indicating narrowing, and scrollbars which reflect only the
11225 Note that mini-buffers sometimes aren't displaying any text. */
11226 if (!MINI_WINDOW_P (w
)
11227 || (w
== XWINDOW (minibuf_window
)
11228 && NILP (echo_area_buffer
[0])))
11230 struct buffer
*buf
= XBUFFER (w
->buffer
);
11231 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11232 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11233 /* I don't think this is guaranteed to be right. For the
11234 moment, we'll pretend it is. */
11235 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11239 if (whole
< (end
- start
))
11240 whole
= end
- start
;
11243 start
= end
= whole
= 0;
11245 /* Indicate what this scroll bar ought to be displaying now. */
11246 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
11249 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11250 selected_window is redisplayed.
11252 We can return without actually redisplaying the window if
11253 fonts_changed_p is nonzero. In that case, redisplay_internal will
11257 redisplay_window (window
, just_this_one_p
)
11258 Lisp_Object window
;
11259 int just_this_one_p
;
11261 struct window
*w
= XWINDOW (window
);
11262 struct frame
*f
= XFRAME (w
->frame
);
11263 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11264 struct buffer
*old
= current_buffer
;
11265 struct text_pos lpoint
, opoint
, startp
;
11266 int update_mode_line
;
11269 /* Record it now because it's overwritten. */
11270 int current_matrix_up_to_date_p
= 0;
11271 /* This is less strict than current_matrix_up_to_date_p.
11272 It indictes that the buffer contents and narrowing are unchanged. */
11273 int buffer_unchanged_p
= 0;
11274 int temp_scroll_step
= 0;
11275 int count
= SPECPDL_INDEX ();
11277 int centering_position
;
11278 int last_line_misfit
= 0;
11280 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11283 /* W must be a leaf window here. */
11284 xassert (!NILP (w
->buffer
));
11286 *w
->desired_matrix
->method
= 0;
11289 specbind (Qinhibit_point_motion_hooks
, Qt
);
11291 reconsider_clip_changes (w
, buffer
);
11293 /* Has the mode line to be updated? */
11294 update_mode_line
= (!NILP (w
->update_mode_line
)
11295 || update_mode_lines
11296 || buffer
->clip_changed
11297 || buffer
->prevent_redisplay_optimizations_p
);
11299 if (MINI_WINDOW_P (w
))
11301 if (w
== XWINDOW (echo_area_window
)
11302 && !NILP (echo_area_buffer
[0]))
11304 if (update_mode_line
)
11305 /* We may have to update a tty frame's menu bar or a
11306 tool-bar. Example `M-x C-h C-h C-g'. */
11307 goto finish_menu_bars
;
11309 /* We've already displayed the echo area glyphs in this window. */
11310 goto finish_scroll_bars
;
11312 else if ((w
!= XWINDOW (minibuf_window
)
11313 || minibuf_level
== 0)
11314 /* When buffer is nonempty, redisplay window normally. */
11315 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11316 /* Quail displays non-mini buffers in minibuffer window.
11317 In that case, redisplay the window normally. */
11318 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11320 /* W is a mini-buffer window, but it's not active, so clear
11322 int yb
= window_text_bottom_y (w
);
11323 struct glyph_row
*row
;
11326 for (y
= 0, row
= w
->desired_matrix
->rows
;
11328 y
+= row
->height
, ++row
)
11329 blank_row (w
, row
, y
);
11330 goto finish_scroll_bars
;
11333 clear_glyph_matrix (w
->desired_matrix
);
11336 /* Otherwise set up data on this window; select its buffer and point
11338 /* Really select the buffer, for the sake of buffer-local
11340 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11341 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11343 current_matrix_up_to_date_p
11344 = (!NILP (w
->window_end_valid
)
11345 && !current_buffer
->clip_changed
11346 && !current_buffer
->prevent_redisplay_optimizations_p
11347 && XFASTINT (w
->last_modified
) >= MODIFF
11348 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11351 = (!NILP (w
->window_end_valid
)
11352 && !current_buffer
->clip_changed
11353 && XFASTINT (w
->last_modified
) >= MODIFF
11354 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11356 /* When windows_or_buffers_changed is non-zero, we can't rely on
11357 the window end being valid, so set it to nil there. */
11358 if (windows_or_buffers_changed
)
11360 /* If window starts on a continuation line, maybe adjust the
11361 window start in case the window's width changed. */
11362 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11363 compute_window_start_on_continuation_line (w
);
11365 w
->window_end_valid
= Qnil
;
11368 /* Some sanity checks. */
11369 CHECK_WINDOW_END (w
);
11370 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11372 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11375 /* If %c is in mode line, update it if needed. */
11376 if (!NILP (w
->column_number_displayed
)
11377 /* This alternative quickly identifies a common case
11378 where no change is needed. */
11379 && !(PT
== XFASTINT (w
->last_point
)
11380 && XFASTINT (w
->last_modified
) >= MODIFF
11381 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11382 && (XFASTINT (w
->column_number_displayed
)
11383 != (int) current_column ())) /* iftc */
11384 update_mode_line
= 1;
11386 /* Count number of windows showing the selected buffer. An indirect
11387 buffer counts as its base buffer. */
11388 if (!just_this_one_p
)
11390 struct buffer
*current_base
, *window_base
;
11391 current_base
= current_buffer
;
11392 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11393 if (current_base
->base_buffer
)
11394 current_base
= current_base
->base_buffer
;
11395 if (window_base
->base_buffer
)
11396 window_base
= window_base
->base_buffer
;
11397 if (current_base
== window_base
)
11401 /* Point refers normally to the selected window. For any other
11402 window, set up appropriate value. */
11403 if (!EQ (window
, selected_window
))
11405 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11406 int new_pt_byte
= marker_byte_position (w
->pointm
);
11410 new_pt_byte
= BEGV_BYTE
;
11411 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11413 else if (new_pt
> (ZV
- 1))
11416 new_pt_byte
= ZV_BYTE
;
11417 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11420 /* We don't use SET_PT so that the point-motion hooks don't run. */
11421 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11424 /* If any of the character widths specified in the display table
11425 have changed, invalidate the width run cache. It's true that
11426 this may be a bit late to catch such changes, but the rest of
11427 redisplay goes (non-fatally) haywire when the display table is
11428 changed, so why should we worry about doing any better? */
11429 if (current_buffer
->width_run_cache
)
11431 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11433 if (! disptab_matches_widthtab (disptab
,
11434 XVECTOR (current_buffer
->width_table
)))
11436 invalidate_region_cache (current_buffer
,
11437 current_buffer
->width_run_cache
,
11439 recompute_width_table (current_buffer
, disptab
);
11443 /* If window-start is screwed up, choose a new one. */
11444 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
11447 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11449 /* If someone specified a new starting point but did not insist,
11450 check whether it can be used. */
11451 if (!NILP (w
->optional_new_start
)
11452 && CHARPOS (startp
) >= BEGV
11453 && CHARPOS (startp
) <= ZV
)
11455 w
->optional_new_start
= Qnil
;
11456 start_display (&it
, w
, startp
);
11457 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11458 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11459 if (IT_CHARPOS (it
) == PT
)
11460 w
->force_start
= Qt
;
11463 /* Handle case where place to start displaying has been specified,
11464 unless the specified location is outside the accessible range. */
11465 if (!NILP (w
->force_start
)
11466 || w
->frozen_window_start_p
)
11468 /* We set this later on if we have to adjust point. */
11471 w
->force_start
= Qnil
;
11473 w
->window_end_valid
= Qnil
;
11475 /* Forget any recorded base line for line number display. */
11476 if (!buffer_unchanged_p
)
11477 w
->base_line_number
= Qnil
;
11479 /* Redisplay the mode line. Select the buffer properly for that.
11480 Also, run the hook window-scroll-functions
11481 because we have scrolled. */
11482 /* Note, we do this after clearing force_start because
11483 if there's an error, it is better to forget about force_start
11484 than to get into an infinite loop calling the hook functions
11485 and having them get more errors. */
11486 if (!update_mode_line
11487 || ! NILP (Vwindow_scroll_functions
))
11489 update_mode_line
= 1;
11490 w
->update_mode_line
= Qt
;
11491 startp
= run_window_scroll_functions (window
, startp
);
11494 w
->last_modified
= make_number (0);
11495 w
->last_overlay_modified
= make_number (0);
11496 if (CHARPOS (startp
) < BEGV
)
11497 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
11498 else if (CHARPOS (startp
) > ZV
)
11499 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
11501 /* Redisplay, then check if cursor has been set during the
11502 redisplay. Give up if new fonts were loaded. */
11503 if (!try_window (window
, startp
))
11505 w
->force_start
= Qt
;
11506 clear_glyph_matrix (w
->desired_matrix
);
11507 goto need_larger_matrices
;
11510 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
11512 /* If point does not appear, try to move point so it does
11513 appear. The desired matrix has been built above, so we
11514 can use it here. */
11515 new_vpos
= window_box_height (w
) / 2;
11518 if (!make_cursor_line_fully_visible (w
))
11520 /* Point does appear, but on a line partly visible at end of window.
11521 Move it back to a fully-visible line. */
11522 new_vpos
= window_box_height (w
);
11525 /* If we need to move point for either of the above reasons,
11526 now actually do it. */
11529 struct glyph_row
*row
;
11531 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
11532 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
11535 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
11536 MATRIX_ROW_START_BYTEPOS (row
));
11538 if (w
!= XWINDOW (selected_window
))
11539 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
11540 else if (current_buffer
== old
)
11541 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11543 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
11545 /* If we are highlighting the region, then we just changed
11546 the region, so redisplay to show it. */
11547 if (!NILP (Vtransient_mark_mode
)
11548 && !NILP (current_buffer
->mark_active
))
11550 clear_glyph_matrix (w
->desired_matrix
);
11551 if (!try_window (window
, startp
))
11552 goto need_larger_matrices
;
11557 debug_method_add (w
, "forced window start");
11562 /* Handle case where text has not changed, only point, and it has
11563 not moved off the frame, and we are not retrying after hscroll.
11564 (current_matrix_up_to_date_p is nonzero when retrying.) */
11565 if (current_matrix_up_to_date_p
11566 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
11567 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
11571 case CURSOR_MOVEMENT_SUCCESS
:
11574 #if 0 /* try_cursor_movement never returns this value. */
11575 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
11576 goto need_larger_matrices
;
11579 case CURSOR_MOVEMENT_MUST_SCROLL
:
11580 goto try_to_scroll
;
11586 /* If current starting point was originally the beginning of a line
11587 but no longer is, find a new starting point. */
11588 else if (!NILP (w
->start_at_line_beg
)
11589 && !(CHARPOS (startp
) <= BEGV
11590 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
11593 debug_method_add (w
, "recenter 1");
11598 /* Try scrolling with try_window_id. Value is > 0 if update has
11599 been done, it is -1 if we know that the same window start will
11600 not work. It is 0 if unsuccessful for some other reason. */
11601 else if ((tem
= try_window_id (w
)) != 0)
11604 debug_method_add (w
, "try_window_id %d", tem
);
11607 if (fonts_changed_p
)
11608 goto need_larger_matrices
;
11612 /* Otherwise try_window_id has returned -1 which means that we
11613 don't want the alternative below this comment to execute. */
11615 else if (CHARPOS (startp
) >= BEGV
11616 && CHARPOS (startp
) <= ZV
11617 && PT
>= CHARPOS (startp
)
11618 && (CHARPOS (startp
) < ZV
11619 /* Avoid starting at end of buffer. */
11620 || CHARPOS (startp
) == BEGV
11621 || (XFASTINT (w
->last_modified
) >= MODIFF
11622 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
11625 debug_method_add (w
, "same window start");
11628 /* Try to redisplay starting at same place as before.
11629 If point has not moved off frame, accept the results. */
11630 if (!current_matrix_up_to_date_p
11631 /* Don't use try_window_reusing_current_matrix in this case
11632 because a window scroll function can have changed the
11634 || !NILP (Vwindow_scroll_functions
)
11635 || MINI_WINDOW_P (w
)
11636 || !try_window_reusing_current_matrix (w
))
11638 IF_DEBUG (debug_method_add (w
, "1"));
11639 try_window (window
, startp
);
11642 if (fonts_changed_p
)
11643 goto need_larger_matrices
;
11645 if (w
->cursor
.vpos
>= 0)
11647 if (!just_this_one_p
11648 || current_buffer
->clip_changed
11649 || BEG_UNCHANGED
< CHARPOS (startp
))
11650 /* Forget any recorded base line for line number display. */
11651 w
->base_line_number
= Qnil
;
11653 if (!make_cursor_line_fully_visible (w
))
11655 clear_glyph_matrix (w
->desired_matrix
);
11656 last_line_misfit
= 1;
11658 /* Drop through and scroll. */
11663 clear_glyph_matrix (w
->desired_matrix
);
11668 w
->last_modified
= make_number (0);
11669 w
->last_overlay_modified
= make_number (0);
11671 /* Redisplay the mode line. Select the buffer properly for that. */
11672 if (!update_mode_line
)
11674 update_mode_line
= 1;
11675 w
->update_mode_line
= Qt
;
11678 /* Try to scroll by specified few lines. */
11679 if ((scroll_conservatively
11681 || temp_scroll_step
11682 || NUMBERP (current_buffer
->scroll_up_aggressively
)
11683 || NUMBERP (current_buffer
->scroll_down_aggressively
))
11684 && !current_buffer
->clip_changed
11685 && CHARPOS (startp
) >= BEGV
11686 && CHARPOS (startp
) <= ZV
)
11688 /* The function returns -1 if new fonts were loaded, 1 if
11689 successful, 0 if not successful. */
11690 int rc
= try_scrolling (window
, just_this_one_p
,
11691 scroll_conservatively
,
11693 temp_scroll_step
, last_line_misfit
);
11696 case SCROLLING_SUCCESS
:
11699 case SCROLLING_NEED_LARGER_MATRICES
:
11700 goto need_larger_matrices
;
11702 case SCROLLING_FAILED
:
11710 /* Finally, just choose place to start which centers point */
11713 centering_position
= window_box_height (w
) / 2;
11716 /* Jump here with centering_position already set to 0. */
11719 debug_method_add (w
, "recenter");
11722 /* w->vscroll = 0; */
11724 /* Forget any previously recorded base line for line number display. */
11725 if (!buffer_unchanged_p
)
11726 w
->base_line_number
= Qnil
;
11728 /* Move backward half the height of the window. */
11729 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11730 it
.current_y
= it
.last_visible_y
;
11731 move_it_vertically_backward (&it
, centering_position
);
11732 xassert (IT_CHARPOS (it
) >= BEGV
);
11734 /* The function move_it_vertically_backward may move over more
11735 than the specified y-distance. If it->w is small, e.g. a
11736 mini-buffer window, we may end up in front of the window's
11737 display area. Start displaying at the start of the line
11738 containing PT in this case. */
11739 if (it
.current_y
<= 0)
11741 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11742 move_it_vertically (&it
, 0);
11743 xassert (IT_CHARPOS (it
) <= PT
);
11747 it
.current_x
= it
.hpos
= 0;
11749 /* Set startp here explicitly in case that helps avoid an infinite loop
11750 in case the window-scroll-functions functions get errors. */
11751 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
11753 /* Run scroll hooks. */
11754 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
11756 /* Redisplay the window. */
11757 if (!current_matrix_up_to_date_p
11758 || windows_or_buffers_changed
11759 || cursor_type_changed
11760 /* Don't use try_window_reusing_current_matrix in this case
11761 because it can have changed the buffer. */
11762 || !NILP (Vwindow_scroll_functions
)
11763 || !just_this_one_p
11764 || MINI_WINDOW_P (w
)
11765 || !try_window_reusing_current_matrix (w
))
11766 try_window (window
, startp
);
11768 /* If new fonts have been loaded (due to fontsets), give up. We
11769 have to start a new redisplay since we need to re-adjust glyph
11771 if (fonts_changed_p
)
11772 goto need_larger_matrices
;
11774 /* If cursor did not appear assume that the middle of the window is
11775 in the first line of the window. Do it again with the next line.
11776 (Imagine a window of height 100, displaying two lines of height
11777 60. Moving back 50 from it->last_visible_y will end in the first
11779 if (w
->cursor
.vpos
< 0)
11781 if (!NILP (w
->window_end_valid
)
11782 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
11784 clear_glyph_matrix (w
->desired_matrix
);
11785 move_it_by_lines (&it
, 1, 0);
11786 try_window (window
, it
.current
.pos
);
11788 else if (PT
< IT_CHARPOS (it
))
11790 clear_glyph_matrix (w
->desired_matrix
);
11791 move_it_by_lines (&it
, -1, 0);
11792 try_window (window
, it
.current
.pos
);
11796 /* Not much we can do about it. */
11800 /* Consider the following case: Window starts at BEGV, there is
11801 invisible, intangible text at BEGV, so that display starts at
11802 some point START > BEGV. It can happen that we are called with
11803 PT somewhere between BEGV and START. Try to handle that case. */
11804 if (w
->cursor
.vpos
< 0)
11806 struct glyph_row
*row
= w
->current_matrix
->rows
;
11807 if (row
->mode_line_p
)
11809 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11812 if (!make_cursor_line_fully_visible (w
))
11814 /* If vscroll is enabled, disable it and try again. */
11818 clear_glyph_matrix (w
->desired_matrix
);
11822 /* If centering point failed to make the whole line visible,
11823 put point at the top instead. That has to make the whole line
11824 visible, if it can be done. */
11825 centering_position
= 0;
11831 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11832 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
11833 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
11836 /* Display the mode line, if we must. */
11837 if ((update_mode_line
11838 /* If window not full width, must redo its mode line
11839 if (a) the window to its side is being redone and
11840 (b) we do a frame-based redisplay. This is a consequence
11841 of how inverted lines are drawn in frame-based redisplay. */
11842 || (!just_this_one_p
11843 && !FRAME_WINDOW_P (f
)
11844 && !WINDOW_FULL_WIDTH_P (w
))
11845 /* Line number to display. */
11846 || INTEGERP (w
->base_line_pos
)
11847 /* Column number is displayed and different from the one displayed. */
11848 || (!NILP (w
->column_number_displayed
)
11849 && (XFASTINT (w
->column_number_displayed
)
11850 != (int) current_column ()))) /* iftc */
11851 /* This means that the window has a mode line. */
11852 && (WINDOW_WANTS_MODELINE_P (w
)
11853 || WINDOW_WANTS_HEADER_LINE_P (w
)))
11855 display_mode_lines (w
);
11857 /* If mode line height has changed, arrange for a thorough
11858 immediate redisplay using the correct mode line height. */
11859 if (WINDOW_WANTS_MODELINE_P (w
)
11860 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
11862 fonts_changed_p
= 1;
11863 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
11864 = DESIRED_MODE_LINE_HEIGHT (w
);
11867 /* If top line height has changed, arrange for a thorough
11868 immediate redisplay using the correct mode line height. */
11869 if (WINDOW_WANTS_HEADER_LINE_P (w
)
11870 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
11872 fonts_changed_p
= 1;
11873 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
11874 = DESIRED_HEADER_LINE_HEIGHT (w
);
11877 if (fonts_changed_p
)
11878 goto need_larger_matrices
;
11881 if (!line_number_displayed
11882 && !BUFFERP (w
->base_line_pos
))
11884 w
->base_line_pos
= Qnil
;
11885 w
->base_line_number
= Qnil
;
11890 /* When we reach a frame's selected window, redo the frame's menu bar. */
11891 if (update_mode_line
11892 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
11894 int redisplay_menu_p
= 0;
11895 int redisplay_tool_bar_p
= 0;
11897 if (FRAME_WINDOW_P (f
))
11899 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
11900 || defined (USE_GTK)
11901 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
11903 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
11907 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
11909 if (redisplay_menu_p
)
11910 display_menu_bar (w
);
11912 #ifdef HAVE_WINDOW_SYSTEM
11914 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
11916 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
11917 && (FRAME_TOOL_BAR_LINES (f
) > 0
11918 || auto_resize_tool_bars_p
);
11922 if (redisplay_tool_bar_p
)
11923 redisplay_tool_bar (f
);
11927 /* We go to this label, with fonts_changed_p nonzero,
11928 if it is necessary to try again using larger glyph matrices.
11929 We have to redeem the scroll bar even in this case,
11930 because the loop in redisplay_internal expects that. */
11931 need_larger_matrices
:
11933 finish_scroll_bars
:
11935 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
11937 /* Set the thumb's position and size. */
11938 set_vertical_scroll_bar (w
);
11940 /* Note that we actually used the scroll bar attached to this
11941 window, so it shouldn't be deleted at the end of redisplay. */
11942 redeem_scroll_bar_hook (w
);
11945 /* Restore current_buffer and value of point in it. */
11946 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
11947 set_buffer_internal_1 (old
);
11948 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
11950 unbind_to (count
, Qnil
);
11954 /* Build the complete desired matrix of WINDOW with a window start
11955 buffer position POS. Value is non-zero if successful. It is zero
11956 if fonts were loaded during redisplay which makes re-adjusting
11957 glyph matrices necessary. */
11960 try_window (window
, pos
)
11961 Lisp_Object window
;
11962 struct text_pos pos
;
11964 struct window
*w
= XWINDOW (window
);
11966 struct glyph_row
*last_text_row
= NULL
;
11968 /* Make POS the new window start. */
11969 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
11971 /* Mark cursor position as unknown. No overlay arrow seen. */
11972 w
->cursor
.vpos
= -1;
11973 overlay_arrow_seen
= 0;
11975 /* Initialize iterator and info to start at POS. */
11976 start_display (&it
, w
, pos
);
11978 /* Display all lines of W. */
11979 while (it
.current_y
< it
.last_visible_y
)
11981 if (display_line (&it
))
11982 last_text_row
= it
.glyph_row
- 1;
11983 if (fonts_changed_p
)
11987 /* If bottom moved off end of frame, change mode line percentage. */
11988 if (XFASTINT (w
->window_end_pos
) <= 0
11989 && Z
!= IT_CHARPOS (it
))
11990 w
->update_mode_line
= Qt
;
11992 /* Set window_end_pos to the offset of the last character displayed
11993 on the window from the end of current_buffer. Set
11994 window_end_vpos to its row number. */
11997 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
11998 w
->window_end_bytepos
11999 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12001 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12003 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12004 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12005 ->displays_text_p
);
12009 w
->window_end_bytepos
= 0;
12010 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
12013 /* But that is not valid info until redisplay finishes. */
12014 w
->window_end_valid
= Qnil
;
12020 /************************************************************************
12021 Window redisplay reusing current matrix when buffer has not changed
12022 ************************************************************************/
12024 /* Try redisplay of window W showing an unchanged buffer with a
12025 different window start than the last time it was displayed by
12026 reusing its current matrix. Value is non-zero if successful.
12027 W->start is the new window start. */
12030 try_window_reusing_current_matrix (w
)
12033 struct frame
*f
= XFRAME (w
->frame
);
12034 struct glyph_row
*row
, *bottom_row
;
12037 struct text_pos start
, new_start
;
12038 int nrows_scrolled
, i
;
12039 struct glyph_row
*last_text_row
;
12040 struct glyph_row
*last_reused_text_row
;
12041 struct glyph_row
*start_row
;
12042 int start_vpos
, min_y
, max_y
;
12045 if (inhibit_try_window_reusing
)
12049 if (/* This function doesn't handle terminal frames. */
12050 !FRAME_WINDOW_P (f
)
12051 /* Don't try to reuse the display if windows have been split
12053 || windows_or_buffers_changed
12054 || cursor_type_changed
)
12057 /* Can't do this if region may have changed. */
12058 if ((!NILP (Vtransient_mark_mode
)
12059 && !NILP (current_buffer
->mark_active
))
12060 || !NILP (w
->region_showing
)
12061 || !NILP (Vshow_trailing_whitespace
))
12064 /* If top-line visibility has changed, give up. */
12065 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12066 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12069 /* Give up if old or new display is scrolled vertically. We could
12070 make this function handle this, but right now it doesn't. */
12071 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12072 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
12075 /* The variable new_start now holds the new window start. The old
12076 start `start' can be determined from the current matrix. */
12077 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12078 start
= start_row
->start
.pos
;
12079 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12081 /* Clear the desired matrix for the display below. */
12082 clear_glyph_matrix (w
->desired_matrix
);
12084 if (CHARPOS (new_start
) <= CHARPOS (start
))
12088 /* Don't use this method if the display starts with an ellipsis
12089 displayed for invisible text. It's not easy to handle that case
12090 below, and it's certainly not worth the effort since this is
12091 not a frequent case. */
12092 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12095 IF_DEBUG (debug_method_add (w
, "twu1"));
12097 /* Display up to a row that can be reused. The variable
12098 last_text_row is set to the last row displayed that displays
12099 text. Note that it.vpos == 0 if or if not there is a
12100 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12101 start_display (&it
, w
, new_start
);
12102 first_row_y
= it
.current_y
;
12103 w
->cursor
.vpos
= -1;
12104 last_text_row
= last_reused_text_row
= NULL
;
12106 while (it
.current_y
< it
.last_visible_y
12107 && IT_CHARPOS (it
) < CHARPOS (start
)
12108 && !fonts_changed_p
)
12109 if (display_line (&it
))
12110 last_text_row
= it
.glyph_row
- 1;
12112 /* A value of current_y < last_visible_y means that we stopped
12113 at the previous window start, which in turn means that we
12114 have at least one reusable row. */
12115 if (it
.current_y
< it
.last_visible_y
)
12117 /* IT.vpos always starts from 0; it counts text lines. */
12118 nrows_scrolled
= it
.vpos
;
12120 /* Find PT if not already found in the lines displayed. */
12121 if (w
->cursor
.vpos
< 0)
12123 int dy
= it
.current_y
- first_row_y
;
12125 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12126 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12128 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12129 dy
, nrows_scrolled
);
12132 clear_glyph_matrix (w
->desired_matrix
);
12137 /* Scroll the display. Do it before the current matrix is
12138 changed. The problem here is that update has not yet
12139 run, i.e. part of the current matrix is not up to date.
12140 scroll_run_hook will clear the cursor, and use the
12141 current matrix to get the height of the row the cursor is
12143 run
.current_y
= first_row_y
;
12144 run
.desired_y
= it
.current_y
;
12145 run
.height
= it
.last_visible_y
- it
.current_y
;
12147 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12150 rif
->update_window_begin_hook (w
);
12151 rif
->clear_window_mouse_face (w
);
12152 rif
->scroll_run_hook (w
, &run
);
12153 rif
->update_window_end_hook (w
, 0, 0);
12157 /* Shift current matrix down by nrows_scrolled lines. */
12158 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12159 rotate_matrix (w
->current_matrix
,
12161 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12164 /* Disable lines that must be updated. */
12165 for (i
= 0; i
< it
.vpos
; ++i
)
12166 (start_row
+ i
)->enabled_p
= 0;
12168 /* Re-compute Y positions. */
12169 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
12170 max_y
= it
.last_visible_y
;
12171 for (row
= start_row
+ nrows_scrolled
;
12175 row
->y
= it
.current_y
;
12176 row
->visible_height
= row
->height
;
12178 if (row
->y
< min_y
)
12179 row
->visible_height
-= min_y
- row
->y
;
12180 if (row
->y
+ row
->height
> max_y
)
12181 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12183 it
.current_y
+= row
->height
;
12185 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12186 last_reused_text_row
= row
;
12187 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12191 /* Disable lines in the current matrix which are now
12192 below the window. */
12193 for (++row
; row
< bottom_row
; ++row
)
12194 row
->enabled_p
= 0;
12197 /* Update window_end_pos etc.; last_reused_text_row is the last
12198 reused row from the current matrix containing text, if any.
12199 The value of last_text_row is the last displayed line
12200 containing text. */
12201 if (last_reused_text_row
)
12203 w
->window_end_bytepos
12204 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12206 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12208 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12209 w
->current_matrix
));
12211 else if (last_text_row
)
12213 w
->window_end_bytepos
12214 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12216 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12218 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12222 /* This window must be completely empty. */
12223 w
->window_end_bytepos
= 0;
12224 w
->window_end_pos
= w
->window_end_vpos
= make_number (0);
12226 w
->window_end_valid
= Qnil
;
12228 /* Update hint: don't try scrolling again in update_window. */
12229 w
->desired_matrix
->no_scrolling_p
= 1;
12232 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12236 else if (CHARPOS (new_start
) > CHARPOS (start
))
12238 struct glyph_row
*pt_row
, *row
;
12239 struct glyph_row
*first_reusable_row
;
12240 struct glyph_row
*first_row_to_display
;
12242 int yb
= window_text_bottom_y (w
);
12244 /* Find the row starting at new_start, if there is one. Don't
12245 reuse a partially visible line at the end. */
12246 first_reusable_row
= start_row
;
12247 while (first_reusable_row
->enabled_p
12248 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12249 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12250 < CHARPOS (new_start
)))
12251 ++first_reusable_row
;
12253 /* Give up if there is no row to reuse. */
12254 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12255 || !first_reusable_row
->enabled_p
12256 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12257 != CHARPOS (new_start
)))
12260 /* We can reuse fully visible rows beginning with
12261 first_reusable_row to the end of the window. Set
12262 first_row_to_display to the first row that cannot be reused.
12263 Set pt_row to the row containing point, if there is any. */
12265 for (first_row_to_display
= first_reusable_row
;
12266 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12267 ++first_row_to_display
)
12269 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12270 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12271 pt_row
= first_row_to_display
;
12274 /* Start displaying at the start of first_row_to_display. */
12275 xassert (first_row_to_display
->y
< yb
);
12276 init_to_row_start (&it
, w
, first_row_to_display
);
12278 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12280 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12282 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12283 + WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
12285 /* Display lines beginning with first_row_to_display in the
12286 desired matrix. Set last_text_row to the last row displayed
12287 that displays text. */
12288 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12289 if (pt_row
== NULL
)
12290 w
->cursor
.vpos
= -1;
12291 last_text_row
= NULL
;
12292 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12293 if (display_line (&it
))
12294 last_text_row
= it
.glyph_row
- 1;
12296 /* Give up If point isn't in a row displayed or reused. */
12297 if (w
->cursor
.vpos
< 0)
12299 clear_glyph_matrix (w
->desired_matrix
);
12303 /* If point is in a reused row, adjust y and vpos of the cursor
12307 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
12308 w
->current_matrix
);
12309 w
->cursor
.y
-= first_reusable_row
->y
;
12312 /* Scroll the display. */
12313 run
.current_y
= first_reusable_row
->y
;
12314 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
12315 run
.height
= it
.last_visible_y
- run
.current_y
;
12316 dy
= run
.current_y
- run
.desired_y
;
12320 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12322 rif
->update_window_begin_hook (w
);
12323 rif
->clear_window_mouse_face (w
);
12324 rif
->scroll_run_hook (w
, &run
);
12325 rif
->update_window_end_hook (w
, 0, 0);
12329 /* Adjust Y positions of reused rows. */
12330 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12331 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
12332 max_y
= it
.last_visible_y
;
12333 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12336 row
->visible_height
= row
->height
;
12337 if (row
->y
< min_y
)
12338 row
->visible_height
-= min_y
- row
->y
;
12339 if (row
->y
+ row
->height
> max_y
)
12340 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12343 /* Scroll the current matrix. */
12344 xassert (nrows_scrolled
> 0);
12345 rotate_matrix (w
->current_matrix
,
12347 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12350 /* Disable rows not reused. */
12351 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12352 row
->enabled_p
= 0;
12354 /* Adjust window end. A null value of last_text_row means that
12355 the window end is in reused rows which in turn means that
12356 only its vpos can have changed. */
12359 w
->window_end_bytepos
12360 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12362 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12364 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12369 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12372 w
->window_end_valid
= Qnil
;
12373 w
->desired_matrix
->no_scrolling_p
= 1;
12376 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12386 /************************************************************************
12387 Window redisplay reusing current matrix when buffer has changed
12388 ************************************************************************/
12390 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12391 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12393 static struct glyph_row
*
12394 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12395 struct glyph_row
*));
12398 /* Return the last row in MATRIX displaying text. If row START is
12399 non-null, start searching with that row. IT gives the dimensions
12400 of the display. Value is null if matrix is empty; otherwise it is
12401 a pointer to the row found. */
12403 static struct glyph_row
*
12404 find_last_row_displaying_text (matrix
, it
, start
)
12405 struct glyph_matrix
*matrix
;
12407 struct glyph_row
*start
;
12409 struct glyph_row
*row
, *row_found
;
12411 /* Set row_found to the last row in IT->w's current matrix
12412 displaying text. The loop looks funny but think of partially
12415 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
12416 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12418 xassert (row
->enabled_p
);
12420 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
12429 /* Return the last row in the current matrix of W that is not affected
12430 by changes at the start of current_buffer that occurred since W's
12431 current matrix was built. Value is null if no such row exists.
12433 BEG_UNCHANGED us the number of characters unchanged at the start of
12434 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
12435 first changed character in current_buffer. Characters at positions <
12436 BEG + BEG_UNCHANGED are at the same buffer positions as they were
12437 when the current matrix was built. */
12439 static struct glyph_row
*
12440 find_last_unchanged_at_beg_row (w
)
12443 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
12444 struct glyph_row
*row
;
12445 struct glyph_row
*row_found
= NULL
;
12446 int yb
= window_text_bottom_y (w
);
12448 /* Find the last row displaying unchanged text. */
12449 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12450 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12451 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
12453 if (/* If row ends before first_changed_pos, it is unchanged,
12454 except in some case. */
12455 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
12456 /* When row ends in ZV and we write at ZV it is not
12458 && !row
->ends_at_zv_p
12459 /* When first_changed_pos is the end of a continued line,
12460 row is not unchanged because it may be no longer
12462 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
12463 && row
->continued_p
))
12466 /* Stop if last visible row. */
12467 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
12477 /* Find the first glyph row in the current matrix of W that is not
12478 affected by changes at the end of current_buffer since the
12479 time W's current matrix was built.
12481 Return in *DELTA the number of chars by which buffer positions in
12482 unchanged text at the end of current_buffer must be adjusted.
12484 Return in *DELTA_BYTES the corresponding number of bytes.
12486 Value is null if no such row exists, i.e. all rows are affected by
12489 static struct glyph_row
*
12490 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
12492 int *delta
, *delta_bytes
;
12494 struct glyph_row
*row
;
12495 struct glyph_row
*row_found
= NULL
;
12497 *delta
= *delta_bytes
= 0;
12499 /* Display must not have been paused, otherwise the current matrix
12500 is not up to date. */
12501 if (NILP (w
->window_end_valid
))
12504 /* A value of window_end_pos >= END_UNCHANGED means that the window
12505 end is in the range of changed text. If so, there is no
12506 unchanged row at the end of W's current matrix. */
12507 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
12510 /* Set row to the last row in W's current matrix displaying text. */
12511 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12513 /* If matrix is entirely empty, no unchanged row exists. */
12514 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12516 /* The value of row is the last glyph row in the matrix having a
12517 meaningful buffer position in it. The end position of row
12518 corresponds to window_end_pos. This allows us to translate
12519 buffer positions in the current matrix to current buffer
12520 positions for characters not in changed text. */
12521 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12522 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12523 int last_unchanged_pos
, last_unchanged_pos_old
;
12524 struct glyph_row
*first_text_row
12525 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12527 *delta
= Z
- Z_old
;
12528 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12530 /* Set last_unchanged_pos to the buffer position of the last
12531 character in the buffer that has not been changed. Z is the
12532 index + 1 of the last character in current_buffer, i.e. by
12533 subtracting END_UNCHANGED we get the index of the last
12534 unchanged character, and we have to add BEG to get its buffer
12536 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
12537 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
12539 /* Search backward from ROW for a row displaying a line that
12540 starts at a minimum position >= last_unchanged_pos_old. */
12541 for (; row
> first_text_row
; --row
)
12543 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12546 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
12551 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
12558 /* Make sure that glyph rows in the current matrix of window W
12559 reference the same glyph memory as corresponding rows in the
12560 frame's frame matrix. This function is called after scrolling W's
12561 current matrix on a terminal frame in try_window_id and
12562 try_window_reusing_current_matrix. */
12565 sync_frame_with_window_matrix_rows (w
)
12568 struct frame
*f
= XFRAME (w
->frame
);
12569 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
12571 /* Preconditions: W must be a leaf window and full-width. Its frame
12572 must have a frame matrix. */
12573 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
12574 xassert (WINDOW_FULL_WIDTH_P (w
));
12575 xassert (!FRAME_WINDOW_P (f
));
12577 /* If W is a full-width window, glyph pointers in W's current matrix
12578 have, by definition, to be the same as glyph pointers in the
12579 corresponding frame matrix. Note that frame matrices have no
12580 marginal areas (see build_frame_matrix). */
12581 window_row
= w
->current_matrix
->rows
;
12582 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
12583 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
12584 while (window_row
< window_row_end
)
12586 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
12587 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
12589 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
12590 frame_row
->glyphs
[TEXT_AREA
] = start
;
12591 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
12592 frame_row
->glyphs
[LAST_AREA
] = end
;
12594 /* Disable frame rows whose corresponding window rows have
12595 been disabled in try_window_id. */
12596 if (!window_row
->enabled_p
)
12597 frame_row
->enabled_p
= 0;
12599 ++window_row
, ++frame_row
;
12604 /* Find the glyph row in window W containing CHARPOS. Consider all
12605 rows between START and END (not inclusive). END null means search
12606 all rows to the end of the display area of W. Value is the row
12607 containing CHARPOS or null. */
12610 row_containing_pos (w
, charpos
, start
, end
, dy
)
12613 struct glyph_row
*start
, *end
;
12616 struct glyph_row
*row
= start
;
12619 /* If we happen to start on a header-line, skip that. */
12620 if (row
->mode_line_p
)
12623 if ((end
&& row
>= end
) || !row
->enabled_p
)
12626 last_y
= window_text_bottom_y (w
) - dy
;
12630 /* Give up if we have gone too far. */
12631 if (end
&& row
>= end
)
12633 /* This formerly returned if they were equal.
12634 I think that both quantities are of a "last plus one" type;
12635 if so, when they are equal, the row is within the screen. -- rms. */
12636 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
12639 /* If it is in this row, return this row. */
12640 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
12641 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
12642 /* The end position of a row equals the start
12643 position of the next row. If CHARPOS is there, we
12644 would rather display it in the next line, except
12645 when this line ends in ZV. */
12646 && !row
->ends_at_zv_p
12647 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12648 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
12655 /* Try to redisplay window W by reusing its existing display. W's
12656 current matrix must be up to date when this function is called,
12657 i.e. window_end_valid must not be nil.
12661 1 if display has been updated
12662 0 if otherwise unsuccessful
12663 -1 if redisplay with same window start is known not to succeed
12665 The following steps are performed:
12667 1. Find the last row in the current matrix of W that is not
12668 affected by changes at the start of current_buffer. If no such row
12671 2. Find the first row in W's current matrix that is not affected by
12672 changes at the end of current_buffer. Maybe there is no such row.
12674 3. Display lines beginning with the row + 1 found in step 1 to the
12675 row found in step 2 or, if step 2 didn't find a row, to the end of
12678 4. If cursor is not known to appear on the window, give up.
12680 5. If display stopped at the row found in step 2, scroll the
12681 display and current matrix as needed.
12683 6. Maybe display some lines at the end of W, if we must. This can
12684 happen under various circumstances, like a partially visible line
12685 becoming fully visible, or because newly displayed lines are displayed
12686 in smaller font sizes.
12688 7. Update W's window end information. */
12694 struct frame
*f
= XFRAME (w
->frame
);
12695 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
12696 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
12697 struct glyph_row
*last_unchanged_at_beg_row
;
12698 struct glyph_row
*first_unchanged_at_end_row
;
12699 struct glyph_row
*row
;
12700 struct glyph_row
*bottom_row
;
12703 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
12704 struct text_pos start_pos
;
12706 int first_unchanged_at_end_vpos
= 0;
12707 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
12708 struct text_pos start
;
12709 int first_changed_charpos
, last_changed_charpos
;
12712 if (inhibit_try_window_id
)
12716 /* This is handy for debugging. */
12718 #define GIVE_UP(X) \
12720 fprintf (stderr, "try_window_id give up %d\n", (X)); \
12724 #define GIVE_UP(X) return 0
12727 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
12729 /* Don't use this for mini-windows because these can show
12730 messages and mini-buffers, and we don't handle that here. */
12731 if (MINI_WINDOW_P (w
))
12734 /* This flag is used to prevent redisplay optimizations. */
12735 if (windows_or_buffers_changed
|| cursor_type_changed
)
12738 /* Verify that narrowing has not changed.
12739 Also verify that we were not told to prevent redisplay optimizations.
12740 It would be nice to further
12741 reduce the number of cases where this prevents try_window_id. */
12742 if (current_buffer
->clip_changed
12743 || current_buffer
->prevent_redisplay_optimizations_p
)
12746 /* Window must either use window-based redisplay or be full width. */
12747 if (!FRAME_WINDOW_P (f
)
12748 && (!line_ins_del_ok
12749 || !WINDOW_FULL_WIDTH_P (w
)))
12752 /* Give up if point is not known NOT to appear in W. */
12753 if (PT
< CHARPOS (start
))
12756 /* Another way to prevent redisplay optimizations. */
12757 if (XFASTINT (w
->last_modified
) == 0)
12760 /* Verify that window is not hscrolled. */
12761 if (XFASTINT (w
->hscroll
) != 0)
12764 /* Verify that display wasn't paused. */
12765 if (NILP (w
->window_end_valid
))
12768 /* Can't use this if highlighting a region because a cursor movement
12769 will do more than just set the cursor. */
12770 if (!NILP (Vtransient_mark_mode
)
12771 && !NILP (current_buffer
->mark_active
))
12774 /* Likewise if highlighting trailing whitespace. */
12775 if (!NILP (Vshow_trailing_whitespace
))
12778 /* Likewise if showing a region. */
12779 if (!NILP (w
->region_showing
))
12782 /* Can use this if overlay arrow position and or string have changed. */
12783 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
12784 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
12788 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
12789 only if buffer has really changed. The reason is that the gap is
12790 initially at Z for freshly visited files. The code below would
12791 set end_unchanged to 0 in that case. */
12792 if (MODIFF
> SAVE_MODIFF
12793 /* This seems to happen sometimes after saving a buffer. */
12794 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
12796 if (GPT
- BEG
< BEG_UNCHANGED
)
12797 BEG_UNCHANGED
= GPT
- BEG
;
12798 if (Z
- GPT
< END_UNCHANGED
)
12799 END_UNCHANGED
= Z
- GPT
;
12802 /* The position of the first and last character that has been changed. */
12803 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
12804 last_changed_charpos
= Z
- END_UNCHANGED
;
12806 /* If window starts after a line end, and the last change is in
12807 front of that newline, then changes don't affect the display.
12808 This case happens with stealth-fontification. Note that although
12809 the display is unchanged, glyph positions in the matrix have to
12810 be adjusted, of course. */
12811 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12812 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12813 && ((last_changed_charpos
< CHARPOS (start
)
12814 && CHARPOS (start
) == BEGV
)
12815 || (last_changed_charpos
< CHARPOS (start
) - 1
12816 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
12818 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
12819 struct glyph_row
*r0
;
12821 /* Compute how many chars/bytes have been added to or removed
12822 from the buffer. */
12823 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12824 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12826 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12828 /* Give up if PT is not in the window. Note that it already has
12829 been checked at the start of try_window_id that PT is not in
12830 front of the window start. */
12831 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
12834 /* If window start is unchanged, we can reuse the whole matrix
12835 as is, after adjusting glyph positions. No need to compute
12836 the window end again, since its offset from Z hasn't changed. */
12837 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
12838 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
12839 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
)
12841 /* Adjust positions in the glyph matrix. */
12842 if (delta
|| delta_bytes
)
12844 struct glyph_row
*r1
12845 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
12846 increment_matrix_positions (w
->current_matrix
,
12847 MATRIX_ROW_VPOS (r0
, current_matrix
),
12848 MATRIX_ROW_VPOS (r1
, current_matrix
),
12849 delta
, delta_bytes
);
12852 /* Set the cursor. */
12853 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
12855 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
12862 /* Handle the case that changes are all below what is displayed in
12863 the window, and that PT is in the window. This shortcut cannot
12864 be taken if ZV is visible in the window, and text has been added
12865 there that is visible in the window. */
12866 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
12867 /* ZV is not visible in the window, or there are no
12868 changes at ZV, actually. */
12869 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
12870 || first_changed_charpos
== last_changed_charpos
))
12872 struct glyph_row
*r0
;
12874 /* Give up if PT is not in the window. Note that it already has
12875 been checked at the start of try_window_id that PT is not in
12876 front of the window start. */
12877 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
12880 /* If window start is unchanged, we can reuse the whole matrix
12881 as is, without changing glyph positions since no text has
12882 been added/removed in front of the window end. */
12883 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
12884 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
))
12886 /* We have to compute the window end anew since text
12887 can have been added/removed after it. */
12889 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12890 w
->window_end_bytepos
12891 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12893 /* Set the cursor. */
12894 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
12896 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
12903 /* Give up if window start is in the changed area.
12905 The condition used to read
12907 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
12909 but why that was tested escapes me at the moment. */
12910 if (CHARPOS (start
) >= first_changed_charpos
12911 && CHARPOS (start
) <= last_changed_charpos
)
12914 /* Check that window start agrees with the start of the first glyph
12915 row in its current matrix. Check this after we know the window
12916 start is not in changed text, otherwise positions would not be
12918 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
12919 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
12922 /* Give up if the window ends in strings. Overlay strings
12923 at the end are difficult to handle, so don't try. */
12924 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
12925 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
12928 /* Compute the position at which we have to start displaying new
12929 lines. Some of the lines at the top of the window might be
12930 reusable because they are not displaying changed text. Find the
12931 last row in W's current matrix not affected by changes at the
12932 start of current_buffer. Value is null if changes start in the
12933 first line of window. */
12934 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
12935 if (last_unchanged_at_beg_row
)
12937 /* Avoid starting to display in the moddle of a character, a TAB
12938 for instance. This is easier than to set up the iterator
12939 exactly, and it's not a frequent case, so the additional
12940 effort wouldn't really pay off. */
12941 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
12942 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
12943 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
12944 --last_unchanged_at_beg_row
;
12946 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
12949 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
12951 start_pos
= it
.current
.pos
;
12953 /* Start displaying new lines in the desired matrix at the same
12954 vpos we would use in the current matrix, i.e. below
12955 last_unchanged_at_beg_row. */
12956 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
12958 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
12959 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
12961 xassert (it
.hpos
== 0 && it
.current_x
== 0);
12965 /* There are no reusable lines at the start of the window.
12966 Start displaying in the first line. */
12967 start_display (&it
, w
, start
);
12968 start_pos
= it
.current
.pos
;
12971 /* Find the first row that is not affected by changes at the end of
12972 the buffer. Value will be null if there is no unchanged row, in
12973 which case we must redisplay to the end of the window. delta
12974 will be set to the value by which buffer positions beginning with
12975 first_unchanged_at_end_row have to be adjusted due to text
12977 first_unchanged_at_end_row
12978 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
12979 IF_DEBUG (debug_delta
= delta
);
12980 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
12982 /* Set stop_pos to the buffer position up to which we will have to
12983 display new lines. If first_unchanged_at_end_row != NULL, this
12984 is the buffer position of the start of the line displayed in that
12985 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
12986 that we don't stop at a buffer position. */
12988 if (first_unchanged_at_end_row
)
12990 xassert (last_unchanged_at_beg_row
== NULL
12991 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
12993 /* If this is a continuation line, move forward to the next one
12994 that isn't. Changes in lines above affect this line.
12995 Caution: this may move first_unchanged_at_end_row to a row
12996 not displaying text. */
12997 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
12998 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
12999 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13000 < it
.last_visible_y
))
13001 ++first_unchanged_at_end_row
;
13003 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13004 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13005 >= it
.last_visible_y
))
13006 first_unchanged_at_end_row
= NULL
;
13009 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13011 first_unchanged_at_end_vpos
13012 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13013 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13016 else if (last_unchanged_at_beg_row
== NULL
)
13022 /* Either there is no unchanged row at the end, or the one we have
13023 now displays text. This is a necessary condition for the window
13024 end pos calculation at the end of this function. */
13025 xassert (first_unchanged_at_end_row
== NULL
13026 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13028 debug_last_unchanged_at_beg_vpos
13029 = (last_unchanged_at_beg_row
13030 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13032 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13034 #endif /* GLYPH_DEBUG != 0 */
13037 /* Display new lines. Set last_text_row to the last new line
13038 displayed which has text on it, i.e. might end up as being the
13039 line where the window_end_vpos is. */
13040 w
->cursor
.vpos
= -1;
13041 last_text_row
= NULL
;
13042 overlay_arrow_seen
= 0;
13043 while (it
.current_y
< it
.last_visible_y
13044 && !fonts_changed_p
13045 && (first_unchanged_at_end_row
== NULL
13046 || IT_CHARPOS (it
) < stop_pos
))
13048 if (display_line (&it
))
13049 last_text_row
= it
.glyph_row
- 1;
13052 if (fonts_changed_p
)
13056 /* Compute differences in buffer positions, y-positions etc. for
13057 lines reused at the bottom of the window. Compute what we can
13059 if (first_unchanged_at_end_row
13060 /* No lines reused because we displayed everything up to the
13061 bottom of the window. */
13062 && it
.current_y
< it
.last_visible_y
)
13065 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13067 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13068 run
.current_y
= first_unchanged_at_end_row
->y
;
13069 run
.desired_y
= run
.current_y
+ dy
;
13070 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13074 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13075 first_unchanged_at_end_row
= NULL
;
13077 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13080 /* Find the cursor if not already found. We have to decide whether
13081 PT will appear on this window (it sometimes doesn't, but this is
13082 not a very frequent case.) This decision has to be made before
13083 the current matrix is altered. A value of cursor.vpos < 0 means
13084 that PT is either in one of the lines beginning at
13085 first_unchanged_at_end_row or below the window. Don't care for
13086 lines that might be displayed later at the window end; as
13087 mentioned, this is not a frequent case. */
13088 if (w
->cursor
.vpos
< 0)
13090 /* Cursor in unchanged rows at the top? */
13091 if (PT
< CHARPOS (start_pos
)
13092 && last_unchanged_at_beg_row
)
13094 row
= row_containing_pos (w
, PT
,
13095 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13096 last_unchanged_at_beg_row
+ 1, 0);
13098 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13101 /* Start from first_unchanged_at_end_row looking for PT. */
13102 else if (first_unchanged_at_end_row
)
13104 row
= row_containing_pos (w
, PT
- delta
,
13105 first_unchanged_at_end_row
, NULL
, 0);
13107 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13108 delta_bytes
, dy
, dvpos
);
13111 /* Give up if cursor was not found. */
13112 if (w
->cursor
.vpos
< 0)
13114 clear_glyph_matrix (w
->desired_matrix
);
13119 /* Don't let the cursor end in the scroll margins. */
13121 int this_scroll_margin
, cursor_height
;
13123 this_scroll_margin
= max (0, scroll_margin
);
13124 this_scroll_margin
= min (this_scroll_margin
,
13125 XFASTINT (w
->height
) / 4);
13126 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
13127 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13129 if ((w
->cursor
.y
< this_scroll_margin
13130 && CHARPOS (start
) > BEGV
)
13131 /* Don't take scroll margin into account at the bottom because
13132 old redisplay didn't do it either. */
13133 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
13135 w
->cursor
.vpos
= -1;
13136 clear_glyph_matrix (w
->desired_matrix
);
13141 /* Scroll the display. Do it before changing the current matrix so
13142 that xterm.c doesn't get confused about where the cursor glyph is
13144 if (dy
&& run
.height
)
13148 if (FRAME_WINDOW_P (f
))
13150 rif
->update_window_begin_hook (w
);
13151 rif
->clear_window_mouse_face (w
);
13152 rif
->scroll_run_hook (w
, &run
);
13153 rif
->update_window_end_hook (w
, 0, 0);
13157 /* Terminal frame. In this case, dvpos gives the number of
13158 lines to scroll by; dvpos < 0 means scroll up. */
13159 int first_unchanged_at_end_vpos
13160 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13161 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
13162 int end
= (XFASTINT (w
->top
)
13163 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13164 + window_internal_height (w
));
13166 /* Perform the operation on the screen. */
13169 /* Scroll last_unchanged_at_beg_row to the end of the
13170 window down dvpos lines. */
13171 set_terminal_window (end
);
13173 /* On dumb terminals delete dvpos lines at the end
13174 before inserting dvpos empty lines. */
13175 if (!scroll_region_ok
)
13176 ins_del_lines (end
- dvpos
, -dvpos
);
13178 /* Insert dvpos empty lines in front of
13179 last_unchanged_at_beg_row. */
13180 ins_del_lines (from
, dvpos
);
13182 else if (dvpos
< 0)
13184 /* Scroll up last_unchanged_at_beg_vpos to the end of
13185 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13186 set_terminal_window (end
);
13188 /* Delete dvpos lines in front of
13189 last_unchanged_at_beg_vpos. ins_del_lines will set
13190 the cursor to the given vpos and emit |dvpos| delete
13192 ins_del_lines (from
+ dvpos
, dvpos
);
13194 /* On a dumb terminal insert dvpos empty lines at the
13196 if (!scroll_region_ok
)
13197 ins_del_lines (end
+ dvpos
, -dvpos
);
13200 set_terminal_window (0);
13206 /* Shift reused rows of the current matrix to the right position.
13207 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13209 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13210 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13213 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13214 bottom_vpos
, dvpos
);
13215 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13218 else if (dvpos
> 0)
13220 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13221 bottom_vpos
, dvpos
);
13222 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13223 first_unchanged_at_end_vpos
+ dvpos
, 0);
13226 /* For frame-based redisplay, make sure that current frame and window
13227 matrix are in sync with respect to glyph memory. */
13228 if (!FRAME_WINDOW_P (f
))
13229 sync_frame_with_window_matrix_rows (w
);
13231 /* Adjust buffer positions in reused rows. */
13233 increment_matrix_positions (current_matrix
,
13234 first_unchanged_at_end_vpos
+ dvpos
,
13235 bottom_vpos
, delta
, delta_bytes
);
13237 /* Adjust Y positions. */
13239 shift_glyph_matrix (w
, current_matrix
,
13240 first_unchanged_at_end_vpos
+ dvpos
,
13243 if (first_unchanged_at_end_row
)
13244 first_unchanged_at_end_row
+= dvpos
;
13246 /* If scrolling up, there may be some lines to display at the end of
13248 last_text_row_at_end
= NULL
;
13251 /* Scrolling up can leave for example a partially visible line
13252 at the end of the window to be redisplayed. */
13253 /* Set last_row to the glyph row in the current matrix where the
13254 window end line is found. It has been moved up or down in
13255 the matrix by dvpos. */
13256 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13257 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13259 /* If last_row is the window end line, it should display text. */
13260 xassert (last_row
->displays_text_p
);
13262 /* If window end line was partially visible before, begin
13263 displaying at that line. Otherwise begin displaying with the
13264 line following it. */
13265 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13267 init_to_row_start (&it
, w
, last_row
);
13268 it
.vpos
= last_vpos
;
13269 it
.current_y
= last_row
->y
;
13273 init_to_row_end (&it
, w
, last_row
);
13274 it
.vpos
= 1 + last_vpos
;
13275 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13279 /* We may start in a continuation line. If so, we have to
13280 get the right continuation_lines_width and current_x. */
13281 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13282 it
.hpos
= it
.current_x
= 0;
13284 /* Display the rest of the lines at the window end. */
13285 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13286 while (it
.current_y
< it
.last_visible_y
13287 && !fonts_changed_p
)
13289 /* Is it always sure that the display agrees with lines in
13290 the current matrix? I don't think so, so we mark rows
13291 displayed invalid in the current matrix by setting their
13292 enabled_p flag to zero. */
13293 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13294 if (display_line (&it
))
13295 last_text_row_at_end
= it
.glyph_row
- 1;
13299 /* Update window_end_pos and window_end_vpos. */
13300 if (first_unchanged_at_end_row
13301 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13302 && !last_text_row_at_end
)
13304 /* Window end line if one of the preserved rows from the current
13305 matrix. Set row to the last row displaying text in current
13306 matrix starting at first_unchanged_at_end_row, after
13308 xassert (first_unchanged_at_end_row
->displays_text_p
);
13309 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13310 first_unchanged_at_end_row
);
13311 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13313 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13314 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13316 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13317 xassert (w
->window_end_bytepos
>= 0);
13318 IF_DEBUG (debug_method_add (w
, "A"));
13320 else if (last_text_row_at_end
)
13323 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13324 w
->window_end_bytepos
13325 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13327 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13328 xassert (w
->window_end_bytepos
>= 0);
13329 IF_DEBUG (debug_method_add (w
, "B"));
13331 else if (last_text_row
)
13333 /* We have displayed either to the end of the window or at the
13334 end of the window, i.e. the last row with text is to be found
13335 in the desired matrix. */
13337 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13338 w
->window_end_bytepos
13339 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13341 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13342 xassert (w
->window_end_bytepos
>= 0);
13344 else if (first_unchanged_at_end_row
== NULL
13345 && last_text_row
== NULL
13346 && last_text_row_at_end
== NULL
)
13348 /* Displayed to end of window, but no line containing text was
13349 displayed. Lines were deleted at the end of the window. */
13350 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13351 int vpos
= XFASTINT (w
->window_end_vpos
);
13352 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13353 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13356 row
== NULL
&& vpos
>= first_vpos
;
13357 --vpos
, --current_row
, --desired_row
)
13359 if (desired_row
->enabled_p
)
13361 if (desired_row
->displays_text_p
)
13364 else if (current_row
->displays_text_p
)
13368 xassert (row
!= NULL
);
13369 w
->window_end_vpos
= make_number (vpos
+ 1);
13370 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13371 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13372 xassert (w
->window_end_bytepos
>= 0);
13373 IF_DEBUG (debug_method_add (w
, "C"));
13378 #if 0 /* This leads to problems, for instance when the cursor is
13379 at ZV, and the cursor line displays no text. */
13380 /* Disable rows below what's displayed in the window. This makes
13381 debugging easier. */
13382 enable_glyph_matrix_rows (current_matrix
,
13383 XFASTINT (w
->window_end_vpos
) + 1,
13387 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13388 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13390 /* Record that display has not been completed. */
13391 w
->window_end_valid
= Qnil
;
13392 w
->desired_matrix
->no_scrolling_p
= 1;
13400 /***********************************************************************
13401 More debugging support
13402 ***********************************************************************/
13406 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13407 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
13408 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
13411 /* Dump the contents of glyph matrix MATRIX on stderr.
13413 GLYPHS 0 means don't show glyph contents.
13414 GLYPHS 1 means show glyphs in short form
13415 GLYPHS > 1 means show glyphs in long form. */
13418 dump_glyph_matrix (matrix
, glyphs
)
13419 struct glyph_matrix
*matrix
;
13423 for (i
= 0; i
< matrix
->nrows
; ++i
)
13424 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
13428 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
13429 the glyph row and area where the glyph comes from. */
13432 dump_glyph (row
, glyph
, area
)
13433 struct glyph_row
*row
;
13434 struct glyph
*glyph
;
13437 if (glyph
->type
== CHAR_GLYPH
)
13440 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13441 glyph
- row
->glyphs
[TEXT_AREA
],
13444 (BUFFERP (glyph
->object
)
13446 : (STRINGP (glyph
->object
)
13449 glyph
->pixel_width
,
13451 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
13455 glyph
->left_box_line_p
,
13456 glyph
->right_box_line_p
);
13458 else if (glyph
->type
== STRETCH_GLYPH
)
13461 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13462 glyph
- row
->glyphs
[TEXT_AREA
],
13465 (BUFFERP (glyph
->object
)
13467 : (STRINGP (glyph
->object
)
13470 glyph
->pixel_width
,
13474 glyph
->left_box_line_p
,
13475 glyph
->right_box_line_p
);
13477 else if (glyph
->type
== IMAGE_GLYPH
)
13480 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13481 glyph
- row
->glyphs
[TEXT_AREA
],
13484 (BUFFERP (glyph
->object
)
13486 : (STRINGP (glyph
->object
)
13489 glyph
->pixel_width
,
13493 glyph
->left_box_line_p
,
13494 glyph
->right_box_line_p
);
13499 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
13500 GLYPHS 0 means don't show glyph contents.
13501 GLYPHS 1 means show glyphs in short form
13502 GLYPHS > 1 means show glyphs in long form. */
13505 dump_glyph_row (row
, vpos
, glyphs
)
13506 struct glyph_row
*row
;
13511 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
13512 fprintf (stderr
, "=======================================================================\n");
13514 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
13515 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
13517 MATRIX_ROW_START_CHARPOS (row
),
13518 MATRIX_ROW_END_CHARPOS (row
),
13519 row
->used
[TEXT_AREA
],
13520 row
->contains_overlapping_glyphs_p
,
13522 row
->truncated_on_left_p
,
13523 row
->truncated_on_right_p
,
13524 row
->overlay_arrow_p
,
13526 MATRIX_ROW_CONTINUATION_LINE_P (row
),
13527 row
->displays_text_p
,
13530 row
->ends_in_middle_of_char_p
,
13531 row
->starts_in_middle_of_char_p
,
13537 row
->visible_height
,
13540 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
13541 row
->end
.overlay_string_index
,
13542 row
->continuation_lines_width
);
13543 fprintf (stderr
, "%9d %5d\n",
13544 CHARPOS (row
->start
.string_pos
),
13545 CHARPOS (row
->end
.string_pos
));
13546 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
13547 row
->end
.dpvec_index
);
13554 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13556 struct glyph
*glyph
= row
->glyphs
[area
];
13557 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
13559 /* Glyph for a line end in text. */
13560 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
13563 if (glyph
< glyph_end
)
13564 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
13566 for (; glyph
< glyph_end
; ++glyph
)
13567 dump_glyph (row
, glyph
, area
);
13570 else if (glyphs
== 1)
13574 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13576 char *s
= (char *) alloca (row
->used
[area
] + 1);
13579 for (i
= 0; i
< row
->used
[area
]; ++i
)
13581 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
13582 if (glyph
->type
== CHAR_GLYPH
13583 && glyph
->u
.ch
< 0x80
13584 && glyph
->u
.ch
>= ' ')
13585 s
[i
] = glyph
->u
.ch
;
13591 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
13597 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
13598 Sdump_glyph_matrix
, 0, 1, "p",
13599 doc
: /* Dump the current matrix of the selected window to stderr.
13600 Shows contents of glyph row structures. With non-nil
13601 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
13602 glyphs in short form, otherwise show glyphs in long form. */)
13604 Lisp_Object glyphs
;
13606 struct window
*w
= XWINDOW (selected_window
);
13607 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13609 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
13610 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
13611 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
13612 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
13613 fprintf (stderr
, "=============================================\n");
13614 dump_glyph_matrix (w
->current_matrix
,
13615 NILP (glyphs
) ? 0 : XINT (glyphs
));
13620 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
13621 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
13624 struct frame
*f
= XFRAME (selected_frame
);
13625 dump_glyph_matrix (f
->current_matrix
, 1);
13630 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
13631 doc
: /* Dump glyph row ROW to stderr.
13632 GLYPH 0 means don't dump glyphs.
13633 GLYPH 1 means dump glyphs in short form.
13634 GLYPH > 1 or omitted means dump glyphs in long form. */)
13636 Lisp_Object row
, glyphs
;
13638 struct glyph_matrix
*matrix
;
13641 CHECK_NUMBER (row
);
13642 matrix
= XWINDOW (selected_window
)->current_matrix
;
13644 if (vpos
>= 0 && vpos
< matrix
->nrows
)
13645 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
13647 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13652 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
13653 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
13654 GLYPH 0 means don't dump glyphs.
13655 GLYPH 1 means dump glyphs in short form.
13656 GLYPH > 1 or omitted means dump glyphs in long form. */)
13658 Lisp_Object row
, glyphs
;
13660 struct frame
*sf
= SELECTED_FRAME ();
13661 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
13664 CHECK_NUMBER (row
);
13666 if (vpos
>= 0 && vpos
< m
->nrows
)
13667 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
13668 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13673 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
13674 doc
: /* Toggle tracing of redisplay.
13675 With ARG, turn tracing on if and only if ARG is positive. */)
13680 trace_redisplay_p
= !trace_redisplay_p
;
13683 arg
= Fprefix_numeric_value (arg
);
13684 trace_redisplay_p
= XINT (arg
) > 0;
13691 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
13692 doc
: /* Like `format', but print result to stderr.
13693 usage: (trace-to-stderr STRING &rest OBJECTS) */)
13698 Lisp_Object s
= Fformat (nargs
, args
);
13699 fprintf (stderr
, "%s", SDATA (s
));
13703 #endif /* GLYPH_DEBUG */
13707 /***********************************************************************
13708 Building Desired Matrix Rows
13709 ***********************************************************************/
13711 /* Return a temporary glyph row holding the glyphs of an overlay
13712 arrow. Only used for non-window-redisplay windows. */
13714 static struct glyph_row
*
13715 get_overlay_arrow_glyph_row (w
)
13718 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13719 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13720 struct buffer
*old
= current_buffer
;
13721 const unsigned char *arrow_string
= SDATA (Voverlay_arrow_string
);
13722 int arrow_len
= SCHARS (Voverlay_arrow_string
);
13723 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
13724 const unsigned char *p
;
13727 int n_glyphs_before
;
13729 set_buffer_temp (buffer
);
13730 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
13731 it
.glyph_row
->used
[TEXT_AREA
] = 0;
13732 SET_TEXT_POS (it
.position
, 0, 0);
13734 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
13736 while (p
< arrow_end
)
13738 Lisp_Object face
, ilisp
;
13740 /* Get the next character. */
13742 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
13744 it
.c
= *p
, it
.len
= 1;
13747 /* Get its face. */
13748 ilisp
= make_number (p
- arrow_string
);
13749 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
13750 it
.face_id
= compute_char_face (f
, it
.c
, face
);
13752 /* Compute its width, get its glyphs. */
13753 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
13754 SET_TEXT_POS (it
.position
, -1, -1);
13755 PRODUCE_GLYPHS (&it
);
13757 /* If this character doesn't fit any more in the line, we have
13758 to remove some glyphs. */
13759 if (it
.current_x
> it
.last_visible_x
)
13761 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
13766 set_buffer_temp (old
);
13767 return it
.glyph_row
;
13771 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
13772 glyphs are only inserted for terminal frames since we can't really
13773 win with truncation glyphs when partially visible glyphs are
13774 involved. Which glyphs to insert is determined by
13775 produce_special_glyphs. */
13778 insert_left_trunc_glyphs (it
)
13781 struct it truncate_it
;
13782 struct glyph
*from
, *end
, *to
, *toend
;
13784 xassert (!FRAME_WINDOW_P (it
->f
));
13786 /* Get the truncation glyphs. */
13788 truncate_it
.current_x
= 0;
13789 truncate_it
.face_id
= DEFAULT_FACE_ID
;
13790 truncate_it
.glyph_row
= &scratch_glyph_row
;
13791 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
13792 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
13793 truncate_it
.object
= make_number (0);
13794 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
13796 /* Overwrite glyphs from IT with truncation glyphs. */
13797 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
13798 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
13799 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
13800 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
13805 /* There may be padding glyphs left over. Overwrite them too. */
13806 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
13808 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
13814 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
13818 /* Compute the pixel height and width of IT->glyph_row.
13820 Most of the time, ascent and height of a display line will be equal
13821 to the max_ascent and max_height values of the display iterator
13822 structure. This is not the case if
13824 1. We hit ZV without displaying anything. In this case, max_ascent
13825 and max_height will be zero.
13827 2. We have some glyphs that don't contribute to the line height.
13828 (The glyph row flag contributes_to_line_height_p is for future
13829 pixmap extensions).
13831 The first case is easily covered by using default values because in
13832 these cases, the line height does not really matter, except that it
13833 must not be zero. */
13836 compute_line_metrics (it
)
13839 struct glyph_row
*row
= it
->glyph_row
;
13842 if (FRAME_WINDOW_P (it
->f
))
13844 int i
, min_y
, max_y
;
13846 /* The line may consist of one space only, that was added to
13847 place the cursor on it. If so, the row's height hasn't been
13849 if (row
->height
== 0)
13851 if (it
->max_ascent
+ it
->max_descent
== 0)
13852 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
13853 row
->ascent
= it
->max_ascent
;
13854 row
->height
= it
->max_ascent
+ it
->max_descent
;
13855 row
->phys_ascent
= it
->max_phys_ascent
;
13856 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13859 /* Compute the width of this line. */
13860 row
->pixel_width
= row
->x
;
13861 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
13862 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
13864 xassert (row
->pixel_width
>= 0);
13865 xassert (row
->ascent
>= 0 && row
->height
> 0);
13867 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
13868 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
13870 /* If first line's physical ascent is larger than its logical
13871 ascent, use the physical ascent, and make the row taller.
13872 This makes accented characters fully visible. */
13873 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
13874 && row
->phys_ascent
> row
->ascent
)
13876 row
->height
+= row
->phys_ascent
- row
->ascent
;
13877 row
->ascent
= row
->phys_ascent
;
13880 /* Compute how much of the line is visible. */
13881 row
->visible_height
= row
->height
;
13883 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
13884 max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
13886 if (row
->y
< min_y
)
13887 row
->visible_height
-= min_y
- row
->y
;
13888 if (row
->y
+ row
->height
> max_y
)
13889 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13893 row
->pixel_width
= row
->used
[TEXT_AREA
];
13894 if (row
->continued_p
)
13895 row
->pixel_width
-= it
->continuation_pixel_width
;
13896 else if (row
->truncated_on_right_p
)
13897 row
->pixel_width
-= it
->truncation_pixel_width
;
13898 row
->ascent
= row
->phys_ascent
= 0;
13899 row
->height
= row
->phys_height
= row
->visible_height
= 1;
13902 /* Compute a hash code for this row. */
13904 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13905 for (i
= 0; i
< row
->used
[area
]; ++i
)
13906 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
13907 + row
->glyphs
[area
][i
].u
.val
13908 + row
->glyphs
[area
][i
].face_id
13909 + row
->glyphs
[area
][i
].padding_p
13910 + (row
->glyphs
[area
][i
].type
<< 2));
13912 it
->max_ascent
= it
->max_descent
= 0;
13913 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
13917 /* Append one space to the glyph row of iterator IT if doing a
13918 window-based redisplay. DEFAULT_FACE_P non-zero means let the
13919 space have the default face, otherwise let it have the same face as
13920 IT->face_id. Value is non-zero if a space was added.
13922 This function is called to make sure that there is always one glyph
13923 at the end of a glyph row that the cursor can be set on under
13924 window-systems. (If there weren't such a glyph we would not know
13925 how wide and tall a box cursor should be displayed).
13927 At the same time this space let's a nicely handle clearing to the
13928 end of the line if the row ends in italic text. */
13931 append_space (it
, default_face_p
)
13933 int default_face_p
;
13935 if (FRAME_WINDOW_P (it
->f
))
13937 int n
= it
->glyph_row
->used
[TEXT_AREA
];
13939 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
13940 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
13942 /* Save some values that must not be changed.
13943 Must save IT->c and IT->len because otherwise
13944 ITERATOR_AT_END_P wouldn't work anymore after
13945 append_space has been called. */
13946 enum display_element_type saved_what
= it
->what
;
13947 int saved_c
= it
->c
, saved_len
= it
->len
;
13948 int saved_x
= it
->current_x
;
13949 int saved_face_id
= it
->face_id
;
13950 struct text_pos saved_pos
;
13951 Lisp_Object saved_object
;
13954 saved_object
= it
->object
;
13955 saved_pos
= it
->position
;
13957 it
->what
= IT_CHARACTER
;
13958 bzero (&it
->position
, sizeof it
->position
);
13959 it
->object
= make_number (0);
13963 if (default_face_p
)
13964 it
->face_id
= DEFAULT_FACE_ID
;
13965 else if (it
->face_before_selective_p
)
13966 it
->face_id
= it
->saved_face_id
;
13967 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
13968 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
13970 PRODUCE_GLYPHS (it
);
13972 it
->current_x
= saved_x
;
13973 it
->object
= saved_object
;
13974 it
->position
= saved_pos
;
13975 it
->what
= saved_what
;
13976 it
->face_id
= saved_face_id
;
13977 it
->len
= saved_len
;
13987 /* Extend the face of the last glyph in the text area of IT->glyph_row
13988 to the end of the display line. Called from display_line.
13989 If the glyph row is empty, add a space glyph to it so that we
13990 know the face to draw. Set the glyph row flag fill_line_p. */
13993 extend_face_to_end_of_line (it
)
13997 struct frame
*f
= it
->f
;
13999 /* If line is already filled, do nothing. */
14000 if (it
->current_x
>= it
->last_visible_x
)
14003 /* Face extension extends the background and box of IT->face_id
14004 to the end of the line. If the background equals the background
14005 of the frame, we don't have to do anything. */
14006 if (it
->face_before_selective_p
)
14007 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14009 face
= FACE_FROM_ID (f
, it
->face_id
);
14011 if (FRAME_WINDOW_P (f
)
14012 && face
->box
== FACE_NO_BOX
14013 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14017 /* Set the glyph row flag indicating that the face of the last glyph
14018 in the text area has to be drawn to the end of the text area. */
14019 it
->glyph_row
->fill_line_p
= 1;
14021 /* If current character of IT is not ASCII, make sure we have the
14022 ASCII face. This will be automatically undone the next time
14023 get_next_display_element returns a multibyte character. Note
14024 that the character will always be single byte in unibyte text. */
14025 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14027 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14030 if (FRAME_WINDOW_P (f
))
14032 /* If the row is empty, add a space with the current face of IT,
14033 so that we know which face to draw. */
14034 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14036 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14037 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14038 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14043 /* Save some values that must not be changed. */
14044 int saved_x
= it
->current_x
;
14045 struct text_pos saved_pos
;
14046 Lisp_Object saved_object
;
14047 enum display_element_type saved_what
= it
->what
;
14048 int saved_face_id
= it
->face_id
;
14050 saved_object
= it
->object
;
14051 saved_pos
= it
->position
;
14053 it
->what
= IT_CHARACTER
;
14054 bzero (&it
->position
, sizeof it
->position
);
14055 it
->object
= make_number (0);
14058 it
->face_id
= face
->id
;
14060 PRODUCE_GLYPHS (it
);
14062 while (it
->current_x
<= it
->last_visible_x
)
14063 PRODUCE_GLYPHS (it
);
14065 /* Don't count these blanks really. It would let us insert a left
14066 truncation glyph below and make us set the cursor on them, maybe. */
14067 it
->current_x
= saved_x
;
14068 it
->object
= saved_object
;
14069 it
->position
= saved_pos
;
14070 it
->what
= saved_what
;
14071 it
->face_id
= saved_face_id
;
14076 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14077 trailing whitespace. */
14080 trailing_whitespace_p (charpos
)
14083 int bytepos
= CHAR_TO_BYTE (charpos
);
14086 while (bytepos
< ZV_BYTE
14087 && (c
= FETCH_CHAR (bytepos
),
14088 c
== ' ' || c
== '\t'))
14091 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14093 if (bytepos
!= PT_BYTE
)
14100 /* Highlight trailing whitespace, if any, in ROW. */
14103 highlight_trailing_whitespace (f
, row
)
14105 struct glyph_row
*row
;
14107 int used
= row
->used
[TEXT_AREA
];
14111 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14112 struct glyph
*glyph
= start
+ used
- 1;
14114 /* Skip over glyphs inserted to display the cursor at the
14115 end of a line, for extending the face of the last glyph
14116 to the end of the line on terminals, and for truncation
14117 and continuation glyphs. */
14118 while (glyph
>= start
14119 && glyph
->type
== CHAR_GLYPH
14120 && INTEGERP (glyph
->object
))
14123 /* If last glyph is a space or stretch, and it's trailing
14124 whitespace, set the face of all trailing whitespace glyphs in
14125 IT->glyph_row to `trailing-whitespace'. */
14127 && BUFFERP (glyph
->object
)
14128 && (glyph
->type
== STRETCH_GLYPH
14129 || (glyph
->type
== CHAR_GLYPH
14130 && glyph
->u
.ch
== ' '))
14131 && trailing_whitespace_p (glyph
->charpos
))
14133 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
14135 while (glyph
>= start
14136 && BUFFERP (glyph
->object
)
14137 && (glyph
->type
== STRETCH_GLYPH
14138 || (glyph
->type
== CHAR_GLYPH
14139 && glyph
->u
.ch
== ' ')))
14140 (glyph
--)->face_id
= face_id
;
14146 /* Value is non-zero if glyph row ROW in window W should be
14147 used to hold the cursor. */
14150 cursor_row_p (w
, row
)
14152 struct glyph_row
*row
;
14154 int cursor_row_p
= 1;
14156 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14158 /* If the row ends with a newline from a string, we don't want
14159 the cursor there (if the row is continued it doesn't end in a
14161 if (CHARPOS (row
->end
.string_pos
) >= 0
14162 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14163 cursor_row_p
= row
->continued_p
;
14165 /* If the row ends at ZV, display the cursor at the end of that
14166 row instead of at the start of the row below. */
14167 else if (row
->ends_at_zv_p
)
14173 return cursor_row_p
;
14177 /* Construct the glyph row IT->glyph_row in the desired matrix of
14178 IT->w from text at the current position of IT. See dispextern.h
14179 for an overview of struct it. Value is non-zero if
14180 IT->glyph_row displays text, as opposed to a line displaying ZV
14187 struct glyph_row
*row
= it
->glyph_row
;
14189 /* We always start displaying at hpos zero even if hscrolled. */
14190 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14192 /* We must not display in a row that's not a text row. */
14193 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14194 < it
->w
->desired_matrix
->nrows
);
14196 /* Is IT->w showing the region? */
14197 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14199 /* Clear the result glyph row and enable it. */
14200 prepare_desired_row (row
);
14202 row
->y
= it
->current_y
;
14203 row
->start
= it
->current
;
14204 row
->continuation_lines_width
= it
->continuation_lines_width
;
14205 row
->displays_text_p
= 1;
14206 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14207 it
->starts_in_middle_of_char_p
= 0;
14209 /* Arrange the overlays nicely for our purposes. Usually, we call
14210 display_line on only one line at a time, in which case this
14211 can't really hurt too much, or we call it on lines which appear
14212 one after another in the buffer, in which case all calls to
14213 recenter_overlay_lists but the first will be pretty cheap. */
14214 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14216 /* Move over display elements that are not visible because we are
14217 hscrolled. This may stop at an x-position < IT->first_visible_x
14218 if the first glyph is partially visible or if we hit a line end. */
14219 if (it
->current_x
< it
->first_visible_x
)
14220 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14221 MOVE_TO_POS
| MOVE_TO_X
);
14223 /* Get the initial row height. This is either the height of the
14224 text hscrolled, if there is any, or zero. */
14225 row
->ascent
= it
->max_ascent
;
14226 row
->height
= it
->max_ascent
+ it
->max_descent
;
14227 row
->phys_ascent
= it
->max_phys_ascent
;
14228 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14230 /* Loop generating characters. The loop is left with IT on the next
14231 character to display. */
14234 int n_glyphs_before
, hpos_before
, x_before
;
14236 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14238 /* Retrieve the next thing to display. Value is zero if end of
14240 if (!get_next_display_element (it
))
14242 /* Maybe add a space at the end of this line that is used to
14243 display the cursor there under X. Set the charpos of the
14244 first glyph of blank lines not corresponding to any text
14246 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14247 || row
->used
[TEXT_AREA
] == 0)
14249 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14250 row
->displays_text_p
= 0;
14252 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14253 && (!MINI_WINDOW_P (it
->w
)
14254 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14255 row
->indicate_empty_line_p
= 1;
14258 it
->continuation_lines_width
= 0;
14259 row
->ends_at_zv_p
= 1;
14263 /* Now, get the metrics of what we want to display. This also
14264 generates glyphs in `row' (which is IT->glyph_row). */
14265 n_glyphs_before
= row
->used
[TEXT_AREA
];
14268 /* Remember the line height so far in case the next element doesn't
14269 fit on the line. */
14270 if (!it
->truncate_lines_p
)
14272 ascent
= it
->max_ascent
;
14273 descent
= it
->max_descent
;
14274 phys_ascent
= it
->max_phys_ascent
;
14275 phys_descent
= it
->max_phys_descent
;
14278 PRODUCE_GLYPHS (it
);
14280 /* If this display element was in marginal areas, continue with
14282 if (it
->area
!= TEXT_AREA
)
14284 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14285 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14286 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14287 row
->phys_height
= max (row
->phys_height
,
14288 it
->max_phys_ascent
+ it
->max_phys_descent
);
14289 set_iterator_to_next (it
, 1);
14293 /* Does the display element fit on the line? If we truncate
14294 lines, we should draw past the right edge of the window. If
14295 we don't truncate, we want to stop so that we can display the
14296 continuation glyph before the right margin. If lines are
14297 continued, there are two possible strategies for characters
14298 resulting in more than 1 glyph (e.g. tabs): Display as many
14299 glyphs as possible in this line and leave the rest for the
14300 continuation line, or display the whole element in the next
14301 line. Original redisplay did the former, so we do it also. */
14302 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14303 hpos_before
= it
->hpos
;
14306 if (/* Not a newline. */
14308 /* Glyphs produced fit entirely in the line. */
14309 && it
->current_x
< it
->last_visible_x
)
14311 it
->hpos
+= nglyphs
;
14312 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14313 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14314 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14315 row
->phys_height
= max (row
->phys_height
,
14316 it
->max_phys_ascent
+ it
->max_phys_descent
);
14317 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14318 row
->x
= x
- it
->first_visible_x
;
14323 struct glyph
*glyph
;
14325 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14327 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14328 new_x
= x
+ glyph
->pixel_width
;
14330 if (/* Lines are continued. */
14331 !it
->truncate_lines_p
14332 && (/* Glyph doesn't fit on the line. */
14333 new_x
> it
->last_visible_x
14334 /* Or it fits exactly on a window system frame. */
14335 || (new_x
== it
->last_visible_x
14336 && FRAME_WINDOW_P (it
->f
))))
14338 /* End of a continued line. */
14341 || (new_x
== it
->last_visible_x
14342 && FRAME_WINDOW_P (it
->f
)))
14344 /* Current glyph is the only one on the line or
14345 fits exactly on the line. We must continue
14346 the line because we can't draw the cursor
14347 after the glyph. */
14348 row
->continued_p
= 1;
14349 it
->current_x
= new_x
;
14350 it
->continuation_lines_width
+= new_x
;
14352 if (i
== nglyphs
- 1)
14353 set_iterator_to_next (it
, 1);
14355 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14356 && !FRAME_WINDOW_P (it
->f
))
14358 /* A padding glyph that doesn't fit on this line.
14359 This means the whole character doesn't fit
14361 row
->used
[TEXT_AREA
] = n_glyphs_before
;
14363 /* Fill the rest of the row with continuation
14364 glyphs like in 20.x. */
14365 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
14366 < row
->glyphs
[1 + TEXT_AREA
])
14367 produce_special_glyphs (it
, IT_CONTINUATION
);
14369 row
->continued_p
= 1;
14370 it
->current_x
= x_before
;
14371 it
->continuation_lines_width
+= x_before
;
14373 /* Restore the height to what it was before the
14374 element not fitting on the line. */
14375 it
->max_ascent
= ascent
;
14376 it
->max_descent
= descent
;
14377 it
->max_phys_ascent
= phys_ascent
;
14378 it
->max_phys_descent
= phys_descent
;
14380 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
14382 /* A TAB that extends past the right edge of the
14383 window. This produces a single glyph on
14384 window system frames. We leave the glyph in
14385 this row and let it fill the row, but don't
14386 consume the TAB. */
14387 it
->continuation_lines_width
+= it
->last_visible_x
;
14388 row
->ends_in_middle_of_char_p
= 1;
14389 row
->continued_p
= 1;
14390 glyph
->pixel_width
= it
->last_visible_x
- x
;
14391 it
->starts_in_middle_of_char_p
= 1;
14395 /* Something other than a TAB that draws past
14396 the right edge of the window. Restore
14397 positions to values before the element. */
14398 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14400 /* Display continuation glyphs. */
14401 if (!FRAME_WINDOW_P (it
->f
))
14402 produce_special_glyphs (it
, IT_CONTINUATION
);
14403 row
->continued_p
= 1;
14405 it
->continuation_lines_width
+= x
;
14407 if (nglyphs
> 1 && i
> 0)
14409 row
->ends_in_middle_of_char_p
= 1;
14410 it
->starts_in_middle_of_char_p
= 1;
14413 /* Restore the height to what it was before the
14414 element not fitting on the line. */
14415 it
->max_ascent
= ascent
;
14416 it
->max_descent
= descent
;
14417 it
->max_phys_ascent
= phys_ascent
;
14418 it
->max_phys_descent
= phys_descent
;
14423 else if (new_x
> it
->first_visible_x
)
14425 /* Increment number of glyphs actually displayed. */
14428 if (x
< it
->first_visible_x
)
14429 /* Glyph is partially visible, i.e. row starts at
14430 negative X position. */
14431 row
->x
= x
- it
->first_visible_x
;
14435 /* Glyph is completely off the left margin of the
14436 window. This should not happen because of the
14437 move_it_in_display_line at the start of this
14438 function, unless the text display area of the
14439 window is empty. */
14440 xassert (it
->first_visible_x
<= it
->last_visible_x
);
14444 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14445 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14446 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14447 row
->phys_height
= max (row
->phys_height
,
14448 it
->max_phys_ascent
+ it
->max_phys_descent
);
14450 /* End of this display line if row is continued. */
14451 if (row
->continued_p
)
14455 /* Is this a line end? If yes, we're also done, after making
14456 sure that a non-default face is extended up to the right
14457 margin of the window. */
14458 if (ITERATOR_AT_END_OF_LINE_P (it
))
14460 int used_before
= row
->used
[TEXT_AREA
];
14462 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
14464 /* Add a space at the end of the line that is used to
14465 display the cursor there. */
14466 append_space (it
, 0);
14468 /* Extend the face to the end of the line. */
14469 extend_face_to_end_of_line (it
);
14471 /* Make sure we have the position. */
14472 if (used_before
== 0)
14473 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
14475 /* Consume the line end. This skips over invisible lines. */
14476 set_iterator_to_next (it
, 1);
14477 it
->continuation_lines_width
= 0;
14481 /* Proceed with next display element. Note that this skips
14482 over lines invisible because of selective display. */
14483 set_iterator_to_next (it
, 1);
14485 /* If we truncate lines, we are done when the last displayed
14486 glyphs reach past the right margin of the window. */
14487 if (it
->truncate_lines_p
14488 && (FRAME_WINDOW_P (it
->f
)
14489 ? (it
->current_x
>= it
->last_visible_x
)
14490 : (it
->current_x
> it
->last_visible_x
)))
14492 /* Maybe add truncation glyphs. */
14493 if (!FRAME_WINDOW_P (it
->f
))
14497 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14498 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14501 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14503 row
->used
[TEXT_AREA
] = i
;
14504 produce_special_glyphs (it
, IT_TRUNCATION
);
14508 row
->truncated_on_right_p
= 1;
14509 it
->continuation_lines_width
= 0;
14510 reseat_at_next_visible_line_start (it
, 0);
14511 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
14512 it
->hpos
= hpos_before
;
14513 it
->current_x
= x_before
;
14518 /* If line is not empty and hscrolled, maybe insert truncation glyphs
14519 at the left window margin. */
14520 if (it
->first_visible_x
14521 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
14523 if (!FRAME_WINDOW_P (it
->f
))
14524 insert_left_trunc_glyphs (it
);
14525 row
->truncated_on_left_p
= 1;
14528 /* If the start of this line is the overlay arrow-position, then
14529 mark this glyph row as the one containing the overlay arrow.
14530 This is clearly a mess with variable size fonts. It would be
14531 better to let it be displayed like cursors under X. */
14532 if (MARKERP (Voverlay_arrow_position
)
14533 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
14534 && (MATRIX_ROW_START_CHARPOS (row
)
14535 == marker_position (Voverlay_arrow_position
))
14536 && STRINGP (Voverlay_arrow_string
)
14537 && ! overlay_arrow_seen
)
14539 /* Overlay arrow in window redisplay is a fringe bitmap. */
14540 if (!FRAME_WINDOW_P (it
->f
))
14542 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
14543 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
14544 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
14545 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
14546 struct glyph
*p2
, *end
;
14548 /* Copy the arrow glyphs. */
14549 while (glyph
< arrow_end
)
14552 /* Throw away padding glyphs. */
14554 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
14555 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
14561 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
14565 overlay_arrow_seen
= 1;
14566 row
->overlay_arrow_p
= 1;
14569 /* Compute pixel dimensions of this line. */
14570 compute_line_metrics (it
);
14572 /* Remember the position at which this line ends. */
14573 row
->end
= it
->current
;
14575 /* Maybe set the cursor. */
14576 if (it
->w
->cursor
.vpos
< 0
14577 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
14578 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14579 && cursor_row_p (it
->w
, row
))
14580 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
14582 /* Highlight trailing whitespace. */
14583 if (!NILP (Vshow_trailing_whitespace
))
14584 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
14586 /* Prepare for the next line. This line starts horizontally at (X
14587 HPOS) = (0 0). Vertical positions are incremented. As a
14588 convenience for the caller, IT->glyph_row is set to the next
14590 it
->current_x
= it
->hpos
= 0;
14591 it
->current_y
+= row
->height
;
14594 return row
->displays_text_p
;
14599 /***********************************************************************
14601 ***********************************************************************/
14603 /* Redisplay the menu bar in the frame for window W.
14605 The menu bar of X frames that don't have X toolkit support is
14606 displayed in a special window W->frame->menu_bar_window.
14608 The menu bar of terminal frames is treated specially as far as
14609 glyph matrices are concerned. Menu bar lines are not part of
14610 windows, so the update is done directly on the frame matrix rows
14611 for the menu bar. */
14614 display_menu_bar (w
)
14617 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14622 /* Don't do all this for graphical frames. */
14624 if (!NILP (Vwindow_system
))
14627 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
14632 if (FRAME_MAC_P (f
))
14636 #ifdef USE_X_TOOLKIT
14637 xassert (!FRAME_WINDOW_P (f
));
14638 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
14639 it
.first_visible_x
= 0;
14640 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
14641 #else /* not USE_X_TOOLKIT */
14642 if (FRAME_WINDOW_P (f
))
14644 /* Menu bar lines are displayed in the desired matrix of the
14645 dummy window menu_bar_window. */
14646 struct window
*menu_w
;
14647 xassert (WINDOWP (f
->menu_bar_window
));
14648 menu_w
= XWINDOW (f
->menu_bar_window
);
14649 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
14651 it
.first_visible_x
= 0;
14652 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
14656 /* This is a TTY frame, i.e. character hpos/vpos are used as
14658 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
14660 it
.first_visible_x
= 0;
14661 it
.last_visible_x
= FRAME_WIDTH (f
);
14663 #endif /* not USE_X_TOOLKIT */
14665 if (! mode_line_inverse_video
)
14666 /* Force the menu-bar to be displayed in the default face. */
14667 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
14669 /* Clear all rows of the menu bar. */
14670 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
14672 struct glyph_row
*row
= it
.glyph_row
+ i
;
14673 clear_glyph_row (row
);
14674 row
->enabled_p
= 1;
14675 row
->full_width_p
= 1;
14678 /* Display all items of the menu bar. */
14679 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
14680 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
14682 Lisp_Object string
;
14684 /* Stop at nil string. */
14685 string
= AREF (items
, i
+ 1);
14689 /* Remember where item was displayed. */
14690 AREF (items
, i
+ 3) = make_number (it
.hpos
);
14692 /* Display the item, pad with one space. */
14693 if (it
.current_x
< it
.last_visible_x
)
14694 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
14695 SCHARS (string
) + 1, 0, 0, -1);
14698 /* Fill out the line with spaces. */
14699 if (it
.current_x
< it
.last_visible_x
)
14700 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
14702 /* Compute the total height of the lines. */
14703 compute_line_metrics (&it
);
14708 /***********************************************************************
14710 ***********************************************************************/
14712 /* Redisplay mode lines in the window tree whose root is WINDOW. If
14713 FORCE is non-zero, redisplay mode lines unconditionally.
14714 Otherwise, redisplay only mode lines that are garbaged. Value is
14715 the number of windows whose mode lines were redisplayed. */
14718 redisplay_mode_lines (window
, force
)
14719 Lisp_Object window
;
14724 while (!NILP (window
))
14726 struct window
*w
= XWINDOW (window
);
14728 if (WINDOWP (w
->hchild
))
14729 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
14730 else if (WINDOWP (w
->vchild
))
14731 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
14733 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
14734 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
14736 struct text_pos lpoint
;
14737 struct buffer
*old
= current_buffer
;
14739 /* Set the window's buffer for the mode line display. */
14740 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14741 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14743 /* Point refers normally to the selected window. For any
14744 other window, set up appropriate value. */
14745 if (!EQ (window
, selected_window
))
14747 struct text_pos pt
;
14749 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
14750 if (CHARPOS (pt
) < BEGV
)
14751 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
14752 else if (CHARPOS (pt
) > (ZV
- 1))
14753 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
14755 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
14758 /* Display mode lines. */
14759 clear_glyph_matrix (w
->desired_matrix
);
14760 if (display_mode_lines (w
))
14763 w
->must_be_updated_p
= 1;
14766 /* Restore old settings. */
14767 set_buffer_internal_1 (old
);
14768 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14778 /* Display the mode and/or top line of window W. Value is the number
14779 of mode lines displayed. */
14782 display_mode_lines (w
)
14785 Lisp_Object old_selected_window
, old_selected_frame
;
14788 old_selected_frame
= selected_frame
;
14789 selected_frame
= w
->frame
;
14790 old_selected_window
= selected_window
;
14791 XSETWINDOW (selected_window
, w
);
14793 /* These will be set while the mode line specs are processed. */
14794 line_number_displayed
= 0;
14795 w
->column_number_displayed
= Qnil
;
14797 if (WINDOW_WANTS_MODELINE_P (w
))
14799 struct window
*sel_w
= XWINDOW (old_selected_window
);
14801 /* Select mode line face based on the real selected window. */
14802 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
14803 current_buffer
->mode_line_format
);
14807 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14809 display_mode_line (w
, HEADER_LINE_FACE_ID
,
14810 current_buffer
->header_line_format
);
14814 selected_frame
= old_selected_frame
;
14815 selected_window
= old_selected_window
;
14820 /* Display mode or top line of window W. FACE_ID specifies which line
14821 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
14822 FORMAT is the mode line format to display. Value is the pixel
14823 height of the mode line displayed. */
14826 display_mode_line (w
, face_id
, format
)
14828 enum face_id face_id
;
14829 Lisp_Object format
;
14834 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
14835 prepare_desired_row (it
.glyph_row
);
14837 if (! mode_line_inverse_video
)
14838 /* Force the mode-line to be displayed in the default face. */
14839 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
14841 /* Temporarily make frame's keyboard the current kboard so that
14842 kboard-local variables in the mode_line_format will get the right
14844 push_frame_kboard (it
.f
);
14845 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
14846 pop_frame_kboard ();
14848 /* Fill up with spaces. */
14849 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
14851 compute_line_metrics (&it
);
14852 it
.glyph_row
->full_width_p
= 1;
14853 it
.glyph_row
->mode_line_p
= 1;
14854 it
.glyph_row
->continued_p
= 0;
14855 it
.glyph_row
->truncated_on_left_p
= 0;
14856 it
.glyph_row
->truncated_on_right_p
= 0;
14858 /* Make a 3D mode-line have a shadow at its right end. */
14859 face
= FACE_FROM_ID (it
.f
, face_id
);
14860 extend_face_to_end_of_line (&it
);
14861 if (face
->box
!= FACE_NO_BOX
)
14863 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
14864 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
14865 last
->right_box_line_p
= 1;
14868 return it
.glyph_row
->height
;
14871 /* Alist that caches the results of :propertize.
14872 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
14873 Lisp_Object mode_line_proptrans_alist
;
14875 /* List of strings making up the mode-line. */
14876 Lisp_Object mode_line_string_list
;
14878 /* Base face property when building propertized mode line string. */
14879 static Lisp_Object mode_line_string_face
;
14880 static Lisp_Object mode_line_string_face_prop
;
14883 /* Contribute ELT to the mode line for window IT->w. How it
14884 translates into text depends on its data type.
14886 IT describes the display environment in which we display, as usual.
14888 DEPTH is the depth in recursion. It is used to prevent
14889 infinite recursion here.
14891 FIELD_WIDTH is the number of characters the display of ELT should
14892 occupy in the mode line, and PRECISION is the maximum number of
14893 characters to display from ELT's representation. See
14894 display_string for details.
14896 Returns the hpos of the end of the text generated by ELT.
14898 PROPS is a property list to add to any string we encounter.
14900 If RISKY is nonzero, remove (disregard) any properties in any string
14901 we encounter, and ignore :eval and :propertize.
14903 If the global variable `frame_title_ptr' is non-NULL, then the output
14904 is passed to `store_frame_title' instead of `display_string'. */
14907 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
14910 int field_width
, precision
;
14911 Lisp_Object elt
, props
;
14914 int n
= 0, field
, prec
;
14923 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
14927 /* A string: output it and check for %-constructs within it. */
14929 const unsigned char *this, *lisp_string
;
14931 if (!NILP (props
) || risky
)
14933 Lisp_Object oprops
, aelt
;
14934 oprops
= Ftext_properties_at (make_number (0), elt
);
14936 if (NILP (Fequal (props
, oprops
)) || risky
)
14938 /* If the starting string has properties,
14939 merge the specified ones onto the existing ones. */
14940 if (! NILP (oprops
) && !risky
)
14944 oprops
= Fcopy_sequence (oprops
);
14946 while (CONSP (tem
))
14948 oprops
= Fplist_put (oprops
, XCAR (tem
),
14949 XCAR (XCDR (tem
)));
14950 tem
= XCDR (XCDR (tem
));
14955 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
14956 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
14958 mode_line_proptrans_alist
14959 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
14966 elt
= Fcopy_sequence (elt
);
14967 Fset_text_properties (make_number (0), Flength (elt
),
14969 /* Add this item to mode_line_proptrans_alist. */
14970 mode_line_proptrans_alist
14971 = Fcons (Fcons (elt
, props
),
14972 mode_line_proptrans_alist
);
14973 /* Truncate mode_line_proptrans_alist
14974 to at most 50 elements. */
14975 tem
= Fnthcdr (make_number (50),
14976 mode_line_proptrans_alist
);
14978 XSETCDR (tem
, Qnil
);
14983 this = SDATA (elt
);
14984 lisp_string
= this;
14988 prec
= precision
- n
;
14989 if (frame_title_ptr
)
14990 n
+= store_frame_title (SDATA (elt
), -1, prec
);
14991 else if (!NILP (mode_line_string_list
))
14992 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
14994 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
14995 0, prec
, 0, STRING_MULTIBYTE (elt
));
15000 while ((precision
<= 0 || n
< precision
)
15002 && (frame_title_ptr
15003 || !NILP (mode_line_string_list
)
15004 || it
->current_x
< it
->last_visible_x
))
15006 const unsigned char *last
= this;
15008 /* Advance to end of string or next format specifier. */
15009 while ((c
= *this++) != '\0' && c
!= '%')
15012 if (this - 1 != last
)
15014 /* Output to end of string or up to '%'. Field width
15015 is length of string. Don't output more than
15016 PRECISION allows us. */
15019 prec
= chars_in_text (last
, this - last
);
15020 if (precision
> 0 && prec
> precision
- n
)
15021 prec
= precision
- n
;
15023 if (frame_title_ptr
)
15024 n
+= store_frame_title (last
, 0, prec
);
15025 else if (!NILP (mode_line_string_list
))
15027 int bytepos
= last
- lisp_string
;
15028 int charpos
= string_byte_to_char (elt
, bytepos
);
15029 n
+= store_mode_line_string (NULL
,
15030 Fsubstring (elt
, make_number (charpos
),
15031 make_number (charpos
+ prec
)),
15036 int bytepos
= last
- lisp_string
;
15037 int charpos
= string_byte_to_char (elt
, bytepos
);
15038 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15040 STRING_MULTIBYTE (elt
));
15043 else /* c == '%' */
15045 const unsigned char *percent_position
= this;
15047 /* Get the specified minimum width. Zero means
15050 while ((c
= *this++) >= '0' && c
<= '9')
15051 field
= field
* 10 + c
- '0';
15053 /* Don't pad beyond the total padding allowed. */
15054 if (field_width
- n
> 0 && field
> field_width
- n
)
15055 field
= field_width
- n
;
15057 /* Note that either PRECISION <= 0 or N < PRECISION. */
15058 prec
= precision
- n
;
15061 n
+= display_mode_element (it
, depth
, field
, prec
,
15062 Vglobal_mode_string
, props
,
15067 int bytepos
, charpos
;
15068 unsigned char *spec
;
15070 bytepos
= percent_position
- lisp_string
;
15071 charpos
= (STRING_MULTIBYTE (elt
)
15072 ? string_byte_to_char (elt
, bytepos
)
15076 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15078 if (frame_title_ptr
)
15079 n
+= store_frame_title (spec
, field
, prec
);
15080 else if (!NILP (mode_line_string_list
))
15082 int len
= strlen (spec
);
15083 Lisp_Object tem
= make_string (spec
, len
);
15084 props
= Ftext_properties_at (make_number (charpos
), elt
);
15085 /* Should only keep face property in props */
15086 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15090 int nglyphs_before
, nwritten
;
15092 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15093 nwritten
= display_string (spec
, Qnil
, elt
,
15098 /* Assign to the glyphs written above the
15099 string where the `%x' came from, position
15103 struct glyph
*glyph
15104 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15108 for (i
= 0; i
< nwritten
; ++i
)
15110 glyph
[i
].object
= elt
;
15111 glyph
[i
].charpos
= charpos
;
15126 /* A symbol: process the value of the symbol recursively
15127 as if it appeared here directly. Avoid error if symbol void.
15128 Special case: if value of symbol is a string, output the string
15131 register Lisp_Object tem
;
15133 /* If the variable is not marked as risky to set
15134 then its contents are risky to use. */
15135 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15138 tem
= Fboundp (elt
);
15141 tem
= Fsymbol_value (elt
);
15142 /* If value is a string, output that string literally:
15143 don't check for % within it. */
15147 if (!EQ (tem
, elt
))
15149 /* Give up right away for nil or t. */
15159 register Lisp_Object car
, tem
;
15161 /* A cons cell: five distinct cases.
15162 If first element is :eval or :propertize, do something special.
15163 If first element is a string or a cons, process all the elements
15164 and effectively concatenate them.
15165 If first element is a negative number, truncate displaying cdr to
15166 at most that many characters. If positive, pad (with spaces)
15167 to at least that many characters.
15168 If first element is a symbol, process the cadr or caddr recursively
15169 according to whether the symbol's value is non-nil or nil. */
15171 if (EQ (car
, QCeval
))
15173 /* An element of the form (:eval FORM) means evaluate FORM
15174 and use the result as mode line elements. */
15179 if (CONSP (XCDR (elt
)))
15182 spec
= safe_eval (XCAR (XCDR (elt
)));
15183 n
+= display_mode_element (it
, depth
, field_width
- n
,
15184 precision
- n
, spec
, props
,
15188 else if (EQ (car
, QCpropertize
))
15190 /* An element of the form (:propertize ELT PROPS...)
15191 means display ELT but applying properties PROPS. */
15196 if (CONSP (XCDR (elt
)))
15197 n
+= display_mode_element (it
, depth
, field_width
- n
,
15198 precision
- n
, XCAR (XCDR (elt
)),
15199 XCDR (XCDR (elt
)), risky
);
15201 else if (SYMBOLP (car
))
15203 tem
= Fboundp (car
);
15207 /* elt is now the cdr, and we know it is a cons cell.
15208 Use its car if CAR has a non-nil value. */
15211 tem
= Fsymbol_value (car
);
15218 /* Symbol's value is nil (or symbol is unbound)
15219 Get the cddr of the original list
15220 and if possible find the caddr and use that. */
15224 else if (!CONSP (elt
))
15229 else if (INTEGERP (car
))
15231 register int lim
= XINT (car
);
15235 /* Negative int means reduce maximum width. */
15236 if (precision
<= 0)
15239 precision
= min (precision
, -lim
);
15243 /* Padding specified. Don't let it be more than
15244 current maximum. */
15246 lim
= min (precision
, lim
);
15248 /* If that's more padding than already wanted, queue it.
15249 But don't reduce padding already specified even if
15250 that is beyond the current truncation point. */
15251 field_width
= max (lim
, field_width
);
15255 else if (STRINGP (car
) || CONSP (car
))
15257 register int limit
= 50;
15258 /* Limit is to protect against circular lists. */
15261 && (precision
<= 0 || n
< precision
))
15263 n
+= display_mode_element (it
, depth
, field_width
- n
,
15264 precision
- n
, XCAR (elt
),
15274 if (frame_title_ptr
)
15275 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
15276 else if (!NILP (mode_line_string_list
))
15277 n
+= store_mode_line_string ("*invalid*", Qnil
, 0, 0, precision
- n
, Qnil
);
15279 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
15280 precision
- n
, 0, 0);
15284 /* Pad to FIELD_WIDTH. */
15285 if (field_width
> 0 && n
< field_width
)
15287 if (frame_title_ptr
)
15288 n
+= store_frame_title ("", field_width
- n
, 0);
15289 else if (!NILP (mode_line_string_list
))
15290 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15292 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15299 /* Store a mode-line string element in mode_line_string_list.
15301 If STRING is non-null, display that C string. Otherwise, the Lisp
15302 string LISP_STRING is displayed.
15304 FIELD_WIDTH is the minimum number of output glyphs to produce.
15305 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15306 with spaces. FIELD_WIDTH <= 0 means don't pad.
15308 PRECISION is the maximum number of characters to output from
15309 STRING. PRECISION <= 0 means don't truncate the string.
15311 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
15312 properties to the string.
15314 PROPS are the properties to add to the string.
15315 The mode_line_string_face face property is always added to the string.
15318 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
15320 Lisp_Object lisp_string
;
15329 if (string
!= NULL
)
15331 len
= strlen (string
);
15332 if (precision
> 0 && len
> precision
)
15334 lisp_string
= make_string (string
, len
);
15336 props
= mode_line_string_face_prop
;
15337 else if (!NILP (mode_line_string_face
))
15339 Lisp_Object face
= Fplist_get (props
, Qface
);
15340 props
= Fcopy_sequence (props
);
15342 face
= mode_line_string_face
;
15344 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15345 props
= Fplist_put (props
, Qface
, face
);
15347 Fadd_text_properties (make_number (0), make_number (len
),
15348 props
, lisp_string
);
15352 len
= XFASTINT (Flength (lisp_string
));
15353 if (precision
> 0 && len
> precision
)
15356 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
15359 if (!NILP (mode_line_string_face
))
15363 props
= Ftext_properties_at (make_number (0), lisp_string
);
15364 face
= Fplist_get (props
, Qface
);
15366 face
= mode_line_string_face
;
15368 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15369 props
= Fcons (Qface
, Fcons (face
, Qnil
));
15371 lisp_string
= Fcopy_sequence (lisp_string
);
15374 Fadd_text_properties (make_number (0), make_number (len
),
15375 props
, lisp_string
);
15380 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15384 if (field_width
> len
)
15386 field_width
-= len
;
15387 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
15389 Fadd_text_properties (make_number (0), make_number (field_width
),
15390 props
, lisp_string
);
15391 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15399 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
15401 doc
: /* Return the mode-line of selected window as a string.
15402 First optional arg FORMAT specifies a different format string (see
15403 `mode-line-format' for details) to use. If FORMAT is t, return
15404 the buffer's header-line. Second optional arg WINDOW specifies a
15405 different window to use as the context for the formatting.
15406 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
15407 (format
, window
, no_props
)
15408 Lisp_Object format
, window
, no_props
;
15413 struct buffer
*old_buffer
= NULL
;
15414 enum face_id face_id
= DEFAULT_FACE_ID
;
15417 window
= selected_window
;
15418 CHECK_WINDOW (window
);
15419 w
= XWINDOW (window
);
15420 CHECK_BUFFER (w
->buffer
);
15422 if (XBUFFER (w
->buffer
) != current_buffer
)
15424 old_buffer
= current_buffer
;
15425 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15428 if (NILP (format
) || EQ (format
, Qt
))
15430 face_id
= NILP (format
)
15431 ? CURRENT_MODE_LINE_FACE_ID (w
) :
15432 HEADER_LINE_FACE_ID
;
15433 format
= NILP (format
)
15434 ? current_buffer
->mode_line_format
15435 : current_buffer
->header_line_format
;
15438 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15440 if (NILP (no_props
))
15442 mode_line_string_face
=
15443 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
15444 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
15445 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
15447 mode_line_string_face_prop
=
15448 NILP (mode_line_string_face
) ? Qnil
:
15449 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
15451 /* We need a dummy last element in mode_line_string_list to
15452 indicate we are building the propertized mode-line string.
15453 Using mode_line_string_face_prop here GC protects it. */
15454 mode_line_string_list
=
15455 Fcons (mode_line_string_face_prop
, Qnil
);
15456 frame_title_ptr
= NULL
;
15460 mode_line_string_face_prop
= Qnil
;
15461 mode_line_string_list
= Qnil
;
15462 frame_title_ptr
= frame_title_buf
;
15465 push_frame_kboard (it
.f
);
15466 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15467 pop_frame_kboard ();
15470 set_buffer_internal_1 (old_buffer
);
15472 if (NILP (no_props
))
15475 mode_line_string_list
= Fnreverse (mode_line_string_list
);
15476 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
15477 make_string ("", 0));
15478 mode_line_string_face_prop
= Qnil
;
15479 mode_line_string_list
= Qnil
;
15483 len
= frame_title_ptr
- frame_title_buf
;
15484 if (len
> 0 && frame_title_ptr
[-1] == '-')
15486 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
15487 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
15489 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
15490 if (len
> frame_title_ptr
- frame_title_buf
)
15491 len
= frame_title_ptr
- frame_title_buf
;
15494 frame_title_ptr
= NULL
;
15495 return make_string (frame_title_buf
, len
);
15498 /* Write a null-terminated, right justified decimal representation of
15499 the positive integer D to BUF using a minimal field width WIDTH. */
15502 pint2str (buf
, width
, d
)
15503 register char *buf
;
15504 register int width
;
15507 register char *p
= buf
;
15515 *p
++ = d
% 10 + '0';
15520 for (width
-= (int) (p
- buf
); width
> 0; --width
)
15531 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
15532 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
15533 type of CODING_SYSTEM. Return updated pointer into BUF. */
15535 static unsigned char invalid_eol_type
[] = "(*invalid*)";
15538 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
15539 Lisp_Object coding_system
;
15540 register char *buf
;
15544 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
15545 const unsigned char *eol_str
;
15547 /* The EOL conversion we are using. */
15548 Lisp_Object eoltype
;
15550 val
= Fget (coding_system
, Qcoding_system
);
15553 if (!VECTORP (val
)) /* Not yet decided. */
15558 eoltype
= eol_mnemonic_undecided
;
15559 /* Don't mention EOL conversion if it isn't decided. */
15563 Lisp_Object eolvalue
;
15565 eolvalue
= Fget (coding_system
, Qeol_type
);
15568 *buf
++ = XFASTINT (AREF (val
, 1));
15572 /* The EOL conversion that is normal on this system. */
15574 if (NILP (eolvalue
)) /* Not yet decided. */
15575 eoltype
= eol_mnemonic_undecided
;
15576 else if (VECTORP (eolvalue
)) /* Not yet decided. */
15577 eoltype
= eol_mnemonic_undecided
;
15578 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
15579 eoltype
= (XFASTINT (eolvalue
) == 0
15580 ? eol_mnemonic_unix
15581 : (XFASTINT (eolvalue
) == 1
15582 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
15588 /* Mention the EOL conversion if it is not the usual one. */
15589 if (STRINGP (eoltype
))
15591 eol_str
= SDATA (eoltype
);
15592 eol_str_len
= SBYTES (eoltype
);
15594 else if (INTEGERP (eoltype
)
15595 && CHAR_VALID_P (XINT (eoltype
), 0))
15597 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
15598 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
15603 eol_str
= invalid_eol_type
;
15604 eol_str_len
= sizeof (invalid_eol_type
) - 1;
15606 bcopy (eol_str
, buf
, eol_str_len
);
15607 buf
+= eol_str_len
;
15613 /* Return a string for the output of a mode line %-spec for window W,
15614 generated by character C. PRECISION >= 0 means don't return a
15615 string longer than that value. FIELD_WIDTH > 0 means pad the
15616 string returned with spaces to that value. Return 1 in *MULTIBYTE
15617 if the result is multibyte text. */
15619 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
15622 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
15625 int field_width
, precision
;
15629 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15630 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
15631 struct buffer
*b
= XBUFFER (w
->buffer
);
15639 if (!NILP (b
->read_only
))
15641 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
15646 /* This differs from %* only for a modified read-only buffer. */
15647 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
15649 if (!NILP (b
->read_only
))
15654 /* This differs from %* in ignoring read-only-ness. */
15655 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
15667 if (command_loop_level
> 5)
15669 p
= decode_mode_spec_buf
;
15670 for (i
= 0; i
< command_loop_level
; i
++)
15673 return decode_mode_spec_buf
;
15681 if (command_loop_level
> 5)
15683 p
= decode_mode_spec_buf
;
15684 for (i
= 0; i
< command_loop_level
; i
++)
15687 return decode_mode_spec_buf
;
15694 /* Let lots_of_dashes be a string of infinite length. */
15695 if (!NILP (mode_line_string_list
))
15697 if (field_width
<= 0
15698 || field_width
> sizeof (lots_of_dashes
))
15700 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
15701 decode_mode_spec_buf
[i
] = '-';
15702 decode_mode_spec_buf
[i
] = '\0';
15703 return decode_mode_spec_buf
;
15706 return lots_of_dashes
;
15715 int col
= (int) current_column (); /* iftc */
15716 w
->column_number_displayed
= make_number (col
);
15717 pint2str (decode_mode_spec_buf
, field_width
, col
);
15718 return decode_mode_spec_buf
;
15722 /* %F displays the frame name. */
15723 if (!NILP (f
->title
))
15724 return (char *) SDATA (f
->title
);
15725 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
15726 return (char *) SDATA (f
->name
);
15735 int startpos
= XMARKER (w
->start
)->charpos
;
15736 int startpos_byte
= marker_byte_position (w
->start
);
15737 int line
, linepos
, linepos_byte
, topline
;
15739 int height
= XFASTINT (w
->height
);
15741 /* If we decided that this buffer isn't suitable for line numbers,
15742 don't forget that too fast. */
15743 if (EQ (w
->base_line_pos
, w
->buffer
))
15745 /* But do forget it, if the window shows a different buffer now. */
15746 else if (BUFFERP (w
->base_line_pos
))
15747 w
->base_line_pos
= Qnil
;
15749 /* If the buffer is very big, don't waste time. */
15750 if (INTEGERP (Vline_number_display_limit
)
15751 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
15753 w
->base_line_pos
= Qnil
;
15754 w
->base_line_number
= Qnil
;
15758 if (!NILP (w
->base_line_number
)
15759 && !NILP (w
->base_line_pos
)
15760 && XFASTINT (w
->base_line_pos
) <= startpos
)
15762 line
= XFASTINT (w
->base_line_number
);
15763 linepos
= XFASTINT (w
->base_line_pos
);
15764 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
15769 linepos
= BUF_BEGV (b
);
15770 linepos_byte
= BUF_BEGV_BYTE (b
);
15773 /* Count lines from base line to window start position. */
15774 nlines
= display_count_lines (linepos
, linepos_byte
,
15778 topline
= nlines
+ line
;
15780 /* Determine a new base line, if the old one is too close
15781 or too far away, or if we did not have one.
15782 "Too close" means it's plausible a scroll-down would
15783 go back past it. */
15784 if (startpos
== BUF_BEGV (b
))
15786 w
->base_line_number
= make_number (topline
);
15787 w
->base_line_pos
= make_number (BUF_BEGV (b
));
15789 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
15790 || linepos
== BUF_BEGV (b
))
15792 int limit
= BUF_BEGV (b
);
15793 int limit_byte
= BUF_BEGV_BYTE (b
);
15795 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
15797 if (startpos
- distance
> limit
)
15799 limit
= startpos
- distance
;
15800 limit_byte
= CHAR_TO_BYTE (limit
);
15803 nlines
= display_count_lines (startpos
, startpos_byte
,
15805 - (height
* 2 + 30),
15807 /* If we couldn't find the lines we wanted within
15808 line_number_display_limit_width chars per line,
15809 give up on line numbers for this window. */
15810 if (position
== limit_byte
&& limit
== startpos
- distance
)
15812 w
->base_line_pos
= w
->buffer
;
15813 w
->base_line_number
= Qnil
;
15817 w
->base_line_number
= make_number (topline
- nlines
);
15818 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
15821 /* Now count lines from the start pos to point. */
15822 nlines
= display_count_lines (startpos
, startpos_byte
,
15823 PT_BYTE
, PT
, &junk
);
15825 /* Record that we did display the line number. */
15826 line_number_displayed
= 1;
15828 /* Make the string to show. */
15829 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
15830 return decode_mode_spec_buf
;
15833 char* p
= decode_mode_spec_buf
;
15834 int pad
= field_width
- 2;
15840 return decode_mode_spec_buf
;
15846 obj
= b
->mode_name
;
15850 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
15856 int pos
= marker_position (w
->start
);
15857 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
15859 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
15861 if (pos
<= BUF_BEGV (b
))
15866 else if (pos
<= BUF_BEGV (b
))
15870 if (total
> 1000000)
15871 /* Do it differently for a large value, to avoid overflow. */
15872 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
15874 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
15875 /* We can't normally display a 3-digit number,
15876 so get us a 2-digit number that is close. */
15879 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
15880 return decode_mode_spec_buf
;
15884 /* Display percentage of size above the bottom of the screen. */
15887 int toppos
= marker_position (w
->start
);
15888 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
15889 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
15891 if (botpos
>= BUF_ZV (b
))
15893 if (toppos
<= BUF_BEGV (b
))
15900 if (total
> 1000000)
15901 /* Do it differently for a large value, to avoid overflow. */
15902 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
15904 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
15905 /* We can't normally display a 3-digit number,
15906 so get us a 2-digit number that is close. */
15909 if (toppos
<= BUF_BEGV (b
))
15910 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
15912 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
15913 return decode_mode_spec_buf
;
15918 /* status of process */
15919 obj
= Fget_buffer_process (w
->buffer
);
15921 return "no process";
15922 #ifdef subprocesses
15923 obj
= Fsymbol_name (Fprocess_status (obj
));
15927 case 't': /* indicate TEXT or BINARY */
15928 #ifdef MODE_LINE_BINARY_TEXT
15929 return MODE_LINE_BINARY_TEXT (b
);
15935 /* coding-system (not including end-of-line format) */
15937 /* coding-system (including end-of-line type) */
15939 int eol_flag
= (c
== 'Z');
15940 char *p
= decode_mode_spec_buf
;
15942 if (! FRAME_WINDOW_P (f
))
15944 /* No need to mention EOL here--the terminal never needs
15945 to do EOL conversion. */
15946 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
15947 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
15949 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
15952 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
15953 #ifdef subprocesses
15954 obj
= Fget_buffer_process (Fcurrent_buffer ());
15955 if (PROCESSP (obj
))
15957 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
15959 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
15962 #endif /* subprocesses */
15965 return decode_mode_spec_buf
;
15971 *multibyte
= STRING_MULTIBYTE (obj
);
15972 return (char *) SDATA (obj
);
15979 /* Count up to COUNT lines starting from START / START_BYTE.
15980 But don't go beyond LIMIT_BYTE.
15981 Return the number of lines thus found (always nonnegative).
15983 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
15986 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
15987 int start
, start_byte
, limit_byte
, count
;
15990 register unsigned char *cursor
;
15991 unsigned char *base
;
15993 register int ceiling
;
15994 register unsigned char *ceiling_addr
;
15995 int orig_count
= count
;
15997 /* If we are not in selective display mode,
15998 check only for newlines. */
15999 int selective_display
= (!NILP (current_buffer
->selective_display
)
16000 && !INTEGERP (current_buffer
->selective_display
));
16004 while (start_byte
< limit_byte
)
16006 ceiling
= BUFFER_CEILING_OF (start_byte
);
16007 ceiling
= min (limit_byte
- 1, ceiling
);
16008 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16009 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16012 if (selective_display
)
16013 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16016 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16019 if (cursor
!= ceiling_addr
)
16023 start_byte
+= cursor
- base
+ 1;
16024 *byte_pos_ptr
= start_byte
;
16028 if (++cursor
== ceiling_addr
)
16034 start_byte
+= cursor
- base
;
16039 while (start_byte
> limit_byte
)
16041 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16042 ceiling
= max (limit_byte
, ceiling
);
16043 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16044 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16047 if (selective_display
)
16048 while (--cursor
!= ceiling_addr
16049 && *cursor
!= '\n' && *cursor
!= 015)
16052 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16055 if (cursor
!= ceiling_addr
)
16059 start_byte
+= cursor
- base
+ 1;
16060 *byte_pos_ptr
= start_byte
;
16061 /* When scanning backwards, we should
16062 not count the newline posterior to which we stop. */
16063 return - orig_count
- 1;
16069 /* Here we add 1 to compensate for the last decrement
16070 of CURSOR, which took it past the valid range. */
16071 start_byte
+= cursor
- base
+ 1;
16075 *byte_pos_ptr
= limit_byte
;
16078 return - orig_count
+ count
;
16079 return orig_count
- count
;
16085 /***********************************************************************
16087 ***********************************************************************/
16089 /* Display a NUL-terminated string, starting with index START.
16091 If STRING is non-null, display that C string. Otherwise, the Lisp
16092 string LISP_STRING is displayed.
16094 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16095 FACE_STRING. Display STRING or LISP_STRING with the face at
16096 FACE_STRING_POS in FACE_STRING:
16098 Display the string in the environment given by IT, but use the
16099 standard display table, temporarily.
16101 FIELD_WIDTH is the minimum number of output glyphs to produce.
16102 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16103 with spaces. If STRING has more characters, more than FIELD_WIDTH
16104 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16106 PRECISION is the maximum number of characters to output from
16107 STRING. PRECISION < 0 means don't truncate the string.
16109 This is roughly equivalent to printf format specifiers:
16111 FIELD_WIDTH PRECISION PRINTF
16112 ----------------------------------------
16118 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16119 display them, and < 0 means obey the current buffer's value of
16120 enable_multibyte_characters.
16122 Value is the number of glyphs produced. */
16125 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16126 start
, it
, field_width
, precision
, max_x
, multibyte
)
16127 unsigned char *string
;
16128 Lisp_Object lisp_string
;
16129 Lisp_Object face_string
;
16130 int face_string_pos
;
16133 int field_width
, precision
, max_x
;
16136 int hpos_at_start
= it
->hpos
;
16137 int saved_face_id
= it
->face_id
;
16138 struct glyph_row
*row
= it
->glyph_row
;
16140 /* Initialize the iterator IT for iteration over STRING beginning
16141 with index START. */
16142 reseat_to_string (it
, string
, lisp_string
, start
,
16143 precision
, field_width
, multibyte
);
16145 /* If displaying STRING, set up the face of the iterator
16146 from LISP_STRING, if that's given. */
16147 if (STRINGP (face_string
))
16153 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16154 0, it
->region_beg_charpos
,
16155 it
->region_end_charpos
,
16156 &endptr
, it
->base_face_id
, 0);
16157 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16158 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16161 /* Set max_x to the maximum allowed X position. Don't let it go
16162 beyond the right edge of the window. */
16164 max_x
= it
->last_visible_x
;
16166 max_x
= min (max_x
, it
->last_visible_x
);
16168 /* Skip over display elements that are not visible. because IT->w is
16170 if (it
->current_x
< it
->first_visible_x
)
16171 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
16172 MOVE_TO_POS
| MOVE_TO_X
);
16174 row
->ascent
= it
->max_ascent
;
16175 row
->height
= it
->max_ascent
+ it
->max_descent
;
16176 row
->phys_ascent
= it
->max_phys_ascent
;
16177 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16179 /* This condition is for the case that we are called with current_x
16180 past last_visible_x. */
16181 while (it
->current_x
< max_x
)
16183 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
16185 /* Get the next display element. */
16186 if (!get_next_display_element (it
))
16189 /* Produce glyphs. */
16190 x_before
= it
->current_x
;
16191 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16192 PRODUCE_GLYPHS (it
);
16194 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
16197 while (i
< nglyphs
)
16199 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16201 if (!it
->truncate_lines_p
16202 && x
+ glyph
->pixel_width
> max_x
)
16204 /* End of continued line or max_x reached. */
16205 if (CHAR_GLYPH_PADDING_P (*glyph
))
16207 /* A wide character is unbreakable. */
16208 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16209 it
->current_x
= x_before
;
16213 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16218 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
16220 /* Glyph is at least partially visible. */
16222 if (x
< it
->first_visible_x
)
16223 it
->glyph_row
->x
= x
- it
->first_visible_x
;
16227 /* Glyph is off the left margin of the display area.
16228 Should not happen. */
16232 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16233 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16234 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16235 row
->phys_height
= max (row
->phys_height
,
16236 it
->max_phys_ascent
+ it
->max_phys_descent
);
16237 x
+= glyph
->pixel_width
;
16241 /* Stop if max_x reached. */
16245 /* Stop at line ends. */
16246 if (ITERATOR_AT_END_OF_LINE_P (it
))
16248 it
->continuation_lines_width
= 0;
16252 set_iterator_to_next (it
, 1);
16254 /* Stop if truncating at the right edge. */
16255 if (it
->truncate_lines_p
16256 && it
->current_x
>= it
->last_visible_x
)
16258 /* Add truncation mark, but don't do it if the line is
16259 truncated at a padding space. */
16260 if (IT_CHARPOS (*it
) < it
->string_nchars
)
16262 if (!FRAME_WINDOW_P (it
->f
))
16266 if (it
->current_x
> it
->last_visible_x
)
16268 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16269 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16271 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16273 row
->used
[TEXT_AREA
] = i
;
16274 produce_special_glyphs (it
, IT_TRUNCATION
);
16277 produce_special_glyphs (it
, IT_TRUNCATION
);
16279 it
->glyph_row
->truncated_on_right_p
= 1;
16285 /* Maybe insert a truncation at the left. */
16286 if (it
->first_visible_x
16287 && IT_CHARPOS (*it
) > 0)
16289 if (!FRAME_WINDOW_P (it
->f
))
16290 insert_left_trunc_glyphs (it
);
16291 it
->glyph_row
->truncated_on_left_p
= 1;
16294 it
->face_id
= saved_face_id
;
16296 /* Value is number of columns displayed. */
16297 return it
->hpos
- hpos_at_start
;
16302 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
16303 appears as an element of LIST or as the car of an element of LIST.
16304 If PROPVAL is a list, compare each element against LIST in that
16305 way, and return 1/2 if any element of PROPVAL is found in LIST.
16306 Otherwise return 0. This function cannot quit.
16307 The return value is 2 if the text is invisible but with an ellipsis
16308 and 1 if it's invisible and without an ellipsis. */
16311 invisible_p (propval
, list
)
16312 register Lisp_Object propval
;
16315 register Lisp_Object tail
, proptail
;
16317 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16319 register Lisp_Object tem
;
16321 if (EQ (propval
, tem
))
16323 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
16324 return NILP (XCDR (tem
)) ? 1 : 2;
16327 if (CONSP (propval
))
16329 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
16331 Lisp_Object propelt
;
16332 propelt
= XCAR (proptail
);
16333 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16335 register Lisp_Object tem
;
16337 if (EQ (propelt
, tem
))
16339 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
16340 return NILP (XCDR (tem
)) ? 1 : 2;
16349 /***********************************************************************
16351 ***********************************************************************/
16353 #ifdef HAVE_WINDOW_SYSTEM
16358 dump_glyph_string (s
)
16359 struct glyph_string
*s
;
16361 fprintf (stderr
, "glyph string\n");
16362 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
16363 s
->x
, s
->y
, s
->width
, s
->height
);
16364 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
16365 fprintf (stderr
, " hl = %d\n", s
->hl
);
16366 fprintf (stderr
, " left overhang = %d, right = %d\n",
16367 s
->left_overhang
, s
->right_overhang
);
16368 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
16369 fprintf (stderr
, " extends to end of line = %d\n",
16370 s
->extends_to_end_of_line_p
);
16371 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
16372 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
16375 #endif /* GLYPH_DEBUG */
16377 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
16378 of XChar2b structures for S; it can't be allocated in
16379 init_glyph_string because it must be allocated via `alloca'. W
16380 is the window on which S is drawn. ROW and AREA are the glyph row
16381 and area within the row from which S is constructed. START is the
16382 index of the first glyph structure covered by S. HL is a
16383 face-override for drawing S. */
16386 #define OPTIONAL_HDC(hdc) hdc,
16387 #define DECLARE_HDC(hdc) HDC hdc;
16388 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
16389 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
16392 #ifndef OPTIONAL_HDC
16393 #define OPTIONAL_HDC(hdc)
16394 #define DECLARE_HDC(hdc)
16395 #define ALLOCATE_HDC(hdc, f)
16396 #define RELEASE_HDC(hdc, f)
16400 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
16401 struct glyph_string
*s
;
16405 struct glyph_row
*row
;
16406 enum glyph_row_area area
;
16408 enum draw_glyphs_face hl
;
16410 bzero (s
, sizeof *s
);
16412 s
->f
= XFRAME (w
->frame
);
16416 s
->display
= FRAME_X_DISPLAY (s
->f
);
16417 s
->window
= FRAME_X_WINDOW (s
->f
);
16418 s
->char2b
= char2b
;
16422 s
->first_glyph
= row
->glyphs
[area
] + start
;
16423 s
->height
= row
->height
;
16424 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
16426 /* Display the internal border below the tool-bar window. */
16427 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
16428 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
16430 s
->ybase
= s
->y
+ row
->ascent
;
16434 /* Append the list of glyph strings with head H and tail T to the list
16435 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
16438 append_glyph_string_lists (head
, tail
, h
, t
)
16439 struct glyph_string
**head
, **tail
;
16440 struct glyph_string
*h
, *t
;
16454 /* Prepend the list of glyph strings with head H and tail T to the
16455 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
16459 prepend_glyph_string_lists (head
, tail
, h
, t
)
16460 struct glyph_string
**head
, **tail
;
16461 struct glyph_string
*h
, *t
;
16475 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
16476 Set *HEAD and *TAIL to the resulting list. */
16479 append_glyph_string (head
, tail
, s
)
16480 struct glyph_string
**head
, **tail
;
16481 struct glyph_string
*s
;
16483 s
->next
= s
->prev
= NULL
;
16484 append_glyph_string_lists (head
, tail
, s
, s
);
16488 /* Get face and two-byte form of character glyph GLYPH on frame F.
16489 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
16490 a pointer to a realized face that is ready for display. */
16492 static INLINE
struct face
*
16493 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
16495 struct glyph
*glyph
;
16501 xassert (glyph
->type
== CHAR_GLYPH
);
16502 face
= FACE_FROM_ID (f
, glyph
->face_id
);
16507 if (!glyph
->multibyte_p
)
16509 /* Unibyte case. We don't have to encode, but we have to make
16510 sure to use a face suitable for unibyte. */
16511 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
16513 else if (glyph
->u
.ch
< 128
16514 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
16516 /* Case of ASCII in a face known to fit ASCII. */
16517 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
16521 int c1
, c2
, charset
;
16523 /* Split characters into bytes. If c2 is -1 afterwards, C is
16524 really a one-byte character so that byte1 is zero. */
16525 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
16527 STORE_XCHAR2B (char2b
, c1
, c2
);
16529 STORE_XCHAR2B (char2b
, 0, c1
);
16531 /* Maybe encode the character in *CHAR2B. */
16532 if (charset
!= CHARSET_ASCII
)
16534 struct font_info
*font_info
16535 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
16538 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
16542 /* Make sure X resources of the face are allocated. */
16543 xassert (face
!= NULL
);
16544 PREPARE_FACE_FOR_DISPLAY (f
, face
);
16549 /* Fill glyph string S with composition components specified by S->cmp.
16551 FACES is an array of faces for all components of this composition.
16552 S->gidx is the index of the first component for S.
16553 OVERLAPS_P non-zero means S should draw the foreground only, and
16554 use its physical height for clipping.
16556 Value is the index of a component not in S. */
16559 fill_composite_glyph_string (s
, faces
, overlaps_p
)
16560 struct glyph_string
*s
;
16561 struct face
**faces
;
16568 s
->for_overlaps_p
= overlaps_p
;
16570 s
->face
= faces
[s
->gidx
];
16571 s
->font
= s
->face
->font
;
16572 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
16574 /* For all glyphs of this composition, starting at the offset
16575 S->gidx, until we reach the end of the definition or encounter a
16576 glyph that requires the different face, add it to S. */
16578 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
16581 /* All glyph strings for the same composition has the same width,
16582 i.e. the width set for the first component of the composition. */
16584 s
->width
= s
->first_glyph
->pixel_width
;
16586 /* If the specified font could not be loaded, use the frame's
16587 default font, but record the fact that we couldn't load it in
16588 the glyph string so that we can draw rectangles for the
16589 characters of the glyph string. */
16590 if (s
->font
== NULL
)
16592 s
->font_not_found_p
= 1;
16593 s
->font
= FRAME_FONT (s
->f
);
16596 /* Adjust base line for subscript/superscript text. */
16597 s
->ybase
+= s
->first_glyph
->voffset
;
16599 xassert (s
->face
&& s
->face
->gc
);
16601 /* This glyph string must always be drawn with 16-bit functions. */
16604 return s
->gidx
+ s
->nchars
;
16608 /* Fill glyph string S from a sequence of character glyphs.
16610 FACE_ID is the face id of the string. START is the index of the
16611 first glyph to consider, END is the index of the last + 1.
16612 OVERLAPS_P non-zero means S should draw the foreground only, and
16613 use its physical height for clipping.
16615 Value is the index of the first glyph not in S. */
16618 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
16619 struct glyph_string
*s
;
16621 int start
, end
, overlaps_p
;
16623 struct glyph
*glyph
, *last
;
16625 int glyph_not_available_p
;
16627 xassert (s
->f
== XFRAME (s
->w
->frame
));
16628 xassert (s
->nchars
== 0);
16629 xassert (start
>= 0 && end
> start
);
16631 s
->for_overlaps_p
= overlaps_p
,
16632 glyph
= s
->row
->glyphs
[s
->area
] + start
;
16633 last
= s
->row
->glyphs
[s
->area
] + end
;
16634 voffset
= glyph
->voffset
;
16636 glyph_not_available_p
= glyph
->glyph_not_available_p
;
16638 while (glyph
< last
16639 && glyph
->type
== CHAR_GLYPH
16640 && glyph
->voffset
== voffset
16641 /* Same face id implies same font, nowadays. */
16642 && glyph
->face_id
== face_id
16643 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
16647 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
16648 s
->char2b
+ s
->nchars
,
16650 s
->two_byte_p
= two_byte_p
;
16652 xassert (s
->nchars
<= end
- start
);
16653 s
->width
+= glyph
->pixel_width
;
16657 s
->font
= s
->face
->font
;
16658 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
16660 /* If the specified font could not be loaded, use the frame's font,
16661 but record the fact that we couldn't load it in
16662 S->font_not_found_p so that we can draw rectangles for the
16663 characters of the glyph string. */
16664 if (s
->font
== NULL
|| glyph_not_available_p
)
16666 s
->font_not_found_p
= 1;
16667 s
->font
= FRAME_FONT (s
->f
);
16670 /* Adjust base line for subscript/superscript text. */
16671 s
->ybase
+= voffset
;
16673 xassert (s
->face
&& s
->face
->gc
);
16674 return glyph
- s
->row
->glyphs
[s
->area
];
16678 /* Fill glyph string S from image glyph S->first_glyph. */
16681 fill_image_glyph_string (s
)
16682 struct glyph_string
*s
;
16684 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
16685 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
16687 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
16688 s
->font
= s
->face
->font
;
16689 s
->width
= s
->first_glyph
->pixel_width
;
16691 /* Adjust base line for subscript/superscript text. */
16692 s
->ybase
+= s
->first_glyph
->voffset
;
16696 /* Fill glyph string S from a sequence of stretch glyphs.
16698 ROW is the glyph row in which the glyphs are found, AREA is the
16699 area within the row. START is the index of the first glyph to
16700 consider, END is the index of the last + 1.
16702 Value is the index of the first glyph not in S. */
16705 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
16706 struct glyph_string
*s
;
16707 struct glyph_row
*row
;
16708 enum glyph_row_area area
;
16711 struct glyph
*glyph
, *last
;
16712 int voffset
, face_id
;
16714 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
16716 glyph
= s
->row
->glyphs
[s
->area
] + start
;
16717 last
= s
->row
->glyphs
[s
->area
] + end
;
16718 face_id
= glyph
->face_id
;
16719 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
16720 s
->font
= s
->face
->font
;
16721 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
16722 s
->width
= glyph
->pixel_width
;
16723 voffset
= glyph
->voffset
;
16727 && glyph
->type
== STRETCH_GLYPH
16728 && glyph
->voffset
== voffset
16729 && glyph
->face_id
== face_id
);
16731 s
->width
+= glyph
->pixel_width
;
16733 /* Adjust base line for subscript/superscript text. */
16734 s
->ybase
+= voffset
;
16736 /* The case that face->gc == 0 is handled when drawing the glyph
16737 string by calling PREPARE_FACE_FOR_DISPLAY. */
16739 return glyph
- s
->row
->glyphs
[s
->area
];
16744 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
16745 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
16746 assumed to be zero. */
16749 x_get_glyph_overhangs (glyph
, f
, left
, right
)
16750 struct glyph
*glyph
;
16754 *left
= *right
= 0;
16756 if (glyph
->type
== CHAR_GLYPH
)
16760 struct font_info
*font_info
;
16764 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
16766 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
16767 if (font
/* ++KFS: Should this be font_info ? */
16768 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
16770 if (pcm
->rbearing
> pcm
->width
)
16771 *right
= pcm
->rbearing
- pcm
->width
;
16772 if (pcm
->lbearing
< 0)
16773 *left
= -pcm
->lbearing
;
16779 /* Return the index of the first glyph preceding glyph string S that
16780 is overwritten by S because of S's left overhang. Value is -1
16781 if no glyphs are overwritten. */
16784 left_overwritten (s
)
16785 struct glyph_string
*s
;
16789 if (s
->left_overhang
)
16792 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
16793 int first
= s
->first_glyph
- glyphs
;
16795 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
16796 x
-= glyphs
[i
].pixel_width
;
16807 /* Return the index of the first glyph preceding glyph string S that
16808 is overwriting S because of its right overhang. Value is -1 if no
16809 glyph in front of S overwrites S. */
16812 left_overwriting (s
)
16813 struct glyph_string
*s
;
16816 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
16817 int first
= s
->first_glyph
- glyphs
;
16821 for (i
= first
- 1; i
>= 0; --i
)
16824 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
16827 x
-= glyphs
[i
].pixel_width
;
16834 /* Return the index of the last glyph following glyph string S that is
16835 not overwritten by S because of S's right overhang. Value is -1 if
16836 no such glyph is found. */
16839 right_overwritten (s
)
16840 struct glyph_string
*s
;
16844 if (s
->right_overhang
)
16847 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
16848 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
16849 int end
= s
->row
->used
[s
->area
];
16851 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
16852 x
+= glyphs
[i
].pixel_width
;
16861 /* Return the index of the last glyph following glyph string S that
16862 overwrites S because of its left overhang. Value is negative
16863 if no such glyph is found. */
16866 right_overwriting (s
)
16867 struct glyph_string
*s
;
16870 int end
= s
->row
->used
[s
->area
];
16871 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
16872 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
16876 for (i
= first
; i
< end
; ++i
)
16879 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
16882 x
+= glyphs
[i
].pixel_width
;
16889 /* Get face and two-byte form of character C in face FACE_ID on frame
16890 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
16891 means we want to display multibyte text. DISPLAY_P non-zero means
16892 make sure that X resources for the face returned are allocated.
16893 Value is a pointer to a realized face that is ready for display if
16894 DISPLAY_P is non-zero. */
16896 static INLINE
struct face
*
16897 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
16901 int multibyte_p
, display_p
;
16903 struct face
*face
= FACE_FROM_ID (f
, face_id
);
16907 /* Unibyte case. We don't have to encode, but we have to make
16908 sure to use a face suitable for unibyte. */
16909 STORE_XCHAR2B (char2b
, 0, c
);
16910 face_id
= FACE_FOR_CHAR (f
, face
, c
);
16911 face
= FACE_FROM_ID (f
, face_id
);
16913 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
16915 /* Case of ASCII in a face known to fit ASCII. */
16916 STORE_XCHAR2B (char2b
, 0, c
);
16920 int c1
, c2
, charset
;
16922 /* Split characters into bytes. If c2 is -1 afterwards, C is
16923 really a one-byte character so that byte1 is zero. */
16924 SPLIT_CHAR (c
, charset
, c1
, c2
);
16926 STORE_XCHAR2B (char2b
, c1
, c2
);
16928 STORE_XCHAR2B (char2b
, 0, c1
);
16930 /* Maybe encode the character in *CHAR2B. */
16931 if (face
->font
!= NULL
)
16933 struct font_info
*font_info
16934 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
16936 rif
->encode_char (c
, char2b
, font_info
, 0);
16940 /* Make sure X resources of the face are allocated. */
16941 #ifdef HAVE_X_WINDOWS
16945 xassert (face
!= NULL
);
16946 PREPARE_FACE_FOR_DISPLAY (f
, face
);
16953 /* Set background width of glyph string S. START is the index of the
16954 first glyph following S. LAST_X is the right-most x-position + 1
16955 in the drawing area. */
16958 set_glyph_string_background_width (s
, start
, last_x
)
16959 struct glyph_string
*s
;
16963 /* If the face of this glyph string has to be drawn to the end of
16964 the drawing area, set S->extends_to_end_of_line_p. */
16965 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
16967 if (start
== s
->row
->used
[s
->area
]
16968 && s
->area
== TEXT_AREA
16969 && ((s
->hl
== DRAW_NORMAL_TEXT
16970 && (s
->row
->fill_line_p
16971 || s
->face
->background
!= default_face
->background
16972 || s
->face
->stipple
!= default_face
->stipple
16973 || s
->row
->mouse_face_p
))
16974 || s
->hl
== DRAW_MOUSE_FACE
16975 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
16976 && s
->row
->fill_line_p
)))
16977 s
->extends_to_end_of_line_p
= 1;
16979 /* If S extends its face to the end of the line, set its
16980 background_width to the distance to the right edge of the drawing
16982 if (s
->extends_to_end_of_line_p
)
16983 s
->background_width
= last_x
- s
->x
+ 1;
16985 s
->background_width
= s
->width
;
16989 /* Compute overhangs and x-positions for glyph string S and its
16990 predecessors, or successors. X is the starting x-position for S.
16991 BACKWARD_P non-zero means process predecessors. */
16994 compute_overhangs_and_x (s
, x
, backward_p
)
16995 struct glyph_string
*s
;
17003 if (rif
->compute_glyph_string_overhangs
)
17004 rif
->compute_glyph_string_overhangs (s
);
17014 if (rif
->compute_glyph_string_overhangs
)
17015 rif
->compute_glyph_string_overhangs (s
);
17025 /* The following macros are only called from draw_glyphs below.
17026 They reference the following parameters of that function directly:
17027 `w', `row', `area', and `overlap_p'
17028 as well as the following local variables:
17029 `s', `f', and `hdc' (in W32) */
17032 /* On W32, silently add local `hdc' variable to argument list of
17033 init_glyph_string. */
17034 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17035 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
17037 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17038 init_glyph_string (s, char2b, w, row, area, start, hl)
17041 /* Add a glyph string for a stretch glyph to the list of strings
17042 between HEAD and TAIL. START is the index of the stretch glyph in
17043 row area AREA of glyph row ROW. END is the index of the last glyph
17044 in that glyph row area. X is the current output position assigned
17045 to the new glyph string constructed. HL overrides that face of the
17046 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17047 is the right-most x-position of the drawing area. */
17049 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
17050 and below -- keep them on one line. */
17051 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17054 s = (struct glyph_string *) alloca (sizeof *s); \
17055 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17056 START = fill_stretch_glyph_string (s, row, area, START, END); \
17057 append_glyph_string (&HEAD, &TAIL, s); \
17063 /* Add a glyph string for an image glyph to the list of strings
17064 between HEAD and TAIL. START is the index of the image glyph in
17065 row area AREA of glyph row ROW. END is the index of the last glyph
17066 in that glyph row area. X is the current output position assigned
17067 to the new glyph string constructed. HL overrides that face of the
17068 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17069 is the right-most x-position of the drawing area. */
17071 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17074 s = (struct glyph_string *) alloca (sizeof *s); \
17075 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17076 fill_image_glyph_string (s); \
17077 append_glyph_string (&HEAD, &TAIL, s); \
17084 /* Add a glyph string for a sequence of character glyphs to the list
17085 of strings between HEAD and TAIL. START is the index of the first
17086 glyph in row area AREA of glyph row ROW that is part of the new
17087 glyph string. END is the index of the last glyph in that glyph row
17088 area. X is the current output position assigned to the new glyph
17089 string constructed. HL overrides that face of the glyph; e.g. it
17090 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
17091 right-most x-position of the drawing area. */
17093 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17099 c = (row)->glyphs[area][START].u.ch; \
17100 face_id = (row)->glyphs[area][START].face_id; \
17102 s = (struct glyph_string *) alloca (sizeof *s); \
17103 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
17104 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
17105 append_glyph_string (&HEAD, &TAIL, s); \
17107 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
17112 /* Add a glyph string for a composite sequence to the list of strings
17113 between HEAD and TAIL. START is the index of the first glyph in
17114 row area AREA of glyph row ROW that is part of the new glyph
17115 string. END is the index of the last glyph in that glyph row area.
17116 X is the current output position assigned to the new glyph string
17117 constructed. HL overrides that face of the glyph; e.g. it is
17118 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
17119 x-position of the drawing area. */
17121 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17123 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
17124 int face_id = (row)->glyphs[area][START].face_id; \
17125 struct face *base_face = FACE_FROM_ID (f, face_id); \
17126 struct composition *cmp = composition_table[cmp_id]; \
17127 int glyph_len = cmp->glyph_len; \
17129 struct face **faces; \
17130 struct glyph_string *first_s = NULL; \
17133 base_face = base_face->ascii_face; \
17134 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
17135 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
17136 /* At first, fill in `char2b' and `faces'. */ \
17137 for (n = 0; n < glyph_len; n++) \
17139 int c = COMPOSITION_GLYPH (cmp, n); \
17140 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
17141 faces[n] = FACE_FROM_ID (f, this_face_id); \
17142 get_char_face_and_encoding (f, c, this_face_id, \
17143 char2b + n, 1, 1); \
17146 /* Make glyph_strings for each glyph sequence that is drawable by \
17147 the same face, and append them to HEAD/TAIL. */ \
17148 for (n = 0; n < cmp->glyph_len;) \
17150 s = (struct glyph_string *) alloca (sizeof *s); \
17151 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
17152 append_glyph_string (&(HEAD), &(TAIL), s); \
17160 n = fill_composite_glyph_string (s, faces, overlaps_p); \
17168 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
17169 of AREA of glyph row ROW on window W between indices START and END.
17170 HL overrides the face for drawing glyph strings, e.g. it is
17171 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
17172 x-positions of the drawing area.
17174 This is an ugly monster macro construct because we must use alloca
17175 to allocate glyph strings (because draw_glyphs can be called
17176 asynchronously). */
17178 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17181 HEAD = TAIL = NULL; \
17182 while (START < END) \
17184 struct glyph *first_glyph = (row)->glyphs[area] + START; \
17185 switch (first_glyph->type) \
17188 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
17192 case COMPOSITE_GLYPH: \
17193 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
17197 case STRETCH_GLYPH: \
17198 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
17202 case IMAGE_GLYPH: \
17203 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
17211 set_glyph_string_background_width (s, START, LAST_X); \
17218 /* Draw glyphs between START and END in AREA of ROW on window W,
17219 starting at x-position X. X is relative to AREA in W. HL is a
17220 face-override with the following meaning:
17222 DRAW_NORMAL_TEXT draw normally
17223 DRAW_CURSOR draw in cursor face
17224 DRAW_MOUSE_FACE draw in mouse face.
17225 DRAW_INVERSE_VIDEO draw in mode line face
17226 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
17227 DRAW_IMAGE_RAISED draw an image with a raised relief around it
17229 If OVERLAPS_P is non-zero, draw only the foreground of characters
17230 and clip to the physical height of ROW.
17232 Value is the x-position reached, relative to AREA of W. */
17235 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
17238 struct glyph_row
*row
;
17239 enum glyph_row_area area
;
17241 enum draw_glyphs_face hl
;
17244 struct glyph_string
*head
, *tail
;
17245 struct glyph_string
*s
;
17246 int last_x
, area_width
;
17249 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17252 ALLOCATE_HDC (hdc
, f
);
17254 /* Let's rather be paranoid than getting a SEGV. */
17255 end
= min (end
, row
->used
[area
]);
17256 start
= max (0, start
);
17257 start
= min (end
, start
);
17259 /* Translate X to frame coordinates. Set last_x to the right
17260 end of the drawing area. */
17261 if (row
->full_width_p
)
17263 /* X is relative to the left edge of W, without scroll bars
17265 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
17267 x
+= window_left_x
;
17268 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
17269 last_x
= window_left_x
+ area_width
;
17271 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
17273 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
17274 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
17280 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
17281 /* ++KFS: W32 and MAC versions had -= in next line (bug??) */
17282 last_x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
17286 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
17287 area_width
= window_box_width (w
, area
);
17288 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
17291 /* Build a doubly-linked list of glyph_string structures between
17292 head and tail from what we have to draw. Note that the macro
17293 BUILD_GLYPH_STRINGS will modify its start parameter. That's
17294 the reason we use a separate variable `i'. */
17296 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
17298 x_reached
= tail
->x
+ tail
->background_width
;
17302 /* If there are any glyphs with lbearing < 0 or rbearing > width in
17303 the row, redraw some glyphs in front or following the glyph
17304 strings built above. */
17305 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
17308 struct glyph_string
*h
, *t
;
17310 /* Compute overhangs for all glyph strings. */
17311 if (rif
->compute_glyph_string_overhangs
)
17312 for (s
= head
; s
; s
= s
->next
)
17313 rif
->compute_glyph_string_overhangs (s
);
17315 /* Prepend glyph strings for glyphs in front of the first glyph
17316 string that are overwritten because of the first glyph
17317 string's left overhang. The background of all strings
17318 prepended must be drawn because the first glyph string
17320 i
= left_overwritten (head
);
17324 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
17325 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17327 compute_overhangs_and_x (t
, head
->x
, 1);
17328 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
17331 /* Prepend glyph strings for glyphs in front of the first glyph
17332 string that overwrite that glyph string because of their
17333 right overhang. For these strings, only the foreground must
17334 be drawn, because it draws over the glyph string at `head'.
17335 The background must not be drawn because this would overwrite
17336 right overhangs of preceding glyphs for which no glyph
17338 i
= left_overwriting (head
);
17341 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
17342 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17343 for (s
= h
; s
; s
= s
->next
)
17344 s
->background_filled_p
= 1;
17345 compute_overhangs_and_x (t
, head
->x
, 1);
17346 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
17349 /* Append glyphs strings for glyphs following the last glyph
17350 string tail that are overwritten by tail. The background of
17351 these strings has to be drawn because tail's foreground draws
17353 i
= right_overwritten (tail
);
17356 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
17357 DRAW_NORMAL_TEXT
, x
, last_x
);
17358 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
17359 append_glyph_string_lists (&head
, &tail
, h
, t
);
17362 /* Append glyph strings for glyphs following the last glyph
17363 string tail that overwrite tail. The foreground of such
17364 glyphs has to be drawn because it writes into the background
17365 of tail. The background must not be drawn because it could
17366 paint over the foreground of following glyphs. */
17367 i
= right_overwriting (tail
);
17370 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
17371 DRAW_NORMAL_TEXT
, x
, last_x
);
17372 for (s
= h
; s
; s
= s
->next
)
17373 s
->background_filled_p
= 1;
17374 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
17375 append_glyph_string_lists (&head
, &tail
, h
, t
);
17379 /* Draw all strings. */
17380 for (s
= head
; s
; s
= s
->next
)
17381 rif
->draw_glyph_string (s
);
17383 if (area
== TEXT_AREA
17384 && !row
->full_width_p
17385 /* When drawing overlapping rows, only the glyph strings'
17386 foreground is drawn, which doesn't erase a cursor
17390 int x0
= head
? head
->x
: x
;
17391 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
17393 x0
= FRAME_TO_WINDOW_PIXEL_X (w
, x0
);
17394 x1
= FRAME_TO_WINDOW_PIXEL_X (w
, x1
);
17396 /* ++KFS: W32 and MAC versions had following test here:
17397 if (!row->full_width_p && XFASTINT (w->left_margin_width) != 0)
17400 if (XFASTINT (w
->left_margin_width
) != 0)
17402 int left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
17403 x0
-= left_area_width
;
17404 x1
-= left_area_width
;
17407 notice_overwritten_cursor (w
, area
, x0
, x1
,
17408 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
17411 /* Value is the x-position up to which drawn, relative to AREA of W.
17412 This doesn't include parts drawn because of overhangs. */
17413 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
17414 if (!row
->full_width_p
)
17416 /* ++KFS: W32 and MAC versions only had this test here:
17417 if (area > LEFT_MARGIN_AREA)
17420 if (area
> LEFT_MARGIN_AREA
&& XFASTINT (w
->left_margin_width
) != 0)
17421 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
17422 if (area
> TEXT_AREA
)
17423 x_reached
-= window_box_width (w
, TEXT_AREA
);
17426 RELEASE_HDC (hdc
, f
);
17432 /* Store one glyph for IT->char_to_display in IT->glyph_row.
17433 Called from x_produce_glyphs when IT->glyph_row is non-null. */
17439 struct glyph
*glyph
;
17440 enum glyph_row_area area
= it
->area
;
17442 xassert (it
->glyph_row
);
17443 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
17445 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17446 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17448 glyph
->charpos
= CHARPOS (it
->position
);
17449 glyph
->object
= it
->object
;
17450 glyph
->pixel_width
= it
->pixel_width
;
17451 glyph
->voffset
= it
->voffset
;
17452 glyph
->type
= CHAR_GLYPH
;
17453 glyph
->multibyte_p
= it
->multibyte_p
;
17454 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17455 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17456 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
17457 || it
->phys_descent
> it
->descent
);
17458 glyph
->padding_p
= 0;
17459 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
17460 glyph
->face_id
= it
->face_id
;
17461 glyph
->u
.ch
= it
->char_to_display
;
17462 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17463 ++it
->glyph_row
->used
[area
];
17467 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
17468 Called from x_produce_glyphs when IT->glyph_row is non-null. */
17471 append_composite_glyph (it
)
17474 struct glyph
*glyph
;
17475 enum glyph_row_area area
= it
->area
;
17477 xassert (it
->glyph_row
);
17479 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17480 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17482 glyph
->charpos
= CHARPOS (it
->position
);
17483 glyph
->object
= it
->object
;
17484 glyph
->pixel_width
= it
->pixel_width
;
17485 glyph
->voffset
= it
->voffset
;
17486 glyph
->type
= COMPOSITE_GLYPH
;
17487 glyph
->multibyte_p
= it
->multibyte_p
;
17488 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17489 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17490 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
17491 || it
->phys_descent
> it
->descent
);
17492 glyph
->padding_p
= 0;
17493 glyph
->glyph_not_available_p
= 0;
17494 glyph
->face_id
= it
->face_id
;
17495 glyph
->u
.cmp_id
= it
->cmp_id
;
17496 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17497 ++it
->glyph_row
->used
[area
];
17502 /* Change IT->ascent and IT->height according to the setting of
17506 take_vertical_position_into_account (it
)
17511 if (it
->voffset
< 0)
17512 /* Increase the ascent so that we can display the text higher
17514 it
->ascent
+= abs (it
->voffset
);
17516 /* Increase the descent so that we can display the text lower
17518 it
->descent
+= it
->voffset
;
17523 /* Produce glyphs/get display metrics for the image IT is loaded with.
17524 See the description of struct display_iterator in dispextern.h for
17525 an overview of struct display_iterator. */
17528 produce_image_glyph (it
)
17534 xassert (it
->what
== IT_IMAGE
);
17536 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17537 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
17540 /* Make sure X resources of the face and image are loaded. */
17541 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
17542 prepare_image_for_display (it
->f
, img
);
17544 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
17545 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
17546 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
17550 if (face
->box
!= FACE_NO_BOX
)
17552 if (face
->box_line_width
> 0)
17554 it
->ascent
+= face
->box_line_width
;
17555 it
->descent
+= face
->box_line_width
;
17558 if (it
->start_of_box_run_p
)
17559 it
->pixel_width
+= abs (face
->box_line_width
);
17560 if (it
->end_of_box_run_p
)
17561 it
->pixel_width
+= abs (face
->box_line_width
);
17564 take_vertical_position_into_account (it
);
17568 struct glyph
*glyph
;
17569 enum glyph_row_area area
= it
->area
;
17571 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17572 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17574 glyph
->charpos
= CHARPOS (it
->position
);
17575 glyph
->object
= it
->object
;
17576 glyph
->pixel_width
= it
->pixel_width
;
17577 glyph
->voffset
= it
->voffset
;
17578 glyph
->type
= IMAGE_GLYPH
;
17579 glyph
->multibyte_p
= it
->multibyte_p
;
17580 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17581 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17582 glyph
->overlaps_vertically_p
= 0;
17583 glyph
->padding_p
= 0;
17584 glyph
->glyph_not_available_p
= 0;
17585 glyph
->face_id
= it
->face_id
;
17586 glyph
->u
.img_id
= img
->id
;
17587 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17588 ++it
->glyph_row
->used
[area
];
17594 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
17595 of the glyph, WIDTH and HEIGHT are the width and height of the
17596 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
17597 ascent of the glyph (0 <= ASCENT <= 1). */
17600 append_stretch_glyph (it
, object
, width
, height
, ascent
)
17602 Lisp_Object object
;
17606 struct glyph
*glyph
;
17607 enum glyph_row_area area
= it
->area
;
17609 xassert (ascent
>= 0 && ascent
<= 1);
17611 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17612 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17614 glyph
->charpos
= CHARPOS (it
->position
);
17615 glyph
->object
= object
;
17616 glyph
->pixel_width
= width
;
17617 glyph
->voffset
= it
->voffset
;
17618 glyph
->type
= STRETCH_GLYPH
;
17619 glyph
->multibyte_p
= it
->multibyte_p
;
17620 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17621 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17622 glyph
->overlaps_vertically_p
= 0;
17623 glyph
->padding_p
= 0;
17624 glyph
->glyph_not_available_p
= 0;
17625 glyph
->face_id
= it
->face_id
;
17626 glyph
->u
.stretch
.ascent
= height
* ascent
;
17627 glyph
->u
.stretch
.height
= height
;
17628 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17629 ++it
->glyph_row
->used
[area
];
17634 /* Produce a stretch glyph for iterator IT. IT->object is the value
17635 of the glyph property displayed. The value must be a list
17636 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
17639 1. `:width WIDTH' specifies that the space should be WIDTH *
17640 canonical char width wide. WIDTH may be an integer or floating
17643 2. `:relative-width FACTOR' specifies that the width of the stretch
17644 should be computed from the width of the first character having the
17645 `glyph' property, and should be FACTOR times that width.
17647 3. `:align-to HPOS' specifies that the space should be wide enough
17648 to reach HPOS, a value in canonical character units.
17650 Exactly one of the above pairs must be present.
17652 4. `:height HEIGHT' specifies that the height of the stretch produced
17653 should be HEIGHT, measured in canonical character units.
17655 5. `:relative-height FACTOR' specifies that the height of the
17656 stretch should be FACTOR times the height of the characters having
17657 the glyph property.
17659 Either none or exactly one of 4 or 5 must be present.
17661 6. `:ascent ASCENT' specifies that ASCENT percent of the height
17662 of the stretch should be used for the ascent of the stretch.
17663 ASCENT must be in the range 0 <= ASCENT <= 100. */
17665 #define NUMVAL(X) \
17666 ((INTEGERP (X) || FLOATP (X)) \
17672 produce_stretch_glyph (it
)
17675 /* (space :width WIDTH :height HEIGHT. */
17676 Lisp_Object prop
, plist
;
17677 int width
= 0, height
= 0;
17679 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17680 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
17682 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
17684 /* List should start with `space'. */
17685 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
17686 plist
= XCDR (it
->object
);
17688 /* Compute the width of the stretch. */
17689 if (prop
= Fplist_get (plist
, QCwidth
),
17691 /* Absolute width `:width WIDTH' specified and valid. */
17692 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
17693 else if (prop
= Fplist_get (plist
, QCrelative_width
),
17696 /* Relative width `:relative-width FACTOR' specified and valid.
17697 Compute the width of the characters having the `glyph'
17700 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
17703 if (it
->multibyte_p
)
17705 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
17706 - IT_BYTEPOS (*it
));
17707 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
17710 it2
.c
= *p
, it2
.len
= 1;
17712 it2
.glyph_row
= NULL
;
17713 it2
.what
= IT_CHARACTER
;
17714 x_produce_glyphs (&it2
);
17715 width
= NUMVAL (prop
) * it2
.pixel_width
;
17717 else if (prop
= Fplist_get (plist
, QCalign_to
),
17719 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
17721 /* Nothing specified -> width defaults to canonical char width. */
17722 width
= CANON_X_UNIT (it
->f
);
17724 /* Compute height. */
17725 if (prop
= Fplist_get (plist
, QCheight
),
17727 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
17728 else if (prop
= Fplist_get (plist
, QCrelative_height
),
17730 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
17732 height
= FONT_HEIGHT (font
);
17734 /* Compute percentage of height used for ascent. If
17735 `:ascent ASCENT' is present and valid, use that. Otherwise,
17736 derive the ascent from the font in use. */
17737 if (prop
= Fplist_get (plist
, QCascent
),
17738 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
17739 ascent
= NUMVAL (prop
) / 100.0;
17741 ascent
= (double) FONT_BASE (font
) / FONT_HEIGHT (font
);
17750 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
17751 if (!STRINGP (object
))
17752 object
= it
->w
->buffer
;
17753 append_stretch_glyph (it
, object
, width
, height
, ascent
);
17756 it
->pixel_width
= width
;
17757 it
->ascent
= it
->phys_ascent
= height
* ascent
;
17758 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
17761 if (face
->box
!= FACE_NO_BOX
)
17763 if (face
->box_line_width
> 0)
17765 it
->ascent
+= face
->box_line_width
;
17766 it
->descent
+= face
->box_line_width
;
17769 if (it
->start_of_box_run_p
)
17770 it
->pixel_width
+= abs (face
->box_line_width
);
17771 if (it
->end_of_box_run_p
)
17772 it
->pixel_width
+= abs (face
->box_line_width
);
17775 take_vertical_position_into_account (it
);
17779 Produce glyphs/get display metrics for the display element IT is
17780 loaded with. See the description of struct display_iterator in
17781 dispextern.h for an overview of struct display_iterator. */
17784 x_produce_glyphs (it
)
17787 it
->glyph_not_available_p
= 0;
17789 if (it
->what
== IT_CHARACTER
)
17793 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17795 int font_not_found_p
;
17796 struct font_info
*font_info
;
17797 int boff
; /* baseline offset */
17798 /* We may change it->multibyte_p upon unibyte<->multibyte
17799 conversion. So, save the current value now and restore it
17802 Note: It seems that we don't have to record multibyte_p in
17803 struct glyph because the character code itself tells if or
17804 not the character is multibyte. Thus, in the future, we must
17805 consider eliminating the field `multibyte_p' in the struct
17807 int saved_multibyte_p
= it
->multibyte_p
;
17809 /* Maybe translate single-byte characters to multibyte, or the
17811 it
->char_to_display
= it
->c
;
17812 if (!ASCII_BYTE_P (it
->c
))
17814 if (unibyte_display_via_language_environment
17815 && SINGLE_BYTE_CHAR_P (it
->c
)
17817 || !NILP (Vnonascii_translation_table
)))
17819 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
17820 it
->multibyte_p
= 1;
17821 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
17822 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17824 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
17825 && !it
->multibyte_p
)
17827 it
->multibyte_p
= 1;
17828 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
17829 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17833 /* Get font to use. Encode IT->char_to_display. */
17834 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
17835 &char2b
, it
->multibyte_p
, 0);
17838 /* When no suitable font found, use the default font. */
17839 font_not_found_p
= font
== NULL
;
17840 if (font_not_found_p
)
17842 font
= FRAME_FONT (it
->f
);
17843 boff
= FRAME_BASELINE_OFFSET (it
->f
);
17848 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
17849 boff
= font_info
->baseline_offset
;
17850 if (font_info
->vertical_centering
)
17851 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
17854 if (it
->char_to_display
>= ' '
17855 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
17857 /* Either unibyte or ASCII. */
17862 pcm
= rif
->per_char_metric (font
, &char2b
,
17863 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
17864 it
->ascent
= FONT_BASE (font
) + boff
;
17865 it
->descent
= FONT_DESCENT (font
) - boff
;
17869 it
->phys_ascent
= pcm
->ascent
+ boff
;
17870 it
->phys_descent
= pcm
->descent
- boff
;
17871 it
->pixel_width
= pcm
->width
;
17875 it
->glyph_not_available_p
= 1;
17876 it
->phys_ascent
= FONT_BASE (font
) + boff
;
17877 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
17878 it
->pixel_width
= FONT_WIDTH (font
);
17881 /* If this is a space inside a region of text with
17882 `space-width' property, change its width. */
17883 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
17885 it
->pixel_width
*= XFLOATINT (it
->space_width
);
17887 /* If face has a box, add the box thickness to the character
17888 height. If character has a box line to the left and/or
17889 right, add the box line width to the character's width. */
17890 if (face
->box
!= FACE_NO_BOX
)
17892 int thick
= face
->box_line_width
;
17896 it
->ascent
+= thick
;
17897 it
->descent
+= thick
;
17902 if (it
->start_of_box_run_p
)
17903 it
->pixel_width
+= thick
;
17904 if (it
->end_of_box_run_p
)
17905 it
->pixel_width
+= thick
;
17908 /* If face has an overline, add the height of the overline
17909 (1 pixel) and a 1 pixel margin to the character height. */
17910 if (face
->overline_p
)
17913 take_vertical_position_into_account (it
);
17915 /* If we have to actually produce glyphs, do it. */
17920 /* Translate a space with a `space-width' property
17921 into a stretch glyph. */
17922 double ascent
= (double) FONT_BASE (font
)
17923 / FONT_HEIGHT (font
);
17924 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
17925 it
->ascent
+ it
->descent
, ascent
);
17930 /* If characters with lbearing or rbearing are displayed
17931 in this line, record that fact in a flag of the
17932 glyph row. This is used to optimize X output code. */
17933 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
17934 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
17937 else if (it
->char_to_display
== '\n')
17939 /* A newline has no width but we need the height of the line. */
17940 it
->pixel_width
= 0;
17942 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
17943 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
17945 if (face
->box
!= FACE_NO_BOX
17946 && face
->box_line_width
> 0)
17948 it
->ascent
+= face
->box_line_width
;
17949 it
->descent
+= face
->box_line_width
;
17952 else if (it
->char_to_display
== '\t')
17954 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
17955 int x
= it
->current_x
+ it
->continuation_lines_width
;
17956 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
17958 /* If the distance from the current position to the next tab
17959 stop is less than a canonical character width, use the
17960 tab stop after that. */
17961 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
17962 next_tab_x
+= tab_width
;
17964 it
->pixel_width
= next_tab_x
- x
;
17966 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
17967 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
17971 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
17972 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
17973 it
->ascent
+ it
->descent
, ascent
);
17978 /* A multi-byte character. Assume that the display width of the
17979 character is the width of the character multiplied by the
17980 width of the font. */
17982 /* If we found a font, this font should give us the right
17983 metrics. If we didn't find a font, use the frame's
17984 default font and calculate the width of the character
17985 from the charset width; this is what old redisplay code
17988 pcm
= rif
->per_char_metric (font
, &char2b
,
17989 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
17991 if (font_not_found_p
|| !pcm
)
17993 int charset
= CHAR_CHARSET (it
->char_to_display
);
17995 it
->glyph_not_available_p
= 1;
17996 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
17997 * CHARSET_WIDTH (charset
));
17998 it
->phys_ascent
= FONT_BASE (font
) + boff
;
17999 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18003 it
->pixel_width
= pcm
->width
;
18004 it
->phys_ascent
= pcm
->ascent
+ boff
;
18005 it
->phys_descent
= pcm
->descent
- boff
;
18007 && (pcm
->lbearing
< 0
18008 || pcm
->rbearing
> pcm
->width
))
18009 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18012 it
->ascent
= FONT_BASE (font
) + boff
;
18013 it
->descent
= FONT_DESCENT (font
) - boff
;
18014 if (face
->box
!= FACE_NO_BOX
)
18016 int thick
= face
->box_line_width
;
18020 it
->ascent
+= thick
;
18021 it
->descent
+= thick
;
18026 if (it
->start_of_box_run_p
)
18027 it
->pixel_width
+= thick
;
18028 if (it
->end_of_box_run_p
)
18029 it
->pixel_width
+= thick
;
18032 /* If face has an overline, add the height of the overline
18033 (1 pixel) and a 1 pixel margin to the character height. */
18034 if (face
->overline_p
)
18037 take_vertical_position_into_account (it
);
18042 it
->multibyte_p
= saved_multibyte_p
;
18044 else if (it
->what
== IT_COMPOSITION
)
18046 /* Note: A composition is represented as one glyph in the
18047 glyph matrix. There are no padding glyphs. */
18050 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18052 int font_not_found_p
;
18053 struct font_info
*font_info
;
18054 int boff
; /* baseline offset */
18055 struct composition
*cmp
= composition_table
[it
->cmp_id
];
18057 /* Maybe translate single-byte characters to multibyte. */
18058 it
->char_to_display
= it
->c
;
18059 if (unibyte_display_via_language_environment
18060 && SINGLE_BYTE_CHAR_P (it
->c
)
18063 && !NILP (Vnonascii_translation_table
))))
18065 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18068 /* Get face and font to use. Encode IT->char_to_display. */
18069 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18070 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18071 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18072 &char2b
, it
->multibyte_p
, 0);
18075 /* When no suitable font found, use the default font. */
18076 font_not_found_p
= font
== NULL
;
18077 if (font_not_found_p
)
18079 font
= FRAME_FONT (it
->f
);
18080 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18085 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18086 boff
= font_info
->baseline_offset
;
18087 if (font_info
->vertical_centering
)
18088 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18091 /* There are no padding glyphs, so there is only one glyph to
18092 produce for the composition. Important is that pixel_width,
18093 ascent and descent are the values of what is drawn by
18094 draw_glyphs (i.e. the values of the overall glyphs composed). */
18097 /* If we have not yet calculated pixel size data of glyphs of
18098 the composition for the current face font, calculate them
18099 now. Theoretically, we have to check all fonts for the
18100 glyphs, but that requires much time and memory space. So,
18101 here we check only the font of the first glyph. This leads
18102 to incorrect display very rarely, and C-l (recenter) can
18103 correct the display anyway. */
18104 if (cmp
->font
!= (void *) font
)
18106 /* Ascent and descent of the font of the first character of
18107 this composition (adjusted by baseline offset). Ascent
18108 and descent of overall glyphs should not be less than
18109 them respectively. */
18110 int font_ascent
= FONT_BASE (font
) + boff
;
18111 int font_descent
= FONT_DESCENT (font
) - boff
;
18112 /* Bounding box of the overall glyphs. */
18113 int leftmost
, rightmost
, lowest
, highest
;
18114 int i
, width
, ascent
, descent
;
18116 cmp
->font
= (void *) font
;
18118 /* Initialize the bounding box. */
18120 && (pcm
= rif
->per_char_metric (font
, &char2b
,
18121 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
18123 width
= pcm
->width
;
18124 ascent
= pcm
->ascent
;
18125 descent
= pcm
->descent
;
18129 width
= FONT_WIDTH (font
);
18130 ascent
= FONT_BASE (font
);
18131 descent
= FONT_DESCENT (font
);
18135 lowest
= - descent
+ boff
;
18136 highest
= ascent
+ boff
;
18140 && font_info
->default_ascent
18141 && CHAR_TABLE_P (Vuse_default_ascent
)
18142 && !NILP (Faref (Vuse_default_ascent
,
18143 make_number (it
->char_to_display
))))
18144 highest
= font_info
->default_ascent
+ boff
;
18146 /* Draw the first glyph at the normal position. It may be
18147 shifted to right later if some other glyphs are drawn at
18149 cmp
->offsets
[0] = 0;
18150 cmp
->offsets
[1] = boff
;
18152 /* Set cmp->offsets for the remaining glyphs. */
18153 for (i
= 1; i
< cmp
->glyph_len
; i
++)
18155 int left
, right
, btm
, top
;
18156 int ch
= COMPOSITION_GLYPH (cmp
, i
);
18157 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
18159 face
= FACE_FROM_ID (it
->f
, face_id
);
18160 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
18161 &char2b
, it
->multibyte_p
, 0);
18165 font
= FRAME_FONT (it
->f
);
18166 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18172 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18173 boff
= font_info
->baseline_offset
;
18174 if (font_info
->vertical_centering
)
18175 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18179 && (pcm
= rif
->per_char_metric (font
, &char2b
,
18180 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
18182 width
= pcm
->width
;
18183 ascent
= pcm
->ascent
;
18184 descent
= pcm
->descent
;
18188 width
= FONT_WIDTH (font
);
18193 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
18195 /* Relative composition with or without
18196 alternate chars. */
18197 left
= (leftmost
+ rightmost
- width
) / 2;
18198 btm
= - descent
+ boff
;
18199 if (font_info
&& font_info
->relative_compose
18200 && (! CHAR_TABLE_P (Vignore_relative_composition
)
18201 || NILP (Faref (Vignore_relative_composition
,
18202 make_number (ch
)))))
18205 if (- descent
>= font_info
->relative_compose
)
18206 /* One extra pixel between two glyphs. */
18208 else if (ascent
<= 0)
18209 /* One extra pixel between two glyphs. */
18210 btm
= lowest
- 1 - ascent
- descent
;
18215 /* A composition rule is specified by an integer
18216 value that encodes global and new reference
18217 points (GREF and NREF). GREF and NREF are
18218 specified by numbers as below:
18220 0---1---2 -- ascent
18224 9--10--11 -- center
18226 ---3---4---5--- baseline
18228 6---7---8 -- descent
18230 int rule
= COMPOSITION_RULE (cmp
, i
);
18231 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
18233 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
18234 grefx
= gref
% 3, nrefx
= nref
% 3;
18235 grefy
= gref
/ 3, nrefy
= nref
/ 3;
18238 + grefx
* (rightmost
- leftmost
) / 2
18239 - nrefx
* width
/ 2);
18240 btm
= ((grefy
== 0 ? highest
18242 : grefy
== 2 ? lowest
18243 : (highest
+ lowest
) / 2)
18244 - (nrefy
== 0 ? ascent
+ descent
18245 : nrefy
== 1 ? descent
- boff
18247 : (ascent
+ descent
) / 2));
18250 cmp
->offsets
[i
* 2] = left
;
18251 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
18253 /* Update the bounding box of the overall glyphs. */
18254 right
= left
+ width
;
18255 top
= btm
+ descent
+ ascent
;
18256 if (left
< leftmost
)
18258 if (right
> rightmost
)
18266 /* If there are glyphs whose x-offsets are negative,
18267 shift all glyphs to the right and make all x-offsets
18271 for (i
= 0; i
< cmp
->glyph_len
; i
++)
18272 cmp
->offsets
[i
* 2] -= leftmost
;
18273 rightmost
-= leftmost
;
18276 cmp
->pixel_width
= rightmost
;
18277 cmp
->ascent
= highest
;
18278 cmp
->descent
= - lowest
;
18279 if (cmp
->ascent
< font_ascent
)
18280 cmp
->ascent
= font_ascent
;
18281 if (cmp
->descent
< font_descent
)
18282 cmp
->descent
= font_descent
;
18285 it
->pixel_width
= cmp
->pixel_width
;
18286 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
18287 it
->descent
= it
->phys_descent
= cmp
->descent
;
18289 if (face
->box
!= FACE_NO_BOX
)
18291 int thick
= face
->box_line_width
;
18295 it
->ascent
+= thick
;
18296 it
->descent
+= thick
;
18301 if (it
->start_of_box_run_p
)
18302 it
->pixel_width
+= thick
;
18303 if (it
->end_of_box_run_p
)
18304 it
->pixel_width
+= thick
;
18307 /* If face has an overline, add the height of the overline
18308 (1 pixel) and a 1 pixel margin to the character height. */
18309 if (face
->overline_p
)
18312 take_vertical_position_into_account (it
);
18315 append_composite_glyph (it
);
18317 else if (it
->what
== IT_IMAGE
)
18318 produce_image_glyph (it
);
18319 else if (it
->what
== IT_STRETCH
)
18320 produce_stretch_glyph (it
);
18322 /* Accumulate dimensions. Note: can't assume that it->descent > 0
18323 because this isn't true for images with `:ascent 100'. */
18324 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
18325 if (it
->area
== TEXT_AREA
)
18326 it
->current_x
+= it
->pixel_width
;
18328 it
->descent
+= it
->extra_line_spacing
;
18330 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
18331 it
->max_descent
= max (it
->max_descent
, it
->descent
);
18332 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
18333 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
18337 Output LEN glyphs starting at START at the nominal cursor position.
18338 Advance the nominal cursor over the text. The global variable
18339 updated_window contains the window being updated, updated_row is
18340 the glyph row being updated, and updated_area is the area of that
18341 row being updated. */
18344 x_write_glyphs (start
, len
)
18345 struct glyph
*start
;
18350 xassert (updated_window
&& updated_row
);
18353 /* Write glyphs. */
18355 hpos
= start
- updated_row
->glyphs
[updated_area
];
18356 x
= draw_glyphs (updated_window
, output_cursor
.x
,
18357 updated_row
, updated_area
,
18359 DRAW_NORMAL_TEXT
, 0);
18361 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
18362 if (updated_area
== TEXT_AREA
18363 && updated_window
->phys_cursor_on_p
18364 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
18365 && updated_window
->phys_cursor
.hpos
>= hpos
18366 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
18367 updated_window
->phys_cursor_on_p
= 0;
18371 /* Advance the output cursor. */
18372 output_cursor
.hpos
+= len
;
18373 output_cursor
.x
= x
;
18378 Insert LEN glyphs from START at the nominal cursor position. */
18381 x_insert_glyphs (start
, len
)
18382 struct glyph
*start
;
18387 int line_height
, shift_by_width
, shifted_region_width
;
18388 struct glyph_row
*row
;
18389 struct glyph
*glyph
;
18390 int frame_x
, frame_y
, hpos
;
18392 xassert (updated_window
&& updated_row
);
18394 w
= updated_window
;
18395 f
= XFRAME (WINDOW_FRAME (w
));
18397 /* Get the height of the line we are in. */
18399 line_height
= row
->height
;
18401 /* Get the width of the glyphs to insert. */
18402 shift_by_width
= 0;
18403 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
18404 shift_by_width
+= glyph
->pixel_width
;
18406 /* Get the width of the region to shift right. */
18407 shifted_region_width
= (window_box_width (w
, updated_area
)
18412 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
18413 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
18415 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
18416 line_height
, shift_by_width
);
18418 /* Write the glyphs. */
18419 hpos
= start
- row
->glyphs
[updated_area
];
18420 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
18422 DRAW_NORMAL_TEXT
, 0);
18424 /* Advance the output cursor. */
18425 output_cursor
.hpos
+= len
;
18426 output_cursor
.x
+= shift_by_width
;
18432 Erase the current text line from the nominal cursor position
18433 (inclusive) to pixel column TO_X (exclusive). The idea is that
18434 everything from TO_X onward is already erased.
18436 TO_X is a pixel position relative to updated_area of
18437 updated_window. TO_X == -1 means clear to the end of this area. */
18440 x_clear_end_of_line (to_x
)
18444 struct window
*w
= updated_window
;
18445 int max_x
, min_y
, max_y
;
18446 int from_x
, from_y
, to_y
;
18448 xassert (updated_window
&& updated_row
);
18449 f
= XFRAME (w
->frame
);
18451 if (updated_row
->full_width_p
)
18453 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
18454 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
18455 && !w
->pseudo_window_p
)
18456 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
18459 max_x
= window_box_width (w
, updated_area
);
18460 max_y
= window_text_bottom_y (w
);
18462 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
18463 of window. For TO_X > 0, truncate to end of drawing area. */
18469 to_x
= min (to_x
, max_x
);
18471 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
18473 /* Notice if the cursor will be cleared by this operation. */
18474 if (!updated_row
->full_width_p
)
18475 notice_overwritten_cursor (w
, updated_area
,
18476 output_cursor
.x
, -1,
18478 MATRIX_ROW_BOTTOM_Y (updated_row
));
18480 from_x
= output_cursor
.x
;
18482 /* Translate to frame coordinates. */
18483 if (updated_row
->full_width_p
)
18485 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
18486 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
18490 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
18491 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
18494 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
18495 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
18496 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
18498 /* Prevent inadvertently clearing to end of the X window. */
18499 if (to_x
> from_x
&& to_y
> from_y
)
18502 rif
->clear_frame_area (f
, from_x
, from_y
,
18503 to_x
- from_x
, to_y
- from_y
);
18508 #endif /* HAVE_WINDOW_SYSTEM */
18512 /***********************************************************************
18514 ***********************************************************************/
18516 /* Value is the internal representation of the specified cursor type
18517 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
18518 of the bar cursor. */
18520 enum text_cursor_kinds
18521 get_specified_cursor_type (arg
, width
)
18525 enum text_cursor_kinds type
;
18530 if (EQ (arg
, Qbox
))
18531 return FILLED_BOX_CURSOR
;
18533 if (EQ (arg
, Qhollow
))
18534 return HOLLOW_BOX_CURSOR
;
18536 if (EQ (arg
, Qbar
))
18543 && EQ (XCAR (arg
), Qbar
)
18544 && INTEGERP (XCDR (arg
))
18545 && XINT (XCDR (arg
)) >= 0)
18547 *width
= XINT (XCDR (arg
));
18551 if (EQ (arg
, Qhbar
))
18554 return HBAR_CURSOR
;
18558 && EQ (XCAR (arg
), Qhbar
)
18559 && INTEGERP (XCDR (arg
))
18560 && XINT (XCDR (arg
)) >= 0)
18562 *width
= XINT (XCDR (arg
));
18563 return HBAR_CURSOR
;
18566 /* Treat anything unknown as "hollow box cursor".
18567 It was bad to signal an error; people have trouble fixing
18568 .Xdefaults with Emacs, when it has something bad in it. */
18569 type
= HOLLOW_BOX_CURSOR
;
18574 /* Set the default cursor types for specified frame. */
18576 set_frame_cursor_types (f
, arg
)
18583 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
18584 FRAME_CURSOR_WIDTH (f
) = width
;
18586 /* By default, set up the blink-off state depending on the on-state. */
18588 tem
= Fassoc (arg
, Vblink_cursor_alist
);
18591 FRAME_BLINK_OFF_CURSOR (f
)
18592 = get_specified_cursor_type (XCDR (tem
), &width
);
18593 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
18596 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
18600 /* Return the cursor we want to be displayed in window W. Return
18601 width of bar/hbar cursor through WIDTH arg. Return with
18602 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
18603 (i.e. if the `system caret' should track this cursor).
18605 In a mini-buffer window, we want the cursor only to appear if we
18606 are reading input from this window. For the selected window, we
18607 want the cursor type given by the frame parameter or buffer local
18608 setting of cursor-type. If explicitly marked off, draw no cursor.
18609 In all other cases, we want a hollow box cursor. */
18611 enum text_cursor_kinds
18612 get_window_cursor_type (w
, width
, active_cursor
)
18615 int *active_cursor
;
18617 struct frame
*f
= XFRAME (w
->frame
);
18618 struct buffer
*b
= XBUFFER (w
->buffer
);
18619 int cursor_type
= DEFAULT_CURSOR
;
18620 Lisp_Object alt_cursor
;
18621 int non_selected
= 0;
18623 *active_cursor
= 1;
18626 if (cursor_in_echo_area
18627 && FRAME_HAS_MINIBUF_P (f
)
18628 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
18630 if (w
== XWINDOW (echo_area_window
))
18632 *width
= FRAME_CURSOR_WIDTH (f
);
18633 return FRAME_DESIRED_CURSOR (f
);
18636 *active_cursor
= 0;
18640 /* Nonselected window or nonselected frame. */
18641 else if (w
!= XWINDOW (f
->selected_window
)
18642 #ifdef HAVE_WINDOW_SYSTEM
18643 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
18647 *active_cursor
= 0;
18649 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
18655 /* Never display a cursor in a window in which cursor-type is nil. */
18656 if (NILP (b
->cursor_type
))
18659 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
18662 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
18663 return get_specified_cursor_type (alt_cursor
, width
);
18666 /* Get the normal cursor type for this window. */
18667 if (EQ (b
->cursor_type
, Qt
))
18669 cursor_type
= FRAME_DESIRED_CURSOR (f
);
18670 *width
= FRAME_CURSOR_WIDTH (f
);
18673 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
18675 /* Use normal cursor if not blinked off. */
18676 if (!w
->cursor_off_p
)
18677 return cursor_type
;
18679 /* Cursor is blinked off, so determine how to "toggle" it. */
18681 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
18682 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
18683 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
18685 /* Then see if frame has specified a specific blink off cursor type. */
18686 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
18688 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
18689 return FRAME_BLINK_OFF_CURSOR (f
);
18692 /* Finally perform built-in cursor blinking:
18693 filled box <-> hollow box
18694 wide [h]bar <-> narrow [h]bar
18695 narrow [h]bar <-> no cursor
18696 other type <-> no cursor */
18698 if (cursor_type
== FILLED_BOX_CURSOR
)
18699 return HOLLOW_BOX_CURSOR
;
18701 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
18704 return cursor_type
;
18711 #ifdef HAVE_WINDOW_SYSTEM
18713 /* Notice when the text cursor of window W has been completely
18714 overwritten by a drawing operation that outputs glyphs in AREA
18715 starting at X0 and ending at X1 in the line starting at Y0 and
18716 ending at Y1. X coordinates are area-relative. X1 < 0 means all
18717 the rest of the line after X0 has been written. Y coordinates
18718 are window-relative. */
18721 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
18723 enum glyph_row_area area
;
18724 int x0
, y0
, x1
, y1
;
18726 if (area
== TEXT_AREA
&& w
->phys_cursor_on_p
)
18728 int cx0
= w
->phys_cursor
.x
;
18729 int cx1
= cx0
+ w
->phys_cursor_width
;
18730 int cy0
= w
->phys_cursor
.y
;
18731 int cy1
= cy0
+ w
->phys_cursor_height
;
18733 if (x0
<= cx0
&& (x1
< 0 || x1
>= cx1
))
18735 /* The cursor image will be completely removed from the
18736 screen if the output area intersects the cursor area in
18737 y-direction. When we draw in [y0 y1[, and some part of
18738 the cursor is at y < y0, that part must have been drawn
18739 before. When scrolling, the cursor is erased before
18740 actually scrolling, so we don't come here. When not
18741 scrolling, the rows above the old cursor row must have
18742 changed, and in this case these rows must have written
18743 over the cursor image.
18745 Likewise if part of the cursor is below y1, with the
18746 exception of the cursor being in the first blank row at
18747 the buffer and window end because update_text_area
18748 doesn't draw that row. (Except when it does, but
18749 that's handled in update_text_area.) */
18751 if (((y0
>= cy0
&& y0
< cy1
) || (y1
> cy0
&& y1
< cy1
))
18752 && w
->current_matrix
->rows
[w
->phys_cursor
.vpos
].displays_text_p
)
18753 w
->phys_cursor_on_p
= 0;
18758 #endif /* HAVE_WINDOW_SYSTEM */
18761 /************************************************************************
18763 ************************************************************************/
18765 #ifdef HAVE_WINDOW_SYSTEM
18768 Fix the display of area AREA of overlapping row ROW in window W. */
18771 x_fix_overlapping_area (w
, row
, area
)
18773 struct glyph_row
*row
;
18774 enum glyph_row_area area
;
18780 if (area
== LEFT_MARGIN_AREA
)
18782 else if (area
== TEXT_AREA
)
18783 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
18785 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
18786 + window_box_width (w
, TEXT_AREA
));
18788 for (i
= 0; i
< row
->used
[area
];)
18790 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
18792 int start
= i
, start_x
= x
;
18796 x
+= row
->glyphs
[area
][i
].pixel_width
;
18799 while (i
< row
->used
[area
]
18800 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
18802 draw_glyphs (w
, start_x
, row
, area
,
18804 DRAW_NORMAL_TEXT
, 1);
18808 x
+= row
->glyphs
[area
][i
].pixel_width
;
18818 Draw the cursor glyph of window W in glyph row ROW. See the
18819 comment of draw_glyphs for the meaning of HL. */
18822 draw_phys_cursor_glyph (w
, row
, hl
)
18824 struct glyph_row
*row
;
18825 enum draw_glyphs_face hl
;
18827 /* If cursor hpos is out of bounds, don't draw garbage. This can
18828 happen in mini-buffer windows when switching between echo area
18829 glyphs and mini-buffer. */
18830 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
18832 int on_p
= w
->phys_cursor_on_p
;
18834 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
18835 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
18837 w
->phys_cursor_on_p
= on_p
;
18839 if (hl
== DRAW_CURSOR
)
18840 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
18841 /* When we erase the cursor, and ROW is overlapped by other
18842 rows, make sure that these overlapping parts of other rows
18844 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
18846 if (row
> w
->current_matrix
->rows
18847 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
18848 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
18850 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
18851 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
18852 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
18859 Erase the image of a cursor of window W from the screen. */
18862 erase_phys_cursor (w
)
18865 struct frame
*f
= XFRAME (w
->frame
);
18866 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
18867 int hpos
= w
->phys_cursor
.hpos
;
18868 int vpos
= w
->phys_cursor
.vpos
;
18869 int mouse_face_here_p
= 0;
18870 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
18871 struct glyph_row
*cursor_row
;
18872 struct glyph
*cursor_glyph
;
18873 enum draw_glyphs_face hl
;
18875 /* No cursor displayed or row invalidated => nothing to do on the
18877 if (w
->phys_cursor_type
== NO_CURSOR
)
18878 goto mark_cursor_off
;
18880 /* VPOS >= active_glyphs->nrows means that window has been resized.
18881 Don't bother to erase the cursor. */
18882 if (vpos
>= active_glyphs
->nrows
)
18883 goto mark_cursor_off
;
18885 /* If row containing cursor is marked invalid, there is nothing we
18887 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
18888 if (!cursor_row
->enabled_p
)
18889 goto mark_cursor_off
;
18891 /* If row is completely invisible, don't attempt to delete a cursor which
18892 isn't there. This can happen if cursor is at top of a window, and
18893 we switch to a buffer with a header line in that window. */
18894 if (cursor_row
->visible_height
<= 0)
18895 goto mark_cursor_off
;
18897 /* This can happen when the new row is shorter than the old one.
18898 In this case, either draw_glyphs or clear_end_of_line
18899 should have cleared the cursor. Note that we wouldn't be
18900 able to erase the cursor in this case because we don't have a
18901 cursor glyph at hand. */
18902 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
18903 goto mark_cursor_off
;
18905 /* If the cursor is in the mouse face area, redisplay that when
18906 we clear the cursor. */
18907 if (! NILP (dpyinfo
->mouse_face_window
)
18908 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
18909 && (vpos
> dpyinfo
->mouse_face_beg_row
18910 || (vpos
== dpyinfo
->mouse_face_beg_row
18911 && hpos
>= dpyinfo
->mouse_face_beg_col
))
18912 && (vpos
< dpyinfo
->mouse_face_end_row
18913 || (vpos
== dpyinfo
->mouse_face_end_row
18914 && hpos
< dpyinfo
->mouse_face_end_col
))
18915 /* Don't redraw the cursor's spot in mouse face if it is at the
18916 end of a line (on a newline). The cursor appears there, but
18917 mouse highlighting does not. */
18918 && cursor_row
->used
[TEXT_AREA
] > hpos
)
18919 mouse_face_here_p
= 1;
18921 /* Maybe clear the display under the cursor. */
18922 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
18925 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
18927 cursor_glyph
= get_phys_cursor_glyph (w
);
18928 if (cursor_glyph
== NULL
)
18929 goto mark_cursor_off
;
18931 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
18932 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
18934 rif
->clear_frame_area (f
, x
, y
,
18935 cursor_glyph
->pixel_width
, cursor_row
->visible_height
);
18938 /* Erase the cursor by redrawing the character underneath it. */
18939 if (mouse_face_here_p
)
18940 hl
= DRAW_MOUSE_FACE
;
18942 hl
= DRAW_NORMAL_TEXT
;
18943 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
18946 w
->phys_cursor_on_p
= 0;
18947 w
->phys_cursor_type
= NO_CURSOR
;
18952 Display or clear cursor of window W. If ON is zero, clear the
18953 cursor. If it is non-zero, display the cursor. If ON is nonzero,
18954 where to put the cursor is specified by HPOS, VPOS, X and Y. */
18957 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
18959 int on
, hpos
, vpos
, x
, y
;
18961 struct frame
*f
= XFRAME (w
->frame
);
18962 int new_cursor_type
;
18963 int new_cursor_width
;
18965 struct glyph_matrix
*current_glyphs
;
18966 struct glyph_row
*glyph_row
;
18967 struct glyph
*glyph
;
18969 /* This is pointless on invisible frames, and dangerous on garbaged
18970 windows and frames; in the latter case, the frame or window may
18971 be in the midst of changing its size, and x and y may be off the
18973 if (! FRAME_VISIBLE_P (f
)
18974 || FRAME_GARBAGED_P (f
)
18975 || vpos
>= w
->current_matrix
->nrows
18976 || hpos
>= w
->current_matrix
->matrix_w
)
18979 /* If cursor is off and we want it off, return quickly. */
18980 if (!on
&& !w
->phys_cursor_on_p
)
18983 current_glyphs
= w
->current_matrix
;
18984 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
18985 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
18987 /* If cursor row is not enabled, we don't really know where to
18988 display the cursor. */
18989 if (!glyph_row
->enabled_p
)
18991 w
->phys_cursor_on_p
= 0;
18995 xassert (interrupt_input_blocked
);
18997 /* Set new_cursor_type to the cursor we want to be displayed. */
18998 new_cursor_type
= get_window_cursor_type (w
, &new_cursor_width
, &active_cursor
);
19000 /* If cursor is currently being shown and we don't want it to be or
19001 it is in the wrong place, or the cursor type is not what we want,
19003 if (w
->phys_cursor_on_p
19005 || w
->phys_cursor
.x
!= x
19006 || w
->phys_cursor
.y
!= y
19007 || new_cursor_type
!= w
->phys_cursor_type
19008 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
19009 && new_cursor_width
!= w
->phys_cursor_width
)))
19010 erase_phys_cursor (w
);
19012 /* Don't check phys_cursor_on_p here because that flag is only set
19013 to zero in some cases where we know that the cursor has been
19014 completely erased, to avoid the extra work of erasing the cursor
19015 twice. In other words, phys_cursor_on_p can be 1 and the cursor
19016 still not be visible, or it has only been partly erased. */
19019 w
->phys_cursor_ascent
= glyph_row
->ascent
;
19020 w
->phys_cursor_height
= glyph_row
->height
;
19022 /* Set phys_cursor_.* before x_draw_.* is called because some
19023 of them may need the information. */
19024 w
->phys_cursor
.x
= x
;
19025 w
->phys_cursor
.y
= glyph_row
->y
;
19026 w
->phys_cursor
.hpos
= hpos
;
19027 w
->phys_cursor
.vpos
= vpos
;
19030 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
19031 new_cursor_type
, new_cursor_width
,
19032 on
, active_cursor
);
19036 /* Switch the display of W's cursor on or off, according to the value
19040 update_window_cursor (w
, on
)
19044 /* Don't update cursor in windows whose frame is in the process
19045 of being deleted. */
19046 if (w
->current_matrix
)
19049 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
19050 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
19056 /* Call update_window_cursor with parameter ON_P on all leaf windows
19057 in the window tree rooted at W. */
19060 update_cursor_in_window_tree (w
, on_p
)
19066 if (!NILP (w
->hchild
))
19067 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
19068 else if (!NILP (w
->vchild
))
19069 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
19071 update_window_cursor (w
, on_p
);
19073 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
19079 Display the cursor on window W, or clear it, according to ON_P.
19080 Don't change the cursor's position. */
19083 x_update_cursor (f
, on_p
)
19087 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
19092 Clear the cursor of window W to background color, and mark the
19093 cursor as not shown. This is used when the text where the cursor
19094 is is about to be rewritten. */
19100 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
19101 update_window_cursor (w
, 0);
19106 Display the active region described by mouse_face_* according to DRAW. */
19109 show_mouse_face (dpyinfo
, draw
)
19110 Display_Info
*dpyinfo
;
19111 enum draw_glyphs_face draw
;
19113 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
19114 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19116 if (/* If window is in the process of being destroyed, don't bother
19118 w
->current_matrix
!= NULL
19119 /* Don't update mouse highlight if hidden */
19120 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
19121 /* Recognize when we are called to operate on rows that don't exist
19122 anymore. This can happen when a window is split. */
19123 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
19125 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
19126 struct glyph_row
*row
, *first
, *last
;
19128 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
19129 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
19131 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
19133 int start_hpos
, end_hpos
, start_x
;
19135 /* For all but the first row, the highlight starts at column 0. */
19138 start_hpos
= dpyinfo
->mouse_face_beg_col
;
19139 start_x
= dpyinfo
->mouse_face_beg_x
;
19148 end_hpos
= dpyinfo
->mouse_face_end_col
;
19150 end_hpos
= row
->used
[TEXT_AREA
];
19152 if (end_hpos
> start_hpos
)
19154 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
19155 start_hpos
, end_hpos
,
19159 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
19163 /* When we've written over the cursor, arrange for it to
19164 be displayed again. */
19165 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
19168 display_and_set_cursor (w
, 1,
19169 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
19170 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
19175 /* Change the mouse cursor. */
19176 if (draw
== DRAW_NORMAL_TEXT
)
19177 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
19178 else if (draw
== DRAW_MOUSE_FACE
)
19179 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
19181 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
19185 Clear out the mouse-highlighted active region.
19186 Redraw it un-highlighted first. Value is non-zero if mouse
19187 face was actually drawn unhighlighted. */
19190 clear_mouse_face (dpyinfo
)
19191 Display_Info
*dpyinfo
;
19195 if (!NILP (dpyinfo
->mouse_face_window
))
19197 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
19201 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
19202 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
19203 dpyinfo
->mouse_face_window
= Qnil
;
19204 dpyinfo
->mouse_face_overlay
= Qnil
;
19210 Non-zero if physical cursor of window W is within mouse face. */
19213 cursor_in_mouse_face_p (w
)
19216 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
19217 int in_mouse_face
= 0;
19219 if (WINDOWP (dpyinfo
->mouse_face_window
)
19220 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
19222 int hpos
= w
->phys_cursor
.hpos
;
19223 int vpos
= w
->phys_cursor
.vpos
;
19225 if (vpos
>= dpyinfo
->mouse_face_beg_row
19226 && vpos
<= dpyinfo
->mouse_face_end_row
19227 && (vpos
> dpyinfo
->mouse_face_beg_row
19228 || hpos
>= dpyinfo
->mouse_face_beg_col
)
19229 && (vpos
< dpyinfo
->mouse_face_end_row
19230 || hpos
< dpyinfo
->mouse_face_end_col
19231 || dpyinfo
->mouse_face_past_end
))
19235 return in_mouse_face
;
19241 /* Find the glyph matrix position of buffer position CHARPOS in window
19242 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
19243 current glyphs must be up to date. If CHARPOS is above window
19244 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
19245 of last line in W. In the row containing CHARPOS, stop before glyphs
19246 having STOP as object. */
19248 #if 0 /* This is a version of fast_find_position that's more correct
19249 in the presence of hscrolling, for example. I didn't install
19250 it right away because the problem fixed is minor, it failed
19251 in 20.x as well, and I think it's too risky to install
19252 so near the release of 21.1. 2001-09-25 gerd. */
19255 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
19258 int *hpos
, *vpos
, *x
, *y
;
19261 struct glyph_row
*row
, *first
;
19262 struct glyph
*glyph
, *end
;
19263 int i
, past_end
= 0;
19265 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19266 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
19269 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
19271 *x
= *y
= *hpos
= *vpos
= 0;
19276 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
19283 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
19285 glyph
= row
->glyphs
[TEXT_AREA
];
19286 end
= glyph
+ row
->used
[TEXT_AREA
];
19288 /* Skip over glyphs not having an object at the start of the row.
19289 These are special glyphs like truncation marks on terminal
19291 if (row
->displays_text_p
)
19293 && INTEGERP (glyph
->object
)
19294 && !EQ (stop
, glyph
->object
)
19295 && glyph
->charpos
< 0)
19297 *x
+= glyph
->pixel_width
;
19302 && !INTEGERP (glyph
->object
)
19303 && !EQ (stop
, glyph
->object
)
19304 && (!BUFFERP (glyph
->object
)
19305 || glyph
->charpos
< charpos
))
19307 *x
+= glyph
->pixel_width
;
19311 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
19318 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
19321 int *hpos
, *vpos
, *x
, *y
;
19326 int maybe_next_line_p
= 0;
19327 int line_start_position
;
19328 int yb
= window_text_bottom_y (w
);
19329 struct glyph_row
*row
, *best_row
;
19330 int row_vpos
, best_row_vpos
;
19333 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19334 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
19336 while (row
->y
< yb
)
19338 if (row
->used
[TEXT_AREA
])
19339 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
19341 line_start_position
= 0;
19343 if (line_start_position
> pos
)
19345 /* If the position sought is the end of the buffer,
19346 don't include the blank lines at the bottom of the window. */
19347 else if (line_start_position
== pos
19348 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
19350 maybe_next_line_p
= 1;
19353 else if (line_start_position
> 0)
19356 best_row_vpos
= row_vpos
;
19359 if (row
->y
+ row
->height
>= yb
)
19366 /* Find the right column within BEST_ROW. */
19368 current_x
= best_row
->x
;
19369 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
19371 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
19372 int charpos
= glyph
->charpos
;
19374 if (BUFFERP (glyph
->object
))
19376 if (charpos
== pos
)
19379 *vpos
= best_row_vpos
;
19384 else if (charpos
> pos
)
19387 else if (EQ (glyph
->object
, stop
))
19392 current_x
+= glyph
->pixel_width
;
19395 /* If we're looking for the end of the buffer,
19396 and we didn't find it in the line we scanned,
19397 use the start of the following line. */
19398 if (maybe_next_line_p
)
19403 current_x
= best_row
->x
;
19406 *vpos
= best_row_vpos
;
19407 *hpos
= lastcol
+ 1;
19416 /* Find the position of the glyph for position POS in OBJECT in
19417 window W's current matrix, and return in *X, *Y the pixel
19418 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
19420 RIGHT_P non-zero means return the position of the right edge of the
19421 glyph, RIGHT_P zero means return the left edge position.
19423 If no glyph for POS exists in the matrix, return the position of
19424 the glyph with the next smaller position that is in the matrix, if
19425 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
19426 exists in the matrix, return the position of the glyph with the
19427 next larger position in OBJECT.
19429 Value is non-zero if a glyph was found. */
19432 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
19435 Lisp_Object object
;
19436 int *hpos
, *vpos
, *x
, *y
;
19439 int yb
= window_text_bottom_y (w
);
19440 struct glyph_row
*r
;
19441 struct glyph
*best_glyph
= NULL
;
19442 struct glyph_row
*best_row
= NULL
;
19445 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19446 r
->enabled_p
&& r
->y
< yb
;
19449 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
19450 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
19453 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
19454 if (EQ (g
->object
, object
))
19456 if (g
->charpos
== pos
)
19463 else if (best_glyph
== NULL
19464 || ((abs (g
->charpos
- pos
)
19465 < abs (best_glyph
->charpos
- pos
))
19468 : g
->charpos
> pos
)))
19482 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
19486 *x
+= best_glyph
->pixel_width
;
19491 *vpos
= best_row
- w
->current_matrix
->rows
;
19494 return best_glyph
!= NULL
;
19498 /* Take proper action when mouse has moved to the mode or header line
19499 or marginal area AREA of window W, x-position X and y-position Y.
19500 X is relative to the start of the text display area of W, so the
19501 width of bitmap areas and scroll bars must be subtracted to get a
19502 position relative to the start of the mode line. */
19505 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
19508 enum window_part area
;
19510 struct frame
*f
= XFRAME (w
->frame
);
19511 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
19512 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
19514 Lisp_Object string
, help
, map
, pos
;
19516 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
19517 string
= mode_line_string (w
, x
, y
, area
, &charpos
);
19519 string
= marginal_area_string (w
, x
, y
, area
, &charpos
);
19521 if (STRINGP (string
))
19523 pos
= make_number (charpos
);
19525 /* If we're on a string with `help-echo' text property, arrange
19526 for the help to be displayed. This is done by setting the
19527 global variable help_echo_string to the help string. */
19528 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
19531 help_echo_string
= help
;
19532 XSETWINDOW (help_echo_window
, w
);
19533 help_echo_object
= string
;
19534 help_echo_pos
= charpos
;
19537 /* Change the mouse pointer according to what is under X/Y. */
19538 map
= Fget_text_property (pos
, Qlocal_map
, string
);
19539 if (!KEYMAPP (map
))
19540 map
= Fget_text_property (pos
, Qkeymap
, string
);
19542 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
19545 rif
->define_frame_cursor (f
, cursor
);
19550 Take proper action when the mouse has moved to position X, Y on
19551 frame F as regards highlighting characters that have mouse-face
19552 properties. Also de-highlighting chars where the mouse was before.
19553 X and Y can be negative or out of range. */
19556 note_mouse_highlight (f
, x
, y
)
19560 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
19561 enum window_part part
;
19562 Lisp_Object window
;
19564 Cursor cursor
= No_Cursor
;
19567 /* When a menu is active, don't highlight because this looks odd. */
19568 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
19569 if (popup_activated ())
19573 if (NILP (Vmouse_highlight
)
19574 || !f
->glyphs_initialized_p
)
19577 dpyinfo
->mouse_face_mouse_x
= x
;
19578 dpyinfo
->mouse_face_mouse_y
= y
;
19579 dpyinfo
->mouse_face_mouse_frame
= f
;
19581 if (dpyinfo
->mouse_face_defer
)
19584 if (gc_in_progress
)
19586 dpyinfo
->mouse_face_deferred_gc
= 1;
19590 /* Which window is that in? */
19591 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
19593 /* If we were displaying active text in another window, clear that. */
19594 if (! EQ (window
, dpyinfo
->mouse_face_window
))
19595 clear_mouse_face (dpyinfo
);
19597 /* Not on a window -> return. */
19598 if (!WINDOWP (window
))
19601 /* Reset help_echo_string. It will get recomputed below. */
19602 /* ++KFS: X version didn't do this, but it looks harmless. */
19603 help_echo_string
= Qnil
;
19605 /* Convert to window-relative pixel coordinates. */
19606 w
= XWINDOW (window
);
19607 frame_to_window_pixel_xy (w
, &x
, &y
);
19609 /* Handle tool-bar window differently since it doesn't display a
19611 if (EQ (window
, f
->tool_bar_window
))
19613 note_tool_bar_highlight (f
, x
, y
);
19617 /* Mouse is on the mode, header line or margin? */
19618 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
19619 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
19621 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
19625 if (part
== ON_VERTICAL_BORDER
)
19626 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
19628 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
19630 /* Are we in a window whose display is up to date?
19631 And verify the buffer's text has not changed. */
19632 b
= XBUFFER (w
->buffer
);
19633 if (part
== ON_TEXT
19634 && EQ (w
->window_end_valid
, w
->buffer
)
19635 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
19636 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
19638 int hpos
, vpos
, pos
, i
, area
;
19639 struct glyph
*glyph
;
19640 Lisp_Object object
;
19641 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
19642 Lisp_Object
*overlay_vec
= NULL
;
19643 int len
, noverlays
;
19644 struct buffer
*obuf
;
19645 int obegv
, ozv
, same_region
;
19647 /* Find the glyph under X/Y. */
19648 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
19650 /* Clear mouse face if X/Y not over text. */
19652 || area
!= TEXT_AREA
19653 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
19655 #if defined (HAVE_NTGUI)
19656 /* ++KFS: Why is this necessary on W32 ? */
19657 clear_mouse_face (dpyinfo
);
19658 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
19660 if (clear_mouse_face (dpyinfo
))
19661 cursor
= No_Cursor
;
19666 pos
= glyph
->charpos
;
19667 object
= glyph
->object
;
19668 if (!STRINGP (object
) && !BUFFERP (object
))
19671 /* If we get an out-of-range value, return now; avoid an error. */
19672 if (BUFFERP (object
) && pos
> BUF_Z (b
))
19675 /* Make the window's buffer temporarily current for
19676 overlays_at and compute_char_face. */
19677 obuf
= current_buffer
;
19678 current_buffer
= b
;
19684 /* Is this char mouse-active or does it have help-echo? */
19685 position
= make_number (pos
);
19687 if (BUFFERP (object
))
19689 /* Put all the overlays we want in a vector in overlay_vec.
19690 Store the length in len. If there are more than 10, make
19691 enough space for all, and try again. */
19693 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
19694 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
19695 if (noverlays
> len
)
19698 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
19699 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
19702 /* Sort overlays into increasing priority order. */
19703 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
19708 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
19709 && vpos
>= dpyinfo
->mouse_face_beg_row
19710 && vpos
<= dpyinfo
->mouse_face_end_row
19711 && (vpos
> dpyinfo
->mouse_face_beg_row
19712 || hpos
>= dpyinfo
->mouse_face_beg_col
)
19713 && (vpos
< dpyinfo
->mouse_face_end_row
19714 || hpos
< dpyinfo
->mouse_face_end_col
19715 || dpyinfo
->mouse_face_past_end
));
19718 cursor
= No_Cursor
;
19720 /* Check mouse-face highlighting. */
19722 /* If there exists an overlay with mouse-face overlapping
19723 the one we are currently highlighting, we have to
19724 check if we enter the overlapping overlay, and then
19725 highlight only that. */
19726 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
19727 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
19729 /* Find the highest priority overlay that has a mouse-face
19732 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
19734 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
19735 if (!NILP (mouse_face
))
19736 overlay
= overlay_vec
[i
];
19739 /* If we're actually highlighting the same overlay as
19740 before, there's no need to do that again. */
19741 if (!NILP (overlay
)
19742 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
19743 goto check_help_echo
;
19745 dpyinfo
->mouse_face_overlay
= overlay
;
19747 /* Clear the display of the old active region, if any. */
19748 if (clear_mouse_face (dpyinfo
))
19749 cursor
= No_Cursor
;
19751 /* If no overlay applies, get a text property. */
19752 if (NILP (overlay
))
19753 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
19755 /* Handle the overlay case. */
19756 if (!NILP (overlay
))
19758 /* Find the range of text around this char that
19759 should be active. */
19760 Lisp_Object before
, after
;
19763 before
= Foverlay_start (overlay
);
19764 after
= Foverlay_end (overlay
);
19765 /* Record this as the current active region. */
19766 fast_find_position (w
, XFASTINT (before
),
19767 &dpyinfo
->mouse_face_beg_col
,
19768 &dpyinfo
->mouse_face_beg_row
,
19769 &dpyinfo
->mouse_face_beg_x
,
19770 &dpyinfo
->mouse_face_beg_y
, Qnil
);
19772 dpyinfo
->mouse_face_past_end
19773 = !fast_find_position (w
, XFASTINT (after
),
19774 &dpyinfo
->mouse_face_end_col
,
19775 &dpyinfo
->mouse_face_end_row
,
19776 &dpyinfo
->mouse_face_end_x
,
19777 &dpyinfo
->mouse_face_end_y
, Qnil
);
19778 dpyinfo
->mouse_face_window
= window
;
19780 dpyinfo
->mouse_face_face_id
19781 = face_at_buffer_position (w
, pos
, 0, 0,
19783 !dpyinfo
->mouse_face_hidden
);
19785 /* Display it as active. */
19786 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
19787 cursor
= No_Cursor
;
19789 /* Handle the text property case. */
19790 else if (!NILP (mouse_face
) && BUFFERP (object
))
19792 /* Find the range of text around this char that
19793 should be active. */
19794 Lisp_Object before
, after
, beginning
, end
;
19797 beginning
= Fmarker_position (w
->start
);
19798 end
= make_number (BUF_Z (XBUFFER (object
))
19799 - XFASTINT (w
->window_end_pos
));
19801 = Fprevious_single_property_change (make_number (pos
+ 1),
19803 object
, beginning
);
19805 = Fnext_single_property_change (position
, Qmouse_face
,
19808 /* Record this as the current active region. */
19809 fast_find_position (w
, XFASTINT (before
),
19810 &dpyinfo
->mouse_face_beg_col
,
19811 &dpyinfo
->mouse_face_beg_row
,
19812 &dpyinfo
->mouse_face_beg_x
,
19813 &dpyinfo
->mouse_face_beg_y
, Qnil
);
19814 dpyinfo
->mouse_face_past_end
19815 = !fast_find_position (w
, XFASTINT (after
),
19816 &dpyinfo
->mouse_face_end_col
,
19817 &dpyinfo
->mouse_face_end_row
,
19818 &dpyinfo
->mouse_face_end_x
,
19819 &dpyinfo
->mouse_face_end_y
, Qnil
);
19820 dpyinfo
->mouse_face_window
= window
;
19822 if (BUFFERP (object
))
19823 dpyinfo
->mouse_face_face_id
19824 = face_at_buffer_position (w
, pos
, 0, 0,
19826 !dpyinfo
->mouse_face_hidden
);
19828 /* Display it as active. */
19829 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
19830 cursor
= No_Cursor
;
19832 else if (!NILP (mouse_face
) && STRINGP (object
))
19837 b
= Fprevious_single_property_change (make_number (pos
+ 1),
19840 e
= Fnext_single_property_change (position
, Qmouse_face
,
19843 b
= make_number (0);
19845 e
= make_number (SCHARS (object
) - 1);
19846 fast_find_string_pos (w
, XINT (b
), object
,
19847 &dpyinfo
->mouse_face_beg_col
,
19848 &dpyinfo
->mouse_face_beg_row
,
19849 &dpyinfo
->mouse_face_beg_x
,
19850 &dpyinfo
->mouse_face_beg_y
, 0);
19851 fast_find_string_pos (w
, XINT (e
), object
,
19852 &dpyinfo
->mouse_face_end_col
,
19853 &dpyinfo
->mouse_face_end_row
,
19854 &dpyinfo
->mouse_face_end_x
,
19855 &dpyinfo
->mouse_face_end_y
, 1);
19856 dpyinfo
->mouse_face_past_end
= 0;
19857 dpyinfo
->mouse_face_window
= window
;
19858 dpyinfo
->mouse_face_face_id
19859 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
19860 glyph
->face_id
, 1);
19861 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
19862 cursor
= No_Cursor
;
19864 else if (STRINGP (object
) && NILP (mouse_face
))
19866 /* A string which doesn't have mouse-face, but
19867 the text ``under'' it might have. */
19868 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
19869 int start
= MATRIX_ROW_START_CHARPOS (r
);
19871 pos
= string_buffer_position (w
, object
, start
);
19873 mouse_face
= get_char_property_and_overlay (make_number (pos
),
19877 if (!NILP (mouse_face
) && !NILP (overlay
))
19879 Lisp_Object before
= Foverlay_start (overlay
);
19880 Lisp_Object after
= Foverlay_end (overlay
);
19883 /* Note that we might not be able to find position
19884 BEFORE in the glyph matrix if the overlay is
19885 entirely covered by a `display' property. In
19886 this case, we overshoot. So let's stop in
19887 the glyph matrix before glyphs for OBJECT. */
19888 fast_find_position (w
, XFASTINT (before
),
19889 &dpyinfo
->mouse_face_beg_col
,
19890 &dpyinfo
->mouse_face_beg_row
,
19891 &dpyinfo
->mouse_face_beg_x
,
19892 &dpyinfo
->mouse_face_beg_y
,
19895 dpyinfo
->mouse_face_past_end
19896 = !fast_find_position (w
, XFASTINT (after
),
19897 &dpyinfo
->mouse_face_end_col
,
19898 &dpyinfo
->mouse_face_end_row
,
19899 &dpyinfo
->mouse_face_end_x
,
19900 &dpyinfo
->mouse_face_end_y
,
19902 dpyinfo
->mouse_face_window
= window
;
19903 dpyinfo
->mouse_face_face_id
19904 = face_at_buffer_position (w
, pos
, 0, 0,
19906 !dpyinfo
->mouse_face_hidden
);
19908 /* Display it as active. */
19909 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
19910 cursor
= No_Cursor
;
19917 /* Look for a `help-echo' property. */
19919 Lisp_Object help
, overlay
;
19921 /* Check overlays first. */
19922 help
= overlay
= Qnil
;
19923 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
19925 overlay
= overlay_vec
[i
];
19926 help
= Foverlay_get (overlay
, Qhelp_echo
);
19931 help_echo_string
= help
;
19932 help_echo_window
= window
;
19933 help_echo_object
= overlay
;
19934 help_echo_pos
= pos
;
19938 Lisp_Object object
= glyph
->object
;
19939 int charpos
= glyph
->charpos
;
19941 /* Try text properties. */
19942 if (STRINGP (object
)
19944 && charpos
< SCHARS (object
))
19946 help
= Fget_text_property (make_number (charpos
),
19947 Qhelp_echo
, object
);
19950 /* If the string itself doesn't specify a help-echo,
19951 see if the buffer text ``under'' it does. */
19952 struct glyph_row
*r
19953 = MATRIX_ROW (w
->current_matrix
, vpos
);
19954 int start
= MATRIX_ROW_START_CHARPOS (r
);
19955 int pos
= string_buffer_position (w
, object
, start
);
19958 help
= Fget_char_property (make_number (pos
),
19959 Qhelp_echo
, w
->buffer
);
19963 object
= w
->buffer
;
19968 else if (BUFFERP (object
)
19971 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
19976 help_echo_string
= help
;
19977 help_echo_window
= window
;
19978 help_echo_object
= object
;
19979 help_echo_pos
= charpos
;
19986 current_buffer
= obuf
;
19991 #ifndef HAVE_CARBON
19992 if (cursor
!= No_Cursor
)
19994 if (bcmp (&cursor
, &No_Cursor
, sizeof (Cursor
)))
19996 rif
->define_frame_cursor (f
, cursor
);
20001 Clear any mouse-face on window W. This function is part of the
20002 redisplay interface, and is called from try_window_id and similar
20003 functions to ensure the mouse-highlight is off. */
20006 x_clear_window_mouse_face (w
)
20009 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20010 Lisp_Object window
;
20013 XSETWINDOW (window
, w
);
20014 if (EQ (window
, dpyinfo
->mouse_face_window
))
20015 clear_mouse_face (dpyinfo
);
20021 Just discard the mouse face information for frame F, if any.
20022 This is used when the size of F is changed. */
20025 cancel_mouse_face (f
)
20028 Lisp_Object window
;
20029 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20031 window
= dpyinfo
->mouse_face_window
;
20032 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
20034 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20035 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20036 dpyinfo
->mouse_face_window
= Qnil
;
20041 #endif /* HAVE_WINDOW_SYSTEM */
20044 /***********************************************************************
20046 ***********************************************************************/
20048 #ifdef HAVE_WINDOW_SYSTEM
20050 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
20051 which intersects rectangle R. R is in window-relative coordinates. */
20054 expose_area (w
, row
, r
, area
)
20056 struct glyph_row
*row
;
20058 enum glyph_row_area area
;
20060 struct glyph
*first
= row
->glyphs
[area
];
20061 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
20062 struct glyph
*last
;
20063 int first_x
, start_x
, x
;
20065 if (area
== TEXT_AREA
&& row
->fill_line_p
)
20066 /* If row extends face to end of line write the whole line. */
20067 draw_glyphs (w
, 0, row
, area
,
20068 0, row
->used
[area
],
20069 DRAW_NORMAL_TEXT
, 0);
20072 /* Set START_X to the window-relative start position for drawing glyphs of
20073 AREA. The first glyph of the text area can be partially visible.
20074 The first glyphs of other areas cannot. */
20075 if (area
== LEFT_MARGIN_AREA
)
20077 else if (area
== TEXT_AREA
)
20078 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
20080 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
20081 + window_box_width (w
, TEXT_AREA
));
20084 /* Find the first glyph that must be redrawn. */
20086 && x
+ first
->pixel_width
< r
->x
)
20088 x
+= first
->pixel_width
;
20092 /* Find the last one. */
20096 && x
< r
->x
+ r
->width
)
20098 x
+= last
->pixel_width
;
20104 draw_glyphs (w
, first_x
- start_x
, row
, area
,
20105 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
20106 DRAW_NORMAL_TEXT
, 0);
20111 /* Redraw the parts of the glyph row ROW on window W intersecting
20112 rectangle R. R is in window-relative coordinates. Value is
20113 non-zero if mouse-face was overwritten. */
20116 expose_line (w
, row
, r
)
20118 struct glyph_row
*row
;
20121 xassert (row
->enabled_p
);
20123 if (row
->mode_line_p
|| w
->pseudo_window_p
)
20124 draw_glyphs (w
, 0, row
, TEXT_AREA
,
20125 0, row
->used
[TEXT_AREA
],
20126 DRAW_NORMAL_TEXT
, 0);
20129 if (row
->used
[LEFT_MARGIN_AREA
])
20130 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
20131 if (row
->used
[TEXT_AREA
])
20132 expose_area (w
, row
, r
, TEXT_AREA
);
20133 if (row
->used
[RIGHT_MARGIN_AREA
])
20134 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
20135 draw_row_fringe_bitmaps (w
, row
);
20138 return row
->mouse_face_p
;
20142 /* Redraw those parts of glyphs rows during expose event handling that
20143 overlap other rows. Redrawing of an exposed line writes over parts
20144 of lines overlapping that exposed line; this function fixes that.
20146 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
20147 row in W's current matrix that is exposed and overlaps other rows.
20148 LAST_OVERLAPPING_ROW is the last such row. */
20151 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
20153 struct glyph_row
*first_overlapping_row
;
20154 struct glyph_row
*last_overlapping_row
;
20156 struct glyph_row
*row
;
20158 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
20159 if (row
->overlapping_p
)
20161 xassert (row
->enabled_p
&& !row
->mode_line_p
);
20163 if (row
->used
[LEFT_MARGIN_AREA
])
20164 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
20166 if (row
->used
[TEXT_AREA
])
20167 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
20169 if (row
->used
[RIGHT_MARGIN_AREA
])
20170 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
20175 /* Return non-zero if W's cursor intersects rectangle R. */
20178 phys_cursor_in_rect_p (w
, r
)
20182 XRectangle cr
, result
;
20183 struct glyph
*cursor_glyph
;
20185 cursor_glyph
= get_phys_cursor_glyph (w
);
20188 cr
.x
= w
->phys_cursor
.x
;
20189 cr
.y
= w
->phys_cursor
.y
;
20190 cr
.width
= cursor_glyph
->pixel_width
;
20191 cr
.height
= w
->phys_cursor_height
;
20192 /* ++KFS: W32 version used W32-specific IntersectRect here, but
20193 I assume the effect is the same -- and this is portable. */
20194 return x_intersect_rectangles (&cr
, r
, &result
);
20202 Draw a vertical window border to the right of window W if W doesn't
20203 have vertical scroll bars. */
20206 x_draw_vertical_border (w
)
20209 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20211 /* Redraw borders between horizontally adjacent windows. Don't
20212 do it for frames with vertical scroll bars because either the
20213 right scroll bar of a window, or the left scroll bar of its
20214 neighbor will suffice as a border. */
20215 if (!WINDOW_RIGHTMOST_P (w
)
20216 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
20218 int x0
, x1
, y0
, y1
;
20220 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
20221 x1
+= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
20224 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
20229 /* Redraw the part of window W intersection rectangle FR. Pixel
20230 coordinates in FR are frame-relative. Call this function with
20231 input blocked. Value is non-zero if the exposure overwrites
20235 expose_window (w
, fr
)
20239 struct frame
*f
= XFRAME (w
->frame
);
20241 int mouse_face_overwritten_p
= 0;
20243 /* If window is not yet fully initialized, do nothing. This can
20244 happen when toolkit scroll bars are used and a window is split.
20245 Reconfiguring the scroll bar will generate an expose for a newly
20247 if (w
->current_matrix
== NULL
)
20250 /* When we're currently updating the window, display and current
20251 matrix usually don't agree. Arrange for a thorough display
20253 if (w
== updated_window
)
20255 SET_FRAME_GARBAGED (f
);
20259 /* Frame-relative pixel rectangle of W. */
20260 wr
.x
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
20261 wr
.y
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
20262 wr
.width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
20263 wr
.height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
20265 if (x_intersect_rectangles (fr
, &wr
, &r
))
20267 int yb
= window_text_bottom_y (w
);
20268 struct glyph_row
*row
;
20269 int cursor_cleared_p
;
20270 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
20272 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
20273 r
.x
, r
.y
, r
.width
, r
.height
));
20275 /* Convert to window coordinates. */
20276 r
.x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.x
);
20277 r
.y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.y
);
20279 /* Turn off the cursor. */
20280 if (!w
->pseudo_window_p
20281 && phys_cursor_in_rect_p (w
, &r
))
20283 x_clear_cursor (w
);
20284 cursor_cleared_p
= 1;
20287 cursor_cleared_p
= 0;
20289 /* Update lines intersecting rectangle R. */
20290 first_overlapping_row
= last_overlapping_row
= NULL
;
20291 for (row
= w
->current_matrix
->rows
;
20296 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
20298 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
20299 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
20300 || (r
.y
>= y0
&& r
.y
< y1
)
20301 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
20303 if (row
->overlapping_p
)
20305 if (first_overlapping_row
== NULL
)
20306 first_overlapping_row
= row
;
20307 last_overlapping_row
= row
;
20310 if (expose_line (w
, row
, &r
))
20311 mouse_face_overwritten_p
= 1;
20318 /* Display the mode line if there is one. */
20319 if (WINDOW_WANTS_MODELINE_P (w
)
20320 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
20322 && row
->y
< r
.y
+ r
.height
)
20324 if (expose_line (w
, row
, &r
))
20325 mouse_face_overwritten_p
= 1;
20328 if (!w
->pseudo_window_p
)
20330 /* Fix the display of overlapping rows. */
20331 if (first_overlapping_row
)
20332 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
20334 /* Draw border between windows. */
20335 x_draw_vertical_border (w
);
20337 /* Turn the cursor on again. */
20338 if (cursor_cleared_p
)
20339 update_window_cursor (w
, 1);
20344 /* Display scroll bar for this window. */
20345 if (!NILP (w
->vertical_scroll_bar
))
20348 If this doesn't work here (maybe some header files are missing),
20349 make a function in macterm.c and call it to do the job! */
20351 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w
->vertical_scroll_bar
));
20357 return mouse_face_overwritten_p
;
20362 /* Redraw (parts) of all windows in the window tree rooted at W that
20363 intersect R. R contains frame pixel coordinates. Value is
20364 non-zero if the exposure overwrites mouse-face. */
20367 expose_window_tree (w
, r
)
20371 struct frame
*f
= XFRAME (w
->frame
);
20372 int mouse_face_overwritten_p
= 0;
20374 while (w
&& !FRAME_GARBAGED_P (f
))
20376 if (!NILP (w
->hchild
))
20377 mouse_face_overwritten_p
20378 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
20379 else if (!NILP (w
->vchild
))
20380 mouse_face_overwritten_p
20381 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
20383 mouse_face_overwritten_p
|= expose_window (w
, r
);
20385 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
20388 return mouse_face_overwritten_p
;
20393 Redisplay an exposed area of frame F. X and Y are the upper-left
20394 corner of the exposed rectangle. W and H are width and height of
20395 the exposed area. All are pixel values. W or H zero means redraw
20396 the entire frame. */
20399 expose_frame (f
, x
, y
, w
, h
)
20404 int mouse_face_overwritten_p
= 0;
20406 TRACE ((stderr
, "expose_frame "));
20408 /* No need to redraw if frame will be redrawn soon. */
20409 if (FRAME_GARBAGED_P (f
))
20411 TRACE ((stderr
, " garbaged\n"));
20416 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
20417 or deactivated here, for unknown reasons, activated scroll bars
20418 are shown in deactivated frames in some instances. */
20419 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
20420 activate_scroll_bars (f
);
20422 deactivate_scroll_bars (f
);
20425 /* If basic faces haven't been realized yet, there is no point in
20426 trying to redraw anything. This can happen when we get an expose
20427 event while Emacs is starting, e.g. by moving another window. */
20428 if (FRAME_FACE_CACHE (f
) == NULL
20429 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
20431 TRACE ((stderr
, " no faces\n"));
20435 if (w
== 0 || h
== 0)
20438 r
.width
= CANON_X_UNIT (f
) * f
->width
;
20439 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
20449 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
20450 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
20452 if (WINDOWP (f
->tool_bar_window
))
20453 mouse_face_overwritten_p
20454 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
20456 #ifdef HAVE_X_WINDOWS
20458 #ifndef USE_X_TOOLKIT
20459 if (WINDOWP (f
->menu_bar_window
))
20460 mouse_face_overwritten_p
20461 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
20462 #endif /* not USE_X_TOOLKIT */
20466 /* Some window managers support a focus-follows-mouse style with
20467 delayed raising of frames. Imagine a partially obscured frame,
20468 and moving the mouse into partially obscured mouse-face on that
20469 frame. The visible part of the mouse-face will be highlighted,
20470 then the WM raises the obscured frame. With at least one WM, KDE
20471 2.1, Emacs is not getting any event for the raising of the frame
20472 (even tried with SubstructureRedirectMask), only Expose events.
20473 These expose events will draw text normally, i.e. not
20474 highlighted. Which means we must redo the highlight here.
20475 Subsume it under ``we love X''. --gerd 2001-08-15 */
20476 /* Included in Windows version because Windows most likely does not
20477 do the right thing if any third party tool offers
20478 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
20479 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
20481 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20482 if (f
== dpyinfo
->mouse_face_mouse_frame
)
20484 int x
= dpyinfo
->mouse_face_mouse_x
;
20485 int y
= dpyinfo
->mouse_face_mouse_y
;
20486 clear_mouse_face (dpyinfo
);
20487 note_mouse_highlight (f
, x
, y
);
20494 Determine the intersection of two rectangles R1 and R2. Return
20495 the intersection in *RESULT. Value is non-zero if RESULT is not
20499 x_intersect_rectangles (r1
, r2
, result
)
20500 XRectangle
*r1
, *r2
, *result
;
20502 XRectangle
*left
, *right
;
20503 XRectangle
*upper
, *lower
;
20504 int intersection_p
= 0;
20506 /* Rearrange so that R1 is the left-most rectangle. */
20508 left
= r1
, right
= r2
;
20510 left
= r2
, right
= r1
;
20512 /* X0 of the intersection is right.x0, if this is inside R1,
20513 otherwise there is no intersection. */
20514 if (right
->x
<= left
->x
+ left
->width
)
20516 result
->x
= right
->x
;
20518 /* The right end of the intersection is the minimum of the
20519 the right ends of left and right. */
20520 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
20523 /* Same game for Y. */
20525 upper
= r1
, lower
= r2
;
20527 upper
= r2
, lower
= r1
;
20529 /* The upper end of the intersection is lower.y0, if this is inside
20530 of upper. Otherwise, there is no intersection. */
20531 if (lower
->y
<= upper
->y
+ upper
->height
)
20533 result
->y
= lower
->y
;
20535 /* The lower end of the intersection is the minimum of the lower
20536 ends of upper and lower. */
20537 result
->height
= (min (lower
->y
+ lower
->height
,
20538 upper
->y
+ upper
->height
)
20540 intersection_p
= 1;
20544 return intersection_p
;
20547 #endif /* HAVE_WINDOW_SYSTEM */
20550 /***********************************************************************
20552 ***********************************************************************/
20557 Vwith_echo_area_save_vector
= Qnil
;
20558 staticpro (&Vwith_echo_area_save_vector
);
20560 Vmessage_stack
= Qnil
;
20561 staticpro (&Vmessage_stack
);
20563 Qinhibit_redisplay
= intern ("inhibit-redisplay");
20564 staticpro (&Qinhibit_redisplay
);
20566 message_dolog_marker1
= Fmake_marker ();
20567 staticpro (&message_dolog_marker1
);
20568 message_dolog_marker2
= Fmake_marker ();
20569 staticpro (&message_dolog_marker2
);
20570 message_dolog_marker3
= Fmake_marker ();
20571 staticpro (&message_dolog_marker3
);
20574 defsubr (&Sdump_frame_glyph_matrix
);
20575 defsubr (&Sdump_glyph_matrix
);
20576 defsubr (&Sdump_glyph_row
);
20577 defsubr (&Sdump_tool_bar_row
);
20578 defsubr (&Strace_redisplay
);
20579 defsubr (&Strace_to_stderr
);
20581 #ifdef HAVE_WINDOW_SYSTEM
20582 defsubr (&Stool_bar_lines_needed
);
20584 defsubr (&Sformat_mode_line
);
20586 staticpro (&Qmenu_bar_update_hook
);
20587 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
20589 staticpro (&Qoverriding_terminal_local_map
);
20590 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
20592 staticpro (&Qoverriding_local_map
);
20593 Qoverriding_local_map
= intern ("overriding-local-map");
20595 staticpro (&Qwindow_scroll_functions
);
20596 Qwindow_scroll_functions
= intern ("window-scroll-functions");
20598 staticpro (&Qredisplay_end_trigger_functions
);
20599 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
20601 staticpro (&Qinhibit_point_motion_hooks
);
20602 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
20604 QCdata
= intern (":data");
20605 staticpro (&QCdata
);
20606 Qdisplay
= intern ("display");
20607 staticpro (&Qdisplay
);
20608 Qspace_width
= intern ("space-width");
20609 staticpro (&Qspace_width
);
20610 Qraise
= intern ("raise");
20611 staticpro (&Qraise
);
20612 Qspace
= intern ("space");
20613 staticpro (&Qspace
);
20614 Qmargin
= intern ("margin");
20615 staticpro (&Qmargin
);
20616 Qleft_margin
= intern ("left-margin");
20617 staticpro (&Qleft_margin
);
20618 Qright_margin
= intern ("right-margin");
20619 staticpro (&Qright_margin
);
20620 Qalign_to
= intern ("align-to");
20621 staticpro (&Qalign_to
);
20622 QCalign_to
= intern (":align-to");
20623 staticpro (&QCalign_to
);
20624 Qrelative_width
= intern ("relative-width");
20625 staticpro (&Qrelative_width
);
20626 QCrelative_width
= intern (":relative-width");
20627 staticpro (&QCrelative_width
);
20628 QCrelative_height
= intern (":relative-height");
20629 staticpro (&QCrelative_height
);
20630 QCeval
= intern (":eval");
20631 staticpro (&QCeval
);
20632 QCpropertize
= intern (":propertize");
20633 staticpro (&QCpropertize
);
20634 QCfile
= intern (":file");
20635 staticpro (&QCfile
);
20636 Qfontified
= intern ("fontified");
20637 staticpro (&Qfontified
);
20638 Qfontification_functions
= intern ("fontification-functions");
20639 staticpro (&Qfontification_functions
);
20640 Qtrailing_whitespace
= intern ("trailing-whitespace");
20641 staticpro (&Qtrailing_whitespace
);
20642 Qimage
= intern ("image");
20643 staticpro (&Qimage
);
20644 Qmessage_truncate_lines
= intern ("message-truncate-lines");
20645 staticpro (&Qmessage_truncate_lines
);
20646 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
20647 staticpro (&Qcursor_in_non_selected_windows
);
20648 Qgrow_only
= intern ("grow-only");
20649 staticpro (&Qgrow_only
);
20650 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
20651 staticpro (&Qinhibit_menubar_update
);
20652 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
20653 staticpro (&Qinhibit_eval_during_redisplay
);
20654 Qposition
= intern ("position");
20655 staticpro (&Qposition
);
20656 Qbuffer_position
= intern ("buffer-position");
20657 staticpro (&Qbuffer_position
);
20658 Qobject
= intern ("object");
20659 staticpro (&Qobject
);
20660 Qbar
= intern ("bar");
20662 Qhbar
= intern ("hbar");
20663 staticpro (&Qhbar
);
20664 Qbox
= intern ("box");
20666 Qhollow
= intern ("hollow");
20667 staticpro (&Qhollow
);
20668 Qrisky_local_variable
= intern ("risky-local-variable");
20669 staticpro (&Qrisky_local_variable
);
20670 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
20671 staticpro (&Qinhibit_free_realized_faces
);
20673 list_of_error
= Fcons (intern ("error"), Qnil
);
20674 staticpro (&list_of_error
);
20676 last_arrow_position
= Qnil
;
20677 last_arrow_string
= Qnil
;
20678 staticpro (&last_arrow_position
);
20679 staticpro (&last_arrow_string
);
20681 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
20682 staticpro (&echo_buffer
[0]);
20683 staticpro (&echo_buffer
[1]);
20685 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
20686 staticpro (&echo_area_buffer
[0]);
20687 staticpro (&echo_area_buffer
[1]);
20689 Vmessages_buffer_name
= build_string ("*Messages*");
20690 staticpro (&Vmessages_buffer_name
);
20692 mode_line_proptrans_alist
= Qnil
;
20693 staticpro (&mode_line_proptrans_alist
);
20695 mode_line_string_list
= Qnil
;
20696 staticpro (&mode_line_string_list
);
20698 help_echo_string
= Qnil
;
20699 staticpro (&help_echo_string
);
20700 help_echo_object
= Qnil
;
20701 staticpro (&help_echo_object
);
20702 help_echo_window
= Qnil
;
20703 staticpro (&help_echo_window
);
20704 previous_help_echo_string
= Qnil
;
20705 staticpro (&previous_help_echo_string
);
20706 help_echo_pos
= -1;
20708 #ifdef HAVE_WINDOW_SYSTEM
20709 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
20710 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
20711 For example, if a block cursor is over a tab, it will be drawn as
20712 wide as that tab on the display. */);
20713 x_stretch_cursor_p
= 0;
20716 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
20717 doc
: /* Non-nil means highlight trailing whitespace.
20718 The face used for trailing whitespace is `trailing-whitespace'. */);
20719 Vshow_trailing_whitespace
= Qnil
;
20721 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
20722 doc
: /* Non-nil means don't actually do any redisplay.
20723 This is used for internal purposes. */);
20724 Vinhibit_redisplay
= Qnil
;
20726 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
20727 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
20728 Vglobal_mode_string
= Qnil
;
20730 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
20731 doc
: /* Marker for where to display an arrow on top of the buffer text.
20732 This must be the beginning of a line in order to work.
20733 See also `overlay-arrow-string'. */);
20734 Voverlay_arrow_position
= Qnil
;
20736 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
20737 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
20738 Voverlay_arrow_string
= Qnil
;
20740 DEFVAR_INT ("scroll-step", &scroll_step
,
20741 doc
: /* *The number of lines to try scrolling a window by when point moves out.
20742 If that fails to bring point back on frame, point is centered instead.
20743 If this is zero, point is always centered after it moves off frame.
20744 If you want scrolling to always be a line at a time, you should set
20745 `scroll-conservatively' to a large value rather than set this to 1. */);
20747 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
20748 doc
: /* *Scroll up to this many lines, to bring point back on screen.
20749 A value of zero means to scroll the text to center point vertically
20750 in the window. */);
20751 scroll_conservatively
= 0;
20753 DEFVAR_INT ("scroll-margin", &scroll_margin
,
20754 doc
: /* *Number of lines of margin at the top and bottom of a window.
20755 Recenter the window whenever point gets within this many lines
20756 of the top or bottom of the window. */);
20760 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
20763 DEFVAR_BOOL ("truncate-partial-width-windows",
20764 &truncate_partial_width_windows
,
20765 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
20766 truncate_partial_width_windows
= 1;
20768 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
20769 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
20770 Any other value means to use the appropriate face, `mode-line',
20771 `header-line', or `menu' respectively. */);
20772 mode_line_inverse_video
= 1;
20774 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
20775 doc
: /* *Maximum buffer size for which line number should be displayed.
20776 If the buffer is bigger than this, the line number does not appear
20777 in the mode line. A value of nil means no limit. */);
20778 Vline_number_display_limit
= Qnil
;
20780 DEFVAR_INT ("line-number-display-limit-width",
20781 &line_number_display_limit_width
,
20782 doc
: /* *Maximum line width (in characters) for line number display.
20783 If the average length of the lines near point is bigger than this, then the
20784 line number may be omitted from the mode line. */);
20785 line_number_display_limit_width
= 200;
20787 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
20788 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
20789 highlight_nonselected_windows
= 0;
20791 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
20792 doc
: /* Non-nil if more than one frame is visible on this display.
20793 Minibuffer-only frames don't count, but iconified frames do.
20794 This variable is not guaranteed to be accurate except while processing
20795 `frame-title-format' and `icon-title-format'. */);
20797 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
20798 doc
: /* Template for displaying the title bar of visible frames.
20799 \(Assuming the window manager supports this feature.)
20800 This variable has the same structure as `mode-line-format' (which see),
20801 and is used only on frames for which no explicit name has been set
20802 \(see `modify-frame-parameters'). */);
20803 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
20804 doc
: /* Template for displaying the title bar of an iconified frame.
20805 \(Assuming the window manager supports this feature.)
20806 This variable has the same structure as `mode-line-format' (which see),
20807 and is used only on frames for which no explicit name has been set
20808 \(see `modify-frame-parameters'). */);
20810 = Vframe_title_format
20811 = Fcons (intern ("multiple-frames"),
20812 Fcons (build_string ("%b"),
20813 Fcons (Fcons (empty_string
,
20814 Fcons (intern ("invocation-name"),
20815 Fcons (build_string ("@"),
20816 Fcons (intern ("system-name"),
20820 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
20821 doc
: /* Maximum number of lines to keep in the message log buffer.
20822 If nil, disable message logging. If t, log messages but don't truncate
20823 the buffer when it becomes large. */);
20824 Vmessage_log_max
= make_number (50);
20826 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
20827 doc
: /* Functions called before redisplay, if window sizes have changed.
20828 The value should be a list of functions that take one argument.
20829 Just before redisplay, for each frame, if any of its windows have changed
20830 size since the last redisplay, or have been split or deleted,
20831 all the functions in the list are called, with the frame as argument. */);
20832 Vwindow_size_change_functions
= Qnil
;
20834 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
20835 doc
: /* List of Functions to call before redisplaying a window with scrolling.
20836 Each function is called with two arguments, the window
20837 and its new display-start position. Note that the value of `window-end'
20838 is not valid when these functions are called. */);
20839 Vwindow_scroll_functions
= Qnil
;
20841 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
20842 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
20843 mouse_autoselect_window
= 0;
20845 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
20846 doc
: /* *Non-nil means automatically resize tool-bars.
20847 This increases a tool-bar's height if not all tool-bar items are visible.
20848 It decreases a tool-bar's height when it would display blank lines
20850 auto_resize_tool_bars_p
= 1;
20852 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
20853 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
20854 auto_raise_tool_bar_buttons_p
= 1;
20856 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
20857 doc
: /* *Margin around tool-bar buttons in pixels.
20858 If an integer, use that for both horizontal and vertical margins.
20859 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
20860 HORZ specifying the horizontal margin, and VERT specifying the
20861 vertical margin. */);
20862 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
20864 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
20865 doc
: /* *Relief thickness of tool-bar buttons. */);
20866 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
20868 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
20869 doc
: /* List of functions to call to fontify regions of text.
20870 Each function is called with one argument POS. Functions must
20871 fontify a region starting at POS in the current buffer, and give
20872 fontified regions the property `fontified'. */);
20873 Vfontification_functions
= Qnil
;
20874 Fmake_variable_buffer_local (Qfontification_functions
);
20876 DEFVAR_BOOL ("unibyte-display-via-language-environment",
20877 &unibyte_display_via_language_environment
,
20878 doc
: /* *Non-nil means display unibyte text according to language environment.
20879 Specifically this means that unibyte non-ASCII characters
20880 are displayed by converting them to the equivalent multibyte characters
20881 according to the current language environment. As a result, they are
20882 displayed according to the current fontset. */);
20883 unibyte_display_via_language_environment
= 0;
20885 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
20886 doc
: /* *Maximum height for resizing mini-windows.
20887 If a float, it specifies a fraction of the mini-window frame's height.
20888 If an integer, it specifies a number of lines. */);
20889 Vmax_mini_window_height
= make_float (0.25);
20891 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
20892 doc
: /* *How to resize mini-windows.
20893 A value of nil means don't automatically resize mini-windows.
20894 A value of t means resize them to fit the text displayed in them.
20895 A value of `grow-only', the default, means let mini-windows grow
20896 only, until their display becomes empty, at which point the windows
20897 go back to their normal size. */);
20898 Vresize_mini_windows
= Qgrow_only
;
20900 DEFVAR_LISP ("cursor-in-non-selected-windows",
20901 &Vcursor_in_non_selected_windows
,
20902 doc
: /* *Cursor type to display in non-selected windows.
20903 t means to use hollow box cursor. See `cursor-type' for other values. */);
20904 Vcursor_in_non_selected_windows
= Qt
;
20906 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
20907 doc
: /* Alist specifying how to blink the cursor off.
20908 Each element has the form (ON-STATE . OFF-STATE). Whenever the
20909 `cursor-type' frame-parameter or variable equals ON-STATE,
20910 comparing using `equal', Emacs uses OFF-STATE to specify
20911 how to blink it off. */);
20912 Vblink_cursor_alist
= Qnil
;
20914 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
20915 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
20916 automatic_hscrolling_p
= 1;
20918 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
20919 doc
: /* *How many columns away from the window edge point is allowed to get
20920 before automatic hscrolling will horizontally scroll the window. */);
20921 hscroll_margin
= 5;
20923 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
20924 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
20925 When point is less than `automatic-hscroll-margin' columns from the window
20926 edge, automatic hscrolling will scroll the window by the amount of columns
20927 determined by this variable. If its value is a positive integer, scroll that
20928 many columns. If it's a positive floating-point number, it specifies the
20929 fraction of the window's width to scroll. If it's nil or zero, point will be
20930 centered horizontally after the scroll. Any other value, including negative
20931 numbers, are treated as if the value were zero.
20933 Automatic hscrolling always moves point outside the scroll margin, so if
20934 point was more than scroll step columns inside the margin, the window will
20935 scroll more than the value given by the scroll step.
20937 Note that the lower bound for automatic hscrolling specified by `scroll-left'
20938 and `scroll-right' overrides this variable's effect. */);
20939 Vhscroll_step
= make_number (0);
20941 DEFVAR_LISP ("image-types", &Vimage_types
,
20942 doc
: /* List of supported image types.
20943 Each element of the list is a symbol for a supported image type. */);
20944 Vimage_types
= Qnil
;
20946 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
20947 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
20948 Bind this around calls to `message' to let it take effect. */);
20949 message_truncate_lines
= 0;
20951 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
20952 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
20953 Can be used to update submenus whose contents should vary. */);
20954 Vmenu_bar_update_hook
= Qnil
;
20956 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
20957 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
20958 inhibit_menubar_update
= 0;
20960 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
20961 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
20962 inhibit_eval_during_redisplay
= 0;
20964 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
20965 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
20966 inhibit_free_realized_faces
= 0;
20969 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
20970 doc
: /* Inhibit try_window_id display optimization. */);
20971 inhibit_try_window_id
= 0;
20973 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
20974 doc
: /* Inhibit try_window_reusing display optimization. */);
20975 inhibit_try_window_reusing
= 0;
20977 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
20978 doc
: /* Inhibit try_cursor_movement display optimization. */);
20979 inhibit_try_cursor_movement
= 0;
20980 #endif /* GLYPH_DEBUG */
20984 /* Initialize this module when Emacs starts. */
20989 Lisp_Object root_window
;
20990 struct window
*mini_w
;
20992 current_header_line_height
= current_mode_line_height
= -1;
20994 CHARPOS (this_line_start_pos
) = 0;
20996 mini_w
= XWINDOW (minibuf_window
);
20997 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
20999 if (!noninteractive
)
21001 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
21004 XWINDOW (root_window
)->top
= make_number (FRAME_TOP_MARGIN (f
));
21005 set_window_height (root_window
,
21006 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
21008 mini_w
->top
= make_number (FRAME_HEIGHT (f
) - 1);
21009 set_window_height (minibuf_window
, 1, 0);
21011 XWINDOW (root_window
)->width
= make_number (FRAME_WIDTH (f
));
21012 mini_w
->width
= make_number (FRAME_WIDTH (f
));
21014 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
21015 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
21016 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
21018 /* The default ellipsis glyphs `...'. */
21019 for (i
= 0; i
< 3; ++i
)
21020 default_invis_vector
[i
] = make_number ('.');
21024 /* Allocate the buffer for frame titles.
21025 Also used for `format-mode-line'. */
21027 frame_title_buf
= (char *) xmalloc (size
);
21028 frame_title_buf_end
= frame_title_buf
+ size
;
21029 frame_title_ptr
= NULL
;
21032 help_echo_showing_p
= 0;