1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985,86,87,88,93,94,95,97,98,99,2000,01,02,03
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 FRAME_LINE_HEIGHT, which means
428 that 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 int height
= WINDOW_TOTAL_HEIGHT (w
);
917 if (WINDOW_WANTS_MODELINE_P (w
))
918 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
922 /* Return the pixel width of display area AREA of window W. AREA < 0
923 means return the total width of W, not including fringes to
924 the left and right of the window. */
927 window_box_width (w
, area
)
931 int cols
= XFASTINT (w
->total_cols
);
934 if (!w
->pseudo_window_p
)
936 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
938 if (area
== TEXT_AREA
)
940 if (INTEGERP (w
->left_margin_cols
))
941 cols
-= XFASTINT (w
->left_margin_cols
);
942 if (INTEGERP (w
->right_margin_cols
))
943 cols
-= XFASTINT (w
->right_margin_cols
);
944 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
946 else if (area
== LEFT_MARGIN_AREA
)
948 cols
= (INTEGERP (w
->left_margin_cols
)
949 ? XFASTINT (w
->left_margin_cols
) : 0);
952 else if (area
== RIGHT_MARGIN_AREA
)
954 cols
= (INTEGERP (w
->right_margin_cols
)
955 ? XFASTINT (w
->right_margin_cols
) : 0);
960 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
964 /* Return the pixel height of the display area of window W, not
965 including mode lines of W, if any. */
968 window_box_height (w
)
971 struct frame
*f
= XFRAME (w
->frame
);
972 int height
= WINDOW_TOTAL_HEIGHT (w
);
974 xassert (height
>= 0);
976 /* Note: the code below that determines the mode-line/header-line
977 height is essentially the same as that contained in the macro
978 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
979 the appropriate glyph row has its `mode_line_p' flag set,
980 and if it doesn't, uses estimate_mode_line_height instead. */
982 if (WINDOW_WANTS_MODELINE_P (w
))
984 struct glyph_row
*ml_row
985 = (w
->current_matrix
&& w
->current_matrix
->rows
986 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
988 if (ml_row
&& ml_row
->mode_line_p
)
989 height
-= ml_row
->height
;
991 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
994 if (WINDOW_WANTS_HEADER_LINE_P (w
))
996 struct glyph_row
*hl_row
997 = (w
->current_matrix
&& w
->current_matrix
->rows
998 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1000 if (hl_row
&& hl_row
->mode_line_p
)
1001 height
-= hl_row
->height
;
1003 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1006 /* With a very small font and a mode-line that's taller than
1007 default, we might end up with a negative height. */
1008 return max (0, height
);
1011 /* Return the window-relative coordinate of the left edge of display
1012 area AREA of window W. AREA < 0 means return the left edge of the
1013 whole window, to the right of the left fringe of W. */
1016 window_box_left_offset (w
, area
)
1022 if (w
->pseudo_window_p
)
1025 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1027 if (area
== TEXT_AREA
)
1028 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1029 + window_box_width (w
, LEFT_MARGIN_AREA
));
1030 else if (area
== RIGHT_MARGIN_AREA
)
1031 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1032 + window_box_width (w
, LEFT_MARGIN_AREA
)
1033 + window_box_width (w
, TEXT_AREA
)
1034 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1036 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1037 else if (area
== LEFT_MARGIN_AREA
1038 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1039 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1045 /* Return the window-relative coordinate of the right edge of display
1046 area AREA of window W. AREA < 0 means return the left edge of the
1047 whole window, to the left of the right fringe of W. */
1050 window_box_right_offset (w
, area
)
1054 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1057 /* Return the frame-relative coordinate of the left edge of display
1058 area AREA of window W. AREA < 0 means return the left edge of the
1059 whole window, to the right of the left fringe of W. */
1062 window_box_left (w
, area
)
1066 struct frame
*f
= XFRAME (w
->frame
);
1069 if (w
->pseudo_window_p
)
1070 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1072 x
= (WINDOW_LEFT_EDGE_X (w
)
1073 + window_box_left_offset (w
, area
));
1079 /* Return the frame-relative coordinate of the right edge of display
1080 area AREA of window W. AREA < 0 means return the left edge of the
1081 whole window, to the left of the right fringe of W. */
1084 window_box_right (w
, area
)
1088 return window_box_left (w
, area
) + window_box_width (w
, area
);
1091 /* Get the bounding box of the display area AREA of window W, without
1092 mode lines, in frame-relative coordinates. AREA < 0 means the
1093 whole window, not including the left and right fringes of
1094 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1095 coordinates of the upper-left corner of the box. Return in
1096 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1099 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1102 int *box_x
, *box_y
, *box_width
, *box_height
;
1105 *box_width
= window_box_width (w
, area
);
1107 *box_height
= window_box_height (w
);
1109 *box_x
= window_box_left (w
, area
);
1112 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1113 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1114 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1119 /* Get the bounding box of the display area AREA of window W, without
1120 mode lines. AREA < 0 means the whole window, not including the
1121 left and right fringe of the window. Return in *TOP_LEFT_X
1122 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1123 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1124 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1128 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1129 bottom_right_x
, bottom_right_y
)
1132 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1134 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1136 *bottom_right_x
+= *top_left_x
;
1137 *bottom_right_y
+= *top_left_y
;
1142 /***********************************************************************
1144 ***********************************************************************/
1146 /* Return the bottom y-position of the line the iterator IT is in.
1147 This can modify IT's settings. */
1153 int line_height
= it
->max_ascent
+ it
->max_descent
;
1154 int line_top_y
= it
->current_y
;
1156 if (line_height
== 0)
1159 line_height
= last_height
;
1160 else if (IT_CHARPOS (*it
) < ZV
)
1162 move_it_by_lines (it
, 1, 1);
1163 line_height
= (it
->max_ascent
|| it
->max_descent
1164 ? it
->max_ascent
+ it
->max_descent
1169 struct glyph_row
*row
= it
->glyph_row
;
1171 /* Use the default character height. */
1172 it
->glyph_row
= NULL
;
1173 it
->what
= IT_CHARACTER
;
1176 PRODUCE_GLYPHS (it
);
1177 line_height
= it
->ascent
+ it
->descent
;
1178 it
->glyph_row
= row
;
1182 return line_top_y
+ line_height
;
1186 /* Return 1 if position CHARPOS is visible in window W. Set *FULLY to
1187 1 if POS is visible and the line containing POS is fully visible.
1188 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1189 and header-lines heights. */
1192 pos_visible_p (w
, charpos
, fully
, exact_mode_line_heights_p
)
1194 int charpos
, *fully
, exact_mode_line_heights_p
;
1197 struct text_pos top
;
1199 struct buffer
*old_buffer
= NULL
;
1201 if (XBUFFER (w
->buffer
) != current_buffer
)
1203 old_buffer
= current_buffer
;
1204 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1207 *fully
= visible_p
= 0;
1208 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1210 /* Compute exact mode line heights, if requested. */
1211 if (exact_mode_line_heights_p
)
1213 if (WINDOW_WANTS_MODELINE_P (w
))
1214 current_mode_line_height
1215 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1216 current_buffer
->mode_line_format
);
1218 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1219 current_header_line_height
1220 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1221 current_buffer
->header_line_format
);
1224 start_display (&it
, w
, top
);
1225 move_it_to (&it
, charpos
, 0, it
.last_visible_y
, -1,
1226 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
1228 /* Note that we may overshoot because of invisible text. */
1229 if (IT_CHARPOS (it
) >= charpos
)
1231 int top_y
= it
.current_y
;
1232 int bottom_y
= line_bottom_y (&it
);
1233 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1235 if (top_y
< window_top_y
)
1236 visible_p
= bottom_y
> window_top_y
;
1237 else if (top_y
< it
.last_visible_y
)
1240 *fully
= bottom_y
<= it
.last_visible_y
;
1243 else if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
> it
.last_visible_y
)
1245 move_it_by_lines (&it
, 1, 0);
1246 if (charpos
< IT_CHARPOS (it
))
1254 set_buffer_internal_1 (old_buffer
);
1256 current_header_line_height
= current_mode_line_height
= -1;
1261 /* Return the next character from STR which is MAXLEN bytes long.
1262 Return in *LEN the length of the character. This is like
1263 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1264 we find one, we return a `?', but with the length of the invalid
1268 string_char_and_length (str
, maxlen
, len
)
1269 const unsigned char *str
;
1274 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1275 if (!CHAR_VALID_P (c
, 1))
1276 /* We may not change the length here because other places in Emacs
1277 don't use this function, i.e. they silently accept invalid
1286 /* Given a position POS containing a valid character and byte position
1287 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1289 static struct text_pos
1290 string_pos_nchars_ahead (pos
, string
, nchars
)
1291 struct text_pos pos
;
1295 xassert (STRINGP (string
) && nchars
>= 0);
1297 if (STRING_MULTIBYTE (string
))
1299 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1300 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1305 string_char_and_length (p
, rest
, &len
);
1306 p
+= len
, rest
-= len
;
1307 xassert (rest
>= 0);
1309 BYTEPOS (pos
) += len
;
1313 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1319 /* Value is the text position, i.e. character and byte position,
1320 for character position CHARPOS in STRING. */
1322 static INLINE
struct text_pos
1323 string_pos (charpos
, string
)
1327 struct text_pos pos
;
1328 xassert (STRINGP (string
));
1329 xassert (charpos
>= 0);
1330 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1335 /* Value is a text position, i.e. character and byte position, for
1336 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1337 means recognize multibyte characters. */
1339 static struct text_pos
1340 c_string_pos (charpos
, s
, multibyte_p
)
1345 struct text_pos pos
;
1347 xassert (s
!= NULL
);
1348 xassert (charpos
>= 0);
1352 int rest
= strlen (s
), len
;
1354 SET_TEXT_POS (pos
, 0, 0);
1357 string_char_and_length (s
, rest
, &len
);
1358 s
+= len
, rest
-= len
;
1359 xassert (rest
>= 0);
1361 BYTEPOS (pos
) += len
;
1365 SET_TEXT_POS (pos
, charpos
, charpos
);
1371 /* Value is the number of characters in C string S. MULTIBYTE_P
1372 non-zero means recognize multibyte characters. */
1375 number_of_chars (s
, multibyte_p
)
1383 int rest
= strlen (s
), len
;
1384 unsigned char *p
= (unsigned char *) s
;
1386 for (nchars
= 0; rest
> 0; ++nchars
)
1388 string_char_and_length (p
, rest
, &len
);
1389 rest
-= len
, p
+= len
;
1393 nchars
= strlen (s
);
1399 /* Compute byte position NEWPOS->bytepos corresponding to
1400 NEWPOS->charpos. POS is a known position in string STRING.
1401 NEWPOS->charpos must be >= POS.charpos. */
1404 compute_string_pos (newpos
, pos
, string
)
1405 struct text_pos
*newpos
, pos
;
1408 xassert (STRINGP (string
));
1409 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1411 if (STRING_MULTIBYTE (string
))
1412 *newpos
= string_pos_nchars_ahead (pos
, string
,
1413 CHARPOS (*newpos
) - CHARPOS (pos
));
1415 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1419 Return an estimation of the pixel height of mode or top lines on
1420 frame F. FACE_ID specifies what line's height to estimate. */
1423 estimate_mode_line_height (f
, face_id
)
1425 enum face_id face_id
;
1427 #ifdef HAVE_WINDOW_SYSTEM
1428 if (FRAME_WINDOW_P (f
))
1430 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1432 /* This function is called so early when Emacs starts that the face
1433 cache and mode line face are not yet initialized. */
1434 if (FRAME_FACE_CACHE (f
))
1436 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1440 height
= FONT_HEIGHT (face
->font
);
1441 if (face
->box_line_width
> 0)
1442 height
+= 2 * face
->box_line_width
;
1453 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1454 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1455 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1456 not force the value into range. */
1459 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1461 register int pix_x
, pix_y
;
1463 NativeRectangle
*bounds
;
1467 #ifdef HAVE_WINDOW_SYSTEM
1468 if (FRAME_WINDOW_P (f
))
1470 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1471 even for negative values. */
1473 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1475 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1477 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1478 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1481 STORE_NATIVE_RECT (*bounds
,
1482 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1483 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1484 FRAME_COLUMN_WIDTH (f
) - 1,
1485 FRAME_LINE_HEIGHT (f
) - 1);
1491 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1492 pix_x
= FRAME_TOTAL_COLS (f
);
1496 else if (pix_y
> FRAME_LINES (f
))
1497 pix_y
= FRAME_LINES (f
);
1507 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1508 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1509 can't tell the positions because W's display is not up to date,
1513 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1516 int *frame_x
, *frame_y
;
1518 #ifdef HAVE_WINDOW_SYSTEM
1519 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1523 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1524 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1526 if (display_completed
)
1528 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1529 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1530 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1536 hpos
+= glyph
->pixel_width
;
1548 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1549 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1560 #ifdef HAVE_WINDOW_SYSTEM
1562 /* Find the glyph under window-relative coordinates X/Y in window W.
1563 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1564 strings. Return in *HPOS and *VPOS the row and column number of
1565 the glyph found. Return in *AREA the glyph area containing X.
1566 Value is a pointer to the glyph found or null if X/Y is not on
1567 text, or we can't tell because W's current matrix is not up to
1570 static struct glyph
*
1571 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
1574 int *hpos
, *vpos
, *area
;
1577 struct glyph
*glyph
, *end
;
1578 struct glyph_row
*row
= NULL
;
1581 /* Find row containing Y. Give up if some row is not enabled. */
1582 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1584 row
= MATRIX_ROW (w
->current_matrix
, i
);
1585 if (!row
->enabled_p
)
1587 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1594 /* Give up if Y is not in the window. */
1595 if (i
== w
->current_matrix
->nrows
)
1598 /* Get the glyph area containing X. */
1599 if (w
->pseudo_window_p
)
1606 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1608 *area
= LEFT_MARGIN_AREA
;
1609 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1611 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1614 x0
= window_box_left_offset (w
, TEXT_AREA
);
1618 *area
= RIGHT_MARGIN_AREA
;
1619 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1623 /* Find glyph containing X. */
1624 glyph
= row
->glyphs
[*area
];
1625 end
= glyph
+ row
->used
[*area
];
1628 if (x
< x0
+ glyph
->pixel_width
)
1630 if (w
->pseudo_window_p
)
1632 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
1636 x0
+= glyph
->pixel_width
;
1643 *hpos
= glyph
- row
->glyphs
[*area
];
1649 Convert frame-relative x/y to coordinates relative to window W.
1650 Takes pseudo-windows into account. */
1653 frame_to_window_pixel_xy (w
, x
, y
)
1657 if (w
->pseudo_window_p
)
1659 /* A pseudo-window is always full-width, and starts at the
1660 left edge of the frame, plus a frame border. */
1661 struct frame
*f
= XFRAME (w
->frame
);
1662 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1663 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1667 *x
-= WINDOW_LEFT_EDGE_X (w
);
1668 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1673 Return in *R the clipping rectangle for glyph string S. */
1676 get_glyph_string_clip_rect (s
, nr
)
1677 struct glyph_string
*s
;
1678 NativeRectangle
*nr
;
1682 if (s
->row
->full_width_p
)
1684 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1685 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1686 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1688 /* Unless displaying a mode or menu bar line, which are always
1689 fully visible, clip to the visible part of the row. */
1690 if (s
->w
->pseudo_window_p
)
1691 r
.height
= s
->row
->visible_height
;
1693 r
.height
= s
->height
;
1697 /* This is a text line that may be partially visible. */
1698 r
.x
= window_box_left (s
->w
, s
->area
);
1699 r
.width
= window_box_width (s
->w
, s
->area
);
1700 r
.height
= s
->row
->visible_height
;
1703 /* If S draws overlapping rows, it's sufficient to use the top and
1704 bottom of the window for clipping because this glyph string
1705 intentionally draws over other lines. */
1706 if (s
->for_overlaps_p
)
1708 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1709 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1713 /* Don't use S->y for clipping because it doesn't take partially
1714 visible lines into account. For example, it can be negative for
1715 partially visible lines at the top of a window. */
1716 if (!s
->row
->full_width_p
1717 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1718 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1720 r
.y
= max (0, s
->row
->y
);
1722 /* If drawing a tool-bar window, draw it over the internal border
1723 at the top of the window. */
1724 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1725 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1728 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1731 /* ++KFS: From W32 port, but it looks ok for all platforms to me. */
1732 /* If drawing the cursor, don't let glyph draw outside its
1733 advertised boundaries. Cleartype does this under some circumstances. */
1734 if (s
->hl
== DRAW_CURSOR
)
1738 r
.width
-= s
->x
- r
.x
;
1741 r
.width
= min (r
.width
, s
->first_glyph
->pixel_width
);
1745 #ifdef CONVERT_FROM_XRECT
1746 CONVERT_FROM_XRECT (r
, *nr
);
1752 #endif /* HAVE_WINDOW_SYSTEM */
1755 /***********************************************************************
1756 Lisp form evaluation
1757 ***********************************************************************/
1759 /* Error handler for safe_eval and safe_call. */
1762 safe_eval_handler (arg
)
1765 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1770 /* Evaluate SEXPR and return the result, or nil if something went
1771 wrong. Prevent redisplay during the evaluation. */
1779 if (inhibit_eval_during_redisplay
)
1783 int count
= SPECPDL_INDEX ();
1784 struct gcpro gcpro1
;
1787 specbind (Qinhibit_redisplay
, Qt
);
1788 /* Use Qt to ensure debugger does not run,
1789 so there is no possibility of wanting to redisplay. */
1790 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1793 val
= unbind_to (count
, val
);
1800 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1801 Return the result, or nil if something went wrong. Prevent
1802 redisplay during the evaluation. */
1805 safe_call (nargs
, args
)
1811 if (inhibit_eval_during_redisplay
)
1815 int count
= SPECPDL_INDEX ();
1816 struct gcpro gcpro1
;
1819 gcpro1
.nvars
= nargs
;
1820 specbind (Qinhibit_redisplay
, Qt
);
1821 /* Use Qt to ensure debugger does not run,
1822 so there is no possibility of wanting to redisplay. */
1823 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
1826 val
= unbind_to (count
, val
);
1833 /* Call function FN with one argument ARG.
1834 Return the result, or nil if something went wrong. */
1837 safe_call1 (fn
, arg
)
1838 Lisp_Object fn
, arg
;
1840 Lisp_Object args
[2];
1843 return safe_call (2, args
);
1848 /***********************************************************************
1850 ***********************************************************************/
1854 /* Define CHECK_IT to perform sanity checks on iterators.
1855 This is for debugging. It is too slow to do unconditionally. */
1861 if (it
->method
== next_element_from_string
)
1863 xassert (STRINGP (it
->string
));
1864 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1866 else if (it
->method
== next_element_from_buffer
)
1868 /* Check that character and byte positions agree. */
1869 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1873 xassert (it
->current
.dpvec_index
>= 0);
1875 xassert (it
->current
.dpvec_index
< 0);
1878 #define CHECK_IT(IT) check_it ((IT))
1882 #define CHECK_IT(IT) (void) 0
1889 /* Check that the window end of window W is what we expect it
1890 to be---the last row in the current matrix displaying text. */
1893 check_window_end (w
)
1896 if (!MINI_WINDOW_P (w
)
1897 && !NILP (w
->window_end_valid
))
1899 struct glyph_row
*row
;
1900 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1901 XFASTINT (w
->window_end_vpos
)),
1903 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1904 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1908 #define CHECK_WINDOW_END(W) check_window_end ((W))
1910 #else /* not GLYPH_DEBUG */
1912 #define CHECK_WINDOW_END(W) (void) 0
1914 #endif /* not GLYPH_DEBUG */
1918 /***********************************************************************
1919 Iterator initialization
1920 ***********************************************************************/
1922 /* Initialize IT for displaying current_buffer in window W, starting
1923 at character position CHARPOS. CHARPOS < 0 means that no buffer
1924 position is specified which is useful when the iterator is assigned
1925 a position later. BYTEPOS is the byte position corresponding to
1926 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
1928 If ROW is not null, calls to produce_glyphs with IT as parameter
1929 will produce glyphs in that row.
1931 BASE_FACE_ID is the id of a base face to use. It must be one of
1932 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
1933 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
1934 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
1936 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
1937 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
1938 will be initialized to use the corresponding mode line glyph row of
1939 the desired matrix of W. */
1942 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1945 int charpos
, bytepos
;
1946 struct glyph_row
*row
;
1947 enum face_id base_face_id
;
1949 int highlight_region_p
;
1951 /* Some precondition checks. */
1952 xassert (w
!= NULL
&& it
!= NULL
);
1953 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
1956 /* If face attributes have been changed since the last redisplay,
1957 free realized faces now because they depend on face definitions
1958 that might have changed. Don't free faces while there might be
1959 desired matrices pending which reference these faces. */
1960 if (face_change_count
&& !inhibit_free_realized_faces
)
1962 face_change_count
= 0;
1963 free_all_realized_faces (Qnil
);
1966 /* Use one of the mode line rows of W's desired matrix if
1970 if (base_face_id
== MODE_LINE_FACE_ID
1971 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
1972 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1973 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1974 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1978 bzero (it
, sizeof *it
);
1979 it
->current
.overlay_string_index
= -1;
1980 it
->current
.dpvec_index
= -1;
1981 it
->base_face_id
= base_face_id
;
1983 /* The window in which we iterate over current_buffer: */
1984 XSETWINDOW (it
->window
, w
);
1986 it
->f
= XFRAME (w
->frame
);
1988 /* Extra space between lines (on window systems only). */
1989 if (base_face_id
== DEFAULT_FACE_ID
1990 && FRAME_WINDOW_P (it
->f
))
1992 if (NATNUMP (current_buffer
->extra_line_spacing
))
1993 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
1994 else if (it
->f
->extra_line_spacing
> 0)
1995 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
1998 /* If realized faces have been removed, e.g. because of face
1999 attribute changes of named faces, recompute them. When running
2000 in batch mode, the face cache of Vterminal_frame is null. If
2001 we happen to get called, make a dummy face cache. */
2006 FRAME_FACE_CACHE (it
->f
) == NULL
)
2007 init_frame_faces (it
->f
);
2008 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2009 recompute_basic_faces (it
->f
);
2011 /* Current value of the `space-width', and 'height' properties. */
2012 it
->space_width
= Qnil
;
2013 it
->font_height
= Qnil
;
2015 /* Are control characters displayed as `^C'? */
2016 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2018 /* -1 means everything between a CR and the following line end
2019 is invisible. >0 means lines indented more than this value are
2021 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2022 ? XFASTINT (current_buffer
->selective_display
)
2023 : (!NILP (current_buffer
->selective_display
)
2025 it
->selective_display_ellipsis_p
2026 = !NILP (current_buffer
->selective_display_ellipses
);
2028 /* Display table to use. */
2029 it
->dp
= window_display_table (w
);
2031 /* Are multibyte characters enabled in current_buffer? */
2032 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2034 /* Non-zero if we should highlight the region. */
2036 = (!NILP (Vtransient_mark_mode
)
2037 && !NILP (current_buffer
->mark_active
)
2038 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2040 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2041 start and end of a visible region in window IT->w. Set both to
2042 -1 to indicate no region. */
2043 if (highlight_region_p
2044 /* Maybe highlight only in selected window. */
2045 && (/* Either show region everywhere. */
2046 highlight_nonselected_windows
2047 /* Or show region in the selected window. */
2048 || w
== XWINDOW (selected_window
)
2049 /* Or show the region if we are in the mini-buffer and W is
2050 the window the mini-buffer refers to. */
2051 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2052 && WINDOWP (minibuf_selected_window
)
2053 && w
== XWINDOW (minibuf_selected_window
))))
2055 int charpos
= marker_position (current_buffer
->mark
);
2056 it
->region_beg_charpos
= min (PT
, charpos
);
2057 it
->region_end_charpos
= max (PT
, charpos
);
2060 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2062 /* Get the position at which the redisplay_end_trigger hook should
2063 be run, if it is to be run at all. */
2064 if (MARKERP (w
->redisplay_end_trigger
)
2065 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2066 it
->redisplay_end_trigger_charpos
2067 = marker_position (w
->redisplay_end_trigger
);
2068 else if (INTEGERP (w
->redisplay_end_trigger
))
2069 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2071 /* Correct bogus values of tab_width. */
2072 it
->tab_width
= XINT (current_buffer
->tab_width
);
2073 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2076 /* Are lines in the display truncated? */
2077 it
->truncate_lines_p
2078 = (base_face_id
!= DEFAULT_FACE_ID
2079 || XINT (it
->w
->hscroll
)
2080 || (truncate_partial_width_windows
2081 && !WINDOW_FULL_WIDTH_P (it
->w
))
2082 || !NILP (current_buffer
->truncate_lines
));
2084 /* Get dimensions of truncation and continuation glyphs. These are
2085 displayed as fringe bitmaps under X, so we don't need them for such
2087 if (!FRAME_WINDOW_P (it
->f
))
2089 if (it
->truncate_lines_p
)
2091 /* We will need the truncation glyph. */
2092 xassert (it
->glyph_row
== NULL
);
2093 produce_special_glyphs (it
, IT_TRUNCATION
);
2094 it
->truncation_pixel_width
= it
->pixel_width
;
2098 /* We will need the continuation glyph. */
2099 xassert (it
->glyph_row
== NULL
);
2100 produce_special_glyphs (it
, IT_CONTINUATION
);
2101 it
->continuation_pixel_width
= it
->pixel_width
;
2104 /* Reset these values to zero because the produce_special_glyphs
2105 above has changed them. */
2106 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2107 it
->phys_ascent
= it
->phys_descent
= 0;
2110 /* Set this after getting the dimensions of truncation and
2111 continuation glyphs, so that we don't produce glyphs when calling
2112 produce_special_glyphs, above. */
2113 it
->glyph_row
= row
;
2114 it
->area
= TEXT_AREA
;
2116 /* Get the dimensions of the display area. The display area
2117 consists of the visible window area plus a horizontally scrolled
2118 part to the left of the window. All x-values are relative to the
2119 start of this total display area. */
2120 if (base_face_id
!= DEFAULT_FACE_ID
)
2122 /* Mode lines, menu bar in terminal frames. */
2123 it
->first_visible_x
= 0;
2124 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2129 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2130 it
->last_visible_x
= (it
->first_visible_x
2131 + window_box_width (w
, TEXT_AREA
));
2133 /* If we truncate lines, leave room for the truncator glyph(s) at
2134 the right margin. Otherwise, leave room for the continuation
2135 glyph(s). Truncation and continuation glyphs are not inserted
2136 for window-based redisplay. */
2137 if (!FRAME_WINDOW_P (it
->f
))
2139 if (it
->truncate_lines_p
)
2140 it
->last_visible_x
-= it
->truncation_pixel_width
;
2142 it
->last_visible_x
-= it
->continuation_pixel_width
;
2145 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2146 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2149 /* Leave room for a border glyph. */
2150 if (!FRAME_WINDOW_P (it
->f
)
2151 && !WINDOW_RIGHTMOST_P (it
->w
))
2152 it
->last_visible_x
-= 1;
2154 it
->last_visible_y
= window_text_bottom_y (w
);
2156 /* For mode lines and alike, arrange for the first glyph having a
2157 left box line if the face specifies a box. */
2158 if (base_face_id
!= DEFAULT_FACE_ID
)
2162 it
->face_id
= base_face_id
;
2164 /* If we have a boxed mode line, make the first character appear
2165 with a left box line. */
2166 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2167 if (face
->box
!= FACE_NO_BOX
)
2168 it
->start_of_box_run_p
= 1;
2171 /* If a buffer position was specified, set the iterator there,
2172 getting overlays and face properties from that position. */
2173 if (charpos
>= BUF_BEG (current_buffer
))
2175 it
->end_charpos
= ZV
;
2177 IT_CHARPOS (*it
) = charpos
;
2179 /* Compute byte position if not specified. */
2180 if (bytepos
< charpos
)
2181 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2183 IT_BYTEPOS (*it
) = bytepos
;
2185 /* Compute faces etc. */
2186 reseat (it
, it
->current
.pos
, 1);
2193 /* Initialize IT for the display of window W with window start POS. */
2196 start_display (it
, w
, pos
)
2199 struct text_pos pos
;
2201 struct glyph_row
*row
;
2202 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2204 row
= w
->desired_matrix
->rows
+ first_vpos
;
2205 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2207 if (!it
->truncate_lines_p
)
2209 int start_at_line_beg_p
;
2210 int first_y
= it
->current_y
;
2212 /* If window start is not at a line start, skip forward to POS to
2213 get the correct continuation lines width. */
2214 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2215 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2216 if (!start_at_line_beg_p
)
2220 reseat_at_previous_visible_line_start (it
);
2221 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2223 new_x
= it
->current_x
+ it
->pixel_width
;
2225 /* If lines are continued, this line may end in the middle
2226 of a multi-glyph character (e.g. a control character
2227 displayed as \003, or in the middle of an overlay
2228 string). In this case move_it_to above will not have
2229 taken us to the start of the continuation line but to the
2230 end of the continued line. */
2231 if (it
->current_x
> 0
2232 && !it
->truncate_lines_p
/* Lines are continued. */
2233 && (/* And glyph doesn't fit on the line. */
2234 new_x
> it
->last_visible_x
2235 /* Or it fits exactly and we're on a window
2237 || (new_x
== it
->last_visible_x
2238 && FRAME_WINDOW_P (it
->f
))))
2240 if (it
->current
.dpvec_index
>= 0
2241 || it
->current
.overlay_string_index
>= 0)
2243 set_iterator_to_next (it
, 1);
2244 move_it_in_display_line_to (it
, -1, -1, 0);
2247 it
->continuation_lines_width
+= it
->current_x
;
2250 /* We're starting a new display line, not affected by the
2251 height of the continued line, so clear the appropriate
2252 fields in the iterator structure. */
2253 it
->max_ascent
= it
->max_descent
= 0;
2254 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2256 it
->current_y
= first_y
;
2258 it
->current_x
= it
->hpos
= 0;
2262 #if 0 /* Don't assert the following because start_display is sometimes
2263 called intentionally with a window start that is not at a
2264 line start. Please leave this code in as a comment. */
2266 /* Window start should be on a line start, now. */
2267 xassert (it
->continuation_lines_width
2268 || IT_CHARPOS (it
) == BEGV
2269 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2274 /* Return 1 if POS is a position in ellipses displayed for invisible
2275 text. W is the window we display, for text property lookup. */
2278 in_ellipses_for_invisible_text_p (pos
, w
)
2279 struct display_pos
*pos
;
2282 Lisp_Object prop
, window
;
2284 int charpos
= CHARPOS (pos
->pos
);
2286 /* If POS specifies a position in a display vector, this might
2287 be for an ellipsis displayed for invisible text. We won't
2288 get the iterator set up for delivering that ellipsis unless
2289 we make sure that it gets aware of the invisible text. */
2290 if (pos
->dpvec_index
>= 0
2291 && pos
->overlay_string_index
< 0
2292 && CHARPOS (pos
->string_pos
) < 0
2294 && (XSETWINDOW (window
, w
),
2295 prop
= Fget_char_property (make_number (charpos
),
2296 Qinvisible
, window
),
2297 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2299 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2301 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2308 /* Initialize IT for stepping through current_buffer in window W,
2309 starting at position POS that includes overlay string and display
2310 vector/ control character translation position information. Value
2311 is zero if there are overlay strings with newlines at POS. */
2314 init_from_display_pos (it
, w
, pos
)
2317 struct display_pos
*pos
;
2319 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2320 int i
, overlay_strings_with_newlines
= 0;
2322 /* If POS specifies a position in a display vector, this might
2323 be for an ellipsis displayed for invisible text. We won't
2324 get the iterator set up for delivering that ellipsis unless
2325 we make sure that it gets aware of the invisible text. */
2326 if (in_ellipses_for_invisible_text_p (pos
, w
))
2332 /* Keep in mind: the call to reseat in init_iterator skips invisible
2333 text, so we might end up at a position different from POS. This
2334 is only a problem when POS is a row start after a newline and an
2335 overlay starts there with an after-string, and the overlay has an
2336 invisible property. Since we don't skip invisible text in
2337 display_line and elsewhere immediately after consuming the
2338 newline before the row start, such a POS will not be in a string,
2339 but the call to init_iterator below will move us to the
2341 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2343 for (i
= 0; i
< it
->n_overlay_strings
; ++i
)
2345 const char *s
= SDATA (it
->overlay_strings
[i
]);
2346 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2348 while (s
< e
&& *s
!= '\n')
2353 overlay_strings_with_newlines
= 1;
2358 /* If position is within an overlay string, set up IT to the right
2360 if (pos
->overlay_string_index
>= 0)
2364 /* If the first overlay string happens to have a `display'
2365 property for an image, the iterator will be set up for that
2366 image, and we have to undo that setup first before we can
2367 correct the overlay string index. */
2368 if (it
->method
== next_element_from_image
)
2371 /* We already have the first chunk of overlay strings in
2372 IT->overlay_strings. Load more until the one for
2373 pos->overlay_string_index is in IT->overlay_strings. */
2374 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2376 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2377 it
->current
.overlay_string_index
= 0;
2380 load_overlay_strings (it
, 0);
2381 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2385 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2386 relative_index
= (it
->current
.overlay_string_index
2387 % OVERLAY_STRING_CHUNK_SIZE
);
2388 it
->string
= it
->overlay_strings
[relative_index
];
2389 xassert (STRINGP (it
->string
));
2390 it
->current
.string_pos
= pos
->string_pos
;
2391 it
->method
= next_element_from_string
;
2394 #if 0 /* This is bogus because POS not having an overlay string
2395 position does not mean it's after the string. Example: A
2396 line starting with a before-string and initialization of IT
2397 to the previous row's end position. */
2398 else if (it
->current
.overlay_string_index
>= 0)
2400 /* If POS says we're already after an overlay string ending at
2401 POS, make sure to pop the iterator because it will be in
2402 front of that overlay string. When POS is ZV, we've thereby
2403 also ``processed'' overlay strings at ZV. */
2406 it
->current
.overlay_string_index
= -1;
2407 it
->method
= next_element_from_buffer
;
2408 if (CHARPOS (pos
->pos
) == ZV
)
2409 it
->overlay_strings_at_end_processed_p
= 1;
2413 if (CHARPOS (pos
->string_pos
) >= 0)
2415 /* Recorded position is not in an overlay string, but in another
2416 string. This can only be a string from a `display' property.
2417 IT should already be filled with that string. */
2418 it
->current
.string_pos
= pos
->string_pos
;
2419 xassert (STRINGP (it
->string
));
2422 /* Restore position in display vector translations, control
2423 character translations or ellipses. */
2424 if (pos
->dpvec_index
>= 0)
2426 if (it
->dpvec
== NULL
)
2427 get_next_display_element (it
);
2428 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2429 it
->current
.dpvec_index
= pos
->dpvec_index
;
2433 return !overlay_strings_with_newlines
;
2437 /* Initialize IT for stepping through current_buffer in window W
2438 starting at ROW->start. */
2441 init_to_row_start (it
, w
, row
)
2444 struct glyph_row
*row
;
2446 init_from_display_pos (it
, w
, &row
->start
);
2447 it
->continuation_lines_width
= row
->continuation_lines_width
;
2452 /* Initialize IT for stepping through current_buffer in window W
2453 starting in the line following ROW, i.e. starting at ROW->end.
2454 Value is zero if there are overlay strings with newlines at ROW's
2458 init_to_row_end (it
, w
, row
)
2461 struct glyph_row
*row
;
2465 if (init_from_display_pos (it
, w
, &row
->end
))
2467 if (row
->continued_p
)
2468 it
->continuation_lines_width
2469 = row
->continuation_lines_width
+ row
->pixel_width
;
2480 /***********************************************************************
2482 ***********************************************************************/
2484 /* Called when IT reaches IT->stop_charpos. Handle text property and
2485 overlay changes. Set IT->stop_charpos to the next position where
2492 enum prop_handled handled
;
2493 int handle_overlay_change_p
= 1;
2497 it
->current
.dpvec_index
= -1;
2501 handled
= HANDLED_NORMALLY
;
2503 /* Call text property handlers. */
2504 for (p
= it_props
; p
->handler
; ++p
)
2506 handled
= p
->handler (it
);
2508 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2510 else if (handled
== HANDLED_RETURN
)
2512 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2513 handle_overlay_change_p
= 0;
2516 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2518 /* Don't check for overlay strings below when set to deliver
2519 characters from a display vector. */
2520 if (it
->method
== next_element_from_display_vector
)
2521 handle_overlay_change_p
= 0;
2523 /* Handle overlay changes. */
2524 if (handle_overlay_change_p
)
2525 handled
= handle_overlay_change (it
);
2527 /* Determine where to stop next. */
2528 if (handled
== HANDLED_NORMALLY
)
2529 compute_stop_pos (it
);
2532 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2536 /* Compute IT->stop_charpos from text property and overlay change
2537 information for IT's current position. */
2540 compute_stop_pos (it
)
2543 register INTERVAL iv
, next_iv
;
2544 Lisp_Object object
, limit
, position
;
2546 /* If nowhere else, stop at the end. */
2547 it
->stop_charpos
= it
->end_charpos
;
2549 if (STRINGP (it
->string
))
2551 /* Strings are usually short, so don't limit the search for
2553 object
= it
->string
;
2555 position
= make_number (IT_STRING_CHARPOS (*it
));
2561 /* If next overlay change is in front of the current stop pos
2562 (which is IT->end_charpos), stop there. Note: value of
2563 next_overlay_change is point-max if no overlay change
2565 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2566 if (charpos
< it
->stop_charpos
)
2567 it
->stop_charpos
= charpos
;
2569 /* If showing the region, we have to stop at the region
2570 start or end because the face might change there. */
2571 if (it
->region_beg_charpos
> 0)
2573 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2574 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2575 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2576 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2579 /* Set up variables for computing the stop position from text
2580 property changes. */
2581 XSETBUFFER (object
, current_buffer
);
2582 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2583 position
= make_number (IT_CHARPOS (*it
));
2587 /* Get the interval containing IT's position. Value is a null
2588 interval if there isn't such an interval. */
2589 iv
= validate_interval_range (object
, &position
, &position
, 0);
2590 if (!NULL_INTERVAL_P (iv
))
2592 Lisp_Object values_here
[LAST_PROP_IDX
];
2595 /* Get properties here. */
2596 for (p
= it_props
; p
->handler
; ++p
)
2597 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2599 /* Look for an interval following iv that has different
2601 for (next_iv
= next_interval (iv
);
2602 (!NULL_INTERVAL_P (next_iv
)
2604 || XFASTINT (limit
) > next_iv
->position
));
2605 next_iv
= next_interval (next_iv
))
2607 for (p
= it_props
; p
->handler
; ++p
)
2609 Lisp_Object new_value
;
2611 new_value
= textget (next_iv
->plist
, *p
->name
);
2612 if (!EQ (values_here
[p
->idx
], new_value
))
2620 if (!NULL_INTERVAL_P (next_iv
))
2622 if (INTEGERP (limit
)
2623 && next_iv
->position
>= XFASTINT (limit
))
2624 /* No text property change up to limit. */
2625 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2627 /* Text properties change in next_iv. */
2628 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2632 xassert (STRINGP (it
->string
)
2633 || (it
->stop_charpos
>= BEGV
2634 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2638 /* Return the position of the next overlay change after POS in
2639 current_buffer. Value is point-max if no overlay change
2640 follows. This is like `next-overlay-change' but doesn't use
2644 next_overlay_change (pos
)
2649 Lisp_Object
*overlays
;
2653 /* Get all overlays at the given position. */
2655 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2656 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2657 if (noverlays
> len
)
2660 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
2661 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
, 1);
2664 /* If any of these overlays ends before endpos,
2665 use its ending point instead. */
2666 for (i
= 0; i
< noverlays
; ++i
)
2671 oend
= OVERLAY_END (overlays
[i
]);
2672 oendpos
= OVERLAY_POSITION (oend
);
2673 endpos
= min (endpos
, oendpos
);
2681 /***********************************************************************
2683 ***********************************************************************/
2685 /* Handle changes in the `fontified' property of the current buffer by
2686 calling hook functions from Qfontification_functions to fontify
2689 static enum prop_handled
2690 handle_fontified_prop (it
)
2693 Lisp_Object prop
, pos
;
2694 enum prop_handled handled
= HANDLED_NORMALLY
;
2696 /* Get the value of the `fontified' property at IT's current buffer
2697 position. (The `fontified' property doesn't have a special
2698 meaning in strings.) If the value is nil, call functions from
2699 Qfontification_functions. */
2700 if (!STRINGP (it
->string
)
2702 && !NILP (Vfontification_functions
)
2703 && !NILP (Vrun_hooks
)
2704 && (pos
= make_number (IT_CHARPOS (*it
)),
2705 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2708 int count
= SPECPDL_INDEX ();
2711 val
= Vfontification_functions
;
2712 specbind (Qfontification_functions
, Qnil
);
2714 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2715 safe_call1 (val
, pos
);
2718 Lisp_Object globals
, fn
;
2719 struct gcpro gcpro1
, gcpro2
;
2722 GCPRO2 (val
, globals
);
2724 for (; CONSP (val
); val
= XCDR (val
))
2730 /* A value of t indicates this hook has a local
2731 binding; it means to run the global binding too.
2732 In a global value, t should not occur. If it
2733 does, we must ignore it to avoid an endless
2735 for (globals
= Fdefault_value (Qfontification_functions
);
2737 globals
= XCDR (globals
))
2739 fn
= XCAR (globals
);
2741 safe_call1 (fn
, pos
);
2745 safe_call1 (fn
, pos
);
2751 unbind_to (count
, Qnil
);
2753 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2754 something. This avoids an endless loop if they failed to
2755 fontify the text for which reason ever. */
2756 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2757 handled
= HANDLED_RECOMPUTE_PROPS
;
2765 /***********************************************************************
2767 ***********************************************************************/
2769 /* Set up iterator IT from face properties at its current position.
2770 Called from handle_stop. */
2772 static enum prop_handled
2773 handle_face_prop (it
)
2776 int new_face_id
, next_stop
;
2778 if (!STRINGP (it
->string
))
2781 = face_at_buffer_position (it
->w
,
2783 it
->region_beg_charpos
,
2784 it
->region_end_charpos
,
2787 + TEXT_PROP_DISTANCE_LIMIT
),
2790 /* Is this a start of a run of characters with box face?
2791 Caveat: this can be called for a freshly initialized
2792 iterator; face_id is -1 in this case. We know that the new
2793 face will not change until limit, i.e. if the new face has a
2794 box, all characters up to limit will have one. But, as
2795 usual, we don't know whether limit is really the end. */
2796 if (new_face_id
!= it
->face_id
)
2798 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2800 /* If new face has a box but old face has not, this is
2801 the start of a run of characters with box, i.e. it has
2802 a shadow on the left side. The value of face_id of the
2803 iterator will be -1 if this is the initial call that gets
2804 the face. In this case, we have to look in front of IT's
2805 position and see whether there is a face != new_face_id. */
2806 it
->start_of_box_run_p
2807 = (new_face
->box
!= FACE_NO_BOX
2808 && (it
->face_id
>= 0
2809 || IT_CHARPOS (*it
) == BEG
2810 || new_face_id
!= face_before_it_pos (it
)));
2811 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2816 int base_face_id
, bufpos
;
2818 if (it
->current
.overlay_string_index
>= 0)
2819 bufpos
= IT_CHARPOS (*it
);
2823 /* For strings from a buffer, i.e. overlay strings or strings
2824 from a `display' property, use the face at IT's current
2825 buffer position as the base face to merge with, so that
2826 overlay strings appear in the same face as surrounding
2827 text, unless they specify their own faces. */
2828 base_face_id
= underlying_face_id (it
);
2830 new_face_id
= face_at_string_position (it
->w
,
2832 IT_STRING_CHARPOS (*it
),
2834 it
->region_beg_charpos
,
2835 it
->region_end_charpos
,
2839 #if 0 /* This shouldn't be neccessary. Let's check it. */
2840 /* If IT is used to display a mode line we would really like to
2841 use the mode line face instead of the frame's default face. */
2842 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
2843 && new_face_id
== DEFAULT_FACE_ID
)
2844 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
2847 /* Is this a start of a run of characters with box? Caveat:
2848 this can be called for a freshly allocated iterator; face_id
2849 is -1 is this case. We know that the new face will not
2850 change until the next check pos, i.e. if the new face has a
2851 box, all characters up to that position will have a
2852 box. But, as usual, we don't know whether that position
2853 is really the end. */
2854 if (new_face_id
!= it
->face_id
)
2856 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
2857 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2859 /* If new face has a box but old face hasn't, this is the
2860 start of a run of characters with box, i.e. it has a
2861 shadow on the left side. */
2862 it
->start_of_box_run_p
2863 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
2864 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
2868 it
->face_id
= new_face_id
;
2869 return HANDLED_NORMALLY
;
2873 /* Return the ID of the face ``underlying'' IT's current position,
2874 which is in a string. If the iterator is associated with a
2875 buffer, return the face at IT's current buffer position.
2876 Otherwise, use the iterator's base_face_id. */
2879 underlying_face_id (it
)
2882 int face_id
= it
->base_face_id
, i
;
2884 xassert (STRINGP (it
->string
));
2886 for (i
= it
->sp
- 1; i
>= 0; --i
)
2887 if (NILP (it
->stack
[i
].string
))
2888 face_id
= it
->stack
[i
].face_id
;
2894 /* Compute the face one character before or after the current position
2895 of IT. BEFORE_P non-zero means get the face in front of IT's
2896 position. Value is the id of the face. */
2899 face_before_or_after_it_pos (it
, before_p
)
2904 int next_check_charpos
;
2905 struct text_pos pos
;
2907 xassert (it
->s
== NULL
);
2909 if (STRINGP (it
->string
))
2911 int bufpos
, base_face_id
;
2913 /* No face change past the end of the string (for the case
2914 we are padding with spaces). No face change before the
2916 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
2917 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
2920 /* Set pos to the position before or after IT's current position. */
2922 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
2924 /* For composition, we must check the character after the
2926 pos
= (it
->what
== IT_COMPOSITION
2927 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
2928 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
2930 if (it
->current
.overlay_string_index
>= 0)
2931 bufpos
= IT_CHARPOS (*it
);
2935 base_face_id
= underlying_face_id (it
);
2937 /* Get the face for ASCII, or unibyte. */
2938 face_id
= face_at_string_position (it
->w
,
2942 it
->region_beg_charpos
,
2943 it
->region_end_charpos
,
2944 &next_check_charpos
,
2947 /* Correct the face for charsets different from ASCII. Do it
2948 for the multibyte case only. The face returned above is
2949 suitable for unibyte text if IT->string is unibyte. */
2950 if (STRING_MULTIBYTE (it
->string
))
2952 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
2953 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
2955 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2957 c
= string_char_and_length (p
, rest
, &len
);
2958 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2963 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
2964 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
2967 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
2968 pos
= it
->current
.pos
;
2971 DEC_TEXT_POS (pos
, it
->multibyte_p
);
2974 if (it
->what
== IT_COMPOSITION
)
2975 /* For composition, we must check the position after the
2977 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
2979 INC_TEXT_POS (pos
, it
->multibyte_p
);
2982 /* Determine face for CHARSET_ASCII, or unibyte. */
2983 face_id
= face_at_buffer_position (it
->w
,
2985 it
->region_beg_charpos
,
2986 it
->region_end_charpos
,
2987 &next_check_charpos
,
2990 /* Correct the face for charsets different from ASCII. Do it
2991 for the multibyte case only. The face returned above is
2992 suitable for unibyte text if current_buffer is unibyte. */
2993 if (it
->multibyte_p
)
2995 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
2996 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
2997 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3006 /***********************************************************************
3008 ***********************************************************************/
3010 /* Set up iterator IT from invisible properties at its current
3011 position. Called from handle_stop. */
3013 static enum prop_handled
3014 handle_invisible_prop (it
)
3017 enum prop_handled handled
= HANDLED_NORMALLY
;
3019 if (STRINGP (it
->string
))
3021 extern Lisp_Object Qinvisible
;
3022 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3024 /* Get the value of the invisible text property at the
3025 current position. Value will be nil if there is no such
3027 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3028 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3031 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3033 handled
= HANDLED_RECOMPUTE_PROPS
;
3035 /* Get the position at which the next change of the
3036 invisible text property can be found in IT->string.
3037 Value will be nil if the property value is the same for
3038 all the rest of IT->string. */
3039 XSETINT (limit
, SCHARS (it
->string
));
3040 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3043 /* Text at current position is invisible. The next
3044 change in the property is at position end_charpos.
3045 Move IT's current position to that position. */
3046 if (INTEGERP (end_charpos
)
3047 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3049 struct text_pos old
;
3050 old
= it
->current
.string_pos
;
3051 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3052 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3056 /* The rest of the string is invisible. If this is an
3057 overlay string, proceed with the next overlay string
3058 or whatever comes and return a character from there. */
3059 if (it
->current
.overlay_string_index
>= 0)
3061 next_overlay_string (it
);
3062 /* Don't check for overlay strings when we just
3063 finished processing them. */
3064 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3068 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3069 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3076 int invis_p
, newpos
, next_stop
, start_charpos
;
3077 Lisp_Object pos
, prop
, overlay
;
3079 /* First of all, is there invisible text at this position? */
3080 start_charpos
= IT_CHARPOS (*it
);
3081 pos
= make_number (IT_CHARPOS (*it
));
3082 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3084 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3086 /* If we are on invisible text, skip over it. */
3087 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3089 /* Record whether we have to display an ellipsis for the
3091 int display_ellipsis_p
= invis_p
== 2;
3093 handled
= HANDLED_RECOMPUTE_PROPS
;
3095 /* Loop skipping over invisible text. The loop is left at
3096 ZV or with IT on the first char being visible again. */
3099 /* Try to skip some invisible text. Return value is the
3100 position reached which can be equal to IT's position
3101 if there is nothing invisible here. This skips both
3102 over invisible text properties and overlays with
3103 invisible property. */
3104 newpos
= skip_invisible (IT_CHARPOS (*it
),
3105 &next_stop
, ZV
, it
->window
);
3107 /* If we skipped nothing at all we weren't at invisible
3108 text in the first place. If everything to the end of
3109 the buffer was skipped, end the loop. */
3110 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3114 /* We skipped some characters but not necessarily
3115 all there are. Check if we ended up on visible
3116 text. Fget_char_property returns the property of
3117 the char before the given position, i.e. if we
3118 get invis_p = 0, this means that the char at
3119 newpos is visible. */
3120 pos
= make_number (newpos
);
3121 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3122 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3125 /* If we ended up on invisible text, proceed to
3126 skip starting with next_stop. */
3128 IT_CHARPOS (*it
) = next_stop
;
3132 /* The position newpos is now either ZV or on visible text. */
3133 IT_CHARPOS (*it
) = newpos
;
3134 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3136 /* If there are before-strings at the start of invisible
3137 text, and the text is invisible because of a text
3138 property, arrange to show before-strings because 20.x did
3139 it that way. (If the text is invisible because of an
3140 overlay property instead of a text property, this is
3141 already handled in the overlay code.) */
3143 && get_overlay_strings (it
, start_charpos
))
3145 handled
= HANDLED_RECOMPUTE_PROPS
;
3146 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3148 else if (display_ellipsis_p
)
3149 setup_for_ellipsis (it
);
3157 /* Make iterator IT return `...' next. */
3160 setup_for_ellipsis (it
)
3164 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3166 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3167 it
->dpvec
= v
->contents
;
3168 it
->dpend
= v
->contents
+ v
->size
;
3172 /* Default `...'. */
3173 it
->dpvec
= default_invis_vector
;
3174 it
->dpend
= default_invis_vector
+ 3;
3177 /* The ellipsis display does not replace the display of the
3178 character at the new position. Indicate this by setting
3179 IT->dpvec_char_len to zero. */
3180 it
->dpvec_char_len
= 0;
3182 it
->current
.dpvec_index
= 0;
3183 it
->method
= next_element_from_display_vector
;
3188 /***********************************************************************
3190 ***********************************************************************/
3192 /* Set up iterator IT from `display' property at its current position.
3193 Called from handle_stop. */
3195 static enum prop_handled
3196 handle_display_prop (it
)
3199 Lisp_Object prop
, object
;
3200 struct text_pos
*position
;
3201 int display_replaced_p
= 0;
3203 if (STRINGP (it
->string
))
3205 object
= it
->string
;
3206 position
= &it
->current
.string_pos
;
3210 object
= it
->w
->buffer
;
3211 position
= &it
->current
.pos
;
3214 /* Reset those iterator values set from display property values. */
3215 it
->font_height
= Qnil
;
3216 it
->space_width
= Qnil
;
3219 /* We don't support recursive `display' properties, i.e. string
3220 values that have a string `display' property, that have a string
3221 `display' property etc. */
3222 if (!it
->string_from_display_prop_p
)
3223 it
->area
= TEXT_AREA
;
3225 prop
= Fget_char_property (make_number (position
->charpos
),
3228 return HANDLED_NORMALLY
;
3231 /* Simple properties. */
3232 && !EQ (XCAR (prop
), Qimage
)
3233 && !EQ (XCAR (prop
), Qspace
)
3234 && !EQ (XCAR (prop
), Qwhen
)
3235 && !EQ (XCAR (prop
), Qspace_width
)
3236 && !EQ (XCAR (prop
), Qheight
)
3237 && !EQ (XCAR (prop
), Qraise
)
3238 /* Marginal area specifications. */
3239 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3240 && !NILP (XCAR (prop
)))
3242 for (; CONSP (prop
); prop
= XCDR (prop
))
3244 if (handle_single_display_prop (it
, XCAR (prop
), object
,
3245 position
, display_replaced_p
))
3246 display_replaced_p
= 1;
3249 else if (VECTORP (prop
))
3252 for (i
= 0; i
< ASIZE (prop
); ++i
)
3253 if (handle_single_display_prop (it
, AREF (prop
, i
), object
,
3254 position
, display_replaced_p
))
3255 display_replaced_p
= 1;
3259 if (handle_single_display_prop (it
, prop
, object
, position
, 0))
3260 display_replaced_p
= 1;
3263 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3267 /* Value is the position of the end of the `display' property starting
3268 at START_POS in OBJECT. */
3270 static struct text_pos
3271 display_prop_end (it
, object
, start_pos
)
3274 struct text_pos start_pos
;
3277 struct text_pos end_pos
;
3279 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3280 Qdisplay
, object
, Qnil
);
3281 CHARPOS (end_pos
) = XFASTINT (end
);
3282 if (STRINGP (object
))
3283 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3285 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3291 /* Set up IT from a single `display' sub-property value PROP. OBJECT
3292 is the object in which the `display' property was found. *POSITION
3293 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3294 means that we previously saw a display sub-property which already
3295 replaced text display with something else, for example an image;
3296 ignore such properties after the first one has been processed.
3298 If PROP is a `space' or `image' sub-property, set *POSITION to the
3299 end position of the `display' property.
3301 Value is non-zero if something was found which replaces the display
3302 of buffer or string text. */
3305 handle_single_display_prop (it
, prop
, object
, position
,
3306 display_replaced_before_p
)
3310 struct text_pos
*position
;
3311 int display_replaced_before_p
;
3314 int replaces_text_display_p
= 0;
3317 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
3318 evaluated. If the result is nil, VALUE is ignored. */
3320 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3329 if (!NILP (form
) && !EQ (form
, Qt
))
3331 int count
= SPECPDL_INDEX ();
3332 struct gcpro gcpro1
;
3334 /* Bind `object' to the object having the `display' property, a
3335 buffer or string. Bind `position' to the position in the
3336 object where the property was found, and `buffer-position'
3337 to the current position in the buffer. */
3338 specbind (Qobject
, object
);
3339 specbind (Qposition
, make_number (CHARPOS (*position
)));
3340 specbind (Qbuffer_position
,
3341 make_number (STRINGP (object
)
3342 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3344 form
= safe_eval (form
);
3346 unbind_to (count
, Qnil
);
3353 && EQ (XCAR (prop
), Qheight
)
3354 && CONSP (XCDR (prop
)))
3356 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3359 /* `(height HEIGHT)'. */
3360 it
->font_height
= XCAR (XCDR (prop
));
3361 if (!NILP (it
->font_height
))
3363 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3364 int new_height
= -1;
3366 if (CONSP (it
->font_height
)
3367 && (EQ (XCAR (it
->font_height
), Qplus
)
3368 || EQ (XCAR (it
->font_height
), Qminus
))
3369 && CONSP (XCDR (it
->font_height
))
3370 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3372 /* `(+ N)' or `(- N)' where N is an integer. */
3373 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3374 if (EQ (XCAR (it
->font_height
), Qplus
))
3376 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3378 else if (FUNCTIONP (it
->font_height
))
3380 /* Call function with current height as argument.
3381 Value is the new height. */
3383 height
= safe_call1 (it
->font_height
,
3384 face
->lface
[LFACE_HEIGHT_INDEX
]);
3385 if (NUMBERP (height
))
3386 new_height
= XFLOATINT (height
);
3388 else if (NUMBERP (it
->font_height
))
3390 /* Value is a multiple of the canonical char height. */
3393 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3394 new_height
= (XFLOATINT (it
->font_height
)
3395 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3399 /* Evaluate IT->font_height with `height' bound to the
3400 current specified height to get the new height. */
3402 int count
= SPECPDL_INDEX ();
3404 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3405 value
= safe_eval (it
->font_height
);
3406 unbind_to (count
, Qnil
);
3408 if (NUMBERP (value
))
3409 new_height
= XFLOATINT (value
);
3413 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3416 else if (CONSP (prop
)
3417 && EQ (XCAR (prop
), Qspace_width
)
3418 && CONSP (XCDR (prop
)))
3420 /* `(space_width WIDTH)'. */
3421 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3424 value
= XCAR (XCDR (prop
));
3425 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3426 it
->space_width
= value
;
3428 else if (CONSP (prop
)
3429 && EQ (XCAR (prop
), Qraise
)
3430 && CONSP (XCDR (prop
)))
3432 /* `(raise FACTOR)'. */
3433 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3436 #ifdef HAVE_WINDOW_SYSTEM
3437 value
= XCAR (XCDR (prop
));
3438 if (NUMBERP (value
))
3440 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3441 it
->voffset
= - (XFLOATINT (value
)
3442 * (FONT_HEIGHT (face
->font
)));
3444 #endif /* HAVE_WINDOW_SYSTEM */
3446 else if (!it
->string_from_display_prop_p
)
3448 /* `((margin left-margin) VALUE)' or `((margin right-margin)
3449 VALUE) or `((margin nil) VALUE)' or VALUE. */
3450 Lisp_Object location
, value
;
3451 struct text_pos start_pos
;
3454 /* Characters having this form of property are not displayed, so
3455 we have to find the end of the property. */
3456 start_pos
= *position
;
3457 *position
= display_prop_end (it
, object
, start_pos
);
3460 /* Let's stop at the new position and assume that all
3461 text properties change there. */
3462 it
->stop_charpos
= position
->charpos
;
3464 location
= Qunbound
;
3465 if (CONSP (prop
) && CONSP (XCAR (prop
)))
3469 value
= XCDR (prop
);
3471 value
= XCAR (value
);
3474 if (EQ (XCAR (tem
), Qmargin
)
3475 && (tem
= XCDR (tem
),
3476 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3478 || EQ (tem
, Qleft_margin
)
3479 || EQ (tem
, Qright_margin
))))
3483 if (EQ (location
, Qunbound
))
3489 #ifdef HAVE_WINDOW_SYSTEM
3490 if (FRAME_TERMCAP_P (it
->f
))
3491 valid_p
= STRINGP (value
);
3493 valid_p
= (STRINGP (value
)
3494 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3495 || valid_image_p (value
));
3496 #else /* not HAVE_WINDOW_SYSTEM */
3497 valid_p
= STRINGP (value
);
3498 #endif /* not HAVE_WINDOW_SYSTEM */
3500 if ((EQ (location
, Qleft_margin
)
3501 || EQ (location
, Qright_margin
)
3504 && !display_replaced_before_p
)
3506 replaces_text_display_p
= 1;
3508 /* Save current settings of IT so that we can restore them
3509 when we are finished with the glyph property value. */
3512 if (NILP (location
))
3513 it
->area
= TEXT_AREA
;
3514 else if (EQ (location
, Qleft_margin
))
3515 it
->area
= LEFT_MARGIN_AREA
;
3517 it
->area
= RIGHT_MARGIN_AREA
;
3519 if (STRINGP (value
))
3522 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3523 it
->current
.overlay_string_index
= -1;
3524 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3525 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3526 it
->method
= next_element_from_string
;
3527 it
->stop_charpos
= 0;
3528 it
->string_from_display_prop_p
= 1;
3529 /* Say that we haven't consumed the characters with
3530 `display' property yet. The call to pop_it in
3531 set_iterator_to_next will clean this up. */
3532 *position
= start_pos
;
3534 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3536 it
->method
= next_element_from_stretch
;
3538 it
->current
.pos
= it
->position
= start_pos
;
3540 #ifdef HAVE_WINDOW_SYSTEM
3543 it
->what
= IT_IMAGE
;
3544 it
->image_id
= lookup_image (it
->f
, value
);
3545 it
->position
= start_pos
;
3546 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3547 it
->method
= next_element_from_image
;
3549 /* Say that we haven't consumed the characters with
3550 `display' property yet. The call to pop_it in
3551 set_iterator_to_next will clean this up. */
3552 *position
= start_pos
;
3554 #endif /* HAVE_WINDOW_SYSTEM */
3557 /* Invalid property or property not supported. Restore
3558 the position to what it was before. */
3559 *position
= start_pos
;
3562 return replaces_text_display_p
;
3566 /* Check if PROP is a display sub-property value whose text should be
3567 treated as intangible. */
3570 single_display_prop_intangible_p (prop
)
3573 /* Skip over `when FORM'. */
3574 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3588 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3589 we don't need to treat text as intangible. */
3590 if (EQ (XCAR (prop
), Qmargin
))
3598 || EQ (XCAR (prop
), Qleft_margin
)
3599 || EQ (XCAR (prop
), Qright_margin
))
3603 return (CONSP (prop
)
3604 && (EQ (XCAR (prop
), Qimage
)
3605 || EQ (XCAR (prop
), Qspace
)));
3609 /* Check if PROP is a display property value whose text should be
3610 treated as intangible. */
3613 display_prop_intangible_p (prop
)
3617 && CONSP (XCAR (prop
))
3618 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3620 /* A list of sub-properties. */
3621 while (CONSP (prop
))
3623 if (single_display_prop_intangible_p (XCAR (prop
)))
3628 else if (VECTORP (prop
))
3630 /* A vector of sub-properties. */
3632 for (i
= 0; i
< ASIZE (prop
); ++i
)
3633 if (single_display_prop_intangible_p (AREF (prop
, i
)))
3637 return single_display_prop_intangible_p (prop
);
3643 /* Return 1 if PROP is a display sub-property value containing STRING. */
3646 single_display_prop_string_p (prop
, string
)
3647 Lisp_Object prop
, string
;
3649 if (EQ (string
, prop
))
3652 /* Skip over `when FORM'. */
3653 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3662 /* Skip over `margin LOCATION'. */
3663 if (EQ (XCAR (prop
), Qmargin
))
3674 return CONSP (prop
) && EQ (XCAR (prop
), string
);
3678 /* Return 1 if STRING appears in the `display' property PROP. */
3681 display_prop_string_p (prop
, string
)
3682 Lisp_Object prop
, string
;
3685 && CONSP (XCAR (prop
))
3686 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3688 /* A list of sub-properties. */
3689 while (CONSP (prop
))
3691 if (single_display_prop_string_p (XCAR (prop
), string
))
3696 else if (VECTORP (prop
))
3698 /* A vector of sub-properties. */
3700 for (i
= 0; i
< ASIZE (prop
); ++i
)
3701 if (single_display_prop_string_p (AREF (prop
, i
), string
))
3705 return single_display_prop_string_p (prop
, string
);
3711 /* Determine from which buffer position in W's buffer STRING comes
3712 from. AROUND_CHARPOS is an approximate position where it could
3713 be from. Value is the buffer position or 0 if it couldn't be
3716 W's buffer must be current.
3718 This function is necessary because we don't record buffer positions
3719 in glyphs generated from strings (to keep struct glyph small).
3720 This function may only use code that doesn't eval because it is
3721 called asynchronously from note_mouse_highlight. */
3724 string_buffer_position (w
, string
, around_charpos
)
3729 Lisp_Object limit
, prop
, pos
;
3730 const int MAX_DISTANCE
= 1000;
3733 pos
= make_number (around_charpos
);
3734 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
3735 while (!found
&& !EQ (pos
, limit
))
3737 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3738 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3741 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
3746 pos
= make_number (around_charpos
);
3747 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
3748 while (!found
&& !EQ (pos
, limit
))
3750 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
3751 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
3754 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
3759 return found
? XINT (pos
) : 0;
3764 /***********************************************************************
3765 `composition' property
3766 ***********************************************************************/
3768 /* Set up iterator IT from `composition' property at its current
3769 position. Called from handle_stop. */
3771 static enum prop_handled
3772 handle_composition_prop (it
)
3775 Lisp_Object prop
, string
;
3776 int pos
, pos_byte
, end
;
3777 enum prop_handled handled
= HANDLED_NORMALLY
;
3779 if (STRINGP (it
->string
))
3781 pos
= IT_STRING_CHARPOS (*it
);
3782 pos_byte
= IT_STRING_BYTEPOS (*it
);
3783 string
= it
->string
;
3787 pos
= IT_CHARPOS (*it
);
3788 pos_byte
= IT_BYTEPOS (*it
);
3792 /* If there's a valid composition and point is not inside of the
3793 composition (in the case that the composition is from the current
3794 buffer), draw a glyph composed from the composition components. */
3795 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
3796 && COMPOSITION_VALID_P (pos
, end
, prop
)
3797 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
3799 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
3803 it
->method
= next_element_from_composition
;
3805 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
3806 /* For a terminal, draw only the first character of the
3808 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
3809 it
->len
= (STRINGP (it
->string
)
3810 ? string_char_to_byte (it
->string
, end
)
3811 : CHAR_TO_BYTE (end
)) - pos_byte
;
3812 it
->stop_charpos
= end
;
3813 handled
= HANDLED_RETURN
;
3822 /***********************************************************************
3824 ***********************************************************************/
3826 /* The following structure is used to record overlay strings for
3827 later sorting in load_overlay_strings. */
3829 struct overlay_entry
3831 Lisp_Object overlay
;
3838 /* Set up iterator IT from overlay strings at its current position.
3839 Called from handle_stop. */
3841 static enum prop_handled
3842 handle_overlay_change (it
)
3845 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
3846 return HANDLED_RECOMPUTE_PROPS
;
3848 return HANDLED_NORMALLY
;
3852 /* Set up the next overlay string for delivery by IT, if there is an
3853 overlay string to deliver. Called by set_iterator_to_next when the
3854 end of the current overlay string is reached. If there are more
3855 overlay strings to display, IT->string and
3856 IT->current.overlay_string_index are set appropriately here.
3857 Otherwise IT->string is set to nil. */
3860 next_overlay_string (it
)
3863 ++it
->current
.overlay_string_index
;
3864 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
3866 /* No more overlay strings. Restore IT's settings to what
3867 they were before overlay strings were processed, and
3868 continue to deliver from current_buffer. */
3869 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
3872 xassert (it
->stop_charpos
>= BEGV
3873 && it
->stop_charpos
<= it
->end_charpos
);
3875 it
->current
.overlay_string_index
= -1;
3876 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
3877 it
->n_overlay_strings
= 0;
3878 it
->method
= next_element_from_buffer
;
3880 /* If we're at the end of the buffer, record that we have
3881 processed the overlay strings there already, so that
3882 next_element_from_buffer doesn't try it again. */
3883 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3884 it
->overlay_strings_at_end_processed_p
= 1;
3886 /* If we have to display `...' for invisible text, set
3887 the iterator up for that. */
3888 if (display_ellipsis_p
)
3889 setup_for_ellipsis (it
);
3893 /* There are more overlay strings to process. If
3894 IT->current.overlay_string_index has advanced to a position
3895 where we must load IT->overlay_strings with more strings, do
3897 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
3899 if (it
->current
.overlay_string_index
&& i
== 0)
3900 load_overlay_strings (it
, 0);
3902 /* Initialize IT to deliver display elements from the overlay
3904 it
->string
= it
->overlay_strings
[i
];
3905 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3906 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
3907 it
->method
= next_element_from_string
;
3908 it
->stop_charpos
= 0;
3915 /* Compare two overlay_entry structures E1 and E2. Used as a
3916 comparison function for qsort in load_overlay_strings. Overlay
3917 strings for the same position are sorted so that
3919 1. All after-strings come in front of before-strings, except
3920 when they come from the same overlay.
3922 2. Within after-strings, strings are sorted so that overlay strings
3923 from overlays with higher priorities come first.
3925 2. Within before-strings, strings are sorted so that overlay
3926 strings from overlays with higher priorities come last.
3928 Value is analogous to strcmp. */
3932 compare_overlay_entries (e1
, e2
)
3935 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
3936 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
3939 if (entry1
->after_string_p
!= entry2
->after_string_p
)
3941 /* Let after-strings appear in front of before-strings if
3942 they come from different overlays. */
3943 if (EQ (entry1
->overlay
, entry2
->overlay
))
3944 result
= entry1
->after_string_p
? 1 : -1;
3946 result
= entry1
->after_string_p
? -1 : 1;
3948 else if (entry1
->after_string_p
)
3949 /* After-strings sorted in order of decreasing priority. */
3950 result
= entry2
->priority
- entry1
->priority
;
3952 /* Before-strings sorted in order of increasing priority. */
3953 result
= entry1
->priority
- entry2
->priority
;
3959 /* Load the vector IT->overlay_strings with overlay strings from IT's
3960 current buffer position, or from CHARPOS if that is > 0. Set
3961 IT->n_overlays to the total number of overlay strings found.
3963 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
3964 a time. On entry into load_overlay_strings,
3965 IT->current.overlay_string_index gives the number of overlay
3966 strings that have already been loaded by previous calls to this
3969 IT->add_overlay_start contains an additional overlay start
3970 position to consider for taking overlay strings from, if non-zero.
3971 This position comes into play when the overlay has an `invisible'
3972 property, and both before and after-strings. When we've skipped to
3973 the end of the overlay, because of its `invisible' property, we
3974 nevertheless want its before-string to appear.
3975 IT->add_overlay_start will contain the overlay start position
3978 Overlay strings are sorted so that after-string strings come in
3979 front of before-string strings. Within before and after-strings,
3980 strings are sorted by overlay priority. See also function
3981 compare_overlay_entries. */
3984 load_overlay_strings (it
, charpos
)
3988 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
3989 Lisp_Object ov
, overlay
, window
, str
, invisible
;
3992 int n
= 0, i
, j
, invis_p
;
3993 struct overlay_entry
*entries
3994 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
3997 charpos
= IT_CHARPOS (*it
);
3999 /* Append the overlay string STRING of overlay OVERLAY to vector
4000 `entries' which has size `size' and currently contains `n'
4001 elements. AFTER_P non-zero means STRING is an after-string of
4003 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4006 Lisp_Object priority; \
4010 int new_size = 2 * size; \
4011 struct overlay_entry *old = entries; \
4013 (struct overlay_entry *) alloca (new_size \
4014 * sizeof *entries); \
4015 bcopy (old, entries, size * sizeof *entries); \
4019 entries[n].string = (STRING); \
4020 entries[n].overlay = (OVERLAY); \
4021 priority = Foverlay_get ((OVERLAY), Qpriority); \
4022 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4023 entries[n].after_string_p = (AFTER_P); \
4028 /* Process overlay before the overlay center. */
4029 for (ov
= current_buffer
->overlays_before
; CONSP (ov
); ov
= XCDR (ov
))
4031 overlay
= XCAR (ov
);
4032 xassert (OVERLAYP (overlay
));
4033 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4034 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4039 /* Skip this overlay if it doesn't start or end at IT's current
4041 if (end
!= charpos
&& start
!= charpos
)
4044 /* Skip this overlay if it doesn't apply to IT->w. */
4045 window
= Foverlay_get (overlay
, Qwindow
);
4046 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4049 /* If the text ``under'' the overlay is invisible, both before-
4050 and after-strings from this overlay are visible; start and
4051 end position are indistinguishable. */
4052 invisible
= Foverlay_get (overlay
, Qinvisible
);
4053 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4055 /* If overlay has a non-empty before-string, record it. */
4056 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4057 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4059 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4061 /* If overlay has a non-empty after-string, record it. */
4062 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4063 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4065 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4068 /* Process overlays after the overlay center. */
4069 for (ov
= current_buffer
->overlays_after
; CONSP (ov
); ov
= XCDR (ov
))
4071 overlay
= XCAR (ov
);
4072 xassert (OVERLAYP (overlay
));
4073 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4074 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4076 if (start
> charpos
)
4079 /* Skip this overlay if it doesn't start or end at IT's current
4081 if (end
!= charpos
&& start
!= charpos
)
4084 /* Skip this overlay if it doesn't apply to IT->w. */
4085 window
= Foverlay_get (overlay
, Qwindow
);
4086 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4089 /* If the text ``under'' the overlay is invisible, it has a zero
4090 dimension, and both before- and after-strings apply. */
4091 invisible
= Foverlay_get (overlay
, Qinvisible
);
4092 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4094 /* If overlay has a non-empty before-string, record it. */
4095 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4096 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4098 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4100 /* If overlay has a non-empty after-string, record it. */
4101 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4102 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4104 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4107 #undef RECORD_OVERLAY_STRING
4111 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4113 /* Record the total number of strings to process. */
4114 it
->n_overlay_strings
= n
;
4116 /* IT->current.overlay_string_index is the number of overlay strings
4117 that have already been consumed by IT. Copy some of the
4118 remaining overlay strings to IT->overlay_strings. */
4120 j
= it
->current
.overlay_string_index
;
4121 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4122 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4128 /* Get the first chunk of overlay strings at IT's current buffer
4129 position, or at CHARPOS if that is > 0. Value is non-zero if at
4130 least one overlay string was found. */
4133 get_overlay_strings (it
, charpos
)
4137 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4138 process. This fills IT->overlay_strings with strings, and sets
4139 IT->n_overlay_strings to the total number of strings to process.
4140 IT->pos.overlay_string_index has to be set temporarily to zero
4141 because load_overlay_strings needs this; it must be set to -1
4142 when no overlay strings are found because a zero value would
4143 indicate a position in the first overlay string. */
4144 it
->current
.overlay_string_index
= 0;
4145 load_overlay_strings (it
, charpos
);
4147 /* If we found overlay strings, set up IT to deliver display
4148 elements from the first one. Otherwise set up IT to deliver
4149 from current_buffer. */
4150 if (it
->n_overlay_strings
)
4152 /* Make sure we know settings in current_buffer, so that we can
4153 restore meaningful values when we're done with the overlay
4155 compute_stop_pos (it
);
4156 xassert (it
->face_id
>= 0);
4158 /* Save IT's settings. They are restored after all overlay
4159 strings have been processed. */
4160 xassert (it
->sp
== 0);
4163 /* Set up IT to deliver display elements from the first overlay
4165 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4166 it
->string
= it
->overlay_strings
[0];
4167 it
->stop_charpos
= 0;
4168 xassert (STRINGP (it
->string
));
4169 it
->end_charpos
= SCHARS (it
->string
);
4170 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4171 it
->method
= next_element_from_string
;
4176 it
->current
.overlay_string_index
= -1;
4177 it
->method
= next_element_from_buffer
;
4182 /* Value is non-zero if we found at least one overlay string. */
4183 return STRINGP (it
->string
);
4188 /***********************************************************************
4189 Saving and restoring state
4190 ***********************************************************************/
4192 /* Save current settings of IT on IT->stack. Called, for example,
4193 before setting up IT for an overlay string, to be able to restore
4194 IT's settings to what they were after the overlay string has been
4201 struct iterator_stack_entry
*p
;
4203 xassert (it
->sp
< 2);
4204 p
= it
->stack
+ it
->sp
;
4206 p
->stop_charpos
= it
->stop_charpos
;
4207 xassert (it
->face_id
>= 0);
4208 p
->face_id
= it
->face_id
;
4209 p
->string
= it
->string
;
4210 p
->pos
= it
->current
;
4211 p
->end_charpos
= it
->end_charpos
;
4212 p
->string_nchars
= it
->string_nchars
;
4214 p
->multibyte_p
= it
->multibyte_p
;
4215 p
->space_width
= it
->space_width
;
4216 p
->font_height
= it
->font_height
;
4217 p
->voffset
= it
->voffset
;
4218 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4219 p
->display_ellipsis_p
= 0;
4224 /* Restore IT's settings from IT->stack. Called, for example, when no
4225 more overlay strings must be processed, and we return to delivering
4226 display elements from a buffer, or when the end of a string from a
4227 `display' property is reached and we return to delivering display
4228 elements from an overlay string, or from a buffer. */
4234 struct iterator_stack_entry
*p
;
4236 xassert (it
->sp
> 0);
4238 p
= it
->stack
+ it
->sp
;
4239 it
->stop_charpos
= p
->stop_charpos
;
4240 it
->face_id
= p
->face_id
;
4241 it
->string
= p
->string
;
4242 it
->current
= p
->pos
;
4243 it
->end_charpos
= p
->end_charpos
;
4244 it
->string_nchars
= p
->string_nchars
;
4246 it
->multibyte_p
= p
->multibyte_p
;
4247 it
->space_width
= p
->space_width
;
4248 it
->font_height
= p
->font_height
;
4249 it
->voffset
= p
->voffset
;
4250 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4255 /***********************************************************************
4257 ***********************************************************************/
4259 /* Set IT's current position to the previous line start. */
4262 back_to_previous_line_start (it
)
4265 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4266 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4270 /* Move IT to the next line start.
4272 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4273 we skipped over part of the text (as opposed to moving the iterator
4274 continuously over the text). Otherwise, don't change the value
4277 Newlines may come from buffer text, overlay strings, or strings
4278 displayed via the `display' property. That's the reason we can't
4279 simply use find_next_newline_no_quit.
4281 Note that this function may not skip over invisible text that is so
4282 because of text properties and immediately follows a newline. If
4283 it would, function reseat_at_next_visible_line_start, when called
4284 from set_iterator_to_next, would effectively make invisible
4285 characters following a newline part of the wrong glyph row, which
4286 leads to wrong cursor motion. */
4289 forward_to_next_line_start (it
, skipped_p
)
4293 int old_selective
, newline_found_p
, n
;
4294 const int MAX_NEWLINE_DISTANCE
= 500;
4296 /* If already on a newline, just consume it to avoid unintended
4297 skipping over invisible text below. */
4298 if (it
->what
== IT_CHARACTER
4300 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4302 set_iterator_to_next (it
, 0);
4307 /* Don't handle selective display in the following. It's (a)
4308 unnecessary because it's done by the caller, and (b) leads to an
4309 infinite recursion because next_element_from_ellipsis indirectly
4310 calls this function. */
4311 old_selective
= it
->selective
;
4314 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4315 from buffer text. */
4316 for (n
= newline_found_p
= 0;
4317 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4318 n
+= STRINGP (it
->string
) ? 0 : 1)
4320 if (!get_next_display_element (it
))
4322 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4323 set_iterator_to_next (it
, 0);
4326 /* If we didn't find a newline near enough, see if we can use a
4328 if (!newline_found_p
)
4330 int start
= IT_CHARPOS (*it
);
4331 int limit
= find_next_newline_no_quit (start
, 1);
4334 xassert (!STRINGP (it
->string
));
4336 /* If there isn't any `display' property in sight, and no
4337 overlays, we can just use the position of the newline in
4339 if (it
->stop_charpos
>= limit
4340 || ((pos
= Fnext_single_property_change (make_number (start
),
4342 Qnil
, make_number (limit
)),
4344 && next_overlay_change (start
) == ZV
))
4346 IT_CHARPOS (*it
) = limit
;
4347 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4348 *skipped_p
= newline_found_p
= 1;
4352 while (get_next_display_element (it
)
4353 && !newline_found_p
)
4355 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4356 set_iterator_to_next (it
, 0);
4361 it
->selective
= old_selective
;
4362 return newline_found_p
;
4366 /* Set IT's current position to the previous visible line start. Skip
4367 invisible text that is so either due to text properties or due to
4368 selective display. Caution: this does not change IT->current_x and
4372 back_to_previous_visible_line_start (it
)
4377 /* Go back one newline if not on BEGV already. */
4378 if (IT_CHARPOS (*it
) > BEGV
)
4379 back_to_previous_line_start (it
);
4381 /* Move over lines that are invisible because of selective display
4382 or text properties. */
4383 while (IT_CHARPOS (*it
) > BEGV
4388 /* If selective > 0, then lines indented more than that values
4390 if (it
->selective
> 0
4391 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4392 (double) it
->selective
)) /* iftc */
4398 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
4399 Qinvisible
, it
->window
);
4400 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4404 /* Back one more newline if the current one is invisible. */
4406 back_to_previous_line_start (it
);
4409 xassert (IT_CHARPOS (*it
) >= BEGV
);
4410 xassert (IT_CHARPOS (*it
) == BEGV
4411 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4416 /* Reseat iterator IT at the previous visible line start. Skip
4417 invisible text that is so either due to text properties or due to
4418 selective display. At the end, update IT's overlay information,
4419 face information etc. */
4422 reseat_at_previous_visible_line_start (it
)
4425 back_to_previous_visible_line_start (it
);
4426 reseat (it
, it
->current
.pos
, 1);
4431 /* Reseat iterator IT on the next visible line start in the current
4432 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4433 preceding the line start. Skip over invisible text that is so
4434 because of selective display. Compute faces, overlays etc at the
4435 new position. Note that this function does not skip over text that
4436 is invisible because of text properties. */
4439 reseat_at_next_visible_line_start (it
, on_newline_p
)
4443 int newline_found_p
, skipped_p
= 0;
4445 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4447 /* Skip over lines that are invisible because they are indented
4448 more than the value of IT->selective. */
4449 if (it
->selective
> 0)
4450 while (IT_CHARPOS (*it
) < ZV
4451 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4452 (double) it
->selective
)) /* iftc */
4454 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4455 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4458 /* Position on the newline if that's what's requested. */
4459 if (on_newline_p
&& newline_found_p
)
4461 if (STRINGP (it
->string
))
4463 if (IT_STRING_CHARPOS (*it
) > 0)
4465 --IT_STRING_CHARPOS (*it
);
4466 --IT_STRING_BYTEPOS (*it
);
4469 else if (IT_CHARPOS (*it
) > BEGV
)
4473 reseat (it
, it
->current
.pos
, 0);
4477 reseat (it
, it
->current
.pos
, 0);
4484 /***********************************************************************
4485 Changing an iterator's position
4486 ***********************************************************************/
4488 /* Change IT's current position to POS in current_buffer. If FORCE_P
4489 is non-zero, always check for text properties at the new position.
4490 Otherwise, text properties are only looked up if POS >=
4491 IT->check_charpos of a property. */
4494 reseat (it
, pos
, force_p
)
4496 struct text_pos pos
;
4499 int original_pos
= IT_CHARPOS (*it
);
4501 reseat_1 (it
, pos
, 0);
4503 /* Determine where to check text properties. Avoid doing it
4504 where possible because text property lookup is very expensive. */
4506 || CHARPOS (pos
) > it
->stop_charpos
4507 || CHARPOS (pos
) < original_pos
)
4514 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4515 IT->stop_pos to POS, also. */
4518 reseat_1 (it
, pos
, set_stop_p
)
4520 struct text_pos pos
;
4523 /* Don't call this function when scanning a C string. */
4524 xassert (it
->s
== NULL
);
4526 /* POS must be a reasonable value. */
4527 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4529 it
->current
.pos
= it
->position
= pos
;
4530 XSETBUFFER (it
->object
, current_buffer
);
4531 it
->end_charpos
= ZV
;
4533 it
->current
.dpvec_index
= -1;
4534 it
->current
.overlay_string_index
= -1;
4535 IT_STRING_CHARPOS (*it
) = -1;
4536 IT_STRING_BYTEPOS (*it
) = -1;
4538 it
->method
= next_element_from_buffer
;
4539 /* RMS: I added this to fix a bug in move_it_vertically_backward
4540 where it->area continued to relate to the starting point
4541 for the backward motion. Bug report from
4542 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4543 However, I am not sure whether reseat still does the right thing
4544 in general after this change. */
4545 it
->area
= TEXT_AREA
;
4546 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4548 it
->face_before_selective_p
= 0;
4551 it
->stop_charpos
= CHARPOS (pos
);
4555 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4556 If S is non-null, it is a C string to iterate over. Otherwise,
4557 STRING gives a Lisp string to iterate over.
4559 If PRECISION > 0, don't return more then PRECISION number of
4560 characters from the string.
4562 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4563 characters have been returned. FIELD_WIDTH < 0 means an infinite
4566 MULTIBYTE = 0 means disable processing of multibyte characters,
4567 MULTIBYTE > 0 means enable it,
4568 MULTIBYTE < 0 means use IT->multibyte_p.
4570 IT must be initialized via a prior call to init_iterator before
4571 calling this function. */
4574 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4579 int precision
, field_width
, multibyte
;
4581 /* No region in strings. */
4582 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4584 /* No text property checks performed by default, but see below. */
4585 it
->stop_charpos
= -1;
4587 /* Set iterator position and end position. */
4588 bzero (&it
->current
, sizeof it
->current
);
4589 it
->current
.overlay_string_index
= -1;
4590 it
->current
.dpvec_index
= -1;
4591 xassert (charpos
>= 0);
4593 /* If STRING is specified, use its multibyteness, otherwise use the
4594 setting of MULTIBYTE, if specified. */
4596 it
->multibyte_p
= multibyte
> 0;
4600 xassert (STRINGP (string
));
4601 it
->string
= string
;
4603 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4604 it
->method
= next_element_from_string
;
4605 it
->current
.string_pos
= string_pos (charpos
, string
);
4612 /* Note that we use IT->current.pos, not it->current.string_pos,
4613 for displaying C strings. */
4614 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4615 if (it
->multibyte_p
)
4617 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4618 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4622 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4623 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4626 it
->method
= next_element_from_c_string
;
4629 /* PRECISION > 0 means don't return more than PRECISION characters
4631 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4632 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4634 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4635 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4636 FIELD_WIDTH < 0 means infinite field width. This is useful for
4637 padding with `-' at the end of a mode line. */
4638 if (field_width
< 0)
4639 field_width
= INFINITY
;
4640 if (field_width
> it
->end_charpos
- charpos
)
4641 it
->end_charpos
= charpos
+ field_width
;
4643 /* Use the standard display table for displaying strings. */
4644 if (DISP_TABLE_P (Vstandard_display_table
))
4645 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4647 it
->stop_charpos
= charpos
;
4653 /***********************************************************************
4655 ***********************************************************************/
4657 /* Load IT's display element fields with information about the next
4658 display element from the current position of IT. Value is zero if
4659 end of buffer (or C string) is reached. */
4662 get_next_display_element (it
)
4665 /* Non-zero means that we found a display element. Zero means that
4666 we hit the end of what we iterate over. Performance note: the
4667 function pointer `method' used here turns out to be faster than
4668 using a sequence of if-statements. */
4669 int success_p
= (*it
->method
) (it
);
4671 if (it
->what
== IT_CHARACTER
)
4673 /* Map via display table or translate control characters.
4674 IT->c, IT->len etc. have been set to the next character by
4675 the function call above. If we have a display table, and it
4676 contains an entry for IT->c, translate it. Don't do this if
4677 IT->c itself comes from a display table, otherwise we could
4678 end up in an infinite recursion. (An alternative could be to
4679 count the recursion depth of this function and signal an
4680 error when a certain maximum depth is reached.) Is it worth
4682 if (success_p
&& it
->dpvec
== NULL
)
4687 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
4690 struct Lisp_Vector
*v
= XVECTOR (dv
);
4692 /* Return the first character from the display table
4693 entry, if not empty. If empty, don't display the
4694 current character. */
4697 it
->dpvec_char_len
= it
->len
;
4698 it
->dpvec
= v
->contents
;
4699 it
->dpend
= v
->contents
+ v
->size
;
4700 it
->current
.dpvec_index
= 0;
4701 it
->method
= next_element_from_display_vector
;
4702 success_p
= get_next_display_element (it
);
4706 set_iterator_to_next (it
, 0);
4707 success_p
= get_next_display_element (it
);
4711 /* Translate control characters into `\003' or `^C' form.
4712 Control characters coming from a display table entry are
4713 currently not translated because we use IT->dpvec to hold
4714 the translation. This could easily be changed but I
4715 don't believe that it is worth doing.
4717 If it->multibyte_p is nonzero, eight-bit characters and
4718 non-printable multibyte characters are also translated to
4721 If it->multibyte_p is zero, eight-bit characters that
4722 don't have corresponding multibyte char code are also
4723 translated to octal form. */
4724 else if ((it
->c
< ' '
4725 && (it
->area
!= TEXT_AREA
4726 || (it
->c
!= '\n' && it
->c
!= '\t')))
4730 || !CHAR_PRINTABLE_P (it
->c
))
4732 && it
->c
== unibyte_char_to_multibyte (it
->c
))))
4734 /* IT->c is a control character which must be displayed
4735 either as '\003' or as `^C' where the '\\' and '^'
4736 can be defined in the display table. Fill
4737 IT->ctl_chars with glyphs for what we have to
4738 display. Then, set IT->dpvec to these glyphs. */
4741 if (it
->c
< 128 && it
->ctl_arrow_p
)
4743 /* Set IT->ctl_chars[0] to the glyph for `^'. */
4745 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
4746 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
4747 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
4749 g
= FAST_MAKE_GLYPH ('^', 0);
4750 XSETINT (it
->ctl_chars
[0], g
);
4752 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
4753 XSETINT (it
->ctl_chars
[1], g
);
4755 /* Set up IT->dpvec and return first character from it. */
4756 it
->dpvec_char_len
= it
->len
;
4757 it
->dpvec
= it
->ctl_chars
;
4758 it
->dpend
= it
->dpvec
+ 2;
4759 it
->current
.dpvec_index
= 0;
4760 it
->method
= next_element_from_display_vector
;
4761 get_next_display_element (it
);
4765 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4770 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
4772 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
4773 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
4774 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
4776 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
4778 if (SINGLE_BYTE_CHAR_P (it
->c
))
4779 str
[0] = it
->c
, len
= 1;
4782 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
4785 /* It's an invalid character, which
4786 shouldn't happen actually, but due to
4787 bugs it may happen. Let's print the char
4788 as is, there's not much meaningful we can
4791 str
[1] = it
->c
>> 8;
4792 str
[2] = it
->c
>> 16;
4793 str
[3] = it
->c
>> 24;
4798 for (i
= 0; i
< len
; i
++)
4800 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
4801 /* Insert three more glyphs into IT->ctl_chars for
4802 the octal display of the character. */
4803 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
4804 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
4805 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
4806 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
4807 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
4808 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
4811 /* Set up IT->dpvec and return the first character
4813 it
->dpvec_char_len
= it
->len
;
4814 it
->dpvec
= it
->ctl_chars
;
4815 it
->dpend
= it
->dpvec
+ len
* 4;
4816 it
->current
.dpvec_index
= 0;
4817 it
->method
= next_element_from_display_vector
;
4818 get_next_display_element (it
);
4823 /* Adjust face id for a multibyte character. There are no
4824 multibyte character in unibyte text. */
4827 && FRAME_WINDOW_P (it
->f
))
4829 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4830 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
4834 /* Is this character the last one of a run of characters with
4835 box? If yes, set IT->end_of_box_run_p to 1. */
4842 it
->end_of_box_run_p
4843 = ((face_id
= face_after_it_pos (it
),
4844 face_id
!= it
->face_id
)
4845 && (face
= FACE_FROM_ID (it
->f
, face_id
),
4846 face
->box
== FACE_NO_BOX
));
4849 /* Value is 0 if end of buffer or string reached. */
4854 /* Move IT to the next display element.
4856 RESEAT_P non-zero means if called on a newline in buffer text,
4857 skip to the next visible line start.
4859 Functions get_next_display_element and set_iterator_to_next are
4860 separate because I find this arrangement easier to handle than a
4861 get_next_display_element function that also increments IT's
4862 position. The way it is we can first look at an iterator's current
4863 display element, decide whether it fits on a line, and if it does,
4864 increment the iterator position. The other way around we probably
4865 would either need a flag indicating whether the iterator has to be
4866 incremented the next time, or we would have to implement a
4867 decrement position function which would not be easy to write. */
4870 set_iterator_to_next (it
, reseat_p
)
4874 /* Reset flags indicating start and end of a sequence of characters
4875 with box. Reset them at the start of this function because
4876 moving the iterator to a new position might set them. */
4877 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
4879 if (it
->method
== next_element_from_buffer
)
4881 /* The current display element of IT is a character from
4882 current_buffer. Advance in the buffer, and maybe skip over
4883 invisible lines that are so because of selective display. */
4884 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
4885 reseat_at_next_visible_line_start (it
, 0);
4888 xassert (it
->len
!= 0);
4889 IT_BYTEPOS (*it
) += it
->len
;
4890 IT_CHARPOS (*it
) += 1;
4891 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
4894 else if (it
->method
== next_element_from_composition
)
4896 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
4897 if (STRINGP (it
->string
))
4899 IT_STRING_BYTEPOS (*it
) += it
->len
;
4900 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
4901 it
->method
= next_element_from_string
;
4902 goto consider_string_end
;
4906 IT_BYTEPOS (*it
) += it
->len
;
4907 IT_CHARPOS (*it
) += it
->cmp_len
;
4908 it
->method
= next_element_from_buffer
;
4911 else if (it
->method
== next_element_from_c_string
)
4913 /* Current display element of IT is from a C string. */
4914 IT_BYTEPOS (*it
) += it
->len
;
4915 IT_CHARPOS (*it
) += 1;
4917 else if (it
->method
== next_element_from_display_vector
)
4919 /* Current display element of IT is from a display table entry.
4920 Advance in the display table definition. Reset it to null if
4921 end reached, and continue with characters from buffers/
4923 ++it
->current
.dpvec_index
;
4925 /* Restore face of the iterator to what they were before the
4926 display vector entry (these entries may contain faces). */
4927 it
->face_id
= it
->saved_face_id
;
4929 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
4932 it
->method
= next_element_from_c_string
;
4933 else if (STRINGP (it
->string
))
4934 it
->method
= next_element_from_string
;
4936 it
->method
= next_element_from_buffer
;
4939 it
->current
.dpvec_index
= -1;
4941 /* Skip over characters which were displayed via IT->dpvec. */
4942 if (it
->dpvec_char_len
< 0)
4943 reseat_at_next_visible_line_start (it
, 1);
4944 else if (it
->dpvec_char_len
> 0)
4946 it
->len
= it
->dpvec_char_len
;
4947 set_iterator_to_next (it
, reseat_p
);
4951 else if (it
->method
== next_element_from_string
)
4953 /* Current display element is a character from a Lisp string. */
4954 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
4955 IT_STRING_BYTEPOS (*it
) += it
->len
;
4956 IT_STRING_CHARPOS (*it
) += 1;
4958 consider_string_end
:
4960 if (it
->current
.overlay_string_index
>= 0)
4962 /* IT->string is an overlay string. Advance to the
4963 next, if there is one. */
4964 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
4965 next_overlay_string (it
);
4969 /* IT->string is not an overlay string. If we reached
4970 its end, and there is something on IT->stack, proceed
4971 with what is on the stack. This can be either another
4972 string, this time an overlay string, or a buffer. */
4973 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
4977 if (!STRINGP (it
->string
))
4978 it
->method
= next_element_from_buffer
;
4980 goto consider_string_end
;
4984 else if (it
->method
== next_element_from_image
4985 || it
->method
== next_element_from_stretch
)
4987 /* The position etc with which we have to proceed are on
4988 the stack. The position may be at the end of a string,
4989 if the `display' property takes up the whole string. */
4992 if (STRINGP (it
->string
))
4994 it
->method
= next_element_from_string
;
4995 goto consider_string_end
;
4998 it
->method
= next_element_from_buffer
;
5001 /* There are no other methods defined, so this should be a bug. */
5004 xassert (it
->method
!= next_element_from_string
5005 || (STRINGP (it
->string
)
5006 && IT_STRING_CHARPOS (*it
) >= 0));
5010 /* Load IT's display element fields with information about the next
5011 display element which comes from a display table entry or from the
5012 result of translating a control character to one of the forms `^C'
5013 or `\003'. IT->dpvec holds the glyphs to return as characters. */
5016 next_element_from_display_vector (it
)
5020 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5022 /* Remember the current face id in case glyphs specify faces.
5023 IT's face is restored in set_iterator_to_next. */
5024 it
->saved_face_id
= it
->face_id
;
5026 if (INTEGERP (*it
->dpvec
)
5027 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5032 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5033 it
->c
= FAST_GLYPH_CHAR (g
);
5034 it
->len
= CHAR_BYTES (it
->c
);
5036 /* The entry may contain a face id to use. Such a face id is
5037 the id of a Lisp face, not a realized face. A face id of
5038 zero means no face is specified. */
5039 lface_id
= FAST_GLYPH_FACE (g
);
5042 /* The function returns -1 if lface_id is invalid. */
5043 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
5045 it
->face_id
= face_id
;
5049 /* Display table entry is invalid. Return a space. */
5050 it
->c
= ' ', it
->len
= 1;
5052 /* Don't change position and object of the iterator here. They are
5053 still the values of the character that had this display table
5054 entry or was translated, and that's what we want. */
5055 it
->what
= IT_CHARACTER
;
5060 /* Load IT with the next display element from Lisp string IT->string.
5061 IT->current.string_pos is the current position within the string.
5062 If IT->current.overlay_string_index >= 0, the Lisp string is an
5066 next_element_from_string (it
)
5069 struct text_pos position
;
5071 xassert (STRINGP (it
->string
));
5072 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5073 position
= it
->current
.string_pos
;
5075 /* Time to check for invisible text? */
5076 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5077 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5081 /* Since a handler may have changed IT->method, we must
5083 return get_next_display_element (it
);
5086 if (it
->current
.overlay_string_index
>= 0)
5088 /* Get the next character from an overlay string. In overlay
5089 strings, There is no field width or padding with spaces to
5091 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5096 else if (STRING_MULTIBYTE (it
->string
))
5098 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5099 const unsigned char *s
= (SDATA (it
->string
)
5100 + IT_STRING_BYTEPOS (*it
));
5101 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5105 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5111 /* Get the next character from a Lisp string that is not an
5112 overlay string. Such strings come from the mode line, for
5113 example. We may have to pad with spaces, or truncate the
5114 string. See also next_element_from_c_string. */
5115 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5120 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5122 /* Pad with spaces. */
5123 it
->c
= ' ', it
->len
= 1;
5124 CHARPOS (position
) = BYTEPOS (position
) = -1;
5126 else if (STRING_MULTIBYTE (it
->string
))
5128 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5129 const unsigned char *s
= (SDATA (it
->string
)
5130 + IT_STRING_BYTEPOS (*it
));
5131 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5135 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5140 /* Record what we have and where it came from. Note that we store a
5141 buffer position in IT->position although it could arguably be a
5143 it
->what
= IT_CHARACTER
;
5144 it
->object
= it
->string
;
5145 it
->position
= position
;
5150 /* Load IT with next display element from C string IT->s.
5151 IT->string_nchars is the maximum number of characters to return
5152 from the string. IT->end_charpos may be greater than
5153 IT->string_nchars when this function is called, in which case we
5154 may have to return padding spaces. Value is zero if end of string
5155 reached, including padding spaces. */
5158 next_element_from_c_string (it
)
5164 it
->what
= IT_CHARACTER
;
5165 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5168 /* IT's position can be greater IT->string_nchars in case a field
5169 width or precision has been specified when the iterator was
5171 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5173 /* End of the game. */
5177 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5179 /* Pad with spaces. */
5180 it
->c
= ' ', it
->len
= 1;
5181 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5183 else if (it
->multibyte_p
)
5185 /* Implementation note: The calls to strlen apparently aren't a
5186 performance problem because there is no noticeable performance
5187 difference between Emacs running in unibyte or multibyte mode. */
5188 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5189 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5193 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5199 /* Set up IT to return characters from an ellipsis, if appropriate.
5200 The definition of the ellipsis glyphs may come from a display table
5201 entry. This function Fills IT with the first glyph from the
5202 ellipsis if an ellipsis is to be displayed. */
5205 next_element_from_ellipsis (it
)
5208 if (it
->selective_display_ellipsis_p
)
5210 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
5212 /* Use the display table definition for `...'. Invalid glyphs
5213 will be handled by the method returning elements from dpvec. */
5214 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
5215 it
->dpvec_char_len
= it
->len
;
5216 it
->dpvec
= v
->contents
;
5217 it
->dpend
= v
->contents
+ v
->size
;
5218 it
->current
.dpvec_index
= 0;
5219 it
->method
= next_element_from_display_vector
;
5223 /* Use default `...' which is stored in default_invis_vector. */
5224 it
->dpvec_char_len
= it
->len
;
5225 it
->dpvec
= default_invis_vector
;
5226 it
->dpend
= default_invis_vector
+ 3;
5227 it
->current
.dpvec_index
= 0;
5228 it
->method
= next_element_from_display_vector
;
5233 /* The face at the current position may be different from the
5234 face we find after the invisible text. Remember what it
5235 was in IT->saved_face_id, and signal that it's there by
5236 setting face_before_selective_p. */
5237 it
->saved_face_id
= it
->face_id
;
5238 it
->method
= next_element_from_buffer
;
5239 reseat_at_next_visible_line_start (it
, 1);
5240 it
->face_before_selective_p
= 1;
5243 return get_next_display_element (it
);
5247 /* Deliver an image display element. The iterator IT is already
5248 filled with image information (done in handle_display_prop). Value
5253 next_element_from_image (it
)
5256 it
->what
= IT_IMAGE
;
5261 /* Fill iterator IT with next display element from a stretch glyph
5262 property. IT->object is the value of the text property. Value is
5266 next_element_from_stretch (it
)
5269 it
->what
= IT_STRETCH
;
5274 /* Load IT with the next display element from current_buffer. Value
5275 is zero if end of buffer reached. IT->stop_charpos is the next
5276 position at which to stop and check for text properties or buffer
5280 next_element_from_buffer (it
)
5285 /* Check this assumption, otherwise, we would never enter the
5286 if-statement, below. */
5287 xassert (IT_CHARPOS (*it
) >= BEGV
5288 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5290 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5292 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5294 int overlay_strings_follow_p
;
5296 /* End of the game, except when overlay strings follow that
5297 haven't been returned yet. */
5298 if (it
->overlay_strings_at_end_processed_p
)
5299 overlay_strings_follow_p
= 0;
5302 it
->overlay_strings_at_end_processed_p
= 1;
5303 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5306 if (overlay_strings_follow_p
)
5307 success_p
= get_next_display_element (it
);
5311 it
->position
= it
->current
.pos
;
5318 return get_next_display_element (it
);
5323 /* No face changes, overlays etc. in sight, so just return a
5324 character from current_buffer. */
5327 /* Maybe run the redisplay end trigger hook. Performance note:
5328 This doesn't seem to cost measurable time. */
5329 if (it
->redisplay_end_trigger_charpos
5331 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5332 run_redisplay_end_trigger_hook (it
);
5334 /* Get the next character, maybe multibyte. */
5335 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5336 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5338 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5339 - IT_BYTEPOS (*it
));
5340 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5343 it
->c
= *p
, it
->len
= 1;
5345 /* Record what we have and where it came from. */
5346 it
->what
= IT_CHARACTER
;;
5347 it
->object
= it
->w
->buffer
;
5348 it
->position
= it
->current
.pos
;
5350 /* Normally we return the character found above, except when we
5351 really want to return an ellipsis for selective display. */
5356 /* A value of selective > 0 means hide lines indented more
5357 than that number of columns. */
5358 if (it
->selective
> 0
5359 && IT_CHARPOS (*it
) + 1 < ZV
5360 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5361 IT_BYTEPOS (*it
) + 1,
5362 (double) it
->selective
)) /* iftc */
5364 success_p
= next_element_from_ellipsis (it
);
5365 it
->dpvec_char_len
= -1;
5368 else if (it
->c
== '\r' && it
->selective
== -1)
5370 /* A value of selective == -1 means that everything from the
5371 CR to the end of the line is invisible, with maybe an
5372 ellipsis displayed for it. */
5373 success_p
= next_element_from_ellipsis (it
);
5374 it
->dpvec_char_len
= -1;
5379 /* Value is zero if end of buffer reached. */
5380 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5385 /* Run the redisplay end trigger hook for IT. */
5388 run_redisplay_end_trigger_hook (it
)
5391 Lisp_Object args
[3];
5393 /* IT->glyph_row should be non-null, i.e. we should be actually
5394 displaying something, or otherwise we should not run the hook. */
5395 xassert (it
->glyph_row
);
5397 /* Set up hook arguments. */
5398 args
[0] = Qredisplay_end_trigger_functions
;
5399 args
[1] = it
->window
;
5400 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5401 it
->redisplay_end_trigger_charpos
= 0;
5403 /* Since we are *trying* to run these functions, don't try to run
5404 them again, even if they get an error. */
5405 it
->w
->redisplay_end_trigger
= Qnil
;
5406 Frun_hook_with_args (3, args
);
5408 /* Notice if it changed the face of the character we are on. */
5409 handle_face_prop (it
);
5413 /* Deliver a composition display element. The iterator IT is already
5414 filled with composition information (done in
5415 handle_composition_prop). Value is always 1. */
5418 next_element_from_composition (it
)
5421 it
->what
= IT_COMPOSITION
;
5422 it
->position
= (STRINGP (it
->string
)
5423 ? it
->current
.string_pos
5430 /***********************************************************************
5431 Moving an iterator without producing glyphs
5432 ***********************************************************************/
5434 /* Move iterator IT to a specified buffer or X position within one
5435 line on the display without producing glyphs.
5437 OP should be a bit mask including some or all of these bits:
5438 MOVE_TO_X: Stop on reaching x-position TO_X.
5439 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5440 Regardless of OP's value, stop in reaching the end of the display line.
5442 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5443 This means, in particular, that TO_X includes window's horizontal
5446 The return value has several possible values that
5447 say what condition caused the scan to stop:
5449 MOVE_POS_MATCH_OR_ZV
5450 - when TO_POS or ZV was reached.
5453 -when TO_X was reached before TO_POS or ZV were reached.
5456 - when we reached the end of the display area and the line must
5460 - when we reached the end of the display area and the line is
5464 - when we stopped at a line end, i.e. a newline or a CR and selective
5467 static enum move_it_result
5468 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5470 int to_charpos
, to_x
, op
;
5472 enum move_it_result result
= MOVE_UNDEFINED
;
5473 struct glyph_row
*saved_glyph_row
;
5475 /* Don't produce glyphs in produce_glyphs. */
5476 saved_glyph_row
= it
->glyph_row
;
5477 it
->glyph_row
= NULL
;
5481 int x
, i
, ascent
= 0, descent
= 0;
5483 /* Stop when ZV or TO_CHARPOS reached. */
5484 if (!get_next_display_element (it
)
5485 || ((op
& MOVE_TO_POS
) != 0
5486 && BUFFERP (it
->object
)
5487 && IT_CHARPOS (*it
) >= to_charpos
))
5489 result
= MOVE_POS_MATCH_OR_ZV
;
5493 /* The call to produce_glyphs will get the metrics of the
5494 display element IT is loaded with. We record in x the
5495 x-position before this display element in case it does not
5499 /* Remember the line height so far in case the next element doesn't
5501 if (!it
->truncate_lines_p
)
5503 ascent
= it
->max_ascent
;
5504 descent
= it
->max_descent
;
5507 PRODUCE_GLYPHS (it
);
5509 if (it
->area
!= TEXT_AREA
)
5511 set_iterator_to_next (it
, 1);
5515 /* The number of glyphs we get back in IT->nglyphs will normally
5516 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5517 character on a terminal frame, or (iii) a line end. For the
5518 second case, IT->nglyphs - 1 padding glyphs will be present
5519 (on X frames, there is only one glyph produced for a
5520 composite character.
5522 The behavior implemented below means, for continuation lines,
5523 that as many spaces of a TAB as fit on the current line are
5524 displayed there. For terminal frames, as many glyphs of a
5525 multi-glyph character are displayed in the current line, too.
5526 This is what the old redisplay code did, and we keep it that
5527 way. Under X, the whole shape of a complex character must
5528 fit on the line or it will be completely displayed in the
5531 Note that both for tabs and padding glyphs, all glyphs have
5535 /* More than one glyph or glyph doesn't fit on line. All
5536 glyphs have the same width. */
5537 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
5540 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
5542 new_x
= x
+ single_glyph_width
;
5544 /* We want to leave anything reaching TO_X to the caller. */
5545 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
5548 result
= MOVE_X_REACHED
;
5551 else if (/* Lines are continued. */
5552 !it
->truncate_lines_p
5553 && (/* And glyph doesn't fit on the line. */
5554 new_x
> it
->last_visible_x
5555 /* Or it fits exactly and we're on a window
5557 || (new_x
== it
->last_visible_x
5558 && FRAME_WINDOW_P (it
->f
))))
5560 if (/* IT->hpos == 0 means the very first glyph
5561 doesn't fit on the line, e.g. a wide image. */
5563 || (new_x
== it
->last_visible_x
5564 && FRAME_WINDOW_P (it
->f
)))
5567 it
->current_x
= new_x
;
5568 if (i
== it
->nglyphs
- 1)
5569 set_iterator_to_next (it
, 1);
5574 it
->max_ascent
= ascent
;
5575 it
->max_descent
= descent
;
5578 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
5580 result
= MOVE_LINE_CONTINUED
;
5583 else if (new_x
> it
->first_visible_x
)
5585 /* Glyph is visible. Increment number of glyphs that
5586 would be displayed. */
5591 /* Glyph is completely off the left margin of the display
5592 area. Nothing to do. */
5596 if (result
!= MOVE_UNDEFINED
)
5599 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
5601 /* Stop when TO_X specified and reached. This check is
5602 necessary here because of lines consisting of a line end,
5603 only. The line end will not produce any glyphs and we
5604 would never get MOVE_X_REACHED. */
5605 xassert (it
->nglyphs
== 0);
5606 result
= MOVE_X_REACHED
;
5610 /* Is this a line end? If yes, we're done. */
5611 if (ITERATOR_AT_END_OF_LINE_P (it
))
5613 result
= MOVE_NEWLINE_OR_CR
;
5617 /* The current display element has been consumed. Advance
5619 set_iterator_to_next (it
, 1);
5621 /* Stop if lines are truncated and IT's current x-position is
5622 past the right edge of the window now. */
5623 if (it
->truncate_lines_p
5624 && it
->current_x
>= it
->last_visible_x
)
5626 result
= MOVE_LINE_TRUNCATED
;
5631 /* Restore the iterator settings altered at the beginning of this
5633 it
->glyph_row
= saved_glyph_row
;
5638 /* Move IT forward until it satisfies one or more of the criteria in
5639 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
5641 OP is a bit-mask that specifies where to stop, and in particular,
5642 which of those four position arguments makes a difference. See the
5643 description of enum move_operation_enum.
5645 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
5646 screen line, this function will set IT to the next position >
5650 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
5652 int to_charpos
, to_x
, to_y
, to_vpos
;
5655 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
5661 if (op
& MOVE_TO_VPOS
)
5663 /* If no TO_CHARPOS and no TO_X specified, stop at the
5664 start of the line TO_VPOS. */
5665 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
5667 if (it
->vpos
== to_vpos
)
5673 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
5677 /* TO_VPOS >= 0 means stop at TO_X in the line at
5678 TO_VPOS, or at TO_POS, whichever comes first. */
5679 if (it
->vpos
== to_vpos
)
5685 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
5687 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
5692 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
5694 /* We have reached TO_X but not in the line we want. */
5695 skip
= move_it_in_display_line_to (it
, to_charpos
,
5697 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5705 else if (op
& MOVE_TO_Y
)
5707 struct it it_backup
;
5709 /* TO_Y specified means stop at TO_X in the line containing
5710 TO_Y---or at TO_CHARPOS if this is reached first. The
5711 problem is that we can't really tell whether the line
5712 contains TO_Y before we have completely scanned it, and
5713 this may skip past TO_X. What we do is to first scan to
5716 If TO_X is not specified, use a TO_X of zero. The reason
5717 is to make the outcome of this function more predictable.
5718 If we didn't use TO_X == 0, we would stop at the end of
5719 the line which is probably not what a caller would expect
5721 skip
= move_it_in_display_line_to (it
, to_charpos
,
5725 | (op
& MOVE_TO_POS
)));
5727 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
5728 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5734 /* If TO_X was reached, we would like to know whether TO_Y
5735 is in the line. This can only be said if we know the
5736 total line height which requires us to scan the rest of
5738 if (skip
== MOVE_X_REACHED
)
5741 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
5742 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
5744 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
5747 /* Now, decide whether TO_Y is in this line. */
5748 line_height
= it
->max_ascent
+ it
->max_descent
;
5749 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
5751 if (to_y
>= it
->current_y
5752 && to_y
< it
->current_y
+ line_height
)
5754 if (skip
== MOVE_X_REACHED
)
5755 /* If TO_Y is in this line and TO_X was reached above,
5756 we scanned too far. We have to restore IT's settings
5757 to the ones before skipping. */
5761 else if (skip
== MOVE_X_REACHED
)
5764 if (skip
== MOVE_POS_MATCH_OR_ZV
)
5772 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
5776 case MOVE_POS_MATCH_OR_ZV
:
5780 case MOVE_NEWLINE_OR_CR
:
5781 set_iterator_to_next (it
, 1);
5782 it
->continuation_lines_width
= 0;
5785 case MOVE_LINE_TRUNCATED
:
5786 it
->continuation_lines_width
= 0;
5787 reseat_at_next_visible_line_start (it
, 0);
5788 if ((op
& MOVE_TO_POS
) != 0
5789 && IT_CHARPOS (*it
) > to_charpos
)
5796 case MOVE_LINE_CONTINUED
:
5797 it
->continuation_lines_width
+= it
->current_x
;
5804 /* Reset/increment for the next run. */
5805 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
5806 it
->current_x
= it
->hpos
= 0;
5807 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
5809 last_height
= it
->max_ascent
+ it
->max_descent
;
5810 last_max_ascent
= it
->max_ascent
;
5811 it
->max_ascent
= it
->max_descent
= 0;
5816 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
5820 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
5822 If DY > 0, move IT backward at least that many pixels. DY = 0
5823 means move IT backward to the preceding line start or BEGV. This
5824 function may move over more than DY pixels if IT->current_y - DY
5825 ends up in the middle of a line; in this case IT->current_y will be
5826 set to the top of the line moved to. */
5829 move_it_vertically_backward (it
, dy
)
5835 int start_pos
= IT_CHARPOS (*it
);
5839 /* Estimate how many newlines we must move back. */
5840 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
5842 /* Set the iterator's position that many lines back. */
5843 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
5844 back_to_previous_visible_line_start (it
);
5846 /* Reseat the iterator here. When moving backward, we don't want
5847 reseat to skip forward over invisible text, set up the iterator
5848 to deliver from overlay strings at the new position etc. So,
5849 use reseat_1 here. */
5850 reseat_1 (it
, it
->current
.pos
, 1);
5852 /* We are now surely at a line start. */
5853 it
->current_x
= it
->hpos
= 0;
5854 it
->continuation_lines_width
= 0;
5856 /* Move forward and see what y-distance we moved. First move to the
5857 start of the next line so that we get its height. We need this
5858 height to be able to tell whether we reached the specified
5861 it2
.max_ascent
= it2
.max_descent
= 0;
5862 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
5863 MOVE_TO_POS
| MOVE_TO_VPOS
);
5864 xassert (IT_CHARPOS (*it
) >= BEGV
);
5867 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
5868 xassert (IT_CHARPOS (*it
) >= BEGV
);
5869 /* H is the actual vertical distance from the position in *IT
5870 and the starting position. */
5871 h
= it2
.current_y
- it
->current_y
;
5872 /* NLINES is the distance in number of lines. */
5873 nlines
= it2
.vpos
- it
->vpos
;
5875 /* Correct IT's y and vpos position
5876 so that they are relative to the starting point. */
5882 /* DY == 0 means move to the start of the screen line. The
5883 value of nlines is > 0 if continuation lines were involved. */
5885 move_it_by_lines (it
, nlines
, 1);
5886 xassert (IT_CHARPOS (*it
) <= start_pos
);
5890 /* The y-position we try to reach, relative to *IT.
5891 Note that H has been subtracted in front of the if-statement. */
5892 int target_y
= it
->current_y
+ h
- dy
;
5893 int y0
= it3
.current_y
;
5894 int y1
= line_bottom_y (&it3
);
5895 int line_height
= y1
- y0
;
5897 /* If we did not reach target_y, try to move further backward if
5898 we can. If we moved too far backward, try to move forward. */
5899 if (target_y
< it
->current_y
5900 /* This is heuristic. In a window that's 3 lines high, with
5901 a line height of 13 pixels each, recentering with point
5902 on the bottom line will try to move -39/2 = 19 pixels
5903 backward. Try to avoid moving into the first line. */
5904 && it
->current_y
- target_y
> line_height
/ 3 * 2
5905 && IT_CHARPOS (*it
) > BEGV
)
5907 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
5908 target_y
- it
->current_y
));
5909 move_it_vertically (it
, target_y
- it
->current_y
);
5910 xassert (IT_CHARPOS (*it
) >= BEGV
);
5912 else if (target_y
>= it
->current_y
+ line_height
5913 && IT_CHARPOS (*it
) < ZV
)
5915 /* Should move forward by at least one line, maybe more.
5917 Note: Calling move_it_by_lines can be expensive on
5918 terminal frames, where compute_motion is used (via
5919 vmotion) to do the job, when there are very long lines
5920 and truncate-lines is nil. That's the reason for
5921 treating terminal frames specially here. */
5923 if (!FRAME_WINDOW_P (it
->f
))
5924 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
5929 move_it_by_lines (it
, 1, 1);
5931 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
5934 xassert (IT_CHARPOS (*it
) >= BEGV
);
5940 /* Move IT by a specified amount of pixel lines DY. DY negative means
5941 move backwards. DY = 0 means move to start of screen line. At the
5942 end, IT will be on the start of a screen line. */
5945 move_it_vertically (it
, dy
)
5950 move_it_vertically_backward (it
, -dy
);
5953 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
5954 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
5955 MOVE_TO_POS
| MOVE_TO_Y
);
5956 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
5958 /* If buffer ends in ZV without a newline, move to the start of
5959 the line to satisfy the post-condition. */
5960 if (IT_CHARPOS (*it
) == ZV
5961 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
5962 move_it_by_lines (it
, 0, 0);
5967 /* Move iterator IT past the end of the text line it is in. */
5970 move_it_past_eol (it
)
5973 enum move_it_result rc
;
5975 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
5976 if (rc
== MOVE_NEWLINE_OR_CR
)
5977 set_iterator_to_next (it
, 0);
5981 #if 0 /* Currently not used. */
5983 /* Return non-zero if some text between buffer positions START_CHARPOS
5984 and END_CHARPOS is invisible. IT->window is the window for text
5988 invisible_text_between_p (it
, start_charpos
, end_charpos
)
5990 int start_charpos
, end_charpos
;
5992 Lisp_Object prop
, limit
;
5993 int invisible_found_p
;
5995 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
5997 /* Is text at START invisible? */
5998 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6000 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6001 invisible_found_p
= 1;
6004 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6006 make_number (end_charpos
));
6007 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6010 return invisible_found_p
;
6016 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6017 negative means move up. DVPOS == 0 means move to the start of the
6018 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6019 NEED_Y_P is zero, IT->current_y will be left unchanged.
6021 Further optimization ideas: If we would know that IT->f doesn't use
6022 a face with proportional font, we could be faster for
6023 truncate-lines nil. */
6026 move_it_by_lines (it
, dvpos
, need_y_p
)
6028 int dvpos
, need_y_p
;
6030 struct position pos
;
6032 if (!FRAME_WINDOW_P (it
->f
))
6034 struct text_pos textpos
;
6036 /* We can use vmotion on frames without proportional fonts. */
6037 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6038 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6039 reseat (it
, textpos
, 1);
6040 it
->vpos
+= pos
.vpos
;
6041 it
->current_y
+= pos
.vpos
;
6043 else if (dvpos
== 0)
6045 /* DVPOS == 0 means move to the start of the screen line. */
6046 move_it_vertically_backward (it
, 0);
6047 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6050 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6054 int start_charpos
, i
;
6056 /* Start at the beginning of the screen line containing IT's
6058 move_it_vertically_backward (it
, 0);
6060 /* Go back -DVPOS visible lines and reseat the iterator there. */
6061 start_charpos
= IT_CHARPOS (*it
);
6062 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6063 back_to_previous_visible_line_start (it
);
6064 reseat (it
, it
->current
.pos
, 1);
6065 it
->current_x
= it
->hpos
= 0;
6067 /* Above call may have moved too far if continuation lines
6068 are involved. Scan forward and see if it did. */
6070 it2
.vpos
= it2
.current_y
= 0;
6071 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6072 it
->vpos
-= it2
.vpos
;
6073 it
->current_y
-= it2
.current_y
;
6074 it
->current_x
= it
->hpos
= 0;
6076 /* If we moved too far, move IT some lines forward. */
6077 if (it2
.vpos
> -dvpos
)
6079 int delta
= it2
.vpos
+ dvpos
;
6080 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6085 /* Return 1 if IT points into the middle of a display vector. */
6088 in_display_vector_p (it
)
6091 return (it
->method
== next_element_from_display_vector
6092 && it
->current
.dpvec_index
> 0
6093 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6097 /***********************************************************************
6099 ***********************************************************************/
6102 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6106 add_to_log (format
, arg1
, arg2
)
6108 Lisp_Object arg1
, arg2
;
6110 Lisp_Object args
[3];
6111 Lisp_Object msg
, fmt
;
6114 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6116 /* Do nothing if called asynchronously. Inserting text into
6117 a buffer may call after-change-functions and alike and
6118 that would means running Lisp asynchronously. */
6119 if (handling_signal
)
6123 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6125 args
[0] = fmt
= build_string (format
);
6128 msg
= Fformat (3, args
);
6130 len
= SBYTES (msg
) + 1;
6131 buffer
= (char *) alloca (len
);
6132 bcopy (SDATA (msg
), buffer
, len
);
6134 message_dolog (buffer
, len
- 1, 1, 0);
6139 /* Output a newline in the *Messages* buffer if "needs" one. */
6142 message_log_maybe_newline ()
6144 if (message_log_need_newline
)
6145 message_dolog ("", 0, 1, 0);
6149 /* Add a string M of length NBYTES to the message log, optionally
6150 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6151 nonzero, means interpret the contents of M as multibyte. This
6152 function calls low-level routines in order to bypass text property
6153 hooks, etc. which might not be safe to run. */
6156 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6158 int nbytes
, nlflag
, multibyte
;
6160 if (!NILP (Vmemory_full
))
6163 if (!NILP (Vmessage_log_max
))
6165 struct buffer
*oldbuf
;
6166 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6167 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6168 int point_at_end
= 0;
6170 Lisp_Object old_deactivate_mark
, tem
;
6171 struct gcpro gcpro1
;
6173 old_deactivate_mark
= Vdeactivate_mark
;
6174 oldbuf
= current_buffer
;
6175 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6176 current_buffer
->undo_list
= Qt
;
6178 oldpoint
= message_dolog_marker1
;
6179 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6180 oldbegv
= message_dolog_marker2
;
6181 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6182 oldzv
= message_dolog_marker3
;
6183 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6184 GCPRO1 (old_deactivate_mark
);
6192 BEGV_BYTE
= BEG_BYTE
;
6195 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6197 /* Insert the string--maybe converting multibyte to single byte
6198 or vice versa, so that all the text fits the buffer. */
6200 && NILP (current_buffer
->enable_multibyte_characters
))
6202 int i
, c
, char_bytes
;
6203 unsigned char work
[1];
6205 /* Convert a multibyte string to single-byte
6206 for the *Message* buffer. */
6207 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6209 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6210 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6212 : multibyte_char_to_unibyte (c
, Qnil
));
6213 insert_1_both (work
, 1, 1, 1, 0, 0);
6216 else if (! multibyte
6217 && ! NILP (current_buffer
->enable_multibyte_characters
))
6219 int i
, c
, char_bytes
;
6220 unsigned char *msg
= (unsigned char *) m
;
6221 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6222 /* Convert a single-byte string to multibyte
6223 for the *Message* buffer. */
6224 for (i
= 0; i
< nbytes
; i
++)
6226 c
= unibyte_char_to_multibyte (msg
[i
]);
6227 char_bytes
= CHAR_STRING (c
, str
);
6228 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6232 insert_1 (m
, nbytes
, 1, 0, 0);
6236 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6237 insert_1 ("\n", 1, 1, 0, 0);
6239 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6241 this_bol_byte
= PT_BYTE
;
6243 /* See if this line duplicates the previous one.
6244 If so, combine duplicates. */
6247 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6249 prev_bol_byte
= PT_BYTE
;
6251 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6252 this_bol
, this_bol_byte
);
6255 del_range_both (prev_bol
, prev_bol_byte
,
6256 this_bol
, this_bol_byte
, 0);
6262 /* If you change this format, don't forget to also
6263 change message_log_check_duplicate. */
6264 sprintf (dupstr
, " [%d times]", dup
);
6265 duplen
= strlen (dupstr
);
6266 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6267 insert_1 (dupstr
, duplen
, 1, 0, 1);
6272 /* If we have more than the desired maximum number of lines
6273 in the *Messages* buffer now, delete the oldest ones.
6274 This is safe because we don't have undo in this buffer. */
6276 if (NATNUMP (Vmessage_log_max
))
6278 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6279 -XFASTINT (Vmessage_log_max
) - 1, 0);
6280 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6283 BEGV
= XMARKER (oldbegv
)->charpos
;
6284 BEGV_BYTE
= marker_byte_position (oldbegv
);
6293 ZV
= XMARKER (oldzv
)->charpos
;
6294 ZV_BYTE
= marker_byte_position (oldzv
);
6298 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6300 /* We can't do Fgoto_char (oldpoint) because it will run some
6302 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6303 XMARKER (oldpoint
)->bytepos
);
6306 unchain_marker (XMARKER (oldpoint
));
6307 unchain_marker (XMARKER (oldbegv
));
6308 unchain_marker (XMARKER (oldzv
));
6310 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6311 set_buffer_internal (oldbuf
);
6313 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6314 message_log_need_newline
= !nlflag
;
6315 Vdeactivate_mark
= old_deactivate_mark
;
6320 /* We are at the end of the buffer after just having inserted a newline.
6321 (Note: We depend on the fact we won't be crossing the gap.)
6322 Check to see if the most recent message looks a lot like the previous one.
6323 Return 0 if different, 1 if the new one should just replace it, or a
6324 value N > 1 if we should also append " [N times]". */
6327 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6328 int prev_bol
, this_bol
;
6329 int prev_bol_byte
, this_bol_byte
;
6332 int len
= Z_BYTE
- 1 - this_bol_byte
;
6334 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6335 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6337 for (i
= 0; i
< len
; i
++)
6339 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6347 if (*p1
++ == ' ' && *p1
++ == '[')
6350 while (*p1
>= '0' && *p1
<= '9')
6351 n
= n
* 10 + *p1
++ - '0';
6352 if (strncmp (p1
, " times]\n", 8) == 0)
6359 /* Display an echo area message M with a specified length of NBYTES
6360 bytes. The string may include null characters. If M is 0, clear
6361 out any existing message, and let the mini-buffer text show
6364 The buffer M must continue to exist until after the echo area gets
6365 cleared or some other message gets displayed there. This means do
6366 not pass text that is stored in a Lisp string; do not pass text in
6367 a buffer that was alloca'd. */
6370 message2 (m
, nbytes
, multibyte
)
6375 /* First flush out any partial line written with print. */
6376 message_log_maybe_newline ();
6378 message_dolog (m
, nbytes
, 1, multibyte
);
6379 message2_nolog (m
, nbytes
, multibyte
);
6383 /* The non-logging counterpart of message2. */
6386 message2_nolog (m
, nbytes
, multibyte
)
6388 int nbytes
, multibyte
;
6390 struct frame
*sf
= SELECTED_FRAME ();
6391 message_enable_multibyte
= multibyte
;
6395 if (noninteractive_need_newline
)
6396 putc ('\n', stderr
);
6397 noninteractive_need_newline
= 0;
6399 fwrite (m
, nbytes
, 1, stderr
);
6400 if (cursor_in_echo_area
== 0)
6401 fprintf (stderr
, "\n");
6404 /* A null message buffer means that the frame hasn't really been
6405 initialized yet. Error messages get reported properly by
6406 cmd_error, so this must be just an informative message; toss it. */
6407 else if (INTERACTIVE
6408 && sf
->glyphs_initialized_p
6409 && FRAME_MESSAGE_BUF (sf
))
6411 Lisp_Object mini_window
;
6414 /* Get the frame containing the mini-buffer
6415 that the selected frame is using. */
6416 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6417 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6419 FRAME_SAMPLE_VISIBILITY (f
);
6420 if (FRAME_VISIBLE_P (sf
)
6421 && ! FRAME_VISIBLE_P (f
))
6422 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6426 set_message (m
, Qnil
, nbytes
, multibyte
);
6427 if (minibuffer_auto_raise
)
6428 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6431 clear_message (1, 1);
6433 do_pending_window_change (0);
6434 echo_area_display (1);
6435 do_pending_window_change (0);
6436 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6437 (*frame_up_to_date_hook
) (f
);
6442 /* Display an echo area message M with a specified length of NBYTES
6443 bytes. The string may include null characters. If M is not a
6444 string, clear out any existing message, and let the mini-buffer
6445 text show through. */
6448 message3 (m
, nbytes
, multibyte
)
6453 struct gcpro gcpro1
;
6457 /* First flush out any partial line written with print. */
6458 message_log_maybe_newline ();
6460 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
6461 message3_nolog (m
, nbytes
, multibyte
);
6467 /* The non-logging version of message3. */
6470 message3_nolog (m
, nbytes
, multibyte
)
6472 int nbytes
, multibyte
;
6474 struct frame
*sf
= SELECTED_FRAME ();
6475 message_enable_multibyte
= multibyte
;
6479 if (noninteractive_need_newline
)
6480 putc ('\n', stderr
);
6481 noninteractive_need_newline
= 0;
6483 fwrite (SDATA (m
), nbytes
, 1, stderr
);
6484 if (cursor_in_echo_area
== 0)
6485 fprintf (stderr
, "\n");
6488 /* A null message buffer means that the frame hasn't really been
6489 initialized yet. Error messages get reported properly by
6490 cmd_error, so this must be just an informative message; toss it. */
6491 else if (INTERACTIVE
6492 && sf
->glyphs_initialized_p
6493 && FRAME_MESSAGE_BUF (sf
))
6495 Lisp_Object mini_window
;
6499 /* Get the frame containing the mini-buffer
6500 that the selected frame is using. */
6501 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6502 frame
= XWINDOW (mini_window
)->frame
;
6505 FRAME_SAMPLE_VISIBILITY (f
);
6506 if (FRAME_VISIBLE_P (sf
)
6507 && !FRAME_VISIBLE_P (f
))
6508 Fmake_frame_visible (frame
);
6510 if (STRINGP (m
) && SCHARS (m
) > 0)
6512 set_message (NULL
, m
, nbytes
, multibyte
);
6513 if (minibuffer_auto_raise
)
6514 Fraise_frame (frame
);
6517 clear_message (1, 1);
6519 do_pending_window_change (0);
6520 echo_area_display (1);
6521 do_pending_window_change (0);
6522 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6523 (*frame_up_to_date_hook
) (f
);
6528 /* Display a null-terminated echo area message M. If M is 0, clear
6529 out any existing message, and let the mini-buffer text show through.
6531 The buffer M must continue to exist until after the echo area gets
6532 cleared or some other message gets displayed there. Do not pass
6533 text that is stored in a Lisp string. Do not pass text in a buffer
6534 that was alloca'd. */
6540 message2 (m
, (m
? strlen (m
) : 0), 0);
6544 /* The non-logging counterpart of message1. */
6550 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
6553 /* Display a message M which contains a single %s
6554 which gets replaced with STRING. */
6557 message_with_string (m
, string
, log
)
6562 CHECK_STRING (string
);
6568 if (noninteractive_need_newline
)
6569 putc ('\n', stderr
);
6570 noninteractive_need_newline
= 0;
6571 fprintf (stderr
, m
, SDATA (string
));
6572 if (cursor_in_echo_area
== 0)
6573 fprintf (stderr
, "\n");
6577 else if (INTERACTIVE
)
6579 /* The frame whose minibuffer we're going to display the message on.
6580 It may be larger than the selected frame, so we need
6581 to use its buffer, not the selected frame's buffer. */
6582 Lisp_Object mini_window
;
6583 struct frame
*f
, *sf
= SELECTED_FRAME ();
6585 /* Get the frame containing the minibuffer
6586 that the selected frame is using. */
6587 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6588 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6590 /* A null message buffer means that the frame hasn't really been
6591 initialized yet. Error messages get reported properly by
6592 cmd_error, so this must be just an informative message; toss it. */
6593 if (FRAME_MESSAGE_BUF (f
))
6595 Lisp_Object args
[2], message
;
6596 struct gcpro gcpro1
, gcpro2
;
6598 args
[0] = build_string (m
);
6599 args
[1] = message
= string
;
6600 GCPRO2 (args
[0], message
);
6603 message
= Fformat (2, args
);
6606 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6608 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
6612 /* Print should start at the beginning of the message
6613 buffer next time. */
6614 message_buf_print
= 0;
6620 /* Dump an informative message to the minibuf. If M is 0, clear out
6621 any existing message, and let the mini-buffer text show through. */
6625 message (m
, a1
, a2
, a3
)
6627 EMACS_INT a1
, a2
, a3
;
6633 if (noninteractive_need_newline
)
6634 putc ('\n', stderr
);
6635 noninteractive_need_newline
= 0;
6636 fprintf (stderr
, m
, a1
, a2
, a3
);
6637 if (cursor_in_echo_area
== 0)
6638 fprintf (stderr
, "\n");
6642 else if (INTERACTIVE
)
6644 /* The frame whose mini-buffer we're going to display the message
6645 on. It may be larger than the selected frame, so we need to
6646 use its buffer, not the selected frame's buffer. */
6647 Lisp_Object mini_window
;
6648 struct frame
*f
, *sf
= SELECTED_FRAME ();
6650 /* Get the frame containing the mini-buffer
6651 that the selected frame is using. */
6652 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6653 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6655 /* A null message buffer means that the frame hasn't really been
6656 initialized yet. Error messages get reported properly by
6657 cmd_error, so this must be just an informative message; toss
6659 if (FRAME_MESSAGE_BUF (f
))
6670 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6671 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
6673 len
= doprnt (FRAME_MESSAGE_BUF (f
),
6674 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
6676 #endif /* NO_ARG_ARRAY */
6678 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
6683 /* Print should start at the beginning of the message
6684 buffer next time. */
6685 message_buf_print
= 0;
6691 /* The non-logging version of message. */
6694 message_nolog (m
, a1
, a2
, a3
)
6696 EMACS_INT a1
, a2
, a3
;
6698 Lisp_Object old_log_max
;
6699 old_log_max
= Vmessage_log_max
;
6700 Vmessage_log_max
= Qnil
;
6701 message (m
, a1
, a2
, a3
);
6702 Vmessage_log_max
= old_log_max
;
6706 /* Display the current message in the current mini-buffer. This is
6707 only called from error handlers in process.c, and is not time
6713 if (!NILP (echo_area_buffer
[0]))
6716 string
= Fcurrent_message ();
6717 message3 (string
, SBYTES (string
),
6718 !NILP (current_buffer
->enable_multibyte_characters
));
6723 /* Make sure echo area buffers in `echo_buffers' are live.
6724 If they aren't, make new ones. */
6727 ensure_echo_area_buffers ()
6731 for (i
= 0; i
< 2; ++i
)
6732 if (!BUFFERP (echo_buffer
[i
])
6733 || NILP (XBUFFER (echo_buffer
[i
])->name
))
6736 Lisp_Object old_buffer
;
6739 old_buffer
= echo_buffer
[i
];
6740 sprintf (name
, " *Echo Area %d*", i
);
6741 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
6742 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
6744 for (j
= 0; j
< 2; ++j
)
6745 if (EQ (old_buffer
, echo_area_buffer
[j
]))
6746 echo_area_buffer
[j
] = echo_buffer
[i
];
6751 /* Call FN with args A1..A4 with either the current or last displayed
6752 echo_area_buffer as current buffer.
6754 WHICH zero means use the current message buffer
6755 echo_area_buffer[0]. If that is nil, choose a suitable buffer
6756 from echo_buffer[] and clear it.
6758 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
6759 suitable buffer from echo_buffer[] and clear it.
6761 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
6762 that the current message becomes the last displayed one, make
6763 choose a suitable buffer for echo_area_buffer[0], and clear it.
6765 Value is what FN returns. */
6768 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
6771 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
6777 int this_one
, the_other
, clear_buffer_p
, rc
;
6778 int count
= SPECPDL_INDEX ();
6780 /* If buffers aren't live, make new ones. */
6781 ensure_echo_area_buffers ();
6786 this_one
= 0, the_other
= 1;
6788 this_one
= 1, the_other
= 0;
6791 this_one
= 0, the_other
= 1;
6794 /* We need a fresh one in case the current echo buffer equals
6795 the one containing the last displayed echo area message. */
6796 if (!NILP (echo_area_buffer
[this_one
])
6797 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
6798 echo_area_buffer
[this_one
] = Qnil
;
6801 /* Choose a suitable buffer from echo_buffer[] is we don't
6803 if (NILP (echo_area_buffer
[this_one
]))
6805 echo_area_buffer
[this_one
]
6806 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
6807 ? echo_buffer
[the_other
]
6808 : echo_buffer
[this_one
]);
6812 buffer
= echo_area_buffer
[this_one
];
6814 /* Don't get confused by reusing the buffer used for echoing
6815 for a different purpose. */
6816 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
6819 record_unwind_protect (unwind_with_echo_area_buffer
,
6820 with_echo_area_buffer_unwind_data (w
));
6822 /* Make the echo area buffer current. Note that for display
6823 purposes, it is not necessary that the displayed window's buffer
6824 == current_buffer, except for text property lookup. So, let's
6825 only set that buffer temporarily here without doing a full
6826 Fset_window_buffer. We must also change w->pointm, though,
6827 because otherwise an assertions in unshow_buffer fails, and Emacs
6829 set_buffer_internal_1 (XBUFFER (buffer
));
6833 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
6836 current_buffer
->undo_list
= Qt
;
6837 current_buffer
->read_only
= Qnil
;
6838 specbind (Qinhibit_read_only
, Qt
);
6839 specbind (Qinhibit_modification_hooks
, Qt
);
6841 if (clear_buffer_p
&& Z
> BEG
)
6844 xassert (BEGV
>= BEG
);
6845 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6847 rc
= fn (a1
, a2
, a3
, a4
);
6849 xassert (BEGV
>= BEG
);
6850 xassert (ZV
<= Z
&& ZV
>= BEGV
);
6852 unbind_to (count
, Qnil
);
6857 /* Save state that should be preserved around the call to the function
6858 FN called in with_echo_area_buffer. */
6861 with_echo_area_buffer_unwind_data (w
)
6867 /* Reduce consing by keeping one vector in
6868 Vwith_echo_area_save_vector. */
6869 vector
= Vwith_echo_area_save_vector
;
6870 Vwith_echo_area_save_vector
= Qnil
;
6873 vector
= Fmake_vector (make_number (7), Qnil
);
6875 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
6876 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
6877 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
6881 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
6882 AREF (vector
, i
) = w
->buffer
; ++i
;
6883 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
6884 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
6889 for (; i
< end
; ++i
)
6890 AREF (vector
, i
) = Qnil
;
6893 xassert (i
== ASIZE (vector
));
6898 /* Restore global state from VECTOR which was created by
6899 with_echo_area_buffer_unwind_data. */
6902 unwind_with_echo_area_buffer (vector
)
6905 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
6906 Vdeactivate_mark
= AREF (vector
, 1);
6907 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
6909 if (WINDOWP (AREF (vector
, 3)))
6912 Lisp_Object buffer
, charpos
, bytepos
;
6914 w
= XWINDOW (AREF (vector
, 3));
6915 buffer
= AREF (vector
, 4);
6916 charpos
= AREF (vector
, 5);
6917 bytepos
= AREF (vector
, 6);
6920 set_marker_both (w
->pointm
, buffer
,
6921 XFASTINT (charpos
), XFASTINT (bytepos
));
6924 Vwith_echo_area_save_vector
= vector
;
6929 /* Set up the echo area for use by print functions. MULTIBYTE_P
6930 non-zero means we will print multibyte. */
6933 setup_echo_area_for_printing (multibyte_p
)
6936 /* If we can't find an echo area any more, exit. */
6937 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
6940 ensure_echo_area_buffers ();
6942 if (!message_buf_print
)
6944 /* A message has been output since the last time we printed.
6945 Choose a fresh echo area buffer. */
6946 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6947 echo_area_buffer
[0] = echo_buffer
[1];
6949 echo_area_buffer
[0] = echo_buffer
[0];
6951 /* Switch to that buffer and clear it. */
6952 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6953 current_buffer
->truncate_lines
= Qnil
;
6957 int count
= SPECPDL_INDEX ();
6958 specbind (Qinhibit_read_only
, Qt
);
6959 /* Note that undo recording is always disabled. */
6961 unbind_to (count
, Qnil
);
6963 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
6965 /* Set up the buffer for the multibyteness we need. */
6967 != !NILP (current_buffer
->enable_multibyte_characters
))
6968 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
6970 /* Raise the frame containing the echo area. */
6971 if (minibuffer_auto_raise
)
6973 struct frame
*sf
= SELECTED_FRAME ();
6974 Lisp_Object mini_window
;
6975 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6976 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6979 message_log_maybe_newline ();
6980 message_buf_print
= 1;
6984 if (NILP (echo_area_buffer
[0]))
6986 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
6987 echo_area_buffer
[0] = echo_buffer
[1];
6989 echo_area_buffer
[0] = echo_buffer
[0];
6992 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
6994 /* Someone switched buffers between print requests. */
6995 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
6996 current_buffer
->truncate_lines
= Qnil
;
7002 /* Display an echo area message in window W. Value is non-zero if W's
7003 height is changed. If display_last_displayed_message_p is
7004 non-zero, display the message that was last displayed, otherwise
7005 display the current message. */
7008 display_echo_area (w
)
7011 int i
, no_message_p
, window_height_changed_p
, count
;
7013 /* Temporarily disable garbage collections while displaying the echo
7014 area. This is done because a GC can print a message itself.
7015 That message would modify the echo area buffer's contents while a
7016 redisplay of the buffer is going on, and seriously confuse
7018 count
= inhibit_garbage_collection ();
7020 /* If there is no message, we must call display_echo_area_1
7021 nevertheless because it resizes the window. But we will have to
7022 reset the echo_area_buffer in question to nil at the end because
7023 with_echo_area_buffer will sets it to an empty buffer. */
7024 i
= display_last_displayed_message_p
? 1 : 0;
7025 no_message_p
= NILP (echo_area_buffer
[i
]);
7027 window_height_changed_p
7028 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7029 display_echo_area_1
,
7030 (EMACS_INT
) w
, Qnil
, 0, 0);
7033 echo_area_buffer
[i
] = Qnil
;
7035 unbind_to (count
, Qnil
);
7036 return window_height_changed_p
;
7040 /* Helper for display_echo_area. Display the current buffer which
7041 contains the current echo area message in window W, a mini-window,
7042 a pointer to which is passed in A1. A2..A4 are currently not used.
7043 Change the height of W so that all of the message is displayed.
7044 Value is non-zero if height of W was changed. */
7047 display_echo_area_1 (a1
, a2
, a3
, a4
)
7052 struct window
*w
= (struct window
*) a1
;
7054 struct text_pos start
;
7055 int window_height_changed_p
= 0;
7057 /* Do this before displaying, so that we have a large enough glyph
7058 matrix for the display. */
7059 window_height_changed_p
= resize_mini_window (w
, 0);
7062 clear_glyph_matrix (w
->desired_matrix
);
7063 XSETWINDOW (window
, w
);
7064 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7065 try_window (window
, start
);
7067 return window_height_changed_p
;
7071 /* Resize the echo area window to exactly the size needed for the
7072 currently displayed message, if there is one. If a mini-buffer
7073 is active, don't shrink it. */
7076 resize_echo_area_exactly ()
7078 if (BUFFERP (echo_area_buffer
[0])
7079 && WINDOWP (echo_area_window
))
7081 struct window
*w
= XWINDOW (echo_area_window
);
7083 Lisp_Object resize_exactly
;
7085 if (minibuf_level
== 0)
7086 resize_exactly
= Qt
;
7088 resize_exactly
= Qnil
;
7090 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7091 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7094 ++windows_or_buffers_changed
;
7095 ++update_mode_lines
;
7096 redisplay_internal (0);
7102 /* Callback function for with_echo_area_buffer, when used from
7103 resize_echo_area_exactly. A1 contains a pointer to the window to
7104 resize, EXACTLY non-nil means resize the mini-window exactly to the
7105 size of the text displayed. A3 and A4 are not used. Value is what
7106 resize_mini_window returns. */
7109 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7111 Lisp_Object exactly
;
7114 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7118 /* Resize mini-window W to fit the size of its contents. EXACT:P
7119 means size the window exactly to the size needed. Otherwise, it's
7120 only enlarged until W's buffer is empty. Value is non-zero if
7121 the window height has been changed. */
7124 resize_mini_window (w
, exact_p
)
7128 struct frame
*f
= XFRAME (w
->frame
);
7129 int window_height_changed_p
= 0;
7131 xassert (MINI_WINDOW_P (w
));
7133 /* Don't resize windows while redisplaying a window; it would
7134 confuse redisplay functions when the size of the window they are
7135 displaying changes from under them. Such a resizing can happen,
7136 for instance, when which-func prints a long message while
7137 we are running fontification-functions. We're running these
7138 functions with safe_call which binds inhibit-redisplay to t. */
7139 if (!NILP (Vinhibit_redisplay
))
7142 /* Nil means don't try to resize. */
7143 if (NILP (Vresize_mini_windows
)
7144 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7147 if (!FRAME_MINIBUF_ONLY_P (f
))
7150 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7151 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7152 int height
, max_height
;
7153 int unit
= FRAME_LINE_HEIGHT (f
);
7154 struct text_pos start
;
7155 struct buffer
*old_current_buffer
= NULL
;
7157 if (current_buffer
!= XBUFFER (w
->buffer
))
7159 old_current_buffer
= current_buffer
;
7160 set_buffer_internal (XBUFFER (w
->buffer
));
7163 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7165 /* Compute the max. number of lines specified by the user. */
7166 if (FLOATP (Vmax_mini_window_height
))
7167 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7168 else if (INTEGERP (Vmax_mini_window_height
))
7169 max_height
= XINT (Vmax_mini_window_height
);
7171 max_height
= total_height
/ 4;
7173 /* Correct that max. height if it's bogus. */
7174 max_height
= max (1, max_height
);
7175 max_height
= min (total_height
, max_height
);
7177 /* Find out the height of the text in the window. */
7178 if (it
.truncate_lines_p
)
7183 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7184 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7185 height
= it
.current_y
+ last_height
;
7187 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7188 height
-= it
.extra_line_spacing
;
7189 height
= (height
+ unit
- 1) / unit
;
7192 /* Compute a suitable window start. */
7193 if (height
> max_height
)
7195 height
= max_height
;
7196 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7197 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7198 start
= it
.current
.pos
;
7201 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7202 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7204 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7206 /* Let it grow only, until we display an empty message, in which
7207 case the window shrinks again. */
7208 if (height
> WINDOW_TOTAL_LINES (w
))
7210 int old_height
= WINDOW_TOTAL_LINES (w
);
7211 freeze_window_starts (f
, 1);
7212 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7213 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7215 else if (height
< WINDOW_TOTAL_LINES (w
)
7216 && (exact_p
|| BEGV
== ZV
))
7218 int old_height
= WINDOW_TOTAL_LINES (w
);
7219 freeze_window_starts (f
, 0);
7220 shrink_mini_window (w
);
7221 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7226 /* Always resize to exact size needed. */
7227 if (height
> WINDOW_TOTAL_LINES (w
))
7229 int old_height
= WINDOW_TOTAL_LINES (w
);
7230 freeze_window_starts (f
, 1);
7231 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7232 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7234 else if (height
< WINDOW_TOTAL_LINES (w
))
7236 int old_height
= WINDOW_TOTAL_LINES (w
);
7237 freeze_window_starts (f
, 0);
7238 shrink_mini_window (w
);
7242 freeze_window_starts (f
, 1);
7243 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7246 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7250 if (old_current_buffer
)
7251 set_buffer_internal (old_current_buffer
);
7254 return window_height_changed_p
;
7258 /* Value is the current message, a string, or nil if there is no
7266 if (NILP (echo_area_buffer
[0]))
7270 with_echo_area_buffer (0, 0, current_message_1
,
7271 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7273 echo_area_buffer
[0] = Qnil
;
7281 current_message_1 (a1
, a2
, a3
, a4
)
7286 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7289 *msg
= make_buffer_string (BEG
, Z
, 1);
7296 /* Push the current message on Vmessage_stack for later restauration
7297 by restore_message. Value is non-zero if the current message isn't
7298 empty. This is a relatively infrequent operation, so it's not
7299 worth optimizing. */
7305 msg
= current_message ();
7306 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7307 return STRINGP (msg
);
7311 /* Restore message display from the top of Vmessage_stack. */
7318 xassert (CONSP (Vmessage_stack
));
7319 msg
= XCAR (Vmessage_stack
);
7321 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7323 message3_nolog (msg
, 0, 0);
7327 /* Handler for record_unwind_protect calling pop_message. */
7330 pop_message_unwind (dummy
)
7337 /* Pop the top-most entry off Vmessage_stack. */
7342 xassert (CONSP (Vmessage_stack
));
7343 Vmessage_stack
= XCDR (Vmessage_stack
);
7347 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7348 exits. If the stack is not empty, we have a missing pop_message
7352 check_message_stack ()
7354 if (!NILP (Vmessage_stack
))
7359 /* Truncate to NCHARS what will be displayed in the echo area the next
7360 time we display it---but don't redisplay it now. */
7363 truncate_echo_area (nchars
)
7367 echo_area_buffer
[0] = Qnil
;
7368 /* A null message buffer means that the frame hasn't really been
7369 initialized yet. Error messages get reported properly by
7370 cmd_error, so this must be just an informative message; toss it. */
7371 else if (!noninteractive
7373 && !NILP (echo_area_buffer
[0]))
7375 struct frame
*sf
= SELECTED_FRAME ();
7376 if (FRAME_MESSAGE_BUF (sf
))
7377 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7382 /* Helper function for truncate_echo_area. Truncate the current
7383 message to at most NCHARS characters. */
7386 truncate_message_1 (nchars
, a2
, a3
, a4
)
7391 if (BEG
+ nchars
< Z
)
7392 del_range (BEG
+ nchars
, Z
);
7394 echo_area_buffer
[0] = Qnil
;
7399 /* Set the current message to a substring of S or STRING.
7401 If STRING is a Lisp string, set the message to the first NBYTES
7402 bytes from STRING. NBYTES zero means use the whole string. If
7403 STRING is multibyte, the message will be displayed multibyte.
7405 If S is not null, set the message to the first LEN bytes of S. LEN
7406 zero means use the whole string. MULTIBYTE_P non-zero means S is
7407 multibyte. Display the message multibyte in that case. */
7410 set_message (s
, string
, nbytes
, multibyte_p
)
7413 int nbytes
, multibyte_p
;
7415 message_enable_multibyte
7416 = ((s
&& multibyte_p
)
7417 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7419 with_echo_area_buffer (0, -1, set_message_1
,
7420 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7421 message_buf_print
= 0;
7422 help_echo_showing_p
= 0;
7426 /* Helper function for set_message. Arguments have the same meaning
7427 as there, with A1 corresponding to S and A2 corresponding to STRING
7428 This function is called with the echo area buffer being
7432 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7435 EMACS_INT nbytes
, multibyte_p
;
7437 const char *s
= (const char *) a1
;
7438 Lisp_Object string
= a2
;
7442 /* Change multibyteness of the echo buffer appropriately. */
7443 if (message_enable_multibyte
7444 != !NILP (current_buffer
->enable_multibyte_characters
))
7445 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7447 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7449 /* Insert new message at BEG. */
7450 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7452 if (STRINGP (string
))
7457 nbytes
= SBYTES (string
);
7458 nchars
= string_byte_to_char (string
, nbytes
);
7460 /* This function takes care of single/multibyte conversion. We
7461 just have to ensure that the echo area buffer has the right
7462 setting of enable_multibyte_characters. */
7463 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7468 nbytes
= strlen (s
);
7470 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
7472 /* Convert from multi-byte to single-byte. */
7474 unsigned char work
[1];
7476 /* Convert a multibyte string to single-byte. */
7477 for (i
= 0; i
< nbytes
; i
+= n
)
7479 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
7480 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7482 : multibyte_char_to_unibyte (c
, Qnil
));
7483 insert_1_both (work
, 1, 1, 1, 0, 0);
7486 else if (!multibyte_p
7487 && !NILP (current_buffer
->enable_multibyte_characters
))
7489 /* Convert from single-byte to multi-byte. */
7491 const unsigned char *msg
= (const unsigned char *) s
;
7492 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7494 /* Convert a single-byte string to multibyte. */
7495 for (i
= 0; i
< nbytes
; i
++)
7497 c
= unibyte_char_to_multibyte (msg
[i
]);
7498 n
= CHAR_STRING (c
, str
);
7499 insert_1_both (str
, 1, n
, 1, 0, 0);
7503 insert_1 (s
, nbytes
, 1, 0, 0);
7510 /* Clear messages. CURRENT_P non-zero means clear the current
7511 message. LAST_DISPLAYED_P non-zero means clear the message
7515 clear_message (current_p
, last_displayed_p
)
7516 int current_p
, last_displayed_p
;
7520 echo_area_buffer
[0] = Qnil
;
7521 message_cleared_p
= 1;
7524 if (last_displayed_p
)
7525 echo_area_buffer
[1] = Qnil
;
7527 message_buf_print
= 0;
7530 /* Clear garbaged frames.
7532 This function is used where the old redisplay called
7533 redraw_garbaged_frames which in turn called redraw_frame which in
7534 turn called clear_frame. The call to clear_frame was a source of
7535 flickering. I believe a clear_frame is not necessary. It should
7536 suffice in the new redisplay to invalidate all current matrices,
7537 and ensure a complete redisplay of all windows. */
7540 clear_garbaged_frames ()
7544 Lisp_Object tail
, frame
;
7545 int changed_count
= 0;
7547 FOR_EACH_FRAME (tail
, frame
)
7549 struct frame
*f
= XFRAME (frame
);
7551 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
7554 Fredraw_frame (frame
);
7555 clear_current_matrices (f
);
7564 ++windows_or_buffers_changed
;
7569 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
7570 is non-zero update selected_frame. Value is non-zero if the
7571 mini-windows height has been changed. */
7574 echo_area_display (update_frame_p
)
7577 Lisp_Object mini_window
;
7580 int window_height_changed_p
= 0;
7581 struct frame
*sf
= SELECTED_FRAME ();
7583 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7584 w
= XWINDOW (mini_window
);
7585 f
= XFRAME (WINDOW_FRAME (w
));
7587 /* Don't display if frame is invisible or not yet initialized. */
7588 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
7591 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
7593 #ifdef HAVE_WINDOW_SYSTEM
7594 /* When Emacs starts, selected_frame may be a visible terminal
7595 frame, even if we run under a window system. If we let this
7596 through, a message would be displayed on the terminal. */
7597 if (EQ (selected_frame
, Vterminal_frame
)
7598 && !NILP (Vwindow_system
))
7600 #endif /* HAVE_WINDOW_SYSTEM */
7603 /* Redraw garbaged frames. */
7605 clear_garbaged_frames ();
7607 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
7609 echo_area_window
= mini_window
;
7610 window_height_changed_p
= display_echo_area (w
);
7611 w
->must_be_updated_p
= 1;
7613 /* Update the display, unless called from redisplay_internal.
7614 Also don't update the screen during redisplay itself. The
7615 update will happen at the end of redisplay, and an update
7616 here could cause confusion. */
7617 if (update_frame_p
&& !redisplaying_p
)
7621 /* If the display update has been interrupted by pending
7622 input, update mode lines in the frame. Due to the
7623 pending input, it might have been that redisplay hasn't
7624 been called, so that mode lines above the echo area are
7625 garbaged. This looks odd, so we prevent it here. */
7626 if (!display_completed
)
7627 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
7629 if (window_height_changed_p
7630 /* Don't do this if Emacs is shutting down. Redisplay
7631 needs to run hooks. */
7632 && !NILP (Vrun_hooks
))
7634 /* Must update other windows. Likewise as in other
7635 cases, don't let this update be interrupted by
7637 int count
= SPECPDL_INDEX ();
7638 specbind (Qredisplay_dont_pause
, Qt
);
7639 windows_or_buffers_changed
= 1;
7640 redisplay_internal (0);
7641 unbind_to (count
, Qnil
);
7643 else if (FRAME_WINDOW_P (f
) && n
== 0)
7645 /* Window configuration is the same as before.
7646 Can do with a display update of the echo area,
7647 unless we displayed some mode lines. */
7648 update_single_window (w
, 1);
7649 rif
->flush_display (f
);
7652 update_frame (f
, 1, 1);
7654 /* If cursor is in the echo area, make sure that the next
7655 redisplay displays the minibuffer, so that the cursor will
7656 be replaced with what the minibuffer wants. */
7657 if (cursor_in_echo_area
)
7658 ++windows_or_buffers_changed
;
7661 else if (!EQ (mini_window
, selected_window
))
7662 windows_or_buffers_changed
++;
7664 /* Last displayed message is now the current message. */
7665 echo_area_buffer
[1] = echo_area_buffer
[0];
7667 /* Prevent redisplay optimization in redisplay_internal by resetting
7668 this_line_start_pos. This is done because the mini-buffer now
7669 displays the message instead of its buffer text. */
7670 if (EQ (mini_window
, selected_window
))
7671 CHARPOS (this_line_start_pos
) = 0;
7673 return window_height_changed_p
;
7678 /***********************************************************************
7680 ***********************************************************************/
7683 /* The frame title buffering code is also used by Fformat_mode_line.
7684 So it is not conditioned by HAVE_WINDOW_SYSTEM. */
7686 /* A buffer for constructing frame titles in it; allocated from the
7687 heap in init_xdisp and resized as needed in store_frame_title_char. */
7689 static char *frame_title_buf
;
7691 /* The buffer's end, and a current output position in it. */
7693 static char *frame_title_buf_end
;
7694 static char *frame_title_ptr
;
7697 /* Store a single character C for the frame title in frame_title_buf.
7698 Re-allocate frame_title_buf if necessary. */
7702 store_frame_title_char (char c
)
7704 store_frame_title_char (c
)
7708 /* If output position has reached the end of the allocated buffer,
7709 double the buffer's size. */
7710 if (frame_title_ptr
== frame_title_buf_end
)
7712 int len
= frame_title_ptr
- frame_title_buf
;
7713 int new_size
= 2 * len
* sizeof *frame_title_buf
;
7714 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
7715 frame_title_buf_end
= frame_title_buf
+ new_size
;
7716 frame_title_ptr
= frame_title_buf
+ len
;
7719 *frame_title_ptr
++ = c
;
7723 /* Store part of a frame title in frame_title_buf, beginning at
7724 frame_title_ptr. STR is the string to store. Do not copy
7725 characters that yield more columns than PRECISION; PRECISION <= 0
7726 means copy the whole string. Pad with spaces until FIELD_WIDTH
7727 number of characters have been copied; FIELD_WIDTH <= 0 means don't
7728 pad. Called from display_mode_element when it is used to build a
7732 store_frame_title (str
, field_width
, precision
)
7733 const unsigned char *str
;
7734 int field_width
, precision
;
7739 /* Copy at most PRECISION chars from STR. */
7740 nbytes
= strlen (str
);
7741 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
7743 store_frame_title_char (*str
++);
7745 /* Fill up with spaces until FIELD_WIDTH reached. */
7746 while (field_width
> 0
7749 store_frame_title_char (' ');
7756 #ifdef HAVE_WINDOW_SYSTEM
7758 /* Set the title of FRAME, if it has changed. The title format is
7759 Vicon_title_format if FRAME is iconified, otherwise it is
7760 frame_title_format. */
7763 x_consider_frame_title (frame
)
7766 struct frame
*f
= XFRAME (frame
);
7768 if (FRAME_WINDOW_P (f
)
7769 || FRAME_MINIBUF_ONLY_P (f
)
7770 || f
->explicit_name
)
7772 /* Do we have more than one visible frame on this X display? */
7775 struct buffer
*obuf
;
7779 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7781 Lisp_Object other_frame
= XCAR (tail
);
7782 struct frame
*tf
= XFRAME (other_frame
);
7785 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
7786 && !FRAME_MINIBUF_ONLY_P (tf
)
7787 && !EQ (other_frame
, tip_frame
)
7788 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
7792 /* Set global variable indicating that multiple frames exist. */
7793 multiple_frames
= CONSP (tail
);
7795 /* Switch to the buffer of selected window of the frame. Set up
7796 frame_title_ptr so that display_mode_element will output into it;
7797 then display the title. */
7798 obuf
= current_buffer
;
7799 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
7800 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
7801 frame_title_ptr
= frame_title_buf
;
7802 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
7803 NULL
, DEFAULT_FACE_ID
);
7804 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
7805 len
= frame_title_ptr
- frame_title_buf
;
7806 frame_title_ptr
= NULL
;
7807 set_buffer_internal_1 (obuf
);
7809 /* Set the title only if it's changed. This avoids consing in
7810 the common case where it hasn't. (If it turns out that we've
7811 already wasted too much time by walking through the list with
7812 display_mode_element, then we might need to optimize at a
7813 higher level than this.) */
7814 if (! STRINGP (f
->name
)
7815 || SBYTES (f
->name
) != len
7816 || bcmp (frame_title_buf
, SDATA (f
->name
), len
) != 0)
7817 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
7821 #endif /* not HAVE_WINDOW_SYSTEM */
7826 /***********************************************************************
7828 ***********************************************************************/
7831 /* Prepare for redisplay by updating menu-bar item lists when
7832 appropriate. This can call eval. */
7835 prepare_menu_bars ()
7838 struct gcpro gcpro1
, gcpro2
;
7840 Lisp_Object tooltip_frame
;
7842 #ifdef HAVE_WINDOW_SYSTEM
7843 tooltip_frame
= tip_frame
;
7845 tooltip_frame
= Qnil
;
7848 /* Update all frame titles based on their buffer names, etc. We do
7849 this before the menu bars so that the buffer-menu will show the
7850 up-to-date frame titles. */
7851 #ifdef HAVE_WINDOW_SYSTEM
7852 if (windows_or_buffers_changed
|| update_mode_lines
)
7854 Lisp_Object tail
, frame
;
7856 FOR_EACH_FRAME (tail
, frame
)
7859 if (!EQ (frame
, tooltip_frame
)
7860 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
7861 x_consider_frame_title (frame
);
7864 #endif /* HAVE_WINDOW_SYSTEM */
7866 /* Update the menu bar item lists, if appropriate. This has to be
7867 done before any actual redisplay or generation of display lines. */
7868 all_windows
= (update_mode_lines
7869 || buffer_shared
> 1
7870 || windows_or_buffers_changed
);
7873 Lisp_Object tail
, frame
;
7874 int count
= SPECPDL_INDEX ();
7876 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
7878 FOR_EACH_FRAME (tail
, frame
)
7882 /* Ignore tooltip frame. */
7883 if (EQ (frame
, tooltip_frame
))
7886 /* If a window on this frame changed size, report that to
7887 the user and clear the size-change flag. */
7888 if (FRAME_WINDOW_SIZES_CHANGED (f
))
7890 Lisp_Object functions
;
7892 /* Clear flag first in case we get an error below. */
7893 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
7894 functions
= Vwindow_size_change_functions
;
7895 GCPRO2 (tail
, functions
);
7897 while (CONSP (functions
))
7899 call1 (XCAR (functions
), frame
);
7900 functions
= XCDR (functions
);
7906 update_menu_bar (f
, 0);
7907 #ifdef HAVE_WINDOW_SYSTEM
7908 update_tool_bar (f
, 0);
7913 unbind_to (count
, Qnil
);
7917 struct frame
*sf
= SELECTED_FRAME ();
7918 update_menu_bar (sf
, 1);
7919 #ifdef HAVE_WINDOW_SYSTEM
7920 update_tool_bar (sf
, 1);
7924 /* Motif needs this. See comment in xmenu.c. Turn it off when
7925 pending_menu_activation is not defined. */
7926 #ifdef USE_X_TOOLKIT
7927 pending_menu_activation
= 0;
7932 /* Update the menu bar item list for frame F. This has to be done
7933 before we start to fill in any display lines, because it can call
7936 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
7939 update_menu_bar (f
, save_match_data
)
7941 int save_match_data
;
7944 register struct window
*w
;
7946 /* If called recursively during a menu update, do nothing. This can
7947 happen when, for instance, an activate-menubar-hook causes a
7949 if (inhibit_menubar_update
)
7952 window
= FRAME_SELECTED_WINDOW (f
);
7953 w
= XWINDOW (window
);
7955 #if 0 /* The if statement below this if statement used to include the
7956 condition !NILP (w->update_mode_line), rather than using
7957 update_mode_lines directly, and this if statement may have
7958 been added to make that condition work. Now the if
7959 statement below matches its comment, this isn't needed. */
7960 if (update_mode_lines
)
7961 w
->update_mode_line
= Qt
;
7964 if (FRAME_WINDOW_P (f
)
7966 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
7967 || defined (USE_GTK)
7968 FRAME_EXTERNAL_MENU_BAR (f
)
7970 FRAME_MENU_BAR_LINES (f
) > 0
7972 : FRAME_MENU_BAR_LINES (f
) > 0)
7974 /* If the user has switched buffers or windows, we need to
7975 recompute to reflect the new bindings. But we'll
7976 recompute when update_mode_lines is set too; that means
7977 that people can use force-mode-line-update to request
7978 that the menu bar be recomputed. The adverse effect on
7979 the rest of the redisplay algorithm is about the same as
7980 windows_or_buffers_changed anyway. */
7981 if (windows_or_buffers_changed
7982 /* This used to test w->update_mode_line, but we believe
7983 there is no need to recompute the menu in that case. */
7984 || update_mode_lines
7985 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7986 < BUF_MODIFF (XBUFFER (w
->buffer
)))
7987 != !NILP (w
->last_had_star
))
7988 || ((!NILP (Vtransient_mark_mode
)
7989 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7990 != !NILP (w
->region_showing
)))
7992 struct buffer
*prev
= current_buffer
;
7993 int count
= SPECPDL_INDEX ();
7995 specbind (Qinhibit_menubar_update
, Qt
);
7997 set_buffer_internal_1 (XBUFFER (w
->buffer
));
7998 if (save_match_data
)
7999 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8000 if (NILP (Voverriding_local_map_menu_flag
))
8002 specbind (Qoverriding_terminal_local_map
, Qnil
);
8003 specbind (Qoverriding_local_map
, Qnil
);
8006 /* Run the Lucid hook. */
8007 safe_run_hooks (Qactivate_menubar_hook
);
8009 /* If it has changed current-menubar from previous value,
8010 really recompute the menu-bar from the value. */
8011 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8012 call0 (Qrecompute_lucid_menubar
);
8014 safe_run_hooks (Qmenu_bar_update_hook
);
8015 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8017 /* Redisplay the menu bar in case we changed it. */
8018 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8019 || defined (USE_GTK)
8020 if (FRAME_WINDOW_P (f
)
8021 #if defined (MAC_OS)
8022 /* All frames on Mac OS share the same menubar. So only the
8023 selected frame should be allowed to set it. */
8024 && f
== SELECTED_FRAME ()
8027 set_frame_menubar (f
, 0, 0);
8029 /* On a terminal screen, the menu bar is an ordinary screen
8030 line, and this makes it get updated. */
8031 w
->update_mode_line
= Qt
;
8032 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8033 /* In the non-toolkit version, the menu bar is an ordinary screen
8034 line, and this makes it get updated. */
8035 w
->update_mode_line
= Qt
;
8036 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8038 unbind_to (count
, Qnil
);
8039 set_buffer_internal_1 (prev
);
8046 /***********************************************************************
8048 ***********************************************************************/
8050 #ifdef HAVE_WINDOW_SYSTEM
8053 Nominal cursor position -- where to draw output.
8054 HPOS and VPOS are window relative glyph matrix coordinates.
8055 X and Y are window relative pixel coordinates. */
8057 struct cursor_pos output_cursor
;
8061 Set the global variable output_cursor to CURSOR. All cursor
8062 positions are relative to updated_window. */
8065 set_output_cursor (cursor
)
8066 struct cursor_pos
*cursor
;
8068 output_cursor
.hpos
= cursor
->hpos
;
8069 output_cursor
.vpos
= cursor
->vpos
;
8070 output_cursor
.x
= cursor
->x
;
8071 output_cursor
.y
= cursor
->y
;
8076 Set a nominal cursor position.
8078 HPOS and VPOS are column/row positions in a window glyph matrix. X
8079 and Y are window text area relative pixel positions.
8081 If this is done during an update, updated_window will contain the
8082 window that is being updated and the position is the future output
8083 cursor position for that window. If updated_window is null, use
8084 selected_window and display the cursor at the given position. */
8087 x_cursor_to (vpos
, hpos
, y
, x
)
8088 int vpos
, hpos
, y
, x
;
8092 /* If updated_window is not set, work on selected_window. */
8096 w
= XWINDOW (selected_window
);
8098 /* Set the output cursor. */
8099 output_cursor
.hpos
= hpos
;
8100 output_cursor
.vpos
= vpos
;
8101 output_cursor
.x
= x
;
8102 output_cursor
.y
= y
;
8104 /* If not called as part of an update, really display the cursor.
8105 This will also set the cursor position of W. */
8106 if (updated_window
== NULL
)
8109 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8110 if (rif
->flush_display_optional
)
8111 rif
->flush_display_optional (SELECTED_FRAME ());
8116 #endif /* HAVE_WINDOW_SYSTEM */
8119 /***********************************************************************
8121 ***********************************************************************/
8123 #ifdef HAVE_WINDOW_SYSTEM
8125 /* Where the mouse was last time we reported a mouse event. */
8127 FRAME_PTR last_mouse_frame
;
8129 /* Tool-bar item index of the item on which a mouse button was pressed
8132 int last_tool_bar_item
;
8135 /* Update the tool-bar item list for frame F. This has to be done
8136 before we start to fill in any display lines. Called from
8137 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8138 and restore it here. */
8141 update_tool_bar (f
, save_match_data
)
8143 int save_match_data
;
8146 int do_update
= FRAME_EXTERNAL_TOOL_BAR(f
);
8148 int do_update
= WINDOWP (f
->tool_bar_window
)
8149 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8157 window
= FRAME_SELECTED_WINDOW (f
);
8158 w
= XWINDOW (window
);
8160 /* If the user has switched buffers or windows, we need to
8161 recompute to reflect the new bindings. But we'll
8162 recompute when update_mode_lines is set too; that means
8163 that people can use force-mode-line-update to request
8164 that the menu bar be recomputed. The adverse effect on
8165 the rest of the redisplay algorithm is about the same as
8166 windows_or_buffers_changed anyway. */
8167 if (windows_or_buffers_changed
8168 || !NILP (w
->update_mode_line
)
8169 || update_mode_lines
8170 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8171 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8172 != !NILP (w
->last_had_star
))
8173 || ((!NILP (Vtransient_mark_mode
)
8174 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8175 != !NILP (w
->region_showing
)))
8177 struct buffer
*prev
= current_buffer
;
8178 int count
= SPECPDL_INDEX ();
8179 Lisp_Object old_tool_bar
;
8180 struct gcpro gcpro1
;
8182 /* Set current_buffer to the buffer of the selected
8183 window of the frame, so that we get the right local
8185 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8187 /* Save match data, if we must. */
8188 if (save_match_data
)
8189 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
8191 /* Make sure that we don't accidentally use bogus keymaps. */
8192 if (NILP (Voverriding_local_map_menu_flag
))
8194 specbind (Qoverriding_terminal_local_map
, Qnil
);
8195 specbind (Qoverriding_local_map
, Qnil
);
8198 old_tool_bar
= f
->tool_bar_items
;
8199 GCPRO1 (old_tool_bar
);
8201 /* Build desired tool-bar items from keymaps. */
8204 = tool_bar_items (f
->tool_bar_items
, &f
->n_tool_bar_items
);
8207 /* Redisplay the tool-bar if we changed it. */
8208 if (! NILP (Fequal (old_tool_bar
, f
->tool_bar_items
)))
8209 w
->update_mode_line
= Qt
;
8213 unbind_to (count
, Qnil
);
8214 set_buffer_internal_1 (prev
);
8220 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8221 F's desired tool-bar contents. F->tool_bar_items must have
8222 been set up previously by calling prepare_menu_bars. */
8225 build_desired_tool_bar_string (f
)
8228 int i
, size
, size_needed
;
8229 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8230 Lisp_Object image
, plist
, props
;
8232 image
= plist
= props
= Qnil
;
8233 GCPRO3 (image
, plist
, props
);
8235 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8236 Otherwise, make a new string. */
8238 /* The size of the string we might be able to reuse. */
8239 size
= (STRINGP (f
->desired_tool_bar_string
)
8240 ? SCHARS (f
->desired_tool_bar_string
)
8243 /* We need one space in the string for each image. */
8244 size_needed
= f
->n_tool_bar_items
;
8246 /* Reuse f->desired_tool_bar_string, if possible. */
8247 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8248 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8252 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8253 Fremove_text_properties (make_number (0), make_number (size
),
8254 props
, f
->desired_tool_bar_string
);
8257 /* Put a `display' property on the string for the images to display,
8258 put a `menu_item' property on tool-bar items with a value that
8259 is the index of the item in F's tool-bar item vector. */
8260 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8262 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8264 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8265 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8266 int hmargin
, vmargin
, relief
, idx
, end
;
8267 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
, Qimage
;
8269 /* If image is a vector, choose the image according to the
8271 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8272 if (VECTORP (image
))
8276 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8277 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8280 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8281 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8283 xassert (ASIZE (image
) >= idx
);
8284 image
= AREF (image
, idx
);
8289 /* Ignore invalid image specifications. */
8290 if (!valid_image_p (image
))
8293 /* Display the tool-bar button pressed, or depressed. */
8294 plist
= Fcopy_sequence (XCDR (image
));
8296 /* Compute margin and relief to draw. */
8297 relief
= (tool_bar_button_relief
>= 0
8298 ? tool_bar_button_relief
8299 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8300 hmargin
= vmargin
= relief
;
8302 if (INTEGERP (Vtool_bar_button_margin
)
8303 && XINT (Vtool_bar_button_margin
) > 0)
8305 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8306 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8308 else if (CONSP (Vtool_bar_button_margin
))
8310 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8311 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8312 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8314 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8315 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8316 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8319 if (auto_raise_tool_bar_buttons_p
)
8321 /* Add a `:relief' property to the image spec if the item is
8325 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8332 /* If image is selected, display it pressed, i.e. with a
8333 negative relief. If it's not selected, display it with a
8335 plist
= Fplist_put (plist
, QCrelief
,
8337 ? make_number (-relief
)
8338 : make_number (relief
)));
8343 /* Put a margin around the image. */
8344 if (hmargin
|| vmargin
)
8346 if (hmargin
== vmargin
)
8347 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8349 plist
= Fplist_put (plist
, QCmargin
,
8350 Fcons (make_number (hmargin
),
8351 make_number (vmargin
)));
8354 /* If button is not enabled, and we don't have special images
8355 for the disabled state, make the image appear disabled by
8356 applying an appropriate algorithm to it. */
8357 if (!enabled_p
&& idx
< 0)
8358 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8360 /* Put a `display' text property on the string for the image to
8361 display. Put a `menu-item' property on the string that gives
8362 the start of this item's properties in the tool-bar items
8364 image
= Fcons (Qimage
, plist
);
8365 props
= list4 (Qdisplay
, image
,
8366 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8368 /* Let the last image hide all remaining spaces in the tool bar
8369 string. The string can be longer than needed when we reuse a
8371 if (i
+ 1 == f
->n_tool_bar_items
)
8372 end
= SCHARS (f
->desired_tool_bar_string
);
8375 Fadd_text_properties (make_number (i
), make_number (end
),
8376 props
, f
->desired_tool_bar_string
);
8384 /* Display one line of the tool-bar of frame IT->f. */
8387 display_tool_bar_line (it
)
8390 struct glyph_row
*row
= it
->glyph_row
;
8391 int max_x
= it
->last_visible_x
;
8394 prepare_desired_row (row
);
8395 row
->y
= it
->current_y
;
8397 /* Note that this isn't made use of if the face hasn't a box,
8398 so there's no need to check the face here. */
8399 it
->start_of_box_run_p
= 1;
8401 while (it
->current_x
< max_x
)
8403 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
8405 /* Get the next display element. */
8406 if (!get_next_display_element (it
))
8409 /* Produce glyphs. */
8410 x_before
= it
->current_x
;
8411 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
8412 PRODUCE_GLYPHS (it
);
8414 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
8419 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
8421 if (x
+ glyph
->pixel_width
> max_x
)
8423 /* Glyph doesn't fit on line. */
8424 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
8430 x
+= glyph
->pixel_width
;
8434 /* Stop at line ends. */
8435 if (ITERATOR_AT_END_OF_LINE_P (it
))
8438 set_iterator_to_next (it
, 1);
8443 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
8444 extend_face_to_end_of_line (it
);
8445 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
8446 last
->right_box_line_p
= 1;
8447 if (last
== row
->glyphs
[TEXT_AREA
])
8448 last
->left_box_line_p
= 1;
8449 compute_line_metrics (it
);
8451 /* If line is empty, make it occupy the rest of the tool-bar. */
8452 if (!row
->displays_text_p
)
8454 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
8455 row
->ascent
= row
->phys_ascent
= 0;
8458 row
->full_width_p
= 1;
8459 row
->continued_p
= 0;
8460 row
->truncated_on_left_p
= 0;
8461 row
->truncated_on_right_p
= 0;
8463 it
->current_x
= it
->hpos
= 0;
8464 it
->current_y
+= row
->height
;
8470 /* Value is the number of screen lines needed to make all tool-bar
8471 items of frame F visible. */
8474 tool_bar_lines_needed (f
)
8477 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8480 /* Initialize an iterator for iteration over
8481 F->desired_tool_bar_string in the tool-bar window of frame F. */
8482 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8483 it
.first_visible_x
= 0;
8484 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8485 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8487 while (!ITERATOR_AT_END_P (&it
))
8489 it
.glyph_row
= w
->desired_matrix
->rows
;
8490 clear_glyph_row (it
.glyph_row
);
8491 display_tool_bar_line (&it
);
8494 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
8498 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
8500 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
8509 frame
= selected_frame
;
8511 CHECK_FRAME (frame
);
8514 if (WINDOWP (f
->tool_bar_window
)
8515 || (w
= XWINDOW (f
->tool_bar_window
),
8516 WINDOW_TOTAL_LINES (w
) > 0))
8518 update_tool_bar (f
, 1);
8519 if (f
->n_tool_bar_items
)
8521 build_desired_tool_bar_string (f
);
8522 nlines
= tool_bar_lines_needed (f
);
8526 return make_number (nlines
);
8530 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
8531 height should be changed. */
8534 redisplay_tool_bar (f
)
8539 struct glyph_row
*row
;
8540 int change_height_p
= 0;
8543 if (FRAME_EXTERNAL_TOOL_BAR(f
))
8544 update_frame_tool_bar (f
);
8548 /* If frame hasn't a tool-bar window or if it is zero-height, don't
8549 do anything. This means you must start with tool-bar-lines
8550 non-zero to get the auto-sizing effect. Or in other words, you
8551 can turn off tool-bars by specifying tool-bar-lines zero. */
8552 if (!WINDOWP (f
->tool_bar_window
)
8553 || (w
= XWINDOW (f
->tool_bar_window
),
8554 WINDOW_TOTAL_LINES (w
) == 0))
8557 /* Set up an iterator for the tool-bar window. */
8558 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
8559 it
.first_visible_x
= 0;
8560 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8563 /* Build a string that represents the contents of the tool-bar. */
8564 build_desired_tool_bar_string (f
);
8565 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
8567 /* Display as many lines as needed to display all tool-bar items. */
8568 while (it
.current_y
< it
.last_visible_y
)
8569 display_tool_bar_line (&it
);
8571 /* It doesn't make much sense to try scrolling in the tool-bar
8572 window, so don't do it. */
8573 w
->desired_matrix
->no_scrolling_p
= 1;
8574 w
->must_be_updated_p
= 1;
8576 if (auto_resize_tool_bars_p
)
8580 /* If we couldn't display everything, change the tool-bar's
8582 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
8583 change_height_p
= 1;
8585 /* If there are blank lines at the end, except for a partially
8586 visible blank line at the end that is smaller than
8587 FRAME_LINE_HEIGHT, change the tool-bar's height. */
8588 row
= it
.glyph_row
- 1;
8589 if (!row
->displays_text_p
8590 && row
->height
>= FRAME_LINE_HEIGHT (f
))
8591 change_height_p
= 1;
8593 /* If row displays tool-bar items, but is partially visible,
8594 change the tool-bar's height. */
8595 if (row
->displays_text_p
8596 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
8597 change_height_p
= 1;
8599 /* Resize windows as needed by changing the `tool-bar-lines'
8602 && (nlines
= tool_bar_lines_needed (f
),
8603 nlines
!= WINDOW_TOTAL_LINES (w
)))
8605 extern Lisp_Object Qtool_bar_lines
;
8607 int old_height
= WINDOW_TOTAL_LINES (w
);
8609 XSETFRAME (frame
, f
);
8610 clear_glyph_matrix (w
->desired_matrix
);
8611 Fmodify_frame_parameters (frame
,
8612 Fcons (Fcons (Qtool_bar_lines
,
8613 make_number (nlines
)),
8615 if (WINDOW_TOTAL_LINES (w
) != old_height
)
8616 fonts_changed_p
= 1;
8620 return change_height_p
;
8624 /* Get information about the tool-bar item which is displayed in GLYPH
8625 on frame F. Return in *PROP_IDX the index where tool-bar item
8626 properties start in F->tool_bar_items. Value is zero if
8627 GLYPH doesn't display a tool-bar item. */
8630 tool_bar_item_info (f
, glyph
, prop_idx
)
8632 struct glyph
*glyph
;
8639 /* This function can be called asynchronously, which means we must
8640 exclude any possibility that Fget_text_property signals an
8642 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
8643 charpos
= max (0, charpos
);
8645 /* Get the text property `menu-item' at pos. The value of that
8646 property is the start index of this item's properties in
8647 F->tool_bar_items. */
8648 prop
= Fget_text_property (make_number (charpos
),
8649 Qmenu_item
, f
->current_tool_bar_string
);
8650 if (INTEGERP (prop
))
8652 *prop_idx
= XINT (prop
);
8662 /* Get information about the tool-bar item at position X/Y on frame F.
8663 Return in *GLYPH a pointer to the glyph of the tool-bar item in
8664 the current matrix of the tool-bar window of F, or NULL if not
8665 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
8666 item in F->tool_bar_items. Value is
8668 -1 if X/Y is not on a tool-bar item
8669 0 if X/Y is on the same item that was highlighted before.
8673 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
8676 struct glyph
**glyph
;
8677 int *hpos
, *vpos
, *prop_idx
;
8679 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8680 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8683 /* Find the glyph under X/Y. */
8684 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
8688 /* Get the start of this tool-bar item's properties in
8689 f->tool_bar_items. */
8690 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
8693 /* Is mouse on the highlighted item? */
8694 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
8695 && *vpos
>= dpyinfo
->mouse_face_beg_row
8696 && *vpos
<= dpyinfo
->mouse_face_end_row
8697 && (*vpos
> dpyinfo
->mouse_face_beg_row
8698 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
8699 && (*vpos
< dpyinfo
->mouse_face_end_row
8700 || *hpos
< dpyinfo
->mouse_face_end_col
8701 || dpyinfo
->mouse_face_past_end
))
8709 Handle mouse button event on the tool-bar of frame F, at
8710 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
8711 0 for button release. MODIFIERS is event modifiers for button
8715 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
8718 unsigned int modifiers
;
8720 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8721 struct window
*w
= XWINDOW (f
->tool_bar_window
);
8722 int hpos
, vpos
, prop_idx
;
8723 struct glyph
*glyph
;
8724 Lisp_Object enabled_p
;
8726 /* If not on the highlighted tool-bar item, return. */
8727 frame_to_window_pixel_xy (w
, &x
, &y
);
8728 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
8731 /* If item is disabled, do nothing. */
8732 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8733 if (NILP (enabled_p
))
8738 /* Show item in pressed state. */
8739 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
8740 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
8741 last_tool_bar_item
= prop_idx
;
8745 Lisp_Object key
, frame
;
8746 struct input_event event
;
8749 /* Show item in released state. */
8750 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
8751 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
8753 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
8755 XSETFRAME (frame
, f
);
8756 event
.kind
= TOOL_BAR_EVENT
;
8757 event
.frame_or_window
= frame
;
8759 kbd_buffer_store_event (&event
);
8761 event
.kind
= TOOL_BAR_EVENT
;
8762 event
.frame_or_window
= frame
;
8764 event
.modifiers
= modifiers
;
8765 kbd_buffer_store_event (&event
);
8766 last_tool_bar_item
= -1;
8771 /* Possibly highlight a tool-bar item on frame F when mouse moves to
8772 tool-bar window-relative coordinates X/Y. Called from
8773 note_mouse_highlight. */
8776 note_tool_bar_highlight (f
, x
, y
)
8780 Lisp_Object window
= f
->tool_bar_window
;
8781 struct window
*w
= XWINDOW (window
);
8782 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8784 struct glyph
*glyph
;
8785 struct glyph_row
*row
;
8787 Lisp_Object enabled_p
;
8789 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
8790 int mouse_down_p
, rc
;
8792 /* Function note_mouse_highlight is called with negative x(y
8793 values when mouse moves outside of the frame. */
8794 if (x
<= 0 || y
<= 0)
8796 clear_mouse_face (dpyinfo
);
8800 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
8803 /* Not on tool-bar item. */
8804 clear_mouse_face (dpyinfo
);
8808 /* On same tool-bar item as before. */
8811 clear_mouse_face (dpyinfo
);
8813 /* Mouse is down, but on different tool-bar item? */
8814 mouse_down_p
= (dpyinfo
->grabbed
8815 && f
== last_mouse_frame
8816 && FRAME_LIVE_P (f
));
8818 && last_tool_bar_item
!= prop_idx
)
8821 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
8822 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
8824 /* If tool-bar item is not enabled, don't highlight it. */
8825 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
8826 if (!NILP (enabled_p
))
8828 /* Compute the x-position of the glyph. In front and past the
8829 image is a space. We include this in the highlighted area. */
8830 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
8831 for (i
= x
= 0; i
< hpos
; ++i
)
8832 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
8834 /* Record this as the current active region. */
8835 dpyinfo
->mouse_face_beg_col
= hpos
;
8836 dpyinfo
->mouse_face_beg_row
= vpos
;
8837 dpyinfo
->mouse_face_beg_x
= x
;
8838 dpyinfo
->mouse_face_beg_y
= row
->y
;
8839 dpyinfo
->mouse_face_past_end
= 0;
8841 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
8842 dpyinfo
->mouse_face_end_row
= vpos
;
8843 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
8844 dpyinfo
->mouse_face_end_y
= row
->y
;
8845 dpyinfo
->mouse_face_window
= window
;
8846 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
8848 /* Display it as active. */
8849 show_mouse_face (dpyinfo
, draw
);
8850 dpyinfo
->mouse_face_image_state
= draw
;
8855 /* Set help_echo_string to a help string to display for this tool-bar item.
8856 XTread_socket does the rest. */
8857 help_echo_object
= help_echo_window
= Qnil
;
8859 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
8860 if (NILP (help_echo_string
))
8861 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
8864 #endif /* HAVE_WINDOW_SYSTEM */
8868 /***********************************************************************
8870 ***********************************************************************/
8872 #ifdef HAVE_WINDOW_SYSTEM
8874 /* An arrow like this: `<-'. */
8875 static unsigned char left_bits
[] = {
8876 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
8878 /* Right truncation arrow bitmap `->'. */
8879 static unsigned char right_bits
[] = {
8880 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
8882 /* Marker for continued lines. */
8883 static unsigned char continued_bits
[] = {
8884 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
8886 /* Marker for continuation lines. */
8887 static unsigned char continuation_bits
[] = {
8888 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
8890 /* Overlay arrow bitmap. A triangular arrow. */
8891 static unsigned char ov_bits
[] = {
8892 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
8894 /* Bitmap drawn to indicate lines not displaying text if
8895 `indicate-empty-lines' is non-nil. */
8896 static unsigned char zv_bits
[] = {
8897 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8898 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8899 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8900 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8901 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8902 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8903 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
8904 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
8906 struct fringe_bitmap fringe_bitmaps
[MAX_FRINGE_BITMAPS
] =
8908 { 0, 0, 0, NULL
/* NO_FRINGE_BITMAP */ },
8909 { 8, sizeof (left_bits
), 0, left_bits
},
8910 { 8, sizeof (right_bits
), 0, right_bits
},
8911 { 8, sizeof (continued_bits
), 0, continued_bits
},
8912 { 8, sizeof (continuation_bits
), 0, continuation_bits
},
8913 { 8, sizeof (ov_bits
), 0, ov_bits
},
8914 { 8, sizeof (zv_bits
), 3, zv_bits
}
8918 /* Draw the bitmap WHICH in one of the left or right fringes of
8919 window W. ROW is the glyph row for which to display the bitmap; it
8920 determines the vertical position at which the bitmap has to be
8924 draw_fringe_bitmap (w
, row
, which
, left_p
)
8926 struct glyph_row
*row
;
8927 enum fringe_bitmap_type which
;
8930 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8931 struct draw_fringe_bitmap_params p
;
8933 /* Convert row to frame coordinates. */
8934 p
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
8937 p
.wd
= fringe_bitmaps
[which
].width
;
8939 p
.h
= fringe_bitmaps
[which
].height
;
8940 p
.dh
= (fringe_bitmaps
[which
].period
8941 ? (p
.y
% fringe_bitmaps
[which
].period
)
8944 /* Clip bitmap if too high. */
8945 if (p
.h
> row
->height
)
8948 p
.face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
8949 PREPARE_FACE_FOR_DISPLAY (f
, p
.face
);
8951 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
8956 int wd
= WINDOW_LEFT_FRINGE_WIDTH (w
);
8957 int x
= window_box_left (w
, (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
8962 p
.x
= x
- p
.wd
- (wd
- p
.wd
) / 2;
8964 if (p
.wd
< wd
|| row
->height
> p
.h
)
8966 /* If W has a vertical border to its left, don't draw over it. */
8967 wd
-= ((!WINDOW_LEFTMOST_P (w
)
8968 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
8976 int x
= window_box_right (w
,
8977 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
8980 int wd
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
8983 p
.x
= x
+ (wd
- p
.wd
) / 2;
8984 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
8986 if (p
.wd
< wd
|| row
->height
> p
.h
)
8995 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
8997 p
.by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, row
->y
));
8998 p
.ny
= row
->visible_height
;
9001 /* Adjust y to the offset in the row to start drawing the bitmap. */
9002 p
.y
+= (row
->height
- p
.h
) / 2;
9004 rif
->draw_fringe_bitmap (w
, row
, &p
);
9007 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
9008 function with input blocked. */
9011 draw_row_fringe_bitmaps (w
, row
)
9013 struct glyph_row
*row
;
9015 enum fringe_bitmap_type bitmap
;
9017 xassert (interrupt_input_blocked
);
9019 /* If row is completely invisible, because of vscrolling, we
9020 don't have to draw anything. */
9021 if (row
->visible_height
<= 0)
9024 if (WINDOW_LEFT_FRINGE_WIDTH (w
) != 0)
9026 /* Decide which bitmap to draw in the left fringe. */
9027 if (row
->overlay_arrow_p
)
9028 bitmap
= OVERLAY_ARROW_BITMAP
;
9029 else if (row
->truncated_on_left_p
)
9030 bitmap
= LEFT_TRUNCATION_BITMAP
;
9031 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
9032 bitmap
= CONTINUATION_LINE_BITMAP
;
9033 else if (row
->indicate_empty_line_p
)
9034 bitmap
= ZV_LINE_BITMAP
;
9036 bitmap
= NO_FRINGE_BITMAP
;
9038 draw_fringe_bitmap (w
, row
, bitmap
, 1);
9041 if (WINDOW_RIGHT_FRINGE_WIDTH (w
) != 0)
9043 /* Decide which bitmap to draw in the right fringe. */
9044 if (row
->truncated_on_right_p
)
9045 bitmap
= RIGHT_TRUNCATION_BITMAP
;
9046 else if (row
->continued_p
)
9047 bitmap
= CONTINUED_LINE_BITMAP
;
9048 else if (row
->indicate_empty_line_p
&& WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
9049 bitmap
= ZV_LINE_BITMAP
;
9051 bitmap
= NO_FRINGE_BITMAP
;
9053 draw_fringe_bitmap (w
, row
, bitmap
, 0);
9058 /* Compute actual fringe widths */
9061 compute_fringe_widths (f
, redraw
)
9065 int o_left
= FRAME_LEFT_FRINGE_WIDTH (f
);
9066 int o_right
= FRAME_RIGHT_FRINGE_WIDTH (f
);
9067 int o_cols
= FRAME_FRINGE_COLS (f
);
9069 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
9070 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
9071 int left_fringe_width
, right_fringe_width
;
9073 if (!NILP (left_fringe
))
9074 left_fringe
= Fcdr (left_fringe
);
9075 if (!NILP (right_fringe
))
9076 right_fringe
= Fcdr (right_fringe
);
9078 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
9079 XINT (left_fringe
));
9080 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
9081 XINT (right_fringe
));
9083 if (left_fringe_width
|| right_fringe_width
)
9085 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
9086 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
9087 int conf_wid
= left_wid
+ right_wid
;
9088 int font_wid
= FRAME_COLUMN_WIDTH (f
);
9089 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
9090 int real_wid
= cols
* font_wid
;
9091 if (left_wid
&& right_wid
)
9093 if (left_fringe_width
< 0)
9095 /* Left fringe width is fixed, adjust right fringe if necessary */
9096 FRAME_LEFT_FRINGE_WIDTH (f
) = left_wid
;
9097 FRAME_RIGHT_FRINGE_WIDTH (f
) = real_wid
- left_wid
;
9099 else if (right_fringe_width
< 0)
9101 /* Right fringe width is fixed, adjust left fringe if necessary */
9102 FRAME_LEFT_FRINGE_WIDTH (f
) = real_wid
- right_wid
;
9103 FRAME_RIGHT_FRINGE_WIDTH (f
) = right_wid
;
9107 /* Adjust both fringes with an equal amount.
9108 Note that we are doing integer arithmetic here, so don't
9109 lose a pixel if the total width is an odd number. */
9110 int fill
= real_wid
- conf_wid
;
9111 FRAME_LEFT_FRINGE_WIDTH (f
) = left_wid
+ fill
/2;
9112 FRAME_RIGHT_FRINGE_WIDTH (f
) = right_wid
+ fill
- fill
/2;
9115 else if (left_fringe_width
)
9117 FRAME_LEFT_FRINGE_WIDTH (f
) = real_wid
;
9118 FRAME_RIGHT_FRINGE_WIDTH (f
) = 0;
9122 FRAME_LEFT_FRINGE_WIDTH (f
) = 0;
9123 FRAME_RIGHT_FRINGE_WIDTH (f
) = real_wid
;
9125 FRAME_FRINGE_COLS (f
) = cols
;
9129 FRAME_LEFT_FRINGE_WIDTH (f
) = 0;
9130 FRAME_RIGHT_FRINGE_WIDTH (f
) = 0;
9131 FRAME_FRINGE_COLS (f
) = 0;
9134 if (redraw
&& FRAME_VISIBLE_P (f
))
9135 if (o_left
!= FRAME_LEFT_FRINGE_WIDTH (f
) ||
9136 o_right
!= FRAME_RIGHT_FRINGE_WIDTH (f
) ||
9137 o_cols
!= FRAME_FRINGE_COLS (f
))
9141 #endif /* HAVE_WINDOW_SYSTEM */
9145 /************************************************************************
9146 Horizontal scrolling
9147 ************************************************************************/
9149 static int hscroll_window_tree
P_ ((Lisp_Object
));
9150 static int hscroll_windows
P_ ((Lisp_Object
));
9152 /* For all leaf windows in the window tree rooted at WINDOW, set their
9153 hscroll value so that PT is (i) visible in the window, and (ii) so
9154 that it is not within a certain margin at the window's left and
9155 right border. Value is non-zero if any window's hscroll has been
9159 hscroll_window_tree (window
)
9162 int hscrolled_p
= 0;
9163 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9164 int hscroll_step_abs
= 0;
9165 double hscroll_step_rel
= 0;
9167 if (hscroll_relative_p
)
9169 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9170 if (hscroll_step_rel
< 0)
9172 hscroll_relative_p
= 0;
9173 hscroll_step_abs
= 0;
9176 else if (INTEGERP (Vhscroll_step
))
9178 hscroll_step_abs
= XINT (Vhscroll_step
);
9179 if (hscroll_step_abs
< 0)
9180 hscroll_step_abs
= 0;
9183 hscroll_step_abs
= 0;
9185 while (WINDOWP (window
))
9187 struct window
*w
= XWINDOW (window
);
9189 if (WINDOWP (w
->hchild
))
9190 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9191 else if (WINDOWP (w
->vchild
))
9192 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9193 else if (w
->cursor
.vpos
>= 0)
9196 int text_area_width
;
9197 struct glyph_row
*current_cursor_row
9198 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9199 struct glyph_row
*desired_cursor_row
9200 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9201 struct glyph_row
*cursor_row
9202 = (desired_cursor_row
->enabled_p
9203 ? desired_cursor_row
9204 : current_cursor_row
);
9206 text_area_width
= window_box_width (w
, TEXT_AREA
);
9208 /* Scroll when cursor is inside this scroll margin. */
9209 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9211 if ((XFASTINT (w
->hscroll
)
9212 && w
->cursor
.x
<= h_margin
)
9213 || (cursor_row
->enabled_p
9214 && cursor_row
->truncated_on_right_p
9215 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9219 struct buffer
*saved_current_buffer
;
9223 /* Find point in a display of infinite width. */
9224 saved_current_buffer
= current_buffer
;
9225 current_buffer
= XBUFFER (w
->buffer
);
9227 if (w
== XWINDOW (selected_window
))
9228 pt
= BUF_PT (current_buffer
);
9231 pt
= marker_position (w
->pointm
);
9232 pt
= max (BEGV
, pt
);
9236 /* Move iterator to pt starting at cursor_row->start in
9237 a line with infinite width. */
9238 init_to_row_start (&it
, w
, cursor_row
);
9239 it
.last_visible_x
= INFINITY
;
9240 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9241 current_buffer
= saved_current_buffer
;
9243 /* Position cursor in window. */
9244 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9245 hscroll
= max (0, it
.current_x
- text_area_width
/ 2)
9246 / FRAME_COLUMN_WIDTH (it
.f
);
9247 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9249 if (hscroll_relative_p
)
9250 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9253 wanted_x
= text_area_width
9254 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9257 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9261 if (hscroll_relative_p
)
9262 wanted_x
= text_area_width
* hscroll_step_rel
9265 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9268 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9270 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9272 /* Don't call Fset_window_hscroll if value hasn't
9273 changed because it will prevent redisplay
9275 if (XFASTINT (w
->hscroll
) != hscroll
)
9277 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9278 w
->hscroll
= make_number (hscroll
);
9287 /* Value is non-zero if hscroll of any leaf window has been changed. */
9292 /* Set hscroll so that cursor is visible and not inside horizontal
9293 scroll margins for all windows in the tree rooted at WINDOW. See
9294 also hscroll_window_tree above. Value is non-zero if any window's
9295 hscroll has been changed. If it has, desired matrices on the frame
9296 of WINDOW are cleared. */
9299 hscroll_windows (window
)
9304 if (automatic_hscrolling_p
)
9306 hscrolled_p
= hscroll_window_tree (window
);
9308 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9317 /************************************************************************
9319 ************************************************************************/
9321 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9322 to a non-zero value. This is sometimes handy to have in a debugger
9327 /* First and last unchanged row for try_window_id. */
9329 int debug_first_unchanged_at_end_vpos
;
9330 int debug_last_unchanged_at_beg_vpos
;
9332 /* Delta vpos and y. */
9334 int debug_dvpos
, debug_dy
;
9336 /* Delta in characters and bytes for try_window_id. */
9338 int debug_delta
, debug_delta_bytes
;
9340 /* Values of window_end_pos and window_end_vpos at the end of
9343 EMACS_INT debug_end_pos
, debug_end_vpos
;
9345 /* Append a string to W->desired_matrix->method. FMT is a printf
9346 format string. A1...A9 are a supplement for a variable-length
9347 argument list. If trace_redisplay_p is non-zero also printf the
9348 resulting string to stderr. */
9351 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9354 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9357 char *method
= w
->desired_matrix
->method
;
9358 int len
= strlen (method
);
9359 int size
= sizeof w
->desired_matrix
->method
;
9360 int remaining
= size
- len
- 1;
9362 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9363 if (len
&& remaining
)
9369 strncpy (method
+ len
, buffer
, remaining
);
9371 if (trace_redisplay_p
)
9372 fprintf (stderr
, "%p (%s): %s\n",
9374 ((BUFFERP (w
->buffer
)
9375 && STRINGP (XBUFFER (w
->buffer
)->name
))
9376 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9381 #endif /* GLYPH_DEBUG */
9384 /* Value is non-zero if all changes in window W, which displays
9385 current_buffer, are in the text between START and END. START is a
9386 buffer position, END is given as a distance from Z. Used in
9387 redisplay_internal for display optimization. */
9390 text_outside_line_unchanged_p (w
, start
, end
)
9394 int unchanged_p
= 1;
9396 /* If text or overlays have changed, see where. */
9397 if (XFASTINT (w
->last_modified
) < MODIFF
9398 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9400 /* Gap in the line? */
9401 if (GPT
< start
|| Z
- GPT
< end
)
9404 /* Changes start in front of the line, or end after it? */
9406 && (BEG_UNCHANGED
< start
- 1
9407 || END_UNCHANGED
< end
))
9410 /* If selective display, can't optimize if changes start at the
9411 beginning of the line. */
9413 && INTEGERP (current_buffer
->selective_display
)
9414 && XINT (current_buffer
->selective_display
) > 0
9415 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9418 /* If there are overlays at the start or end of the line, these
9419 may have overlay strings with newlines in them. A change at
9420 START, for instance, may actually concern the display of such
9421 overlay strings as well, and they are displayed on different
9422 lines. So, quickly rule out this case. (For the future, it
9423 might be desirable to implement something more telling than
9424 just BEG/END_UNCHANGED.) */
9427 if (BEG
+ BEG_UNCHANGED
== start
9428 && overlay_touches_p (start
))
9430 if (END_UNCHANGED
== end
9431 && overlay_touches_p (Z
- end
))
9440 /* Do a frame update, taking possible shortcuts into account. This is
9441 the main external entry point for redisplay.
9443 If the last redisplay displayed an echo area message and that message
9444 is no longer requested, we clear the echo area or bring back the
9445 mini-buffer if that is in use. */
9450 redisplay_internal (0);
9454 /* Return 1 if point moved out of or into a composition. Otherwise
9455 return 0. PREV_BUF and PREV_PT are the last point buffer and
9456 position. BUF and PT are the current point buffer and position. */
9459 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9460 struct buffer
*prev_buf
, *buf
;
9467 XSETBUFFER (buffer
, buf
);
9468 /* Check a composition at the last point if point moved within the
9470 if (prev_buf
== buf
)
9473 /* Point didn't move. */
9476 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9477 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9478 && COMPOSITION_VALID_P (start
, end
, prop
)
9479 && start
< prev_pt
&& end
> prev_pt
)
9480 /* The last point was within the composition. Return 1 iff
9481 point moved out of the composition. */
9482 return (pt
<= start
|| pt
>= end
);
9485 /* Check a composition at the current point. */
9486 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9487 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9488 && COMPOSITION_VALID_P (start
, end
, prop
)
9489 && start
< pt
&& end
> pt
);
9493 /* Reconsider the setting of B->clip_changed which is displayed
9497 reconsider_clip_changes (w
, b
)
9502 && !NILP (w
->window_end_valid
)
9503 && w
->current_matrix
->buffer
== b
9504 && w
->current_matrix
->zv
== BUF_ZV (b
)
9505 && w
->current_matrix
->begv
== BUF_BEGV (b
))
9506 b
->clip_changed
= 0;
9508 /* If display wasn't paused, and W is not a tool bar window, see if
9509 point has been moved into or out of a composition. In that case,
9510 we set b->clip_changed to 1 to force updating the screen. If
9511 b->clip_changed has already been set to 1, we can skip this
9513 if (!b
->clip_changed
9514 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
9518 if (w
== XWINDOW (selected_window
))
9519 pt
= BUF_PT (current_buffer
);
9521 pt
= marker_position (w
->pointm
);
9523 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
9524 || pt
!= XINT (w
->last_point
))
9525 && check_point_in_composition (w
->current_matrix
->buffer
,
9526 XINT (w
->last_point
),
9527 XBUFFER (w
->buffer
), pt
))
9528 b
->clip_changed
= 1;
9532 #define STOP_POLLING \
9533 do { if (! polling_stopped_here) stop_polling (); \
9534 polling_stopped_here = 1; } while (0)
9536 #define RESUME_POLLING \
9537 do { if (polling_stopped_here) start_polling (); \
9538 polling_stopped_here = 0; } while (0)
9541 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
9542 response to any user action; therefore, we should preserve the echo
9543 area. (Actually, our caller does that job.) Perhaps in the future
9544 avoid recentering windows if it is not necessary; currently that
9545 causes some problems. */
9548 redisplay_internal (preserve_echo_area
)
9549 int preserve_echo_area
;
9551 struct window
*w
= XWINDOW (selected_window
);
9552 struct frame
*f
= XFRAME (w
->frame
);
9554 int must_finish
= 0;
9555 struct text_pos tlbufpos
, tlendpos
;
9556 int number_of_visible_frames
;
9558 struct frame
*sf
= SELECTED_FRAME ();
9559 int polling_stopped_here
= 0;
9561 /* Non-zero means redisplay has to consider all windows on all
9562 frames. Zero means, only selected_window is considered. */
9563 int consider_all_windows_p
;
9565 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
9567 /* No redisplay if running in batch mode or frame is not yet fully
9568 initialized, or redisplay is explicitly turned off by setting
9569 Vinhibit_redisplay. */
9571 || !NILP (Vinhibit_redisplay
)
9572 || !f
->glyphs_initialized_p
)
9575 /* The flag redisplay_performed_directly_p is set by
9576 direct_output_for_insert when it already did the whole screen
9577 update necessary. */
9578 if (redisplay_performed_directly_p
)
9580 redisplay_performed_directly_p
= 0;
9581 if (!hscroll_windows (selected_window
))
9585 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9586 if (popup_activated ())
9590 /* I don't think this happens but let's be paranoid. */
9594 /* Record a function that resets redisplaying_p to its old value
9595 when we leave this function. */
9596 count
= SPECPDL_INDEX ();
9597 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
9599 specbind (Qinhibit_free_realized_faces
, Qnil
);
9603 reconsider_clip_changes (w
, current_buffer
);
9605 /* If new fonts have been loaded that make a glyph matrix adjustment
9606 necessary, do it. */
9607 if (fonts_changed_p
)
9609 adjust_glyphs (NULL
);
9610 ++windows_or_buffers_changed
;
9611 fonts_changed_p
= 0;
9614 /* If face_change_count is non-zero, init_iterator will free all
9615 realized faces, which includes the faces referenced from current
9616 matrices. So, we can't reuse current matrices in this case. */
9617 if (face_change_count
)
9618 ++windows_or_buffers_changed
;
9620 if (! FRAME_WINDOW_P (sf
)
9621 && previous_terminal_frame
!= sf
)
9623 /* Since frames on an ASCII terminal share the same display
9624 area, displaying a different frame means redisplay the whole
9626 windows_or_buffers_changed
++;
9627 SET_FRAME_GARBAGED (sf
);
9628 XSETFRAME (Vterminal_frame
, sf
);
9630 previous_terminal_frame
= sf
;
9632 /* Set the visible flags for all frames. Do this before checking
9633 for resized or garbaged frames; they want to know if their frames
9634 are visible. See the comment in frame.h for
9635 FRAME_SAMPLE_VISIBILITY. */
9637 Lisp_Object tail
, frame
;
9639 number_of_visible_frames
= 0;
9641 FOR_EACH_FRAME (tail
, frame
)
9643 struct frame
*f
= XFRAME (frame
);
9645 FRAME_SAMPLE_VISIBILITY (f
);
9646 if (FRAME_VISIBLE_P (f
))
9647 ++number_of_visible_frames
;
9648 clear_desired_matrices (f
);
9652 /* Notice any pending interrupt request to change frame size. */
9653 do_pending_window_change (1);
9655 /* Clear frames marked as garbaged. */
9657 clear_garbaged_frames ();
9659 /* Build menubar and tool-bar items. */
9660 prepare_menu_bars ();
9662 if (windows_or_buffers_changed
)
9663 update_mode_lines
++;
9665 /* Detect case that we need to write or remove a star in the mode line. */
9666 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
9668 w
->update_mode_line
= Qt
;
9669 if (buffer_shared
> 1)
9670 update_mode_lines
++;
9673 /* If %c is in the mode line, update it if needed. */
9674 if (!NILP (w
->column_number_displayed
)
9675 /* This alternative quickly identifies a common case
9676 where no change is needed. */
9677 && !(PT
== XFASTINT (w
->last_point
)
9678 && XFASTINT (w
->last_modified
) >= MODIFF
9679 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
9680 && (XFASTINT (w
->column_number_displayed
)
9681 != (int) current_column ())) /* iftc */
9682 w
->update_mode_line
= Qt
;
9684 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
9686 /* The variable buffer_shared is set in redisplay_window and
9687 indicates that we redisplay a buffer in different windows. See
9689 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
9690 || cursor_type_changed
);
9692 /* If specs for an arrow have changed, do thorough redisplay
9693 to ensure we remove any arrow that should no longer exist. */
9694 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
9695 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
9696 consider_all_windows_p
= windows_or_buffers_changed
= 1;
9698 /* Normally the message* functions will have already displayed and
9699 updated the echo area, but the frame may have been trashed, or
9700 the update may have been preempted, so display the echo area
9701 again here. Checking message_cleared_p captures the case that
9702 the echo area should be cleared. */
9703 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
9704 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
9705 || (message_cleared_p
9706 && minibuf_level
== 0
9707 /* If the mini-window is currently selected, this means the
9708 echo-area doesn't show through. */
9709 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
9711 int window_height_changed_p
= echo_area_display (0);
9714 /* If we don't display the current message, don't clear the
9715 message_cleared_p flag, because, if we did, we wouldn't clear
9716 the echo area in the next redisplay which doesn't preserve
9718 if (!display_last_displayed_message_p
)
9719 message_cleared_p
= 0;
9721 if (fonts_changed_p
)
9723 else if (window_height_changed_p
)
9725 consider_all_windows_p
= 1;
9726 ++update_mode_lines
;
9727 ++windows_or_buffers_changed
;
9729 /* If window configuration was changed, frames may have been
9730 marked garbaged. Clear them or we will experience
9731 surprises wrt scrolling. */
9733 clear_garbaged_frames ();
9736 else if (EQ (selected_window
, minibuf_window
)
9737 && (current_buffer
->clip_changed
9738 || XFASTINT (w
->last_modified
) < MODIFF
9739 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9740 && resize_mini_window (w
, 0))
9742 /* Resized active mini-window to fit the size of what it is
9743 showing if its contents might have changed. */
9745 consider_all_windows_p
= 1;
9746 ++windows_or_buffers_changed
;
9747 ++update_mode_lines
;
9749 /* If window configuration was changed, frames may have been
9750 marked garbaged. Clear them or we will experience
9751 surprises wrt scrolling. */
9753 clear_garbaged_frames ();
9757 /* If showing the region, and mark has changed, we must redisplay
9758 the whole window. The assignment to this_line_start_pos prevents
9759 the optimization directly below this if-statement. */
9760 if (((!NILP (Vtransient_mark_mode
)
9761 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9762 != !NILP (w
->region_showing
))
9763 || (!NILP (w
->region_showing
)
9764 && !EQ (w
->region_showing
,
9765 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
9766 CHARPOS (this_line_start_pos
) = 0;
9768 /* Optimize the case that only the line containing the cursor in the
9769 selected window has changed. Variables starting with this_ are
9770 set in display_line and record information about the line
9771 containing the cursor. */
9772 tlbufpos
= this_line_start_pos
;
9773 tlendpos
= this_line_end_pos
;
9774 if (!consider_all_windows_p
9775 && CHARPOS (tlbufpos
) > 0
9776 && NILP (w
->update_mode_line
)
9777 && !current_buffer
->clip_changed
9778 && !current_buffer
->prevent_redisplay_optimizations_p
9779 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
9780 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
9781 /* Make sure recorded data applies to current buffer, etc. */
9782 && this_line_buffer
== current_buffer
9783 && current_buffer
== XBUFFER (w
->buffer
)
9784 && NILP (w
->force_start
)
9785 && NILP (w
->optional_new_start
)
9786 /* Point must be on the line that we have info recorded about. */
9787 && PT
>= CHARPOS (tlbufpos
)
9788 && PT
<= Z
- CHARPOS (tlendpos
)
9789 /* All text outside that line, including its final newline,
9790 must be unchanged */
9791 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
9792 CHARPOS (tlendpos
)))
9794 if (CHARPOS (tlbufpos
) > BEGV
9795 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
9796 && (CHARPOS (tlbufpos
) == ZV
9797 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
9798 /* Former continuation line has disappeared by becoming empty */
9800 else if (XFASTINT (w
->last_modified
) < MODIFF
9801 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
9802 || MINI_WINDOW_P (w
))
9804 /* We have to handle the case of continuation around a
9805 wide-column character (See the comment in indent.c around
9808 For instance, in the following case:
9810 -------- Insert --------
9811 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
9812 J_I_ ==> J_I_ `^^' are cursors.
9816 As we have to redraw the line above, we should goto cancel. */
9819 int line_height_before
= this_line_pixel_height
;
9821 /* Note that start_display will handle the case that the
9822 line starting at tlbufpos is a continuation lines. */
9823 start_display (&it
, w
, tlbufpos
);
9825 /* Implementation note: It this still necessary? */
9826 if (it
.current_x
!= this_line_start_x
)
9829 TRACE ((stderr
, "trying display optimization 1\n"));
9830 w
->cursor
.vpos
= -1;
9831 overlay_arrow_seen
= 0;
9832 it
.vpos
= this_line_vpos
;
9833 it
.current_y
= this_line_y
;
9834 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
9837 /* If line contains point, is not continued,
9838 and ends at same distance from eob as before, we win */
9839 if (w
->cursor
.vpos
>= 0
9840 /* Line is not continued, otherwise this_line_start_pos
9841 would have been set to 0 in display_line. */
9842 && CHARPOS (this_line_start_pos
)
9843 /* Line ends as before. */
9844 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
9845 /* Line has same height as before. Otherwise other lines
9846 would have to be shifted up or down. */
9847 && this_line_pixel_height
== line_height_before
)
9849 /* If this is not the window's last line, we must adjust
9850 the charstarts of the lines below. */
9851 if (it
.current_y
< it
.last_visible_y
)
9853 struct glyph_row
*row
9854 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
9855 int delta
, delta_bytes
;
9857 if (Z
- CHARPOS (tlendpos
) == ZV
)
9859 /* This line ends at end of (accessible part of)
9860 buffer. There is no newline to count. */
9862 - CHARPOS (tlendpos
)
9863 - MATRIX_ROW_START_CHARPOS (row
));
9864 delta_bytes
= (Z_BYTE
9865 - BYTEPOS (tlendpos
)
9866 - MATRIX_ROW_START_BYTEPOS (row
));
9870 /* This line ends in a newline. Must take
9871 account of the newline and the rest of the
9872 text that follows. */
9874 - CHARPOS (tlendpos
)
9875 - MATRIX_ROW_START_CHARPOS (row
));
9876 delta_bytes
= (Z_BYTE
9877 - BYTEPOS (tlendpos
)
9878 - MATRIX_ROW_START_BYTEPOS (row
));
9881 increment_matrix_positions (w
->current_matrix
,
9883 w
->current_matrix
->nrows
,
9884 delta
, delta_bytes
);
9887 /* If this row displays text now but previously didn't,
9888 or vice versa, w->window_end_vpos may have to be
9890 if ((it
.glyph_row
- 1)->displays_text_p
)
9892 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
9893 XSETINT (w
->window_end_vpos
, this_line_vpos
);
9895 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
9896 && this_line_vpos
> 0)
9897 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
9898 w
->window_end_valid
= Qnil
;
9900 /* Update hint: No need to try to scroll in update_window. */
9901 w
->desired_matrix
->no_scrolling_p
= 1;
9904 *w
->desired_matrix
->method
= 0;
9905 debug_method_add (w
, "optimization 1");
9912 else if (/* Cursor position hasn't changed. */
9913 PT
== XFASTINT (w
->last_point
)
9914 /* Make sure the cursor was last displayed
9915 in this window. Otherwise we have to reposition it. */
9916 && 0 <= w
->cursor
.vpos
9917 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
9921 do_pending_window_change (1);
9923 /* We used to always goto end_of_redisplay here, but this
9924 isn't enough if we have a blinking cursor. */
9925 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
9926 goto end_of_redisplay
;
9930 /* If highlighting the region, or if the cursor is in the echo area,
9931 then we can't just move the cursor. */
9932 else if (! (!NILP (Vtransient_mark_mode
)
9933 && !NILP (current_buffer
->mark_active
))
9934 && (EQ (selected_window
, current_buffer
->last_selected_window
)
9935 || highlight_nonselected_windows
)
9936 && NILP (w
->region_showing
)
9937 && NILP (Vshow_trailing_whitespace
)
9938 && !cursor_in_echo_area
)
9941 struct glyph_row
*row
;
9943 /* Skip from tlbufpos to PT and see where it is. Note that
9944 PT may be in invisible text. If so, we will end at the
9945 next visible position. */
9946 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
9947 NULL
, DEFAULT_FACE_ID
);
9948 it
.current_x
= this_line_start_x
;
9949 it
.current_y
= this_line_y
;
9950 it
.vpos
= this_line_vpos
;
9952 /* The call to move_it_to stops in front of PT, but
9953 moves over before-strings. */
9954 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
9956 if (it
.vpos
== this_line_vpos
9957 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
9960 xassert (this_line_vpos
== it
.vpos
);
9961 xassert (this_line_y
== it
.current_y
);
9962 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9964 *w
->desired_matrix
->method
= 0;
9965 debug_method_add (w
, "optimization 3");
9974 /* Text changed drastically or point moved off of line. */
9975 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
9978 CHARPOS (this_line_start_pos
) = 0;
9979 consider_all_windows_p
|= buffer_shared
> 1;
9980 ++clear_face_cache_count
;
9983 /* Build desired matrices, and update the display. If
9984 consider_all_windows_p is non-zero, do it for all windows on all
9985 frames. Otherwise do it for selected_window, only. */
9987 if (consider_all_windows_p
)
9989 Lisp_Object tail
, frame
;
9990 int i
, n
= 0, size
= 50;
9991 struct frame
**updated
9992 = (struct frame
**) alloca (size
* sizeof *updated
);
9994 /* Clear the face cache eventually. */
9995 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
9997 clear_face_cache (0);
9998 clear_face_cache_count
= 0;
10001 /* Recompute # windows showing selected buffer. This will be
10002 incremented each time such a window is displayed. */
10005 FOR_EACH_FRAME (tail
, frame
)
10007 struct frame
*f
= XFRAME (frame
);
10009 if (FRAME_WINDOW_P (f
) || f
== sf
)
10011 #ifdef HAVE_WINDOW_SYSTEM
10012 if (clear_face_cache_count
% 50 == 0
10013 && FRAME_WINDOW_P (f
))
10014 clear_image_cache (f
, 0);
10015 #endif /* HAVE_WINDOW_SYSTEM */
10017 /* Mark all the scroll bars to be removed; we'll redeem
10018 the ones we want when we redisplay their windows. */
10019 if (condemn_scroll_bars_hook
)
10020 condemn_scroll_bars_hook (f
);
10022 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10023 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10025 /* Any scroll bars which redisplay_windows should have
10026 nuked should now go away. */
10027 if (judge_scroll_bars_hook
)
10028 judge_scroll_bars_hook (f
);
10030 /* If fonts changed, display again. */
10031 /* ??? rms: I suspect it is a mistake to jump all the way
10032 back to retry here. It should just retry this frame. */
10033 if (fonts_changed_p
)
10036 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10038 /* See if we have to hscroll. */
10039 if (hscroll_windows (f
->root_window
))
10042 /* Prevent various kinds of signals during display
10043 update. stdio is not robust about handling
10044 signals, which can cause an apparent I/O
10046 if (interrupt_input
)
10047 unrequest_sigio ();
10050 /* Update the display. */
10051 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10052 pause
|= update_frame (f
, 0, 0);
10053 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10060 int nbytes
= size
* sizeof *updated
;
10061 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10062 bcopy (updated
, p
, nbytes
);
10071 /* Do the mark_window_display_accurate after all windows have
10072 been redisplayed because this call resets flags in buffers
10073 which are needed for proper redisplay. */
10074 for (i
= 0; i
< n
; ++i
)
10076 struct frame
*f
= updated
[i
];
10077 mark_window_display_accurate (f
->root_window
, 1);
10078 if (frame_up_to_date_hook
)
10079 frame_up_to_date_hook (f
);
10082 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10084 Lisp_Object mini_window
;
10085 struct frame
*mini_frame
;
10087 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10088 /* Use list_of_error, not Qerror, so that
10089 we catch only errors and don't run the debugger. */
10090 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10092 redisplay_window_error
);
10094 /* Compare desired and current matrices, perform output. */
10097 /* If fonts changed, display again. */
10098 if (fonts_changed_p
)
10101 /* Prevent various kinds of signals during display update.
10102 stdio is not robust about handling signals,
10103 which can cause an apparent I/O error. */
10104 if (interrupt_input
)
10105 unrequest_sigio ();
10108 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10110 if (hscroll_windows (selected_window
))
10113 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10114 pause
= update_frame (sf
, 0, 0);
10117 /* We may have called echo_area_display at the top of this
10118 function. If the echo area is on another frame, that may
10119 have put text on a frame other than the selected one, so the
10120 above call to update_frame would not have caught it. Catch
10122 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10123 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10125 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10127 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10128 pause
|= update_frame (mini_frame
, 0, 0);
10129 if (!pause
&& hscroll_windows (mini_window
))
10134 /* If display was paused because of pending input, make sure we do a
10135 thorough update the next time. */
10138 /* Prevent the optimization at the beginning of
10139 redisplay_internal that tries a single-line update of the
10140 line containing the cursor in the selected window. */
10141 CHARPOS (this_line_start_pos
) = 0;
10143 /* Let the overlay arrow be updated the next time. */
10144 if (!NILP (last_arrow_position
))
10146 last_arrow_position
= Qt
;
10147 last_arrow_string
= Qt
;
10150 /* If we pause after scrolling, some rows in the current
10151 matrices of some windows are not valid. */
10152 if (!WINDOW_FULL_WIDTH_P (w
)
10153 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10154 update_mode_lines
= 1;
10158 if (!consider_all_windows_p
)
10160 /* This has already been done above if
10161 consider_all_windows_p is set. */
10162 mark_window_display_accurate_1 (w
, 1);
10164 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
10165 last_arrow_string
= Voverlay_arrow_string
;
10167 if (frame_up_to_date_hook
!= 0)
10168 frame_up_to_date_hook (sf
);
10171 update_mode_lines
= 0;
10172 windows_or_buffers_changed
= 0;
10173 cursor_type_changed
= 0;
10176 /* Start SIGIO interrupts coming again. Having them off during the
10177 code above makes it less likely one will discard output, but not
10178 impossible, since there might be stuff in the system buffer here.
10179 But it is much hairier to try to do anything about that. */
10180 if (interrupt_input
)
10184 /* If a frame has become visible which was not before, redisplay
10185 again, so that we display it. Expose events for such a frame
10186 (which it gets when becoming visible) don't call the parts of
10187 redisplay constructing glyphs, so simply exposing a frame won't
10188 display anything in this case. So, we have to display these
10189 frames here explicitly. */
10192 Lisp_Object tail
, frame
;
10195 FOR_EACH_FRAME (tail
, frame
)
10197 int this_is_visible
= 0;
10199 if (XFRAME (frame
)->visible
)
10200 this_is_visible
= 1;
10201 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10202 if (XFRAME (frame
)->visible
)
10203 this_is_visible
= 1;
10205 if (this_is_visible
)
10209 if (new_count
!= number_of_visible_frames
)
10210 windows_or_buffers_changed
++;
10213 /* Change frame size now if a change is pending. */
10214 do_pending_window_change (1);
10216 /* If we just did a pending size change, or have additional
10217 visible frames, redisplay again. */
10218 if (windows_or_buffers_changed
&& !pause
)
10222 unbind_to (count
, Qnil
);
10227 /* Redisplay, but leave alone any recent echo area message unless
10228 another message has been requested in its place.
10230 This is useful in situations where you need to redisplay but no
10231 user action has occurred, making it inappropriate for the message
10232 area to be cleared. See tracking_off and
10233 wait_reading_process_input for examples of these situations.
10235 FROM_WHERE is an integer saying from where this function was
10236 called. This is useful for debugging. */
10239 redisplay_preserve_echo_area (from_where
)
10242 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10244 if (!NILP (echo_area_buffer
[1]))
10246 /* We have a previously displayed message, but no current
10247 message. Redisplay the previous message. */
10248 display_last_displayed_message_p
= 1;
10249 redisplay_internal (1);
10250 display_last_displayed_message_p
= 0;
10253 redisplay_internal (1);
10257 /* Function registered with record_unwind_protect in
10258 redisplay_internal. Reset redisplaying_p to the value it had
10259 before redisplay_internal was called, and clear
10260 prevent_freeing_realized_faces_p. */
10263 unwind_redisplay (old_redisplaying_p
)
10264 Lisp_Object old_redisplaying_p
;
10266 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10271 /* Mark the display of window W as accurate or inaccurate. If
10272 ACCURATE_P is non-zero mark display of W as accurate. If
10273 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10274 redisplay_internal is called. */
10277 mark_window_display_accurate_1 (w
, accurate_p
)
10281 if (BUFFERP (w
->buffer
))
10283 struct buffer
*b
= XBUFFER (w
->buffer
);
10286 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10287 w
->last_overlay_modified
10288 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10290 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10294 b
->clip_changed
= 0;
10295 b
->prevent_redisplay_optimizations_p
= 0;
10297 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10298 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10299 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10300 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10302 w
->current_matrix
->buffer
= b
;
10303 w
->current_matrix
->begv
= BUF_BEGV (b
);
10304 w
->current_matrix
->zv
= BUF_ZV (b
);
10306 w
->last_cursor
= w
->cursor
;
10307 w
->last_cursor_off_p
= w
->cursor_off_p
;
10309 if (w
== XWINDOW (selected_window
))
10310 w
->last_point
= make_number (BUF_PT (b
));
10312 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10318 w
->window_end_valid
= w
->buffer
;
10319 #if 0 /* This is incorrect with variable-height lines. */
10320 xassert (XINT (w
->window_end_vpos
)
10321 < (WINDOW_TOTAL_LINES (w
)
10322 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10324 w
->update_mode_line
= Qnil
;
10329 /* Mark the display of windows in the window tree rooted at WINDOW as
10330 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10331 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10332 be redisplayed the next time redisplay_internal is called. */
10335 mark_window_display_accurate (window
, accurate_p
)
10336 Lisp_Object window
;
10341 for (; !NILP (window
); window
= w
->next
)
10343 w
= XWINDOW (window
);
10344 mark_window_display_accurate_1 (w
, accurate_p
);
10346 if (!NILP (w
->vchild
))
10347 mark_window_display_accurate (w
->vchild
, accurate_p
);
10348 if (!NILP (w
->hchild
))
10349 mark_window_display_accurate (w
->hchild
, accurate_p
);
10354 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
10355 last_arrow_string
= Voverlay_arrow_string
;
10359 /* Force a thorough redisplay the next time by setting
10360 last_arrow_position and last_arrow_string to t, which is
10361 unequal to any useful value of Voverlay_arrow_... */
10362 last_arrow_position
= Qt
;
10363 last_arrow_string
= Qt
;
10368 /* Return value in display table DP (Lisp_Char_Table *) for character
10369 C. Since a display table doesn't have any parent, we don't have to
10370 follow parent. Do not call this function directly but use the
10371 macro DISP_CHAR_VECTOR. */
10374 disp_char_vector (dp
, c
)
10375 struct Lisp_Char_Table
*dp
;
10381 if (SINGLE_BYTE_CHAR_P (c
))
10382 return (dp
->contents
[c
]);
10384 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10387 else if (code
[2] < 32)
10390 /* Here, the possible range of code[0] (== charset ID) is
10391 128..max_charset. Since the top level char table contains data
10392 for multibyte characters after 256th element, we must increment
10393 code[0] by 128 to get a correct index. */
10395 code
[3] = -1; /* anchor */
10397 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10399 val
= dp
->contents
[code
[i
]];
10400 if (!SUB_CHAR_TABLE_P (val
))
10401 return (NILP (val
) ? dp
->defalt
: val
);
10404 /* Here, val is a sub char table. We return the default value of
10406 return (dp
->defalt
);
10411 /***********************************************************************
10413 ***********************************************************************/
10415 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10418 redisplay_windows (window
)
10419 Lisp_Object window
;
10421 while (!NILP (window
))
10423 struct window
*w
= XWINDOW (window
);
10425 if (!NILP (w
->hchild
))
10426 redisplay_windows (w
->hchild
);
10427 else if (!NILP (w
->vchild
))
10428 redisplay_windows (w
->vchild
);
10431 displayed_buffer
= XBUFFER (w
->buffer
);
10432 /* Use list_of_error, not Qerror, so that
10433 we catch only errors and don't run the debugger. */
10434 internal_condition_case_1 (redisplay_window_0
, window
,
10436 redisplay_window_error
);
10444 redisplay_window_error ()
10446 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
10451 redisplay_window_0 (window
)
10452 Lisp_Object window
;
10454 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10455 redisplay_window (window
, 0);
10460 redisplay_window_1 (window
)
10461 Lisp_Object window
;
10463 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
10464 redisplay_window (window
, 1);
10469 /* Increment GLYPH until it reaches END or CONDITION fails while
10470 adding (GLYPH)->pixel_width to X. */
10472 #define SKIP_GLYPHS(glyph, end, x, condition) \
10475 (x) += (glyph)->pixel_width; \
10478 while ((glyph) < (end) && (condition))
10481 /* Set cursor position of W. PT is assumed to be displayed in ROW.
10482 DELTA is the number of bytes by which positions recorded in ROW
10483 differ from current buffer positions. */
10486 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
10488 struct glyph_row
*row
;
10489 struct glyph_matrix
*matrix
;
10490 int delta
, delta_bytes
, dy
, dvpos
;
10492 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
10493 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
10494 /* The first glyph that starts a sequence of glyphs from string. */
10495 struct glyph
*string_start
;
10496 /* The X coordinate of string_start. */
10497 int string_start_x
;
10498 /* The last known character position. */
10499 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
10500 /* The last known character position before string_start. */
10501 int string_before_pos
;
10503 int pt_old
= PT
- delta
;
10505 /* Skip over glyphs not having an object at the start of the row.
10506 These are special glyphs like truncation marks on terminal
10508 if (row
->displays_text_p
)
10510 && INTEGERP (glyph
->object
)
10511 && glyph
->charpos
< 0)
10513 x
+= glyph
->pixel_width
;
10517 string_start
= NULL
;
10519 && !INTEGERP (glyph
->object
)
10520 && (!BUFFERP (glyph
->object
)
10521 || (last_pos
= glyph
->charpos
) < pt_old
))
10523 if (! STRINGP (glyph
->object
))
10525 string_start
= NULL
;
10526 x
+= glyph
->pixel_width
;
10531 string_before_pos
= last_pos
;
10532 string_start
= glyph
;
10533 string_start_x
= x
;
10534 /* Skip all glyphs from string. */
10535 SKIP_GLYPHS (glyph
, end
, x
, STRINGP (glyph
->object
));
10540 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
10542 /* We may have skipped over point because the previous glyphs
10543 are from string. As there's no easy way to know the
10544 character position of the current glyph, find the correct
10545 glyph on point by scanning from string_start again. */
10547 Lisp_Object string
;
10550 limit
= make_number (pt_old
+ 1);
10552 glyph
= string_start
;
10553 x
= string_start_x
;
10554 string
= glyph
->object
;
10555 pos
= string_buffer_position (w
, string
, string_before_pos
);
10556 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
10557 because we always put cursor after overlay strings. */
10558 while (pos
== 0 && glyph
< end
)
10560 string
= glyph
->object
;
10561 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10563 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
10566 while (glyph
< end
)
10568 pos
= XINT (Fnext_single_char_property_change
10569 (make_number (pos
), Qdisplay
, Qnil
, limit
));
10572 /* Skip glyphs from the same string. */
10573 string
= glyph
->object
;
10574 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10575 /* Skip glyphs from an overlay. */
10577 && ! string_buffer_position (w
, glyph
->object
, pos
))
10579 string
= glyph
->object
;
10580 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
10585 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
10587 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
10588 w
->cursor
.y
= row
->y
+ dy
;
10590 if (w
== XWINDOW (selected_window
))
10592 if (!row
->continued_p
10593 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
10596 this_line_buffer
= XBUFFER (w
->buffer
);
10598 CHARPOS (this_line_start_pos
)
10599 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
10600 BYTEPOS (this_line_start_pos
)
10601 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
10603 CHARPOS (this_line_end_pos
)
10604 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
10605 BYTEPOS (this_line_end_pos
)
10606 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
10608 this_line_y
= w
->cursor
.y
;
10609 this_line_pixel_height
= row
->height
;
10610 this_line_vpos
= w
->cursor
.vpos
;
10611 this_line_start_x
= row
->x
;
10614 CHARPOS (this_line_start_pos
) = 0;
10619 /* Run window scroll functions, if any, for WINDOW with new window
10620 start STARTP. Sets the window start of WINDOW to that position.
10622 We assume that the window's buffer is really current. */
10624 static INLINE
struct text_pos
10625 run_window_scroll_functions (window
, startp
)
10626 Lisp_Object window
;
10627 struct text_pos startp
;
10629 struct window
*w
= XWINDOW (window
);
10630 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
10632 if (current_buffer
!= XBUFFER (w
->buffer
))
10635 if (!NILP (Vwindow_scroll_functions
))
10637 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
10638 make_number (CHARPOS (startp
)));
10639 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10640 /* In case the hook functions switch buffers. */
10641 if (current_buffer
!= XBUFFER (w
->buffer
))
10642 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10649 /* Make sure the line containing the cursor is fully visible.
10650 A value of 1 means there is nothing to be done.
10651 (Either the line is fully visible, or it cannot be made so,
10652 or we cannot tell.)
10653 A value of 0 means the caller should do scrolling
10654 as if point had gone off the screen. */
10657 make_cursor_line_fully_visible (w
)
10660 struct glyph_matrix
*matrix
;
10661 struct glyph_row
*row
;
10664 /* It's not always possible to find the cursor, e.g, when a window
10665 is full of overlay strings. Don't do anything in that case. */
10666 if (w
->cursor
.vpos
< 0)
10669 matrix
= w
->desired_matrix
;
10670 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
10672 /* If the cursor row is not partially visible, there's nothing to do. */
10673 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
10676 /* If the row the cursor is in is taller than the window's height,
10677 it's not clear what to do, so do nothing. */
10678 window_height
= window_box_height (w
);
10679 if (row
->height
>= window_height
)
10685 /* This code used to try to scroll the window just enough to make
10686 the line visible. It returned 0 to say that the caller should
10687 allocate larger glyph matrices. */
10689 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
10691 int dy
= row
->height
- row
->visible_height
;
10694 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10696 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
10698 int dy
= - (row
->height
- row
->visible_height
);
10701 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
10704 /* When we change the cursor y-position of the selected window,
10705 change this_line_y as well so that the display optimization for
10706 the cursor line of the selected window in redisplay_internal uses
10707 the correct y-position. */
10708 if (w
== XWINDOW (selected_window
))
10709 this_line_y
= w
->cursor
.y
;
10711 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
10712 redisplay with larger matrices. */
10713 if (matrix
->nrows
< required_matrix_height (w
))
10715 fonts_changed_p
= 1;
10724 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
10725 non-zero means only WINDOW is redisplayed in redisplay_internal.
10726 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
10727 in redisplay_window to bring a partially visible line into view in
10728 the case that only the cursor has moved.
10730 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
10731 last screen line's vertical height extends past the end of the screen.
10735 1 if scrolling succeeded
10737 0 if scrolling didn't find point.
10739 -1 if new fonts have been loaded so that we must interrupt
10740 redisplay, adjust glyph matrices, and try again. */
10746 SCROLLING_NEED_LARGER_MATRICES
10750 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
10751 scroll_step
, temp_scroll_step
, last_line_misfit
)
10752 Lisp_Object window
;
10753 int just_this_one_p
;
10754 EMACS_INT scroll_conservatively
, scroll_step
;
10755 int temp_scroll_step
;
10756 int last_line_misfit
;
10758 struct window
*w
= XWINDOW (window
);
10759 struct frame
*f
= XFRAME (w
->frame
);
10760 struct text_pos scroll_margin_pos
;
10761 struct text_pos pos
;
10762 struct text_pos startp
;
10764 Lisp_Object window_end
;
10765 int this_scroll_margin
;
10769 int amount_to_scroll
= 0;
10770 Lisp_Object aggressive
;
10772 int end_scroll_margin
;
10775 debug_method_add (w
, "try_scrolling");
10778 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
10780 /* Compute scroll margin height in pixels. We scroll when point is
10781 within this distance from the top or bottom of the window. */
10782 if (scroll_margin
> 0)
10784 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
10785 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
10788 this_scroll_margin
= 0;
10790 /* Compute how much we should try to scroll maximally to bring point
10792 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
10793 scroll_max
= max (scroll_step
,
10794 max (scroll_conservatively
, temp_scroll_step
));
10795 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
10796 || NUMBERP (current_buffer
->scroll_up_aggressively
))
10797 /* We're trying to scroll because of aggressive scrolling
10798 but no scroll_step is set. Choose an arbitrary one. Maybe
10799 there should be a variable for this. */
10803 scroll_max
*= FRAME_LINE_HEIGHT (f
);
10805 /* Decide whether we have to scroll down. Start at the window end
10806 and move this_scroll_margin up to find the position of the scroll
10808 window_end
= Fwindow_end (window
, Qt
);
10812 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
10813 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
10815 end_scroll_margin
= this_scroll_margin
+ !!last_line_misfit
;
10816 if (end_scroll_margin
)
10818 start_display (&it
, w
, scroll_margin_pos
);
10819 move_it_vertically (&it
, - end_scroll_margin
);
10820 scroll_margin_pos
= it
.current
.pos
;
10823 if (PT
>= CHARPOS (scroll_margin_pos
))
10827 /* Point is in the scroll margin at the bottom of the window, or
10828 below. Compute a new window start that makes point visible. */
10830 /* Compute the distance from the scroll margin to PT.
10831 Give up if the distance is greater than scroll_max. */
10832 start_display (&it
, w
, scroll_margin_pos
);
10834 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
10835 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10837 /* To make point visible, we have to move the window start
10838 down so that the line the cursor is in is visible, which
10839 means we have to add in the height of the cursor line. */
10840 dy
= line_bottom_y (&it
) - y0
;
10842 if (dy
> scroll_max
)
10843 return SCROLLING_FAILED
;
10845 /* Move the window start down. If scrolling conservatively,
10846 move it just enough down to make point visible. If
10847 scroll_step is set, move it down by scroll_step. */
10848 start_display (&it
, w
, startp
);
10850 if (scroll_conservatively
)
10851 /* Set AMOUNT_TO_SCROLL to at least one line,
10852 and at most scroll_conservatively lines. */
10854 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
10855 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
10856 else if (scroll_step
|| temp_scroll_step
)
10857 amount_to_scroll
= scroll_max
;
10860 aggressive
= current_buffer
->scroll_up_aggressively
;
10861 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
10862 if (NUMBERP (aggressive
))
10863 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
10866 if (amount_to_scroll
<= 0)
10867 return SCROLLING_FAILED
;
10869 /* If moving by amount_to_scroll leaves STARTP unchanged,
10870 move it down one screen line. */
10872 move_it_vertically (&it
, amount_to_scroll
);
10873 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
10874 move_it_by_lines (&it
, 1, 1);
10875 startp
= it
.current
.pos
;
10879 /* See if point is inside the scroll margin at the top of the
10881 scroll_margin_pos
= startp
;
10882 if (this_scroll_margin
)
10884 start_display (&it
, w
, startp
);
10885 move_it_vertically (&it
, this_scroll_margin
);
10886 scroll_margin_pos
= it
.current
.pos
;
10889 if (PT
< CHARPOS (scroll_margin_pos
))
10891 /* Point is in the scroll margin at the top of the window or
10892 above what is displayed in the window. */
10895 /* Compute the vertical distance from PT to the scroll
10896 margin position. Give up if distance is greater than
10898 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
10899 start_display (&it
, w
, pos
);
10901 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
10902 it
.last_visible_y
, -1,
10903 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
10904 dy
= it
.current_y
- y0
;
10905 if (dy
> scroll_max
)
10906 return SCROLLING_FAILED
;
10908 /* Compute new window start. */
10909 start_display (&it
, w
, startp
);
10911 if (scroll_conservatively
)
10913 max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
10914 else if (scroll_step
|| temp_scroll_step
)
10915 amount_to_scroll
= scroll_max
;
10918 aggressive
= current_buffer
->scroll_down_aggressively
;
10919 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
10920 if (NUMBERP (aggressive
))
10921 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
10924 if (amount_to_scroll
<= 0)
10925 return SCROLLING_FAILED
;
10927 move_it_vertically (&it
, - amount_to_scroll
);
10928 startp
= it
.current
.pos
;
10932 /* Run window scroll functions. */
10933 startp
= run_window_scroll_functions (window
, startp
);
10935 /* Display the window. Give up if new fonts are loaded, or if point
10937 if (!try_window (window
, startp
))
10938 rc
= SCROLLING_NEED_LARGER_MATRICES
;
10939 else if (w
->cursor
.vpos
< 0)
10941 clear_glyph_matrix (w
->desired_matrix
);
10942 rc
= SCROLLING_FAILED
;
10946 /* Maybe forget recorded base line for line number display. */
10947 if (!just_this_one_p
10948 || current_buffer
->clip_changed
10949 || BEG_UNCHANGED
< CHARPOS (startp
))
10950 w
->base_line_number
= Qnil
;
10952 /* If cursor ends up on a partially visible line,
10953 treat that as being off the bottom of the screen. */
10954 if (! make_cursor_line_fully_visible (w
))
10956 clear_glyph_matrix (w
->desired_matrix
);
10957 last_line_misfit
= 1;
10960 rc
= SCROLLING_SUCCESS
;
10967 /* Compute a suitable window start for window W if display of W starts
10968 on a continuation line. Value is non-zero if a new window start
10971 The new window start will be computed, based on W's width, starting
10972 from the start of the continued line. It is the start of the
10973 screen line with the minimum distance from the old start W->start. */
10976 compute_window_start_on_continuation_line (w
)
10979 struct text_pos pos
, start_pos
;
10980 int window_start_changed_p
= 0;
10982 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
10984 /* If window start is on a continuation line... Window start may be
10985 < BEGV in case there's invisible text at the start of the
10986 buffer (M-x rmail, for example). */
10987 if (CHARPOS (start_pos
) > BEGV
10988 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
10991 struct glyph_row
*row
;
10993 /* Handle the case that the window start is out of range. */
10994 if (CHARPOS (start_pos
) < BEGV
)
10995 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
10996 else if (CHARPOS (start_pos
) > ZV
)
10997 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
10999 /* Find the start of the continued line. This should be fast
11000 because scan_buffer is fast (newline cache). */
11001 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11002 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11003 row
, DEFAULT_FACE_ID
);
11004 reseat_at_previous_visible_line_start (&it
);
11006 /* If the line start is "too far" away from the window start,
11007 say it takes too much time to compute a new window start. */
11008 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11009 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11011 int min_distance
, distance
;
11013 /* Move forward by display lines to find the new window
11014 start. If window width was enlarged, the new start can
11015 be expected to be > the old start. If window width was
11016 decreased, the new window start will be < the old start.
11017 So, we're looking for the display line start with the
11018 minimum distance from the old window start. */
11019 pos
= it
.current
.pos
;
11020 min_distance
= INFINITY
;
11021 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11022 distance
< min_distance
)
11024 min_distance
= distance
;
11025 pos
= it
.current
.pos
;
11026 move_it_by_lines (&it
, 1, 0);
11029 /* Set the window start there. */
11030 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11031 window_start_changed_p
= 1;
11035 return window_start_changed_p
;
11039 /* Try cursor movement in case text has not changed in window WINDOW,
11040 with window start STARTP. Value is
11042 CURSOR_MOVEMENT_SUCCESS if successful
11044 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11046 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11047 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11048 we want to scroll as if scroll-step were set to 1. See the code.
11050 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11051 which case we have to abort this redisplay, and adjust matrices
11056 CURSOR_MOVEMENT_SUCCESS
,
11057 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11058 CURSOR_MOVEMENT_MUST_SCROLL
,
11059 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11063 try_cursor_movement (window
, startp
, scroll_step
)
11064 Lisp_Object window
;
11065 struct text_pos startp
;
11068 struct window
*w
= XWINDOW (window
);
11069 struct frame
*f
= XFRAME (w
->frame
);
11070 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11073 if (inhibit_try_cursor_movement
)
11077 /* Handle case where text has not changed, only point, and it has
11078 not moved off the frame. */
11079 if (/* Point may be in this window. */
11080 PT
>= CHARPOS (startp
)
11081 /* Selective display hasn't changed. */
11082 && !current_buffer
->clip_changed
11083 /* Function force-mode-line-update is used to force a thorough
11084 redisplay. It sets either windows_or_buffers_changed or
11085 update_mode_lines. So don't take a shortcut here for these
11087 && !update_mode_lines
11088 && !windows_or_buffers_changed
11089 && !cursor_type_changed
11090 /* Can't use this case if highlighting a region. When a
11091 region exists, cursor movement has to do more than just
11093 && !(!NILP (Vtransient_mark_mode
)
11094 && !NILP (current_buffer
->mark_active
))
11095 && NILP (w
->region_showing
)
11096 && NILP (Vshow_trailing_whitespace
)
11097 /* Right after splitting windows, last_point may be nil. */
11098 && INTEGERP (w
->last_point
)
11099 /* This code is not used for mini-buffer for the sake of the case
11100 of redisplaying to replace an echo area message; since in
11101 that case the mini-buffer contents per se are usually
11102 unchanged. This code is of no real use in the mini-buffer
11103 since the handling of this_line_start_pos, etc., in redisplay
11104 handles the same cases. */
11105 && !EQ (window
, minibuf_window
)
11106 /* When splitting windows or for new windows, it happens that
11107 redisplay is called with a nil window_end_vpos or one being
11108 larger than the window. This should really be fixed in
11109 window.c. I don't have this on my list, now, so we do
11110 approximately the same as the old redisplay code. --gerd. */
11111 && INTEGERP (w
->window_end_vpos
)
11112 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11113 && (FRAME_WINDOW_P (f
)
11114 || !MARKERP (Voverlay_arrow_position
)
11115 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
11117 int this_scroll_margin
;
11118 struct glyph_row
*row
= NULL
;
11121 debug_method_add (w
, "cursor movement");
11124 /* Scroll if point within this distance from the top or bottom
11125 of the window. This is a pixel value. */
11126 this_scroll_margin
= max (0, scroll_margin
);
11127 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11128 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11130 /* Start with the row the cursor was displayed during the last
11131 not paused redisplay. Give up if that row is not valid. */
11132 if (w
->last_cursor
.vpos
< 0
11133 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11134 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11137 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11138 if (row
->mode_line_p
)
11140 if (!row
->enabled_p
)
11141 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11144 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11147 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11149 if (PT
> XFASTINT (w
->last_point
))
11151 /* Point has moved forward. */
11152 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11153 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11155 xassert (row
->enabled_p
);
11159 /* The end position of a row equals the start position
11160 of the next row. If PT is there, we would rather
11161 display it in the next line. */
11162 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11163 && MATRIX_ROW_END_CHARPOS (row
) == PT
11164 && !cursor_row_p (w
, row
))
11167 /* If within the scroll margin, scroll. Note that
11168 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11169 the next line would be drawn, and that
11170 this_scroll_margin can be zero. */
11171 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11172 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11173 /* Line is completely visible last line in window
11174 and PT is to be set in the next line. */
11175 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11176 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11177 && !row
->ends_at_zv_p
11178 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11181 else if (PT
< XFASTINT (w
->last_point
))
11183 /* Cursor has to be moved backward. Note that PT >=
11184 CHARPOS (startp) because of the outer
11186 while (!row
->mode_line_p
11187 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11188 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11189 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11190 && (row
->y
> this_scroll_margin
11191 || CHARPOS (startp
) == BEGV
))
11193 xassert (row
->enabled_p
);
11197 /* Consider the following case: Window starts at BEGV,
11198 there is invisible, intangible text at BEGV, so that
11199 display starts at some point START > BEGV. It can
11200 happen that we are called with PT somewhere between
11201 BEGV and START. Try to handle that case. */
11202 if (row
< w
->current_matrix
->rows
11203 || row
->mode_line_p
)
11205 row
= w
->current_matrix
->rows
;
11206 if (row
->mode_line_p
)
11210 /* Due to newlines in overlay strings, we may have to
11211 skip forward over overlay strings. */
11212 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11213 && MATRIX_ROW_END_CHARPOS (row
) == PT
11214 && !cursor_row_p (w
, row
))
11217 /* If within the scroll margin, scroll. */
11218 if (row
->y
< this_scroll_margin
11219 && CHARPOS (startp
) != BEGV
)
11223 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11224 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11226 /* if PT is not in the glyph row, give up. */
11227 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11229 else if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
11231 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11232 && !row
->ends_at_zv_p
11233 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11234 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11235 else if (row
->height
> window_box_height (w
))
11237 /* If we end up in a partially visible line, let's
11238 make it fully visible, except when it's taller
11239 than the window, in which case we can't do much
11242 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11246 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11247 if (!make_cursor_line_fully_visible (w
))
11248 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11250 rc
= CURSOR_MOVEMENT_SUCCESS
;
11254 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11257 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11258 rc
= CURSOR_MOVEMENT_SUCCESS
;
11267 set_vertical_scroll_bar (w
)
11270 int start
, end
, whole
;
11272 /* Calculate the start and end positions for the current window.
11273 At some point, it would be nice to choose between scrollbars
11274 which reflect the whole buffer size, with special markers
11275 indicating narrowing, and scrollbars which reflect only the
11278 Note that mini-buffers sometimes aren't displaying any text. */
11279 if (!MINI_WINDOW_P (w
)
11280 || (w
== XWINDOW (minibuf_window
)
11281 && NILP (echo_area_buffer
[0])))
11283 struct buffer
*buf
= XBUFFER (w
->buffer
);
11284 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11285 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11286 /* I don't think this is guaranteed to be right. For the
11287 moment, we'll pretend it is. */
11288 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11292 if (whole
< (end
- start
))
11293 whole
= end
- start
;
11296 start
= end
= whole
= 0;
11298 /* Indicate what this scroll bar ought to be displaying now. */
11299 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
11302 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11303 selected_window is redisplayed.
11305 We can return without actually redisplaying the window if
11306 fonts_changed_p is nonzero. In that case, redisplay_internal will
11310 redisplay_window (window
, just_this_one_p
)
11311 Lisp_Object window
;
11312 int just_this_one_p
;
11314 struct window
*w
= XWINDOW (window
);
11315 struct frame
*f
= XFRAME (w
->frame
);
11316 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11317 struct buffer
*old
= current_buffer
;
11318 struct text_pos lpoint
, opoint
, startp
;
11319 int update_mode_line
;
11322 /* Record it now because it's overwritten. */
11323 int current_matrix_up_to_date_p
= 0;
11324 /* This is less strict than current_matrix_up_to_date_p.
11325 It indictes that the buffer contents and narrowing are unchanged. */
11326 int buffer_unchanged_p
= 0;
11327 int temp_scroll_step
= 0;
11328 int count
= SPECPDL_INDEX ();
11330 int centering_position
;
11331 int last_line_misfit
= 0;
11333 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11336 /* W must be a leaf window here. */
11337 xassert (!NILP (w
->buffer
));
11339 *w
->desired_matrix
->method
= 0;
11342 specbind (Qinhibit_point_motion_hooks
, Qt
);
11344 reconsider_clip_changes (w
, buffer
);
11346 /* Has the mode line to be updated? */
11347 update_mode_line
= (!NILP (w
->update_mode_line
)
11348 || update_mode_lines
11349 || buffer
->clip_changed
11350 || buffer
->prevent_redisplay_optimizations_p
);
11352 if (MINI_WINDOW_P (w
))
11354 if (w
== XWINDOW (echo_area_window
)
11355 && !NILP (echo_area_buffer
[0]))
11357 if (update_mode_line
)
11358 /* We may have to update a tty frame's menu bar or a
11359 tool-bar. Example `M-x C-h C-h C-g'. */
11360 goto finish_menu_bars
;
11362 /* We've already displayed the echo area glyphs in this window. */
11363 goto finish_scroll_bars
;
11365 else if ((w
!= XWINDOW (minibuf_window
)
11366 || minibuf_level
== 0)
11367 /* When buffer is nonempty, redisplay window normally. */
11368 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
11369 /* Quail displays non-mini buffers in minibuffer window.
11370 In that case, redisplay the window normally. */
11371 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
11373 /* W is a mini-buffer window, but it's not active, so clear
11375 int yb
= window_text_bottom_y (w
);
11376 struct glyph_row
*row
;
11379 for (y
= 0, row
= w
->desired_matrix
->rows
;
11381 y
+= row
->height
, ++row
)
11382 blank_row (w
, row
, y
);
11383 goto finish_scroll_bars
;
11386 clear_glyph_matrix (w
->desired_matrix
);
11389 /* Otherwise set up data on this window; select its buffer and point
11391 /* Really select the buffer, for the sake of buffer-local
11393 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11394 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
11396 current_matrix_up_to_date_p
11397 = (!NILP (w
->window_end_valid
)
11398 && !current_buffer
->clip_changed
11399 && !current_buffer
->prevent_redisplay_optimizations_p
11400 && XFASTINT (w
->last_modified
) >= MODIFF
11401 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11404 = (!NILP (w
->window_end_valid
)
11405 && !current_buffer
->clip_changed
11406 && XFASTINT (w
->last_modified
) >= MODIFF
11407 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
11409 /* When windows_or_buffers_changed is non-zero, we can't rely on
11410 the window end being valid, so set it to nil there. */
11411 if (windows_or_buffers_changed
)
11413 /* If window starts on a continuation line, maybe adjust the
11414 window start in case the window's width changed. */
11415 if (XMARKER (w
->start
)->buffer
== current_buffer
)
11416 compute_window_start_on_continuation_line (w
);
11418 w
->window_end_valid
= Qnil
;
11421 /* Some sanity checks. */
11422 CHECK_WINDOW_END (w
);
11423 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
11425 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
11428 /* If %c is in mode line, update it if needed. */
11429 if (!NILP (w
->column_number_displayed
)
11430 /* This alternative quickly identifies a common case
11431 where no change is needed. */
11432 && !(PT
== XFASTINT (w
->last_point
)
11433 && XFASTINT (w
->last_modified
) >= MODIFF
11434 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11435 && (XFASTINT (w
->column_number_displayed
)
11436 != (int) current_column ())) /* iftc */
11437 update_mode_line
= 1;
11439 /* Count number of windows showing the selected buffer. An indirect
11440 buffer counts as its base buffer. */
11441 if (!just_this_one_p
)
11443 struct buffer
*current_base
, *window_base
;
11444 current_base
= current_buffer
;
11445 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11446 if (current_base
->base_buffer
)
11447 current_base
= current_base
->base_buffer
;
11448 if (window_base
->base_buffer
)
11449 window_base
= window_base
->base_buffer
;
11450 if (current_base
== window_base
)
11454 /* Point refers normally to the selected window. For any other
11455 window, set up appropriate value. */
11456 if (!EQ (window
, selected_window
))
11458 int new_pt
= XMARKER (w
->pointm
)->charpos
;
11459 int new_pt_byte
= marker_byte_position (w
->pointm
);
11463 new_pt_byte
= BEGV_BYTE
;
11464 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
11466 else if (new_pt
> (ZV
- 1))
11469 new_pt_byte
= ZV_BYTE
;
11470 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
11473 /* We don't use SET_PT so that the point-motion hooks don't run. */
11474 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
11477 /* If any of the character widths specified in the display table
11478 have changed, invalidate the width run cache. It's true that
11479 this may be a bit late to catch such changes, but the rest of
11480 redisplay goes (non-fatally) haywire when the display table is
11481 changed, so why should we worry about doing any better? */
11482 if (current_buffer
->width_run_cache
)
11484 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
11486 if (! disptab_matches_widthtab (disptab
,
11487 XVECTOR (current_buffer
->width_table
)))
11489 invalidate_region_cache (current_buffer
,
11490 current_buffer
->width_run_cache
,
11492 recompute_width_table (current_buffer
, disptab
);
11496 /* If window-start is screwed up, choose a new one. */
11497 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
11500 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11502 /* If someone specified a new starting point but did not insist,
11503 check whether it can be used. */
11504 if (!NILP (w
->optional_new_start
)
11505 && CHARPOS (startp
) >= BEGV
11506 && CHARPOS (startp
) <= ZV
)
11508 w
->optional_new_start
= Qnil
;
11509 start_display (&it
, w
, startp
);
11510 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11511 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11512 if (IT_CHARPOS (it
) == PT
)
11513 w
->force_start
= Qt
;
11516 /* Handle case where place to start displaying has been specified,
11517 unless the specified location is outside the accessible range. */
11518 if (!NILP (w
->force_start
)
11519 || w
->frozen_window_start_p
)
11521 /* We set this later on if we have to adjust point. */
11524 w
->force_start
= Qnil
;
11526 w
->window_end_valid
= Qnil
;
11528 /* Forget any recorded base line for line number display. */
11529 if (!buffer_unchanged_p
)
11530 w
->base_line_number
= Qnil
;
11532 /* Redisplay the mode line. Select the buffer properly for that.
11533 Also, run the hook window-scroll-functions
11534 because we have scrolled. */
11535 /* Note, we do this after clearing force_start because
11536 if there's an error, it is better to forget about force_start
11537 than to get into an infinite loop calling the hook functions
11538 and having them get more errors. */
11539 if (!update_mode_line
11540 || ! NILP (Vwindow_scroll_functions
))
11542 update_mode_line
= 1;
11543 w
->update_mode_line
= Qt
;
11544 startp
= run_window_scroll_functions (window
, startp
);
11547 w
->last_modified
= make_number (0);
11548 w
->last_overlay_modified
= make_number (0);
11549 if (CHARPOS (startp
) < BEGV
)
11550 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
11551 else if (CHARPOS (startp
) > ZV
)
11552 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
11554 /* Redisplay, then check if cursor has been set during the
11555 redisplay. Give up if new fonts were loaded. */
11556 if (!try_window (window
, startp
))
11558 w
->force_start
= Qt
;
11559 clear_glyph_matrix (w
->desired_matrix
);
11560 goto need_larger_matrices
;
11563 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
11565 /* If point does not appear, try to move point so it does
11566 appear. The desired matrix has been built above, so we
11567 can use it here. */
11568 new_vpos
= window_box_height (w
) / 2;
11571 if (!make_cursor_line_fully_visible (w
))
11573 /* Point does appear, but on a line partly visible at end of window.
11574 Move it back to a fully-visible line. */
11575 new_vpos
= window_box_height (w
);
11578 /* If we need to move point for either of the above reasons,
11579 now actually do it. */
11582 struct glyph_row
*row
;
11584 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
11585 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
11588 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
11589 MATRIX_ROW_START_BYTEPOS (row
));
11591 if (w
!= XWINDOW (selected_window
))
11592 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
11593 else if (current_buffer
== old
)
11594 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11596 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
11598 /* If we are highlighting the region, then we just changed
11599 the region, so redisplay to show it. */
11600 if (!NILP (Vtransient_mark_mode
)
11601 && !NILP (current_buffer
->mark_active
))
11603 clear_glyph_matrix (w
->desired_matrix
);
11604 if (!try_window (window
, startp
))
11605 goto need_larger_matrices
;
11610 debug_method_add (w
, "forced window start");
11615 /* Handle case where text has not changed, only point, and it has
11616 not moved off the frame, and we are not retrying after hscroll.
11617 (current_matrix_up_to_date_p is nonzero when retrying.) */
11618 if (current_matrix_up_to_date_p
11619 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
11620 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
11624 case CURSOR_MOVEMENT_SUCCESS
:
11627 #if 0 /* try_cursor_movement never returns this value. */
11628 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
11629 goto need_larger_matrices
;
11632 case CURSOR_MOVEMENT_MUST_SCROLL
:
11633 goto try_to_scroll
;
11639 /* If current starting point was originally the beginning of a line
11640 but no longer is, find a new starting point. */
11641 else if (!NILP (w
->start_at_line_beg
)
11642 && !(CHARPOS (startp
) <= BEGV
11643 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
11646 debug_method_add (w
, "recenter 1");
11651 /* Try scrolling with try_window_id. Value is > 0 if update has
11652 been done, it is -1 if we know that the same window start will
11653 not work. It is 0 if unsuccessful for some other reason. */
11654 else if ((tem
= try_window_id (w
)) != 0)
11657 debug_method_add (w
, "try_window_id %d", tem
);
11660 if (fonts_changed_p
)
11661 goto need_larger_matrices
;
11665 /* Otherwise try_window_id has returned -1 which means that we
11666 don't want the alternative below this comment to execute. */
11668 else if (CHARPOS (startp
) >= BEGV
11669 && CHARPOS (startp
) <= ZV
11670 && PT
>= CHARPOS (startp
)
11671 && (CHARPOS (startp
) < ZV
11672 /* Avoid starting at end of buffer. */
11673 || CHARPOS (startp
) == BEGV
11674 || (XFASTINT (w
->last_modified
) >= MODIFF
11675 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
11678 debug_method_add (w
, "same window start");
11681 /* Try to redisplay starting at same place as before.
11682 If point has not moved off frame, accept the results. */
11683 if (!current_matrix_up_to_date_p
11684 /* Don't use try_window_reusing_current_matrix in this case
11685 because a window scroll function can have changed the
11687 || !NILP (Vwindow_scroll_functions
)
11688 || MINI_WINDOW_P (w
)
11689 || !try_window_reusing_current_matrix (w
))
11691 IF_DEBUG (debug_method_add (w
, "1"));
11692 try_window (window
, startp
);
11695 if (fonts_changed_p
)
11696 goto need_larger_matrices
;
11698 if (w
->cursor
.vpos
>= 0)
11700 if (!just_this_one_p
11701 || current_buffer
->clip_changed
11702 || BEG_UNCHANGED
< CHARPOS (startp
))
11703 /* Forget any recorded base line for line number display. */
11704 w
->base_line_number
= Qnil
;
11706 if (!make_cursor_line_fully_visible (w
))
11708 clear_glyph_matrix (w
->desired_matrix
);
11709 last_line_misfit
= 1;
11711 /* Drop through and scroll. */
11716 clear_glyph_matrix (w
->desired_matrix
);
11721 w
->last_modified
= make_number (0);
11722 w
->last_overlay_modified
= make_number (0);
11724 /* Redisplay the mode line. Select the buffer properly for that. */
11725 if (!update_mode_line
)
11727 update_mode_line
= 1;
11728 w
->update_mode_line
= Qt
;
11731 /* Try to scroll by specified few lines. */
11732 if ((scroll_conservatively
11734 || temp_scroll_step
11735 || NUMBERP (current_buffer
->scroll_up_aggressively
)
11736 || NUMBERP (current_buffer
->scroll_down_aggressively
))
11737 && !current_buffer
->clip_changed
11738 && CHARPOS (startp
) >= BEGV
11739 && CHARPOS (startp
) <= ZV
)
11741 /* The function returns -1 if new fonts were loaded, 1 if
11742 successful, 0 if not successful. */
11743 int rc
= try_scrolling (window
, just_this_one_p
,
11744 scroll_conservatively
,
11746 temp_scroll_step
, last_line_misfit
);
11749 case SCROLLING_SUCCESS
:
11752 case SCROLLING_NEED_LARGER_MATRICES
:
11753 goto need_larger_matrices
;
11755 case SCROLLING_FAILED
:
11763 /* Finally, just choose place to start which centers point */
11766 centering_position
= window_box_height (w
) / 2;
11769 /* Jump here with centering_position already set to 0. */
11772 debug_method_add (w
, "recenter");
11775 /* w->vscroll = 0; */
11777 /* Forget any previously recorded base line for line number display. */
11778 if (!buffer_unchanged_p
)
11779 w
->base_line_number
= Qnil
;
11781 /* Move backward half the height of the window. */
11782 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11783 it
.current_y
= it
.last_visible_y
;
11784 move_it_vertically_backward (&it
, centering_position
);
11785 xassert (IT_CHARPOS (it
) >= BEGV
);
11787 /* The function move_it_vertically_backward may move over more
11788 than the specified y-distance. If it->w is small, e.g. a
11789 mini-buffer window, we may end up in front of the window's
11790 display area. Start displaying at the start of the line
11791 containing PT in this case. */
11792 if (it
.current_y
<= 0)
11794 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
11795 move_it_vertically (&it
, 0);
11796 xassert (IT_CHARPOS (it
) <= PT
);
11800 it
.current_x
= it
.hpos
= 0;
11802 /* Set startp here explicitly in case that helps avoid an infinite loop
11803 in case the window-scroll-functions functions get errors. */
11804 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
11806 /* Run scroll hooks. */
11807 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
11809 /* Redisplay the window. */
11810 if (!current_matrix_up_to_date_p
11811 || windows_or_buffers_changed
11812 || cursor_type_changed
11813 /* Don't use try_window_reusing_current_matrix in this case
11814 because it can have changed the buffer. */
11815 || !NILP (Vwindow_scroll_functions
)
11816 || !just_this_one_p
11817 || MINI_WINDOW_P (w
)
11818 || !try_window_reusing_current_matrix (w
))
11819 try_window (window
, startp
);
11821 /* If new fonts have been loaded (due to fontsets), give up. We
11822 have to start a new redisplay since we need to re-adjust glyph
11824 if (fonts_changed_p
)
11825 goto need_larger_matrices
;
11827 /* If cursor did not appear assume that the middle of the window is
11828 in the first line of the window. Do it again with the next line.
11829 (Imagine a window of height 100, displaying two lines of height
11830 60. Moving back 50 from it->last_visible_y will end in the first
11832 if (w
->cursor
.vpos
< 0)
11834 if (!NILP (w
->window_end_valid
)
11835 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
11837 clear_glyph_matrix (w
->desired_matrix
);
11838 move_it_by_lines (&it
, 1, 0);
11839 try_window (window
, it
.current
.pos
);
11841 else if (PT
< IT_CHARPOS (it
))
11843 clear_glyph_matrix (w
->desired_matrix
);
11844 move_it_by_lines (&it
, -1, 0);
11845 try_window (window
, it
.current
.pos
);
11849 /* Not much we can do about it. */
11853 /* Consider the following case: Window starts at BEGV, there is
11854 invisible, intangible text at BEGV, so that display starts at
11855 some point START > BEGV. It can happen that we are called with
11856 PT somewhere between BEGV and START. Try to handle that case. */
11857 if (w
->cursor
.vpos
< 0)
11859 struct glyph_row
*row
= w
->current_matrix
->rows
;
11860 if (row
->mode_line_p
)
11862 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11865 if (!make_cursor_line_fully_visible (w
))
11867 /* If vscroll is enabled, disable it and try again. */
11871 clear_glyph_matrix (w
->desired_matrix
);
11875 /* If centering point failed to make the whole line visible,
11876 put point at the top instead. That has to make the whole line
11877 visible, if it can be done. */
11878 centering_position
= 0;
11884 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11885 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
11886 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
11889 /* Display the mode line, if we must. */
11890 if ((update_mode_line
11891 /* If window not full width, must redo its mode line
11892 if (a) the window to its side is being redone and
11893 (b) we do a frame-based redisplay. This is a consequence
11894 of how inverted lines are drawn in frame-based redisplay. */
11895 || (!just_this_one_p
11896 && !FRAME_WINDOW_P (f
)
11897 && !WINDOW_FULL_WIDTH_P (w
))
11898 /* Line number to display. */
11899 || INTEGERP (w
->base_line_pos
)
11900 /* Column number is displayed and different from the one displayed. */
11901 || (!NILP (w
->column_number_displayed
)
11902 && (XFASTINT (w
->column_number_displayed
)
11903 != (int) current_column ()))) /* iftc */
11904 /* This means that the window has a mode line. */
11905 && (WINDOW_WANTS_MODELINE_P (w
)
11906 || WINDOW_WANTS_HEADER_LINE_P (w
)))
11908 display_mode_lines (w
);
11910 /* If mode line height has changed, arrange for a thorough
11911 immediate redisplay using the correct mode line height. */
11912 if (WINDOW_WANTS_MODELINE_P (w
)
11913 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
11915 fonts_changed_p
= 1;
11916 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
11917 = DESIRED_MODE_LINE_HEIGHT (w
);
11920 /* If top line height has changed, arrange for a thorough
11921 immediate redisplay using the correct mode line height. */
11922 if (WINDOW_WANTS_HEADER_LINE_P (w
)
11923 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
11925 fonts_changed_p
= 1;
11926 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
11927 = DESIRED_HEADER_LINE_HEIGHT (w
);
11930 if (fonts_changed_p
)
11931 goto need_larger_matrices
;
11934 if (!line_number_displayed
11935 && !BUFFERP (w
->base_line_pos
))
11937 w
->base_line_pos
= Qnil
;
11938 w
->base_line_number
= Qnil
;
11943 /* When we reach a frame's selected window, redo the frame's menu bar. */
11944 if (update_mode_line
11945 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
11947 int redisplay_menu_p
= 0;
11948 int redisplay_tool_bar_p
= 0;
11950 if (FRAME_WINDOW_P (f
))
11952 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
11953 || defined (USE_GTK)
11954 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
11956 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
11960 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
11962 if (redisplay_menu_p
)
11963 display_menu_bar (w
);
11965 #ifdef HAVE_WINDOW_SYSTEM
11967 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
11969 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
11970 && (FRAME_TOOL_BAR_LINES (f
) > 0
11971 || auto_resize_tool_bars_p
);
11975 if (redisplay_tool_bar_p
)
11976 redisplay_tool_bar (f
);
11980 /* We go to this label, with fonts_changed_p nonzero,
11981 if it is necessary to try again using larger glyph matrices.
11982 We have to redeem the scroll bar even in this case,
11983 because the loop in redisplay_internal expects that. */
11984 need_larger_matrices
:
11986 finish_scroll_bars
:
11988 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
11990 /* Set the thumb's position and size. */
11991 set_vertical_scroll_bar (w
);
11993 /* Note that we actually used the scroll bar attached to this
11994 window, so it shouldn't be deleted at the end of redisplay. */
11995 redeem_scroll_bar_hook (w
);
11998 /* Restore current_buffer and value of point in it. */
11999 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12000 set_buffer_internal_1 (old
);
12001 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12003 unbind_to (count
, Qnil
);
12007 /* Build the complete desired matrix of WINDOW with a window start
12008 buffer position POS. Value is non-zero if successful. It is zero
12009 if fonts were loaded during redisplay which makes re-adjusting
12010 glyph matrices necessary. */
12013 try_window (window
, pos
)
12014 Lisp_Object window
;
12015 struct text_pos pos
;
12017 struct window
*w
= XWINDOW (window
);
12019 struct glyph_row
*last_text_row
= NULL
;
12021 /* Make POS the new window start. */
12022 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12024 /* Mark cursor position as unknown. No overlay arrow seen. */
12025 w
->cursor
.vpos
= -1;
12026 overlay_arrow_seen
= 0;
12028 /* Initialize iterator and info to start at POS. */
12029 start_display (&it
, w
, pos
);
12031 /* Display all lines of W. */
12032 while (it
.current_y
< it
.last_visible_y
)
12034 if (display_line (&it
))
12035 last_text_row
= it
.glyph_row
- 1;
12036 if (fonts_changed_p
)
12040 /* If bottom moved off end of frame, change mode line percentage. */
12041 if (XFASTINT (w
->window_end_pos
) <= 0
12042 && Z
!= IT_CHARPOS (it
))
12043 w
->update_mode_line
= Qt
;
12045 /* Set window_end_pos to the offset of the last character displayed
12046 on the window from the end of current_buffer. Set
12047 window_end_vpos to its row number. */
12050 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12051 w
->window_end_bytepos
12052 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12054 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12056 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12057 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12058 ->displays_text_p
);
12062 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12063 w
->window_end_pos
= make_number (Z
- ZV
);
12064 w
->window_end_vpos
= make_number (0);
12067 /* But that is not valid info until redisplay finishes. */
12068 w
->window_end_valid
= Qnil
;
12074 /************************************************************************
12075 Window redisplay reusing current matrix when buffer has not changed
12076 ************************************************************************/
12078 /* Try redisplay of window W showing an unchanged buffer with a
12079 different window start than the last time it was displayed by
12080 reusing its current matrix. Value is non-zero if successful.
12081 W->start is the new window start. */
12084 try_window_reusing_current_matrix (w
)
12087 struct frame
*f
= XFRAME (w
->frame
);
12088 struct glyph_row
*row
, *bottom_row
;
12091 struct text_pos start
, new_start
;
12092 int nrows_scrolled
, i
;
12093 struct glyph_row
*last_text_row
;
12094 struct glyph_row
*last_reused_text_row
;
12095 struct glyph_row
*start_row
;
12096 int start_vpos
, min_y
, max_y
;
12099 if (inhibit_try_window_reusing
)
12103 if (/* This function doesn't handle terminal frames. */
12104 !FRAME_WINDOW_P (f
)
12105 /* Don't try to reuse the display if windows have been split
12107 || windows_or_buffers_changed
12108 || cursor_type_changed
)
12111 /* Can't do this if region may have changed. */
12112 if ((!NILP (Vtransient_mark_mode
)
12113 && !NILP (current_buffer
->mark_active
))
12114 || !NILP (w
->region_showing
)
12115 || !NILP (Vshow_trailing_whitespace
))
12118 /* If top-line visibility has changed, give up. */
12119 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12120 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12123 /* Give up if old or new display is scrolled vertically. We could
12124 make this function handle this, but right now it doesn't. */
12125 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12126 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
12129 /* The variable new_start now holds the new window start. The old
12130 start `start' can be determined from the current matrix. */
12131 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12132 start
= start_row
->start
.pos
;
12133 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12135 /* Clear the desired matrix for the display below. */
12136 clear_glyph_matrix (w
->desired_matrix
);
12138 if (CHARPOS (new_start
) <= CHARPOS (start
))
12142 /* Don't use this method if the display starts with an ellipsis
12143 displayed for invisible text. It's not easy to handle that case
12144 below, and it's certainly not worth the effort since this is
12145 not a frequent case. */
12146 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12149 IF_DEBUG (debug_method_add (w
, "twu1"));
12151 /* Display up to a row that can be reused. The variable
12152 last_text_row is set to the last row displayed that displays
12153 text. Note that it.vpos == 0 if or if not there is a
12154 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12155 start_display (&it
, w
, new_start
);
12156 first_row_y
= it
.current_y
;
12157 w
->cursor
.vpos
= -1;
12158 last_text_row
= last_reused_text_row
= NULL
;
12160 while (it
.current_y
< it
.last_visible_y
12161 && IT_CHARPOS (it
) < CHARPOS (start
)
12162 && !fonts_changed_p
)
12163 if (display_line (&it
))
12164 last_text_row
= it
.glyph_row
- 1;
12166 /* A value of current_y < last_visible_y means that we stopped
12167 at the previous window start, which in turn means that we
12168 have at least one reusable row. */
12169 if (it
.current_y
< it
.last_visible_y
)
12171 /* IT.vpos always starts from 0; it counts text lines. */
12172 nrows_scrolled
= it
.vpos
;
12174 /* Find PT if not already found in the lines displayed. */
12175 if (w
->cursor
.vpos
< 0)
12177 int dy
= it
.current_y
- first_row_y
;
12179 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12180 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12182 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12183 dy
, nrows_scrolled
);
12186 clear_glyph_matrix (w
->desired_matrix
);
12191 /* Scroll the display. Do it before the current matrix is
12192 changed. The problem here is that update has not yet
12193 run, i.e. part of the current matrix is not up to date.
12194 scroll_run_hook will clear the cursor, and use the
12195 current matrix to get the height of the row the cursor is
12197 run
.current_y
= first_row_y
;
12198 run
.desired_y
= it
.current_y
;
12199 run
.height
= it
.last_visible_y
- it
.current_y
;
12201 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12204 rif
->update_window_begin_hook (w
);
12205 rif
->clear_window_mouse_face (w
);
12206 rif
->scroll_run_hook (w
, &run
);
12207 rif
->update_window_end_hook (w
, 0, 0);
12211 /* Shift current matrix down by nrows_scrolled lines. */
12212 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12213 rotate_matrix (w
->current_matrix
,
12215 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12218 /* Disable lines that must be updated. */
12219 for (i
= 0; i
< it
.vpos
; ++i
)
12220 (start_row
+ i
)->enabled_p
= 0;
12222 /* Re-compute Y positions. */
12223 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12224 max_y
= it
.last_visible_y
;
12225 for (row
= start_row
+ nrows_scrolled
;
12229 row
->y
= it
.current_y
;
12230 row
->visible_height
= row
->height
;
12232 if (row
->y
< min_y
)
12233 row
->visible_height
-= min_y
- row
->y
;
12234 if (row
->y
+ row
->height
> max_y
)
12235 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12237 it
.current_y
+= row
->height
;
12239 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12240 last_reused_text_row
= row
;
12241 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12245 /* Disable lines in the current matrix which are now
12246 below the window. */
12247 for (++row
; row
< bottom_row
; ++row
)
12248 row
->enabled_p
= 0;
12251 /* Update window_end_pos etc.; last_reused_text_row is the last
12252 reused row from the current matrix containing text, if any.
12253 The value of last_text_row is the last displayed line
12254 containing text. */
12255 if (last_reused_text_row
)
12257 w
->window_end_bytepos
12258 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
12260 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
12262 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
12263 w
->current_matrix
));
12265 else if (last_text_row
)
12267 w
->window_end_bytepos
12268 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12270 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12272 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12276 /* This window must be completely empty. */
12277 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12278 w
->window_end_pos
= make_number (Z
- ZV
);
12279 w
->window_end_vpos
= make_number (0);
12281 w
->window_end_valid
= Qnil
;
12283 /* Update hint: don't try scrolling again in update_window. */
12284 w
->desired_matrix
->no_scrolling_p
= 1;
12287 debug_method_add (w
, "try_window_reusing_current_matrix 1");
12291 else if (CHARPOS (new_start
) > CHARPOS (start
))
12293 struct glyph_row
*pt_row
, *row
;
12294 struct glyph_row
*first_reusable_row
;
12295 struct glyph_row
*first_row_to_display
;
12297 int yb
= window_text_bottom_y (w
);
12299 /* Find the row starting at new_start, if there is one. Don't
12300 reuse a partially visible line at the end. */
12301 first_reusable_row
= start_row
;
12302 while (first_reusable_row
->enabled_p
12303 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
12304 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12305 < CHARPOS (new_start
)))
12306 ++first_reusable_row
;
12308 /* Give up if there is no row to reuse. */
12309 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
12310 || !first_reusable_row
->enabled_p
12311 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
12312 != CHARPOS (new_start
)))
12315 /* We can reuse fully visible rows beginning with
12316 first_reusable_row to the end of the window. Set
12317 first_row_to_display to the first row that cannot be reused.
12318 Set pt_row to the row containing point, if there is any. */
12320 for (first_row_to_display
= first_reusable_row
;
12321 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
12322 ++first_row_to_display
)
12324 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
12325 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
12326 pt_row
= first_row_to_display
;
12329 /* Start displaying at the start of first_row_to_display. */
12330 xassert (first_row_to_display
->y
< yb
);
12331 init_to_row_start (&it
, w
, first_row_to_display
);
12333 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
12335 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
12337 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
12338 + WINDOW_HEADER_LINE_HEIGHT (w
));
12340 /* Display lines beginning with first_row_to_display in the
12341 desired matrix. Set last_text_row to the last row displayed
12342 that displays text. */
12343 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
12344 if (pt_row
== NULL
)
12345 w
->cursor
.vpos
= -1;
12346 last_text_row
= NULL
;
12347 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
12348 if (display_line (&it
))
12349 last_text_row
= it
.glyph_row
- 1;
12351 /* Give up If point isn't in a row displayed or reused. */
12352 if (w
->cursor
.vpos
< 0)
12354 clear_glyph_matrix (w
->desired_matrix
);
12358 /* If point is in a reused row, adjust y and vpos of the cursor
12362 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
12363 w
->current_matrix
);
12364 w
->cursor
.y
-= first_reusable_row
->y
;
12367 /* Scroll the display. */
12368 run
.current_y
= first_reusable_row
->y
;
12369 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12370 run
.height
= it
.last_visible_y
- run
.current_y
;
12371 dy
= run
.current_y
- run
.desired_y
;
12375 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12377 rif
->update_window_begin_hook (w
);
12378 rif
->clear_window_mouse_face (w
);
12379 rif
->scroll_run_hook (w
, &run
);
12380 rif
->update_window_end_hook (w
, 0, 0);
12384 /* Adjust Y positions of reused rows. */
12385 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12386 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12387 max_y
= it
.last_visible_y
;
12388 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
12391 row
->visible_height
= row
->height
;
12392 if (row
->y
< min_y
)
12393 row
->visible_height
-= min_y
- row
->y
;
12394 if (row
->y
+ row
->height
> max_y
)
12395 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12398 /* Scroll the current matrix. */
12399 xassert (nrows_scrolled
> 0);
12400 rotate_matrix (w
->current_matrix
,
12402 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12405 /* Disable rows not reused. */
12406 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
12407 row
->enabled_p
= 0;
12409 /* Adjust window end. A null value of last_text_row means that
12410 the window end is in reused rows which in turn means that
12411 only its vpos can have changed. */
12414 w
->window_end_bytepos
12415 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12417 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12419 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12424 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
12427 w
->window_end_valid
= Qnil
;
12428 w
->desired_matrix
->no_scrolling_p
= 1;
12431 debug_method_add (w
, "try_window_reusing_current_matrix 2");
12441 /************************************************************************
12442 Window redisplay reusing current matrix when buffer has changed
12443 ************************************************************************/
12445 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
12446 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
12448 static struct glyph_row
*
12449 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
12450 struct glyph_row
*));
12453 /* Return the last row in MATRIX displaying text. If row START is
12454 non-null, start searching with that row. IT gives the dimensions
12455 of the display. Value is null if matrix is empty; otherwise it is
12456 a pointer to the row found. */
12458 static struct glyph_row
*
12459 find_last_row_displaying_text (matrix
, it
, start
)
12460 struct glyph_matrix
*matrix
;
12462 struct glyph_row
*start
;
12464 struct glyph_row
*row
, *row_found
;
12466 /* Set row_found to the last row in IT->w's current matrix
12467 displaying text. The loop looks funny but think of partially
12470 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
12471 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12473 xassert (row
->enabled_p
);
12475 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
12484 /* Return the last row in the current matrix of W that is not affected
12485 by changes at the start of current_buffer that occurred since W's
12486 current matrix was built. Value is null if no such row exists.
12488 BEG_UNCHANGED us the number of characters unchanged at the start of
12489 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
12490 first changed character in current_buffer. Characters at positions <
12491 BEG + BEG_UNCHANGED are at the same buffer positions as they were
12492 when the current matrix was built. */
12494 static struct glyph_row
*
12495 find_last_unchanged_at_beg_row (w
)
12498 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
12499 struct glyph_row
*row
;
12500 struct glyph_row
*row_found
= NULL
;
12501 int yb
= window_text_bottom_y (w
);
12503 /* Find the last row displaying unchanged text. */
12504 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12505 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12506 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
12508 if (/* If row ends before first_changed_pos, it is unchanged,
12509 except in some case. */
12510 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
12511 /* When row ends in ZV and we write at ZV it is not
12513 && !row
->ends_at_zv_p
12514 /* When first_changed_pos is the end of a continued line,
12515 row is not unchanged because it may be no longer
12517 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
12518 && row
->continued_p
))
12521 /* Stop if last visible row. */
12522 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
12532 /* Find the first glyph row in the current matrix of W that is not
12533 affected by changes at the end of current_buffer since the
12534 time W's current matrix was built.
12536 Return in *DELTA the number of chars by which buffer positions in
12537 unchanged text at the end of current_buffer must be adjusted.
12539 Return in *DELTA_BYTES the corresponding number of bytes.
12541 Value is null if no such row exists, i.e. all rows are affected by
12544 static struct glyph_row
*
12545 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
12547 int *delta
, *delta_bytes
;
12549 struct glyph_row
*row
;
12550 struct glyph_row
*row_found
= NULL
;
12552 *delta
= *delta_bytes
= 0;
12554 /* Display must not have been paused, otherwise the current matrix
12555 is not up to date. */
12556 if (NILP (w
->window_end_valid
))
12559 /* A value of window_end_pos >= END_UNCHANGED means that the window
12560 end is in the range of changed text. If so, there is no
12561 unchanged row at the end of W's current matrix. */
12562 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
12565 /* Set row to the last row in W's current matrix displaying text. */
12566 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12568 /* If matrix is entirely empty, no unchanged row exists. */
12569 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12571 /* The value of row is the last glyph row in the matrix having a
12572 meaningful buffer position in it. The end position of row
12573 corresponds to window_end_pos. This allows us to translate
12574 buffer positions in the current matrix to current buffer
12575 positions for characters not in changed text. */
12576 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12577 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12578 int last_unchanged_pos
, last_unchanged_pos_old
;
12579 struct glyph_row
*first_text_row
12580 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12582 *delta
= Z
- Z_old
;
12583 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12585 /* Set last_unchanged_pos to the buffer position of the last
12586 character in the buffer that has not been changed. Z is the
12587 index + 1 of the last character in current_buffer, i.e. by
12588 subtracting END_UNCHANGED we get the index of the last
12589 unchanged character, and we have to add BEG to get its buffer
12591 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
12592 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
12594 /* Search backward from ROW for a row displaying a line that
12595 starts at a minimum position >= last_unchanged_pos_old. */
12596 for (; row
> first_text_row
; --row
)
12598 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12601 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
12606 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
12613 /* Make sure that glyph rows in the current matrix of window W
12614 reference the same glyph memory as corresponding rows in the
12615 frame's frame matrix. This function is called after scrolling W's
12616 current matrix on a terminal frame in try_window_id and
12617 try_window_reusing_current_matrix. */
12620 sync_frame_with_window_matrix_rows (w
)
12623 struct frame
*f
= XFRAME (w
->frame
);
12624 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
12626 /* Preconditions: W must be a leaf window and full-width. Its frame
12627 must have a frame matrix. */
12628 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
12629 xassert (WINDOW_FULL_WIDTH_P (w
));
12630 xassert (!FRAME_WINDOW_P (f
));
12632 /* If W is a full-width window, glyph pointers in W's current matrix
12633 have, by definition, to be the same as glyph pointers in the
12634 corresponding frame matrix. Note that frame matrices have no
12635 marginal areas (see build_frame_matrix). */
12636 window_row
= w
->current_matrix
->rows
;
12637 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
12638 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
12639 while (window_row
< window_row_end
)
12641 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
12642 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
12644 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
12645 frame_row
->glyphs
[TEXT_AREA
] = start
;
12646 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
12647 frame_row
->glyphs
[LAST_AREA
] = end
;
12649 /* Disable frame rows whose corresponding window rows have
12650 been disabled in try_window_id. */
12651 if (!window_row
->enabled_p
)
12652 frame_row
->enabled_p
= 0;
12654 ++window_row
, ++frame_row
;
12659 /* Find the glyph row in window W containing CHARPOS. Consider all
12660 rows between START and END (not inclusive). END null means search
12661 all rows to the end of the display area of W. Value is the row
12662 containing CHARPOS or null. */
12665 row_containing_pos (w
, charpos
, start
, end
, dy
)
12668 struct glyph_row
*start
, *end
;
12671 struct glyph_row
*row
= start
;
12674 /* If we happen to start on a header-line, skip that. */
12675 if (row
->mode_line_p
)
12678 if ((end
&& row
>= end
) || !row
->enabled_p
)
12681 last_y
= window_text_bottom_y (w
) - dy
;
12685 /* Give up if we have gone too far. */
12686 if (end
&& row
>= end
)
12688 /* This formerly returned if they were equal.
12689 I think that both quantities are of a "last plus one" type;
12690 if so, when they are equal, the row is within the screen. -- rms. */
12691 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
12694 /* If it is in this row, return this row. */
12695 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
12696 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
12697 /* The end position of a row equals the start
12698 position of the next row. If CHARPOS is there, we
12699 would rather display it in the next line, except
12700 when this line ends in ZV. */
12701 && !row
->ends_at_zv_p
12702 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12703 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
12710 /* Try to redisplay window W by reusing its existing display. W's
12711 current matrix must be up to date when this function is called,
12712 i.e. window_end_valid must not be nil.
12716 1 if display has been updated
12717 0 if otherwise unsuccessful
12718 -1 if redisplay with same window start is known not to succeed
12720 The following steps are performed:
12722 1. Find the last row in the current matrix of W that is not
12723 affected by changes at the start of current_buffer. If no such row
12726 2. Find the first row in W's current matrix that is not affected by
12727 changes at the end of current_buffer. Maybe there is no such row.
12729 3. Display lines beginning with the row + 1 found in step 1 to the
12730 row found in step 2 or, if step 2 didn't find a row, to the end of
12733 4. If cursor is not known to appear on the window, give up.
12735 5. If display stopped at the row found in step 2, scroll the
12736 display and current matrix as needed.
12738 6. Maybe display some lines at the end of W, if we must. This can
12739 happen under various circumstances, like a partially visible line
12740 becoming fully visible, or because newly displayed lines are displayed
12741 in smaller font sizes.
12743 7. Update W's window end information. */
12749 struct frame
*f
= XFRAME (w
->frame
);
12750 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
12751 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
12752 struct glyph_row
*last_unchanged_at_beg_row
;
12753 struct glyph_row
*first_unchanged_at_end_row
;
12754 struct glyph_row
*row
;
12755 struct glyph_row
*bottom_row
;
12758 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
12759 struct text_pos start_pos
;
12761 int first_unchanged_at_end_vpos
= 0;
12762 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
12763 struct text_pos start
;
12764 int first_changed_charpos
, last_changed_charpos
;
12767 if (inhibit_try_window_id
)
12771 /* This is handy for debugging. */
12773 #define GIVE_UP(X) \
12775 fprintf (stderr, "try_window_id give up %d\n", (X)); \
12779 #define GIVE_UP(X) return 0
12782 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
12784 /* Don't use this for mini-windows because these can show
12785 messages and mini-buffers, and we don't handle that here. */
12786 if (MINI_WINDOW_P (w
))
12789 /* This flag is used to prevent redisplay optimizations. */
12790 if (windows_or_buffers_changed
|| cursor_type_changed
)
12793 /* Verify that narrowing has not changed.
12794 Also verify that we were not told to prevent redisplay optimizations.
12795 It would be nice to further
12796 reduce the number of cases where this prevents try_window_id. */
12797 if (current_buffer
->clip_changed
12798 || current_buffer
->prevent_redisplay_optimizations_p
)
12801 /* Window must either use window-based redisplay or be full width. */
12802 if (!FRAME_WINDOW_P (f
)
12803 && (!line_ins_del_ok
12804 || !WINDOW_FULL_WIDTH_P (w
)))
12807 /* Give up if point is not known NOT to appear in W. */
12808 if (PT
< CHARPOS (start
))
12811 /* Another way to prevent redisplay optimizations. */
12812 if (XFASTINT (w
->last_modified
) == 0)
12815 /* Verify that window is not hscrolled. */
12816 if (XFASTINT (w
->hscroll
) != 0)
12819 /* Verify that display wasn't paused. */
12820 if (NILP (w
->window_end_valid
))
12823 /* Can't use this if highlighting a region because a cursor movement
12824 will do more than just set the cursor. */
12825 if (!NILP (Vtransient_mark_mode
)
12826 && !NILP (current_buffer
->mark_active
))
12829 /* Likewise if highlighting trailing whitespace. */
12830 if (!NILP (Vshow_trailing_whitespace
))
12833 /* Likewise if showing a region. */
12834 if (!NILP (w
->region_showing
))
12837 /* Can use this if overlay arrow position and or string have changed. */
12838 if (!EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
12839 || !EQ (last_arrow_string
, Voverlay_arrow_string
))
12843 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
12844 only if buffer has really changed. The reason is that the gap is
12845 initially at Z for freshly visited files. The code below would
12846 set end_unchanged to 0 in that case. */
12847 if (MODIFF
> SAVE_MODIFF
12848 /* This seems to happen sometimes after saving a buffer. */
12849 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
12851 if (GPT
- BEG
< BEG_UNCHANGED
)
12852 BEG_UNCHANGED
= GPT
- BEG
;
12853 if (Z
- GPT
< END_UNCHANGED
)
12854 END_UNCHANGED
= Z
- GPT
;
12857 /* The position of the first and last character that has been changed. */
12858 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
12859 last_changed_charpos
= Z
- END_UNCHANGED
;
12861 /* If window starts after a line end, and the last change is in
12862 front of that newline, then changes don't affect the display.
12863 This case happens with stealth-fontification. Note that although
12864 the display is unchanged, glyph positions in the matrix have to
12865 be adjusted, of course. */
12866 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
12867 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12868 && ((last_changed_charpos
< CHARPOS (start
)
12869 && CHARPOS (start
) == BEGV
)
12870 || (last_changed_charpos
< CHARPOS (start
) - 1
12871 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
12873 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
12874 struct glyph_row
*r0
;
12876 /* Compute how many chars/bytes have been added to or removed
12877 from the buffer. */
12878 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
12879 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
12881 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
12883 /* Give up if PT is not in the window. Note that it already has
12884 been checked at the start of try_window_id that PT is not in
12885 front of the window start. */
12886 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
12889 /* If window start is unchanged, we can reuse the whole matrix
12890 as is, after adjusting glyph positions. No need to compute
12891 the window end again, since its offset from Z hasn't changed. */
12892 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
12893 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
12894 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
12895 /* PT must not be in a partially visible line. */
12896 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
12897 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
12899 /* Adjust positions in the glyph matrix. */
12900 if (delta
|| delta_bytes
)
12902 struct glyph_row
*r1
12903 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
12904 increment_matrix_positions (w
->current_matrix
,
12905 MATRIX_ROW_VPOS (r0
, current_matrix
),
12906 MATRIX_ROW_VPOS (r1
, current_matrix
),
12907 delta
, delta_bytes
);
12910 /* Set the cursor. */
12911 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
12913 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
12920 /* Handle the case that changes are all below what is displayed in
12921 the window, and that PT is in the window. This shortcut cannot
12922 be taken if ZV is visible in the window, and text has been added
12923 there that is visible in the window. */
12924 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
12925 /* ZV is not visible in the window, or there are no
12926 changes at ZV, actually. */
12927 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
12928 || first_changed_charpos
== last_changed_charpos
))
12930 struct glyph_row
*r0
;
12932 /* Give up if PT is not in the window. Note that it already has
12933 been checked at the start of try_window_id that PT is not in
12934 front of the window start. */
12935 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
12938 /* If window start is unchanged, we can reuse the whole matrix
12939 as is, without changing glyph positions since no text has
12940 been added/removed in front of the window end. */
12941 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
12942 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
12943 /* PT must not be in a partially visible line. */
12944 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
12945 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
12947 /* We have to compute the window end anew since text
12948 can have been added/removed after it. */
12950 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
12951 w
->window_end_bytepos
12952 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
12954 /* Set the cursor. */
12955 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
12957 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
12964 /* Give up if window start is in the changed area.
12966 The condition used to read
12968 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
12970 but why that was tested escapes me at the moment. */
12971 if (CHARPOS (start
) >= first_changed_charpos
12972 && CHARPOS (start
) <= last_changed_charpos
)
12975 /* Check that window start agrees with the start of the first glyph
12976 row in its current matrix. Check this after we know the window
12977 start is not in changed text, otherwise positions would not be
12979 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
12980 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
12983 /* Give up if the window ends in strings. Overlay strings
12984 at the end are difficult to handle, so don't try. */
12985 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
12986 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
12989 /* Compute the position at which we have to start displaying new
12990 lines. Some of the lines at the top of the window might be
12991 reusable because they are not displaying changed text. Find the
12992 last row in W's current matrix not affected by changes at the
12993 start of current_buffer. Value is null if changes start in the
12994 first line of window. */
12995 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
12996 if (last_unchanged_at_beg_row
)
12998 /* Avoid starting to display in the moddle of a character, a TAB
12999 for instance. This is easier than to set up the iterator
13000 exactly, and it's not a frequent case, so the additional
13001 effort wouldn't really pay off. */
13002 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13003 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13004 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13005 --last_unchanged_at_beg_row
;
13007 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13010 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13012 start_pos
= it
.current
.pos
;
13014 /* Start displaying new lines in the desired matrix at the same
13015 vpos we would use in the current matrix, i.e. below
13016 last_unchanged_at_beg_row. */
13017 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13019 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13020 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13022 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13026 /* There are no reusable lines at the start of the window.
13027 Start displaying in the first line. */
13028 start_display (&it
, w
, start
);
13029 start_pos
= it
.current
.pos
;
13032 /* Find the first row that is not affected by changes at the end of
13033 the buffer. Value will be null if there is no unchanged row, in
13034 which case we must redisplay to the end of the window. delta
13035 will be set to the value by which buffer positions beginning with
13036 first_unchanged_at_end_row have to be adjusted due to text
13038 first_unchanged_at_end_row
13039 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13040 IF_DEBUG (debug_delta
= delta
);
13041 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13043 /* Set stop_pos to the buffer position up to which we will have to
13044 display new lines. If first_unchanged_at_end_row != NULL, this
13045 is the buffer position of the start of the line displayed in that
13046 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13047 that we don't stop at a buffer position. */
13049 if (first_unchanged_at_end_row
)
13051 xassert (last_unchanged_at_beg_row
== NULL
13052 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13054 /* If this is a continuation line, move forward to the next one
13055 that isn't. Changes in lines above affect this line.
13056 Caution: this may move first_unchanged_at_end_row to a row
13057 not displaying text. */
13058 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13059 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13060 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13061 < it
.last_visible_y
))
13062 ++first_unchanged_at_end_row
;
13064 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13065 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13066 >= it
.last_visible_y
))
13067 first_unchanged_at_end_row
= NULL
;
13070 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13072 first_unchanged_at_end_vpos
13073 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13074 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13077 else if (last_unchanged_at_beg_row
== NULL
)
13083 /* Either there is no unchanged row at the end, or the one we have
13084 now displays text. This is a necessary condition for the window
13085 end pos calculation at the end of this function. */
13086 xassert (first_unchanged_at_end_row
== NULL
13087 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13089 debug_last_unchanged_at_beg_vpos
13090 = (last_unchanged_at_beg_row
13091 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13093 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13095 #endif /* GLYPH_DEBUG != 0 */
13098 /* Display new lines. Set last_text_row to the last new line
13099 displayed which has text on it, i.e. might end up as being the
13100 line where the window_end_vpos is. */
13101 w
->cursor
.vpos
= -1;
13102 last_text_row
= NULL
;
13103 overlay_arrow_seen
= 0;
13104 while (it
.current_y
< it
.last_visible_y
13105 && !fonts_changed_p
13106 && (first_unchanged_at_end_row
== NULL
13107 || IT_CHARPOS (it
) < stop_pos
))
13109 if (display_line (&it
))
13110 last_text_row
= it
.glyph_row
- 1;
13113 if (fonts_changed_p
)
13117 /* Compute differences in buffer positions, y-positions etc. for
13118 lines reused at the bottom of the window. Compute what we can
13120 if (first_unchanged_at_end_row
13121 /* No lines reused because we displayed everything up to the
13122 bottom of the window. */
13123 && it
.current_y
< it
.last_visible_y
)
13126 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13128 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13129 run
.current_y
= first_unchanged_at_end_row
->y
;
13130 run
.desired_y
= run
.current_y
+ dy
;
13131 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13135 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13136 first_unchanged_at_end_row
= NULL
;
13138 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13141 /* Find the cursor if not already found. We have to decide whether
13142 PT will appear on this window (it sometimes doesn't, but this is
13143 not a very frequent case.) This decision has to be made before
13144 the current matrix is altered. A value of cursor.vpos < 0 means
13145 that PT is either in one of the lines beginning at
13146 first_unchanged_at_end_row or below the window. Don't care for
13147 lines that might be displayed later at the window end; as
13148 mentioned, this is not a frequent case. */
13149 if (w
->cursor
.vpos
< 0)
13151 /* Cursor in unchanged rows at the top? */
13152 if (PT
< CHARPOS (start_pos
)
13153 && last_unchanged_at_beg_row
)
13155 row
= row_containing_pos (w
, PT
,
13156 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13157 last_unchanged_at_beg_row
+ 1, 0);
13159 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13162 /* Start from first_unchanged_at_end_row looking for PT. */
13163 else if (first_unchanged_at_end_row
)
13165 row
= row_containing_pos (w
, PT
- delta
,
13166 first_unchanged_at_end_row
, NULL
, 0);
13168 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13169 delta_bytes
, dy
, dvpos
);
13172 /* Give up if cursor was not found. */
13173 if (w
->cursor
.vpos
< 0)
13175 clear_glyph_matrix (w
->desired_matrix
);
13180 /* Don't let the cursor end in the scroll margins. */
13182 int this_scroll_margin
, cursor_height
;
13184 this_scroll_margin
= max (0, scroll_margin
);
13185 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13186 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13187 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13189 if ((w
->cursor
.y
< this_scroll_margin
13190 && CHARPOS (start
) > BEGV
)
13191 /* Don't take scroll margin into account at the bottom because
13192 old redisplay didn't do it either. */
13193 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
13195 w
->cursor
.vpos
= -1;
13196 clear_glyph_matrix (w
->desired_matrix
);
13201 /* Scroll the display. Do it before changing the current matrix so
13202 that xterm.c doesn't get confused about where the cursor glyph is
13204 if (dy
&& run
.height
)
13208 if (FRAME_WINDOW_P (f
))
13210 rif
->update_window_begin_hook (w
);
13211 rif
->clear_window_mouse_face (w
);
13212 rif
->scroll_run_hook (w
, &run
);
13213 rif
->update_window_end_hook (w
, 0, 0);
13217 /* Terminal frame. In this case, dvpos gives the number of
13218 lines to scroll by; dvpos < 0 means scroll up. */
13219 int first_unchanged_at_end_vpos
13220 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13221 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13222 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13223 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13224 + window_internal_height (w
));
13226 /* Perform the operation on the screen. */
13229 /* Scroll last_unchanged_at_beg_row to the end of the
13230 window down dvpos lines. */
13231 set_terminal_window (end
);
13233 /* On dumb terminals delete dvpos lines at the end
13234 before inserting dvpos empty lines. */
13235 if (!scroll_region_ok
)
13236 ins_del_lines (end
- dvpos
, -dvpos
);
13238 /* Insert dvpos empty lines in front of
13239 last_unchanged_at_beg_row. */
13240 ins_del_lines (from
, dvpos
);
13242 else if (dvpos
< 0)
13244 /* Scroll up last_unchanged_at_beg_vpos to the end of
13245 the window to last_unchanged_at_beg_vpos - |dvpos|. */
13246 set_terminal_window (end
);
13248 /* Delete dvpos lines in front of
13249 last_unchanged_at_beg_vpos. ins_del_lines will set
13250 the cursor to the given vpos and emit |dvpos| delete
13252 ins_del_lines (from
+ dvpos
, dvpos
);
13254 /* On a dumb terminal insert dvpos empty lines at the
13256 if (!scroll_region_ok
)
13257 ins_del_lines (end
+ dvpos
, -dvpos
);
13260 set_terminal_window (0);
13266 /* Shift reused rows of the current matrix to the right position.
13267 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
13269 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13270 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
13273 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
13274 bottom_vpos
, dvpos
);
13275 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
13278 else if (dvpos
> 0)
13280 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
13281 bottom_vpos
, dvpos
);
13282 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
13283 first_unchanged_at_end_vpos
+ dvpos
, 0);
13286 /* For frame-based redisplay, make sure that current frame and window
13287 matrix are in sync with respect to glyph memory. */
13288 if (!FRAME_WINDOW_P (f
))
13289 sync_frame_with_window_matrix_rows (w
);
13291 /* Adjust buffer positions in reused rows. */
13293 increment_matrix_positions (current_matrix
,
13294 first_unchanged_at_end_vpos
+ dvpos
,
13295 bottom_vpos
, delta
, delta_bytes
);
13297 /* Adjust Y positions. */
13299 shift_glyph_matrix (w
, current_matrix
,
13300 first_unchanged_at_end_vpos
+ dvpos
,
13303 if (first_unchanged_at_end_row
)
13304 first_unchanged_at_end_row
+= dvpos
;
13306 /* If scrolling up, there may be some lines to display at the end of
13308 last_text_row_at_end
= NULL
;
13311 /* Scrolling up can leave for example a partially visible line
13312 at the end of the window to be redisplayed. */
13313 /* Set last_row to the glyph row in the current matrix where the
13314 window end line is found. It has been moved up or down in
13315 the matrix by dvpos. */
13316 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
13317 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
13319 /* If last_row is the window end line, it should display text. */
13320 xassert (last_row
->displays_text_p
);
13322 /* If window end line was partially visible before, begin
13323 displaying at that line. Otherwise begin displaying with the
13324 line following it. */
13325 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
13327 init_to_row_start (&it
, w
, last_row
);
13328 it
.vpos
= last_vpos
;
13329 it
.current_y
= last_row
->y
;
13333 init_to_row_end (&it
, w
, last_row
);
13334 it
.vpos
= 1 + last_vpos
;
13335 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
13339 /* We may start in a continuation line. If so, we have to
13340 get the right continuation_lines_width and current_x. */
13341 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
13342 it
.hpos
= it
.current_x
= 0;
13344 /* Display the rest of the lines at the window end. */
13345 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13346 while (it
.current_y
< it
.last_visible_y
13347 && !fonts_changed_p
)
13349 /* Is it always sure that the display agrees with lines in
13350 the current matrix? I don't think so, so we mark rows
13351 displayed invalid in the current matrix by setting their
13352 enabled_p flag to zero. */
13353 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
13354 if (display_line (&it
))
13355 last_text_row_at_end
= it
.glyph_row
- 1;
13359 /* Update window_end_pos and window_end_vpos. */
13360 if (first_unchanged_at_end_row
13361 && first_unchanged_at_end_row
->y
< it
.last_visible_y
13362 && !last_text_row_at_end
)
13364 /* Window end line if one of the preserved rows from the current
13365 matrix. Set row to the last row displaying text in current
13366 matrix starting at first_unchanged_at_end_row, after
13368 xassert (first_unchanged_at_end_row
->displays_text_p
);
13369 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
13370 first_unchanged_at_end_row
);
13371 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
13373 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13374 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13376 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
13377 xassert (w
->window_end_bytepos
>= 0);
13378 IF_DEBUG (debug_method_add (w
, "A"));
13380 else if (last_text_row_at_end
)
13383 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
13384 w
->window_end_bytepos
13385 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
13387 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
13388 xassert (w
->window_end_bytepos
>= 0);
13389 IF_DEBUG (debug_method_add (w
, "B"));
13391 else if (last_text_row
)
13393 /* We have displayed either to the end of the window or at the
13394 end of the window, i.e. the last row with text is to be found
13395 in the desired matrix. */
13397 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13398 w
->window_end_bytepos
13399 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13401 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
13402 xassert (w
->window_end_bytepos
>= 0);
13404 else if (first_unchanged_at_end_row
== NULL
13405 && last_text_row
== NULL
13406 && last_text_row_at_end
== NULL
)
13408 /* Displayed to end of window, but no line containing text was
13409 displayed. Lines were deleted at the end of the window. */
13410 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
13411 int vpos
= XFASTINT (w
->window_end_vpos
);
13412 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
13413 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
13416 row
== NULL
&& vpos
>= first_vpos
;
13417 --vpos
, --current_row
, --desired_row
)
13419 if (desired_row
->enabled_p
)
13421 if (desired_row
->displays_text_p
)
13424 else if (current_row
->displays_text_p
)
13428 xassert (row
!= NULL
);
13429 w
->window_end_vpos
= make_number (vpos
+ 1);
13430 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13431 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13432 xassert (w
->window_end_bytepos
>= 0);
13433 IF_DEBUG (debug_method_add (w
, "C"));
13438 #if 0 /* This leads to problems, for instance when the cursor is
13439 at ZV, and the cursor line displays no text. */
13440 /* Disable rows below what's displayed in the window. This makes
13441 debugging easier. */
13442 enable_glyph_matrix_rows (current_matrix
,
13443 XFASTINT (w
->window_end_vpos
) + 1,
13447 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
13448 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
13450 /* Record that display has not been completed. */
13451 w
->window_end_valid
= Qnil
;
13452 w
->desired_matrix
->no_scrolling_p
= 1;
13460 /***********************************************************************
13461 More debugging support
13462 ***********************************************************************/
13466 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
13467 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
13468 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
13471 /* Dump the contents of glyph matrix MATRIX on stderr.
13473 GLYPHS 0 means don't show glyph contents.
13474 GLYPHS 1 means show glyphs in short form
13475 GLYPHS > 1 means show glyphs in long form. */
13478 dump_glyph_matrix (matrix
, glyphs
)
13479 struct glyph_matrix
*matrix
;
13483 for (i
= 0; i
< matrix
->nrows
; ++i
)
13484 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
13488 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
13489 the glyph row and area where the glyph comes from. */
13492 dump_glyph (row
, glyph
, area
)
13493 struct glyph_row
*row
;
13494 struct glyph
*glyph
;
13497 if (glyph
->type
== CHAR_GLYPH
)
13500 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13501 glyph
- row
->glyphs
[TEXT_AREA
],
13504 (BUFFERP (glyph
->object
)
13506 : (STRINGP (glyph
->object
)
13509 glyph
->pixel_width
,
13511 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
13515 glyph
->left_box_line_p
,
13516 glyph
->right_box_line_p
);
13518 else if (glyph
->type
== STRETCH_GLYPH
)
13521 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13522 glyph
- row
->glyphs
[TEXT_AREA
],
13525 (BUFFERP (glyph
->object
)
13527 : (STRINGP (glyph
->object
)
13530 glyph
->pixel_width
,
13534 glyph
->left_box_line_p
,
13535 glyph
->right_box_line_p
);
13537 else if (glyph
->type
== IMAGE_GLYPH
)
13540 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
13541 glyph
- row
->glyphs
[TEXT_AREA
],
13544 (BUFFERP (glyph
->object
)
13546 : (STRINGP (glyph
->object
)
13549 glyph
->pixel_width
,
13553 glyph
->left_box_line_p
,
13554 glyph
->right_box_line_p
);
13559 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
13560 GLYPHS 0 means don't show glyph contents.
13561 GLYPHS 1 means show glyphs in short form
13562 GLYPHS > 1 means show glyphs in long form. */
13565 dump_glyph_row (row
, vpos
, glyphs
)
13566 struct glyph_row
*row
;
13571 fprintf (stderr
, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n");
13572 fprintf (stderr
, "=======================================================================\n");
13574 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\
13575 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
13577 MATRIX_ROW_START_CHARPOS (row
),
13578 MATRIX_ROW_END_CHARPOS (row
),
13579 row
->used
[TEXT_AREA
],
13580 row
->contains_overlapping_glyphs_p
,
13582 row
->truncated_on_left_p
,
13583 row
->truncated_on_right_p
,
13584 row
->overlay_arrow_p
,
13586 MATRIX_ROW_CONTINUATION_LINE_P (row
),
13587 row
->displays_text_p
,
13590 row
->ends_in_middle_of_char_p
,
13591 row
->starts_in_middle_of_char_p
,
13597 row
->visible_height
,
13600 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
13601 row
->end
.overlay_string_index
,
13602 row
->continuation_lines_width
);
13603 fprintf (stderr
, "%9d %5d\n",
13604 CHARPOS (row
->start
.string_pos
),
13605 CHARPOS (row
->end
.string_pos
));
13606 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
13607 row
->end
.dpvec_index
);
13614 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13616 struct glyph
*glyph
= row
->glyphs
[area
];
13617 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
13619 /* Glyph for a line end in text. */
13620 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
13623 if (glyph
< glyph_end
)
13624 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
13626 for (; glyph
< glyph_end
; ++glyph
)
13627 dump_glyph (row
, glyph
, area
);
13630 else if (glyphs
== 1)
13634 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13636 char *s
= (char *) alloca (row
->used
[area
] + 1);
13639 for (i
= 0; i
< row
->used
[area
]; ++i
)
13641 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
13642 if (glyph
->type
== CHAR_GLYPH
13643 && glyph
->u
.ch
< 0x80
13644 && glyph
->u
.ch
>= ' ')
13645 s
[i
] = glyph
->u
.ch
;
13651 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
13657 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
13658 Sdump_glyph_matrix
, 0, 1, "p",
13659 doc
: /* Dump the current matrix of the selected window to stderr.
13660 Shows contents of glyph row structures. With non-nil
13661 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
13662 glyphs in short form, otherwise show glyphs in long form. */)
13664 Lisp_Object glyphs
;
13666 struct window
*w
= XWINDOW (selected_window
);
13667 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13669 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
13670 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
13671 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
13672 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
13673 fprintf (stderr
, "=============================================\n");
13674 dump_glyph_matrix (w
->current_matrix
,
13675 NILP (glyphs
) ? 0 : XINT (glyphs
));
13680 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
13681 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
13684 struct frame
*f
= XFRAME (selected_frame
);
13685 dump_glyph_matrix (f
->current_matrix
, 1);
13690 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
13691 doc
: /* Dump glyph row ROW to stderr.
13692 GLYPH 0 means don't dump glyphs.
13693 GLYPH 1 means dump glyphs in short form.
13694 GLYPH > 1 or omitted means dump glyphs in long form. */)
13696 Lisp_Object row
, glyphs
;
13698 struct glyph_matrix
*matrix
;
13701 CHECK_NUMBER (row
);
13702 matrix
= XWINDOW (selected_window
)->current_matrix
;
13704 if (vpos
>= 0 && vpos
< matrix
->nrows
)
13705 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
13707 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13712 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
13713 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
13714 GLYPH 0 means don't dump glyphs.
13715 GLYPH 1 means dump glyphs in short form.
13716 GLYPH > 1 or omitted means dump glyphs in long form. */)
13718 Lisp_Object row
, glyphs
;
13720 struct frame
*sf
= SELECTED_FRAME ();
13721 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
13724 CHECK_NUMBER (row
);
13726 if (vpos
>= 0 && vpos
< m
->nrows
)
13727 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
13728 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
13733 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
13734 doc
: /* Toggle tracing of redisplay.
13735 With ARG, turn tracing on if and only if ARG is positive. */)
13740 trace_redisplay_p
= !trace_redisplay_p
;
13743 arg
= Fprefix_numeric_value (arg
);
13744 trace_redisplay_p
= XINT (arg
) > 0;
13751 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
13752 doc
: /* Like `format', but print result to stderr.
13753 usage: (trace-to-stderr STRING &rest OBJECTS) */)
13758 Lisp_Object s
= Fformat (nargs
, args
);
13759 fprintf (stderr
, "%s", SDATA (s
));
13763 #endif /* GLYPH_DEBUG */
13767 /***********************************************************************
13768 Building Desired Matrix Rows
13769 ***********************************************************************/
13771 /* Return a temporary glyph row holding the glyphs of an overlay
13772 arrow. Only used for non-window-redisplay windows. */
13774 static struct glyph_row
*
13775 get_overlay_arrow_glyph_row (w
)
13778 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
13779 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13780 struct buffer
*old
= current_buffer
;
13781 const unsigned char *arrow_string
= SDATA (Voverlay_arrow_string
);
13782 int arrow_len
= SCHARS (Voverlay_arrow_string
);
13783 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
13784 const unsigned char *p
;
13787 int n_glyphs_before
;
13789 set_buffer_temp (buffer
);
13790 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
13791 it
.glyph_row
->used
[TEXT_AREA
] = 0;
13792 SET_TEXT_POS (it
.position
, 0, 0);
13794 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
13796 while (p
< arrow_end
)
13798 Lisp_Object face
, ilisp
;
13800 /* Get the next character. */
13802 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
13804 it
.c
= *p
, it
.len
= 1;
13807 /* Get its face. */
13808 ilisp
= make_number (p
- arrow_string
);
13809 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
13810 it
.face_id
= compute_char_face (f
, it
.c
, face
);
13812 /* Compute its width, get its glyphs. */
13813 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
13814 SET_TEXT_POS (it
.position
, -1, -1);
13815 PRODUCE_GLYPHS (&it
);
13817 /* If this character doesn't fit any more in the line, we have
13818 to remove some glyphs. */
13819 if (it
.current_x
> it
.last_visible_x
)
13821 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
13826 set_buffer_temp (old
);
13827 return it
.glyph_row
;
13831 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
13832 glyphs are only inserted for terminal frames since we can't really
13833 win with truncation glyphs when partially visible glyphs are
13834 involved. Which glyphs to insert is determined by
13835 produce_special_glyphs. */
13838 insert_left_trunc_glyphs (it
)
13841 struct it truncate_it
;
13842 struct glyph
*from
, *end
, *to
, *toend
;
13844 xassert (!FRAME_WINDOW_P (it
->f
));
13846 /* Get the truncation glyphs. */
13848 truncate_it
.current_x
= 0;
13849 truncate_it
.face_id
= DEFAULT_FACE_ID
;
13850 truncate_it
.glyph_row
= &scratch_glyph_row
;
13851 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
13852 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
13853 truncate_it
.object
= make_number (0);
13854 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
13856 /* Overwrite glyphs from IT with truncation glyphs. */
13857 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
13858 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
13859 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
13860 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
13865 /* There may be padding glyphs left over. Overwrite them too. */
13866 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
13868 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
13874 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
13878 /* Compute the pixel height and width of IT->glyph_row.
13880 Most of the time, ascent and height of a display line will be equal
13881 to the max_ascent and max_height values of the display iterator
13882 structure. This is not the case if
13884 1. We hit ZV without displaying anything. In this case, max_ascent
13885 and max_height will be zero.
13887 2. We have some glyphs that don't contribute to the line height.
13888 (The glyph row flag contributes_to_line_height_p is for future
13889 pixmap extensions).
13891 The first case is easily covered by using default values because in
13892 these cases, the line height does not really matter, except that it
13893 must not be zero. */
13896 compute_line_metrics (it
)
13899 struct glyph_row
*row
= it
->glyph_row
;
13902 if (FRAME_WINDOW_P (it
->f
))
13904 int i
, min_y
, max_y
;
13906 /* The line may consist of one space only, that was added to
13907 place the cursor on it. If so, the row's height hasn't been
13909 if (row
->height
== 0)
13911 if (it
->max_ascent
+ it
->max_descent
== 0)
13912 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
13913 row
->ascent
= it
->max_ascent
;
13914 row
->height
= it
->max_ascent
+ it
->max_descent
;
13915 row
->phys_ascent
= it
->max_phys_ascent
;
13916 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
13919 /* Compute the width of this line. */
13920 row
->pixel_width
= row
->x
;
13921 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
13922 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
13924 xassert (row
->pixel_width
>= 0);
13925 xassert (row
->ascent
>= 0 && row
->height
> 0);
13927 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
13928 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
13930 /* If first line's physical ascent is larger than its logical
13931 ascent, use the physical ascent, and make the row taller.
13932 This makes accented characters fully visible. */
13933 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
13934 && row
->phys_ascent
> row
->ascent
)
13936 row
->height
+= row
->phys_ascent
- row
->ascent
;
13937 row
->ascent
= row
->phys_ascent
;
13940 /* Compute how much of the line is visible. */
13941 row
->visible_height
= row
->height
;
13943 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
13944 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
13946 if (row
->y
< min_y
)
13947 row
->visible_height
-= min_y
- row
->y
;
13948 if (row
->y
+ row
->height
> max_y
)
13949 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13953 row
->pixel_width
= row
->used
[TEXT_AREA
];
13954 if (row
->continued_p
)
13955 row
->pixel_width
-= it
->continuation_pixel_width
;
13956 else if (row
->truncated_on_right_p
)
13957 row
->pixel_width
-= it
->truncation_pixel_width
;
13958 row
->ascent
= row
->phys_ascent
= 0;
13959 row
->height
= row
->phys_height
= row
->visible_height
= 1;
13962 /* Compute a hash code for this row. */
13964 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
13965 for (i
= 0; i
< row
->used
[area
]; ++i
)
13966 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
13967 + row
->glyphs
[area
][i
].u
.val
13968 + row
->glyphs
[area
][i
].face_id
13969 + row
->glyphs
[area
][i
].padding_p
13970 + (row
->glyphs
[area
][i
].type
<< 2));
13972 it
->max_ascent
= it
->max_descent
= 0;
13973 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
13977 /* Append one space to the glyph row of iterator IT if doing a
13978 window-based redisplay. DEFAULT_FACE_P non-zero means let the
13979 space have the default face, otherwise let it have the same face as
13980 IT->face_id. Value is non-zero if a space was added.
13982 This function is called to make sure that there is always one glyph
13983 at the end of a glyph row that the cursor can be set on under
13984 window-systems. (If there weren't such a glyph we would not know
13985 how wide and tall a box cursor should be displayed).
13987 At the same time this space let's a nicely handle clearing to the
13988 end of the line if the row ends in italic text. */
13991 append_space (it
, default_face_p
)
13993 int default_face_p
;
13995 if (FRAME_WINDOW_P (it
->f
))
13997 int n
= it
->glyph_row
->used
[TEXT_AREA
];
13999 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14000 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14002 /* Save some values that must not be changed.
14003 Must save IT->c and IT->len because otherwise
14004 ITERATOR_AT_END_P wouldn't work anymore after
14005 append_space has been called. */
14006 enum display_element_type saved_what
= it
->what
;
14007 int saved_c
= it
->c
, saved_len
= it
->len
;
14008 int saved_x
= it
->current_x
;
14009 int saved_face_id
= it
->face_id
;
14010 struct text_pos saved_pos
;
14011 Lisp_Object saved_object
;
14014 saved_object
= it
->object
;
14015 saved_pos
= it
->position
;
14017 it
->what
= IT_CHARACTER
;
14018 bzero (&it
->position
, sizeof it
->position
);
14019 it
->object
= make_number (0);
14023 if (default_face_p
)
14024 it
->face_id
= DEFAULT_FACE_ID
;
14025 else if (it
->face_before_selective_p
)
14026 it
->face_id
= it
->saved_face_id
;
14027 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14028 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14030 PRODUCE_GLYPHS (it
);
14032 it
->current_x
= saved_x
;
14033 it
->object
= saved_object
;
14034 it
->position
= saved_pos
;
14035 it
->what
= saved_what
;
14036 it
->face_id
= saved_face_id
;
14037 it
->len
= saved_len
;
14047 /* Extend the face of the last glyph in the text area of IT->glyph_row
14048 to the end of the display line. Called from display_line.
14049 If the glyph row is empty, add a space glyph to it so that we
14050 know the face to draw. Set the glyph row flag fill_line_p. */
14053 extend_face_to_end_of_line (it
)
14057 struct frame
*f
= it
->f
;
14059 /* If line is already filled, do nothing. */
14060 if (it
->current_x
>= it
->last_visible_x
)
14063 /* Face extension extends the background and box of IT->face_id
14064 to the end of the line. If the background equals the background
14065 of the frame, we don't have to do anything. */
14066 if (it
->face_before_selective_p
)
14067 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14069 face
= FACE_FROM_ID (f
, it
->face_id
);
14071 if (FRAME_WINDOW_P (f
)
14072 && face
->box
== FACE_NO_BOX
14073 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14077 /* Set the glyph row flag indicating that the face of the last glyph
14078 in the text area has to be drawn to the end of the text area. */
14079 it
->glyph_row
->fill_line_p
= 1;
14081 /* If current character of IT is not ASCII, make sure we have the
14082 ASCII face. This will be automatically undone the next time
14083 get_next_display_element returns a multibyte character. Note
14084 that the character will always be single byte in unibyte text. */
14085 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14087 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14090 if (FRAME_WINDOW_P (f
))
14092 /* If the row is empty, add a space with the current face of IT,
14093 so that we know which face to draw. */
14094 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14096 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14097 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14098 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14103 /* Save some values that must not be changed. */
14104 int saved_x
= it
->current_x
;
14105 struct text_pos saved_pos
;
14106 Lisp_Object saved_object
;
14107 enum display_element_type saved_what
= it
->what
;
14108 int saved_face_id
= it
->face_id
;
14110 saved_object
= it
->object
;
14111 saved_pos
= it
->position
;
14113 it
->what
= IT_CHARACTER
;
14114 bzero (&it
->position
, sizeof it
->position
);
14115 it
->object
= make_number (0);
14118 it
->face_id
= face
->id
;
14120 PRODUCE_GLYPHS (it
);
14122 while (it
->current_x
<= it
->last_visible_x
)
14123 PRODUCE_GLYPHS (it
);
14125 /* Don't count these blanks really. It would let us insert a left
14126 truncation glyph below and make us set the cursor on them, maybe. */
14127 it
->current_x
= saved_x
;
14128 it
->object
= saved_object
;
14129 it
->position
= saved_pos
;
14130 it
->what
= saved_what
;
14131 it
->face_id
= saved_face_id
;
14136 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14137 trailing whitespace. */
14140 trailing_whitespace_p (charpos
)
14143 int bytepos
= CHAR_TO_BYTE (charpos
);
14146 while (bytepos
< ZV_BYTE
14147 && (c
= FETCH_CHAR (bytepos
),
14148 c
== ' ' || c
== '\t'))
14151 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14153 if (bytepos
!= PT_BYTE
)
14160 /* Highlight trailing whitespace, if any, in ROW. */
14163 highlight_trailing_whitespace (f
, row
)
14165 struct glyph_row
*row
;
14167 int used
= row
->used
[TEXT_AREA
];
14171 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14172 struct glyph
*glyph
= start
+ used
- 1;
14174 /* Skip over glyphs inserted to display the cursor at the
14175 end of a line, for extending the face of the last glyph
14176 to the end of the line on terminals, and for truncation
14177 and continuation glyphs. */
14178 while (glyph
>= start
14179 && glyph
->type
== CHAR_GLYPH
14180 && INTEGERP (glyph
->object
))
14183 /* If last glyph is a space or stretch, and it's trailing
14184 whitespace, set the face of all trailing whitespace glyphs in
14185 IT->glyph_row to `trailing-whitespace'. */
14187 && BUFFERP (glyph
->object
)
14188 && (glyph
->type
== STRETCH_GLYPH
14189 || (glyph
->type
== CHAR_GLYPH
14190 && glyph
->u
.ch
== ' '))
14191 && trailing_whitespace_p (glyph
->charpos
))
14193 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
14195 while (glyph
>= start
14196 && BUFFERP (glyph
->object
)
14197 && (glyph
->type
== STRETCH_GLYPH
14198 || (glyph
->type
== CHAR_GLYPH
14199 && glyph
->u
.ch
== ' ')))
14200 (glyph
--)->face_id
= face_id
;
14206 /* Value is non-zero if glyph row ROW in window W should be
14207 used to hold the cursor. */
14210 cursor_row_p (w
, row
)
14212 struct glyph_row
*row
;
14214 int cursor_row_p
= 1;
14216 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14218 /* If the row ends with a newline from a string, we don't want
14219 the cursor there (if the row is continued it doesn't end in a
14221 if (CHARPOS (row
->end
.string_pos
) >= 0
14222 || MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
14223 cursor_row_p
= row
->continued_p
;
14225 /* If the row ends at ZV, display the cursor at the end of that
14226 row instead of at the start of the row below. */
14227 else if (row
->ends_at_zv_p
)
14233 return cursor_row_p
;
14237 /* Construct the glyph row IT->glyph_row in the desired matrix of
14238 IT->w from text at the current position of IT. See dispextern.h
14239 for an overview of struct it. Value is non-zero if
14240 IT->glyph_row displays text, as opposed to a line displaying ZV
14247 struct glyph_row
*row
= it
->glyph_row
;
14249 /* We always start displaying at hpos zero even if hscrolled. */
14250 xassert (it
->hpos
== 0 && it
->current_x
== 0);
14252 /* We must not display in a row that's not a text row. */
14253 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
14254 < it
->w
->desired_matrix
->nrows
);
14256 /* Is IT->w showing the region? */
14257 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
14259 /* Clear the result glyph row and enable it. */
14260 prepare_desired_row (row
);
14262 row
->y
= it
->current_y
;
14263 row
->start
= it
->current
;
14264 row
->continuation_lines_width
= it
->continuation_lines_width
;
14265 row
->displays_text_p
= 1;
14266 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
14267 it
->starts_in_middle_of_char_p
= 0;
14269 /* Arrange the overlays nicely for our purposes. Usually, we call
14270 display_line on only one line at a time, in which case this
14271 can't really hurt too much, or we call it on lines which appear
14272 one after another in the buffer, in which case all calls to
14273 recenter_overlay_lists but the first will be pretty cheap. */
14274 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
14276 /* Move over display elements that are not visible because we are
14277 hscrolled. This may stop at an x-position < IT->first_visible_x
14278 if the first glyph is partially visible or if we hit a line end. */
14279 if (it
->current_x
< it
->first_visible_x
)
14280 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
14281 MOVE_TO_POS
| MOVE_TO_X
);
14283 /* Get the initial row height. This is either the height of the
14284 text hscrolled, if there is any, or zero. */
14285 row
->ascent
= it
->max_ascent
;
14286 row
->height
= it
->max_ascent
+ it
->max_descent
;
14287 row
->phys_ascent
= it
->max_phys_ascent
;
14288 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14290 /* Loop generating characters. The loop is left with IT on the next
14291 character to display. */
14294 int n_glyphs_before
, hpos_before
, x_before
;
14296 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
14298 /* Retrieve the next thing to display. Value is zero if end of
14300 if (!get_next_display_element (it
))
14302 /* Maybe add a space at the end of this line that is used to
14303 display the cursor there under X. Set the charpos of the
14304 first glyph of blank lines not corresponding to any text
14306 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
14307 || row
->used
[TEXT_AREA
] == 0)
14309 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
14310 row
->displays_text_p
= 0;
14312 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
14313 && (!MINI_WINDOW_P (it
->w
)
14314 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
14315 row
->indicate_empty_line_p
= 1;
14318 it
->continuation_lines_width
= 0;
14319 row
->ends_at_zv_p
= 1;
14323 /* Now, get the metrics of what we want to display. This also
14324 generates glyphs in `row' (which is IT->glyph_row). */
14325 n_glyphs_before
= row
->used
[TEXT_AREA
];
14328 /* Remember the line height so far in case the next element doesn't
14329 fit on the line. */
14330 if (!it
->truncate_lines_p
)
14332 ascent
= it
->max_ascent
;
14333 descent
= it
->max_descent
;
14334 phys_ascent
= it
->max_phys_ascent
;
14335 phys_descent
= it
->max_phys_descent
;
14338 PRODUCE_GLYPHS (it
);
14340 /* If this display element was in marginal areas, continue with
14342 if (it
->area
!= TEXT_AREA
)
14344 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14345 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14346 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14347 row
->phys_height
= max (row
->phys_height
,
14348 it
->max_phys_ascent
+ it
->max_phys_descent
);
14349 set_iterator_to_next (it
, 1);
14353 /* Does the display element fit on the line? If we truncate
14354 lines, we should draw past the right edge of the window. If
14355 we don't truncate, we want to stop so that we can display the
14356 continuation glyph before the right margin. If lines are
14357 continued, there are two possible strategies for characters
14358 resulting in more than 1 glyph (e.g. tabs): Display as many
14359 glyphs as possible in this line and leave the rest for the
14360 continuation line, or display the whole element in the next
14361 line. Original redisplay did the former, so we do it also. */
14362 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
14363 hpos_before
= it
->hpos
;
14366 if (/* Not a newline. */
14368 /* Glyphs produced fit entirely in the line. */
14369 && it
->current_x
< it
->last_visible_x
)
14371 it
->hpos
+= nglyphs
;
14372 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14373 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14374 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14375 row
->phys_height
= max (row
->phys_height
,
14376 it
->max_phys_ascent
+ it
->max_phys_descent
);
14377 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
14378 row
->x
= x
- it
->first_visible_x
;
14383 struct glyph
*glyph
;
14385 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
14387 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
14388 new_x
= x
+ glyph
->pixel_width
;
14390 if (/* Lines are continued. */
14391 !it
->truncate_lines_p
14392 && (/* Glyph doesn't fit on the line. */
14393 new_x
> it
->last_visible_x
14394 /* Or it fits exactly on a window system frame. */
14395 || (new_x
== it
->last_visible_x
14396 && FRAME_WINDOW_P (it
->f
))))
14398 /* End of a continued line. */
14401 || (new_x
== it
->last_visible_x
14402 && FRAME_WINDOW_P (it
->f
)))
14404 /* Current glyph is the only one on the line or
14405 fits exactly on the line. We must continue
14406 the line because we can't draw the cursor
14407 after the glyph. */
14408 row
->continued_p
= 1;
14409 it
->current_x
= new_x
;
14410 it
->continuation_lines_width
+= new_x
;
14412 if (i
== nglyphs
- 1)
14413 set_iterator_to_next (it
, 1);
14415 else if (CHAR_GLYPH_PADDING_P (*glyph
)
14416 && !FRAME_WINDOW_P (it
->f
))
14418 /* A padding glyph that doesn't fit on this line.
14419 This means the whole character doesn't fit
14421 row
->used
[TEXT_AREA
] = n_glyphs_before
;
14423 /* Fill the rest of the row with continuation
14424 glyphs like in 20.x. */
14425 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
14426 < row
->glyphs
[1 + TEXT_AREA
])
14427 produce_special_glyphs (it
, IT_CONTINUATION
);
14429 row
->continued_p
= 1;
14430 it
->current_x
= x_before
;
14431 it
->continuation_lines_width
+= x_before
;
14433 /* Restore the height to what it was before the
14434 element not fitting on the line. */
14435 it
->max_ascent
= ascent
;
14436 it
->max_descent
= descent
;
14437 it
->max_phys_ascent
= phys_ascent
;
14438 it
->max_phys_descent
= phys_descent
;
14440 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
14442 /* A TAB that extends past the right edge of the
14443 window. This produces a single glyph on
14444 window system frames. We leave the glyph in
14445 this row and let it fill the row, but don't
14446 consume the TAB. */
14447 it
->continuation_lines_width
+= it
->last_visible_x
;
14448 row
->ends_in_middle_of_char_p
= 1;
14449 row
->continued_p
= 1;
14450 glyph
->pixel_width
= it
->last_visible_x
- x
;
14451 it
->starts_in_middle_of_char_p
= 1;
14455 /* Something other than a TAB that draws past
14456 the right edge of the window. Restore
14457 positions to values before the element. */
14458 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
14460 /* Display continuation glyphs. */
14461 if (!FRAME_WINDOW_P (it
->f
))
14462 produce_special_glyphs (it
, IT_CONTINUATION
);
14463 row
->continued_p
= 1;
14465 it
->continuation_lines_width
+= x
;
14467 if (nglyphs
> 1 && i
> 0)
14469 row
->ends_in_middle_of_char_p
= 1;
14470 it
->starts_in_middle_of_char_p
= 1;
14473 /* Restore the height to what it was before the
14474 element not fitting on the line. */
14475 it
->max_ascent
= ascent
;
14476 it
->max_descent
= descent
;
14477 it
->max_phys_ascent
= phys_ascent
;
14478 it
->max_phys_descent
= phys_descent
;
14483 else if (new_x
> it
->first_visible_x
)
14485 /* Increment number of glyphs actually displayed. */
14488 if (x
< it
->first_visible_x
)
14489 /* Glyph is partially visible, i.e. row starts at
14490 negative X position. */
14491 row
->x
= x
- it
->first_visible_x
;
14495 /* Glyph is completely off the left margin of the
14496 window. This should not happen because of the
14497 move_it_in_display_line at the start of this
14498 function, unless the text display area of the
14499 window is empty. */
14500 xassert (it
->first_visible_x
<= it
->last_visible_x
);
14504 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
14505 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
14506 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
14507 row
->phys_height
= max (row
->phys_height
,
14508 it
->max_phys_ascent
+ it
->max_phys_descent
);
14510 /* End of this display line if row is continued. */
14511 if (row
->continued_p
)
14515 /* Is this a line end? If yes, we're also done, after making
14516 sure that a non-default face is extended up to the right
14517 margin of the window. */
14518 if (ITERATOR_AT_END_OF_LINE_P (it
))
14520 int used_before
= row
->used
[TEXT_AREA
];
14522 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
14524 /* Add a space at the end of the line that is used to
14525 display the cursor there. */
14526 append_space (it
, 0);
14528 /* Extend the face to the end of the line. */
14529 extend_face_to_end_of_line (it
);
14531 /* Make sure we have the position. */
14532 if (used_before
== 0)
14533 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
14535 /* Consume the line end. This skips over invisible lines. */
14536 set_iterator_to_next (it
, 1);
14537 it
->continuation_lines_width
= 0;
14541 /* Proceed with next display element. Note that this skips
14542 over lines invisible because of selective display. */
14543 set_iterator_to_next (it
, 1);
14545 /* If we truncate lines, we are done when the last displayed
14546 glyphs reach past the right margin of the window. */
14547 if (it
->truncate_lines_p
14548 && (FRAME_WINDOW_P (it
->f
)
14549 ? (it
->current_x
>= it
->last_visible_x
)
14550 : (it
->current_x
> it
->last_visible_x
)))
14552 /* Maybe add truncation glyphs. */
14553 if (!FRAME_WINDOW_P (it
->f
))
14557 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
14558 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
14561 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
14563 row
->used
[TEXT_AREA
] = i
;
14564 produce_special_glyphs (it
, IT_TRUNCATION
);
14568 row
->truncated_on_right_p
= 1;
14569 it
->continuation_lines_width
= 0;
14570 reseat_at_next_visible_line_start (it
, 0);
14571 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
14572 it
->hpos
= hpos_before
;
14573 it
->current_x
= x_before
;
14578 /* If line is not empty and hscrolled, maybe insert truncation glyphs
14579 at the left window margin. */
14580 if (it
->first_visible_x
14581 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
14583 if (!FRAME_WINDOW_P (it
->f
))
14584 insert_left_trunc_glyphs (it
);
14585 row
->truncated_on_left_p
= 1;
14588 /* If the start of this line is the overlay arrow-position, then
14589 mark this glyph row as the one containing the overlay arrow.
14590 This is clearly a mess with variable size fonts. It would be
14591 better to let it be displayed like cursors under X. */
14592 if (MARKERP (Voverlay_arrow_position
)
14593 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
14594 && (MATRIX_ROW_START_CHARPOS (row
)
14595 == marker_position (Voverlay_arrow_position
))
14596 && STRINGP (Voverlay_arrow_string
)
14597 && ! overlay_arrow_seen
)
14599 /* Overlay arrow in window redisplay is a fringe bitmap. */
14600 if (!FRAME_WINDOW_P (it
->f
))
14602 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
14603 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
14604 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
14605 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
14606 struct glyph
*p2
, *end
;
14608 /* Copy the arrow glyphs. */
14609 while (glyph
< arrow_end
)
14612 /* Throw away padding glyphs. */
14614 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
14615 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
14621 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
14625 overlay_arrow_seen
= 1;
14626 row
->overlay_arrow_p
= 1;
14629 /* Compute pixel dimensions of this line. */
14630 compute_line_metrics (it
);
14632 /* Remember the position at which this line ends. */
14633 row
->end
= it
->current
;
14635 /* Maybe set the cursor. */
14636 if (it
->w
->cursor
.vpos
< 0
14637 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
14638 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
14639 && cursor_row_p (it
->w
, row
))
14640 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
14642 /* Highlight trailing whitespace. */
14643 if (!NILP (Vshow_trailing_whitespace
))
14644 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
14646 /* Prepare for the next line. This line starts horizontally at (X
14647 HPOS) = (0 0). Vertical positions are incremented. As a
14648 convenience for the caller, IT->glyph_row is set to the next
14650 it
->current_x
= it
->hpos
= 0;
14651 it
->current_y
+= row
->height
;
14654 return row
->displays_text_p
;
14659 /***********************************************************************
14661 ***********************************************************************/
14663 /* Redisplay the menu bar in the frame for window W.
14665 The menu bar of X frames that don't have X toolkit support is
14666 displayed in a special window W->frame->menu_bar_window.
14668 The menu bar of terminal frames is treated specially as far as
14669 glyph matrices are concerned. Menu bar lines are not part of
14670 windows, so the update is done directly on the frame matrix rows
14671 for the menu bar. */
14674 display_menu_bar (w
)
14677 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14682 /* Don't do all this for graphical frames. */
14684 if (!NILP (Vwindow_system
))
14687 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
14692 if (FRAME_MAC_P (f
))
14696 #ifdef USE_X_TOOLKIT
14697 xassert (!FRAME_WINDOW_P (f
));
14698 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
14699 it
.first_visible_x
= 0;
14700 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
14701 #else /* not USE_X_TOOLKIT */
14702 if (FRAME_WINDOW_P (f
))
14704 /* Menu bar lines are displayed in the desired matrix of the
14705 dummy window menu_bar_window. */
14706 struct window
*menu_w
;
14707 xassert (WINDOWP (f
->menu_bar_window
));
14708 menu_w
= XWINDOW (f
->menu_bar_window
);
14709 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
14711 it
.first_visible_x
= 0;
14712 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
14716 /* This is a TTY frame, i.e. character hpos/vpos are used as
14718 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
14720 it
.first_visible_x
= 0;
14721 it
.last_visible_x
= FRAME_COLS (f
);
14723 #endif /* not USE_X_TOOLKIT */
14725 if (! mode_line_inverse_video
)
14726 /* Force the menu-bar to be displayed in the default face. */
14727 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
14729 /* Clear all rows of the menu bar. */
14730 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
14732 struct glyph_row
*row
= it
.glyph_row
+ i
;
14733 clear_glyph_row (row
);
14734 row
->enabled_p
= 1;
14735 row
->full_width_p
= 1;
14738 /* Display all items of the menu bar. */
14739 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
14740 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
14742 Lisp_Object string
;
14744 /* Stop at nil string. */
14745 string
= AREF (items
, i
+ 1);
14749 /* Remember where item was displayed. */
14750 AREF (items
, i
+ 3) = make_number (it
.hpos
);
14752 /* Display the item, pad with one space. */
14753 if (it
.current_x
< it
.last_visible_x
)
14754 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
14755 SCHARS (string
) + 1, 0, 0, -1);
14758 /* Fill out the line with spaces. */
14759 if (it
.current_x
< it
.last_visible_x
)
14760 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
14762 /* Compute the total height of the lines. */
14763 compute_line_metrics (&it
);
14768 /***********************************************************************
14770 ***********************************************************************/
14772 /* Redisplay mode lines in the window tree whose root is WINDOW. If
14773 FORCE is non-zero, redisplay mode lines unconditionally.
14774 Otherwise, redisplay only mode lines that are garbaged. Value is
14775 the number of windows whose mode lines were redisplayed. */
14778 redisplay_mode_lines (window
, force
)
14779 Lisp_Object window
;
14784 while (!NILP (window
))
14786 struct window
*w
= XWINDOW (window
);
14788 if (WINDOWP (w
->hchild
))
14789 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
14790 else if (WINDOWP (w
->vchild
))
14791 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
14793 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
14794 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
14796 struct text_pos lpoint
;
14797 struct buffer
*old
= current_buffer
;
14799 /* Set the window's buffer for the mode line display. */
14800 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14801 set_buffer_internal_1 (XBUFFER (w
->buffer
));
14803 /* Point refers normally to the selected window. For any
14804 other window, set up appropriate value. */
14805 if (!EQ (window
, selected_window
))
14807 struct text_pos pt
;
14809 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
14810 if (CHARPOS (pt
) < BEGV
)
14811 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
14812 else if (CHARPOS (pt
) > (ZV
- 1))
14813 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
14815 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
14818 /* Display mode lines. */
14819 clear_glyph_matrix (w
->desired_matrix
);
14820 if (display_mode_lines (w
))
14823 w
->must_be_updated_p
= 1;
14826 /* Restore old settings. */
14827 set_buffer_internal_1 (old
);
14828 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14838 /* Display the mode and/or top line of window W. Value is the number
14839 of mode lines displayed. */
14842 display_mode_lines (w
)
14845 Lisp_Object old_selected_window
, old_selected_frame
;
14848 old_selected_frame
= selected_frame
;
14849 selected_frame
= w
->frame
;
14850 old_selected_window
= selected_window
;
14851 XSETWINDOW (selected_window
, w
);
14853 /* These will be set while the mode line specs are processed. */
14854 line_number_displayed
= 0;
14855 w
->column_number_displayed
= Qnil
;
14857 if (WINDOW_WANTS_MODELINE_P (w
))
14859 struct window
*sel_w
= XWINDOW (old_selected_window
);
14861 /* Select mode line face based on the real selected window. */
14862 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
14863 current_buffer
->mode_line_format
);
14867 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14869 display_mode_line (w
, HEADER_LINE_FACE_ID
,
14870 current_buffer
->header_line_format
);
14874 selected_frame
= old_selected_frame
;
14875 selected_window
= old_selected_window
;
14880 /* Display mode or top line of window W. FACE_ID specifies which line
14881 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
14882 FORMAT is the mode line format to display. Value is the pixel
14883 height of the mode line displayed. */
14886 display_mode_line (w
, face_id
, format
)
14888 enum face_id face_id
;
14889 Lisp_Object format
;
14894 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
14895 prepare_desired_row (it
.glyph_row
);
14897 if (! mode_line_inverse_video
)
14898 /* Force the mode-line to be displayed in the default face. */
14899 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
14901 /* Temporarily make frame's keyboard the current kboard so that
14902 kboard-local variables in the mode_line_format will get the right
14904 push_frame_kboard (it
.f
);
14905 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
14906 pop_frame_kboard ();
14908 /* Fill up with spaces. */
14909 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
14911 compute_line_metrics (&it
);
14912 it
.glyph_row
->full_width_p
= 1;
14913 it
.glyph_row
->mode_line_p
= 1;
14914 it
.glyph_row
->continued_p
= 0;
14915 it
.glyph_row
->truncated_on_left_p
= 0;
14916 it
.glyph_row
->truncated_on_right_p
= 0;
14918 /* Make a 3D mode-line have a shadow at its right end. */
14919 face
= FACE_FROM_ID (it
.f
, face_id
);
14920 extend_face_to_end_of_line (&it
);
14921 if (face
->box
!= FACE_NO_BOX
)
14923 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
14924 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
14925 last
->right_box_line_p
= 1;
14928 return it
.glyph_row
->height
;
14931 /* Alist that caches the results of :propertize.
14932 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
14933 Lisp_Object mode_line_proptrans_alist
;
14935 /* List of strings making up the mode-line. */
14936 Lisp_Object mode_line_string_list
;
14938 /* Base face property when building propertized mode line string. */
14939 static Lisp_Object mode_line_string_face
;
14940 static Lisp_Object mode_line_string_face_prop
;
14943 /* Contribute ELT to the mode line for window IT->w. How it
14944 translates into text depends on its data type.
14946 IT describes the display environment in which we display, as usual.
14948 DEPTH is the depth in recursion. It is used to prevent
14949 infinite recursion here.
14951 FIELD_WIDTH is the number of characters the display of ELT should
14952 occupy in the mode line, and PRECISION is the maximum number of
14953 characters to display from ELT's representation. See
14954 display_string for details.
14956 Returns the hpos of the end of the text generated by ELT.
14958 PROPS is a property list to add to any string we encounter.
14960 If RISKY is nonzero, remove (disregard) any properties in any string
14961 we encounter, and ignore :eval and :propertize.
14963 If the global variable `frame_title_ptr' is non-NULL, then the output
14964 is passed to `store_frame_title' instead of `display_string'. */
14967 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
14970 int field_width
, precision
;
14971 Lisp_Object elt
, props
;
14974 int n
= 0, field
, prec
;
14979 elt
= build_string ("*too-deep*");
14983 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
14987 /* A string: output it and check for %-constructs within it. */
14989 const unsigned char *this, *lisp_string
;
14991 if (!NILP (props
) || risky
)
14993 Lisp_Object oprops
, aelt
;
14994 oprops
= Ftext_properties_at (make_number (0), elt
);
14996 if (NILP (Fequal (props
, oprops
)) || risky
)
14998 /* If the starting string has properties,
14999 merge the specified ones onto the existing ones. */
15000 if (! NILP (oprops
) && !risky
)
15004 oprops
= Fcopy_sequence (oprops
);
15006 while (CONSP (tem
))
15008 oprops
= Fplist_put (oprops
, XCAR (tem
),
15009 XCAR (XCDR (tem
)));
15010 tem
= XCDR (XCDR (tem
));
15015 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15016 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15018 mode_line_proptrans_alist
15019 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15026 elt
= Fcopy_sequence (elt
);
15027 Fset_text_properties (make_number (0), Flength (elt
),
15029 /* Add this item to mode_line_proptrans_alist. */
15030 mode_line_proptrans_alist
15031 = Fcons (Fcons (elt
, props
),
15032 mode_line_proptrans_alist
);
15033 /* Truncate mode_line_proptrans_alist
15034 to at most 50 elements. */
15035 tem
= Fnthcdr (make_number (50),
15036 mode_line_proptrans_alist
);
15038 XSETCDR (tem
, Qnil
);
15043 this = SDATA (elt
);
15044 lisp_string
= this;
15048 prec
= precision
- n
;
15049 if (frame_title_ptr
)
15050 n
+= store_frame_title (SDATA (elt
), -1, prec
);
15051 else if (!NILP (mode_line_string_list
))
15052 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15054 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15055 0, prec
, 0, STRING_MULTIBYTE (elt
));
15060 while ((precision
<= 0 || n
< precision
)
15062 && (frame_title_ptr
15063 || !NILP (mode_line_string_list
)
15064 || it
->current_x
< it
->last_visible_x
))
15066 const unsigned char *last
= this;
15068 /* Advance to end of string or next format specifier. */
15069 while ((c
= *this++) != '\0' && c
!= '%')
15072 if (this - 1 != last
)
15074 /* Output to end of string or up to '%'. Field width
15075 is length of string. Don't output more than
15076 PRECISION allows us. */
15079 prec
= chars_in_text (last
, this - last
);
15080 if (precision
> 0 && prec
> precision
- n
)
15081 prec
= precision
- n
;
15083 if (frame_title_ptr
)
15084 n
+= store_frame_title (last
, 0, prec
);
15085 else if (!NILP (mode_line_string_list
))
15087 int bytepos
= last
- lisp_string
;
15088 int charpos
= string_byte_to_char (elt
, bytepos
);
15089 n
+= store_mode_line_string (NULL
,
15090 Fsubstring (elt
, make_number (charpos
),
15091 make_number (charpos
+ prec
)),
15096 int bytepos
= last
- lisp_string
;
15097 int charpos
= string_byte_to_char (elt
, bytepos
);
15098 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15100 STRING_MULTIBYTE (elt
));
15103 else /* c == '%' */
15105 const unsigned char *percent_position
= this;
15107 /* Get the specified minimum width. Zero means
15110 while ((c
= *this++) >= '0' && c
<= '9')
15111 field
= field
* 10 + c
- '0';
15113 /* Don't pad beyond the total padding allowed. */
15114 if (field_width
- n
> 0 && field
> field_width
- n
)
15115 field
= field_width
- n
;
15117 /* Note that either PRECISION <= 0 or N < PRECISION. */
15118 prec
= precision
- n
;
15121 n
+= display_mode_element (it
, depth
, field
, prec
,
15122 Vglobal_mode_string
, props
,
15127 int bytepos
, charpos
;
15128 unsigned char *spec
;
15130 bytepos
= percent_position
- lisp_string
;
15131 charpos
= (STRING_MULTIBYTE (elt
)
15132 ? string_byte_to_char (elt
, bytepos
)
15136 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
15138 if (frame_title_ptr
)
15139 n
+= store_frame_title (spec
, field
, prec
);
15140 else if (!NILP (mode_line_string_list
))
15142 int len
= strlen (spec
);
15143 Lisp_Object tem
= make_string (spec
, len
);
15144 props
= Ftext_properties_at (make_number (charpos
), elt
);
15145 /* Should only keep face property in props */
15146 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
15150 int nglyphs_before
, nwritten
;
15152 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
15153 nwritten
= display_string (spec
, Qnil
, elt
,
15158 /* Assign to the glyphs written above the
15159 string where the `%x' came from, position
15163 struct glyph
*glyph
15164 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
15168 for (i
= 0; i
< nwritten
; ++i
)
15170 glyph
[i
].object
= elt
;
15171 glyph
[i
].charpos
= charpos
;
15186 /* A symbol: process the value of the symbol recursively
15187 as if it appeared here directly. Avoid error if symbol void.
15188 Special case: if value of symbol is a string, output the string
15191 register Lisp_Object tem
;
15193 /* If the variable is not marked as risky to set
15194 then its contents are risky to use. */
15195 if (NILP (Fget (elt
, Qrisky_local_variable
)))
15198 tem
= Fboundp (elt
);
15201 tem
= Fsymbol_value (elt
);
15202 /* If value is a string, output that string literally:
15203 don't check for % within it. */
15207 if (!EQ (tem
, elt
))
15209 /* Give up right away for nil or t. */
15219 register Lisp_Object car
, tem
;
15221 /* A cons cell: five distinct cases.
15222 If first element is :eval or :propertize, do something special.
15223 If first element is a string or a cons, process all the elements
15224 and effectively concatenate them.
15225 If first element is a negative number, truncate displaying cdr to
15226 at most that many characters. If positive, pad (with spaces)
15227 to at least that many characters.
15228 If first element is a symbol, process the cadr or caddr recursively
15229 according to whether the symbol's value is non-nil or nil. */
15231 if (EQ (car
, QCeval
))
15233 /* An element of the form (:eval FORM) means evaluate FORM
15234 and use the result as mode line elements. */
15239 if (CONSP (XCDR (elt
)))
15242 spec
= safe_eval (XCAR (XCDR (elt
)));
15243 n
+= display_mode_element (it
, depth
, field_width
- n
,
15244 precision
- n
, spec
, props
,
15248 else if (EQ (car
, QCpropertize
))
15250 /* An element of the form (:propertize ELT PROPS...)
15251 means display ELT but applying properties PROPS. */
15256 if (CONSP (XCDR (elt
)))
15257 n
+= display_mode_element (it
, depth
, field_width
- n
,
15258 precision
- n
, XCAR (XCDR (elt
)),
15259 XCDR (XCDR (elt
)), risky
);
15261 else if (SYMBOLP (car
))
15263 tem
= Fboundp (car
);
15267 /* elt is now the cdr, and we know it is a cons cell.
15268 Use its car if CAR has a non-nil value. */
15271 tem
= Fsymbol_value (car
);
15278 /* Symbol's value is nil (or symbol is unbound)
15279 Get the cddr of the original list
15280 and if possible find the caddr and use that. */
15284 else if (!CONSP (elt
))
15289 else if (INTEGERP (car
))
15291 register int lim
= XINT (car
);
15295 /* Negative int means reduce maximum width. */
15296 if (precision
<= 0)
15299 precision
= min (precision
, -lim
);
15303 /* Padding specified. Don't let it be more than
15304 current maximum. */
15306 lim
= min (precision
, lim
);
15308 /* If that's more padding than already wanted, queue it.
15309 But don't reduce padding already specified even if
15310 that is beyond the current truncation point. */
15311 field_width
= max (lim
, field_width
);
15315 else if (STRINGP (car
) || CONSP (car
))
15317 register int limit
= 50;
15318 /* Limit is to protect against circular lists. */
15321 && (precision
<= 0 || n
< precision
))
15323 n
+= display_mode_element (it
, depth
, field_width
- n
,
15324 precision
- n
, XCAR (elt
),
15334 elt
= build_string ("*invalid*");
15338 /* Pad to FIELD_WIDTH. */
15339 if (field_width
> 0 && n
< field_width
)
15341 if (frame_title_ptr
)
15342 n
+= store_frame_title ("", field_width
- n
, 0);
15343 else if (!NILP (mode_line_string_list
))
15344 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
15346 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
15353 /* Store a mode-line string element in mode_line_string_list.
15355 If STRING is non-null, display that C string. Otherwise, the Lisp
15356 string LISP_STRING is displayed.
15358 FIELD_WIDTH is the minimum number of output glyphs to produce.
15359 If STRING has fewer characters than FIELD_WIDTH, pad to the right
15360 with spaces. FIELD_WIDTH <= 0 means don't pad.
15362 PRECISION is the maximum number of characters to output from
15363 STRING. PRECISION <= 0 means don't truncate the string.
15365 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
15366 properties to the string.
15368 PROPS are the properties to add to the string.
15369 The mode_line_string_face face property is always added to the string.
15372 static int store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
15374 Lisp_Object lisp_string
;
15383 if (string
!= NULL
)
15385 len
= strlen (string
);
15386 if (precision
> 0 && len
> precision
)
15388 lisp_string
= make_string (string
, len
);
15390 props
= mode_line_string_face_prop
;
15391 else if (!NILP (mode_line_string_face
))
15393 Lisp_Object face
= Fplist_get (props
, Qface
);
15394 props
= Fcopy_sequence (props
);
15396 face
= mode_line_string_face
;
15398 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15399 props
= Fplist_put (props
, Qface
, face
);
15401 Fadd_text_properties (make_number (0), make_number (len
),
15402 props
, lisp_string
);
15406 len
= XFASTINT (Flength (lisp_string
));
15407 if (precision
> 0 && len
> precision
)
15410 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
15413 if (!NILP (mode_line_string_face
))
15417 props
= Ftext_properties_at (make_number (0), lisp_string
);
15418 face
= Fplist_get (props
, Qface
);
15420 face
= mode_line_string_face
;
15422 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
15423 props
= Fcons (Qface
, Fcons (face
, Qnil
));
15425 lisp_string
= Fcopy_sequence (lisp_string
);
15428 Fadd_text_properties (make_number (0), make_number (len
),
15429 props
, lisp_string
);
15434 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15438 if (field_width
> len
)
15440 field_width
-= len
;
15441 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
15443 Fadd_text_properties (make_number (0), make_number (field_width
),
15444 props
, lisp_string
);
15445 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
15453 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
15455 doc
: /* Return the mode-line of selected window as a string.
15456 First optional arg FORMAT specifies a different format string (see
15457 `mode-line-format' for details) to use. If FORMAT is t, return
15458 the buffer's header-line. Second optional arg WINDOW specifies a
15459 different window to use as the context for the formatting.
15460 If third optional arg NO-PROPS is non-nil, string is not propertized. */)
15461 (format
, window
, no_props
)
15462 Lisp_Object format
, window
, no_props
;
15467 struct buffer
*old_buffer
= NULL
;
15468 enum face_id face_id
= DEFAULT_FACE_ID
;
15471 window
= selected_window
;
15472 CHECK_WINDOW (window
);
15473 w
= XWINDOW (window
);
15474 CHECK_BUFFER (w
->buffer
);
15476 if (XBUFFER (w
->buffer
) != current_buffer
)
15478 old_buffer
= current_buffer
;
15479 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15482 if (NILP (format
) || EQ (format
, Qt
))
15484 face_id
= NILP (format
)
15485 ? CURRENT_MODE_LINE_FACE_ID (w
) :
15486 HEADER_LINE_FACE_ID
;
15487 format
= NILP (format
)
15488 ? current_buffer
->mode_line_format
15489 : current_buffer
->header_line_format
;
15492 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15494 if (NILP (no_props
))
15496 mode_line_string_face
=
15497 (face_id
== MODE_LINE_FACE_ID
? Qmode_line
:
15498 face_id
== MODE_LINE_INACTIVE_FACE_ID
? Qmode_line_inactive
:
15499 face_id
== HEADER_LINE_FACE_ID
? Qheader_line
: Qnil
);
15501 mode_line_string_face_prop
=
15502 NILP (mode_line_string_face
) ? Qnil
:
15503 Fcons (Qface
, Fcons (mode_line_string_face
, Qnil
));
15505 /* We need a dummy last element in mode_line_string_list to
15506 indicate we are building the propertized mode-line string.
15507 Using mode_line_string_face_prop here GC protects it. */
15508 mode_line_string_list
=
15509 Fcons (mode_line_string_face_prop
, Qnil
);
15510 frame_title_ptr
= NULL
;
15514 mode_line_string_face_prop
= Qnil
;
15515 mode_line_string_list
= Qnil
;
15516 frame_title_ptr
= frame_title_buf
;
15519 push_frame_kboard (it
.f
);
15520 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15521 pop_frame_kboard ();
15524 set_buffer_internal_1 (old_buffer
);
15526 if (NILP (no_props
))
15529 mode_line_string_list
= Fnreverse (mode_line_string_list
);
15530 str
= Fmapconcat (intern ("identity"), XCDR (mode_line_string_list
),
15531 make_string ("", 0));
15532 mode_line_string_face_prop
= Qnil
;
15533 mode_line_string_list
= Qnil
;
15537 len
= frame_title_ptr
- frame_title_buf
;
15538 if (len
> 0 && frame_title_ptr
[-1] == '-')
15540 /* Mode lines typically ends with numerous dashes; reduce to two dashes. */
15541 while (frame_title_ptr
> frame_title_buf
&& *--frame_title_ptr
== '-')
15543 frame_title_ptr
+= 3; /* restore last non-dash + two dashes */
15544 if (len
> frame_title_ptr
- frame_title_buf
)
15545 len
= frame_title_ptr
- frame_title_buf
;
15548 frame_title_ptr
= NULL
;
15549 return make_string (frame_title_buf
, len
);
15552 /* Write a null-terminated, right justified decimal representation of
15553 the positive integer D to BUF using a minimal field width WIDTH. */
15556 pint2str (buf
, width
, d
)
15557 register char *buf
;
15558 register int width
;
15561 register char *p
= buf
;
15569 *p
++ = d
% 10 + '0';
15574 for (width
-= (int) (p
- buf
); width
> 0; --width
)
15585 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
15586 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
15587 type of CODING_SYSTEM. Return updated pointer into BUF. */
15589 static unsigned char invalid_eol_type
[] = "(*invalid*)";
15592 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
15593 Lisp_Object coding_system
;
15594 register char *buf
;
15598 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
15599 const unsigned char *eol_str
;
15601 /* The EOL conversion we are using. */
15602 Lisp_Object eoltype
;
15604 val
= Fget (coding_system
, Qcoding_system
);
15607 if (!VECTORP (val
)) /* Not yet decided. */
15612 eoltype
= eol_mnemonic_undecided
;
15613 /* Don't mention EOL conversion if it isn't decided. */
15617 Lisp_Object eolvalue
;
15619 eolvalue
= Fget (coding_system
, Qeol_type
);
15622 *buf
++ = XFASTINT (AREF (val
, 1));
15626 /* The EOL conversion that is normal on this system. */
15628 if (NILP (eolvalue
)) /* Not yet decided. */
15629 eoltype
= eol_mnemonic_undecided
;
15630 else if (VECTORP (eolvalue
)) /* Not yet decided. */
15631 eoltype
= eol_mnemonic_undecided
;
15632 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
15633 eoltype
= (XFASTINT (eolvalue
) == 0
15634 ? eol_mnemonic_unix
15635 : (XFASTINT (eolvalue
) == 1
15636 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
15642 /* Mention the EOL conversion if it is not the usual one. */
15643 if (STRINGP (eoltype
))
15645 eol_str
= SDATA (eoltype
);
15646 eol_str_len
= SBYTES (eoltype
);
15648 else if (INTEGERP (eoltype
)
15649 && CHAR_VALID_P (XINT (eoltype
), 0))
15651 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
15652 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
15657 eol_str
= invalid_eol_type
;
15658 eol_str_len
= sizeof (invalid_eol_type
) - 1;
15660 bcopy (eol_str
, buf
, eol_str_len
);
15661 buf
+= eol_str_len
;
15667 /* Return a string for the output of a mode line %-spec for window W,
15668 generated by character C. PRECISION >= 0 means don't return a
15669 string longer than that value. FIELD_WIDTH > 0 means pad the
15670 string returned with spaces to that value. Return 1 in *MULTIBYTE
15671 if the result is multibyte text. */
15673 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
15676 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
15679 int field_width
, precision
;
15683 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15684 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
15685 struct buffer
*b
= XBUFFER (w
->buffer
);
15693 if (!NILP (b
->read_only
))
15695 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
15700 /* This differs from %* only for a modified read-only buffer. */
15701 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
15703 if (!NILP (b
->read_only
))
15708 /* This differs from %* in ignoring read-only-ness. */
15709 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
15721 if (command_loop_level
> 5)
15723 p
= decode_mode_spec_buf
;
15724 for (i
= 0; i
< command_loop_level
; i
++)
15727 return decode_mode_spec_buf
;
15735 if (command_loop_level
> 5)
15737 p
= decode_mode_spec_buf
;
15738 for (i
= 0; i
< command_loop_level
; i
++)
15741 return decode_mode_spec_buf
;
15748 /* Let lots_of_dashes be a string of infinite length. */
15749 if (!NILP (mode_line_string_list
))
15751 if (field_width
<= 0
15752 || field_width
> sizeof (lots_of_dashes
))
15754 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
15755 decode_mode_spec_buf
[i
] = '-';
15756 decode_mode_spec_buf
[i
] = '\0';
15757 return decode_mode_spec_buf
;
15760 return lots_of_dashes
;
15769 int col
= (int) current_column (); /* iftc */
15770 w
->column_number_displayed
= make_number (col
);
15771 pint2str (decode_mode_spec_buf
, field_width
, col
);
15772 return decode_mode_spec_buf
;
15776 /* %F displays the frame name. */
15777 if (!NILP (f
->title
))
15778 return (char *) SDATA (f
->title
);
15779 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
15780 return (char *) SDATA (f
->name
);
15789 int startpos
= XMARKER (w
->start
)->charpos
;
15790 int startpos_byte
= marker_byte_position (w
->start
);
15791 int line
, linepos
, linepos_byte
, topline
;
15793 int height
= WINDOW_TOTAL_LINES (w
);
15795 /* If we decided that this buffer isn't suitable for line numbers,
15796 don't forget that too fast. */
15797 if (EQ (w
->base_line_pos
, w
->buffer
))
15799 /* But do forget it, if the window shows a different buffer now. */
15800 else if (BUFFERP (w
->base_line_pos
))
15801 w
->base_line_pos
= Qnil
;
15803 /* If the buffer is very big, don't waste time. */
15804 if (INTEGERP (Vline_number_display_limit
)
15805 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
15807 w
->base_line_pos
= Qnil
;
15808 w
->base_line_number
= Qnil
;
15812 if (!NILP (w
->base_line_number
)
15813 && !NILP (w
->base_line_pos
)
15814 && XFASTINT (w
->base_line_pos
) <= startpos
)
15816 line
= XFASTINT (w
->base_line_number
);
15817 linepos
= XFASTINT (w
->base_line_pos
);
15818 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
15823 linepos
= BUF_BEGV (b
);
15824 linepos_byte
= BUF_BEGV_BYTE (b
);
15827 /* Count lines from base line to window start position. */
15828 nlines
= display_count_lines (linepos
, linepos_byte
,
15832 topline
= nlines
+ line
;
15834 /* Determine a new base line, if the old one is too close
15835 or too far away, or if we did not have one.
15836 "Too close" means it's plausible a scroll-down would
15837 go back past it. */
15838 if (startpos
== BUF_BEGV (b
))
15840 w
->base_line_number
= make_number (topline
);
15841 w
->base_line_pos
= make_number (BUF_BEGV (b
));
15843 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
15844 || linepos
== BUF_BEGV (b
))
15846 int limit
= BUF_BEGV (b
);
15847 int limit_byte
= BUF_BEGV_BYTE (b
);
15849 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
15851 if (startpos
- distance
> limit
)
15853 limit
= startpos
- distance
;
15854 limit_byte
= CHAR_TO_BYTE (limit
);
15857 nlines
= display_count_lines (startpos
, startpos_byte
,
15859 - (height
* 2 + 30),
15861 /* If we couldn't find the lines we wanted within
15862 line_number_display_limit_width chars per line,
15863 give up on line numbers for this window. */
15864 if (position
== limit_byte
&& limit
== startpos
- distance
)
15866 w
->base_line_pos
= w
->buffer
;
15867 w
->base_line_number
= Qnil
;
15871 w
->base_line_number
= make_number (topline
- nlines
);
15872 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
15875 /* Now count lines from the start pos to point. */
15876 nlines
= display_count_lines (startpos
, startpos_byte
,
15877 PT_BYTE
, PT
, &junk
);
15879 /* Record that we did display the line number. */
15880 line_number_displayed
= 1;
15882 /* Make the string to show. */
15883 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
15884 return decode_mode_spec_buf
;
15887 char* p
= decode_mode_spec_buf
;
15888 int pad
= field_width
- 2;
15894 return decode_mode_spec_buf
;
15900 obj
= b
->mode_name
;
15904 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
15910 int pos
= marker_position (w
->start
);
15911 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
15913 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
15915 if (pos
<= BUF_BEGV (b
))
15920 else if (pos
<= BUF_BEGV (b
))
15924 if (total
> 1000000)
15925 /* Do it differently for a large value, to avoid overflow. */
15926 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
15928 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
15929 /* We can't normally display a 3-digit number,
15930 so get us a 2-digit number that is close. */
15933 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
15934 return decode_mode_spec_buf
;
15938 /* Display percentage of size above the bottom of the screen. */
15941 int toppos
= marker_position (w
->start
);
15942 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
15943 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
15945 if (botpos
>= BUF_ZV (b
))
15947 if (toppos
<= BUF_BEGV (b
))
15954 if (total
> 1000000)
15955 /* Do it differently for a large value, to avoid overflow. */
15956 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
15958 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
15959 /* We can't normally display a 3-digit number,
15960 so get us a 2-digit number that is close. */
15963 if (toppos
<= BUF_BEGV (b
))
15964 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
15966 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
15967 return decode_mode_spec_buf
;
15972 /* status of process */
15973 obj
= Fget_buffer_process (w
->buffer
);
15975 return "no process";
15976 #ifdef subprocesses
15977 obj
= Fsymbol_name (Fprocess_status (obj
));
15981 case 't': /* indicate TEXT or BINARY */
15982 #ifdef MODE_LINE_BINARY_TEXT
15983 return MODE_LINE_BINARY_TEXT (b
);
15989 /* coding-system (not including end-of-line format) */
15991 /* coding-system (including end-of-line type) */
15993 int eol_flag
= (c
== 'Z');
15994 char *p
= decode_mode_spec_buf
;
15996 if (! FRAME_WINDOW_P (f
))
15998 /* No need to mention EOL here--the terminal never needs
15999 to do EOL conversion. */
16000 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
16001 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
16003 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
16006 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
16007 #ifdef subprocesses
16008 obj
= Fget_buffer_process (Fcurrent_buffer ());
16009 if (PROCESSP (obj
))
16011 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
16013 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
16016 #endif /* subprocesses */
16019 return decode_mode_spec_buf
;
16025 *multibyte
= STRING_MULTIBYTE (obj
);
16026 return (char *) SDATA (obj
);
16033 /* Count up to COUNT lines starting from START / START_BYTE.
16034 But don't go beyond LIMIT_BYTE.
16035 Return the number of lines thus found (always nonnegative).
16037 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
16040 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
16041 int start
, start_byte
, limit_byte
, count
;
16044 register unsigned char *cursor
;
16045 unsigned char *base
;
16047 register int ceiling
;
16048 register unsigned char *ceiling_addr
;
16049 int orig_count
= count
;
16051 /* If we are not in selective display mode,
16052 check only for newlines. */
16053 int selective_display
= (!NILP (current_buffer
->selective_display
)
16054 && !INTEGERP (current_buffer
->selective_display
));
16058 while (start_byte
< limit_byte
)
16060 ceiling
= BUFFER_CEILING_OF (start_byte
);
16061 ceiling
= min (limit_byte
- 1, ceiling
);
16062 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
16063 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
16066 if (selective_display
)
16067 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
16070 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
16073 if (cursor
!= ceiling_addr
)
16077 start_byte
+= cursor
- base
+ 1;
16078 *byte_pos_ptr
= start_byte
;
16082 if (++cursor
== ceiling_addr
)
16088 start_byte
+= cursor
- base
;
16093 while (start_byte
> limit_byte
)
16095 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
16096 ceiling
= max (limit_byte
, ceiling
);
16097 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
16098 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
16101 if (selective_display
)
16102 while (--cursor
!= ceiling_addr
16103 && *cursor
!= '\n' && *cursor
!= 015)
16106 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
16109 if (cursor
!= ceiling_addr
)
16113 start_byte
+= cursor
- base
+ 1;
16114 *byte_pos_ptr
= start_byte
;
16115 /* When scanning backwards, we should
16116 not count the newline posterior to which we stop. */
16117 return - orig_count
- 1;
16123 /* Here we add 1 to compensate for the last decrement
16124 of CURSOR, which took it past the valid range. */
16125 start_byte
+= cursor
- base
+ 1;
16129 *byte_pos_ptr
= limit_byte
;
16132 return - orig_count
+ count
;
16133 return orig_count
- count
;
16139 /***********************************************************************
16141 ***********************************************************************/
16143 /* Display a NUL-terminated string, starting with index START.
16145 If STRING is non-null, display that C string. Otherwise, the Lisp
16146 string LISP_STRING is displayed.
16148 If FACE_STRING is not nil, FACE_STRING_POS is a position in
16149 FACE_STRING. Display STRING or LISP_STRING with the face at
16150 FACE_STRING_POS in FACE_STRING:
16152 Display the string in the environment given by IT, but use the
16153 standard display table, temporarily.
16155 FIELD_WIDTH is the minimum number of output glyphs to produce.
16156 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16157 with spaces. If STRING has more characters, more than FIELD_WIDTH
16158 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
16160 PRECISION is the maximum number of characters to output from
16161 STRING. PRECISION < 0 means don't truncate the string.
16163 This is roughly equivalent to printf format specifiers:
16165 FIELD_WIDTH PRECISION PRINTF
16166 ----------------------------------------
16172 MULTIBYTE zero means do not display multibyte chars, > 0 means do
16173 display them, and < 0 means obey the current buffer's value of
16174 enable_multibyte_characters.
16176 Value is the number of glyphs produced. */
16179 display_string (string
, lisp_string
, face_string
, face_string_pos
,
16180 start
, it
, field_width
, precision
, max_x
, multibyte
)
16181 unsigned char *string
;
16182 Lisp_Object lisp_string
;
16183 Lisp_Object face_string
;
16184 int face_string_pos
;
16187 int field_width
, precision
, max_x
;
16190 int hpos_at_start
= it
->hpos
;
16191 int saved_face_id
= it
->face_id
;
16192 struct glyph_row
*row
= it
->glyph_row
;
16194 /* Initialize the iterator IT for iteration over STRING beginning
16195 with index START. */
16196 reseat_to_string (it
, string
, lisp_string
, start
,
16197 precision
, field_width
, multibyte
);
16199 /* If displaying STRING, set up the face of the iterator
16200 from LISP_STRING, if that's given. */
16201 if (STRINGP (face_string
))
16207 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
16208 0, it
->region_beg_charpos
,
16209 it
->region_end_charpos
,
16210 &endptr
, it
->base_face_id
, 0);
16211 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16212 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
16215 /* Set max_x to the maximum allowed X position. Don't let it go
16216 beyond the right edge of the window. */
16218 max_x
= it
->last_visible_x
;
16220 max_x
= min (max_x
, it
->last_visible_x
);
16222 /* Skip over display elements that are not visible. because IT->w is
16224 if (it
->current_x
< it
->first_visible_x
)
16225 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
16226 MOVE_TO_POS
| MOVE_TO_X
);
16228 row
->ascent
= it
->max_ascent
;
16229 row
->height
= it
->max_ascent
+ it
->max_descent
;
16230 row
->phys_ascent
= it
->max_phys_ascent
;
16231 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16233 /* This condition is for the case that we are called with current_x
16234 past last_visible_x. */
16235 while (it
->current_x
< max_x
)
16237 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
16239 /* Get the next display element. */
16240 if (!get_next_display_element (it
))
16243 /* Produce glyphs. */
16244 x_before
= it
->current_x
;
16245 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16246 PRODUCE_GLYPHS (it
);
16248 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
16251 while (i
< nglyphs
)
16253 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16255 if (!it
->truncate_lines_p
16256 && x
+ glyph
->pixel_width
> max_x
)
16258 /* End of continued line or max_x reached. */
16259 if (CHAR_GLYPH_PADDING_P (*glyph
))
16261 /* A wide character is unbreakable. */
16262 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16263 it
->current_x
= x_before
;
16267 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16272 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
16274 /* Glyph is at least partially visible. */
16276 if (x
< it
->first_visible_x
)
16277 it
->glyph_row
->x
= x
- it
->first_visible_x
;
16281 /* Glyph is off the left margin of the display area.
16282 Should not happen. */
16286 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16287 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16288 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16289 row
->phys_height
= max (row
->phys_height
,
16290 it
->max_phys_ascent
+ it
->max_phys_descent
);
16291 x
+= glyph
->pixel_width
;
16295 /* Stop if max_x reached. */
16299 /* Stop at line ends. */
16300 if (ITERATOR_AT_END_OF_LINE_P (it
))
16302 it
->continuation_lines_width
= 0;
16306 set_iterator_to_next (it
, 1);
16308 /* Stop if truncating at the right edge. */
16309 if (it
->truncate_lines_p
16310 && it
->current_x
>= it
->last_visible_x
)
16312 /* Add truncation mark, but don't do it if the line is
16313 truncated at a padding space. */
16314 if (IT_CHARPOS (*it
) < it
->string_nchars
)
16316 if (!FRAME_WINDOW_P (it
->f
))
16320 if (it
->current_x
> it
->last_visible_x
)
16322 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16323 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16325 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16327 row
->used
[TEXT_AREA
] = i
;
16328 produce_special_glyphs (it
, IT_TRUNCATION
);
16331 produce_special_glyphs (it
, IT_TRUNCATION
);
16333 it
->glyph_row
->truncated_on_right_p
= 1;
16339 /* Maybe insert a truncation at the left. */
16340 if (it
->first_visible_x
16341 && IT_CHARPOS (*it
) > 0)
16343 if (!FRAME_WINDOW_P (it
->f
))
16344 insert_left_trunc_glyphs (it
);
16345 it
->glyph_row
->truncated_on_left_p
= 1;
16348 it
->face_id
= saved_face_id
;
16350 /* Value is number of columns displayed. */
16351 return it
->hpos
- hpos_at_start
;
16356 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
16357 appears as an element of LIST or as the car of an element of LIST.
16358 If PROPVAL is a list, compare each element against LIST in that
16359 way, and return 1/2 if any element of PROPVAL is found in LIST.
16360 Otherwise return 0. This function cannot quit.
16361 The return value is 2 if the text is invisible but with an ellipsis
16362 and 1 if it's invisible and without an ellipsis. */
16365 invisible_p (propval
, list
)
16366 register Lisp_Object propval
;
16369 register Lisp_Object tail
, proptail
;
16371 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16373 register Lisp_Object tem
;
16375 if (EQ (propval
, tem
))
16377 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
16378 return NILP (XCDR (tem
)) ? 1 : 2;
16381 if (CONSP (propval
))
16383 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
16385 Lisp_Object propelt
;
16386 propelt
= XCAR (proptail
);
16387 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
16389 register Lisp_Object tem
;
16391 if (EQ (propelt
, tem
))
16393 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
16394 return NILP (XCDR (tem
)) ? 1 : 2;
16403 /***********************************************************************
16405 ***********************************************************************/
16407 #ifdef HAVE_WINDOW_SYSTEM
16412 dump_glyph_string (s
)
16413 struct glyph_string
*s
;
16415 fprintf (stderr
, "glyph string\n");
16416 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
16417 s
->x
, s
->y
, s
->width
, s
->height
);
16418 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
16419 fprintf (stderr
, " hl = %d\n", s
->hl
);
16420 fprintf (stderr
, " left overhang = %d, right = %d\n",
16421 s
->left_overhang
, s
->right_overhang
);
16422 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
16423 fprintf (stderr
, " extends to end of line = %d\n",
16424 s
->extends_to_end_of_line_p
);
16425 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
16426 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
16429 #endif /* GLYPH_DEBUG */
16431 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
16432 of XChar2b structures for S; it can't be allocated in
16433 init_glyph_string because it must be allocated via `alloca'. W
16434 is the window on which S is drawn. ROW and AREA are the glyph row
16435 and area within the row from which S is constructed. START is the
16436 index of the first glyph structure covered by S. HL is a
16437 face-override for drawing S. */
16440 #define OPTIONAL_HDC(hdc) hdc,
16441 #define DECLARE_HDC(hdc) HDC hdc;
16442 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
16443 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
16446 #ifndef OPTIONAL_HDC
16447 #define OPTIONAL_HDC(hdc)
16448 #define DECLARE_HDC(hdc)
16449 #define ALLOCATE_HDC(hdc, f)
16450 #define RELEASE_HDC(hdc, f)
16454 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
16455 struct glyph_string
*s
;
16459 struct glyph_row
*row
;
16460 enum glyph_row_area area
;
16462 enum draw_glyphs_face hl
;
16464 bzero (s
, sizeof *s
);
16466 s
->f
= XFRAME (w
->frame
);
16470 s
->display
= FRAME_X_DISPLAY (s
->f
);
16471 s
->window
= FRAME_X_WINDOW (s
->f
);
16472 s
->char2b
= char2b
;
16476 s
->first_glyph
= row
->glyphs
[area
] + start
;
16477 s
->height
= row
->height
;
16478 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
16480 /* Display the internal border below the tool-bar window. */
16481 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
16482 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
16484 s
->ybase
= s
->y
+ row
->ascent
;
16488 /* Append the list of glyph strings with head H and tail T to the list
16489 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
16492 append_glyph_string_lists (head
, tail
, h
, t
)
16493 struct glyph_string
**head
, **tail
;
16494 struct glyph_string
*h
, *t
;
16508 /* Prepend the list of glyph strings with head H and tail T to the
16509 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
16513 prepend_glyph_string_lists (head
, tail
, h
, t
)
16514 struct glyph_string
**head
, **tail
;
16515 struct glyph_string
*h
, *t
;
16529 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
16530 Set *HEAD and *TAIL to the resulting list. */
16533 append_glyph_string (head
, tail
, s
)
16534 struct glyph_string
**head
, **tail
;
16535 struct glyph_string
*s
;
16537 s
->next
= s
->prev
= NULL
;
16538 append_glyph_string_lists (head
, tail
, s
, s
);
16542 /* Get face and two-byte form of character glyph GLYPH on frame F.
16543 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
16544 a pointer to a realized face that is ready for display. */
16546 static INLINE
struct face
*
16547 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
16549 struct glyph
*glyph
;
16555 xassert (glyph
->type
== CHAR_GLYPH
);
16556 face
= FACE_FROM_ID (f
, glyph
->face_id
);
16561 if (!glyph
->multibyte_p
)
16563 /* Unibyte case. We don't have to encode, but we have to make
16564 sure to use a face suitable for unibyte. */
16565 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
16567 else if (glyph
->u
.ch
< 128
16568 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
16570 /* Case of ASCII in a face known to fit ASCII. */
16571 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
16575 int c1
, c2
, charset
;
16577 /* Split characters into bytes. If c2 is -1 afterwards, C is
16578 really a one-byte character so that byte1 is zero. */
16579 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
16581 STORE_XCHAR2B (char2b
, c1
, c2
);
16583 STORE_XCHAR2B (char2b
, 0, c1
);
16585 /* Maybe encode the character in *CHAR2B. */
16586 if (charset
!= CHARSET_ASCII
)
16588 struct font_info
*font_info
16589 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
16592 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
16596 /* Make sure X resources of the face are allocated. */
16597 xassert (face
!= NULL
);
16598 PREPARE_FACE_FOR_DISPLAY (f
, face
);
16603 /* Fill glyph string S with composition components specified by S->cmp.
16605 FACES is an array of faces for all components of this composition.
16606 S->gidx is the index of the first component for S.
16607 OVERLAPS_P non-zero means S should draw the foreground only, and
16608 use its physical height for clipping.
16610 Value is the index of a component not in S. */
16613 fill_composite_glyph_string (s
, faces
, overlaps_p
)
16614 struct glyph_string
*s
;
16615 struct face
**faces
;
16622 s
->for_overlaps_p
= overlaps_p
;
16624 s
->face
= faces
[s
->gidx
];
16625 s
->font
= s
->face
->font
;
16626 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
16628 /* For all glyphs of this composition, starting at the offset
16629 S->gidx, until we reach the end of the definition or encounter a
16630 glyph that requires the different face, add it to S. */
16632 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
16635 /* All glyph strings for the same composition has the same width,
16636 i.e. the width set for the first component of the composition. */
16638 s
->width
= s
->first_glyph
->pixel_width
;
16640 /* If the specified font could not be loaded, use the frame's
16641 default font, but record the fact that we couldn't load it in
16642 the glyph string so that we can draw rectangles for the
16643 characters of the glyph string. */
16644 if (s
->font
== NULL
)
16646 s
->font_not_found_p
= 1;
16647 s
->font
= FRAME_FONT (s
->f
);
16650 /* Adjust base line for subscript/superscript text. */
16651 s
->ybase
+= s
->first_glyph
->voffset
;
16653 xassert (s
->face
&& s
->face
->gc
);
16655 /* This glyph string must always be drawn with 16-bit functions. */
16658 return s
->gidx
+ s
->nchars
;
16662 /* Fill glyph string S from a sequence of character glyphs.
16664 FACE_ID is the face id of the string. START is the index of the
16665 first glyph to consider, END is the index of the last + 1.
16666 OVERLAPS_P non-zero means S should draw the foreground only, and
16667 use its physical height for clipping.
16669 Value is the index of the first glyph not in S. */
16672 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
16673 struct glyph_string
*s
;
16675 int start
, end
, overlaps_p
;
16677 struct glyph
*glyph
, *last
;
16679 int glyph_not_available_p
;
16681 xassert (s
->f
== XFRAME (s
->w
->frame
));
16682 xassert (s
->nchars
== 0);
16683 xassert (start
>= 0 && end
> start
);
16685 s
->for_overlaps_p
= overlaps_p
,
16686 glyph
= s
->row
->glyphs
[s
->area
] + start
;
16687 last
= s
->row
->glyphs
[s
->area
] + end
;
16688 voffset
= glyph
->voffset
;
16690 glyph_not_available_p
= glyph
->glyph_not_available_p
;
16692 while (glyph
< last
16693 && glyph
->type
== CHAR_GLYPH
16694 && glyph
->voffset
== voffset
16695 /* Same face id implies same font, nowadays. */
16696 && glyph
->face_id
== face_id
16697 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
16701 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
16702 s
->char2b
+ s
->nchars
,
16704 s
->two_byte_p
= two_byte_p
;
16706 xassert (s
->nchars
<= end
- start
);
16707 s
->width
+= glyph
->pixel_width
;
16711 s
->font
= s
->face
->font
;
16712 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
16714 /* If the specified font could not be loaded, use the frame's font,
16715 but record the fact that we couldn't load it in
16716 S->font_not_found_p so that we can draw rectangles for the
16717 characters of the glyph string. */
16718 if (s
->font
== NULL
|| glyph_not_available_p
)
16720 s
->font_not_found_p
= 1;
16721 s
->font
= FRAME_FONT (s
->f
);
16724 /* Adjust base line for subscript/superscript text. */
16725 s
->ybase
+= voffset
;
16727 xassert (s
->face
&& s
->face
->gc
);
16728 return glyph
- s
->row
->glyphs
[s
->area
];
16732 /* Fill glyph string S from image glyph S->first_glyph. */
16735 fill_image_glyph_string (s
)
16736 struct glyph_string
*s
;
16738 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
16739 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
16741 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
16742 s
->font
= s
->face
->font
;
16743 s
->width
= s
->first_glyph
->pixel_width
;
16745 /* Adjust base line for subscript/superscript text. */
16746 s
->ybase
+= s
->first_glyph
->voffset
;
16750 /* Fill glyph string S from a sequence of stretch glyphs.
16752 ROW is the glyph row in which the glyphs are found, AREA is the
16753 area within the row. START is the index of the first glyph to
16754 consider, END is the index of the last + 1.
16756 Value is the index of the first glyph not in S. */
16759 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
16760 struct glyph_string
*s
;
16761 struct glyph_row
*row
;
16762 enum glyph_row_area area
;
16765 struct glyph
*glyph
, *last
;
16766 int voffset
, face_id
;
16768 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
16770 glyph
= s
->row
->glyphs
[s
->area
] + start
;
16771 last
= s
->row
->glyphs
[s
->area
] + end
;
16772 face_id
= glyph
->face_id
;
16773 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
16774 s
->font
= s
->face
->font
;
16775 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
16776 s
->width
= glyph
->pixel_width
;
16777 voffset
= glyph
->voffset
;
16781 && glyph
->type
== STRETCH_GLYPH
16782 && glyph
->voffset
== voffset
16783 && glyph
->face_id
== face_id
);
16785 s
->width
+= glyph
->pixel_width
;
16787 /* Adjust base line for subscript/superscript text. */
16788 s
->ybase
+= voffset
;
16790 /* The case that face->gc == 0 is handled when drawing the glyph
16791 string by calling PREPARE_FACE_FOR_DISPLAY. */
16793 return glyph
- s
->row
->glyphs
[s
->area
];
16798 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
16799 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
16800 assumed to be zero. */
16803 x_get_glyph_overhangs (glyph
, f
, left
, right
)
16804 struct glyph
*glyph
;
16808 *left
= *right
= 0;
16810 if (glyph
->type
== CHAR_GLYPH
)
16814 struct font_info
*font_info
;
16818 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
16820 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
16821 if (font
/* ++KFS: Should this be font_info ? */
16822 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
16824 if (pcm
->rbearing
> pcm
->width
)
16825 *right
= pcm
->rbearing
- pcm
->width
;
16826 if (pcm
->lbearing
< 0)
16827 *left
= -pcm
->lbearing
;
16833 /* Return the index of the first glyph preceding glyph string S that
16834 is overwritten by S because of S's left overhang. Value is -1
16835 if no glyphs are overwritten. */
16838 left_overwritten (s
)
16839 struct glyph_string
*s
;
16843 if (s
->left_overhang
)
16846 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
16847 int first
= s
->first_glyph
- glyphs
;
16849 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
16850 x
-= glyphs
[i
].pixel_width
;
16861 /* Return the index of the first glyph preceding glyph string S that
16862 is overwriting S because of its right overhang. Value is -1 if no
16863 glyph in front of S overwrites S. */
16866 left_overwriting (s
)
16867 struct glyph_string
*s
;
16870 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
16871 int first
= s
->first_glyph
- glyphs
;
16875 for (i
= first
- 1; i
>= 0; --i
)
16878 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
16881 x
-= glyphs
[i
].pixel_width
;
16888 /* Return the index of the last glyph following glyph string S that is
16889 not overwritten by S because of S's right overhang. Value is -1 if
16890 no such glyph is found. */
16893 right_overwritten (s
)
16894 struct glyph_string
*s
;
16898 if (s
->right_overhang
)
16901 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
16902 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
16903 int end
= s
->row
->used
[s
->area
];
16905 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
16906 x
+= glyphs
[i
].pixel_width
;
16915 /* Return the index of the last glyph following glyph string S that
16916 overwrites S because of its left overhang. Value is negative
16917 if no such glyph is found. */
16920 right_overwriting (s
)
16921 struct glyph_string
*s
;
16924 int end
= s
->row
->used
[s
->area
];
16925 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
16926 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
16930 for (i
= first
; i
< end
; ++i
)
16933 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
16936 x
+= glyphs
[i
].pixel_width
;
16943 /* Get face and two-byte form of character C in face FACE_ID on frame
16944 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
16945 means we want to display multibyte text. DISPLAY_P non-zero means
16946 make sure that X resources for the face returned are allocated.
16947 Value is a pointer to a realized face that is ready for display if
16948 DISPLAY_P is non-zero. */
16950 static INLINE
struct face
*
16951 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
16955 int multibyte_p
, display_p
;
16957 struct face
*face
= FACE_FROM_ID (f
, face_id
);
16961 /* Unibyte case. We don't have to encode, but we have to make
16962 sure to use a face suitable for unibyte. */
16963 STORE_XCHAR2B (char2b
, 0, c
);
16964 face_id
= FACE_FOR_CHAR (f
, face
, c
);
16965 face
= FACE_FROM_ID (f
, face_id
);
16967 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
16969 /* Case of ASCII in a face known to fit ASCII. */
16970 STORE_XCHAR2B (char2b
, 0, c
);
16974 int c1
, c2
, charset
;
16976 /* Split characters into bytes. If c2 is -1 afterwards, C is
16977 really a one-byte character so that byte1 is zero. */
16978 SPLIT_CHAR (c
, charset
, c1
, c2
);
16980 STORE_XCHAR2B (char2b
, c1
, c2
);
16982 STORE_XCHAR2B (char2b
, 0, c1
);
16984 /* Maybe encode the character in *CHAR2B. */
16985 if (face
->font
!= NULL
)
16987 struct font_info
*font_info
16988 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
16990 rif
->encode_char (c
, char2b
, font_info
, 0);
16994 /* Make sure X resources of the face are allocated. */
16995 #ifdef HAVE_X_WINDOWS
16999 xassert (face
!= NULL
);
17000 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17007 /* Set background width of glyph string S. START is the index of the
17008 first glyph following S. LAST_X is the right-most x-position + 1
17009 in the drawing area. */
17012 set_glyph_string_background_width (s
, start
, last_x
)
17013 struct glyph_string
*s
;
17017 /* If the face of this glyph string has to be drawn to the end of
17018 the drawing area, set S->extends_to_end_of_line_p. */
17019 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
17021 if (start
== s
->row
->used
[s
->area
]
17022 && s
->area
== TEXT_AREA
17023 && ((s
->hl
== DRAW_NORMAL_TEXT
17024 && (s
->row
->fill_line_p
17025 || s
->face
->background
!= default_face
->background
17026 || s
->face
->stipple
!= default_face
->stipple
17027 || s
->row
->mouse_face_p
))
17028 || s
->hl
== DRAW_MOUSE_FACE
17029 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
17030 && s
->row
->fill_line_p
)))
17031 s
->extends_to_end_of_line_p
= 1;
17033 /* If S extends its face to the end of the line, set its
17034 background_width to the distance to the right edge of the drawing
17036 if (s
->extends_to_end_of_line_p
)
17037 s
->background_width
= last_x
- s
->x
+ 1;
17039 s
->background_width
= s
->width
;
17043 /* Compute overhangs and x-positions for glyph string S and its
17044 predecessors, or successors. X is the starting x-position for S.
17045 BACKWARD_P non-zero means process predecessors. */
17048 compute_overhangs_and_x (s
, x
, backward_p
)
17049 struct glyph_string
*s
;
17057 if (rif
->compute_glyph_string_overhangs
)
17058 rif
->compute_glyph_string_overhangs (s
);
17068 if (rif
->compute_glyph_string_overhangs
)
17069 rif
->compute_glyph_string_overhangs (s
);
17079 /* The following macros are only called from draw_glyphs below.
17080 They reference the following parameters of that function directly:
17081 `w', `row', `area', and `overlap_p'
17082 as well as the following local variables:
17083 `s', `f', and `hdc' (in W32) */
17086 /* On W32, silently add local `hdc' variable to argument list of
17087 init_glyph_string. */
17088 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17089 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
17091 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
17092 init_glyph_string (s, char2b, w, row, area, start, hl)
17095 /* Add a glyph string for a stretch glyph to the list of strings
17096 between HEAD and TAIL. START is the index of the stretch glyph in
17097 row area AREA of glyph row ROW. END is the index of the last glyph
17098 in that glyph row area. X is the current output position assigned
17099 to the new glyph string constructed. HL overrides that face of the
17100 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17101 is the right-most x-position of the drawing area. */
17103 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
17104 and below -- keep them on one line. */
17105 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17108 s = (struct glyph_string *) alloca (sizeof *s); \
17109 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17110 START = fill_stretch_glyph_string (s, row, area, START, END); \
17111 append_glyph_string (&HEAD, &TAIL, s); \
17117 /* Add a glyph string for an image glyph to the list of strings
17118 between HEAD and TAIL. START is the index of the image glyph in
17119 row area AREA of glyph row ROW. END is the index of the last glyph
17120 in that glyph row area. X is the current output position assigned
17121 to the new glyph string constructed. HL overrides that face of the
17122 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
17123 is the right-most x-position of the drawing area. */
17125 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17128 s = (struct glyph_string *) alloca (sizeof *s); \
17129 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
17130 fill_image_glyph_string (s); \
17131 append_glyph_string (&HEAD, &TAIL, s); \
17138 /* Add a glyph string for a sequence of character glyphs to the list
17139 of strings between HEAD and TAIL. START is the index of the first
17140 glyph in row area AREA of glyph row ROW that is part of the new
17141 glyph string. END is the index of the last glyph in that glyph row
17142 area. X is the current output position assigned to the new glyph
17143 string constructed. HL overrides that face of the glyph; e.g. it
17144 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
17145 right-most x-position of the drawing area. */
17147 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17153 c = (row)->glyphs[area][START].u.ch; \
17154 face_id = (row)->glyphs[area][START].face_id; \
17156 s = (struct glyph_string *) alloca (sizeof *s); \
17157 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
17158 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
17159 append_glyph_string (&HEAD, &TAIL, s); \
17161 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
17166 /* Add a glyph string for a composite sequence to the list of strings
17167 between HEAD and TAIL. START is the index of the first glyph in
17168 row area AREA of glyph row ROW that is part of the new glyph
17169 string. END is the index of the last glyph in that glyph row area.
17170 X is the current output position assigned to the new glyph string
17171 constructed. HL overrides that face of the glyph; e.g. it is
17172 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
17173 x-position of the drawing area. */
17175 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
17177 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
17178 int face_id = (row)->glyphs[area][START].face_id; \
17179 struct face *base_face = FACE_FROM_ID (f, face_id); \
17180 struct composition *cmp = composition_table[cmp_id]; \
17181 int glyph_len = cmp->glyph_len; \
17183 struct face **faces; \
17184 struct glyph_string *first_s = NULL; \
17187 base_face = base_face->ascii_face; \
17188 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
17189 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
17190 /* At first, fill in `char2b' and `faces'. */ \
17191 for (n = 0; n < glyph_len; n++) \
17193 int c = COMPOSITION_GLYPH (cmp, n); \
17194 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
17195 faces[n] = FACE_FROM_ID (f, this_face_id); \
17196 get_char_face_and_encoding (f, c, this_face_id, \
17197 char2b + n, 1, 1); \
17200 /* Make glyph_strings for each glyph sequence that is drawable by \
17201 the same face, and append them to HEAD/TAIL. */ \
17202 for (n = 0; n < cmp->glyph_len;) \
17204 s = (struct glyph_string *) alloca (sizeof *s); \
17205 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
17206 append_glyph_string (&(HEAD), &(TAIL), s); \
17214 n = fill_composite_glyph_string (s, faces, overlaps_p); \
17222 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
17223 of AREA of glyph row ROW on window W between indices START and END.
17224 HL overrides the face for drawing glyph strings, e.g. it is
17225 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
17226 x-positions of the drawing area.
17228 This is an ugly monster macro construct because we must use alloca
17229 to allocate glyph strings (because draw_glyphs can be called
17230 asynchronously). */
17232 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
17235 HEAD = TAIL = NULL; \
17236 while (START < END) \
17238 struct glyph *first_glyph = (row)->glyphs[area] + START; \
17239 switch (first_glyph->type) \
17242 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
17246 case COMPOSITE_GLYPH: \
17247 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
17251 case STRETCH_GLYPH: \
17252 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
17256 case IMAGE_GLYPH: \
17257 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
17265 set_glyph_string_background_width (s, START, LAST_X); \
17272 /* Draw glyphs between START and END in AREA of ROW on window W,
17273 starting at x-position X. X is relative to AREA in W. HL is a
17274 face-override with the following meaning:
17276 DRAW_NORMAL_TEXT draw normally
17277 DRAW_CURSOR draw in cursor face
17278 DRAW_MOUSE_FACE draw in mouse face.
17279 DRAW_INVERSE_VIDEO draw in mode line face
17280 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
17281 DRAW_IMAGE_RAISED draw an image with a raised relief around it
17283 If OVERLAPS_P is non-zero, draw only the foreground of characters
17284 and clip to the physical height of ROW.
17286 Value is the x-position reached, relative to AREA of W. */
17289 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
17292 struct glyph_row
*row
;
17293 enum glyph_row_area area
;
17295 enum draw_glyphs_face hl
;
17298 struct glyph_string
*head
, *tail
;
17299 struct glyph_string
*s
;
17300 int last_x
, area_width
;
17303 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17306 ALLOCATE_HDC (hdc
, f
);
17308 /* Let's rather be paranoid than getting a SEGV. */
17309 end
= min (end
, row
->used
[area
]);
17310 start
= max (0, start
);
17311 start
= min (end
, start
);
17313 /* Translate X to frame coordinates. Set last_x to the right
17314 end of the drawing area. */
17315 if (row
->full_width_p
)
17317 /* X is relative to the left edge of W, without scroll bars
17319 x
+= WINDOW_LEFT_EDGE_X (w
);
17320 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
17324 int area_left
= window_box_left (w
, area
);
17326 area_width
= window_box_width (w
, area
);
17327 last_x
= area_left
+ area_width
;
17330 /* Build a doubly-linked list of glyph_string structures between
17331 head and tail from what we have to draw. Note that the macro
17332 BUILD_GLYPH_STRINGS will modify its start parameter. That's
17333 the reason we use a separate variable `i'. */
17335 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
17337 x_reached
= tail
->x
+ tail
->background_width
;
17341 /* If there are any glyphs with lbearing < 0 or rbearing > width in
17342 the row, redraw some glyphs in front or following the glyph
17343 strings built above. */
17344 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
17347 struct glyph_string
*h
, *t
;
17349 /* Compute overhangs for all glyph strings. */
17350 if (rif
->compute_glyph_string_overhangs
)
17351 for (s
= head
; s
; s
= s
->next
)
17352 rif
->compute_glyph_string_overhangs (s
);
17354 /* Prepend glyph strings for glyphs in front of the first glyph
17355 string that are overwritten because of the first glyph
17356 string's left overhang. The background of all strings
17357 prepended must be drawn because the first glyph string
17359 i
= left_overwritten (head
);
17363 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
17364 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17366 compute_overhangs_and_x (t
, head
->x
, 1);
17367 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
17370 /* Prepend glyph strings for glyphs in front of the first glyph
17371 string that overwrite that glyph string because of their
17372 right overhang. For these strings, only the foreground must
17373 be drawn, because it draws over the glyph string at `head'.
17374 The background must not be drawn because this would overwrite
17375 right overhangs of preceding glyphs for which no glyph
17377 i
= left_overwriting (head
);
17380 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
17381 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
17382 for (s
= h
; s
; s
= s
->next
)
17383 s
->background_filled_p
= 1;
17384 compute_overhangs_and_x (t
, head
->x
, 1);
17385 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
17388 /* Append glyphs strings for glyphs following the last glyph
17389 string tail that are overwritten by tail. The background of
17390 these strings has to be drawn because tail's foreground draws
17392 i
= right_overwritten (tail
);
17395 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
17396 DRAW_NORMAL_TEXT
, x
, last_x
);
17397 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
17398 append_glyph_string_lists (&head
, &tail
, h
, t
);
17401 /* Append glyph strings for glyphs following the last glyph
17402 string tail that overwrite tail. The foreground of such
17403 glyphs has to be drawn because it writes into the background
17404 of tail. The background must not be drawn because it could
17405 paint over the foreground of following glyphs. */
17406 i
= right_overwriting (tail
);
17409 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
17410 DRAW_NORMAL_TEXT
, x
, last_x
);
17411 for (s
= h
; s
; s
= s
->next
)
17412 s
->background_filled_p
= 1;
17413 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
17414 append_glyph_string_lists (&head
, &tail
, h
, t
);
17418 /* Draw all strings. */
17419 for (s
= head
; s
; s
= s
->next
)
17420 rif
->draw_glyph_string (s
);
17422 if (area
== TEXT_AREA
17423 && !row
->full_width_p
17424 /* When drawing overlapping rows, only the glyph strings'
17425 foreground is drawn, which doesn't erase a cursor
17429 int x0
= head
? head
->x
: x
;
17430 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
17432 int text_left
= window_box_left (w
, TEXT_AREA
);
17436 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
17437 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
17440 /* Value is the x-position up to which drawn, relative to AREA of W.
17441 This doesn't include parts drawn because of overhangs. */
17442 if (row
->full_width_p
)
17443 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
17445 x_reached
-= window_box_left (w
, area
);
17447 RELEASE_HDC (hdc
, f
);
17453 /* Store one glyph for IT->char_to_display in IT->glyph_row.
17454 Called from x_produce_glyphs when IT->glyph_row is non-null. */
17460 struct glyph
*glyph
;
17461 enum glyph_row_area area
= it
->area
;
17463 xassert (it
->glyph_row
);
17464 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
17466 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17467 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17469 glyph
->charpos
= CHARPOS (it
->position
);
17470 glyph
->object
= it
->object
;
17471 glyph
->pixel_width
= it
->pixel_width
;
17472 glyph
->voffset
= it
->voffset
;
17473 glyph
->type
= CHAR_GLYPH
;
17474 glyph
->multibyte_p
= it
->multibyte_p
;
17475 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17476 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17477 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
17478 || it
->phys_descent
> it
->descent
);
17479 glyph
->padding_p
= 0;
17480 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
17481 glyph
->face_id
= it
->face_id
;
17482 glyph
->u
.ch
= it
->char_to_display
;
17483 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17484 ++it
->glyph_row
->used
[area
];
17488 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
17489 Called from x_produce_glyphs when IT->glyph_row is non-null. */
17492 append_composite_glyph (it
)
17495 struct glyph
*glyph
;
17496 enum glyph_row_area area
= it
->area
;
17498 xassert (it
->glyph_row
);
17500 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17501 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17503 glyph
->charpos
= CHARPOS (it
->position
);
17504 glyph
->object
= it
->object
;
17505 glyph
->pixel_width
= it
->pixel_width
;
17506 glyph
->voffset
= it
->voffset
;
17507 glyph
->type
= COMPOSITE_GLYPH
;
17508 glyph
->multibyte_p
= it
->multibyte_p
;
17509 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17510 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17511 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
17512 || it
->phys_descent
> it
->descent
);
17513 glyph
->padding_p
= 0;
17514 glyph
->glyph_not_available_p
= 0;
17515 glyph
->face_id
= it
->face_id
;
17516 glyph
->u
.cmp_id
= it
->cmp_id
;
17517 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17518 ++it
->glyph_row
->used
[area
];
17523 /* Change IT->ascent and IT->height according to the setting of
17527 take_vertical_position_into_account (it
)
17532 if (it
->voffset
< 0)
17533 /* Increase the ascent so that we can display the text higher
17535 it
->ascent
+= abs (it
->voffset
);
17537 /* Increase the descent so that we can display the text lower
17539 it
->descent
+= it
->voffset
;
17544 /* Produce glyphs/get display metrics for the image IT is loaded with.
17545 See the description of struct display_iterator in dispextern.h for
17546 an overview of struct display_iterator. */
17549 produce_image_glyph (it
)
17555 xassert (it
->what
== IT_IMAGE
);
17557 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17558 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
17561 /* Make sure X resources of the face and image are loaded. */
17562 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
17563 prepare_image_for_display (it
->f
, img
);
17565 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
17566 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
17567 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
17571 if (face
->box
!= FACE_NO_BOX
)
17573 if (face
->box_line_width
> 0)
17575 it
->ascent
+= face
->box_line_width
;
17576 it
->descent
+= face
->box_line_width
;
17579 if (it
->start_of_box_run_p
)
17580 it
->pixel_width
+= abs (face
->box_line_width
);
17581 if (it
->end_of_box_run_p
)
17582 it
->pixel_width
+= abs (face
->box_line_width
);
17585 take_vertical_position_into_account (it
);
17589 struct glyph
*glyph
;
17590 enum glyph_row_area area
= it
->area
;
17592 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17593 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17595 glyph
->charpos
= CHARPOS (it
->position
);
17596 glyph
->object
= it
->object
;
17597 glyph
->pixel_width
= it
->pixel_width
;
17598 glyph
->voffset
= it
->voffset
;
17599 glyph
->type
= IMAGE_GLYPH
;
17600 glyph
->multibyte_p
= it
->multibyte_p
;
17601 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17602 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17603 glyph
->overlaps_vertically_p
= 0;
17604 glyph
->padding_p
= 0;
17605 glyph
->glyph_not_available_p
= 0;
17606 glyph
->face_id
= it
->face_id
;
17607 glyph
->u
.img_id
= img
->id
;
17608 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17609 ++it
->glyph_row
->used
[area
];
17615 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
17616 of the glyph, WIDTH and HEIGHT are the width and height of the
17617 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
17618 ascent of the glyph (0 <= ASCENT <= 1). */
17621 append_stretch_glyph (it
, object
, width
, height
, ascent
)
17623 Lisp_Object object
;
17627 struct glyph
*glyph
;
17628 enum glyph_row_area area
= it
->area
;
17630 xassert (ascent
>= 0 && ascent
<= 1);
17632 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
17633 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
17635 glyph
->charpos
= CHARPOS (it
->position
);
17636 glyph
->object
= object
;
17637 glyph
->pixel_width
= width
;
17638 glyph
->voffset
= it
->voffset
;
17639 glyph
->type
= STRETCH_GLYPH
;
17640 glyph
->multibyte_p
= it
->multibyte_p
;
17641 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
17642 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
17643 glyph
->overlaps_vertically_p
= 0;
17644 glyph
->padding_p
= 0;
17645 glyph
->glyph_not_available_p
= 0;
17646 glyph
->face_id
= it
->face_id
;
17647 glyph
->u
.stretch
.ascent
= height
* ascent
;
17648 glyph
->u
.stretch
.height
= height
;
17649 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
17650 ++it
->glyph_row
->used
[area
];
17655 /* Produce a stretch glyph for iterator IT. IT->object is the value
17656 of the glyph property displayed. The value must be a list
17657 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
17660 1. `:width WIDTH' specifies that the space should be WIDTH *
17661 canonical char width wide. WIDTH may be an integer or floating
17664 2. `:relative-width FACTOR' specifies that the width of the stretch
17665 should be computed from the width of the first character having the
17666 `glyph' property, and should be FACTOR times that width.
17668 3. `:align-to HPOS' specifies that the space should be wide enough
17669 to reach HPOS, a value in canonical character units.
17671 Exactly one of the above pairs must be present.
17673 4. `:height HEIGHT' specifies that the height of the stretch produced
17674 should be HEIGHT, measured in canonical character units.
17676 5. `:relative-height FACTOR' specifies that the height of the
17677 stretch should be FACTOR times the height of the characters having
17678 the glyph property.
17680 Either none or exactly one of 4 or 5 must be present.
17682 6. `:ascent ASCENT' specifies that ASCENT percent of the height
17683 of the stretch should be used for the ascent of the stretch.
17684 ASCENT must be in the range 0 <= ASCENT <= 100. */
17686 #define NUMVAL(X) \
17687 ((INTEGERP (X) || FLOATP (X)) \
17693 produce_stretch_glyph (it
)
17696 /* (space :width WIDTH :height HEIGHT. */
17697 Lisp_Object prop
, plist
;
17698 int width
= 0, height
= 0;
17700 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17701 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
17703 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
17705 /* List should start with `space'. */
17706 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
17707 plist
= XCDR (it
->object
);
17709 /* Compute the width of the stretch. */
17710 if (prop
= Fplist_get (plist
, QCwidth
),
17712 /* Absolute width `:width WIDTH' specified and valid. */
17713 width
= NUMVAL (prop
) * FRAME_COLUMN_WIDTH (it
->f
);
17714 else if (prop
= Fplist_get (plist
, QCrelative_width
),
17717 /* Relative width `:relative-width FACTOR' specified and valid.
17718 Compute the width of the characters having the `glyph'
17721 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
17724 if (it
->multibyte_p
)
17726 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
17727 - IT_BYTEPOS (*it
));
17728 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
17731 it2
.c
= *p
, it2
.len
= 1;
17733 it2
.glyph_row
= NULL
;
17734 it2
.what
= IT_CHARACTER
;
17735 x_produce_glyphs (&it2
);
17736 width
= NUMVAL (prop
) * it2
.pixel_width
;
17738 else if (prop
= Fplist_get (plist
, QCalign_to
),
17740 width
= NUMVAL (prop
) * FRAME_COLUMN_WIDTH (it
->f
) - it
->current_x
;
17742 /* Nothing specified -> width defaults to canonical char width. */
17743 width
= FRAME_COLUMN_WIDTH (it
->f
);
17745 /* Compute height. */
17746 if (prop
= Fplist_get (plist
, QCheight
),
17748 height
= NUMVAL (prop
) * FRAME_LINE_HEIGHT (it
->f
);
17749 else if (prop
= Fplist_get (plist
, QCrelative_height
),
17751 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
17753 height
= FONT_HEIGHT (font
);
17755 /* Compute percentage of height used for ascent. If
17756 `:ascent ASCENT' is present and valid, use that. Otherwise,
17757 derive the ascent from the font in use. */
17758 if (prop
= Fplist_get (plist
, QCascent
),
17759 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
17760 ascent
= NUMVAL (prop
) / 100.0;
17762 ascent
= (double) FONT_BASE (font
) / FONT_HEIGHT (font
);
17771 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
17772 if (!STRINGP (object
))
17773 object
= it
->w
->buffer
;
17774 append_stretch_glyph (it
, object
, width
, height
, ascent
);
17777 it
->pixel_width
= width
;
17778 it
->ascent
= it
->phys_ascent
= height
* ascent
;
17779 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
17782 if (face
->box
!= FACE_NO_BOX
)
17784 if (face
->box_line_width
> 0)
17786 it
->ascent
+= face
->box_line_width
;
17787 it
->descent
+= face
->box_line_width
;
17790 if (it
->start_of_box_run_p
)
17791 it
->pixel_width
+= abs (face
->box_line_width
);
17792 if (it
->end_of_box_run_p
)
17793 it
->pixel_width
+= abs (face
->box_line_width
);
17796 take_vertical_position_into_account (it
);
17800 Produce glyphs/get display metrics for the display element IT is
17801 loaded with. See the description of struct display_iterator in
17802 dispextern.h for an overview of struct display_iterator. */
17805 x_produce_glyphs (it
)
17808 it
->glyph_not_available_p
= 0;
17810 if (it
->what
== IT_CHARACTER
)
17814 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17816 int font_not_found_p
;
17817 struct font_info
*font_info
;
17818 int boff
; /* baseline offset */
17819 /* We may change it->multibyte_p upon unibyte<->multibyte
17820 conversion. So, save the current value now and restore it
17823 Note: It seems that we don't have to record multibyte_p in
17824 struct glyph because the character code itself tells if or
17825 not the character is multibyte. Thus, in the future, we must
17826 consider eliminating the field `multibyte_p' in the struct
17828 int saved_multibyte_p
= it
->multibyte_p
;
17830 /* Maybe translate single-byte characters to multibyte, or the
17832 it
->char_to_display
= it
->c
;
17833 if (!ASCII_BYTE_P (it
->c
))
17835 if (unibyte_display_via_language_environment
17836 && SINGLE_BYTE_CHAR_P (it
->c
)
17838 || !NILP (Vnonascii_translation_table
)))
17840 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
17841 it
->multibyte_p
= 1;
17842 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
17843 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17845 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
17846 && !it
->multibyte_p
)
17848 it
->multibyte_p
= 1;
17849 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
17850 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17854 /* Get font to use. Encode IT->char_to_display. */
17855 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
17856 &char2b
, it
->multibyte_p
, 0);
17859 /* When no suitable font found, use the default font. */
17860 font_not_found_p
= font
== NULL
;
17861 if (font_not_found_p
)
17863 font
= FRAME_FONT (it
->f
);
17864 boff
= FRAME_BASELINE_OFFSET (it
->f
);
17869 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
17870 boff
= font_info
->baseline_offset
;
17871 if (font_info
->vertical_centering
)
17872 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
17875 if (it
->char_to_display
>= ' '
17876 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
17878 /* Either unibyte or ASCII. */
17883 pcm
= rif
->per_char_metric (font
, &char2b
,
17884 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
17885 it
->ascent
= FONT_BASE (font
) + boff
;
17886 it
->descent
= FONT_DESCENT (font
) - boff
;
17890 it
->phys_ascent
= pcm
->ascent
+ boff
;
17891 it
->phys_descent
= pcm
->descent
- boff
;
17892 it
->pixel_width
= pcm
->width
;
17896 it
->glyph_not_available_p
= 1;
17897 it
->phys_ascent
= FONT_BASE (font
) + boff
;
17898 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
17899 it
->pixel_width
= FONT_WIDTH (font
);
17902 /* If this is a space inside a region of text with
17903 `space-width' property, change its width. */
17904 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
17906 it
->pixel_width
*= XFLOATINT (it
->space_width
);
17908 /* If face has a box, add the box thickness to the character
17909 height. If character has a box line to the left and/or
17910 right, add the box line width to the character's width. */
17911 if (face
->box
!= FACE_NO_BOX
)
17913 int thick
= face
->box_line_width
;
17917 it
->ascent
+= thick
;
17918 it
->descent
+= thick
;
17923 if (it
->start_of_box_run_p
)
17924 it
->pixel_width
+= thick
;
17925 if (it
->end_of_box_run_p
)
17926 it
->pixel_width
+= thick
;
17929 /* If face has an overline, add the height of the overline
17930 (1 pixel) and a 1 pixel margin to the character height. */
17931 if (face
->overline_p
)
17934 take_vertical_position_into_account (it
);
17936 /* If we have to actually produce glyphs, do it. */
17941 /* Translate a space with a `space-width' property
17942 into a stretch glyph. */
17943 double ascent
= (double) FONT_BASE (font
)
17944 / FONT_HEIGHT (font
);
17945 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
17946 it
->ascent
+ it
->descent
, ascent
);
17951 /* If characters with lbearing or rbearing are displayed
17952 in this line, record that fact in a flag of the
17953 glyph row. This is used to optimize X output code. */
17954 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
17955 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
17958 else if (it
->char_to_display
== '\n')
17960 /* A newline has no width but we need the height of the line. */
17961 it
->pixel_width
= 0;
17963 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
17964 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
17966 if (face
->box
!= FACE_NO_BOX
17967 && face
->box_line_width
> 0)
17969 it
->ascent
+= face
->box_line_width
;
17970 it
->descent
+= face
->box_line_width
;
17973 else if (it
->char_to_display
== '\t')
17975 int tab_width
= it
->tab_width
* FRAME_COLUMN_WIDTH (it
->f
);
17976 int x
= it
->current_x
+ it
->continuation_lines_width
;
17977 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
17979 /* If the distance from the current position to the next tab
17980 stop is less than a canonical character width, use the
17981 tab stop after that. */
17982 if (next_tab_x
- x
< FRAME_COLUMN_WIDTH (it
->f
))
17983 next_tab_x
+= tab_width
;
17985 it
->pixel_width
= next_tab_x
- x
;
17987 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
17988 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
17992 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
17993 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
17994 it
->ascent
+ it
->descent
, ascent
);
17999 /* A multi-byte character. Assume that the display width of the
18000 character is the width of the character multiplied by the
18001 width of the font. */
18003 /* If we found a font, this font should give us the right
18004 metrics. If we didn't find a font, use the frame's
18005 default font and calculate the width of the character
18006 from the charset width; this is what old redisplay code
18009 pcm
= rif
->per_char_metric (font
, &char2b
,
18010 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
18012 if (font_not_found_p
|| !pcm
)
18014 int charset
= CHAR_CHARSET (it
->char_to_display
);
18016 it
->glyph_not_available_p
= 1;
18017 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
18018 * CHARSET_WIDTH (charset
));
18019 it
->phys_ascent
= FONT_BASE (font
) + boff
;
18020 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
18024 it
->pixel_width
= pcm
->width
;
18025 it
->phys_ascent
= pcm
->ascent
+ boff
;
18026 it
->phys_descent
= pcm
->descent
- boff
;
18028 && (pcm
->lbearing
< 0
18029 || pcm
->rbearing
> pcm
->width
))
18030 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
18033 it
->ascent
= FONT_BASE (font
) + boff
;
18034 it
->descent
= FONT_DESCENT (font
) - boff
;
18035 if (face
->box
!= FACE_NO_BOX
)
18037 int thick
= face
->box_line_width
;
18041 it
->ascent
+= thick
;
18042 it
->descent
+= thick
;
18047 if (it
->start_of_box_run_p
)
18048 it
->pixel_width
+= thick
;
18049 if (it
->end_of_box_run_p
)
18050 it
->pixel_width
+= thick
;
18053 /* If face has an overline, add the height of the overline
18054 (1 pixel) and a 1 pixel margin to the character height. */
18055 if (face
->overline_p
)
18058 take_vertical_position_into_account (it
);
18063 it
->multibyte_p
= saved_multibyte_p
;
18065 else if (it
->what
== IT_COMPOSITION
)
18067 /* Note: A composition is represented as one glyph in the
18068 glyph matrix. There are no padding glyphs. */
18071 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18073 int font_not_found_p
;
18074 struct font_info
*font_info
;
18075 int boff
; /* baseline offset */
18076 struct composition
*cmp
= composition_table
[it
->cmp_id
];
18078 /* Maybe translate single-byte characters to multibyte. */
18079 it
->char_to_display
= it
->c
;
18080 if (unibyte_display_via_language_environment
18081 && SINGLE_BYTE_CHAR_P (it
->c
)
18084 && !NILP (Vnonascii_translation_table
))))
18086 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
18089 /* Get face and font to use. Encode IT->char_to_display. */
18090 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
18091 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18092 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
18093 &char2b
, it
->multibyte_p
, 0);
18096 /* When no suitable font found, use the default font. */
18097 font_not_found_p
= font
== NULL
;
18098 if (font_not_found_p
)
18100 font
= FRAME_FONT (it
->f
);
18101 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18106 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18107 boff
= font_info
->baseline_offset
;
18108 if (font_info
->vertical_centering
)
18109 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18112 /* There are no padding glyphs, so there is only one glyph to
18113 produce for the composition. Important is that pixel_width,
18114 ascent and descent are the values of what is drawn by
18115 draw_glyphs (i.e. the values of the overall glyphs composed). */
18118 /* If we have not yet calculated pixel size data of glyphs of
18119 the composition for the current face font, calculate them
18120 now. Theoretically, we have to check all fonts for the
18121 glyphs, but that requires much time and memory space. So,
18122 here we check only the font of the first glyph. This leads
18123 to incorrect display very rarely, and C-l (recenter) can
18124 correct the display anyway. */
18125 if (cmp
->font
!= (void *) font
)
18127 /* Ascent and descent of the font of the first character of
18128 this composition (adjusted by baseline offset). Ascent
18129 and descent of overall glyphs should not be less than
18130 them respectively. */
18131 int font_ascent
= FONT_BASE (font
) + boff
;
18132 int font_descent
= FONT_DESCENT (font
) - boff
;
18133 /* Bounding box of the overall glyphs. */
18134 int leftmost
, rightmost
, lowest
, highest
;
18135 int i
, width
, ascent
, descent
;
18137 cmp
->font
= (void *) font
;
18139 /* Initialize the bounding box. */
18141 && (pcm
= rif
->per_char_metric (font
, &char2b
,
18142 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
18144 width
= pcm
->width
;
18145 ascent
= pcm
->ascent
;
18146 descent
= pcm
->descent
;
18150 width
= FONT_WIDTH (font
);
18151 ascent
= FONT_BASE (font
);
18152 descent
= FONT_DESCENT (font
);
18156 lowest
= - descent
+ boff
;
18157 highest
= ascent
+ boff
;
18161 && font_info
->default_ascent
18162 && CHAR_TABLE_P (Vuse_default_ascent
)
18163 && !NILP (Faref (Vuse_default_ascent
,
18164 make_number (it
->char_to_display
))))
18165 highest
= font_info
->default_ascent
+ boff
;
18167 /* Draw the first glyph at the normal position. It may be
18168 shifted to right later if some other glyphs are drawn at
18170 cmp
->offsets
[0] = 0;
18171 cmp
->offsets
[1] = boff
;
18173 /* Set cmp->offsets for the remaining glyphs. */
18174 for (i
= 1; i
< cmp
->glyph_len
; i
++)
18176 int left
, right
, btm
, top
;
18177 int ch
= COMPOSITION_GLYPH (cmp
, i
);
18178 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
18180 face
= FACE_FROM_ID (it
->f
, face_id
);
18181 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
18182 &char2b
, it
->multibyte_p
, 0);
18186 font
= FRAME_FONT (it
->f
);
18187 boff
= FRAME_BASELINE_OFFSET (it
->f
);
18193 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
18194 boff
= font_info
->baseline_offset
;
18195 if (font_info
->vertical_centering
)
18196 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
18200 && (pcm
= rif
->per_char_metric (font
, &char2b
,
18201 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
18203 width
= pcm
->width
;
18204 ascent
= pcm
->ascent
;
18205 descent
= pcm
->descent
;
18209 width
= FONT_WIDTH (font
);
18214 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
18216 /* Relative composition with or without
18217 alternate chars. */
18218 left
= (leftmost
+ rightmost
- width
) / 2;
18219 btm
= - descent
+ boff
;
18220 if (font_info
&& font_info
->relative_compose
18221 && (! CHAR_TABLE_P (Vignore_relative_composition
)
18222 || NILP (Faref (Vignore_relative_composition
,
18223 make_number (ch
)))))
18226 if (- descent
>= font_info
->relative_compose
)
18227 /* One extra pixel between two glyphs. */
18229 else if (ascent
<= 0)
18230 /* One extra pixel between two glyphs. */
18231 btm
= lowest
- 1 - ascent
- descent
;
18236 /* A composition rule is specified by an integer
18237 value that encodes global and new reference
18238 points (GREF and NREF). GREF and NREF are
18239 specified by numbers as below:
18241 0---1---2 -- ascent
18245 9--10--11 -- center
18247 ---3---4---5--- baseline
18249 6---7---8 -- descent
18251 int rule
= COMPOSITION_RULE (cmp
, i
);
18252 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
18254 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
18255 grefx
= gref
% 3, nrefx
= nref
% 3;
18256 grefy
= gref
/ 3, nrefy
= nref
/ 3;
18259 + grefx
* (rightmost
- leftmost
) / 2
18260 - nrefx
* width
/ 2);
18261 btm
= ((grefy
== 0 ? highest
18263 : grefy
== 2 ? lowest
18264 : (highest
+ lowest
) / 2)
18265 - (nrefy
== 0 ? ascent
+ descent
18266 : nrefy
== 1 ? descent
- boff
18268 : (ascent
+ descent
) / 2));
18271 cmp
->offsets
[i
* 2] = left
;
18272 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
18274 /* Update the bounding box of the overall glyphs. */
18275 right
= left
+ width
;
18276 top
= btm
+ descent
+ ascent
;
18277 if (left
< leftmost
)
18279 if (right
> rightmost
)
18287 /* If there are glyphs whose x-offsets are negative,
18288 shift all glyphs to the right and make all x-offsets
18292 for (i
= 0; i
< cmp
->glyph_len
; i
++)
18293 cmp
->offsets
[i
* 2] -= leftmost
;
18294 rightmost
-= leftmost
;
18297 cmp
->pixel_width
= rightmost
;
18298 cmp
->ascent
= highest
;
18299 cmp
->descent
= - lowest
;
18300 if (cmp
->ascent
< font_ascent
)
18301 cmp
->ascent
= font_ascent
;
18302 if (cmp
->descent
< font_descent
)
18303 cmp
->descent
= font_descent
;
18306 it
->pixel_width
= cmp
->pixel_width
;
18307 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
18308 it
->descent
= it
->phys_descent
= cmp
->descent
;
18310 if (face
->box
!= FACE_NO_BOX
)
18312 int thick
= face
->box_line_width
;
18316 it
->ascent
+= thick
;
18317 it
->descent
+= thick
;
18322 if (it
->start_of_box_run_p
)
18323 it
->pixel_width
+= thick
;
18324 if (it
->end_of_box_run_p
)
18325 it
->pixel_width
+= thick
;
18328 /* If face has an overline, add the height of the overline
18329 (1 pixel) and a 1 pixel margin to the character height. */
18330 if (face
->overline_p
)
18333 take_vertical_position_into_account (it
);
18336 append_composite_glyph (it
);
18338 else if (it
->what
== IT_IMAGE
)
18339 produce_image_glyph (it
);
18340 else if (it
->what
== IT_STRETCH
)
18341 produce_stretch_glyph (it
);
18343 /* Accumulate dimensions. Note: can't assume that it->descent > 0
18344 because this isn't true for images with `:ascent 100'. */
18345 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
18346 if (it
->area
== TEXT_AREA
)
18347 it
->current_x
+= it
->pixel_width
;
18349 it
->descent
+= it
->extra_line_spacing
;
18351 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
18352 it
->max_descent
= max (it
->max_descent
, it
->descent
);
18353 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
18354 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
18358 Output LEN glyphs starting at START at the nominal cursor position.
18359 Advance the nominal cursor over the text. The global variable
18360 updated_window contains the window being updated, updated_row is
18361 the glyph row being updated, and updated_area is the area of that
18362 row being updated. */
18365 x_write_glyphs (start
, len
)
18366 struct glyph
*start
;
18371 xassert (updated_window
&& updated_row
);
18374 /* Write glyphs. */
18376 hpos
= start
- updated_row
->glyphs
[updated_area
];
18377 x
= draw_glyphs (updated_window
, output_cursor
.x
,
18378 updated_row
, updated_area
,
18380 DRAW_NORMAL_TEXT
, 0);
18382 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
18383 if (updated_area
== TEXT_AREA
18384 && updated_window
->phys_cursor_on_p
18385 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
18386 && updated_window
->phys_cursor
.hpos
>= hpos
18387 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
18388 updated_window
->phys_cursor_on_p
= 0;
18392 /* Advance the output cursor. */
18393 output_cursor
.hpos
+= len
;
18394 output_cursor
.x
= x
;
18399 Insert LEN glyphs from START at the nominal cursor position. */
18402 x_insert_glyphs (start
, len
)
18403 struct glyph
*start
;
18408 int line_height
, shift_by_width
, shifted_region_width
;
18409 struct glyph_row
*row
;
18410 struct glyph
*glyph
;
18411 int frame_x
, frame_y
, hpos
;
18413 xassert (updated_window
&& updated_row
);
18415 w
= updated_window
;
18416 f
= XFRAME (WINDOW_FRAME (w
));
18418 /* Get the height of the line we are in. */
18420 line_height
= row
->height
;
18422 /* Get the width of the glyphs to insert. */
18423 shift_by_width
= 0;
18424 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
18425 shift_by_width
+= glyph
->pixel_width
;
18427 /* Get the width of the region to shift right. */
18428 shifted_region_width
= (window_box_width (w
, updated_area
)
18433 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
18434 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
18436 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
18437 line_height
, shift_by_width
);
18439 /* Write the glyphs. */
18440 hpos
= start
- row
->glyphs
[updated_area
];
18441 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
18443 DRAW_NORMAL_TEXT
, 0);
18445 /* Advance the output cursor. */
18446 output_cursor
.hpos
+= len
;
18447 output_cursor
.x
+= shift_by_width
;
18453 Erase the current text line from the nominal cursor position
18454 (inclusive) to pixel column TO_X (exclusive). The idea is that
18455 everything from TO_X onward is already erased.
18457 TO_X is a pixel position relative to updated_area of
18458 updated_window. TO_X == -1 means clear to the end of this area. */
18461 x_clear_end_of_line (to_x
)
18465 struct window
*w
= updated_window
;
18466 int max_x
, min_y
, max_y
;
18467 int from_x
, from_y
, to_y
;
18469 xassert (updated_window
&& updated_row
);
18470 f
= XFRAME (w
->frame
);
18472 if (updated_row
->full_width_p
)
18473 max_x
= WINDOW_TOTAL_WIDTH (w
);
18475 max_x
= window_box_width (w
, updated_area
);
18476 max_y
= window_text_bottom_y (w
);
18478 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
18479 of window. For TO_X > 0, truncate to end of drawing area. */
18485 to_x
= min (to_x
, max_x
);
18487 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
18489 /* Notice if the cursor will be cleared by this operation. */
18490 if (!updated_row
->full_width_p
)
18491 notice_overwritten_cursor (w
, updated_area
,
18492 output_cursor
.x
, -1,
18494 MATRIX_ROW_BOTTOM_Y (updated_row
));
18496 from_x
= output_cursor
.x
;
18498 /* Translate to frame coordinates. */
18499 if (updated_row
->full_width_p
)
18501 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
18502 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
18506 int area_left
= window_box_left (w
, updated_area
);
18507 from_x
+= area_left
;
18511 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
18512 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
18513 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
18515 /* Prevent inadvertently clearing to end of the X window. */
18516 if (to_x
> from_x
&& to_y
> from_y
)
18519 rif
->clear_frame_area (f
, from_x
, from_y
,
18520 to_x
- from_x
, to_y
- from_y
);
18525 #endif /* HAVE_WINDOW_SYSTEM */
18529 /***********************************************************************
18531 ***********************************************************************/
18533 /* Value is the internal representation of the specified cursor type
18534 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
18535 of the bar cursor. */
18537 enum text_cursor_kinds
18538 get_specified_cursor_type (arg
, width
)
18542 enum text_cursor_kinds type
;
18547 if (EQ (arg
, Qbox
))
18548 return FILLED_BOX_CURSOR
;
18550 if (EQ (arg
, Qhollow
))
18551 return HOLLOW_BOX_CURSOR
;
18553 if (EQ (arg
, Qbar
))
18560 && EQ (XCAR (arg
), Qbar
)
18561 && INTEGERP (XCDR (arg
))
18562 && XINT (XCDR (arg
)) >= 0)
18564 *width
= XINT (XCDR (arg
));
18568 if (EQ (arg
, Qhbar
))
18571 return HBAR_CURSOR
;
18575 && EQ (XCAR (arg
), Qhbar
)
18576 && INTEGERP (XCDR (arg
))
18577 && XINT (XCDR (arg
)) >= 0)
18579 *width
= XINT (XCDR (arg
));
18580 return HBAR_CURSOR
;
18583 /* Treat anything unknown as "hollow box cursor".
18584 It was bad to signal an error; people have trouble fixing
18585 .Xdefaults with Emacs, when it has something bad in it. */
18586 type
= HOLLOW_BOX_CURSOR
;
18591 /* Set the default cursor types for specified frame. */
18593 set_frame_cursor_types (f
, arg
)
18600 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
18601 FRAME_CURSOR_WIDTH (f
) = width
;
18603 /* By default, set up the blink-off state depending on the on-state. */
18605 tem
= Fassoc (arg
, Vblink_cursor_alist
);
18608 FRAME_BLINK_OFF_CURSOR (f
)
18609 = get_specified_cursor_type (XCDR (tem
), &width
);
18610 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
18613 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
18617 /* Return the cursor we want to be displayed in window W. Return
18618 width of bar/hbar cursor through WIDTH arg. Return with
18619 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
18620 (i.e. if the `system caret' should track this cursor).
18622 In a mini-buffer window, we want the cursor only to appear if we
18623 are reading input from this window. For the selected window, we
18624 want the cursor type given by the frame parameter or buffer local
18625 setting of cursor-type. If explicitly marked off, draw no cursor.
18626 In all other cases, we want a hollow box cursor. */
18628 enum text_cursor_kinds
18629 get_window_cursor_type (w
, width
, active_cursor
)
18632 int *active_cursor
;
18634 struct frame
*f
= XFRAME (w
->frame
);
18635 struct buffer
*b
= XBUFFER (w
->buffer
);
18636 int cursor_type
= DEFAULT_CURSOR
;
18637 Lisp_Object alt_cursor
;
18638 int non_selected
= 0;
18640 *active_cursor
= 1;
18643 if (cursor_in_echo_area
18644 && FRAME_HAS_MINIBUF_P (f
)
18645 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
18647 if (w
== XWINDOW (echo_area_window
))
18649 *width
= FRAME_CURSOR_WIDTH (f
);
18650 return FRAME_DESIRED_CURSOR (f
);
18653 *active_cursor
= 0;
18657 /* Nonselected window or nonselected frame. */
18658 else if (w
!= XWINDOW (f
->selected_window
)
18659 #ifdef HAVE_WINDOW_SYSTEM
18660 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
18664 *active_cursor
= 0;
18666 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
18672 /* Never display a cursor in a window in which cursor-type is nil. */
18673 if (NILP (b
->cursor_type
))
18676 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
18679 alt_cursor
= Fbuffer_local_value (Qcursor_in_non_selected_windows
, w
->buffer
);
18680 return get_specified_cursor_type (alt_cursor
, width
);
18683 /* Get the normal cursor type for this window. */
18684 if (EQ (b
->cursor_type
, Qt
))
18686 cursor_type
= FRAME_DESIRED_CURSOR (f
);
18687 *width
= FRAME_CURSOR_WIDTH (f
);
18690 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
18692 /* Use normal cursor if not blinked off. */
18693 if (!w
->cursor_off_p
)
18694 return cursor_type
;
18696 /* Cursor is blinked off, so determine how to "toggle" it. */
18698 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
18699 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
18700 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
18702 /* Then see if frame has specified a specific blink off cursor type. */
18703 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
18705 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
18706 return FRAME_BLINK_OFF_CURSOR (f
);
18709 /* Finally perform built-in cursor blinking:
18710 filled box <-> hollow box
18711 wide [h]bar <-> narrow [h]bar
18712 narrow [h]bar <-> no cursor
18713 other type <-> no cursor */
18715 if (cursor_type
== FILLED_BOX_CURSOR
)
18716 return HOLLOW_BOX_CURSOR
;
18718 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
18721 return cursor_type
;
18728 #ifdef HAVE_WINDOW_SYSTEM
18730 /* Notice when the text cursor of window W has been completely
18731 overwritten by a drawing operation that outputs glyphs in AREA
18732 starting at X0 and ending at X1 in the line starting at Y0 and
18733 ending at Y1. X coordinates are area-relative. X1 < 0 means all
18734 the rest of the line after X0 has been written. Y coordinates
18735 are window-relative. */
18738 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
18740 enum glyph_row_area area
;
18741 int x0
, y0
, x1
, y1
;
18743 if (area
== TEXT_AREA
&& w
->phys_cursor_on_p
)
18745 int cx0
= w
->phys_cursor
.x
;
18746 int cx1
= cx0
+ w
->phys_cursor_width
;
18747 int cy0
= w
->phys_cursor
.y
;
18748 int cy1
= cy0
+ w
->phys_cursor_height
;
18750 if (x0
<= cx0
&& (x1
< 0 || x1
>= cx1
))
18752 /* The cursor image will be completely removed from the
18753 screen if the output area intersects the cursor area in
18754 y-direction. When we draw in [y0 y1[, and some part of
18755 the cursor is at y < y0, that part must have been drawn
18756 before. When scrolling, the cursor is erased before
18757 actually scrolling, so we don't come here. When not
18758 scrolling, the rows above the old cursor row must have
18759 changed, and in this case these rows must have written
18760 over the cursor image.
18762 Likewise if part of the cursor is below y1, with the
18763 exception of the cursor being in the first blank row at
18764 the buffer and window end because update_text_area
18765 doesn't draw that row. (Except when it does, but
18766 that's handled in update_text_area.) */
18768 if (((y0
>= cy0
&& y0
< cy1
) || (y1
> cy0
&& y1
< cy1
))
18769 && w
->current_matrix
->rows
[w
->phys_cursor
.vpos
].displays_text_p
)
18770 w
->phys_cursor_on_p
= 0;
18775 #endif /* HAVE_WINDOW_SYSTEM */
18778 /************************************************************************
18780 ************************************************************************/
18782 #ifdef HAVE_WINDOW_SYSTEM
18785 Fix the display of area AREA of overlapping row ROW in window W. */
18788 x_fix_overlapping_area (w
, row
, area
)
18790 struct glyph_row
*row
;
18791 enum glyph_row_area area
;
18798 for (i
= 0; i
< row
->used
[area
];)
18800 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
18802 int start
= i
, start_x
= x
;
18806 x
+= row
->glyphs
[area
][i
].pixel_width
;
18809 while (i
< row
->used
[area
]
18810 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
18812 draw_glyphs (w
, start_x
, row
, area
,
18814 DRAW_NORMAL_TEXT
, 1);
18818 x
+= row
->glyphs
[area
][i
].pixel_width
;
18828 Draw the cursor glyph of window W in glyph row ROW. See the
18829 comment of draw_glyphs for the meaning of HL. */
18832 draw_phys_cursor_glyph (w
, row
, hl
)
18834 struct glyph_row
*row
;
18835 enum draw_glyphs_face hl
;
18837 /* If cursor hpos is out of bounds, don't draw garbage. This can
18838 happen in mini-buffer windows when switching between echo area
18839 glyphs and mini-buffer. */
18840 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
18842 int on_p
= w
->phys_cursor_on_p
;
18844 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
18845 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
18847 w
->phys_cursor_on_p
= on_p
;
18849 if (hl
== DRAW_CURSOR
)
18850 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
18851 /* When we erase the cursor, and ROW is overlapped by other
18852 rows, make sure that these overlapping parts of other rows
18854 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
18856 if (row
> w
->current_matrix
->rows
18857 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
18858 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
18860 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
18861 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
18862 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
18869 Erase the image of a cursor of window W from the screen. */
18872 erase_phys_cursor (w
)
18875 struct frame
*f
= XFRAME (w
->frame
);
18876 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
18877 int hpos
= w
->phys_cursor
.hpos
;
18878 int vpos
= w
->phys_cursor
.vpos
;
18879 int mouse_face_here_p
= 0;
18880 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
18881 struct glyph_row
*cursor_row
;
18882 struct glyph
*cursor_glyph
;
18883 enum draw_glyphs_face hl
;
18885 /* No cursor displayed or row invalidated => nothing to do on the
18887 if (w
->phys_cursor_type
== NO_CURSOR
)
18888 goto mark_cursor_off
;
18890 /* VPOS >= active_glyphs->nrows means that window has been resized.
18891 Don't bother to erase the cursor. */
18892 if (vpos
>= active_glyphs
->nrows
)
18893 goto mark_cursor_off
;
18895 /* If row containing cursor is marked invalid, there is nothing we
18897 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
18898 if (!cursor_row
->enabled_p
)
18899 goto mark_cursor_off
;
18901 /* If row is completely invisible, don't attempt to delete a cursor which
18902 isn't there. This can happen if cursor is at top of a window, and
18903 we switch to a buffer with a header line in that window. */
18904 if (cursor_row
->visible_height
<= 0)
18905 goto mark_cursor_off
;
18907 /* This can happen when the new row is shorter than the old one.
18908 In this case, either draw_glyphs or clear_end_of_line
18909 should have cleared the cursor. Note that we wouldn't be
18910 able to erase the cursor in this case because we don't have a
18911 cursor glyph at hand. */
18912 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
18913 goto mark_cursor_off
;
18915 /* If the cursor is in the mouse face area, redisplay that when
18916 we clear the cursor. */
18917 if (! NILP (dpyinfo
->mouse_face_window
)
18918 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
18919 && (vpos
> dpyinfo
->mouse_face_beg_row
18920 || (vpos
== dpyinfo
->mouse_face_beg_row
18921 && hpos
>= dpyinfo
->mouse_face_beg_col
))
18922 && (vpos
< dpyinfo
->mouse_face_end_row
18923 || (vpos
== dpyinfo
->mouse_face_end_row
18924 && hpos
< dpyinfo
->mouse_face_end_col
))
18925 /* Don't redraw the cursor's spot in mouse face if it is at the
18926 end of a line (on a newline). The cursor appears there, but
18927 mouse highlighting does not. */
18928 && cursor_row
->used
[TEXT_AREA
] > hpos
)
18929 mouse_face_here_p
= 1;
18931 /* Maybe clear the display under the cursor. */
18932 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
18935 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
18937 cursor_glyph
= get_phys_cursor_glyph (w
);
18938 if (cursor_glyph
== NULL
)
18939 goto mark_cursor_off
;
18941 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
18942 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
18944 rif
->clear_frame_area (f
, x
, y
,
18945 cursor_glyph
->pixel_width
, cursor_row
->visible_height
);
18948 /* Erase the cursor by redrawing the character underneath it. */
18949 if (mouse_face_here_p
)
18950 hl
= DRAW_MOUSE_FACE
;
18952 hl
= DRAW_NORMAL_TEXT
;
18953 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
18956 w
->phys_cursor_on_p
= 0;
18957 w
->phys_cursor_type
= NO_CURSOR
;
18962 Display or clear cursor of window W. If ON is zero, clear the
18963 cursor. If it is non-zero, display the cursor. If ON is nonzero,
18964 where to put the cursor is specified by HPOS, VPOS, X and Y. */
18967 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
18969 int on
, hpos
, vpos
, x
, y
;
18971 struct frame
*f
= XFRAME (w
->frame
);
18972 int new_cursor_type
;
18973 int new_cursor_width
;
18975 struct glyph_matrix
*current_glyphs
;
18976 struct glyph_row
*glyph_row
;
18977 struct glyph
*glyph
;
18979 /* This is pointless on invisible frames, and dangerous on garbaged
18980 windows and frames; in the latter case, the frame or window may
18981 be in the midst of changing its size, and x and y may be off the
18983 if (! FRAME_VISIBLE_P (f
)
18984 || FRAME_GARBAGED_P (f
)
18985 || vpos
>= w
->current_matrix
->nrows
18986 || hpos
>= w
->current_matrix
->matrix_w
)
18989 /* If cursor is off and we want it off, return quickly. */
18990 if (!on
&& !w
->phys_cursor_on_p
)
18993 current_glyphs
= w
->current_matrix
;
18994 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
18995 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
18997 /* If cursor row is not enabled, we don't really know where to
18998 display the cursor. */
18999 if (!glyph_row
->enabled_p
)
19001 w
->phys_cursor_on_p
= 0;
19005 xassert (interrupt_input_blocked
);
19007 /* Set new_cursor_type to the cursor we want to be displayed. */
19008 new_cursor_type
= get_window_cursor_type (w
, &new_cursor_width
, &active_cursor
);
19010 /* If cursor is currently being shown and we don't want it to be or
19011 it is in the wrong place, or the cursor type is not what we want,
19013 if (w
->phys_cursor_on_p
19015 || w
->phys_cursor
.x
!= x
19016 || w
->phys_cursor
.y
!= y
19017 || new_cursor_type
!= w
->phys_cursor_type
19018 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
19019 && new_cursor_width
!= w
->phys_cursor_width
)))
19020 erase_phys_cursor (w
);
19022 /* Don't check phys_cursor_on_p here because that flag is only set
19023 to zero in some cases where we know that the cursor has been
19024 completely erased, to avoid the extra work of erasing the cursor
19025 twice. In other words, phys_cursor_on_p can be 1 and the cursor
19026 still not be visible, or it has only been partly erased. */
19029 w
->phys_cursor_ascent
= glyph_row
->ascent
;
19030 w
->phys_cursor_height
= glyph_row
->height
;
19032 /* Set phys_cursor_.* before x_draw_.* is called because some
19033 of them may need the information. */
19034 w
->phys_cursor
.x
= x
;
19035 w
->phys_cursor
.y
= glyph_row
->y
;
19036 w
->phys_cursor
.hpos
= hpos
;
19037 w
->phys_cursor
.vpos
= vpos
;
19040 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
19041 new_cursor_type
, new_cursor_width
,
19042 on
, active_cursor
);
19046 /* Switch the display of W's cursor on or off, according to the value
19050 update_window_cursor (w
, on
)
19054 /* Don't update cursor in windows whose frame is in the process
19055 of being deleted. */
19056 if (w
->current_matrix
)
19059 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
19060 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
19066 /* Call update_window_cursor with parameter ON_P on all leaf windows
19067 in the window tree rooted at W. */
19070 update_cursor_in_window_tree (w
, on_p
)
19076 if (!NILP (w
->hchild
))
19077 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
19078 else if (!NILP (w
->vchild
))
19079 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
19081 update_window_cursor (w
, on_p
);
19083 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
19089 Display the cursor on window W, or clear it, according to ON_P.
19090 Don't change the cursor's position. */
19093 x_update_cursor (f
, on_p
)
19097 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
19102 Clear the cursor of window W to background color, and mark the
19103 cursor as not shown. This is used when the text where the cursor
19104 is is about to be rewritten. */
19110 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
19111 update_window_cursor (w
, 0);
19116 Display the active region described by mouse_face_* according to DRAW. */
19119 show_mouse_face (dpyinfo
, draw
)
19120 Display_Info
*dpyinfo
;
19121 enum draw_glyphs_face draw
;
19123 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
19124 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19126 if (/* If window is in the process of being destroyed, don't bother
19128 w
->current_matrix
!= NULL
19129 /* Don't update mouse highlight if hidden */
19130 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
19131 /* Recognize when we are called to operate on rows that don't exist
19132 anymore. This can happen when a window is split. */
19133 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
19135 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
19136 struct glyph_row
*row
, *first
, *last
;
19138 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
19139 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
19141 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
19143 int start_hpos
, end_hpos
, start_x
;
19145 /* For all but the first row, the highlight starts at column 0. */
19148 start_hpos
= dpyinfo
->mouse_face_beg_col
;
19149 start_x
= dpyinfo
->mouse_face_beg_x
;
19158 end_hpos
= dpyinfo
->mouse_face_end_col
;
19160 end_hpos
= row
->used
[TEXT_AREA
];
19162 if (end_hpos
> start_hpos
)
19164 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
19165 start_hpos
, end_hpos
,
19169 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
19173 /* When we've written over the cursor, arrange for it to
19174 be displayed again. */
19175 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
19178 display_and_set_cursor (w
, 1,
19179 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
19180 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
19185 /* Change the mouse cursor. */
19186 if (draw
== DRAW_NORMAL_TEXT
)
19187 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
19188 else if (draw
== DRAW_MOUSE_FACE
)
19189 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
19191 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
19195 Clear out the mouse-highlighted active region.
19196 Redraw it un-highlighted first. Value is non-zero if mouse
19197 face was actually drawn unhighlighted. */
19200 clear_mouse_face (dpyinfo
)
19201 Display_Info
*dpyinfo
;
19205 if (!NILP (dpyinfo
->mouse_face_window
))
19207 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
19211 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
19212 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
19213 dpyinfo
->mouse_face_window
= Qnil
;
19214 dpyinfo
->mouse_face_overlay
= Qnil
;
19220 Non-zero if physical cursor of window W is within mouse face. */
19223 cursor_in_mouse_face_p (w
)
19226 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
19227 int in_mouse_face
= 0;
19229 if (WINDOWP (dpyinfo
->mouse_face_window
)
19230 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
19232 int hpos
= w
->phys_cursor
.hpos
;
19233 int vpos
= w
->phys_cursor
.vpos
;
19235 if (vpos
>= dpyinfo
->mouse_face_beg_row
19236 && vpos
<= dpyinfo
->mouse_face_end_row
19237 && (vpos
> dpyinfo
->mouse_face_beg_row
19238 || hpos
>= dpyinfo
->mouse_face_beg_col
)
19239 && (vpos
< dpyinfo
->mouse_face_end_row
19240 || hpos
< dpyinfo
->mouse_face_end_col
19241 || dpyinfo
->mouse_face_past_end
))
19245 return in_mouse_face
;
19251 /* Find the glyph matrix position of buffer position CHARPOS in window
19252 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
19253 current glyphs must be up to date. If CHARPOS is above window
19254 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
19255 of last line in W. In the row containing CHARPOS, stop before glyphs
19256 having STOP as object. */
19258 #if 1 /* This is a version of fast_find_position that's more correct
19259 in the presence of hscrolling, for example. I didn't install
19260 it right away because the problem fixed is minor, it failed
19261 in 20.x as well, and I think it's too risky to install
19262 so near the release of 21.1. 2001-09-25 gerd. */
19265 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
19268 int *hpos
, *vpos
, *x
, *y
;
19271 struct glyph_row
*row
, *first
;
19272 struct glyph
*glyph
, *end
;
19275 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19276 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
19279 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
19281 *x
= *y
= *hpos
= *vpos
= 0;
19286 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
19293 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
19295 glyph
= row
->glyphs
[TEXT_AREA
];
19296 end
= glyph
+ row
->used
[TEXT_AREA
];
19298 /* Skip over glyphs not having an object at the start of the row.
19299 These are special glyphs like truncation marks on terminal
19301 if (row
->displays_text_p
)
19303 && INTEGERP (glyph
->object
)
19304 && !EQ (stop
, glyph
->object
)
19305 && glyph
->charpos
< 0)
19307 *x
+= glyph
->pixel_width
;
19312 && !INTEGERP (glyph
->object
)
19313 && !EQ (stop
, glyph
->object
)
19314 && (!BUFFERP (glyph
->object
)
19315 || glyph
->charpos
< charpos
))
19317 *x
+= glyph
->pixel_width
;
19321 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
19328 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
19331 int *hpos
, *vpos
, *x
, *y
;
19336 int maybe_next_line_p
= 0;
19337 int line_start_position
;
19338 int yb
= window_text_bottom_y (w
);
19339 struct glyph_row
*row
, *best_row
;
19340 int row_vpos
, best_row_vpos
;
19343 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19344 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
19346 while (row
->y
< yb
)
19348 if (row
->used
[TEXT_AREA
])
19349 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
19351 line_start_position
= 0;
19353 if (line_start_position
> pos
)
19355 /* If the position sought is the end of the buffer,
19356 don't include the blank lines at the bottom of the window. */
19357 else if (line_start_position
== pos
19358 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
19360 maybe_next_line_p
= 1;
19363 else if (line_start_position
> 0)
19366 best_row_vpos
= row_vpos
;
19369 if (row
->y
+ row
->height
>= yb
)
19376 /* Find the right column within BEST_ROW. */
19378 current_x
= best_row
->x
;
19379 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
19381 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
19382 int charpos
= glyph
->charpos
;
19384 if (BUFFERP (glyph
->object
))
19386 if (charpos
== pos
)
19389 *vpos
= best_row_vpos
;
19394 else if (charpos
> pos
)
19397 else if (EQ (glyph
->object
, stop
))
19402 current_x
+= glyph
->pixel_width
;
19405 /* If we're looking for the end of the buffer,
19406 and we didn't find it in the line we scanned,
19407 use the start of the following line. */
19408 if (maybe_next_line_p
)
19413 current_x
= best_row
->x
;
19416 *vpos
= best_row_vpos
;
19417 *hpos
= lastcol
+ 1;
19426 /* Find the position of the glyph for position POS in OBJECT in
19427 window W's current matrix, and return in *X, *Y the pixel
19428 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
19430 RIGHT_P non-zero means return the position of the right edge of the
19431 glyph, RIGHT_P zero means return the left edge position.
19433 If no glyph for POS exists in the matrix, return the position of
19434 the glyph with the next smaller position that is in the matrix, if
19435 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
19436 exists in the matrix, return the position of the glyph with the
19437 next larger position in OBJECT.
19439 Value is non-zero if a glyph was found. */
19442 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
19445 Lisp_Object object
;
19446 int *hpos
, *vpos
, *x
, *y
;
19449 int yb
= window_text_bottom_y (w
);
19450 struct glyph_row
*r
;
19451 struct glyph
*best_glyph
= NULL
;
19452 struct glyph_row
*best_row
= NULL
;
19455 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
19456 r
->enabled_p
&& r
->y
< yb
;
19459 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
19460 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
19463 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
19464 if (EQ (g
->object
, object
))
19466 if (g
->charpos
== pos
)
19473 else if (best_glyph
== NULL
19474 || ((abs (g
->charpos
- pos
)
19475 < abs (best_glyph
->charpos
- pos
))
19478 : g
->charpos
> pos
)))
19492 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
19496 *x
+= best_glyph
->pixel_width
;
19501 *vpos
= best_row
- w
->current_matrix
->rows
;
19504 return best_glyph
!= NULL
;
19508 /* Take proper action when mouse has moved to the mode or header line
19509 or marginal area AREA of window W, x-position X and y-position Y.
19510 X is relative to the start of the text display area of W, so the
19511 width of bitmap areas and scroll bars must be subtracted to get a
19512 position relative to the start of the mode line. */
19515 note_mode_line_or_margin_highlight (w
, x
, y
, area
)
19518 enum window_part area
;
19520 struct frame
*f
= XFRAME (w
->frame
);
19521 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
19522 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
19524 Lisp_Object string
, help
, map
, pos
;
19526 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
19527 string
= mode_line_string (w
, x
, y
, area
, &charpos
);
19529 string
= marginal_area_string (w
, x
, y
, area
, &charpos
);
19531 if (STRINGP (string
))
19533 pos
= make_number (charpos
);
19535 /* If we're on a string with `help-echo' text property, arrange
19536 for the help to be displayed. This is done by setting the
19537 global variable help_echo_string to the help string. */
19538 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
19541 help_echo_string
= help
;
19542 XSETWINDOW (help_echo_window
, w
);
19543 help_echo_object
= string
;
19544 help_echo_pos
= charpos
;
19547 /* Change the mouse pointer according to what is under X/Y. */
19548 map
= Fget_text_property (pos
, Qlocal_map
, string
);
19549 if (!KEYMAPP (map
))
19550 map
= Fget_text_property (pos
, Qkeymap
, string
);
19552 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
19555 rif
->define_frame_cursor (f
, cursor
);
19560 Take proper action when the mouse has moved to position X, Y on
19561 frame F as regards highlighting characters that have mouse-face
19562 properties. Also de-highlighting chars where the mouse was before.
19563 X and Y can be negative or out of range. */
19566 note_mouse_highlight (f
, x
, y
)
19570 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
19571 enum window_part part
;
19572 Lisp_Object window
;
19574 Cursor cursor
= No_Cursor
;
19577 /* When a menu is active, don't highlight because this looks odd. */
19578 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
19579 if (popup_activated ())
19583 if (NILP (Vmouse_highlight
)
19584 || !f
->glyphs_initialized_p
)
19587 dpyinfo
->mouse_face_mouse_x
= x
;
19588 dpyinfo
->mouse_face_mouse_y
= y
;
19589 dpyinfo
->mouse_face_mouse_frame
= f
;
19591 if (dpyinfo
->mouse_face_defer
)
19594 if (gc_in_progress
)
19596 dpyinfo
->mouse_face_deferred_gc
= 1;
19600 /* Which window is that in? */
19601 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
19603 /* If we were displaying active text in another window, clear that. */
19604 if (! EQ (window
, dpyinfo
->mouse_face_window
))
19605 clear_mouse_face (dpyinfo
);
19607 /* Not on a window -> return. */
19608 if (!WINDOWP (window
))
19611 /* Reset help_echo_string. It will get recomputed below. */
19612 /* ++KFS: X version didn't do this, but it looks harmless. */
19613 help_echo_string
= Qnil
;
19615 /* Convert to window-relative pixel coordinates. */
19616 w
= XWINDOW (window
);
19617 frame_to_window_pixel_xy (w
, &x
, &y
);
19619 /* Handle tool-bar window differently since it doesn't display a
19621 if (EQ (window
, f
->tool_bar_window
))
19623 note_tool_bar_highlight (f
, x
, y
);
19627 /* Mouse is on the mode, header line or margin? */
19628 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
19629 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
19631 note_mode_line_or_margin_highlight (w
, x
, y
, part
);
19635 if (part
== ON_VERTICAL_BORDER
)
19636 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
19638 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
19640 /* Are we in a window whose display is up to date?
19641 And verify the buffer's text has not changed. */
19642 b
= XBUFFER (w
->buffer
);
19643 if (part
== ON_TEXT
19644 && EQ (w
->window_end_valid
, w
->buffer
)
19645 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
19646 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
19648 int hpos
, vpos
, pos
, i
, area
;
19649 struct glyph
*glyph
;
19650 Lisp_Object object
;
19651 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
19652 Lisp_Object
*overlay_vec
= NULL
;
19653 int len
, noverlays
;
19654 struct buffer
*obuf
;
19655 int obegv
, ozv
, same_region
;
19657 /* Find the glyph under X/Y. */
19658 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
19660 /* Clear mouse face if X/Y not over text. */
19662 || area
!= TEXT_AREA
19663 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
19665 #if defined (HAVE_NTGUI)
19666 /* ++KFS: Why is this necessary on W32 ? */
19667 clear_mouse_face (dpyinfo
);
19668 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
19670 if (clear_mouse_face (dpyinfo
))
19671 cursor
= No_Cursor
;
19676 pos
= glyph
->charpos
;
19677 object
= glyph
->object
;
19678 if (!STRINGP (object
) && !BUFFERP (object
))
19681 /* If we get an out-of-range value, return now; avoid an error. */
19682 if (BUFFERP (object
) && pos
> BUF_Z (b
))
19685 /* Make the window's buffer temporarily current for
19686 overlays_at and compute_char_face. */
19687 obuf
= current_buffer
;
19688 current_buffer
= b
;
19694 /* Is this char mouse-active or does it have help-echo? */
19695 position
= make_number (pos
);
19697 if (BUFFERP (object
))
19699 /* Put all the overlays we want in a vector in overlay_vec.
19700 Store the length in len. If there are more than 10, make
19701 enough space for all, and try again. */
19703 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
19704 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
19705 if (noverlays
> len
)
19708 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
19709 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
19712 /* Sort overlays into increasing priority order. */
19713 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
19718 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
19719 && vpos
>= dpyinfo
->mouse_face_beg_row
19720 && vpos
<= dpyinfo
->mouse_face_end_row
19721 && (vpos
> dpyinfo
->mouse_face_beg_row
19722 || hpos
>= dpyinfo
->mouse_face_beg_col
)
19723 && (vpos
< dpyinfo
->mouse_face_end_row
19724 || hpos
< dpyinfo
->mouse_face_end_col
19725 || dpyinfo
->mouse_face_past_end
));
19728 cursor
= No_Cursor
;
19730 /* Check mouse-face highlighting. */
19732 /* If there exists an overlay with mouse-face overlapping
19733 the one we are currently highlighting, we have to
19734 check if we enter the overlapping overlay, and then
19735 highlight only that. */
19736 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
19737 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
19739 /* Find the highest priority overlay that has a mouse-face
19742 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
19744 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
19745 if (!NILP (mouse_face
))
19746 overlay
= overlay_vec
[i
];
19749 /* If we're actually highlighting the same overlay as
19750 before, there's no need to do that again. */
19751 if (!NILP (overlay
)
19752 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
19753 goto check_help_echo
;
19755 dpyinfo
->mouse_face_overlay
= overlay
;
19757 /* Clear the display of the old active region, if any. */
19758 if (clear_mouse_face (dpyinfo
))
19759 cursor
= No_Cursor
;
19761 /* If no overlay applies, get a text property. */
19762 if (NILP (overlay
))
19763 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
19765 /* Handle the overlay case. */
19766 if (!NILP (overlay
))
19768 /* Find the range of text around this char that
19769 should be active. */
19770 Lisp_Object before
, after
;
19773 before
= Foverlay_start (overlay
);
19774 after
= Foverlay_end (overlay
);
19775 /* Record this as the current active region. */
19776 fast_find_position (w
, XFASTINT (before
),
19777 &dpyinfo
->mouse_face_beg_col
,
19778 &dpyinfo
->mouse_face_beg_row
,
19779 &dpyinfo
->mouse_face_beg_x
,
19780 &dpyinfo
->mouse_face_beg_y
, Qnil
);
19782 dpyinfo
->mouse_face_past_end
19783 = !fast_find_position (w
, XFASTINT (after
),
19784 &dpyinfo
->mouse_face_end_col
,
19785 &dpyinfo
->mouse_face_end_row
,
19786 &dpyinfo
->mouse_face_end_x
,
19787 &dpyinfo
->mouse_face_end_y
, Qnil
);
19788 dpyinfo
->mouse_face_window
= window
;
19790 dpyinfo
->mouse_face_face_id
19791 = face_at_buffer_position (w
, pos
, 0, 0,
19793 !dpyinfo
->mouse_face_hidden
);
19795 /* Display it as active. */
19796 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
19797 cursor
= No_Cursor
;
19799 /* Handle the text property case. */
19800 else if (!NILP (mouse_face
) && BUFFERP (object
))
19802 /* Find the range of text around this char that
19803 should be active. */
19804 Lisp_Object before
, after
, beginning
, end
;
19807 beginning
= Fmarker_position (w
->start
);
19808 end
= make_number (BUF_Z (XBUFFER (object
))
19809 - XFASTINT (w
->window_end_pos
));
19811 = Fprevious_single_property_change (make_number (pos
+ 1),
19813 object
, beginning
);
19815 = Fnext_single_property_change (position
, Qmouse_face
,
19818 /* Record this as the current active region. */
19819 fast_find_position (w
, XFASTINT (before
),
19820 &dpyinfo
->mouse_face_beg_col
,
19821 &dpyinfo
->mouse_face_beg_row
,
19822 &dpyinfo
->mouse_face_beg_x
,
19823 &dpyinfo
->mouse_face_beg_y
, Qnil
);
19824 dpyinfo
->mouse_face_past_end
19825 = !fast_find_position (w
, XFASTINT (after
),
19826 &dpyinfo
->mouse_face_end_col
,
19827 &dpyinfo
->mouse_face_end_row
,
19828 &dpyinfo
->mouse_face_end_x
,
19829 &dpyinfo
->mouse_face_end_y
, Qnil
);
19830 dpyinfo
->mouse_face_window
= window
;
19832 if (BUFFERP (object
))
19833 dpyinfo
->mouse_face_face_id
19834 = face_at_buffer_position (w
, pos
, 0, 0,
19836 !dpyinfo
->mouse_face_hidden
);
19838 /* Display it as active. */
19839 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
19840 cursor
= No_Cursor
;
19842 else if (!NILP (mouse_face
) && STRINGP (object
))
19847 b
= Fprevious_single_property_change (make_number (pos
+ 1),
19850 e
= Fnext_single_property_change (position
, Qmouse_face
,
19853 b
= make_number (0);
19855 e
= make_number (SCHARS (object
) - 1);
19856 fast_find_string_pos (w
, XINT (b
), object
,
19857 &dpyinfo
->mouse_face_beg_col
,
19858 &dpyinfo
->mouse_face_beg_row
,
19859 &dpyinfo
->mouse_face_beg_x
,
19860 &dpyinfo
->mouse_face_beg_y
, 0);
19861 fast_find_string_pos (w
, XINT (e
), object
,
19862 &dpyinfo
->mouse_face_end_col
,
19863 &dpyinfo
->mouse_face_end_row
,
19864 &dpyinfo
->mouse_face_end_x
,
19865 &dpyinfo
->mouse_face_end_y
, 1);
19866 dpyinfo
->mouse_face_past_end
= 0;
19867 dpyinfo
->mouse_face_window
= window
;
19868 dpyinfo
->mouse_face_face_id
19869 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
19870 glyph
->face_id
, 1);
19871 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
19872 cursor
= No_Cursor
;
19874 else if (STRINGP (object
) && NILP (mouse_face
))
19876 /* A string which doesn't have mouse-face, but
19877 the text ``under'' it might have. */
19878 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
19879 int start
= MATRIX_ROW_START_CHARPOS (r
);
19881 pos
= string_buffer_position (w
, object
, start
);
19883 mouse_face
= get_char_property_and_overlay (make_number (pos
),
19887 if (!NILP (mouse_face
) && !NILP (overlay
))
19889 Lisp_Object before
= Foverlay_start (overlay
);
19890 Lisp_Object after
= Foverlay_end (overlay
);
19893 /* Note that we might not be able to find position
19894 BEFORE in the glyph matrix if the overlay is
19895 entirely covered by a `display' property. In
19896 this case, we overshoot. So let's stop in
19897 the glyph matrix before glyphs for OBJECT. */
19898 fast_find_position (w
, XFASTINT (before
),
19899 &dpyinfo
->mouse_face_beg_col
,
19900 &dpyinfo
->mouse_face_beg_row
,
19901 &dpyinfo
->mouse_face_beg_x
,
19902 &dpyinfo
->mouse_face_beg_y
,
19905 dpyinfo
->mouse_face_past_end
19906 = !fast_find_position (w
, XFASTINT (after
),
19907 &dpyinfo
->mouse_face_end_col
,
19908 &dpyinfo
->mouse_face_end_row
,
19909 &dpyinfo
->mouse_face_end_x
,
19910 &dpyinfo
->mouse_face_end_y
,
19912 dpyinfo
->mouse_face_window
= window
;
19913 dpyinfo
->mouse_face_face_id
19914 = face_at_buffer_position (w
, pos
, 0, 0,
19916 !dpyinfo
->mouse_face_hidden
);
19918 /* Display it as active. */
19919 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
19920 cursor
= No_Cursor
;
19927 /* Look for a `help-echo' property. */
19929 Lisp_Object help
, overlay
;
19931 /* Check overlays first. */
19932 help
= overlay
= Qnil
;
19933 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
19935 overlay
= overlay_vec
[i
];
19936 help
= Foverlay_get (overlay
, Qhelp_echo
);
19941 help_echo_string
= help
;
19942 help_echo_window
= window
;
19943 help_echo_object
= overlay
;
19944 help_echo_pos
= pos
;
19948 Lisp_Object object
= glyph
->object
;
19949 int charpos
= glyph
->charpos
;
19951 /* Try text properties. */
19952 if (STRINGP (object
)
19954 && charpos
< SCHARS (object
))
19956 help
= Fget_text_property (make_number (charpos
),
19957 Qhelp_echo
, object
);
19960 /* If the string itself doesn't specify a help-echo,
19961 see if the buffer text ``under'' it does. */
19962 struct glyph_row
*r
19963 = MATRIX_ROW (w
->current_matrix
, vpos
);
19964 int start
= MATRIX_ROW_START_CHARPOS (r
);
19965 int pos
= string_buffer_position (w
, object
, start
);
19968 help
= Fget_char_property (make_number (pos
),
19969 Qhelp_echo
, w
->buffer
);
19973 object
= w
->buffer
;
19978 else if (BUFFERP (object
)
19981 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
19986 help_echo_string
= help
;
19987 help_echo_window
= window
;
19988 help_echo_object
= object
;
19989 help_echo_pos
= charpos
;
19996 current_buffer
= obuf
;
20001 #ifndef HAVE_CARBON
20002 if (cursor
!= No_Cursor
)
20004 if (bcmp (&cursor
, &No_Cursor
, sizeof (Cursor
)))
20006 rif
->define_frame_cursor (f
, cursor
);
20011 Clear any mouse-face on window W. This function is part of the
20012 redisplay interface, and is called from try_window_id and similar
20013 functions to ensure the mouse-highlight is off. */
20016 x_clear_window_mouse_face (w
)
20019 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20020 Lisp_Object window
;
20023 XSETWINDOW (window
, w
);
20024 if (EQ (window
, dpyinfo
->mouse_face_window
))
20025 clear_mouse_face (dpyinfo
);
20031 Just discard the mouse face information for frame F, if any.
20032 This is used when the size of F is changed. */
20035 cancel_mouse_face (f
)
20038 Lisp_Object window
;
20039 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20041 window
= dpyinfo
->mouse_face_window
;
20042 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
20044 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20045 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20046 dpyinfo
->mouse_face_window
= Qnil
;
20051 #endif /* HAVE_WINDOW_SYSTEM */
20054 /***********************************************************************
20056 ***********************************************************************/
20058 #ifdef HAVE_WINDOW_SYSTEM
20060 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
20061 which intersects rectangle R. R is in window-relative coordinates. */
20064 expose_area (w
, row
, r
, area
)
20066 struct glyph_row
*row
;
20068 enum glyph_row_area area
;
20070 struct glyph
*first
= row
->glyphs
[area
];
20071 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
20072 struct glyph
*last
;
20073 int first_x
, start_x
, x
;
20075 if (area
== TEXT_AREA
&& row
->fill_line_p
)
20076 /* If row extends face to end of line write the whole line. */
20077 draw_glyphs (w
, 0, row
, area
,
20078 0, row
->used
[area
],
20079 DRAW_NORMAL_TEXT
, 0);
20082 /* Set START_X to the window-relative start position for drawing glyphs of
20083 AREA. The first glyph of the text area can be partially visible.
20084 The first glyphs of other areas cannot. */
20085 start_x
= window_box_left_offset (w
, area
);
20086 if (area
== TEXT_AREA
)
20090 /* Find the first glyph that must be redrawn. */
20092 && x
+ first
->pixel_width
< r
->x
)
20094 x
+= first
->pixel_width
;
20098 /* Find the last one. */
20102 && x
< r
->x
+ r
->width
)
20104 x
+= last
->pixel_width
;
20110 draw_glyphs (w
, first_x
- start_x
, row
, area
,
20111 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
20112 DRAW_NORMAL_TEXT
, 0);
20117 /* Redraw the parts of the glyph row ROW on window W intersecting
20118 rectangle R. R is in window-relative coordinates. Value is
20119 non-zero if mouse-face was overwritten. */
20122 expose_line (w
, row
, r
)
20124 struct glyph_row
*row
;
20127 xassert (row
->enabled_p
);
20129 if (row
->mode_line_p
|| w
->pseudo_window_p
)
20130 draw_glyphs (w
, 0, row
, TEXT_AREA
,
20131 0, row
->used
[TEXT_AREA
],
20132 DRAW_NORMAL_TEXT
, 0);
20135 if (row
->used
[LEFT_MARGIN_AREA
])
20136 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
20137 if (row
->used
[TEXT_AREA
])
20138 expose_area (w
, row
, r
, TEXT_AREA
);
20139 if (row
->used
[RIGHT_MARGIN_AREA
])
20140 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
20141 draw_row_fringe_bitmaps (w
, row
);
20144 return row
->mouse_face_p
;
20148 /* Redraw those parts of glyphs rows during expose event handling that
20149 overlap other rows. Redrawing of an exposed line writes over parts
20150 of lines overlapping that exposed line; this function fixes that.
20152 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
20153 row in W's current matrix that is exposed and overlaps other rows.
20154 LAST_OVERLAPPING_ROW is the last such row. */
20157 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
20159 struct glyph_row
*first_overlapping_row
;
20160 struct glyph_row
*last_overlapping_row
;
20162 struct glyph_row
*row
;
20164 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
20165 if (row
->overlapping_p
)
20167 xassert (row
->enabled_p
&& !row
->mode_line_p
);
20169 if (row
->used
[LEFT_MARGIN_AREA
])
20170 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
20172 if (row
->used
[TEXT_AREA
])
20173 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
20175 if (row
->used
[RIGHT_MARGIN_AREA
])
20176 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
20181 /* Return non-zero if W's cursor intersects rectangle R. */
20184 phys_cursor_in_rect_p (w
, r
)
20188 XRectangle cr
, result
;
20189 struct glyph
*cursor_glyph
;
20191 cursor_glyph
= get_phys_cursor_glyph (w
);
20194 /* r is relative to W's box, but w->phys_cursor.x is relative
20195 to left edge of W's TEXT area. Adjust it. */
20196 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
20197 cr
.y
= w
->phys_cursor
.y
;
20198 cr
.width
= cursor_glyph
->pixel_width
;
20199 cr
.height
= w
->phys_cursor_height
;
20200 /* ++KFS: W32 version used W32-specific IntersectRect here, but
20201 I assume the effect is the same -- and this is portable. */
20202 return x_intersect_rectangles (&cr
, r
, &result
);
20210 Draw a vertical window border to the right of window W if W doesn't
20211 have vertical scroll bars. */
20214 x_draw_vertical_border (w
)
20217 /* We could do better, if we knew what type of scroll-bar the adjacent
20218 windows (on either side) have... But we don't :-(
20219 However, I think this works ok. ++KFS 2003-04-25 */
20221 /* Redraw borders between horizontally adjacent windows. Don't
20222 do it for frames with vertical scroll bars because either the
20223 right scroll bar of a window, or the left scroll bar of its
20224 neighbor will suffice as a border. */
20225 if (!WINDOW_RIGHTMOST_P (w
)
20226 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
20228 int x0
, x1
, y0
, y1
;
20230 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
20233 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
20235 else if (!WINDOW_LEFTMOST_P (w
)
20236 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
20238 int x0
, x1
, y0
, y1
;
20240 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
20243 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
20248 /* Redraw the part of window W intersection rectangle FR. Pixel
20249 coordinates in FR are frame-relative. Call this function with
20250 input blocked. Value is non-zero if the exposure overwrites
20254 expose_window (w
, fr
)
20258 struct frame
*f
= XFRAME (w
->frame
);
20260 int mouse_face_overwritten_p
= 0;
20262 /* If window is not yet fully initialized, do nothing. This can
20263 happen when toolkit scroll bars are used and a window is split.
20264 Reconfiguring the scroll bar will generate an expose for a newly
20266 if (w
->current_matrix
== NULL
)
20269 /* When we're currently updating the window, display and current
20270 matrix usually don't agree. Arrange for a thorough display
20272 if (w
== updated_window
)
20274 SET_FRAME_GARBAGED (f
);
20278 /* Frame-relative pixel rectangle of W. */
20279 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
20280 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
20281 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
20282 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
20284 if (x_intersect_rectangles (fr
, &wr
, &r
))
20286 int yb
= window_text_bottom_y (w
);
20287 struct glyph_row
*row
;
20288 int cursor_cleared_p
;
20289 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
20291 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
20292 r
.x
, r
.y
, r
.width
, r
.height
));
20294 /* Convert to window coordinates. */
20295 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
20296 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
20298 /* Turn off the cursor. */
20299 if (!w
->pseudo_window_p
20300 && phys_cursor_in_rect_p (w
, &r
))
20302 x_clear_cursor (w
);
20303 cursor_cleared_p
= 1;
20306 cursor_cleared_p
= 0;
20308 /* Update lines intersecting rectangle R. */
20309 first_overlapping_row
= last_overlapping_row
= NULL
;
20310 for (row
= w
->current_matrix
->rows
;
20315 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
20317 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
20318 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
20319 || (r
.y
>= y0
&& r
.y
< y1
)
20320 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
20322 if (row
->overlapping_p
)
20324 if (first_overlapping_row
== NULL
)
20325 first_overlapping_row
= row
;
20326 last_overlapping_row
= row
;
20329 if (expose_line (w
, row
, &r
))
20330 mouse_face_overwritten_p
= 1;
20337 /* Display the mode line if there is one. */
20338 if (WINDOW_WANTS_MODELINE_P (w
)
20339 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
20341 && row
->y
< r
.y
+ r
.height
)
20343 if (expose_line (w
, row
, &r
))
20344 mouse_face_overwritten_p
= 1;
20347 if (!w
->pseudo_window_p
)
20349 /* Fix the display of overlapping rows. */
20350 if (first_overlapping_row
)
20351 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
20353 /* Draw border between windows. */
20354 x_draw_vertical_border (w
);
20356 /* Turn the cursor on again. */
20357 if (cursor_cleared_p
)
20358 update_window_cursor (w
, 1);
20363 /* Display scroll bar for this window. */
20364 if (!NILP (w
->vertical_scroll_bar
))
20367 If this doesn't work here (maybe some header files are missing),
20368 make a function in macterm.c and call it to do the job! */
20370 = SCROLL_BAR_CONTROL_HANDLE (XSCROLL_BAR (w
->vertical_scroll_bar
));
20376 return mouse_face_overwritten_p
;
20381 /* Redraw (parts) of all windows in the window tree rooted at W that
20382 intersect R. R contains frame pixel coordinates. Value is
20383 non-zero if the exposure overwrites mouse-face. */
20386 expose_window_tree (w
, r
)
20390 struct frame
*f
= XFRAME (w
->frame
);
20391 int mouse_face_overwritten_p
= 0;
20393 while (w
&& !FRAME_GARBAGED_P (f
))
20395 if (!NILP (w
->hchild
))
20396 mouse_face_overwritten_p
20397 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
20398 else if (!NILP (w
->vchild
))
20399 mouse_face_overwritten_p
20400 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
20402 mouse_face_overwritten_p
|= expose_window (w
, r
);
20404 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
20407 return mouse_face_overwritten_p
;
20412 Redisplay an exposed area of frame F. X and Y are the upper-left
20413 corner of the exposed rectangle. W and H are width and height of
20414 the exposed area. All are pixel values. W or H zero means redraw
20415 the entire frame. */
20418 expose_frame (f
, x
, y
, w
, h
)
20423 int mouse_face_overwritten_p
= 0;
20425 TRACE ((stderr
, "expose_frame "));
20427 /* No need to redraw if frame will be redrawn soon. */
20428 if (FRAME_GARBAGED_P (f
))
20430 TRACE ((stderr
, " garbaged\n"));
20435 /* MAC_TODO: this is a kludge, but if scroll bars are not activated
20436 or deactivated here, for unknown reasons, activated scroll bars
20437 are shown in deactivated frames in some instances. */
20438 if (f
== FRAME_MAC_DISPLAY_INFO (f
)->x_focus_frame
)
20439 activate_scroll_bars (f
);
20441 deactivate_scroll_bars (f
);
20444 /* If basic faces haven't been realized yet, there is no point in
20445 trying to redraw anything. This can happen when we get an expose
20446 event while Emacs is starting, e.g. by moving another window. */
20447 if (FRAME_FACE_CACHE (f
) == NULL
20448 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
20450 TRACE ((stderr
, " no faces\n"));
20454 if (w
== 0 || h
== 0)
20457 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
20458 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
20468 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
20469 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
20471 if (WINDOWP (f
->tool_bar_window
))
20472 mouse_face_overwritten_p
20473 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
20475 #ifdef HAVE_X_WINDOWS
20477 #ifndef USE_X_TOOLKIT
20478 if (WINDOWP (f
->menu_bar_window
))
20479 mouse_face_overwritten_p
20480 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
20481 #endif /* not USE_X_TOOLKIT */
20485 /* Some window managers support a focus-follows-mouse style with
20486 delayed raising of frames. Imagine a partially obscured frame,
20487 and moving the mouse into partially obscured mouse-face on that
20488 frame. The visible part of the mouse-face will be highlighted,
20489 then the WM raises the obscured frame. With at least one WM, KDE
20490 2.1, Emacs is not getting any event for the raising of the frame
20491 (even tried with SubstructureRedirectMask), only Expose events.
20492 These expose events will draw text normally, i.e. not
20493 highlighted. Which means we must redo the highlight here.
20494 Subsume it under ``we love X''. --gerd 2001-08-15 */
20495 /* Included in Windows version because Windows most likely does not
20496 do the right thing if any third party tool offers
20497 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
20498 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
20500 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20501 if (f
== dpyinfo
->mouse_face_mouse_frame
)
20503 int x
= dpyinfo
->mouse_face_mouse_x
;
20504 int y
= dpyinfo
->mouse_face_mouse_y
;
20505 clear_mouse_face (dpyinfo
);
20506 note_mouse_highlight (f
, x
, y
);
20513 Determine the intersection of two rectangles R1 and R2. Return
20514 the intersection in *RESULT. Value is non-zero if RESULT is not
20518 x_intersect_rectangles (r1
, r2
, result
)
20519 XRectangle
*r1
, *r2
, *result
;
20521 XRectangle
*left
, *right
;
20522 XRectangle
*upper
, *lower
;
20523 int intersection_p
= 0;
20525 /* Rearrange so that R1 is the left-most rectangle. */
20527 left
= r1
, right
= r2
;
20529 left
= r2
, right
= r1
;
20531 /* X0 of the intersection is right.x0, if this is inside R1,
20532 otherwise there is no intersection. */
20533 if (right
->x
<= left
->x
+ left
->width
)
20535 result
->x
= right
->x
;
20537 /* The right end of the intersection is the minimum of the
20538 the right ends of left and right. */
20539 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
20542 /* Same game for Y. */
20544 upper
= r1
, lower
= r2
;
20546 upper
= r2
, lower
= r1
;
20548 /* The upper end of the intersection is lower.y0, if this is inside
20549 of upper. Otherwise, there is no intersection. */
20550 if (lower
->y
<= upper
->y
+ upper
->height
)
20552 result
->y
= lower
->y
;
20554 /* The lower end of the intersection is the minimum of the lower
20555 ends of upper and lower. */
20556 result
->height
= (min (lower
->y
+ lower
->height
,
20557 upper
->y
+ upper
->height
)
20559 intersection_p
= 1;
20563 return intersection_p
;
20566 #endif /* HAVE_WINDOW_SYSTEM */
20569 /***********************************************************************
20571 ***********************************************************************/
20576 Vwith_echo_area_save_vector
= Qnil
;
20577 staticpro (&Vwith_echo_area_save_vector
);
20579 Vmessage_stack
= Qnil
;
20580 staticpro (&Vmessage_stack
);
20582 Qinhibit_redisplay
= intern ("inhibit-redisplay");
20583 staticpro (&Qinhibit_redisplay
);
20585 message_dolog_marker1
= Fmake_marker ();
20586 staticpro (&message_dolog_marker1
);
20587 message_dolog_marker2
= Fmake_marker ();
20588 staticpro (&message_dolog_marker2
);
20589 message_dolog_marker3
= Fmake_marker ();
20590 staticpro (&message_dolog_marker3
);
20593 defsubr (&Sdump_frame_glyph_matrix
);
20594 defsubr (&Sdump_glyph_matrix
);
20595 defsubr (&Sdump_glyph_row
);
20596 defsubr (&Sdump_tool_bar_row
);
20597 defsubr (&Strace_redisplay
);
20598 defsubr (&Strace_to_stderr
);
20600 #ifdef HAVE_WINDOW_SYSTEM
20601 defsubr (&Stool_bar_lines_needed
);
20603 defsubr (&Sformat_mode_line
);
20605 staticpro (&Qmenu_bar_update_hook
);
20606 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
20608 staticpro (&Qoverriding_terminal_local_map
);
20609 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
20611 staticpro (&Qoverriding_local_map
);
20612 Qoverriding_local_map
= intern ("overriding-local-map");
20614 staticpro (&Qwindow_scroll_functions
);
20615 Qwindow_scroll_functions
= intern ("window-scroll-functions");
20617 staticpro (&Qredisplay_end_trigger_functions
);
20618 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
20620 staticpro (&Qinhibit_point_motion_hooks
);
20621 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
20623 QCdata
= intern (":data");
20624 staticpro (&QCdata
);
20625 Qdisplay
= intern ("display");
20626 staticpro (&Qdisplay
);
20627 Qspace_width
= intern ("space-width");
20628 staticpro (&Qspace_width
);
20629 Qraise
= intern ("raise");
20630 staticpro (&Qraise
);
20631 Qspace
= intern ("space");
20632 staticpro (&Qspace
);
20633 Qmargin
= intern ("margin");
20634 staticpro (&Qmargin
);
20635 Qleft_margin
= intern ("left-margin");
20636 staticpro (&Qleft_margin
);
20637 Qright_margin
= intern ("right-margin");
20638 staticpro (&Qright_margin
);
20639 Qalign_to
= intern ("align-to");
20640 staticpro (&Qalign_to
);
20641 QCalign_to
= intern (":align-to");
20642 staticpro (&QCalign_to
);
20643 Qrelative_width
= intern ("relative-width");
20644 staticpro (&Qrelative_width
);
20645 QCrelative_width
= intern (":relative-width");
20646 staticpro (&QCrelative_width
);
20647 QCrelative_height
= intern (":relative-height");
20648 staticpro (&QCrelative_height
);
20649 QCeval
= intern (":eval");
20650 staticpro (&QCeval
);
20651 QCpropertize
= intern (":propertize");
20652 staticpro (&QCpropertize
);
20653 QCfile
= intern (":file");
20654 staticpro (&QCfile
);
20655 Qfontified
= intern ("fontified");
20656 staticpro (&Qfontified
);
20657 Qfontification_functions
= intern ("fontification-functions");
20658 staticpro (&Qfontification_functions
);
20659 Qtrailing_whitespace
= intern ("trailing-whitespace");
20660 staticpro (&Qtrailing_whitespace
);
20661 Qimage
= intern ("image");
20662 staticpro (&Qimage
);
20663 Qmessage_truncate_lines
= intern ("message-truncate-lines");
20664 staticpro (&Qmessage_truncate_lines
);
20665 Qcursor_in_non_selected_windows
= intern ("cursor-in-non-selected-windows");
20666 staticpro (&Qcursor_in_non_selected_windows
);
20667 Qgrow_only
= intern ("grow-only");
20668 staticpro (&Qgrow_only
);
20669 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
20670 staticpro (&Qinhibit_menubar_update
);
20671 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
20672 staticpro (&Qinhibit_eval_during_redisplay
);
20673 Qposition
= intern ("position");
20674 staticpro (&Qposition
);
20675 Qbuffer_position
= intern ("buffer-position");
20676 staticpro (&Qbuffer_position
);
20677 Qobject
= intern ("object");
20678 staticpro (&Qobject
);
20679 Qbar
= intern ("bar");
20681 Qhbar
= intern ("hbar");
20682 staticpro (&Qhbar
);
20683 Qbox
= intern ("box");
20685 Qhollow
= intern ("hollow");
20686 staticpro (&Qhollow
);
20687 Qrisky_local_variable
= intern ("risky-local-variable");
20688 staticpro (&Qrisky_local_variable
);
20689 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
20690 staticpro (&Qinhibit_free_realized_faces
);
20692 list_of_error
= Fcons (intern ("error"), Qnil
);
20693 staticpro (&list_of_error
);
20695 last_arrow_position
= Qnil
;
20696 last_arrow_string
= Qnil
;
20697 staticpro (&last_arrow_position
);
20698 staticpro (&last_arrow_string
);
20700 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
20701 staticpro (&echo_buffer
[0]);
20702 staticpro (&echo_buffer
[1]);
20704 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
20705 staticpro (&echo_area_buffer
[0]);
20706 staticpro (&echo_area_buffer
[1]);
20708 Vmessages_buffer_name
= build_string ("*Messages*");
20709 staticpro (&Vmessages_buffer_name
);
20711 mode_line_proptrans_alist
= Qnil
;
20712 staticpro (&mode_line_proptrans_alist
);
20714 mode_line_string_list
= Qnil
;
20715 staticpro (&mode_line_string_list
);
20717 help_echo_string
= Qnil
;
20718 staticpro (&help_echo_string
);
20719 help_echo_object
= Qnil
;
20720 staticpro (&help_echo_object
);
20721 help_echo_window
= Qnil
;
20722 staticpro (&help_echo_window
);
20723 previous_help_echo_string
= Qnil
;
20724 staticpro (&previous_help_echo_string
);
20725 help_echo_pos
= -1;
20727 #ifdef HAVE_WINDOW_SYSTEM
20728 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
20729 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
20730 For example, if a block cursor is over a tab, it will be drawn as
20731 wide as that tab on the display. */);
20732 x_stretch_cursor_p
= 0;
20735 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
20736 doc
: /* Non-nil means highlight trailing whitespace.
20737 The face used for trailing whitespace is `trailing-whitespace'. */);
20738 Vshow_trailing_whitespace
= Qnil
;
20740 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
20741 doc
: /* Non-nil means don't actually do any redisplay.
20742 This is used for internal purposes. */);
20743 Vinhibit_redisplay
= Qnil
;
20745 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
20746 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
20747 Vglobal_mode_string
= Qnil
;
20749 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
20750 doc
: /* Marker for where to display an arrow on top of the buffer text.
20751 This must be the beginning of a line in order to work.
20752 See also `overlay-arrow-string'. */);
20753 Voverlay_arrow_position
= Qnil
;
20755 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
20756 doc
: /* String to display as an arrow. See also `overlay-arrow-position'. */);
20757 Voverlay_arrow_string
= Qnil
;
20759 DEFVAR_INT ("scroll-step", &scroll_step
,
20760 doc
: /* *The number of lines to try scrolling a window by when point moves out.
20761 If that fails to bring point back on frame, point is centered instead.
20762 If this is zero, point is always centered after it moves off frame.
20763 If you want scrolling to always be a line at a time, you should set
20764 `scroll-conservatively' to a large value rather than set this to 1. */);
20766 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
20767 doc
: /* *Scroll up to this many lines, to bring point back on screen.
20768 A value of zero means to scroll the text to center point vertically
20769 in the window. */);
20770 scroll_conservatively
= 0;
20772 DEFVAR_INT ("scroll-margin", &scroll_margin
,
20773 doc
: /* *Number of lines of margin at the top and bottom of a window.
20774 Recenter the window whenever point gets within this many lines
20775 of the top or bottom of the window. */);
20779 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
20782 DEFVAR_BOOL ("truncate-partial-width-windows",
20783 &truncate_partial_width_windows
,
20784 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
20785 truncate_partial_width_windows
= 1;
20787 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
20788 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
20789 Any other value means to use the appropriate face, `mode-line',
20790 `header-line', or `menu' respectively. */);
20791 mode_line_inverse_video
= 1;
20793 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
20794 doc
: /* *Maximum buffer size for which line number should be displayed.
20795 If the buffer is bigger than this, the line number does not appear
20796 in the mode line. A value of nil means no limit. */);
20797 Vline_number_display_limit
= Qnil
;
20799 DEFVAR_INT ("line-number-display-limit-width",
20800 &line_number_display_limit_width
,
20801 doc
: /* *Maximum line width (in characters) for line number display.
20802 If the average length of the lines near point is bigger than this, then the
20803 line number may be omitted from the mode line. */);
20804 line_number_display_limit_width
= 200;
20806 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
20807 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
20808 highlight_nonselected_windows
= 0;
20810 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
20811 doc
: /* Non-nil if more than one frame is visible on this display.
20812 Minibuffer-only frames don't count, but iconified frames do.
20813 This variable is not guaranteed to be accurate except while processing
20814 `frame-title-format' and `icon-title-format'. */);
20816 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
20817 doc
: /* Template for displaying the title bar of visible frames.
20818 \(Assuming the window manager supports this feature.)
20819 This variable has the same structure as `mode-line-format' (which see),
20820 and is used only on frames for which no explicit name has been set
20821 \(see `modify-frame-parameters'). */);
20822 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
20823 doc
: /* Template for displaying the title bar of an iconified frame.
20824 \(Assuming the window manager supports this feature.)
20825 This variable has the same structure as `mode-line-format' (which see),
20826 and is used only on frames for which no explicit name has been set
20827 \(see `modify-frame-parameters'). */);
20829 = Vframe_title_format
20830 = Fcons (intern ("multiple-frames"),
20831 Fcons (build_string ("%b"),
20832 Fcons (Fcons (empty_string
,
20833 Fcons (intern ("invocation-name"),
20834 Fcons (build_string ("@"),
20835 Fcons (intern ("system-name"),
20839 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
20840 doc
: /* Maximum number of lines to keep in the message log buffer.
20841 If nil, disable message logging. If t, log messages but don't truncate
20842 the buffer when it becomes large. */);
20843 Vmessage_log_max
= make_number (50);
20845 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
20846 doc
: /* Functions called before redisplay, if window sizes have changed.
20847 The value should be a list of functions that take one argument.
20848 Just before redisplay, for each frame, if any of its windows have changed
20849 size since the last redisplay, or have been split or deleted,
20850 all the functions in the list are called, with the frame as argument. */);
20851 Vwindow_size_change_functions
= Qnil
;
20853 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
20854 doc
: /* List of Functions to call before redisplaying a window with scrolling.
20855 Each function is called with two arguments, the window
20856 and its new display-start position. Note that the value of `window-end'
20857 is not valid when these functions are called. */);
20858 Vwindow_scroll_functions
= Qnil
;
20860 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
20861 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
20862 mouse_autoselect_window
= 0;
20864 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
20865 doc
: /* *Non-nil means automatically resize tool-bars.
20866 This increases a tool-bar's height if not all tool-bar items are visible.
20867 It decreases a tool-bar's height when it would display blank lines
20869 auto_resize_tool_bars_p
= 1;
20871 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
20872 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
20873 auto_raise_tool_bar_buttons_p
= 1;
20875 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
20876 doc
: /* *Margin around tool-bar buttons in pixels.
20877 If an integer, use that for both horizontal and vertical margins.
20878 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
20879 HORZ specifying the horizontal margin, and VERT specifying the
20880 vertical margin. */);
20881 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
20883 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
20884 doc
: /* *Relief thickness of tool-bar buttons. */);
20885 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
20887 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
20888 doc
: /* List of functions to call to fontify regions of text.
20889 Each function is called with one argument POS. Functions must
20890 fontify a region starting at POS in the current buffer, and give
20891 fontified regions the property `fontified'. */);
20892 Vfontification_functions
= Qnil
;
20893 Fmake_variable_buffer_local (Qfontification_functions
);
20895 DEFVAR_BOOL ("unibyte-display-via-language-environment",
20896 &unibyte_display_via_language_environment
,
20897 doc
: /* *Non-nil means display unibyte text according to language environment.
20898 Specifically this means that unibyte non-ASCII characters
20899 are displayed by converting them to the equivalent multibyte characters
20900 according to the current language environment. As a result, they are
20901 displayed according to the current fontset. */);
20902 unibyte_display_via_language_environment
= 0;
20904 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
20905 doc
: /* *Maximum height for resizing mini-windows.
20906 If a float, it specifies a fraction of the mini-window frame's height.
20907 If an integer, it specifies a number of lines. */);
20908 Vmax_mini_window_height
= make_float (0.25);
20910 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
20911 doc
: /* *How to resize mini-windows.
20912 A value of nil means don't automatically resize mini-windows.
20913 A value of t means resize them to fit the text displayed in them.
20914 A value of `grow-only', the default, means let mini-windows grow
20915 only, until their display becomes empty, at which point the windows
20916 go back to their normal size. */);
20917 Vresize_mini_windows
= Qgrow_only
;
20919 DEFVAR_LISP ("cursor-in-non-selected-windows",
20920 &Vcursor_in_non_selected_windows
,
20921 doc
: /* *Cursor type to display in non-selected windows.
20922 t means to use hollow box cursor. See `cursor-type' for other values. */);
20923 Vcursor_in_non_selected_windows
= Qt
;
20925 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
20926 doc
: /* Alist specifying how to blink the cursor off.
20927 Each element has the form (ON-STATE . OFF-STATE). Whenever the
20928 `cursor-type' frame-parameter or variable equals ON-STATE,
20929 comparing using `equal', Emacs uses OFF-STATE to specify
20930 how to blink it off. */);
20931 Vblink_cursor_alist
= Qnil
;
20933 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
20934 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
20935 automatic_hscrolling_p
= 1;
20937 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
20938 doc
: /* *How many columns away from the window edge point is allowed to get
20939 before automatic hscrolling will horizontally scroll the window. */);
20940 hscroll_margin
= 5;
20942 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
20943 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
20944 When point is less than `automatic-hscroll-margin' columns from the window
20945 edge, automatic hscrolling will scroll the window by the amount of columns
20946 determined by this variable. If its value is a positive integer, scroll that
20947 many columns. If it's a positive floating-point number, it specifies the
20948 fraction of the window's width to scroll. If it's nil or zero, point will be
20949 centered horizontally after the scroll. Any other value, including negative
20950 numbers, are treated as if the value were zero.
20952 Automatic hscrolling always moves point outside the scroll margin, so if
20953 point was more than scroll step columns inside the margin, the window will
20954 scroll more than the value given by the scroll step.
20956 Note that the lower bound for automatic hscrolling specified by `scroll-left'
20957 and `scroll-right' overrides this variable's effect. */);
20958 Vhscroll_step
= make_number (0);
20960 DEFVAR_LISP ("image-types", &Vimage_types
,
20961 doc
: /* List of supported image types.
20962 Each element of the list is a symbol for a supported image type. */);
20963 Vimage_types
= Qnil
;
20965 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
20966 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
20967 Bind this around calls to `message' to let it take effect. */);
20968 message_truncate_lines
= 0;
20970 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
20971 doc
: /* Normal hook run for clicks on menu bar, before displaying a submenu.
20972 Can be used to update submenus whose contents should vary. */);
20973 Vmenu_bar_update_hook
= Qnil
;
20975 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
20976 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
20977 inhibit_menubar_update
= 0;
20979 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
20980 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
20981 inhibit_eval_during_redisplay
= 0;
20983 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
20984 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
20985 inhibit_free_realized_faces
= 0;
20988 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
20989 doc
: /* Inhibit try_window_id display optimization. */);
20990 inhibit_try_window_id
= 0;
20992 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
20993 doc
: /* Inhibit try_window_reusing display optimization. */);
20994 inhibit_try_window_reusing
= 0;
20996 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
20997 doc
: /* Inhibit try_cursor_movement display optimization. */);
20998 inhibit_try_cursor_movement
= 0;
20999 #endif /* GLYPH_DEBUG */
21003 /* Initialize this module when Emacs starts. */
21008 Lisp_Object root_window
;
21009 struct window
*mini_w
;
21011 current_header_line_height
= current_mode_line_height
= -1;
21013 CHARPOS (this_line_start_pos
) = 0;
21015 mini_w
= XWINDOW (minibuf_window
);
21016 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
21018 if (!noninteractive
)
21020 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
21023 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
21024 set_window_height (root_window
,
21025 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
21027 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
21028 set_window_height (minibuf_window
, 1, 0);
21030 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
21031 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
21033 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
21034 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
21035 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
21037 /* The default ellipsis glyphs `...'. */
21038 for (i
= 0; i
< 3; ++i
)
21039 default_invis_vector
[i
] = make_number ('.');
21043 /* Allocate the buffer for frame titles.
21044 Also used for `format-mode-line'. */
21046 frame_title_buf
= (char *) xmalloc (size
);
21047 frame_title_buf_end
= frame_title_buf
+ size
;
21048 frame_title_ptr
= NULL
;
21051 help_echo_showing_p
= 0;